blob: 176025f9e8436e85c8a9d3c532b3fc7ea5b7c579 [file] [log] [blame]
Andrew Geisslerf0343792020-11-18 10:42:21 -06001.. SPDX-License-Identifier: CC-BY-SA-2.0-UK
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002
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
Andrew Geissler09209ee2020-12-13 08:44:15 -060021":ref:`overview-manual/yp-intro:the yocto project layer model`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050022section 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
Andrew Geissler09209ee2020-12-13 08:44:15 -060034Guide and the ":ref:`dev-manual/common-tasks:creating a general layer using the \`\`bitbake-layers\`\` script`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050035section 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
Andrew Geisslerd1e89492021-02-12 15:35:20 -060041 you need. You can see the :oe_layerindex:`OpenEmbedded Metadata Index <>`
42 for a list of layers from the OpenEmbedded community that can be used in
Andrew Geisslerc9f78652020-09-18 14:11:35 -050043 the Yocto Project. You could find a layer that is identical or close
44 to what you need.
45
462. *Create a Directory:* Create the directory for your layer. When you
47 create the layer, be sure to create the directory in an area not
48 associated with the Yocto Project :term:`Source Directory`
49 (e.g. the cloned ``poky`` repository).
50
51 While not strictly required, prepend the name of the directory with
52 the string "meta-". For example:
53 ::
54
55 meta-mylayer
56 meta-GUI_xyz
57 meta-mymachine
58
59 With rare exceptions, a layer's name follows this form:
60 ::
61
62 meta-root_name
63
64 Following this layer naming convention can save
65 you trouble later when tools, components, or variables "assume" your
66 layer name begins with "meta-". A notable example is in configuration
67 files as shown in the following step where layer names without the
68 "meta-" string are appended to several variables used in the
69 configuration.
70
713. *Create a Layer Configuration File:* Inside your new layer folder,
72 you need to create a ``conf/layer.conf`` file. It is easiest to take
73 an existing layer configuration file and copy that to your layer's
74 ``conf`` directory and then modify the file as needed.
75
76 The ``meta-yocto-bsp/conf/layer.conf`` file in the Yocto Project
Andrew Geissler09209ee2020-12-13 08:44:15 -060077 :yocto_git:`Source Repositories </poky/tree/meta-yocto-bsp/conf>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050078 demonstrates the required syntax. For your layer, you need to replace
79 "yoctobsp" with a unique identifier for your layer (e.g. "machinexyz"
80 for a layer named "meta-machinexyz"):
81 ::
82
83 # We have a conf and classes directory, add to BBPATH
84 BBPATH .= ":${LAYERDIR}"
85
Andrew Geissler4c19ea12020-10-27 13:52:24 -050086 # We have recipes-* directories, add to BBFILES
Andrew Geisslerc9f78652020-09-18 14:11:35 -050087 BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
88 ${LAYERDIR}/recipes-*/*/*.bbappend"
89
90 BBFILE_COLLECTIONS += "yoctobsp"
91 BBFILE_PATTERN_yoctobsp = "^${LAYERDIR}/"
92 BBFILE_PRIORITY_yoctobsp = "5"
93 LAYERVERSION_yoctobsp = "4"
94 LAYERSERIES_COMPAT_yoctobsp = "dunfell"
95
96 Following is an explanation of the layer configuration file:
97
98 - :term:`BBPATH`: Adds the layer's
99 root directory to BitBake's search path. Through the use of the
100 ``BBPATH`` variable, BitBake locates class files (``.bbclass``),
101 configuration files, and files that are included with ``include``
102 and ``require`` statements. For these cases, BitBake uses the
103 first file that matches the name found in ``BBPATH``. This is
104 similar to the way the ``PATH`` variable is used for binaries. It
105 is recommended, therefore, that you use unique class and
106 configuration filenames in your custom layer.
107
108 - :term:`BBFILES`: Defines the
109 location for all recipes in the layer.
110
111 - :term:`BBFILE_COLLECTIONS`:
112 Establishes the current layer through a unique identifier that is
113 used throughout the OpenEmbedded build system to refer to the
114 layer. In this example, the identifier "yoctobsp" is the
115 representation for the container layer named "meta-yocto-bsp".
116
117 - :term:`BBFILE_PATTERN`:
118 Expands immediately during parsing to provide the directory of the
119 layer.
120
121 - :term:`BBFILE_PRIORITY`:
122 Establishes a priority to use for recipes in the layer when the
123 OpenEmbedded build finds recipes of the same name in different
124 layers.
125
126 - :term:`LAYERVERSION`:
127 Establishes a version number for the layer. You can use this
128 version number to specify this exact version of the layer as a
129 dependency when using the
130 :term:`LAYERDEPENDS`
131 variable.
132
133 - :term:`LAYERDEPENDS`:
134 Lists all layers on which this layer depends (if any).
135
136 - :term:`LAYERSERIES_COMPAT`:
Andrew Geissler09209ee2020-12-13 08:44:15 -0600137 Lists the :yocto_wiki:`Yocto Project </Releases>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500138 releases for which the current version is compatible. This
139 variable is a good way to indicate if your particular layer is
140 current.
141
1424. *Add Content:* Depending on the type of layer, add the content. If
143 the layer adds support for a machine, add the machine configuration
144 in a ``conf/machine/`` file within the layer. If the layer adds
145 distro policy, add the distro configuration in a ``conf/distro/``
146 file within the layer. If the layer introduces new recipes, put the
147 recipes you need in ``recipes-*`` subdirectories within the layer.
148
149 .. note::
150
151 For an explanation of layer hierarchy that is compliant with the
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500152 Yocto Project, see the ":ref:`bsp-guide/bsp:example filesystem layout`"
153 section in the Yocto Project Board Support Package (BSP) Developer's Guide.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500154
1555. *Optionally Test for Compatibility:* If you want permission to use
156 the Yocto Project Compatibility logo with your layer or application
157 that uses your layer, perform the steps to apply for compatibility.
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500158 See the
159 ":ref:`dev-manual/common-tasks:making sure your layer is compatible with yocto project`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500160 section for more information.
161
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500162Following Best Practices When Creating Layers
163---------------------------------------------
164
165To create layers that are easier to maintain and that will not impact
166builds for other machines, you should consider the information in the
167following list:
168
169- *Avoid "Overlaying" Entire Recipes from Other Layers in Your
170 Configuration:* In other words, do not copy an entire recipe into
171 your layer and then modify it. Rather, use an append file
172 (``.bbappend``) to override only those parts of the original recipe
173 you need to modify.
174
175- *Avoid Duplicating Include Files:* Use append files (``.bbappend``)
176 for each recipe that uses an include file. Or, if you are introducing
177 a new recipe that requires the included file, use the path relative
178 to the original layer directory to refer to the file. For example,
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500179 use ``require recipes-core/``\ `package`\ ``/``\ `file`\ ``.inc`` instead
180 of ``require`` `file`\ ``.inc``. If you're finding you have to overlay
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500181 the include file, it could indicate a deficiency in the include file
182 in the layer to which it originally belongs. If this is the case, you
183 should try to address that deficiency instead of overlaying the
184 include file. For example, you could address this by getting the
185 maintainer of the include file to add a variable or variables to make
186 it easy to override the parts needing to be overridden.
187
188- *Structure Your Layers:* Proper use of overrides within append files
189 and placement of machine-specific files within your layer can ensure
190 that a build is not using the wrong Metadata and negatively impacting
191 a build for a different machine. Following are some examples:
192
193 - *Modify Variables to Support a Different Machine:* Suppose you
194 have a layer named ``meta-one`` that adds support for building
195 machine "one". To do so, you use an append file named
196 ``base-files.bbappend`` and create a dependency on "foo" by
197 altering the :term:`DEPENDS`
198 variable:
199 ::
200
201 DEPENDS = "foo"
202
203 The dependency is created during any
204 build that includes the layer ``meta-one``. However, you might not
205 want this dependency for all machines. For example, suppose you
206 are building for machine "two" but your ``bblayers.conf`` file has
207 the ``meta-one`` layer included. During the build, the
208 ``base-files`` for machine "two" will also have the dependency on
209 ``foo``.
210
211 To make sure your changes apply only when building machine "one",
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500212 use a machine override with the ``DEPENDS`` statement:
213 ::
214
215 DEPENDS_one = "foo"
216
217 You should follow the same strategy when using ``_append``
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500218 and ``_prepend`` operations:
219 ::
220
221 DEPENDS_append_one = " foo"
222 DEPENDS_prepend_one = "foo "
223
224 As an actual example, here's a
225 snippet from the generic kernel include file ``linux-yocto.inc``,
226 wherein the kernel compile and link options are adjusted in the
227 case of a subset of the supported architectures:
228 ::
229
230 DEPENDS_append_aarch64 = " libgcc"
231 KERNEL_CC_append_aarch64 = " ${TOOLCHAIN_OPTIONS}"
232 KERNEL_LD_append_aarch64 = " ${TOOLCHAIN_OPTIONS}"
233
234 DEPENDS_append_nios2 = " libgcc"
235 KERNEL_CC_append_nios2 = " ${TOOLCHAIN_OPTIONS}"
236 KERNEL_LD_append_nios2 = " ${TOOLCHAIN_OPTIONS}"
237
238 DEPENDS_append_arc = " libgcc"
239 KERNEL_CC_append_arc = " ${TOOLCHAIN_OPTIONS}"
240 KERNEL_LD_append_arc = " ${TOOLCHAIN_OPTIONS}"
241
242 KERNEL_FEATURES_append_qemuall=" features/debug/printk.scc"
243
244 .. note::
245
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500246 Avoiding "+=" and "=+" and using machine-specific ``_append``
247 and ``_prepend`` operations is recommended as well.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500248
249 - *Place Machine-Specific Files in Machine-Specific Locations:* When
250 you have a base recipe, such as ``base-files.bb``, that contains a
251 :term:`SRC_URI` statement to a
252 file, you can use an append file to cause the build to use your
253 own version of the file. For example, an append file in your layer
254 at ``meta-one/recipes-core/base-files/base-files.bbappend`` could
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500255 extend :term:`FILESPATH` using :term:`FILESEXTRAPATHS` as follows:
256 ::
257
258 FILESEXTRAPATHS_prepend := "${THISDIR}/${BPN}:"
259
260 The build for machine "one" will pick up your machine-specific file as
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500261 long as you have the file in
262 ``meta-one/recipes-core/base-files/base-files/``. However, if you
263 are building for a different machine and the ``bblayers.conf``
264 file includes the ``meta-one`` layer and the location of your
265 machine-specific file is the first location where that file is
266 found according to ``FILESPATH``, builds for all machines will
267 also use that machine-specific file.
268
269 You can make sure that a machine-specific file is used for a
270 particular machine by putting the file in a subdirectory specific
271 to the machine. For example, rather than placing the file in
272 ``meta-one/recipes-core/base-files/base-files/`` as shown above,
273 put it in ``meta-one/recipes-core/base-files/base-files/one/``.
274 Not only does this make sure the file is used only when building
275 for machine "one", but the build process locates the file more
276 quickly.
277
278 In summary, you need to place all files referenced from
279 ``SRC_URI`` in a machine-specific subdirectory within the layer in
280 order to restrict those files to machine-specific builds.
281
282- *Perform Steps to Apply for Yocto Project Compatibility:* If you want
283 permission to use the Yocto Project Compatibility logo with your
284 layer or application that uses your layer, perform the steps to apply
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500285 for compatibility. See the
286 ":ref:`dev-manual/common-tasks:making sure your layer is compatible with yocto project`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500287 section for more information.
288
289- *Follow the Layer Naming Convention:* Store custom layers in a Git
290 repository that use the ``meta-layer_name`` format.
291
292- *Group Your Layers Locally:* Clone your repository alongside other
293 cloned ``meta`` directories from the :term:`Source Directory`.
294
295Making Sure Your Layer is Compatible With Yocto Project
296-------------------------------------------------------
297
298When you create a layer used with the Yocto Project, it is advantageous
299to make sure that the layer interacts well with existing Yocto Project
300layers (i.e. the layer is compatible with the Yocto Project). Ensuring
301compatibility makes the layer easy to be consumed by others in the Yocto
302Project community and could allow you permission to use the Yocto
303Project Compatible Logo.
304
305.. note::
306
307 Only Yocto Project member organizations are permitted to use the
308 Yocto Project Compatible Logo. The logo is not available for general
309 use. For information on how to become a Yocto Project member
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500310 organization, see the :yocto_home:`Yocto Project Website <>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500311
312The Yocto Project Compatibility Program consists of a layer application
313process that requests permission to use the Yocto Project Compatibility
314Logo for your layer and application. The process consists of two parts:
315
3161. Successfully passing a script (``yocto-check-layer``) that when run
317 against your layer, tests it against constraints based on experiences
318 of how layers have worked in the real world and where pitfalls have
319 been found. Getting a "PASS" result from the script is required for
320 successful compatibility registration.
321
3222. Completion of an application acceptance form, which you can find at
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600323 :yocto_home:`/webform/yocto-project-compatible-registration`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500324
325To be granted permission to use the logo, you need to satisfy the
326following:
327
328- Be able to check the box indicating that you got a "PASS" when
329 running the script against your layer.
330
331- Answer "Yes" to the questions on the form or have an acceptable
332 explanation for any questions answered "No".
333
334- Be a Yocto Project Member Organization.
335
336The remainder of this section presents information on the registration
337form and on the ``yocto-check-layer`` script.
338
339Yocto Project Compatible Program Application
340~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
341
342Use the form to apply for your layer's approval. Upon successful
343application, you can use the Yocto Project Compatibility Logo with your
344layer and the application that uses your layer.
345
346To access the form, use this link:
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600347:yocto_home:`/webform/yocto-project-compatible-registration`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500348Follow the instructions on the form to complete your application.
349
350The application consists of the following sections:
351
352- *Contact Information:* Provide your contact information as the fields
353 require. Along with your information, provide the released versions
354 of the Yocto Project for which your layer is compatible.
355
356- *Acceptance Criteria:* Provide "Yes" or "No" answers for each of the
357 items in the checklist. Space exists at the bottom of the form for
358 any explanations for items for which you answered "No".
359
360- *Recommendations:* Provide answers for the questions regarding Linux
361 kernel use and build success.
362
363``yocto-check-layer`` Script
364~~~~~~~~~~~~~~~~~~~~~~~~~~~~
365
366The ``yocto-check-layer`` script provides you a way to assess how
367compatible your layer is with the Yocto Project. You should run this
368script prior to using the form to apply for compatibility as described
369in the previous section. You need to achieve a "PASS" result in order to
370have your application form successfully processed.
371
372The script divides tests into three areas: COMMON, BSP, and DISTRO. For
373example, given a distribution layer (DISTRO), the layer must pass both
374the COMMON and DISTRO related tests. Furthermore, if your layer is a BSP
375layer, the layer must pass the COMMON and BSP set of tests.
376
377To execute the script, enter the following commands from your build
378directory:
379::
380
381 $ source oe-init-build-env
382 $ yocto-check-layer your_layer_directory
383
384Be sure to provide the actual directory for your
385layer as part of the command.
386
387Entering the command causes the script to determine the type of layer
388and then to execute a set of specific tests against the layer. The
389following list overviews the test:
390
391- ``common.test_readme``: Tests if a ``README`` file exists in the
392 layer and the file is not empty.
393
394- ``common.test_parse``: Tests to make sure that BitBake can parse the
395 files without error (i.e. ``bitbake -p``).
396
397- ``common.test_show_environment``: Tests that the global or per-recipe
398 environment is in order without errors (i.e. ``bitbake -e``).
399
400- ``common.test_world``: Verifies that ``bitbake world`` works.
401
402- ``common.test_signatures``: Tests to be sure that BSP and DISTRO
403 layers do not come with recipes that change signatures.
404
405- ``common.test_layerseries_compat``: Verifies layer compatibility is
406 set properly.
407
408- ``bsp.test_bsp_defines_machines``: Tests if a BSP layer has machine
409 configurations.
410
411- ``bsp.test_bsp_no_set_machine``: Tests to ensure a BSP layer does not
412 set the machine when the layer is added.
413
414- ``bsp.test_machine_world``: Verifies that ``bitbake world`` works
415 regardless of which machine is selected.
416
417- ``bsp.test_machine_signatures``: Verifies that building for a
418 particular machine affects only the signature of tasks specific to
419 that machine.
420
421- ``distro.test_distro_defines_distros``: Tests if a DISTRO layer has
422 distro configurations.
423
424- ``distro.test_distro_no_set_distros``: Tests to ensure a DISTRO layer
425 does not set the distribution when the layer is added.
426
427Enabling Your Layer
428-------------------
429
430Before the OpenEmbedded build system can use your new layer, you need to
431enable it. To enable your layer, simply add your layer's path to the
432``BBLAYERS`` variable in your ``conf/bblayers.conf`` file, which is
433found in the :term:`Build Directory`.
434The following example shows how to enable a layer named
435``meta-mylayer``:
436::
437
438 # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
439 # changes incompatibly
440 POKY_BBLAYERS_CONF_VERSION = "2"
441 BBPATH = "${TOPDIR}"
442 BBFILES ?= ""
443 BBLAYERS ?= " \
444 /home/user/poky/meta \
445 /home/user/poky/meta-poky \
446 /home/user/poky/meta-yocto-bsp \
447 /home/user/poky/meta-mylayer \
448 "
449
450BitBake parses each ``conf/layer.conf`` file from the top down as
451specified in the ``BBLAYERS`` variable within the ``conf/bblayers.conf``
452file. During the processing of each ``conf/layer.conf`` file, BitBake
453adds the recipes, classes and configurations contained within the
454particular layer to the source directory.
455
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500456Using .bbappend Files in Your Layer
457-----------------------------------
458
459A recipe that appends Metadata to another recipe is called a BitBake
460append file. A BitBake append file uses the ``.bbappend`` file type
461suffix, while the corresponding recipe to which Metadata is being
462appended uses the ``.bb`` file type suffix.
463
464You can use a ``.bbappend`` file in your layer to make additions or
465changes to the content of another layer's recipe without having to copy
466the other layer's recipe into your layer. Your ``.bbappend`` file
467resides in your layer, while the main ``.bb`` recipe file to which you
468are appending Metadata resides in a different layer.
469
470Being able to append information to an existing recipe not only avoids
471duplication, but also automatically applies recipe changes from a
472different layer into your layer. If you were copying recipes, you would
473have to manually merge changes as they occur.
474
475When you create an append file, you must use the same root name as the
476corresponding recipe file. For example, the append file
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500477``someapp_3.1.bbappend`` must apply to ``someapp_3.1.bb``. This
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500478means the original recipe and append file names are version
479number-specific. If the corresponding recipe is renamed to update to a
480newer version, you must also rename and possibly update the
481corresponding ``.bbappend`` as well. During the build process, BitBake
482displays an error on starting if it detects a ``.bbappend`` file that
483does not have a corresponding recipe with a matching name. See the
484:term:`BB_DANGLINGAPPENDS_WARNONLY`
485variable for information on how to handle this error.
486
487As an example, consider the main formfactor recipe and a corresponding
488formfactor append file both from the :term:`Source Directory`.
489Here is the main
490formfactor recipe, which is named ``formfactor_0.0.bb`` and located in
491the "meta" layer at ``meta/recipes-bsp/formfactor``:
492::
493
494 SUMMARY = "Device formfactor information"
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500495 DESCRIPTION = "A formfactor configuration file provides information about the \
496 target hardware for which the image is being built and information that the \
497 build system cannot obtain from other sources such as the kernel."
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500498 SECTION = "base"
499 LICENSE = "MIT"
500 LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
501 PR = "r45"
502
503 SRC_URI = "file://config file://machconfig"
504 S = "${WORKDIR}"
505
506 PACKAGE_ARCH = "${MACHINE_ARCH}"
507 INHIBIT_DEFAULT_DEPS = "1"
508
509 do_install() {
510 # Install file only if it has contents
511 install -d ${D}${sysconfdir}/formfactor/
512 install -m 0644 ${S}/config ${D}${sysconfdir}/formfactor/
513 if [ -s "${S}/machconfig" ]; then
514 install -m 0644 ${S}/machconfig ${D}${sysconfdir}/formfactor/
515 fi
516 }
517
518In the main recipe, note the :term:`SRC_URI`
519variable, which tells the OpenEmbedded build system where to find files
520during the build.
521
522Following is the append file, which is named ``formfactor_0.0.bbappend``
523and is from the Raspberry Pi BSP Layer named ``meta-raspberrypi``. The
524file is in the layer at ``recipes-bsp/formfactor``:
525::
526
527 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
528
529By default, the build system uses the
530:term:`FILESPATH` variable to
531locate files. This append file extends the locations by setting the
532:term:`FILESEXTRAPATHS`
533variable. Setting this variable in the ``.bbappend`` file is the most
534reliable and recommended method for adding directories to the search
535path used by the build system to find files.
536
537The statement in this example extends the directories to include
538``${``\ :term:`THISDIR`\ ``}/${``\ :term:`PN`\ ``}``,
539which resolves to a directory named ``formfactor`` in the same directory
540in which the append file resides (i.e.
541``meta-raspberrypi/recipes-bsp/formfactor``. This implies that you must
542have the supporting directory structure set up that will contain any
543files or patches you will be including from the layer.
544
545Using the immediate expansion assignment operator ``:=`` is important
546because of the reference to ``THISDIR``. The trailing colon character is
547important as it ensures that items in the list remain colon-separated.
548
549.. note::
550
551 BitBake automatically defines the ``THISDIR`` variable. You should
552 never set this variable yourself. Using "_prepend" as part of the
553 ``FILESEXTRAPATHS`` ensures your path will be searched prior to other
554 paths in the final list.
555
556 Also, not all append files add extra files. Many append files simply
557 exist to add build options (e.g. ``systemd``). For these cases, your
558 append file would not even use the ``FILESEXTRAPATHS`` statement.
559
560Prioritizing Your Layer
561-----------------------
562
563Each layer is assigned a priority value. Priority values control which
564layer takes precedence if there are recipe files with the same name in
565multiple layers. For these cases, the recipe file from the layer with a
566higher priority number takes precedence. Priority values also affect the
567order in which multiple ``.bbappend`` files for the same recipe are
568applied. You can either specify the priority manually, or allow the
569build system to calculate it based on the layer's dependencies.
570
571To specify the layer's priority manually, use the
572:term:`BBFILE_PRIORITY`
573variable and append the layer's root name:
574::
575
576 BBFILE_PRIORITY_mylayer = "1"
577
578.. note::
579
580 It is possible for a recipe with a lower version number
581 :term:`PV` in a layer that has a higher
582 priority to take precedence.
583
584 Also, the layer priority does not currently affect the precedence
585 order of ``.conf`` or ``.bbclass`` files. Future versions of BitBake
586 might address this.
587
588Managing Layers
589---------------
590
591You can use the BitBake layer management tool ``bitbake-layers`` to
592provide a view into the structure of recipes across a multi-layer
593project. Being able to generate output that reports on configured layers
594with their paths and priorities and on ``.bbappend`` files and their
595applicable recipes can help to reveal potential problems.
596
597For help on the BitBake layer management tool, use the following
598command:
599::
600
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500601 $ bitbake-layers --help
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500602 NOTE: Starting bitbake server...
603 usage: bitbake-layers [-d] [-q] [-F] [--color COLOR] [-h] <subcommand> ...
604
605 BitBake layers utility
606
607 optional arguments:
608 -d, --debug Enable debug output
609 -q, --quiet Print only errors
610 -F, --force Force add without recipe parse verification
611 --color COLOR Colorize output (where COLOR is auto, always, never)
612 -h, --help show this help message and exit
613
614 subcommands:
615 <subcommand>
616 layerindex-fetch Fetches a layer from a layer index along with its
617 dependent layers, and adds them to conf/bblayers.conf.
618 layerindex-show-depends
619 Find layer dependencies from layer index.
620 add-layer Add one or more layers to bblayers.conf.
621 remove-layer Remove one or more layers from bblayers.conf.
622 flatten flatten layer configuration into a separate output
623 directory.
624 show-layers show current configured layers.
625 show-overlayed list overlayed recipes (where the same recipe exists
626 in another layer)
627 show-recipes list available recipes, showing the layer they are
628 provided by
629 show-appends list bbappend files and recipe files they apply to
630 show-cross-depends Show dependencies between recipes that cross layer
631 boundaries.
632 create-layer Create a basic layer
633
634 Use bitbake-layers <subcommand> --help to get help on a specific command
635
636The following list describes the available commands:
637
638- ``help:`` Displays general help or help on a specified command.
639
640- ``show-layers:`` Shows the current configured layers.
641
642- ``show-overlayed:`` Lists overlayed recipes. A recipe is overlayed
643 when a recipe with the same name exists in another layer that has a
644 higher layer priority.
645
646- ``show-recipes:`` Lists available recipes and the layers that
647 provide them.
648
649- ``show-appends:`` Lists ``.bbappend`` files and the recipe files to
650 which they apply.
651
652- ``show-cross-depends:`` Lists dependency relationships between
653 recipes that cross layer boundaries.
654
655- ``add-layer:`` Adds a layer to ``bblayers.conf``.
656
657- ``remove-layer:`` Removes a layer from ``bblayers.conf``
658
659- ``flatten:`` Flattens the layer configuration into a separate
660 output directory. Flattening your layer configuration builds a
661 "flattened" directory that contains the contents of all layers, with
662 any overlayed recipes removed and any ``.bbappend`` files appended to
663 the corresponding recipes. You might have to perform some manual
664 cleanup of the flattened layer as follows:
665
666 - Non-recipe files (such as patches) are overwritten. The flatten
667 command shows a warning for these files.
668
669 - Anything beyond the normal layer setup has been added to the
670 ``layer.conf`` file. Only the lowest priority layer's
671 ``layer.conf`` is used.
672
673 - Overridden and appended items from ``.bbappend`` files need to be
674 cleaned up. The contents of each ``.bbappend`` end up in the
675 flattened recipe. However, if there are appended or changed
676 variable values, you need to tidy these up yourself. Consider the
677 following example. Here, the ``bitbake-layers`` command adds the
678 line ``#### bbappended ...`` so that you know where the following
679 lines originate:
680 ::
681
682 ...
683 DESCRIPTION = "A useful utility"
684 ...
685 EXTRA_OECONF = "--enable-something"
686 ...
687
688 #### bbappended from meta-anotherlayer ####
689
690 DESCRIPTION = "Customized utility"
691 EXTRA_OECONF += "--enable-somethingelse"
692
693
694 Ideally, you would tidy up these utilities as follows:
695 ::
696
697 ...
698 DESCRIPTION = "Customized utility"
699 ...
700 EXTRA_OECONF = "--enable-something --enable-somethingelse"
701 ...
702
703- ``layerindex-fetch``: Fetches a layer from a layer index, along
704 with its dependent layers, and adds the layers to the
705 ``conf/bblayers.conf`` file.
706
707- ``layerindex-show-depends``: Finds layer dependencies from the
708 layer index.
709
710- ``create-layer``: Creates a basic layer.
711
712Creating a General Layer Using the ``bitbake-layers`` Script
713------------------------------------------------------------
714
715The ``bitbake-layers`` script with the ``create-layer`` subcommand
716simplifies creating a new general layer.
717
718.. note::
719
720 - For information on BSP layers, see the ":ref:`bsp-guide/bsp:bsp layers`"
721 section in the Yocto
722 Project Board Specific (BSP) Developer's Guide.
723
724 - In order to use a layer with the OpenEmbedded build system, you
725 need to add the layer to your ``bblayers.conf`` configuration
Andrew Geissler09209ee2020-12-13 08:44:15 -0600726 file. See the ":ref:`dev-manual/common-tasks:adding a layer using the \`\`bitbake-layers\`\` script`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500727 section for more information.
728
729The default mode of the script's operation with this subcommand is to
730create a layer with the following:
731
732- A layer priority of 6.
733
734- A ``conf`` subdirectory that contains a ``layer.conf`` file.
735
736- A ``recipes-example`` subdirectory that contains a further
737 subdirectory named ``example``, which contains an ``example.bb``
738 recipe file.
739
740- A ``COPYING.MIT``, which is the license statement for the layer. The
741 script assumes you want to use the MIT license, which is typical for
742 most layers, for the contents of the layer itself.
743
744- A ``README`` file, which is a file describing the contents of your
745 new layer.
746
747In its simplest form, you can use the following command form to create a
748layer. The command creates a layer whose name corresponds to
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500749"your_layer_name" in the current directory:
750::
751
752 $ bitbake-layers create-layer your_layer_name
753
754As an example, the following command creates a layer named ``meta-scottrif``
755in your home directory:
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500756::
757
758 $ cd /usr/home
759 $ bitbake-layers create-layer meta-scottrif
760 NOTE: Starting bitbake server...
761 Add your new layer with 'bitbake-layers add-layer meta-scottrif'
762
763If you want to set the priority of the layer to other than the default
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500764value of "6", you can either use the ``--priority`` option or you
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500765can edit the
766:term:`BBFILE_PRIORITY` value
767in the ``conf/layer.conf`` after the script creates it. Furthermore, if
768you want to give the example recipe file some name other than the
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500769default, you can use the ``--example-recipe-name`` option.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500770
771The easiest way to see how the ``bitbake-layers create-layer`` command
772works is to experiment with the script. You can also read the usage
773information by entering the following:
774::
775
776 $ bitbake-layers create-layer --help
777 NOTE: Starting bitbake server...
778 usage: bitbake-layers create-layer [-h] [--priority PRIORITY]
779 [--example-recipe-name EXAMPLERECIPE]
780 layerdir
781
782 Create a basic layer
783
784 positional arguments:
785 layerdir Layer directory to create
786
787 optional arguments:
788 -h, --help show this help message and exit
789 --priority PRIORITY, -p PRIORITY
790 Layer directory to create
791 --example-recipe-name EXAMPLERECIPE, -e EXAMPLERECIPE
792 Filename of the example recipe
793
794Adding a Layer Using the ``bitbake-layers`` Script
795--------------------------------------------------
796
797Once you create your general layer, you must add it to your
798``bblayers.conf`` file. Adding the layer to this configuration file
799makes the OpenEmbedded build system aware of your layer so that it can
800search it for metadata.
801
802Add your layer by using the ``bitbake-layers add-layer`` command:
803::
804
805 $ bitbake-layers add-layer your_layer_name
806
807Here is an example that adds a
808layer named ``meta-scottrif`` to the configuration file. Following the
809command that adds the layer is another ``bitbake-layers`` command that
810shows the layers that are in your ``bblayers.conf`` file:
811::
812
813 $ bitbake-layers add-layer meta-scottrif
814 NOTE: Starting bitbake server...
815 Parsing recipes: 100% |##########################################################| Time: 0:00:49
816 Parsing of 1441 .bb files complete (0 cached, 1441 parsed). 2055 targets, 56 skipped, 0 masked, 0 errors.
817 $ bitbake-layers show-layers
818 NOTE: Starting bitbake server...
819 layer path priority
820 ==========================================================================
821 meta /home/scottrif/poky/meta 5
822 meta-poky /home/scottrif/poky/meta-poky 5
823 meta-yocto-bsp /home/scottrif/poky/meta-yocto-bsp 5
824 workspace /home/scottrif/poky/build/workspace 99
825 meta-scottrif /home/scottrif/poky/build/meta-scottrif 6
826
827
828Adding the layer to this file
829enables the build system to locate the layer during the build.
830
831.. note::
832
833 During a build, the OpenEmbedded build system looks in the layers
834 from the top of the list down to the bottom in that order.
835
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500836Customizing Images
837==================
838
839You can customize images to satisfy particular requirements. This
840section describes several methods and provides guidelines for each.
841
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500842Customizing Images Using ``local.conf``
843---------------------------------------
844
845Probably the easiest way to customize an image is to add a package by
846way of the ``local.conf`` configuration file. Because it is limited to
847local use, this method generally only allows you to add packages and is
848not as flexible as creating your own customized image. When you add
849packages using local variables this way, you need to realize that these
850variable changes are in effect for every build and consequently affect
851all images, which might not be what you require.
852
853To add a package to your image using the local configuration file, use
854the ``IMAGE_INSTALL`` variable with the ``_append`` operator:
855::
856
857 IMAGE_INSTALL_append = " strace"
858
859Use of the syntax is important -
860specifically, the space between the quote and the package name, which is
861``strace`` in this example. This space is required since the ``_append``
862operator does not add the space.
863
864Furthermore, you must use ``_append`` instead of the ``+=`` operator if
865you want to avoid ordering issues. The reason for this is because doing
866so unconditionally appends to the variable and avoids ordering problems
867due to the variable being set in image recipes and ``.bbclass`` files
868with operators like ``?=``. Using ``_append`` ensures the operation
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500869takes effect.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500870
871As shown in its simplest use, ``IMAGE_INSTALL_append`` affects all
872images. It is possible to extend the syntax so that the variable applies
873to a specific image only. Here is an example:
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500874::
875
876 IMAGE_INSTALL_append_pn-core-image-minimal = " strace"
877
878This example adds ``strace`` to the ``core-image-minimal`` image only.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500879
880You can add packages using a similar approach through the
881``CORE_IMAGE_EXTRA_INSTALL`` variable. If you use this variable, only
882``core-image-*`` images are affected.
883
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500884Customizing Images Using Custom ``IMAGE_FEATURES`` and ``EXTRA_IMAGE_FEATURES``
885-------------------------------------------------------------------------------
886
887Another method for customizing your image is to enable or disable
888high-level image features by using the
889:term:`IMAGE_FEATURES` and
890:term:`EXTRA_IMAGE_FEATURES`
891variables. Although the functions for both variables are nearly
892equivalent, best practices dictate using ``IMAGE_FEATURES`` from within
893a recipe and using ``EXTRA_IMAGE_FEATURES`` from within your
894``local.conf`` file, which is found in the
895:term:`Build Directory`.
896
897To understand how these features work, the best reference is
898``meta/classes/core-image.bbclass``. This class lists out the available
899``IMAGE_FEATURES`` of which most map to package groups while some, such
900as ``debug-tweaks`` and ``read-only-rootfs``, resolve as general
901configuration settings.
902
903In summary, the file looks at the contents of the ``IMAGE_FEATURES``
904variable and then maps or configures the feature accordingly. Based on
905this information, the build system automatically adds the appropriate
906packages or configurations to the
907:term:`IMAGE_INSTALL` variable.
908Effectively, you are enabling extra features by extending the class or
909creating a custom class for use with specialized image ``.bb`` files.
910
911Use the ``EXTRA_IMAGE_FEATURES`` variable from within your local
912configuration file. Using a separate area from which to enable features
913with this variable helps you avoid overwriting the features in the image
914recipe that are enabled with ``IMAGE_FEATURES``. The value of
915``EXTRA_IMAGE_FEATURES`` is added to ``IMAGE_FEATURES`` within
916``meta/conf/bitbake.conf``.
917
918To illustrate how you can use these variables to modify your image,
919consider an example that selects the SSH server. The Yocto Project ships
920with two SSH servers you can use with your images: Dropbear and OpenSSH.
921Dropbear is a minimal SSH server appropriate for resource-constrained
922environments, while OpenSSH is a well-known standard SSH server
923implementation. By default, the ``core-image-sato`` image is configured
924to use Dropbear. The ``core-image-full-cmdline`` and ``core-image-lsb``
925images both include OpenSSH. The ``core-image-minimal`` image does not
926contain an SSH server.
927
928You can customize your image and change these defaults. Edit the
929``IMAGE_FEATURES`` variable in your recipe or use the
930``EXTRA_IMAGE_FEATURES`` in your ``local.conf`` file so that it
931configures the image you are working with to include
932``ssh-server-dropbear`` or ``ssh-server-openssh``.
933
934.. note::
935
Andrew Geissler09209ee2020-12-13 08:44:15 -0600936 See the ":ref:`ref-manual/features:image features`" section in the Yocto
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500937 Project Reference Manual for a complete list of image features that ship
938 with the Yocto Project.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500939
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500940Customizing Images Using Custom .bb Files
941-----------------------------------------
942
943You can also customize an image by creating a custom recipe that defines
944additional software as part of the image. The following example shows
945the form for the two lines you need:
946::
947
948 IMAGE_INSTALL = "packagegroup-core-x11-base package1 package2"
949 inherit core-image
950
951Defining the software using a custom recipe gives you total control over
952the contents of the image. It is important to use the correct names of
953packages in the ``IMAGE_INSTALL`` variable. You must use the
954OpenEmbedded notation and not the Debian notation for the names (e.g.
955``glibc-dev`` instead of ``libc6-dev``).
956
957The other method for creating a custom image is to base it on an
958existing image. For example, if you want to create an image based on
959``core-image-sato`` but add the additional package ``strace`` to the
960image, copy the ``meta/recipes-sato/images/core-image-sato.bb`` to a new
961``.bb`` and add the following line to the end of the copy:
962::
963
964 IMAGE_INSTALL += "strace"
965
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500966Customizing Images Using Custom Package Groups
967----------------------------------------------
968
969For complex custom images, the best approach for customizing an image is
970to create a custom package group recipe that is used to build the image
971or images. A good example of a package group recipe is
972``meta/recipes-core/packagegroups/packagegroup-base.bb``.
973
974If you examine that recipe, you see that the ``PACKAGES`` variable lists
975the package group packages to produce. The ``inherit packagegroup``
976statement sets appropriate default values and automatically adds
977``-dev``, ``-dbg``, and ``-ptest`` complementary packages for each
978package specified in the ``PACKAGES`` statement.
979
980.. note::
981
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500982 The ``inherit packagegroup`` line should be located near the top of the
983 recipe, certainly before the ``PACKAGES`` statement.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500984
985For each package you specify in ``PACKAGES``, you can use ``RDEPENDS``
986and ``RRECOMMENDS`` entries to provide a list of packages the parent
987task package should contain. You can see examples of these further down
988in the ``packagegroup-base.bb`` recipe.
989
990Here is a short, fabricated example showing the same basic pieces for a
991hypothetical packagegroup defined in ``packagegroup-custom.bb``, where
992the variable ``PN`` is the standard way to abbreviate the reference to
993the full packagegroup name ``packagegroup-custom``:
994::
995
996 DESCRIPTION = "My Custom Package Groups"
997
998 inherit packagegroup
999
1000 PACKAGES = "\
1001 ${PN}-apps \
1002 ${PN}-tools \
1003 "
1004
1005 RDEPENDS_${PN}-apps = "\
1006 dropbear \
1007 portmap \
1008 psplash"
1009
1010 RDEPENDS_${PN}-tools = "\
1011 oprofile \
1012 oprofileui-server \
1013 lttng-tools"
1014
1015 RRECOMMENDS_${PN}-tools = "\
1016 kernel-module-oprofile"
1017
1018In the previous example, two package group packages are created with
1019their dependencies and their recommended package dependencies listed:
1020``packagegroup-custom-apps``, and ``packagegroup-custom-tools``. To
1021build an image using these package group packages, you need to add
1022``packagegroup-custom-apps`` and/or ``packagegroup-custom-tools`` to
1023``IMAGE_INSTALL``. For other forms of image dependencies see the other
1024areas of this section.
1025
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001026Customizing an Image Hostname
1027-----------------------------
1028
1029By default, the configured hostname (i.e. ``/etc/hostname``) in an image
1030is the same as the machine name. For example, if
1031:term:`MACHINE` equals "qemux86", the
1032configured hostname written to ``/etc/hostname`` is "qemux86".
1033
1034You can customize this name by altering the value of the "hostname"
1035variable in the ``base-files`` recipe using either an append file or a
1036configuration file. Use the following in an append file:
1037::
1038
1039 hostname = "myhostname"
1040
1041Use the following in a configuration file:
1042::
1043
1044 hostname_pn-base-files = "myhostname"
1045
1046Changing the default value of the variable "hostname" can be useful in
1047certain situations. For example, suppose you need to do extensive
1048testing on an image and you would like to easily identify the image
1049under test from existing images with typical default hostnames. In this
1050situation, you could change the default hostname to "testme", which
1051results in all the images using the name "testme". Once testing is
1052complete and you do not need to rebuild the image for test any longer,
1053you can easily reset the default hostname.
1054
1055Another point of interest is that if you unset the variable, the image
1056will have no default hostname in the filesystem. Here is an example that
1057unsets the variable in a configuration file:
1058::
1059
1060 hostname_pn-base-files = ""
1061
1062Having no default hostname in the filesystem is suitable for
1063environments that use dynamic hostnames such as virtual machines.
1064
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001065Writing a New Recipe
1066====================
1067
1068Recipes (``.bb`` files) are fundamental components in the Yocto Project
1069environment. Each software component built by the OpenEmbedded build
1070system requires a recipe to define the component. This section describes
1071how to create, write, and test a new recipe.
1072
1073.. note::
1074
1075 For information on variables that are useful for recipes and for
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001076 information about recipe naming issues, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001077 ":ref:`ref-manual/varlocality:recipes`" section of the Yocto Project
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001078 Reference Manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001079
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001080Overview
1081--------
1082
1083The following figure shows the basic process for creating a new recipe.
1084The remainder of the section provides details for the steps.
1085
1086.. image:: figures/recipe-workflow.png
1087 :align: center
1088
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001089Locate or Automatically Create a Base Recipe
1090--------------------------------------------
1091
1092You can always write a recipe from scratch. However, three choices exist
1093that can help you quickly get a start on a new recipe:
1094
1095- ``devtool add``: A command that assists in creating a recipe and an
1096 environment conducive to development.
1097
1098- ``recipetool create``: A command provided by the Yocto Project that
1099 automates creation of a base recipe based on the source files.
1100
1101- *Existing Recipes:* Location and modification of an existing recipe
1102 that is similar in function to the recipe you need.
1103
1104.. note::
1105
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001106 For information on recipe syntax, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001107 ":ref:`dev-manual/common-tasks:recipe syntax`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001108
1109Creating the Base Recipe Using ``devtool add``
1110~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1111
1112The ``devtool add`` command uses the same logic for auto-creating the
1113recipe as ``recipetool create``, which is listed below. Additionally,
1114however, ``devtool add`` sets up an environment that makes it easy for
1115you to patch the source and to make changes to the recipe as is often
1116necessary when adding a recipe to build a new piece of software to be
1117included in a build.
1118
1119You can find a complete description of the ``devtool add`` command in
Andrew Geissler09209ee2020-12-13 08:44:15 -06001120the ":ref:`sdk-manual/extensible:a closer look at \`\`devtool add\`\``" section
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001121in the Yocto Project Application Development and the Extensible Software
1122Development Kit (eSDK) manual.
1123
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001124Creating the Base Recipe Using ``recipetool create``
1125~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1126
1127``recipetool create`` automates creation of a base recipe given a set of
1128source code files. As long as you can extract or point to the source
1129files, the tool will construct a recipe and automatically configure all
1130pre-build information into the recipe. For example, suppose you have an
1131application that builds using Autotools. Creating the base recipe using
1132``recipetool`` results in a recipe that has the pre-build dependencies,
1133license requirements, and checksums configured.
1134
1135To run the tool, you just need to be in your
1136:term:`Build Directory` and have sourced the
1137build environment setup script (i.e.
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001138:ref:`structure-core-script`).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001139To get help on the tool, use the following command:
1140::
1141
1142 $ recipetool -h
1143 NOTE: Starting bitbake server...
1144 usage: recipetool [-d] [-q] [--color COLOR] [-h] <subcommand> ...
1145
1146 OpenEmbedded recipe tool
1147
1148 options:
1149 -d, --debug Enable debug output
1150 -q, --quiet Print only errors
1151 --color COLOR Colorize output (where COLOR is auto, always, never)
1152 -h, --help show this help message and exit
1153
1154 subcommands:
1155 create Create a new recipe
1156 newappend Create a bbappend for the specified target in the specified
1157 layer
1158 setvar Set a variable within a recipe
1159 appendfile Create/update a bbappend to replace a target file
1160 appendsrcfiles Create/update a bbappend to add or replace source files
1161 appendsrcfile Create/update a bbappend to add or replace a source file
1162 Use recipetool <subcommand> --help to get help on a specific command
1163
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001164Running ``recipetool create -o OUTFILE`` creates the base recipe and
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001165locates it properly in the layer that contains your source files.
1166Following are some syntax examples:
1167
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001168 - Use this syntax to generate a recipe based on source. Once generated,
1169 the recipe resides in the existing source code layer:
1170 ::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001171
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001172 recipetool create -o OUTFILE source
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001173
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001174 - Use this syntax to generate a recipe using code that
1175 you extract from source. The extracted code is placed in its own layer
1176 defined by ``EXTERNALSRC``.
1177 ::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001178
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001179 recipetool create -o OUTFILE -x EXTERNALSRC source
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001180
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001181 - Use this syntax to generate a recipe based on source. The options
1182 direct ``recipetool`` to generate debugging information. Once generated,
1183 the recipe resides in the existing source code layer:
1184 ::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001185
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001186 recipetool create -d -o OUTFILE source
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001187
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001188Locating and Using a Similar Recipe
1189~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1190
1191Before writing a recipe from scratch, it is often useful to discover
1192whether someone else has already written one that meets (or comes close
1193to meeting) your needs. The Yocto Project and OpenEmbedded communities
1194maintain many recipes that might be candidates for what you are doing.
Andrew Geisslerd1e89492021-02-12 15:35:20 -06001195You can find a good central index of these recipes in the
1196:oe_layerindex:`OpenEmbedded Layer Index <>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001197
1198Working from an existing recipe or a skeleton recipe is the best way to
1199get started. Here are some points on both methods:
1200
1201- *Locate and modify a recipe that is close to what you want to do:*
1202 This method works when you are familiar with the current recipe
1203 space. The method does not work so well for those new to the Yocto
1204 Project or writing recipes.
1205
1206 Some risks associated with this method are using a recipe that has
1207 areas totally unrelated to what you are trying to accomplish with
1208 your recipe, not recognizing areas of the recipe that you might have
1209 to add from scratch, and so forth. All these risks stem from
1210 unfamiliarity with the existing recipe space.
1211
1212- *Use and modify the following skeleton recipe:* If for some reason
1213 you do not want to use ``recipetool`` and you cannot find an existing
1214 recipe that is close to meeting your needs, you can use the following
1215 structure to provide the fundamental areas of a new recipe.
1216 ::
1217
1218 DESCRIPTION = ""
1219 HOMEPAGE = ""
1220 LICENSE = ""
1221 SECTION = ""
1222 DEPENDS = ""
1223 LIC_FILES_CHKSUM = ""
1224
1225 SRC_URI = ""
1226
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001227Storing and Naming the Recipe
1228-----------------------------
1229
1230Once you have your base recipe, you should put it in your own layer and
1231name it appropriately. Locating it correctly ensures that the
1232OpenEmbedded build system can find it when you use BitBake to process
1233the recipe.
1234
1235- *Storing Your Recipe:* The OpenEmbedded build system locates your
1236 recipe through the layer's ``conf/layer.conf`` file and the
1237 :term:`BBFILES` variable. This
1238 variable sets up a path from which the build system can locate
1239 recipes. Here is the typical use:
1240 ::
1241
1242 BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
1243 ${LAYERDIR}/recipes-*/*/*.bbappend"
1244
1245 Consequently, you need to be sure you locate your new recipe inside
1246 your layer such that it can be found.
1247
1248 You can find more information on how layers are structured in the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001249 ":ref:`dev-manual/common-tasks:understanding and creating layers`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001250
1251- *Naming Your Recipe:* When you name your recipe, you need to follow
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001252 this naming convention:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001253 ::
1254
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001255 basename_version.bb
1256
1257 Use lower-cased characters and do not include the reserved suffixes
1258 ``-native``, ``-cross``, ``-initial``, or ``-dev`` casually (i.e. do not use
1259 them as part of your recipe name unless the string applies). Here are some
1260 examples:
1261
1262 .. code-block:: none
1263
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001264 cups_1.7.0.bb
1265 gawk_4.0.2.bb
1266 irssi_0.8.16-rc1.bb
1267
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001268Running a Build on the Recipe
1269-----------------------------
1270
1271Creating a new recipe is usually an iterative process that requires
1272using BitBake to process the recipe multiple times in order to
1273progressively discover and add information to the recipe file.
1274
1275Assuming you have sourced the build environment setup script (i.e.
1276:ref:`structure-core-script`) and you are in
1277the :term:`Build Directory`, use
1278BitBake to process your recipe. All you need to provide is the
1279``basename`` of the recipe as described in the previous section:
1280::
1281
1282 $ bitbake basename
1283
1284During the build, the OpenEmbedded build system creates a temporary work
1285directory for each recipe
1286(``${``\ :term:`WORKDIR`\ ``}``)
1287where it keeps extracted source files, log files, intermediate
1288compilation and packaging files, and so forth.
1289
1290The path to the per-recipe temporary work directory depends on the
1291context in which it is being built. The quickest way to find this path
1292is to have BitBake return it by running the following:
1293::
1294
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001295 $ bitbake -e basename | grep ^WORKDIR=
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001296
1297As an example, assume a Source Directory
1298top-level folder named ``poky``, a default Build Directory at
1299``poky/build``, and a ``qemux86-poky-linux`` machine target system.
1300Furthermore, suppose your recipe is named ``foo_1.3.0.bb``. In this
1301case, the work directory the build system uses to build the package
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001302would be as follows:
1303::
1304
1305 poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
1306
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001307Inside this directory you can find sub-directories such as ``image``,
1308``packages-split``, and ``temp``. After the build, you can examine these
1309to determine how well the build went.
1310
1311.. note::
1312
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001313 You can find log files for each task in the recipe's ``temp``
1314 directory (e.g. ``poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0/temp``).
1315 Log files are named ``log.taskname`` (e.g. ``log.do_configure``,
1316 ``log.do_fetch``, and ``log.do_compile``).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001317
1318You can find more information about the build process in
Andrew Geissler09209ee2020-12-13 08:44:15 -06001319":doc:`/overview-manual/development-environment`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001320chapter of the Yocto Project Overview and Concepts Manual.
1321
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001322Fetching Code
1323-------------
1324
1325The first thing your recipe must do is specify how to fetch the source
1326files. Fetching is controlled mainly through the
1327:term:`SRC_URI` variable. Your recipe
1328must have a ``SRC_URI`` variable that points to where the source is
1329located. For a graphical representation of source locations, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001330":ref:`overview-manual/concepts:sources`" section in
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001331the Yocto Project Overview and Concepts Manual.
1332
1333The :ref:`ref-tasks-fetch` task uses
1334the prefix of each entry in the ``SRC_URI`` variable value to determine
Andrew Geissler09209ee2020-12-13 08:44:15 -06001335which :ref:`fetcher <bitbake:bitbake-user-manual/bitbake-user-manual-fetching:fetchers>` to use to get your
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001336source files. It is the ``SRC_URI`` variable that triggers the fetcher.
1337The :ref:`ref-tasks-patch` task uses
1338the variable after source is fetched to apply patches. The OpenEmbedded
1339build system uses
1340:term:`FILESOVERRIDES` for
1341scanning directory locations for local files in ``SRC_URI``.
1342
1343The ``SRC_URI`` variable in your recipe must define each unique location
1344for your source files. It is good practice to not hard-code version
1345numbers in a URL used in ``SRC_URI``. Rather than hard-code these
1346values, use ``${``\ :term:`PV`\ ``}``,
1347which causes the fetch process to use the version specified in the
1348recipe filename. Specifying the version in this manner means that
1349upgrading the recipe to a future version is as simple as renaming the
1350recipe to match the new version.
1351
1352Here is a simple example from the
1353``meta/recipes-devtools/strace/strace_5.5.bb`` recipe where the source
1354comes from a single tarball. Notice the use of the
1355:term:`PV` variable:
1356::
1357
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001358 SRC_URI = "https://strace.io/files/${PV}/strace-${PV}.tar.xz \
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001359
1360Files mentioned in ``SRC_URI`` whose names end in a typical archive
1361extension (e.g. ``.tar``, ``.tar.gz``, ``.tar.bz2``, ``.zip``, and so
1362forth), are automatically extracted during the
1363:ref:`ref-tasks-unpack` task. For
1364another example that specifies these types of files, see the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001365":ref:`dev-manual/common-tasks:autotooled package`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001366
1367Another way of specifying source is from an SCM. For Git repositories,
1368you must specify :term:`SRCREV` and
1369you should specify :term:`PV` to include
1370the revision with :term:`SRCPV`. Here
1371is an example from the recipe
1372``meta/recipes-kernel/blktrace/blktrace_git.bb``:
1373::
1374
1375 SRCREV = "d6918c8832793b4205ed3bfede78c2f915c23385"
1376
1377 PR = "r6"
1378 PV = "1.0.5+git${SRCPV}"
1379
1380 SRC_URI = "git://git.kernel.dk/blktrace.git \
1381 file://ldflags.patch"
1382
1383If your ``SRC_URI`` statement includes URLs pointing to individual files
1384fetched from a remote server other than a version control system,
1385BitBake attempts to verify the files against checksums defined in your
1386recipe to ensure they have not been tampered with or otherwise modified
1387since the recipe was written. Two checksums are used:
1388``SRC_URI[md5sum]`` and ``SRC_URI[sha256sum]``.
1389
1390If your ``SRC_URI`` variable points to more than a single URL (excluding
1391SCM URLs), you need to provide the ``md5`` and ``sha256`` checksums for
1392each URL. For these cases, you provide a name for each URL as part of
1393the ``SRC_URI`` and then reference that name in the subsequent checksum
1394statements. Here is an example combining lines from the files
1395``git.inc`` and ``git_2.24.1.bb``:
1396::
1397
1398 SRC_URI = "${KERNELORG_MIRROR}/software/scm/git/git-${PV}.tar.gz;name=tarball \
1399 ${KERNELORG_MIRROR}/software/scm/git/git-manpages-${PV}.tar.gz;name=manpages"
1400
1401 SRC_URI[tarball.md5sum] = "166bde96adbbc11c8843d4f8f4f9811b"
1402 SRC_URI[tarball.sha256sum] = "ad5334956301c86841eb1e5b1bb20884a6bad89a10a6762c958220c7cf64da02"
1403 SRC_URI[manpages.md5sum] = "31c2272a8979022497ba3d4202df145d"
1404 SRC_URI[manpages.sha256sum] = "9a7ae3a093bea39770eb96ca3e5b40bff7af0b9f6123f089d7821d0e5b8e1230"
1405
1406Proper values for ``md5`` and ``sha256`` checksums might be available
1407with other signatures on the download page for the upstream source (e.g.
1408``md5``, ``sha1``, ``sha256``, ``GPG``, and so forth). Because the
1409OpenEmbedded build system only deals with ``sha256sum`` and ``md5sum``,
1410you should verify all the signatures you find by hand.
1411
1412If no ``SRC_URI`` checksums are specified when you attempt to build the
1413recipe, or you provide an incorrect checksum, the build will produce an
1414error for each missing or incorrect checksum. As part of the error
1415message, the build system provides the checksum string corresponding to
1416the fetched file. Once you have the correct checksums, you can copy and
1417paste them into your recipe and then run the build again to continue.
1418
1419.. note::
1420
1421 As mentioned, if the upstream source provides signatures for
1422 verifying the downloaded source code, you should verify those
1423 manually before setting the checksum values in the recipe and
1424 continuing with the build.
1425
1426This final example is a bit more complicated and is from the
1427``meta/recipes-sato/rxvt-unicode/rxvt-unicode_9.20.bb`` recipe. The
1428example's ``SRC_URI`` statement identifies multiple files as the source
1429files for the recipe: a tarball, a patch file, a desktop file, and an
1430icon.
1431::
1432
1433 SRC_URI = "http://dist.schmorp.de/rxvt-unicode/Attic/rxvt-unicode-${PV}.tar.bz2 \
1434 file://xwc.patch \
1435 file://rxvt.desktop \
1436 file://rxvt.png"
1437
1438When you specify local files using the ``file://`` URI protocol, the
1439build system fetches files from the local machine. The path is relative
1440to the :term:`FILESPATH` variable
1441and searches specific directories in a certain order:
1442``${``\ :term:`BP`\ ``}``,
1443``${``\ :term:`BPN`\ ``}``, and
1444``files``. The directories are assumed to be subdirectories of the
1445directory in which the recipe or append file resides. For another
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001446example that specifies these types of files, see the
1447":ref:`dev-manual/common-tasks:single .c file package (hello world!)`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001448
1449The previous example also specifies a patch file. Patch files are files
1450whose names usually end in ``.patch`` or ``.diff`` but can end with
1451compressed suffixes such as ``diff.gz`` and ``patch.bz2``, for example.
1452The build system automatically applies patches as described in the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001453":ref:`dev-manual/common-tasks:patching code`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001454
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001455Unpacking Code
1456--------------
1457
1458During the build, the
1459:ref:`ref-tasks-unpack` task unpacks
1460the source with ``${``\ :term:`S`\ ``}``
1461pointing to where it is unpacked.
1462
1463If you are fetching your source files from an upstream source archived
1464tarball and the tarball's internal structure matches the common
1465convention of a top-level subdirectory named
1466``${``\ :term:`BPN`\ ``}-${``\ :term:`PV`\ ``}``,
1467then you do not need to set ``S``. However, if ``SRC_URI`` specifies to
1468fetch source from an archive that does not use this convention, or from
1469an SCM like Git or Subversion, your recipe needs to define ``S``.
1470
1471If processing your recipe using BitBake successfully unpacks the source
1472files, you need to be sure that the directory pointed to by ``${S}``
1473matches the structure of the source.
1474
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001475Patching Code
1476-------------
1477
1478Sometimes it is necessary to patch code after it has been fetched. Any
1479files mentioned in ``SRC_URI`` whose names end in ``.patch`` or
1480``.diff`` or compressed versions of these suffixes (e.g. ``diff.gz`` are
1481treated as patches. The
1482:ref:`ref-tasks-patch` task
1483automatically applies these patches.
1484
1485The build system should be able to apply patches with the "-p1" option
1486(i.e. one directory level in the path will be stripped off). If your
1487patch needs to have more directory levels stripped off, specify the
1488number of levels using the "striplevel" option in the ``SRC_URI`` entry
1489for the patch. Alternatively, if your patch needs to be applied in a
1490specific subdirectory that is not specified in the patch file, use the
1491"patchdir" option in the entry.
1492
1493As with all local files referenced in
1494:term:`SRC_URI` using ``file://``,
1495you should place patch files in a directory next to the recipe either
1496named the same as the base name of the recipe
1497(:term:`BP` and
1498:term:`BPN`) or "files".
1499
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001500Licensing
1501---------
1502
1503Your recipe needs to have both the
1504:term:`LICENSE` and
1505:term:`LIC_FILES_CHKSUM`
1506variables:
1507
1508- ``LICENSE``: This variable specifies the license for the software.
1509 If you do not know the license under which the software you are
1510 building is distributed, you should go to the source code and look
1511 for that information. Typical files containing this information
1512 include ``COPYING``, ``LICENSE``, and ``README`` files. You could
1513 also find the information near the top of a source file. For example,
1514 given a piece of software licensed under the GNU General Public
1515 License version 2, you would set ``LICENSE`` as follows:
1516 ::
1517
1518 LICENSE = "GPLv2"
1519
1520 The licenses you specify within ``LICENSE`` can have any name as long
1521 as you do not use spaces, since spaces are used as separators between
1522 license names. For standard licenses, use the names of the files in
1523 ``meta/files/common-licenses/`` or the ``SPDXLICENSEMAP`` flag names
1524 defined in ``meta/conf/licenses.conf``.
1525
1526- ``LIC_FILES_CHKSUM``: The OpenEmbedded build system uses this
1527 variable to make sure the license text has not changed. If it has,
1528 the build produces an error and it affords you the chance to figure
1529 it out and correct the problem.
1530
1531 You need to specify all applicable licensing files for the software.
1532 At the end of the configuration step, the build process will compare
1533 the checksums of the files to be sure the text has not changed. Any
1534 differences result in an error with the message containing the
1535 current checksum. For more explanation and examples of how to set the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001536 ``LIC_FILES_CHKSUM`` variable, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001537 ":ref:`dev-manual/common-tasks:tracking license changes`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001538
1539 To determine the correct checksum string, you can list the
1540 appropriate files in the ``LIC_FILES_CHKSUM`` variable with incorrect
1541 md5 strings, attempt to build the software, and then note the
1542 resulting error messages that will report the correct md5 strings.
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001543 See the ":ref:`dev-manual/common-tasks:fetching code`" section for
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001544 additional information.
1545
1546 Here is an example that assumes the software has a ``COPYING`` file:
1547 ::
1548
1549 LIC_FILES_CHKSUM = "file://COPYING;md5=xxx"
1550
1551 When you try to build the
1552 software, the build system will produce an error and give you the
1553 correct string that you can substitute into the recipe file for a
1554 subsequent build.
1555
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001556Dependencies
1557------------
1558
1559Most software packages have a short list of other packages that they
1560require, which are called dependencies. These dependencies fall into two
1561main categories: build-time dependencies, which are required when the
1562software is built; and runtime dependencies, which are required to be
1563installed on the target in order for the software to run.
1564
1565Within a recipe, you specify build-time dependencies using the
1566:term:`DEPENDS` variable. Although
1567nuances exist, items specified in ``DEPENDS`` should be names of other
1568recipes. It is important that you specify all build-time dependencies
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001569explicitly.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001570
1571Another consideration is that configure scripts might automatically
1572check for optional dependencies and enable corresponding functionality
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001573if those dependencies are found. If you wish to make a recipe that is
1574more generally useful (e.g. publish the recipe in a layer for others to
1575use), instead of hard-disabling the functionality, you can use the
1576:term:`PACKAGECONFIG` variable to allow functionality and the
1577corresponding dependencies to be enabled and disabled easily by other
1578users of the recipe.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001579
1580Similar to build-time dependencies, you specify runtime dependencies
1581through a variable -
1582:term:`RDEPENDS`, which is
1583package-specific. All variables that are package-specific need to have
1584the name of the package added to the end as an override. Since the main
1585package for a recipe has the same name as the recipe, and the recipe's
1586name can be found through the
1587``${``\ :term:`PN`\ ``}`` variable, then
1588you specify the dependencies for the main package by setting
1589``RDEPENDS_${PN}``. If the package were named ``${PN}-tools``, then you
1590would set ``RDEPENDS_${PN}-tools``, and so forth.
1591
1592Some runtime dependencies will be set automatically at packaging time.
1593These dependencies include any shared library dependencies (i.e. if a
1594package "example" contains "libexample" and another package "mypackage"
1595contains a binary that links to "libexample" then the OpenEmbedded build
1596system will automatically add a runtime dependency to "mypackage" on
1597"example"). See the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001598":ref:`overview-manual/concepts:automatically added runtime dependencies`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001599section in the Yocto Project Overview and Concepts Manual for further
1600details.
1601
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001602Configuring the Recipe
1603----------------------
1604
1605Most software provides some means of setting build-time configuration
1606options before compilation. Typically, setting these options is
1607accomplished by running a configure script with options, or by modifying
1608a build configuration file.
1609
1610.. note::
1611
1612 As of Yocto Project Release 1.7, some of the core recipes that
1613 package binary configuration scripts now disable the scripts due to
1614 the scripts previously requiring error-prone path substitution. The
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001615 OpenEmbedded build system uses ``pkg-config`` now, which is much more
1616 robust. You can find a list of the ``*-config`` scripts that are disabled
1617 in the ":ref:`migration-1.7-binary-configuration-scripts-disabled`" section
1618 in the Yocto Project Reference Manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001619
1620A major part of build-time configuration is about checking for
1621build-time dependencies and possibly enabling optional functionality as
1622a result. You need to specify any build-time dependencies for the
1623software you are building in your recipe's
1624:term:`DEPENDS` value, in terms of
1625other recipes that satisfy those dependencies. You can often find
1626build-time or runtime dependencies described in the software's
1627documentation.
1628
1629The following list provides configuration items of note based on how
1630your software is built:
1631
1632- *Autotools:* If your source files have a ``configure.ac`` file, then
1633 your software is built using Autotools. If this is the case, you just
1634 need to worry about modifying the configuration.
1635
1636 When using Autotools, your recipe needs to inherit the
1637 :ref:`autotools <ref-classes-autotools>` class
1638 and your recipe does not have to contain a
1639 :ref:`ref-tasks-configure` task.
1640 However, you might still want to make some adjustments. For example,
1641 you can set
1642 :term:`EXTRA_OECONF` or
1643 :term:`PACKAGECONFIG_CONFARGS`
1644 to pass any needed configure options that are specific to the recipe.
1645
1646- *CMake:* If your source files have a ``CMakeLists.txt`` file, then
1647 your software is built using CMake. If this is the case, you just
1648 need to worry about modifying the configuration.
1649
1650 When you use CMake, your recipe needs to inherit the
1651 :ref:`cmake <ref-classes-cmake>` class and your
1652 recipe does not have to contain a
1653 :ref:`ref-tasks-configure` task.
1654 You can make some adjustments by setting
1655 :term:`EXTRA_OECMAKE` to
1656 pass any needed configure options that are specific to the recipe.
1657
1658 .. note::
1659
1660 If you need to install one or more custom CMake toolchain files
1661 that are supplied by the application you are building, install the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001662 files to ``${D}${datadir}/cmake/Modules`` during ``do_install``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001663
1664- *Other:* If your source files do not have a ``configure.ac`` or
1665 ``CMakeLists.txt`` file, then your software is built using some
1666 method other than Autotools or CMake. If this is the case, you
1667 normally need to provide a
1668 :ref:`ref-tasks-configure` task
1669 in your recipe unless, of course, there is nothing to configure.
1670
1671 Even if your software is not being built by Autotools or CMake, you
1672 still might not need to deal with any configuration issues. You need
1673 to determine if configuration is even a required step. You might need
1674 to modify a Makefile or some configuration file used for the build to
1675 specify necessary build options. Or, perhaps you might need to run a
1676 provided, custom configure script with the appropriate options.
1677
1678 For the case involving a custom configure script, you would run
1679 ``./configure --help`` and look for the options you need to set.
1680
1681Once configuration succeeds, it is always good practice to look at the
1682``log.do_configure`` file to ensure that the appropriate options have
1683been enabled and no additional build-time dependencies need to be added
1684to ``DEPENDS``. For example, if the configure script reports that it
1685found something not mentioned in ``DEPENDS``, or that it did not find
1686something that it needed for some desired optional functionality, then
1687you would need to add those to ``DEPENDS``. Looking at the log might
1688also reveal items being checked for, enabled, or both that you do not
1689want, or items not being found that are in ``DEPENDS``, in which case
1690you would need to look at passing extra options to the configure script
1691as needed. For reference information on configure options specific to
1692the software you are building, you can consult the output of the
1693``./configure --help`` command within ``${S}`` or consult the software's
1694upstream documentation.
1695
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001696Using Headers to Interface with Devices
1697---------------------------------------
1698
1699If your recipe builds an application that needs to communicate with some
1700device or needs an API into a custom kernel, you will need to provide
1701appropriate header files. Under no circumstances should you ever modify
1702the existing
1703``meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc`` file.
1704These headers are used to build ``libc`` and must not be compromised
1705with custom or machine-specific header information. If you customize
1706``libc`` through modified headers all other applications that use
1707``libc`` thus become affected.
1708
1709.. note::
1710
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001711 Never copy and customize the ``libc`` header file (i.e.
1712 ``meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc``).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001713
1714The correct way to interface to a device or custom kernel is to use a
1715separate package that provides the additional headers for the driver or
1716other unique interfaces. When doing so, your application also becomes
1717responsible for creating a dependency on that specific provider.
1718
1719Consider the following:
1720
1721- Never modify ``linux-libc-headers.inc``. Consider that file to be
1722 part of the ``libc`` system, and not something you use to access the
1723 kernel directly. You should access ``libc`` through specific ``libc``
1724 calls.
1725
1726- Applications that must talk directly to devices should either provide
1727 necessary headers themselves, or establish a dependency on a special
1728 headers package that is specific to that driver.
1729
1730For example, suppose you want to modify an existing header that adds I/O
1731control or network support. If the modifications are used by a small
1732number programs, providing a unique version of a header is easy and has
1733little impact. When doing so, bear in mind the guidelines in the
1734previous list.
1735
1736.. note::
1737
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001738 If for some reason your changes need to modify the behavior of the ``libc``,
1739 and subsequently all other applications on the system, use a ``.bbappend``
1740 to modify the ``linux-kernel-headers.inc`` file. However, take care to not
1741 make the changes machine specific.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001742
1743Consider a case where your kernel is older and you need an older
1744``libc`` ABI. The headers installed by your recipe should still be a
1745standard mainline kernel, not your own custom one.
1746
1747When you use custom kernel headers you need to get them from
1748:term:`STAGING_KERNEL_DIR`,
1749which is the directory with kernel headers that are required to build
1750out-of-tree modules. Your recipe will also need the following:
1751::
1752
1753 do_configure[depends] += "virtual/kernel:do_shared_workdir"
1754
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001755Compilation
1756-----------
1757
1758During a build, the ``do_compile`` task happens after source is fetched,
1759unpacked, and configured. If the recipe passes through ``do_compile``
1760successfully, nothing needs to be done.
1761
1762However, if the compile step fails, you need to diagnose the failure.
1763Here are some common issues that cause failures.
1764
1765.. note::
1766
1767 For cases where improper paths are detected for configuration files
1768 or for when libraries/headers cannot be found, be sure you are using
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001769 the more robust ``pkg-config``. See the note in section
Andrew Geissler09209ee2020-12-13 08:44:15 -06001770 ":ref:`dev-manual/common-tasks:Configuring the Recipe`" for additional information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001771
1772- *Parallel build failures:* These failures manifest themselves as
1773 intermittent errors, or errors reporting that a file or directory
1774 that should be created by some other part of the build process could
1775 not be found. This type of failure can occur even if, upon
1776 inspection, the file or directory does exist after the build has
1777 failed, because that part of the build process happened in the wrong
1778 order.
1779
1780 To fix the problem, you need to either satisfy the missing dependency
1781 in the Makefile or whatever script produced the Makefile, or (as a
1782 workaround) set :term:`PARALLEL_MAKE` to an empty string:
1783 ::
1784
1785 PARALLEL_MAKE = ""
1786
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001787 For information on parallel Makefile issues, see the
1788 ":ref:`dev-manual/common-tasks:debugging parallel make races`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001789
1790- *Improper host path usage:* This failure applies to recipes building
1791 for the target or ``nativesdk`` only. The failure occurs when the
1792 compilation process uses improper headers, libraries, or other files
1793 from the host system when cross-compiling for the target.
1794
1795 To fix the problem, examine the ``log.do_compile`` file to identify
1796 the host paths being used (e.g. ``/usr/include``, ``/usr/lib``, and
1797 so forth) and then either add configure options, apply a patch, or do
1798 both.
1799
1800- *Failure to find required libraries/headers:* If a build-time
1801 dependency is missing because it has not been declared in
1802 :term:`DEPENDS`, or because the
1803 dependency exists but the path used by the build process to find the
1804 file is incorrect and the configure step did not detect it, the
1805 compilation process could fail. For either of these failures, the
1806 compilation process notes that files could not be found. In these
1807 cases, you need to go back and add additional options to the
1808 configure script as well as possibly add additional build-time
1809 dependencies to ``DEPENDS``.
1810
1811 Occasionally, it is necessary to apply a patch to the source to
1812 ensure the correct paths are used. If you need to specify paths to
1813 find files staged into the sysroot from other recipes, use the
1814 variables that the OpenEmbedded build system provides (e.g.
1815 ``STAGING_BINDIR``, ``STAGING_INCDIR``, ``STAGING_DATADIR``, and so
1816 forth).
1817
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001818Installing
1819----------
1820
1821During ``do_install``, the task copies the built files along with their
1822hierarchy to locations that would mirror their locations on the target
1823device. The installation process copies files from the
1824``${``\ :term:`S`\ ``}``,
1825``${``\ :term:`B`\ ``}``, and
1826``${``\ :term:`WORKDIR`\ ``}``
1827directories to the ``${``\ :term:`D`\ ``}``
1828directory to create the structure as it should appear on the target
1829system.
1830
1831How your software is built affects what you must do to be sure your
1832software is installed correctly. The following list describes what you
1833must do for installation depending on the type of build system used by
1834the software being built:
1835
1836- *Autotools and CMake:* If the software your recipe is building uses
1837 Autotools or CMake, the OpenEmbedded build system understands how to
1838 install the software. Consequently, you do not have to have a
1839 ``do_install`` task as part of your recipe. You just need to make
1840 sure the install portion of the build completes with no issues.
1841 However, if you wish to install additional files not already being
1842 installed by ``make install``, you should do this using a
1843 ``do_install_append`` function using the install command as described
1844 in the "Manual" bulleted item later in this list.
1845
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001846- *Other (using* ``make install``\ *)*: You need to define a ``do_install``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001847 function in your recipe. The function should call
1848 ``oe_runmake install`` and will likely need to pass in the
1849 destination directory as well. How you pass that path is dependent on
1850 how the ``Makefile`` being run is written (e.g. ``DESTDIR=${D}``,
1851 ``PREFIX=${D}``, ``INSTALLROOT=${D}``, and so forth).
1852
1853 For an example recipe using ``make install``, see the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001854 ":ref:`dev-manual/common-tasks:makefile-based package`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001855
1856- *Manual:* You need to define a ``do_install`` function in your
1857 recipe. The function must first use ``install -d`` to create the
1858 directories under
1859 ``${``\ :term:`D`\ ``}``. Once the
1860 directories exist, your function can use ``install`` to manually
1861 install the built software into the directories.
1862
1863 You can find more information on ``install`` at
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001864 https://www.gnu.org/software/coreutils/manual/html_node/install-invocation.html.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001865
1866For the scenarios that do not use Autotools or CMake, you need to track
1867the installation and diagnose and fix any issues until everything
1868installs correctly. You need to look in the default location of
1869``${D}``, which is ``${WORKDIR}/image``, to be sure your files have been
1870installed correctly.
1871
1872.. note::
1873
1874 - During the installation process, you might need to modify some of
1875 the installed files to suit the target layout. For example, you
1876 might need to replace hard-coded paths in an initscript with
1877 values of variables provided by the build system, such as
1878 replacing ``/usr/bin/`` with ``${bindir}``. If you do perform such
1879 modifications during ``do_install``, be sure to modify the
1880 destination file after copying rather than before copying.
1881 Modifying after copying ensures that the build system can
1882 re-execute ``do_install`` if needed.
1883
1884 - ``oe_runmake install``, which can be run directly or can be run
1885 indirectly by the
1886 :ref:`autotools <ref-classes-autotools>` and
1887 :ref:`cmake <ref-classes-cmake>` classes,
1888 runs ``make install`` in parallel. Sometimes, a Makefile can have
1889 missing dependencies between targets that can result in race
1890 conditions. If you experience intermittent failures during
1891 ``do_install``, you might be able to work around them by disabling
1892 parallel Makefile installs by adding the following to the recipe:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001893 ::
1894
1895 PARALLEL_MAKEINST = ""
1896
1897 See :term:`PARALLEL_MAKEINST` for additional information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001898
1899 - If you need to install one or more custom CMake toolchain files
1900 that are supplied by the application you are building, install the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001901 files to ``${D}${datadir}/cmake/Modules`` during
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001902 :ref:`ref-tasks-install`.
1903
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001904Enabling System Services
1905------------------------
1906
1907If you want to install a service, which is a process that usually starts
1908on boot and runs in the background, then you must include some
1909additional definitions in your recipe.
1910
1911If you are adding services and the service initialization script or the
1912service file itself is not installed, you must provide for that
1913installation in your recipe using a ``do_install_append`` function. If
1914your recipe already has a ``do_install`` function, update the function
1915near its end rather than adding an additional ``do_install_append``
1916function.
1917
1918When you create the installation for your services, you need to
1919accomplish what is normally done by ``make install``. In other words,
1920make sure your installation arranges the output similar to how it is
1921arranged on the target system.
1922
1923The OpenEmbedded build system provides support for starting services two
1924different ways:
1925
1926- *SysVinit:* SysVinit is a system and service manager that manages the
1927 init system used to control the very basic functions of your system.
1928 The init program is the first program started by the Linux kernel
1929 when the system boots. Init then controls the startup, running and
1930 shutdown of all other programs.
1931
1932 To enable a service using SysVinit, your recipe needs to inherit the
1933 :ref:`update-rc.d <ref-classes-update-rc.d>`
1934 class. The class helps facilitate safely installing the package on
1935 the target.
1936
1937 You will need to set the
1938 :term:`INITSCRIPT_PACKAGES`,
1939 :term:`INITSCRIPT_NAME`,
1940 and
1941 :term:`INITSCRIPT_PARAMS`
1942 variables within your recipe.
1943
1944- *systemd:* System Management Daemon (systemd) was designed to replace
1945 SysVinit and to provide enhanced management of services. For more
1946 information on systemd, see the systemd homepage at
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001947 https://freedesktop.org/wiki/Software/systemd/.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001948
1949 To enable a service using systemd, your recipe needs to inherit the
1950 :ref:`systemd <ref-classes-systemd>` class. See
1951 the ``systemd.bbclass`` file located in your :term:`Source Directory`
1952 section for
1953 more information.
1954
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001955Packaging
1956---------
1957
1958Successful packaging is a combination of automated processes performed
1959by the OpenEmbedded build system and some specific steps you need to
1960take. The following list describes the process:
1961
1962- *Splitting Files*: The ``do_package`` task splits the files produced
1963 by the recipe into logical components. Even software that produces a
1964 single binary might still have debug symbols, documentation, and
1965 other logical components that should be split out. The ``do_package``
1966 task ensures that files are split up and packaged correctly.
1967
1968- *Running QA Checks*: The
1969 :ref:`insane <ref-classes-insane>` class adds a
1970 step to the package generation process so that output quality
1971 assurance checks are generated by the OpenEmbedded build system. This
1972 step performs a range of checks to be sure the build's output is free
1973 of common problems that show up during runtime. For information on
1974 these checks, see the
1975 :ref:`insane <ref-classes-insane>` class and
Andrew Geissler09209ee2020-12-13 08:44:15 -06001976 the ":ref:`ref-manual/qa-checks:qa error and warning messages`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001977 chapter in the Yocto Project Reference Manual.
1978
1979- *Hand-Checking Your Packages*: After you build your software, you
1980 need to be sure your packages are correct. Examine the
1981 ``${``\ :term:`WORKDIR`\ ``}/packages-split``
1982 directory and make sure files are where you expect them to be. If you
1983 discover problems, you can set
1984 :term:`PACKAGES`,
1985 :term:`FILES`,
1986 ``do_install(_append)``, and so forth as needed.
1987
1988- *Splitting an Application into Multiple Packages*: If you need to
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001989 split an application into several packages, see the
1990 ":ref:`dev-manual/common-tasks:splitting an application into multiple packages`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001991 section for an example.
1992
1993- *Installing a Post-Installation Script*: For an example showing how
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001994 to install a post-installation script, see the
1995 ":ref:`dev-manual/common-tasks:post-installation scripts`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001996
1997- *Marking Package Architecture*: Depending on what your recipe is
1998 building and how it is configured, it might be important to mark the
1999 packages produced as being specific to a particular machine, or to
2000 mark them as not being specific to a particular machine or
2001 architecture at all.
2002
2003 By default, packages apply to any machine with the same architecture
2004 as the target machine. When a recipe produces packages that are
2005 machine-specific (e.g. the
2006 :term:`MACHINE` value is passed
2007 into the configure script or a patch is applied only for a particular
2008 machine), you should mark them as such by adding the following to the
2009 recipe:
2010 ::
2011
2012 PACKAGE_ARCH = "${MACHINE_ARCH}"
2013
2014 On the other hand, if the recipe produces packages that do not
2015 contain anything specific to the target machine or architecture at
2016 all (e.g. recipes that simply package script files or configuration
2017 files), you should use the
2018 :ref:`allarch <ref-classes-allarch>` class to
2019 do this for you by adding this to your recipe:
2020 ::
2021
2022 inherit allarch
2023
2024 Ensuring that the package architecture is correct is not critical
2025 while you are doing the first few builds of your recipe. However, it
2026 is important in order to ensure that your recipe rebuilds (or does
2027 not rebuild) appropriately in response to changes in configuration,
2028 and to ensure that you get the appropriate packages installed on the
2029 target machine, particularly if you run separate builds for more than
2030 one target machine.
2031
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002032Sharing Files Between Recipes
2033-----------------------------
2034
2035Recipes often need to use files provided by other recipes on the build
2036host. For example, an application linking to a common library needs
2037access to the library itself and its associated headers. The way this
2038access is accomplished is by populating a sysroot with files. Each
2039recipe has two sysroots in its work directory, one for target files
2040(``recipe-sysroot``) and one for files that are native to the build host
2041(``recipe-sysroot-native``).
2042
2043.. note::
2044
2045 You could find the term "staging" used within the Yocto project
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002046 regarding files populating sysroots (e.g. the :term:`STAGING_DIR`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002047 variable).
2048
2049Recipes should never populate the sysroot directly (i.e. write files
2050into sysroot). Instead, files should be installed into standard
2051locations during the
2052:ref:`ref-tasks-install` task within
2053the ``${``\ :term:`D`\ ``}`` directory. The
2054reason for this limitation is that almost all files that populate the
2055sysroot are cataloged in manifests in order to ensure the files can be
2056removed later when a recipe is either modified or removed. Thus, the
2057sysroot is able to remain free from stale files.
2058
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05002059A subset of the files installed by the :ref:`ref-tasks-install` task are
2060used by the :ref:`ref-tasks-populate_sysroot` task as defined by the the
2061:term:`SYSROOT_DIRS` variable to automatically populate the sysroot. It
2062is possible to modify the list of directories that populate the sysroot.
2063The following example shows how you could add the ``/opt`` directory to
2064the list of directories within a recipe:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002065::
2066
2067 SYSROOT_DIRS += "/opt"
2068
Andrew Geisslerd1e89492021-02-12 15:35:20 -06002069.. note::
2070
2071 The `/sysroot-only` is to be used by recipes that generate artifacts
2072 that are not included in the target filesystem, allowing them to share
2073 these artifacts without needing to use the ``DEPLOY_DIR``.
2074
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05002075For a more complete description of the :ref:`ref-tasks-populate_sysroot`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002076task and its associated functions, see the
2077:ref:`staging <ref-classes-staging>` class.
2078
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002079Using Virtual Providers
2080-----------------------
2081
2082Prior to a build, if you know that several different recipes provide the
2083same functionality, you can use a virtual provider (i.e. ``virtual/*``)
2084as a placeholder for the actual provider. The actual provider is
2085determined at build-time.
2086
2087A common scenario where a virtual provider is used would be for the
2088kernel recipe. Suppose you have three kernel recipes whose
2089:term:`PN` values map to ``kernel-big``,
2090``kernel-mid``, and ``kernel-small``. Furthermore, each of these recipes
2091in some way uses a :term:`PROVIDES`
2092statement that essentially identifies itself as being able to provide
2093``virtual/kernel``. Here is one way through the
2094:ref:`kernel <ref-classes-kernel>` class:
2095::
2096
2097 PROVIDES += "${@ "virtual/kernel" if (d.getVar("KERNEL_PACKAGE_NAME") == "kernel") else "" }"
2098
2099Any recipe that inherits the ``kernel`` class is
2100going to utilize a ``PROVIDES`` statement that identifies that recipe as
2101being able to provide the ``virtual/kernel`` item.
2102
2103Now comes the time to actually build an image and you need a kernel
2104recipe, but which one? You can configure your build to call out the
Andrew Geissler09209ee2020-12-13 08:44:15 -06002105kernel recipe you want by using the :term:`PREFERRED_PROVIDER` variable. As
2106an example, consider the :yocto_git:`x86-base.inc
2107</poky/tree/meta/conf/machine/include/x86-base.inc>` include file, which is a
2108machine (i.e. :term:`MACHINE`) configuration file. This include file is the
2109reason all x86-based machines use the ``linux-yocto`` kernel. Here are the
2110relevant lines from the include file:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002111::
2112
2113 PREFERRED_PROVIDER_virtual/kernel ??= "linux-yocto"
2114 PREFERRED_VERSION_linux-yocto ??= "4.15%"
2115
2116When you use a virtual provider, you do not have to "hard code" a recipe
2117name as a build dependency. You can use the
2118:term:`DEPENDS` variable to state the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002119build is dependent on ``virtual/kernel`` for example:
2120::
2121
2122 DEPENDS = "virtual/kernel"
2123
2124During the build, the OpenEmbedded build system picks
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002125the correct recipe needed for the ``virtual/kernel`` dependency based on
2126the ``PREFERRED_PROVIDER`` variable. If you want to use the small kernel
2127mentioned at the beginning of this section, configure your build as
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002128follows:
2129::
2130
2131 PREFERRED_PROVIDER_virtual/kernel ??= "kernel-small"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002132
2133.. note::
2134
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002135 Any recipe that ``PROVIDES`` a ``virtual/*`` item that is ultimately not
2136 selected through ``PREFERRED_PROVIDER`` does not get built. Preventing these
2137 recipes from building is usually the desired behavior since this mechanism's
2138 purpose is to select between mutually exclusive alternative providers.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002139
2140The following lists specific examples of virtual providers:
2141
2142- ``virtual/kernel``: Provides the name of the kernel recipe to use
2143 when building a kernel image.
2144
2145- ``virtual/bootloader``: Provides the name of the bootloader to use
2146 when building an image.
2147
2148- ``virtual/libgbm``: Provides ``gbm.pc``.
2149
2150- ``virtual/egl``: Provides ``egl.pc`` and possibly ``wayland-egl.pc``.
2151
2152- ``virtual/libgl``: Provides ``gl.pc`` (i.e. libGL).
2153
2154- ``virtual/libgles1``: Provides ``glesv1_cm.pc`` (i.e. libGLESv1_CM).
2155
2156- ``virtual/libgles2``: Provides ``glesv2.pc`` (i.e. libGLESv2).
2157
2158.. note::
2159
2160 Virtual providers only apply to build time dependencies specified with
2161 :term:`PROVIDES` and :term:`DEPENDS`. They do not apply to runtime
2162 dependencies specified with :term:`RPROVIDES` and :term:`RDEPENDS`.
2163
2164Properly Versioning Pre-Release Recipes
2165---------------------------------------
2166
2167Sometimes the name of a recipe can lead to versioning problems when the
2168recipe is upgraded to a final release. For example, consider the
2169``irssi_0.8.16-rc1.bb`` recipe file in the list of example recipes in
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05002170the ":ref:`dev-manual/common-tasks:storing and naming the recipe`" section.
2171This recipe is at a release candidate stage (i.e. "rc1"). When the recipe is
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002172released, the recipe filename becomes ``irssi_0.8.16.bb``. The version
2173change from ``0.8.16-rc1`` to ``0.8.16`` is seen as a decrease by the
2174build system and package managers, so the resulting packages will not
2175correctly trigger an upgrade.
2176
2177In order to ensure the versions compare properly, the recommended
2178convention is to set :term:`PV` within the
2179recipe to "previous_version+current_version". You can use an additional
2180variable so that you can use the current version elsewhere. Here is an
2181example:
2182::
2183
2184 REALPV = "0.8.16-rc1"
2185 PV = "0.8.15+${REALPV}"
2186
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002187Post-Installation Scripts
2188-------------------------
2189
2190Post-installation scripts run immediately after installing a package on
2191the target or during image creation when a package is included in an
2192image. To add a post-installation script to a package, add a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002193``pkg_postinst_``\ `PACKAGENAME`\ ``()`` function to the recipe file
2194(``.bb``) and replace `PACKAGENAME` with the name of the package you want
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002195to attach to the ``postinst`` script. To apply the post-installation
2196script to the main package for the recipe, which is usually what is
2197required, specify
2198``${``\ :term:`PN`\ ``}`` in place of
2199PACKAGENAME.
2200
2201A post-installation function has the following structure:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002202::
2203
2204 pkg_postinst_PACKAGENAME() {
2205 # Commands to carry out
2206 }
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002207
2208The script defined in the post-installation function is called when the
2209root filesystem is created. If the script succeeds, the package is
2210marked as installed.
2211
2212.. note::
2213
2214 Any RPM post-installation script that runs on the target should
2215 return a 0 exit code. RPM does not allow non-zero exit codes for
2216 these scripts, and the RPM package manager will cause the package to
2217 fail installation on the target.
2218
2219Sometimes it is necessary for the execution of a post-installation
2220script to be delayed until the first boot. For example, the script might
2221need to be executed on the device itself. To delay script execution
2222until boot time, you must explicitly mark post installs to defer to the
2223target. You can use ``pkg_postinst_ontarget()`` or call
2224``postinst_intercept delay_to_first_boot`` from ``pkg_postinst()``. Any
2225failure of a ``pkg_postinst()`` script (including exit 1) triggers an
2226error during the
2227:ref:`ref-tasks-rootfs` task.
2228
2229If you have recipes that use ``pkg_postinst`` function and they require
2230the use of non-standard native tools that have dependencies during
2231rootfs construction, you need to use the
2232:term:`PACKAGE_WRITE_DEPS`
2233variable in your recipe to list these tools. If you do not use this
2234variable, the tools might be missing and execution of the
2235post-installation script is deferred until first boot. Deferring the
2236script to first boot is undesirable and for read-only rootfs impossible.
2237
2238.. note::
2239
2240 Equivalent support for pre-install, pre-uninstall, and post-uninstall
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002241 scripts exist by way of ``pkg_preinst``, ``pkg_prerm``, and ``pkg_postrm``,
2242 respectively. These scrips work in exactly the same way as does
2243 ``pkg_postinst`` with the exception that they run at different times. Also,
2244 because of when they run, they are not applicable to being run at image
2245 creation time like ``pkg_postinst``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002246
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002247Testing
2248-------
2249
2250The final step for completing your recipe is to be sure that the
2251software you built runs correctly. To accomplish runtime testing, add
2252the build's output packages to your image and test them on the target.
2253
2254For information on how to customize your image by adding specific
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05002255packages, see ":ref:`dev-manual/common-tasks:customizing images`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002256
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002257Examples
2258--------
2259
2260To help summarize how to write a recipe, this section provides some
2261examples given various scenarios:
2262
2263- Recipes that use local files
2264
2265- Using an Autotooled package
2266
2267- Using a Makefile-based package
2268
2269- Splitting an application into multiple packages
2270
2271- Adding binaries to an image
2272
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002273Single .c File Package (Hello World!)
2274~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2275
2276Building an application from a single file that is stored locally (e.g.
2277under ``files``) requires a recipe that has the file listed in the
2278``SRC_URI`` variable. Additionally, you need to manually write the
2279``do_compile`` and ``do_install`` tasks. The ``S`` variable defines the
2280directory containing the source code, which is set to
2281:term:`WORKDIR` in this case - the
2282directory BitBake uses for the build.
2283::
2284
2285 SUMMARY = "Simple helloworld application"
2286 SECTION = "examples"
2287 LICENSE = "MIT"
2288 LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
2289
2290 SRC_URI = "file://helloworld.c"
2291
2292 S = "${WORKDIR}"
2293
2294 do_compile() {
Andrew Geisslerd1e89492021-02-12 15:35:20 -06002295 ${CC} ${LDFLAGS} helloworld.c -o helloworld
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002296 }
2297
2298 do_install() {
2299 install -d ${D}${bindir}
2300 install -m 0755 helloworld ${D}${bindir}
2301 }
2302
2303By default, the ``helloworld``, ``helloworld-dbg``, and
2304``helloworld-dev`` packages are built. For information on how to
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05002305customize the packaging process, see the
2306":ref:`dev-manual/common-tasks:splitting an application into multiple packages`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002307section.
2308
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002309Autotooled Package
2310~~~~~~~~~~~~~~~~~~
2311
2312Applications that use Autotools such as ``autoconf`` and ``automake``
2313require a recipe that has a source archive listed in ``SRC_URI`` and
2314also inherit the
2315:ref:`autotools <ref-classes-autotools>` class,
2316which contains the definitions of all the steps needed to build an
2317Autotool-based application. The result of the build is automatically
2318packaged. And, if the application uses NLS for localization, packages
2319with local information are generated (one package per language).
2320Following is one example: (``hello_2.3.bb``)
2321::
2322
2323 SUMMARY = "GNU Helloworld application"
2324 SECTION = "examples"
2325 LICENSE = "GPLv2+"
2326 LIC_FILES_CHKSUM = "file://COPYING;md5=751419260aa954499f7abaabaa882bbe"
2327
2328 SRC_URI = "${GNU_MIRROR}/hello/hello-${PV}.tar.gz"
2329
2330 inherit autotools gettext
2331
2332The variable ``LIC_FILES_CHKSUM`` is used to track source license
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002333changes as described in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06002334":ref:`dev-manual/common-tasks:tracking license changes`" section in
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002335the Yocto Project Overview and Concepts Manual. You can quickly create
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002336Autotool-based recipes in a manner similar to the previous example.
2337
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002338Makefile-Based Package
2339~~~~~~~~~~~~~~~~~~~~~~
2340
2341Applications that use GNU ``make`` also require a recipe that has the
2342source archive listed in ``SRC_URI``. You do not need to add a
2343``do_compile`` step since by default BitBake starts the ``make`` command
2344to compile the application. If you need additional ``make`` options, you
2345should store them in the
2346:term:`EXTRA_OEMAKE` or
2347:term:`PACKAGECONFIG_CONFARGS`
2348variables. BitBake passes these options into the GNU ``make``
2349invocation. Note that a ``do_install`` task is still required.
2350Otherwise, BitBake runs an empty ``do_install`` task by default.
2351
2352Some applications might require extra parameters to be passed to the
2353compiler. For example, the application might need an additional header
2354path. You can accomplish this by adding to the ``CFLAGS`` variable. The
2355following example shows this:
2356::
2357
2358 CFLAGS_prepend = "-I ${S}/include "
2359
2360In the following example, ``mtd-utils`` is a makefile-based package:
2361::
2362
2363 SUMMARY = "Tools for managing memory technology devices"
2364 SECTION = "base"
2365 DEPENDS = "zlib lzo e2fsprogs util-linux"
2366 HOMEPAGE = "http://www.linux-mtd.infradead.org/"
2367 LICENSE = "GPLv2+"
2368 LIC_FILES_CHKSUM = "file://COPYING;md5=0636e73ff0215e8d672dc4c32c317bb3 \
2369 file://include/common.h;beginline=1;endline=17;md5=ba05b07912a44ea2bf81ce409380049c"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002370
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002371 # Use the latest version at 26 Oct, 2013
2372 SRCREV = "9f107132a6a073cce37434ca9cda6917dd8d866b"
2373 SRC_URI = "git://git.infradead.org/mtd-utils.git \
2374 file://add-exclusion-to-mkfs-jffs2-git-2.patch \
2375 "
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002376
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002377 PV = "1.5.1+git${SRCPV}"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002378
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002379 S = "${WORKDIR}/git"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002380
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002381 EXTRA_OEMAKE = "'CC=${CC}' 'RANLIB=${RANLIB}' 'AR=${AR}' 'CFLAGS=${CFLAGS} -I${S}/include -DWITHOUT_XATTR' 'BUILDDIR=${S}'"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002382
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002383 do_install () {
2384 oe_runmake install DESTDIR=${D} SBINDIR=${sbindir} MANDIR=${mandir} INCLUDEDIR=${includedir}
2385 }
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002386
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002387 PACKAGES =+ "mtd-utils-jffs2 mtd-utils-ubifs mtd-utils-misc"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002388
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002389 FILES_mtd-utils-jffs2 = "${sbindir}/mkfs.jffs2 ${sbindir}/jffs2dump ${sbindir}/jffs2reader ${sbindir}/sumtool"
2390 FILES_mtd-utils-ubifs = "${sbindir}/mkfs.ubifs ${sbindir}/ubi*"
2391 FILES_mtd-utils-misc = "${sbindir}/nftl* ${sbindir}/ftl* ${sbindir}/rfd* ${sbindir}/doc* ${sbindir}/serve_image ${sbindir}/recv_image"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002392
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002393 PARALLEL_MAKE = ""
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002394
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002395 BBCLASSEXTEND = "native"
2396
2397Splitting an Application into Multiple Packages
2398~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2399
2400You can use the variables ``PACKAGES`` and ``FILES`` to split an
2401application into multiple packages.
2402
2403Following is an example that uses the ``libxpm`` recipe. By default,
2404this recipe generates a single package that contains the library along
2405with a few binaries. You can modify the recipe to split the binaries
2406into separate packages:
2407::
2408
2409 require xorg-lib-common.inc
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002410
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002411 SUMMARY = "Xpm: X Pixmap extension library"
2412 LICENSE = "BSD"
2413 LIC_FILES_CHKSUM = "file://COPYING;md5=51f4270b012ecd4ab1a164f5f4ed6cf7"
2414 DEPENDS += "libxext libsm libxt"
2415 PE = "1"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002416
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002417 XORG_PN = "libXpm"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002418
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002419 PACKAGES =+ "sxpm cxpm"
2420 FILES_cxpm = "${bindir}/cxpm"
2421 FILES_sxpm = "${bindir}/sxpm"
2422
2423In the previous example, we want to ship the ``sxpm`` and ``cxpm``
2424binaries in separate packages. Since ``bindir`` would be packaged into
2425the main ``PN`` package by default, we prepend the ``PACKAGES`` variable
2426so additional package names are added to the start of list. This results
2427in the extra ``FILES_*`` variables then containing information that
2428define which files and directories go into which packages. Files
2429included by earlier packages are skipped by latter packages. Thus, the
2430main ``PN`` package does not include the above listed files.
2431
2432Packaging Externally Produced Binaries
2433~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2434
2435Sometimes, you need to add pre-compiled binaries to an image. For
2436example, suppose that binaries for proprietary code exist, which are
2437created by a particular division of a company. Your part of the company
2438needs to use those binaries as part of an image that you are building
2439using the OpenEmbedded build system. Since you only have the binaries
2440and not the source code, you cannot use a typical recipe that expects to
2441fetch the source specified in
2442:term:`SRC_URI` and then compile it.
2443
2444One method is to package the binaries and then install them as part of
2445the image. Generally, it is not a good idea to package binaries since,
2446among other things, it can hinder the ability to reproduce builds and
2447could lead to compatibility problems with ABI in the future. However,
2448sometimes you have no choice.
2449
2450The easiest solution is to create a recipe that uses the
2451:ref:`bin_package <ref-classes-bin-package>` class
2452and to be sure that you are using default locations for build artifacts.
2453In most cases, the ``bin_package`` class handles "skipping" the
2454configure and compile steps as well as sets things up to grab packages
2455from the appropriate area. In particular, this class sets ``noexec`` on
2456both the :ref:`ref-tasks-configure`
2457and :ref:`ref-tasks-compile` tasks,
2458sets ``FILES_${PN}`` to "/" so that it picks up all files, and sets up a
2459:ref:`ref-tasks-install` task, which
2460effectively copies all files from ``${S}`` to ``${D}``. The
2461``bin_package`` class works well when the files extracted into ``${S}``
2462are already laid out in the way they should be laid out on the target.
2463For more information on these variables, see the
2464:term:`FILES`,
2465:term:`PN`,
2466:term:`S`, and
2467:term:`D` variables in the Yocto Project
2468Reference Manual's variable glossary.
2469
2470.. note::
2471
2472 - Using :term:`DEPENDS` is a good
2473 idea even for components distributed in binary form, and is often
2474 necessary for shared libraries. For a shared library, listing the
2475 library dependencies in ``DEPENDS`` makes sure that the libraries
2476 are available in the staging sysroot when other recipes link
2477 against the library, which might be necessary for successful
2478 linking.
2479
2480 - Using ``DEPENDS`` also allows runtime dependencies between
2481 packages to be added automatically. See the
Andrew Geissler09209ee2020-12-13 08:44:15 -06002482 ":ref:`overview-manual/concepts:automatically added runtime dependencies`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002483 section in the Yocto Project Overview and Concepts Manual for more
2484 information.
2485
2486If you cannot use the ``bin_package`` class, you need to be sure you are
2487doing the following:
2488
2489- Create a recipe where the
2490 :ref:`ref-tasks-configure` and
2491 :ref:`ref-tasks-compile` tasks do
2492 nothing: It is usually sufficient to just not define these tasks in
2493 the recipe, because the default implementations do nothing unless a
2494 Makefile is found in
2495 ``${``\ :term:`S`\ ``}``.
2496
2497 If ``${S}`` might contain a Makefile, or if you inherit some class
2498 that replaces ``do_configure`` and ``do_compile`` with custom
2499 versions, then you can use the
2500 ``[``\ :ref:`noexec <bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ``]``
2501 flag to turn the tasks into no-ops, as follows:
2502 ::
2503
2504 do_configure[noexec] = "1"
2505 do_compile[noexec] = "1"
2506
2507 Unlike
2508 :ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:deleting a task`,
2509 using the flag preserves the dependency chain from the
2510 :ref:`ref-tasks-fetch`,
2511 :ref:`ref-tasks-unpack`, and
2512 :ref:`ref-tasks-patch` tasks to the
2513 :ref:`ref-tasks-install` task.
2514
2515- Make sure your ``do_install`` task installs the binaries
2516 appropriately.
2517
2518- Ensure that you set up :term:`FILES`
2519 (usually
2520 ``FILES_${``\ :term:`PN`\ ``}``) to
2521 point to the files you have installed, which of course depends on
2522 where you have installed them and whether those files are in
2523 different locations than the defaults.
2524
Andrew Geissler6ce62a22020-11-30 19:58:47 -06002525.. note::
2526
2527 If image prelinking is enabled (e.g. "image-prelink" is in :term:`USER_CLASSES`
2528 which it is by default), prelink will change the binaries in the generated images
2529 and this often catches people out. Remove that class to ensure binaries are
2530 preserved exactly if that is necessary.
2531
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002532Following Recipe Style Guidelines
2533---------------------------------
2534
2535When writing recipes, it is good to conform to existing style
Andrew Geisslerd1e89492021-02-12 15:35:20 -06002536guidelines. The :oe_wiki:`OpenEmbedded Styleguide </Styleguide>` wiki page
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002537provides rough guidelines for preferred recipe style.
2538
2539It is common for existing recipes to deviate a bit from this style.
2540However, aiming for at least a consistent style is a good idea. Some
2541practices, such as omitting spaces around ``=`` operators in assignments
2542or ordering recipe components in an erratic way, are widely seen as poor
2543style.
2544
2545Recipe Syntax
2546-------------
2547
2548Understanding recipe file syntax is important for writing recipes. The
2549following list overviews the basic items that make up a BitBake recipe
2550file. For more complete BitBake syntax descriptions, see the
2551":doc:`bitbake-user-manual/bitbake-user-manual-metadata`"
2552chapter of the BitBake User Manual.
2553
2554- *Variable Assignments and Manipulations:* Variable assignments allow
2555 a value to be assigned to a variable. The assignment can be static
2556 text or might include the contents of other variables. In addition to
2557 the assignment, appending and prepending operations are also
2558 supported.
2559
2560 The following example shows some of the ways you can use variables in
2561 recipes:
2562 ::
2563
2564 S = "${WORKDIR}/postfix-${PV}"
2565 CFLAGS += "-DNO_ASM"
2566 SRC_URI_append = " file://fixup.patch"
2567
2568- *Functions:* Functions provide a series of actions to be performed.
2569 You usually use functions to override the default implementation of a
2570 task function or to complement a default function (i.e. append or
2571 prepend to an existing function). Standard functions use ``sh`` shell
2572 syntax, although access to OpenEmbedded variables and internal
2573 methods are also available.
2574
2575 The following is an example function from the ``sed`` recipe:
2576 ::
2577
2578 do_install () {
2579 autotools_do_install
2580 install -d ${D}${base_bindir}
2581 mv ${D}${bindir}/sed ${D}${base_bindir}/sed
2582 rmdir ${D}${bindir}/
2583 }
2584
2585 It is
2586 also possible to implement new functions that are called between
2587 existing tasks as long as the new functions are not replacing or
2588 complementing the default functions. You can implement functions in
2589 Python instead of shell. Both of these options are not seen in the
2590 majority of recipes.
2591
2592- *Keywords:* BitBake recipes use only a few keywords. You use keywords
2593 to include common functions (``inherit``), load parts of a recipe
2594 from other files (``include`` and ``require``) and export variables
2595 to the environment (``export``).
2596
2597 The following example shows the use of some of these keywords:
2598 ::
2599
2600 export POSTCONF = "${STAGING_BINDIR}/postconf"
2601 inherit autoconf
2602 require otherfile.inc
2603
2604- *Comments (#):* Any lines that begin with the hash character (``#``)
2605 are treated as comment lines and are ignored:
2606 ::
2607
2608 # This is a comment
2609
2610This next list summarizes the most important and most commonly used
2611parts of the recipe syntax. For more information on these parts of the
2612syntax, you can reference the
2613:doc:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata` chapter
2614in the BitBake User Manual.
2615
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002616- *Line Continuation (\\):* Use the backward slash (``\``) character to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002617 split a statement over multiple lines. Place the slash character at
2618 the end of the line that is to be continued on the next line:
2619 ::
2620
2621 VAR = "A really long \
2622 line"
2623
2624 .. note::
2625
2626 You cannot have any characters including spaces or tabs after the
2627 slash character.
2628
2629- *Using Variables (${VARNAME}):* Use the ``${VARNAME}`` syntax to
2630 access the contents of a variable:
2631 ::
2632
2633 SRC_URI = "${SOURCEFORGE_MIRROR}/libpng/zlib-${PV}.tar.gz"
2634
2635 .. note::
2636
2637 It is important to understand that the value of a variable
2638 expressed in this form does not get substituted automatically. The
2639 expansion of these expressions happens on-demand later (e.g.
2640 usually when a function that makes reference to the variable
2641 executes). This behavior ensures that the values are most
2642 appropriate for the context in which they are finally used. On the
2643 rare occasion that you do need the variable expression to be
2644 expanded immediately, you can use the
2645 :=
2646 operator instead of
2647 =
2648 when you make the assignment, but this is not generally needed.
2649
2650- *Quote All Assignments ("value"):* Use double quotes around values in
2651 all variable assignments (e.g. ``"value"``). Following is an example:
2652 ::
2653
2654 VAR1 = "${OTHERVAR}"
2655 VAR2 = "The version is ${PV}"
2656
2657- *Conditional Assignment (?=):* Conditional assignment is used to
2658 assign a value to a variable, but only when the variable is currently
2659 unset. Use the question mark followed by the equal sign (``?=``) to
2660 make a "soft" assignment used for conditional assignment. Typically,
2661 "soft" assignments are used in the ``local.conf`` file for variables
2662 that are allowed to come through from the external environment.
2663
2664 Here is an example where ``VAR1`` is set to "New value" if it is
2665 currently empty. However, if ``VAR1`` has already been set, it
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002666 remains unchanged:
2667 ::
2668
2669 VAR1 ?= "New value"
2670
2671 In this next example, ``VAR1`` is left with the value "Original value":
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002672 ::
2673
2674 VAR1 = "Original value"
2675 VAR1 ?= "New value"
2676
2677- *Appending (+=):* Use the plus character followed by the equals sign
2678 (``+=``) to append values to existing variables.
2679
2680 .. note::
2681
2682 This operator adds a space between the existing content of the
2683 variable and the new content.
2684
2685 Here is an example:
2686 ::
2687
2688 SRC_URI += "file://fix-makefile.patch"
2689
2690- *Prepending (=+):* Use the equals sign followed by the plus character
2691 (``=+``) to prepend values to existing variables.
2692
2693 .. note::
2694
2695 This operator adds a space between the new content and the
2696 existing content of the variable.
2697
2698 Here is an example:
2699 ::
2700
2701 VAR =+ "Starts"
2702
2703- *Appending (_append):* Use the ``_append`` operator to append values
2704 to existing variables. This operator does not add any additional
2705 space. Also, the operator is applied after all the ``+=``, and ``=+``
2706 operators have been applied and after all ``=`` assignments have
2707 occurred.
2708
2709 The following example shows the space being explicitly added to the
2710 start to ensure the appended value is not merged with the existing
2711 value:
2712 ::
2713
2714 SRC_URI_append = " file://fix-makefile.patch"
2715
2716 You can also use
2717 the ``_append`` operator with overrides, which results in the actions
2718 only being performed for the specified target or machine:
2719 ::
2720
2721 SRC_URI_append_sh4 = " file://fix-makefile.patch"
2722
2723- *Prepending (_prepend):* Use the ``_prepend`` operator to prepend
2724 values to existing variables. This operator does not add any
2725 additional space. Also, the operator is applied after all the ``+=``,
2726 and ``=+`` operators have been applied and after all ``=``
2727 assignments have occurred.
2728
2729 The following example shows the space being explicitly added to the
2730 end to ensure the prepended value is not merged with the existing
2731 value:
2732 ::
2733
2734 CFLAGS_prepend = "-I${S}/myincludes "
2735
2736 You can also use the
2737 ``_prepend`` operator with overrides, which results in the actions
2738 only being performed for the specified target or machine:
2739 ::
2740
2741 CFLAGS_prepend_sh4 = "-I${S}/myincludes "
2742
2743- *Overrides:* You can use overrides to set a value conditionally,
2744 typically based on how the recipe is being built. For example, to set
2745 the :term:`KBRANCH` variable's
2746 value to "standard/base" for any target
2747 :term:`MACHINE`, except for
2748 qemuarm where it should be set to "standard/arm-versatile-926ejs",
2749 you would do the following:
2750 ::
2751
2752 KBRANCH = "standard/base"
2753 KBRANCH_qemuarm = "standard/arm-versatile-926ejs"
2754
2755 Overrides are also used to separate
2756 alternate values of a variable in other situations. For example, when
2757 setting variables such as
2758 :term:`FILES` and
2759 :term:`RDEPENDS` that are
2760 specific to individual packages produced by a recipe, you should
2761 always use an override that specifies the name of the package.
2762
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002763- *Indentation:* Use spaces for indentation rather than tabs. For
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002764 shell functions, both currently work. However, it is a policy
2765 decision of the Yocto Project to use tabs in shell functions. Realize
2766 that some layers have a policy to use spaces for all indentation.
2767
2768- *Using Python for Complex Operations:* For more advanced processing,
2769 it is possible to use Python code during variable assignments (e.g.
2770 search and replacement on a variable).
2771
2772 You indicate Python code using the ``${@python_code}`` syntax for the
2773 variable assignment:
2774 ::
2775
2776 SRC_URI = "ftp://ftp.info-zip.org/pub/infozip/src/zip${@d.getVar('PV',1).replace('.', '')}.tgz
2777
2778- *Shell Function Syntax:* Write shell functions as if you were writing
2779 a shell script when you describe a list of actions to take. You
2780 should ensure that your script works with a generic ``sh`` and that
2781 it does not require any ``bash`` or other shell-specific
2782 functionality. The same considerations apply to various system
2783 utilities (e.g. ``sed``, ``grep``, ``awk``, and so forth) that you
2784 might wish to use. If in doubt, you should check with multiple
2785 implementations - including those from BusyBox.
2786
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002787Adding a New Machine
2788====================
2789
2790Adding a new machine to the Yocto Project is a straightforward process.
2791This section describes how to add machines that are similar to those
2792that the Yocto Project already supports.
2793
2794.. note::
2795
2796 Although well within the capabilities of the Yocto Project, adding a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002797 totally new architecture might require changes to ``gcc``/``glibc``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002798 and to the site information, which is beyond the scope of this
2799 manual.
2800
2801For a complete example that shows how to add a new machine, see the
2802":ref:`bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script`"
2803section in the Yocto Project Board Support Package (BSP) Developer's
2804Guide.
2805
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002806Adding the Machine Configuration File
2807-------------------------------------
2808
2809To add a new machine, you need to add a new machine configuration file
2810to the layer's ``conf/machine`` directory. This configuration file
2811provides details about the device you are adding.
2812
2813The OpenEmbedded build system uses the root name of the machine
2814configuration file to reference the new machine. For example, given a
2815machine configuration file named ``crownbay.conf``, the build system
2816recognizes the machine as "crownbay".
2817
2818The most important variables you must set in your machine configuration
2819file or include from a lower-level configuration file are as follows:
2820
2821- ``TARGET_ARCH`` (e.g. "arm")
2822
2823- ``PREFERRED_PROVIDER_virtual/kernel``
2824
2825- ``MACHINE_FEATURES`` (e.g. "apm screen wifi")
2826
2827You might also need these variables:
2828
2829- ``SERIAL_CONSOLES`` (e.g. "115200;ttyS0 115200;ttyS1")
2830
2831- ``KERNEL_IMAGETYPE`` (e.g. "zImage")
2832
2833- ``IMAGE_FSTYPES`` (e.g. "tar.gz jffs2")
2834
2835You can find full details on these variables in the reference section.
2836You can leverage existing machine ``.conf`` files from
2837``meta-yocto-bsp/conf/machine/``.
2838
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002839Adding a Kernel for the Machine
2840-------------------------------
2841
2842The OpenEmbedded build system needs to be able to build a kernel for the
2843machine. You need to either create a new kernel recipe for this machine,
2844or extend an existing kernel recipe. You can find several kernel recipe
2845examples in the Source Directory at ``meta/recipes-kernel/linux`` that
2846you can use as references.
2847
2848If you are creating a new kernel recipe, normal recipe-writing rules
2849apply for setting up a ``SRC_URI``. Thus, you need to specify any
2850necessary patches and set ``S`` to point at the source code. You need to
2851create a ``do_configure`` task that configures the unpacked kernel with
2852a ``defconfig`` file. You can do this by using a ``make defconfig``
2853command or, more commonly, by copying in a suitable ``defconfig`` file
2854and then running ``make oldconfig``. By making use of ``inherit kernel``
2855and potentially some of the ``linux-*.inc`` files, most other
2856functionality is centralized and the defaults of the class normally work
2857well.
2858
2859If you are extending an existing kernel recipe, it is usually a matter
2860of adding a suitable ``defconfig`` file. The file needs to be added into
2861a location similar to ``defconfig`` files used for other machines in a
2862given kernel recipe. A possible way to do this is by listing the file in
2863the ``SRC_URI`` and adding the machine to the expression in
2864``COMPATIBLE_MACHINE``:
2865::
2866
2867 COMPATIBLE_MACHINE = '(qemux86|qemumips)'
2868
2869For more information on ``defconfig`` files, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06002870":ref:`kernel-dev/common:changing the configuration`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002871section in the Yocto Project Linux Kernel Development Manual.
2872
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002873Adding a Formfactor Configuration File
2874--------------------------------------
2875
2876A formfactor configuration file provides information about the target
2877hardware for which the image is being built and information that the
2878build system cannot obtain from other sources such as the kernel. Some
2879examples of information contained in a formfactor configuration file
2880include framebuffer orientation, whether or not the system has a
2881keyboard, the positioning of the keyboard in relation to the screen, and
2882the screen resolution.
2883
2884The build system uses reasonable defaults in most cases. However, if
2885customization is necessary, you need to create a ``machconfig`` file in
2886the ``meta/recipes-bsp/formfactor/files`` directory. This directory
2887contains directories for specific machines such as ``qemuarm`` and
2888``qemux86``. For information about the settings available and the
2889defaults, see the ``meta/recipes-bsp/formfactor/files/config`` file
2890found in the same area.
2891
2892Following is an example for "qemuarm" machine:
2893::
2894
2895 HAVE_TOUCHSCREEN=1
2896 HAVE_KEYBOARD=1
2897 DISPLAY_CAN_ROTATE=0
2898 DISPLAY_ORIENTATION=0
2899 #DISPLAY_WIDTH_PIXELS=640
2900 #DISPLAY_HEIGHT_PIXELS=480
2901 #DISPLAY_BPP=16
2902 DISPLAY_DPI=150
2903 DISPLAY_SUBPIXEL_ORDER=vrgb
2904
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002905Upgrading Recipes
2906=================
2907
2908Over time, upstream developers publish new versions for software built
2909by layer recipes. It is recommended to keep recipes up-to-date with
2910upstream version releases.
2911
2912While several methods exist that allow you upgrade a recipe, you might
2913consider checking on the upgrade status of a recipe first. You can do so
2914using the ``devtool check-upgrade-status`` command. See the
2915":ref:`devtool-checking-on-the-upgrade-status-of-a-recipe`"
2916section in the Yocto Project Reference Manual for more information.
2917
2918The remainder of this section describes three ways you can upgrade a
2919recipe. You can use the Automated Upgrade Helper (AUH) to set up
2920automatic version upgrades. Alternatively, you can use
2921``devtool upgrade`` to set up semi-automatic version upgrades. Finally,
2922you can manually upgrade a recipe by editing the recipe itself.
2923
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002924Using the Auto Upgrade Helper (AUH)
2925-----------------------------------
2926
2927The AUH utility works in conjunction with the OpenEmbedded build system
2928in order to automatically generate upgrades for recipes based on new
2929versions being published upstream. Use AUH when you want to create a
2930service that performs the upgrades automatically and optionally sends
2931you an email with the results.
2932
2933AUH allows you to update several recipes with a single use. You can also
2934optionally perform build and integration tests using images with the
2935results saved to your hard drive and emails of results optionally sent
2936to recipe maintainers. Finally, AUH creates Git commits with appropriate
2937commit messages in the layer's tree for the changes made to recipes.
2938
2939.. note::
2940
2941 Conditions do exist when you should not use AUH to upgrade recipes
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002942 and you should instead use either ``devtool upgrade`` or upgrade your
2943 recipes manually:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002944
2945 - When AUH cannot complete the upgrade sequence. This situation
2946 usually results because custom patches carried by the recipe
2947 cannot be automatically rebased to the new version. In this case,
2948 ``devtool upgrade`` allows you to manually resolve conflicts.
2949
2950 - When for any reason you want fuller control over the upgrade
2951 process. For example, when you want special arrangements for
2952 testing.
2953
2954The following steps describe how to set up the AUH utility:
2955
29561. *Be Sure the Development Host is Set Up:* You need to be sure that
2957 your development host is set up to use the Yocto Project. For
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002958 information on how to set up your host, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06002959 ":ref:`dev-manual/start:Preparing the Build Host`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002960
29612. *Make Sure Git is Configured:* The AUH utility requires Git to be
2962 configured because AUH uses Git to save upgrades. Thus, you must have
2963 Git user and email configured. The following command shows your
2964 configurations:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002965 ::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002966
2967 $ git config --list
2968
2969 If you do not have the user and
2970 email configured, you can use the following commands to do so:
2971 ::
2972
2973 $ git config --global user.name some_name
2974 $ git config --global user.email username@domain.com
2975
29763. *Clone the AUH Repository:* To use AUH, you must clone the repository
2977 onto your development host. The following command uses Git to create
2978 a local copy of the repository on your system:
2979 ::
2980
2981 $ git clone git://git.yoctoproject.org/auto-upgrade-helper
2982 Cloning into 'auto-upgrade-helper'... remote: Counting objects: 768, done.
2983 remote: Compressing objects: 100% (300/300), done.
2984 remote: Total 768 (delta 499), reused 703 (delta 434)
2985 Receiving objects: 100% (768/768), 191.47 KiB | 98.00 KiB/s, done.
2986 Resolving deltas: 100% (499/499), done.
2987 Checking connectivity... done.
2988
2989 AUH is not part of the :term:`OpenEmbedded-Core (OE-Core)` or
2990 :term:`Poky` repositories.
2991
29924. *Create a Dedicated Build Directory:* Run the
2993 :ref:`structure-core-script`
2994 script to create a fresh build directory that you use exclusively for
2995 running the AUH utility:
2996 ::
2997
Andrew Geissler95ac1b82021-03-31 14:34:31 -05002998 $ cd poky
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002999 $ source oe-init-build-env your_AUH_build_directory
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003000
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003001 Re-using an existing build directory and its configurations is not
3002 recommended as existing settings could cause AUH to fail or behave
3003 undesirably.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003004
30055. *Make Configurations in Your Local Configuration File:* Several
3006 settings need to exist in the ``local.conf`` file in the build
3007 directory you just created for AUH. Make these following
3008 configurations:
3009
3010 - If you want to enable :ref:`Build
Andrew Geissler09209ee2020-12-13 08:44:15 -06003011 History <dev-manual/common-tasks:maintaining build output quality>`,
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003012 which is optional, you need the following lines in the
3013 ``conf/local.conf`` file:
3014 ::
3015
3016 INHERIT =+ "buildhistory"
3017 BUILDHISTORY_COMMIT = "1"
3018
3019 With this configuration and a successful
3020 upgrade, a build history "diff" file appears in the
3021 ``upgrade-helper/work/recipe/buildhistory-diff.txt`` file found in
3022 your build directory.
3023
3024 - If you want to enable testing through the
3025 :ref:`testimage <ref-classes-testimage*>`
3026 class, which is optional, you need to have the following set in
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003027 your ``conf/local.conf`` file:
3028 ::
3029
3030 INHERIT += "testimage"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003031
3032 .. note::
3033
3034 If your distro does not enable by default ptest, which Poky
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003035 does, you need the following in your ``local.conf`` file:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003036 ::
3037
3038 DISTRO_FEATURES_append = " ptest"
3039
3040
30416. *Optionally Start a vncserver:* If you are running in a server
3042 without an X11 session, you need to start a vncserver:
3043 ::
3044
3045 $ vncserver :1
3046 $ export DISPLAY=:1
3047
30487. *Create and Edit an AUH Configuration File:* You need to have the
3049 ``upgrade-helper/upgrade-helper.conf`` configuration file in your
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003050 build directory. You can find a sample configuration file in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003051 :yocto_git:`AUH source repository </auto-upgrade-helper/tree/>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003052
3053 Read through the sample file and make configurations as needed. For
3054 example, if you enabled build history in your ``local.conf`` as
3055 described earlier, you must enable it in ``upgrade-helper.conf``.
3056
3057 Also, if you are using the default ``maintainers.inc`` file supplied
3058 with Poky and located in ``meta-yocto`` and you do not set a
3059 "maintainers_whitelist" or "global_maintainer_override" in the
3060 ``upgrade-helper.conf`` configuration, and you specify "-e all" on
3061 the AUH command-line, the utility automatically sends out emails to
3062 all the default maintainers. Please avoid this.
3063
3064This next set of examples describes how to use the AUH:
3065
3066- *Upgrading a Specific Recipe:* To upgrade a specific recipe, use the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003067 following form:
3068 ::
3069
3070 $ upgrade-helper.py recipe_name
3071
3072 For example, this command upgrades the ``xmodmap`` recipe:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003073 ::
3074
3075 $ upgrade-helper.py xmodmap
3076
3077- *Upgrading a Specific Recipe to a Particular Version:* To upgrade a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003078 specific recipe to a particular version, use the following form:
3079 ::
3080
3081 $ upgrade-helper.py recipe_name -t version
3082
3083 For example, this command upgrades the ``xmodmap`` recipe to version 1.2.3:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003084 ::
3085
3086 $ upgrade-helper.py xmodmap -t 1.2.3
3087
3088- *Upgrading all Recipes to the Latest Versions and Suppressing Email
3089 Notifications:* To upgrade all recipes to their most recent versions
3090 and suppress the email notifications, use the following command:
3091 ::
3092
3093 $ upgrade-helper.py all
3094
3095- *Upgrading all Recipes to the Latest Versions and Send Email
3096 Notifications:* To upgrade all recipes to their most recent versions
3097 and send email messages to maintainers for each attempted recipe as
3098 well as a status email, use the following command:
3099 ::
3100
3101 $ upgrade-helper.py -e all
3102
3103Once you have run the AUH utility, you can find the results in the AUH
3104build directory:
3105::
3106
3107 ${BUILDDIR}/upgrade-helper/timestamp
3108
3109The AUH utility
3110also creates recipe update commits from successful upgrade attempts in
3111the layer tree.
3112
3113You can easily set up to run the AUH utility on a regular basis by using
3114a cron job. See the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003115:yocto_git:`weeklyjob.sh </auto-upgrade-helper/tree/weeklyjob.sh>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003116file distributed with the utility for an example.
3117
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003118Using ``devtool upgrade``
3119-------------------------
3120
3121As mentioned earlier, an alternative method for upgrading recipes to
3122newer versions is to use
Andrew Geissler09209ee2020-12-13 08:44:15 -06003123:doc:`devtool upgrade </ref-manual/devtool-reference>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003124You can read about ``devtool upgrade`` in general in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003125":ref:`sdk-manual/extensible:use \`\`devtool upgrade\`\` to create a version of the recipe that supports a newer version of the software`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003126section in the Yocto Project Application Development and the Extensible
3127Software Development Kit (eSDK) Manual.
3128
3129To see all the command-line options available with ``devtool upgrade``,
3130use the following help command:
3131::
3132
3133 $ devtool upgrade -h
3134
3135If you want to find out what version a recipe is currently at upstream
3136without any attempt to upgrade your local version of the recipe, you can
3137use the following command:
3138::
3139
3140 $ devtool latest-version recipe_name
3141
3142As mentioned in the previous section describing AUH, ``devtool upgrade``
3143works in a less-automated manner than AUH. Specifically,
3144``devtool upgrade`` only works on a single recipe that you name on the
3145command line, cannot perform build and integration testing using images,
3146and does not automatically generate commits for changes in the source
3147tree. Despite all these "limitations", ``devtool upgrade`` updates the
3148recipe file to the new upstream version and attempts to rebase custom
3149patches contained by the recipe as needed.
3150
3151.. note::
3152
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003153 AUH uses much of ``devtool upgrade`` behind the scenes making AUH somewhat
3154 of a "wrapper" application for ``devtool upgrade``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003155
3156A typical scenario involves having used Git to clone an upstream
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003157repository that you use during build operations. Because you have built the
3158recipe in the past, the layer is likely added to your
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003159configuration already. If for some reason, the layer is not added, you
3160could add it easily using the
3161":ref:`bitbake-layers <bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script>`"
3162script. For example, suppose you use the ``nano.bb`` recipe from the
3163``meta-oe`` layer in the ``meta-openembedded`` repository. For this
3164example, assume that the layer has been cloned into following area:
3165::
3166
3167 /home/scottrif/meta-openembedded
3168
3169The following command from your
3170:term:`Build Directory` adds the layer to
3171your build configuration (i.e. ``${BUILDDIR}/conf/bblayers.conf``):
3172::
3173
3174 $ bitbake-layers add-layer /home/scottrif/meta-openembedded/meta-oe
3175 NOTE: Starting bitbake server...
3176 Parsing recipes: 100% |##########################################| Time: 0:00:55
3177 Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
3178 Removing 12 recipes from the x86_64 sysroot: 100% |##############| Time: 0:00:00
3179 Removing 1 recipes from the x86_64_i586 sysroot: 100% |##########| Time: 0:00:00
3180 Removing 5 recipes from the i586 sysroot: 100% |#################| Time: 0:00:00
3181 Removing 5 recipes from the qemux86 sysroot: 100% |##############| Time: 0:00:00
3182
3183For this example, assume that the ``nano.bb`` recipe that
3184is upstream has a 2.9.3 version number. However, the version in the
3185local repository is 2.7.4. The following command from your build
3186directory automatically upgrades the recipe for you:
3187
3188.. note::
3189
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003190 Using the ``-V`` option is not necessary. Omitting the version number causes
3191 ``devtool upgrade`` to upgrade the recipe to the most recent version.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003192
3193::
3194
3195 $ devtool upgrade nano -V 2.9.3
3196 NOTE: Starting bitbake server...
3197 NOTE: Creating workspace layer in /home/scottrif/poky/build/workspace
3198 Parsing recipes: 100% |##########################################| Time: 0:00:46
3199 Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
3200 NOTE: Extracting current version source...
3201 NOTE: Resolving any missing task queue dependencies
3202 .
3203 .
3204 .
3205 NOTE: Executing SetScene Tasks
3206 NOTE: Executing RunQueue Tasks
3207 NOTE: Tasks Summary: Attempted 74 tasks of which 72 didn't need to be rerun and all succeeded.
3208 Adding changed files: 100% |#####################################| Time: 0:00:00
3209 NOTE: Upgraded source extracted to /home/scottrif/poky/build/workspace/sources/nano
3210 NOTE: New recipe is /home/scottrif/poky/build/workspace/recipes/nano/nano_2.9.3.bb
3211
3212Continuing with this example, you can use ``devtool build`` to build the
3213newly upgraded recipe:
3214::
3215
3216 $ devtool build nano
3217 NOTE: Starting bitbake server...
3218 Loading cache: 100% |################################################################################################| Time: 0:00:01
3219 Loaded 2040 entries from dependency cache.
3220 Parsing recipes: 100% |##############################################################################################| Time: 0:00:00
3221 Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
3222 NOTE: Resolving any missing task queue dependencies
3223 .
3224 .
3225 .
3226 NOTE: Executing SetScene Tasks
3227 NOTE: Executing RunQueue Tasks
3228 NOTE: nano: compiling from external source tree /home/scottrif/poky/build/workspace/sources/nano
3229 NOTE: Tasks Summary: Attempted 520 tasks of which 304 didn't need to be rerun and all succeeded.
3230
3231Within the ``devtool upgrade`` workflow, opportunity
3232exists to deploy and test your rebuilt software. For this example,
3233however, running ``devtool finish`` cleans up the workspace once the
3234source in your workspace is clean. This usually means using Git to stage
3235and submit commits for the changes generated by the upgrade process.
3236
3237Once the tree is clean, you can clean things up in this example with the
3238following command from the ``${BUILDDIR}/workspace/sources/nano``
3239directory:
3240::
3241
3242 $ devtool finish nano meta-oe
3243 NOTE: Starting bitbake server...
3244 Loading cache: 100% |################################################################################################| Time: 0:00:00
3245 Loaded 2040 entries from dependency cache.
3246 Parsing recipes: 100% |##############################################################################################| Time: 0:00:01
3247 Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
3248 NOTE: Adding new patch 0001-nano.bb-Stuff-I-changed-when-upgrading-nano.bb.patch
3249 NOTE: Updating recipe nano_2.9.3.bb
3250 NOTE: Removing file /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano/nano_2.7.4.bb
3251 NOTE: Moving recipe file to /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano
3252 NOTE: Leaving source tree /home/scottrif/poky/build/workspace/sources/nano as-is; if you no longer need it then please delete it manually
3253
3254
3255Using the ``devtool finish`` command cleans up the workspace and creates a patch
3256file based on your commits. The tool puts all patch files back into the
3257source directory in a sub-directory named ``nano`` in this case.
3258
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003259Manually Upgrading a Recipe
3260---------------------------
3261
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003262If for some reason you choose not to upgrade recipes using
Andrew Geissler09209ee2020-12-13 08:44:15 -06003263:ref:`dev-manual/common-tasks:Using the Auto Upgrade Helper (AUH)` or
3264by :ref:`dev-manual/common-tasks:Using \`\`devtool upgrade\`\``,
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003265you can manually edit the recipe files to upgrade the versions.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003266
3267.. note::
3268
3269 Manually updating multiple recipes scales poorly and involves many
3270 steps. The recommendation to upgrade recipe versions is through AUH
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003271 or ``devtool upgrade``, both of which automate some steps and provide
3272 guidance for others needed for the manual process.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003273
3274To manually upgrade recipe versions, follow these general steps:
3275
32761. *Change the Version:* Rename the recipe such that the version (i.e.
3277 the :term:`PV` part of the recipe name)
3278 changes appropriately. If the version is not part of the recipe name,
3279 change the value as it is set for ``PV`` within the recipe itself.
3280
Andrew Geissler4c19ea12020-10-27 13:52:24 -050032812. *Update* ``SRCREV`` *if Needed*: If the source code your recipe builds
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003282 is fetched from Git or some other version control system, update
3283 :term:`SRCREV` to point to the
3284 commit hash that matches the new version.
3285
32863. *Build the Software:* Try to build the recipe using BitBake. Typical
3287 build failures include the following:
3288
3289 - License statements were updated for the new version. For this
3290 case, you need to review any changes to the license and update the
3291 values of :term:`LICENSE` and
3292 :term:`LIC_FILES_CHKSUM`
3293 as needed.
3294
3295 .. note::
3296
3297 License changes are often inconsequential. For example, the
3298 license text's copyright year might have changed.
3299
3300 - Custom patches carried by the older version of the recipe might
3301 fail to apply to the new version. For these cases, you need to
3302 review the failures. Patches might not be necessary for the new
3303 version of the software if the upgraded version has fixed those
3304 issues. If a patch is necessary and failing, you need to rebase it
3305 into the new version.
3306
33074. *Optionally Attempt to Build for Several Architectures:* Once you
3308 successfully build the new software for a given architecture, you
3309 could test the build for other architectures by changing the
3310 :term:`MACHINE` variable and
3311 rebuilding the software. This optional step is especially important
3312 if the recipe is to be released publicly.
3313
33145. *Check the Upstream Change Log or Release Notes:* Checking both these
3315 reveals if new features exist that could break
3316 backwards-compatibility. If so, you need to take steps to mitigate or
3317 eliminate that situation.
3318
33196. *Optionally Create a Bootable Image and Test:* If you want, you can
3320 test the new software by booting it onto actual hardware.
3321
33227. *Create a Commit with the Change in the Layer Repository:* After all
3323 builds work and any testing is successful, you can create commits for
3324 any changes in the layer holding your upgraded recipe.
3325
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003326Finding Temporary Source Code
3327=============================
3328
3329You might find it helpful during development to modify the temporary
3330source code used by recipes to build packages. For example, suppose you
3331are developing a patch and you need to experiment a bit to figure out
3332your solution. After you have initially built the package, you can
3333iteratively tweak the source code, which is located in the
3334:term:`Build Directory`, and then you can
3335force a re-compile and quickly test your altered code. Once you settle
3336on a solution, you can then preserve your changes in the form of
3337patches.
3338
3339During a build, the unpacked temporary source code used by recipes to
3340build packages is available in the Build Directory as defined by the
3341:term:`S` variable. Below is the default
3342value for the ``S`` variable as defined in the
3343``meta/conf/bitbake.conf`` configuration file in the
3344:term:`Source Directory`:
3345::
3346
3347 S = "${WORKDIR}/${BP}"
3348
3349You should be aware that many recipes override the
3350``S`` variable. For example, recipes that fetch their source from Git
3351usually set ``S`` to ``${WORKDIR}/git``.
3352
3353.. note::
3354
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003355 The :term:`BP` represents the base recipe name, which consists of the name
3356 and version:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003357 ::
3358
3359 BP = "${BPN}-${PV}"
3360
3361
3362The path to the work directory for the recipe
3363(:term:`WORKDIR`) is defined as
3364follows:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003365::
3366
3367 ${TMPDIR}/work/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR}
3368
3369The actual directory depends on several things:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003370
3371- :term:`TMPDIR`: The top-level build
3372 output directory.
3373
3374- :term:`MULTIMACH_TARGET_SYS`:
3375 The target system identifier.
3376
3377- :term:`PN`: The recipe name.
3378
3379- :term:`EXTENDPE`: The epoch - (if
3380 :term:`PE` is not specified, which is
3381 usually the case for most recipes, then ``EXTENDPE`` is blank).
3382
3383- :term:`PV`: The recipe version.
3384
3385- :term:`PR`: The recipe revision.
3386
3387As an example, assume a Source Directory top-level folder named
3388``poky``, a default Build Directory at ``poky/build``, and a
3389``qemux86-poky-linux`` machine target system. Furthermore, suppose your
3390recipe is named ``foo_1.3.0.bb``. In this case, the work directory the
3391build system uses to build the package would be as follows:
3392::
3393
3394 poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
3395
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003396Using Quilt in Your Workflow
3397============================
3398
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003399`Quilt <https://savannah.nongnu.org/projects/quilt>`__ is a powerful tool
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003400that allows you to capture source code changes without having a clean
3401source tree. This section outlines the typical workflow you can use to
3402modify source code, test changes, and then preserve the changes in the
3403form of a patch all using Quilt.
3404
3405.. note::
3406
3407 With regard to preserving changes to source files, if you clean a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003408 recipe or have ``rm_work`` enabled, the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003409 :ref:`devtool workflow <sdk-manual/extensible:using \`\`devtool\`\` in your sdk workflow>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003410 as described in the Yocto Project Application Development and the
3411 Extensible Software Development Kit (eSDK) manual is a safer
3412 development flow than the flow that uses Quilt.
3413
3414Follow these general steps:
3415
34161. *Find the Source Code:* Temporary source code used by the
3417 OpenEmbedded build system is kept in the
3418 :term:`Build Directory`. See the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05003419 ":ref:`dev-manual/common-tasks:finding temporary source code`" section to
3420 learn how to locate the directory that has the temporary source code for a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003421 particular package.
3422
34232. *Change Your Working Directory:* You need to be in the directory that
3424 has the temporary source code. That directory is defined by the
3425 :term:`S` variable.
3426
34273. *Create a New Patch:* Before modifying source code, you need to
3428 create a new patch. To create a new patch file, use ``quilt new`` as
3429 below:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003430 ::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003431
3432 $ quilt new my_changes.patch
3433
34344. *Notify Quilt and Add Files:* After creating the patch, you need to
3435 notify Quilt about the files you plan to edit. You notify Quilt by
3436 adding the files to the patch you just created:
3437 ::
3438
3439 $ quilt add file1.c file2.c file3.c
3440
34415. *Edit the Files:* Make your changes in the source code to the files
3442 you added to the patch.
3443
34446. *Test Your Changes:* Once you have modified the source code, the
3445 easiest way to test your changes is by calling the ``do_compile``
3446 task as shown in the following example:
3447 ::
3448
3449 $ bitbake -c compile -f package
3450
3451 The ``-f`` or ``--force`` option forces the specified task to
3452 execute. If you find problems with your code, you can just keep
3453 editing and re-testing iteratively until things work as expected.
3454
3455 .. note::
3456
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003457 All the modifications you make to the temporary source code disappear
3458 once you run the ``do_clean`` or ``do_cleanall`` tasks using BitBake
3459 (i.e. ``bitbake -c clean package`` and ``bitbake -c cleanall package``).
3460 Modifications will also disappear if you use the ``rm_work`` feature as
3461 described in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003462 ":ref:`dev-manual/common-tasks:conserving disk space during builds`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003463 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003464
34657. *Generate the Patch:* Once your changes work as expected, you need to
3466 use Quilt to generate the final patch that contains all your
3467 modifications.
3468 ::
3469
3470 $ quilt refresh
3471
3472 At this point, the
3473 ``my_changes.patch`` file has all your edits made to the ``file1.c``,
3474 ``file2.c``, and ``file3.c`` files.
3475
3476 You can find the resulting patch file in the ``patches/``
3477 subdirectory of the source (``S``) directory.
3478
34798. *Copy the Patch File:* For simplicity, copy the patch file into a
3480 directory named ``files``, which you can create in the same directory
3481 that holds the recipe (``.bb``) file or the append (``.bbappend``)
3482 file. Placing the patch here guarantees that the OpenEmbedded build
3483 system will find the patch. Next, add the patch into the ``SRC_URI``
3484 of the recipe. Here is an example:
3485 ::
3486
3487 SRC_URI += "file://my_changes.patch"
3488
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003489Using a Development Shell
3490=========================
3491
3492When debugging certain commands or even when just editing packages,
3493``devshell`` can be a useful tool. When you invoke ``devshell``, all
3494tasks up to and including
3495:ref:`ref-tasks-patch` are run for the
3496specified target. Then, a new terminal is opened and you are placed in
3497``${``\ :term:`S`\ ``}``, the source
3498directory. In the new terminal, all the OpenEmbedded build-related
3499environment variables are still defined so you can use commands such as
3500``configure`` and ``make``. The commands execute just as if the
3501OpenEmbedded build system were executing them. Consequently, working
3502this way can be helpful when debugging a build or preparing software to
3503be used with the OpenEmbedded build system.
3504
3505Following is an example that uses ``devshell`` on a target named
3506``matchbox-desktop``:
3507::
3508
3509 $ bitbake matchbox-desktop -c devshell
3510
3511This command spawns a terminal with a shell prompt within the
3512OpenEmbedded build environment. The
3513:term:`OE_TERMINAL` variable
3514controls what type of shell is opened.
3515
3516For spawned terminals, the following occurs:
3517
3518- The ``PATH`` variable includes the cross-toolchain.
3519
3520- The ``pkgconfig`` variables find the correct ``.pc`` files.
3521
3522- The ``configure`` command finds the Yocto Project site files as well
3523 as any other necessary files.
3524
3525Within this environment, you can run configure or compile commands as if
3526they were being run by the OpenEmbedded build system itself. As noted
3527earlier, the working directory also automatically changes to the Source
3528Directory (:term:`S`).
3529
3530To manually run a specific task using ``devshell``, run the
3531corresponding ``run.*`` script in the
3532``${``\ :term:`WORKDIR`\ ``}/temp``
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003533directory (e.g., ``run.do_configure.``\ `pid`). If a task's script does
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003534not exist, which would be the case if the task was skipped by way of the
3535sstate cache, you can create the task by first running it outside of the
3536``devshell``:
3537::
3538
3539 $ bitbake -c task
3540
3541.. note::
3542
3543 - Execution of a task's ``run.*`` script and BitBake's execution of
3544 a task are identical. In other words, running the script re-runs
3545 the task just as it would be run using the ``bitbake -c`` command.
3546
3547 - Any ``run.*`` file that does not have a ``.pid`` extension is a
3548 symbolic link (symlink) to the most recent version of that file.
3549
3550Remember, that the ``devshell`` is a mechanism that allows you to get
3551into the BitBake task execution environment. And as such, all commands
3552must be called just as BitBake would call them. That means you need to
3553provide the appropriate options for cross-compilation and so forth as
3554applicable.
3555
3556When you are finished using ``devshell``, exit the shell or close the
3557terminal window.
3558
3559.. note::
3560
3561 - It is worth remembering that when using ``devshell`` you need to
3562 use the full compiler name such as ``arm-poky-linux-gnueabi-gcc``
3563 instead of just using ``gcc``. The same applies to other
3564 applications such as ``binutils``, ``libtool`` and so forth.
3565 BitBake sets up environment variables such as ``CC`` to assist
3566 applications, such as ``make`` to find the correct tools.
3567
3568 - It is also worth noting that ``devshell`` still works over X11
3569 forwarding and similar situations.
3570
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003571Using a Development Python Shell
3572================================
3573
3574Similar to working within a development shell as described in the
3575previous section, you can also spawn and work within an interactive
3576Python development shell. When debugging certain commands or even when
3577just editing packages, ``devpyshell`` can be a useful tool. When you
3578invoke ``devpyshell``, all tasks up to and including
3579:ref:`ref-tasks-patch` are run for the
3580specified target. Then a new terminal is opened. Additionally, key
3581Python objects and code are available in the same way they are to
3582BitBake tasks, in particular, the data store 'd'. So, commands such as
3583the following are useful when exploring the data store and running
3584functions:
3585::
3586
3587 pydevshell> d.getVar("STAGING_DIR")
3588 '/media/build1/poky/build/tmp/sysroots'
3589 pydevshell> d.getVar("STAGING_DIR")
3590 '${TMPDIR}/sysroots'
3591 pydevshell> d.setVar("FOO", "bar")
3592 pydevshell> d.getVar("FOO")
3593 'bar'
3594 pydevshell> d.delVar("FOO")
3595 pydevshell> d.getVar("FOO")
3596 pydevshell> bb.build.exec_func("do_unpack", d)
3597 pydevshell>
3598
3599The commands execute just as if the OpenEmbedded build
3600system were executing them. Consequently, working this way can be
3601helpful when debugging a build or preparing software to be used with the
3602OpenEmbedded build system.
3603
3604Following is an example that uses ``devpyshell`` on a target named
3605``matchbox-desktop``:
3606::
3607
3608 $ bitbake matchbox-desktop -c devpyshell
3609
3610This command spawns a terminal and places you in an interactive Python
3611interpreter within the OpenEmbedded build environment. The
3612:term:`OE_TERMINAL` variable
3613controls what type of shell is opened.
3614
3615When you are finished using ``devpyshell``, you can exit the shell
3616either by using Ctrl+d or closing the terminal window.
3617
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003618Building
3619========
3620
3621This section describes various build procedures. For example, the steps
3622needed for a simple build, a target that uses multiple configurations,
3623building an image for more than one machine, and so forth.
3624
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003625Building a Simple Image
3626-----------------------
3627
3628In the development environment, you need to build an image whenever you
3629change hardware support, add or change system libraries, or add or
3630change services that have dependencies. Several methods exist that allow
3631you to build an image within the Yocto Project. This section presents
3632the basic steps you need to build a simple image using BitBake from a
3633build host running Linux.
3634
3635.. note::
3636
3637 - For information on how to build an image using
3638 :term:`Toaster`, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003639 :doc:`/toaster-manual/index`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003640
3641 - For information on how to use ``devtool`` to build images, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003642 ":ref:`sdk-manual/extensible:using \`\`devtool\`\` in your sdk workflow`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003643 section in the Yocto Project Application Development and the
3644 Extensible Software Development Kit (eSDK) manual.
3645
3646 - For a quick example on how to build an image using the
3647 OpenEmbedded build system, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003648 :doc:`/brief-yoctoprojectqs/index` document.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003649
3650The build process creates an entire Linux distribution from source and
3651places it in your :term:`Build Directory` under
3652``tmp/deploy/images``. For detailed information on the build process
Andrew Geissler09209ee2020-12-13 08:44:15 -06003653using BitBake, see the ":ref:`overview-manual/concepts:images`" section in the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003654Yocto Project Overview and Concepts Manual.
3655
3656The following figure and list overviews the build process:
3657
3658.. image:: figures/bitbake-build-flow.png
3659 :align: center
3660
36611. *Set up Your Host Development System to Support Development Using the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003662 Yocto Project*: See the ":doc:`start`" section for options on how to get a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003663 build host ready to use the Yocto Project.
3664
36652. *Initialize the Build Environment:* Initialize the build environment
3666 by sourcing the build environment script (i.e.
3667 :ref:`structure-core-script`):
3668 ::
3669
3670 $ source oe-init-build-env [build_dir]
3671
3672 When you use the initialization script, the OpenEmbedded build system
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003673 uses ``build`` as the default :term:`Build Directory` in your current work
3674 directory. You can use a `build_dir` argument with the script to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003675 specify a different build directory.
3676
3677 .. note::
3678
3679 A common practice is to use a different Build Directory for
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003680 different targets. For example, ``~/build/x86`` for a ``qemux86``
3681 target, and ``~/build/arm`` for a ``qemuarm`` target.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003682
Andrew Geissler4c19ea12020-10-27 13:52:24 -050036833. *Make Sure Your* ``local.conf`` *File is Correct*: Ensure the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003684 ``conf/local.conf`` configuration file, which is found in the Build
3685 Directory, is set up how you want it. This file defines many aspects
3686 of the build environment including the target machine architecture
3687 through the ``MACHINE`` variable, the packaging format used during
3688 the build
3689 (:term:`PACKAGE_CLASSES`),
3690 and a centralized tarball download directory through the
3691 :term:`DL_DIR` variable.
3692
36934. *Build the Image:* Build the image using the ``bitbake`` command:
3694 ::
3695
3696 $ bitbake target
3697
3698 .. note::
3699
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003700 For information on BitBake, see the :doc:`bitbake:index`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003701
3702 The target is the name of the recipe you want to build. Common
3703 targets are the images in ``meta/recipes-core/images``,
3704 ``meta/recipes-sato/images``, and so forth all found in the
3705 :term:`Source Directory`. Or, the target
3706 can be the name of a recipe for a specific piece of software such as
3707 BusyBox. For more details about the images the OpenEmbedded build
3708 system supports, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003709 ":ref:`ref-manual/images:Images`" chapter in the Yocto
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003710 Project Reference Manual.
3711
3712 As an example, the following command builds the
3713 ``core-image-minimal`` image:
3714 ::
3715
3716 $ bitbake core-image-minimal
3717
3718 Once an
3719 image has been built, it often needs to be installed. The images and
3720 kernels built by the OpenEmbedded build system are placed in the
3721 Build Directory in ``tmp/deploy/images``. For information on how to
3722 run pre-built images such as ``qemux86`` and ``qemuarm``, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003723 :doc:`/sdk-manual/index` manual. For
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003724 information about how to install these images, see the documentation
3725 for your particular board or machine.
3726
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003727Building Images for Multiple Targets Using Multiple Configurations
3728------------------------------------------------------------------
3729
3730You can use a single ``bitbake`` command to build multiple images or
3731packages for different targets where each image or package requires a
3732different configuration (multiple configuration builds). The builds, in
3733this scenario, are sometimes referred to as "multiconfigs", and this
3734section uses that term throughout.
3735
3736This section describes how to set up for multiple configuration builds
3737and how to account for cross-build dependencies between the
3738multiconfigs.
3739
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003740Setting Up and Running a Multiple Configuration Build
3741~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3742
3743To accomplish a multiple configuration build, you must define each
3744target's configuration separately using a parallel configuration file in
3745the :term:`Build Directory`, and you
3746must follow a required file hierarchy. Additionally, you must enable the
3747multiple configuration builds in your ``local.conf`` file.
3748
3749Follow these steps to set up and execute multiple configuration builds:
3750
3751- *Create Separate Configuration Files*: You need to create a single
3752 configuration file for each build target (each multiconfig).
3753 Minimally, each configuration file must define the machine and the
3754 temporary directory BitBake uses for the build. Suggested practice
3755 dictates that you do not overlap the temporary directories used
3756 during the builds. However, it is possible that you can share the
3757 temporary directory
3758 (:term:`TMPDIR`). For example,
3759 consider a scenario with two different multiconfigs for the same
3760 :term:`MACHINE`: "qemux86" built
3761 for two distributions such as "poky" and "poky-lsb". In this case,
3762 you might want to use the same ``TMPDIR``.
3763
3764 Here is an example showing the minimal statements needed in a
3765 configuration file for a "qemux86" target whose temporary build
3766 directory is ``tmpmultix86``:
3767 ::
3768
3769 MACHINE = "qemux86"
3770 TMPDIR = "${TOPDIR}/tmpmultix86"
3771
3772 The location for these multiconfig configuration files is specific.
3773 They must reside in the current build directory in a sub-directory of
3774 ``conf`` named ``multiconfig``. Following is an example that defines
3775 two configuration files for the "x86" and "arm" multiconfigs:
3776
3777 .. image:: figures/multiconfig_files.png
3778 :align: center
3779
3780 The reason for this required file hierarchy is because the ``BBPATH``
3781 variable is not constructed until the layers are parsed.
3782 Consequently, using the configuration file as a pre-configuration
3783 file is not possible unless it is located in the current working
3784 directory.
3785
3786- *Add the BitBake Multi-configuration Variable to the Local
3787 Configuration File*: Use the
3788 :term:`BBMULTICONFIG`
3789 variable in your ``conf/local.conf`` configuration file to specify
3790 each multiconfig. Continuing with the example from the previous
3791 figure, the ``BBMULTICONFIG`` variable needs to enable two
3792 multiconfigs: "x86" and "arm" by specifying each configuration file:
3793 ::
3794
3795 BBMULTICONFIG = "x86 arm"
3796
3797 .. note::
3798
3799 A "default" configuration already exists by definition. This
3800 configuration is named: "" (i.e. empty string) and is defined by
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003801 the variables coming from your ``local.conf``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003802 file. Consequently, the previous example actually adds two
3803 additional configurations to your build: "arm" and "x86" along
3804 with "".
3805
3806- *Launch BitBake*: Use the following BitBake command form to launch
3807 the multiple configuration build:
3808 ::
3809
3810 $ bitbake [mc:multiconfigname:]target [[[mc:multiconfigname:]target] ... ]
3811
3812 For the example in this section, the following command applies:
3813 ::
3814
3815 $ bitbake mc:x86:core-image-minimal mc:arm:core-image-sato mc::core-image-base
3816
3817 The previous BitBake command builds a ``core-image-minimal`` image
3818 that is configured through the ``x86.conf`` configuration file, a
3819 ``core-image-sato`` image that is configured through the ``arm.conf``
3820 configuration file and a ``core-image-base`` that is configured
3821 through your ``local.conf`` configuration file.
3822
3823.. note::
3824
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003825 Support for multiple configuration builds in the Yocto Project &DISTRO;
3826 (&DISTRO_NAME;) Release does not include Shared State (sstate)
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003827 optimizations. Consequently, if a build uses the same object twice
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003828 in, for example, two different ``TMPDIR``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003829 directories, the build either loads from an existing sstate cache for
3830 that build at the start or builds the object fresh.
3831
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003832Enabling Multiple Configuration Build Dependencies
3833~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3834
3835Sometimes dependencies can exist between targets (multiconfigs) in a
3836multiple configuration build. For example, suppose that in order to
3837build a ``core-image-sato`` image for an "x86" multiconfig, the root
3838filesystem of an "arm" multiconfig must exist. This dependency is
3839essentially that the
3840:ref:`ref-tasks-image` task in the
3841``core-image-sato`` recipe depends on the completion of the
3842:ref:`ref-tasks-rootfs` task of the
3843``core-image-minimal`` recipe.
3844
3845To enable dependencies in a multiple configuration build, you must
3846declare the dependencies in the recipe using the following statement
3847form:
3848::
3849
3850 task_or_package[mcdepends] = "mc:from_multiconfig:to_multiconfig:recipe_name:task_on_which_to_depend"
3851
3852To better show how to use this statement, consider the example scenario
3853from the first paragraph of this section. The following statement needs
3854to be added to the recipe that builds the ``core-image-sato`` image:
3855::
3856
3857 do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_rootfs"
3858
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003859In this example, the `from_multiconfig` is "x86". The `to_multiconfig` is "arm". The
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003860task on which the ``do_image`` task in the recipe depends is the
3861``do_rootfs`` task from the ``core-image-minimal`` recipe associated
3862with the "arm" multiconfig.
3863
3864Once you set up this dependency, you can build the "x86" multiconfig
3865using a BitBake command as follows:
3866::
3867
3868 $ bitbake mc:x86:core-image-sato
3869
3870This command executes all the tasks needed to create the
3871``core-image-sato`` image for the "x86" multiconfig. Because of the
3872dependency, BitBake also executes through the ``do_rootfs`` task for the
3873"arm" multiconfig build.
3874
3875Having a recipe depend on the root filesystem of another build might not
3876seem that useful. Consider this change to the statement in the
3877``core-image-sato`` recipe:
3878::
3879
3880 do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_image"
3881
3882In this case, BitBake must
3883create the ``core-image-minimal`` image for the "arm" build since the
3884"x86" build depends on it.
3885
3886Because "x86" and "arm" are enabled for multiple configuration builds
3887and have separate configuration files, BitBake places the artifacts for
3888each build in the respective temporary build directories (i.e.
3889:term:`TMPDIR`).
3890
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003891Building an Initial RAM Filesystem (initramfs) Image
3892----------------------------------------------------
3893
3894An initial RAM filesystem (initramfs) image provides a temporary root
3895filesystem used for early system initialization (e.g. loading of modules
3896needed to locate and mount the "real" root filesystem).
3897
3898.. note::
3899
3900 The initramfs image is the successor of initial RAM disk (initrd). It
3901 is a "copy in and out" (cpio) archive of the initial filesystem that
3902 gets loaded into memory during the Linux startup process. Because
3903 Linux uses the contents of the archive during initialization, the
3904 initramfs image needs to contain all of the device drivers and tools
3905 needed to mount the final root filesystem.
3906
3907Follow these steps to create an initramfs image:
3908
39091. *Create the initramfs Image Recipe:* You can reference the
3910 ``core-image-minimal-initramfs.bb`` recipe found in the
3911 ``meta/recipes-core`` directory of the :term:`Source Directory`
3912 as an example
3913 from which to work.
3914
39152. *Decide if You Need to Bundle the initramfs Image Into the Kernel
3916 Image:* If you want the initramfs image that is built to be bundled
3917 in with the kernel image, set the
3918 :term:`INITRAMFS_IMAGE_BUNDLE`
3919 variable to "1" in your ``local.conf`` configuration file and set the
3920 :term:`INITRAMFS_IMAGE`
3921 variable in the recipe that builds the kernel image.
3922
3923 .. note::
3924
3925 It is recommended that you do bundle the initramfs image with the
3926 kernel image to avoid circular dependencies between the kernel
3927 recipe and the initramfs recipe should the initramfs image include
3928 kernel modules.
3929
3930 Setting the ``INITRAMFS_IMAGE_BUNDLE`` flag causes the initramfs
3931 image to be unpacked into the ``${B}/usr/`` directory. The unpacked
3932 initramfs image is then passed to the kernel's ``Makefile`` using the
3933 :term:`CONFIG_INITRAMFS_SOURCE`
3934 variable, allowing the initramfs image to be built into the kernel
3935 normally.
3936
3937 .. note::
3938
3939 If you choose to not bundle the initramfs image with the kernel
3940 image, you are essentially using an
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003941 `Initial RAM Disk (initrd) <https://en.wikipedia.org/wiki/Initrd>`__.
3942 Creating an initrd is handled primarily through the :term:`INITRD_IMAGE`,
3943 ``INITRD_LIVE``, and ``INITRD_IMAGE_LIVE`` variables. For more
3944 information, see the :ref:`ref-classes-image-live` file.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003945
39463. *Optionally Add Items to the initramfs Image Through the initramfs
3947 Image Recipe:* If you add items to the initramfs image by way of its
3948 recipe, you should use
3949 :term:`PACKAGE_INSTALL`
3950 rather than
3951 :term:`IMAGE_INSTALL`.
3952 ``PACKAGE_INSTALL`` gives more direct control of what is added to the
3953 image as compared to the defaults you might not necessarily want that
3954 are set by the :ref:`image <ref-classes-image>`
3955 or :ref:`core-image <ref-classes-core-image>`
3956 classes.
3957
39584. *Build the Kernel Image and the initramfs Image:* Build your kernel
3959 image using BitBake. Because the initramfs image recipe is a
3960 dependency of the kernel image, the initramfs image is built as well
3961 and bundled with the kernel image if you used the
3962 :term:`INITRAMFS_IMAGE_BUNDLE`
3963 variable described earlier.
3964
3965Building a Tiny System
3966----------------------
3967
3968Very small distributions have some significant advantages such as
3969requiring less on-die or in-package memory (cheaper), better performance
3970through efficient cache usage, lower power requirements due to less
3971memory, faster boot times, and reduced development overhead. Some
3972real-world examples where a very small distribution gives you distinct
3973advantages are digital cameras, medical devices, and small headless
3974systems.
3975
3976This section presents information that shows you how you can trim your
3977distribution to even smaller sizes than the ``poky-tiny`` distribution,
3978which is around 5 Mbytes, that can be built out-of-the-box using the
3979Yocto Project.
3980
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003981Tiny System Overview
3982~~~~~~~~~~~~~~~~~~~~
3983
3984The following list presents the overall steps you need to consider and
3985perform to create distributions with smaller root filesystems, achieve
3986faster boot times, maintain your critical functionality, and avoid
3987initial RAM disks:
3988
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05003989- :ref:`Determine your goals and guiding principles
3990 <dev-manual/common-tasks:goals and guiding principles>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003991
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05003992- :ref:`dev-manual/common-tasks:understand what contributes to your image size`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003993
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05003994- :ref:`Reduce the size of the root filesystem
3995 <dev-manual/common-tasks:trim the root filesystem>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003996
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05003997- :ref:`Reduce the size of the kernel <dev-manual/common-tasks:trim the kernel>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003998
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05003999- :ref:`dev-manual/common-tasks:remove package management requirements`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004000
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004001- :ref:`dev-manual/common-tasks:look for other ways to minimize size`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004002
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004003- :ref:`dev-manual/common-tasks:iterate on the process`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004004
4005Goals and Guiding Principles
4006~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4007
4008Before you can reach your destination, you need to know where you are
4009going. Here is an example list that you can use as a guide when creating
4010very small distributions:
4011
4012- Determine how much space you need (e.g. a kernel that is 1 Mbyte or
4013 less and a root filesystem that is 3 Mbytes or less).
4014
4015- Find the areas that are currently taking 90% of the space and
4016 concentrate on reducing those areas.
4017
4018- Do not create any difficult "hacks" to achieve your goals.
4019
4020- Leverage the device-specific options.
4021
4022- Work in a separate layer so that you keep changes isolated. For
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004023 information on how to create layers, see the
4024 ":ref:`dev-manual/common-tasks:understanding and creating layers`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004025
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004026Understand What Contributes to Your Image Size
4027~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4028
4029It is easiest to have something to start with when creating your own
4030distribution. You can use the Yocto Project out-of-the-box to create the
4031``poky-tiny`` distribution. Ultimately, you will want to make changes in
4032your own distribution that are likely modeled after ``poky-tiny``.
4033
4034.. note::
4035
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004036 To use ``poky-tiny`` in your build, set the ``DISTRO`` variable in your
4037 ``local.conf`` file to "poky-tiny" as described in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06004038 ":ref:`dev-manual/common-tasks:creating your own distribution`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004039 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004040
4041Understanding some memory concepts will help you reduce the system size.
4042Memory consists of static, dynamic, and temporary memory. Static memory
4043is the TEXT (code), DATA (initialized data in the code), and BSS
4044(uninitialized data) sections. Dynamic memory represents memory that is
4045allocated at runtime: stacks, hash tables, and so forth. Temporary
4046memory is recovered after the boot process. This memory consists of
4047memory used for decompressing the kernel and for the ``__init__``
4048functions.
4049
4050To help you see where you currently are with kernel and root filesystem
4051sizes, you can use two tools found in the :term:`Source Directory`
4052in the
4053``scripts/tiny/`` directory:
4054
4055- ``ksize.py``: Reports component sizes for the kernel build objects.
4056
4057- ``dirsize.py``: Reports component sizes for the root filesystem.
4058
4059This next tool and command help you organize configuration fragments and
4060view file dependencies in a human-readable form:
4061
4062- ``merge_config.sh``: Helps you manage configuration files and
4063 fragments within the kernel. With this tool, you can merge individual
4064 configuration fragments together. The tool allows you to make
4065 overrides and warns you of any missing configuration options. The
4066 tool is ideal for allowing you to iterate on configurations, create
4067 minimal configurations, and create configuration files for different
4068 machines without having to duplicate your process.
4069
4070 The ``merge_config.sh`` script is part of the Linux Yocto kernel Git
4071 repositories (i.e. ``linux-yocto-3.14``, ``linux-yocto-3.10``,
4072 ``linux-yocto-3.8``, and so forth) in the ``scripts/kconfig``
4073 directory.
4074
4075 For more information on configuration fragments, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06004076 ":ref:`kernel-dev/common:creating configuration fragments`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004077 section in the Yocto Project Linux Kernel Development Manual.
4078
4079- ``bitbake -u taskexp -g bitbake_target``: Using the BitBake command
4080 with these options brings up a Dependency Explorer from which you can
4081 view file dependencies. Understanding these dependencies allows you
4082 to make informed decisions when cutting out various pieces of the
4083 kernel and root filesystem.
4084
4085Trim the Root Filesystem
4086~~~~~~~~~~~~~~~~~~~~~~~~
4087
4088The root filesystem is made up of packages for booting, libraries, and
4089applications. To change things, you can configure how the packaging
4090happens, which changes the way you build them. You can also modify the
4091filesystem itself or select a different filesystem.
4092
4093First, find out what is hogging your root filesystem by running the
4094``dirsize.py`` script from your root directory:
4095::
4096
4097 $ cd root-directory-of-image
4098 $ dirsize.py 100000 > dirsize-100k.log
4099 $ cat dirsize-100k.log
4100
4101You can apply a filter to the script to ignore files
4102under a certain size. The previous example filters out any files below
4103100 Kbytes. The sizes reported by the tool are uncompressed, and thus
4104will be smaller by a relatively constant factor in a compressed root
4105filesystem. When you examine your log file, you can focus on areas of
4106the root filesystem that take up large amounts of memory.
4107
4108You need to be sure that what you eliminate does not cripple the
4109functionality you need. One way to see how packages relate to each other
4110is by using the Dependency Explorer UI with the BitBake command:
4111::
4112
4113 $ cd image-directory
4114 $ bitbake -u taskexp -g image
4115
4116Use the interface to
4117select potential packages you wish to eliminate and see their dependency
4118relationships.
4119
4120When deciding how to reduce the size, get rid of packages that result in
4121minimal impact on the feature set. For example, you might not need a VGA
4122display. Or, you might be able to get by with ``devtmpfs`` and ``mdev``
4123instead of ``udev``.
4124
4125Use your ``local.conf`` file to make changes. For example, to eliminate
4126``udev`` and ``glib``, set the following in the local configuration
4127file:
4128::
4129
4130 VIRTUAL-RUNTIME_dev_manager = ""
4131
4132Finally, you should consider exactly the type of root filesystem you
4133need to meet your needs while also reducing its size. For example,
4134consider ``cramfs``, ``squashfs``, ``ubifs``, ``ext2``, or an
4135``initramfs`` using ``initramfs``. Be aware that ``ext3`` requires a 1
4136Mbyte journal. If you are okay with running read-only, you do not need
4137this journal.
4138
4139.. note::
4140
4141 After each round of elimination, you need to rebuild your system and
4142 then use the tools to see the effects of your reductions.
4143
4144Trim the Kernel
4145~~~~~~~~~~~~~~~
4146
4147The kernel is built by including policies for hardware-independent
4148aspects. What subsystems do you enable? For what architecture are you
4149building? Which drivers do you build by default?
4150
4151.. note::
4152
4153 You can modify the kernel source if you want to help with boot time.
4154
4155Run the ``ksize.py`` script from the top-level Linux build directory to
4156get an idea of what is making up the kernel:
4157::
4158
4159 $ cd top-level-linux-build-directory
4160 $ ksize.py > ksize.log
4161 $ cat ksize.log
4162
4163When you examine the log, you will see how much space is taken up with
4164the built-in ``.o`` files for drivers, networking, core kernel files,
4165filesystem, sound, and so forth. The sizes reported by the tool are
4166uncompressed, and thus will be smaller by a relatively constant factor
4167in a compressed kernel image. Look to reduce the areas that are large
4168and taking up around the "90% rule."
4169
4170To examine, or drill down, into any particular area, use the ``-d``
4171option with the script:
4172::
4173
4174 $ ksize.py -d > ksize.log
4175
4176Using this option
4177breaks out the individual file information for each area of the kernel
4178(e.g. drivers, networking, and so forth).
4179
4180Use your log file to see what you can eliminate from the kernel based on
4181features you can let go. For example, if you are not going to need
4182sound, you do not need any drivers that support sound.
4183
4184After figuring out what to eliminate, you need to reconfigure the kernel
4185to reflect those changes during the next build. You could run
4186``menuconfig`` and make all your changes at once. However, that makes it
4187difficult to see the effects of your individual eliminations and also
4188makes it difficult to replicate the changes for perhaps another target
4189device. A better method is to start with no configurations using
4190``allnoconfig``, create configuration fragments for individual changes,
4191and then manage the fragments into a single configuration file using
4192``merge_config.sh``. The tool makes it easy for you to iterate using the
4193configuration change and build cycle.
4194
4195Each time you make configuration changes, you need to rebuild the kernel
4196and check to see what impact your changes had on the overall size.
4197
4198Remove Package Management Requirements
4199~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4200
4201Packaging requirements add size to the image. One way to reduce the size
4202of the image is to remove all the packaging requirements from the image.
4203This reduction includes both removing the package manager and its unique
4204dependencies as well as removing the package management data itself.
4205
4206To eliminate all the packaging requirements for an image, be sure that
4207"package-management" is not part of your
4208:term:`IMAGE_FEATURES`
4209statement for the image. When you remove this feature, you are removing
4210the package manager as well as its dependencies from the root
4211filesystem.
4212
4213Look for Other Ways to Minimize Size
4214~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4215
4216Depending on your particular circumstances, other areas that you can
4217trim likely exist. The key to finding these areas is through tools and
4218methods described here combined with experimentation and iteration. Here
4219are a couple of areas to experiment with:
4220
4221- ``glibc``: In general, follow this process:
4222
4223 1. Remove ``glibc`` features from
4224 :term:`DISTRO_FEATURES`
4225 that you think you do not need.
4226
4227 2. Build your distribution.
4228
4229 3. If the build fails due to missing symbols in a package, determine
4230 if you can reconfigure the package to not need those features. For
4231 example, change the configuration to not support wide character
4232 support as is done for ``ncurses``. Or, if support for those
4233 characters is needed, determine what ``glibc`` features provide
4234 the support and restore the configuration.
4235
4236 4. Rebuild and repeat the process.
4237
4238- ``busybox``: For BusyBox, use a process similar as described for
4239 ``glibc``. A difference is you will need to boot the resulting system
4240 to see if you are able to do everything you expect from the running
4241 system. You need to be sure to integrate configuration fragments into
4242 Busybox because BusyBox handles its own core features and then allows
4243 you to add configuration fragments on top.
4244
4245Iterate on the Process
4246~~~~~~~~~~~~~~~~~~~~~~
4247
4248If you have not reached your goals on system size, you need to iterate
4249on the process. The process is the same. Use the tools and see just what
4250is taking up 90% of the root filesystem and the kernel. Decide what you
4251can eliminate without limiting your device beyond what you need.
4252
4253Depending on your system, a good place to look might be Busybox, which
4254provides a stripped down version of Unix tools in a single, executable
4255file. You might be able to drop virtual terminal services or perhaps
4256ipv6.
4257
4258Building Images for More than One Machine
4259-----------------------------------------
4260
4261A common scenario developers face is creating images for several
4262different machines that use the same software environment. In this
4263situation, it is tempting to set the tunings and optimization flags for
4264each build specifically for the targeted hardware (i.e. "maxing out" the
4265tunings). Doing so can considerably add to build times and package feed
4266maintenance collectively for the machines. For example, selecting tunes
4267that are extremely specific to a CPU core used in a system might enable
4268some micro optimizations in GCC for that particular system but would
4269otherwise not gain you much of a performance difference across the other
4270systems as compared to using a more general tuning across all the builds
4271(e.g. setting :term:`DEFAULTTUNE`
4272specifically for each machine's build). Rather than "max out" each
4273build's tunings, you can take steps that cause the OpenEmbedded build
4274system to reuse software across the various machines where it makes
4275sense.
4276
4277If build speed and package feed maintenance are considerations, you
4278should consider the points in this section that can help you optimize
4279your tunings to best consider build times and package feed maintenance.
4280
4281- *Share the Build Directory:* If at all possible, share the
4282 :term:`TMPDIR` across builds. The
4283 Yocto Project supports switching between different
4284 :term:`MACHINE` values in the same
4285 ``TMPDIR``. This practice is well supported and regularly used by
4286 developers when building for multiple machines. When you use the same
4287 ``TMPDIR`` for multiple machine builds, the OpenEmbedded build system
4288 can reuse the existing native and often cross-recipes for multiple
4289 machines. Thus, build time decreases.
4290
4291 .. note::
4292
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004293 If :term:`DISTRO` settings change or fundamental configuration settings
4294 such as the filesystem layout, you need to work with a clean ``TMPDIR``.
4295 Sharing ``TMPDIR`` under these circumstances might work but since it is
4296 not guaranteed, you should use a clean ``TMPDIR``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004297
4298- *Enable the Appropriate Package Architecture:* By default, the
4299 OpenEmbedded build system enables three levels of package
4300 architectures: "all", "tune" or "package", and "machine". Any given
4301 recipe usually selects one of these package architectures (types) for
4302 its output. Depending for what a given recipe creates packages,
4303 making sure you enable the appropriate package architecture can
4304 directly impact the build time.
4305
4306 A recipe that just generates scripts can enable "all" architecture
4307 because there are no binaries to build. To specifically enable "all"
4308 architecture, be sure your recipe inherits the
4309 :ref:`allarch <ref-classes-allarch>` class.
4310 This class is useful for "all" architectures because it configures
4311 many variables so packages can be used across multiple architectures.
4312
4313 If your recipe needs to generate packages that are machine-specific
4314 or when one of the build or runtime dependencies is already
4315 machine-architecture dependent, which makes your recipe also
4316 machine-architecture dependent, make sure your recipe enables the
4317 "machine" package architecture through the
4318 :term:`MACHINE_ARCH`
4319 variable:
4320 ::
4321
4322 PACKAGE_ARCH = "${MACHINE_ARCH}"
4323
4324 When you do not
4325 specifically enable a package architecture through the
4326 :term:`PACKAGE_ARCH`, The
4327 OpenEmbedded build system defaults to the
4328 :term:`TUNE_PKGARCH` setting:
4329 ::
4330
4331 PACKAGE_ARCH = "${TUNE_PKGARCH}"
4332
4333- *Choose a Generic Tuning File if Possible:* Some tunes are more
4334 generic and can run on multiple targets (e.g. an ``armv5`` set of
4335 packages could run on ``armv6`` and ``armv7`` processors in most
4336 cases). Similarly, ``i486`` binaries could work on ``i586`` and
4337 higher processors. You should realize, however, that advances on
4338 newer processor versions would not be used.
4339
4340 If you select the same tune for several different machines, the
4341 OpenEmbedded build system reuses software previously built, thus
4342 speeding up the overall build time. Realize that even though a new
4343 sysroot for each machine is generated, the software is not recompiled
4344 and only one package feed exists.
4345
4346- *Manage Granular Level Packaging:* Sometimes cases exist where
4347 injecting another level of package architecture beyond the three
4348 higher levels noted earlier can be useful. For example, consider how
4349 NXP (formerly Freescale) allows for the easy reuse of binary packages
4350 in their layer
Andrew Geissler09209ee2020-12-13 08:44:15 -06004351 :yocto_git:`meta-freescale </meta-freescale/>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004352 In this example, the
Andrew Geissler09209ee2020-12-13 08:44:15 -06004353 :yocto_git:`fsl-dynamic-packagearch </meta-freescale/tree/classes/fsl-dynamic-packagearch.bbclass>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004354 class shares GPU packages for i.MX53 boards because all boards share
4355 the AMD GPU. The i.MX6-based boards can do the same because all
4356 boards share the Vivante GPU. This class inspects the BitBake
4357 datastore to identify if the package provides or depends on one of
4358 the sub-architecture values. If so, the class sets the
4359 :term:`PACKAGE_ARCH` value
4360 based on the ``MACHINE_SUBARCH`` value. If the package does not
4361 provide or depend on one of the sub-architecture values but it
4362 matches a value in the machine-specific filter, it sets
4363 :term:`MACHINE_ARCH`. This
4364 behavior reduces the number of packages built and saves build time by
4365 reusing binaries.
4366
4367- *Use Tools to Debug Issues:* Sometimes you can run into situations
4368 where software is being rebuilt when you think it should not be. For
4369 example, the OpenEmbedded build system might not be using shared
4370 state between machines when you think it should be. These types of
4371 situations are usually due to references to machine-specific
4372 variables such as :term:`MACHINE`,
4373 :term:`SERIAL_CONSOLES`,
4374 :term:`XSERVER`,
4375 :term:`MACHINE_FEATURES`,
4376 and so forth in code that is supposed to only be tune-specific or
4377 when the recipe depends
4378 (:term:`DEPENDS`,
4379 :term:`RDEPENDS`,
4380 :term:`RRECOMMENDS`,
4381 :term:`RSUGGESTS`, and so forth)
4382 on some other recipe that already has
4383 :term:`PACKAGE_ARCH` defined
4384 as "${MACHINE_ARCH}".
4385
4386 .. note::
4387
4388 Patches to fix any issues identified are most welcome as these
4389 issues occasionally do occur.
4390
4391 For such cases, you can use some tools to help you sort out the
4392 situation:
4393
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004394 - ``state-diff-machines.sh``*:* You can find this tool in the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004395 ``scripts`` directory of the Source Repositories. See the comments
4396 in the script for information on how to use the tool.
4397
4398 - *BitBake's "-S printdiff" Option:* Using this option causes
4399 BitBake to try to establish the closest signature match it can
4400 (e.g. in the shared state cache) and then run ``bitbake-diffsigs``
4401 over the matches to determine the stamps and delta where these two
4402 stamp trees diverge.
4403
4404Building Software from an External Source
4405-----------------------------------------
4406
4407By default, the OpenEmbedded build system uses the
4408:term:`Build Directory` when building source
4409code. The build process involves fetching the source files, unpacking
4410them, and then patching them if necessary before the build takes place.
4411
4412Situations exist where you might want to build software from source
4413files that are external to and thus outside of the OpenEmbedded build
4414system. For example, suppose you have a project that includes a new BSP
4415with a heavily customized kernel. And, you want to minimize exposing the
4416build system to the development team so that they can focus on their
4417project and maintain everyone's workflow as much as possible. In this
4418case, you want a kernel source directory on the development machine
4419where the development occurs. You want the recipe's
4420:term:`SRC_URI` variable to point to
4421the external directory and use it as is, not copy it.
4422
4423To build from software that comes from an external source, all you need
4424to do is inherit the
4425:ref:`externalsrc <ref-classes-externalsrc>` class
4426and then set the
4427:term:`EXTERNALSRC` variable to
4428point to your external source code. Here are the statements to put in
4429your ``local.conf`` file:
4430::
4431
4432 INHERIT += "externalsrc"
4433 EXTERNALSRC_pn-myrecipe = "path-to-your-source-tree"
4434
4435This next example shows how to accomplish the same thing by setting
4436``EXTERNALSRC`` in the recipe itself or in the recipe's append file:
4437::
4438
4439 EXTERNALSRC = "path"
4440 EXTERNALSRC_BUILD = "path"
4441
4442.. note::
4443
4444 In order for these settings to take effect, you must globally or
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004445 locally inherit the :ref:`externalsrc <ref-classes-externalsrc>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004446 class.
4447
4448By default, ``externalsrc.bbclass`` builds the source code in a
4449directory separate from the external source directory as specified by
4450:term:`EXTERNALSRC`. If you need
4451to have the source built in the same directory in which it resides, or
4452some other nominated directory, you can set
4453:term:`EXTERNALSRC_BUILD`
4454to point to that directory:
4455::
4456
4457 EXTERNALSRC_BUILD_pn-myrecipe = "path-to-your-source-tree"
4458
4459Replicating a Build Offline
4460---------------------------
4461
4462It can be useful to take a "snapshot" of upstream sources used in a
4463build and then use that "snapshot" later to replicate the build offline.
4464To do so, you need to first prepare and populate your downloads
4465directory your "snapshot" of files. Once your downloads directory is
4466ready, you can use it at any time and from any machine to replicate your
4467build.
4468
4469Follow these steps to populate your Downloads directory:
4470
44711. *Create a Clean Downloads Directory:* Start with an empty downloads
4472 directory (:term:`DL_DIR`). You
4473 start with an empty downloads directory by either removing the files
4474 in the existing directory or by setting ``DL_DIR`` to point to either
4475 an empty location or one that does not yet exist.
4476
44772. *Generate Tarballs of the Source Git Repositories:* Edit your
4478 ``local.conf`` configuration file as follows:
4479 ::
4480
4481 DL_DIR = "/home/your-download-dir/"
4482 BB_GENERATE_MIRROR_TARBALLS = "1"
4483
4484 During
4485 the fetch process in the next step, BitBake gathers the source files
4486 and creates tarballs in the directory pointed to by ``DL_DIR``. See
4487 the
4488 :term:`BB_GENERATE_MIRROR_TARBALLS`
4489 variable for more information.
4490
44913. *Populate Your Downloads Directory Without Building:* Use BitBake to
4492 fetch your sources but inhibit the build:
4493 ::
4494
4495 $ bitbake target --runonly=fetch
4496
4497 The downloads directory (i.e. ``${DL_DIR}``) now has
4498 a "snapshot" of the source files in the form of tarballs, which can
4499 be used for the build.
4500
45014. *Optionally Remove Any Git or other SCM Subdirectories From the
4502 Downloads Directory:* If you want, you can clean up your downloads
4503 directory by removing any Git or other Source Control Management
4504 (SCM) subdirectories such as ``${DL_DIR}/git2/*``. The tarballs
4505 already contain these subdirectories.
4506
4507Once your downloads directory has everything it needs regarding source
4508files, you can create your "own-mirror" and build your target.
4509Understand that you can use the files to build the target offline from
4510any machine and at any time.
4511
4512Follow these steps to build your target using the files in the downloads
4513directory:
4514
45151. *Using Local Files Only:* Inside your ``local.conf`` file, add the
4516 :term:`SOURCE_MIRROR_URL`
4517 variable, inherit the
4518 :ref:`own-mirrors <ref-classes-own-mirrors>`
4519 class, and use the
4520 :term:`bitbake:BB_NO_NETWORK`
4521 variable to your ``local.conf``.
4522 ::
4523
4524 SOURCE_MIRROR_URL ?= "file:///home/your-download-dir/"
4525 INHERIT += "own-mirrors"
4526 BB_NO_NETWORK = "1"
4527
4528 The ``SOURCE_MIRROR_URL`` and ``own-mirror``
4529 class set up the system to use the downloads directory as your "own
4530 mirror". Using the ``BB_NO_NETWORK`` variable makes sure that
4531 BitBake's fetching process in step 3 stays local, which means files
4532 from your "own-mirror" are used.
4533
45342. *Start With a Clean Build:* You can start with a clean build by
4535 removing the
4536 ``${``\ :term:`TMPDIR`\ ``}``
4537 directory or using a new :term:`Build Directory`.
4538
45393. *Build Your Target:* Use BitBake to build your target:
4540 ::
4541
4542 $ bitbake target
4543
4544 The build completes using the known local "snapshot" of source
4545 files from your mirror. The resulting tarballs for your "snapshot" of
4546 source files are in the downloads directory.
4547
4548 .. note::
4549
4550 The offline build does not work if recipes attempt to find the
4551 latest version of software by setting
4552 :term:`SRCREV` to
4553 ``${``\ :term:`AUTOREV`\ ``}``:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004554 ::
4555
4556 SRCREV = "${AUTOREV}"
4557
4558 When a recipe sets ``SRCREV`` to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004559 ``${AUTOREV}``, the build system accesses the network in an
4560 attempt to determine the latest version of software from the SCM.
4561 Typically, recipes that use ``AUTOREV`` are custom or modified
4562 recipes. Recipes that reside in public repositories usually do not
4563 use ``AUTOREV``.
4564
4565 If you do have recipes that use ``AUTOREV``, you can take steps to
4566 still use the recipes in an offline build. Do the following:
4567
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004568 1. Use a configuration generated by enabling :ref:`build
4569 history <dev-manual/common-tasks:maintaining build output quality>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004570
4571 2. Use the ``buildhistory-collect-srcrevs`` command to collect the
4572 stored ``SRCREV`` values from the build's history. For more
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004573 information on collecting these values, see the
4574 ":ref:`dev-manual/common-tasks:build history package information`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004575 section.
4576
4577 3. Once you have the correct source revisions, you can modify
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004578 those recipes to set ``SRCREV`` to specific versions of the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004579 software.
4580
4581Speeding Up a Build
4582===================
4583
4584Build time can be an issue. By default, the build system uses simple
4585controls to try and maximize build efficiency. In general, the default
4586settings for all the following variables result in the most efficient
4587build times when dealing with single socket systems (i.e. a single CPU).
4588If you have multiple CPUs, you might try increasing the default values
4589to gain more speed. See the descriptions in the glossary for each
4590variable for more information:
4591
4592- :term:`BB_NUMBER_THREADS`:
4593 The maximum number of threads BitBake simultaneously executes.
4594
4595- :term:`bitbake:BB_NUMBER_PARSE_THREADS`:
4596 The number of threads BitBake uses during parsing.
4597
4598- :term:`PARALLEL_MAKE`: Extra
4599 options passed to the ``make`` command during the
4600 :ref:`ref-tasks-compile` task in
4601 order to specify parallel compilation on the local build host.
4602
4603- :term:`PARALLEL_MAKEINST`:
4604 Extra options passed to the ``make`` command during the
4605 :ref:`ref-tasks-install` task in
4606 order to specify parallel installation on the local build host.
4607
4608As mentioned, these variables all scale to the number of processor cores
4609available on the build system. For single socket systems, this
4610auto-scaling ensures that the build system fundamentally takes advantage
4611of potential parallel operations during the build based on the build
4612machine's capabilities.
4613
4614Following are additional factors that can affect build speed:
4615
4616- File system type: The file system type that the build is being
4617 performed on can also influence performance. Using ``ext4`` is
4618 recommended as compared to ``ext2`` and ``ext3`` due to ``ext4``
4619 improved features such as extents.
4620
4621- Disabling the updating of access time using ``noatime``: The
4622 ``noatime`` mount option prevents the build system from updating file
4623 and directory access times.
4624
4625- Setting a longer commit: Using the "commit=" mount option increases
4626 the interval in seconds between disk cache writes. Changing this
4627 interval from the five second default to something longer increases
4628 the risk of data loss but decreases the need to write to the disk,
4629 thus increasing the build performance.
4630
4631- Choosing the packaging backend: Of the available packaging backends,
4632 IPK is the fastest. Additionally, selecting a singular packaging
4633 backend also helps.
4634
4635- Using ``tmpfs`` for :term:`TMPDIR`
4636 as a temporary file system: While this can help speed up the build,
4637 the benefits are limited due to the compiler using ``-pipe``. The
4638 build system goes to some lengths to avoid ``sync()`` calls into the
4639 file system on the principle that if there was a significant failure,
4640 the :term:`Build Directory`
4641 contents could easily be rebuilt.
4642
4643- Inheriting the
4644 :ref:`rm_work <ref-classes-rm-work>` class:
4645 Inheriting this class has shown to speed up builds due to
4646 significantly lower amounts of data stored in the data cache as well
4647 as on disk. Inheriting this class also makes cleanup of
4648 :term:`TMPDIR` faster, at the
4649 expense of being easily able to dive into the source code. File
4650 system maintainers have recommended that the fastest way to clean up
4651 large numbers of files is to reformat partitions rather than delete
4652 files due to the linear nature of partitions. This, of course,
4653 assumes you structure the disk partitions and file systems in a way
4654 that this is practical.
4655
4656Aside from the previous list, you should keep some trade offs in mind
4657that can help you speed up the build:
4658
4659- Remove items from
4660 :term:`DISTRO_FEATURES`
4661 that you might not need.
4662
4663- Exclude debug symbols and other debug information: If you do not need
4664 these symbols and other debug information, disabling the ``*-dbg``
4665 package generation can speed up the build. You can disable this
4666 generation by setting the
4667 :term:`INHIBIT_PACKAGE_DEBUG_SPLIT`
4668 variable to "1".
4669
4670- Disable static library generation for recipes derived from
4671 ``autoconf`` or ``libtool``: Following is an example showing how to
4672 disable static libraries and still provide an override to handle
4673 exceptions:
4674 ::
4675
4676 STATICLIBCONF = "--disable-static"
4677 STATICLIBCONF_sqlite3-native = ""
4678 EXTRA_OECONF += "${STATICLIBCONF}"
4679
4680 .. note::
4681
4682 - Some recipes need static libraries in order to work correctly
4683 (e.g. ``pseudo-native`` needs ``sqlite3-native``). Overrides,
4684 as in the previous example, account for these kinds of
4685 exceptions.
4686
4687 - Some packages have packaging code that assumes the presence of
4688 the static libraries. If so, you might need to exclude them as
4689 well.
4690
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004691Working With Libraries
4692======================
4693
4694Libraries are an integral part of your system. This section describes
4695some common practices you might find helpful when working with libraries
4696to build your system:
4697
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004698- :ref:`How to include static library files
4699 <dev-manual/common-tasks:including static library files>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004700
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004701- :ref:`How to use the Multilib feature to combine multiple versions of
4702 library files into a single image
4703 <dev-manual/common-tasks:combining multiple versions of library files into one image>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004704
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004705- :ref:`How to install multiple versions of the same library in parallel on
4706 the same system
4707 <dev-manual/common-tasks:installing multiple versions of the same library>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004708
4709Including Static Library Files
4710------------------------------
4711
4712If you are building a library and the library offers static linking, you
4713can control which static library files (``*.a`` files) get included in
4714the built library.
4715
4716The :term:`PACKAGES` and
4717:term:`FILES_* <FILES>` variables in the
4718``meta/conf/bitbake.conf`` configuration file define how files installed
4719by the ``do_install`` task are packaged. By default, the ``PACKAGES``
4720variable includes ``${PN}-staticdev``, which represents all static
4721library files.
4722
4723.. note::
4724
4725 Some previously released versions of the Yocto Project defined the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004726 static library files through ``${PN}-dev``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004727
4728Following is part of the BitBake configuration file, where you can see
4729how the static library files are defined:
4730::
4731
4732 PACKAGE_BEFORE_PN ?= ""
4733 PACKAGES = "${PN}-dbg ${PN}-staticdev ${PN}-dev ${PN}-doc ${PN}-locale ${PACKAGE_BEFORE_PN} ${PN}"
4734 PACKAGES_DYNAMIC = "^${PN}-locale-.*"
4735 FILES = ""
4736
4737 FILES_${PN} = "${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*${SOLIBS} \
4738 ${sysconfdir} ${sharedstatedir} ${localstatedir} \
4739 ${base_bindir}/* ${base_sbindir}/* \
4740 ${base_libdir}/*${SOLIBS} \
4741 ${base_prefix}/lib/udev/rules.d ${prefix}/lib/udev/rules.d \
4742 ${datadir}/${BPN} ${libdir}/${BPN}/* \
4743 ${datadir}/pixmaps ${datadir}/applications \
4744 ${datadir}/idl ${datadir}/omf ${datadir}/sounds \
4745 ${libdir}/bonobo/servers"
4746
4747 FILES_${PN}-bin = "${bindir}/* ${sbindir}/*"
4748
4749 FILES_${PN}-doc = "${docdir} ${mandir} ${infodir} ${datadir}/gtk-doc \
4750 ${datadir}/gnome/help"
4751 SECTION_${PN}-doc = "doc"
4752
4753 FILES_SOLIBSDEV ?= "${base_libdir}/lib*${SOLIBSDEV} ${libdir}/lib*${SOLIBSDEV}"
4754 FILES_${PN}-dev = "${includedir} ${FILES_SOLIBSDEV} ${libdir}/*.la \
4755 ${libdir}/*.o ${libdir}/pkgconfig ${datadir}/pkgconfig \
4756 ${datadir}/aclocal ${base_libdir}/*.o \
4757 ${libdir}/${BPN}/*.la ${base_libdir}/*.la"
4758 SECTION_${PN}-dev = "devel"
4759 ALLOW_EMPTY_${PN}-dev = "1"
4760 RDEPENDS_${PN}-dev = "${PN} (= ${EXTENDPKGV})"
4761
4762 FILES_${PN}-staticdev = "${libdir}/*.a ${base_libdir}/*.a ${libdir}/${BPN}/*.a"
4763 SECTION_${PN}-staticdev = "devel"
4764 RDEPENDS_${PN}-staticdev = "${PN}-dev (= ${EXTENDPKGV})"
4765
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004766Combining Multiple Versions of Library Files into One Image
4767-----------------------------------------------------------
4768
4769The build system offers the ability to build libraries with different
4770target optimizations or architecture formats and combine these together
4771into one system image. You can link different binaries in the image
4772against the different libraries as needed for specific use cases. This
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004773feature is called "Multilib".
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004774
4775An example would be where you have most of a system compiled in 32-bit
4776mode using 32-bit libraries, but you have something large, like a
4777database engine, that needs to be a 64-bit application and uses 64-bit
4778libraries. Multilib allows you to get the best of both 32-bit and 64-bit
4779libraries.
4780
4781While the Multilib feature is most commonly used for 32 and 64-bit
4782differences, the approach the build system uses facilitates different
4783target optimizations. You could compile some binaries to use one set of
4784libraries and other binaries to use a different set of libraries. The
4785libraries could differ in architecture, compiler options, or other
4786optimizations.
4787
4788Several examples exist in the ``meta-skeleton`` layer found in the
4789:term:`Source Directory`:
4790
4791- ``conf/multilib-example.conf`` configuration file
4792
4793- ``conf/multilib-example2.conf`` configuration file
4794
4795- ``recipes-multilib/images/core-image-multilib-example.bb`` recipe
4796
4797Preparing to Use Multilib
4798~~~~~~~~~~~~~~~~~~~~~~~~~
4799
4800User-specific requirements drive the Multilib feature. Consequently,
4801there is no one "out-of-the-box" configuration that likely exists to
4802meet your needs.
4803
4804In order to enable Multilib, you first need to ensure your recipe is
4805extended to support multiple libraries. Many standard recipes are
4806already extended and support multiple libraries. You can check in the
4807``meta/conf/multilib.conf`` configuration file in the
4808:term:`Source Directory` to see how this is
4809done using the
4810:term:`BBCLASSEXTEND` variable.
4811Eventually, all recipes will be covered and this list will not be
4812needed.
4813
4814For the most part, the Multilib class extension works automatically to
4815extend the package name from ``${PN}`` to ``${MLPREFIX}${PN}``, where
4816``MLPREFIX`` is the particular multilib (e.g. "lib32-" or "lib64-").
4817Standard variables such as
4818:term:`DEPENDS`,
4819:term:`RDEPENDS`,
4820:term:`RPROVIDES`,
4821:term:`RRECOMMENDS`,
4822:term:`PACKAGES`, and
4823:term:`PACKAGES_DYNAMIC` are
4824automatically extended by the system. If you are extending any manual
4825code in the recipe, you can use the ``${MLPREFIX}`` variable to ensure
4826those names are extended correctly. This automatic extension code
4827resides in ``multilib.bbclass``.
4828
4829Using Multilib
4830~~~~~~~~~~~~~~
4831
4832After you have set up the recipes, you need to define the actual
4833combination of multiple libraries you want to build. You accomplish this
4834through your ``local.conf`` configuration file in the
4835:term:`Build Directory`. An example
4836configuration would be as follows:
4837::
4838
4839 MACHINE = "qemux86-64"
4840 require conf/multilib.conf
4841 MULTILIBS = "multilib:lib32"
4842 DEFAULTTUNE_virtclass-multilib-lib32 = "x86"
4843 IMAGE_INSTALL_append = "lib32-glib-2.0"
4844
4845This example enables an additional library named
4846``lib32`` alongside the normal target packages. When combining these
4847"lib32" alternatives, the example uses "x86" for tuning. For information
4848on this particular tuning, see
4849``meta/conf/machine/include/ia32/arch-ia32.inc``.
4850
4851The example then includes ``lib32-glib-2.0`` in all the images, which
4852illustrates one method of including a multiple library dependency. You
4853can use a normal image build to include this dependency, for example:
4854::
4855
4856 $ bitbake core-image-sato
4857
4858You can also build Multilib packages
4859specifically with a command like this:
4860::
4861
4862 $ bitbake lib32-glib-2.0
4863
4864Additional Implementation Details
4865~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4866
4867Generic implementation details as well as details that are specific to
4868package management systems exist. Following are implementation details
4869that exist regardless of the package management system:
4870
4871- The typical convention used for the class extension code as used by
4872 Multilib assumes that all package names specified in
4873 :term:`PACKAGES` that contain
4874 ``${PN}`` have ``${PN}`` at the start of the name. When that
4875 convention is not followed and ``${PN}`` appears at the middle or the
4876 end of a name, problems occur.
4877
4878- The :term:`TARGET_VENDOR`
4879 value under Multilib will be extended to "-vendormlmultilib" (e.g.
4880 "-pokymllib32" for a "lib32" Multilib with Poky). The reason for this
4881 slightly unwieldy contraction is that any "-" characters in the
4882 vendor string presently break Autoconf's ``config.sub``, and other
4883 separators are problematic for different reasons.
4884
4885For the RPM Package Management System, the following implementation
4886details exist:
4887
4888- A unique architecture is defined for the Multilib packages, along
4889 with creating a unique deploy folder under ``tmp/deploy/rpm`` in the
4890 :term:`Build Directory`. For
4891 example, consider ``lib32`` in a ``qemux86-64`` image. The possible
4892 architectures in the system are "all", "qemux86_64",
4893 "lib32_qemux86_64", and "lib32_x86".
4894
4895- The ``${MLPREFIX}`` variable is stripped from ``${PN}`` during RPM
4896 packaging. The naming for a normal RPM package and a Multilib RPM
4897 package in a ``qemux86-64`` system resolves to something similar to
4898 ``bash-4.1-r2.x86_64.rpm`` and ``bash-4.1.r2.lib32_x86.rpm``,
4899 respectively.
4900
4901- When installing a Multilib image, the RPM backend first installs the
4902 base image and then installs the Multilib libraries.
4903
4904- The build system relies on RPM to resolve the identical files in the
4905 two (or more) Multilib packages.
4906
4907For the IPK Package Management System, the following implementation
4908details exist:
4909
4910- The ``${MLPREFIX}`` is not stripped from ``${PN}`` during IPK
4911 packaging. The naming for a normal RPM package and a Multilib IPK
4912 package in a ``qemux86-64`` system resolves to something like
4913 ``bash_4.1-r2.x86_64.ipk`` and ``lib32-bash_4.1-rw_x86.ipk``,
4914 respectively.
4915
4916- The IPK deploy folder is not modified with ``${MLPREFIX}`` because
4917 packages with and without the Multilib feature can exist in the same
4918 folder due to the ``${PN}`` differences.
4919
4920- IPK defines a sanity check for Multilib installation using certain
4921 rules for file comparison, overridden, etc.
4922
4923Installing Multiple Versions of the Same Library
4924------------------------------------------------
4925
4926Situations can exist where you need to install and use multiple versions
4927of the same library on the same system at the same time. These
4928situations almost always exist when a library API changes and you have
4929multiple pieces of software that depend on the separate versions of the
4930library. To accommodate these situations, you can install multiple
4931versions of the same library in parallel on the same system.
4932
4933The process is straightforward as long as the libraries use proper
4934versioning. With properly versioned libraries, all you need to do to
4935individually specify the libraries is create separate, appropriately
4936named recipes where the :term:`PN` part of
4937the name includes a portion that differentiates each library version
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004938(e.g. the major part of the version number). Thus, instead of having a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004939single recipe that loads one version of a library (e.g. ``clutter``),
4940you provide multiple recipes that result in different versions of the
4941libraries you want. As an example, the following two recipes would allow
4942the two separate versions of the ``clutter`` library to co-exist on the
4943same system:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004944
4945.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004946
4947 clutter-1.6_1.6.20.bb
4948 clutter-1.8_1.8.4.bb
4949
4950Additionally, if
4951you have other recipes that depend on a given library, you need to use
4952the :term:`DEPENDS` variable to
4953create the dependency. Continuing with the same example, if you want to
4954have a recipe depend on the 1.8 version of the ``clutter`` library, use
4955the following in your recipe:
4956::
4957
4958 DEPENDS = "clutter-1.8"
4959
4960Using x32 psABI
4961===============
4962
4963x32 processor-specific Application Binary Interface (`x32
4964psABI <https://software.intel.com/en-us/node/628948>`__) is a native
496532-bit processor-specific ABI for Intel 64 (x86-64) architectures. An
4966ABI defines the calling conventions between functions in a processing
4967environment. The interface determines what registers are used and what
4968the sizes are for various C data types.
4969
4970Some processing environments prefer using 32-bit applications even when
4971running on Intel 64-bit platforms. Consider the i386 psABI, which is a
4972very old 32-bit ABI for Intel 64-bit platforms. The i386 psABI does not
4973provide efficient use and access of the Intel 64-bit processor
4974resources, leaving the system underutilized. Now consider the x86_64
4975psABI. This ABI is newer and uses 64-bits for data sizes and program
4976pointers. The extra bits increase the footprint size of the programs,
4977libraries, and also increases the memory and file system size
4978requirements. Executing under the x32 psABI enables user programs to
4979utilize CPU and system resources more efficiently while keeping the
4980memory footprint of the applications low. Extra bits are used for
4981registers but not for addressing mechanisms.
4982
4983The Yocto Project supports the final specifications of x32 psABI as
4984follows:
4985
4986- You can create packages and images in x32 psABI format on x86_64
4987 architecture targets.
4988
4989- You can successfully build recipes with the x32 toolchain.
4990
4991- You can create and boot ``core-image-minimal`` and
4992 ``core-image-sato`` images.
4993
4994- RPM Package Manager (RPM) support exists for x32 binaries.
4995
4996- Support for large images exists.
4997
4998To use the x32 psABI, you need to edit your ``conf/local.conf``
4999configuration file as follows:
5000::
5001
5002 MACHINE = "qemux86-64"
5003 DEFAULTTUNE = "x86-64-x32"
5004 baselib = "${@d.getVar('BASE_LIB_tune-' + (d.getVar('DEFAULTTUNE') \
5005 or 'INVALID')) or 'lib'}"
5006
5007Once you have set
5008up your configuration file, use BitBake to build an image that supports
5009the x32 psABI. Here is an example:
5010::
5011
5012 $ bitbake core-image-sato
5013
5014Enabling GObject Introspection Support
5015======================================
5016
5017`GObject
5018introspection <https://wiki.gnome.org/Projects/GObjectIntrospection>`__
5019is the standard mechanism for accessing GObject-based software from
5020runtime environments. GObject is a feature of the GLib library that
5021provides an object framework for the GNOME desktop and related software.
5022GObject Introspection adds information to GObject that allows objects
5023created within it to be represented across different programming
5024languages. If you want to construct GStreamer pipelines using Python, or
5025control UPnP infrastructure using Javascript and GUPnP, GObject
5026introspection is the only way to do it.
5027
5028This section describes the Yocto Project support for generating and
5029packaging GObject introspection data. GObject introspection data is a
5030description of the API provided by libraries built on top of GLib
5031framework, and, in particular, that framework's GObject mechanism.
5032GObject Introspection Repository (GIR) files go to ``-dev`` packages,
5033``typelib`` files go to main packages as they are packaged together with
5034libraries that are introspected.
5035
5036The data is generated when building such a library, by linking the
5037library with a small executable binary that asks the library to describe
5038itself, and then executing the binary and processing its output.
5039
5040Generating this data in a cross-compilation environment is difficult
5041because the library is produced for the target architecture, but its
5042code needs to be executed on the build host. This problem is solved with
5043the OpenEmbedded build system by running the code through QEMU, which
5044allows precisely that. Unfortunately, QEMU does not always work
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05005045perfectly as mentioned in the ":ref:`dev-manual/common-tasks:known issues`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005046section.
5047
5048Enabling the Generation of Introspection Data
5049---------------------------------------------
5050
5051Enabling the generation of introspection data (GIR files) in your
5052library package involves the following:
5053
50541. Inherit the
5055 :ref:`gobject-introspection <ref-classes-gobject-introspection>`
5056 class.
5057
50582. Make sure introspection is not disabled anywhere in the recipe or
5059 from anything the recipe includes. Also, make sure that
5060 "gobject-introspection-data" is not in
5061 :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`
5062 and that "qemu-usermode" is not in
5063 :term:`MACHINE_FEATURES_BACKFILL_CONSIDERED`.
5064 If either of these conditions exist, nothing will happen.
5065
50663. Try to build the recipe. If you encounter build errors that look like
5067 something is unable to find ``.so`` libraries, check where these
5068 libraries are located in the source tree and add the following to the
5069 recipe:
5070 ::
5071
5072 GIR_EXTRA_LIBS_PATH = "${B}/something/.libs"
5073
5074 .. note::
5075
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005076 See recipes in the ``oe-core`` repository that use that
5077 ``GIR_EXTRA_LIBS_PATH`` variable as an example.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005078
50794. Look for any other errors, which probably mean that introspection
5080 support in a package is not entirely standard, and thus breaks down
5081 in a cross-compilation environment. For such cases, custom-made fixes
5082 are needed. A good place to ask and receive help in these cases is
5083 the :ref:`Yocto Project mailing
5084 lists <resources-mailinglist>`.
5085
5086.. note::
5087
5088 Using a library that no longer builds against the latest Yocto
5089 Project release and prints introspection related errors is a good
5090 candidate for the previous procedure.
5091
5092Disabling the Generation of Introspection Data
5093----------------------------------------------
5094
5095You might find that you do not want to generate introspection data. Or,
5096perhaps QEMU does not work on your build host and target architecture
5097combination. If so, you can use either of the following methods to
5098disable GIR file generations:
5099
5100- Add the following to your distro configuration:
5101 ::
5102
5103 DISTRO_FEATURES_BACKFILL_CONSIDERED = "gobject-introspection-data"
5104
5105 Adding this statement disables generating introspection data using
5106 QEMU but will still enable building introspection tools and libraries
5107 (i.e. building them does not require the use of QEMU).
5108
5109- Add the following to your machine configuration:
5110 ::
5111
5112 MACHINE_FEATURES_BACKFILL_CONSIDERED = "qemu-usermode"
5113
5114 Adding this statement disables the use of QEMU when building packages for your
5115 machine. Currently, this feature is used only by introspection
5116 recipes and has the same effect as the previously described option.
5117
5118 .. note::
5119
5120 Future releases of the Yocto Project might have other features
5121 affected by this option.
5122
5123If you disable introspection data, you can still obtain it through other
5124means such as copying the data from a suitable sysroot, or by generating
5125it on the target hardware. The OpenEmbedded build system does not
5126currently provide specific support for these techniques.
5127
5128Testing that Introspection Works in an Image
5129--------------------------------------------
5130
5131Use the following procedure to test if generating introspection data is
5132working in an image:
5133
51341. Make sure that "gobject-introspection-data" is not in
5135 :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`
5136 and that "qemu-usermode" is not in
5137 :term:`MACHINE_FEATURES_BACKFILL_CONSIDERED`.
5138
51392. Build ``core-image-sato``.
5140
51413. Launch a Terminal and then start Python in the terminal.
5142
51434. Enter the following in the terminal:
5144 ::
5145
5146 >>> from gi.repository import GLib
5147 >>> GLib.get_host_name()
5148
51495. For something a little more advanced, enter the following see:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005150 https://python-gtk-3-tutorial.readthedocs.io/en/latest/introduction.html
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005151
5152Known Issues
5153------------
5154
5155The following know issues exist for GObject Introspection Support:
5156
5157- ``qemu-ppc64`` immediately crashes. Consequently, you cannot build
5158 introspection data on that architecture.
5159
5160- x32 is not supported by QEMU. Consequently, introspection data is
5161 disabled.
5162
5163- musl causes transient GLib binaries to crash on assertion failures.
5164 Consequently, generating introspection data is disabled.
5165
5166- Because QEMU is not able to run the binaries correctly, introspection
5167 is disabled for some specific packages under specific architectures
5168 (e.g. ``gcr``, ``libsecret``, and ``webkit``).
5169
5170- QEMU usermode might not work properly when running 64-bit binaries
5171 under 32-bit host machines. In particular, "qemumips64" is known to
5172 not work under i686.
5173
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005174Optionally Using an External Toolchain
5175======================================
5176
5177You might want to use an external toolchain as part of your development.
5178If this is the case, the fundamental steps you need to accomplish are as
5179follows:
5180
5181- Understand where the installed toolchain resides. For cases where you
5182 need to build the external toolchain, you would need to take separate
5183 steps to build and install the toolchain.
5184
5185- Make sure you add the layer that contains the toolchain to your
5186 ``bblayers.conf`` file through the
5187 :term:`BBLAYERS` variable.
5188
5189- Set the ``EXTERNAL_TOOLCHAIN`` variable in your ``local.conf`` file
5190 to the location in which you installed the toolchain.
5191
5192A good example of an external toolchain used with the Yocto Project is
5193Mentor Graphics Sourcery G++ Toolchain. You can see information on how
5194to use that particular layer in the ``README`` file at
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005195https://github.com/MentorEmbedded/meta-sourcery/. You can find
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005196further information by reading about the
5197:term:`TCMODE` variable in the Yocto
5198Project Reference Manual's variable glossary.
5199
5200Creating Partitioned Images Using Wic
5201=====================================
5202
5203Creating an image for a particular hardware target using the
5204OpenEmbedded build system does not necessarily mean you can boot that
5205image as is on your device. Physical devices accept and boot images in
5206various ways depending on the specifics of the device. Usually,
5207information about the hardware can tell you what image format the device
5208requires. Should your device require multiple partitions on an SD card,
5209flash, or an HDD, you can use the OpenEmbedded Image Creator, Wic, to
5210create the properly partitioned image.
5211
5212The ``wic`` command generates partitioned images from existing
5213OpenEmbedded build artifacts. Image generation is driven by partitioning
5214commands contained in an Openembedded kickstart file (``.wks``)
5215specified either directly on the command line or as one of a selection
5216of canned kickstart files as shown with the ``wic list images`` command
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05005217in the
5218":ref:`dev-manual/common-tasks:generate an image using an existing kickstart file`"
5219section. When you apply the command to a given set of build artifacts, the
5220result is an image or set of images that can be directly written onto media and
5221used on a particular system.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005222
5223.. note::
5224
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005225 For a kickstart file reference, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06005226 ":ref:`ref-manual/kickstart:openembedded kickstart (\`\`.wks\`\`) reference`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005227 Chapter in the Yocto Project Reference Manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005228
5229The ``wic`` command and the infrastructure it is based on is by
5230definition incomplete. The purpose of the command is to allow the
5231generation of customized images, and as such, was designed to be
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05005232completely extensible through a plugin interface. See the
5233":ref:`dev-manual/common-tasks:using the wic plugin interface`" section
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005234for information on these plugins.
5235
5236This section provides some background information on Wic, describes what
5237you need to have in place to run the tool, provides instruction on how
5238to use the Wic utility, provides information on using the Wic plugins
5239interface, and provides several examples that show how to use Wic.
5240
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005241Background
5242----------
5243
5244This section provides some background on the Wic utility. While none of
5245this information is required to use Wic, you might find it interesting.
5246
5247- The name "Wic" is derived from OpenEmbedded Image Creator (oeic). The
5248 "oe" diphthong in "oeic" was promoted to the letter "w", because
5249 "oeic" is both difficult to remember and to pronounce.
5250
5251- Wic is loosely based on the Meego Image Creator (``mic``) framework.
5252 The Wic implementation has been heavily modified to make direct use
5253 of OpenEmbedded build artifacts instead of package installation and
5254 configuration, which are already incorporated within the OpenEmbedded
5255 artifacts.
5256
5257- Wic is a completely independent standalone utility that initially
5258 provides easier-to-use and more flexible replacements for an existing
5259 functionality in OE-Core's
5260 :ref:`image-live <ref-classes-image-live>`
5261 class. The difference between Wic and those examples is that with Wic
5262 the functionality of those scripts is implemented by a
5263 general-purpose partitioning language, which is based on Redhat
5264 kickstart syntax.
5265
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005266Requirements
5267------------
5268
5269In order to use the Wic utility with the OpenEmbedded Build system, your
5270system needs to meet the following requirements:
5271
5272- The Linux distribution on your development host must support the
5273 Yocto Project. See the ":ref:`detailed-supported-distros`"
5274 section in the Yocto Project Reference Manual for the list of
5275 distributions that support the Yocto Project.
5276
5277- The standard system utilities, such as ``cp``, must be installed on
5278 your development host system.
5279
5280- You must have sourced the build environment setup script (i.e.
5281 :ref:`structure-core-script`) found in the
5282 :term:`Build Directory`.
5283
5284- You need to have the build artifacts already available, which
5285 typically means that you must have already created an image using the
5286 Openembedded build system (e.g. ``core-image-minimal``). While it
5287 might seem redundant to generate an image in order to create an image
5288 using Wic, the current version of Wic requires the artifacts in the
5289 form generated by the OpenEmbedded build system.
5290
5291- You must build several native tools, which are built to run on the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005292 build system:
5293 ::
5294
5295 $ bitbake parted-native dosfstools-native mtools-native
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005296
5297- Include "wic" as part of the
5298 :term:`IMAGE_FSTYPES`
5299 variable.
5300
5301- Include the name of the :ref:`wic kickstart file <openembedded-kickstart-wks-reference>`
5302 as part of the :term:`WKS_FILE` variable
5303
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005304Getting Help
5305------------
5306
5307You can get general help for the ``wic`` command by entering the ``wic``
5308command by itself or by entering the command with a help argument as
5309follows:
5310::
5311
5312 $ wic -h
5313 $ wic --help
5314 $ wic help
5315
5316Currently, Wic supports seven commands: ``cp``, ``create``, ``help``,
5317``list``, ``ls``, ``rm``, and ``write``. You can get help for all these
5318commands except "help" by using the following form:
5319::
5320
5321 $ wic help command
5322
5323For example, the following command returns help for the ``write``
5324command:
5325::
5326
5327 $ wic help write
5328
5329Wic supports help for three topics: ``overview``, ``plugins``, and
5330``kickstart``. You can get help for any topic using the following form:
5331::
5332
5333 $ wic help topic
5334
5335For example, the following returns overview help for Wic:
5336::
5337
5338 $ wic help overview
5339
5340One additional level of help exists for Wic. You can get help on
5341individual images through the ``list`` command. You can use the ``list``
5342command to return the available Wic images as follows:
5343::
5344
5345 $ wic list images
5346 genericx86 Create an EFI disk image for genericx86*
5347 beaglebone-yocto Create SD card image for Beaglebone
5348 edgerouter Create SD card image for Edgerouter
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05005349 qemux86-directdisk Create a QEMU machine 'pcbios' direct disk image
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005350 directdisk-gpt Create a 'pcbios' direct disk image
5351 mkefidisk Create an EFI disk image
5352 directdisk Create a 'pcbios' direct disk image
5353 systemd-bootdisk Create an EFI disk image with systemd-boot
5354 mkhybridiso Create a hybrid ISO image
5355 sdimage-bootpart Create SD card image with a boot partition
5356 directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
5357 directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
5358
5359Once you know the list of available
5360Wic images, you can use ``help`` with the command to get help on a
5361particular image. For example, the following command returns help on the
5362"beaglebone-yocto" image:
5363::
5364
5365 $ wic list beaglebone-yocto help
5366
5367 Creates a partitioned SD card image for Beaglebone.
5368 Boot files are located in the first vfat partition.
5369
5370Operational Modes
5371-----------------
5372
5373You can use Wic in two different modes, depending on how much control
5374you need for specifying the Openembedded build artifacts that are used
5375for creating the image: Raw and Cooked:
5376
5377- *Raw Mode:* You explicitly specify build artifacts through Wic
5378 command-line arguments.
5379
5380- *Cooked Mode:* The current
5381 :term:`MACHINE` setting and image
5382 name are used to automatically locate and provide the build
5383 artifacts. You just supply a kickstart file and the name of the image
5384 from which to use artifacts.
5385
5386Regardless of the mode you use, you need to have the build artifacts
5387ready and available.
5388
5389Raw Mode
5390~~~~~~~~
5391
5392Running Wic in raw mode allows you to specify all the partitions through
5393the ``wic`` command line. The primary use for raw mode is if you have
5394built your kernel outside of the Yocto Project
5395:term:`Build Directory`. In other words, you
5396can point to arbitrary kernel, root filesystem locations, and so forth.
5397Contrast this behavior with cooked mode where Wic looks in the Build
5398Directory (e.g. ``tmp/deploy/images/``\ machine).
5399
5400The general form of the ``wic`` command in raw mode is:
5401::
5402
5403 $ wic create wks_file options ...
5404
5405 Where:
5406
5407 wks_file:
5408 An OpenEmbedded kickstart file. You can provide
5409 your own custom file or use a file from a set of
5410 existing files as described by further options.
5411
5412 optional arguments:
5413 -h, --help show this help message and exit
5414 -o OUTDIR, --outdir OUTDIR
5415 name of directory to create image in
5416 -e IMAGE_NAME, --image-name IMAGE_NAME
5417 name of the image to use the artifacts from e.g. core-
5418 image-sato
5419 -r ROOTFS_DIR, --rootfs-dir ROOTFS_DIR
5420 path to the /rootfs dir to use as the .wks rootfs
5421 source
5422 -b BOOTIMG_DIR, --bootimg-dir BOOTIMG_DIR
5423 path to the dir containing the boot artifacts (e.g.
5424 /EFI or /syslinux dirs) to use as the .wks bootimg
5425 source
5426 -k KERNEL_DIR, --kernel-dir KERNEL_DIR
5427 path to the dir containing the kernel to use in the
5428 .wks bootimg
5429 -n NATIVE_SYSROOT, --native-sysroot NATIVE_SYSROOT
5430 path to the native sysroot containing the tools to use
5431 to build the image
5432 -s, --skip-build-check
5433 skip the build check
5434 -f, --build-rootfs build rootfs
5435 -c {gzip,bzip2,xz}, --compress-with {gzip,bzip2,xz}
5436 compress image with specified compressor
5437 -m, --bmap generate .bmap
5438 --no-fstab-update Do not change fstab file.
5439 -v VARS_DIR, --vars VARS_DIR
5440 directory with <image>.env files that store bitbake
5441 variables
5442 -D, --debug output debug information
5443
5444.. note::
5445
5446 You do not need root privileges to run Wic. In fact, you should not
5447 run as root when using the utility.
5448
5449Cooked Mode
5450~~~~~~~~~~~
5451
5452Running Wic in cooked mode leverages off artifacts in the Build
5453Directory. In other words, you do not have to specify kernel or root
5454filesystem locations as part of the command. All you need to provide is
5455a kickstart file and the name of the image from which to use artifacts
5456by using the "-e" option. Wic looks in the Build Directory (e.g.
5457``tmp/deploy/images/``\ machine) for artifacts.
5458
5459The general form of the ``wic`` command using Cooked Mode is as follows:
5460::
5461
5462 $ wic create wks_file -e IMAGE_NAME
5463
5464 Where:
5465
5466 wks_file:
5467 An OpenEmbedded kickstart file. You can provide
5468 your own custom file or use a file from a set of
5469 existing files provided with the Yocto Project
5470 release.
5471
5472 required argument:
5473 -e IMAGE_NAME, --image-name IMAGE_NAME
5474 name of the image to use the artifacts from e.g. core-
5475 image-sato
5476
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005477Using an Existing Kickstart File
5478--------------------------------
5479
5480If you do not want to create your own kickstart file, you can use an
5481existing file provided by the Wic installation. As shipped, kickstart
Andrew Geissler09209ee2020-12-13 08:44:15 -06005482files can be found in the :ref:`overview-manual/development-environment:yocto project source repositories` in the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005483following two locations:
5484::
5485
5486 poky/meta-yocto-bsp/wic
5487 poky/scripts/lib/wic/canned-wks
5488
5489Use the following command to list the available kickstart files:
5490::
5491
5492 $ wic list images
5493 genericx86 Create an EFI disk image for genericx86*
5494 beaglebone-yocto Create SD card image for Beaglebone
5495 edgerouter Create SD card image for Edgerouter
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05005496 qemux86-directdisk Create a QEMU machine 'pcbios' direct disk image
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005497 directdisk-gpt Create a 'pcbios' direct disk image
5498 mkefidisk Create an EFI disk image
5499 directdisk Create a 'pcbios' direct disk image
5500 systemd-bootdisk Create an EFI disk image with systemd-boot
5501 mkhybridiso Create a hybrid ISO image
5502 sdimage-bootpart Create SD card image with a boot partition
5503 directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
5504 directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
5505
5506When you use an existing file, you
5507do not have to use the ``.wks`` extension. Here is an example in Raw
5508Mode that uses the ``directdisk`` file:
5509::
5510
5511 $ wic create directdisk -r rootfs_dir -b bootimg_dir \
5512 -k kernel_dir -n native_sysroot
5513
5514Here are the actual partition language commands used in the
5515``genericx86.wks`` file to generate an image:
5516::
5517
5518 # short-description: Create an EFI disk image for genericx86*
5519 # long-description: Creates a partitioned EFI disk image for genericx86* machines
5520 part /boot --source bootimg-efi --sourceparams="loader=grub-efi" --ondisk sda --label msdos --active --align 1024
5521 part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid
5522 part swap --ondisk sda --size 44 --label swap1 --fstype=swap
5523
5524 bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=ttyS0,115200 console=tty0"
5525
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005526Using the Wic Plugin Interface
5527------------------------------
5528
5529You can extend and specialize Wic functionality by using Wic plugins.
5530This section explains the Wic plugin interface.
5531
5532.. note::
5533
5534 Wic plugins consist of "source" and "imager" plugins. Imager plugins
5535 are beyond the scope of this section.
5536
5537Source plugins provide a mechanism to customize partition content during
5538the Wic image generation process. You can use source plugins to map
5539values that you specify using ``--source`` commands in kickstart files
5540(i.e. ``*.wks``) to a plugin implementation used to populate a given
5541partition.
5542
5543.. note::
5544
5545 If you use plugins that have build-time dependencies (e.g. native
5546 tools, bootloaders, and so forth) when building a Wic image, you need
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005547 to specify those dependencies using the :term:`WKS_FILE_DEPENDS`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005548 variable.
5549
5550Source plugins are subclasses defined in plugin files. As shipped, the
5551Yocto Project provides several plugin files. You can see the source
5552plugin files that ship with the Yocto Project
Andrew Geissler09209ee2020-12-13 08:44:15 -06005553:yocto_git:`here </poky/tree/scripts/lib/wic/plugins/source>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005554Each of these plugin files contains source plugins that are designed to
5555populate a specific Wic image partition.
5556
5557Source plugins are subclasses of the ``SourcePlugin`` class, which is
5558defined in the ``poky/scripts/lib/wic/pluginbase.py`` file. For example,
5559the ``BootimgEFIPlugin`` source plugin found in the ``bootimg-efi.py``
5560file is a subclass of the ``SourcePlugin`` class, which is found in the
5561``pluginbase.py`` file.
5562
5563You can also implement source plugins in a layer outside of the Source
5564Repositories (external layer). To do so, be sure that your plugin files
5565are located in a directory whose path is
5566``scripts/lib/wic/plugins/source/`` within your external layer. When the
5567plugin files are located there, the source plugins they contain are made
5568available to Wic.
5569
5570When the Wic implementation needs to invoke a partition-specific
5571implementation, it looks for the plugin with the same name as the
5572``--source`` parameter used in the kickstart file given to that
5573partition. For example, if the partition is set up using the following
5574command in a kickstart file:
5575::
5576
5577 part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024
5578
5579The methods defined as class
5580members of the matching source plugin (i.e. ``bootimg-pcbios``) in the
5581``bootimg-pcbios.py`` plugin file are used.
5582
5583To be more concrete, here is the corresponding plugin definition from
5584the ``bootimg-pcbios.py`` file for the previous command along with an
5585example method called by the Wic implementation when it needs to prepare
5586a partition using an implementation-specific function:
5587::
5588
5589 .
5590 .
5591 .
5592 class BootimgPcbiosPlugin(SourcePlugin):
5593 """
5594 Create MBR boot partition and install syslinux on it.
5595 """
5596
5597 name = 'bootimg-pcbios'
5598 .
5599 .
5600 .
5601 @classmethod
5602 def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
5603 oe_builddir, bootimg_dir, kernel_dir,
5604 rootfs_dir, native_sysroot):
5605 """
5606 Called to do the actual content population for a partition i.e. it
5607 'prepares' the partition to be incorporated into the image.
5608 In this case, prepare content for legacy bios boot partition.
5609 """
5610 .
5611 .
5612 .
5613
5614If a
5615subclass (plugin) itself does not implement a particular function, Wic
5616locates and uses the default version in the superclass. It is for this
5617reason that all source plugins are derived from the ``SourcePlugin``
5618class.
5619
5620The ``SourcePlugin`` class defined in the ``pluginbase.py`` file defines
5621a set of methods that source plugins can implement or override. Any
5622plugins (subclass of ``SourcePlugin``) that do not implement a
5623particular method inherit the implementation of the method from the
5624``SourcePlugin`` class. For more information, see the ``SourcePlugin``
5625class in the ``pluginbase.py`` file for details:
5626
5627The following list describes the methods implemented in the
5628``SourcePlugin`` class:
5629
5630- ``do_prepare_partition()``: Called to populate a partition with
5631 actual content. In other words, the method prepares the final
5632 partition image that is incorporated into the disk image.
5633
5634- ``do_configure_partition()``: Called before
5635 ``do_prepare_partition()`` to create custom configuration files for a
5636 partition (e.g. syslinux or grub configuration files).
5637
5638- ``do_install_disk()``: Called after all partitions have been
5639 prepared and assembled into a disk image. This method provides a hook
5640 to allow finalization of a disk image (e.g. writing an MBR).
5641
5642- ``do_stage_partition()``: Special content-staging hook called
5643 before ``do_prepare_partition()``. This method is normally empty.
5644
5645 Typically, a partition just uses the passed-in parameters (e.g. the
5646 unmodified value of ``bootimg_dir``). However, in some cases, things
5647 might need to be more tailored. As an example, certain files might
5648 additionally need to be taken from ``bootimg_dir + /boot``. This hook
5649 allows those files to be staged in a customized fashion.
5650
5651 .. note::
5652
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005653 ``get_bitbake_var()`` allows you to access non-standard variables that
5654 you might want to use for this behavior.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005655
5656You can extend the source plugin mechanism. To add more hooks, create
5657more source plugin methods within ``SourcePlugin`` and the corresponding
5658derived subclasses. The code that calls the plugin methods uses the
5659``plugin.get_source_plugin_methods()`` function to find the method or
5660methods needed by the call. Retrieval of those methods is accomplished
5661by filling up a dict with keys that contain the method names of
5662interest. On success, these will be filled in with the actual methods.
5663See the Wic implementation for examples and details.
5664
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005665Wic Examples
5666------------
5667
5668This section provides several examples that show how to use the Wic
5669utility. All the examples assume the list of requirements in the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05005670":ref:`dev-manual/common-tasks:requirements`" section have been met. The
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005671examples assume the previously generated image is
5672``core-image-minimal``.
5673
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005674Generate an Image using an Existing Kickstart File
5675~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5676
5677This example runs in Cooked Mode and uses the ``mkefidisk`` kickstart
5678file:
5679::
5680
5681 $ wic create mkefidisk -e core-image-minimal
5682 INFO: Building wic-tools...
5683 .
5684 .
5685 .
5686 INFO: The new image(s) can be found here:
5687 ./mkefidisk-201804191017-sda.direct
5688
5689 The following build artifacts were used to create the image(s):
5690 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
5691 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
5692 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
5693 NATIVE_SYSROOT: /home/stephano/build/master/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
5694
5695 INFO: The image(s) were created using OE kickstart file:
5696 /home/stephano/build/master/openembedded-core/scripts/lib/wic/canned-wks/mkefidisk.wks
5697
5698The previous example shows the easiest way to create an image by running
5699in cooked mode and supplying a kickstart file and the "-e" option to
5700point to the existing build artifacts. Your ``local.conf`` file needs to
5701have the :term:`MACHINE` variable set
5702to the machine you are using, which is "qemux86" in this example.
5703
5704Once the image builds, the output provides image location, artifact use,
5705and kickstart file information.
5706
5707.. note::
5708
5709 You should always verify the details provided in the output to make
5710 sure that the image was indeed created exactly as expected.
5711
5712Continuing with the example, you can now write the image from the Build
5713Directory onto a USB stick, or whatever media for which you built your
5714image, and boot from the media. You can write the image by using
5715``bmaptool`` or ``dd``:
5716::
5717
5718 $ oe-run-native bmaptool copy mkefidisk-201804191017-sda.direct /dev/sdX
5719
5720or ::
5721
5722 $ sudo dd if=mkefidisk-201804191017-sda.direct of=/dev/sdX
5723
5724.. note::
5725
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005726 For more information on how to use the ``bmaptool``
5727 to flash a device with an image, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06005728 ":ref:`dev-manual/common-tasks:flashing images using \`\`bmaptool\`\``"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005729 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005730
5731Using a Modified Kickstart File
5732~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5733
5734Because partitioned image creation is driven by the kickstart file, it
5735is easy to affect image creation by changing the parameters in the file.
5736This next example demonstrates that through modification of the
5737``directdisk-gpt`` kickstart file.
5738
5739As mentioned earlier, you can use the command ``wic list images`` to
5740show the list of existing kickstart files. The directory in which the
5741``directdisk-gpt.wks`` file resides is
5742``scripts/lib/image/canned-wks/``, which is located in the
5743:term:`Source Directory` (e.g. ``poky``).
5744Because available files reside in this directory, you can create and add
5745your own custom files to the directory. Subsequent use of the
5746``wic list images`` command would then include your kickstart files.
5747
5748In this example, the existing ``directdisk-gpt`` file already does most
5749of what is needed. However, for the hardware in this example, the image
5750will need to boot from ``sdb`` instead of ``sda``, which is what the
5751``directdisk-gpt`` kickstart file uses.
5752
5753The example begins by making a copy of the ``directdisk-gpt.wks`` file
5754in the ``scripts/lib/image/canned-wks`` directory and then by changing
5755the lines that specify the target disk from which to boot.
5756::
5757
5758 $ cp /home/stephano/poky/scripts/lib/wic/canned-wks/directdisk-gpt.wks \
5759 /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
5760
5761Next, the example modifies the ``directdisksdb-gpt.wks`` file and
5762changes all instances of "``--ondisk sda``" to "``--ondisk sdb``". The
5763example changes the following two lines and leaves the remaining lines
5764untouched:
5765::
5766
5767 part /boot --source bootimg-pcbios --ondisk sdb --label boot --active --align 1024
5768 part / --source rootfs --ondisk sdb --fstype=ext4 --label platform --align 1024 --use-uuid
5769
5770Once the lines are changed, the
5771example generates the ``directdisksdb-gpt`` image. The command points
5772the process at the ``core-image-minimal`` artifacts for the Next Unit of
5773Computing (nuc) :term:`MACHINE` the
5774``local.conf``.
5775::
5776
5777 $ wic create directdisksdb-gpt -e core-image-minimal
5778 INFO: Building wic-tools...
5779 .
5780 .
5781 .
5782 Initialising tasks: 100% |#######################################| Time: 0:00:01
5783 NOTE: Executing SetScene Tasks
5784 NOTE: Executing RunQueue Tasks
5785 NOTE: Tasks Summary: Attempted 1161 tasks of which 1157 didn't need to be rerun and all succeeded.
5786 INFO: Creating image(s)...
5787
5788 INFO: The new image(s) can be found here:
5789 ./directdisksdb-gpt-201710090938-sdb.direct
5790
5791 The following build artifacts were used to create the image(s):
5792 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
5793 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
5794 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
5795 NATIVE_SYSROOT: /home/stephano/build/master/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
5796
5797 INFO: The image(s) were created using OE kickstart file:
5798 /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
5799
5800Continuing with the example, you can now directly ``dd`` the image to a
5801USB stick, or whatever media for which you built your image, and boot
5802the resulting media:
5803::
5804
5805 $ sudo dd if=directdisksdb-gpt-201710090938-sdb.direct of=/dev/sdb
5806 140966+0 records in
5807 140966+0 records out
5808 72174592 bytes (72 MB, 69 MiB) copied, 78.0282 s, 925 kB/s
5809 $ sudo eject /dev/sdb
5810
5811Using a Modified Kickstart File and Running in Raw Mode
5812~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5813
5814This next example manually specifies each build artifact (runs in Raw
5815Mode) and uses a modified kickstart file. The example also uses the
5816``-o`` option to cause Wic to create the output somewhere other than the
5817default output directory, which is the current directory:
5818::
5819
5820 $ wic create /home/stephano/my_yocto/test.wks -o /home/stephano/testwic \
5821 --rootfs-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/rootfs \
5822 --bootimg-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share \
5823 --kernel-dir /home/stephano/build/master/build/tmp/deploy/images/qemux86 \
5824 --native-sysroot /home/stephano/build/master/build/tmp/work/i586-poky-linux/wic-tools/1.0-r0/recipe-sysroot-native
5825
5826 INFO: Creating image(s)...
5827
5828 INFO: The new image(s) can be found here:
5829 /home/stephano/testwic/test-201710091445-sdb.direct
5830
5831 The following build artifacts were used to create the image(s):
5832 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
5833 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
5834 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
5835 NATIVE_SYSROOT: /home/stephano/build/master/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
5836
5837 INFO: The image(s) were created using OE kickstart file:
5838 /home/stephano/my_yocto/test.wks
5839
5840For this example,
5841:term:`MACHINE` did not have to be
5842specified in the ``local.conf`` file since the artifact is manually
5843specified.
5844
5845Using Wic to Manipulate an Image
5846~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5847
5848Wic image manipulation allows you to shorten turnaround time during
5849image development. For example, you can use Wic to delete the kernel
5850partition of a Wic image and then insert a newly built kernel. This
5851saves you time from having to rebuild the entire image each time you
5852modify the kernel.
5853
5854.. note::
5855
5856 In order to use Wic to manipulate a Wic image as in this example,
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005857 your development machine must have the ``mtools`` package installed.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005858
5859The following example examines the contents of the Wic image, deletes
5860the existing kernel, and then inserts a new kernel:
5861
58621. *List the Partitions:* Use the ``wic ls`` command to list all the
5863 partitions in the Wic image:
5864 ::
5865
5866 $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic
5867 Num Start End Size Fstype
5868 1 1048576 25041919 23993344 fat16
5869 2 25165824 72157183 46991360 ext4
5870
5871 The previous output shows two partitions in the
5872 ``core-image-minimal-qemux86.wic`` image.
5873
58742. *Examine a Particular Partition:* Use the ``wic ls`` command again
5875 but in a different form to examine a particular partition.
5876
5877 .. note::
5878
5879 You can get command usage on any Wic command using the following
5880 form:
5881 ::
5882
5883 $ wic help command
5884
5885
5886 For example, the following command shows you the various ways to
5887 use the
5888 wic ls
5889 command:
5890 ::
5891
5892 $ wic help ls
5893
5894
Andrew Geissler95ac1b82021-03-31 14:34:31 -05005895 The following command shows what is in partition one:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005896 ::
5897
5898 $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1
5899 Volume in drive : is boot
5900 Volume Serial Number is E894-1809
5901 Directory for ::/
5902
5903 libcom32 c32 186500 2017-10-09 16:06
5904 libutil c32 24148 2017-10-09 16:06
5905 syslinux cfg 220 2017-10-09 16:06
5906 vesamenu c32 27104 2017-10-09 16:06
5907 vmlinuz 6904608 2017-10-09 16:06
5908 5 files 7 142 580 bytes
5909 16 582 656 bytes free
5910
5911 The previous output shows five files, with the
5912 ``vmlinuz`` being the kernel.
5913
5914 .. note::
5915
5916 If you see the following error, you need to update or create a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005917 ``~/.mtoolsrc`` file and be sure to have the line "mtools_skip_check=1"
5918 in the file. Then, run the Wic command again:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005919 ::
5920
5921 ERROR: _exec_cmd: /usr/bin/mdir -i /tmp/wic-parttfokuwra ::/ returned '1' instead of 0
5922 output: Total number of sectors (47824) not a multiple of sectors per track (32)!
5923 Add mtools_skip_check=1 to your .mtoolsrc file to skip this test
5924
5925
59263. *Remove the Old Kernel:* Use the ``wic rm`` command to remove the
5927 ``vmlinuz`` file (kernel):
5928 ::
5929
5930 $ wic rm tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
5931
59324. *Add In the New Kernel:* Use the ``wic cp`` command to add the
5933 updated kernel to the Wic image. Depending on how you built your
5934 kernel, it could be in different places. If you used ``devtool`` and
5935 an SDK to build your kernel, it resides in the ``tmp/work`` directory
5936 of the extensible SDK. If you used ``make`` to build the kernel, the
5937 kernel will be in the ``workspace/sources`` area.
5938
5939 The following example assumes ``devtool`` was used to build the
5940 kernel:
5941 ::
5942
Andrew Geissler95ac1b82021-03-31 14:34:31 -05005943 $ wic 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 \
5944 poky/build/tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005945
5946 Once the new kernel is added back into the image, you can use the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005947 ``dd`` command or :ref:`bmaptool
Andrew Geissler09209ee2020-12-13 08:44:15 -06005948 <dev-manual/common-tasks:flashing images using \`\`bmaptool\`\`>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005949 to flash your wic image onto an SD card or USB stick and test your
5950 target.
5951
5952 .. note::
5953
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005954 Using ``bmaptool`` is generally 10 to 20 times faster than using ``dd``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005955
5956Flashing Images Using ``bmaptool``
5957==================================
5958
5959A fast and easy way to flash an image to a bootable device is to use
5960Bmaptool, which is integrated into the OpenEmbedded build system.
5961Bmaptool is a generic tool that creates a file's block map (bmap) and
5962then uses that map to copy the file. As compared to traditional tools
5963such as dd or cp, Bmaptool can copy (or flash) large files like raw
5964system image files much faster.
5965
5966.. note::
5967
5968 - If you are using Ubuntu or Debian distributions, you can install
5969 the ``bmap-tools`` package using the following command and then
5970 use the tool without specifying ``PATH`` even from the root
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005971 account:
5972 ::
5973
5974 $ sudo apt-get install bmap-tools
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005975
5976 - If you are unable to install the ``bmap-tools`` package, you will
5977 need to build Bmaptool before using it. Use the following command:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005978 ::
5979
5980 $ bitbake bmap-tools-native
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005981
5982Following, is an example that shows how to flash a Wic image. Realize
5983that while this example uses a Wic image, you can use Bmaptool to flash
5984any type of image. Use these steps to flash an image using Bmaptool:
5985
59861. *Update your local.conf File:* You need to have the following set
5987 in your ``local.conf`` file before building your image:
5988 ::
5989
5990 IMAGE_FSTYPES += "wic wic.bmap"
5991
59922. *Get Your Image:* Either have your image ready (pre-built with the
5993 :term:`IMAGE_FSTYPES`
5994 setting previously mentioned) or take the step to build the image:
5995 ::
5996
5997 $ bitbake image
5998
59993. *Flash the Device:* Flash the device with the image by using Bmaptool
6000 depending on your particular setup. The following commands assume the
6001 image resides in the Build Directory's ``deploy/images/`` area:
6002
6003 - If you have write access to the media, use this command form:
6004 ::
6005
6006 $ oe-run-native bmap-tools-native bmaptool copy build-directory/tmp/deploy/images/machine/image.wic /dev/sdX
6007
6008 - If you do not have write access to the media, set your permissions
6009 first and then use the same command form:
6010 ::
6011
6012 $ sudo chmod 666 /dev/sdX
6013 $ oe-run-native bmap-tools-native bmaptool copy build-directory/tmp/deploy/images/machine/image.wic /dev/sdX
6014
6015For help on the ``bmaptool`` command, use the following command:
6016::
6017
6018 $ bmaptool --help
6019
6020Making Images More Secure
6021=========================
6022
6023Security is of increasing concern for embedded devices. Consider the
6024issues and problems discussed in just this sampling of work found across
6025the Internet:
6026
6027- *"*\ `Security Risks of Embedded
6028 Systems <https://www.schneier.com/blog/archives/2014/01/security_risks_9.html>`__\ *"*
6029 by Bruce Schneier
6030
6031- *"*\ `Internet Census
6032 2012 <http://census2012.sourceforge.net/paper.html>`__\ *"* by Carna
6033 Botnet
6034
6035- *"*\ `Security Issues for Embedded
Andrew Geisslerd1e89492021-02-12 15:35:20 -06006036 Devices <https://elinux.org/images/6/6f/Security-issues.pdf>`__\ *"*
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006037 by Jake Edge
6038
6039When securing your image is of concern, there are steps, tools, and
6040variables that you can consider to help you reach the security goals you
6041need for your particular device. Not all situations are identical when
6042it comes to making an image secure. Consequently, this section provides
6043some guidance and suggestions for consideration when you want to make
6044your image more secure.
6045
6046.. note::
6047
6048 Because the security requirements and risks are different for every
6049 type of device, this section cannot provide a complete reference on
6050 securing your custom OS. It is strongly recommended that you also
6051 consult other sources of information on embedded Linux system
6052 hardening and on security.
6053
6054General Considerations
6055----------------------
6056
6057General considerations exist that help you create more secure images.
6058You should consider the following suggestions to help make your device
6059more secure:
6060
6061- Scan additional code you are adding to the system (e.g. application
6062 code) by using static analysis tools. Look for buffer overflows and
6063 other potential security problems.
6064
6065- Pay particular attention to the security for any web-based
6066 administration interface.
6067
6068 Web interfaces typically need to perform administrative functions and
6069 tend to need to run with elevated privileges. Thus, the consequences
6070 resulting from the interface's security becoming compromised can be
6071 serious. Look for common web vulnerabilities such as
6072 cross-site-scripting (XSS), unvalidated inputs, and so forth.
6073
6074 As with system passwords, the default credentials for accessing a
6075 web-based interface should not be the same across all devices. This
6076 is particularly true if the interface is enabled by default as it can
6077 be assumed that many end-users will not change the credentials.
6078
6079- Ensure you can update the software on the device to mitigate
6080 vulnerabilities discovered in the future. This consideration
6081 especially applies when your device is network-enabled.
6082
6083- Ensure you remove or disable debugging functionality before producing
6084 the final image. For information on how to do this, see the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006085 ":ref:`dev-manual/common-tasks:considerations specific to the openembedded build system`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006086 section.
6087
6088- Ensure you have no network services listening that are not needed.
6089
6090- Remove any software from the image that is not needed.
6091
6092- Enable hardware support for secure boot functionality when your
6093 device supports this functionality.
6094
6095Security Flags
6096--------------
6097
6098The Yocto Project has security flags that you can enable that help make
6099your build output more secure. The security flags are in the
6100``meta/conf/distro/include/security_flags.inc`` file in your
6101:term:`Source Directory` (e.g. ``poky``).
6102
6103.. note::
6104
6105 Depending on the recipe, certain security flags are enabled and
6106 disabled by default.
6107
6108Use the following line in your ``local.conf`` file or in your custom
6109distribution configuration file to enable the security compiler and
6110linker flags for your build:
6111::
6112
6113 require conf/distro/include/security_flags.inc
6114
6115Considerations Specific to the OpenEmbedded Build System
6116--------------------------------------------------------
6117
6118You can take some steps that are specific to the OpenEmbedded build
6119system to make your images more secure:
6120
6121- Ensure "debug-tweaks" is not one of your selected
6122 :term:`IMAGE_FEATURES`.
6123 When creating a new project, the default is to provide you with an
6124 initial ``local.conf`` file that enables this feature using the
6125 :term:`EXTRA_IMAGE_FEATURES`
6126 variable with the line:
6127 ::
6128
6129 EXTRA_IMAGE_FEATURES = "debug-tweaks"
6130
6131 To disable that feature, simply comment out that line in your
6132 ``local.conf`` file, or make sure ``IMAGE_FEATURES`` does not contain
6133 "debug-tweaks" before producing your final image. Among other things,
6134 leaving this in place sets the root password as blank, which makes
6135 logging in for debugging or inspection easy during development but
6136 also means anyone can easily log in during production.
6137
6138- It is possible to set a root password for the image and also to set
6139 passwords for any extra users you might add (e.g. administrative or
6140 service type users). When you set up passwords for multiple images or
6141 users, you should not duplicate passwords.
6142
6143 To set up passwords, use the
6144 :ref:`extrausers <ref-classes-extrausers>`
6145 class, which is the preferred method. For an example on how to set up
6146 both root and user passwords, see the
6147 ":ref:`extrausers.bbclass <ref-classes-extrausers>`"
6148 section.
6149
6150 .. note::
6151
6152 When adding extra user accounts or setting a root password, be
6153 cautious about setting the same password on every device. If you
6154 do this, and the password you have set is exposed, then every
6155 device is now potentially compromised. If you need this access but
6156 want to ensure security, consider setting a different, random
6157 password for each device. Typically, you do this as a separate
6158 step after you deploy the image onto the device.
6159
6160- Consider enabling a Mandatory Access Control (MAC) framework such as
6161 SMACK or SELinux and tuning it appropriately for your device's usage.
6162 You can find more information in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06006163 :yocto_git:`meta-selinux </meta-selinux/>` layer.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006164
6165Tools for Hardening Your Image
6166------------------------------
6167
6168The Yocto Project provides tools for making your image more secure. You
6169can find these tools in the ``meta-security`` layer of the
6170:yocto_git:`Yocto Project Source Repositories <>`.
6171
6172Creating Your Own Distribution
6173==============================
6174
6175When you build an image using the Yocto Project and do not alter any
6176distribution :term:`Metadata`, you are
6177creating a Poky distribution. If you wish to gain more control over
6178package alternative selections, compile-time options, and other
6179low-level configurations, you can create your own distribution.
6180
6181To create your own distribution, the basic steps consist of creating
6182your own distribution layer, creating your own distribution
6183configuration file, and then adding any needed code and Metadata to the
6184layer. The following steps provide some more detail:
6185
6186- *Create a layer for your new distro:* Create your distribution layer
6187 so that you can keep your Metadata and code for the distribution
6188 separate. It is strongly recommended that you create and use your own
6189 layer for configuration and code. Using your own layer as compared to
6190 just placing configurations in a ``local.conf`` configuration file
6191 makes it easier to reproduce the same build configuration when using
6192 multiple build machines. See the
Andrew Geissler09209ee2020-12-13 08:44:15 -06006193 ":ref:`dev-manual/common-tasks:creating a general layer using the \`\`bitbake-layers\`\` script`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006194 section for information on how to quickly set up a layer.
6195
6196- *Create the distribution configuration file:* The distribution
6197 configuration file needs to be created in the ``conf/distro``
6198 directory of your layer. You need to name it using your distribution
6199 name (e.g. ``mydistro.conf``).
6200
6201 .. note::
6202
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006203 The :term:`DISTRO` variable in your ``local.conf`` file determines the
6204 name of your distribution.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006205
6206 You can split out parts of your configuration file into include files
6207 and then "require" them from within your distribution configuration
6208 file. Be sure to place the include files in the
6209 ``conf/distro/include`` directory of your layer. A common example
6210 usage of include files would be to separate out the selection of
6211 desired version and revisions for individual recipes.
6212
6213 Your configuration file needs to set the following required
6214 variables:
6215
6216 - :term:`DISTRO_NAME`
6217
6218 - :term:`DISTRO_VERSION`
6219
6220 These following variables are optional and you typically set them
6221 from the distribution configuration file:
6222
6223 - :term:`DISTRO_FEATURES`
6224
6225 - :term:`DISTRO_EXTRA_RDEPENDS`
6226
6227 - :term:`DISTRO_EXTRA_RRECOMMENDS`
6228
6229 - :term:`TCLIBC`
6230
6231 .. tip::
6232
6233 If you want to base your distribution configuration file on the
6234 very basic configuration from OE-Core, you can use
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006235 ``conf/distro/defaultsetup.conf`` as a reference and just include
6236 variables that differ as compared to ``defaultsetup.conf``.
6237 Alternatively, you can create a distribution configuration file
6238 from scratch using the ``defaultsetup.conf`` file or configuration files
6239 from other distributions such as Poky or Angstrom as references.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006240
6241- *Provide miscellaneous variables:* Be sure to define any other
6242 variables for which you want to create a default or enforce as part
6243 of the distribution configuration. You can include nearly any
6244 variable from the ``local.conf`` file. The variables you use are not
6245 limited to the list in the previous bulleted item.
6246
6247- *Point to Your distribution configuration file:* In your
6248 ``local.conf`` file in the :term:`Build Directory`,
6249 set your
6250 :term:`DISTRO` variable to point to
6251 your distribution's configuration file. For example, if your
6252 distribution's configuration file is named ``mydistro.conf``, then
6253 you point to it as follows:
6254 ::
6255
6256 DISTRO = "mydistro"
6257
6258- *Add more to the layer if necessary:* Use your layer to hold other
6259 information needed for the distribution:
6260
6261 - Add recipes for installing distro-specific configuration files
6262 that are not already installed by another recipe. If you have
6263 distro-specific configuration files that are included by an
6264 existing recipe, you should add an append file (``.bbappend``) for
6265 those. For general information and recommendations on how to add
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006266 recipes to your layer, see the
6267 ":ref:`dev-manual/common-tasks:creating your own layer`" and
6268 ":ref:`dev-manual/common-tasks:following best practices when creating layers`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006269 sections.
6270
6271 - Add any image recipes that are specific to your distribution.
6272
6273 - Add a ``psplash`` append file for a branded splash screen. For
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006274 information on append files, see the
6275 ":ref:`dev-manual/common-tasks:using .bbappend files in your layer`"
6276 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006277
6278 - Add any other append files to make custom changes that are
6279 specific to individual recipes.
6280
6281Creating a Custom Template Configuration Directory
6282==================================================
6283
6284If you are producing your own customized version of the build system for
6285use by other users, you might want to customize the message shown by the
6286setup script or you might want to change the template configuration
6287files (i.e. ``local.conf`` and ``bblayers.conf``) that are created in a
6288new build directory.
6289
6290The OpenEmbedded build system uses the environment variable
6291``TEMPLATECONF`` to locate the directory from which it gathers
6292configuration information that ultimately ends up in the
6293:term:`Build Directory` ``conf`` directory.
6294By default, ``TEMPLATECONF`` is set as follows in the ``poky``
6295repository:
6296::
6297
6298 TEMPLATECONF=${TEMPLATECONF:-meta-poky/conf}
6299
6300This is the
6301directory used by the build system to find templates from which to build
6302some key configuration files. If you look at this directory, you will
6303see the ``bblayers.conf.sample``, ``local.conf.sample``, and
6304``conf-notes.txt`` files. The build system uses these files to form the
6305respective ``bblayers.conf`` file, ``local.conf`` file, and display the
6306list of BitBake targets when running the setup script.
6307
6308To override these default configuration files with configurations you
6309want used within every new Build Directory, simply set the
6310``TEMPLATECONF`` variable to your directory. The ``TEMPLATECONF``
6311variable is set in the ``.templateconf`` file, which is in the top-level
6312:term:`Source Directory` folder
6313(e.g. ``poky``). Edit the ``.templateconf`` so that it can locate your
6314directory.
6315
6316Best practices dictate that you should keep your template configuration
6317directory in your custom distribution layer. For example, suppose you
6318have a layer named ``meta-mylayer`` located in your home directory and
6319you want your template configuration directory named ``myconf``.
6320Changing the ``.templateconf`` as follows causes the OpenEmbedded build
6321system to look in your directory and base its configuration files on the
6322``*.sample`` configuration files it finds. The final configuration files
6323(i.e. ``local.conf`` and ``bblayers.conf`` ultimately still end up in
6324your Build Directory, but they are based on your ``*.sample`` files.
6325::
6326
6327 TEMPLATECONF=${TEMPLATECONF:-meta-mylayer/myconf}
6328
6329Aside from the ``*.sample`` configuration files, the ``conf-notes.txt``
6330also resides in the default ``meta-poky/conf`` directory. The script
6331that sets up the build environment (i.e.
6332:ref:`structure-core-script`) uses this file to
6333display BitBake targets as part of the script output. Customizing this
6334``conf-notes.txt`` file is a good way to make sure your list of custom
6335targets appears as part of the script's output.
6336
6337Here is the default list of targets displayed as a result of running
6338either of the setup scripts:
6339::
6340
6341 You can now run 'bitbake <target>'
6342
6343 Common targets are:
6344 core-image-minimal
6345 core-image-sato
6346 meta-toolchain
6347 meta-ide-support
6348
6349Changing the listed common targets is as easy as editing your version of
6350``conf-notes.txt`` in your custom template configuration directory and
6351making sure you have ``TEMPLATECONF`` set to your directory.
6352
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006353Conserving Disk Space During Builds
6354===================================
6355
6356To help conserve disk space during builds, you can add the following
6357statement to your project's ``local.conf`` configuration file found in
6358the :term:`Build Directory`:
6359::
6360
6361 INHERIT += "rm_work"
6362
6363Adding this statement deletes the work directory used for
6364building a recipe once the recipe is built. For more information on
6365"rm_work", see the
6366:ref:`rm_work <ref-classes-rm-work>` class in the
6367Yocto Project Reference Manual.
6368
6369Working with Packages
6370=====================
6371
6372This section describes a few tasks that involve packages:
6373
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006374- :ref:`dev-manual/common-tasks:excluding packages from an image`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006375
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006376- :ref:`dev-manual/common-tasks:incrementing a package version`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006377
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006378- :ref:`dev-manual/common-tasks:handling optional module packaging`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006379
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006380- :ref:`dev-manual/common-tasks:using runtime package management`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006381
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006382- :ref:`dev-manual/common-tasks:generating and using signed packages`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006383
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006384- :ref:`Setting up and running package test
6385 (ptest) <dev-manual/common-tasks:testing packages with ptest>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006386
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006387- :ref:`dev-manual/common-tasks:creating node package manager (npm) packages`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006388
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006389- :ref:`dev-manual/common-tasks:adding custom metadata to packages`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006390
6391Excluding Packages from an Image
6392--------------------------------
6393
6394You might find it necessary to prevent specific packages from being
6395installed into an image. If so, you can use several variables to direct
6396the build system to essentially ignore installing recommended packages
6397or to not install a package at all.
6398
6399The following list introduces variables you can use to prevent packages
6400from being installed into your image. Each of these variables only works
6401with IPK and RPM package types. Support for Debian packages does not
6402exist. Also, you can use these variables from your ``local.conf`` file
6403or attach them to a specific image recipe by using a recipe name
6404override. For more detail on the variables, see the descriptions in the
6405Yocto Project Reference Manual's glossary chapter.
6406
6407- :term:`BAD_RECOMMENDATIONS`:
6408 Use this variable to specify "recommended-only" packages that you do
6409 not want installed.
6410
6411- :term:`NO_RECOMMENDATIONS`:
6412 Use this variable to prevent all "recommended-only" packages from
6413 being installed.
6414
6415- :term:`PACKAGE_EXCLUDE`:
6416 Use this variable to prevent specific packages from being installed
6417 regardless of whether they are "recommended-only" or not. You need to
6418 realize that the build process could fail with an error when you
6419 prevent the installation of a package whose presence is required by
6420 an installed package.
6421
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006422Incrementing a Package Version
6423------------------------------
6424
6425This section provides some background on how binary package versioning
6426is accomplished and presents some of the services, variables, and
6427terminology involved.
6428
6429In order to understand binary package versioning, you need to consider
6430the following:
6431
6432- Binary Package: The binary package that is eventually built and
6433 installed into an image.
6434
6435- Binary Package Version: The binary package version is composed of two
6436 components - a version and a revision.
6437
6438 .. note::
6439
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006440 Technically, a third component, the "epoch" (i.e. :term:`PE`) is involved
6441 but this discussion for the most part ignores ``PE``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006442
6443 The version and revision are taken from the
6444 :term:`PV` and
6445 :term:`PR` variables, respectively.
6446
6447- ``PV``: The recipe version. ``PV`` represents the version of the
6448 software being packaged. Do not confuse ``PV`` with the binary
6449 package version.
6450
6451- ``PR``: The recipe revision.
6452
6453- :term:`SRCPV`: The OpenEmbedded
6454 build system uses this string to help define the value of ``PV`` when
6455 the source code revision needs to be included in it.
6456
Andrew Geissler09209ee2020-12-13 08:44:15 -06006457- :yocto_wiki:`PR Service </PR_Service>`: A
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006458 network-based service that helps automate keeping package feeds
6459 compatible with existing package manager applications such as RPM,
6460 APT, and OPKG.
6461
6462Whenever the binary package content changes, the binary package version
6463must change. Changing the binary package version is accomplished by
6464changing or "bumping" the ``PR`` and/or ``PV`` values. Increasing these
6465values occurs one of two ways:
6466
6467- Automatically using a Package Revision Service (PR Service).
6468
6469- Manually incrementing the ``PR`` and/or ``PV`` variables.
6470
6471Given a primary challenge of any build system and its users is how to
6472maintain a package feed that is compatible with existing package manager
6473applications such as RPM, APT, and OPKG, using an automated system is
6474much preferred over a manual system. In either system, the main
6475requirement is that binary package version numbering increases in a
6476linear fashion and that a number of version components exist that
6477support that linear progression. For information on how to ensure
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006478package revisioning remains linear, see the
6479":ref:`dev-manual/common-tasks:automatically incrementing a package version number`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006480section.
6481
6482The following three sections provide related information on the PR
6483Service, the manual method for "bumping" ``PR`` and/or ``PV``, and on
6484how to ensure binary package revisioning remains linear.
6485
6486Working With a PR Service
6487~~~~~~~~~~~~~~~~~~~~~~~~~
6488
6489As mentioned, attempting to maintain revision numbers in the
6490:term:`Metadata` is error prone, inaccurate,
6491and causes problems for people submitting recipes. Conversely, the PR
6492Service automatically generates increasing numbers, particularly the
6493revision field, which removes the human element.
6494
6495.. note::
6496
6497 For additional information on using a PR Service, you can see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06006498 :yocto_wiki:`PR Service </PR_Service>` wiki page.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006499
6500The Yocto Project uses variables in order of decreasing priority to
6501facilitate revision numbering (i.e.
6502:term:`PE`,
6503:term:`PV`, and
6504:term:`PR` for epoch, version, and
6505revision, respectively). The values are highly dependent on the policies
6506and procedures of a given distribution and package feed.
6507
6508Because the OpenEmbedded build system uses
Andrew Geissler09209ee2020-12-13 08:44:15 -06006509":ref:`signatures <overview-manual/concepts:checksums (signatures)>`", which are
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006510unique to a given build, the build system knows when to rebuild
6511packages. All the inputs into a given task are represented by a
6512signature, which can trigger a rebuild when different. Thus, the build
6513system itself does not rely on the ``PR``, ``PV``, and ``PE`` numbers to
6514trigger a rebuild. The signatures, however, can be used to generate
6515these values.
6516
6517The PR Service works with both ``OEBasic`` and ``OEBasicHash``
6518generators. The value of ``PR`` bumps when the checksum changes and the
6519different generator mechanisms change signatures under different
6520circumstances.
6521
6522As implemented, the build system includes values from the PR Service
6523into the ``PR`` field as an addition using the form "``.x``" so ``r0``
6524becomes ``r0.1``, ``r0.2`` and so forth. This scheme allows existing
6525``PR`` values to be used for whatever reasons, which include manual
6526``PR`` bumps, should it be necessary.
6527
6528By default, the PR Service is not enabled or running. Thus, the packages
6529generated are just "self consistent". The build system adds and removes
6530packages and there are no guarantees about upgrade paths but images will
6531be consistent and correct with the latest changes.
6532
6533The simplest form for a PR Service is for it to exist for a single host
6534development system that builds the package feed (building system). For
6535this scenario, you can enable a local PR Service by setting
6536:term:`PRSERV_HOST` in your
6537``local.conf`` file in the :term:`Build Directory`:
6538::
6539
6540 PRSERV_HOST = "localhost:0"
6541
6542Once the service is started, packages will automatically
6543get increasing ``PR`` values and BitBake takes care of starting and
6544stopping the server.
6545
6546If you have a more complex setup where multiple host development systems
6547work against a common, shared package feed, you have a single PR Service
6548running and it is connected to each building system. For this scenario,
6549you need to start the PR Service using the ``bitbake-prserv`` command:
6550::
6551
6552 bitbake-prserv --host ip --port port --start
6553
6554In addition to
6555hand-starting the service, you need to update the ``local.conf`` file of
6556each building system as described earlier so each system points to the
6557server and port.
6558
6559It is also recommended you use build history, which adds some sanity
6560checks to binary package versions, in conjunction with the server that
6561is running the PR Service. To enable build history, add the following to
6562each building system's ``local.conf`` file:
6563::
6564
6565 # It is recommended to activate "buildhistory" for testing the PR service
6566 INHERIT += "buildhistory"
6567 BUILDHISTORY_COMMIT = "1"
6568
6569For information on build
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006570history, see the
6571":ref:`dev-manual/common-tasks:maintaining build output quality`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006572
6573.. note::
6574
6575 The OpenEmbedded build system does not maintain ``PR`` information as
6576 part of the shared state (sstate) packages. If you maintain an sstate
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006577 feed, it's expected that either all your building systems that
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006578 contribute to the sstate feed use a shared PR Service, or you do not
6579 run a PR Service on any of your building systems. Having some systems
6580 use a PR Service while others do not leads to obvious problems.
6581
6582 For more information on shared state, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06006583 ":ref:`overview-manual/concepts:shared state cache`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006584 section in the Yocto Project Overview and Concepts Manual.
6585
6586Manually Bumping PR
6587~~~~~~~~~~~~~~~~~~~
6588
6589The alternative to setting up a PR Service is to manually "bump" the
6590:term:`PR` variable.
6591
6592If a committed change results in changing the package output, then the
6593value of the PR variable needs to be increased (or "bumped") as part of
6594that commit. For new recipes you should add the ``PR`` variable and set
6595its initial value equal to "r0", which is the default. Even though the
6596default value is "r0", the practice of adding it to a new recipe makes
6597it harder to forget to bump the variable when you make changes to the
6598recipe in future.
6599
6600If you are sharing a common ``.inc`` file with multiple recipes, you can
6601also use the ``INC_PR`` variable to ensure that the recipes sharing the
6602``.inc`` file are rebuilt when the ``.inc`` file itself is changed. The
6603``.inc`` file must set ``INC_PR`` (initially to "r0"), and all recipes
6604referring to it should set ``PR`` to "${INC_PR}.0" initially,
6605incrementing the last number when the recipe is changed. If the ``.inc``
6606file is changed then its ``INC_PR`` should be incremented.
6607
6608When upgrading the version of a binary package, assuming the ``PV``
6609changes, the ``PR`` variable should be reset to "r0" (or "${INC_PR}.0"
6610if you are using ``INC_PR``).
6611
6612Usually, version increases occur only to binary packages. However, if
6613for some reason ``PV`` changes but does not increase, you can increase
6614the ``PE`` variable (Package Epoch). The ``PE`` variable defaults to
6615"0".
6616
6617Binary package version numbering strives to follow the `Debian Version
6618Field Policy
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006619Guidelines <https://www.debian.org/doc/debian-policy/ch-controlfields.html>`__.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006620These guidelines define how versions are compared and what "increasing"
6621a version means.
6622
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006623Automatically Incrementing a Package Version Number
6624~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6625
6626When fetching a repository, BitBake uses the
6627:term:`SRCREV` variable to determine
6628the specific source code revision from which to build. You set the
6629``SRCREV`` variable to
6630:term:`AUTOREV` to cause the
6631OpenEmbedded build system to automatically use the latest revision of
6632the software:
6633::
6634
6635 SRCREV = "${AUTOREV}"
6636
6637Furthermore, you need to reference ``SRCPV`` in ``PV`` in order to
6638automatically update the version whenever the revision of the source
6639code changes. Here is an example:
6640::
6641
6642 PV = "1.0+git${SRCPV}"
6643
6644The OpenEmbedded build system substitutes ``SRCPV`` with the following:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006645
6646.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006647
6648 AUTOINC+source_code_revision
6649
6650The build system replaces the ``AUTOINC``
6651with a number. The number used depends on the state of the PR Service:
6652
6653- If PR Service is enabled, the build system increments the number,
6654 which is similar to the behavior of
6655 :term:`PR`. This behavior results in
6656 linearly increasing package versions, which is desirable. Here is an
6657 example:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006658
6659 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006660
6661 hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
6662 hello-world-git_0.0+git1+dd2f5c3565-r0.0_armv7a-neon.ipk
6663
6664- If PR Service is not enabled, the build system replaces the
6665 ``AUTOINC`` placeholder with zero (i.e. "0"). This results in
6666 changing the package version since the source revision is included.
6667 However, package versions are not increased linearly. Here is an
6668 example:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006669
6670 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006671
6672 hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
6673 hello-world-git_0.0+git0+dd2f5c3565-r0.0_armv7a-neon.ipk
6674
6675In summary, the OpenEmbedded build system does not track the history of
6676binary package versions for this purpose. ``AUTOINC``, in this case, is
6677comparable to ``PR``. If PR server is not enabled, ``AUTOINC`` in the
6678package version is simply replaced by "0". If PR server is enabled, the
6679build system keeps track of the package versions and bumps the number
6680when the package revision changes.
6681
6682Handling Optional Module Packaging
6683----------------------------------
6684
6685Many pieces of software split functionality into optional modules (or
6686plugins) and the plugins that are built might depend on configuration
6687options. To avoid having to duplicate the logic that determines what
6688modules are available in your recipe or to avoid having to package each
6689module by hand, the OpenEmbedded build system provides functionality to
6690handle module packaging dynamically.
6691
6692To handle optional module packaging, you need to do two things:
6693
6694- Ensure the module packaging is actually done.
6695
6696- Ensure that any dependencies on optional modules from other recipes
6697 are satisfied by your recipe.
6698
6699Making Sure the Packaging is Done
6700~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6701
6702To ensure the module packaging actually gets done, you use the
6703``do_split_packages`` function within the ``populate_packages`` Python
6704function in your recipe. The ``do_split_packages`` function searches for
6705a pattern of files or directories under a specified path and creates a
6706package for each one it finds by appending to the
6707:term:`PACKAGES` variable and
6708setting the appropriate values for ``FILES_packagename``,
6709``RDEPENDS_packagename``, ``DESCRIPTION_packagename``, and so forth.
6710Here is an example from the ``lighttpd`` recipe:
6711::
6712
6713 python populate_packages_prepend () {
6714 lighttpd_libdir = d.expand('${libdir}')
6715 do_split_packages(d, lighttpd_libdir, '^mod_(.*).so$',
6716 'lighttpd-module-%s', 'Lighttpd module for %s',
6717 extra_depends='')
6718 }
6719
6720The previous example specifies a number of things in the call to
6721``do_split_packages``.
6722
6723- A directory within the files installed by your recipe through
6724 ``do_install`` in which to search.
6725
6726- A regular expression used to match module files in that directory. In
6727 the example, note the parentheses () that mark the part of the
6728 expression from which the module name should be derived.
6729
6730- A pattern to use for the package names.
6731
6732- A description for each package.
6733
6734- An empty string for ``extra_depends``, which disables the default
6735 dependency on the main ``lighttpd`` package. Thus, if a file in
6736 ``${libdir}`` called ``mod_alias.so`` is found, a package called
6737 ``lighttpd-module-alias`` is created for it and the
6738 :term:`DESCRIPTION` is set to
6739 "Lighttpd module for alias".
6740
6741Often, packaging modules is as simple as the previous example. However,
6742more advanced options exist that you can use within
6743``do_split_packages`` to modify its behavior. And, if you need to, you
6744can add more logic by specifying a hook function that is called for each
6745package. It is also perfectly acceptable to call ``do_split_packages``
6746multiple times if you have more than one set of modules to package.
6747
6748For more examples that show how to use ``do_split_packages``, see the
6749``connman.inc`` file in the ``meta/recipes-connectivity/connman/``
Andrew Geissler09209ee2020-12-13 08:44:15 -06006750directory of the ``poky`` :ref:`source repository <overview-manual/development-environment:yocto project source repositories>`. You can
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006751also find examples in ``meta/classes/kernel.bbclass``.
6752
6753Following is a reference that shows ``do_split_packages`` mandatory and
6754optional arguments:
6755::
6756
6757 Mandatory arguments
6758
6759 root
6760 The path in which to search
6761 file_regex
6762 Regular expression to match searched files.
6763 Use parentheses () to mark the part of this
6764 expression that should be used to derive the
6765 module name (to be substituted where %s is
6766 used in other function arguments as noted below)
6767 output_pattern
6768 Pattern to use for the package names. Must
6769 include %s.
6770 description
6771 Description to set for each package. Must
6772 include %s.
6773
6774 Optional arguments
6775
6776 postinst
6777 Postinstall script to use for all packages
6778 (as a string)
6779 recursive
6780 True to perform a recursive search - default
6781 False
6782 hook
6783 A hook function to be called for every match.
6784 The function will be called with the following
6785 arguments (in the order listed):
6786
6787 f
6788 Full path to the file/directory match
6789 pkg
6790 The package name
6791 file_regex
6792 As above
6793 output_pattern
6794 As above
6795 modulename
6796 The module name derived using file_regex
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006797 extra_depends
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006798 Extra runtime dependencies (RDEPENDS) to be
6799 set for all packages. The default value of None
6800 causes a dependency on the main package
6801 (${PN}) - if you do not want this, pass empty
6802 string '' for this parameter.
6803 aux_files_pattern
6804 Extra item(s) to be added to FILES for each
6805 package. Can be a single string item or a list
6806 of strings for multiple items. Must include %s.
6807 postrm
6808 postrm script to use for all packages (as a
6809 string)
6810 allow_dirs
6811 True to allow directories to be matched -
6812 default False
6813 prepend
6814 If True, prepend created packages to PACKAGES
6815 instead of the default False which appends them
6816 match_path
6817 match file_regex on the whole relative path to
6818 the root rather than just the file name
6819 aux_files_pattern_verbatim
6820 Extra item(s) to be added to FILES for each
6821 package, using the actual derived module name
6822 rather than converting it to something legal
6823 for a package name. Can be a single string item
6824 or a list of strings for multiple items. Must
6825 include %s.
6826 allow_links
6827 True to allow symlinks to be matched - default
6828 False
6829 summary
6830 Summary to set for each package. Must include %s;
6831 defaults to description if not set.
6832
6833
6834
6835Satisfying Dependencies
6836~~~~~~~~~~~~~~~~~~~~~~~
6837
6838The second part for handling optional module packaging is to ensure that
6839any dependencies on optional modules from other recipes are satisfied by
6840your recipe. You can be sure these dependencies are satisfied by using
6841the :term:`PACKAGES_DYNAMIC`
6842variable. Here is an example that continues with the ``lighttpd`` recipe
6843shown earlier:
6844::
6845
6846 PACKAGES_DYNAMIC = "lighttpd-module-.*"
6847
6848The name
6849specified in the regular expression can of course be anything. In this
6850example, it is ``lighttpd-module-`` and is specified as the prefix to
6851ensure that any :term:`RDEPENDS` and
6852:term:`RRECOMMENDS` on a package
6853name starting with the prefix are satisfied during build time. If you
6854are using ``do_split_packages`` as described in the previous section,
6855the value you put in ``PACKAGES_DYNAMIC`` should correspond to the name
6856pattern specified in the call to ``do_split_packages``.
6857
6858Using Runtime Package Management
6859--------------------------------
6860
6861During a build, BitBake always transforms a recipe into one or more
6862packages. For example, BitBake takes the ``bash`` recipe and produces a
6863number of packages (e.g. ``bash``, ``bash-bashbug``,
6864``bash-completion``, ``bash-completion-dbg``, ``bash-completion-dev``,
6865``bash-completion-extra``, ``bash-dbg``, and so forth). Not all
6866generated packages are included in an image.
6867
6868In several situations, you might need to update, add, remove, or query
6869the packages on a target device at runtime (i.e. without having to
6870generate a new image). Examples of such situations include:
6871
6872- You want to provide in-the-field updates to deployed devices (e.g.
6873 security updates).
6874
6875- You want to have a fast turn-around development cycle for one or more
6876 applications that run on your device.
6877
6878- You want to temporarily install the "debug" packages of various
6879 applications on your device so that debugging can be greatly improved
6880 by allowing access to symbols and source debugging.
6881
6882- You want to deploy a more minimal package selection of your device
6883 but allow in-the-field updates to add a larger selection for
6884 customization.
6885
6886In all these situations, you have something similar to a more
6887traditional Linux distribution in that in-field devices are able to
6888receive pre-compiled packages from a server for installation or update.
6889Being able to install these packages on a running, in-field device is
6890what is termed "runtime package management".
6891
6892In order to use runtime package management, you need a host or server
6893machine that serves up the pre-compiled packages plus the required
6894metadata. You also need package manipulation tools on the target. The
6895build machine is a likely candidate to act as the server. However, that
6896machine does not necessarily have to be the package server. The build
6897machine could push its artifacts to another machine that acts as the
6898server (e.g. Internet-facing). In fact, doing so is advantageous for a
6899production environment as getting the packages away from the development
6900system's build directory prevents accidental overwrites.
6901
6902A simple build that targets just one device produces more than one
6903package database. In other words, the packages produced by a build are
6904separated out into a couple of different package groupings based on
6905criteria such as the target's CPU architecture, the target board, or the
6906C library used on the target. For example, a build targeting the
6907``qemux86`` device produces the following three package databases:
6908``noarch``, ``i586``, and ``qemux86``. If you wanted your ``qemux86``
6909device to be aware of all the packages that were available to it, you
6910would need to point it to each of these databases individually. In a
6911similar way, a traditional Linux distribution usually is configured to
6912be aware of a number of software repositories from which it retrieves
6913packages.
6914
6915Using runtime package management is completely optional and not required
6916for a successful build or deployment in any way. But if you want to make
6917use of runtime package management, you need to do a couple things above
6918and beyond the basics. The remainder of this section describes what you
6919need to do.
6920
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006921Build Considerations
6922~~~~~~~~~~~~~~~~~~~~
6923
6924This section describes build considerations of which you need to be
6925aware in order to provide support for runtime package management.
6926
6927When BitBake generates packages, it needs to know what format or formats
6928to use. In your configuration, you use the
6929:term:`PACKAGE_CLASSES`
6930variable to specify the format:
6931
69321. Open the ``local.conf`` file inside your
6933 :term:`Build Directory` (e.g.
Andrew Geissler95ac1b82021-03-31 14:34:31 -05006934 ``poky/build/conf/local.conf``).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006935
69362. Select the desired package format as follows:
6937 ::
6938
6939 PACKAGE_CLASSES ?= "package_packageformat"
6940
6941 where packageformat can be "ipk", "rpm",
6942 "deb", or "tar" which are the supported package formats.
6943
6944 .. note::
6945
6946 Because the Yocto Project supports four different package formats,
6947 you can set the variable with more than one argument. However, the
6948 OpenEmbedded build system only uses the first argument when
6949 creating an image or Software Development Kit (SDK).
6950
6951If you would like your image to start off with a basic package database
6952containing the packages in your current build as well as to have the
6953relevant tools available on the target for runtime package management,
6954you can include "package-management" in the
6955:term:`IMAGE_FEATURES`
6956variable. Including "package-management" in this configuration variable
6957ensures that when the image is assembled for your target, the image
6958includes the currently-known package databases as well as the
6959target-specific tools required for runtime package management to be
6960performed on the target. However, this is not strictly necessary. You
6961could start your image off without any databases but only include the
6962required on-target package tool(s). As an example, you could include
6963"opkg" in your
6964:term:`IMAGE_INSTALL` variable
6965if you are using the IPK package format. You can then initialize your
6966target's package database(s) later once your image is up and running.
6967
6968Whenever you perform any sort of build step that can potentially
6969generate a package or modify existing package, it is always a good idea
6970to re-generate the package index after the build by using the following
6971command:
6972::
6973
6974 $ bitbake package-index
6975
6976It might be tempting to build the
6977package and the package index at the same time with a command such as
6978the following:
6979::
6980
6981 $ bitbake some-package package-index
6982
6983Do not do this as
6984BitBake does not schedule the package index for after the completion of
6985the package you are building. Consequently, you cannot be sure of the
6986package index including information for the package you just built.
6987Thus, be sure to run the package update step separately after building
6988any packages.
6989
6990You can use the
6991:term:`PACKAGE_FEED_ARCHS`,
6992:term:`PACKAGE_FEED_BASE_PATHS`,
6993and
6994:term:`PACKAGE_FEED_URIS`
6995variables to pre-configure target images to use a package feed. If you
6996do not define these variables, then manual steps as described in the
6997subsequent sections are necessary to configure the target. You should
6998set these variables before building the image in order to produce a
6999correctly configured image.
7000
7001When your build is complete, your packages reside in the
7002``${TMPDIR}/deploy/packageformat`` directory. For example, if
7003``${``\ :term:`TMPDIR`\ ``}`` is
7004``tmp`` and your selected package type is RPM, then your RPM packages
7005are available in ``tmp/deploy/rpm``.
7006
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007007Host or Server Machine Setup
7008~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7009
7010Although other protocols are possible, a server using HTTP typically
7011serves packages. If you want to use HTTP, then set up and configure a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007012web server such as Apache 2, lighttpd, or Python web server on the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007013machine serving the packages.
7014
7015To keep things simple, this section describes how to set up a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007016Python web server to share package feeds from the developer's
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007017machine. Although this server might not be the best for a production
7018environment, the setup is simple and straight forward. Should you want
7019to use a different server more suited for production (e.g. Apache 2,
7020Lighttpd, or Nginx), take the appropriate steps to do so.
7021
7022From within the build directory where you have built an image based on
7023your packaging choice (i.e. the
7024:term:`PACKAGE_CLASSES`
7025setting), simply start the server. The following example assumes a build
Andrew Geissler95ac1b82021-03-31 14:34:31 -05007026directory of ``poky/build/tmp/deploy/rpm`` and a ``PACKAGE_CLASSES``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007027setting of "package_rpm":
7028::
7029
Andrew Geissler95ac1b82021-03-31 14:34:31 -05007030 $ cd poky/build/tmp/deploy/rpm
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007031 $ python3 -m http.server
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007032
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007033Target Setup
7034~~~~~~~~~~~~
7035
7036Setting up the target differs depending on the package management
7037system. This section provides information for RPM, IPK, and DEB.
7038
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007039Using RPM
7040^^^^^^^^^
7041
7042The `Dandified Packaging
7043Tool <https://en.wikipedia.org/wiki/DNF_(software)>`__ (DNF) performs
7044runtime package management of RPM packages. In order to use DNF for
7045runtime package management, you must perform an initial setup on the
7046target machine for cases where the ``PACKAGE_FEED_*`` variables were not
7047set as part of the image that is running on the target. This means if
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05007048you built your image and did not use these variables as part of the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007049build and your image is now running on the target, you need to perform
7050the steps in this section if you want to use runtime package management.
7051
7052.. note::
7053
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007054 For information on the ``PACKAGE_FEED_*`` variables, see
7055 :term:`PACKAGE_FEED_ARCHS`, :term:`PACKAGE_FEED_BASE_PATHS`, and
7056 :term:`PACKAGE_FEED_URIS` in the Yocto Project Reference Manual variables
7057 glossary.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007058
7059On the target, you must inform DNF that package databases are available.
7060You do this by creating a file named
7061``/etc/yum.repos.d/oe-packages.repo`` and defining the ``oe-packages``.
7062
7063As an example, assume the target is able to use the following package
7064databases: ``all``, ``i586``, and ``qemux86`` from a server named
7065``my.server``. The specifics for setting up the web server are up to
7066you. The critical requirement is that the URIs in the target repository
7067configuration point to the correct remote location for the feeds.
7068
7069.. note::
7070
7071 For development purposes, you can point the web server to the build
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007072 system's ``deploy`` directory. However, for production use, it is better to
7073 copy the package directories to a location outside of the build area and use
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007074 that location. Doing so avoids situations where the build system
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007075 overwrites or changes the ``deploy`` directory.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007076
7077When telling DNF where to look for the package databases, you must
7078declare individual locations per architecture or a single location used
7079for all architectures. You cannot do both:
7080
7081- *Create an Explicit List of Architectures:* Define individual base
7082 URLs to identify where each package database is located:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007083
7084 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007085
7086 [oe-packages]
7087 baseurl=http://my.server/rpm/i586 http://my.server/rpm/qemux86 http://my.server/rpm/all
7088
7089 This example
7090 informs DNF about individual package databases for all three
7091 architectures.
7092
7093- *Create a Single (Full) Package Index:* Define a single base URL that
7094 identifies where a full package database is located:
7095 ::
7096
7097 [oe-packages]
7098 baseurl=http://my.server/rpm
7099
7100 This example informs DNF about a single
7101 package database that contains all the package index information for
7102 all supported architectures.
7103
7104Once you have informed DNF where to find the package databases, you need
7105to fetch them:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007106
7107.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007108
7109 # dnf makecache
7110
7111DNF is now able to find, install, and
7112upgrade packages from the specified repository or repositories.
7113
7114.. note::
7115
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007116 See the `DNF documentation <https://dnf.readthedocs.io/en/latest/>`__ for
7117 additional information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007118
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007119Using IPK
7120^^^^^^^^^
7121
7122The ``opkg`` application performs runtime package management of IPK
7123packages. You must perform an initial setup for ``opkg`` on the target
7124machine if the
7125:term:`PACKAGE_FEED_ARCHS`,
7126:term:`PACKAGE_FEED_BASE_PATHS`,
7127and
7128:term:`PACKAGE_FEED_URIS`
7129variables have not been set or the target image was built before the
7130variables were set.
7131
7132The ``opkg`` application uses configuration files to find available
7133package databases. Thus, you need to create a configuration file inside
7134the ``/etc/opkg/`` direction, which informs ``opkg`` of any repository
7135you want to use.
7136
7137As an example, suppose you are serving packages from a ``ipk/``
7138directory containing the ``i586``, ``all``, and ``qemux86`` databases
7139through an HTTP server named ``my.server``. On the target, create a
7140configuration file (e.g. ``my_repo.conf``) inside the ``/etc/opkg/``
7141directory containing the following:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007142
7143.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007144
7145 src/gz all http://my.server/ipk/all
7146 src/gz i586 http://my.server/ipk/i586
7147 src/gz qemux86 http://my.server/ipk/qemux86
7148
7149Next, instruct ``opkg`` to fetch the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007150repository information:
7151
7152.. code-block:: none
7153
7154 # opkg update
7155
7156The ``opkg`` application is now able to find, install, and upgrade packages
7157from the specified repository.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007158
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007159Using DEB
7160^^^^^^^^^
7161
7162The ``apt`` application performs runtime package management of DEB
7163packages. This application uses a source list file to find available
7164package databases. You must perform an initial setup for ``apt`` on the
7165target machine if the
7166:term:`PACKAGE_FEED_ARCHS`,
7167:term:`PACKAGE_FEED_BASE_PATHS`,
7168and
7169:term:`PACKAGE_FEED_URIS`
7170variables have not been set or the target image was built before the
7171variables were set.
7172
7173To inform ``apt`` of the repository you want to use, you might create a
7174list file (e.g. ``my_repo.list``) inside the
7175``/etc/apt/sources.list.d/`` directory. As an example, suppose you are
7176serving packages from a ``deb/`` directory containing the ``i586``,
7177``all``, and ``qemux86`` databases through an HTTP server named
7178``my.server``. The list file should contain:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007179
7180.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007181
7182 deb http://my.server/deb/all ./
7183 deb http://my.server/deb/i586 ./
7184 deb http://my.server/deb/qemux86 ./
7185
7186Next, instruct the ``apt`` application
7187to fetch the repository information:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007188
7189.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007190
7191 # apt-get update
7192
7193After this step,
7194``apt`` is able to find, install, and upgrade packages from the
7195specified repository.
7196
7197Generating and Using Signed Packages
7198------------------------------------
7199
7200In order to add security to RPM packages used during a build, you can
7201take steps to securely sign them. Once a signature is verified, the
7202OpenEmbedded build system can use the package in the build. If security
7203fails for a signed package, the build system aborts the build.
7204
7205This section describes how to sign RPM packages during a build and how
7206to use signed package feeds (repositories) when doing a build.
7207
7208Signing RPM Packages
7209~~~~~~~~~~~~~~~~~~~~
7210
7211To enable signing RPM packages, you must set up the following
7212configurations in either your ``local.config`` or ``distro.config``
7213file:
7214::
7215
7216 # Inherit sign_rpm.bbclass to enable signing functionality
7217 INHERIT += " sign_rpm"
7218 # Define the GPG key that will be used for signing.
7219 RPM_GPG_NAME = "key_name"
7220 # Provide passphrase for the key
7221 RPM_GPG_PASSPHRASE = "passphrase"
7222
7223.. note::
7224
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007225 Be sure to supply appropriate values for both `key_name` and
7226 `passphrase`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007227
7228Aside from the ``RPM_GPG_NAME`` and ``RPM_GPG_PASSPHRASE`` variables in
7229the previous example, two optional variables related to signing exist:
7230
7231- *GPG_BIN:* Specifies a ``gpg`` binary/wrapper that is executed
7232 when the package is signed.
7233
7234- *GPG_PATH:* Specifies the ``gpg`` home directory used when the
7235 package is signed.
7236
7237Processing Package Feeds
7238~~~~~~~~~~~~~~~~~~~~~~~~
7239
7240In addition to being able to sign RPM packages, you can also enable
7241signed package feeds for IPK and RPM packages.
7242
7243The steps you need to take to enable signed package feed use are similar
7244to the steps used to sign RPM packages. You must define the following in
7245your ``local.config`` or ``distro.config`` file:
7246::
7247
7248 INHERIT += "sign_package_feed"
7249 PACKAGE_FEED_GPG_NAME = "key_name"
7250 PACKAGE_FEED_GPG_PASSPHRASE_FILE = "path_to_file_containing_passphrase"
7251
7252For signed package feeds, the passphrase must exist in a separate file,
7253which is pointed to by the ``PACKAGE_FEED_GPG_PASSPHRASE_FILE``
7254variable. Regarding security, keeping a plain text passphrase out of the
7255configuration is more secure.
7256
7257Aside from the ``PACKAGE_FEED_GPG_NAME`` and
7258``PACKAGE_FEED_GPG_PASSPHRASE_FILE`` variables, three optional variables
7259related to signed package feeds exist:
7260
7261- *GPG_BIN* Specifies a ``gpg`` binary/wrapper that is executed
7262 when the package is signed.
7263
7264- *GPG_PATH:* Specifies the ``gpg`` home directory used when the
7265 package is signed.
7266
7267- *PACKAGE_FEED_GPG_SIGNATURE_TYPE:* Specifies the type of ``gpg``
7268 signature. This variable applies only to RPM and IPK package feeds.
7269 Allowable values for the ``PACKAGE_FEED_GPG_SIGNATURE_TYPE`` are
7270 "ASC", which is the default and specifies ascii armored, and "BIN",
7271 which specifies binary.
7272
7273Testing Packages With ptest
7274---------------------------
7275
7276A Package Test (ptest) runs tests against packages built by the
7277OpenEmbedded build system on the target machine. A ptest contains at
7278least two items: the actual test, and a shell script (``run-ptest``)
7279that starts the test. The shell script that starts the test must not
7280contain the actual test - the script only starts the test. On the other
7281hand, the test can be anything from a simple shell script that runs a
7282binary and checks the output to an elaborate system of test binaries and
7283data files.
7284
7285The test generates output in the format used by Automake:
7286::
7287
7288 result: testname
7289
7290where the result can be ``PASS``, ``FAIL``, or ``SKIP``, and
7291the testname can be any identifying string.
7292
7293For a list of Yocto Project recipes that are already enabled with ptest,
Andrew Geissler09209ee2020-12-13 08:44:15 -06007294see the :yocto_wiki:`Ptest </Ptest>` wiki page.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007295
7296.. note::
7297
7298 A recipe is "ptest-enabled" if it inherits the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007299 :ref:`ptest <ref-classes-ptest>` class.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007300
7301Adding ptest to Your Build
7302~~~~~~~~~~~~~~~~~~~~~~~~~~
7303
7304To add package testing to your build, add the
7305:term:`DISTRO_FEATURES` and
7306:term:`EXTRA_IMAGE_FEATURES`
7307variables to your ``local.conf`` file, which is found in the
7308:term:`Build Directory`:
7309::
7310
7311 DISTRO_FEATURES_append = " ptest"
7312 EXTRA_IMAGE_FEATURES += "ptest-pkgs"
7313
7314Once your build is complete, the ptest files are installed into the
7315``/usr/lib/package/ptest`` directory within the image, where ``package``
7316is the name of the package.
7317
7318Running ptest
7319~~~~~~~~~~~~~
7320
7321The ``ptest-runner`` package installs a shell script that loops through
7322all installed ptest test suites and runs them in sequence. Consequently,
7323you might want to add this package to your image.
7324
7325Getting Your Package Ready
7326~~~~~~~~~~~~~~~~~~~~~~~~~~
7327
7328In order to enable a recipe to run installed ptests on target hardware,
7329you need to prepare the recipes that build the packages you want to
7330test. Here is what you have to do for each recipe:
7331
7332- *Be sure the recipe inherits
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007333 the* :ref:`ptest <ref-classes-ptest>` *class:*
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007334 Include the following line in each recipe:
7335 ::
7336
7337 inherit ptest
7338
7339- *Create run-ptest:* This script starts your test. Locate the
7340 script where you will refer to it using
7341 :term:`SRC_URI`. Here is an
7342 example that starts a test for ``dbus``:
7343 ::
7344
7345 #!/bin/sh
7346 cd test
7347 make -k runtest-TESTS
7348
7349- *Ensure dependencies are met:* If the test adds build or runtime
7350 dependencies that normally do not exist for the package (such as
7351 requiring "make" to run the test suite), use the
7352 :term:`DEPENDS` and
7353 :term:`RDEPENDS` variables in
7354 your recipe in order for the package to meet the dependencies. Here
7355 is an example where the package has a runtime dependency on "make":
7356 ::
7357
7358 RDEPENDS_${PN}-ptest += "make"
7359
7360- *Add a function to build the test suite:* Not many packages support
7361 cross-compilation of their test suites. Consequently, you usually
7362 need to add a cross-compilation function to the package.
7363
7364 Many packages based on Automake compile and run the test suite by
7365 using a single command such as ``make check``. However, the host
7366 ``make check`` builds and runs on the same computer, while
7367 cross-compiling requires that the package is built on the host but
7368 executed for the target architecture (though often, as in the case
7369 for ptest, the execution occurs on the host). The built version of
7370 Automake that ships with the Yocto Project includes a patch that
7371 separates building and execution. Consequently, packages that use the
7372 unaltered, patched version of ``make check`` automatically
7373 cross-compiles.
7374
7375 Regardless, you still must add a ``do_compile_ptest`` function to
7376 build the test suite. Add a function similar to the following to your
7377 recipe:
7378 ::
7379
7380 do_compile_ptest() {
7381 oe_runmake buildtest-TESTS
7382 }
7383
7384- *Ensure special configurations are set:* If the package requires
7385 special configurations prior to compiling the test code, you must
7386 insert a ``do_configure_ptest`` function into the recipe.
7387
7388- *Install the test suite:* The ``ptest`` class automatically copies
7389 the file ``run-ptest`` to the target and then runs make
7390 ``install-ptest`` to run the tests. If this is not enough, you need
7391 to create a ``do_install_ptest`` function and make sure it gets
7392 called after the "make install-ptest" completes.
7393
7394Creating Node Package Manager (NPM) Packages
7395--------------------------------------------
7396
7397`NPM <https://en.wikipedia.org/wiki/Npm_(software)>`__ is a package
7398manager for the JavaScript programming language. The Yocto Project
Andrew Geissler09209ee2020-12-13 08:44:15 -06007399supports the NPM :ref:`fetcher <bitbake:bitbake-user-manual/bitbake-user-manual-fetching:fetchers>`. You can
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007400use this fetcher in combination with
Andrew Geissler09209ee2020-12-13 08:44:15 -06007401:doc:`devtool </ref-manual/devtool-reference>` to create
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007402recipes that produce NPM packages.
7403
7404Two workflows exist that allow you to create NPM packages using
7405``devtool``: the NPM registry modules method and the NPM project code
7406method.
7407
7408.. note::
7409
7410 While it is possible to create NPM recipes manually, using
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007411 ``devtool`` is far simpler.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007412
7413Additionally, some requirements and caveats exist.
7414
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007415Requirements and Caveats
7416~~~~~~~~~~~~~~~~~~~~~~~~
7417
7418You need to be aware of the following before using ``devtool`` to create
7419NPM packages:
7420
7421- Of the two methods that you can use ``devtool`` to create NPM
7422 packages, the registry approach is slightly simpler. However, you
7423 might consider the project approach because you do not have to
7424 publish your module in the NPM registry
7425 (`npm-registry <https://docs.npmjs.com/misc/registry>`_), which
7426 is NPM's public registry.
7427
7428- Be familiar with
Andrew Geissler09209ee2020-12-13 08:44:15 -06007429 :doc:`devtool </ref-manual/devtool-reference>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007430
7431- The NPM host tools need the native ``nodejs-npm`` package, which is
7432 part of the OpenEmbedded environment. You need to get the package by
7433 cloning the https://github.com/openembedded/meta-openembedded
7434 repository out of GitHub. Be sure to add the path to your local copy
7435 to your ``bblayers.conf`` file.
7436
7437- ``devtool`` cannot detect native libraries in module dependencies.
7438 Consequently, you must manually add packages to your recipe.
7439
7440- While deploying NPM packages, ``devtool`` cannot determine which
7441 dependent packages are missing on the target (e.g. the node runtime
7442 ``nodejs``). Consequently, you need to find out what files are
7443 missing and be sure they are on the target.
7444
7445- Although you might not need NPM to run your node package, it is
7446 useful to have NPM on your target. The NPM package name is
7447 ``nodejs-npm``.
7448
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007449Using the Registry Modules Method
7450~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7451
7452This section presents an example that uses the ``cute-files`` module,
7453which is a file browser web application.
7454
7455.. note::
7456
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007457 You must know the ``cute-files`` module version.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007458
7459The first thing you need to do is use ``devtool`` and the NPM fetcher to
7460create the recipe:
7461::
7462
7463 $ devtool add "npm://registry.npmjs.org;package=cute-files;version=1.0.2"
7464
7465The
7466``devtool add`` command runs ``recipetool create`` and uses the same
7467fetch URI to download each dependency and capture license details where
7468possible. The result is a generated recipe.
7469
7470The recipe file is fairly simple and contains every license that
7471``recipetool`` finds and includes the licenses in the recipe's
7472:term:`LIC_FILES_CHKSUM`
7473variables. You need to examine the variables and look for those with
7474"unknown" in the :term:`LICENSE`
7475field. You need to track down the license information for "unknown"
7476modules and manually add the information to the recipe.
7477
7478``recipetool`` creates a "shrinkwrap" file for your recipe. Shrinkwrap
7479files capture the version of all dependent modules. Many packages do not
7480provide shrinkwrap files. ``recipetool`` create a shrinkwrap file as it
7481runs.
7482
7483.. note::
7484
7485 A package is created for each sub-module. This policy is the only
7486 practical way to have the licenses for all of the dependencies
7487 represented in the license manifest of the image.
7488
7489The ``devtool edit-recipe`` command lets you take a look at the recipe:
7490::
7491
7492 $ devtool edit-recipe cute-files
7493 SUMMARY = "Turn any folder on your computer into a cute file browser, available on the local network."
7494 LICENSE = "MIT & ISC & Unknown"
7495 LIC_FILES_CHKSUM = "file://LICENSE;md5=71d98c0a1db42956787b1909c74a86ca \
7496 file://node_modules/toidentifier/LICENSE;md5=1a261071a044d02eb6f2bb47f51a3502 \
7497 file://node_modules/debug/LICENSE;md5=ddd815a475e7338b0be7a14d8ee35a99 \
7498 ...
7499 SRC_URI = " \
7500 npm://registry.npmjs.org/;package=cute-files;version=${PV} \
7501 npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \
7502 "
7503 S = "${WORKDIR}/npm"
7504 inherit npm LICENSE_${PN} = "MIT"
7505 LICENSE_${PN}-accepts = "MIT"
7506 LICENSE_${PN}-array-flatten = "MIT"
7507 ...
7508 LICENSE_${PN}-vary = "MIT"
7509
7510Three key points exist in the previous example:
7511
7512- :term:`SRC_URI` uses the NPM
7513 scheme so that the NPM fetcher is used.
7514
7515- ``recipetool`` collects all the license information. If a
7516 sub-module's license is unavailable, the sub-module's name appears in
7517 the comments.
7518
7519- The ``inherit npm`` statement causes the
7520 :ref:`npm <ref-classes-npm>` class to package
7521 up all the modules.
7522
7523You can run the following command to build the ``cute-files`` package:
7524::
7525
7526 $ devtool build cute-files
7527
7528Remember that ``nodejs`` must be installed on
7529the target before your package.
7530
7531Assuming 192.168.7.2 for the target's IP address, use the following
7532command to deploy your package:
7533::
7534
7535 $ devtool deploy-target -s cute-files root@192.168.7.2
7536
7537Once the package is installed on the target, you can
7538test the application:
7539
7540.. note::
7541
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007542 Because of a known issue, you cannot simply run ``cute-files`` as you would
7543 if you had run ``npm install``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007544
7545::
7546
7547 $ cd /usr/lib/node_modules/cute-files
7548 $ node cute-files.js
7549
7550On a browser,
7551go to ``http://192.168.7.2:3000`` and you see the following:
7552
7553.. image:: figures/cute-files-npm-example.png
7554 :align: center
7555
7556You can find the recipe in ``workspace/recipes/cute-files``. You can use
7557the recipe in any layer you choose.
7558
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007559Using the NPM Projects Code Method
7560~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7561
7562Although it is useful to package modules already in the NPM registry,
7563adding ``node.js`` projects under development is a more common developer
7564use case.
7565
7566This section covers the NPM projects code method, which is very similar
7567to the "registry" approach described in the previous section. In the NPM
7568projects method, you provide ``devtool`` with an URL that points to the
7569source files.
7570
7571Replicating the same example, (i.e. ``cute-files``) use the following
7572command:
7573::
7574
7575 $ devtool add https://github.com/martinaglv/cute-files.git
7576
7577The
7578recipe this command generates is very similar to the recipe created in
7579the previous section. However, the ``SRC_URI`` looks like the following:
7580::
7581
7582 SRC_URI = " \
7583 git://github.com/martinaglv/cute-files.git;protocol=https \
7584 npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \
7585 "
7586
7587In this example,
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007588the main module is taken from the Git repository and dependencies are
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007589taken from the NPM registry. Other than those differences, the recipe is
7590basically the same between the two methods. You can build and deploy the
7591package exactly as described in the previous section that uses the
7592registry modules method.
7593
7594Adding custom metadata to packages
7595----------------------------------
7596
7597The variable
7598:term:`PACKAGE_ADD_METADATA`
7599can be used to add additional metadata to packages. This is reflected in
7600the package control/spec file. To take the ipk format for example, the
7601CONTROL file stored inside would contain the additional metadata as
7602additional lines.
7603
7604The variable can be used in multiple ways, including using suffixes to
7605set it for a specific package type and/or package. Note that the order
7606of precedence is the same as this list:
7607
7608- ``PACKAGE_ADD_METADATA_<PKGTYPE>_<PN>``
7609
7610- ``PACKAGE_ADD_METADATA_<PKGTYPE>``
7611
7612- ``PACKAGE_ADD_METADATA_<PN>``
7613
7614- ``PACKAGE_ADD_METADATA``
7615
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007616`<PKGTYPE>` is a parameter and expected to be a distinct name of specific
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007617package type:
7618
7619- IPK for .ipk packages
7620
7621- DEB for .deb packages
7622
7623- RPM for .rpm packages
7624
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007625`<PN>` is a parameter and expected to be a package name.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007626
7627The variable can contain multiple [one-line] metadata fields separated
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007628by the literal sequence '\\n'. The separator can be redefined using the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007629variable flag ``separator``.
7630
7631The following is an example that adds two custom fields for ipk
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007632packages:
7633::
7634
7635 PACKAGE_ADD_METADATA_IPK = "Vendor: CustomIpk\nGroup:Applications/Spreadsheets"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007636
7637Efficiently Fetching Source Files During a Build
7638================================================
7639
7640The OpenEmbedded build system works with source files located through
7641the :term:`SRC_URI` variable. When
7642you build something using BitBake, a big part of the operation is
7643locating and downloading all the source tarballs. For images,
7644downloading all the source for various packages can take a significant
7645amount of time.
7646
7647This section shows you how you can use mirrors to speed up fetching
7648source files and how you can pre-fetch files all of which leads to more
7649efficient use of resources and time.
7650
7651Setting up Effective Mirrors
7652----------------------------
7653
7654A good deal that goes into a Yocto Project build is simply downloading
7655all of the source tarballs. Maybe you have been working with another
7656build system (OpenEmbedded or Angstrom) for which you have built up a
7657sizable directory of source tarballs. Or, perhaps someone else has such
7658a directory for which you have read access. If so, you can save time by
7659adding statements to your configuration file so that the build process
7660checks local directories first for existing tarballs before checking the
7661Internet.
7662
7663Here is an efficient way to set it up in your ``local.conf`` file:
7664::
7665
7666 SOURCE_MIRROR_URL ?= "file:///home/you/your-download-dir/"
7667 INHERIT += "own-mirrors"
7668 BB_GENERATE_MIRROR_TARBALLS = "1"
7669 # BB_NO_NETWORK = "1"
7670
7671In the previous example, the
7672:term:`BB_GENERATE_MIRROR_TARBALLS`
7673variable causes the OpenEmbedded build system to generate tarballs of
7674the Git repositories and store them in the
7675:term:`DL_DIR` directory. Due to
7676performance reasons, generating and storing these tarballs is not the
7677build system's default behavior.
7678
7679You can also use the
7680:term:`PREMIRRORS` variable. For
7681an example, see the variable's glossary entry in the Yocto Project
7682Reference Manual.
7683
7684Getting Source Files and Suppressing the Build
7685----------------------------------------------
7686
7687Another technique you can use to ready yourself for a successive string
7688of build operations, is to pre-fetch all the source files without
7689actually starting a build. This technique lets you work through any
7690download issues and ultimately gathers all the source files into your
7691download directory :ref:`structure-build-downloads`,
7692which is located with :term:`DL_DIR`.
7693
7694Use the following BitBake command form to fetch all the necessary
7695sources without starting the build:
7696::
7697
7698 $ bitbake target --runall=fetch
7699
7700This
7701variation of the BitBake command guarantees that you have all the
7702sources for that BitBake target should you disconnect from the Internet
7703and want to do the build later offline.
7704
7705Selecting an Initialization Manager
7706===================================
7707
7708By default, the Yocto Project uses SysVinit as the initialization
7709manager. However, support also exists for systemd, which is a full
7710replacement for init with parallel starting of services, reduced shell
7711overhead and other features that are used by many distributions.
7712
7713Within the system, SysVinit treats system components as services. These
7714services are maintained as shell scripts stored in the ``/etc/init.d/``
7715directory. Services organize into different run levels. This
7716organization is maintained by putting links to the services in the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007717``/etc/rcN.d/`` directories, where `N/` is one of the following options:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007718"S", "0", "1", "2", "3", "4", "5", or "6".
7719
7720.. note::
7721
7722 Each runlevel has a dependency on the previous runlevel. This
7723 dependency allows the services to work properly.
7724
7725In comparison, systemd treats components as units. Using units is a
7726broader concept as compared to using a service. A unit includes several
7727different types of entities. Service is one of the types of entities.
7728The runlevel concept in SysVinit corresponds to the concept of a target
7729in systemd, where target is also a type of supported unit.
7730
7731In a SysVinit-based system, services load sequentially (i.e. one by one)
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007732during init and parallelization is not supported. With systemd, services
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007733start in parallel. Needless to say, the method can have an impact on
7734system startup performance.
7735
7736If you want to use SysVinit, you do not have to do anything. But, if you
7737want to use systemd, you must take some steps as described in the
7738following sections.
7739
7740Using systemd Exclusively
7741-------------------------
7742
7743Set these variables in your distribution configuration file as follows:
7744::
7745
7746 DISTRO_FEATURES_append = " systemd"
7747 VIRTUAL-RUNTIME_init_manager = "systemd"
7748
7749You can also prevent the SysVinit distribution feature from
7750being automatically enabled as follows:
7751::
7752
7753 DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
7754
7755Doing so removes any
7756redundant SysVinit scripts.
7757
7758To remove initscripts from your image altogether, set this variable
7759also:
7760::
7761
7762 VIRTUAL-RUNTIME_initscripts = ""
7763
7764For information on the backfill variable, see
7765:term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`.
7766
7767Using systemd for the Main Image and Using SysVinit for the Rescue Image
7768------------------------------------------------------------------------
7769
7770Set these variables in your distribution configuration file as follows:
7771::
7772
7773 DISTRO_FEATURES_append = " systemd"
7774 VIRTUAL-RUNTIME_init_manager = "systemd"
7775
7776Doing so causes your main image to use the
7777``packagegroup-core-boot.bb`` recipe and systemd. The rescue/minimal
7778image cannot use this package group. However, it can install SysVinit
7779and the appropriate packages will have support for both systemd and
7780SysVinit.
7781
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007782Selecting a Device Manager
7783==========================
7784
7785The Yocto Project provides multiple ways to manage the device manager
7786(``/dev``):
7787
7788- Persistent and Pre-Populated\ ``/dev``: For this case, the ``/dev``
7789 directory is persistent and the required device nodes are created
7790 during the build.
7791
7792- Use ``devtmpfs`` with a Device Manager: For this case, the ``/dev``
7793 directory is provided by the kernel as an in-memory file system and
7794 is automatically populated by the kernel at runtime. Additional
7795 configuration of device nodes is done in user space by a device
7796 manager like ``udev`` or ``busybox-mdev``.
7797
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007798Using Persistent and Pre-Populated\ ``/dev``
7799--------------------------------------------
7800
7801To use the static method for device population, you need to set the
7802:term:`USE_DEVFS` variable to "0"
7803as follows:
7804::
7805
7806 USE_DEVFS = "0"
7807
7808The content of the resulting ``/dev`` directory is defined in a Device
7809Table file. The
7810:term:`IMAGE_DEVICE_TABLES`
7811variable defines the Device Table to use and should be set in the
7812machine or distro configuration file. Alternatively, you can set this
7813variable in your ``local.conf`` configuration file.
7814
7815If you do not define the ``IMAGE_DEVICE_TABLES`` variable, the default
7816``device_table-minimal.txt`` is used:
7817::
7818
7819 IMAGE_DEVICE_TABLES = "device_table-mymachine.txt"
7820
7821The population is handled by the ``makedevs`` utility during image
7822creation:
7823
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007824Using ``devtmpfs`` and a Device Manager
7825---------------------------------------
7826
7827To use the dynamic method for device population, you need to use (or be
7828sure to set) the :term:`USE_DEVFS`
7829variable to "1", which is the default:
7830::
7831
7832 USE_DEVFS = "1"
7833
7834With this
7835setting, the resulting ``/dev`` directory is populated by the kernel
7836using ``devtmpfs``. Make sure the corresponding kernel configuration
7837variable ``CONFIG_DEVTMPFS`` is set when building you build a Linux
7838kernel.
7839
7840All devices created by ``devtmpfs`` will be owned by ``root`` and have
7841permissions ``0600``.
7842
7843To have more control over the device nodes, you can use a device manager
7844like ``udev`` or ``busybox-mdev``. You choose the device manager by
7845defining the ``VIRTUAL-RUNTIME_dev_manager`` variable in your machine or
7846distro configuration file. Alternatively, you can set this variable in
7847your ``local.conf`` configuration file:
7848::
7849
7850 VIRTUAL-RUNTIME_dev_manager = "udev"
7851
7852 # Some alternative values
7853 # VIRTUAL-RUNTIME_dev_manager = "busybox-mdev"
7854 # VIRTUAL-RUNTIME_dev_manager = "systemd"
7855
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007856Using an External SCM
7857=====================
7858
7859If you're working on a recipe that pulls from an external Source Code
7860Manager (SCM), it is possible to have the OpenEmbedded build system
7861notice new recipe changes added to the SCM and then build the resulting
7862packages that depend on the new recipes by using the latest versions.
7863This only works for SCMs from which it is possible to get a sensible
7864revision number for changes. Currently, you can do this with Apache
7865Subversion (SVN), Git, and Bazaar (BZR) repositories.
7866
7867To enable this behavior, the :term:`PV` of
7868the recipe needs to reference
7869:term:`SRCPV`. Here is an example:
7870::
7871
7872 PV = "1.2.3+git${SRCPV}"
7873
7874Then, you can add the following to your
7875``local.conf``:
7876::
7877
7878 SRCREV_pn-PN = "${AUTOREV}"
7879
7880:term:`PN` is the name of the recipe for
7881which you want to enable automatic source revision updating.
7882
7883If you do not want to update your local configuration file, you can add
7884the following directly to the recipe to finish enabling the feature:
7885::
7886
7887 SRCREV = "${AUTOREV}"
7888
7889The Yocto Project provides a distribution named ``poky-bleeding``, whose
7890configuration file contains the line:
7891::
7892
7893 require conf/distro/include/poky-floating-revisions.inc
7894
7895This line pulls in the
7896listed include file that contains numerous lines of exactly that form:
7897::
7898
7899 #SRCREV_pn-opkg-native ?= "${AUTOREV}"
7900 #SRCREV_pn-opkg-sdk ?= "${AUTOREV}"
7901 #SRCREV_pn-opkg ?= "${AUTOREV}"
7902 #SRCREV_pn-opkg-utils-native ?= "${AUTOREV}"
7903 #SRCREV_pn-opkg-utils ?= "${AUTOREV}"
7904 SRCREV_pn-gconf-dbus ?= "${AUTOREV}"
7905 SRCREV_pn-matchbox-common ?= "${AUTOREV}"
7906 SRCREV_pn-matchbox-config-gtk ?= "${AUTOREV}"
7907 SRCREV_pn-matchbox-desktop ?= "${AUTOREV}"
7908 SRCREV_pn-matchbox-keyboard ?= "${AUTOREV}"
7909 SRCREV_pn-matchbox-panel-2 ?= "${AUTOREV}"
7910 SRCREV_pn-matchbox-themes-extra ?= "${AUTOREV}"
7911 SRCREV_pn-matchbox-terminal ?= "${AUTOREV}"
7912 SRCREV_pn-matchbox-wm ?= "${AUTOREV}"
7913 SRCREV_pn-settings-daemon ?= "${AUTOREV}"
7914 SRCREV_pn-screenshot ?= "${AUTOREV}"
7915 . . .
7916
7917These lines allow you to
7918experiment with building a distribution that tracks the latest
7919development source for numerous packages.
7920
7921.. note::
7922
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007923 The ``poky-bleeding`` distribution is not tested on a regular basis. Keep
7924 this in mind if you use it.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007925
7926Creating a Read-Only Root Filesystem
7927====================================
7928
7929Suppose, for security reasons, you need to disable your target device's
7930root filesystem's write permissions (i.e. you need a read-only root
7931filesystem). Or, perhaps you are running the device's operating system
7932from a read-only storage device. For either case, you can customize your
7933image for that behavior.
7934
7935.. note::
7936
7937 Supporting a read-only root filesystem requires that the system and
7938 applications do not try to write to the root filesystem. You must
7939 configure all parts of the target system to write elsewhere, or to
7940 gracefully fail in the event of attempting to write to the root
7941 filesystem.
7942
7943Creating the Root Filesystem
7944----------------------------
7945
7946To create the read-only root filesystem, simply add the
7947"read-only-rootfs" feature to your image, normally in one of two ways.
7948The first way is to add the "read-only-rootfs" image feature in the
7949image's recipe file via the ``IMAGE_FEATURES`` variable:
7950::
7951
7952 IMAGE_FEATURES += "read-only-rootfs"
7953
7954As an alternative, you can add the same feature
7955from within your build directory's ``local.conf`` file with the
7956associated ``EXTRA_IMAGE_FEATURES`` variable, as in:
7957::
7958
7959 EXTRA_IMAGE_FEATURES = "read-only-rootfs"
7960
7961For more information on how to use these variables, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06007962":ref:`dev-manual/common-tasks:Customizing Images Using Custom \`\`IMAGE_FEATURES\`\` and \`\`EXTRA_IMAGE_FEATURES\`\``"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007963section. For information on the variables, see
7964:term:`IMAGE_FEATURES` and
7965:term:`EXTRA_IMAGE_FEATURES`.
7966
7967Post-Installation Scripts and Read-Only Root Filesystem
7968-------------------------------------------------------
7969
7970It is very important that you make sure all post-Installation
7971(``pkg_postinst``) scripts for packages that are installed into the
7972image can be run at the time when the root filesystem is created during
7973the build on the host system. These scripts cannot attempt to run during
7974first-boot on the target device. With the "read-only-rootfs" feature
7975enabled, the build system checks during root filesystem creation to make
7976sure all post-installation scripts succeed. If any of these scripts
7977still need to be run after the root filesystem is created, the build
7978immediately fails. These build-time checks ensure that the build fails
7979rather than the target device fails later during its initial boot
7980operation.
7981
7982Most of the common post-installation scripts generated by the build
7983system for the out-of-the-box Yocto Project are engineered so that they
7984can run during root filesystem creation (e.g. post-installation scripts
7985for caching fonts). However, if you create and add custom scripts, you
7986need to be sure they can be run during this file system creation.
7987
7988Here are some common problems that prevent post-installation scripts
7989from running during root filesystem creation:
7990
7991- *Not using $D in front of absolute paths:* The build system defines
7992 ``$``\ :term:`D` when the root
7993 filesystem is created. Furthermore, ``$D`` is blank when the script
7994 is run on the target device. This implies two purposes for ``$D``:
7995 ensuring paths are valid in both the host and target environments,
7996 and checking to determine which environment is being used as a method
7997 for taking appropriate actions.
7998
7999- *Attempting to run processes that are specific to or dependent on the
8000 target architecture:* You can work around these attempts by using
8001 native tools, which run on the host system, to accomplish the same
8002 tasks, or by alternatively running the processes under QEMU, which
8003 has the ``qemu_run_binary`` function. For more information, see the
8004 :ref:`qemu <ref-classes-qemu>` class.
8005
8006Areas With Write Access
8007-----------------------
8008
8009With the "read-only-rootfs" feature enabled, any attempt by the target
8010to write to the root filesystem at runtime fails. Consequently, you must
8011make sure that you configure processes and applications that attempt
8012these types of writes do so to directories with write access (e.g.
8013``/tmp`` or ``/var/run``).
8014
8015Maintaining Build Output Quality
8016================================
8017
8018Many factors can influence the quality of a build. For example, if you
8019upgrade a recipe to use a new version of an upstream software package or
8020you experiment with some new configuration options, subtle changes can
8021occur that you might not detect until later. Consider the case where
8022your recipe is using a newer version of an upstream package. In this
8023case, a new version of a piece of software might introduce an optional
8024dependency on another library, which is auto-detected. If that library
8025has already been built when the software is building, the software will
8026link to the built library and that library will be pulled into your
8027image along with the new software even if you did not want the library.
8028
8029The :ref:`buildhistory <ref-classes-buildhistory>`
8030class exists to help you maintain the quality of your build output. You
8031can use the class to highlight unexpected and possibly unwanted changes
8032in the build output. When you enable build history, it records
8033information about the contents of each package and image and then
8034commits that information to a local Git repository where you can examine
8035the information.
8036
8037The remainder of this section describes the following:
8038
Andrew Geissler09209ee2020-12-13 08:44:15 -06008039- :ref:`How you can enable and disable build history <dev-manual/common-tasks:enabling and disabling build history>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008040
Andrew Geissler09209ee2020-12-13 08:44:15 -06008041- :ref:`How to understand what the build history contains <dev-manual/common-tasks:understanding what the build history contains>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008042
Andrew Geissler09209ee2020-12-13 08:44:15 -06008043- :ref:`How to limit the information used for build history <dev-manual/common-tasks:using build history to gather image information only>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008044
Andrew Geissler09209ee2020-12-13 08:44:15 -06008045- :ref:`How to examine the build history from both a command-line and web interface <dev-manual/common-tasks:examining build history information>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008046
8047Enabling and Disabling Build History
8048------------------------------------
8049
8050Build history is disabled by default. To enable it, add the following
8051``INHERIT`` statement and set the
8052:term:`BUILDHISTORY_COMMIT`
8053variable to "1" at the end of your ``conf/local.conf`` file found in the
8054:term:`Build Directory`:
8055::
8056
8057 INHERIT += "buildhistory"
8058 BUILDHISTORY_COMMIT = "1"
8059
8060Enabling build history as
8061previously described causes the OpenEmbedded build system to collect
8062build output information and commit it as a single commit to a local
Andrew Geissler09209ee2020-12-13 08:44:15 -06008063:ref:`overview-manual/development-environment:git` repository.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008064
8065.. note::
8066
8067 Enabling build history increases your build times slightly,
8068 particularly for images, and increases the amount of disk space used
8069 during the build.
8070
8071You can disable build history by removing the previous statements from
8072your ``conf/local.conf`` file.
8073
8074Understanding What the Build History Contains
8075---------------------------------------------
8076
8077Build history information is kept in
8078``${``\ :term:`TOPDIR`\ ``}/buildhistory``
8079in the Build Directory as defined by the
8080:term:`BUILDHISTORY_DIR`
8081variable. The following is an example abbreviated listing:
8082
8083.. image:: figures/buildhistory.png
8084 :align: center
8085
8086At the top level, a ``metadata-revs`` file exists that lists the
8087revisions of the repositories for the enabled layers when the build was
8088produced. The rest of the data splits into separate ``packages``,
8089``images`` and ``sdk`` directories, the contents of which are described
8090as follows.
8091
8092Build History Package Information
8093~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8094
8095The history for each package contains a text file that has name-value
8096pairs with information about the package. For example,
8097``buildhistory/packages/i586-poky-linux/busybox/busybox/latest``
8098contains the following:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008099
8100.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008101
8102 PV = 1.22.1
8103 PR = r32
8104 RPROVIDES =
8105 RDEPENDS = glibc (>= 2.20) update-alternatives-opkg
8106 RRECOMMENDS = busybox-syslog busybox-udhcpc update-rc.d
8107 PKGSIZE = 540168
8108 FILES = /usr/bin/* /usr/sbin/* /usr/lib/busybox/* /usr/lib/lib*.so.* \
8109 /etc /com /var /bin/* /sbin/* /lib/*.so.* /lib/udev/rules.d \
8110 /usr/lib/udev/rules.d /usr/share/busybox /usr/lib/busybox/* \
8111 /usr/share/pixmaps /usr/share/applications /usr/share/idl \
8112 /usr/share/omf /usr/share/sounds /usr/lib/bonobo/servers
8113 FILELIST = /bin/busybox /bin/busybox.nosuid /bin/busybox.suid /bin/sh \
8114 /etc/busybox.links.nosuid /etc/busybox.links.suid
8115
8116Most of these
8117name-value pairs correspond to variables used to produce the package.
8118The exceptions are ``FILELIST``, which is the actual list of files in
8119the package, and ``PKGSIZE``, which is the total size of files in the
8120package in bytes.
8121
8122A file also exists that corresponds to the recipe from which the package
8123came (e.g. ``buildhistory/packages/i586-poky-linux/busybox/latest``):
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008124
8125.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008126
8127 PV = 1.22.1
8128 PR = r32
8129 DEPENDS = initscripts kern-tools-native update-rc.d-native \
8130 virtual/i586-poky-linux-compilerlibs virtual/i586-poky-linux-gcc \
8131 virtual/libc virtual/update-alternatives
8132 PACKAGES = busybox-ptest busybox-httpd busybox-udhcpd busybox-udhcpc \
8133 busybox-syslog busybox-mdev busybox-hwclock busybox-dbg \
8134 busybox-staticdev busybox-dev busybox-doc busybox-locale busybox
8135
8136Finally, for those recipes fetched from a version control system (e.g.,
8137Git), a file exists that lists source revisions that are specified in
8138the recipe and lists the actual revisions used during the build. Listed
8139and actual revisions might differ when
8140:term:`SRCREV` is set to
8141${:term:`AUTOREV`}. Here is an
8142example assuming
8143``buildhistory/packages/qemux86-poky-linux/linux-yocto/latest_srcrev``):
8144::
8145
8146 # SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
8147 SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
8148 # SRCREV_meta = "a227f20eff056e511d504b2e490f3774ab260d6f"
8149 SRCREV_meta ="a227f20eff056e511d504b2e490f3774ab260d6f"
8150
8151You can use the
8152``buildhistory-collect-srcrevs`` command with the ``-a`` option to
8153collect the stored ``SRCREV`` values from build history and report them
8154in a format suitable for use in global configuration (e.g.,
8155``local.conf`` or a distro include file) to override floating
8156``AUTOREV`` values to a fixed set of revisions. Here is some example
8157output from this command:
8158::
8159
8160 $ buildhistory-collect-srcrevs -a
8161 # i586-poky-linux
8162 SRCREV_pn-glibc = "b8079dd0d360648e4e8de48656c5c38972621072"
8163 SRCREV_pn-glibc-initial = "b8079dd0d360648e4e8de48656c5c38972621072"
8164 SRCREV_pn-opkg-utils = "53274f087565fd45d8452c5367997ba6a682a37a"
8165 SRCREV_pn-kmod = "fd56638aed3fe147015bfa10ed4a5f7491303cb4"
8166 # x86_64-linux
8167 SRCREV_pn-gtk-doc-stub-native = "1dea266593edb766d6d898c79451ef193eb17cfa"
8168 SRCREV_pn-dtc-native = "65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf"
8169 SRCREV_pn-update-rc.d-native = "eca680ddf28d024954895f59a241a622dd575c11"
8170 SRCREV_glibc_pn-cross-localedef-native = "b8079dd0d360648e4e8de48656c5c38972621072"
8171 SRCREV_localedef_pn-cross-localedef-native = "c833367348d39dad7ba018990bfdaffaec8e9ed3"
8172 SRCREV_pn-prelink-native = "faa069deec99bf61418d0bab831c83d7c1b797ca"
8173 SRCREV_pn-opkg-utils-native = "53274f087565fd45d8452c5367997ba6a682a37a"
8174 SRCREV_pn-kern-tools-native = "23345b8846fe4bd167efdf1bd8a1224b2ba9a5ff"
8175 SRCREV_pn-kmod-native = "fd56638aed3fe147015bfa10ed4a5f7491303cb4"
8176 # qemux86-poky-linux
8177 SRCREV_machine_pn-linux-yocto = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
8178 SRCREV_meta_pn-linux-yocto = "a227f20eff056e511d504b2e490f3774ab260d6f"
8179 # all-poky-linux
8180 SRCREV_pn-update-rc.d = "eca680ddf28d024954895f59a241a622dd575c11"
8181
8182.. note::
8183
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008184 Here are some notes on using the ``buildhistory-collect-srcrevs`` command:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008185
8186 - By default, only values where the ``SRCREV`` was not hardcoded
8187 (usually when ``AUTOREV`` is used) are reported. Use the ``-a``
8188 option to see all ``SRCREV`` values.
8189
8190 - The output statements might not have any effect if overrides are
8191 applied elsewhere in the build system configuration. Use the
8192 ``-f`` option to add the ``forcevariable`` override to each output
8193 line if you need to work around this restriction.
8194
8195 - The script does apply special handling when building for multiple
8196 machines. However, the script does place a comment before each set
8197 of values that specifies which triplet to which they belong as
8198 previously shown (e.g., ``i586-poky-linux``).
8199
8200Build History Image Information
8201~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8202
8203The files produced for each image are as follows:
8204
8205- ``image-files:`` A directory containing selected files from the root
8206 filesystem. The files are defined by
8207 :term:`BUILDHISTORY_IMAGE_FILES`.
8208
8209- ``build-id.txt:`` Human-readable information about the build
8210 configuration and metadata source revisions. This file contains the
8211 full build header as printed by BitBake.
8212
8213- ``*.dot:`` Dependency graphs for the image that are compatible with
8214 ``graphviz``.
8215
8216- ``files-in-image.txt:`` A list of files in the image with
8217 permissions, owner, group, size, and symlink information.
8218
8219- ``image-info.txt:`` A text file containing name-value pairs with
8220 information about the image. See the following listing example for
8221 more information.
8222
8223- ``installed-package-names.txt:`` A list of installed packages by name
8224 only.
8225
8226- ``installed-package-sizes.txt:`` A list of installed packages ordered
8227 by size.
8228
8229- ``installed-packages.txt:`` A list of installed packages with full
8230 package filenames.
8231
8232.. note::
8233
8234 Installed package information is able to be gathered and produced
8235 even if package management is disabled for the final image.
8236
8237Here is an example of ``image-info.txt``:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008238
8239.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008240
8241 DISTRO = poky
8242 DISTRO_VERSION = 1.7
8243 USER_CLASSES = buildstats image-mklibs image-prelink
8244 IMAGE_CLASSES = image_types
8245 IMAGE_FEATURES = debug-tweaks
8246 IMAGE_LINGUAS =
8247 IMAGE_INSTALL = packagegroup-core-boot run-postinsts
8248 BAD_RECOMMENDATIONS =
8249 NO_RECOMMENDATIONS =
8250 PACKAGE_EXCLUDE =
8251 ROOTFS_POSTPROCESS_COMMAND = write_package_manifest; license_create_manifest; \
8252 write_image_manifest ; buildhistory_list_installed_image ; \
8253 buildhistory_get_image_installed ; ssh_allow_empty_password; \
8254 postinst_enable_logging; rootfs_update_timestamp ; ssh_disable_dns_lookup ;
8255 IMAGE_POSTPROCESS_COMMAND = buildhistory_get_imageinfo ;
8256 IMAGESIZE = 6900
8257
8258Other than ``IMAGESIZE``,
8259which is the total size of the files in the image in Kbytes, the
8260name-value pairs are variables that may have influenced the content of
8261the image. This information is often useful when you are trying to
8262determine why a change in the package or file listings has occurred.
8263
8264Using Build History to Gather Image Information Only
8265~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8266
8267As you can see, build history produces image information, including
8268dependency graphs, so you can see why something was pulled into the
8269image. If you are just interested in this information and not interested
8270in collecting specific package or SDK information, you can enable
8271writing only image information without any history by adding the
8272following to your ``conf/local.conf`` file found in the
8273:term:`Build Directory`:
8274::
8275
8276 INHERIT += "buildhistory"
8277 BUILDHISTORY_COMMIT = "0"
8278 BUILDHISTORY_FEATURES = "image"
8279
8280Here, you set the
8281:term:`BUILDHISTORY_FEATURES`
8282variable to use the image feature only.
8283
8284Build History SDK Information
8285~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8286
8287Build history collects similar information on the contents of SDKs (e.g.
8288``bitbake -c populate_sdk imagename``) as compared to information it
8289collects for images. Furthermore, this information differs depending on
8290whether an extensible or standard SDK is being produced.
8291
8292The following list shows the files produced for SDKs:
8293
8294- ``files-in-sdk.txt:`` A list of files in the SDK with permissions,
8295 owner, group, size, and symlink information. This list includes both
8296 the host and target parts of the SDK.
8297
8298- ``sdk-info.txt:`` A text file containing name-value pairs with
8299 information about the SDK. See the following listing example for more
8300 information.
8301
8302- ``sstate-task-sizes.txt:`` A text file containing name-value pairs
8303 with information about task group sizes (e.g. ``do_populate_sysroot``
8304 tasks have a total size). The ``sstate-task-sizes.txt`` file exists
8305 only when an extensible SDK is created.
8306
8307- ``sstate-package-sizes.txt:`` A text file containing name-value pairs
8308 with information for the shared-state packages and sizes in the SDK.
8309 The ``sstate-package-sizes.txt`` file exists only when an extensible
8310 SDK is created.
8311
8312- ``sdk-files:`` A folder that contains copies of the files mentioned
8313 in ``BUILDHISTORY_SDK_FILES`` if the files are present in the output.
8314 Additionally, the default value of ``BUILDHISTORY_SDK_FILES`` is
8315 specific to the extensible SDK although you can set it differently if
8316 you would like to pull in specific files from the standard SDK.
8317
8318 The default files are ``conf/local.conf``, ``conf/bblayers.conf``,
8319 ``conf/auto.conf``, ``conf/locked-sigs.inc``, and
8320 ``conf/devtool.conf``. Thus, for an extensible SDK, these files get
8321 copied into the ``sdk-files`` directory.
8322
8323- The following information appears under each of the ``host`` and
8324 ``target`` directories for the portions of the SDK that run on the
8325 host and on the target, respectively:
8326
8327 .. note::
8328
8329 The following files for the most part are empty when producing an
8330 extensible SDK because this type of SDK is not constructed from
8331 packages as is the standard SDK.
8332
8333 - ``depends.dot:`` Dependency graph for the SDK that is compatible
8334 with ``graphviz``.
8335
8336 - ``installed-package-names.txt:`` A list of installed packages by
8337 name only.
8338
8339 - ``installed-package-sizes.txt:`` A list of installed packages
8340 ordered by size.
8341
8342 - ``installed-packages.txt:`` A list of installed packages with full
8343 package filenames.
8344
8345Here is an example of ``sdk-info.txt``:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008346
8347.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008348
8349 DISTRO = poky
8350 DISTRO_VERSION = 1.3+snapshot-20130327
8351 SDK_NAME = poky-glibc-i686-arm
8352 SDK_VERSION = 1.3+snapshot
8353 SDKMACHINE =
8354 SDKIMAGE_FEATURES = dev-pkgs dbg-pkgs
8355 BAD_RECOMMENDATIONS =
8356 SDKSIZE = 352712
8357
8358Other than ``SDKSIZE``, which is
8359the total size of the files in the SDK in Kbytes, the name-value pairs
8360are variables that might have influenced the content of the SDK. This
8361information is often useful when you are trying to determine why a
8362change in the package or file listings has occurred.
8363
8364Examining Build History Information
8365~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8366
8367You can examine build history output from the command line or from a web
8368interface.
8369
8370To see any changes that have occurred (assuming you have
8371:term:`BUILDHISTORY_COMMIT` = "1"),
8372you can simply use any Git command that allows you to view the history
8373of a repository. Here is one method:
8374::
8375
8376 $ git log -p
8377
8378You need to realize,
8379however, that this method does show changes that are not significant
8380(e.g. a package's size changing by a few bytes).
8381
8382A command-line tool called ``buildhistory-diff`` does exist, though,
8383that queries the Git repository and prints just the differences that
8384might be significant in human-readable form. Here is an example:
8385::
8386
Andrew Geissler95ac1b82021-03-31 14:34:31 -05008387 $ poky/poky/scripts/buildhistory-diff . HEAD^
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008388 Changes to images/qemux86_64/glibc/core-image-minimal (files-in-image.txt):
8389 /etc/anotherpkg.conf was added
8390 /sbin/anotherpkg was added
8391 * (installed-package-names.txt):
8392 * anotherpkg was added
8393 Changes to images/qemux86_64/glibc/core-image-minimal (installed-package-names.txt):
8394 anotherpkg was added
8395 packages/qemux86_64-poky-linux/v86d: PACKAGES: added "v86d-extras"
8396 * PR changed from "r0" to "r1"
8397 * PV changed from "0.1.10" to "0.1.12"
8398 packages/qemux86_64-poky-linux/v86d/v86d: PKGSIZE changed from 110579 to 144381 (+30%)
8399 * PR changed from "r0" to "r1"
8400 * PV changed from "0.1.10" to "0.1.12"
8401
8402.. note::
8403
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008404 The ``buildhistory-diff`` tool requires the ``GitPython``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008405 package. Be sure to install it using Pip3 as follows:
8406 ::
8407
8408 $ pip3 install GitPython --user
8409
8410
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008411 Alternatively, you can install ``python3-git`` using the appropriate
8412 distribution package manager (e.g. ``apt-get``, ``dnf``, or ``zipper``).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008413
8414To see changes to the build history using a web interface, follow the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008415instruction in the ``README`` file
Andrew Geissler09209ee2020-12-13 08:44:15 -06008416:yocto_git:`here </buildhistory-web/>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008417
8418Here is a sample screenshot of the interface:
8419
8420.. image:: figures/buildhistory-web.png
8421 :align: center
8422
8423Performing Automated Runtime Testing
8424====================================
8425
8426The OpenEmbedded build system makes available a series of automated
8427tests for images to verify runtime functionality. You can run these
8428tests on either QEMU or actual target hardware. Tests are written in
8429Python making use of the ``unittest`` module, and the majority of them
8430run commands on the target system over SSH. This section describes how
8431you set up the environment to use these tests, run available tests, and
8432write and add your own tests.
8433
8434For information on the test and QA infrastructure available within the
Andrew Geissler09209ee2020-12-13 08:44:15 -06008435Yocto Project, see the ":ref:`ref-manual/release-process:testing and quality assurance`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008436section in the Yocto Project Reference Manual.
8437
8438Enabling Tests
8439--------------
8440
8441Depending on whether you are planning to run tests using QEMU or on the
8442hardware, you have to take different steps to enable the tests. See the
8443following subsections for information on how to enable both types of
8444tests.
8445
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008446Enabling Runtime Tests on QEMU
8447~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8448
8449In order to run tests, you need to do the following:
8450
8451- *Set up to avoid interaction with sudo for networking:* To
8452 accomplish this, you must do one of the following:
8453
8454 - Add ``NOPASSWD`` for your user in ``/etc/sudoers`` either for all
8455 commands or just for ``runqemu-ifup``. You must provide the full
8456 path as that can change if you are using multiple clones of the
8457 source repository.
8458
8459 .. note::
8460
8461 On some distributions, you also need to comment out "Defaults
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008462 requiretty" in ``/etc/sudoers``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008463
8464 - Manually configure a tap interface for your system.
8465
8466 - Run as root the script in ``scripts/runqemu-gen-tapdevs``, which
8467 should generate a list of tap devices. This is the option
8468 typically chosen for Autobuilder-type environments.
8469
8470 .. note::
8471
8472 - Be sure to use an absolute path when calling this script
8473 with sudo.
8474
8475 - The package recipe ``qemu-helper-native`` is required to run
8476 this script. Build the package using the following command:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008477 ::
8478
8479 $ bitbake qemu-helper-native
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008480
8481- *Set the DISPLAY variable:* You need to set this variable so that
8482 you have an X server available (e.g. start ``vncserver`` for a
8483 headless machine).
8484
8485- *Be sure your host's firewall accepts incoming connections from
8486 192.168.7.0/24:* Some of the tests (in particular DNF tests) start an
8487 HTTP server on a random high number port, which is used to serve
8488 files to the target. The DNF module serves
8489 ``${WORKDIR}/oe-rootfs-repo`` so it can run DNF channel commands.
8490 That means your host's firewall must accept incoming connections from
8491 192.168.7.0/24, which is the default IP range used for tap devices by
8492 ``runqemu``.
8493
8494- *Be sure your host has the correct packages installed:* Depending
8495 your host's distribution, you need to have the following packages
8496 installed:
8497
8498 - Ubuntu and Debian: ``sysstat`` and ``iproute2``
8499
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05008500 - openSUSE: ``sysstat`` and ``iproute2``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008501
8502 - Fedora: ``sysstat`` and ``iproute``
8503
8504 - CentOS: ``sysstat`` and ``iproute``
8505
8506Once you start running the tests, the following happens:
8507
85081. A copy of the root filesystem is written to ``${WORKDIR}/testimage``.
8509
85102. The image is booted under QEMU using the standard ``runqemu`` script.
8511
85123. A default timeout of 500 seconds occurs to allow for the boot process
8513 to reach the login prompt. You can change the timeout period by
8514 setting
8515 :term:`TEST_QEMUBOOT_TIMEOUT`
8516 in the ``local.conf`` file.
8517
85184. Once the boot process is reached and the login prompt appears, the
8519 tests run. The full boot log is written to
8520 ``${WORKDIR}/testimage/qemu_boot_log``.
8521
85225. Each test module loads in the order found in ``TEST_SUITES``. You can
8523 find the full output of the commands run over SSH in
8524 ``${WORKDIR}/testimgage/ssh_target_log``.
8525
85266. If no failures occur, the task running the tests ends successfully.
8527 You can find the output from the ``unittest`` in the task log at
8528 ``${WORKDIR}/temp/log.do_testimage``.
8529
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008530Enabling Runtime Tests on Hardware
8531~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8532
8533The OpenEmbedded build system can run tests on real hardware, and for
8534certain devices it can also deploy the image to be tested onto the
8535device beforehand.
8536
8537For automated deployment, a "master image" is installed onto the
8538hardware once as part of setup. Then, each time tests are to be run, the
8539following occurs:
8540
85411. The master image is booted into and used to write the image to be
8542 tested to a second partition.
8543
85442. The device is then rebooted using an external script that you need to
8545 provide.
8546
85473. The device boots into the image to be tested.
8548
8549When running tests (independent of whether the image has been deployed
8550automatically or not), the device is expected to be connected to a
8551network on a pre-determined IP address. You can either use static IP
8552addresses written into the image, or set the image to use DHCP and have
8553your DHCP server on the test network assign a known IP address based on
8554the MAC address of the device.
8555
8556In order to run tests on hardware, you need to set ``TEST_TARGET`` to an
8557appropriate value. For QEMU, you do not have to change anything, the
8558default value is "qemu". For running tests on hardware, the following
8559options exist:
8560
8561- *"simpleremote":* Choose "simpleremote" if you are going to run tests
8562 on a target system that is already running the image to be tested and
8563 is available on the network. You can use "simpleremote" in
8564 conjunction with either real hardware or an image running within a
8565 separately started QEMU or any other virtual machine manager.
8566
8567- *"SystemdbootTarget":* Choose "SystemdbootTarget" if your hardware is
8568 an EFI-based machine with ``systemd-boot`` as bootloader and
8569 ``core-image-testmaster`` (or something similar) is installed. Also,
8570 your hardware under test must be in a DHCP-enabled network that gives
8571 it the same IP address for each reboot.
8572
8573 If you choose "SystemdbootTarget", there are additional requirements
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05008574 and considerations. See the
8575 ":ref:`dev-manual/common-tasks:selecting systemdboottarget`" section, which
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008576 follows, for more information.
8577
8578- *"BeagleBoneTarget":* Choose "BeagleBoneTarget" if you are deploying
8579 images and running tests on the BeagleBone "Black" or original
8580 "White" hardware. For information on how to use these tests, see the
8581 comments at the top of the BeagleBoneTarget
8582 ``meta-yocto-bsp/lib/oeqa/controllers/beaglebonetarget.py`` file.
8583
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008584- *"EdgeRouterTarget":* Choose "EdgeRouterTarget" if you are deploying
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008585 images and running tests on the Ubiquiti Networks EdgeRouter Lite.
8586 For information on how to use these tests, see the comments at the
8587 top of the EdgeRouterTarget
8588 ``meta-yocto-bsp/lib/oeqa/controllers/edgeroutertarget.py`` file.
8589
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008590- *"GrubTarget":* Choose "GrubTarget" if you are deploying images and running
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008591 tests on any generic PC that boots using GRUB. For information on how
8592 to use these tests, see the comments at the top of the GrubTarget
8593 ``meta-yocto-bsp/lib/oeqa/controllers/grubtarget.py`` file.
8594
8595- *"your-target":* Create your own custom target if you want to run
8596 tests when you are deploying images and running tests on a custom
8597 machine within your BSP layer. To do this, you need to add a Python
8598 unit that defines the target class under ``lib/oeqa/controllers/``
8599 within your layer. You must also provide an empty ``__init__.py``.
8600 For examples, see files in ``meta-yocto-bsp/lib/oeqa/controllers/``.
8601
8602Selecting SystemdbootTarget
8603~~~~~~~~~~~~~~~~~~~~~~~~~~~
8604
8605If you did not set ``TEST_TARGET`` to "SystemdbootTarget", then you do
8606not need any information in this section. You can skip down to the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05008607":ref:`dev-manual/common-tasks:running tests`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008608
8609If you did set ``TEST_TARGET`` to "SystemdbootTarget", you also need to
8610perform a one-time setup of your master image by doing the following:
8611
86121. *Set EFI_PROVIDER:* Be sure that ``EFI_PROVIDER`` is as follows:
8613 ::
8614
8615 EFI_PROVIDER = "systemd-boot"
8616
86172. *Build the master image:* Build the ``core-image-testmaster`` image.
8618 The ``core-image-testmaster`` recipe is provided as an example for a
8619 "master" image and you can customize the image recipe as you would
8620 any other recipe.
8621
8622 Here are the image recipe requirements:
8623
8624 - Inherits ``core-image`` so that kernel modules are installed.
8625
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05008626 - Installs normal linux utilities not BusyBox ones (e.g. ``bash``,
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008627 ``coreutils``, ``tar``, ``gzip``, and ``kmod``).
8628
8629 - Uses a custom Initial RAM Disk (initramfs) image with a custom
8630 installer. A normal image that you can install usually creates a
8631 single rootfs partition. This image uses another installer that
8632 creates a specific partition layout. Not all Board Support
8633 Packages (BSPs) can use an installer. For such cases, you need to
8634 manually create the following partition layout on the target:
8635
8636 - First partition mounted under ``/boot``, labeled "boot".
8637
8638 - The main rootfs partition where this image gets installed,
8639 which is mounted under ``/``.
8640
8641 - Another partition labeled "testrootfs" where test images get
8642 deployed.
8643
86443. *Install image:* Install the image that you just built on the target
8645 system.
8646
8647The final thing you need to do when setting ``TEST_TARGET`` to
8648"SystemdbootTarget" is to set up the test image:
8649
86501. *Set up your local.conf file:* Make sure you have the following
8651 statements in your ``local.conf`` file:
8652 ::
8653
8654 IMAGE_FSTYPES += "tar.gz"
8655 INHERIT += "testimage"
8656 TEST_TARGET = "SystemdbootTarget"
8657 TEST_TARGET_IP = "192.168.2.3"
8658
86592. *Build your test image:* Use BitBake to build the image:
8660 ::
8661
8662 $ bitbake core-image-sato
8663
8664Power Control
8665~~~~~~~~~~~~~
8666
8667For most hardware targets other than "simpleremote", you can control
8668power:
8669
8670- You can use ``TEST_POWERCONTROL_CMD`` together with
8671 ``TEST_POWERCONTROL_EXTRA_ARGS`` as a command that runs on the host
8672 and does power cycling. The test code passes one argument to that
8673 command: off, on or cycle (off then on). Here is an example that
8674 could appear in your ``local.conf`` file:
8675 ::
8676
8677 TEST_POWERCONTROL_CMD = "powercontrol.exp test 10.11.12.1 nuc1"
8678
8679 In this example, the expect
8680 script does the following:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008681
8682 .. code-block:: shell
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008683
8684 ssh test@10.11.12.1 "pyctl nuc1 arg"
8685
8686 It then runs a Python script that controls power for a label called
8687 ``nuc1``.
8688
8689 .. note::
8690
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008691 You need to customize ``TEST_POWERCONTROL_CMD`` and
8692 ``TEST_POWERCONTROL_EXTRA_ARGS`` for your own setup. The one requirement
8693 is that it accepts "on", "off", and "cycle" as the last argument.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008694
8695- When no command is defined, it connects to the device over SSH and
8696 uses the classic reboot command to reboot the device. Classic reboot
8697 is fine as long as the machine actually reboots (i.e. the SSH test
8698 has not failed). It is useful for scenarios where you have a simple
8699 setup, typically with a single board, and where some manual
8700 interaction is okay from time to time.
8701
8702If you have no hardware to automatically perform power control but still
8703wish to experiment with automated hardware testing, you can use the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008704``dialog-power-control`` script that shows a dialog prompting you to perform
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008705the required power action. This script requires either KDialog or Zenity
8706to be installed. To use this script, set the
8707:term:`TEST_POWERCONTROL_CMD`
8708variable as follows:
8709::
8710
8711 TEST_POWERCONTROL_CMD = "${COREBASE}/scripts/contrib/dialog-power-control"
8712
8713Serial Console Connection
8714~~~~~~~~~~~~~~~~~~~~~~~~~
8715
8716For test target classes requiring a serial console to interact with the
8717bootloader (e.g. BeagleBoneTarget, EdgeRouterTarget, and GrubTarget),
8718you need to specify a command to use to connect to the serial console of
8719the target machine by using the
8720:term:`TEST_SERIALCONTROL_CMD`
8721variable and optionally the
8722:term:`TEST_SERIALCONTROL_EXTRA_ARGS`
8723variable.
8724
8725These cases could be a serial terminal program if the machine is
8726connected to a local serial port, or a ``telnet`` or ``ssh`` command
8727connecting to a remote console server. Regardless of the case, the
8728command simply needs to connect to the serial console and forward that
8729connection to standard input and output as any normal terminal program
8730does. For example, to use the picocom terminal program on serial device
8731``/dev/ttyUSB0`` at 115200bps, you would set the variable as follows:
8732::
8733
8734 TEST_SERIALCONTROL_CMD = "picocom /dev/ttyUSB0 -b 115200"
8735
8736For local
8737devices where the serial port device disappears when the device reboots,
8738an additional "serdevtry" wrapper script is provided. To use this
8739wrapper, simply prefix the terminal command with
8740``${COREBASE}/scripts/contrib/serdevtry``:
8741::
8742
8743 TEST_SERIALCONTROL_CMD = "${COREBASE}/scripts/contrib/serdevtry picocom -b 115200 /dev/ttyUSB0"
8744
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008745Running Tests
8746-------------
8747
8748You can start the tests automatically or manually:
8749
8750- *Automatically running tests:* To run the tests automatically after
8751 the OpenEmbedded build system successfully creates an image, first
8752 set the
8753 :term:`TESTIMAGE_AUTO`
8754 variable to "1" in your ``local.conf`` file in the
8755 :term:`Build Directory`:
8756 ::
8757
8758 TESTIMAGE_AUTO = "1"
8759
8760 Next, build your image. If the image successfully builds, the
8761 tests run:
8762 ::
8763
8764 bitbake core-image-sato
8765
8766- *Manually running tests:* To manually run the tests, first globally
8767 inherit the
8768 :ref:`testimage <ref-classes-testimage*>` class
8769 by editing your ``local.conf`` file:
8770 ::
8771
8772 INHERIT += "testimage"
8773
8774 Next, use BitBake to run the tests:
8775 ::
8776
8777 bitbake -c testimage image
8778
8779All test files reside in ``meta/lib/oeqa/runtime`` in the
8780:term:`Source Directory`. A test name maps
8781directly to a Python module. Each test module may contain a number of
8782individual tests. Tests are usually grouped together by the area tested
8783(e.g tests for systemd reside in ``meta/lib/oeqa/runtime/systemd.py``).
8784
8785You can add tests to any layer provided you place them in the proper
8786area and you extend :term:`BBPATH` in
8787the ``local.conf`` file as normal. Be sure that tests reside in
8788``layer/lib/oeqa/runtime``.
8789
8790.. note::
8791
8792 Be sure that module names do not collide with module names used in
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008793 the default set of test modules in ``meta/lib/oeqa/runtime``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008794
8795You can change the set of tests run by appending or overriding
8796:term:`TEST_SUITES` variable in
8797``local.conf``. Each name in ``TEST_SUITES`` represents a required test
8798for the image. Test modules named within ``TEST_SUITES`` cannot be
8799skipped even if a test is not suitable for an image (e.g. running the
8800RPM tests on an image without ``rpm``). Appending "auto" to
8801``TEST_SUITES`` causes the build system to try to run all tests that are
8802suitable for the image (i.e. each test module may elect to skip itself).
8803
8804The order you list tests in ``TEST_SUITES`` is important and influences
8805test dependencies. Consequently, tests that depend on other tests should
8806be added after the test on which they depend. For example, since the
8807``ssh`` test depends on the ``ping`` test, "ssh" needs to come after
8808"ping" in the list. The test class provides no re-ordering or dependency
8809handling.
8810
8811.. note::
8812
8813 Each module can have multiple classes with multiple test methods.
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008814 And, Python ``unittest`` rules apply.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008815
8816Here are some things to keep in mind when running tests:
8817
8818- The default tests for the image are defined as:
8819 ::
8820
8821 DEFAULT_TEST_SUITES_pn-image = "ping ssh df connman syslog xorg scp vnc date rpm dnf dmesg"
8822
8823- Add your own test to the list of the by using the following:
8824 ::
8825
8826 TEST_SUITES_append = " mytest"
8827
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008828- Run a specific list of tests as follows:
8829 ::
8830
8831 TEST_SUITES = "test1 test2 test3"
8832
8833 Remember, order is important. Be sure to place a test that is
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008834 dependent on another test later in the order.
8835
8836Exporting Tests
8837---------------
8838
8839You can export tests so that they can run independently of the build
8840system. Exporting tests is required if you want to be able to hand the
8841test execution off to a scheduler. You can only export tests that are
8842defined in :term:`TEST_SUITES`.
8843
8844If your image is already built, make sure the following are set in your
8845``local.conf`` file:
8846::
8847
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008848 INHERIT += "testexport"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008849 TEST_TARGET_IP = "IP-address-for-the-test-target"
8850 TEST_SERVER_IP = "IP-address-for-the-test-server"
8851
8852You can then export the tests with the
8853following BitBake command form:
8854::
8855
8856 $ bitbake image -c testexport
8857
8858Exporting the tests places them in the
8859:term:`Build Directory` in
8860``tmp/testexport/``\ image, which is controlled by the
8861``TEST_EXPORT_DIR`` variable.
8862
8863You can now run the tests outside of the build environment:
8864::
8865
8866 $ cd tmp/testexport/image
8867 $ ./runexported.py testdata.json
8868
8869Here is a complete example that shows IP addresses and uses the
8870``core-image-sato`` image:
8871::
8872
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008873 INHERIT += "testexport"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008874 TEST_TARGET_IP = "192.168.7.2"
8875 TEST_SERVER_IP = "192.168.7.1"
8876
8877Use BitBake to export the tests:
8878::
8879
8880 $ bitbake core-image-sato -c testexport
8881
8882Run the tests outside of
8883the build environment using the following:
8884::
8885
8886 $ cd tmp/testexport/core-image-sato
8887 $ ./runexported.py testdata.json
8888
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008889Writing New Tests
8890-----------------
8891
8892As mentioned previously, all new test files need to be in the proper
8893place for the build system to find them. New tests for additional
8894functionality outside of the core should be added to the layer that adds
8895the functionality, in ``layer/lib/oeqa/runtime`` (as long as
8896:term:`BBPATH` is extended in the
8897layer's ``layer.conf`` file as normal). Just remember the following:
8898
8899- Filenames need to map directly to test (module) names.
8900
8901- Do not use module names that collide with existing core tests.
8902
8903- Minimally, an empty ``__init__.py`` file must exist in the runtime
8904 directory.
8905
8906To create a new test, start by copying an existing module (e.g.
8907``syslog.py`` or ``gcc.py`` are good ones to use). Test modules can use
8908code from ``meta/lib/oeqa/utils``, which are helper classes.
8909
8910.. note::
8911
8912 Structure shell commands such that you rely on them and they return a
8913 single code for success. Be aware that sometimes you will need to
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008914 parse the output. See the ``df.py`` and ``date.py`` modules for examples.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008915
8916You will notice that all test classes inherit ``oeRuntimeTest``, which
8917is found in ``meta/lib/oetest.py``. This base class offers some helper
8918attributes, which are described in the following sections:
8919
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008920Class Methods
8921~~~~~~~~~~~~~
8922
8923Class methods are as follows:
8924
8925- *hasPackage(pkg):* Returns "True" if ``pkg`` is in the installed
8926 package list of the image, which is based on the manifest file that
8927 is generated during the ``do_rootfs`` task.
8928
8929- *hasFeature(feature):* Returns "True" if the feature is in
8930 :term:`IMAGE_FEATURES` or
8931 :term:`DISTRO_FEATURES`.
8932
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008933Class Attributes
8934~~~~~~~~~~~~~~~~
8935
8936Class attributes are as follows:
8937
8938- *pscmd:* Equals "ps -ef" if ``procps`` is installed in the image.
8939 Otherwise, ``pscmd`` equals "ps" (busybox).
8940
8941- *tc:* The called test context, which gives access to the
8942 following attributes:
8943
8944 - *d:* The BitBake datastore, which allows you to use stuff such
8945 as ``oeRuntimeTest.tc.d.getVar("VIRTUAL-RUNTIME_init_manager")``.
8946
8947 - *testslist and testsrequired:* Used internally. The tests
8948 do not need these.
8949
8950 - *filesdir:* The absolute path to
8951 ``meta/lib/oeqa/runtime/files``, which contains helper files for
8952 tests meant for copying on the target such as small files written
8953 in C for compilation.
8954
8955 - *target:* The target controller object used to deploy and
8956 start an image on a particular target (e.g. Qemu, SimpleRemote,
8957 and SystemdbootTarget). Tests usually use the following:
8958
8959 - *ip:* The target's IP address.
8960
8961 - *server_ip:* The host's IP address, which is usually used
8962 by the DNF test suite.
8963
8964 - *run(cmd, timeout=None):* The single, most used method.
8965 This command is a wrapper for: ``ssh root@host "cmd"``. The
8966 command returns a tuple: (status, output), which are what their
8967 names imply - the return code of "cmd" and whatever output it
8968 produces. The optional timeout argument represents the number
8969 of seconds the test should wait for "cmd" to return. If the
8970 argument is "None", the test uses the default instance's
8971 timeout period, which is 300 seconds. If the argument is "0",
8972 the test runs until the command returns.
8973
8974 - *copy_to(localpath, remotepath):*
8975 ``scp localpath root@ip:remotepath``.
8976
8977 - *copy_from(remotepath, localpath):*
8978 ``scp root@host:remotepath localpath``.
8979
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008980Instance Attributes
8981~~~~~~~~~~~~~~~~~~~
8982
8983A single instance attribute exists, which is ``target``. The ``target``
8984instance attribute is identical to the class attribute of the same name,
8985which is described in the previous section. This attribute exists as
8986both an instance and class attribute so tests can use
8987``self.target.run(cmd)`` in instance methods instead of
8988``oeRuntimeTest.tc.target.run(cmd)``.
8989
8990Installing Packages in the DUT Without the Package Manager
8991----------------------------------------------------------
8992
8993When a test requires a package built by BitBake, it is possible to
8994install that package. Installing the package does not require a package
8995manager be installed in the device under test (DUT). It does, however,
8996require an SSH connection and the target must be using the
8997``sshcontrol`` class.
8998
8999.. note::
9000
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009001 This method uses ``scp`` to copy files from the host to the target, which
9002 causes permissions and special attributes to be lost.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009003
9004A JSON file is used to define the packages needed by a test. This file
9005must be in the same path as the file used to define the tests.
9006Furthermore, the filename must map directly to the test module name with
9007a ``.json`` extension.
9008
9009The JSON file must include an object with the test name as keys of an
9010object or an array. This object (or array of objects) uses the following
9011data:
9012
9013- "pkg" - A mandatory string that is the name of the package to be
9014 installed.
9015
9016- "rm" - An optional boolean, which defaults to "false", that specifies
9017 to remove the package after the test.
9018
9019- "extract" - An optional boolean, which defaults to "false", that
9020 specifies if the package must be extracted from the package format.
9021 When set to "true", the package is not automatically installed into
9022 the DUT.
9023
9024Following is an example JSON file that handles test "foo" installing
9025package "bar" and test "foobar" installing packages "foo" and "bar".
9026Once the test is complete, the packages are removed from the DUT.
9027::
9028
9029 {
9030 "foo": {
9031 "pkg": "bar"
9032 },
9033 "foobar": [
9034 {
9035 "pkg": "foo",
9036 "rm": true
9037 },
9038 {
9039 "pkg": "bar",
9040 "rm": true
9041 }
9042 ]
9043 }
9044
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009045Debugging Tools and Techniques
9046==============================
9047
9048The exact method for debugging build failures depends on the nature of
9049the problem and on the system's area from which the bug originates.
9050Standard debugging practices such as comparison against the last known
9051working version with examination of the changes and the re-application
9052of steps to identify the one causing the problem are valid for the Yocto
9053Project just as they are for any other system. Even though it is
9054impossible to detail every possible potential failure, this section
9055provides some general tips to aid in debugging given a variety of
9056situations.
9057
9058.. note::
9059
9060 A useful feature for debugging is the error reporting tool.
9061 Configuring the Yocto Project to use this tool causes the
9062 OpenEmbedded build system to produce error reporting commands as part
9063 of the console output. You can enter the commands after the build
9064 completes to log error information into a common database, that can
9065 help you figure out what might be going wrong. For information on how
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009066 to enable and use this feature, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06009067 ":ref:`dev-manual/common-tasks:using the error reporting tool`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009068 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009069
9070The following list shows the debugging topics in the remainder of this
9071section:
9072
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009073- ":ref:`dev-manual/common-tasks:viewing logs from failed tasks`" describes
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009074 how to find and view logs from tasks that failed during the build
9075 process.
9076
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009077- ":ref:`dev-manual/common-tasks:viewing variable values`" describes how to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009078 use the BitBake ``-e`` option to examine variable values after a
9079 recipe has been parsed.
9080
Andrew Geissler09209ee2020-12-13 08:44:15 -06009081- ":ref:`dev-manual/common-tasks:viewing package information with \`\`oe-pkgdata-util\`\``"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009082 describes how to use the ``oe-pkgdata-util`` utility to query
9083 :term:`PKGDATA_DIR` and
9084 display package-related information for built packages.
9085
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009086- ":ref:`dev-manual/common-tasks:viewing dependencies between recipes and tasks`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009087 describes how to use the BitBake ``-g`` option to display recipe
9088 dependency information used during the build.
9089
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009090- ":ref:`dev-manual/common-tasks:viewing task variable dependencies`" describes
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009091 how to use the ``bitbake-dumpsig`` command in conjunction with key
9092 subdirectories in the
9093 :term:`Build Directory` to determine
9094 variable dependencies.
9095
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009096- ":ref:`dev-manual/common-tasks:running specific tasks`" describes
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009097 how to use several BitBake options (e.g. ``-c``, ``-C``, and ``-f``)
9098 to run specific tasks in the build chain. It can be useful to run
9099 tasks "out-of-order" when trying isolate build issues.
9100
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009101- ":ref:`dev-manual/common-tasks:general bitbake problems`" describes how
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009102 to use BitBake's ``-D`` debug output option to reveal more about what
9103 BitBake is doing during the build.
9104
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009105- ":ref:`dev-manual/common-tasks:building with no dependencies`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009106 describes how to use the BitBake ``-b`` option to build a recipe
9107 while ignoring dependencies.
9108
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009109- ":ref:`dev-manual/common-tasks:recipe logging mechanisms`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009110 describes how to use the many recipe logging functions to produce
9111 debugging output and report errors and warnings.
9112
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009113- ":ref:`dev-manual/common-tasks:debugging parallel make races`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009114 describes how to debug situations where the build consists of several
9115 parts that are run simultaneously and when the output or result of
9116 one part is not ready for use with a different part of the build that
9117 depends on that output.
9118
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009119- ":ref:`dev-manual/common-tasks:debugging with the gnu project debugger (gdb) remotely`"
9120 describes how to use GDB to allow you to examine running programs, which can
9121 help you fix problems.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009122
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009123- ":ref:`dev-manual/common-tasks:debugging with the gnu project debugger (gdb) on the target`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009124 describes how to use GDB directly on target hardware for debugging.
9125
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009126- ":ref:`dev-manual/common-tasks:other debugging tips`" describes
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009127 miscellaneous debugging tips that can be useful.
9128
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009129Viewing Logs from Failed Tasks
9130------------------------------
9131
9132You can find the log for a task in the file
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009133``${``\ :term:`WORKDIR`\ ``}/temp/log.do_``\ `taskname`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009134For example, the log for the
9135:ref:`ref-tasks-compile` task of the
9136QEMU minimal image for the x86 machine (``qemux86``) might be in
9137``tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/temp/log.do_compile``.
9138To see the commands :term:`BitBake` ran
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009139to generate a log, look at the corresponding ``run.do_``\ `taskname` file
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009140in the same directory.
9141
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009142``log.do_``\ `taskname` and ``run.do_``\ `taskname` are actually symbolic
9143links to ``log.do_``\ `taskname`\ ``.``\ `pid` and
9144``log.run_``\ `taskname`\ ``.``\ `pid`, where `pid` is the PID the task had
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009145when it ran. The symlinks always point to the files corresponding to the
9146most recent run.
9147
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009148Viewing Variable Values
9149-----------------------
9150
9151Sometimes you need to know the value of a variable as a result of
9152BitBake's parsing step. This could be because some unexpected behavior
9153occurred in your project. Perhaps an attempt to :ref:`modify a variable
9154<bitbake:bitbake-user-manual/bitbake-user-manual-metadata:modifying existing
9155variables>` did not work out as expected.
9156
9157BitBake's ``-e`` option is used to display variable values after
9158parsing. The following command displays the variable values after the
9159configuration files (i.e. ``local.conf``, ``bblayers.conf``,
9160``bitbake.conf`` and so forth) have been parsed:
9161::
9162
9163 $ bitbake -e
9164
9165The following command displays variable values after a specific recipe has
9166been parsed. The variables include those from the configuration as well:
9167::
9168
9169 $ bitbake -e recipename
9170
9171.. note::
9172
9173 Each recipe has its own private set of variables (datastore).
9174 Internally, after parsing the configuration, a copy of the resulting
9175 datastore is made prior to parsing each recipe. This copying implies
9176 that variables set in one recipe will not be visible to other
9177 recipes.
9178
9179 Likewise, each task within a recipe gets a private datastore based on
9180 the recipe datastore, which means that variables set within one task
9181 will not be visible to other tasks.
9182
9183In the output of ``bitbake -e``, each variable is preceded by a
9184description of how the variable got its value, including temporary
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009185values that were later overridden. This description also includes
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009186variable flags (varflags) set on the variable. The output can be very
9187helpful during debugging.
9188
9189Variables that are exported to the environment are preceded by
9190``export`` in the output of ``bitbake -e``. See the following example:
9191::
9192
9193 export CC="i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/ulf/poky/build/tmp/sysroots/qemux86"
9194
9195In addition to variable values, the output of the ``bitbake -e`` and
9196``bitbake -e`` recipe commands includes the following information:
9197
9198- The output starts with a tree listing all configuration files and
9199 classes included globally, recursively listing the files they include
9200 or inherit in turn. Much of the behavior of the OpenEmbedded build
Andrew Geissler09209ee2020-12-13 08:44:15 -06009201 system (including the behavior of the :ref:`ref-manual/tasks:normal recipe build tasks`) is
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009202 implemented in the
9203 :ref:`base <ref-classes-base>` class and the
9204 classes it inherits, rather than being built into BitBake itself.
9205
9206- After the variable values, all functions appear in the output. For
9207 shell functions, variables referenced within the function body are
9208 expanded. If a function has been modified using overrides or using
9209 override-style operators like ``_append`` and ``_prepend``, then the
9210 final assembled function body appears in the output.
9211
9212Viewing Package Information with ``oe-pkgdata-util``
9213----------------------------------------------------
9214
9215You can use the ``oe-pkgdata-util`` command-line utility to query
9216:term:`PKGDATA_DIR` and display
9217various package-related information. When you use the utility, you must
9218use it to view information on packages that have already been built.
9219
9220Following are a few of the available ``oe-pkgdata-util`` subcommands.
9221
9222.. note::
9223
9224 You can use the standard \* and ? globbing wildcards as part of
9225 package names and paths.
9226
9227- ``oe-pkgdata-util list-pkgs [pattern]``: Lists all packages
9228 that have been built, optionally limiting the match to packages that
9229 match pattern.
9230
9231- ``oe-pkgdata-util list-pkg-files package ...``: Lists the
9232 files and directories contained in the given packages.
9233
9234 .. note::
9235
9236 A different way to view the contents of a package is to look at
9237 the
9238 ``${``\ :term:`WORKDIR`\ ``}/packages-split``
9239 directory of the recipe that generates the package. This directory
9240 is created by the
9241 :ref:`ref-tasks-package` task
9242 and has one subdirectory for each package the recipe generates,
9243 which contains the files stored in that package.
9244
9245 If you want to inspect the ``${WORKDIR}/packages-split``
9246 directory, make sure that
9247 :ref:`rm_work <ref-classes-rm-work>` is not
9248 enabled when you build the recipe.
9249
9250- ``oe-pkgdata-util find-path path ...``: Lists the names of
9251 the packages that contain the given paths. For example, the following
9252 tells us that ``/usr/share/man/man1/make.1`` is contained in the
9253 ``make-doc`` package:
9254 ::
9255
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009256 $ oe-pkgdata-util find-path /usr/share/man/man1/make.1
9257 make-doc: /usr/share/man/man1/make.1
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009258
9259- ``oe-pkgdata-util lookup-recipe package ...``: Lists the name
9260 of the recipes that produce the given packages.
9261
9262For more information on the ``oe-pkgdata-util`` command, use the help
9263facility:
9264::
9265
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009266 $ oe-pkgdata-util --help
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009267 $ oe-pkgdata-util subcommand --help
9268
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009269Viewing Dependencies Between Recipes and Tasks
9270----------------------------------------------
9271
9272Sometimes it can be hard to see why BitBake wants to build other recipes
9273before the one you have specified. Dependency information can help you
9274understand why a recipe is built.
9275
9276To generate dependency information for a recipe, run the following
9277command:
9278::
9279
9280 $ bitbake -g recipename
9281
9282This command writes the following files in the current directory:
9283
9284- ``pn-buildlist``: A list of recipes/targets involved in building
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009285 `recipename`. "Involved" here means that at least one task from the
9286 recipe needs to run when building `recipename` from scratch. Targets
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009287 that are in
9288 :term:`ASSUME_PROVIDED`
9289 are not listed.
9290
9291- ``task-depends.dot``: A graph showing dependencies between tasks.
9292
9293The graphs are in
9294`DOT <https://en.wikipedia.org/wiki/DOT_%28graph_description_language%29>`__
9295format and can be converted to images (e.g. using the ``dot`` tool from
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009296`Graphviz <https://www.graphviz.org/>`__).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009297
9298.. note::
9299
9300 - DOT files use a plain text format. The graphs generated using the
9301 ``bitbake -g`` command are often so large as to be difficult to
9302 read without special pruning (e.g. with Bitbake's ``-I`` option)
9303 and processing. Despite the form and size of the graphs, the
9304 corresponding ``.dot`` files can still be possible to read and
9305 provide useful information.
9306
9307 As an example, the ``task-depends.dot`` file contains lines such
9308 as the following:
9309 ::
9310
9311 "libxslt.do_configure" -> "libxml2.do_populate_sysroot"
9312
9313 The above example line reveals that the
9314 :ref:`ref-tasks-configure`
9315 task in ``libxslt`` depends on the
9316 :ref:`ref-tasks-populate_sysroot`
9317 task in ``libxml2``, which is a normal
9318 :term:`DEPENDS` dependency
9319 between the two recipes.
9320
9321 - For an example of how ``.dot`` files can be processed, see the
9322 ``scripts/contrib/graph-tool`` Python script, which finds and
9323 displays paths between graph nodes.
9324
9325You can use a different method to view dependency information by using
9326the following command:
9327::
9328
9329 $ bitbake -g -u taskexp recipename
9330
9331This command
9332displays a GUI window from which you can view build-time and runtime
9333dependencies for the recipes involved in building recipename.
9334
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009335Viewing Task Variable Dependencies
9336----------------------------------
9337
9338As mentioned in the
9339":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-execution:checksums (signatures)`" section of the BitBake
9340User Manual, BitBake tries to automatically determine what variables a
9341task depends on so that it can rerun the task if any values of the
9342variables change. This determination is usually reliable. However, if
9343you do things like construct variable names at runtime, then you might
9344have to manually declare dependencies on those variables using
9345``vardeps`` as described in the
9346":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags`" section of the BitBake
9347User Manual.
9348
9349If you are unsure whether a variable dependency is being picked up
9350automatically for a given task, you can list the variable dependencies
9351BitBake has determined by doing the following:
9352
93531. Build the recipe containing the task:
9354::
9355
9356 $ bitbake recipename
9357
93582. Inside the :term:`STAMPS_DIR`
9359 directory, find the signature data (``sigdata``) file that
9360 corresponds to the task. The ``sigdata`` files contain a pickled
9361 Python database of all the metadata that went into creating the input
9362 checksum for the task. As an example, for the
9363 :ref:`ref-tasks-fetch` task of the
9364 ``db`` recipe, the ``sigdata`` file might be found in the following
9365 location:
9366 ::
9367
9368 ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
9369
9370 For tasks that are accelerated through the shared state
Andrew Geissler09209ee2020-12-13 08:44:15 -06009371 (:ref:`sstate <overview-manual/concepts:shared state cache>`) cache, an
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009372 additional ``siginfo`` file is written into
9373 :term:`SSTATE_DIR` along with
9374 the cached task output. The ``siginfo`` files contain exactly the
9375 same information as ``sigdata`` files.
9376
93773. Run ``bitbake-dumpsig`` on the ``sigdata`` or ``siginfo`` file. Here
9378 is an example:
9379 ::
9380
9381 $ bitbake-dumpsig ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
9382
9383 In the output of the above command, you will find a line like the
9384 following, which lists all the (inferred) variable dependencies for
9385 the task. This list also includes indirect dependencies from
9386 variables depending on other variables, recursively.
9387 ::
9388
9389 Task dependencies: ['PV', 'SRCREV', 'SRC_URI', 'SRC_URI[md5sum]', 'SRC_URI[sha256sum]', 'base_do_fetch']
9390
9391 .. note::
9392
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009393 Functions (e.g. ``base_do_fetch``) also count as variable dependencies.
9394 These functions in turn depend on the variables they reference.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009395
9396 The output of ``bitbake-dumpsig`` also includes the value each
9397 variable had, a list of dependencies for each variable, and
9398 :term:`bitbake:BB_HASHBASE_WHITELIST`
9399 information.
9400
9401There is also a ``bitbake-diffsigs`` command for comparing two
9402``siginfo`` or ``sigdata`` files. This command can be helpful when
9403trying to figure out what changed between two versions of a task. If you
9404call ``bitbake-diffsigs`` with just one file, the command behaves like
9405``bitbake-dumpsig``.
9406
9407You can also use BitBake to dump out the signature construction
9408information without executing tasks by using either of the following
9409BitBake command-line options:
9410::
9411
9412 ‐‐dump-signatures=SIGNATURE_HANDLER
9413 -S SIGNATURE_HANDLER
9414
9415
9416.. note::
9417
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009418 Two common values for `SIGNATURE_HANDLER` are "none" and "printdiff", which
9419 dump only the signature or compare the dumped signature with the cached one,
9420 respectively.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009421
9422Using BitBake with either of these options causes BitBake to dump out
9423``sigdata`` files in the ``stamps`` directory for every task it would
9424have executed instead of building the specified target package.
9425
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009426Viewing Metadata Used to Create the Input Signature of a Shared State Task
9427--------------------------------------------------------------------------
9428
9429Seeing what metadata went into creating the input signature of a shared
9430state (sstate) task can be a useful debugging aid. This information is
9431available in signature information (``siginfo``) files in
9432:term:`SSTATE_DIR`. For
9433information on how to view and interpret information in ``siginfo``
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009434files, see the
9435":ref:`dev-manual/common-tasks:viewing task variable dependencies`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009436
9437For conceptual information on shared state, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06009438":ref:`overview-manual/concepts:shared state`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009439section in the Yocto Project Overview and Concepts Manual.
9440
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009441Invalidating Shared State to Force a Task to Run
9442------------------------------------------------
9443
9444The OpenEmbedded build system uses
Andrew Geissler09209ee2020-12-13 08:44:15 -06009445:ref:`checksums <overview-manual/concepts:checksums (signatures)>` and
9446:ref:`overview-manual/concepts:shared state` cache to avoid unnecessarily
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009447rebuilding tasks. Collectively, this scheme is known as "shared state
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009448code".
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009449
9450As with all schemes, this one has some drawbacks. It is possible that
9451you could make implicit changes to your code that the checksum
9452calculations do not take into account. These implicit changes affect a
9453task's output but do not trigger the shared state code into rebuilding a
9454recipe. Consider an example during which a tool changes its output.
9455Assume that the output of ``rpmdeps`` changes. The result of the change
9456should be that all the ``package`` and ``package_write_rpm`` shared
9457state cache items become invalid. However, because the change to the
9458output is external to the code and therefore implicit, the associated
9459shared state cache items do not become invalidated. In this case, the
9460build process uses the cached items rather than running the task again.
9461Obviously, these types of implicit changes can cause problems.
9462
9463To avoid these problems during the build, you need to understand the
9464effects of any changes you make. Realize that changes you make directly
9465to a function are automatically factored into the checksum calculation.
9466Thus, these explicit changes invalidate the associated area of shared
9467state cache. However, you need to be aware of any implicit changes that
9468are not obvious changes to the code and could affect the output of a
9469given task.
9470
9471When you identify an implicit change, you can easily take steps to
9472invalidate the cache and force the tasks to run. The steps you can take
9473are as simple as changing a function's comments in the source code. For
9474example, to invalidate package shared state files, change the comment
9475statements of
9476:ref:`ref-tasks-package` or the
9477comments of one of the functions it calls. Even though the change is
9478purely cosmetic, it causes the checksum to be recalculated and forces
9479the build system to run the task again.
9480
9481.. note::
9482
9483 For an example of a commit that makes a cosmetic change to invalidate
9484 shared state, see this
Andrew Geissler09209ee2020-12-13 08:44:15 -06009485 :yocto_git:`commit </poky/commit/meta/classes/package.bbclass?id=737f8bbb4f27b4837047cb9b4fbfe01dfde36d54>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009486
9487Running Specific Tasks
9488----------------------
9489
9490Any given recipe consists of a set of tasks. The standard BitBake
9491behavior in most cases is: ``do_fetch``, ``do_unpack``, ``do_patch``,
9492``do_configure``, ``do_compile``, ``do_install``, ``do_package``,
9493``do_package_write_*``, and ``do_build``. The default task is
9494``do_build`` and any tasks on which it depends build first. Some tasks,
9495such as ``do_devshell``, are not part of the default build chain. If you
9496wish to run a task that is not part of the default build chain, you can
9497use the ``-c`` option in BitBake. Here is an example:
9498::
9499
9500 $ bitbake matchbox-desktop -c devshell
9501
9502The ``-c`` option respects task dependencies, which means that all other
9503tasks (including tasks from other recipes) that the specified task
9504depends on will be run before the task. Even when you manually specify a
9505task to run with ``-c``, BitBake will only run the task if it considers
9506it "out of date". See the
Andrew Geissler09209ee2020-12-13 08:44:15 -06009507":ref:`overview-manual/concepts:stamp files and the rerunning of tasks`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009508section in the Yocto Project Overview and Concepts Manual for how
9509BitBake determines whether a task is "out of date".
9510
9511If you want to force an up-to-date task to be rerun (e.g. because you
9512made manual modifications to the recipe's
9513:term:`WORKDIR` that you want to try
9514out), then you can use the ``-f`` option.
9515
9516.. note::
9517
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009518 The reason ``-f`` is never required when running the
9519 :ref:`ref-tasks-devshell` task is because the
9520 [\ :ref:`nostamp <bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ]
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009521 variable flag is already set for the task.
9522
9523The following example shows one way you can use the ``-f`` option:
9524::
9525
9526 $ bitbake matchbox-desktop
9527 .
9528 .
9529 make some changes to the source code in the work directory
9530 .
9531 .
9532 $ bitbake matchbox-desktop -c compile -f
9533 $ bitbake matchbox-desktop
9534
9535This sequence first builds and then recompiles ``matchbox-desktop``. The
9536last command reruns all tasks (basically the packaging tasks) after the
9537compile. BitBake recognizes that the ``do_compile`` task was rerun and
9538therefore understands that the other tasks also need to be run again.
9539
9540Another, shorter way to rerun a task and all
Andrew Geissler09209ee2020-12-13 08:44:15 -06009541:ref:`ref-manual/tasks:normal recipe build tasks`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009542that depend on it is to use the ``-C`` option.
9543
9544.. note::
9545
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009546 This option is upper-cased and is separate from the ``-c``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009547 option, which is lower-cased.
9548
9549Using this option invalidates the given task and then runs the
9550:ref:`ref-tasks-build` task, which is
9551the default task if no task is given, and the tasks on which it depends.
9552You could replace the final two commands in the previous example with
9553the following single command:
9554::
9555
9556 $ bitbake matchbox-desktop -C compile
9557
9558Internally, the ``-f`` and ``-C`` options work by tainting (modifying)
9559the input checksum of the specified task. This tainting indirectly
9560causes the task and its dependent tasks to be rerun through the normal
9561task dependency mechanisms.
9562
9563.. note::
9564
9565 BitBake explicitly keeps track of which tasks have been tainted in
9566 this fashion, and will print warnings such as the following for
9567 builds involving such tasks:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009568
9569 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009570
9571 WARNING: /home/ulf/poky/meta/recipes-sato/matchbox-desktop/matchbox-desktop_2.1.bb.do_compile is tainted from a forced run
9572
9573
9574 The purpose of the warning is to let you know that the work directory
9575 and build output might not be in the clean state they would be in for
9576 a "normal" build, depending on what actions you took. To get rid of
9577 such warnings, you can remove the work directory and rebuild the
9578 recipe, as follows:
9579 ::
9580
9581 $ bitbake matchbox-desktop -c clean
9582 $ bitbake matchbox-desktop
9583
9584
9585You can view a list of tasks in a given package by running the
9586``do_listtasks`` task as follows:
9587::
9588
9589 $ bitbake matchbox-desktop -c listtasks
9590
9591The results appear as output to the console and are also in
9592the file ``${WORKDIR}/temp/log.do_listtasks``.
9593
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009594General BitBake Problems
9595------------------------
9596
9597You can see debug output from BitBake by using the ``-D`` option. The
9598debug output gives more information about what BitBake is doing and the
9599reason behind it. Each ``-D`` option you use increases the logging
9600level. The most common usage is ``-DDD``.
9601
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009602The output from ``bitbake -DDD -v targetname`` can reveal why BitBake
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009603chose a certain version of a package or why BitBake picked a certain
9604provider. This command could also help you in a situation where you
9605think BitBake did something unexpected.
9606
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009607Building with No Dependencies
9608-----------------------------
9609
9610To build a specific recipe (``.bb`` file), you can use the following
9611command form:
9612::
9613
9614 $ bitbake -b somepath/somerecipe.bb
9615
9616This command form does
9617not check for dependencies. Consequently, you should use it only when
9618you know existing dependencies have been met.
9619
9620.. note::
9621
9622 You can also specify fragments of the filename. In this case, BitBake
9623 checks for a unique match.
9624
9625Recipe Logging Mechanisms
9626-------------------------
9627
9628The Yocto Project provides several logging functions for producing
9629debugging output and reporting errors and warnings. For Python
9630functions, the following logging functions exist. All of these functions
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009631log to ``${T}/log.do_``\ `task`, and can also log to standard output
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009632(stdout) with the right settings:
9633
9634- ``bb.plain(msg)``: Writes msg as is to the log while also
9635 logging to stdout.
9636
9637- ``bb.note(msg)``: Writes "NOTE: msg" to the log. Also logs to
9638 stdout if BitBake is called with "-v".
9639
9640- ``bb.debug(level, msg)``: Writes "DEBUG: msg" to the
9641 log. Also logs to stdout if the log level is greater than or equal to
9642 level. See the ":ref:`-D <bitbake:bitbake-user-manual/bitbake-user-manual-intro:usage and syntax>`" option
9643 in the BitBake User Manual for more information.
9644
9645- ``bb.warn(msg)``: Writes "WARNING: msg" to the log while also
9646 logging to stdout.
9647
9648- ``bb.error(msg)``: Writes "ERROR: msg" to the log while also
9649 logging to standard out (stdout).
9650
9651 .. note::
9652
9653 Calling this function does not cause the task to fail.
9654
9655- ``bb.fatal(``\ msg\ ``)``: This logging function is similar to
9656 ``bb.error(``\ msg\ ``)`` but also causes the calling task to fail.
9657
9658 .. note::
9659
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009660 ``bb.fatal()`` raises an exception, which means you do not need to put a
9661 "return" statement after the function.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009662
9663The same logging functions are also available in shell functions, under
9664the names ``bbplain``, ``bbnote``, ``bbdebug``, ``bbwarn``, ``bberror``,
9665and ``bbfatal``. The
9666:ref:`logging <ref-classes-logging>` class
9667implements these functions. See that class in the ``meta/classes``
9668folder of the :term:`Source Directory` for information.
9669
9670Logging With Python
9671~~~~~~~~~~~~~~~~~~~
9672
9673When creating recipes using Python and inserting code that handles build
9674logs, keep in mind the goal is to have informative logs while keeping
9675the console as "silent" as possible. Also, if you want status messages
9676in the log, use the "debug" loglevel.
9677
9678Following is an example written in Python. The code handles logging for
9679a function that determines the number of tasks needed to be run. See the
9680":ref:`ref-tasks-listtasks`"
9681section for additional information:
9682::
9683
9684 python do_listtasks() {
9685 bb.debug(2, "Starting to figure out the task list")
9686 if noteworthy_condition:
9687 bb.note("There are 47 tasks to run")
9688 bb.debug(2, "Got to point xyz")
9689 if warning_trigger:
9690 bb.warn("Detected warning_trigger, this might be a problem later.")
9691 if recoverable_error:
9692 bb.error("Hit recoverable_error, you really need to fix this!")
9693 if fatal_error:
9694 bb.fatal("fatal_error detected, unable to print the task list")
9695 bb.plain("The tasks present are abc")
9696 bb.debug(2, "Finished figuring out the tasklist")
9697 }
9698
9699Logging With Bash
9700~~~~~~~~~~~~~~~~~
9701
9702When creating recipes using Bash and inserting code that handles build
9703logs, you have the same goals - informative with minimal console output.
9704The syntax you use for recipes written in Bash is similar to that of
9705recipes written in Python described in the previous section.
9706
9707Following is an example written in Bash. The code logs the progress of
9708the ``do_my_function`` function.
9709::
9710
9711 do_my_function() {
9712 bbdebug 2 "Running do_my_function"
9713 if [ exceptional_condition ]; then
9714 bbnote "Hit exceptional_condition"
9715 fi
9716 bbdebug 2 "Got to point xyz"
9717 if [ warning_trigger ]; then
9718 bbwarn "Detected warning_trigger, this might cause a problem later."
9719 fi
9720 if [ recoverable_error ]; then
9721 bberror "Hit recoverable_error, correcting"
9722 fi
9723 if [ fatal_error ]; then
9724 bbfatal "fatal_error detected"
9725 fi
9726 bbdebug 2 "Completed do_my_function"
9727 }
9728
9729
9730Debugging Parallel Make Races
9731-----------------------------
9732
9733A parallel ``make`` race occurs when the build consists of several parts
9734that are run simultaneously and a situation occurs when the output or
9735result of one part is not ready for use with a different part of the
9736build that depends on that output. Parallel make races are annoying and
9737can sometimes be difficult to reproduce and fix. However, some simple
9738tips and tricks exist that can help you debug and fix them. This section
9739presents a real-world example of an error encountered on the Yocto
9740Project autobuilder and the process used to fix it.
9741
9742.. note::
9743
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009744 If you cannot properly fix a ``make`` race condition, you can work around it
9745 by clearing either the :term:`PARALLEL_MAKE` or :term:`PARALLEL_MAKEINST`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009746 variables.
9747
9748The Failure
9749~~~~~~~~~~~
9750
9751For this example, assume that you are building an image that depends on
9752the "neard" package. And, during the build, BitBake runs into problems
9753and creates the following output.
9754
9755.. note::
9756
9757 This example log file has longer lines artificially broken to make
9758 the listing easier to read.
9759
9760If you examine the output or the log file, you see the failure during
9761``make``:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009762
9763.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009764
9765 | DEBUG: SITE files ['endian-little', 'bit-32', 'ix86-common', 'common-linux', 'common-glibc', 'i586-linux', 'common']
9766 | DEBUG: Executing shell function do_compile
9767 | NOTE: make -j 16
9768 | make --no-print-directory all-am
9769 | /bin/mkdir -p include/near
9770 | /bin/mkdir -p include/near
9771 | /bin/mkdir -p include/near
9772 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9773 0.14-r0/neard-0.14/include/types.h include/near/types.h
9774 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9775 0.14-r0/neard-0.14/include/log.h include/near/log.h
9776 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9777 0.14-r0/neard-0.14/include/plugin.h include/near/plugin.h
9778 | /bin/mkdir -p include/near
9779 | /bin/mkdir -p include/near
9780 | /bin/mkdir -p include/near
9781 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9782 0.14-r0/neard-0.14/include/tag.h include/near/tag.h
9783 | /bin/mkdir -p include/near
9784 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9785 0.14-r0/neard-0.14/include/adapter.h include/near/adapter.h
9786 | /bin/mkdir -p include/near
9787 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9788 0.14-r0/neard-0.14/include/ndef.h include/near/ndef.h
9789 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9790 0.14-r0/neard-0.14/include/tlv.h include/near/tlv.h
9791 | /bin/mkdir -p include/near
9792 | /bin/mkdir -p include/near
9793 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9794 0.14-r0/neard-0.14/include/setting.h include/near/setting.h
9795 | /bin/mkdir -p include/near
9796 | /bin/mkdir -p include/near
9797 | /bin/mkdir -p include/near
9798 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9799 0.14-r0/neard-0.14/include/device.h include/near/device.h
9800 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9801 0.14-r0/neard-0.14/include/nfc_copy.h include/near/nfc_copy.h
9802 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9803 0.14-r0/neard-0.14/include/snep.h include/near/snep.h
9804 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9805 0.14-r0/neard-0.14/include/version.h include/near/version.h
9806 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9807 0.14-r0/neard-0.14/include/dbus.h include/near/dbus.h
9808 | ./src/genbuiltin nfctype1 nfctype2 nfctype3 nfctype4 p2p > src/builtin.h
9809 | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/
9810 build/build/tmp/sysroots/qemux86 -DHAVE_CONFIG_H -I. -I./include -I./src -I./gdbus -I/home/pokybuild/
9811 yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/glib-2.0
9812 -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/
9813 lib/glib-2.0/include -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/
9814 tmp/sysroots/qemux86/usr/include/dbus-1.0 -I/home/pokybuild/yocto-autobuilder/yocto-slave/
9815 nightly-x86/build/build/tmp/sysroots/qemux86/usr/lib/dbus-1.0/include -I/home/pokybuild/yocto-autobuilder/
9816 yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/libnl3
9817 -DNEAR_PLUGIN_BUILTIN -DPLUGINDIR=\""/usr/lib/near/plugins"\"
9818 -DCONFIGDIR=\""/etc/neard\"" -O2 -pipe -g -feliminate-unused-debug-types -c
9819 -o tools/snep-send.o tools/snep-send.c
9820 | In file included from tools/snep-send.c:16:0:
9821 | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
9822 | #include <near/dbus.h>
9823 | ^
9824 | compilation terminated.
9825 | make[1]: *** [tools/snep-send.o] Error 1
9826 | make[1]: *** Waiting for unfinished jobs....
9827 | make: *** [all] Error 2
9828 | ERROR: oe_runmake failed
9829
9830Reproducing the Error
9831~~~~~~~~~~~~~~~~~~~~~
9832
9833Because race conditions are intermittent, they do not manifest
9834themselves every time you do the build. In fact, most times the build
9835will complete without problems even though the potential race condition
9836exists. Thus, once the error surfaces, you need a way to reproduce it.
9837
9838In this example, compiling the "neard" package is causing the problem.
9839So the first thing to do is build "neard" locally. Before you start the
9840build, set the
9841:term:`PARALLEL_MAKE` variable
9842in your ``local.conf`` file to a high number (e.g. "-j 20"). Using a
9843high value for ``PARALLEL_MAKE`` increases the chances of the race
9844condition showing up:
9845::
9846
9847 $ bitbake neard
9848
9849Once the local build for "neard" completes, start a ``devshell`` build:
9850::
9851
9852 $ bitbake neard -c devshell
9853
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009854For information on how to use a ``devshell``, see the
9855":ref:`dev-manual/common-tasks:using a development shell`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009856
9857In the ``devshell``, do the following:
9858::
9859
9860 $ make clean
9861 $ make tools/snep-send.o
9862
9863The ``devshell`` commands cause the failure to clearly
9864be visible. In this case, a missing dependency exists for the "neard"
9865Makefile target. Here is some abbreviated, sample output with the
9866missing dependency clearly visible at the end:
9867::
9868
9869 i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/scott-lenovo/......
9870 .
9871 .
9872 .
9873 tools/snep-send.c
9874 In file included from tools/snep-send.c:16:0:
9875 tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
9876 #include <near/dbus.h>
9877 ^
9878 compilation terminated.
9879 make: *** [tools/snep-send.o] Error 1
9880 $
9881
9882
9883Creating a Patch for the Fix
9884~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9885
9886Because there is a missing dependency for the Makefile target, you need
9887to patch the ``Makefile.am`` file, which is generated from
9888``Makefile.in``. You can use Quilt to create the patch:
9889::
9890
9891 $ quilt new parallelmake.patch
9892 Patch patches/parallelmake.patch is now on top
9893 $ quilt add Makefile.am
9894 File Makefile.am added to patch patches/parallelmake.patch
9895
9896For more information on using Quilt, see the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009897":ref:`dev-manual/common-tasks:using quilt in your workflow`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009898
9899At this point you need to make the edits to ``Makefile.am`` to add the
9900missing dependency. For our example, you have to add the following line
9901to the file:
9902::
9903
9904 tools/snep-send.$(OBJEXT): include/near/dbus.h
9905
9906Once you have edited the file, use the ``refresh`` command to create the
9907patch:
9908::
9909
9910 $ quilt refresh
9911 Refreshed patch patches/parallelmake.patch
9912
9913Once
9914the patch file exists, you need to add it back to the originating recipe
9915folder. Here is an example assuming a top-level
9916:term:`Source Directory` named ``poky``:
9917::
9918
9919 $ cp patches/parallelmake.patch poky/meta/recipes-connectivity/neard/neard
9920
9921The final thing you need to do to implement the fix in the build is to
9922update the "neard" recipe (i.e. ``neard-0.14.bb``) so that the
9923:term:`SRC_URI` statement includes
9924the patch file. The recipe file is in the folder above the patch. Here
9925is what the edited ``SRC_URI`` statement would look like:
9926::
9927
9928 SRC_URI = "${KERNELORG_MIRROR}/linux/network/nfc/${BPN}-${PV}.tar.xz \
9929 file://neard.in \
9930 file://neard.service.in \
9931 file://parallelmake.patch \
9932 "
9933
9934With the patch complete and moved to the correct folder and the
9935``SRC_URI`` statement updated, you can exit the ``devshell``:
9936::
9937
9938 $ exit
9939
9940Testing the Build
9941~~~~~~~~~~~~~~~~~
9942
9943With everything in place, you can get back to trying the build again
9944locally:
9945::
9946
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009947 $ bitbake neard
9948
9949This build should succeed.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009950
9951Now you can open up a ``devshell`` again and repeat the clean and make
9952operations as follows:
9953::
9954
9955 $ bitbake neard -c devshell
9956 $ make clean
9957 $ make tools/snep-send.o
9958
9959The build should work without issue.
9960
9961As with all solved problems, if they originated upstream, you need to
9962submit the fix for the recipe in OE-Core and upstream so that the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009963problem is taken care of at its source. See the
9964":ref:`dev-manual/common-tasks:submitting a change to the yocto project`"
9965section for more information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009966
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009967Debugging With the GNU Project Debugger (GDB) Remotely
9968------------------------------------------------------
9969
9970GDB allows you to examine running programs, which in turn helps you to
9971understand and fix problems. It also allows you to perform post-mortem
9972style analysis of program crashes. GDB is available as a package within
9973the Yocto Project and is installed in SDK images by default. See the
Andrew Geissler09209ee2020-12-13 08:44:15 -06009974":ref:`ref-manual/images:Images`" chapter in the Yocto
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009975Project Reference Manual for a description of these images. You can find
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009976information on GDB at https://sourceware.org/gdb/.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009977
9978.. note::
9979
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009980 For best results, install debug (``-dbg``) packages for the applications you
9981 are going to debug. Doing so makes extra debug symbols available that give
9982 you more meaningful output.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009983
9984Sometimes, due to memory or disk space constraints, it is not possible
9985to use GDB directly on the remote target to debug applications. These
9986constraints arise because GDB needs to load the debugging information
9987and the binaries of the process being debugged. Additionally, GDB needs
9988to perform many computations to locate information such as function
9989names, variable names and values, stack traces and so forth - even
9990before starting the debugging process. These extra computations place
9991more load on the target system and can alter the characteristics of the
9992program being debugged.
9993
Andrew Geissler95ac1b82021-03-31 14:34:31 -05009994To help get past the previously mentioned constraints, there are two
9995methods you can use: running a debuginfod server and using gdbserver.
9996
9997Using the debuginfod server method
9998~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9999
10000"debuginfod" from "elfutils" is a way to distribute "debuginfo" files.
10001Running a "debuginfod" server makes debug symbols readily available,
10002which means you don't need to download debugging information
10003and the binaries of the process being debugged. You can just fetch
10004debug symbols from the server.
10005
10006To run a debuginfod server, you need to do the following:
10007
10008- Ensure that this variable is set in your ``local.conf`` file:
10009 ::
10010
10011 PACKAGECONFIG_pn-elfutils-native = "debuginfod libdebuginfod"
10012
10013 This :term:`PACKAGECONFIG` option enables debuginfod and libdebuginfod for
10014 "elfutils-native".
10015
10016- Run the following commands to set up the "debuginfod" server:
10017 ::
10018
10019 $ oe-debuginfod
10020
10021
10022To use debuginfod on the target, you need the following:
10023
10024- Ensure that this variable is set in your ``local.conf`` file:
10025 ::
10026
10027 DEBUGINFOD_URLS = "http://localhost:8002/"
10028
10029 This :term:`DEBUGINFOD_URLS` option does the client configuration.
10030
10031 ::
10032
10033 PACKAGECONFIG_pn-gdb = "debuginfod"
10034
10035 This :term:`PACKAGECONFIG` option enables "debuginfod" for "gdb".
10036
10037Using the gdbserver method
10038~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10039
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010040gdbserver, which runs on the remote target and does not load any
10041debugging information from the debugged process. Instead, a GDB instance
10042processes the debugging information that is run on a remote computer -
10043the host GDB. The host GDB then sends control commands to gdbserver to
10044make it stop or start the debugged program, as well as read or write
10045memory regions of that debugged program. All the debugging information
10046loaded and processed as well as all the heavy debugging is done by the
10047host GDB. Offloading these processes gives the gdbserver running on the
10048target a chance to remain small and fast.
10049
10050Because the host GDB is responsible for loading the debugging
10051information and for doing the necessary processing to make actual
10052debugging happen, you have to make sure the host can access the
10053unstripped binaries complete with their debugging information and also
10054be sure the target is compiled with no optimizations. The host GDB must
10055also have local access to all the libraries used by the debugged
10056program. Because gdbserver does not need any local debugging
10057information, the binaries on the remote target can remain stripped.
10058However, the binaries must also be compiled without optimization so they
10059match the host's binaries.
10060
10061To remain consistent with GDB documentation and terminology, the binary
10062being debugged on the remote target machine is referred to as the
10063"inferior" binary. For documentation on GDB see the `GDB
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010064site <https://sourceware.org/gdb/documentation/>`__.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010065
10066The following steps show you how to debug using the GNU project
10067debugger.
10068
100691. *Configure your build system to construct the companion debug
10070 filesystem:*
10071
10072 In your ``local.conf`` file, set the following:
10073 ::
10074
10075 IMAGE_GEN_DEBUGFS = "1"
10076 IMAGE_FSTYPES_DEBUGFS = "tar.bz2"
10077
10078 These options cause the
10079 OpenEmbedded build system to generate a special companion filesystem
10080 fragment, which contains the matching source and debug symbols to
10081 your deployable filesystem. The build system does this by looking at
10082 what is in the deployed filesystem, and pulling the corresponding
10083 ``-dbg`` packages.
10084
10085 The companion debug filesystem is not a complete filesystem, but only
10086 contains the debug fragments. This filesystem must be combined with
10087 the full filesystem for debugging. Subsequent steps in this procedure
10088 show how to combine the partial filesystem with the full filesystem.
10089
100902. *Configure the system to include gdbserver in the target filesystem:*
10091
10092 Make the following addition in either your ``local.conf`` file or in
10093 an image recipe:
10094 ::
10095
10096 IMAGE_INSTALL_append = " gdbserver"
10097
10098 The change makes
10099 sure the ``gdbserver`` package is included.
10100
101013. *Build the environment:*
10102
10103 Use the following command to construct the image and the companion
10104 Debug Filesystem:
10105 ::
10106
10107 $ bitbake image
10108
10109 Build the cross GDB component and
10110 make it available for debugging. Build the SDK that matches the
10111 image. Building the SDK is best for a production build that can be
10112 used later for debugging, especially during long term maintenance:
10113 ::
10114
10115 $ bitbake -c populate_sdk image
10116
10117 Alternatively, you can build the minimal toolchain components that
10118 match the target. Doing so creates a smaller than typical SDK and
10119 only contains a minimal set of components with which to build simple
10120 test applications, as well as run the debugger:
10121 ::
10122
10123 $ bitbake meta-toolchain
10124
10125 A final method is to build Gdb itself within the build system:
10126 ::
10127
10128 $ bitbake gdb-cross-<architecture>
10129
10130 Doing so produces a temporary copy of
10131 ``cross-gdb`` you can use for debugging during development. While
10132 this is the quickest approach, the two previous methods in this step
10133 are better when considering long-term maintenance strategies.
10134
10135 .. note::
10136
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010137 If you run ``bitbake gdb-cross``, the OpenEmbedded build system suggests
10138 the actual image (e.g. ``gdb-cross-i586``). The suggestion is usually the
10139 actual name you want to use.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010140
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500101414. *Set up the* ``debugfs``\ *:*
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010142
10143 Run the following commands to set up the ``debugfs``:
10144 ::
10145
10146 $ mkdir debugfs
10147 $ cd debugfs
10148 $ tar xvfj build-dir/tmp-glibc/deploy/images/machine/image.rootfs.tar.bz2
10149 $ tar xvfj build-dir/tmp-glibc/deploy/images/machine/image-dbg.rootfs.tar.bz2
10150
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500101515. *Set up GDB:*
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010152
10153 Install the SDK (if you built one) and then source the correct
10154 environment file. Sourcing the environment file puts the SDK in your
10155 ``PATH`` environment variable.
10156
10157 If you are using the build system, Gdb is located in
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010158 `build-dir`\ ``/tmp/sysroots/``\ `host`\ ``/usr/bin/``\ `architecture`\ ``/``\ `architecture`\ ``-gdb``
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010159
101606. *Boot the target:*
10161
10162 For information on how to run QEMU, see the `QEMU
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010163 Documentation <https://wiki.qemu.org/Documentation/GettingStartedDevelopers>`__.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010164
10165 .. note::
10166
10167 Be sure to verify that your host can access the target via TCP.
10168
101697. *Debug a program:*
10170
10171 Debugging a program involves running gdbserver on the target and then
10172 running Gdb on the host. The example in this step debugs ``gzip``:
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010173
10174 .. code-block:: shell
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010175
10176 root@qemux86:~# gdbserver localhost:1234 /bin/gzip —help
10177
10178 For
10179 additional gdbserver options, see the `GDB Server
10180 Documentation <https://www.gnu.org/software/gdb/documentation/>`__.
10181
10182 After running gdbserver on the target, you need to run Gdb on the
10183 host and configure it and connect to the target. Use these commands:
10184 ::
10185
10186 $ cd directory-holding-the-debugfs-directory
10187 $ arch-gdb
10188 (gdb) set sysroot debugfs
10189 (gdb) set substitute-path /usr/src/debug debugfs/usr/src/debug
10190 (gdb) target remote IP-of-target:1234
10191
10192 At this
10193 point, everything should automatically load (i.e. matching binaries,
10194 symbols and headers).
10195
10196 .. note::
10197
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010198 The Gdb ``set`` commands in the previous example can be placed into the
10199 users ``~/.gdbinit`` file. Upon starting, Gdb automatically runs whatever
10200 commands are in that file.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010201
102028. *Deploying without a full image rebuild:*
10203
10204 In many cases, during development you want a quick method to deploy a
10205 new binary to the target and debug it, without waiting for a full
10206 image build.
10207
10208 One approach to solving this situation is to just build the component
10209 you want to debug. Once you have built the component, copy the
10210 executable directly to both the target and the host ``debugfs``.
10211
10212 If the binary is processed through the debug splitting in
10213 OpenEmbedded, you should also copy the debug items (i.e. ``.debug``
10214 contents and corresponding ``/usr/src/debug`` files) from the work
10215 directory. Here is an example:
10216 ::
10217
10218 $ bitbake bash
10219 $ bitbake -c devshell bash
10220 $ cd ..
10221 $ scp packages-split/bash/bin/bash target:/bin/bash
10222 $ cp -a packages-split/bash-dbg/\* path/debugfs
10223
10224Debugging with the GNU Project Debugger (GDB) on the Target
10225-----------------------------------------------------------
10226
10227The previous section addressed using GDB remotely for debugging
10228purposes, which is the most usual case due to the inherent hardware
10229limitations on many embedded devices. However, debugging in the target
10230hardware itself is also possible with more powerful devices. This
10231section describes what you need to do in order to support using GDB to
10232debug on the target hardware.
10233
10234To support this kind of debugging, you need do the following:
10235
10236- Ensure that GDB is on the target. You can do this by adding "gdb" to
10237 :term:`IMAGE_INSTALL`:
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010238 ::
10239
10240 IMAGE_INSTALL_append = " gdb"
10241
10242 Alternatively, you can add "tools-debug" to :term:`IMAGE_FEATURES`:
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010243 ::
10244
10245 IMAGE_FEATURES_append = " tools-debug"
10246
10247- Ensure that debug symbols are present. You can make sure these
10248 symbols are present by installing ``-dbg``:
10249 ::
10250
10251 IMAGE_INSTALL_append = "packagename-dbg"
10252
10253 Alternatively, you can do the following to include
10254 all the debug symbols:
10255 ::
10256
10257 IMAGE_FEATURES_append = " dbg-pkgs"
10258
10259.. note::
10260
10261 To improve the debug information accuracy, you can reduce the level
10262 of optimization used by the compiler. For example, when adding the
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010263 following line to your ``local.conf`` file, you will reduce optimization
10264 from :term:`FULL_OPTIMIZATION` of "-O2" to :term:`DEBUG_OPTIMIZATION`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010265 of "-O -fno-omit-frame-pointer":
10266 ::
10267
10268 DEBUG_BUILD = "1"
10269
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010270 Consider that this will reduce the application's performance and is
10271 recommended only for debugging purposes.
10272
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010273Other Debugging Tips
10274--------------------
10275
10276Here are some other tips that you might find useful:
10277
10278- When adding new packages, it is worth watching for undesirable items
10279 making their way into compiler command lines. For example, you do not
10280 want references to local system files like ``/usr/lib/`` or
10281 ``/usr/include/``.
10282
10283- If you want to remove the ``psplash`` boot splashscreen, add
10284 ``psplash=false`` to the kernel command line. Doing so prevents
10285 ``psplash`` from loading and thus allows you to see the console. It
10286 is also possible to switch out of the splashscreen by switching the
10287 virtual console (e.g. Fn+Left or Fn+Right on a Zaurus).
10288
10289- Removing :term:`TMPDIR` (usually
10290 ``tmp/``, within the
10291 :term:`Build Directory`) can often fix
10292 temporary build issues. Removing ``TMPDIR`` is usually a relatively
10293 cheap operation, because task output will be cached in
10294 :term:`SSTATE_DIR` (usually
10295 ``sstate-cache/``, which is also in the Build Directory).
10296
10297 .. note::
10298
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010299 Removing ``TMPDIR`` might be a workaround rather than a fix.
10300 Consequently, trying to determine the underlying cause of an issue before
10301 removing the directory is a good idea.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010302
10303- Understanding how a feature is used in practice within existing
10304 recipes can be very helpful. It is recommended that you configure
10305 some method that allows you to quickly search through files.
10306
10307 Using GNU Grep, you can use the following shell function to
10308 recursively search through common recipe-related files, skipping
10309 binary files, ``.git`` directories, and the Build Directory (assuming
10310 its name starts with "build"):
10311 ::
10312
10313 g() {
10314 grep -Ir \
10315 --exclude-dir=.git \
10316 --exclude-dir='build*' \
10317 --include='*.bb*' \
10318 --include='*.inc*' \
10319 --include='*.conf*' \
10320 --include='*.py*' \
10321 "$@"
10322 }
10323
10324 Following are some usage examples:
10325 ::
10326
10327 $ g FOO # Search recursively for "FOO"
10328 $ g -i foo # Search recursively for "foo", ignoring case
10329 $ g -w FOO # Search recursively for "FOO" as a word, ignoring e.g. "FOOBAR"
10330
10331 If figuring
10332 out how some feature works requires a lot of searching, it might
10333 indicate that the documentation should be extended or improved. In
10334 such cases, consider filing a documentation bug using the Yocto
10335 Project implementation of
10336 :yocto_bugs:`Bugzilla <>`. For information on
10337 how to submit a bug against the Yocto Project, see the Yocto Project
Andrew Geissler09209ee2020-12-13 08:44:15 -060010338 Bugzilla :yocto_wiki:`wiki page </Bugzilla_Configuration_and_Bug_Tracking>`
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050010339 and the
10340 ":ref:`dev-manual/common-tasks:submitting a defect against the yocto project`"
10341 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010342
10343 .. note::
10344
10345 The manuals might not be the right place to document variables
10346 that are purely internal and have a limited scope (e.g. internal
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010347 variables used to implement a single ``.bbclass`` file).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010348
10349Making Changes to the Yocto Project
10350===================================
10351
10352Because the Yocto Project is an open-source, community-based project,
10353you can effect changes to the project. This section presents procedures
10354that show you how to submit a defect against the project and how to
10355submit a change.
10356
10357Submitting a Defect Against the Yocto Project
10358---------------------------------------------
10359
10360Use the Yocto Project implementation of
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010361`Bugzilla <https://www.bugzilla.org/about/>`__ to submit a defect (bug)
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010362against the Yocto Project. For additional information on this
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010363implementation of Bugzilla see the ":ref:`Yocto Project
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010364Bugzilla <resources-bugtracker>`" section in the
10365Yocto Project Reference Manual. For more detail on any of the following
10366steps, see the Yocto Project
Andrew Geissler09209ee2020-12-13 08:44:15 -060010367:yocto_wiki:`Bugzilla wiki page </Bugzilla_Configuration_and_Bug_Tracking>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010368
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010369Use the following general steps to submit a bug:
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010370
103711. Open the Yocto Project implementation of :yocto_bugs:`Bugzilla <>`.
10372
103732. Click "File a Bug" to enter a new bug.
10374
103753. Choose the appropriate "Classification", "Product", and "Component"
10376 for which the bug was found. Bugs for the Yocto Project fall into
10377 one of several classifications, which in turn break down into
10378 several products and components. For example, for a bug against the
10379 ``meta-intel`` layer, you would choose "Build System, Metadata &
10380 Runtime", "BSPs", and "bsps-meta-intel", respectively.
10381
103824. Choose the "Version" of the Yocto Project for which you found the
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010383 bug (e.g. &DISTRO;).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010384
103855. Determine and select the "Severity" of the bug. The severity
10386 indicates how the bug impacted your work.
10387
103886. Choose the "Hardware" that the bug impacts.
10389
103907. Choose the "Architecture" that the bug impacts.
10391
103928. Choose a "Documentation change" item for the bug. Fixing a bug might
10393 or might not affect the Yocto Project documentation. If you are
10394 unsure of the impact to the documentation, select "Don't Know".
10395
103969. Provide a brief "Summary" of the bug. Try to limit your summary to
10397 just a line or two and be sure to capture the essence of the bug.
10398
1039910. Provide a detailed "Description" of the bug. You should provide as
10400 much detail as you can about the context, behavior, output, and so
10401 forth that surrounds the bug. You can even attach supporting files
10402 for output from logs by using the "Add an attachment" button.
10403
1040411. Click the "Submit Bug" button submit the bug. A new Bugzilla number
10405 is assigned to the bug and the defect is logged in the bug tracking
10406 system.
10407
10408Once you file a bug, the bug is processed by the Yocto Project Bug
10409Triage Team and further details concerning the bug are assigned (e.g.
10410priority and owner). You are the "Submitter" of the bug and any further
10411categorization, progress, or comments on the bug result in Bugzilla
10412sending you an automated email concerning the particular change or
10413progress to the bug.
10414
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010415Submitting a Change to the Yocto Project
10416----------------------------------------
10417
10418Contributions to the Yocto Project and OpenEmbedded are very welcome.
10419Because the system is extremely configurable and flexible, we recognize
10420that developers will want to extend, configure or optimize it for their
10421specific uses.
10422
10423The Yocto Project uses a mailing list and a patch-based workflow that is
10424similar to the Linux kernel but contains important differences. In
10425general, a mailing list exists through which you can submit patches. You
10426should send patches to the appropriate mailing list so that they can be
10427reviewed and merged by the appropriate maintainer. The specific mailing
10428list you need to use depends on the location of the code you are
10429changing. Each component (e.g. layer) should have a ``README`` file that
10430indicates where to send the changes and which process to follow.
10431
10432You can send the patch to the mailing list using whichever approach you
10433feel comfortable with to generate the patch. Once sent, the patch is
10434usually reviewed by the community at large. If somebody has concerns
10435with the patch, they will usually voice their concern over the mailing
10436list. If a patch does not receive any negative reviews, the maintainer
10437of the affected layer typically takes the patch, tests it, and then
10438based on successful testing, merges the patch.
10439
10440The "poky" repository, which is the Yocto Project's reference build
10441environment, is a hybrid repository that contains several individual
10442pieces (e.g. BitBake, Metadata, documentation, and so forth) built using
10443the combo-layer tool. The upstream location used for submitting changes
10444varies by component:
10445
10446- *Core Metadata:* Send your patch to the
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010447 :oe_lists:`openembedded-core </g/openembedded-core>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010448 mailing list. For example, a change to anything under the ``meta`` or
10449 ``scripts`` directories should be sent to this mailing list.
10450
10451- *BitBake:* For changes to BitBake (i.e. anything under the
10452 ``bitbake`` directory), send your patch to the
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010453 :oe_lists:`bitbake-devel </g/bitbake-devel>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010454 mailing list.
10455
Andrew Geisslerc3d88e42020-10-02 09:45:00 -050010456- *"meta-\*" trees:* These trees contain Metadata. Use the
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010457 :yocto_lists:`poky </g/poky>` mailing list.
Andrew Geisslerc3d88e42020-10-02 09:45:00 -050010458
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010459- *Documentation*: For changes to the Yocto Project documentation, use the
10460 :yocto_lists:`docs </g/docs>` mailing list.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010461
10462For changes to other layers hosted in the Yocto Project source
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010463repositories (i.e. ``yoctoproject.org``) and tools use the
10464:yocto_lists:`Yocto Project </g/yocto/>` general mailing list.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010465
10466.. note::
10467
10468 Sometimes a layer's documentation specifies to use a particular
10469 mailing list. If so, use that list.
10470
10471For additional recipes that do not fit into the core Metadata, you
10472should determine which layer the recipe should go into and submit the
10473change in the manner recommended by the documentation (e.g. the
10474``README`` file) supplied with the layer. If in doubt, please ask on the
10475Yocto general mailing list or on the openembedded-devel mailing list.
10476
10477You can also push a change upstream and request a maintainer to pull the
10478change into the component's upstream repository. You do this by pushing
Andrew Geissler09209ee2020-12-13 08:44:15 -060010479to a contribution repository that is upstream. See the
10480":ref:`overview-manual/development-environment:git workflows and the yocto project`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010481section in the Yocto Project Overview and Concepts Manual for additional
10482concepts on working in the Yocto Project development environment.
10483
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010484Maintainers commonly use ``-next`` branches to test submissions prior to
10485merging patches. Thus, you can get an idea of the status of a patch based on
10486whether the patch has been merged into one of these branches. The commonly
10487used testing branches for OpenEmbedded-Core are as follows:
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010488
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010489- *openembedded-core "master-next" branch:* This branch is part of the
10490 :oe_git:`openembedded-core </openembedded-core/>` repository and contains
10491 proposed changes to the core metadata.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010492
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010493- *poky "master-next" branch:* This branch is part of the
Andrew Geissler09209ee2020-12-13 08:44:15 -060010494 :yocto_git:`poky </poky/>` repository and combines proposed
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010495 changes to bitbake, the core metadata and the poky distro.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010496
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010497Similarly, stable branches maintained by the project may have corresponding
10498``-next`` branches which collect proposed changes. For example,
10499``&DISTRO_NAME_NO_CAP;-next`` and ``&DISTRO_NAME_NO_CAP_MINUS_ONE;-next``
10500branches in both the "openembdedded-core" and "poky" repositories.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010501
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010502Other layers may have similar testing branches but there is no formal
10503requirement or standard for these so please check the documentation for the
10504layers you are contributing to.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010505
10506The following sections provide procedures for submitting a change.
10507
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010508Preparing Changes for Submission
10509~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010510
105111. *Make Your Changes Locally:* Make your changes in your local Git
10512 repository. You should make small, controlled, isolated changes.
10513 Keeping changes small and isolated aids review, makes
10514 merging/rebasing easier and keeps the change history clean should
10515 anyone need to refer to it in future.
10516
105172. *Stage Your Changes:* Stage your changes by using the ``git add``
10518 command on each file you changed.
10519
105203. *Commit Your Changes:* Commit the change by using the ``git commit``
10521 command. Make sure your commit information follows standards by
10522 following these accepted conventions:
10523
10524 - Be sure to include a "Signed-off-by:" line in the same style as
10525 required by the Linux kernel. Adding this line signifies that you,
10526 the submitter, have agreed to the Developer's Certificate of
10527 Origin 1.1 as follows:
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010528
10529 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010530
10531 Developer's Certificate of Origin 1.1
10532
10533 By making a contribution to this project, I certify that:
10534
10535 (a) The contribution was created in whole or in part by me and I
10536 have the right to submit it under the open source license
10537 indicated in the file; or
10538
10539 (b) The contribution is based upon previous work that, to the best
10540 of my knowledge, is covered under an appropriate open source
10541 license and I have the right under that license to submit that
10542 work with modifications, whether created in whole or in part
10543 by me, under the same open source license (unless I am
10544 permitted to submit under a different license), as indicated
10545 in the file; or
10546
10547 (c) The contribution was provided directly to me by some other
10548 person who certified (a), (b) or (c) and I have not modified
10549 it.
10550
10551 (d) I understand and agree that this project and the contribution
10552 are public and that a record of the contribution (including all
10553 personal information I submit with it, including my sign-off) is
10554 maintained indefinitely and may be redistributed consistent with
10555 this project or the open source license(s) involved.
10556
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010557 - Provide a single-line summary of the change and, if more
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010558 explanation is needed, provide more detail in the body of the
10559 commit. This summary is typically viewable in the "shortlist" of
10560 changes. Thus, providing something short and descriptive that
10561 gives the reader a summary of the change is useful when viewing a
10562 list of many commits. You should prefix this short description
10563 with the recipe name (if changing a recipe), or else with the
10564 short form path to the file being changed.
10565
10566 - For the body of the commit message, provide detailed information
10567 that describes what you changed, why you made the change, and the
10568 approach you used. It might also be helpful if you mention how you
10569 tested the change. Provide as much detail as you can in the body
10570 of the commit message.
10571
10572 .. note::
10573
10574 You do not need to provide a more detailed explanation of a
10575 change if the change is minor to the point of the single line
10576 summary providing all the information.
10577
10578 - If the change addresses a specific bug or issue that is associated
10579 with a bug-tracking ID, include a reference to that ID in your
10580 detailed description. For example, the Yocto Project uses a
10581 specific convention for bug references - any commit that addresses
10582 a specific bug should use the following form for the detailed
10583 description. Be sure to use the actual bug-tracking ID from
10584 Bugzilla for bug-id:
10585 ::
10586
10587 Fixes [YOCTO #bug-id]
10588
10589 detailed description of change
10590
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010591Using Email to Submit a Patch
10592~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10593
10594Depending on the components changed, you need to submit the email to a
10595specific mailing list. For some guidance on which mailing list to use,
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050010596see the
10597:ref:`list <dev-manual/common-tasks:submitting a change to the yocto project>`
10598at the beginning of this section. For a description of all the available
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010599mailing lists, see the ":ref:`Mailing Lists <resources-mailinglist>`" section in the
10600Yocto Project Reference Manual.
10601
10602Here is the general procedure on how to submit a patch through email
10603without using the scripts once the steps in
Andrew Geissler09209ee2020-12-13 08:44:15 -060010604:ref:`dev-manual/common-tasks:preparing changes for submission` have been followed:
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010605
106061. *Format the Commit:* Format the commit into an email message. To
10607 format commits, use the ``git format-patch`` command. When you
10608 provide the command, you must include a revision list or a number of
10609 patches as part of the command. For example, either of these two
10610 commands takes your most recent single commit and formats it as an
10611 email message in the current directory:
10612 ::
10613
10614 $ git format-patch -1
10615
10616 or ::
10617
10618 $ git format-patch HEAD~
10619
10620 After the command is run, the current directory contains a numbered
10621 ``.patch`` file for the commit.
10622
10623 If you provide several commits as part of the command, the
10624 ``git format-patch`` command produces a series of numbered files in
10625 the current directory – one for each commit. If you have more than
10626 one patch, you should also use the ``--cover`` option with the
10627 command, which generates a cover letter as the first "patch" in the
10628 series. You can then edit the cover letter to provide a description
10629 for the series of patches. For information on the
10630 ``git format-patch`` command, see ``GIT_FORMAT_PATCH(1)`` displayed
10631 using the ``man git-format-patch`` command.
10632
10633 .. note::
10634
10635 If you are or will be a frequent contributor to the Yocto Project
10636 or to OpenEmbedded, you might consider requesting a contrib area
10637 and the necessary associated rights.
10638
106392. *Send the patches via email:* Send the patches to the recipients and
10640 relevant mailing lists by using the ``git send-email`` command.
10641
10642 .. note::
10643
10644 In order to use ``git send-email``, you must have the proper Git packages
10645 installed on your host.
10646 For Ubuntu, Debian, and Fedora the package is ``git-email``.
10647
10648 The ``git send-email`` command sends email by using a local or remote
10649 Mail Transport Agent (MTA) such as ``msmtp``, ``sendmail``, or
10650 through a direct ``smtp`` configuration in your Git ``~/.gitconfig``
10651 file. If you are submitting patches through email only, it is very
10652 important that you submit them without any whitespace or HTML
10653 formatting that either you or your mailer introduces. The maintainer
10654 that receives your patches needs to be able to save and apply them
10655 directly from your emails. A good way to verify that what you are
10656 sending will be applicable by the maintainer is to do a dry run and
10657 send them to yourself and then save and apply them as the maintainer
10658 would.
10659
10660 The ``git send-email`` command is the preferred method for sending
10661 your patches using email since there is no risk of compromising
10662 whitespace in the body of the message, which can occur when you use
10663 your own mail client. The command also has several options that let
10664 you specify recipients and perform further editing of the email
10665 message. For information on how to use the ``git send-email``
10666 command, see ``GIT-SEND-EMAIL(1)`` displayed using the
10667 ``man git-send-email`` command.
10668
10669The Yocto Project uses a `Patchwork instance <https://patchwork.openembedded.org/>`__
10670to track the status of patches submitted to the various mailing lists and to
10671support automated patch testing. Each submitted patch is checked for common
10672mistakes and deviations from the expected patch format and submitters are
10673notified by patchtest if such mistakes are found. This process helps to
10674reduce the burden of patch review on maintainers.
10675
10676.. note::
10677
10678 This system is imperfect and changes can sometimes get lost in the flow.
10679 Asking about the status of a patch or change is reasonable if the change
10680 has been idle for a while with no feedback.
10681
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010682Using Scripts to Push a Change Upstream and Request a Pull
10683~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10684
10685For larger patch series it is preferable to send a pull request which not
10686only includes the patch but also a pointer to a branch that can be pulled
10687from. This involves making a local branch for your changes, pushing this
10688branch to an accessible repository and then using the ``create-pull-request``
10689and ``send-pull-request`` scripts from openembedded-core to create and send a
10690patch series with a link to the branch for review.
10691
10692Follow this procedure to push a change to an upstream "contrib" Git
Andrew Geissler09209ee2020-12-13 08:44:15 -060010693repository once the steps in :ref:`dev-manual/common-tasks:preparing changes for submission` have
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010694been followed:
10695
10696.. note::
10697
10698 You can find general Git information on how to push a change upstream
10699 in the
10700 `Git Community Book <https://git-scm.com/book/en/v2/Distributed-Git-Distributed-Workflows>`__.
10701
107021. *Push Your Commits to a "Contrib" Upstream:* If you have arranged for
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010703 permissions to push to an upstream contrib repository, push the
10704 change to that repository:
10705 ::
10706
10707 $ git push upstream_remote_repo local_branch_name
10708
10709 For example, suppose you have permissions to push
10710 into the upstream ``meta-intel-contrib`` repository and you are
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010711 working in a local branch named `your_name`\ ``/README``. The following
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010712 command pushes your local commits to the ``meta-intel-contrib``
10713 upstream repository and puts the commit in a branch named
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010714 `your_name`\ ``/README``:
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010715 ::
10716
10717 $ git push meta-intel-contrib your_name/README
10718
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600107192. *Determine Who to Notify:* Determine the maintainer or the mailing
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010720 list that you need to notify for the change.
10721
10722 Before submitting any change, you need to be sure who the maintainer
10723 is or what mailing list that you need to notify. Use either these
10724 methods to find out:
10725
10726 - *Maintenance File:* Examine the ``maintainers.inc`` file, which is
10727 located in the :term:`Source Directory` at
10728 ``meta/conf/distro/include``, to see who is responsible for code.
10729
Andrew Geissler09209ee2020-12-13 08:44:15 -060010730 - *Search by File:* Using :ref:`overview-manual/development-environment:git`, you can
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010731 enter the following command to bring up a short list of all
10732 commits against a specific file:
10733 ::
10734
10735 git shortlog -- filename
10736
10737 Just provide the name of the file for which you are interested. The
10738 information returned is not ordered by history but does include a
10739 list of everyone who has committed grouped by name. From the list,
10740 you can see who is responsible for the bulk of the changes against
10741 the file.
10742
10743 - *Examine the List of Mailing Lists:* For a list of the Yocto
10744 Project and related mailing lists, see the ":ref:`Mailing
10745 lists <resources-mailinglist>`" section in
10746 the Yocto Project Reference Manual.
10747
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600107483. *Make a Pull Request:* Notify the maintainer or the mailing list that
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010749 you have pushed a change by making a pull request.
10750
10751 The Yocto Project provides two scripts that conveniently let you
10752 generate and send pull requests to the Yocto Project. These scripts
10753 are ``create-pull-request`` and ``send-pull-request``. You can find
10754 these scripts in the ``scripts`` directory within the
10755 :term:`Source Directory` (e.g.
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010756 ``poky/scripts``).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010757
10758 Using these scripts correctly formats the requests without
10759 introducing any whitespace or HTML formatting. The maintainer that
10760 receives your patches either directly or through the mailing list
10761 needs to be able to save and apply them directly from your emails.
10762 Using these scripts is the preferred method for sending patches.
10763
10764 First, create the pull request. For example, the following command
10765 runs the script, specifies the upstream repository in the contrib
10766 directory into which you pushed the change, and provides a subject
10767 line in the created patch files:
10768 ::
10769
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010770 $ poky/scripts/create-pull-request -u meta-intel-contrib -s "Updated Manual Section Reference in README"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010771
10772 Running this script forms ``*.patch`` files in a folder named
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010773 ``pull-``\ `PID` in the current directory. One of the patch files is a
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010774 cover letter.
10775
10776 Before running the ``send-pull-request`` script, you must edit the
10777 cover letter patch to insert information about your change. After
10778 editing the cover letter, send the pull request. For example, the
10779 following command runs the script and specifies the patch directory
10780 and email address. In this example, the email address is a mailing
10781 list:
10782 ::
10783
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010784 $ poky/scripts/send-pull-request -p ~/meta-intel/pull-10565 -t meta-intel@yoctoproject.org
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010785
10786 You need to follow the prompts as the script is interactive.
10787
10788 .. note::
10789
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010790 For help on using these scripts, simply provide the ``-h``
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010791 argument as follows:
10792 ::
10793
10794 $ poky/scripts/create-pull-request -h
10795 $ poky/scripts/send-pull-request -h
10796
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010797Responding to Patch Review
10798~~~~~~~~~~~~~~~~~~~~~~~~~~
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010799
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010800You may get feedback on your submitted patches from other community members
10801or from the automated patchtest service. If issues are identified in your
10802patch then it is usually necessary to address these before the patch will be
10803accepted into the project. In this case you should amend the patch according
10804to the feedback and submit an updated version to the relevant mailing list,
10805copying in the reviewers who provided feedback to the previous version of the
10806patch.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010807
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010808The patch should be amended using ``git commit --amend`` or perhaps ``git
10809rebase`` for more expert git users. You should also modify the ``[PATCH]``
10810tag in the email subject line when sending the revised patch to mark the new
10811iteration as ``[PATCH v2]``, ``[PATCH v3]``, etc as appropriate. This can be
10812done by passing the ``-v`` argument to ``git format-patch`` with a version
10813number.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010814
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010815Lastly please ensure that you also test your revised changes. In particular
10816please don't just edit the patch file written out by ``git format-patch`` and
10817resend it.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010818
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010819Submitting Changes to Stable Release Branches
10820~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010821
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010822The process for proposing changes to a Yocto Project stable branch differs
10823from the steps described above. Changes to a stable branch must address
10824identified bugs or CVEs and should be made carefully in order to avoid the
10825risk of introducing new bugs or breaking backwards compatibility. Typically
10826bug fixes must already be accepted into the master branch before they can be
10827backported to a stable branch unless the bug in question does not affect the
10828master branch or the fix on the master branch is unsuitable for backporting.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010829
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010830The list of stable branches along with the status and maintainer for each
10831branch can be obtained from the
Andrew Geissler09209ee2020-12-13 08:44:15 -060010832:yocto_wiki:`Releases wiki page </Releases>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010833
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010834.. note::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010835
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010836 Changes will not typically be accepted for branches which are marked as
10837 End-Of-Life (EOL).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010838
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010839With this in mind, the steps to submit a change for a stable branch are as
10840follows:
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010841
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600108421. *Identify the bug or CVE to be fixed:* This information should be
10843 collected so that it can be included in your submission.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010844
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600108452. *Check if the fix is already present in the master branch:* This will
10846 result in the most straightforward path into the stable branch for the
10847 fix.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010848
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010849 a. *If the fix is present in the master branch - Submit a backport request
10850 by email:* You should send an email to the relevant stable branch
10851 maintainer and the mailing list with details of the bug or CVE to be
10852 fixed, the commit hash on the master branch that fixes the issue and
10853 the stable branches which you would like this fix to be backported to.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010854
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010855 b. *If the fix is not present in the master branch - Submit the fix to the
10856 master branch first:* This will ensure that the fix passes through the
10857 project's usual patch review and test processes before being accepted.
10858 It will also ensure that bugs are not left unresolved in the master
10859 branch itself. Once the fix is accepted in the master branch a backport
10860 request can be submitted as above.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010861
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010862 c. *If the fix is unsuitable for the master branch - Submit a patch
10863 directly for the stable branch:* This method should be considered as a
10864 last resort. It is typically necessary when the master branch is using
10865 a newer version of the software which includes an upstream fix for the
10866 issue or when the issue has been fixed on the master branch in a way
10867 that introduces backwards incompatible changes. In this case follow the
Andrew Geissler09209ee2020-12-13 08:44:15 -060010868 steps in :ref:`dev-manual/common-tasks:preparing changes for submission` and
10869 :ref:`dev-manual/common-tasks:using email to submit a patch` but modify the subject header of your patch
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010870 email to include the name of the stable branch which you are
10871 targetting. This can be done using the ``--subject-prefix`` argument to
10872 ``git format-patch``, for example to submit a patch to the dunfell
10873 branch use
10874 ``git format-patch --subject-prefix='&DISTRO_NAME_NO_CAP_MINUS_ONE;][PATCH' ...``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010875
10876Working With Licenses
10877=====================
10878
Andrew Geissler09209ee2020-12-13 08:44:15 -060010879As mentioned in the ":ref:`overview-manual/development-environment:licensing`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010880section in the Yocto Project Overview and Concepts Manual, open source
10881projects are open to the public and they consequently have different
10882licensing structures in place. This section describes the mechanism by
10883which the :term:`OpenEmbedded Build System`
10884tracks changes to
10885licensing text and covers how to maintain open source license compliance
10886during your project's lifecycle. The section also describes how to
10887enable commercially licensed recipes, which by default are disabled.
10888
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010889Tracking License Changes
10890------------------------
10891
10892The license of an upstream project might change in the future. In order
10893to prevent these changes going unnoticed, the
10894:term:`LIC_FILES_CHKSUM`
10895variable tracks changes to the license text. The checksums are validated
10896at the end of the configure step, and if the checksums do not match, the
10897build will fail.
10898
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010899Specifying the ``LIC_FILES_CHKSUM`` Variable
10900~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10901
10902The ``LIC_FILES_CHKSUM`` variable contains checksums of the license text
10903in the source code for the recipe. Following is an example of how to
10904specify ``LIC_FILES_CHKSUM``:
10905::
10906
10907 LIC_FILES_CHKSUM = "file://COPYING;md5=xxxx \
10908 file://licfile1.txt;beginline=5;endline=29;md5=yyyy \
10909 file://licfile2.txt;endline=50;md5=zzzz \
10910 ..."
10911
10912.. note::
10913
10914 - When using "beginline" and "endline", realize that line numbering
10915 begins with one and not zero. Also, the included lines are
10916 inclusive (i.e. lines five through and including 29 in the
10917 previous example for ``licfile1.txt``).
10918
10919 - When a license check fails, the selected license text is included
10920 as part of the QA message. Using this output, you can determine
10921 the exact start and finish for the needed license text.
10922
10923The build system uses the :term:`S`
10924variable as the default directory when searching files listed in
10925``LIC_FILES_CHKSUM``. The previous example employs the default
10926directory.
10927
10928Consider this next example:
10929::
10930
10931 LIC_FILES_CHKSUM = "file://src/ls.c;beginline=5;endline=16;\
10932 md5=bb14ed3c4cda583abc85401304b5cd4e"
10933 LIC_FILES_CHKSUM = "file://${WORKDIR}/license.html;md5=5c94767cedb5d6987c902ac850ded2c6"
10934
10935The first line locates a file in ``${S}/src/ls.c`` and isolates lines
10936five through 16 as license text. The second line refers to a file in
10937:term:`WORKDIR`.
10938
10939Note that ``LIC_FILES_CHKSUM`` variable is mandatory for all recipes,
10940unless the ``LICENSE`` variable is set to "CLOSED".
10941
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010942Explanation of Syntax
10943~~~~~~~~~~~~~~~~~~~~~
10944
10945As mentioned in the previous section, the ``LIC_FILES_CHKSUM`` variable
10946lists all the important files that contain the license text for the
10947source code. It is possible to specify a checksum for an entire file, or
10948a specific section of a file (specified by beginning and ending line
10949numbers with the "beginline" and "endline" parameters, respectively).
10950The latter is useful for source files with a license notice header,
10951README documents, and so forth. If you do not use the "beginline"
10952parameter, then it is assumed that the text begins on the first line of
10953the file. Similarly, if you do not use the "endline" parameter, it is
10954assumed that the license text ends with the last line of the file.
10955
10956The "md5" parameter stores the md5 checksum of the license text. If the
10957license text changes in any way as compared to this parameter then a
10958mismatch occurs. This mismatch triggers a build failure and notifies the
10959developer. Notification allows the developer to review and address the
10960license text changes. Also note that if a mismatch occurs during the
10961build, the correct md5 checksum is placed in the build log and can be
10962easily copied to the recipe.
10963
10964There is no limit to how many files you can specify using the
10965``LIC_FILES_CHKSUM`` variable. Generally, however, every project
10966requires a few specifications for license tracking. Many projects have a
10967"COPYING" file that stores the license information for all the source
10968code files. This practice allows you to just track the "COPYING" file as
10969long as it is kept up to date.
10970
10971.. note::
10972
10973 - If you specify an empty or invalid "md5" parameter,
10974 :term:`BitBake` returns an md5
10975 mis-match error and displays the correct "md5" parameter value
10976 during the build. The correct parameter is also captured in the
10977 build log.
10978
10979 - If the whole file contains only license text, you do not need to
10980 use the "beginline" and "endline" parameters.
10981
10982Enabling Commercially Licensed Recipes
10983--------------------------------------
10984
10985By default, the OpenEmbedded build system disables components that have
10986commercial or other special licensing requirements. Such requirements
10987are defined on a recipe-by-recipe basis through the
10988:term:`LICENSE_FLAGS` variable
10989definition in the affected recipe. For instance, the
10990``poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly`` recipe
10991contains the following statement:
10992::
10993
10994 LICENSE_FLAGS = "commercial"
10995
10996Here is a
10997slightly more complicated example that contains both an explicit recipe
10998name and version (after variable expansion):
10999::
11000
11001 LICENSE_FLAGS = "license_${PN}_${PV}"
11002
11003In order for a component restricted by a
11004``LICENSE_FLAGS`` definition to be enabled and included in an image, it
11005needs to have a matching entry in the global
11006:term:`LICENSE_FLAGS_WHITELIST`
11007variable, which is a variable typically defined in your ``local.conf``
11008file. For example, to enable the
11009``poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly`` package, you
11010could add either the string "commercial_gst-plugins-ugly" or the more
11011general string "commercial" to ``LICENSE_FLAGS_WHITELIST``. See the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050011012":ref:`dev-manual/common-tasks:license flag matching`" section for a full
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011013explanation of how ``LICENSE_FLAGS`` matching works. Here is the
11014example:
11015::
11016
11017 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly"
11018
11019Likewise, to additionally enable the package built from the recipe
11020containing ``LICENSE_FLAGS = "license_${PN}_${PV}"``, and assuming that
11021the actual recipe name was ``emgd_1.10.bb``, the following string would
11022enable that package as well as the original ``gst-plugins-ugly``
11023package:
11024::
11025
11026 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly license_emgd_1.10"
11027
11028As a convenience, you do not need to specify the
11029complete license string in the whitelist for every package. You can use
11030an abbreviated form, which consists of just the first portion or
11031portions of the license string before the initial underscore character
11032or characters. A partial string will match any license that contains the
11033given string as the first portion of its license. For example, the
11034following whitelist string will also match both of the packages
11035previously mentioned as well as any other packages that have licenses
11036starting with "commercial" or "license".
11037::
11038
11039 LICENSE_FLAGS_WHITELIST = "commercial license"
11040
11041License Flag Matching
11042~~~~~~~~~~~~~~~~~~~~~
11043
11044License flag matching allows you to control what recipes the
11045OpenEmbedded build system includes in the build. Fundamentally, the
11046build system attempts to match ``LICENSE_FLAGS`` strings found in
11047recipes against ``LICENSE_FLAGS_WHITELIST`` strings found in the
11048whitelist. A match causes the build system to include a recipe in the
11049build, while failure to find a match causes the build system to exclude
11050a recipe.
11051
11052In general, license flag matching is simple. However, understanding some
11053concepts will help you correctly and effectively use matching.
11054
11055Before a flag defined by a particular recipe is tested against the
11056contents of the whitelist, the expanded string ``_${PN}`` is appended to
11057the flag. This expansion makes each ``LICENSE_FLAGS`` value
11058recipe-specific. After expansion, the string is then matched against the
11059whitelist. Thus, specifying ``LICENSE_FLAGS = "commercial"`` in recipe
11060"foo", for example, results in the string ``"commercial_foo"``. And, to
11061create a match, that string must appear in the whitelist.
11062
11063Judicious use of the ``LICENSE_FLAGS`` strings and the contents of the
11064``LICENSE_FLAGS_WHITELIST`` variable allows you a lot of flexibility for
11065including or excluding recipes based on licensing. For example, you can
11066broaden the matching capabilities by using license flags string subsets
11067in the whitelist.
11068
11069.. note::
11070
11071 When using a string subset, be sure to use the part of the expanded
11072 string that precedes the appended underscore character (e.g.
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011073 ``usethispart_1.3``, ``usethispart_1.4``, and so forth).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011074
11075For example, simply specifying the string "commercial" in the whitelist
11076matches any expanded ``LICENSE_FLAGS`` definition that starts with the
11077string "commercial" such as "commercial_foo" and "commercial_bar", which
11078are the strings the build system automatically generates for
11079hypothetical recipes named "foo" and "bar" assuming those recipes simply
11080specify the following:
11081::
11082
11083 LICENSE_FLAGS = "commercial"
11084
11085Thus, you can choose
11086to exhaustively enumerate each license flag in the whitelist and allow
11087only specific recipes into the image, or you can use a string subset
11088that causes a broader range of matches to allow a range of recipes into
11089the image.
11090
11091This scheme works even if the ``LICENSE_FLAGS`` string already has
11092``_${PN}`` appended. For example, the build system turns the license
11093flag "commercial_1.2_foo" into "commercial_1.2_foo_foo" and would match
11094both the general "commercial" and the specific "commercial_1.2_foo"
11095strings found in the whitelist, as expected.
11096
11097Here are some other scenarios:
11098
11099- You can specify a versioned string in the recipe such as
11100 "commercial_foo_1.2" in a "foo" recipe. The build system expands this
11101 string to "commercial_foo_1.2_foo". Combine this license flag with a
11102 whitelist that has the string "commercial" and you match the flag
11103 along with any other flag that starts with the string "commercial".
11104
11105- Under the same circumstances, you can use "commercial_foo" in the
11106 whitelist and the build system not only matches "commercial_foo_1.2"
11107 but also matches any license flag with the string "commercial_foo",
11108 regardless of the version.
11109
11110- You can be very specific and use both the package and version parts
11111 in the whitelist (e.g. "commercial_foo_1.2") to specifically match a
11112 versioned recipe.
11113
11114Other Variables Related to Commercial Licenses
11115~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11116
11117Other helpful variables related to commercial license handling exist and
11118are defined in the
11119``poky/meta/conf/distro/include/default-distrovars.inc`` file:
11120::
11121
11122 COMMERCIAL_AUDIO_PLUGINS ?= ""
11123 COMMERCIAL_VIDEO_PLUGINS ?= ""
11124
11125If you
11126want to enable these components, you can do so by making sure you have
11127statements similar to the following in your ``local.conf`` configuration
11128file:
11129::
11130
11131 COMMERCIAL_AUDIO_PLUGINS = "gst-plugins-ugly-mad \
11132 gst-plugins-ugly-mpegaudioparse"
11133 COMMERCIAL_VIDEO_PLUGINS = "gst-plugins-ugly-mpeg2dec \
11134 gst-plugins-ugly-mpegstream gst-plugins-bad-mpegvideoparse"
11135 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly commercial_gst-plugins-bad commercial_qmmp"
11136
11137
11138Of course, you could also create a matching whitelist for those
11139components using the more general "commercial" in the whitelist, but
11140that would also enable all the other packages with ``LICENSE_FLAGS``
11141containing "commercial", which you may or may not want:
11142::
11143
11144 LICENSE_FLAGS_WHITELIST = "commercial"
11145
11146Specifying audio and video plugins as part of the
11147``COMMERCIAL_AUDIO_PLUGINS`` and ``COMMERCIAL_VIDEO_PLUGINS`` statements
11148(along with the enabling ``LICENSE_FLAGS_WHITELIST``) includes the
11149plugins or components into built images, thus adding support for media
11150formats or components.
11151
11152Maintaining Open Source License Compliance During Your Product's Lifecycle
11153--------------------------------------------------------------------------
11154
11155One of the concerns for a development organization using open source
11156software is how to maintain compliance with various open source
11157licensing during the lifecycle of the product. While this section does
11158not provide legal advice or comprehensively cover all scenarios, it does
11159present methods that you can use to assist you in meeting the compliance
11160requirements during a software release.
11161
11162With hundreds of different open source licenses that the Yocto Project
11163tracks, it is difficult to know the requirements of each and every
11164license. However, the requirements of the major FLOSS licenses can begin
11165to be covered by assuming that three main areas of concern exist:
11166
11167- Source code must be provided.
11168
11169- License text for the software must be provided.
11170
11171- Compilation scripts and modifications to the source code must be
11172 provided.
11173
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011174- spdx files can be provided.
11175
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011176There are other requirements beyond the scope of these three and the
11177methods described in this section (e.g. the mechanism through which
11178source code is distributed).
11179
11180As different organizations have different methods of complying with open
11181source licensing, this section is not meant to imply that there is only
11182one single way to meet your compliance obligations, but rather to
11183describe one method of achieving compliance. The remainder of this
11184section describes methods supported to meet the previously mentioned
11185three requirements. Once you take steps to meet these requirements, and
11186prior to releasing images, sources, and the build system, you should
11187audit all artifacts to ensure completeness.
11188
11189.. note::
11190
11191 The Yocto Project generates a license manifest during image creation
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011192 that is located in ``${DEPLOY_DIR}/licenses/``\ `image_name`\ ``-``\ `datestamp`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011193 to assist with any audits.
11194
11195Providing the Source Code
11196~~~~~~~~~~~~~~~~~~~~~~~~~
11197
11198Compliance activities should begin before you generate the final image.
11199The first thing you should look at is the requirement that tops the list
11200for most compliance groups - providing the source. The Yocto Project has
11201a few ways of meeting this requirement.
11202
11203One of the easiest ways to meet this requirement is to provide the
11204entire :term:`DL_DIR` used by the
11205build. This method, however, has a few issues. The most obvious is the
11206size of the directory since it includes all sources used in the build
11207and not just the source used in the released image. It will include
11208toolchain source, and other artifacts, which you would not generally
11209release. However, the more serious issue for most companies is
11210accidental release of proprietary software. The Yocto Project provides
11211an :ref:`archiver <ref-classes-archiver>` class to
11212help avoid some of these concerns.
11213
11214Before you employ ``DL_DIR`` or the ``archiver`` class, you need to
11215decide how you choose to provide source. The source ``archiver`` class
11216can generate tarballs and SRPMs and can create them with various levels
11217of compliance in mind.
11218
11219One way of doing this (but certainly not the only way) is to release
11220just the source as a tarball. You can do this by adding the following to
11221the ``local.conf`` file found in the
11222:term:`Build Directory`:
11223::
11224
11225 INHERIT += "archiver"
11226 ARCHIVER_MODE[src] = "original"
11227
11228During the creation of your
11229image, the source from all recipes that deploy packages to the image is
11230placed within subdirectories of ``DEPLOY_DIR/sources`` based on the
11231:term:`LICENSE` for each recipe.
11232Releasing the entire directory enables you to comply with requirements
11233concerning providing the unmodified source. It is important to note that
11234the size of the directory can get large.
11235
11236A way to help mitigate the size issue is to only release tarballs for
11237licenses that require the release of source. Let us assume you are only
11238concerned with GPL code as identified by running the following script:
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011239
11240.. code-block:: shell
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011241
11242 # Script to archive a subset of packages matching specific license(s)
11243 # Source and license files are copied into sub folders of package folder
11244 # Must be run from build folder
11245 #!/bin/bash
11246 src_release_dir="source-release"
11247 mkdir -p $src_release_dir
11248 for a in tmp/deploy/sources/*; do
11249 for d in $a/*; do
11250 # Get package name from path
11251 p=`basename $d`
11252 p=${p%-*}
11253 p=${p%-*}
11254 # Only archive GPL packages (update *GPL* regex for your license check)
11255 numfiles=`ls tmp/deploy/licenses/$p/*GPL* 2> /dev/null | wc -l`
11256 if [ $numfiles -gt 1 ]; then
11257 echo Archiving $p
11258 mkdir -p $src_release_dir/$p/source
11259 cp $d/* $src_release_dir/$p/source 2> /dev/null
11260 mkdir -p $src_release_dir/$p/license
11261 cp tmp/deploy/licenses/$p/* $src_release_dir/$p/license 2> /dev/null
11262 fi
11263 done
11264 done
11265
11266At this point, you
11267could create a tarball from the ``gpl_source_release`` directory and
11268provide that to the end user. This method would be a step toward
11269achieving compliance with section 3a of GPLv2 and with section 6 of
11270GPLv3.
11271
11272Providing License Text
11273~~~~~~~~~~~~~~~~~~~~~~
11274
11275One requirement that is often overlooked is inclusion of license text.
11276This requirement also needs to be dealt with prior to generating the
11277final image. Some licenses require the license text to accompany the
11278binary. You can achieve this by adding the following to your
11279``local.conf`` file:
11280::
11281
11282 COPY_LIC_MANIFEST = "1"
11283 COPY_LIC_DIRS = "1"
11284 LICENSE_CREATE_PACKAGE = "1"
11285
11286Adding these statements to the
11287configuration file ensures that the licenses collected during package
11288generation are included on your image.
11289
11290.. note::
11291
11292 Setting all three variables to "1" results in the image having two
11293 copies of the same license file. One copy resides in
11294 ``/usr/share/common-licenses`` and the other resides in
11295 ``/usr/share/license``.
11296
11297 The reason for this behavior is because
11298 :term:`COPY_LIC_DIRS` and
11299 :term:`COPY_LIC_MANIFEST`
11300 add a copy of the license when the image is built but do not offer a
11301 path for adding licenses for newly installed packages to an image.
11302 :term:`LICENSE_CREATE_PACKAGE`
11303 adds a separate package and an upgrade path for adding licenses to an
11304 image.
11305
11306As the source ``archiver`` class has already archived the original
11307unmodified source that contains the license files, you would have
11308already met the requirements for inclusion of the license information
11309with source as defined by the GPL and other open source licenses.
11310
11311Providing Compilation Scripts and Source Code Modifications
11312~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11313
11314At this point, we have addressed all we need to prior to generating the
11315image. The next two requirements are addressed during the final
11316packaging of the release.
11317
11318By releasing the version of the OpenEmbedded build system and the layers
11319used during the build, you will be providing both compilation scripts
11320and the source code modifications in one step.
11321
Andrew Geissler09209ee2020-12-13 08:44:15 -060011322If the deployment team has a :ref:`overview-manual/concepts:bsp layer`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011323and a distro layer, and those
11324those layers are used to patch, compile, package, or modify (in any way)
11325any open source software included in your released images, you might be
11326required to release those layers under section 3 of GPLv2 or section 1
11327of GPLv3. One way of doing that is with a clean checkout of the version
11328of the Yocto Project and layers used during your build. Here is an
11329example:
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011330
11331.. code-block:: shell
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011332
11333 # We built using the dunfell branch of the poky repo
11334 $ git clone -b dunfell git://git.yoctoproject.org/poky
11335 $ cd poky
11336 # We built using the release_branch for our layers
11337 $ git clone -b release_branch git://git.mycompany.com/meta-my-bsp-layer
11338 $ git clone -b release_branch git://git.mycompany.com/meta-my-software-layer
11339 # clean up the .git repos
11340 $ find . -name ".git" -type d -exec rm -rf {} \;
11341
11342One
11343thing a development organization might want to consider for end-user
11344convenience is to modify ``meta-poky/conf/bblayers.conf.sample`` to
11345ensure that when the end user utilizes the released build system to
11346build an image, the development organization's layers are included in
11347the ``bblayers.conf`` file automatically:
11348::
11349
11350 # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
11351 # changes incompatibly
11352 POKY_BBLAYERS_CONF_VERSION = "2"
11353
11354 BBPATH = "${TOPDIR}"
11355 BBFILES ?= ""
11356
11357 BBLAYERS ?= " \
11358 ##OEROOT##/meta \
11359 ##OEROOT##/meta-poky \
11360 ##OEROOT##/meta-yocto-bsp \
11361 ##OEROOT##/meta-mylayer \
11362 "
11363
11364Creating and
11365providing an archive of the :term:`Metadata`
11366layers (recipes, configuration files, and so forth) enables you to meet
11367your requirements to include the scripts to control compilation as well
11368as any modifications to the original source.
11369
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011370Providing spdx files
11371~~~~~~~~~~~~~~~~~~~~~~~~~
11372
11373The spdx module has been integrated to a layer named meta-spdxscanner.
11374meta-spdxscanner provides several kinds of scanner. If you want to enable
11375this function, you have to follow the following steps:
11376
113771. Add meta-spdxscanner layer into ``bblayers.conf``.
11378
113792. Refer to the README in meta-spdxscanner to setup the environment (e.g,
11380 setup a fossology server) needed for the scanner.
11381
113823. Meta-spdxscanner provides several methods within the bbclass to create spdx files.
11383 Please choose one that you want to use and enable the spdx task. You have to
11384 add some config options in ``local.conf`` file in your :term:`Build
11385 Directory`. The following is an example showing how to generate spdx files
11386 during bitbake using the fossology-python.bbclass::
11387
11388 # Select fossology-python.bbclass.
11389 INHERIT += "fossology-python"
11390 # For fossology-python.bbclass, TOKEN is necessary, so, after setup a
11391 # Fossology server, you have to create a token.
11392 TOKEN = "eyJ0eXAiO..."
11393 # The fossology server is necessary for fossology-python.bbclass.
11394 FOSSOLOGY_SERVER = "http://xx.xx.xx.xx:8081/repo"
11395 # If you want to upload the source code to a special folder:
11396 FOLDER_NAME = "xxxx" //Optional
11397 # If you don't want to put spdx files in tmp/deploy/spdx, you can enable:
11398 SPDX_DEPLOY_DIR = "${DEPLOY_DIR}" //Optional
11399
11400For more usage information refer to :yocto_git:`the meta-spdxscanner repository
Andrew Geissler09209ee2020-12-13 08:44:15 -060011401</meta-spdxscanner/>`.
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011402
11403
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011404Copying Licenses that Do Not Exist
11405----------------------------------
11406
11407Some packages, such as the linux-firmware package, have many licenses
11408that are not in any way common. You can avoid adding a lot of these
11409types of common license files, which are only applicable to a specific
11410package, by using the
11411:term:`NO_GENERIC_LICENSE`
11412variable. Using this variable also avoids QA errors when you use a
11413non-common, non-CLOSED license in a recipe.
11414
11415The following is an example that uses the ``LICENSE.Abilis.txt`` file as
11416the license from the fetched source:
11417::
11418
11419 NO_GENERIC_LICENSE[Firmware-Abilis] = "LICENSE.Abilis.txt"
11420
11421Using the Error Reporting Tool
11422==============================
11423
11424The error reporting tool allows you to submit errors encountered during
11425builds to a central database. Outside of the build environment, you can
11426use a web interface to browse errors, view statistics, and query for
11427errors. The tool works using a client-server system where the client
11428portion is integrated with the installed Yocto Project
11429:term:`Source Directory` (e.g. ``poky``).
11430The server receives the information collected and saves it in a
11431database.
11432
11433A live instance of the error reporting server exists at
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011434https://errors.yoctoproject.org. This server exists so that when
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011435you want to get help with build failures, you can submit all of the
11436information on the failure easily and then point to the URL in your bug
11437report or send an email to the mailing list.
11438
11439.. note::
11440
11441 If you send error reports to this server, the reports become publicly
11442 visible.
11443
11444Enabling and Using the Tool
11445---------------------------
11446
11447By default, the error reporting tool is disabled. You can enable it by
11448inheriting the
11449:ref:`report-error <ref-classes-report-error>`
11450class by adding the following statement to the end of your
11451``local.conf`` file in your
11452:term:`Build Directory`.
11453::
11454
11455 INHERIT += "report-error"
11456
11457By default, the error reporting feature stores information in
11458``${``\ :term:`LOG_DIR`\ ``}/error-report``.
11459However, you can specify a directory to use by adding the following to
11460your ``local.conf`` file:
11461::
11462
11463 ERR_REPORT_DIR = "path"
11464
11465Enabling error
11466reporting causes the build process to collect the errors and store them
11467in a file as previously described. When the build system encounters an
11468error, it includes a command as part of the console output. You can run
11469the command to send the error file to the server. For example, the
11470following command sends the errors to an upstream server:
11471::
11472
11473 $ send-error-report /home/brandusa/project/poky/build/tmp/log/error-report/error_report_201403141617.txt
11474
11475In the previous example, the errors are sent to a public database
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011476available at https://errors.yoctoproject.org, which is used by the
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011477entire community. If you specify a particular server, you can send the
11478errors to a different database. Use the following command for more
11479information on available options:
11480::
11481
11482 $ send-error-report --help
11483
11484When sending the error file, you are prompted to review the data being
11485sent as well as to provide a name and optional email address. Once you
11486satisfy these prompts, the command returns a link from the server that
11487corresponds to your entry in the database. For example, here is a
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011488typical link: https://errors.yoctoproject.org/Errors/Details/9522/
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011489
11490Following the link takes you to a web interface where you can browse,
11491query the errors, and view statistics.
11492
11493Disabling the Tool
11494------------------
11495
11496To disable the error reporting feature, simply remove or comment out the
11497following statement from the end of your ``local.conf`` file in your
11498:term:`Build Directory`.
11499::
11500
11501 INHERIT += "report-error"
11502
11503Setting Up Your Own Error Reporting Server
11504------------------------------------------
11505
11506If you want to set up your own error reporting server, you can obtain
Andrew Geissler09209ee2020-12-13 08:44:15 -060011507the code from the Git repository at :yocto_git:`/error-report-web/`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011508Instructions on how to set it up are in the README document.
11509
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011510Using Wayland and Weston
11511========================
11512
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011513`Wayland <https://en.wikipedia.org/wiki/Wayland_(display_server_protocol)>`__
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011514is a computer display server protocol that provides a method for
11515compositing window managers to communicate directly with applications
11516and video hardware and expects them to communicate with input hardware
11517using other libraries. Using Wayland with supporting targets can result
11518in better control over graphics frame rendering than an application
11519might otherwise achieve.
11520
11521The Yocto Project provides the Wayland protocol libraries and the
11522reference
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011523`Weston <https://en.wikipedia.org/wiki/Wayland_(display_server_protocol)#Weston>`__
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011524compositor as part of its release. You can find the integrated packages
11525in the ``meta`` layer of the :term:`Source Directory`.
11526Specifically, you
11527can find the recipes that build both Wayland and Weston at
11528``meta/recipes-graphics/wayland``.
11529
11530You can build both the Wayland and Weston packages for use only with
11531targets that accept the `Mesa 3D and Direct Rendering
11532Infrastructure <https://en.wikipedia.org/wiki/Mesa_(computer_graphics)>`__,
11533which is also known as Mesa DRI. This implies that you cannot build and
11534use the packages if your target uses, for example, the Intel Embedded
11535Media and Graphics Driver (Intel EMGD) that overrides Mesa DRI.
11536
11537.. note::
11538
11539 Due to lack of EGL support, Weston 1.0.3 will not run directly on the
11540 emulated QEMU hardware. However, this version of Weston will run
11541 under X emulation without issues.
11542
11543This section describes what you need to do to implement Wayland and use
11544the Weston compositor when building an image for a supporting target.
11545
11546Enabling Wayland in an Image
11547----------------------------
11548
11549To enable Wayland, you need to enable it to be built and enable it to be
11550included (installed) in the image.
11551
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011552Building Wayland
11553~~~~~~~~~~~~~~~~
11554
11555To cause Mesa to build the ``wayland-egl`` platform and Weston to build
11556Wayland with Kernel Mode Setting
11557(`KMS <https://wiki.archlinux.org/index.php/Kernel_Mode_Setting>`__)
11558support, include the "wayland" flag in the
11559:term:`DISTRO_FEATURES`
11560statement in your ``local.conf`` file:
11561::
11562
11563 DISTRO_FEATURES_append = " wayland"
11564
11565.. note::
11566
11567 If X11 has been enabled elsewhere, Weston will build Wayland with X11
11568 support
11569
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011570Installing Wayland and Weston
11571~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11572
11573To install the Wayland feature into an image, you must include the
11574following
11575:term:`CORE_IMAGE_EXTRA_INSTALL`
11576statement in your ``local.conf`` file:
11577::
11578
11579 CORE_IMAGE_EXTRA_INSTALL += "wayland weston"
11580
11581Running Weston
11582--------------
11583
11584To run Weston inside X11, enabling it as described earlier and building
11585a Sato image is sufficient. If you are running your image under Sato, a
11586Weston Launcher appears in the "Utility" category.
11587
11588Alternatively, you can run Weston through the command-line interpretor
11589(CLI), which is better suited for development work. To run Weston under
11590the CLI, you need to do the following after your image is built:
11591
115921. Run these commands to export ``XDG_RUNTIME_DIR``:
11593 ::
11594
11595 mkdir -p /tmp/$USER-weston
11596 chmod 0700 /tmp/$USER-weston
11597 export XDG_RUNTIME_DIR=/tmp/$USER-weston
11598
115992. Launch Weston in the shell:
11600 ::
11601
11602 weston