blob: e1dee8ecdd311c114adfc42e50022b794f6bae41 [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 Geisslerc723b722021-01-08 16:14:09 -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.
158 See the "`Making Sure Your Layer is Compatible With Yocto
159 Project <#making-sure-your-layer-is-compatible-with-yocto-project>`__"
160 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
285 for compatibility. See the "`Making Sure Your Layer is Compatible
286 With Yocto
287 Project <#making-sure-your-layer-is-compatible-with-yocto-project>`__"
288 section for more information.
289
290- *Follow the Layer Naming Convention:* Store custom layers in a Git
291 repository that use the ``meta-layer_name`` format.
292
293- *Group Your Layers Locally:* Clone your repository alongside other
294 cloned ``meta`` directories from the :term:`Source Directory`.
295
296Making Sure Your Layer is Compatible With Yocto Project
297-------------------------------------------------------
298
299When you create a layer used with the Yocto Project, it is advantageous
300to make sure that the layer interacts well with existing Yocto Project
301layers (i.e. the layer is compatible with the Yocto Project). Ensuring
302compatibility makes the layer easy to be consumed by others in the Yocto
303Project community and could allow you permission to use the Yocto
304Project Compatible Logo.
305
306.. note::
307
308 Only Yocto Project member organizations are permitted to use the
309 Yocto Project Compatible Logo. The logo is not available for general
310 use. For information on how to become a Yocto Project member
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500311 organization, see the :yocto_home:`Yocto Project Website <>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500312
313The Yocto Project Compatibility Program consists of a layer application
314process that requests permission to use the Yocto Project Compatibility
315Logo for your layer and application. The process consists of two parts:
316
3171. Successfully passing a script (``yocto-check-layer``) that when run
318 against your layer, tests it against constraints based on experiences
319 of how layers have worked in the real world and where pitfalls have
320 been found. Getting a "PASS" result from the script is required for
321 successful compatibility registration.
322
3232. Completion of an application acceptance form, which you can find at
Andrew Geisslerc723b722021-01-08 16:14:09 -0600324 :yocto_home:`/webform/yocto-project-compatible-registration`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500325
326To be granted permission to use the logo, you need to satisfy the
327following:
328
329- Be able to check the box indicating that you got a "PASS" when
330 running the script against your layer.
331
332- Answer "Yes" to the questions on the form or have an acceptable
333 explanation for any questions answered "No".
334
335- Be a Yocto Project Member Organization.
336
337The remainder of this section presents information on the registration
338form and on the ``yocto-check-layer`` script.
339
340Yocto Project Compatible Program Application
341~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
342
343Use the form to apply for your layer's approval. Upon successful
344application, you can use the Yocto Project Compatibility Logo with your
345layer and the application that uses your layer.
346
347To access the form, use this link:
Andrew Geisslerc723b722021-01-08 16:14:09 -0600348:yocto_home:`/webform/yocto-project-compatible-registration`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500349Follow the instructions on the form to complete your application.
350
351The application consists of the following sections:
352
353- *Contact Information:* Provide your contact information as the fields
354 require. Along with your information, provide the released versions
355 of the Yocto Project for which your layer is compatible.
356
357- *Acceptance Criteria:* Provide "Yes" or "No" answers for each of the
358 items in the checklist. Space exists at the bottom of the form for
359 any explanations for items for which you answered "No".
360
361- *Recommendations:* Provide answers for the questions regarding Linux
362 kernel use and build success.
363
364``yocto-check-layer`` Script
365~~~~~~~~~~~~~~~~~~~~~~~~~~~~
366
367The ``yocto-check-layer`` script provides you a way to assess how
368compatible your layer is with the Yocto Project. You should run this
369script prior to using the form to apply for compatibility as described
370in the previous section. You need to achieve a "PASS" result in order to
371have your application form successfully processed.
372
373The script divides tests into three areas: COMMON, BSP, and DISTRO. For
374example, given a distribution layer (DISTRO), the layer must pass both
375the COMMON and DISTRO related tests. Furthermore, if your layer is a BSP
376layer, the layer must pass the COMMON and BSP set of tests.
377
378To execute the script, enter the following commands from your build
379directory:
380::
381
382 $ source oe-init-build-env
383 $ yocto-check-layer your_layer_directory
384
385Be sure to provide the actual directory for your
386layer as part of the command.
387
388Entering the command causes the script to determine the type of layer
389and then to execute a set of specific tests against the layer. The
390following list overviews the test:
391
392- ``common.test_readme``: Tests if a ``README`` file exists in the
393 layer and the file is not empty.
394
395- ``common.test_parse``: Tests to make sure that BitBake can parse the
396 files without error (i.e. ``bitbake -p``).
397
398- ``common.test_show_environment``: Tests that the global or per-recipe
399 environment is in order without errors (i.e. ``bitbake -e``).
400
401- ``common.test_world``: Verifies that ``bitbake world`` works.
402
403- ``common.test_signatures``: Tests to be sure that BSP and DISTRO
404 layers do not come with recipes that change signatures.
405
406- ``common.test_layerseries_compat``: Verifies layer compatibility is
407 set properly.
408
409- ``bsp.test_bsp_defines_machines``: Tests if a BSP layer has machine
410 configurations.
411
412- ``bsp.test_bsp_no_set_machine``: Tests to ensure a BSP layer does not
413 set the machine when the layer is added.
414
415- ``bsp.test_machine_world``: Verifies that ``bitbake world`` works
416 regardless of which machine is selected.
417
418- ``bsp.test_machine_signatures``: Verifies that building for a
419 particular machine affects only the signature of tasks specific to
420 that machine.
421
422- ``distro.test_distro_defines_distros``: Tests if a DISTRO layer has
423 distro configurations.
424
425- ``distro.test_distro_no_set_distros``: Tests to ensure a DISTRO layer
426 does not set the distribution when the layer is added.
427
428Enabling Your Layer
429-------------------
430
431Before the OpenEmbedded build system can use your new layer, you need to
432enable it. To enable your layer, simply add your layer's path to the
433``BBLAYERS`` variable in your ``conf/bblayers.conf`` file, which is
434found in the :term:`Build Directory`.
435The following example shows how to enable a layer named
436``meta-mylayer``:
437::
438
439 # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
440 # changes incompatibly
441 POKY_BBLAYERS_CONF_VERSION = "2"
442 BBPATH = "${TOPDIR}"
443 BBFILES ?= ""
444 BBLAYERS ?= " \
445 /home/user/poky/meta \
446 /home/user/poky/meta-poky \
447 /home/user/poky/meta-yocto-bsp \
448 /home/user/poky/meta-mylayer \
449 "
450
451BitBake parses each ``conf/layer.conf`` file from the top down as
452specified in the ``BBLAYERS`` variable within the ``conf/bblayers.conf``
453file. During the processing of each ``conf/layer.conf`` file, BitBake
454adds the recipes, classes and configurations contained within the
455particular layer to the source directory.
456
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500457Using .bbappend Files in Your Layer
458-----------------------------------
459
460A recipe that appends Metadata to another recipe is called a BitBake
461append file. A BitBake append file uses the ``.bbappend`` file type
462suffix, while the corresponding recipe to which Metadata is being
463appended uses the ``.bb`` file type suffix.
464
465You can use a ``.bbappend`` file in your layer to make additions or
466changes to the content of another layer's recipe without having to copy
467the other layer's recipe into your layer. Your ``.bbappend`` file
468resides in your layer, while the main ``.bb`` recipe file to which you
469are appending Metadata resides in a different layer.
470
471Being able to append information to an existing recipe not only avoids
472duplication, but also automatically applies recipe changes from a
473different layer into your layer. If you were copying recipes, you would
474have to manually merge changes as they occur.
475
476When you create an append file, you must use the same root name as the
477corresponding recipe file. For example, the append file
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500478``someapp_3.1.bbappend`` must apply to ``someapp_3.1.bb``. This
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500479means the original recipe and append file names are version
480number-specific. If the corresponding recipe is renamed to update to a
481newer version, you must also rename and possibly update the
482corresponding ``.bbappend`` as well. During the build process, BitBake
483displays an error on starting if it detects a ``.bbappend`` file that
484does not have a corresponding recipe with a matching name. See the
485:term:`BB_DANGLINGAPPENDS_WARNONLY`
486variable for information on how to handle this error.
487
488As an example, consider the main formfactor recipe and a corresponding
489formfactor append file both from the :term:`Source Directory`.
490Here is the main
491formfactor recipe, which is named ``formfactor_0.0.bb`` and located in
492the "meta" layer at ``meta/recipes-bsp/formfactor``:
493::
494
495 SUMMARY = "Device formfactor information"
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500496 DESCRIPTION = "A formfactor configuration file provides information about the \
497 target hardware for which the image is being built and information that the \
498 build system cannot obtain from other sources such as the kernel."
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500499 SECTION = "base"
500 LICENSE = "MIT"
501 LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
502 PR = "r45"
503
504 SRC_URI = "file://config file://machconfig"
505 S = "${WORKDIR}"
506
507 PACKAGE_ARCH = "${MACHINE_ARCH}"
508 INHIBIT_DEFAULT_DEPS = "1"
509
510 do_install() {
511 # Install file only if it has contents
512 install -d ${D}${sysconfdir}/formfactor/
513 install -m 0644 ${S}/config ${D}${sysconfdir}/formfactor/
514 if [ -s "${S}/machconfig" ]; then
515 install -m 0644 ${S}/machconfig ${D}${sysconfdir}/formfactor/
516 fi
517 }
518
519In the main recipe, note the :term:`SRC_URI`
520variable, which tells the OpenEmbedded build system where to find files
521during the build.
522
523Following is the append file, which is named ``formfactor_0.0.bbappend``
524and is from the Raspberry Pi BSP Layer named ``meta-raspberrypi``. The
525file is in the layer at ``recipes-bsp/formfactor``:
526::
527
528 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
529
530By default, the build system uses the
531:term:`FILESPATH` variable to
532locate files. This append file extends the locations by setting the
533:term:`FILESEXTRAPATHS`
534variable. Setting this variable in the ``.bbappend`` file is the most
535reliable and recommended method for adding directories to the search
536path used by the build system to find files.
537
538The statement in this example extends the directories to include
539``${``\ :term:`THISDIR`\ ``}/${``\ :term:`PN`\ ``}``,
540which resolves to a directory named ``formfactor`` in the same directory
541in which the append file resides (i.e.
542``meta-raspberrypi/recipes-bsp/formfactor``. This implies that you must
543have the supporting directory structure set up that will contain any
544files or patches you will be including from the layer.
545
546Using the immediate expansion assignment operator ``:=`` is important
547because of the reference to ``THISDIR``. The trailing colon character is
548important as it ensures that items in the list remain colon-separated.
549
550.. note::
551
552 BitBake automatically defines the ``THISDIR`` variable. You should
553 never set this variable yourself. Using "_prepend" as part of the
554 ``FILESEXTRAPATHS`` ensures your path will be searched prior to other
555 paths in the final list.
556
557 Also, not all append files add extra files. Many append files simply
558 exist to add build options (e.g. ``systemd``). For these cases, your
559 append file would not even use the ``FILESEXTRAPATHS`` statement.
560
561Prioritizing Your Layer
562-----------------------
563
564Each layer is assigned a priority value. Priority values control which
565layer takes precedence if there are recipe files with the same name in
566multiple layers. For these cases, the recipe file from the layer with a
567higher priority number takes precedence. Priority values also affect the
568order in which multiple ``.bbappend`` files for the same recipe are
569applied. You can either specify the priority manually, or allow the
570build system to calculate it based on the layer's dependencies.
571
572To specify the layer's priority manually, use the
573:term:`BBFILE_PRIORITY`
574variable and append the layer's root name:
575::
576
577 BBFILE_PRIORITY_mylayer = "1"
578
579.. note::
580
581 It is possible for a recipe with a lower version number
582 :term:`PV` in a layer that has a higher
583 priority to take precedence.
584
585 Also, the layer priority does not currently affect the precedence
586 order of ``.conf`` or ``.bbclass`` files. Future versions of BitBake
587 might address this.
588
589Managing Layers
590---------------
591
592You can use the BitBake layer management tool ``bitbake-layers`` to
593provide a view into the structure of recipes across a multi-layer
594project. Being able to generate output that reports on configured layers
595with their paths and priorities and on ``.bbappend`` files and their
596applicable recipes can help to reveal potential problems.
597
598For help on the BitBake layer management tool, use the following
599command:
600::
601
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500602 $ bitbake-layers --help
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500603 NOTE: Starting bitbake server...
604 usage: bitbake-layers [-d] [-q] [-F] [--color COLOR] [-h] <subcommand> ...
605
606 BitBake layers utility
607
608 optional arguments:
609 -d, --debug Enable debug output
610 -q, --quiet Print only errors
611 -F, --force Force add without recipe parse verification
612 --color COLOR Colorize output (where COLOR is auto, always, never)
613 -h, --help show this help message and exit
614
615 subcommands:
616 <subcommand>
617 layerindex-fetch Fetches a layer from a layer index along with its
618 dependent layers, and adds them to conf/bblayers.conf.
619 layerindex-show-depends
620 Find layer dependencies from layer index.
621 add-layer Add one or more layers to bblayers.conf.
622 remove-layer Remove one or more layers from bblayers.conf.
623 flatten flatten layer configuration into a separate output
624 directory.
625 show-layers show current configured layers.
626 show-overlayed list overlayed recipes (where the same recipe exists
627 in another layer)
628 show-recipes list available recipes, showing the layer they are
629 provided by
630 show-appends list bbappend files and recipe files they apply to
631 show-cross-depends Show dependencies between recipes that cross layer
632 boundaries.
633 create-layer Create a basic layer
634
635 Use bitbake-layers <subcommand> --help to get help on a specific command
636
637The following list describes the available commands:
638
639- ``help:`` Displays general help or help on a specified command.
640
641- ``show-layers:`` Shows the current configured layers.
642
643- ``show-overlayed:`` Lists overlayed recipes. A recipe is overlayed
644 when a recipe with the same name exists in another layer that has a
645 higher layer priority.
646
647- ``show-recipes:`` Lists available recipes and the layers that
648 provide them.
649
650- ``show-appends:`` Lists ``.bbappend`` files and the recipe files to
651 which they apply.
652
653- ``show-cross-depends:`` Lists dependency relationships between
654 recipes that cross layer boundaries.
655
656- ``add-layer:`` Adds a layer to ``bblayers.conf``.
657
658- ``remove-layer:`` Removes a layer from ``bblayers.conf``
659
660- ``flatten:`` Flattens the layer configuration into a separate
661 output directory. Flattening your layer configuration builds a
662 "flattened" directory that contains the contents of all layers, with
663 any overlayed recipes removed and any ``.bbappend`` files appended to
664 the corresponding recipes. You might have to perform some manual
665 cleanup of the flattened layer as follows:
666
667 - Non-recipe files (such as patches) are overwritten. The flatten
668 command shows a warning for these files.
669
670 - Anything beyond the normal layer setup has been added to the
671 ``layer.conf`` file. Only the lowest priority layer's
672 ``layer.conf`` is used.
673
674 - Overridden and appended items from ``.bbappend`` files need to be
675 cleaned up. The contents of each ``.bbappend`` end up in the
676 flattened recipe. However, if there are appended or changed
677 variable values, you need to tidy these up yourself. Consider the
678 following example. Here, the ``bitbake-layers`` command adds the
679 line ``#### bbappended ...`` so that you know where the following
680 lines originate:
681 ::
682
683 ...
684 DESCRIPTION = "A useful utility"
685 ...
686 EXTRA_OECONF = "--enable-something"
687 ...
688
689 #### bbappended from meta-anotherlayer ####
690
691 DESCRIPTION = "Customized utility"
692 EXTRA_OECONF += "--enable-somethingelse"
693
694
695 Ideally, you would tidy up these utilities as follows:
696 ::
697
698 ...
699 DESCRIPTION = "Customized utility"
700 ...
701 EXTRA_OECONF = "--enable-something --enable-somethingelse"
702 ...
703
704- ``layerindex-fetch``: Fetches a layer from a layer index, along
705 with its dependent layers, and adds the layers to the
706 ``conf/bblayers.conf`` file.
707
708- ``layerindex-show-depends``: Finds layer dependencies from the
709 layer index.
710
711- ``create-layer``: Creates a basic layer.
712
713Creating a General Layer Using the ``bitbake-layers`` Script
714------------------------------------------------------------
715
716The ``bitbake-layers`` script with the ``create-layer`` subcommand
717simplifies creating a new general layer.
718
719.. note::
720
721 - For information on BSP layers, see the ":ref:`bsp-guide/bsp:bsp layers`"
722 section in the Yocto
723 Project Board Specific (BSP) Developer's Guide.
724
725 - In order to use a layer with the OpenEmbedded build system, you
726 need to add the layer to your ``bblayers.conf`` configuration
Andrew Geissler09209ee2020-12-13 08:44:15 -0600727 file. See the ":ref:`dev-manual/common-tasks:adding a layer using the \`\`bitbake-layers\`\` script`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500728 section for more information.
729
730The default mode of the script's operation with this subcommand is to
731create a layer with the following:
732
733- A layer priority of 6.
734
735- A ``conf`` subdirectory that contains a ``layer.conf`` file.
736
737- A ``recipes-example`` subdirectory that contains a further
738 subdirectory named ``example``, which contains an ``example.bb``
739 recipe file.
740
741- A ``COPYING.MIT``, which is the license statement for the layer. The
742 script assumes you want to use the MIT license, which is typical for
743 most layers, for the contents of the layer itself.
744
745- A ``README`` file, which is a file describing the contents of your
746 new layer.
747
748In its simplest form, you can use the following command form to create a
749layer. The command creates a layer whose name corresponds to
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500750"your_layer_name" in the current directory:
751::
752
753 $ bitbake-layers create-layer your_layer_name
754
755As an example, the following command creates a layer named ``meta-scottrif``
756in your home directory:
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500757::
758
759 $ cd /usr/home
760 $ bitbake-layers create-layer meta-scottrif
761 NOTE: Starting bitbake server...
762 Add your new layer with 'bitbake-layers add-layer meta-scottrif'
763
764If you want to set the priority of the layer to other than the default
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500765value of "6", you can either use the ``--priority`` option or you
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500766can edit the
767:term:`BBFILE_PRIORITY` value
768in the ``conf/layer.conf`` after the script creates it. Furthermore, if
769you want to give the example recipe file some name other than the
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500770default, you can use the ``--example-recipe-name`` option.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500771
772The easiest way to see how the ``bitbake-layers create-layer`` command
773works is to experiment with the script. You can also read the usage
774information by entering the following:
775::
776
777 $ bitbake-layers create-layer --help
778 NOTE: Starting bitbake server...
779 usage: bitbake-layers create-layer [-h] [--priority PRIORITY]
780 [--example-recipe-name EXAMPLERECIPE]
781 layerdir
782
783 Create a basic layer
784
785 positional arguments:
786 layerdir Layer directory to create
787
788 optional arguments:
789 -h, --help show this help message and exit
790 --priority PRIORITY, -p PRIORITY
791 Layer directory to create
792 --example-recipe-name EXAMPLERECIPE, -e EXAMPLERECIPE
793 Filename of the example recipe
794
795Adding a Layer Using the ``bitbake-layers`` Script
796--------------------------------------------------
797
798Once you create your general layer, you must add it to your
799``bblayers.conf`` file. Adding the layer to this configuration file
800makes the OpenEmbedded build system aware of your layer so that it can
801search it for metadata.
802
803Add your layer by using the ``bitbake-layers add-layer`` command:
804::
805
806 $ bitbake-layers add-layer your_layer_name
807
808Here is an example that adds a
809layer named ``meta-scottrif`` to the configuration file. Following the
810command that adds the layer is another ``bitbake-layers`` command that
811shows the layers that are in your ``bblayers.conf`` file:
812::
813
814 $ bitbake-layers add-layer meta-scottrif
815 NOTE: Starting bitbake server...
816 Parsing recipes: 100% |##########################################################| Time: 0:00:49
817 Parsing of 1441 .bb files complete (0 cached, 1441 parsed). 2055 targets, 56 skipped, 0 masked, 0 errors.
818 $ bitbake-layers show-layers
819 NOTE: Starting bitbake server...
820 layer path priority
821 ==========================================================================
822 meta /home/scottrif/poky/meta 5
823 meta-poky /home/scottrif/poky/meta-poky 5
824 meta-yocto-bsp /home/scottrif/poky/meta-yocto-bsp 5
825 workspace /home/scottrif/poky/build/workspace 99
826 meta-scottrif /home/scottrif/poky/build/meta-scottrif 6
827
828
829Adding the layer to this file
830enables the build system to locate the layer during the build.
831
832.. note::
833
834 During a build, the OpenEmbedded build system looks in the layers
835 from the top of the list down to the bottom in that order.
836
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500837Customizing Images
838==================
839
840You can customize images to satisfy particular requirements. This
841section describes several methods and provides guidelines for each.
842
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500843Customizing Images Using ``local.conf``
844---------------------------------------
845
846Probably the easiest way to customize an image is to add a package by
847way of the ``local.conf`` configuration file. Because it is limited to
848local use, this method generally only allows you to add packages and is
849not as flexible as creating your own customized image. When you add
850packages using local variables this way, you need to realize that these
851variable changes are in effect for every build and consequently affect
852all images, which might not be what you require.
853
854To add a package to your image using the local configuration file, use
855the ``IMAGE_INSTALL`` variable with the ``_append`` operator:
856::
857
858 IMAGE_INSTALL_append = " strace"
859
860Use of the syntax is important -
861specifically, the space between the quote and the package name, which is
862``strace`` in this example. This space is required since the ``_append``
863operator does not add the space.
864
865Furthermore, you must use ``_append`` instead of the ``+=`` operator if
866you want to avoid ordering issues. The reason for this is because doing
867so unconditionally appends to the variable and avoids ordering problems
868due to the variable being set in image recipes and ``.bbclass`` files
869with operators like ``?=``. Using ``_append`` ensures the operation
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500870takes effect.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500871
872As shown in its simplest use, ``IMAGE_INSTALL_append`` affects all
873images. It is possible to extend the syntax so that the variable applies
874to a specific image only. Here is an example:
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500875::
876
877 IMAGE_INSTALL_append_pn-core-image-minimal = " strace"
878
879This example adds ``strace`` to the ``core-image-minimal`` image only.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500880
881You can add packages using a similar approach through the
882``CORE_IMAGE_EXTRA_INSTALL`` variable. If you use this variable, only
883``core-image-*`` images are affected.
884
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500885Customizing Images Using Custom ``IMAGE_FEATURES`` and ``EXTRA_IMAGE_FEATURES``
886-------------------------------------------------------------------------------
887
888Another method for customizing your image is to enable or disable
889high-level image features by using the
890:term:`IMAGE_FEATURES` and
891:term:`EXTRA_IMAGE_FEATURES`
892variables. Although the functions for both variables are nearly
893equivalent, best practices dictate using ``IMAGE_FEATURES`` from within
894a recipe and using ``EXTRA_IMAGE_FEATURES`` from within your
895``local.conf`` file, which is found in the
896:term:`Build Directory`.
897
898To understand how these features work, the best reference is
899``meta/classes/core-image.bbclass``. This class lists out the available
900``IMAGE_FEATURES`` of which most map to package groups while some, such
901as ``debug-tweaks`` and ``read-only-rootfs``, resolve as general
902configuration settings.
903
904In summary, the file looks at the contents of the ``IMAGE_FEATURES``
905variable and then maps or configures the feature accordingly. Based on
906this information, the build system automatically adds the appropriate
907packages or configurations to the
908:term:`IMAGE_INSTALL` variable.
909Effectively, you are enabling extra features by extending the class or
910creating a custom class for use with specialized image ``.bb`` files.
911
912Use the ``EXTRA_IMAGE_FEATURES`` variable from within your local
913configuration file. Using a separate area from which to enable features
914with this variable helps you avoid overwriting the features in the image
915recipe that are enabled with ``IMAGE_FEATURES``. The value of
916``EXTRA_IMAGE_FEATURES`` is added to ``IMAGE_FEATURES`` within
917``meta/conf/bitbake.conf``.
918
919To illustrate how you can use these variables to modify your image,
920consider an example that selects the SSH server. The Yocto Project ships
921with two SSH servers you can use with your images: Dropbear and OpenSSH.
922Dropbear is a minimal SSH server appropriate for resource-constrained
923environments, while OpenSSH is a well-known standard SSH server
924implementation. By default, the ``core-image-sato`` image is configured
925to use Dropbear. The ``core-image-full-cmdline`` and ``core-image-lsb``
926images both include OpenSSH. The ``core-image-minimal`` image does not
927contain an SSH server.
928
929You can customize your image and change these defaults. Edit the
930``IMAGE_FEATURES`` variable in your recipe or use the
931``EXTRA_IMAGE_FEATURES`` in your ``local.conf`` file so that it
932configures the image you are working with to include
933``ssh-server-dropbear`` or ``ssh-server-openssh``.
934
935.. note::
936
Andrew Geissler09209ee2020-12-13 08:44:15 -0600937 See the ":ref:`ref-manual/features:image features`" section in the Yocto
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500938 Project Reference Manual for a complete list of image features that ship
939 with the Yocto Project.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500940
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500941Customizing Images Using Custom .bb Files
942-----------------------------------------
943
944You can also customize an image by creating a custom recipe that defines
945additional software as part of the image. The following example shows
946the form for the two lines you need:
947::
948
949 IMAGE_INSTALL = "packagegroup-core-x11-base package1 package2"
950 inherit core-image
951
952Defining the software using a custom recipe gives you total control over
953the contents of the image. It is important to use the correct names of
954packages in the ``IMAGE_INSTALL`` variable. You must use the
955OpenEmbedded notation and not the Debian notation for the names (e.g.
956``glibc-dev`` instead of ``libc6-dev``).
957
958The other method for creating a custom image is to base it on an
959existing image. For example, if you want to create an image based on
960``core-image-sato`` but add the additional package ``strace`` to the
961image, copy the ``meta/recipes-sato/images/core-image-sato.bb`` to a new
962``.bb`` and add the following line to the end of the copy:
963::
964
965 IMAGE_INSTALL += "strace"
966
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500967Customizing Images Using Custom Package Groups
968----------------------------------------------
969
970For complex custom images, the best approach for customizing an image is
971to create a custom package group recipe that is used to build the image
972or images. A good example of a package group recipe is
973``meta/recipes-core/packagegroups/packagegroup-base.bb``.
974
975If you examine that recipe, you see that the ``PACKAGES`` variable lists
976the package group packages to produce. The ``inherit packagegroup``
977statement sets appropriate default values and automatically adds
978``-dev``, ``-dbg``, and ``-ptest`` complementary packages for each
979package specified in the ``PACKAGES`` statement.
980
981.. note::
982
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500983 The ``inherit packagegroup`` line should be located near the top of the
984 recipe, certainly before the ``PACKAGES`` statement.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500985
986For each package you specify in ``PACKAGES``, you can use ``RDEPENDS``
987and ``RRECOMMENDS`` entries to provide a list of packages the parent
988task package should contain. You can see examples of these further down
989in the ``packagegroup-base.bb`` recipe.
990
991Here is a short, fabricated example showing the same basic pieces for a
992hypothetical packagegroup defined in ``packagegroup-custom.bb``, where
993the variable ``PN`` is the standard way to abbreviate the reference to
994the full packagegroup name ``packagegroup-custom``:
995::
996
997 DESCRIPTION = "My Custom Package Groups"
998
999 inherit packagegroup
1000
1001 PACKAGES = "\
1002 ${PN}-apps \
1003 ${PN}-tools \
1004 "
1005
1006 RDEPENDS_${PN}-apps = "\
1007 dropbear \
1008 portmap \
1009 psplash"
1010
1011 RDEPENDS_${PN}-tools = "\
1012 oprofile \
1013 oprofileui-server \
1014 lttng-tools"
1015
1016 RRECOMMENDS_${PN}-tools = "\
1017 kernel-module-oprofile"
1018
1019In the previous example, two package group packages are created with
1020their dependencies and their recommended package dependencies listed:
1021``packagegroup-custom-apps``, and ``packagegroup-custom-tools``. To
1022build an image using these package group packages, you need to add
1023``packagegroup-custom-apps`` and/or ``packagegroup-custom-tools`` to
1024``IMAGE_INSTALL``. For other forms of image dependencies see the other
1025areas of this section.
1026
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001027Customizing an Image Hostname
1028-----------------------------
1029
1030By default, the configured hostname (i.e. ``/etc/hostname``) in an image
1031is the same as the machine name. For example, if
1032:term:`MACHINE` equals "qemux86", the
1033configured hostname written to ``/etc/hostname`` is "qemux86".
1034
1035You can customize this name by altering the value of the "hostname"
1036variable in the ``base-files`` recipe using either an append file or a
1037configuration file. Use the following in an append file:
1038::
1039
1040 hostname = "myhostname"
1041
1042Use the following in a configuration file:
1043::
1044
1045 hostname_pn-base-files = "myhostname"
1046
1047Changing the default value of the variable "hostname" can be useful in
1048certain situations. For example, suppose you need to do extensive
1049testing on an image and you would like to easily identify the image
1050under test from existing images with typical default hostnames. In this
1051situation, you could change the default hostname to "testme", which
1052results in all the images using the name "testme". Once testing is
1053complete and you do not need to rebuild the image for test any longer,
1054you can easily reset the default hostname.
1055
1056Another point of interest is that if you unset the variable, the image
1057will have no default hostname in the filesystem. Here is an example that
1058unsets the variable in a configuration file:
1059::
1060
1061 hostname_pn-base-files = ""
1062
1063Having no default hostname in the filesystem is suitable for
1064environments that use dynamic hostnames such as virtual machines.
1065
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001066Writing a New Recipe
1067====================
1068
1069Recipes (``.bb`` files) are fundamental components in the Yocto Project
1070environment. Each software component built by the OpenEmbedded build
1071system requires a recipe to define the component. This section describes
1072how to create, write, and test a new recipe.
1073
1074.. note::
1075
1076 For information on variables that are useful for recipes and for
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001077 information about recipe naming issues, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001078 ":ref:`ref-manual/varlocality:recipes`" section of the Yocto Project
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001079 Reference Manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001080
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001081Overview
1082--------
1083
1084The following figure shows the basic process for creating a new recipe.
1085The remainder of the section provides details for the steps.
1086
1087.. image:: figures/recipe-workflow.png
1088 :align: center
1089
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001090Locate or Automatically Create a Base Recipe
1091--------------------------------------------
1092
1093You can always write a recipe from scratch. However, three choices exist
1094that can help you quickly get a start on a new recipe:
1095
1096- ``devtool add``: A command that assists in creating a recipe and an
1097 environment conducive to development.
1098
1099- ``recipetool create``: A command provided by the Yocto Project that
1100 automates creation of a base recipe based on the source files.
1101
1102- *Existing Recipes:* Location and modification of an existing recipe
1103 that is similar in function to the recipe you need.
1104
1105.. note::
1106
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001107 For information on recipe syntax, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001108 ":ref:`dev-manual/common-tasks:recipe syntax`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001109
1110Creating the Base Recipe Using ``devtool add``
1111~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1112
1113The ``devtool add`` command uses the same logic for auto-creating the
1114recipe as ``recipetool create``, which is listed below. Additionally,
1115however, ``devtool add`` sets up an environment that makes it easy for
1116you to patch the source and to make changes to the recipe as is often
1117necessary when adding a recipe to build a new piece of software to be
1118included in a build.
1119
1120You can find a complete description of the ``devtool add`` command in
Andrew Geissler09209ee2020-12-13 08:44:15 -06001121the ":ref:`sdk-manual/extensible:a closer look at \`\`devtool add\`\``" section
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001122in the Yocto Project Application Development and the Extensible Software
1123Development Kit (eSDK) manual.
1124
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001125Creating the Base Recipe Using ``recipetool create``
1126~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1127
1128``recipetool create`` automates creation of a base recipe given a set of
1129source code files. As long as you can extract or point to the source
1130files, the tool will construct a recipe and automatically configure all
1131pre-build information into the recipe. For example, suppose you have an
1132application that builds using Autotools. Creating the base recipe using
1133``recipetool`` results in a recipe that has the pre-build dependencies,
1134license requirements, and checksums configured.
1135
1136To run the tool, you just need to be in your
1137:term:`Build Directory` and have sourced the
1138build environment setup script (i.e.
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001139:ref:`structure-core-script`).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001140To get help on the tool, use the following command:
1141::
1142
1143 $ recipetool -h
1144 NOTE: Starting bitbake server...
1145 usage: recipetool [-d] [-q] [--color COLOR] [-h] <subcommand> ...
1146
1147 OpenEmbedded recipe tool
1148
1149 options:
1150 -d, --debug Enable debug output
1151 -q, --quiet Print only errors
1152 --color COLOR Colorize output (where COLOR is auto, always, never)
1153 -h, --help show this help message and exit
1154
1155 subcommands:
1156 create Create a new recipe
1157 newappend Create a bbappend for the specified target in the specified
1158 layer
1159 setvar Set a variable within a recipe
1160 appendfile Create/update a bbappend to replace a target file
1161 appendsrcfiles Create/update a bbappend to add or replace source files
1162 appendsrcfile Create/update a bbappend to add or replace a source file
1163 Use recipetool <subcommand> --help to get help on a specific command
1164
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001165Running ``recipetool create -o OUTFILE`` creates the base recipe and
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001166locates it properly in the layer that contains your source files.
1167Following are some syntax examples:
1168
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001169 - Use this syntax to generate a recipe based on source. Once generated,
1170 the recipe resides in the existing source code layer:
1171 ::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001172
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001173 recipetool create -o OUTFILE source
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001174
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001175 - Use this syntax to generate a recipe using code that
1176 you extract from source. The extracted code is placed in its own layer
1177 defined by ``EXTERNALSRC``.
1178 ::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001179
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001180 recipetool create -o OUTFILE -x EXTERNALSRC source
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001181
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001182 - Use this syntax to generate a recipe based on source. The options
1183 direct ``recipetool`` to generate debugging information. Once generated,
1184 the recipe resides in the existing source code layer:
1185 ::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001186
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001187 recipetool create -d -o OUTFILE source
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001188
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001189Locating and Using a Similar Recipe
1190~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1191
1192Before writing a recipe from scratch, it is often useful to discover
1193whether someone else has already written one that meets (or comes close
1194to meeting) your needs. The Yocto Project and OpenEmbedded communities
1195maintain many recipes that might be candidates for what you are doing.
Andrew Geisslerc723b722021-01-08 16:14:09 -06001196You can find a good central index of these recipes in the
1197:oe_layerindex:`OpenEmbedded Layer Index <>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001198
1199Working from an existing recipe or a skeleton recipe is the best way to
1200get started. Here are some points on both methods:
1201
1202- *Locate and modify a recipe that is close to what you want to do:*
1203 This method works when you are familiar with the current recipe
1204 space. The method does not work so well for those new to the Yocto
1205 Project or writing recipes.
1206
1207 Some risks associated with this method are using a recipe that has
1208 areas totally unrelated to what you are trying to accomplish with
1209 your recipe, not recognizing areas of the recipe that you might have
1210 to add from scratch, and so forth. All these risks stem from
1211 unfamiliarity with the existing recipe space.
1212
1213- *Use and modify the following skeleton recipe:* If for some reason
1214 you do not want to use ``recipetool`` and you cannot find an existing
1215 recipe that is close to meeting your needs, you can use the following
1216 structure to provide the fundamental areas of a new recipe.
1217 ::
1218
1219 DESCRIPTION = ""
1220 HOMEPAGE = ""
1221 LICENSE = ""
1222 SECTION = ""
1223 DEPENDS = ""
1224 LIC_FILES_CHKSUM = ""
1225
1226 SRC_URI = ""
1227
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001228Storing and Naming the Recipe
1229-----------------------------
1230
1231Once you have your base recipe, you should put it in your own layer and
1232name it appropriately. Locating it correctly ensures that the
1233OpenEmbedded build system can find it when you use BitBake to process
1234the recipe.
1235
1236- *Storing Your Recipe:* The OpenEmbedded build system locates your
1237 recipe through the layer's ``conf/layer.conf`` file and the
1238 :term:`BBFILES` variable. This
1239 variable sets up a path from which the build system can locate
1240 recipes. Here is the typical use:
1241 ::
1242
1243 BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
1244 ${LAYERDIR}/recipes-*/*/*.bbappend"
1245
1246 Consequently, you need to be sure you locate your new recipe inside
1247 your layer such that it can be found.
1248
1249 You can find more information on how layers are structured in the
1250 "`Understanding and Creating
1251 Layers <#understanding-and-creating-layers>`__" section.
1252
1253- *Naming Your Recipe:* When you name your recipe, you need to follow
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001254 this naming convention:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001255 ::
1256
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001257 basename_version.bb
1258
1259 Use lower-cased characters and do not include the reserved suffixes
1260 ``-native``, ``-cross``, ``-initial``, or ``-dev`` casually (i.e. do not use
1261 them as part of your recipe name unless the string applies). Here are some
1262 examples:
1263
1264 .. code-block:: none
1265
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001266 cups_1.7.0.bb
1267 gawk_4.0.2.bb
1268 irssi_0.8.16-rc1.bb
1269
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001270Running a Build on the Recipe
1271-----------------------------
1272
1273Creating a new recipe is usually an iterative process that requires
1274using BitBake to process the recipe multiple times in order to
1275progressively discover and add information to the recipe file.
1276
1277Assuming you have sourced the build environment setup script (i.e.
1278:ref:`structure-core-script`) and you are in
1279the :term:`Build Directory`, use
1280BitBake to process your recipe. All you need to provide is the
1281``basename`` of the recipe as described in the previous section:
1282::
1283
1284 $ bitbake basename
1285
1286During the build, the OpenEmbedded build system creates a temporary work
1287directory for each recipe
1288(``${``\ :term:`WORKDIR`\ ``}``)
1289where it keeps extracted source files, log files, intermediate
1290compilation and packaging files, and so forth.
1291
1292The path to the per-recipe temporary work directory depends on the
1293context in which it is being built. The quickest way to find this path
1294is to have BitBake return it by running the following:
1295::
1296
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001297 $ bitbake -e basename | grep ^WORKDIR=
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001298
1299As an example, assume a Source Directory
1300top-level folder named ``poky``, a default Build Directory at
1301``poky/build``, and a ``qemux86-poky-linux`` machine target system.
1302Furthermore, suppose your recipe is named ``foo_1.3.0.bb``. In this
1303case, the work directory the build system uses to build the package
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001304would be as follows:
1305::
1306
1307 poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
1308
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001309Inside this directory you can find sub-directories such as ``image``,
1310``packages-split``, and ``temp``. After the build, you can examine these
1311to determine how well the build went.
1312
1313.. note::
1314
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001315 You can find log files for each task in the recipe's ``temp``
1316 directory (e.g. ``poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0/temp``).
1317 Log files are named ``log.taskname`` (e.g. ``log.do_configure``,
1318 ``log.do_fetch``, and ``log.do_compile``).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001319
1320You can find more information about the build process in
Andrew Geissler09209ee2020-12-13 08:44:15 -06001321":doc:`/overview-manual/development-environment`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001322chapter of the Yocto Project Overview and Concepts Manual.
1323
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001324Fetching Code
1325-------------
1326
1327The first thing your recipe must do is specify how to fetch the source
1328files. Fetching is controlled mainly through the
1329:term:`SRC_URI` variable. Your recipe
1330must have a ``SRC_URI`` variable that points to where the source is
1331located. For a graphical representation of source locations, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001332":ref:`overview-manual/concepts:sources`" section in
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001333the Yocto Project Overview and Concepts Manual.
1334
1335The :ref:`ref-tasks-fetch` task uses
1336the prefix of each entry in the ``SRC_URI`` variable value to determine
Andrew Geissler09209ee2020-12-13 08:44:15 -06001337which :ref:`fetcher <bitbake:bitbake-user-manual/bitbake-user-manual-fetching:fetchers>` to use to get your
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001338source files. It is the ``SRC_URI`` variable that triggers the fetcher.
1339The :ref:`ref-tasks-patch` task uses
1340the variable after source is fetched to apply patches. The OpenEmbedded
1341build system uses
1342:term:`FILESOVERRIDES` for
1343scanning directory locations for local files in ``SRC_URI``.
1344
1345The ``SRC_URI`` variable in your recipe must define each unique location
1346for your source files. It is good practice to not hard-code version
1347numbers in a URL used in ``SRC_URI``. Rather than hard-code these
1348values, use ``${``\ :term:`PV`\ ``}``,
1349which causes the fetch process to use the version specified in the
1350recipe filename. Specifying the version in this manner means that
1351upgrading the recipe to a future version is as simple as renaming the
1352recipe to match the new version.
1353
1354Here is a simple example from the
1355``meta/recipes-devtools/strace/strace_5.5.bb`` recipe where the source
1356comes from a single tarball. Notice the use of the
1357:term:`PV` variable:
1358::
1359
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001360 SRC_URI = "https://strace.io/files/${PV}/strace-${PV}.tar.xz \
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001361
1362Files mentioned in ``SRC_URI`` whose names end in a typical archive
1363extension (e.g. ``.tar``, ``.tar.gz``, ``.tar.bz2``, ``.zip``, and so
1364forth), are automatically extracted during the
1365:ref:`ref-tasks-unpack` task. For
1366another example that specifies these types of files, see the
1367"`Autotooled Package <#new-recipe-autotooled-package>`__" section.
1368
1369Another way of specifying source is from an SCM. For Git repositories,
1370you must specify :term:`SRCREV` and
1371you should specify :term:`PV` to include
1372the revision with :term:`SRCPV`. Here
1373is an example from the recipe
1374``meta/recipes-kernel/blktrace/blktrace_git.bb``:
1375::
1376
1377 SRCREV = "d6918c8832793b4205ed3bfede78c2f915c23385"
1378
1379 PR = "r6"
1380 PV = "1.0.5+git${SRCPV}"
1381
1382 SRC_URI = "git://git.kernel.dk/blktrace.git \
1383 file://ldflags.patch"
1384
1385If your ``SRC_URI`` statement includes URLs pointing to individual files
1386fetched from a remote server other than a version control system,
1387BitBake attempts to verify the files against checksums defined in your
1388recipe to ensure they have not been tampered with or otherwise modified
1389since the recipe was written. Two checksums are used:
1390``SRC_URI[md5sum]`` and ``SRC_URI[sha256sum]``.
1391
1392If your ``SRC_URI`` variable points to more than a single URL (excluding
1393SCM URLs), you need to provide the ``md5`` and ``sha256`` checksums for
1394each URL. For these cases, you provide a name for each URL as part of
1395the ``SRC_URI`` and then reference that name in the subsequent checksum
1396statements. Here is an example combining lines from the files
1397``git.inc`` and ``git_2.24.1.bb``:
1398::
1399
1400 SRC_URI = "${KERNELORG_MIRROR}/software/scm/git/git-${PV}.tar.gz;name=tarball \
1401 ${KERNELORG_MIRROR}/software/scm/git/git-manpages-${PV}.tar.gz;name=manpages"
1402
1403 SRC_URI[tarball.md5sum] = "166bde96adbbc11c8843d4f8f4f9811b"
1404 SRC_URI[tarball.sha256sum] = "ad5334956301c86841eb1e5b1bb20884a6bad89a10a6762c958220c7cf64da02"
1405 SRC_URI[manpages.md5sum] = "31c2272a8979022497ba3d4202df145d"
1406 SRC_URI[manpages.sha256sum] = "9a7ae3a093bea39770eb96ca3e5b40bff7af0b9f6123f089d7821d0e5b8e1230"
1407
1408Proper values for ``md5`` and ``sha256`` checksums might be available
1409with other signatures on the download page for the upstream source (e.g.
1410``md5``, ``sha1``, ``sha256``, ``GPG``, and so forth). Because the
1411OpenEmbedded build system only deals with ``sha256sum`` and ``md5sum``,
1412you should verify all the signatures you find by hand.
1413
1414If no ``SRC_URI`` checksums are specified when you attempt to build the
1415recipe, or you provide an incorrect checksum, the build will produce an
1416error for each missing or incorrect checksum. As part of the error
1417message, the build system provides the checksum string corresponding to
1418the fetched file. Once you have the correct checksums, you can copy and
1419paste them into your recipe and then run the build again to continue.
1420
1421.. note::
1422
1423 As mentioned, if the upstream source provides signatures for
1424 verifying the downloaded source code, you should verify those
1425 manually before setting the checksum values in the recipe and
1426 continuing with the build.
1427
1428This final example is a bit more complicated and is from the
1429``meta/recipes-sato/rxvt-unicode/rxvt-unicode_9.20.bb`` recipe. The
1430example's ``SRC_URI`` statement identifies multiple files as the source
1431files for the recipe: a tarball, a patch file, a desktop file, and an
1432icon.
1433::
1434
1435 SRC_URI = "http://dist.schmorp.de/rxvt-unicode/Attic/rxvt-unicode-${PV}.tar.bz2 \
1436 file://xwc.patch \
1437 file://rxvt.desktop \
1438 file://rxvt.png"
1439
1440When you specify local files using the ``file://`` URI protocol, the
1441build system fetches files from the local machine. The path is relative
1442to the :term:`FILESPATH` variable
1443and searches specific directories in a certain order:
1444``${``\ :term:`BP`\ ``}``,
1445``${``\ :term:`BPN`\ ``}``, and
1446``files``. The directories are assumed to be subdirectories of the
1447directory in which the recipe or append file resides. For another
1448example that specifies these types of files, see the "`Single .c File
1449Package (Hello
1450World!) <#new-recipe-single-c-file-package-hello-world>`__" section.
1451
1452The previous example also specifies a patch file. Patch files are files
1453whose names usually end in ``.patch`` or ``.diff`` but can end with
1454compressed suffixes such as ``diff.gz`` and ``patch.bz2``, for example.
1455The build system automatically applies patches as described in the
1456"`Patching Code <#new-recipe-patching-code>`__" section.
1457
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001458Unpacking Code
1459--------------
1460
1461During the build, the
1462:ref:`ref-tasks-unpack` task unpacks
1463the source with ``${``\ :term:`S`\ ``}``
1464pointing to where it is unpacked.
1465
1466If you are fetching your source files from an upstream source archived
1467tarball and the tarball's internal structure matches the common
1468convention of a top-level subdirectory named
1469``${``\ :term:`BPN`\ ``}-${``\ :term:`PV`\ ``}``,
1470then you do not need to set ``S``. However, if ``SRC_URI`` specifies to
1471fetch source from an archive that does not use this convention, or from
1472an SCM like Git or Subversion, your recipe needs to define ``S``.
1473
1474If processing your recipe using BitBake successfully unpacks the source
1475files, you need to be sure that the directory pointed to by ``${S}``
1476matches the structure of the source.
1477
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001478Patching Code
1479-------------
1480
1481Sometimes it is necessary to patch code after it has been fetched. Any
1482files mentioned in ``SRC_URI`` whose names end in ``.patch`` or
1483``.diff`` or compressed versions of these suffixes (e.g. ``diff.gz`` are
1484treated as patches. The
1485:ref:`ref-tasks-patch` task
1486automatically applies these patches.
1487
1488The build system should be able to apply patches with the "-p1" option
1489(i.e. one directory level in the path will be stripped off). If your
1490patch needs to have more directory levels stripped off, specify the
1491number of levels using the "striplevel" option in the ``SRC_URI`` entry
1492for the patch. Alternatively, if your patch needs to be applied in a
1493specific subdirectory that is not specified in the patch file, use the
1494"patchdir" option in the entry.
1495
1496As with all local files referenced in
1497:term:`SRC_URI` using ``file://``,
1498you should place patch files in a directory next to the recipe either
1499named the same as the base name of the recipe
1500(:term:`BP` and
1501:term:`BPN`) or "files".
1502
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001503Licensing
1504---------
1505
1506Your recipe needs to have both the
1507:term:`LICENSE` and
1508:term:`LIC_FILES_CHKSUM`
1509variables:
1510
1511- ``LICENSE``: This variable specifies the license for the software.
1512 If you do not know the license under which the software you are
1513 building is distributed, you should go to the source code and look
1514 for that information. Typical files containing this information
1515 include ``COPYING``, ``LICENSE``, and ``README`` files. You could
1516 also find the information near the top of a source file. For example,
1517 given a piece of software licensed under the GNU General Public
1518 License version 2, you would set ``LICENSE`` as follows:
1519 ::
1520
1521 LICENSE = "GPLv2"
1522
1523 The licenses you specify within ``LICENSE`` can have any name as long
1524 as you do not use spaces, since spaces are used as separators between
1525 license names. For standard licenses, use the names of the files in
1526 ``meta/files/common-licenses/`` or the ``SPDXLICENSEMAP`` flag names
1527 defined in ``meta/conf/licenses.conf``.
1528
1529- ``LIC_FILES_CHKSUM``: The OpenEmbedded build system uses this
1530 variable to make sure the license text has not changed. If it has,
1531 the build produces an error and it affords you the chance to figure
1532 it out and correct the problem.
1533
1534 You need to specify all applicable licensing files for the software.
1535 At the end of the configuration step, the build process will compare
1536 the checksums of the files to be sure the text has not changed. Any
1537 differences result in an error with the message containing the
1538 current checksum. For more explanation and examples of how to set the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001539 ``LIC_FILES_CHKSUM`` variable, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001540 ":ref:`dev-manual/common-tasks:tracking license changes`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001541
1542 To determine the correct checksum string, you can list the
1543 appropriate files in the ``LIC_FILES_CHKSUM`` variable with incorrect
1544 md5 strings, attempt to build the software, and then note the
1545 resulting error messages that will report the correct md5 strings.
1546 See the "`Fetching Code <#new-recipe-fetching-code>`__" section for
1547 additional information.
1548
1549 Here is an example that assumes the software has a ``COPYING`` file:
1550 ::
1551
1552 LIC_FILES_CHKSUM = "file://COPYING;md5=xxx"
1553
1554 When you try to build the
1555 software, the build system will produce an error and give you the
1556 correct string that you can substitute into the recipe file for a
1557 subsequent build.
1558
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001559Dependencies
1560------------
1561
1562Most software packages have a short list of other packages that they
1563require, which are called dependencies. These dependencies fall into two
1564main categories: build-time dependencies, which are required when the
1565software is built; and runtime dependencies, which are required to be
1566installed on the target in order for the software to run.
1567
1568Within a recipe, you specify build-time dependencies using the
1569:term:`DEPENDS` variable. Although
1570nuances exist, items specified in ``DEPENDS`` should be names of other
1571recipes. It is important that you specify all build-time dependencies
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001572explicitly.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001573
1574Another consideration is that configure scripts might automatically
1575check for optional dependencies and enable corresponding functionality
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001576if those dependencies are found. If you wish to make a recipe that is
1577more generally useful (e.g. publish the recipe in a layer for others to
1578use), instead of hard-disabling the functionality, you can use the
1579:term:`PACKAGECONFIG` variable to allow functionality and the
1580corresponding dependencies to be enabled and disabled easily by other
1581users of the recipe.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001582
1583Similar to build-time dependencies, you specify runtime dependencies
1584through a variable -
1585:term:`RDEPENDS`, which is
1586package-specific. All variables that are package-specific need to have
1587the name of the package added to the end as an override. Since the main
1588package for a recipe has the same name as the recipe, and the recipe's
1589name can be found through the
1590``${``\ :term:`PN`\ ``}`` variable, then
1591you specify the dependencies for the main package by setting
1592``RDEPENDS_${PN}``. If the package were named ``${PN}-tools``, then you
1593would set ``RDEPENDS_${PN}-tools``, and so forth.
1594
1595Some runtime dependencies will be set automatically at packaging time.
1596These dependencies include any shared library dependencies (i.e. if a
1597package "example" contains "libexample" and another package "mypackage"
1598contains a binary that links to "libexample" then the OpenEmbedded build
1599system will automatically add a runtime dependency to "mypackage" on
1600"example"). See the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001601":ref:`overview-manual/concepts:automatically added runtime dependencies`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001602section in the Yocto Project Overview and Concepts Manual for further
1603details.
1604
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001605Configuring the Recipe
1606----------------------
1607
1608Most software provides some means of setting build-time configuration
1609options before compilation. Typically, setting these options is
1610accomplished by running a configure script with options, or by modifying
1611a build configuration file.
1612
1613.. note::
1614
1615 As of Yocto Project Release 1.7, some of the core recipes that
1616 package binary configuration scripts now disable the scripts due to
1617 the scripts previously requiring error-prone path substitution. The
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001618 OpenEmbedded build system uses ``pkg-config`` now, which is much more
1619 robust. You can find a list of the ``*-config`` scripts that are disabled
1620 in the ":ref:`migration-1.7-binary-configuration-scripts-disabled`" section
1621 in the Yocto Project Reference Manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001622
1623A major part of build-time configuration is about checking for
1624build-time dependencies and possibly enabling optional functionality as
1625a result. You need to specify any build-time dependencies for the
1626software you are building in your recipe's
1627:term:`DEPENDS` value, in terms of
1628other recipes that satisfy those dependencies. You can often find
1629build-time or runtime dependencies described in the software's
1630documentation.
1631
1632The following list provides configuration items of note based on how
1633your software is built:
1634
1635- *Autotools:* If your source files have a ``configure.ac`` file, then
1636 your software is built using Autotools. If this is the case, you just
1637 need to worry about modifying the configuration.
1638
1639 When using Autotools, your recipe needs to inherit the
1640 :ref:`autotools <ref-classes-autotools>` class
1641 and your recipe does not have to contain a
1642 :ref:`ref-tasks-configure` task.
1643 However, you might still want to make some adjustments. For example,
1644 you can set
1645 :term:`EXTRA_OECONF` or
1646 :term:`PACKAGECONFIG_CONFARGS`
1647 to pass any needed configure options that are specific to the recipe.
1648
1649- *CMake:* If your source files have a ``CMakeLists.txt`` file, then
1650 your software is built using CMake. If this is the case, you just
1651 need to worry about modifying the configuration.
1652
1653 When you use CMake, your recipe needs to inherit the
1654 :ref:`cmake <ref-classes-cmake>` class and your
1655 recipe does not have to contain a
1656 :ref:`ref-tasks-configure` task.
1657 You can make some adjustments by setting
1658 :term:`EXTRA_OECMAKE` to
1659 pass any needed configure options that are specific to the recipe.
1660
1661 .. note::
1662
1663 If you need to install one or more custom CMake toolchain files
1664 that are supplied by the application you are building, install the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001665 files to ``${D}${datadir}/cmake/Modules`` during ``do_install``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001666
1667- *Other:* If your source files do not have a ``configure.ac`` or
1668 ``CMakeLists.txt`` file, then your software is built using some
1669 method other than Autotools or CMake. If this is the case, you
1670 normally need to provide a
1671 :ref:`ref-tasks-configure` task
1672 in your recipe unless, of course, there is nothing to configure.
1673
1674 Even if your software is not being built by Autotools or CMake, you
1675 still might not need to deal with any configuration issues. You need
1676 to determine if configuration is even a required step. You might need
1677 to modify a Makefile or some configuration file used for the build to
1678 specify necessary build options. Or, perhaps you might need to run a
1679 provided, custom configure script with the appropriate options.
1680
1681 For the case involving a custom configure script, you would run
1682 ``./configure --help`` and look for the options you need to set.
1683
1684Once configuration succeeds, it is always good practice to look at the
1685``log.do_configure`` file to ensure that the appropriate options have
1686been enabled and no additional build-time dependencies need to be added
1687to ``DEPENDS``. For example, if the configure script reports that it
1688found something not mentioned in ``DEPENDS``, or that it did not find
1689something that it needed for some desired optional functionality, then
1690you would need to add those to ``DEPENDS``. Looking at the log might
1691also reveal items being checked for, enabled, or both that you do not
1692want, or items not being found that are in ``DEPENDS``, in which case
1693you would need to look at passing extra options to the configure script
1694as needed. For reference information on configure options specific to
1695the software you are building, you can consult the output of the
1696``./configure --help`` command within ``${S}`` or consult the software's
1697upstream documentation.
1698
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001699Using Headers to Interface with Devices
1700---------------------------------------
1701
1702If your recipe builds an application that needs to communicate with some
1703device or needs an API into a custom kernel, you will need to provide
1704appropriate header files. Under no circumstances should you ever modify
1705the existing
1706``meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc`` file.
1707These headers are used to build ``libc`` and must not be compromised
1708with custom or machine-specific header information. If you customize
1709``libc`` through modified headers all other applications that use
1710``libc`` thus become affected.
1711
1712.. note::
1713
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001714 Never copy and customize the ``libc`` header file (i.e.
1715 ``meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc``).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001716
1717The correct way to interface to a device or custom kernel is to use a
1718separate package that provides the additional headers for the driver or
1719other unique interfaces. When doing so, your application also becomes
1720responsible for creating a dependency on that specific provider.
1721
1722Consider the following:
1723
1724- Never modify ``linux-libc-headers.inc``. Consider that file to be
1725 part of the ``libc`` system, and not something you use to access the
1726 kernel directly. You should access ``libc`` through specific ``libc``
1727 calls.
1728
1729- Applications that must talk directly to devices should either provide
1730 necessary headers themselves, or establish a dependency on a special
1731 headers package that is specific to that driver.
1732
1733For example, suppose you want to modify an existing header that adds I/O
1734control or network support. If the modifications are used by a small
1735number programs, providing a unique version of a header is easy and has
1736little impact. When doing so, bear in mind the guidelines in the
1737previous list.
1738
1739.. note::
1740
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001741 If for some reason your changes need to modify the behavior of the ``libc``,
1742 and subsequently all other applications on the system, use a ``.bbappend``
1743 to modify the ``linux-kernel-headers.inc`` file. However, take care to not
1744 make the changes machine specific.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001745
1746Consider a case where your kernel is older and you need an older
1747``libc`` ABI. The headers installed by your recipe should still be a
1748standard mainline kernel, not your own custom one.
1749
1750When you use custom kernel headers you need to get them from
1751:term:`STAGING_KERNEL_DIR`,
1752which is the directory with kernel headers that are required to build
1753out-of-tree modules. Your recipe will also need the following:
1754::
1755
1756 do_configure[depends] += "virtual/kernel:do_shared_workdir"
1757
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001758Compilation
1759-----------
1760
1761During a build, the ``do_compile`` task happens after source is fetched,
1762unpacked, and configured. If the recipe passes through ``do_compile``
1763successfully, nothing needs to be done.
1764
1765However, if the compile step fails, you need to diagnose the failure.
1766Here are some common issues that cause failures.
1767
1768.. note::
1769
1770 For cases where improper paths are detected for configuration files
1771 or for when libraries/headers cannot be found, be sure you are using
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001772 the more robust ``pkg-config``. See the note in section
Andrew Geissler09209ee2020-12-13 08:44:15 -06001773 ":ref:`dev-manual/common-tasks:Configuring the Recipe`" for additional information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001774
1775- *Parallel build failures:* These failures manifest themselves as
1776 intermittent errors, or errors reporting that a file or directory
1777 that should be created by some other part of the build process could
1778 not be found. This type of failure can occur even if, upon
1779 inspection, the file or directory does exist after the build has
1780 failed, because that part of the build process happened in the wrong
1781 order.
1782
1783 To fix the problem, you need to either satisfy the missing dependency
1784 in the Makefile or whatever script produced the Makefile, or (as a
1785 workaround) set :term:`PARALLEL_MAKE` to an empty string:
1786 ::
1787
1788 PARALLEL_MAKE = ""
1789
1790 For information on parallel Makefile issues, see the "`Debugging
1791 Parallel Make Races <#debugging-parallel-make-races>`__" section.
1792
1793- *Improper host path usage:* This failure applies to recipes building
1794 for the target or ``nativesdk`` only. The failure occurs when the
1795 compilation process uses improper headers, libraries, or other files
1796 from the host system when cross-compiling for the target.
1797
1798 To fix the problem, examine the ``log.do_compile`` file to identify
1799 the host paths being used (e.g. ``/usr/include``, ``/usr/lib``, and
1800 so forth) and then either add configure options, apply a patch, or do
1801 both.
1802
1803- *Failure to find required libraries/headers:* If a build-time
1804 dependency is missing because it has not been declared in
1805 :term:`DEPENDS`, or because the
1806 dependency exists but the path used by the build process to find the
1807 file is incorrect and the configure step did not detect it, the
1808 compilation process could fail. For either of these failures, the
1809 compilation process notes that files could not be found. In these
1810 cases, you need to go back and add additional options to the
1811 configure script as well as possibly add additional build-time
1812 dependencies to ``DEPENDS``.
1813
1814 Occasionally, it is necessary to apply a patch to the source to
1815 ensure the correct paths are used. If you need to specify paths to
1816 find files staged into the sysroot from other recipes, use the
1817 variables that the OpenEmbedded build system provides (e.g.
1818 ``STAGING_BINDIR``, ``STAGING_INCDIR``, ``STAGING_DATADIR``, and so
1819 forth).
1820
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001821Installing
1822----------
1823
1824During ``do_install``, the task copies the built files along with their
1825hierarchy to locations that would mirror their locations on the target
1826device. The installation process copies files from the
1827``${``\ :term:`S`\ ``}``,
1828``${``\ :term:`B`\ ``}``, and
1829``${``\ :term:`WORKDIR`\ ``}``
1830directories to the ``${``\ :term:`D`\ ``}``
1831directory to create the structure as it should appear on the target
1832system.
1833
1834How your software is built affects what you must do to be sure your
1835software is installed correctly. The following list describes what you
1836must do for installation depending on the type of build system used by
1837the software being built:
1838
1839- *Autotools and CMake:* If the software your recipe is building uses
1840 Autotools or CMake, the OpenEmbedded build system understands how to
1841 install the software. Consequently, you do not have to have a
1842 ``do_install`` task as part of your recipe. You just need to make
1843 sure the install portion of the build completes with no issues.
1844 However, if you wish to install additional files not already being
1845 installed by ``make install``, you should do this using a
1846 ``do_install_append`` function using the install command as described
1847 in the "Manual" bulleted item later in this list.
1848
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001849- *Other (using* ``make install``\ *)*: You need to define a ``do_install``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001850 function in your recipe. The function should call
1851 ``oe_runmake install`` and will likely need to pass in the
1852 destination directory as well. How you pass that path is dependent on
1853 how the ``Makefile`` being run is written (e.g. ``DESTDIR=${D}``,
1854 ``PREFIX=${D}``, ``INSTALLROOT=${D}``, and so forth).
1855
1856 For an example recipe using ``make install``, see the
1857 "`Makefile-Based Package <#new-recipe-makefile-based-package>`__"
1858 section.
1859
1860- *Manual:* You need to define a ``do_install`` function in your
1861 recipe. The function must first use ``install -d`` to create the
1862 directories under
1863 ``${``\ :term:`D`\ ``}``. Once the
1864 directories exist, your function can use ``install`` to manually
1865 install the built software into the directories.
1866
1867 You can find more information on ``install`` at
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001868 https://www.gnu.org/software/coreutils/manual/html_node/install-invocation.html.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001869
1870For the scenarios that do not use Autotools or CMake, you need to track
1871the installation and diagnose and fix any issues until everything
1872installs correctly. You need to look in the default location of
1873``${D}``, which is ``${WORKDIR}/image``, to be sure your files have been
1874installed correctly.
1875
1876.. note::
1877
1878 - During the installation process, you might need to modify some of
1879 the installed files to suit the target layout. For example, you
1880 might need to replace hard-coded paths in an initscript with
1881 values of variables provided by the build system, such as
1882 replacing ``/usr/bin/`` with ``${bindir}``. If you do perform such
1883 modifications during ``do_install``, be sure to modify the
1884 destination file after copying rather than before copying.
1885 Modifying after copying ensures that the build system can
1886 re-execute ``do_install`` if needed.
1887
1888 - ``oe_runmake install``, which can be run directly or can be run
1889 indirectly by the
1890 :ref:`autotools <ref-classes-autotools>` and
1891 :ref:`cmake <ref-classes-cmake>` classes,
1892 runs ``make install`` in parallel. Sometimes, a Makefile can have
1893 missing dependencies between targets that can result in race
1894 conditions. If you experience intermittent failures during
1895 ``do_install``, you might be able to work around them by disabling
1896 parallel Makefile installs by adding the following to the recipe:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001897 ::
1898
1899 PARALLEL_MAKEINST = ""
1900
1901 See :term:`PARALLEL_MAKEINST` for additional information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001902
1903 - If you need to install one or more custom CMake toolchain files
1904 that are supplied by the application you are building, install the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001905 files to ``${D}${datadir}/cmake/Modules`` during
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001906 :ref:`ref-tasks-install`.
1907
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001908Enabling System Services
1909------------------------
1910
1911If you want to install a service, which is a process that usually starts
1912on boot and runs in the background, then you must include some
1913additional definitions in your recipe.
1914
1915If you are adding services and the service initialization script or the
1916service file itself is not installed, you must provide for that
1917installation in your recipe using a ``do_install_append`` function. If
1918your recipe already has a ``do_install`` function, update the function
1919near its end rather than adding an additional ``do_install_append``
1920function.
1921
1922When you create the installation for your services, you need to
1923accomplish what is normally done by ``make install``. In other words,
1924make sure your installation arranges the output similar to how it is
1925arranged on the target system.
1926
1927The OpenEmbedded build system provides support for starting services two
1928different ways:
1929
1930- *SysVinit:* SysVinit is a system and service manager that manages the
1931 init system used to control the very basic functions of your system.
1932 The init program is the first program started by the Linux kernel
1933 when the system boots. Init then controls the startup, running and
1934 shutdown of all other programs.
1935
1936 To enable a service using SysVinit, your recipe needs to inherit the
1937 :ref:`update-rc.d <ref-classes-update-rc.d>`
1938 class. The class helps facilitate safely installing the package on
1939 the target.
1940
1941 You will need to set the
1942 :term:`INITSCRIPT_PACKAGES`,
1943 :term:`INITSCRIPT_NAME`,
1944 and
1945 :term:`INITSCRIPT_PARAMS`
1946 variables within your recipe.
1947
1948- *systemd:* System Management Daemon (systemd) was designed to replace
1949 SysVinit and to provide enhanced management of services. For more
1950 information on systemd, see the systemd homepage at
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001951 https://freedesktop.org/wiki/Software/systemd/.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001952
1953 To enable a service using systemd, your recipe needs to inherit the
1954 :ref:`systemd <ref-classes-systemd>` class. See
1955 the ``systemd.bbclass`` file located in your :term:`Source Directory`
1956 section for
1957 more information.
1958
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001959Packaging
1960---------
1961
1962Successful packaging is a combination of automated processes performed
1963by the OpenEmbedded build system and some specific steps you need to
1964take. The following list describes the process:
1965
1966- *Splitting Files*: The ``do_package`` task splits the files produced
1967 by the recipe into logical components. Even software that produces a
1968 single binary might still have debug symbols, documentation, and
1969 other logical components that should be split out. The ``do_package``
1970 task ensures that files are split up and packaged correctly.
1971
1972- *Running QA Checks*: The
1973 :ref:`insane <ref-classes-insane>` class adds a
1974 step to the package generation process so that output quality
1975 assurance checks are generated by the OpenEmbedded build system. This
1976 step performs a range of checks to be sure the build's output is free
1977 of common problems that show up during runtime. For information on
1978 these checks, see the
1979 :ref:`insane <ref-classes-insane>` class and
Andrew Geissler09209ee2020-12-13 08:44:15 -06001980 the ":ref:`ref-manual/qa-checks:qa error and warning messages`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001981 chapter in the Yocto Project Reference Manual.
1982
1983- *Hand-Checking Your Packages*: After you build your software, you
1984 need to be sure your packages are correct. Examine the
1985 ``${``\ :term:`WORKDIR`\ ``}/packages-split``
1986 directory and make sure files are where you expect them to be. If you
1987 discover problems, you can set
1988 :term:`PACKAGES`,
1989 :term:`FILES`,
1990 ``do_install(_append)``, and so forth as needed.
1991
1992- *Splitting an Application into Multiple Packages*: If you need to
1993 split an application into several packages, see the "`Splitting an
1994 Application into Multiple
1995 Packages <#splitting-an-application-into-multiple-packages>`__"
1996 section for an example.
1997
1998- *Installing a Post-Installation Script*: For an example showing how
1999 to install a post-installation script, see the "`Post-Installation
2000 Scripts <#new-recipe-post-installation-scripts>`__" section.
2001
2002- *Marking Package Architecture*: Depending on what your recipe is
2003 building and how it is configured, it might be important to mark the
2004 packages produced as being specific to a particular machine, or to
2005 mark them as not being specific to a particular machine or
2006 architecture at all.
2007
2008 By default, packages apply to any machine with the same architecture
2009 as the target machine. When a recipe produces packages that are
2010 machine-specific (e.g. the
2011 :term:`MACHINE` value is passed
2012 into the configure script or a patch is applied only for a particular
2013 machine), you should mark them as such by adding the following to the
2014 recipe:
2015 ::
2016
2017 PACKAGE_ARCH = "${MACHINE_ARCH}"
2018
2019 On the other hand, if the recipe produces packages that do not
2020 contain anything specific to the target machine or architecture at
2021 all (e.g. recipes that simply package script files or configuration
2022 files), you should use the
2023 :ref:`allarch <ref-classes-allarch>` class to
2024 do this for you by adding this to your recipe:
2025 ::
2026
2027 inherit allarch
2028
2029 Ensuring that the package architecture is correct is not critical
2030 while you are doing the first few builds of your recipe. However, it
2031 is important in order to ensure that your recipe rebuilds (or does
2032 not rebuild) appropriately in response to changes in configuration,
2033 and to ensure that you get the appropriate packages installed on the
2034 target machine, particularly if you run separate builds for more than
2035 one target machine.
2036
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002037Sharing Files Between Recipes
2038-----------------------------
2039
2040Recipes often need to use files provided by other recipes on the build
2041host. For example, an application linking to a common library needs
2042access to the library itself and its associated headers. The way this
2043access is accomplished is by populating a sysroot with files. Each
2044recipe has two sysroots in its work directory, one for target files
2045(``recipe-sysroot``) and one for files that are native to the build host
2046(``recipe-sysroot-native``).
2047
2048.. note::
2049
2050 You could find the term "staging" used within the Yocto project
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002051 regarding files populating sysroots (e.g. the :term:`STAGING_DIR`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002052 variable).
2053
2054Recipes should never populate the sysroot directly (i.e. write files
2055into sysroot). Instead, files should be installed into standard
2056locations during the
2057:ref:`ref-tasks-install` task within
2058the ``${``\ :term:`D`\ ``}`` directory. The
2059reason for this limitation is that almost all files that populate the
2060sysroot are cataloged in manifests in order to ensure the files can be
2061removed later when a recipe is either modified or removed. Thus, the
2062sysroot is able to remain free from stale files.
2063
2064A subset of the files installed by the
2065:ref:`ref-tasks-install` task are
2066used by the
2067:ref:`ref-tasks-populate_sysroot`
2068task as defined by the the
2069:term:`SYSROOT_DIRS` variable to
2070automatically populate the sysroot. It is possible to modify the list of
2071directories that populate the sysroot. The following example shows how
2072you could add the ``/opt`` directory to the list of directories within a
2073recipe:
2074::
2075
2076 SYSROOT_DIRS += "/opt"
2077
2078For a more complete description of the
2079:ref:`ref-tasks-populate_sysroot`
2080task and its associated functions, see the
2081:ref:`staging <ref-classes-staging>` class.
2082
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002083Using Virtual Providers
2084-----------------------
2085
2086Prior to a build, if you know that several different recipes provide the
2087same functionality, you can use a virtual provider (i.e. ``virtual/*``)
2088as a placeholder for the actual provider. The actual provider is
2089determined at build-time.
2090
2091A common scenario where a virtual provider is used would be for the
2092kernel recipe. Suppose you have three kernel recipes whose
2093:term:`PN` values map to ``kernel-big``,
2094``kernel-mid``, and ``kernel-small``. Furthermore, each of these recipes
2095in some way uses a :term:`PROVIDES`
2096statement that essentially identifies itself as being able to provide
2097``virtual/kernel``. Here is one way through the
2098:ref:`kernel <ref-classes-kernel>` class:
2099::
2100
2101 PROVIDES += "${@ "virtual/kernel" if (d.getVar("KERNEL_PACKAGE_NAME") == "kernel") else "" }"
2102
2103Any recipe that inherits the ``kernel`` class is
2104going to utilize a ``PROVIDES`` statement that identifies that recipe as
2105being able to provide the ``virtual/kernel`` item.
2106
2107Now comes the time to actually build an image and you need a kernel
2108recipe, but which one? You can configure your build to call out the
Andrew Geissler09209ee2020-12-13 08:44:15 -06002109kernel recipe you want by using the :term:`PREFERRED_PROVIDER` variable. As
2110an example, consider the :yocto_git:`x86-base.inc
2111</poky/tree/meta/conf/machine/include/x86-base.inc>` include file, which is a
2112machine (i.e. :term:`MACHINE`) configuration file. This include file is the
2113reason all x86-based machines use the ``linux-yocto`` kernel. Here are the
2114relevant lines from the include file:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002115::
2116
2117 PREFERRED_PROVIDER_virtual/kernel ??= "linux-yocto"
2118 PREFERRED_VERSION_linux-yocto ??= "4.15%"
2119
2120When you use a virtual provider, you do not have to "hard code" a recipe
2121name as a build dependency. You can use the
2122:term:`DEPENDS` variable to state the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002123build is dependent on ``virtual/kernel`` for example:
2124::
2125
2126 DEPENDS = "virtual/kernel"
2127
2128During the build, the OpenEmbedded build system picks
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002129the correct recipe needed for the ``virtual/kernel`` dependency based on
2130the ``PREFERRED_PROVIDER`` variable. If you want to use the small kernel
2131mentioned at the beginning of this section, configure your build as
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002132follows:
2133::
2134
2135 PREFERRED_PROVIDER_virtual/kernel ??= "kernel-small"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002136
2137.. note::
2138
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002139 Any recipe that ``PROVIDES`` a ``virtual/*`` item that is ultimately not
2140 selected through ``PREFERRED_PROVIDER`` does not get built. Preventing these
2141 recipes from building is usually the desired behavior since this mechanism's
2142 purpose is to select between mutually exclusive alternative providers.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002143
2144The following lists specific examples of virtual providers:
2145
2146- ``virtual/kernel``: Provides the name of the kernel recipe to use
2147 when building a kernel image.
2148
2149- ``virtual/bootloader``: Provides the name of the bootloader to use
2150 when building an image.
2151
2152- ``virtual/libgbm``: Provides ``gbm.pc``.
2153
2154- ``virtual/egl``: Provides ``egl.pc`` and possibly ``wayland-egl.pc``.
2155
2156- ``virtual/libgl``: Provides ``gl.pc`` (i.e. libGL).
2157
2158- ``virtual/libgles1``: Provides ``glesv1_cm.pc`` (i.e. libGLESv1_CM).
2159
2160- ``virtual/libgles2``: Provides ``glesv2.pc`` (i.e. libGLESv2).
2161
2162.. note::
2163
2164 Virtual providers only apply to build time dependencies specified with
2165 :term:`PROVIDES` and :term:`DEPENDS`. They do not apply to runtime
2166 dependencies specified with :term:`RPROVIDES` and :term:`RDEPENDS`.
2167
2168Properly Versioning Pre-Release Recipes
2169---------------------------------------
2170
2171Sometimes the name of a recipe can lead to versioning problems when the
2172recipe is upgraded to a final release. For example, consider the
2173``irssi_0.8.16-rc1.bb`` recipe file in the list of example recipes in
2174the "`Storing and Naming the
2175Recipe <#new-recipe-storing-and-naming-the-recipe>`__" section. This
2176recipe is at a release candidate stage (i.e. "rc1"). When the recipe is
2177released, the recipe filename becomes ``irssi_0.8.16.bb``. The version
2178change from ``0.8.16-rc1`` to ``0.8.16`` is seen as a decrease by the
2179build system and package managers, so the resulting packages will not
2180correctly trigger an upgrade.
2181
2182In order to ensure the versions compare properly, the recommended
2183convention is to set :term:`PV` within the
2184recipe to "previous_version+current_version". You can use an additional
2185variable so that you can use the current version elsewhere. Here is an
2186example:
2187::
2188
2189 REALPV = "0.8.16-rc1"
2190 PV = "0.8.15+${REALPV}"
2191
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002192Post-Installation Scripts
2193-------------------------
2194
2195Post-installation scripts run immediately after installing a package on
2196the target or during image creation when a package is included in an
2197image. To add a post-installation script to a package, add a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002198``pkg_postinst_``\ `PACKAGENAME`\ ``()`` function to the recipe file
2199(``.bb``) and replace `PACKAGENAME` with the name of the package you want
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002200to attach to the ``postinst`` script. To apply the post-installation
2201script to the main package for the recipe, which is usually what is
2202required, specify
2203``${``\ :term:`PN`\ ``}`` in place of
2204PACKAGENAME.
2205
2206A post-installation function has the following structure:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002207::
2208
2209 pkg_postinst_PACKAGENAME() {
2210 # Commands to carry out
2211 }
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002212
2213The script defined in the post-installation function is called when the
2214root filesystem is created. If the script succeeds, the package is
2215marked as installed.
2216
2217.. note::
2218
2219 Any RPM post-installation script that runs on the target should
2220 return a 0 exit code. RPM does not allow non-zero exit codes for
2221 these scripts, and the RPM package manager will cause the package to
2222 fail installation on the target.
2223
2224Sometimes it is necessary for the execution of a post-installation
2225script to be delayed until the first boot. For example, the script might
2226need to be executed on the device itself. To delay script execution
2227until boot time, you must explicitly mark post installs to defer to the
2228target. You can use ``pkg_postinst_ontarget()`` or call
2229``postinst_intercept delay_to_first_boot`` from ``pkg_postinst()``. Any
2230failure of a ``pkg_postinst()`` script (including exit 1) triggers an
2231error during the
2232:ref:`ref-tasks-rootfs` task.
2233
2234If you have recipes that use ``pkg_postinst`` function and they require
2235the use of non-standard native tools that have dependencies during
2236rootfs construction, you need to use the
2237:term:`PACKAGE_WRITE_DEPS`
2238variable in your recipe to list these tools. If you do not use this
2239variable, the tools might be missing and execution of the
2240post-installation script is deferred until first boot. Deferring the
2241script to first boot is undesirable and for read-only rootfs impossible.
2242
2243.. note::
2244
2245 Equivalent support for pre-install, pre-uninstall, and post-uninstall
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002246 scripts exist by way of ``pkg_preinst``, ``pkg_prerm``, and ``pkg_postrm``,
2247 respectively. These scrips work in exactly the same way as does
2248 ``pkg_postinst`` with the exception that they run at different times. Also,
2249 because of when they run, they are not applicable to being run at image
2250 creation time like ``pkg_postinst``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002251
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002252Testing
2253-------
2254
2255The final step for completing your recipe is to be sure that the
2256software you built runs correctly. To accomplish runtime testing, add
2257the build's output packages to your image and test them on the target.
2258
2259For information on how to customize your image by adding specific
2260packages, see the "`Customizing
2261Images <#usingpoky-extend-customimage>`__" section.
2262
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002263Examples
2264--------
2265
2266To help summarize how to write a recipe, this section provides some
2267examples given various scenarios:
2268
2269- Recipes that use local files
2270
2271- Using an Autotooled package
2272
2273- Using a Makefile-based package
2274
2275- Splitting an application into multiple packages
2276
2277- Adding binaries to an image
2278
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002279Single .c File Package (Hello World!)
2280~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2281
2282Building an application from a single file that is stored locally (e.g.
2283under ``files``) requires a recipe that has the file listed in the
2284``SRC_URI`` variable. Additionally, you need to manually write the
2285``do_compile`` and ``do_install`` tasks. The ``S`` variable defines the
2286directory containing the source code, which is set to
2287:term:`WORKDIR` in this case - the
2288directory BitBake uses for the build.
2289::
2290
2291 SUMMARY = "Simple helloworld application"
2292 SECTION = "examples"
2293 LICENSE = "MIT"
2294 LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
2295
2296 SRC_URI = "file://helloworld.c"
2297
2298 S = "${WORKDIR}"
2299
2300 do_compile() {
2301 ${CC} helloworld.c -o helloworld
2302 }
2303
2304 do_install() {
2305 install -d ${D}${bindir}
2306 install -m 0755 helloworld ${D}${bindir}
2307 }
2308
2309By default, the ``helloworld``, ``helloworld-dbg``, and
2310``helloworld-dev`` packages are built. For information on how to
2311customize the packaging process, see the "`Splitting an Application into
2312Multiple Packages <#splitting-an-application-into-multiple-packages>`__"
2313section.
2314
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002315Autotooled Package
2316~~~~~~~~~~~~~~~~~~
2317
2318Applications that use Autotools such as ``autoconf`` and ``automake``
2319require a recipe that has a source archive listed in ``SRC_URI`` and
2320also inherit the
2321:ref:`autotools <ref-classes-autotools>` class,
2322which contains the definitions of all the steps needed to build an
2323Autotool-based application. The result of the build is automatically
2324packaged. And, if the application uses NLS for localization, packages
2325with local information are generated (one package per language).
2326Following is one example: (``hello_2.3.bb``)
2327::
2328
2329 SUMMARY = "GNU Helloworld application"
2330 SECTION = "examples"
2331 LICENSE = "GPLv2+"
2332 LIC_FILES_CHKSUM = "file://COPYING;md5=751419260aa954499f7abaabaa882bbe"
2333
2334 SRC_URI = "${GNU_MIRROR}/hello/hello-${PV}.tar.gz"
2335
2336 inherit autotools gettext
2337
2338The variable ``LIC_FILES_CHKSUM`` is used to track source license
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002339changes as described in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06002340":ref:`dev-manual/common-tasks:tracking license changes`" section in
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002341the Yocto Project Overview and Concepts Manual. You can quickly create
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002342Autotool-based recipes in a manner similar to the previous example.
2343
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002344Makefile-Based Package
2345~~~~~~~~~~~~~~~~~~~~~~
2346
2347Applications that use GNU ``make`` also require a recipe that has the
2348source archive listed in ``SRC_URI``. You do not need to add a
2349``do_compile`` step since by default BitBake starts the ``make`` command
2350to compile the application. If you need additional ``make`` options, you
2351should store them in the
2352:term:`EXTRA_OEMAKE` or
2353:term:`PACKAGECONFIG_CONFARGS`
2354variables. BitBake passes these options into the GNU ``make``
2355invocation. Note that a ``do_install`` task is still required.
2356Otherwise, BitBake runs an empty ``do_install`` task by default.
2357
2358Some applications might require extra parameters to be passed to the
2359compiler. For example, the application might need an additional header
2360path. You can accomplish this by adding to the ``CFLAGS`` variable. The
2361following example shows this:
2362::
2363
2364 CFLAGS_prepend = "-I ${S}/include "
2365
2366In the following example, ``mtd-utils`` is a makefile-based package:
2367::
2368
2369 SUMMARY = "Tools for managing memory technology devices"
2370 SECTION = "base"
2371 DEPENDS = "zlib lzo e2fsprogs util-linux"
2372 HOMEPAGE = "http://www.linux-mtd.infradead.org/"
2373 LICENSE = "GPLv2+"
2374 LIC_FILES_CHKSUM = "file://COPYING;md5=0636e73ff0215e8d672dc4c32c317bb3 \
2375 file://include/common.h;beginline=1;endline=17;md5=ba05b07912a44ea2bf81ce409380049c"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002376
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002377 # Use the latest version at 26 Oct, 2013
2378 SRCREV = "9f107132a6a073cce37434ca9cda6917dd8d866b"
2379 SRC_URI = "git://git.infradead.org/mtd-utils.git \
2380 file://add-exclusion-to-mkfs-jffs2-git-2.patch \
2381 "
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002382
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002383 PV = "1.5.1+git${SRCPV}"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002384
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002385 S = "${WORKDIR}/git"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002386
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002387 EXTRA_OEMAKE = "'CC=${CC}' 'RANLIB=${RANLIB}' 'AR=${AR}' 'CFLAGS=${CFLAGS} -I${S}/include -DWITHOUT_XATTR' 'BUILDDIR=${S}'"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002388
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002389 do_install () {
2390 oe_runmake install DESTDIR=${D} SBINDIR=${sbindir} MANDIR=${mandir} INCLUDEDIR=${includedir}
2391 }
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002392
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002393 PACKAGES =+ "mtd-utils-jffs2 mtd-utils-ubifs mtd-utils-misc"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002394
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002395 FILES_mtd-utils-jffs2 = "${sbindir}/mkfs.jffs2 ${sbindir}/jffs2dump ${sbindir}/jffs2reader ${sbindir}/sumtool"
2396 FILES_mtd-utils-ubifs = "${sbindir}/mkfs.ubifs ${sbindir}/ubi*"
2397 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 -05002398
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002399 PARALLEL_MAKE = ""
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002400
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002401 BBCLASSEXTEND = "native"
2402
2403Splitting an Application into Multiple Packages
2404~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2405
2406You can use the variables ``PACKAGES`` and ``FILES`` to split an
2407application into multiple packages.
2408
2409Following is an example that uses the ``libxpm`` recipe. By default,
2410this recipe generates a single package that contains the library along
2411with a few binaries. You can modify the recipe to split the binaries
2412into separate packages:
2413::
2414
2415 require xorg-lib-common.inc
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002416
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002417 SUMMARY = "Xpm: X Pixmap extension library"
2418 LICENSE = "BSD"
2419 LIC_FILES_CHKSUM = "file://COPYING;md5=51f4270b012ecd4ab1a164f5f4ed6cf7"
2420 DEPENDS += "libxext libsm libxt"
2421 PE = "1"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002422
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002423 XORG_PN = "libXpm"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002424
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002425 PACKAGES =+ "sxpm cxpm"
2426 FILES_cxpm = "${bindir}/cxpm"
2427 FILES_sxpm = "${bindir}/sxpm"
2428
2429In the previous example, we want to ship the ``sxpm`` and ``cxpm``
2430binaries in separate packages. Since ``bindir`` would be packaged into
2431the main ``PN`` package by default, we prepend the ``PACKAGES`` variable
2432so additional package names are added to the start of list. This results
2433in the extra ``FILES_*`` variables then containing information that
2434define which files and directories go into which packages. Files
2435included by earlier packages are skipped by latter packages. Thus, the
2436main ``PN`` package does not include the above listed files.
2437
2438Packaging Externally Produced Binaries
2439~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2440
2441Sometimes, you need to add pre-compiled binaries to an image. For
2442example, suppose that binaries for proprietary code exist, which are
2443created by a particular division of a company. Your part of the company
2444needs to use those binaries as part of an image that you are building
2445using the OpenEmbedded build system. Since you only have the binaries
2446and not the source code, you cannot use a typical recipe that expects to
2447fetch the source specified in
2448:term:`SRC_URI` and then compile it.
2449
2450One method is to package the binaries and then install them as part of
2451the image. Generally, it is not a good idea to package binaries since,
2452among other things, it can hinder the ability to reproduce builds and
2453could lead to compatibility problems with ABI in the future. However,
2454sometimes you have no choice.
2455
2456The easiest solution is to create a recipe that uses the
2457:ref:`bin_package <ref-classes-bin-package>` class
2458and to be sure that you are using default locations for build artifacts.
2459In most cases, the ``bin_package`` class handles "skipping" the
2460configure and compile steps as well as sets things up to grab packages
2461from the appropriate area. In particular, this class sets ``noexec`` on
2462both the :ref:`ref-tasks-configure`
2463and :ref:`ref-tasks-compile` tasks,
2464sets ``FILES_${PN}`` to "/" so that it picks up all files, and sets up a
2465:ref:`ref-tasks-install` task, which
2466effectively copies all files from ``${S}`` to ``${D}``. The
2467``bin_package`` class works well when the files extracted into ``${S}``
2468are already laid out in the way they should be laid out on the target.
2469For more information on these variables, see the
2470:term:`FILES`,
2471:term:`PN`,
2472:term:`S`, and
2473:term:`D` variables in the Yocto Project
2474Reference Manual's variable glossary.
2475
2476.. note::
2477
2478 - Using :term:`DEPENDS` is a good
2479 idea even for components distributed in binary form, and is often
2480 necessary for shared libraries. For a shared library, listing the
2481 library dependencies in ``DEPENDS`` makes sure that the libraries
2482 are available in the staging sysroot when other recipes link
2483 against the library, which might be necessary for successful
2484 linking.
2485
2486 - Using ``DEPENDS`` also allows runtime dependencies between
2487 packages to be added automatically. See the
Andrew Geissler09209ee2020-12-13 08:44:15 -06002488 ":ref:`overview-manual/concepts:automatically added runtime dependencies`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002489 section in the Yocto Project Overview and Concepts Manual for more
2490 information.
2491
2492If you cannot use the ``bin_package`` class, you need to be sure you are
2493doing the following:
2494
2495- Create a recipe where the
2496 :ref:`ref-tasks-configure` and
2497 :ref:`ref-tasks-compile` tasks do
2498 nothing: It is usually sufficient to just not define these tasks in
2499 the recipe, because the default implementations do nothing unless a
2500 Makefile is found in
2501 ``${``\ :term:`S`\ ``}``.
2502
2503 If ``${S}`` might contain a Makefile, or if you inherit some class
2504 that replaces ``do_configure`` and ``do_compile`` with custom
2505 versions, then you can use the
2506 ``[``\ :ref:`noexec <bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ``]``
2507 flag to turn the tasks into no-ops, as follows:
2508 ::
2509
2510 do_configure[noexec] = "1"
2511 do_compile[noexec] = "1"
2512
2513 Unlike
2514 :ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:deleting a task`,
2515 using the flag preserves the dependency chain from the
2516 :ref:`ref-tasks-fetch`,
2517 :ref:`ref-tasks-unpack`, and
2518 :ref:`ref-tasks-patch` tasks to the
2519 :ref:`ref-tasks-install` task.
2520
2521- Make sure your ``do_install`` task installs the binaries
2522 appropriately.
2523
2524- Ensure that you set up :term:`FILES`
2525 (usually
2526 ``FILES_${``\ :term:`PN`\ ``}``) to
2527 point to the files you have installed, which of course depends on
2528 where you have installed them and whether those files are in
2529 different locations than the defaults.
2530
Andrew Geissler6ce62a22020-11-30 19:58:47 -06002531.. note::
2532
2533 If image prelinking is enabled (e.g. "image-prelink" is in :term:`USER_CLASSES`
2534 which it is by default), prelink will change the binaries in the generated images
2535 and this often catches people out. Remove that class to ensure binaries are
2536 preserved exactly if that is necessary.
2537
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002538Following Recipe Style Guidelines
2539---------------------------------
2540
2541When writing recipes, it is good to conform to existing style
Andrew Geisslerc723b722021-01-08 16:14:09 -06002542guidelines. The :oe_wiki:`OpenEmbedded Styleguide </Styleguide>` wiki page
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002543provides rough guidelines for preferred recipe style.
2544
2545It is common for existing recipes to deviate a bit from this style.
2546However, aiming for at least a consistent style is a good idea. Some
2547practices, such as omitting spaces around ``=`` operators in assignments
2548or ordering recipe components in an erratic way, are widely seen as poor
2549style.
2550
2551Recipe Syntax
2552-------------
2553
2554Understanding recipe file syntax is important for writing recipes. The
2555following list overviews the basic items that make up a BitBake recipe
2556file. For more complete BitBake syntax descriptions, see the
2557":doc:`bitbake-user-manual/bitbake-user-manual-metadata`"
2558chapter of the BitBake User Manual.
2559
2560- *Variable Assignments and Manipulations:* Variable assignments allow
2561 a value to be assigned to a variable. The assignment can be static
2562 text or might include the contents of other variables. In addition to
2563 the assignment, appending and prepending operations are also
2564 supported.
2565
2566 The following example shows some of the ways you can use variables in
2567 recipes:
2568 ::
2569
2570 S = "${WORKDIR}/postfix-${PV}"
2571 CFLAGS += "-DNO_ASM"
2572 SRC_URI_append = " file://fixup.patch"
2573
2574- *Functions:* Functions provide a series of actions to be performed.
2575 You usually use functions to override the default implementation of a
2576 task function or to complement a default function (i.e. append or
2577 prepend to an existing function). Standard functions use ``sh`` shell
2578 syntax, although access to OpenEmbedded variables and internal
2579 methods are also available.
2580
2581 The following is an example function from the ``sed`` recipe:
2582 ::
2583
2584 do_install () {
2585 autotools_do_install
2586 install -d ${D}${base_bindir}
2587 mv ${D}${bindir}/sed ${D}${base_bindir}/sed
2588 rmdir ${D}${bindir}/
2589 }
2590
2591 It is
2592 also possible to implement new functions that are called between
2593 existing tasks as long as the new functions are not replacing or
2594 complementing the default functions. You can implement functions in
2595 Python instead of shell. Both of these options are not seen in the
2596 majority of recipes.
2597
2598- *Keywords:* BitBake recipes use only a few keywords. You use keywords
2599 to include common functions (``inherit``), load parts of a recipe
2600 from other files (``include`` and ``require``) and export variables
2601 to the environment (``export``).
2602
2603 The following example shows the use of some of these keywords:
2604 ::
2605
2606 export POSTCONF = "${STAGING_BINDIR}/postconf"
2607 inherit autoconf
2608 require otherfile.inc
2609
2610- *Comments (#):* Any lines that begin with the hash character (``#``)
2611 are treated as comment lines and are ignored:
2612 ::
2613
2614 # This is a comment
2615
2616This next list summarizes the most important and most commonly used
2617parts of the recipe syntax. For more information on these parts of the
2618syntax, you can reference the
2619:doc:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata` chapter
2620in the BitBake User Manual.
2621
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002622- *Line Continuation (\\):* Use the backward slash (``\``) character to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002623 split a statement over multiple lines. Place the slash character at
2624 the end of the line that is to be continued on the next line:
2625 ::
2626
2627 VAR = "A really long \
2628 line"
2629
2630 .. note::
2631
2632 You cannot have any characters including spaces or tabs after the
2633 slash character.
2634
2635- *Using Variables (${VARNAME}):* Use the ``${VARNAME}`` syntax to
2636 access the contents of a variable:
2637 ::
2638
2639 SRC_URI = "${SOURCEFORGE_MIRROR}/libpng/zlib-${PV}.tar.gz"
2640
2641 .. note::
2642
2643 It is important to understand that the value of a variable
2644 expressed in this form does not get substituted automatically. The
2645 expansion of these expressions happens on-demand later (e.g.
2646 usually when a function that makes reference to the variable
2647 executes). This behavior ensures that the values are most
2648 appropriate for the context in which they are finally used. On the
2649 rare occasion that you do need the variable expression to be
2650 expanded immediately, you can use the
2651 :=
2652 operator instead of
2653 =
2654 when you make the assignment, but this is not generally needed.
2655
2656- *Quote All Assignments ("value"):* Use double quotes around values in
2657 all variable assignments (e.g. ``"value"``). Following is an example:
2658 ::
2659
2660 VAR1 = "${OTHERVAR}"
2661 VAR2 = "The version is ${PV}"
2662
2663- *Conditional Assignment (?=):* Conditional assignment is used to
2664 assign a value to a variable, but only when the variable is currently
2665 unset. Use the question mark followed by the equal sign (``?=``) to
2666 make a "soft" assignment used for conditional assignment. Typically,
2667 "soft" assignments are used in the ``local.conf`` file for variables
2668 that are allowed to come through from the external environment.
2669
2670 Here is an example where ``VAR1`` is set to "New value" if it is
2671 currently empty. However, if ``VAR1`` has already been set, it
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002672 remains unchanged:
2673 ::
2674
2675 VAR1 ?= "New value"
2676
2677 In this next example, ``VAR1`` is left with the value "Original value":
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002678 ::
2679
2680 VAR1 = "Original value"
2681 VAR1 ?= "New value"
2682
2683- *Appending (+=):* Use the plus character followed by the equals sign
2684 (``+=``) to append values to existing variables.
2685
2686 .. note::
2687
2688 This operator adds a space between the existing content of the
2689 variable and the new content.
2690
2691 Here is an example:
2692 ::
2693
2694 SRC_URI += "file://fix-makefile.patch"
2695
2696- *Prepending (=+):* Use the equals sign followed by the plus character
2697 (``=+``) to prepend values to existing variables.
2698
2699 .. note::
2700
2701 This operator adds a space between the new content and the
2702 existing content of the variable.
2703
2704 Here is an example:
2705 ::
2706
2707 VAR =+ "Starts"
2708
2709- *Appending (_append):* Use the ``_append`` operator to append values
2710 to existing variables. This operator does not add any additional
2711 space. Also, the operator is applied after all the ``+=``, and ``=+``
2712 operators have been applied and after all ``=`` assignments have
2713 occurred.
2714
2715 The following example shows the space being explicitly added to the
2716 start to ensure the appended value is not merged with the existing
2717 value:
2718 ::
2719
2720 SRC_URI_append = " file://fix-makefile.patch"
2721
2722 You can also use
2723 the ``_append`` operator with overrides, which results in the actions
2724 only being performed for the specified target or machine:
2725 ::
2726
2727 SRC_URI_append_sh4 = " file://fix-makefile.patch"
2728
2729- *Prepending (_prepend):* Use the ``_prepend`` operator to prepend
2730 values to existing variables. This operator does not add any
2731 additional space. Also, the operator is applied after all the ``+=``,
2732 and ``=+`` operators have been applied and after all ``=``
2733 assignments have occurred.
2734
2735 The following example shows the space being explicitly added to the
2736 end to ensure the prepended value is not merged with the existing
2737 value:
2738 ::
2739
2740 CFLAGS_prepend = "-I${S}/myincludes "
2741
2742 You can also use the
2743 ``_prepend`` operator with overrides, which results in the actions
2744 only being performed for the specified target or machine:
2745 ::
2746
2747 CFLAGS_prepend_sh4 = "-I${S}/myincludes "
2748
2749- *Overrides:* You can use overrides to set a value conditionally,
2750 typically based on how the recipe is being built. For example, to set
2751 the :term:`KBRANCH` variable's
2752 value to "standard/base" for any target
2753 :term:`MACHINE`, except for
2754 qemuarm where it should be set to "standard/arm-versatile-926ejs",
2755 you would do the following:
2756 ::
2757
2758 KBRANCH = "standard/base"
2759 KBRANCH_qemuarm = "standard/arm-versatile-926ejs"
2760
2761 Overrides are also used to separate
2762 alternate values of a variable in other situations. For example, when
2763 setting variables such as
2764 :term:`FILES` and
2765 :term:`RDEPENDS` that are
2766 specific to individual packages produced by a recipe, you should
2767 always use an override that specifies the name of the package.
2768
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002769- *Indentation:* Use spaces for indentation rather than tabs. For
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002770 shell functions, both currently work. However, it is a policy
2771 decision of the Yocto Project to use tabs in shell functions. Realize
2772 that some layers have a policy to use spaces for all indentation.
2773
2774- *Using Python for Complex Operations:* For more advanced processing,
2775 it is possible to use Python code during variable assignments (e.g.
2776 search and replacement on a variable).
2777
2778 You indicate Python code using the ``${@python_code}`` syntax for the
2779 variable assignment:
2780 ::
2781
2782 SRC_URI = "ftp://ftp.info-zip.org/pub/infozip/src/zip${@d.getVar('PV',1).replace('.', '')}.tgz
2783
2784- *Shell Function Syntax:* Write shell functions as if you were writing
2785 a shell script when you describe a list of actions to take. You
2786 should ensure that your script works with a generic ``sh`` and that
2787 it does not require any ``bash`` or other shell-specific
2788 functionality. The same considerations apply to various system
2789 utilities (e.g. ``sed``, ``grep``, ``awk``, and so forth) that you
2790 might wish to use. If in doubt, you should check with multiple
2791 implementations - including those from BusyBox.
2792
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002793Adding a New Machine
2794====================
2795
2796Adding a new machine to the Yocto Project is a straightforward process.
2797This section describes how to add machines that are similar to those
2798that the Yocto Project already supports.
2799
2800.. note::
2801
2802 Although well within the capabilities of the Yocto Project, adding a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002803 totally new architecture might require changes to ``gcc``/``glibc``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002804 and to the site information, which is beyond the scope of this
2805 manual.
2806
2807For a complete example that shows how to add a new machine, see the
2808":ref:`bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script`"
2809section in the Yocto Project Board Support Package (BSP) Developer's
2810Guide.
2811
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002812Adding the Machine Configuration File
2813-------------------------------------
2814
2815To add a new machine, you need to add a new machine configuration file
2816to the layer's ``conf/machine`` directory. This configuration file
2817provides details about the device you are adding.
2818
2819The OpenEmbedded build system uses the root name of the machine
2820configuration file to reference the new machine. For example, given a
2821machine configuration file named ``crownbay.conf``, the build system
2822recognizes the machine as "crownbay".
2823
2824The most important variables you must set in your machine configuration
2825file or include from a lower-level configuration file are as follows:
2826
2827- ``TARGET_ARCH`` (e.g. "arm")
2828
2829- ``PREFERRED_PROVIDER_virtual/kernel``
2830
2831- ``MACHINE_FEATURES`` (e.g. "apm screen wifi")
2832
2833You might also need these variables:
2834
2835- ``SERIAL_CONSOLES`` (e.g. "115200;ttyS0 115200;ttyS1")
2836
2837- ``KERNEL_IMAGETYPE`` (e.g. "zImage")
2838
2839- ``IMAGE_FSTYPES`` (e.g. "tar.gz jffs2")
2840
2841You can find full details on these variables in the reference section.
2842You can leverage existing machine ``.conf`` files from
2843``meta-yocto-bsp/conf/machine/``.
2844
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002845Adding a Kernel for the Machine
2846-------------------------------
2847
2848The OpenEmbedded build system needs to be able to build a kernel for the
2849machine. You need to either create a new kernel recipe for this machine,
2850or extend an existing kernel recipe. You can find several kernel recipe
2851examples in the Source Directory at ``meta/recipes-kernel/linux`` that
2852you can use as references.
2853
2854If you are creating a new kernel recipe, normal recipe-writing rules
2855apply for setting up a ``SRC_URI``. Thus, you need to specify any
2856necessary patches and set ``S`` to point at the source code. You need to
2857create a ``do_configure`` task that configures the unpacked kernel with
2858a ``defconfig`` file. You can do this by using a ``make defconfig``
2859command or, more commonly, by copying in a suitable ``defconfig`` file
2860and then running ``make oldconfig``. By making use of ``inherit kernel``
2861and potentially some of the ``linux-*.inc`` files, most other
2862functionality is centralized and the defaults of the class normally work
2863well.
2864
2865If you are extending an existing kernel recipe, it is usually a matter
2866of adding a suitable ``defconfig`` file. The file needs to be added into
2867a location similar to ``defconfig`` files used for other machines in a
2868given kernel recipe. A possible way to do this is by listing the file in
2869the ``SRC_URI`` and adding the machine to the expression in
2870``COMPATIBLE_MACHINE``:
2871::
2872
2873 COMPATIBLE_MACHINE = '(qemux86|qemumips)'
2874
2875For more information on ``defconfig`` files, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06002876":ref:`kernel-dev/common:changing the configuration`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002877section in the Yocto Project Linux Kernel Development Manual.
2878
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002879Adding a Formfactor Configuration File
2880--------------------------------------
2881
2882A formfactor configuration file provides information about the target
2883hardware for which the image is being built and information that the
2884build system cannot obtain from other sources such as the kernel. Some
2885examples of information contained in a formfactor configuration file
2886include framebuffer orientation, whether or not the system has a
2887keyboard, the positioning of the keyboard in relation to the screen, and
2888the screen resolution.
2889
2890The build system uses reasonable defaults in most cases. However, if
2891customization is necessary, you need to create a ``machconfig`` file in
2892the ``meta/recipes-bsp/formfactor/files`` directory. This directory
2893contains directories for specific machines such as ``qemuarm`` and
2894``qemux86``. For information about the settings available and the
2895defaults, see the ``meta/recipes-bsp/formfactor/files/config`` file
2896found in the same area.
2897
2898Following is an example for "qemuarm" machine:
2899::
2900
2901 HAVE_TOUCHSCREEN=1
2902 HAVE_KEYBOARD=1
2903 DISPLAY_CAN_ROTATE=0
2904 DISPLAY_ORIENTATION=0
2905 #DISPLAY_WIDTH_PIXELS=640
2906 #DISPLAY_HEIGHT_PIXELS=480
2907 #DISPLAY_BPP=16
2908 DISPLAY_DPI=150
2909 DISPLAY_SUBPIXEL_ORDER=vrgb
2910
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002911Upgrading Recipes
2912=================
2913
2914Over time, upstream developers publish new versions for software built
2915by layer recipes. It is recommended to keep recipes up-to-date with
2916upstream version releases.
2917
2918While several methods exist that allow you upgrade a recipe, you might
2919consider checking on the upgrade status of a recipe first. You can do so
2920using the ``devtool check-upgrade-status`` command. See the
2921":ref:`devtool-checking-on-the-upgrade-status-of-a-recipe`"
2922section in the Yocto Project Reference Manual for more information.
2923
2924The remainder of this section describes three ways you can upgrade a
2925recipe. You can use the Automated Upgrade Helper (AUH) to set up
2926automatic version upgrades. Alternatively, you can use
2927``devtool upgrade`` to set up semi-automatic version upgrades. Finally,
2928you can manually upgrade a recipe by editing the recipe itself.
2929
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002930Using the Auto Upgrade Helper (AUH)
2931-----------------------------------
2932
2933The AUH utility works in conjunction with the OpenEmbedded build system
2934in order to automatically generate upgrades for recipes based on new
2935versions being published upstream. Use AUH when you want to create a
2936service that performs the upgrades automatically and optionally sends
2937you an email with the results.
2938
2939AUH allows you to update several recipes with a single use. You can also
2940optionally perform build and integration tests using images with the
2941results saved to your hard drive and emails of results optionally sent
2942to recipe maintainers. Finally, AUH creates Git commits with appropriate
2943commit messages in the layer's tree for the changes made to recipes.
2944
2945.. note::
2946
2947 Conditions do exist when you should not use AUH to upgrade recipes
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002948 and you should instead use either ``devtool upgrade`` or upgrade your
2949 recipes manually:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002950
2951 - When AUH cannot complete the upgrade sequence. This situation
2952 usually results because custom patches carried by the recipe
2953 cannot be automatically rebased to the new version. In this case,
2954 ``devtool upgrade`` allows you to manually resolve conflicts.
2955
2956 - When for any reason you want fuller control over the upgrade
2957 process. For example, when you want special arrangements for
2958 testing.
2959
2960The following steps describe how to set up the AUH utility:
2961
29621. *Be Sure the Development Host is Set Up:* You need to be sure that
2963 your development host is set up to use the Yocto Project. For
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002964 information on how to set up your host, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06002965 ":ref:`dev-manual/start:Preparing the Build Host`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002966
29672. *Make Sure Git is Configured:* The AUH utility requires Git to be
2968 configured because AUH uses Git to save upgrades. Thus, you must have
2969 Git user and email configured. The following command shows your
2970 configurations:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002971 ::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002972
2973 $ git config --list
2974
2975 If you do not have the user and
2976 email configured, you can use the following commands to do so:
2977 ::
2978
2979 $ git config --global user.name some_name
2980 $ git config --global user.email username@domain.com
2981
29823. *Clone the AUH Repository:* To use AUH, you must clone the repository
2983 onto your development host. The following command uses Git to create
2984 a local copy of the repository on your system:
2985 ::
2986
2987 $ git clone git://git.yoctoproject.org/auto-upgrade-helper
2988 Cloning into 'auto-upgrade-helper'... remote: Counting objects: 768, done.
2989 remote: Compressing objects: 100% (300/300), done.
2990 remote: Total 768 (delta 499), reused 703 (delta 434)
2991 Receiving objects: 100% (768/768), 191.47 KiB | 98.00 KiB/s, done.
2992 Resolving deltas: 100% (499/499), done.
2993 Checking connectivity... done.
2994
2995 AUH is not part of the :term:`OpenEmbedded-Core (OE-Core)` or
2996 :term:`Poky` repositories.
2997
29984. *Create a Dedicated Build Directory:* Run the
2999 :ref:`structure-core-script`
3000 script to create a fresh build directory that you use exclusively for
3001 running the AUH utility:
3002 ::
3003
3004 $ cd ~/poky
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003005 $ source oe-init-build-env your_AUH_build_directory
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003006
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003007 Re-using an existing build directory and its configurations is not
3008 recommended as existing settings could cause AUH to fail or behave
3009 undesirably.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003010
30115. *Make Configurations in Your Local Configuration File:* Several
3012 settings need to exist in the ``local.conf`` file in the build
3013 directory you just created for AUH. Make these following
3014 configurations:
3015
3016 - If you want to enable :ref:`Build
Andrew Geissler09209ee2020-12-13 08:44:15 -06003017 History <dev-manual/common-tasks:maintaining build output quality>`,
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003018 which is optional, you need the following lines in the
3019 ``conf/local.conf`` file:
3020 ::
3021
3022 INHERIT =+ "buildhistory"
3023 BUILDHISTORY_COMMIT = "1"
3024
3025 With this configuration and a successful
3026 upgrade, a build history "diff" file appears in the
3027 ``upgrade-helper/work/recipe/buildhistory-diff.txt`` file found in
3028 your build directory.
3029
3030 - If you want to enable testing through the
3031 :ref:`testimage <ref-classes-testimage*>`
3032 class, which is optional, you need to have the following set in
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003033 your ``conf/local.conf`` file:
3034 ::
3035
3036 INHERIT += "testimage"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003037
3038 .. note::
3039
3040 If your distro does not enable by default ptest, which Poky
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003041 does, you need the following in your ``local.conf`` file:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003042 ::
3043
3044 DISTRO_FEATURES_append = " ptest"
3045
3046
30476. *Optionally Start a vncserver:* If you are running in a server
3048 without an X11 session, you need to start a vncserver:
3049 ::
3050
3051 $ vncserver :1
3052 $ export DISPLAY=:1
3053
30547. *Create and Edit an AUH Configuration File:* You need to have the
3055 ``upgrade-helper/upgrade-helper.conf`` configuration file in your
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003056 build directory. You can find a sample configuration file in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003057 :yocto_git:`AUH source repository </auto-upgrade-helper/tree/>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003058
3059 Read through the sample file and make configurations as needed. For
3060 example, if you enabled build history in your ``local.conf`` as
3061 described earlier, you must enable it in ``upgrade-helper.conf``.
3062
3063 Also, if you are using the default ``maintainers.inc`` file supplied
3064 with Poky and located in ``meta-yocto`` and you do not set a
3065 "maintainers_whitelist" or "global_maintainer_override" in the
3066 ``upgrade-helper.conf`` configuration, and you specify "-e all" on
3067 the AUH command-line, the utility automatically sends out emails to
3068 all the default maintainers. Please avoid this.
3069
3070This next set of examples describes how to use the AUH:
3071
3072- *Upgrading a Specific Recipe:* To upgrade a specific recipe, use the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003073 following form:
3074 ::
3075
3076 $ upgrade-helper.py recipe_name
3077
3078 For example, this command upgrades the ``xmodmap`` recipe:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003079 ::
3080
3081 $ upgrade-helper.py xmodmap
3082
3083- *Upgrading a Specific Recipe to a Particular Version:* To upgrade a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003084 specific recipe to a particular version, use the following form:
3085 ::
3086
3087 $ upgrade-helper.py recipe_name -t version
3088
3089 For example, this command upgrades the ``xmodmap`` recipe to version 1.2.3:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003090 ::
3091
3092 $ upgrade-helper.py xmodmap -t 1.2.3
3093
3094- *Upgrading all Recipes to the Latest Versions and Suppressing Email
3095 Notifications:* To upgrade all recipes to their most recent versions
3096 and suppress the email notifications, use the following command:
3097 ::
3098
3099 $ upgrade-helper.py all
3100
3101- *Upgrading all Recipes to the Latest Versions and Send Email
3102 Notifications:* To upgrade all recipes to their most recent versions
3103 and send email messages to maintainers for each attempted recipe as
3104 well as a status email, use the following command:
3105 ::
3106
3107 $ upgrade-helper.py -e all
3108
3109Once you have run the AUH utility, you can find the results in the AUH
3110build directory:
3111::
3112
3113 ${BUILDDIR}/upgrade-helper/timestamp
3114
3115The AUH utility
3116also creates recipe update commits from successful upgrade attempts in
3117the layer tree.
3118
3119You can easily set up to run the AUH utility on a regular basis by using
3120a cron job. See the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003121:yocto_git:`weeklyjob.sh </auto-upgrade-helper/tree/weeklyjob.sh>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003122file distributed with the utility for an example.
3123
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003124Using ``devtool upgrade``
3125-------------------------
3126
3127As mentioned earlier, an alternative method for upgrading recipes to
3128newer versions is to use
Andrew Geissler09209ee2020-12-13 08:44:15 -06003129:doc:`devtool upgrade </ref-manual/devtool-reference>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003130You can read about ``devtool upgrade`` in general in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003131":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 -05003132section in the Yocto Project Application Development and the Extensible
3133Software Development Kit (eSDK) Manual.
3134
3135To see all the command-line options available with ``devtool upgrade``,
3136use the following help command:
3137::
3138
3139 $ devtool upgrade -h
3140
3141If you want to find out what version a recipe is currently at upstream
3142without any attempt to upgrade your local version of the recipe, you can
3143use the following command:
3144::
3145
3146 $ devtool latest-version recipe_name
3147
3148As mentioned in the previous section describing AUH, ``devtool upgrade``
3149works in a less-automated manner than AUH. Specifically,
3150``devtool upgrade`` only works on a single recipe that you name on the
3151command line, cannot perform build and integration testing using images,
3152and does not automatically generate commits for changes in the source
3153tree. Despite all these "limitations", ``devtool upgrade`` updates the
3154recipe file to the new upstream version and attempts to rebase custom
3155patches contained by the recipe as needed.
3156
3157.. note::
3158
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003159 AUH uses much of ``devtool upgrade`` behind the scenes making AUH somewhat
3160 of a "wrapper" application for ``devtool upgrade``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003161
3162A typical scenario involves having used Git to clone an upstream
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003163repository that you use during build operations. Because you have built the
3164recipe in the past, the layer is likely added to your
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003165configuration already. If for some reason, the layer is not added, you
3166could add it easily using the
3167":ref:`bitbake-layers <bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script>`"
3168script. For example, suppose you use the ``nano.bb`` recipe from the
3169``meta-oe`` layer in the ``meta-openembedded`` repository. For this
3170example, assume that the layer has been cloned into following area:
3171::
3172
3173 /home/scottrif/meta-openembedded
3174
3175The following command from your
3176:term:`Build Directory` adds the layer to
3177your build configuration (i.e. ``${BUILDDIR}/conf/bblayers.conf``):
3178::
3179
3180 $ bitbake-layers add-layer /home/scottrif/meta-openembedded/meta-oe
3181 NOTE: Starting bitbake server...
3182 Parsing recipes: 100% |##########################################| Time: 0:00:55
3183 Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
3184 Removing 12 recipes from the x86_64 sysroot: 100% |##############| Time: 0:00:00
3185 Removing 1 recipes from the x86_64_i586 sysroot: 100% |##########| Time: 0:00:00
3186 Removing 5 recipes from the i586 sysroot: 100% |#################| Time: 0:00:00
3187 Removing 5 recipes from the qemux86 sysroot: 100% |##############| Time: 0:00:00
3188
3189For this example, assume that the ``nano.bb`` recipe that
3190is upstream has a 2.9.3 version number. However, the version in the
3191local repository is 2.7.4. The following command from your build
3192directory automatically upgrades the recipe for you:
3193
3194.. note::
3195
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003196 Using the ``-V`` option is not necessary. Omitting the version number causes
3197 ``devtool upgrade`` to upgrade the recipe to the most recent version.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003198
3199::
3200
3201 $ devtool upgrade nano -V 2.9.3
3202 NOTE: Starting bitbake server...
3203 NOTE: Creating workspace layer in /home/scottrif/poky/build/workspace
3204 Parsing recipes: 100% |##########################################| Time: 0:00:46
3205 Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
3206 NOTE: Extracting current version source...
3207 NOTE: Resolving any missing task queue dependencies
3208 .
3209 .
3210 .
3211 NOTE: Executing SetScene Tasks
3212 NOTE: Executing RunQueue Tasks
3213 NOTE: Tasks Summary: Attempted 74 tasks of which 72 didn't need to be rerun and all succeeded.
3214 Adding changed files: 100% |#####################################| Time: 0:00:00
3215 NOTE: Upgraded source extracted to /home/scottrif/poky/build/workspace/sources/nano
3216 NOTE: New recipe is /home/scottrif/poky/build/workspace/recipes/nano/nano_2.9.3.bb
3217
3218Continuing with this example, you can use ``devtool build`` to build the
3219newly upgraded recipe:
3220::
3221
3222 $ devtool build nano
3223 NOTE: Starting bitbake server...
3224 Loading cache: 100% |################################################################################################| Time: 0:00:01
3225 Loaded 2040 entries from dependency cache.
3226 Parsing recipes: 100% |##############################################################################################| Time: 0:00:00
3227 Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
3228 NOTE: Resolving any missing task queue dependencies
3229 .
3230 .
3231 .
3232 NOTE: Executing SetScene Tasks
3233 NOTE: Executing RunQueue Tasks
3234 NOTE: nano: compiling from external source tree /home/scottrif/poky/build/workspace/sources/nano
3235 NOTE: Tasks Summary: Attempted 520 tasks of which 304 didn't need to be rerun and all succeeded.
3236
3237Within the ``devtool upgrade`` workflow, opportunity
3238exists to deploy and test your rebuilt software. For this example,
3239however, running ``devtool finish`` cleans up the workspace once the
3240source in your workspace is clean. This usually means using Git to stage
3241and submit commits for the changes generated by the upgrade process.
3242
3243Once the tree is clean, you can clean things up in this example with the
3244following command from the ``${BUILDDIR}/workspace/sources/nano``
3245directory:
3246::
3247
3248 $ devtool finish nano meta-oe
3249 NOTE: Starting bitbake server...
3250 Loading cache: 100% |################################################################################################| Time: 0:00:00
3251 Loaded 2040 entries from dependency cache.
3252 Parsing recipes: 100% |##############################################################################################| Time: 0:00:01
3253 Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
3254 NOTE: Adding new patch 0001-nano.bb-Stuff-I-changed-when-upgrading-nano.bb.patch
3255 NOTE: Updating recipe nano_2.9.3.bb
3256 NOTE: Removing file /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano/nano_2.7.4.bb
3257 NOTE: Moving recipe file to /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano
3258 NOTE: Leaving source tree /home/scottrif/poky/build/workspace/sources/nano as-is; if you no longer need it then please delete it manually
3259
3260
3261Using the ``devtool finish`` command cleans up the workspace and creates a patch
3262file based on your commits. The tool puts all patch files back into the
3263source directory in a sub-directory named ``nano`` in this case.
3264
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003265Manually Upgrading a Recipe
3266---------------------------
3267
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003268If for some reason you choose not to upgrade recipes using
Andrew Geissler09209ee2020-12-13 08:44:15 -06003269:ref:`dev-manual/common-tasks:Using the Auto Upgrade Helper (AUH)` or
3270by :ref:`dev-manual/common-tasks:Using \`\`devtool upgrade\`\``,
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003271you can manually edit the recipe files to upgrade the versions.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003272
3273.. note::
3274
3275 Manually updating multiple recipes scales poorly and involves many
3276 steps. The recommendation to upgrade recipe versions is through AUH
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003277 or ``devtool upgrade``, both of which automate some steps and provide
3278 guidance for others needed for the manual process.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003279
3280To manually upgrade recipe versions, follow these general steps:
3281
32821. *Change the Version:* Rename the recipe such that the version (i.e.
3283 the :term:`PV` part of the recipe name)
3284 changes appropriately. If the version is not part of the recipe name,
3285 change the value as it is set for ``PV`` within the recipe itself.
3286
Andrew Geissler4c19ea12020-10-27 13:52:24 -050032872. *Update* ``SRCREV`` *if Needed*: If the source code your recipe builds
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003288 is fetched from Git or some other version control system, update
3289 :term:`SRCREV` to point to the
3290 commit hash that matches the new version.
3291
32923. *Build the Software:* Try to build the recipe using BitBake. Typical
3293 build failures include the following:
3294
3295 - License statements were updated for the new version. For this
3296 case, you need to review any changes to the license and update the
3297 values of :term:`LICENSE` and
3298 :term:`LIC_FILES_CHKSUM`
3299 as needed.
3300
3301 .. note::
3302
3303 License changes are often inconsequential. For example, the
3304 license text's copyright year might have changed.
3305
3306 - Custom patches carried by the older version of the recipe might
3307 fail to apply to the new version. For these cases, you need to
3308 review the failures. Patches might not be necessary for the new
3309 version of the software if the upgraded version has fixed those
3310 issues. If a patch is necessary and failing, you need to rebase it
3311 into the new version.
3312
33134. *Optionally Attempt to Build for Several Architectures:* Once you
3314 successfully build the new software for a given architecture, you
3315 could test the build for other architectures by changing the
3316 :term:`MACHINE` variable and
3317 rebuilding the software. This optional step is especially important
3318 if the recipe is to be released publicly.
3319
33205. *Check the Upstream Change Log or Release Notes:* Checking both these
3321 reveals if new features exist that could break
3322 backwards-compatibility. If so, you need to take steps to mitigate or
3323 eliminate that situation.
3324
33256. *Optionally Create a Bootable Image and Test:* If you want, you can
3326 test the new software by booting it onto actual hardware.
3327
33287. *Create a Commit with the Change in the Layer Repository:* After all
3329 builds work and any testing is successful, you can create commits for
3330 any changes in the layer holding your upgraded recipe.
3331
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003332Finding Temporary Source Code
3333=============================
3334
3335You might find it helpful during development to modify the temporary
3336source code used by recipes to build packages. For example, suppose you
3337are developing a patch and you need to experiment a bit to figure out
3338your solution. After you have initially built the package, you can
3339iteratively tweak the source code, which is located in the
3340:term:`Build Directory`, and then you can
3341force a re-compile and quickly test your altered code. Once you settle
3342on a solution, you can then preserve your changes in the form of
3343patches.
3344
3345During a build, the unpacked temporary source code used by recipes to
3346build packages is available in the Build Directory as defined by the
3347:term:`S` variable. Below is the default
3348value for the ``S`` variable as defined in the
3349``meta/conf/bitbake.conf`` configuration file in the
3350:term:`Source Directory`:
3351::
3352
3353 S = "${WORKDIR}/${BP}"
3354
3355You should be aware that many recipes override the
3356``S`` variable. For example, recipes that fetch their source from Git
3357usually set ``S`` to ``${WORKDIR}/git``.
3358
3359.. note::
3360
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003361 The :term:`BP` represents the base recipe name, which consists of the name
3362 and version:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003363 ::
3364
3365 BP = "${BPN}-${PV}"
3366
3367
3368The path to the work directory for the recipe
3369(:term:`WORKDIR`) is defined as
3370follows:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003371::
3372
3373 ${TMPDIR}/work/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR}
3374
3375The actual directory depends on several things:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003376
3377- :term:`TMPDIR`: The top-level build
3378 output directory.
3379
3380- :term:`MULTIMACH_TARGET_SYS`:
3381 The target system identifier.
3382
3383- :term:`PN`: The recipe name.
3384
3385- :term:`EXTENDPE`: The epoch - (if
3386 :term:`PE` is not specified, which is
3387 usually the case for most recipes, then ``EXTENDPE`` is blank).
3388
3389- :term:`PV`: The recipe version.
3390
3391- :term:`PR`: The recipe revision.
3392
3393As an example, assume a Source Directory top-level folder named
3394``poky``, a default Build Directory at ``poky/build``, and a
3395``qemux86-poky-linux`` machine target system. Furthermore, suppose your
3396recipe is named ``foo_1.3.0.bb``. In this case, the work directory the
3397build system uses to build the package would be as follows:
3398::
3399
3400 poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
3401
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003402Using Quilt in Your Workflow
3403============================
3404
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003405`Quilt <https://savannah.nongnu.org/projects/quilt>`__ is a powerful tool
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003406that allows you to capture source code changes without having a clean
3407source tree. This section outlines the typical workflow you can use to
3408modify source code, test changes, and then preserve the changes in the
3409form of a patch all using Quilt.
3410
3411.. note::
3412
3413 With regard to preserving changes to source files, if you clean a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003414 recipe or have ``rm_work`` enabled, the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003415 :ref:`devtool workflow <sdk-manual/extensible:using \`\`devtool\`\` in your sdk workflow>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003416 as described in the Yocto Project Application Development and the
3417 Extensible Software Development Kit (eSDK) manual is a safer
3418 development flow than the flow that uses Quilt.
3419
3420Follow these general steps:
3421
34221. *Find the Source Code:* Temporary source code used by the
3423 OpenEmbedded build system is kept in the
3424 :term:`Build Directory`. See the
3425 "`Finding Temporary Source
3426 Code <#finding-the-temporary-source-code>`__" section to learn how to
3427 locate the directory that has the temporary source code for a
3428 particular package.
3429
34302. *Change Your Working Directory:* You need to be in the directory that
3431 has the temporary source code. That directory is defined by the
3432 :term:`S` variable.
3433
34343. *Create a New Patch:* Before modifying source code, you need to
3435 create a new patch. To create a new patch file, use ``quilt new`` as
3436 below:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003437 ::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003438
3439 $ quilt new my_changes.patch
3440
34414. *Notify Quilt and Add Files:* After creating the patch, you need to
3442 notify Quilt about the files you plan to edit. You notify Quilt by
3443 adding the files to the patch you just created:
3444 ::
3445
3446 $ quilt add file1.c file2.c file3.c
3447
34485. *Edit the Files:* Make your changes in the source code to the files
3449 you added to the patch.
3450
34516. *Test Your Changes:* Once you have modified the source code, the
3452 easiest way to test your changes is by calling the ``do_compile``
3453 task as shown in the following example:
3454 ::
3455
3456 $ bitbake -c compile -f package
3457
3458 The ``-f`` or ``--force`` option forces the specified task to
3459 execute. If you find problems with your code, you can just keep
3460 editing and re-testing iteratively until things work as expected.
3461
3462 .. note::
3463
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003464 All the modifications you make to the temporary source code disappear
3465 once you run the ``do_clean`` or ``do_cleanall`` tasks using BitBake
3466 (i.e. ``bitbake -c clean package`` and ``bitbake -c cleanall package``).
3467 Modifications will also disappear if you use the ``rm_work`` feature as
3468 described in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003469 ":ref:`dev-manual/common-tasks:conserving disk space during builds`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003470 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003471
34727. *Generate the Patch:* Once your changes work as expected, you need to
3473 use Quilt to generate the final patch that contains all your
3474 modifications.
3475 ::
3476
3477 $ quilt refresh
3478
3479 At this point, the
3480 ``my_changes.patch`` file has all your edits made to the ``file1.c``,
3481 ``file2.c``, and ``file3.c`` files.
3482
3483 You can find the resulting patch file in the ``patches/``
3484 subdirectory of the source (``S``) directory.
3485
34868. *Copy the Patch File:* For simplicity, copy the patch file into a
3487 directory named ``files``, which you can create in the same directory
3488 that holds the recipe (``.bb``) file or the append (``.bbappend``)
3489 file. Placing the patch here guarantees that the OpenEmbedded build
3490 system will find the patch. Next, add the patch into the ``SRC_URI``
3491 of the recipe. Here is an example:
3492 ::
3493
3494 SRC_URI += "file://my_changes.patch"
3495
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003496Using a Development Shell
3497=========================
3498
3499When debugging certain commands or even when just editing packages,
3500``devshell`` can be a useful tool. When you invoke ``devshell``, all
3501tasks up to and including
3502:ref:`ref-tasks-patch` are run for the
3503specified target. Then, a new terminal is opened and you are placed in
3504``${``\ :term:`S`\ ``}``, the source
3505directory. In the new terminal, all the OpenEmbedded build-related
3506environment variables are still defined so you can use commands such as
3507``configure`` and ``make``. The commands execute just as if the
3508OpenEmbedded build system were executing them. Consequently, working
3509this way can be helpful when debugging a build or preparing software to
3510be used with the OpenEmbedded build system.
3511
3512Following is an example that uses ``devshell`` on a target named
3513``matchbox-desktop``:
3514::
3515
3516 $ bitbake matchbox-desktop -c devshell
3517
3518This command spawns a terminal with a shell prompt within the
3519OpenEmbedded build environment. The
3520:term:`OE_TERMINAL` variable
3521controls what type of shell is opened.
3522
3523For spawned terminals, the following occurs:
3524
3525- The ``PATH`` variable includes the cross-toolchain.
3526
3527- The ``pkgconfig`` variables find the correct ``.pc`` files.
3528
3529- The ``configure`` command finds the Yocto Project site files as well
3530 as any other necessary files.
3531
3532Within this environment, you can run configure or compile commands as if
3533they were being run by the OpenEmbedded build system itself. As noted
3534earlier, the working directory also automatically changes to the Source
3535Directory (:term:`S`).
3536
3537To manually run a specific task using ``devshell``, run the
3538corresponding ``run.*`` script in the
3539``${``\ :term:`WORKDIR`\ ``}/temp``
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003540directory (e.g., ``run.do_configure.``\ `pid`). If a task's script does
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003541not exist, which would be the case if the task was skipped by way of the
3542sstate cache, you can create the task by first running it outside of the
3543``devshell``:
3544::
3545
3546 $ bitbake -c task
3547
3548.. note::
3549
3550 - Execution of a task's ``run.*`` script and BitBake's execution of
3551 a task are identical. In other words, running the script re-runs
3552 the task just as it would be run using the ``bitbake -c`` command.
3553
3554 - Any ``run.*`` file that does not have a ``.pid`` extension is a
3555 symbolic link (symlink) to the most recent version of that file.
3556
3557Remember, that the ``devshell`` is a mechanism that allows you to get
3558into the BitBake task execution environment. And as such, all commands
3559must be called just as BitBake would call them. That means you need to
3560provide the appropriate options for cross-compilation and so forth as
3561applicable.
3562
3563When you are finished using ``devshell``, exit the shell or close the
3564terminal window.
3565
3566.. note::
3567
3568 - It is worth remembering that when using ``devshell`` you need to
3569 use the full compiler name such as ``arm-poky-linux-gnueabi-gcc``
3570 instead of just using ``gcc``. The same applies to other
3571 applications such as ``binutils``, ``libtool`` and so forth.
3572 BitBake sets up environment variables such as ``CC`` to assist
3573 applications, such as ``make`` to find the correct tools.
3574
3575 - It is also worth noting that ``devshell`` still works over X11
3576 forwarding and similar situations.
3577
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003578Using a Development Python Shell
3579================================
3580
3581Similar to working within a development shell as described in the
3582previous section, you can also spawn and work within an interactive
3583Python development shell. When debugging certain commands or even when
3584just editing packages, ``devpyshell`` can be a useful tool. When you
3585invoke ``devpyshell``, all tasks up to and including
3586:ref:`ref-tasks-patch` are run for the
3587specified target. Then a new terminal is opened. Additionally, key
3588Python objects and code are available in the same way they are to
3589BitBake tasks, in particular, the data store 'd'. So, commands such as
3590the following are useful when exploring the data store and running
3591functions:
3592::
3593
3594 pydevshell> d.getVar("STAGING_DIR")
3595 '/media/build1/poky/build/tmp/sysroots'
3596 pydevshell> d.getVar("STAGING_DIR")
3597 '${TMPDIR}/sysroots'
3598 pydevshell> d.setVar("FOO", "bar")
3599 pydevshell> d.getVar("FOO")
3600 'bar'
3601 pydevshell> d.delVar("FOO")
3602 pydevshell> d.getVar("FOO")
3603 pydevshell> bb.build.exec_func("do_unpack", d)
3604 pydevshell>
3605
3606The commands execute just as if the OpenEmbedded build
3607system were executing them. Consequently, working this way can be
3608helpful when debugging a build or preparing software to be used with the
3609OpenEmbedded build system.
3610
3611Following is an example that uses ``devpyshell`` on a target named
3612``matchbox-desktop``:
3613::
3614
3615 $ bitbake matchbox-desktop -c devpyshell
3616
3617This command spawns a terminal and places you in an interactive Python
3618interpreter within the OpenEmbedded build environment. The
3619:term:`OE_TERMINAL` variable
3620controls what type of shell is opened.
3621
3622When you are finished using ``devpyshell``, you can exit the shell
3623either by using Ctrl+d or closing the terminal window.
3624
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003625Building
3626========
3627
3628This section describes various build procedures. For example, the steps
3629needed for a simple build, a target that uses multiple configurations,
3630building an image for more than one machine, and so forth.
3631
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003632Building a Simple Image
3633-----------------------
3634
3635In the development environment, you need to build an image whenever you
3636change hardware support, add or change system libraries, or add or
3637change services that have dependencies. Several methods exist that allow
3638you to build an image within the Yocto Project. This section presents
3639the basic steps you need to build a simple image using BitBake from a
3640build host running Linux.
3641
3642.. note::
3643
3644 - For information on how to build an image using
3645 :term:`Toaster`, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003646 :doc:`/toaster-manual/index`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003647
3648 - For information on how to use ``devtool`` to build images, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003649 ":ref:`sdk-manual/extensible:using \`\`devtool\`\` in your sdk workflow`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003650 section in the Yocto Project Application Development and the
3651 Extensible Software Development Kit (eSDK) manual.
3652
3653 - For a quick example on how to build an image using the
3654 OpenEmbedded build system, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003655 :doc:`/brief-yoctoprojectqs/index` document.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003656
3657The build process creates an entire Linux distribution from source and
3658places it in your :term:`Build Directory` under
3659``tmp/deploy/images``. For detailed information on the build process
Andrew Geissler09209ee2020-12-13 08:44:15 -06003660using BitBake, see the ":ref:`overview-manual/concepts:images`" section in the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003661Yocto Project Overview and Concepts Manual.
3662
3663The following figure and list overviews the build process:
3664
3665.. image:: figures/bitbake-build-flow.png
3666 :align: center
3667
36681. *Set up Your Host Development System to Support Development Using the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003669 Yocto Project*: See the ":doc:`start`" section for options on how to get a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003670 build host ready to use the Yocto Project.
3671
36722. *Initialize the Build Environment:* Initialize the build environment
3673 by sourcing the build environment script (i.e.
3674 :ref:`structure-core-script`):
3675 ::
3676
3677 $ source oe-init-build-env [build_dir]
3678
3679 When you use the initialization script, the OpenEmbedded build system
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003680 uses ``build`` as the default :term:`Build Directory` in your current work
3681 directory. You can use a `build_dir` argument with the script to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003682 specify a different build directory.
3683
3684 .. note::
3685
3686 A common practice is to use a different Build Directory for
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003687 different targets. For example, ``~/build/x86`` for a ``qemux86``
3688 target, and ``~/build/arm`` for a ``qemuarm`` target.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003689
Andrew Geissler4c19ea12020-10-27 13:52:24 -050036903. *Make Sure Your* ``local.conf`` *File is Correct*: Ensure the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003691 ``conf/local.conf`` configuration file, which is found in the Build
3692 Directory, is set up how you want it. This file defines many aspects
3693 of the build environment including the target machine architecture
3694 through the ``MACHINE`` variable, the packaging format used during
3695 the build
3696 (:term:`PACKAGE_CLASSES`),
3697 and a centralized tarball download directory through the
3698 :term:`DL_DIR` variable.
3699
37004. *Build the Image:* Build the image using the ``bitbake`` command:
3701 ::
3702
3703 $ bitbake target
3704
3705 .. note::
3706
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003707 For information on BitBake, see the :doc:`bitbake:index`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003708
3709 The target is the name of the recipe you want to build. Common
3710 targets are the images in ``meta/recipes-core/images``,
3711 ``meta/recipes-sato/images``, and so forth all found in the
3712 :term:`Source Directory`. Or, the target
3713 can be the name of a recipe for a specific piece of software such as
3714 BusyBox. For more details about the images the OpenEmbedded build
3715 system supports, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003716 ":ref:`ref-manual/images:Images`" chapter in the Yocto
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003717 Project Reference Manual.
3718
3719 As an example, the following command builds the
3720 ``core-image-minimal`` image:
3721 ::
3722
3723 $ bitbake core-image-minimal
3724
3725 Once an
3726 image has been built, it often needs to be installed. The images and
3727 kernels built by the OpenEmbedded build system are placed in the
3728 Build Directory in ``tmp/deploy/images``. For information on how to
3729 run pre-built images such as ``qemux86`` and ``qemuarm``, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003730 :doc:`/sdk-manual/index` manual. For
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003731 information about how to install these images, see the documentation
3732 for your particular board or machine.
3733
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003734Building Images for Multiple Targets Using Multiple Configurations
3735------------------------------------------------------------------
3736
3737You can use a single ``bitbake`` command to build multiple images or
3738packages for different targets where each image or package requires a
3739different configuration (multiple configuration builds). The builds, in
3740this scenario, are sometimes referred to as "multiconfigs", and this
3741section uses that term throughout.
3742
3743This section describes how to set up for multiple configuration builds
3744and how to account for cross-build dependencies between the
3745multiconfigs.
3746
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003747Setting Up and Running a Multiple Configuration Build
3748~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3749
3750To accomplish a multiple configuration build, you must define each
3751target's configuration separately using a parallel configuration file in
3752the :term:`Build Directory`, and you
3753must follow a required file hierarchy. Additionally, you must enable the
3754multiple configuration builds in your ``local.conf`` file.
3755
3756Follow these steps to set up and execute multiple configuration builds:
3757
3758- *Create Separate Configuration Files*: You need to create a single
3759 configuration file for each build target (each multiconfig).
3760 Minimally, each configuration file must define the machine and the
3761 temporary directory BitBake uses for the build. Suggested practice
3762 dictates that you do not overlap the temporary directories used
3763 during the builds. However, it is possible that you can share the
3764 temporary directory
3765 (:term:`TMPDIR`). For example,
3766 consider a scenario with two different multiconfigs for the same
3767 :term:`MACHINE`: "qemux86" built
3768 for two distributions such as "poky" and "poky-lsb". In this case,
3769 you might want to use the same ``TMPDIR``.
3770
3771 Here is an example showing the minimal statements needed in a
3772 configuration file for a "qemux86" target whose temporary build
3773 directory is ``tmpmultix86``:
3774 ::
3775
3776 MACHINE = "qemux86"
3777 TMPDIR = "${TOPDIR}/tmpmultix86"
3778
3779 The location for these multiconfig configuration files is specific.
3780 They must reside in the current build directory in a sub-directory of
3781 ``conf`` named ``multiconfig``. Following is an example that defines
3782 two configuration files for the "x86" and "arm" multiconfigs:
3783
3784 .. image:: figures/multiconfig_files.png
3785 :align: center
3786
3787 The reason for this required file hierarchy is because the ``BBPATH``
3788 variable is not constructed until the layers are parsed.
3789 Consequently, using the configuration file as a pre-configuration
3790 file is not possible unless it is located in the current working
3791 directory.
3792
3793- *Add the BitBake Multi-configuration Variable to the Local
3794 Configuration File*: Use the
3795 :term:`BBMULTICONFIG`
3796 variable in your ``conf/local.conf`` configuration file to specify
3797 each multiconfig. Continuing with the example from the previous
3798 figure, the ``BBMULTICONFIG`` variable needs to enable two
3799 multiconfigs: "x86" and "arm" by specifying each configuration file:
3800 ::
3801
3802 BBMULTICONFIG = "x86 arm"
3803
3804 .. note::
3805
3806 A "default" configuration already exists by definition. This
3807 configuration is named: "" (i.e. empty string) and is defined by
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003808 the variables coming from your ``local.conf``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003809 file. Consequently, the previous example actually adds two
3810 additional configurations to your build: "arm" and "x86" along
3811 with "".
3812
3813- *Launch BitBake*: Use the following BitBake command form to launch
3814 the multiple configuration build:
3815 ::
3816
3817 $ bitbake [mc:multiconfigname:]target [[[mc:multiconfigname:]target] ... ]
3818
3819 For the example in this section, the following command applies:
3820 ::
3821
3822 $ bitbake mc:x86:core-image-minimal mc:arm:core-image-sato mc::core-image-base
3823
3824 The previous BitBake command builds a ``core-image-minimal`` image
3825 that is configured through the ``x86.conf`` configuration file, a
3826 ``core-image-sato`` image that is configured through the ``arm.conf``
3827 configuration file and a ``core-image-base`` that is configured
3828 through your ``local.conf`` configuration file.
3829
3830.. note::
3831
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003832 Support for multiple configuration builds in the Yocto Project &DISTRO;
3833 (&DISTRO_NAME;) Release does not include Shared State (sstate)
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003834 optimizations. Consequently, if a build uses the same object twice
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003835 in, for example, two different ``TMPDIR``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003836 directories, the build either loads from an existing sstate cache for
3837 that build at the start or builds the object fresh.
3838
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003839Enabling Multiple Configuration Build Dependencies
3840~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3841
3842Sometimes dependencies can exist between targets (multiconfigs) in a
3843multiple configuration build. For example, suppose that in order to
3844build a ``core-image-sato`` image for an "x86" multiconfig, the root
3845filesystem of an "arm" multiconfig must exist. This dependency is
3846essentially that the
3847:ref:`ref-tasks-image` task in the
3848``core-image-sato`` recipe depends on the completion of the
3849:ref:`ref-tasks-rootfs` task of the
3850``core-image-minimal`` recipe.
3851
3852To enable dependencies in a multiple configuration build, you must
3853declare the dependencies in the recipe using the following statement
3854form:
3855::
3856
3857 task_or_package[mcdepends] = "mc:from_multiconfig:to_multiconfig:recipe_name:task_on_which_to_depend"
3858
3859To better show how to use this statement, consider the example scenario
3860from the first paragraph of this section. The following statement needs
3861to be added to the recipe that builds the ``core-image-sato`` image:
3862::
3863
3864 do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_rootfs"
3865
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003866In this example, the `from_multiconfig` is "x86". The `to_multiconfig` is "arm". The
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003867task on which the ``do_image`` task in the recipe depends is the
3868``do_rootfs`` task from the ``core-image-minimal`` recipe associated
3869with the "arm" multiconfig.
3870
3871Once you set up this dependency, you can build the "x86" multiconfig
3872using a BitBake command as follows:
3873::
3874
3875 $ bitbake mc:x86:core-image-sato
3876
3877This command executes all the tasks needed to create the
3878``core-image-sato`` image for the "x86" multiconfig. Because of the
3879dependency, BitBake also executes through the ``do_rootfs`` task for the
3880"arm" multiconfig build.
3881
3882Having a recipe depend on the root filesystem of another build might not
3883seem that useful. Consider this change to the statement in the
3884``core-image-sato`` recipe:
3885::
3886
3887 do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_image"
3888
3889In this case, BitBake must
3890create the ``core-image-minimal`` image for the "arm" build since the
3891"x86" build depends on it.
3892
3893Because "x86" and "arm" are enabled for multiple configuration builds
3894and have separate configuration files, BitBake places the artifacts for
3895each build in the respective temporary build directories (i.e.
3896:term:`TMPDIR`).
3897
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003898Building an Initial RAM Filesystem (initramfs) Image
3899----------------------------------------------------
3900
3901An initial RAM filesystem (initramfs) image provides a temporary root
3902filesystem used for early system initialization (e.g. loading of modules
3903needed to locate and mount the "real" root filesystem).
3904
3905.. note::
3906
3907 The initramfs image is the successor of initial RAM disk (initrd). It
3908 is a "copy in and out" (cpio) archive of the initial filesystem that
3909 gets loaded into memory during the Linux startup process. Because
3910 Linux uses the contents of the archive during initialization, the
3911 initramfs image needs to contain all of the device drivers and tools
3912 needed to mount the final root filesystem.
3913
3914Follow these steps to create an initramfs image:
3915
39161. *Create the initramfs Image Recipe:* You can reference the
3917 ``core-image-minimal-initramfs.bb`` recipe found in the
3918 ``meta/recipes-core`` directory of the :term:`Source Directory`
3919 as an example
3920 from which to work.
3921
39222. *Decide if You Need to Bundle the initramfs Image Into the Kernel
3923 Image:* If you want the initramfs image that is built to be bundled
3924 in with the kernel image, set the
3925 :term:`INITRAMFS_IMAGE_BUNDLE`
3926 variable to "1" in your ``local.conf`` configuration file and set the
3927 :term:`INITRAMFS_IMAGE`
3928 variable in the recipe that builds the kernel image.
3929
3930 .. note::
3931
3932 It is recommended that you do bundle the initramfs image with the
3933 kernel image to avoid circular dependencies between the kernel
3934 recipe and the initramfs recipe should the initramfs image include
3935 kernel modules.
3936
3937 Setting the ``INITRAMFS_IMAGE_BUNDLE`` flag causes the initramfs
3938 image to be unpacked into the ``${B}/usr/`` directory. The unpacked
3939 initramfs image is then passed to the kernel's ``Makefile`` using the
3940 :term:`CONFIG_INITRAMFS_SOURCE`
3941 variable, allowing the initramfs image to be built into the kernel
3942 normally.
3943
3944 .. note::
3945
3946 If you choose to not bundle the initramfs image with the kernel
3947 image, you are essentially using an
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003948 `Initial RAM Disk (initrd) <https://en.wikipedia.org/wiki/Initrd>`__.
3949 Creating an initrd is handled primarily through the :term:`INITRD_IMAGE`,
3950 ``INITRD_LIVE``, and ``INITRD_IMAGE_LIVE`` variables. For more
3951 information, see the :ref:`ref-classes-image-live` file.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003952
39533. *Optionally Add Items to the initramfs Image Through the initramfs
3954 Image Recipe:* If you add items to the initramfs image by way of its
3955 recipe, you should use
3956 :term:`PACKAGE_INSTALL`
3957 rather than
3958 :term:`IMAGE_INSTALL`.
3959 ``PACKAGE_INSTALL`` gives more direct control of what is added to the
3960 image as compared to the defaults you might not necessarily want that
3961 are set by the :ref:`image <ref-classes-image>`
3962 or :ref:`core-image <ref-classes-core-image>`
3963 classes.
3964
39654. *Build the Kernel Image and the initramfs Image:* Build your kernel
3966 image using BitBake. Because the initramfs image recipe is a
3967 dependency of the kernel image, the initramfs image is built as well
3968 and bundled with the kernel image if you used the
3969 :term:`INITRAMFS_IMAGE_BUNDLE`
3970 variable described earlier.
3971
3972Building a Tiny System
3973----------------------
3974
3975Very small distributions have some significant advantages such as
3976requiring less on-die or in-package memory (cheaper), better performance
3977through efficient cache usage, lower power requirements due to less
3978memory, faster boot times, and reduced development overhead. Some
3979real-world examples where a very small distribution gives you distinct
3980advantages are digital cameras, medical devices, and small headless
3981systems.
3982
3983This section presents information that shows you how you can trim your
3984distribution to even smaller sizes than the ``poky-tiny`` distribution,
3985which is around 5 Mbytes, that can be built out-of-the-box using the
3986Yocto Project.
3987
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003988Tiny System Overview
3989~~~~~~~~~~~~~~~~~~~~
3990
3991The following list presents the overall steps you need to consider and
3992perform to create distributions with smaller root filesystems, achieve
3993faster boot times, maintain your critical functionality, and avoid
3994initial RAM disks:
3995
3996- `Determine your goals and guiding
3997 principles. <#goals-and-guiding-principles>`__
3998
3999- `Understand what contributes to your image
4000 size. <#understand-what-gives-your-image-size>`__
4001
4002- `Reduce the size of the root
4003 filesystem. <#trim-the-root-filesystem>`__
4004
4005- `Reduce the size of the kernel. <#trim-the-kernel>`__
4006
4007- `Eliminate packaging
4008 requirements. <#remove-package-management-requirements>`__
4009
4010- `Look for other ways to minimize
4011 size. <#look-for-other-ways-to-minimize-size>`__
4012
4013- `Iterate on the process. <#iterate-on-the-process>`__
4014
4015Goals and Guiding Principles
4016~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4017
4018Before you can reach your destination, you need to know where you are
4019going. Here is an example list that you can use as a guide when creating
4020very small distributions:
4021
4022- Determine how much space you need (e.g. a kernel that is 1 Mbyte or
4023 less and a root filesystem that is 3 Mbytes or less).
4024
4025- Find the areas that are currently taking 90% of the space and
4026 concentrate on reducing those areas.
4027
4028- Do not create any difficult "hacks" to achieve your goals.
4029
4030- Leverage the device-specific options.
4031
4032- Work in a separate layer so that you keep changes isolated. For
4033 information on how to create layers, see the "`Understanding and
4034 Creating Layers <#understanding-and-creating-layers>`__" section.
4035
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004036Understand What Contributes to Your Image Size
4037~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4038
4039It is easiest to have something to start with when creating your own
4040distribution. You can use the Yocto Project out-of-the-box to create the
4041``poky-tiny`` distribution. Ultimately, you will want to make changes in
4042your own distribution that are likely modeled after ``poky-tiny``.
4043
4044.. note::
4045
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004046 To use ``poky-tiny`` in your build, set the ``DISTRO`` variable in your
4047 ``local.conf`` file to "poky-tiny" as described in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06004048 ":ref:`dev-manual/common-tasks:creating your own distribution`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004049 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004050
4051Understanding some memory concepts will help you reduce the system size.
4052Memory consists of static, dynamic, and temporary memory. Static memory
4053is the TEXT (code), DATA (initialized data in the code), and BSS
4054(uninitialized data) sections. Dynamic memory represents memory that is
4055allocated at runtime: stacks, hash tables, and so forth. Temporary
4056memory is recovered after the boot process. This memory consists of
4057memory used for decompressing the kernel and for the ``__init__``
4058functions.
4059
4060To help you see where you currently are with kernel and root filesystem
4061sizes, you can use two tools found in the :term:`Source Directory`
4062in the
4063``scripts/tiny/`` directory:
4064
4065- ``ksize.py``: Reports component sizes for the kernel build objects.
4066
4067- ``dirsize.py``: Reports component sizes for the root filesystem.
4068
4069This next tool and command help you organize configuration fragments and
4070view file dependencies in a human-readable form:
4071
4072- ``merge_config.sh``: Helps you manage configuration files and
4073 fragments within the kernel. With this tool, you can merge individual
4074 configuration fragments together. The tool allows you to make
4075 overrides and warns you of any missing configuration options. The
4076 tool is ideal for allowing you to iterate on configurations, create
4077 minimal configurations, and create configuration files for different
4078 machines without having to duplicate your process.
4079
4080 The ``merge_config.sh`` script is part of the Linux Yocto kernel Git
4081 repositories (i.e. ``linux-yocto-3.14``, ``linux-yocto-3.10``,
4082 ``linux-yocto-3.8``, and so forth) in the ``scripts/kconfig``
4083 directory.
4084
4085 For more information on configuration fragments, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06004086 ":ref:`kernel-dev/common:creating configuration fragments`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004087 section in the Yocto Project Linux Kernel Development Manual.
4088
4089- ``bitbake -u taskexp -g bitbake_target``: Using the BitBake command
4090 with these options brings up a Dependency Explorer from which you can
4091 view file dependencies. Understanding these dependencies allows you
4092 to make informed decisions when cutting out various pieces of the
4093 kernel and root filesystem.
4094
4095Trim the Root Filesystem
4096~~~~~~~~~~~~~~~~~~~~~~~~
4097
4098The root filesystem is made up of packages for booting, libraries, and
4099applications. To change things, you can configure how the packaging
4100happens, which changes the way you build them. You can also modify the
4101filesystem itself or select a different filesystem.
4102
4103First, find out what is hogging your root filesystem by running the
4104``dirsize.py`` script from your root directory:
4105::
4106
4107 $ cd root-directory-of-image
4108 $ dirsize.py 100000 > dirsize-100k.log
4109 $ cat dirsize-100k.log
4110
4111You can apply a filter to the script to ignore files
4112under a certain size. The previous example filters out any files below
4113100 Kbytes. The sizes reported by the tool are uncompressed, and thus
4114will be smaller by a relatively constant factor in a compressed root
4115filesystem. When you examine your log file, you can focus on areas of
4116the root filesystem that take up large amounts of memory.
4117
4118You need to be sure that what you eliminate does not cripple the
4119functionality you need. One way to see how packages relate to each other
4120is by using the Dependency Explorer UI with the BitBake command:
4121::
4122
4123 $ cd image-directory
4124 $ bitbake -u taskexp -g image
4125
4126Use the interface to
4127select potential packages you wish to eliminate and see their dependency
4128relationships.
4129
4130When deciding how to reduce the size, get rid of packages that result in
4131minimal impact on the feature set. For example, you might not need a VGA
4132display. Or, you might be able to get by with ``devtmpfs`` and ``mdev``
4133instead of ``udev``.
4134
4135Use your ``local.conf`` file to make changes. For example, to eliminate
4136``udev`` and ``glib``, set the following in the local configuration
4137file:
4138::
4139
4140 VIRTUAL-RUNTIME_dev_manager = ""
4141
4142Finally, you should consider exactly the type of root filesystem you
4143need to meet your needs while also reducing its size. For example,
4144consider ``cramfs``, ``squashfs``, ``ubifs``, ``ext2``, or an
4145``initramfs`` using ``initramfs``. Be aware that ``ext3`` requires a 1
4146Mbyte journal. If you are okay with running read-only, you do not need
4147this journal.
4148
4149.. note::
4150
4151 After each round of elimination, you need to rebuild your system and
4152 then use the tools to see the effects of your reductions.
4153
4154Trim the Kernel
4155~~~~~~~~~~~~~~~
4156
4157The kernel is built by including policies for hardware-independent
4158aspects. What subsystems do you enable? For what architecture are you
4159building? Which drivers do you build by default?
4160
4161.. note::
4162
4163 You can modify the kernel source if you want to help with boot time.
4164
4165Run the ``ksize.py`` script from the top-level Linux build directory to
4166get an idea of what is making up the kernel:
4167::
4168
4169 $ cd top-level-linux-build-directory
4170 $ ksize.py > ksize.log
4171 $ cat ksize.log
4172
4173When you examine the log, you will see how much space is taken up with
4174the built-in ``.o`` files for drivers, networking, core kernel files,
4175filesystem, sound, and so forth. The sizes reported by the tool are
4176uncompressed, and thus will be smaller by a relatively constant factor
4177in a compressed kernel image. Look to reduce the areas that are large
4178and taking up around the "90% rule."
4179
4180To examine, or drill down, into any particular area, use the ``-d``
4181option with the script:
4182::
4183
4184 $ ksize.py -d > ksize.log
4185
4186Using this option
4187breaks out the individual file information for each area of the kernel
4188(e.g. drivers, networking, and so forth).
4189
4190Use your log file to see what you can eliminate from the kernel based on
4191features you can let go. For example, if you are not going to need
4192sound, you do not need any drivers that support sound.
4193
4194After figuring out what to eliminate, you need to reconfigure the kernel
4195to reflect those changes during the next build. You could run
4196``menuconfig`` and make all your changes at once. However, that makes it
4197difficult to see the effects of your individual eliminations and also
4198makes it difficult to replicate the changes for perhaps another target
4199device. A better method is to start with no configurations using
4200``allnoconfig``, create configuration fragments for individual changes,
4201and then manage the fragments into a single configuration file using
4202``merge_config.sh``. The tool makes it easy for you to iterate using the
4203configuration change and build cycle.
4204
4205Each time you make configuration changes, you need to rebuild the kernel
4206and check to see what impact your changes had on the overall size.
4207
4208Remove Package Management Requirements
4209~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4210
4211Packaging requirements add size to the image. One way to reduce the size
4212of the image is to remove all the packaging requirements from the image.
4213This reduction includes both removing the package manager and its unique
4214dependencies as well as removing the package management data itself.
4215
4216To eliminate all the packaging requirements for an image, be sure that
4217"package-management" is not part of your
4218:term:`IMAGE_FEATURES`
4219statement for the image. When you remove this feature, you are removing
4220the package manager as well as its dependencies from the root
4221filesystem.
4222
4223Look for Other Ways to Minimize Size
4224~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4225
4226Depending on your particular circumstances, other areas that you can
4227trim likely exist. The key to finding these areas is through tools and
4228methods described here combined with experimentation and iteration. Here
4229are a couple of areas to experiment with:
4230
4231- ``glibc``: In general, follow this process:
4232
4233 1. Remove ``glibc`` features from
4234 :term:`DISTRO_FEATURES`
4235 that you think you do not need.
4236
4237 2. Build your distribution.
4238
4239 3. If the build fails due to missing symbols in a package, determine
4240 if you can reconfigure the package to not need those features. For
4241 example, change the configuration to not support wide character
4242 support as is done for ``ncurses``. Or, if support for those
4243 characters is needed, determine what ``glibc`` features provide
4244 the support and restore the configuration.
4245
4246 4. Rebuild and repeat the process.
4247
4248- ``busybox``: For BusyBox, use a process similar as described for
4249 ``glibc``. A difference is you will need to boot the resulting system
4250 to see if you are able to do everything you expect from the running
4251 system. You need to be sure to integrate configuration fragments into
4252 Busybox because BusyBox handles its own core features and then allows
4253 you to add configuration fragments on top.
4254
4255Iterate on the Process
4256~~~~~~~~~~~~~~~~~~~~~~
4257
4258If you have not reached your goals on system size, you need to iterate
4259on the process. The process is the same. Use the tools and see just what
4260is taking up 90% of the root filesystem and the kernel. Decide what you
4261can eliminate without limiting your device beyond what you need.
4262
4263Depending on your system, a good place to look might be Busybox, which
4264provides a stripped down version of Unix tools in a single, executable
4265file. You might be able to drop virtual terminal services or perhaps
4266ipv6.
4267
4268Building Images for More than One Machine
4269-----------------------------------------
4270
4271A common scenario developers face is creating images for several
4272different machines that use the same software environment. In this
4273situation, it is tempting to set the tunings and optimization flags for
4274each build specifically for the targeted hardware (i.e. "maxing out" the
4275tunings). Doing so can considerably add to build times and package feed
4276maintenance collectively for the machines. For example, selecting tunes
4277that are extremely specific to a CPU core used in a system might enable
4278some micro optimizations in GCC for that particular system but would
4279otherwise not gain you much of a performance difference across the other
4280systems as compared to using a more general tuning across all the builds
4281(e.g. setting :term:`DEFAULTTUNE`
4282specifically for each machine's build). Rather than "max out" each
4283build's tunings, you can take steps that cause the OpenEmbedded build
4284system to reuse software across the various machines where it makes
4285sense.
4286
4287If build speed and package feed maintenance are considerations, you
4288should consider the points in this section that can help you optimize
4289your tunings to best consider build times and package feed maintenance.
4290
4291- *Share the Build Directory:* If at all possible, share the
4292 :term:`TMPDIR` across builds. The
4293 Yocto Project supports switching between different
4294 :term:`MACHINE` values in the same
4295 ``TMPDIR``. This practice is well supported and regularly used by
4296 developers when building for multiple machines. When you use the same
4297 ``TMPDIR`` for multiple machine builds, the OpenEmbedded build system
4298 can reuse the existing native and often cross-recipes for multiple
4299 machines. Thus, build time decreases.
4300
4301 .. note::
4302
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004303 If :term:`DISTRO` settings change or fundamental configuration settings
4304 such as the filesystem layout, you need to work with a clean ``TMPDIR``.
4305 Sharing ``TMPDIR`` under these circumstances might work but since it is
4306 not guaranteed, you should use a clean ``TMPDIR``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004307
4308- *Enable the Appropriate Package Architecture:* By default, the
4309 OpenEmbedded build system enables three levels of package
4310 architectures: "all", "tune" or "package", and "machine". Any given
4311 recipe usually selects one of these package architectures (types) for
4312 its output. Depending for what a given recipe creates packages,
4313 making sure you enable the appropriate package architecture can
4314 directly impact the build time.
4315
4316 A recipe that just generates scripts can enable "all" architecture
4317 because there are no binaries to build. To specifically enable "all"
4318 architecture, be sure your recipe inherits the
4319 :ref:`allarch <ref-classes-allarch>` class.
4320 This class is useful for "all" architectures because it configures
4321 many variables so packages can be used across multiple architectures.
4322
4323 If your recipe needs to generate packages that are machine-specific
4324 or when one of the build or runtime dependencies is already
4325 machine-architecture dependent, which makes your recipe also
4326 machine-architecture dependent, make sure your recipe enables the
4327 "machine" package architecture through the
4328 :term:`MACHINE_ARCH`
4329 variable:
4330 ::
4331
4332 PACKAGE_ARCH = "${MACHINE_ARCH}"
4333
4334 When you do not
4335 specifically enable a package architecture through the
4336 :term:`PACKAGE_ARCH`, The
4337 OpenEmbedded build system defaults to the
4338 :term:`TUNE_PKGARCH` setting:
4339 ::
4340
4341 PACKAGE_ARCH = "${TUNE_PKGARCH}"
4342
4343- *Choose a Generic Tuning File if Possible:* Some tunes are more
4344 generic and can run on multiple targets (e.g. an ``armv5`` set of
4345 packages could run on ``armv6`` and ``armv7`` processors in most
4346 cases). Similarly, ``i486`` binaries could work on ``i586`` and
4347 higher processors. You should realize, however, that advances on
4348 newer processor versions would not be used.
4349
4350 If you select the same tune for several different machines, the
4351 OpenEmbedded build system reuses software previously built, thus
4352 speeding up the overall build time. Realize that even though a new
4353 sysroot for each machine is generated, the software is not recompiled
4354 and only one package feed exists.
4355
4356- *Manage Granular Level Packaging:* Sometimes cases exist where
4357 injecting another level of package architecture beyond the three
4358 higher levels noted earlier can be useful. For example, consider how
4359 NXP (formerly Freescale) allows for the easy reuse of binary packages
4360 in their layer
Andrew Geissler09209ee2020-12-13 08:44:15 -06004361 :yocto_git:`meta-freescale </meta-freescale/>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004362 In this example, the
Andrew Geissler09209ee2020-12-13 08:44:15 -06004363 :yocto_git:`fsl-dynamic-packagearch </meta-freescale/tree/classes/fsl-dynamic-packagearch.bbclass>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004364 class shares GPU packages for i.MX53 boards because all boards share
4365 the AMD GPU. The i.MX6-based boards can do the same because all
4366 boards share the Vivante GPU. This class inspects the BitBake
4367 datastore to identify if the package provides or depends on one of
4368 the sub-architecture values. If so, the class sets the
4369 :term:`PACKAGE_ARCH` value
4370 based on the ``MACHINE_SUBARCH`` value. If the package does not
4371 provide or depend on one of the sub-architecture values but it
4372 matches a value in the machine-specific filter, it sets
4373 :term:`MACHINE_ARCH`. This
4374 behavior reduces the number of packages built and saves build time by
4375 reusing binaries.
4376
4377- *Use Tools to Debug Issues:* Sometimes you can run into situations
4378 where software is being rebuilt when you think it should not be. For
4379 example, the OpenEmbedded build system might not be using shared
4380 state between machines when you think it should be. These types of
4381 situations are usually due to references to machine-specific
4382 variables such as :term:`MACHINE`,
4383 :term:`SERIAL_CONSOLES`,
4384 :term:`XSERVER`,
4385 :term:`MACHINE_FEATURES`,
4386 and so forth in code that is supposed to only be tune-specific or
4387 when the recipe depends
4388 (:term:`DEPENDS`,
4389 :term:`RDEPENDS`,
4390 :term:`RRECOMMENDS`,
4391 :term:`RSUGGESTS`, and so forth)
4392 on some other recipe that already has
4393 :term:`PACKAGE_ARCH` defined
4394 as "${MACHINE_ARCH}".
4395
4396 .. note::
4397
4398 Patches to fix any issues identified are most welcome as these
4399 issues occasionally do occur.
4400
4401 For such cases, you can use some tools to help you sort out the
4402 situation:
4403
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004404 - ``state-diff-machines.sh``*:* You can find this tool in the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004405 ``scripts`` directory of the Source Repositories. See the comments
4406 in the script for information on how to use the tool.
4407
4408 - *BitBake's "-S printdiff" Option:* Using this option causes
4409 BitBake to try to establish the closest signature match it can
4410 (e.g. in the shared state cache) and then run ``bitbake-diffsigs``
4411 over the matches to determine the stamps and delta where these two
4412 stamp trees diverge.
4413
4414Building Software from an External Source
4415-----------------------------------------
4416
4417By default, the OpenEmbedded build system uses the
4418:term:`Build Directory` when building source
4419code. The build process involves fetching the source files, unpacking
4420them, and then patching them if necessary before the build takes place.
4421
4422Situations exist where you might want to build software from source
4423files that are external to and thus outside of the OpenEmbedded build
4424system. For example, suppose you have a project that includes a new BSP
4425with a heavily customized kernel. And, you want to minimize exposing the
4426build system to the development team so that they can focus on their
4427project and maintain everyone's workflow as much as possible. In this
4428case, you want a kernel source directory on the development machine
4429where the development occurs. You want the recipe's
4430:term:`SRC_URI` variable to point to
4431the external directory and use it as is, not copy it.
4432
4433To build from software that comes from an external source, all you need
4434to do is inherit the
4435:ref:`externalsrc <ref-classes-externalsrc>` class
4436and then set the
4437:term:`EXTERNALSRC` variable to
4438point to your external source code. Here are the statements to put in
4439your ``local.conf`` file:
4440::
4441
4442 INHERIT += "externalsrc"
4443 EXTERNALSRC_pn-myrecipe = "path-to-your-source-tree"
4444
4445This next example shows how to accomplish the same thing by setting
4446``EXTERNALSRC`` in the recipe itself or in the recipe's append file:
4447::
4448
4449 EXTERNALSRC = "path"
4450 EXTERNALSRC_BUILD = "path"
4451
4452.. note::
4453
4454 In order for these settings to take effect, you must globally or
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004455 locally inherit the :ref:`externalsrc <ref-classes-externalsrc>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004456 class.
4457
4458By default, ``externalsrc.bbclass`` builds the source code in a
4459directory separate from the external source directory as specified by
4460:term:`EXTERNALSRC`. If you need
4461to have the source built in the same directory in which it resides, or
4462some other nominated directory, you can set
4463:term:`EXTERNALSRC_BUILD`
4464to point to that directory:
4465::
4466
4467 EXTERNALSRC_BUILD_pn-myrecipe = "path-to-your-source-tree"
4468
4469Replicating a Build Offline
4470---------------------------
4471
4472It can be useful to take a "snapshot" of upstream sources used in a
4473build and then use that "snapshot" later to replicate the build offline.
4474To do so, you need to first prepare and populate your downloads
4475directory your "snapshot" of files. Once your downloads directory is
4476ready, you can use it at any time and from any machine to replicate your
4477build.
4478
4479Follow these steps to populate your Downloads directory:
4480
44811. *Create a Clean Downloads Directory:* Start with an empty downloads
4482 directory (:term:`DL_DIR`). You
4483 start with an empty downloads directory by either removing the files
4484 in the existing directory or by setting ``DL_DIR`` to point to either
4485 an empty location or one that does not yet exist.
4486
44872. *Generate Tarballs of the Source Git Repositories:* Edit your
4488 ``local.conf`` configuration file as follows:
4489 ::
4490
4491 DL_DIR = "/home/your-download-dir/"
4492 BB_GENERATE_MIRROR_TARBALLS = "1"
4493
4494 During
4495 the fetch process in the next step, BitBake gathers the source files
4496 and creates tarballs in the directory pointed to by ``DL_DIR``. See
4497 the
4498 :term:`BB_GENERATE_MIRROR_TARBALLS`
4499 variable for more information.
4500
45013. *Populate Your Downloads Directory Without Building:* Use BitBake to
4502 fetch your sources but inhibit the build:
4503 ::
4504
4505 $ bitbake target --runonly=fetch
4506
4507 The downloads directory (i.e. ``${DL_DIR}``) now has
4508 a "snapshot" of the source files in the form of tarballs, which can
4509 be used for the build.
4510
45114. *Optionally Remove Any Git or other SCM Subdirectories From the
4512 Downloads Directory:* If you want, you can clean up your downloads
4513 directory by removing any Git or other Source Control Management
4514 (SCM) subdirectories such as ``${DL_DIR}/git2/*``. The tarballs
4515 already contain these subdirectories.
4516
4517Once your downloads directory has everything it needs regarding source
4518files, you can create your "own-mirror" and build your target.
4519Understand that you can use the files to build the target offline from
4520any machine and at any time.
4521
4522Follow these steps to build your target using the files in the downloads
4523directory:
4524
45251. *Using Local Files Only:* Inside your ``local.conf`` file, add the
4526 :term:`SOURCE_MIRROR_URL`
4527 variable, inherit the
4528 :ref:`own-mirrors <ref-classes-own-mirrors>`
4529 class, and use the
4530 :term:`bitbake:BB_NO_NETWORK`
4531 variable to your ``local.conf``.
4532 ::
4533
4534 SOURCE_MIRROR_URL ?= "file:///home/your-download-dir/"
4535 INHERIT += "own-mirrors"
4536 BB_NO_NETWORK = "1"
4537
4538 The ``SOURCE_MIRROR_URL`` and ``own-mirror``
4539 class set up the system to use the downloads directory as your "own
4540 mirror". Using the ``BB_NO_NETWORK`` variable makes sure that
4541 BitBake's fetching process in step 3 stays local, which means files
4542 from your "own-mirror" are used.
4543
45442. *Start With a Clean Build:* You can start with a clean build by
4545 removing the
4546 ``${``\ :term:`TMPDIR`\ ``}``
4547 directory or using a new :term:`Build Directory`.
4548
45493. *Build Your Target:* Use BitBake to build your target:
4550 ::
4551
4552 $ bitbake target
4553
4554 The build completes using the known local "snapshot" of source
4555 files from your mirror. The resulting tarballs for your "snapshot" of
4556 source files are in the downloads directory.
4557
4558 .. note::
4559
4560 The offline build does not work if recipes attempt to find the
4561 latest version of software by setting
4562 :term:`SRCREV` to
4563 ``${``\ :term:`AUTOREV`\ ``}``:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004564 ::
4565
4566 SRCREV = "${AUTOREV}"
4567
4568 When a recipe sets ``SRCREV`` to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004569 ``${AUTOREV}``, the build system accesses the network in an
4570 attempt to determine the latest version of software from the SCM.
4571 Typically, recipes that use ``AUTOREV`` are custom or modified
4572 recipes. Recipes that reside in public repositories usually do not
4573 use ``AUTOREV``.
4574
4575 If you do have recipes that use ``AUTOREV``, you can take steps to
4576 still use the recipes in an offline build. Do the following:
4577
4578 1. Use a configuration generated by enabling `build
4579 history <#maintaining-build-output-quality>`__.
4580
4581 2. Use the ``buildhistory-collect-srcrevs`` command to collect the
4582 stored ``SRCREV`` values from the build's history. For more
4583 information on collecting these values, see the "`Build History
4584 Package Information <#build-history-package-information>`__"
4585 section.
4586
4587 3. Once you have the correct source revisions, you can modify
4588 those recipes to to set ``SRCREV`` to specific versions of the
4589 software.
4590
4591Speeding Up a Build
4592===================
4593
4594Build time can be an issue. By default, the build system uses simple
4595controls to try and maximize build efficiency. In general, the default
4596settings for all the following variables result in the most efficient
4597build times when dealing with single socket systems (i.e. a single CPU).
4598If you have multiple CPUs, you might try increasing the default values
4599to gain more speed. See the descriptions in the glossary for each
4600variable for more information:
4601
4602- :term:`BB_NUMBER_THREADS`:
4603 The maximum number of threads BitBake simultaneously executes.
4604
4605- :term:`bitbake:BB_NUMBER_PARSE_THREADS`:
4606 The number of threads BitBake uses during parsing.
4607
4608- :term:`PARALLEL_MAKE`: Extra
4609 options passed to the ``make`` command during the
4610 :ref:`ref-tasks-compile` task in
4611 order to specify parallel compilation on the local build host.
4612
4613- :term:`PARALLEL_MAKEINST`:
4614 Extra options passed to the ``make`` command during the
4615 :ref:`ref-tasks-install` task in
4616 order to specify parallel installation on the local build host.
4617
4618As mentioned, these variables all scale to the number of processor cores
4619available on the build system. For single socket systems, this
4620auto-scaling ensures that the build system fundamentally takes advantage
4621of potential parallel operations during the build based on the build
4622machine's capabilities.
4623
4624Following are additional factors that can affect build speed:
4625
4626- File system type: The file system type that the build is being
4627 performed on can also influence performance. Using ``ext4`` is
4628 recommended as compared to ``ext2`` and ``ext3`` due to ``ext4``
4629 improved features such as extents.
4630
4631- Disabling the updating of access time using ``noatime``: The
4632 ``noatime`` mount option prevents the build system from updating file
4633 and directory access times.
4634
4635- Setting a longer commit: Using the "commit=" mount option increases
4636 the interval in seconds between disk cache writes. Changing this
4637 interval from the five second default to something longer increases
4638 the risk of data loss but decreases the need to write to the disk,
4639 thus increasing the build performance.
4640
4641- Choosing the packaging backend: Of the available packaging backends,
4642 IPK is the fastest. Additionally, selecting a singular packaging
4643 backend also helps.
4644
4645- Using ``tmpfs`` for :term:`TMPDIR`
4646 as a temporary file system: While this can help speed up the build,
4647 the benefits are limited due to the compiler using ``-pipe``. The
4648 build system goes to some lengths to avoid ``sync()`` calls into the
4649 file system on the principle that if there was a significant failure,
4650 the :term:`Build Directory`
4651 contents could easily be rebuilt.
4652
4653- Inheriting the
4654 :ref:`rm_work <ref-classes-rm-work>` class:
4655 Inheriting this class has shown to speed up builds due to
4656 significantly lower amounts of data stored in the data cache as well
4657 as on disk. Inheriting this class also makes cleanup of
4658 :term:`TMPDIR` faster, at the
4659 expense of being easily able to dive into the source code. File
4660 system maintainers have recommended that the fastest way to clean up
4661 large numbers of files is to reformat partitions rather than delete
4662 files due to the linear nature of partitions. This, of course,
4663 assumes you structure the disk partitions and file systems in a way
4664 that this is practical.
4665
4666Aside from the previous list, you should keep some trade offs in mind
4667that can help you speed up the build:
4668
4669- Remove items from
4670 :term:`DISTRO_FEATURES`
4671 that you might not need.
4672
4673- Exclude debug symbols and other debug information: If you do not need
4674 these symbols and other debug information, disabling the ``*-dbg``
4675 package generation can speed up the build. You can disable this
4676 generation by setting the
4677 :term:`INHIBIT_PACKAGE_DEBUG_SPLIT`
4678 variable to "1".
4679
4680- Disable static library generation for recipes derived from
4681 ``autoconf`` or ``libtool``: Following is an example showing how to
4682 disable static libraries and still provide an override to handle
4683 exceptions:
4684 ::
4685
4686 STATICLIBCONF = "--disable-static"
4687 STATICLIBCONF_sqlite3-native = ""
4688 EXTRA_OECONF += "${STATICLIBCONF}"
4689
4690 .. note::
4691
4692 - Some recipes need static libraries in order to work correctly
4693 (e.g. ``pseudo-native`` needs ``sqlite3-native``). Overrides,
4694 as in the previous example, account for these kinds of
4695 exceptions.
4696
4697 - Some packages have packaging code that assumes the presence of
4698 the static libraries. If so, you might need to exclude them as
4699 well.
4700
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004701Working With Libraries
4702======================
4703
4704Libraries are an integral part of your system. This section describes
4705some common practices you might find helpful when working with libraries
4706to build your system:
4707
4708- `How to include static library
4709 files <#including-static-library-files>`__
4710
4711- `How to use the Multilib feature to combine multiple versions of
4712 library files into a single
4713 image <#combining-multiple-versions-library-files-into-one-image>`__
4714
4715- `How to install multiple versions of the same library in parallel on
4716 the same
4717 system <#installing-multiple-versions-of-the-same-library>`__
4718
4719Including Static Library Files
4720------------------------------
4721
4722If you are building a library and the library offers static linking, you
4723can control which static library files (``*.a`` files) get included in
4724the built library.
4725
4726The :term:`PACKAGES` and
4727:term:`FILES_* <FILES>` variables in the
4728``meta/conf/bitbake.conf`` configuration file define how files installed
4729by the ``do_install`` task are packaged. By default, the ``PACKAGES``
4730variable includes ``${PN}-staticdev``, which represents all static
4731library files.
4732
4733.. note::
4734
4735 Some previously released versions of the Yocto Project defined the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004736 static library files through ``${PN}-dev``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004737
4738Following is part of the BitBake configuration file, where you can see
4739how the static library files are defined:
4740::
4741
4742 PACKAGE_BEFORE_PN ?= ""
4743 PACKAGES = "${PN}-dbg ${PN}-staticdev ${PN}-dev ${PN}-doc ${PN}-locale ${PACKAGE_BEFORE_PN} ${PN}"
4744 PACKAGES_DYNAMIC = "^${PN}-locale-.*"
4745 FILES = ""
4746
4747 FILES_${PN} = "${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*${SOLIBS} \
4748 ${sysconfdir} ${sharedstatedir} ${localstatedir} \
4749 ${base_bindir}/* ${base_sbindir}/* \
4750 ${base_libdir}/*${SOLIBS} \
4751 ${base_prefix}/lib/udev/rules.d ${prefix}/lib/udev/rules.d \
4752 ${datadir}/${BPN} ${libdir}/${BPN}/* \
4753 ${datadir}/pixmaps ${datadir}/applications \
4754 ${datadir}/idl ${datadir}/omf ${datadir}/sounds \
4755 ${libdir}/bonobo/servers"
4756
4757 FILES_${PN}-bin = "${bindir}/* ${sbindir}/*"
4758
4759 FILES_${PN}-doc = "${docdir} ${mandir} ${infodir} ${datadir}/gtk-doc \
4760 ${datadir}/gnome/help"
4761 SECTION_${PN}-doc = "doc"
4762
4763 FILES_SOLIBSDEV ?= "${base_libdir}/lib*${SOLIBSDEV} ${libdir}/lib*${SOLIBSDEV}"
4764 FILES_${PN}-dev = "${includedir} ${FILES_SOLIBSDEV} ${libdir}/*.la \
4765 ${libdir}/*.o ${libdir}/pkgconfig ${datadir}/pkgconfig \
4766 ${datadir}/aclocal ${base_libdir}/*.o \
4767 ${libdir}/${BPN}/*.la ${base_libdir}/*.la"
4768 SECTION_${PN}-dev = "devel"
4769 ALLOW_EMPTY_${PN}-dev = "1"
4770 RDEPENDS_${PN}-dev = "${PN} (= ${EXTENDPKGV})"
4771
4772 FILES_${PN}-staticdev = "${libdir}/*.a ${base_libdir}/*.a ${libdir}/${BPN}/*.a"
4773 SECTION_${PN}-staticdev = "devel"
4774 RDEPENDS_${PN}-staticdev = "${PN}-dev (= ${EXTENDPKGV})"
4775
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004776Combining Multiple Versions of Library Files into One Image
4777-----------------------------------------------------------
4778
4779The build system offers the ability to build libraries with different
4780target optimizations or architecture formats and combine these together
4781into one system image. You can link different binaries in the image
4782against the different libraries as needed for specific use cases. This
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004783feature is called "Multilib".
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004784
4785An example would be where you have most of a system compiled in 32-bit
4786mode using 32-bit libraries, but you have something large, like a
4787database engine, that needs to be a 64-bit application and uses 64-bit
4788libraries. Multilib allows you to get the best of both 32-bit and 64-bit
4789libraries.
4790
4791While the Multilib feature is most commonly used for 32 and 64-bit
4792differences, the approach the build system uses facilitates different
4793target optimizations. You could compile some binaries to use one set of
4794libraries and other binaries to use a different set of libraries. The
4795libraries could differ in architecture, compiler options, or other
4796optimizations.
4797
4798Several examples exist in the ``meta-skeleton`` layer found in the
4799:term:`Source Directory`:
4800
4801- ``conf/multilib-example.conf`` configuration file
4802
4803- ``conf/multilib-example2.conf`` configuration file
4804
4805- ``recipes-multilib/images/core-image-multilib-example.bb`` recipe
4806
4807Preparing to Use Multilib
4808~~~~~~~~~~~~~~~~~~~~~~~~~
4809
4810User-specific requirements drive the Multilib feature. Consequently,
4811there is no one "out-of-the-box" configuration that likely exists to
4812meet your needs.
4813
4814In order to enable Multilib, you first need to ensure your recipe is
4815extended to support multiple libraries. Many standard recipes are
4816already extended and support multiple libraries. You can check in the
4817``meta/conf/multilib.conf`` configuration file in the
4818:term:`Source Directory` to see how this is
4819done using the
4820:term:`BBCLASSEXTEND` variable.
4821Eventually, all recipes will be covered and this list will not be
4822needed.
4823
4824For the most part, the Multilib class extension works automatically to
4825extend the package name from ``${PN}`` to ``${MLPREFIX}${PN}``, where
4826``MLPREFIX`` is the particular multilib (e.g. "lib32-" or "lib64-").
4827Standard variables such as
4828:term:`DEPENDS`,
4829:term:`RDEPENDS`,
4830:term:`RPROVIDES`,
4831:term:`RRECOMMENDS`,
4832:term:`PACKAGES`, and
4833:term:`PACKAGES_DYNAMIC` are
4834automatically extended by the system. If you are extending any manual
4835code in the recipe, you can use the ``${MLPREFIX}`` variable to ensure
4836those names are extended correctly. This automatic extension code
4837resides in ``multilib.bbclass``.
4838
4839Using Multilib
4840~~~~~~~~~~~~~~
4841
4842After you have set up the recipes, you need to define the actual
4843combination of multiple libraries you want to build. You accomplish this
4844through your ``local.conf`` configuration file in the
4845:term:`Build Directory`. An example
4846configuration would be as follows:
4847::
4848
4849 MACHINE = "qemux86-64"
4850 require conf/multilib.conf
4851 MULTILIBS = "multilib:lib32"
4852 DEFAULTTUNE_virtclass-multilib-lib32 = "x86"
4853 IMAGE_INSTALL_append = "lib32-glib-2.0"
4854
4855This example enables an additional library named
4856``lib32`` alongside the normal target packages. When combining these
4857"lib32" alternatives, the example uses "x86" for tuning. For information
4858on this particular tuning, see
4859``meta/conf/machine/include/ia32/arch-ia32.inc``.
4860
4861The example then includes ``lib32-glib-2.0`` in all the images, which
4862illustrates one method of including a multiple library dependency. You
4863can use a normal image build to include this dependency, for example:
4864::
4865
4866 $ bitbake core-image-sato
4867
4868You can also build Multilib packages
4869specifically with a command like this:
4870::
4871
4872 $ bitbake lib32-glib-2.0
4873
4874Additional Implementation Details
4875~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4876
4877Generic implementation details as well as details that are specific to
4878package management systems exist. Following are implementation details
4879that exist regardless of the package management system:
4880
4881- The typical convention used for the class extension code as used by
4882 Multilib assumes that all package names specified in
4883 :term:`PACKAGES` that contain
4884 ``${PN}`` have ``${PN}`` at the start of the name. When that
4885 convention is not followed and ``${PN}`` appears at the middle or the
4886 end of a name, problems occur.
4887
4888- The :term:`TARGET_VENDOR`
4889 value under Multilib will be extended to "-vendormlmultilib" (e.g.
4890 "-pokymllib32" for a "lib32" Multilib with Poky). The reason for this
4891 slightly unwieldy contraction is that any "-" characters in the
4892 vendor string presently break Autoconf's ``config.sub``, and other
4893 separators are problematic for different reasons.
4894
4895For the RPM Package Management System, the following implementation
4896details exist:
4897
4898- A unique architecture is defined for the Multilib packages, along
4899 with creating a unique deploy folder under ``tmp/deploy/rpm`` in the
4900 :term:`Build Directory`. For
4901 example, consider ``lib32`` in a ``qemux86-64`` image. The possible
4902 architectures in the system are "all", "qemux86_64",
4903 "lib32_qemux86_64", and "lib32_x86".
4904
4905- The ``${MLPREFIX}`` variable is stripped from ``${PN}`` during RPM
4906 packaging. The naming for a normal RPM package and a Multilib RPM
4907 package in a ``qemux86-64`` system resolves to something similar to
4908 ``bash-4.1-r2.x86_64.rpm`` and ``bash-4.1.r2.lib32_x86.rpm``,
4909 respectively.
4910
4911- When installing a Multilib image, the RPM backend first installs the
4912 base image and then installs the Multilib libraries.
4913
4914- The build system relies on RPM to resolve the identical files in the
4915 two (or more) Multilib packages.
4916
4917For the IPK Package Management System, the following implementation
4918details exist:
4919
4920- The ``${MLPREFIX}`` is not stripped from ``${PN}`` during IPK
4921 packaging. The naming for a normal RPM package and a Multilib IPK
4922 package in a ``qemux86-64`` system resolves to something like
4923 ``bash_4.1-r2.x86_64.ipk`` and ``lib32-bash_4.1-rw_x86.ipk``,
4924 respectively.
4925
4926- The IPK deploy folder is not modified with ``${MLPREFIX}`` because
4927 packages with and without the Multilib feature can exist in the same
4928 folder due to the ``${PN}`` differences.
4929
4930- IPK defines a sanity check for Multilib installation using certain
4931 rules for file comparison, overridden, etc.
4932
4933Installing Multiple Versions of the Same Library
4934------------------------------------------------
4935
4936Situations can exist where you need to install and use multiple versions
4937of the same library on the same system at the same time. These
4938situations almost always exist when a library API changes and you have
4939multiple pieces of software that depend on the separate versions of the
4940library. To accommodate these situations, you can install multiple
4941versions of the same library in parallel on the same system.
4942
4943The process is straightforward as long as the libraries use proper
4944versioning. With properly versioned libraries, all you need to do to
4945individually specify the libraries is create separate, appropriately
4946named recipes where the :term:`PN` part of
4947the name includes a portion that differentiates each library version
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004948(e.g. the major part of the version number). Thus, instead of having a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004949single recipe that loads one version of a library (e.g. ``clutter``),
4950you provide multiple recipes that result in different versions of the
4951libraries you want. As an example, the following two recipes would allow
4952the two separate versions of the ``clutter`` library to co-exist on the
4953same system:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004954
4955.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004956
4957 clutter-1.6_1.6.20.bb
4958 clutter-1.8_1.8.4.bb
4959
4960Additionally, if
4961you have other recipes that depend on a given library, you need to use
4962the :term:`DEPENDS` variable to
4963create the dependency. Continuing with the same example, if you want to
4964have a recipe depend on the 1.8 version of the ``clutter`` library, use
4965the following in your recipe:
4966::
4967
4968 DEPENDS = "clutter-1.8"
4969
4970Using x32 psABI
4971===============
4972
4973x32 processor-specific Application Binary Interface (`x32
4974psABI <https://software.intel.com/en-us/node/628948>`__) is a native
497532-bit processor-specific ABI for Intel 64 (x86-64) architectures. An
4976ABI defines the calling conventions between functions in a processing
4977environment. The interface determines what registers are used and what
4978the sizes are for various C data types.
4979
4980Some processing environments prefer using 32-bit applications even when
4981running on Intel 64-bit platforms. Consider the i386 psABI, which is a
4982very old 32-bit ABI for Intel 64-bit platforms. The i386 psABI does not
4983provide efficient use and access of the Intel 64-bit processor
4984resources, leaving the system underutilized. Now consider the x86_64
4985psABI. This ABI is newer and uses 64-bits for data sizes and program
4986pointers. The extra bits increase the footprint size of the programs,
4987libraries, and also increases the memory and file system size
4988requirements. Executing under the x32 psABI enables user programs to
4989utilize CPU and system resources more efficiently while keeping the
4990memory footprint of the applications low. Extra bits are used for
4991registers but not for addressing mechanisms.
4992
4993The Yocto Project supports the final specifications of x32 psABI as
4994follows:
4995
4996- You can create packages and images in x32 psABI format on x86_64
4997 architecture targets.
4998
4999- You can successfully build recipes with the x32 toolchain.
5000
5001- You can create and boot ``core-image-minimal`` and
5002 ``core-image-sato`` images.
5003
5004- RPM Package Manager (RPM) support exists for x32 binaries.
5005
5006- Support for large images exists.
5007
5008To use the x32 psABI, you need to edit your ``conf/local.conf``
5009configuration file as follows:
5010::
5011
5012 MACHINE = "qemux86-64"
5013 DEFAULTTUNE = "x86-64-x32"
5014 baselib = "${@d.getVar('BASE_LIB_tune-' + (d.getVar('DEFAULTTUNE') \
5015 or 'INVALID')) or 'lib'}"
5016
5017Once you have set
5018up your configuration file, use BitBake to build an image that supports
5019the x32 psABI. Here is an example:
5020::
5021
5022 $ bitbake core-image-sato
5023
5024Enabling GObject Introspection Support
5025======================================
5026
5027`GObject
5028introspection <https://wiki.gnome.org/Projects/GObjectIntrospection>`__
5029is the standard mechanism for accessing GObject-based software from
5030runtime environments. GObject is a feature of the GLib library that
5031provides an object framework for the GNOME desktop and related software.
5032GObject Introspection adds information to GObject that allows objects
5033created within it to be represented across different programming
5034languages. If you want to construct GStreamer pipelines using Python, or
5035control UPnP infrastructure using Javascript and GUPnP, GObject
5036introspection is the only way to do it.
5037
5038This section describes the Yocto Project support for generating and
5039packaging GObject introspection data. GObject introspection data is a
5040description of the API provided by libraries built on top of GLib
5041framework, and, in particular, that framework's GObject mechanism.
5042GObject Introspection Repository (GIR) files go to ``-dev`` packages,
5043``typelib`` files go to main packages as they are packaged together with
5044libraries that are introspected.
5045
5046The data is generated when building such a library, by linking the
5047library with a small executable binary that asks the library to describe
5048itself, and then executing the binary and processing its output.
5049
5050Generating this data in a cross-compilation environment is difficult
5051because the library is produced for the target architecture, but its
5052code needs to be executed on the build host. This problem is solved with
5053the OpenEmbedded build system by running the code through QEMU, which
5054allows precisely that. Unfortunately, QEMU does not always work
5055perfectly as mentioned in the "`Known Issues <#known-issues>`__"
5056section.
5057
5058Enabling the Generation of Introspection Data
5059---------------------------------------------
5060
5061Enabling the generation of introspection data (GIR files) in your
5062library package involves the following:
5063
50641. Inherit the
5065 :ref:`gobject-introspection <ref-classes-gobject-introspection>`
5066 class.
5067
50682. Make sure introspection is not disabled anywhere in the recipe or
5069 from anything the recipe includes. Also, make sure that
5070 "gobject-introspection-data" is not in
5071 :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`
5072 and that "qemu-usermode" is not in
5073 :term:`MACHINE_FEATURES_BACKFILL_CONSIDERED`.
5074 If either of these conditions exist, nothing will happen.
5075
50763. Try to build the recipe. If you encounter build errors that look like
5077 something is unable to find ``.so`` libraries, check where these
5078 libraries are located in the source tree and add the following to the
5079 recipe:
5080 ::
5081
5082 GIR_EXTRA_LIBS_PATH = "${B}/something/.libs"
5083
5084 .. note::
5085
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005086 See recipes in the ``oe-core`` repository that use that
5087 ``GIR_EXTRA_LIBS_PATH`` variable as an example.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005088
50894. Look for any other errors, which probably mean that introspection
5090 support in a package is not entirely standard, and thus breaks down
5091 in a cross-compilation environment. For such cases, custom-made fixes
5092 are needed. A good place to ask and receive help in these cases is
5093 the :ref:`Yocto Project mailing
5094 lists <resources-mailinglist>`.
5095
5096.. note::
5097
5098 Using a library that no longer builds against the latest Yocto
5099 Project release and prints introspection related errors is a good
5100 candidate for the previous procedure.
5101
5102Disabling the Generation of Introspection Data
5103----------------------------------------------
5104
5105You might find that you do not want to generate introspection data. Or,
5106perhaps QEMU does not work on your build host and target architecture
5107combination. If so, you can use either of the following methods to
5108disable GIR file generations:
5109
5110- Add the following to your distro configuration:
5111 ::
5112
5113 DISTRO_FEATURES_BACKFILL_CONSIDERED = "gobject-introspection-data"
5114
5115 Adding this statement disables generating introspection data using
5116 QEMU but will still enable building introspection tools and libraries
5117 (i.e. building them does not require the use of QEMU).
5118
5119- Add the following to your machine configuration:
5120 ::
5121
5122 MACHINE_FEATURES_BACKFILL_CONSIDERED = "qemu-usermode"
5123
5124 Adding this statement disables the use of QEMU when building packages for your
5125 machine. Currently, this feature is used only by introspection
5126 recipes and has the same effect as the previously described option.
5127
5128 .. note::
5129
5130 Future releases of the Yocto Project might have other features
5131 affected by this option.
5132
5133If you disable introspection data, you can still obtain it through other
5134means such as copying the data from a suitable sysroot, or by generating
5135it on the target hardware. The OpenEmbedded build system does not
5136currently provide specific support for these techniques.
5137
5138Testing that Introspection Works in an Image
5139--------------------------------------------
5140
5141Use the following procedure to test if generating introspection data is
5142working in an image:
5143
51441. Make sure that "gobject-introspection-data" is not in
5145 :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`
5146 and that "qemu-usermode" is not in
5147 :term:`MACHINE_FEATURES_BACKFILL_CONSIDERED`.
5148
51492. Build ``core-image-sato``.
5150
51513. Launch a Terminal and then start Python in the terminal.
5152
51534. Enter the following in the terminal:
5154 ::
5155
5156 >>> from gi.repository import GLib
5157 >>> GLib.get_host_name()
5158
51595. For something a little more advanced, enter the following see:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005160 https://python-gtk-3-tutorial.readthedocs.io/en/latest/introduction.html
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005161
5162Known Issues
5163------------
5164
5165The following know issues exist for GObject Introspection Support:
5166
5167- ``qemu-ppc64`` immediately crashes. Consequently, you cannot build
5168 introspection data on that architecture.
5169
5170- x32 is not supported by QEMU. Consequently, introspection data is
5171 disabled.
5172
5173- musl causes transient GLib binaries to crash on assertion failures.
5174 Consequently, generating introspection data is disabled.
5175
5176- Because QEMU is not able to run the binaries correctly, introspection
5177 is disabled for some specific packages under specific architectures
5178 (e.g. ``gcr``, ``libsecret``, and ``webkit``).
5179
5180- QEMU usermode might not work properly when running 64-bit binaries
5181 under 32-bit host machines. In particular, "qemumips64" is known to
5182 not work under i686.
5183
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005184Optionally Using an External Toolchain
5185======================================
5186
5187You might want to use an external toolchain as part of your development.
5188If this is the case, the fundamental steps you need to accomplish are as
5189follows:
5190
5191- Understand where the installed toolchain resides. For cases where you
5192 need to build the external toolchain, you would need to take separate
5193 steps to build and install the toolchain.
5194
5195- Make sure you add the layer that contains the toolchain to your
5196 ``bblayers.conf`` file through the
5197 :term:`BBLAYERS` variable.
5198
5199- Set the ``EXTERNAL_TOOLCHAIN`` variable in your ``local.conf`` file
5200 to the location in which you installed the toolchain.
5201
5202A good example of an external toolchain used with the Yocto Project is
5203Mentor Graphics Sourcery G++ Toolchain. You can see information on how
5204to use that particular layer in the ``README`` file at
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005205https://github.com/MentorEmbedded/meta-sourcery/. You can find
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005206further information by reading about the
5207:term:`TCMODE` variable in the Yocto
5208Project Reference Manual's variable glossary.
5209
5210Creating Partitioned Images Using Wic
5211=====================================
5212
5213Creating an image for a particular hardware target using the
5214OpenEmbedded build system does not necessarily mean you can boot that
5215image as is on your device. Physical devices accept and boot images in
5216various ways depending on the specifics of the device. Usually,
5217information about the hardware can tell you what image format the device
5218requires. Should your device require multiple partitions on an SD card,
5219flash, or an HDD, you can use the OpenEmbedded Image Creator, Wic, to
5220create the properly partitioned image.
5221
5222The ``wic`` command generates partitioned images from existing
5223OpenEmbedded build artifacts. Image generation is driven by partitioning
5224commands contained in an Openembedded kickstart file (``.wks``)
5225specified either directly on the command line or as one of a selection
5226of canned kickstart files as shown with the ``wic list images`` command
5227in the "`Using an Existing Kickstart
5228File <#using-a-provided-kickstart-file>`__" section. When you apply the
5229command to a given set of build artifacts, the result is an image or set
5230of images that can be directly written onto media and used on a
5231particular system.
5232
5233.. note::
5234
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005235 For a kickstart file reference, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06005236 ":ref:`ref-manual/kickstart:openembedded kickstart (\`\`.wks\`\`) reference`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005237 Chapter in the Yocto Project Reference Manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005238
5239The ``wic`` command and the infrastructure it is based on is by
5240definition incomplete. The purpose of the command is to allow the
5241generation of customized images, and as such, was designed to be
5242completely extensible through a plugin interface. See the "`Using the
5243Wic PlugIn Interface <#wic-using-the-wic-plugin-interface>`__" section
5244for information on these plugins.
5245
5246This section provides some background information on Wic, describes what
5247you need to have in place to run the tool, provides instruction on how
5248to use the Wic utility, provides information on using the Wic plugins
5249interface, and provides several examples that show how to use Wic.
5250
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005251Background
5252----------
5253
5254This section provides some background on the Wic utility. While none of
5255this information is required to use Wic, you might find it interesting.
5256
5257- The name "Wic" is derived from OpenEmbedded Image Creator (oeic). The
5258 "oe" diphthong in "oeic" was promoted to the letter "w", because
5259 "oeic" is both difficult to remember and to pronounce.
5260
5261- Wic is loosely based on the Meego Image Creator (``mic``) framework.
5262 The Wic implementation has been heavily modified to make direct use
5263 of OpenEmbedded build artifacts instead of package installation and
5264 configuration, which are already incorporated within the OpenEmbedded
5265 artifacts.
5266
5267- Wic is a completely independent standalone utility that initially
5268 provides easier-to-use and more flexible replacements for an existing
5269 functionality in OE-Core's
5270 :ref:`image-live <ref-classes-image-live>`
5271 class. The difference between Wic and those examples is that with Wic
5272 the functionality of those scripts is implemented by a
5273 general-purpose partitioning language, which is based on Redhat
5274 kickstart syntax.
5275
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005276Requirements
5277------------
5278
5279In order to use the Wic utility with the OpenEmbedded Build system, your
5280system needs to meet the following requirements:
5281
5282- The Linux distribution on your development host must support the
5283 Yocto Project. See the ":ref:`detailed-supported-distros`"
5284 section in the Yocto Project Reference Manual for the list of
5285 distributions that support the Yocto Project.
5286
5287- The standard system utilities, such as ``cp``, must be installed on
5288 your development host system.
5289
5290- You must have sourced the build environment setup script (i.e.
5291 :ref:`structure-core-script`) found in the
5292 :term:`Build Directory`.
5293
5294- You need to have the build artifacts already available, which
5295 typically means that you must have already created an image using the
5296 Openembedded build system (e.g. ``core-image-minimal``). While it
5297 might seem redundant to generate an image in order to create an image
5298 using Wic, the current version of Wic requires the artifacts in the
5299 form generated by the OpenEmbedded build system.
5300
5301- You must build several native tools, which are built to run on the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005302 build system:
5303 ::
5304
5305 $ bitbake parted-native dosfstools-native mtools-native
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005306
5307- Include "wic" as part of the
5308 :term:`IMAGE_FSTYPES`
5309 variable.
5310
5311- Include the name of the :ref:`wic kickstart file <openembedded-kickstart-wks-reference>`
5312 as part of the :term:`WKS_FILE` variable
5313
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005314Getting Help
5315------------
5316
5317You can get general help for the ``wic`` command by entering the ``wic``
5318command by itself or by entering the command with a help argument as
5319follows:
5320::
5321
5322 $ wic -h
5323 $ wic --help
5324 $ wic help
5325
5326Currently, Wic supports seven commands: ``cp``, ``create``, ``help``,
5327``list``, ``ls``, ``rm``, and ``write``. You can get help for all these
5328commands except "help" by using the following form:
5329::
5330
5331 $ wic help command
5332
5333For example, the following command returns help for the ``write``
5334command:
5335::
5336
5337 $ wic help write
5338
5339Wic supports help for three topics: ``overview``, ``plugins``, and
5340``kickstart``. You can get help for any topic using the following form:
5341::
5342
5343 $ wic help topic
5344
5345For example, the following returns overview help for Wic:
5346::
5347
5348 $ wic help overview
5349
5350One additional level of help exists for Wic. You can get help on
5351individual images through the ``list`` command. You can use the ``list``
5352command to return the available Wic images as follows:
5353::
5354
5355 $ wic list images
5356 genericx86 Create an EFI disk image for genericx86*
5357 beaglebone-yocto Create SD card image for Beaglebone
5358 edgerouter Create SD card image for Edgerouter
5359 qemux86-directdisk Create a qemu machine 'pcbios' direct disk image
5360 directdisk-gpt Create a 'pcbios' direct disk image
5361 mkefidisk Create an EFI disk image
5362 directdisk Create a 'pcbios' direct disk image
5363 systemd-bootdisk Create an EFI disk image with systemd-boot
5364 mkhybridiso Create a hybrid ISO image
5365 sdimage-bootpart Create SD card image with a boot partition
5366 directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
5367 directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
5368
5369Once you know the list of available
5370Wic images, you can use ``help`` with the command to get help on a
5371particular image. For example, the following command returns help on the
5372"beaglebone-yocto" image:
5373::
5374
5375 $ wic list beaglebone-yocto help
5376
5377 Creates a partitioned SD card image for Beaglebone.
5378 Boot files are located in the first vfat partition.
5379
5380Operational Modes
5381-----------------
5382
5383You can use Wic in two different modes, depending on how much control
5384you need for specifying the Openembedded build artifacts that are used
5385for creating the image: Raw and Cooked:
5386
5387- *Raw Mode:* You explicitly specify build artifacts through Wic
5388 command-line arguments.
5389
5390- *Cooked Mode:* The current
5391 :term:`MACHINE` setting and image
5392 name are used to automatically locate and provide the build
5393 artifacts. You just supply a kickstart file and the name of the image
5394 from which to use artifacts.
5395
5396Regardless of the mode you use, you need to have the build artifacts
5397ready and available.
5398
5399Raw Mode
5400~~~~~~~~
5401
5402Running Wic in raw mode allows you to specify all the partitions through
5403the ``wic`` command line. The primary use for raw mode is if you have
5404built your kernel outside of the Yocto Project
5405:term:`Build Directory`. In other words, you
5406can point to arbitrary kernel, root filesystem locations, and so forth.
5407Contrast this behavior with cooked mode where Wic looks in the Build
5408Directory (e.g. ``tmp/deploy/images/``\ machine).
5409
5410The general form of the ``wic`` command in raw mode is:
5411::
5412
5413 $ wic create wks_file options ...
5414
5415 Where:
5416
5417 wks_file:
5418 An OpenEmbedded kickstart file. You can provide
5419 your own custom file or use a file from a set of
5420 existing files as described by further options.
5421
5422 optional arguments:
5423 -h, --help show this help message and exit
5424 -o OUTDIR, --outdir OUTDIR
5425 name of directory to create image in
5426 -e IMAGE_NAME, --image-name IMAGE_NAME
5427 name of the image to use the artifacts from e.g. core-
5428 image-sato
5429 -r ROOTFS_DIR, --rootfs-dir ROOTFS_DIR
5430 path to the /rootfs dir to use as the .wks rootfs
5431 source
5432 -b BOOTIMG_DIR, --bootimg-dir BOOTIMG_DIR
5433 path to the dir containing the boot artifacts (e.g.
5434 /EFI or /syslinux dirs) to use as the .wks bootimg
5435 source
5436 -k KERNEL_DIR, --kernel-dir KERNEL_DIR
5437 path to the dir containing the kernel to use in the
5438 .wks bootimg
5439 -n NATIVE_SYSROOT, --native-sysroot NATIVE_SYSROOT
5440 path to the native sysroot containing the tools to use
5441 to build the image
5442 -s, --skip-build-check
5443 skip the build check
5444 -f, --build-rootfs build rootfs
5445 -c {gzip,bzip2,xz}, --compress-with {gzip,bzip2,xz}
5446 compress image with specified compressor
5447 -m, --bmap generate .bmap
5448 --no-fstab-update Do not change fstab file.
5449 -v VARS_DIR, --vars VARS_DIR
5450 directory with <image>.env files that store bitbake
5451 variables
5452 -D, --debug output debug information
5453
5454.. note::
5455
5456 You do not need root privileges to run Wic. In fact, you should not
5457 run as root when using the utility.
5458
5459Cooked Mode
5460~~~~~~~~~~~
5461
5462Running Wic in cooked mode leverages off artifacts in the Build
5463Directory. In other words, you do not have to specify kernel or root
5464filesystem locations as part of the command. All you need to provide is
5465a kickstart file and the name of the image from which to use artifacts
5466by using the "-e" option. Wic looks in the Build Directory (e.g.
5467``tmp/deploy/images/``\ machine) for artifacts.
5468
5469The general form of the ``wic`` command using Cooked Mode is as follows:
5470::
5471
5472 $ wic create wks_file -e IMAGE_NAME
5473
5474 Where:
5475
5476 wks_file:
5477 An OpenEmbedded kickstart file. You can provide
5478 your own custom file or use a file from a set of
5479 existing files provided with the Yocto Project
5480 release.
5481
5482 required argument:
5483 -e IMAGE_NAME, --image-name IMAGE_NAME
5484 name of the image to use the artifacts from e.g. core-
5485 image-sato
5486
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005487Using an Existing Kickstart File
5488--------------------------------
5489
5490If you do not want to create your own kickstart file, you can use an
5491existing file provided by the Wic installation. As shipped, kickstart
Andrew Geissler09209ee2020-12-13 08:44:15 -06005492files can be found in the :ref:`overview-manual/development-environment:yocto project source repositories` in the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005493following two locations:
5494::
5495
5496 poky/meta-yocto-bsp/wic
5497 poky/scripts/lib/wic/canned-wks
5498
5499Use the following command to list the available kickstart files:
5500::
5501
5502 $ wic list images
5503 genericx86 Create an EFI disk image for genericx86*
5504 beaglebone-yocto Create SD card image for Beaglebone
5505 edgerouter Create SD card image for Edgerouter
5506 qemux86-directdisk Create a qemu machine 'pcbios' direct disk image
5507 directdisk-gpt Create a 'pcbios' direct disk image
5508 mkefidisk Create an EFI disk image
5509 directdisk Create a 'pcbios' direct disk image
5510 systemd-bootdisk Create an EFI disk image with systemd-boot
5511 mkhybridiso Create a hybrid ISO image
5512 sdimage-bootpart Create SD card image with a boot partition
5513 directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
5514 directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
5515
5516When you use an existing file, you
5517do not have to use the ``.wks`` extension. Here is an example in Raw
5518Mode that uses the ``directdisk`` file:
5519::
5520
5521 $ wic create directdisk -r rootfs_dir -b bootimg_dir \
5522 -k kernel_dir -n native_sysroot
5523
5524Here are the actual partition language commands used in the
5525``genericx86.wks`` file to generate an image:
5526::
5527
5528 # short-description: Create an EFI disk image for genericx86*
5529 # long-description: Creates a partitioned EFI disk image for genericx86* machines
5530 part /boot --source bootimg-efi --sourceparams="loader=grub-efi" --ondisk sda --label msdos --active --align 1024
5531 part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid
5532 part swap --ondisk sda --size 44 --label swap1 --fstype=swap
5533
5534 bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=ttyS0,115200 console=tty0"
5535
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005536Using the Wic Plugin Interface
5537------------------------------
5538
5539You can extend and specialize Wic functionality by using Wic plugins.
5540This section explains the Wic plugin interface.
5541
5542.. note::
5543
5544 Wic plugins consist of "source" and "imager" plugins. Imager plugins
5545 are beyond the scope of this section.
5546
5547Source plugins provide a mechanism to customize partition content during
5548the Wic image generation process. You can use source plugins to map
5549values that you specify using ``--source`` commands in kickstart files
5550(i.e. ``*.wks``) to a plugin implementation used to populate a given
5551partition.
5552
5553.. note::
5554
5555 If you use plugins that have build-time dependencies (e.g. native
5556 tools, bootloaders, and so forth) when building a Wic image, you need
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005557 to specify those dependencies using the :term:`WKS_FILE_DEPENDS`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005558 variable.
5559
5560Source plugins are subclasses defined in plugin files. As shipped, the
5561Yocto Project provides several plugin files. You can see the source
5562plugin files that ship with the Yocto Project
Andrew Geissler09209ee2020-12-13 08:44:15 -06005563:yocto_git:`here </poky/tree/scripts/lib/wic/plugins/source>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005564Each of these plugin files contains source plugins that are designed to
5565populate a specific Wic image partition.
5566
5567Source plugins are subclasses of the ``SourcePlugin`` class, which is
5568defined in the ``poky/scripts/lib/wic/pluginbase.py`` file. For example,
5569the ``BootimgEFIPlugin`` source plugin found in the ``bootimg-efi.py``
5570file is a subclass of the ``SourcePlugin`` class, which is found in the
5571``pluginbase.py`` file.
5572
5573You can also implement source plugins in a layer outside of the Source
5574Repositories (external layer). To do so, be sure that your plugin files
5575are located in a directory whose path is
5576``scripts/lib/wic/plugins/source/`` within your external layer. When the
5577plugin files are located there, the source plugins they contain are made
5578available to Wic.
5579
5580When the Wic implementation needs to invoke a partition-specific
5581implementation, it looks for the plugin with the same name as the
5582``--source`` parameter used in the kickstart file given to that
5583partition. For example, if the partition is set up using the following
5584command in a kickstart file:
5585::
5586
5587 part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024
5588
5589The methods defined as class
5590members of the matching source plugin (i.e. ``bootimg-pcbios``) in the
5591``bootimg-pcbios.py`` plugin file are used.
5592
5593To be more concrete, here is the corresponding plugin definition from
5594the ``bootimg-pcbios.py`` file for the previous command along with an
5595example method called by the Wic implementation when it needs to prepare
5596a partition using an implementation-specific function:
5597::
5598
5599 .
5600 .
5601 .
5602 class BootimgPcbiosPlugin(SourcePlugin):
5603 """
5604 Create MBR boot partition and install syslinux on it.
5605 """
5606
5607 name = 'bootimg-pcbios'
5608 .
5609 .
5610 .
5611 @classmethod
5612 def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
5613 oe_builddir, bootimg_dir, kernel_dir,
5614 rootfs_dir, native_sysroot):
5615 """
5616 Called to do the actual content population for a partition i.e. it
5617 'prepares' the partition to be incorporated into the image.
5618 In this case, prepare content for legacy bios boot partition.
5619 """
5620 .
5621 .
5622 .
5623
5624If a
5625subclass (plugin) itself does not implement a particular function, Wic
5626locates and uses the default version in the superclass. It is for this
5627reason that all source plugins are derived from the ``SourcePlugin``
5628class.
5629
5630The ``SourcePlugin`` class defined in the ``pluginbase.py`` file defines
5631a set of methods that source plugins can implement or override. Any
5632plugins (subclass of ``SourcePlugin``) that do not implement a
5633particular method inherit the implementation of the method from the
5634``SourcePlugin`` class. For more information, see the ``SourcePlugin``
5635class in the ``pluginbase.py`` file for details:
5636
5637The following list describes the methods implemented in the
5638``SourcePlugin`` class:
5639
5640- ``do_prepare_partition()``: Called to populate a partition with
5641 actual content. In other words, the method prepares the final
5642 partition image that is incorporated into the disk image.
5643
5644- ``do_configure_partition()``: Called before
5645 ``do_prepare_partition()`` to create custom configuration files for a
5646 partition (e.g. syslinux or grub configuration files).
5647
5648- ``do_install_disk()``: Called after all partitions have been
5649 prepared and assembled into a disk image. This method provides a hook
5650 to allow finalization of a disk image (e.g. writing an MBR).
5651
5652- ``do_stage_partition()``: Special content-staging hook called
5653 before ``do_prepare_partition()``. This method is normally empty.
5654
5655 Typically, a partition just uses the passed-in parameters (e.g. the
5656 unmodified value of ``bootimg_dir``). However, in some cases, things
5657 might need to be more tailored. As an example, certain files might
5658 additionally need to be taken from ``bootimg_dir + /boot``. This hook
5659 allows those files to be staged in a customized fashion.
5660
5661 .. note::
5662
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005663 ``get_bitbake_var()`` allows you to access non-standard variables that
5664 you might want to use for this behavior.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005665
5666You can extend the source plugin mechanism. To add more hooks, create
5667more source plugin methods within ``SourcePlugin`` and the corresponding
5668derived subclasses. The code that calls the plugin methods uses the
5669``plugin.get_source_plugin_methods()`` function to find the method or
5670methods needed by the call. Retrieval of those methods is accomplished
5671by filling up a dict with keys that contain the method names of
5672interest. On success, these will be filled in with the actual methods.
5673See the Wic implementation for examples and details.
5674
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005675Wic Examples
5676------------
5677
5678This section provides several examples that show how to use the Wic
5679utility. All the examples assume the list of requirements in the
5680"`Requirements <#wic-requirements>`__" section have been met. The
5681examples assume the previously generated image is
5682``core-image-minimal``.
5683
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005684Generate an Image using an Existing Kickstart File
5685~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5686
5687This example runs in Cooked Mode and uses the ``mkefidisk`` kickstart
5688file:
5689::
5690
5691 $ wic create mkefidisk -e core-image-minimal
5692 INFO: Building wic-tools...
5693 .
5694 .
5695 .
5696 INFO: The new image(s) can be found here:
5697 ./mkefidisk-201804191017-sda.direct
5698
5699 The following build artifacts were used to create the image(s):
5700 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
5701 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
5702 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
5703 NATIVE_SYSROOT: /home/stephano/build/master/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
5704
5705 INFO: The image(s) were created using OE kickstart file:
5706 /home/stephano/build/master/openembedded-core/scripts/lib/wic/canned-wks/mkefidisk.wks
5707
5708The previous example shows the easiest way to create an image by running
5709in cooked mode and supplying a kickstart file and the "-e" option to
5710point to the existing build artifacts. Your ``local.conf`` file needs to
5711have the :term:`MACHINE` variable set
5712to the machine you are using, which is "qemux86" in this example.
5713
5714Once the image builds, the output provides image location, artifact use,
5715and kickstart file information.
5716
5717.. note::
5718
5719 You should always verify the details provided in the output to make
5720 sure that the image was indeed created exactly as expected.
5721
5722Continuing with the example, you can now write the image from the Build
5723Directory onto a USB stick, or whatever media for which you built your
5724image, and boot from the media. You can write the image by using
5725``bmaptool`` or ``dd``:
5726::
5727
5728 $ oe-run-native bmaptool copy mkefidisk-201804191017-sda.direct /dev/sdX
5729
5730or ::
5731
5732 $ sudo dd if=mkefidisk-201804191017-sda.direct of=/dev/sdX
5733
5734.. note::
5735
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005736 For more information on how to use the ``bmaptool``
5737 to flash a device with an image, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06005738 ":ref:`dev-manual/common-tasks:flashing images using \`\`bmaptool\`\``"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005739 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005740
5741Using a Modified Kickstart File
5742~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5743
5744Because partitioned image creation is driven by the kickstart file, it
5745is easy to affect image creation by changing the parameters in the file.
5746This next example demonstrates that through modification of the
5747``directdisk-gpt`` kickstart file.
5748
5749As mentioned earlier, you can use the command ``wic list images`` to
5750show the list of existing kickstart files. The directory in which the
5751``directdisk-gpt.wks`` file resides is
5752``scripts/lib/image/canned-wks/``, which is located in the
5753:term:`Source Directory` (e.g. ``poky``).
5754Because available files reside in this directory, you can create and add
5755your own custom files to the directory. Subsequent use of the
5756``wic list images`` command would then include your kickstart files.
5757
5758In this example, the existing ``directdisk-gpt`` file already does most
5759of what is needed. However, for the hardware in this example, the image
5760will need to boot from ``sdb`` instead of ``sda``, which is what the
5761``directdisk-gpt`` kickstart file uses.
5762
5763The example begins by making a copy of the ``directdisk-gpt.wks`` file
5764in the ``scripts/lib/image/canned-wks`` directory and then by changing
5765the lines that specify the target disk from which to boot.
5766::
5767
5768 $ cp /home/stephano/poky/scripts/lib/wic/canned-wks/directdisk-gpt.wks \
5769 /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
5770
5771Next, the example modifies the ``directdisksdb-gpt.wks`` file and
5772changes all instances of "``--ondisk sda``" to "``--ondisk sdb``". The
5773example changes the following two lines and leaves the remaining lines
5774untouched:
5775::
5776
5777 part /boot --source bootimg-pcbios --ondisk sdb --label boot --active --align 1024
5778 part / --source rootfs --ondisk sdb --fstype=ext4 --label platform --align 1024 --use-uuid
5779
5780Once the lines are changed, the
5781example generates the ``directdisksdb-gpt`` image. The command points
5782the process at the ``core-image-minimal`` artifacts for the Next Unit of
5783Computing (nuc) :term:`MACHINE` the
5784``local.conf``.
5785::
5786
5787 $ wic create directdisksdb-gpt -e core-image-minimal
5788 INFO: Building wic-tools...
5789 .
5790 .
5791 .
5792 Initialising tasks: 100% |#######################################| Time: 0:00:01
5793 NOTE: Executing SetScene Tasks
5794 NOTE: Executing RunQueue Tasks
5795 NOTE: Tasks Summary: Attempted 1161 tasks of which 1157 didn't need to be rerun and all succeeded.
5796 INFO: Creating image(s)...
5797
5798 INFO: The new image(s) can be found here:
5799 ./directdisksdb-gpt-201710090938-sdb.direct
5800
5801 The following build artifacts were used to create the image(s):
5802 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
5803 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
5804 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
5805 NATIVE_SYSROOT: /home/stephano/build/master/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
5806
5807 INFO: The image(s) were created using OE kickstart file:
5808 /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
5809
5810Continuing with the example, you can now directly ``dd`` the image to a
5811USB stick, or whatever media for which you built your image, and boot
5812the resulting media:
5813::
5814
5815 $ sudo dd if=directdisksdb-gpt-201710090938-sdb.direct of=/dev/sdb
5816 140966+0 records in
5817 140966+0 records out
5818 72174592 bytes (72 MB, 69 MiB) copied, 78.0282 s, 925 kB/s
5819 $ sudo eject /dev/sdb
5820
5821Using a Modified Kickstart File and Running in Raw Mode
5822~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5823
5824This next example manually specifies each build artifact (runs in Raw
5825Mode) and uses a modified kickstart file. The example also uses the
5826``-o`` option to cause Wic to create the output somewhere other than the
5827default output directory, which is the current directory:
5828::
5829
5830 $ wic create /home/stephano/my_yocto/test.wks -o /home/stephano/testwic \
5831 --rootfs-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/rootfs \
5832 --bootimg-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share \
5833 --kernel-dir /home/stephano/build/master/build/tmp/deploy/images/qemux86 \
5834 --native-sysroot /home/stephano/build/master/build/tmp/work/i586-poky-linux/wic-tools/1.0-r0/recipe-sysroot-native
5835
5836 INFO: Creating image(s)...
5837
5838 INFO: The new image(s) can be found here:
5839 /home/stephano/testwic/test-201710091445-sdb.direct
5840
5841 The following build artifacts were used to create the image(s):
5842 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
5843 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
5844 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
5845 NATIVE_SYSROOT: /home/stephano/build/master/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
5846
5847 INFO: The image(s) were created using OE kickstart file:
5848 /home/stephano/my_yocto/test.wks
5849
5850For this example,
5851:term:`MACHINE` did not have to be
5852specified in the ``local.conf`` file since the artifact is manually
5853specified.
5854
5855Using Wic to Manipulate an Image
5856~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5857
5858Wic image manipulation allows you to shorten turnaround time during
5859image development. For example, you can use Wic to delete the kernel
5860partition of a Wic image and then insert a newly built kernel. This
5861saves you time from having to rebuild the entire image each time you
5862modify the kernel.
5863
5864.. note::
5865
5866 In order to use Wic to manipulate a Wic image as in this example,
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005867 your development machine must have the ``mtools`` package installed.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005868
5869The following example examines the contents of the Wic image, deletes
5870the existing kernel, and then inserts a new kernel:
5871
58721. *List the Partitions:* Use the ``wic ls`` command to list all the
5873 partitions in the Wic image:
5874 ::
5875
5876 $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic
5877 Num Start End Size Fstype
5878 1 1048576 25041919 23993344 fat16
5879 2 25165824 72157183 46991360 ext4
5880
5881 The previous output shows two partitions in the
5882 ``core-image-minimal-qemux86.wic`` image.
5883
58842. *Examine a Particular Partition:* Use the ``wic ls`` command again
5885 but in a different form to examine a particular partition.
5886
5887 .. note::
5888
5889 You can get command usage on any Wic command using the following
5890 form:
5891 ::
5892
5893 $ wic help command
5894
5895
5896 For example, the following command shows you the various ways to
5897 use the
5898 wic ls
5899 command:
5900 ::
5901
5902 $ wic help ls
5903
5904
5905 The following command shows what is in Partition one:
5906 ::
5907
5908 $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1
5909 Volume in drive : is boot
5910 Volume Serial Number is E894-1809
5911 Directory for ::/
5912
5913 libcom32 c32 186500 2017-10-09 16:06
5914 libutil c32 24148 2017-10-09 16:06
5915 syslinux cfg 220 2017-10-09 16:06
5916 vesamenu c32 27104 2017-10-09 16:06
5917 vmlinuz 6904608 2017-10-09 16:06
5918 5 files 7 142 580 bytes
5919 16 582 656 bytes free
5920
5921 The previous output shows five files, with the
5922 ``vmlinuz`` being the kernel.
5923
5924 .. note::
5925
5926 If you see the following error, you need to update or create a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005927 ``~/.mtoolsrc`` file and be sure to have the line "mtools_skip_check=1"
5928 in the file. Then, run the Wic command again:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005929 ::
5930
5931 ERROR: _exec_cmd: /usr/bin/mdir -i /tmp/wic-parttfokuwra ::/ returned '1' instead of 0
5932 output: Total number of sectors (47824) not a multiple of sectors per track (32)!
5933 Add mtools_skip_check=1 to your .mtoolsrc file to skip this test
5934
5935
59363. *Remove the Old Kernel:* Use the ``wic rm`` command to remove the
5937 ``vmlinuz`` file (kernel):
5938 ::
5939
5940 $ wic rm tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
5941
59424. *Add In the New Kernel:* Use the ``wic cp`` command to add the
5943 updated kernel to the Wic image. Depending on how you built your
5944 kernel, it could be in different places. If you used ``devtool`` and
5945 an SDK to build your kernel, it resides in the ``tmp/work`` directory
5946 of the extensible SDK. If you used ``make`` to build the kernel, the
5947 kernel will be in the ``workspace/sources`` area.
5948
5949 The following example assumes ``devtool`` was used to build the
5950 kernel:
5951 ::
5952
5953 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 \
5954 ~/poky/build/tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
5955
5956 Once the new kernel is added back into the image, you can use the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005957 ``dd`` command or :ref:`bmaptool
Andrew Geissler09209ee2020-12-13 08:44:15 -06005958 <dev-manual/common-tasks:flashing images using \`\`bmaptool\`\`>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005959 to flash your wic image onto an SD card or USB stick and test your
5960 target.
5961
5962 .. note::
5963
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005964 Using ``bmaptool`` is generally 10 to 20 times faster than using ``dd``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005965
5966Flashing Images Using ``bmaptool``
5967==================================
5968
5969A fast and easy way to flash an image to a bootable device is to use
5970Bmaptool, which is integrated into the OpenEmbedded build system.
5971Bmaptool is a generic tool that creates a file's block map (bmap) and
5972then uses that map to copy the file. As compared to traditional tools
5973such as dd or cp, Bmaptool can copy (or flash) large files like raw
5974system image files much faster.
5975
5976.. note::
5977
5978 - If you are using Ubuntu or Debian distributions, you can install
5979 the ``bmap-tools`` package using the following command and then
5980 use the tool without specifying ``PATH`` even from the root
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005981 account:
5982 ::
5983
5984 $ sudo apt-get install bmap-tools
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005985
5986 - If you are unable to install the ``bmap-tools`` package, you will
5987 need to build Bmaptool before using it. Use the following command:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005988 ::
5989
5990 $ bitbake bmap-tools-native
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005991
5992Following, is an example that shows how to flash a Wic image. Realize
5993that while this example uses a Wic image, you can use Bmaptool to flash
5994any type of image. Use these steps to flash an image using Bmaptool:
5995
59961. *Update your local.conf File:* You need to have the following set
5997 in your ``local.conf`` file before building your image:
5998 ::
5999
6000 IMAGE_FSTYPES += "wic wic.bmap"
6001
60022. *Get Your Image:* Either have your image ready (pre-built with the
6003 :term:`IMAGE_FSTYPES`
6004 setting previously mentioned) or take the step to build the image:
6005 ::
6006
6007 $ bitbake image
6008
60093. *Flash the Device:* Flash the device with the image by using Bmaptool
6010 depending on your particular setup. The following commands assume the
6011 image resides in the Build Directory's ``deploy/images/`` area:
6012
6013 - If you have write access to the media, use this command form:
6014 ::
6015
6016 $ oe-run-native bmap-tools-native bmaptool copy build-directory/tmp/deploy/images/machine/image.wic /dev/sdX
6017
6018 - If you do not have write access to the media, set your permissions
6019 first and then use the same command form:
6020 ::
6021
6022 $ sudo chmod 666 /dev/sdX
6023 $ oe-run-native bmap-tools-native bmaptool copy build-directory/tmp/deploy/images/machine/image.wic /dev/sdX
6024
6025For help on the ``bmaptool`` command, use the following command:
6026::
6027
6028 $ bmaptool --help
6029
6030Making Images More Secure
6031=========================
6032
6033Security is of increasing concern for embedded devices. Consider the
6034issues and problems discussed in just this sampling of work found across
6035the Internet:
6036
6037- *"*\ `Security Risks of Embedded
6038 Systems <https://www.schneier.com/blog/archives/2014/01/security_risks_9.html>`__\ *"*
6039 by Bruce Schneier
6040
6041- *"*\ `Internet Census
6042 2012 <http://census2012.sourceforge.net/paper.html>`__\ *"* by Carna
6043 Botnet
6044
6045- *"*\ `Security Issues for Embedded
Andrew Geisslerc723b722021-01-08 16:14:09 -06006046 Devices <https://elinux.org/images/6/6f/Security-issues.pdf>`__\ *"*
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006047 by Jake Edge
6048
6049When securing your image is of concern, there are steps, tools, and
6050variables that you can consider to help you reach the security goals you
6051need for your particular device. Not all situations are identical when
6052it comes to making an image secure. Consequently, this section provides
6053some guidance and suggestions for consideration when you want to make
6054your image more secure.
6055
6056.. note::
6057
6058 Because the security requirements and risks are different for every
6059 type of device, this section cannot provide a complete reference on
6060 securing your custom OS. It is strongly recommended that you also
6061 consult other sources of information on embedded Linux system
6062 hardening and on security.
6063
6064General Considerations
6065----------------------
6066
6067General considerations exist that help you create more secure images.
6068You should consider the following suggestions to help make your device
6069more secure:
6070
6071- Scan additional code you are adding to the system (e.g. application
6072 code) by using static analysis tools. Look for buffer overflows and
6073 other potential security problems.
6074
6075- Pay particular attention to the security for any web-based
6076 administration interface.
6077
6078 Web interfaces typically need to perform administrative functions and
6079 tend to need to run with elevated privileges. Thus, the consequences
6080 resulting from the interface's security becoming compromised can be
6081 serious. Look for common web vulnerabilities such as
6082 cross-site-scripting (XSS), unvalidated inputs, and so forth.
6083
6084 As with system passwords, the default credentials for accessing a
6085 web-based interface should not be the same across all devices. This
6086 is particularly true if the interface is enabled by default as it can
6087 be assumed that many end-users will not change the credentials.
6088
6089- Ensure you can update the software on the device to mitigate
6090 vulnerabilities discovered in the future. This consideration
6091 especially applies when your device is network-enabled.
6092
6093- Ensure you remove or disable debugging functionality before producing
6094 the final image. For information on how to do this, see the
6095 "`Considerations Specific to the OpenEmbedded Build
6096 System <#considerations-specific-to-the-openembedded-build-system>`__"
6097 section.
6098
6099- Ensure you have no network services listening that are not needed.
6100
6101- Remove any software from the image that is not needed.
6102
6103- Enable hardware support for secure boot functionality when your
6104 device supports this functionality.
6105
6106Security Flags
6107--------------
6108
6109The Yocto Project has security flags that you can enable that help make
6110your build output more secure. The security flags are in the
6111``meta/conf/distro/include/security_flags.inc`` file in your
6112:term:`Source Directory` (e.g. ``poky``).
6113
6114.. note::
6115
6116 Depending on the recipe, certain security flags are enabled and
6117 disabled by default.
6118
6119Use the following line in your ``local.conf`` file or in your custom
6120distribution configuration file to enable the security compiler and
6121linker flags for your build:
6122::
6123
6124 require conf/distro/include/security_flags.inc
6125
6126Considerations Specific to the OpenEmbedded Build System
6127--------------------------------------------------------
6128
6129You can take some steps that are specific to the OpenEmbedded build
6130system to make your images more secure:
6131
6132- Ensure "debug-tweaks" is not one of your selected
6133 :term:`IMAGE_FEATURES`.
6134 When creating a new project, the default is to provide you with an
6135 initial ``local.conf`` file that enables this feature using the
6136 :term:`EXTRA_IMAGE_FEATURES`
6137 variable with the line:
6138 ::
6139
6140 EXTRA_IMAGE_FEATURES = "debug-tweaks"
6141
6142 To disable that feature, simply comment out that line in your
6143 ``local.conf`` file, or make sure ``IMAGE_FEATURES`` does not contain
6144 "debug-tweaks" before producing your final image. Among other things,
6145 leaving this in place sets the root password as blank, which makes
6146 logging in for debugging or inspection easy during development but
6147 also means anyone can easily log in during production.
6148
6149- It is possible to set a root password for the image and also to set
6150 passwords for any extra users you might add (e.g. administrative or
6151 service type users). When you set up passwords for multiple images or
6152 users, you should not duplicate passwords.
6153
6154 To set up passwords, use the
6155 :ref:`extrausers <ref-classes-extrausers>`
6156 class, which is the preferred method. For an example on how to set up
6157 both root and user passwords, see the
6158 ":ref:`extrausers.bbclass <ref-classes-extrausers>`"
6159 section.
6160
6161 .. note::
6162
6163 When adding extra user accounts or setting a root password, be
6164 cautious about setting the same password on every device. If you
6165 do this, and the password you have set is exposed, then every
6166 device is now potentially compromised. If you need this access but
6167 want to ensure security, consider setting a different, random
6168 password for each device. Typically, you do this as a separate
6169 step after you deploy the image onto the device.
6170
6171- Consider enabling a Mandatory Access Control (MAC) framework such as
6172 SMACK or SELinux and tuning it appropriately for your device's usage.
6173 You can find more information in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06006174 :yocto_git:`meta-selinux </meta-selinux/>` layer.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006175
6176Tools for Hardening Your Image
6177------------------------------
6178
6179The Yocto Project provides tools for making your image more secure. You
6180can find these tools in the ``meta-security`` layer of the
6181:yocto_git:`Yocto Project Source Repositories <>`.
6182
6183Creating Your Own Distribution
6184==============================
6185
6186When you build an image using the Yocto Project and do not alter any
6187distribution :term:`Metadata`, you are
6188creating a Poky distribution. If you wish to gain more control over
6189package alternative selections, compile-time options, and other
6190low-level configurations, you can create your own distribution.
6191
6192To create your own distribution, the basic steps consist of creating
6193your own distribution layer, creating your own distribution
6194configuration file, and then adding any needed code and Metadata to the
6195layer. The following steps provide some more detail:
6196
6197- *Create a layer for your new distro:* Create your distribution layer
6198 so that you can keep your Metadata and code for the distribution
6199 separate. It is strongly recommended that you create and use your own
6200 layer for configuration and code. Using your own layer as compared to
6201 just placing configurations in a ``local.conf`` configuration file
6202 makes it easier to reproduce the same build configuration when using
6203 multiple build machines. See the
Andrew Geissler09209ee2020-12-13 08:44:15 -06006204 ":ref:`dev-manual/common-tasks:creating a general layer using the \`\`bitbake-layers\`\` script`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006205 section for information on how to quickly set up a layer.
6206
6207- *Create the distribution configuration file:* The distribution
6208 configuration file needs to be created in the ``conf/distro``
6209 directory of your layer. You need to name it using your distribution
6210 name (e.g. ``mydistro.conf``).
6211
6212 .. note::
6213
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006214 The :term:`DISTRO` variable in your ``local.conf`` file determines the
6215 name of your distribution.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006216
6217 You can split out parts of your configuration file into include files
6218 and then "require" them from within your distribution configuration
6219 file. Be sure to place the include files in the
6220 ``conf/distro/include`` directory of your layer. A common example
6221 usage of include files would be to separate out the selection of
6222 desired version and revisions for individual recipes.
6223
6224 Your configuration file needs to set the following required
6225 variables:
6226
6227 - :term:`DISTRO_NAME`
6228
6229 - :term:`DISTRO_VERSION`
6230
6231 These following variables are optional and you typically set them
6232 from the distribution configuration file:
6233
6234 - :term:`DISTRO_FEATURES`
6235
6236 - :term:`DISTRO_EXTRA_RDEPENDS`
6237
6238 - :term:`DISTRO_EXTRA_RRECOMMENDS`
6239
6240 - :term:`TCLIBC`
6241
6242 .. tip::
6243
6244 If you want to base your distribution configuration file on the
6245 very basic configuration from OE-Core, you can use
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006246 ``conf/distro/defaultsetup.conf`` as a reference and just include
6247 variables that differ as compared to ``defaultsetup.conf``.
6248 Alternatively, you can create a distribution configuration file
6249 from scratch using the ``defaultsetup.conf`` file or configuration files
6250 from other distributions such as Poky or Angstrom as references.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006251
6252- *Provide miscellaneous variables:* Be sure to define any other
6253 variables for which you want to create a default or enforce as part
6254 of the distribution configuration. You can include nearly any
6255 variable from the ``local.conf`` file. The variables you use are not
6256 limited to the list in the previous bulleted item.
6257
6258- *Point to Your distribution configuration file:* In your
6259 ``local.conf`` file in the :term:`Build Directory`,
6260 set your
6261 :term:`DISTRO` variable to point to
6262 your distribution's configuration file. For example, if your
6263 distribution's configuration file is named ``mydistro.conf``, then
6264 you point to it as follows:
6265 ::
6266
6267 DISTRO = "mydistro"
6268
6269- *Add more to the layer if necessary:* Use your layer to hold other
6270 information needed for the distribution:
6271
6272 - Add recipes for installing distro-specific configuration files
6273 that are not already installed by another recipe. If you have
6274 distro-specific configuration files that are included by an
6275 existing recipe, you should add an append file (``.bbappend``) for
6276 those. For general information and recommendations on how to add
6277 recipes to your layer, see the "`Creating Your Own
6278 Layer <#creating-your-own-layer>`__" and "`Following Best
6279 Practices When Creating
6280 Layers <#best-practices-to-follow-when-creating-layers>`__"
6281 sections.
6282
6283 - Add any image recipes that are specific to your distribution.
6284
6285 - Add a ``psplash`` append file for a branded splash screen. For
6286 information on append files, see the "`Using .bbappend Files in
6287 Your Layer <#using-bbappend-files>`__" section.
6288
6289 - Add any other append files to make custom changes that are
6290 specific to individual recipes.
6291
6292Creating a Custom Template Configuration Directory
6293==================================================
6294
6295If you are producing your own customized version of the build system for
6296use by other users, you might want to customize the message shown by the
6297setup script or you might want to change the template configuration
6298files (i.e. ``local.conf`` and ``bblayers.conf``) that are created in a
6299new build directory.
6300
6301The OpenEmbedded build system uses the environment variable
6302``TEMPLATECONF`` to locate the directory from which it gathers
6303configuration information that ultimately ends up in the
6304:term:`Build Directory` ``conf`` directory.
6305By default, ``TEMPLATECONF`` is set as follows in the ``poky``
6306repository:
6307::
6308
6309 TEMPLATECONF=${TEMPLATECONF:-meta-poky/conf}
6310
6311This is the
6312directory used by the build system to find templates from which to build
6313some key configuration files. If you look at this directory, you will
6314see the ``bblayers.conf.sample``, ``local.conf.sample``, and
6315``conf-notes.txt`` files. The build system uses these files to form the
6316respective ``bblayers.conf`` file, ``local.conf`` file, and display the
6317list of BitBake targets when running the setup script.
6318
6319To override these default configuration files with configurations you
6320want used within every new Build Directory, simply set the
6321``TEMPLATECONF`` variable to your directory. The ``TEMPLATECONF``
6322variable is set in the ``.templateconf`` file, which is in the top-level
6323:term:`Source Directory` folder
6324(e.g. ``poky``). Edit the ``.templateconf`` so that it can locate your
6325directory.
6326
6327Best practices dictate that you should keep your template configuration
6328directory in your custom distribution layer. For example, suppose you
6329have a layer named ``meta-mylayer`` located in your home directory and
6330you want your template configuration directory named ``myconf``.
6331Changing the ``.templateconf`` as follows causes the OpenEmbedded build
6332system to look in your directory and base its configuration files on the
6333``*.sample`` configuration files it finds. The final configuration files
6334(i.e. ``local.conf`` and ``bblayers.conf`` ultimately still end up in
6335your Build Directory, but they are based on your ``*.sample`` files.
6336::
6337
6338 TEMPLATECONF=${TEMPLATECONF:-meta-mylayer/myconf}
6339
6340Aside from the ``*.sample`` configuration files, the ``conf-notes.txt``
6341also resides in the default ``meta-poky/conf`` directory. The script
6342that sets up the build environment (i.e.
6343:ref:`structure-core-script`) uses this file to
6344display BitBake targets as part of the script output. Customizing this
6345``conf-notes.txt`` file is a good way to make sure your list of custom
6346targets appears as part of the script's output.
6347
6348Here is the default list of targets displayed as a result of running
6349either of the setup scripts:
6350::
6351
6352 You can now run 'bitbake <target>'
6353
6354 Common targets are:
6355 core-image-minimal
6356 core-image-sato
6357 meta-toolchain
6358 meta-ide-support
6359
6360Changing the listed common targets is as easy as editing your version of
6361``conf-notes.txt`` in your custom template configuration directory and
6362making sure you have ``TEMPLATECONF`` set to your directory.
6363
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006364Conserving Disk Space During Builds
6365===================================
6366
6367To help conserve disk space during builds, you can add the following
6368statement to your project's ``local.conf`` configuration file found in
6369the :term:`Build Directory`:
6370::
6371
6372 INHERIT += "rm_work"
6373
6374Adding this statement deletes the work directory used for
6375building a recipe once the recipe is built. For more information on
6376"rm_work", see the
6377:ref:`rm_work <ref-classes-rm-work>` class in the
6378Yocto Project Reference Manual.
6379
6380Working with Packages
6381=====================
6382
6383This section describes a few tasks that involve packages:
6384
6385- `Excluding packages from an
6386 image <#excluding-packages-from-an-image>`__
6387
6388- `Incrementing a binary package
6389 version <#incrementing-a-binary-package-version>`__
6390
6391- `Handling optional module
6392 packaging <#handling-optional-module-packaging>`__
6393
6394- `Using runtime package
6395 management <#using-runtime-package-management>`__
6396
6397- `Generating and using signed
6398 packages <#generating-and-using-signed-packages>`__
6399
6400- `Setting up and running package test
6401 (ptest) <#testing-packages-with-ptest>`__
6402
6403- `Creating node package manager (NPM)
6404 packages <#creating-node-package-manager-npm-packages>`__
6405
6406- `Adding custom metadata to
6407 packages <#adding-custom-metadata-to-packages>`__
6408
6409Excluding Packages from an Image
6410--------------------------------
6411
6412You might find it necessary to prevent specific packages from being
6413installed into an image. If so, you can use several variables to direct
6414the build system to essentially ignore installing recommended packages
6415or to not install a package at all.
6416
6417The following list introduces variables you can use to prevent packages
6418from being installed into your image. Each of these variables only works
6419with IPK and RPM package types. Support for Debian packages does not
6420exist. Also, you can use these variables from your ``local.conf`` file
6421or attach them to a specific image recipe by using a recipe name
6422override. For more detail on the variables, see the descriptions in the
6423Yocto Project Reference Manual's glossary chapter.
6424
6425- :term:`BAD_RECOMMENDATIONS`:
6426 Use this variable to specify "recommended-only" packages that you do
6427 not want installed.
6428
6429- :term:`NO_RECOMMENDATIONS`:
6430 Use this variable to prevent all "recommended-only" packages from
6431 being installed.
6432
6433- :term:`PACKAGE_EXCLUDE`:
6434 Use this variable to prevent specific packages from being installed
6435 regardless of whether they are "recommended-only" or not. You need to
6436 realize that the build process could fail with an error when you
6437 prevent the installation of a package whose presence is required by
6438 an installed package.
6439
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006440Incrementing a Package Version
6441------------------------------
6442
6443This section provides some background on how binary package versioning
6444is accomplished and presents some of the services, variables, and
6445terminology involved.
6446
6447In order to understand binary package versioning, you need to consider
6448the following:
6449
6450- Binary Package: The binary package that is eventually built and
6451 installed into an image.
6452
6453- Binary Package Version: The binary package version is composed of two
6454 components - a version and a revision.
6455
6456 .. note::
6457
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006458 Technically, a third component, the "epoch" (i.e. :term:`PE`) is involved
6459 but this discussion for the most part ignores ``PE``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006460
6461 The version and revision are taken from the
6462 :term:`PV` and
6463 :term:`PR` variables, respectively.
6464
6465- ``PV``: The recipe version. ``PV`` represents the version of the
6466 software being packaged. Do not confuse ``PV`` with the binary
6467 package version.
6468
6469- ``PR``: The recipe revision.
6470
6471- :term:`SRCPV`: The OpenEmbedded
6472 build system uses this string to help define the value of ``PV`` when
6473 the source code revision needs to be included in it.
6474
Andrew Geissler09209ee2020-12-13 08:44:15 -06006475- :yocto_wiki:`PR Service </PR_Service>`: A
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006476 network-based service that helps automate keeping package feeds
6477 compatible with existing package manager applications such as RPM,
6478 APT, and OPKG.
6479
6480Whenever the binary package content changes, the binary package version
6481must change. Changing the binary package version is accomplished by
6482changing or "bumping" the ``PR`` and/or ``PV`` values. Increasing these
6483values occurs one of two ways:
6484
6485- Automatically using a Package Revision Service (PR Service).
6486
6487- Manually incrementing the ``PR`` and/or ``PV`` variables.
6488
6489Given a primary challenge of any build system and its users is how to
6490maintain a package feed that is compatible with existing package manager
6491applications such as RPM, APT, and OPKG, using an automated system is
6492much preferred over a manual system. In either system, the main
6493requirement is that binary package version numbering increases in a
6494linear fashion and that a number of version components exist that
6495support that linear progression. For information on how to ensure
6496package revisioning remains linear, see the "`Automatically Incrementing
6497a Binary Package Revision
6498Number <#automatically-incrementing-a-binary-package-revision-number>`__"
6499section.
6500
6501The following three sections provide related information on the PR
6502Service, the manual method for "bumping" ``PR`` and/or ``PV``, and on
6503how to ensure binary package revisioning remains linear.
6504
6505Working With a PR Service
6506~~~~~~~~~~~~~~~~~~~~~~~~~
6507
6508As mentioned, attempting to maintain revision numbers in the
6509:term:`Metadata` is error prone, inaccurate,
6510and causes problems for people submitting recipes. Conversely, the PR
6511Service automatically generates increasing numbers, particularly the
6512revision field, which removes the human element.
6513
6514.. note::
6515
6516 For additional information on using a PR Service, you can see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06006517 :yocto_wiki:`PR Service </PR_Service>` wiki page.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006518
6519The Yocto Project uses variables in order of decreasing priority to
6520facilitate revision numbering (i.e.
6521:term:`PE`,
6522:term:`PV`, and
6523:term:`PR` for epoch, version, and
6524revision, respectively). The values are highly dependent on the policies
6525and procedures of a given distribution and package feed.
6526
6527Because the OpenEmbedded build system uses
Andrew Geissler09209ee2020-12-13 08:44:15 -06006528":ref:`signatures <overview-manual/concepts:checksums (signatures)>`", which are
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006529unique to a given build, the build system knows when to rebuild
6530packages. All the inputs into a given task are represented by a
6531signature, which can trigger a rebuild when different. Thus, the build
6532system itself does not rely on the ``PR``, ``PV``, and ``PE`` numbers to
6533trigger a rebuild. The signatures, however, can be used to generate
6534these values.
6535
6536The PR Service works with both ``OEBasic`` and ``OEBasicHash``
6537generators. The value of ``PR`` bumps when the checksum changes and the
6538different generator mechanisms change signatures under different
6539circumstances.
6540
6541As implemented, the build system includes values from the PR Service
6542into the ``PR`` field as an addition using the form "``.x``" so ``r0``
6543becomes ``r0.1``, ``r0.2`` and so forth. This scheme allows existing
6544``PR`` values to be used for whatever reasons, which include manual
6545``PR`` bumps, should it be necessary.
6546
6547By default, the PR Service is not enabled or running. Thus, the packages
6548generated are just "self consistent". The build system adds and removes
6549packages and there are no guarantees about upgrade paths but images will
6550be consistent and correct with the latest changes.
6551
6552The simplest form for a PR Service is for it to exist for a single host
6553development system that builds the package feed (building system). For
6554this scenario, you can enable a local PR Service by setting
6555:term:`PRSERV_HOST` in your
6556``local.conf`` file in the :term:`Build Directory`:
6557::
6558
6559 PRSERV_HOST = "localhost:0"
6560
6561Once the service is started, packages will automatically
6562get increasing ``PR`` values and BitBake takes care of starting and
6563stopping the server.
6564
6565If you have a more complex setup where multiple host development systems
6566work against a common, shared package feed, you have a single PR Service
6567running and it is connected to each building system. For this scenario,
6568you need to start the PR Service using the ``bitbake-prserv`` command:
6569::
6570
6571 bitbake-prserv --host ip --port port --start
6572
6573In addition to
6574hand-starting the service, you need to update the ``local.conf`` file of
6575each building system as described earlier so each system points to the
6576server and port.
6577
6578It is also recommended you use build history, which adds some sanity
6579checks to binary package versions, in conjunction with the server that
6580is running the PR Service. To enable build history, add the following to
6581each building system's ``local.conf`` file:
6582::
6583
6584 # It is recommended to activate "buildhistory" for testing the PR service
6585 INHERIT += "buildhistory"
6586 BUILDHISTORY_COMMIT = "1"
6587
6588For information on build
6589history, see the "`Maintaining Build Output
6590Quality <#maintaining-build-output-quality>`__" section.
6591
6592.. note::
6593
6594 The OpenEmbedded build system does not maintain ``PR`` information as
6595 part of the shared state (sstate) packages. If you maintain an sstate
6596 feed, its expected that either all your building systems that
6597 contribute to the sstate feed use a shared PR Service, or you do not
6598 run a PR Service on any of your building systems. Having some systems
6599 use a PR Service while others do not leads to obvious problems.
6600
6601 For more information on shared state, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06006602 ":ref:`overview-manual/concepts:shared state cache`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006603 section in the Yocto Project Overview and Concepts Manual.
6604
6605Manually Bumping PR
6606~~~~~~~~~~~~~~~~~~~
6607
6608The alternative to setting up a PR Service is to manually "bump" the
6609:term:`PR` variable.
6610
6611If a committed change results in changing the package output, then the
6612value of the PR variable needs to be increased (or "bumped") as part of
6613that commit. For new recipes you should add the ``PR`` variable and set
6614its initial value equal to "r0", which is the default. Even though the
6615default value is "r0", the practice of adding it to a new recipe makes
6616it harder to forget to bump the variable when you make changes to the
6617recipe in future.
6618
6619If you are sharing a common ``.inc`` file with multiple recipes, you can
6620also use the ``INC_PR`` variable to ensure that the recipes sharing the
6621``.inc`` file are rebuilt when the ``.inc`` file itself is changed. The
6622``.inc`` file must set ``INC_PR`` (initially to "r0"), and all recipes
6623referring to it should set ``PR`` to "${INC_PR}.0" initially,
6624incrementing the last number when the recipe is changed. If the ``.inc``
6625file is changed then its ``INC_PR`` should be incremented.
6626
6627When upgrading the version of a binary package, assuming the ``PV``
6628changes, the ``PR`` variable should be reset to "r0" (or "${INC_PR}.0"
6629if you are using ``INC_PR``).
6630
6631Usually, version increases occur only to binary packages. However, if
6632for some reason ``PV`` changes but does not increase, you can increase
6633the ``PE`` variable (Package Epoch). The ``PE`` variable defaults to
6634"0".
6635
6636Binary package version numbering strives to follow the `Debian Version
6637Field Policy
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006638Guidelines <https://www.debian.org/doc/debian-policy/ch-controlfields.html>`__.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006639These guidelines define how versions are compared and what "increasing"
6640a version means.
6641
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006642Automatically Incrementing a Package Version Number
6643~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6644
6645When fetching a repository, BitBake uses the
6646:term:`SRCREV` variable to determine
6647the specific source code revision from which to build. You set the
6648``SRCREV`` variable to
6649:term:`AUTOREV` to cause the
6650OpenEmbedded build system to automatically use the latest revision of
6651the software:
6652::
6653
6654 SRCREV = "${AUTOREV}"
6655
6656Furthermore, you need to reference ``SRCPV`` in ``PV`` in order to
6657automatically update the version whenever the revision of the source
6658code changes. Here is an example:
6659::
6660
6661 PV = "1.0+git${SRCPV}"
6662
6663The OpenEmbedded build system substitutes ``SRCPV`` with the following:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006664
6665.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006666
6667 AUTOINC+source_code_revision
6668
6669The build system replaces the ``AUTOINC``
6670with a number. The number used depends on the state of the PR Service:
6671
6672- If PR Service is enabled, the build system increments the number,
6673 which is similar to the behavior of
6674 :term:`PR`. This behavior results in
6675 linearly increasing package versions, which is desirable. Here is an
6676 example:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006677
6678 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006679
6680 hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
6681 hello-world-git_0.0+git1+dd2f5c3565-r0.0_armv7a-neon.ipk
6682
6683- If PR Service is not enabled, the build system replaces the
6684 ``AUTOINC`` placeholder with zero (i.e. "0"). This results in
6685 changing the package version since the source revision is included.
6686 However, package versions are not increased linearly. Here is an
6687 example:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006688
6689 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006690
6691 hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
6692 hello-world-git_0.0+git0+dd2f5c3565-r0.0_armv7a-neon.ipk
6693
6694In summary, the OpenEmbedded build system does not track the history of
6695binary package versions for this purpose. ``AUTOINC``, in this case, is
6696comparable to ``PR``. If PR server is not enabled, ``AUTOINC`` in the
6697package version is simply replaced by "0". If PR server is enabled, the
6698build system keeps track of the package versions and bumps the number
6699when the package revision changes.
6700
6701Handling Optional Module Packaging
6702----------------------------------
6703
6704Many pieces of software split functionality into optional modules (or
6705plugins) and the plugins that are built might depend on configuration
6706options. To avoid having to duplicate the logic that determines what
6707modules are available in your recipe or to avoid having to package each
6708module by hand, the OpenEmbedded build system provides functionality to
6709handle module packaging dynamically.
6710
6711To handle optional module packaging, you need to do two things:
6712
6713- Ensure the module packaging is actually done.
6714
6715- Ensure that any dependencies on optional modules from other recipes
6716 are satisfied by your recipe.
6717
6718Making Sure the Packaging is Done
6719~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6720
6721To ensure the module packaging actually gets done, you use the
6722``do_split_packages`` function within the ``populate_packages`` Python
6723function in your recipe. The ``do_split_packages`` function searches for
6724a pattern of files or directories under a specified path and creates a
6725package for each one it finds by appending to the
6726:term:`PACKAGES` variable and
6727setting the appropriate values for ``FILES_packagename``,
6728``RDEPENDS_packagename``, ``DESCRIPTION_packagename``, and so forth.
6729Here is an example from the ``lighttpd`` recipe:
6730::
6731
6732 python populate_packages_prepend () {
6733 lighttpd_libdir = d.expand('${libdir}')
6734 do_split_packages(d, lighttpd_libdir, '^mod_(.*).so$',
6735 'lighttpd-module-%s', 'Lighttpd module for %s',
6736 extra_depends='')
6737 }
6738
6739The previous example specifies a number of things in the call to
6740``do_split_packages``.
6741
6742- A directory within the files installed by your recipe through
6743 ``do_install`` in which to search.
6744
6745- A regular expression used to match module files in that directory. In
6746 the example, note the parentheses () that mark the part of the
6747 expression from which the module name should be derived.
6748
6749- A pattern to use for the package names.
6750
6751- A description for each package.
6752
6753- An empty string for ``extra_depends``, which disables the default
6754 dependency on the main ``lighttpd`` package. Thus, if a file in
6755 ``${libdir}`` called ``mod_alias.so`` is found, a package called
6756 ``lighttpd-module-alias`` is created for it and the
6757 :term:`DESCRIPTION` is set to
6758 "Lighttpd module for alias".
6759
6760Often, packaging modules is as simple as the previous example. However,
6761more advanced options exist that you can use within
6762``do_split_packages`` to modify its behavior. And, if you need to, you
6763can add more logic by specifying a hook function that is called for each
6764package. It is also perfectly acceptable to call ``do_split_packages``
6765multiple times if you have more than one set of modules to package.
6766
6767For more examples that show how to use ``do_split_packages``, see the
6768``connman.inc`` file in the ``meta/recipes-connectivity/connman/``
Andrew Geissler09209ee2020-12-13 08:44:15 -06006769directory of the ``poky`` :ref:`source repository <overview-manual/development-environment:yocto project source repositories>`. You can
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006770also find examples in ``meta/classes/kernel.bbclass``.
6771
6772Following is a reference that shows ``do_split_packages`` mandatory and
6773optional arguments:
6774::
6775
6776 Mandatory arguments
6777
6778 root
6779 The path in which to search
6780 file_regex
6781 Regular expression to match searched files.
6782 Use parentheses () to mark the part of this
6783 expression that should be used to derive the
6784 module name (to be substituted where %s is
6785 used in other function arguments as noted below)
6786 output_pattern
6787 Pattern to use for the package names. Must
6788 include %s.
6789 description
6790 Description to set for each package. Must
6791 include %s.
6792
6793 Optional arguments
6794
6795 postinst
6796 Postinstall script to use for all packages
6797 (as a string)
6798 recursive
6799 True to perform a recursive search - default
6800 False
6801 hook
6802 A hook function to be called for every match.
6803 The function will be called with the following
6804 arguments (in the order listed):
6805
6806 f
6807 Full path to the file/directory match
6808 pkg
6809 The package name
6810 file_regex
6811 As above
6812 output_pattern
6813 As above
6814 modulename
6815 The module name derived using file_regex
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006816 extra_depends
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006817 Extra runtime dependencies (RDEPENDS) to be
6818 set for all packages. The default value of None
6819 causes a dependency on the main package
6820 (${PN}) - if you do not want this, pass empty
6821 string '' for this parameter.
6822 aux_files_pattern
6823 Extra item(s) to be added to FILES for each
6824 package. Can be a single string item or a list
6825 of strings for multiple items. Must include %s.
6826 postrm
6827 postrm script to use for all packages (as a
6828 string)
6829 allow_dirs
6830 True to allow directories to be matched -
6831 default False
6832 prepend
6833 If True, prepend created packages to PACKAGES
6834 instead of the default False which appends them
6835 match_path
6836 match file_regex on the whole relative path to
6837 the root rather than just the file name
6838 aux_files_pattern_verbatim
6839 Extra item(s) to be added to FILES for each
6840 package, using the actual derived module name
6841 rather than converting it to something legal
6842 for a package name. Can be a single string item
6843 or a list of strings for multiple items. Must
6844 include %s.
6845 allow_links
6846 True to allow symlinks to be matched - default
6847 False
6848 summary
6849 Summary to set for each package. Must include %s;
6850 defaults to description if not set.
6851
6852
6853
6854Satisfying Dependencies
6855~~~~~~~~~~~~~~~~~~~~~~~
6856
6857The second part for handling optional module packaging is to ensure that
6858any dependencies on optional modules from other recipes are satisfied by
6859your recipe. You can be sure these dependencies are satisfied by using
6860the :term:`PACKAGES_DYNAMIC`
6861variable. Here is an example that continues with the ``lighttpd`` recipe
6862shown earlier:
6863::
6864
6865 PACKAGES_DYNAMIC = "lighttpd-module-.*"
6866
6867The name
6868specified in the regular expression can of course be anything. In this
6869example, it is ``lighttpd-module-`` and is specified as the prefix to
6870ensure that any :term:`RDEPENDS` and
6871:term:`RRECOMMENDS` on a package
6872name starting with the prefix are satisfied during build time. If you
6873are using ``do_split_packages`` as described in the previous section,
6874the value you put in ``PACKAGES_DYNAMIC`` should correspond to the name
6875pattern specified in the call to ``do_split_packages``.
6876
6877Using Runtime Package Management
6878--------------------------------
6879
6880During a build, BitBake always transforms a recipe into one or more
6881packages. For example, BitBake takes the ``bash`` recipe and produces a
6882number of packages (e.g. ``bash``, ``bash-bashbug``,
6883``bash-completion``, ``bash-completion-dbg``, ``bash-completion-dev``,
6884``bash-completion-extra``, ``bash-dbg``, and so forth). Not all
6885generated packages are included in an image.
6886
6887In several situations, you might need to update, add, remove, or query
6888the packages on a target device at runtime (i.e. without having to
6889generate a new image). Examples of such situations include:
6890
6891- You want to provide in-the-field updates to deployed devices (e.g.
6892 security updates).
6893
6894- You want to have a fast turn-around development cycle for one or more
6895 applications that run on your device.
6896
6897- You want to temporarily install the "debug" packages of various
6898 applications on your device so that debugging can be greatly improved
6899 by allowing access to symbols and source debugging.
6900
6901- You want to deploy a more minimal package selection of your device
6902 but allow in-the-field updates to add a larger selection for
6903 customization.
6904
6905In all these situations, you have something similar to a more
6906traditional Linux distribution in that in-field devices are able to
6907receive pre-compiled packages from a server for installation or update.
6908Being able to install these packages on a running, in-field device is
6909what is termed "runtime package management".
6910
6911In order to use runtime package management, you need a host or server
6912machine that serves up the pre-compiled packages plus the required
6913metadata. You also need package manipulation tools on the target. The
6914build machine is a likely candidate to act as the server. However, that
6915machine does not necessarily have to be the package server. The build
6916machine could push its artifacts to another machine that acts as the
6917server (e.g. Internet-facing). In fact, doing so is advantageous for a
6918production environment as getting the packages away from the development
6919system's build directory prevents accidental overwrites.
6920
6921A simple build that targets just one device produces more than one
6922package database. In other words, the packages produced by a build are
6923separated out into a couple of different package groupings based on
6924criteria such as the target's CPU architecture, the target board, or the
6925C library used on the target. For example, a build targeting the
6926``qemux86`` device produces the following three package databases:
6927``noarch``, ``i586``, and ``qemux86``. If you wanted your ``qemux86``
6928device to be aware of all the packages that were available to it, you
6929would need to point it to each of these databases individually. In a
6930similar way, a traditional Linux distribution usually is configured to
6931be aware of a number of software repositories from which it retrieves
6932packages.
6933
6934Using runtime package management is completely optional and not required
6935for a successful build or deployment in any way. But if you want to make
6936use of runtime package management, you need to do a couple things above
6937and beyond the basics. The remainder of this section describes what you
6938need to do.
6939
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006940Build Considerations
6941~~~~~~~~~~~~~~~~~~~~
6942
6943This section describes build considerations of which you need to be
6944aware in order to provide support for runtime package management.
6945
6946When BitBake generates packages, it needs to know what format or formats
6947to use. In your configuration, you use the
6948:term:`PACKAGE_CLASSES`
6949variable to specify the format:
6950
69511. Open the ``local.conf`` file inside your
6952 :term:`Build Directory` (e.g.
6953 ``~/poky/build/conf/local.conf``).
6954
69552. Select the desired package format as follows:
6956 ::
6957
6958 PACKAGE_CLASSES ?= "package_packageformat"
6959
6960 where packageformat can be "ipk", "rpm",
6961 "deb", or "tar" which are the supported package formats.
6962
6963 .. note::
6964
6965 Because the Yocto Project supports four different package formats,
6966 you can set the variable with more than one argument. However, the
6967 OpenEmbedded build system only uses the first argument when
6968 creating an image or Software Development Kit (SDK).
6969
6970If you would like your image to start off with a basic package database
6971containing the packages in your current build as well as to have the
6972relevant tools available on the target for runtime package management,
6973you can include "package-management" in the
6974:term:`IMAGE_FEATURES`
6975variable. Including "package-management" in this configuration variable
6976ensures that when the image is assembled for your target, the image
6977includes the currently-known package databases as well as the
6978target-specific tools required for runtime package management to be
6979performed on the target. However, this is not strictly necessary. You
6980could start your image off without any databases but only include the
6981required on-target package tool(s). As an example, you could include
6982"opkg" in your
6983:term:`IMAGE_INSTALL` variable
6984if you are using the IPK package format. You can then initialize your
6985target's package database(s) later once your image is up and running.
6986
6987Whenever you perform any sort of build step that can potentially
6988generate a package or modify existing package, it is always a good idea
6989to re-generate the package index after the build by using the following
6990command:
6991::
6992
6993 $ bitbake package-index
6994
6995It might be tempting to build the
6996package and the package index at the same time with a command such as
6997the following:
6998::
6999
7000 $ bitbake some-package package-index
7001
7002Do not do this as
7003BitBake does not schedule the package index for after the completion of
7004the package you are building. Consequently, you cannot be sure of the
7005package index including information for the package you just built.
7006Thus, be sure to run the package update step separately after building
7007any packages.
7008
7009You can use the
7010:term:`PACKAGE_FEED_ARCHS`,
7011:term:`PACKAGE_FEED_BASE_PATHS`,
7012and
7013:term:`PACKAGE_FEED_URIS`
7014variables to pre-configure target images to use a package feed. If you
7015do not define these variables, then manual steps as described in the
7016subsequent sections are necessary to configure the target. You should
7017set these variables before building the image in order to produce a
7018correctly configured image.
7019
7020When your build is complete, your packages reside in the
7021``${TMPDIR}/deploy/packageformat`` directory. For example, if
7022``${``\ :term:`TMPDIR`\ ``}`` is
7023``tmp`` and your selected package type is RPM, then your RPM packages
7024are available in ``tmp/deploy/rpm``.
7025
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007026Host or Server Machine Setup
7027~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7028
7029Although other protocols are possible, a server using HTTP typically
7030serves packages. If you want to use HTTP, then set up and configure a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007031web server such as Apache 2, lighttpd, or Python web server on the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007032machine serving the packages.
7033
7034To keep things simple, this section describes how to set up a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007035Python web server to share package feeds from the developer's
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007036machine. Although this server might not be the best for a production
7037environment, the setup is simple and straight forward. Should you want
7038to use a different server more suited for production (e.g. Apache 2,
7039Lighttpd, or Nginx), take the appropriate steps to do so.
7040
7041From within the build directory where you have built an image based on
7042your packaging choice (i.e. the
7043:term:`PACKAGE_CLASSES`
7044setting), simply start the server. The following example assumes a build
7045directory of ``~/poky/build/tmp/deploy/rpm`` and a ``PACKAGE_CLASSES``
7046setting of "package_rpm":
7047::
7048
7049 $ cd ~/poky/build/tmp/deploy/rpm
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007050 $ python3 -m http.server
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007051
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007052Target Setup
7053~~~~~~~~~~~~
7054
7055Setting up the target differs depending on the package management
7056system. This section provides information for RPM, IPK, and DEB.
7057
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007058Using RPM
7059^^^^^^^^^
7060
7061The `Dandified Packaging
7062Tool <https://en.wikipedia.org/wiki/DNF_(software)>`__ (DNF) performs
7063runtime package management of RPM packages. In order to use DNF for
7064runtime package management, you must perform an initial setup on the
7065target machine for cases where the ``PACKAGE_FEED_*`` variables were not
7066set as part of the image that is running on the target. This means if
7067you built your image and did not not use these variables as part of the
7068build and your image is now running on the target, you need to perform
7069the steps in this section if you want to use runtime package management.
7070
7071.. note::
7072
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007073 For information on the ``PACKAGE_FEED_*`` variables, see
7074 :term:`PACKAGE_FEED_ARCHS`, :term:`PACKAGE_FEED_BASE_PATHS`, and
7075 :term:`PACKAGE_FEED_URIS` in the Yocto Project Reference Manual variables
7076 glossary.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007077
7078On the target, you must inform DNF that package databases are available.
7079You do this by creating a file named
7080``/etc/yum.repos.d/oe-packages.repo`` and defining the ``oe-packages``.
7081
7082As an example, assume the target is able to use the following package
7083databases: ``all``, ``i586``, and ``qemux86`` from a server named
7084``my.server``. The specifics for setting up the web server are up to
7085you. The critical requirement is that the URIs in the target repository
7086configuration point to the correct remote location for the feeds.
7087
7088.. note::
7089
7090 For development purposes, you can point the web server to the build
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007091 system's ``deploy`` directory. However, for production use, it is better to
7092 copy the package directories to a location outside of the build area and use
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007093 that location. Doing so avoids situations where the build system
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007094 overwrites or changes the ``deploy`` directory.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007095
7096When telling DNF where to look for the package databases, you must
7097declare individual locations per architecture or a single location used
7098for all architectures. You cannot do both:
7099
7100- *Create an Explicit List of Architectures:* Define individual base
7101 URLs to identify where each package database is located:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007102
7103 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007104
7105 [oe-packages]
7106 baseurl=http://my.server/rpm/i586 http://my.server/rpm/qemux86 http://my.server/rpm/all
7107
7108 This example
7109 informs DNF about individual package databases for all three
7110 architectures.
7111
7112- *Create a Single (Full) Package Index:* Define a single base URL that
7113 identifies where a full package database is located:
7114 ::
7115
7116 [oe-packages]
7117 baseurl=http://my.server/rpm
7118
7119 This example informs DNF about a single
7120 package database that contains all the package index information for
7121 all supported architectures.
7122
7123Once you have informed DNF where to find the package databases, you need
7124to fetch them:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007125
7126.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007127
7128 # dnf makecache
7129
7130DNF is now able to find, install, and
7131upgrade packages from the specified repository or repositories.
7132
7133.. note::
7134
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007135 See the `DNF documentation <https://dnf.readthedocs.io/en/latest/>`__ for
7136 additional information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007137
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007138Using IPK
7139^^^^^^^^^
7140
7141The ``opkg`` application performs runtime package management of IPK
7142packages. You must perform an initial setup for ``opkg`` on the target
7143machine if the
7144:term:`PACKAGE_FEED_ARCHS`,
7145:term:`PACKAGE_FEED_BASE_PATHS`,
7146and
7147:term:`PACKAGE_FEED_URIS`
7148variables have not been set or the target image was built before the
7149variables were set.
7150
7151The ``opkg`` application uses configuration files to find available
7152package databases. Thus, you need to create a configuration file inside
7153the ``/etc/opkg/`` direction, which informs ``opkg`` of any repository
7154you want to use.
7155
7156As an example, suppose you are serving packages from a ``ipk/``
7157directory containing the ``i586``, ``all``, and ``qemux86`` databases
7158through an HTTP server named ``my.server``. On the target, create a
7159configuration file (e.g. ``my_repo.conf``) inside the ``/etc/opkg/``
7160directory containing the following:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007161
7162.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007163
7164 src/gz all http://my.server/ipk/all
7165 src/gz i586 http://my.server/ipk/i586
7166 src/gz qemux86 http://my.server/ipk/qemux86
7167
7168Next, instruct ``opkg`` to fetch the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007169repository information:
7170
7171.. code-block:: none
7172
7173 # opkg update
7174
7175The ``opkg`` application is now able to find, install, and upgrade packages
7176from the specified repository.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007177
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007178Using DEB
7179^^^^^^^^^
7180
7181The ``apt`` application performs runtime package management of DEB
7182packages. This application uses a source list file to find available
7183package databases. You must perform an initial setup for ``apt`` on the
7184target machine if the
7185:term:`PACKAGE_FEED_ARCHS`,
7186:term:`PACKAGE_FEED_BASE_PATHS`,
7187and
7188:term:`PACKAGE_FEED_URIS`
7189variables have not been set or the target image was built before the
7190variables were set.
7191
7192To inform ``apt`` of the repository you want to use, you might create a
7193list file (e.g. ``my_repo.list``) inside the
7194``/etc/apt/sources.list.d/`` directory. As an example, suppose you are
7195serving packages from a ``deb/`` directory containing the ``i586``,
7196``all``, and ``qemux86`` databases through an HTTP server named
7197``my.server``. The list file should contain:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007198
7199.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007200
7201 deb http://my.server/deb/all ./
7202 deb http://my.server/deb/i586 ./
7203 deb http://my.server/deb/qemux86 ./
7204
7205Next, instruct the ``apt`` application
7206to fetch the repository information:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007207
7208.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007209
7210 # apt-get update
7211
7212After this step,
7213``apt`` is able to find, install, and upgrade packages from the
7214specified repository.
7215
7216Generating and Using Signed Packages
7217------------------------------------
7218
7219In order to add security to RPM packages used during a build, you can
7220take steps to securely sign them. Once a signature is verified, the
7221OpenEmbedded build system can use the package in the build. If security
7222fails for a signed package, the build system aborts the build.
7223
7224This section describes how to sign RPM packages during a build and how
7225to use signed package feeds (repositories) when doing a build.
7226
7227Signing RPM Packages
7228~~~~~~~~~~~~~~~~~~~~
7229
7230To enable signing RPM packages, you must set up the following
7231configurations in either your ``local.config`` or ``distro.config``
7232file:
7233::
7234
7235 # Inherit sign_rpm.bbclass to enable signing functionality
7236 INHERIT += " sign_rpm"
7237 # Define the GPG key that will be used for signing.
7238 RPM_GPG_NAME = "key_name"
7239 # Provide passphrase for the key
7240 RPM_GPG_PASSPHRASE = "passphrase"
7241
7242.. note::
7243
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007244 Be sure to supply appropriate values for both `key_name` and
7245 `passphrase`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007246
7247Aside from the ``RPM_GPG_NAME`` and ``RPM_GPG_PASSPHRASE`` variables in
7248the previous example, two optional variables related to signing exist:
7249
7250- *GPG_BIN:* Specifies a ``gpg`` binary/wrapper that is executed
7251 when the package is signed.
7252
7253- *GPG_PATH:* Specifies the ``gpg`` home directory used when the
7254 package is signed.
7255
7256Processing Package Feeds
7257~~~~~~~~~~~~~~~~~~~~~~~~
7258
7259In addition to being able to sign RPM packages, you can also enable
7260signed package feeds for IPK and RPM packages.
7261
7262The steps you need to take to enable signed package feed use are similar
7263to the steps used to sign RPM packages. You must define the following in
7264your ``local.config`` or ``distro.config`` file:
7265::
7266
7267 INHERIT += "sign_package_feed"
7268 PACKAGE_FEED_GPG_NAME = "key_name"
7269 PACKAGE_FEED_GPG_PASSPHRASE_FILE = "path_to_file_containing_passphrase"
7270
7271For signed package feeds, the passphrase must exist in a separate file,
7272which is pointed to by the ``PACKAGE_FEED_GPG_PASSPHRASE_FILE``
7273variable. Regarding security, keeping a plain text passphrase out of the
7274configuration is more secure.
7275
7276Aside from the ``PACKAGE_FEED_GPG_NAME`` and
7277``PACKAGE_FEED_GPG_PASSPHRASE_FILE`` variables, three optional variables
7278related to signed package feeds exist:
7279
7280- *GPG_BIN* Specifies a ``gpg`` binary/wrapper that is executed
7281 when the package is signed.
7282
7283- *GPG_PATH:* Specifies the ``gpg`` home directory used when the
7284 package is signed.
7285
7286- *PACKAGE_FEED_GPG_SIGNATURE_TYPE:* Specifies the type of ``gpg``
7287 signature. This variable applies only to RPM and IPK package feeds.
7288 Allowable values for the ``PACKAGE_FEED_GPG_SIGNATURE_TYPE`` are
7289 "ASC", which is the default and specifies ascii armored, and "BIN",
7290 which specifies binary.
7291
7292Testing Packages With ptest
7293---------------------------
7294
7295A Package Test (ptest) runs tests against packages built by the
7296OpenEmbedded build system on the target machine. A ptest contains at
7297least two items: the actual test, and a shell script (``run-ptest``)
7298that starts the test. The shell script that starts the test must not
7299contain the actual test - the script only starts the test. On the other
7300hand, the test can be anything from a simple shell script that runs a
7301binary and checks the output to an elaborate system of test binaries and
7302data files.
7303
7304The test generates output in the format used by Automake:
7305::
7306
7307 result: testname
7308
7309where the result can be ``PASS``, ``FAIL``, or ``SKIP``, and
7310the testname can be any identifying string.
7311
7312For a list of Yocto Project recipes that are already enabled with ptest,
Andrew Geissler09209ee2020-12-13 08:44:15 -06007313see the :yocto_wiki:`Ptest </Ptest>` wiki page.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007314
7315.. note::
7316
7317 A recipe is "ptest-enabled" if it inherits the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007318 :ref:`ptest <ref-classes-ptest>` class.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007319
7320Adding ptest to Your Build
7321~~~~~~~~~~~~~~~~~~~~~~~~~~
7322
7323To add package testing to your build, add the
7324:term:`DISTRO_FEATURES` and
7325:term:`EXTRA_IMAGE_FEATURES`
7326variables to your ``local.conf`` file, which is found in the
7327:term:`Build Directory`:
7328::
7329
7330 DISTRO_FEATURES_append = " ptest"
7331 EXTRA_IMAGE_FEATURES += "ptest-pkgs"
7332
7333Once your build is complete, the ptest files are installed into the
7334``/usr/lib/package/ptest`` directory within the image, where ``package``
7335is the name of the package.
7336
7337Running ptest
7338~~~~~~~~~~~~~
7339
7340The ``ptest-runner`` package installs a shell script that loops through
7341all installed ptest test suites and runs them in sequence. Consequently,
7342you might want to add this package to your image.
7343
7344Getting Your Package Ready
7345~~~~~~~~~~~~~~~~~~~~~~~~~~
7346
7347In order to enable a recipe to run installed ptests on target hardware,
7348you need to prepare the recipes that build the packages you want to
7349test. Here is what you have to do for each recipe:
7350
7351- *Be sure the recipe inherits
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007352 the* :ref:`ptest <ref-classes-ptest>` *class:*
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007353 Include the following line in each recipe:
7354 ::
7355
7356 inherit ptest
7357
7358- *Create run-ptest:* This script starts your test. Locate the
7359 script where you will refer to it using
7360 :term:`SRC_URI`. Here is an
7361 example that starts a test for ``dbus``:
7362 ::
7363
7364 #!/bin/sh
7365 cd test
7366 make -k runtest-TESTS
7367
7368- *Ensure dependencies are met:* If the test adds build or runtime
7369 dependencies that normally do not exist for the package (such as
7370 requiring "make" to run the test suite), use the
7371 :term:`DEPENDS` and
7372 :term:`RDEPENDS` variables in
7373 your recipe in order for the package to meet the dependencies. Here
7374 is an example where the package has a runtime dependency on "make":
7375 ::
7376
7377 RDEPENDS_${PN}-ptest += "make"
7378
7379- *Add a function to build the test suite:* Not many packages support
7380 cross-compilation of their test suites. Consequently, you usually
7381 need to add a cross-compilation function to the package.
7382
7383 Many packages based on Automake compile and run the test suite by
7384 using a single command such as ``make check``. However, the host
7385 ``make check`` builds and runs on the same computer, while
7386 cross-compiling requires that the package is built on the host but
7387 executed for the target architecture (though often, as in the case
7388 for ptest, the execution occurs on the host). The built version of
7389 Automake that ships with the Yocto Project includes a patch that
7390 separates building and execution. Consequently, packages that use the
7391 unaltered, patched version of ``make check`` automatically
7392 cross-compiles.
7393
7394 Regardless, you still must add a ``do_compile_ptest`` function to
7395 build the test suite. Add a function similar to the following to your
7396 recipe:
7397 ::
7398
7399 do_compile_ptest() {
7400 oe_runmake buildtest-TESTS
7401 }
7402
7403- *Ensure special configurations are set:* If the package requires
7404 special configurations prior to compiling the test code, you must
7405 insert a ``do_configure_ptest`` function into the recipe.
7406
7407- *Install the test suite:* The ``ptest`` class automatically copies
7408 the file ``run-ptest`` to the target and then runs make
7409 ``install-ptest`` to run the tests. If this is not enough, you need
7410 to create a ``do_install_ptest`` function and make sure it gets
7411 called after the "make install-ptest" completes.
7412
7413Creating Node Package Manager (NPM) Packages
7414--------------------------------------------
7415
7416`NPM <https://en.wikipedia.org/wiki/Npm_(software)>`__ is a package
7417manager for the JavaScript programming language. The Yocto Project
Andrew Geissler09209ee2020-12-13 08:44:15 -06007418supports the NPM :ref:`fetcher <bitbake:bitbake-user-manual/bitbake-user-manual-fetching:fetchers>`. You can
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007419use this fetcher in combination with
Andrew Geissler09209ee2020-12-13 08:44:15 -06007420:doc:`devtool </ref-manual/devtool-reference>` to create
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007421recipes that produce NPM packages.
7422
7423Two workflows exist that allow you to create NPM packages using
7424``devtool``: the NPM registry modules method and the NPM project code
7425method.
7426
7427.. note::
7428
7429 While it is possible to create NPM recipes manually, using
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007430 ``devtool`` is far simpler.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007431
7432Additionally, some requirements and caveats exist.
7433
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007434Requirements and Caveats
7435~~~~~~~~~~~~~~~~~~~~~~~~
7436
7437You need to be aware of the following before using ``devtool`` to create
7438NPM packages:
7439
7440- Of the two methods that you can use ``devtool`` to create NPM
7441 packages, the registry approach is slightly simpler. However, you
7442 might consider the project approach because you do not have to
7443 publish your module in the NPM registry
7444 (`npm-registry <https://docs.npmjs.com/misc/registry>`_), which
7445 is NPM's public registry.
7446
7447- Be familiar with
Andrew Geissler09209ee2020-12-13 08:44:15 -06007448 :doc:`devtool </ref-manual/devtool-reference>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007449
7450- The NPM host tools need the native ``nodejs-npm`` package, which is
7451 part of the OpenEmbedded environment. You need to get the package by
7452 cloning the https://github.com/openembedded/meta-openembedded
7453 repository out of GitHub. Be sure to add the path to your local copy
7454 to your ``bblayers.conf`` file.
7455
7456- ``devtool`` cannot detect native libraries in module dependencies.
7457 Consequently, you must manually add packages to your recipe.
7458
7459- While deploying NPM packages, ``devtool`` cannot determine which
7460 dependent packages are missing on the target (e.g. the node runtime
7461 ``nodejs``). Consequently, you need to find out what files are
7462 missing and be sure they are on the target.
7463
7464- Although you might not need NPM to run your node package, it is
7465 useful to have NPM on your target. The NPM package name is
7466 ``nodejs-npm``.
7467
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007468Using the Registry Modules Method
7469~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7470
7471This section presents an example that uses the ``cute-files`` module,
7472which is a file browser web application.
7473
7474.. note::
7475
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007476 You must know the ``cute-files`` module version.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007477
7478The first thing you need to do is use ``devtool`` and the NPM fetcher to
7479create the recipe:
7480::
7481
7482 $ devtool add "npm://registry.npmjs.org;package=cute-files;version=1.0.2"
7483
7484The
7485``devtool add`` command runs ``recipetool create`` and uses the same
7486fetch URI to download each dependency and capture license details where
7487possible. The result is a generated recipe.
7488
7489The recipe file is fairly simple and contains every license that
7490``recipetool`` finds and includes the licenses in the recipe's
7491:term:`LIC_FILES_CHKSUM`
7492variables. You need to examine the variables and look for those with
7493"unknown" in the :term:`LICENSE`
7494field. You need to track down the license information for "unknown"
7495modules and manually add the information to the recipe.
7496
7497``recipetool`` creates a "shrinkwrap" file for your recipe. Shrinkwrap
7498files capture the version of all dependent modules. Many packages do not
7499provide shrinkwrap files. ``recipetool`` create a shrinkwrap file as it
7500runs.
7501
7502.. note::
7503
7504 A package is created for each sub-module. This policy is the only
7505 practical way to have the licenses for all of the dependencies
7506 represented in the license manifest of the image.
7507
7508The ``devtool edit-recipe`` command lets you take a look at the recipe:
7509::
7510
7511 $ devtool edit-recipe cute-files
7512 SUMMARY = "Turn any folder on your computer into a cute file browser, available on the local network."
7513 LICENSE = "MIT & ISC & Unknown"
7514 LIC_FILES_CHKSUM = "file://LICENSE;md5=71d98c0a1db42956787b1909c74a86ca \
7515 file://node_modules/toidentifier/LICENSE;md5=1a261071a044d02eb6f2bb47f51a3502 \
7516 file://node_modules/debug/LICENSE;md5=ddd815a475e7338b0be7a14d8ee35a99 \
7517 ...
7518 SRC_URI = " \
7519 npm://registry.npmjs.org/;package=cute-files;version=${PV} \
7520 npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \
7521 "
7522 S = "${WORKDIR}/npm"
7523 inherit npm LICENSE_${PN} = "MIT"
7524 LICENSE_${PN}-accepts = "MIT"
7525 LICENSE_${PN}-array-flatten = "MIT"
7526 ...
7527 LICENSE_${PN}-vary = "MIT"
7528
7529Three key points exist in the previous example:
7530
7531- :term:`SRC_URI` uses the NPM
7532 scheme so that the NPM fetcher is used.
7533
7534- ``recipetool`` collects all the license information. If a
7535 sub-module's license is unavailable, the sub-module's name appears in
7536 the comments.
7537
7538- The ``inherit npm`` statement causes the
7539 :ref:`npm <ref-classes-npm>` class to package
7540 up all the modules.
7541
7542You can run the following command to build the ``cute-files`` package:
7543::
7544
7545 $ devtool build cute-files
7546
7547Remember that ``nodejs`` must be installed on
7548the target before your package.
7549
7550Assuming 192.168.7.2 for the target's IP address, use the following
7551command to deploy your package:
7552::
7553
7554 $ devtool deploy-target -s cute-files root@192.168.7.2
7555
7556Once the package is installed on the target, you can
7557test the application:
7558
7559.. note::
7560
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007561 Because of a known issue, you cannot simply run ``cute-files`` as you would
7562 if you had run ``npm install``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007563
7564::
7565
7566 $ cd /usr/lib/node_modules/cute-files
7567 $ node cute-files.js
7568
7569On a browser,
7570go to ``http://192.168.7.2:3000`` and you see the following:
7571
7572.. image:: figures/cute-files-npm-example.png
7573 :align: center
7574
7575You can find the recipe in ``workspace/recipes/cute-files``. You can use
7576the recipe in any layer you choose.
7577
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007578Using the NPM Projects Code Method
7579~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7580
7581Although it is useful to package modules already in the NPM registry,
7582adding ``node.js`` projects under development is a more common developer
7583use case.
7584
7585This section covers the NPM projects code method, which is very similar
7586to the "registry" approach described in the previous section. In the NPM
7587projects method, you provide ``devtool`` with an URL that points to the
7588source files.
7589
7590Replicating the same example, (i.e. ``cute-files``) use the following
7591command:
7592::
7593
7594 $ devtool add https://github.com/martinaglv/cute-files.git
7595
7596The
7597recipe this command generates is very similar to the recipe created in
7598the previous section. However, the ``SRC_URI`` looks like the following:
7599::
7600
7601 SRC_URI = " \
7602 git://github.com/martinaglv/cute-files.git;protocol=https \
7603 npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \
7604 "
7605
7606In this example,
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007607the main module is taken from the Git repository and dependencies are
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007608taken from the NPM registry. Other than those differences, the recipe is
7609basically the same between the two methods. You can build and deploy the
7610package exactly as described in the previous section that uses the
7611registry modules method.
7612
7613Adding custom metadata to packages
7614----------------------------------
7615
7616The variable
7617:term:`PACKAGE_ADD_METADATA`
7618can be used to add additional metadata to packages. This is reflected in
7619the package control/spec file. To take the ipk format for example, the
7620CONTROL file stored inside would contain the additional metadata as
7621additional lines.
7622
7623The variable can be used in multiple ways, including using suffixes to
7624set it for a specific package type and/or package. Note that the order
7625of precedence is the same as this list:
7626
7627- ``PACKAGE_ADD_METADATA_<PKGTYPE>_<PN>``
7628
7629- ``PACKAGE_ADD_METADATA_<PKGTYPE>``
7630
7631- ``PACKAGE_ADD_METADATA_<PN>``
7632
7633- ``PACKAGE_ADD_METADATA``
7634
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007635`<PKGTYPE>` is a parameter and expected to be a distinct name of specific
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007636package type:
7637
7638- IPK for .ipk packages
7639
7640- DEB for .deb packages
7641
7642- RPM for .rpm packages
7643
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007644`<PN>` is a parameter and expected to be a package name.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007645
7646The variable can contain multiple [one-line] metadata fields separated
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007647by the literal sequence '\\n'. The separator can be redefined using the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007648variable flag ``separator``.
7649
7650The following is an example that adds two custom fields for ipk
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007651packages:
7652::
7653
7654 PACKAGE_ADD_METADATA_IPK = "Vendor: CustomIpk\nGroup:Applications/Spreadsheets"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007655
7656Efficiently Fetching Source Files During a Build
7657================================================
7658
7659The OpenEmbedded build system works with source files located through
7660the :term:`SRC_URI` variable. When
7661you build something using BitBake, a big part of the operation is
7662locating and downloading all the source tarballs. For images,
7663downloading all the source for various packages can take a significant
7664amount of time.
7665
7666This section shows you how you can use mirrors to speed up fetching
7667source files and how you can pre-fetch files all of which leads to more
7668efficient use of resources and time.
7669
7670Setting up Effective Mirrors
7671----------------------------
7672
7673A good deal that goes into a Yocto Project build is simply downloading
7674all of the source tarballs. Maybe you have been working with another
7675build system (OpenEmbedded or Angstrom) for which you have built up a
7676sizable directory of source tarballs. Or, perhaps someone else has such
7677a directory for which you have read access. If so, you can save time by
7678adding statements to your configuration file so that the build process
7679checks local directories first for existing tarballs before checking the
7680Internet.
7681
7682Here is an efficient way to set it up in your ``local.conf`` file:
7683::
7684
7685 SOURCE_MIRROR_URL ?= "file:///home/you/your-download-dir/"
7686 INHERIT += "own-mirrors"
7687 BB_GENERATE_MIRROR_TARBALLS = "1"
7688 # BB_NO_NETWORK = "1"
7689
7690In the previous example, the
7691:term:`BB_GENERATE_MIRROR_TARBALLS`
7692variable causes the OpenEmbedded build system to generate tarballs of
7693the Git repositories and store them in the
7694:term:`DL_DIR` directory. Due to
7695performance reasons, generating and storing these tarballs is not the
7696build system's default behavior.
7697
7698You can also use the
7699:term:`PREMIRRORS` variable. For
7700an example, see the variable's glossary entry in the Yocto Project
7701Reference Manual.
7702
7703Getting Source Files and Suppressing the Build
7704----------------------------------------------
7705
7706Another technique you can use to ready yourself for a successive string
7707of build operations, is to pre-fetch all the source files without
7708actually starting a build. This technique lets you work through any
7709download issues and ultimately gathers all the source files into your
7710download directory :ref:`structure-build-downloads`,
7711which is located with :term:`DL_DIR`.
7712
7713Use the following BitBake command form to fetch all the necessary
7714sources without starting the build:
7715::
7716
7717 $ bitbake target --runall=fetch
7718
7719This
7720variation of the BitBake command guarantees that you have all the
7721sources for that BitBake target should you disconnect from the Internet
7722and want to do the build later offline.
7723
7724Selecting an Initialization Manager
7725===================================
7726
7727By default, the Yocto Project uses SysVinit as the initialization
7728manager. However, support also exists for systemd, which is a full
7729replacement for init with parallel starting of services, reduced shell
7730overhead and other features that are used by many distributions.
7731
7732Within the system, SysVinit treats system components as services. These
7733services are maintained as shell scripts stored in the ``/etc/init.d/``
7734directory. Services organize into different run levels. This
7735organization is maintained by putting links to the services in the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007736``/etc/rcN.d/`` directories, where `N/` is one of the following options:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007737"S", "0", "1", "2", "3", "4", "5", or "6".
7738
7739.. note::
7740
7741 Each runlevel has a dependency on the previous runlevel. This
7742 dependency allows the services to work properly.
7743
7744In comparison, systemd treats components as units. Using units is a
7745broader concept as compared to using a service. A unit includes several
7746different types of entities. Service is one of the types of entities.
7747The runlevel concept in SysVinit corresponds to the concept of a target
7748in systemd, where target is also a type of supported unit.
7749
7750In a SysVinit-based system, services load sequentially (i.e. one by one)
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007751during init and parallelization is not supported. With systemd, services
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007752start in parallel. Needless to say, the method can have an impact on
7753system startup performance.
7754
7755If you want to use SysVinit, you do not have to do anything. But, if you
7756want to use systemd, you must take some steps as described in the
7757following sections.
7758
7759Using systemd Exclusively
7760-------------------------
7761
7762Set these variables in your distribution configuration file as follows:
7763::
7764
7765 DISTRO_FEATURES_append = " systemd"
7766 VIRTUAL-RUNTIME_init_manager = "systemd"
7767
7768You can also prevent the SysVinit distribution feature from
7769being automatically enabled as follows:
7770::
7771
7772 DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
7773
7774Doing so removes any
7775redundant SysVinit scripts.
7776
7777To remove initscripts from your image altogether, set this variable
7778also:
7779::
7780
7781 VIRTUAL-RUNTIME_initscripts = ""
7782
7783For information on the backfill variable, see
7784:term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`.
7785
7786Using systemd for the Main Image and Using SysVinit for the Rescue Image
7787------------------------------------------------------------------------
7788
7789Set these variables in your distribution configuration file as follows:
7790::
7791
7792 DISTRO_FEATURES_append = " systemd"
7793 VIRTUAL-RUNTIME_init_manager = "systemd"
7794
7795Doing so causes your main image to use the
7796``packagegroup-core-boot.bb`` recipe and systemd. The rescue/minimal
7797image cannot use this package group. However, it can install SysVinit
7798and the appropriate packages will have support for both systemd and
7799SysVinit.
7800
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007801Selecting a Device Manager
7802==========================
7803
7804The Yocto Project provides multiple ways to manage the device manager
7805(``/dev``):
7806
7807- Persistent and Pre-Populated\ ``/dev``: For this case, the ``/dev``
7808 directory is persistent and the required device nodes are created
7809 during the build.
7810
7811- Use ``devtmpfs`` with a Device Manager: For this case, the ``/dev``
7812 directory is provided by the kernel as an in-memory file system and
7813 is automatically populated by the kernel at runtime. Additional
7814 configuration of device nodes is done in user space by a device
7815 manager like ``udev`` or ``busybox-mdev``.
7816
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007817Using Persistent and Pre-Populated\ ``/dev``
7818--------------------------------------------
7819
7820To use the static method for device population, you need to set the
7821:term:`USE_DEVFS` variable to "0"
7822as follows:
7823::
7824
7825 USE_DEVFS = "0"
7826
7827The content of the resulting ``/dev`` directory is defined in a Device
7828Table file. The
7829:term:`IMAGE_DEVICE_TABLES`
7830variable defines the Device Table to use and should be set in the
7831machine or distro configuration file. Alternatively, you can set this
7832variable in your ``local.conf`` configuration file.
7833
7834If you do not define the ``IMAGE_DEVICE_TABLES`` variable, the default
7835``device_table-minimal.txt`` is used:
7836::
7837
7838 IMAGE_DEVICE_TABLES = "device_table-mymachine.txt"
7839
7840The population is handled by the ``makedevs`` utility during image
7841creation:
7842
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007843Using ``devtmpfs`` and a Device Manager
7844---------------------------------------
7845
7846To use the dynamic method for device population, you need to use (or be
7847sure to set) the :term:`USE_DEVFS`
7848variable to "1", which is the default:
7849::
7850
7851 USE_DEVFS = "1"
7852
7853With this
7854setting, the resulting ``/dev`` directory is populated by the kernel
7855using ``devtmpfs``. Make sure the corresponding kernel configuration
7856variable ``CONFIG_DEVTMPFS`` is set when building you build a Linux
7857kernel.
7858
7859All devices created by ``devtmpfs`` will be owned by ``root`` and have
7860permissions ``0600``.
7861
7862To have more control over the device nodes, you can use a device manager
7863like ``udev`` or ``busybox-mdev``. You choose the device manager by
7864defining the ``VIRTUAL-RUNTIME_dev_manager`` variable in your machine or
7865distro configuration file. Alternatively, you can set this variable in
7866your ``local.conf`` configuration file:
7867::
7868
7869 VIRTUAL-RUNTIME_dev_manager = "udev"
7870
7871 # Some alternative values
7872 # VIRTUAL-RUNTIME_dev_manager = "busybox-mdev"
7873 # VIRTUAL-RUNTIME_dev_manager = "systemd"
7874
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007875Using an External SCM
7876=====================
7877
7878If you're working on a recipe that pulls from an external Source Code
7879Manager (SCM), it is possible to have the OpenEmbedded build system
7880notice new recipe changes added to the SCM and then build the resulting
7881packages that depend on the new recipes by using the latest versions.
7882This only works for SCMs from which it is possible to get a sensible
7883revision number for changes. Currently, you can do this with Apache
7884Subversion (SVN), Git, and Bazaar (BZR) repositories.
7885
7886To enable this behavior, the :term:`PV` of
7887the recipe needs to reference
7888:term:`SRCPV`. Here is an example:
7889::
7890
7891 PV = "1.2.3+git${SRCPV}"
7892
7893Then, you can add the following to your
7894``local.conf``:
7895::
7896
7897 SRCREV_pn-PN = "${AUTOREV}"
7898
7899:term:`PN` is the name of the recipe for
7900which you want to enable automatic source revision updating.
7901
7902If you do not want to update your local configuration file, you can add
7903the following directly to the recipe to finish enabling the feature:
7904::
7905
7906 SRCREV = "${AUTOREV}"
7907
7908The Yocto Project provides a distribution named ``poky-bleeding``, whose
7909configuration file contains the line:
7910::
7911
7912 require conf/distro/include/poky-floating-revisions.inc
7913
7914This line pulls in the
7915listed include file that contains numerous lines of exactly that form:
7916::
7917
7918 #SRCREV_pn-opkg-native ?= "${AUTOREV}"
7919 #SRCREV_pn-opkg-sdk ?= "${AUTOREV}"
7920 #SRCREV_pn-opkg ?= "${AUTOREV}"
7921 #SRCREV_pn-opkg-utils-native ?= "${AUTOREV}"
7922 #SRCREV_pn-opkg-utils ?= "${AUTOREV}"
7923 SRCREV_pn-gconf-dbus ?= "${AUTOREV}"
7924 SRCREV_pn-matchbox-common ?= "${AUTOREV}"
7925 SRCREV_pn-matchbox-config-gtk ?= "${AUTOREV}"
7926 SRCREV_pn-matchbox-desktop ?= "${AUTOREV}"
7927 SRCREV_pn-matchbox-keyboard ?= "${AUTOREV}"
7928 SRCREV_pn-matchbox-panel-2 ?= "${AUTOREV}"
7929 SRCREV_pn-matchbox-themes-extra ?= "${AUTOREV}"
7930 SRCREV_pn-matchbox-terminal ?= "${AUTOREV}"
7931 SRCREV_pn-matchbox-wm ?= "${AUTOREV}"
7932 SRCREV_pn-settings-daemon ?= "${AUTOREV}"
7933 SRCREV_pn-screenshot ?= "${AUTOREV}"
7934 . . .
7935
7936These lines allow you to
7937experiment with building a distribution that tracks the latest
7938development source for numerous packages.
7939
7940.. note::
7941
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007942 The ``poky-bleeding`` distribution is not tested on a regular basis. Keep
7943 this in mind if you use it.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007944
7945Creating a Read-Only Root Filesystem
7946====================================
7947
7948Suppose, for security reasons, you need to disable your target device's
7949root filesystem's write permissions (i.e. you need a read-only root
7950filesystem). Or, perhaps you are running the device's operating system
7951from a read-only storage device. For either case, you can customize your
7952image for that behavior.
7953
7954.. note::
7955
7956 Supporting a read-only root filesystem requires that the system and
7957 applications do not try to write to the root filesystem. You must
7958 configure all parts of the target system to write elsewhere, or to
7959 gracefully fail in the event of attempting to write to the root
7960 filesystem.
7961
7962Creating the Root Filesystem
7963----------------------------
7964
7965To create the read-only root filesystem, simply add the
7966"read-only-rootfs" feature to your image, normally in one of two ways.
7967The first way is to add the "read-only-rootfs" image feature in the
7968image's recipe file via the ``IMAGE_FEATURES`` variable:
7969::
7970
7971 IMAGE_FEATURES += "read-only-rootfs"
7972
7973As an alternative, you can add the same feature
7974from within your build directory's ``local.conf`` file with the
7975associated ``EXTRA_IMAGE_FEATURES`` variable, as in:
7976::
7977
7978 EXTRA_IMAGE_FEATURES = "read-only-rootfs"
7979
7980For more information on how to use these variables, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06007981":ref:`dev-manual/common-tasks:Customizing Images Using Custom \`\`IMAGE_FEATURES\`\` and \`\`EXTRA_IMAGE_FEATURES\`\``"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007982section. For information on the variables, see
7983:term:`IMAGE_FEATURES` and
7984:term:`EXTRA_IMAGE_FEATURES`.
7985
7986Post-Installation Scripts and Read-Only Root Filesystem
7987-------------------------------------------------------
7988
7989It is very important that you make sure all post-Installation
7990(``pkg_postinst``) scripts for packages that are installed into the
7991image can be run at the time when the root filesystem is created during
7992the build on the host system. These scripts cannot attempt to run during
7993first-boot on the target device. With the "read-only-rootfs" feature
7994enabled, the build system checks during root filesystem creation to make
7995sure all post-installation scripts succeed. If any of these scripts
7996still need to be run after the root filesystem is created, the build
7997immediately fails. These build-time checks ensure that the build fails
7998rather than the target device fails later during its initial boot
7999operation.
8000
8001Most of the common post-installation scripts generated by the build
8002system for the out-of-the-box Yocto Project are engineered so that they
8003can run during root filesystem creation (e.g. post-installation scripts
8004for caching fonts). However, if you create and add custom scripts, you
8005need to be sure they can be run during this file system creation.
8006
8007Here are some common problems that prevent post-installation scripts
8008from running during root filesystem creation:
8009
8010- *Not using $D in front of absolute paths:* The build system defines
8011 ``$``\ :term:`D` when the root
8012 filesystem is created. Furthermore, ``$D`` is blank when the script
8013 is run on the target device. This implies two purposes for ``$D``:
8014 ensuring paths are valid in both the host and target environments,
8015 and checking to determine which environment is being used as a method
8016 for taking appropriate actions.
8017
8018- *Attempting to run processes that are specific to or dependent on the
8019 target architecture:* You can work around these attempts by using
8020 native tools, which run on the host system, to accomplish the same
8021 tasks, or by alternatively running the processes under QEMU, which
8022 has the ``qemu_run_binary`` function. For more information, see the
8023 :ref:`qemu <ref-classes-qemu>` class.
8024
8025Areas With Write Access
8026-----------------------
8027
8028With the "read-only-rootfs" feature enabled, any attempt by the target
8029to write to the root filesystem at runtime fails. Consequently, you must
8030make sure that you configure processes and applications that attempt
8031these types of writes do so to directories with write access (e.g.
8032``/tmp`` or ``/var/run``).
8033
8034Maintaining Build Output Quality
8035================================
8036
8037Many factors can influence the quality of a build. For example, if you
8038upgrade a recipe to use a new version of an upstream software package or
8039you experiment with some new configuration options, subtle changes can
8040occur that you might not detect until later. Consider the case where
8041your recipe is using a newer version of an upstream package. In this
8042case, a new version of a piece of software might introduce an optional
8043dependency on another library, which is auto-detected. If that library
8044has already been built when the software is building, the software will
8045link to the built library and that library will be pulled into your
8046image along with the new software even if you did not want the library.
8047
8048The :ref:`buildhistory <ref-classes-buildhistory>`
8049class exists to help you maintain the quality of your build output. You
8050can use the class to highlight unexpected and possibly unwanted changes
8051in the build output. When you enable build history, it records
8052information about the contents of each package and image and then
8053commits that information to a local Git repository where you can examine
8054the information.
8055
8056The remainder of this section describes the following:
8057
Andrew Geissler09209ee2020-12-13 08:44:15 -06008058- :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 -05008059
Andrew Geissler09209ee2020-12-13 08:44:15 -06008060- :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 -05008061
Andrew Geissler09209ee2020-12-13 08:44:15 -06008062- :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 -05008063
Andrew Geissler09209ee2020-12-13 08:44:15 -06008064- :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 -05008065
8066Enabling and Disabling Build History
8067------------------------------------
8068
8069Build history is disabled by default. To enable it, add the following
8070``INHERIT`` statement and set the
8071:term:`BUILDHISTORY_COMMIT`
8072variable to "1" at the end of your ``conf/local.conf`` file found in the
8073:term:`Build Directory`:
8074::
8075
8076 INHERIT += "buildhistory"
8077 BUILDHISTORY_COMMIT = "1"
8078
8079Enabling build history as
8080previously described causes the OpenEmbedded build system to collect
8081build output information and commit it as a single commit to a local
Andrew Geissler09209ee2020-12-13 08:44:15 -06008082:ref:`overview-manual/development-environment:git` repository.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008083
8084.. note::
8085
8086 Enabling build history increases your build times slightly,
8087 particularly for images, and increases the amount of disk space used
8088 during the build.
8089
8090You can disable build history by removing the previous statements from
8091your ``conf/local.conf`` file.
8092
8093Understanding What the Build History Contains
8094---------------------------------------------
8095
8096Build history information is kept in
8097``${``\ :term:`TOPDIR`\ ``}/buildhistory``
8098in the Build Directory as defined by the
8099:term:`BUILDHISTORY_DIR`
8100variable. The following is an example abbreviated listing:
8101
8102.. image:: figures/buildhistory.png
8103 :align: center
8104
8105At the top level, a ``metadata-revs`` file exists that lists the
8106revisions of the repositories for the enabled layers when the build was
8107produced. The rest of the data splits into separate ``packages``,
8108``images`` and ``sdk`` directories, the contents of which are described
8109as follows.
8110
8111Build History Package Information
8112~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8113
8114The history for each package contains a text file that has name-value
8115pairs with information about the package. For example,
8116``buildhistory/packages/i586-poky-linux/busybox/busybox/latest``
8117contains the following:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008118
8119.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008120
8121 PV = 1.22.1
8122 PR = r32
8123 RPROVIDES =
8124 RDEPENDS = glibc (>= 2.20) update-alternatives-opkg
8125 RRECOMMENDS = busybox-syslog busybox-udhcpc update-rc.d
8126 PKGSIZE = 540168
8127 FILES = /usr/bin/* /usr/sbin/* /usr/lib/busybox/* /usr/lib/lib*.so.* \
8128 /etc /com /var /bin/* /sbin/* /lib/*.so.* /lib/udev/rules.d \
8129 /usr/lib/udev/rules.d /usr/share/busybox /usr/lib/busybox/* \
8130 /usr/share/pixmaps /usr/share/applications /usr/share/idl \
8131 /usr/share/omf /usr/share/sounds /usr/lib/bonobo/servers
8132 FILELIST = /bin/busybox /bin/busybox.nosuid /bin/busybox.suid /bin/sh \
8133 /etc/busybox.links.nosuid /etc/busybox.links.suid
8134
8135Most of these
8136name-value pairs correspond to variables used to produce the package.
8137The exceptions are ``FILELIST``, which is the actual list of files in
8138the package, and ``PKGSIZE``, which is the total size of files in the
8139package in bytes.
8140
8141A file also exists that corresponds to the recipe from which the package
8142came (e.g. ``buildhistory/packages/i586-poky-linux/busybox/latest``):
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008143
8144.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008145
8146 PV = 1.22.1
8147 PR = r32
8148 DEPENDS = initscripts kern-tools-native update-rc.d-native \
8149 virtual/i586-poky-linux-compilerlibs virtual/i586-poky-linux-gcc \
8150 virtual/libc virtual/update-alternatives
8151 PACKAGES = busybox-ptest busybox-httpd busybox-udhcpd busybox-udhcpc \
8152 busybox-syslog busybox-mdev busybox-hwclock busybox-dbg \
8153 busybox-staticdev busybox-dev busybox-doc busybox-locale busybox
8154
8155Finally, for those recipes fetched from a version control system (e.g.,
8156Git), a file exists that lists source revisions that are specified in
8157the recipe and lists the actual revisions used during the build. Listed
8158and actual revisions might differ when
8159:term:`SRCREV` is set to
8160${:term:`AUTOREV`}. Here is an
8161example assuming
8162``buildhistory/packages/qemux86-poky-linux/linux-yocto/latest_srcrev``):
8163::
8164
8165 # SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
8166 SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
8167 # SRCREV_meta = "a227f20eff056e511d504b2e490f3774ab260d6f"
8168 SRCREV_meta ="a227f20eff056e511d504b2e490f3774ab260d6f"
8169
8170You can use the
8171``buildhistory-collect-srcrevs`` command with the ``-a`` option to
8172collect the stored ``SRCREV`` values from build history and report them
8173in a format suitable for use in global configuration (e.g.,
8174``local.conf`` or a distro include file) to override floating
8175``AUTOREV`` values to a fixed set of revisions. Here is some example
8176output from this command:
8177::
8178
8179 $ buildhistory-collect-srcrevs -a
8180 # i586-poky-linux
8181 SRCREV_pn-glibc = "b8079dd0d360648e4e8de48656c5c38972621072"
8182 SRCREV_pn-glibc-initial = "b8079dd0d360648e4e8de48656c5c38972621072"
8183 SRCREV_pn-opkg-utils = "53274f087565fd45d8452c5367997ba6a682a37a"
8184 SRCREV_pn-kmod = "fd56638aed3fe147015bfa10ed4a5f7491303cb4"
8185 # x86_64-linux
8186 SRCREV_pn-gtk-doc-stub-native = "1dea266593edb766d6d898c79451ef193eb17cfa"
8187 SRCREV_pn-dtc-native = "65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf"
8188 SRCREV_pn-update-rc.d-native = "eca680ddf28d024954895f59a241a622dd575c11"
8189 SRCREV_glibc_pn-cross-localedef-native = "b8079dd0d360648e4e8de48656c5c38972621072"
8190 SRCREV_localedef_pn-cross-localedef-native = "c833367348d39dad7ba018990bfdaffaec8e9ed3"
8191 SRCREV_pn-prelink-native = "faa069deec99bf61418d0bab831c83d7c1b797ca"
8192 SRCREV_pn-opkg-utils-native = "53274f087565fd45d8452c5367997ba6a682a37a"
8193 SRCREV_pn-kern-tools-native = "23345b8846fe4bd167efdf1bd8a1224b2ba9a5ff"
8194 SRCREV_pn-kmod-native = "fd56638aed3fe147015bfa10ed4a5f7491303cb4"
8195 # qemux86-poky-linux
8196 SRCREV_machine_pn-linux-yocto = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
8197 SRCREV_meta_pn-linux-yocto = "a227f20eff056e511d504b2e490f3774ab260d6f"
8198 # all-poky-linux
8199 SRCREV_pn-update-rc.d = "eca680ddf28d024954895f59a241a622dd575c11"
8200
8201.. note::
8202
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008203 Here are some notes on using the ``buildhistory-collect-srcrevs`` command:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008204
8205 - By default, only values where the ``SRCREV`` was not hardcoded
8206 (usually when ``AUTOREV`` is used) are reported. Use the ``-a``
8207 option to see all ``SRCREV`` values.
8208
8209 - The output statements might not have any effect if overrides are
8210 applied elsewhere in the build system configuration. Use the
8211 ``-f`` option to add the ``forcevariable`` override to each output
8212 line if you need to work around this restriction.
8213
8214 - The script does apply special handling when building for multiple
8215 machines. However, the script does place a comment before each set
8216 of values that specifies which triplet to which they belong as
8217 previously shown (e.g., ``i586-poky-linux``).
8218
8219Build History Image Information
8220~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8221
8222The files produced for each image are as follows:
8223
8224- ``image-files:`` A directory containing selected files from the root
8225 filesystem. The files are defined by
8226 :term:`BUILDHISTORY_IMAGE_FILES`.
8227
8228- ``build-id.txt:`` Human-readable information about the build
8229 configuration and metadata source revisions. This file contains the
8230 full build header as printed by BitBake.
8231
8232- ``*.dot:`` Dependency graphs for the image that are compatible with
8233 ``graphviz``.
8234
8235- ``files-in-image.txt:`` A list of files in the image with
8236 permissions, owner, group, size, and symlink information.
8237
8238- ``image-info.txt:`` A text file containing name-value pairs with
8239 information about the image. See the following listing example for
8240 more information.
8241
8242- ``installed-package-names.txt:`` A list of installed packages by name
8243 only.
8244
8245- ``installed-package-sizes.txt:`` A list of installed packages ordered
8246 by size.
8247
8248- ``installed-packages.txt:`` A list of installed packages with full
8249 package filenames.
8250
8251.. note::
8252
8253 Installed package information is able to be gathered and produced
8254 even if package management is disabled for the final image.
8255
8256Here is an example of ``image-info.txt``:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008257
8258.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008259
8260 DISTRO = poky
8261 DISTRO_VERSION = 1.7
8262 USER_CLASSES = buildstats image-mklibs image-prelink
8263 IMAGE_CLASSES = image_types
8264 IMAGE_FEATURES = debug-tweaks
8265 IMAGE_LINGUAS =
8266 IMAGE_INSTALL = packagegroup-core-boot run-postinsts
8267 BAD_RECOMMENDATIONS =
8268 NO_RECOMMENDATIONS =
8269 PACKAGE_EXCLUDE =
8270 ROOTFS_POSTPROCESS_COMMAND = write_package_manifest; license_create_manifest; \
8271 write_image_manifest ; buildhistory_list_installed_image ; \
8272 buildhistory_get_image_installed ; ssh_allow_empty_password; \
8273 postinst_enable_logging; rootfs_update_timestamp ; ssh_disable_dns_lookup ;
8274 IMAGE_POSTPROCESS_COMMAND = buildhistory_get_imageinfo ;
8275 IMAGESIZE = 6900
8276
8277Other than ``IMAGESIZE``,
8278which is the total size of the files in the image in Kbytes, the
8279name-value pairs are variables that may have influenced the content of
8280the image. This information is often useful when you are trying to
8281determine why a change in the package or file listings has occurred.
8282
8283Using Build History to Gather Image Information Only
8284~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8285
8286As you can see, build history produces image information, including
8287dependency graphs, so you can see why something was pulled into the
8288image. If you are just interested in this information and not interested
8289in collecting specific package or SDK information, you can enable
8290writing only image information without any history by adding the
8291following to your ``conf/local.conf`` file found in the
8292:term:`Build Directory`:
8293::
8294
8295 INHERIT += "buildhistory"
8296 BUILDHISTORY_COMMIT = "0"
8297 BUILDHISTORY_FEATURES = "image"
8298
8299Here, you set the
8300:term:`BUILDHISTORY_FEATURES`
8301variable to use the image feature only.
8302
8303Build History SDK Information
8304~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8305
8306Build history collects similar information on the contents of SDKs (e.g.
8307``bitbake -c populate_sdk imagename``) as compared to information it
8308collects for images. Furthermore, this information differs depending on
8309whether an extensible or standard SDK is being produced.
8310
8311The following list shows the files produced for SDKs:
8312
8313- ``files-in-sdk.txt:`` A list of files in the SDK with permissions,
8314 owner, group, size, and symlink information. This list includes both
8315 the host and target parts of the SDK.
8316
8317- ``sdk-info.txt:`` A text file containing name-value pairs with
8318 information about the SDK. See the following listing example for more
8319 information.
8320
8321- ``sstate-task-sizes.txt:`` A text file containing name-value pairs
8322 with information about task group sizes (e.g. ``do_populate_sysroot``
8323 tasks have a total size). The ``sstate-task-sizes.txt`` file exists
8324 only when an extensible SDK is created.
8325
8326- ``sstate-package-sizes.txt:`` A text file containing name-value pairs
8327 with information for the shared-state packages and sizes in the SDK.
8328 The ``sstate-package-sizes.txt`` file exists only when an extensible
8329 SDK is created.
8330
8331- ``sdk-files:`` A folder that contains copies of the files mentioned
8332 in ``BUILDHISTORY_SDK_FILES`` if the files are present in the output.
8333 Additionally, the default value of ``BUILDHISTORY_SDK_FILES`` is
8334 specific to the extensible SDK although you can set it differently if
8335 you would like to pull in specific files from the standard SDK.
8336
8337 The default files are ``conf/local.conf``, ``conf/bblayers.conf``,
8338 ``conf/auto.conf``, ``conf/locked-sigs.inc``, and
8339 ``conf/devtool.conf``. Thus, for an extensible SDK, these files get
8340 copied into the ``sdk-files`` directory.
8341
8342- The following information appears under each of the ``host`` and
8343 ``target`` directories for the portions of the SDK that run on the
8344 host and on the target, respectively:
8345
8346 .. note::
8347
8348 The following files for the most part are empty when producing an
8349 extensible SDK because this type of SDK is not constructed from
8350 packages as is the standard SDK.
8351
8352 - ``depends.dot:`` Dependency graph for the SDK that is compatible
8353 with ``graphviz``.
8354
8355 - ``installed-package-names.txt:`` A list of installed packages by
8356 name only.
8357
8358 - ``installed-package-sizes.txt:`` A list of installed packages
8359 ordered by size.
8360
8361 - ``installed-packages.txt:`` A list of installed packages with full
8362 package filenames.
8363
8364Here is an example of ``sdk-info.txt``:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008365
8366.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008367
8368 DISTRO = poky
8369 DISTRO_VERSION = 1.3+snapshot-20130327
8370 SDK_NAME = poky-glibc-i686-arm
8371 SDK_VERSION = 1.3+snapshot
8372 SDKMACHINE =
8373 SDKIMAGE_FEATURES = dev-pkgs dbg-pkgs
8374 BAD_RECOMMENDATIONS =
8375 SDKSIZE = 352712
8376
8377Other than ``SDKSIZE``, which is
8378the total size of the files in the SDK in Kbytes, the name-value pairs
8379are variables that might have influenced the content of the SDK. This
8380information is often useful when you are trying to determine why a
8381change in the package or file listings has occurred.
8382
8383Examining Build History Information
8384~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8385
8386You can examine build history output from the command line or from a web
8387interface.
8388
8389To see any changes that have occurred (assuming you have
8390:term:`BUILDHISTORY_COMMIT` = "1"),
8391you can simply use any Git command that allows you to view the history
8392of a repository. Here is one method:
8393::
8394
8395 $ git log -p
8396
8397You need to realize,
8398however, that this method does show changes that are not significant
8399(e.g. a package's size changing by a few bytes).
8400
8401A command-line tool called ``buildhistory-diff`` does exist, though,
8402that queries the Git repository and prints just the differences that
8403might be significant in human-readable form. Here is an example:
8404::
8405
8406 $ ~/poky/poky/scripts/buildhistory-diff . HEAD^
8407 Changes to images/qemux86_64/glibc/core-image-minimal (files-in-image.txt):
8408 /etc/anotherpkg.conf was added
8409 /sbin/anotherpkg was added
8410 * (installed-package-names.txt):
8411 * anotherpkg was added
8412 Changes to images/qemux86_64/glibc/core-image-minimal (installed-package-names.txt):
8413 anotherpkg was added
8414 packages/qemux86_64-poky-linux/v86d: PACKAGES: added "v86d-extras"
8415 * PR changed from "r0" to "r1"
8416 * PV changed from "0.1.10" to "0.1.12"
8417 packages/qemux86_64-poky-linux/v86d/v86d: PKGSIZE changed from 110579 to 144381 (+30%)
8418 * PR changed from "r0" to "r1"
8419 * PV changed from "0.1.10" to "0.1.12"
8420
8421.. note::
8422
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008423 The ``buildhistory-diff`` tool requires the ``GitPython``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008424 package. Be sure to install it using Pip3 as follows:
8425 ::
8426
8427 $ pip3 install GitPython --user
8428
8429
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008430 Alternatively, you can install ``python3-git`` using the appropriate
8431 distribution package manager (e.g. ``apt-get``, ``dnf``, or ``zipper``).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008432
8433To see changes to the build history using a web interface, follow the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008434instruction in the ``README`` file
Andrew Geissler09209ee2020-12-13 08:44:15 -06008435:yocto_git:`here </buildhistory-web/>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008436
8437Here is a sample screenshot of the interface:
8438
8439.. image:: figures/buildhistory-web.png
8440 :align: center
8441
8442Performing Automated Runtime Testing
8443====================================
8444
8445The OpenEmbedded build system makes available a series of automated
8446tests for images to verify runtime functionality. You can run these
8447tests on either QEMU or actual target hardware. Tests are written in
8448Python making use of the ``unittest`` module, and the majority of them
8449run commands on the target system over SSH. This section describes how
8450you set up the environment to use these tests, run available tests, and
8451write and add your own tests.
8452
8453For information on the test and QA infrastructure available within the
Andrew Geissler09209ee2020-12-13 08:44:15 -06008454Yocto Project, see the ":ref:`ref-manual/release-process:testing and quality assurance`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008455section in the Yocto Project Reference Manual.
8456
8457Enabling Tests
8458--------------
8459
8460Depending on whether you are planning to run tests using QEMU or on the
8461hardware, you have to take different steps to enable the tests. See the
8462following subsections for information on how to enable both types of
8463tests.
8464
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008465Enabling Runtime Tests on QEMU
8466~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8467
8468In order to run tests, you need to do the following:
8469
8470- *Set up to avoid interaction with sudo for networking:* To
8471 accomplish this, you must do one of the following:
8472
8473 - Add ``NOPASSWD`` for your user in ``/etc/sudoers`` either for all
8474 commands or just for ``runqemu-ifup``. You must provide the full
8475 path as that can change if you are using multiple clones of the
8476 source repository.
8477
8478 .. note::
8479
8480 On some distributions, you also need to comment out "Defaults
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008481 requiretty" in ``/etc/sudoers``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008482
8483 - Manually configure a tap interface for your system.
8484
8485 - Run as root the script in ``scripts/runqemu-gen-tapdevs``, which
8486 should generate a list of tap devices. This is the option
8487 typically chosen for Autobuilder-type environments.
8488
8489 .. note::
8490
8491 - Be sure to use an absolute path when calling this script
8492 with sudo.
8493
8494 - The package recipe ``qemu-helper-native`` is required to run
8495 this script. Build the package using the following command:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008496 ::
8497
8498 $ bitbake qemu-helper-native
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008499
8500- *Set the DISPLAY variable:* You need to set this variable so that
8501 you have an X server available (e.g. start ``vncserver`` for a
8502 headless machine).
8503
8504- *Be sure your host's firewall accepts incoming connections from
8505 192.168.7.0/24:* Some of the tests (in particular DNF tests) start an
8506 HTTP server on a random high number port, which is used to serve
8507 files to the target. The DNF module serves
8508 ``${WORKDIR}/oe-rootfs-repo`` so it can run DNF channel commands.
8509 That means your host's firewall must accept incoming connections from
8510 192.168.7.0/24, which is the default IP range used for tap devices by
8511 ``runqemu``.
8512
8513- *Be sure your host has the correct packages installed:* Depending
8514 your host's distribution, you need to have the following packages
8515 installed:
8516
8517 - Ubuntu and Debian: ``sysstat`` and ``iproute2``
8518
8519 - OpenSUSE: ``sysstat`` and ``iproute2``
8520
8521 - Fedora: ``sysstat`` and ``iproute``
8522
8523 - CentOS: ``sysstat`` and ``iproute``
8524
8525Once you start running the tests, the following happens:
8526
85271. A copy of the root filesystem is written to ``${WORKDIR}/testimage``.
8528
85292. The image is booted under QEMU using the standard ``runqemu`` script.
8530
85313. A default timeout of 500 seconds occurs to allow for the boot process
8532 to reach the login prompt. You can change the timeout period by
8533 setting
8534 :term:`TEST_QEMUBOOT_TIMEOUT`
8535 in the ``local.conf`` file.
8536
85374. Once the boot process is reached and the login prompt appears, the
8538 tests run. The full boot log is written to
8539 ``${WORKDIR}/testimage/qemu_boot_log``.
8540
85415. Each test module loads in the order found in ``TEST_SUITES``. You can
8542 find the full output of the commands run over SSH in
8543 ``${WORKDIR}/testimgage/ssh_target_log``.
8544
85456. If no failures occur, the task running the tests ends successfully.
8546 You can find the output from the ``unittest`` in the task log at
8547 ``${WORKDIR}/temp/log.do_testimage``.
8548
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008549Enabling Runtime Tests on Hardware
8550~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8551
8552The OpenEmbedded build system can run tests on real hardware, and for
8553certain devices it can also deploy the image to be tested onto the
8554device beforehand.
8555
8556For automated deployment, a "master image" is installed onto the
8557hardware once as part of setup. Then, each time tests are to be run, the
8558following occurs:
8559
85601. The master image is booted into and used to write the image to be
8561 tested to a second partition.
8562
85632. The device is then rebooted using an external script that you need to
8564 provide.
8565
85663. The device boots into the image to be tested.
8567
8568When running tests (independent of whether the image has been deployed
8569automatically or not), the device is expected to be connected to a
8570network on a pre-determined IP address. You can either use static IP
8571addresses written into the image, or set the image to use DHCP and have
8572your DHCP server on the test network assign a known IP address based on
8573the MAC address of the device.
8574
8575In order to run tests on hardware, you need to set ``TEST_TARGET`` to an
8576appropriate value. For QEMU, you do not have to change anything, the
8577default value is "qemu". For running tests on hardware, the following
8578options exist:
8579
8580- *"simpleremote":* Choose "simpleremote" if you are going to run tests
8581 on a target system that is already running the image to be tested and
8582 is available on the network. You can use "simpleremote" in
8583 conjunction with either real hardware or an image running within a
8584 separately started QEMU or any other virtual machine manager.
8585
8586- *"SystemdbootTarget":* Choose "SystemdbootTarget" if your hardware is
8587 an EFI-based machine with ``systemd-boot`` as bootloader and
8588 ``core-image-testmaster`` (or something similar) is installed. Also,
8589 your hardware under test must be in a DHCP-enabled network that gives
8590 it the same IP address for each reboot.
8591
8592 If you choose "SystemdbootTarget", there are additional requirements
8593 and considerations. See the "`Selecting
8594 SystemdbootTarget <#selecting-systemdboottarget>`__" section, which
8595 follows, for more information.
8596
8597- *"BeagleBoneTarget":* Choose "BeagleBoneTarget" if you are deploying
8598 images and running tests on the BeagleBone "Black" or original
8599 "White" hardware. For information on how to use these tests, see the
8600 comments at the top of the BeagleBoneTarget
8601 ``meta-yocto-bsp/lib/oeqa/controllers/beaglebonetarget.py`` file.
8602
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008603- *"EdgeRouterTarget":* Choose "EdgeRouterTarget" if you are deploying
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008604 images and running tests on the Ubiquiti Networks EdgeRouter Lite.
8605 For information on how to use these tests, see the comments at the
8606 top of the EdgeRouterTarget
8607 ``meta-yocto-bsp/lib/oeqa/controllers/edgeroutertarget.py`` file.
8608
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008609- *"GrubTarget":* Choose "GrubTarget" if you are deploying images and running
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008610 tests on any generic PC that boots using GRUB. For information on how
8611 to use these tests, see the comments at the top of the GrubTarget
8612 ``meta-yocto-bsp/lib/oeqa/controllers/grubtarget.py`` file.
8613
8614- *"your-target":* Create your own custom target if you want to run
8615 tests when you are deploying images and running tests on a custom
8616 machine within your BSP layer. To do this, you need to add a Python
8617 unit that defines the target class under ``lib/oeqa/controllers/``
8618 within your layer. You must also provide an empty ``__init__.py``.
8619 For examples, see files in ``meta-yocto-bsp/lib/oeqa/controllers/``.
8620
8621Selecting SystemdbootTarget
8622~~~~~~~~~~~~~~~~~~~~~~~~~~~
8623
8624If you did not set ``TEST_TARGET`` to "SystemdbootTarget", then you do
8625not need any information in this section. You can skip down to the
8626"`Running Tests <#qemu-image-running-tests>`__" section.
8627
8628If you did set ``TEST_TARGET`` to "SystemdbootTarget", you also need to
8629perform a one-time setup of your master image by doing the following:
8630
86311. *Set EFI_PROVIDER:* Be sure that ``EFI_PROVIDER`` is as follows:
8632 ::
8633
8634 EFI_PROVIDER = "systemd-boot"
8635
86362. *Build the master image:* Build the ``core-image-testmaster`` image.
8637 The ``core-image-testmaster`` recipe is provided as an example for a
8638 "master" image and you can customize the image recipe as you would
8639 any other recipe.
8640
8641 Here are the image recipe requirements:
8642
8643 - Inherits ``core-image`` so that kernel modules are installed.
8644
8645 - Installs normal linux utilities not busybox ones (e.g. ``bash``,
8646 ``coreutils``, ``tar``, ``gzip``, and ``kmod``).
8647
8648 - Uses a custom Initial RAM Disk (initramfs) image with a custom
8649 installer. A normal image that you can install usually creates a
8650 single rootfs partition. This image uses another installer that
8651 creates a specific partition layout. Not all Board Support
8652 Packages (BSPs) can use an installer. For such cases, you need to
8653 manually create the following partition layout on the target:
8654
8655 - First partition mounted under ``/boot``, labeled "boot".
8656
8657 - The main rootfs partition where this image gets installed,
8658 which is mounted under ``/``.
8659
8660 - Another partition labeled "testrootfs" where test images get
8661 deployed.
8662
86633. *Install image:* Install the image that you just built on the target
8664 system.
8665
8666The final thing you need to do when setting ``TEST_TARGET`` to
8667"SystemdbootTarget" is to set up the test image:
8668
86691. *Set up your local.conf file:* Make sure you have the following
8670 statements in your ``local.conf`` file:
8671 ::
8672
8673 IMAGE_FSTYPES += "tar.gz"
8674 INHERIT += "testimage"
8675 TEST_TARGET = "SystemdbootTarget"
8676 TEST_TARGET_IP = "192.168.2.3"
8677
86782. *Build your test image:* Use BitBake to build the image:
8679 ::
8680
8681 $ bitbake core-image-sato
8682
8683Power Control
8684~~~~~~~~~~~~~
8685
8686For most hardware targets other than "simpleremote", you can control
8687power:
8688
8689- You can use ``TEST_POWERCONTROL_CMD`` together with
8690 ``TEST_POWERCONTROL_EXTRA_ARGS`` as a command that runs on the host
8691 and does power cycling. The test code passes one argument to that
8692 command: off, on or cycle (off then on). Here is an example that
8693 could appear in your ``local.conf`` file:
8694 ::
8695
8696 TEST_POWERCONTROL_CMD = "powercontrol.exp test 10.11.12.1 nuc1"
8697
8698 In this example, the expect
8699 script does the following:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008700
8701 .. code-block:: shell
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008702
8703 ssh test@10.11.12.1 "pyctl nuc1 arg"
8704
8705 It then runs a Python script that controls power for a label called
8706 ``nuc1``.
8707
8708 .. note::
8709
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008710 You need to customize ``TEST_POWERCONTROL_CMD`` and
8711 ``TEST_POWERCONTROL_EXTRA_ARGS`` for your own setup. The one requirement
8712 is that it accepts "on", "off", and "cycle" as the last argument.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008713
8714- When no command is defined, it connects to the device over SSH and
8715 uses the classic reboot command to reboot the device. Classic reboot
8716 is fine as long as the machine actually reboots (i.e. the SSH test
8717 has not failed). It is useful for scenarios where you have a simple
8718 setup, typically with a single board, and where some manual
8719 interaction is okay from time to time.
8720
8721If you have no hardware to automatically perform power control but still
8722wish to experiment with automated hardware testing, you can use the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008723``dialog-power-control`` script that shows a dialog prompting you to perform
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008724the required power action. This script requires either KDialog or Zenity
8725to be installed. To use this script, set the
8726:term:`TEST_POWERCONTROL_CMD`
8727variable as follows:
8728::
8729
8730 TEST_POWERCONTROL_CMD = "${COREBASE}/scripts/contrib/dialog-power-control"
8731
8732Serial Console Connection
8733~~~~~~~~~~~~~~~~~~~~~~~~~
8734
8735For test target classes requiring a serial console to interact with the
8736bootloader (e.g. BeagleBoneTarget, EdgeRouterTarget, and GrubTarget),
8737you need to specify a command to use to connect to the serial console of
8738the target machine by using the
8739:term:`TEST_SERIALCONTROL_CMD`
8740variable and optionally the
8741:term:`TEST_SERIALCONTROL_EXTRA_ARGS`
8742variable.
8743
8744These cases could be a serial terminal program if the machine is
8745connected to a local serial port, or a ``telnet`` or ``ssh`` command
8746connecting to a remote console server. Regardless of the case, the
8747command simply needs to connect to the serial console and forward that
8748connection to standard input and output as any normal terminal program
8749does. For example, to use the picocom terminal program on serial device
8750``/dev/ttyUSB0`` at 115200bps, you would set the variable as follows:
8751::
8752
8753 TEST_SERIALCONTROL_CMD = "picocom /dev/ttyUSB0 -b 115200"
8754
8755For local
8756devices where the serial port device disappears when the device reboots,
8757an additional "serdevtry" wrapper script is provided. To use this
8758wrapper, simply prefix the terminal command with
8759``${COREBASE}/scripts/contrib/serdevtry``:
8760::
8761
8762 TEST_SERIALCONTROL_CMD = "${COREBASE}/scripts/contrib/serdevtry picocom -b 115200 /dev/ttyUSB0"
8763
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008764Running Tests
8765-------------
8766
8767You can start the tests automatically or manually:
8768
8769- *Automatically running tests:* To run the tests automatically after
8770 the OpenEmbedded build system successfully creates an image, first
8771 set the
8772 :term:`TESTIMAGE_AUTO`
8773 variable to "1" in your ``local.conf`` file in the
8774 :term:`Build Directory`:
8775 ::
8776
8777 TESTIMAGE_AUTO = "1"
8778
8779 Next, build your image. If the image successfully builds, the
8780 tests run:
8781 ::
8782
8783 bitbake core-image-sato
8784
8785- *Manually running tests:* To manually run the tests, first globally
8786 inherit the
8787 :ref:`testimage <ref-classes-testimage*>` class
8788 by editing your ``local.conf`` file:
8789 ::
8790
8791 INHERIT += "testimage"
8792
8793 Next, use BitBake to run the tests:
8794 ::
8795
8796 bitbake -c testimage image
8797
8798All test files reside in ``meta/lib/oeqa/runtime`` in the
8799:term:`Source Directory`. A test name maps
8800directly to a Python module. Each test module may contain a number of
8801individual tests. Tests are usually grouped together by the area tested
8802(e.g tests for systemd reside in ``meta/lib/oeqa/runtime/systemd.py``).
8803
8804You can add tests to any layer provided you place them in the proper
8805area and you extend :term:`BBPATH` in
8806the ``local.conf`` file as normal. Be sure that tests reside in
8807``layer/lib/oeqa/runtime``.
8808
8809.. note::
8810
8811 Be sure that module names do not collide with module names used in
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008812 the default set of test modules in ``meta/lib/oeqa/runtime``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008813
8814You can change the set of tests run by appending or overriding
8815:term:`TEST_SUITES` variable in
8816``local.conf``. Each name in ``TEST_SUITES`` represents a required test
8817for the image. Test modules named within ``TEST_SUITES`` cannot be
8818skipped even if a test is not suitable for an image (e.g. running the
8819RPM tests on an image without ``rpm``). Appending "auto" to
8820``TEST_SUITES`` causes the build system to try to run all tests that are
8821suitable for the image (i.e. each test module may elect to skip itself).
8822
8823The order you list tests in ``TEST_SUITES`` is important and influences
8824test dependencies. Consequently, tests that depend on other tests should
8825be added after the test on which they depend. For example, since the
8826``ssh`` test depends on the ``ping`` test, "ssh" needs to come after
8827"ping" in the list. The test class provides no re-ordering or dependency
8828handling.
8829
8830.. note::
8831
8832 Each module can have multiple classes with multiple test methods.
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008833 And, Python ``unittest`` rules apply.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008834
8835Here are some things to keep in mind when running tests:
8836
8837- The default tests for the image are defined as:
8838 ::
8839
8840 DEFAULT_TEST_SUITES_pn-image = "ping ssh df connman syslog xorg scp vnc date rpm dnf dmesg"
8841
8842- Add your own test to the list of the by using the following:
8843 ::
8844
8845 TEST_SUITES_append = " mytest"
8846
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008847- Run a specific list of tests as follows:
8848 ::
8849
8850 TEST_SUITES = "test1 test2 test3"
8851
8852 Remember, order is important. Be sure to place a test that is
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008853 dependent on another test later in the order.
8854
8855Exporting Tests
8856---------------
8857
8858You can export tests so that they can run independently of the build
8859system. Exporting tests is required if you want to be able to hand the
8860test execution off to a scheduler. You can only export tests that are
8861defined in :term:`TEST_SUITES`.
8862
8863If your image is already built, make sure the following are set in your
8864``local.conf`` file:
8865::
8866
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008867 INHERIT += "testexport"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008868 TEST_TARGET_IP = "IP-address-for-the-test-target"
8869 TEST_SERVER_IP = "IP-address-for-the-test-server"
8870
8871You can then export the tests with the
8872following BitBake command form:
8873::
8874
8875 $ bitbake image -c testexport
8876
8877Exporting the tests places them in the
8878:term:`Build Directory` in
8879``tmp/testexport/``\ image, which is controlled by the
8880``TEST_EXPORT_DIR`` variable.
8881
8882You can now run the tests outside of the build environment:
8883::
8884
8885 $ cd tmp/testexport/image
8886 $ ./runexported.py testdata.json
8887
8888Here is a complete example that shows IP addresses and uses the
8889``core-image-sato`` image:
8890::
8891
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008892 INHERIT += "testexport"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008893 TEST_TARGET_IP = "192.168.7.2"
8894 TEST_SERVER_IP = "192.168.7.1"
8895
8896Use BitBake to export the tests:
8897::
8898
8899 $ bitbake core-image-sato -c testexport
8900
8901Run the tests outside of
8902the build environment using the following:
8903::
8904
8905 $ cd tmp/testexport/core-image-sato
8906 $ ./runexported.py testdata.json
8907
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008908Writing New Tests
8909-----------------
8910
8911As mentioned previously, all new test files need to be in the proper
8912place for the build system to find them. New tests for additional
8913functionality outside of the core should be added to the layer that adds
8914the functionality, in ``layer/lib/oeqa/runtime`` (as long as
8915:term:`BBPATH` is extended in the
8916layer's ``layer.conf`` file as normal). Just remember the following:
8917
8918- Filenames need to map directly to test (module) names.
8919
8920- Do not use module names that collide with existing core tests.
8921
8922- Minimally, an empty ``__init__.py`` file must exist in the runtime
8923 directory.
8924
8925To create a new test, start by copying an existing module (e.g.
8926``syslog.py`` or ``gcc.py`` are good ones to use). Test modules can use
8927code from ``meta/lib/oeqa/utils``, which are helper classes.
8928
8929.. note::
8930
8931 Structure shell commands such that you rely on them and they return a
8932 single code for success. Be aware that sometimes you will need to
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008933 parse the output. See the ``df.py`` and ``date.py`` modules for examples.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008934
8935You will notice that all test classes inherit ``oeRuntimeTest``, which
8936is found in ``meta/lib/oetest.py``. This base class offers some helper
8937attributes, which are described in the following sections:
8938
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008939Class Methods
8940~~~~~~~~~~~~~
8941
8942Class methods are as follows:
8943
8944- *hasPackage(pkg):* Returns "True" if ``pkg`` is in the installed
8945 package list of the image, which is based on the manifest file that
8946 is generated during the ``do_rootfs`` task.
8947
8948- *hasFeature(feature):* Returns "True" if the feature is in
8949 :term:`IMAGE_FEATURES` or
8950 :term:`DISTRO_FEATURES`.
8951
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008952Class Attributes
8953~~~~~~~~~~~~~~~~
8954
8955Class attributes are as follows:
8956
8957- *pscmd:* Equals "ps -ef" if ``procps`` is installed in the image.
8958 Otherwise, ``pscmd`` equals "ps" (busybox).
8959
8960- *tc:* The called test context, which gives access to the
8961 following attributes:
8962
8963 - *d:* The BitBake datastore, which allows you to use stuff such
8964 as ``oeRuntimeTest.tc.d.getVar("VIRTUAL-RUNTIME_init_manager")``.
8965
8966 - *testslist and testsrequired:* Used internally. The tests
8967 do not need these.
8968
8969 - *filesdir:* The absolute path to
8970 ``meta/lib/oeqa/runtime/files``, which contains helper files for
8971 tests meant for copying on the target such as small files written
8972 in C for compilation.
8973
8974 - *target:* The target controller object used to deploy and
8975 start an image on a particular target (e.g. Qemu, SimpleRemote,
8976 and SystemdbootTarget). Tests usually use the following:
8977
8978 - *ip:* The target's IP address.
8979
8980 - *server_ip:* The host's IP address, which is usually used
8981 by the DNF test suite.
8982
8983 - *run(cmd, timeout=None):* The single, most used method.
8984 This command is a wrapper for: ``ssh root@host "cmd"``. The
8985 command returns a tuple: (status, output), which are what their
8986 names imply - the return code of "cmd" and whatever output it
8987 produces. The optional timeout argument represents the number
8988 of seconds the test should wait for "cmd" to return. If the
8989 argument is "None", the test uses the default instance's
8990 timeout period, which is 300 seconds. If the argument is "0",
8991 the test runs until the command returns.
8992
8993 - *copy_to(localpath, remotepath):*
8994 ``scp localpath root@ip:remotepath``.
8995
8996 - *copy_from(remotepath, localpath):*
8997 ``scp root@host:remotepath localpath``.
8998
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008999Instance Attributes
9000~~~~~~~~~~~~~~~~~~~
9001
9002A single instance attribute exists, which is ``target``. The ``target``
9003instance attribute is identical to the class attribute of the same name,
9004which is described in the previous section. This attribute exists as
9005both an instance and class attribute so tests can use
9006``self.target.run(cmd)`` in instance methods instead of
9007``oeRuntimeTest.tc.target.run(cmd)``.
9008
9009Installing Packages in the DUT Without the Package Manager
9010----------------------------------------------------------
9011
9012When a test requires a package built by BitBake, it is possible to
9013install that package. Installing the package does not require a package
9014manager be installed in the device under test (DUT). It does, however,
9015require an SSH connection and the target must be using the
9016``sshcontrol`` class.
9017
9018.. note::
9019
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009020 This method uses ``scp`` to copy files from the host to the target, which
9021 causes permissions and special attributes to be lost.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009022
9023A JSON file is used to define the packages needed by a test. This file
9024must be in the same path as the file used to define the tests.
9025Furthermore, the filename must map directly to the test module name with
9026a ``.json`` extension.
9027
9028The JSON file must include an object with the test name as keys of an
9029object or an array. This object (or array of objects) uses the following
9030data:
9031
9032- "pkg" - A mandatory string that is the name of the package to be
9033 installed.
9034
9035- "rm" - An optional boolean, which defaults to "false", that specifies
9036 to remove the package after the test.
9037
9038- "extract" - An optional boolean, which defaults to "false", that
9039 specifies if the package must be extracted from the package format.
9040 When set to "true", the package is not automatically installed into
9041 the DUT.
9042
9043Following is an example JSON file that handles test "foo" installing
9044package "bar" and test "foobar" installing packages "foo" and "bar".
9045Once the test is complete, the packages are removed from the DUT.
9046::
9047
9048 {
9049 "foo": {
9050 "pkg": "bar"
9051 },
9052 "foobar": [
9053 {
9054 "pkg": "foo",
9055 "rm": true
9056 },
9057 {
9058 "pkg": "bar",
9059 "rm": true
9060 }
9061 ]
9062 }
9063
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009064Debugging Tools and Techniques
9065==============================
9066
9067The exact method for debugging build failures depends on the nature of
9068the problem and on the system's area from which the bug originates.
9069Standard debugging practices such as comparison against the last known
9070working version with examination of the changes and the re-application
9071of steps to identify the one causing the problem are valid for the Yocto
9072Project just as they are for any other system. Even though it is
9073impossible to detail every possible potential failure, this section
9074provides some general tips to aid in debugging given a variety of
9075situations.
9076
9077.. note::
9078
9079 A useful feature for debugging is the error reporting tool.
9080 Configuring the Yocto Project to use this tool causes the
9081 OpenEmbedded build system to produce error reporting commands as part
9082 of the console output. You can enter the commands after the build
9083 completes to log error information into a common database, that can
9084 help you figure out what might be going wrong. For information on how
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009085 to enable and use this feature, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06009086 ":ref:`dev-manual/common-tasks:using the error reporting tool`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009087 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009088
9089The following list shows the debugging topics in the remainder of this
9090section:
9091
9092- "`Viewing Logs from Failed
9093 Tasks <#dev-debugging-viewing-logs-from-failed-tasks>`__" describes
9094 how to find and view logs from tasks that failed during the build
9095 process.
9096
9097- "`Viewing Variable
9098 Values <#dev-debugging-viewing-variable-values>`__" describes how to
9099 use the BitBake ``-e`` option to examine variable values after a
9100 recipe has been parsed.
9101
Andrew Geissler09209ee2020-12-13 08:44:15 -06009102- ":ref:`dev-manual/common-tasks:viewing package information with \`\`oe-pkgdata-util\`\``"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009103 describes how to use the ``oe-pkgdata-util`` utility to query
9104 :term:`PKGDATA_DIR` and
9105 display package-related information for built packages.
9106
9107- "`Viewing Dependencies Between Recipes and
9108 Tasks <#dev-viewing-dependencies-between-recipes-and-tasks>`__"
9109 describes how to use the BitBake ``-g`` option to display recipe
9110 dependency information used during the build.
9111
9112- "`Viewing Task Variable
9113 Dependencies <#dev-viewing-task-variable-dependencies>`__" describes
9114 how to use the ``bitbake-dumpsig`` command in conjunction with key
9115 subdirectories in the
9116 :term:`Build Directory` to determine
9117 variable dependencies.
9118
9119- "`Running Specific Tasks <#dev-debugging-taskrunning>`__" describes
9120 how to use several BitBake options (e.g. ``-c``, ``-C``, and ``-f``)
9121 to run specific tasks in the build chain. It can be useful to run
9122 tasks "out-of-order" when trying isolate build issues.
9123
9124- "`General BitBake Problems <#dev-debugging-bitbake>`__" describes how
9125 to use BitBake's ``-D`` debug output option to reveal more about what
9126 BitBake is doing during the build.
9127
9128- "`Building with No Dependencies <#dev-debugging-buildfile>`__"
9129 describes how to use the BitBake ``-b`` option to build a recipe
9130 while ignoring dependencies.
9131
9132- "`Recipe Logging Mechanisms <#recipe-logging-mechanisms>`__"
9133 describes how to use the many recipe logging functions to produce
9134 debugging output and report errors and warnings.
9135
9136- "`Debugging Parallel Make Races <#debugging-parallel-make-races>`__"
9137 describes how to debug situations where the build consists of several
9138 parts that are run simultaneously and when the output or result of
9139 one part is not ready for use with a different part of the build that
9140 depends on that output.
9141
9142- "`Debugging With the GNU Project Debugger (GDB)
9143 Remotely <#platdev-gdb-remotedebug>`__" describes how to use GDB to
9144 allow you to examine running programs, which can help you fix
9145 problems.
9146
9147- "`Debugging with the GNU Project Debugger (GDB) on the
9148 Target <#debugging-with-the-gnu-project-debugger-gdb-on-the-target>`__"
9149 describes how to use GDB directly on target hardware for debugging.
9150
9151- "`Other Debugging Tips <#dev-other-debugging-others>`__" describes
9152 miscellaneous debugging tips that can be useful.
9153
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009154Viewing Logs from Failed Tasks
9155------------------------------
9156
9157You can find the log for a task in the file
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009158``${``\ :term:`WORKDIR`\ ``}/temp/log.do_``\ `taskname`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009159For example, the log for the
9160:ref:`ref-tasks-compile` task of the
9161QEMU minimal image for the x86 machine (``qemux86``) might be in
9162``tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/temp/log.do_compile``.
9163To see the commands :term:`BitBake` ran
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009164to generate a log, look at the corresponding ``run.do_``\ `taskname` file
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009165in the same directory.
9166
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009167``log.do_``\ `taskname` and ``run.do_``\ `taskname` are actually symbolic
9168links to ``log.do_``\ `taskname`\ ``.``\ `pid` and
9169``log.run_``\ `taskname`\ ``.``\ `pid`, where `pid` is the PID the task had
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009170when it ran. The symlinks always point to the files corresponding to the
9171most recent run.
9172
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009173Viewing Variable Values
9174-----------------------
9175
9176Sometimes you need to know the value of a variable as a result of
9177BitBake's parsing step. This could be because some unexpected behavior
9178occurred in your project. Perhaps an attempt to :ref:`modify a variable
9179<bitbake:bitbake-user-manual/bitbake-user-manual-metadata:modifying existing
9180variables>` did not work out as expected.
9181
9182BitBake's ``-e`` option is used to display variable values after
9183parsing. The following command displays the variable values after the
9184configuration files (i.e. ``local.conf``, ``bblayers.conf``,
9185``bitbake.conf`` and so forth) have been parsed:
9186::
9187
9188 $ bitbake -e
9189
9190The following command displays variable values after a specific recipe has
9191been parsed. The variables include those from the configuration as well:
9192::
9193
9194 $ bitbake -e recipename
9195
9196.. note::
9197
9198 Each recipe has its own private set of variables (datastore).
9199 Internally, after parsing the configuration, a copy of the resulting
9200 datastore is made prior to parsing each recipe. This copying implies
9201 that variables set in one recipe will not be visible to other
9202 recipes.
9203
9204 Likewise, each task within a recipe gets a private datastore based on
9205 the recipe datastore, which means that variables set within one task
9206 will not be visible to other tasks.
9207
9208In the output of ``bitbake -e``, each variable is preceded by a
9209description of how the variable got its value, including temporary
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009210values that were later overridden. This description also includes
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009211variable flags (varflags) set on the variable. The output can be very
9212helpful during debugging.
9213
9214Variables that are exported to the environment are preceded by
9215``export`` in the output of ``bitbake -e``. See the following example:
9216::
9217
9218 export CC="i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/ulf/poky/build/tmp/sysroots/qemux86"
9219
9220In addition to variable values, the output of the ``bitbake -e`` and
9221``bitbake -e`` recipe commands includes the following information:
9222
9223- The output starts with a tree listing all configuration files and
9224 classes included globally, recursively listing the files they include
9225 or inherit in turn. Much of the behavior of the OpenEmbedded build
Andrew Geissler09209ee2020-12-13 08:44:15 -06009226 system (including the behavior of the :ref:`ref-manual/tasks:normal recipe build tasks`) is
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009227 implemented in the
9228 :ref:`base <ref-classes-base>` class and the
9229 classes it inherits, rather than being built into BitBake itself.
9230
9231- After the variable values, all functions appear in the output. For
9232 shell functions, variables referenced within the function body are
9233 expanded. If a function has been modified using overrides or using
9234 override-style operators like ``_append`` and ``_prepend``, then the
9235 final assembled function body appears in the output.
9236
9237Viewing Package Information with ``oe-pkgdata-util``
9238----------------------------------------------------
9239
9240You can use the ``oe-pkgdata-util`` command-line utility to query
9241:term:`PKGDATA_DIR` and display
9242various package-related information. When you use the utility, you must
9243use it to view information on packages that have already been built.
9244
9245Following are a few of the available ``oe-pkgdata-util`` subcommands.
9246
9247.. note::
9248
9249 You can use the standard \* and ? globbing wildcards as part of
9250 package names and paths.
9251
9252- ``oe-pkgdata-util list-pkgs [pattern]``: Lists all packages
9253 that have been built, optionally limiting the match to packages that
9254 match pattern.
9255
9256- ``oe-pkgdata-util list-pkg-files package ...``: Lists the
9257 files and directories contained in the given packages.
9258
9259 .. note::
9260
9261 A different way to view the contents of a package is to look at
9262 the
9263 ``${``\ :term:`WORKDIR`\ ``}/packages-split``
9264 directory of the recipe that generates the package. This directory
9265 is created by the
9266 :ref:`ref-tasks-package` task
9267 and has one subdirectory for each package the recipe generates,
9268 which contains the files stored in that package.
9269
9270 If you want to inspect the ``${WORKDIR}/packages-split``
9271 directory, make sure that
9272 :ref:`rm_work <ref-classes-rm-work>` is not
9273 enabled when you build the recipe.
9274
9275- ``oe-pkgdata-util find-path path ...``: Lists the names of
9276 the packages that contain the given paths. For example, the following
9277 tells us that ``/usr/share/man/man1/make.1`` is contained in the
9278 ``make-doc`` package:
9279 ::
9280
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009281 $ oe-pkgdata-util find-path /usr/share/man/man1/make.1
9282 make-doc: /usr/share/man/man1/make.1
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009283
9284- ``oe-pkgdata-util lookup-recipe package ...``: Lists the name
9285 of the recipes that produce the given packages.
9286
9287For more information on the ``oe-pkgdata-util`` command, use the help
9288facility:
9289::
9290
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009291 $ oe-pkgdata-util --help
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009292 $ oe-pkgdata-util subcommand --help
9293
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009294Viewing Dependencies Between Recipes and Tasks
9295----------------------------------------------
9296
9297Sometimes it can be hard to see why BitBake wants to build other recipes
9298before the one you have specified. Dependency information can help you
9299understand why a recipe is built.
9300
9301To generate dependency information for a recipe, run the following
9302command:
9303::
9304
9305 $ bitbake -g recipename
9306
9307This command writes the following files in the current directory:
9308
9309- ``pn-buildlist``: A list of recipes/targets involved in building
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009310 `recipename`. "Involved" here means that at least one task from the
9311 recipe needs to run when building `recipename` from scratch. Targets
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009312 that are in
9313 :term:`ASSUME_PROVIDED`
9314 are not listed.
9315
9316- ``task-depends.dot``: A graph showing dependencies between tasks.
9317
9318The graphs are in
9319`DOT <https://en.wikipedia.org/wiki/DOT_%28graph_description_language%29>`__
9320format and can be converted to images (e.g. using the ``dot`` tool from
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009321`Graphviz <https://www.graphviz.org/>`__).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009322
9323.. note::
9324
9325 - DOT files use a plain text format. The graphs generated using the
9326 ``bitbake -g`` command are often so large as to be difficult to
9327 read without special pruning (e.g. with Bitbake's ``-I`` option)
9328 and processing. Despite the form and size of the graphs, the
9329 corresponding ``.dot`` files can still be possible to read and
9330 provide useful information.
9331
9332 As an example, the ``task-depends.dot`` file contains lines such
9333 as the following:
9334 ::
9335
9336 "libxslt.do_configure" -> "libxml2.do_populate_sysroot"
9337
9338 The above example line reveals that the
9339 :ref:`ref-tasks-configure`
9340 task in ``libxslt`` depends on the
9341 :ref:`ref-tasks-populate_sysroot`
9342 task in ``libxml2``, which is a normal
9343 :term:`DEPENDS` dependency
9344 between the two recipes.
9345
9346 - For an example of how ``.dot`` files can be processed, see the
9347 ``scripts/contrib/graph-tool`` Python script, which finds and
9348 displays paths between graph nodes.
9349
9350You can use a different method to view dependency information by using
9351the following command:
9352::
9353
9354 $ bitbake -g -u taskexp recipename
9355
9356This command
9357displays a GUI window from which you can view build-time and runtime
9358dependencies for the recipes involved in building recipename.
9359
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009360Viewing Task Variable Dependencies
9361----------------------------------
9362
9363As mentioned in the
9364":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-execution:checksums (signatures)`" section of the BitBake
9365User Manual, BitBake tries to automatically determine what variables a
9366task depends on so that it can rerun the task if any values of the
9367variables change. This determination is usually reliable. However, if
9368you do things like construct variable names at runtime, then you might
9369have to manually declare dependencies on those variables using
9370``vardeps`` as described in the
9371":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags`" section of the BitBake
9372User Manual.
9373
9374If you are unsure whether a variable dependency is being picked up
9375automatically for a given task, you can list the variable dependencies
9376BitBake has determined by doing the following:
9377
93781. Build the recipe containing the task:
9379::
9380
9381 $ bitbake recipename
9382
93832. Inside the :term:`STAMPS_DIR`
9384 directory, find the signature data (``sigdata``) file that
9385 corresponds to the task. The ``sigdata`` files contain a pickled
9386 Python database of all the metadata that went into creating the input
9387 checksum for the task. As an example, for the
9388 :ref:`ref-tasks-fetch` task of the
9389 ``db`` recipe, the ``sigdata`` file might be found in the following
9390 location:
9391 ::
9392
9393 ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
9394
9395 For tasks that are accelerated through the shared state
Andrew Geissler09209ee2020-12-13 08:44:15 -06009396 (:ref:`sstate <overview-manual/concepts:shared state cache>`) cache, an
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009397 additional ``siginfo`` file is written into
9398 :term:`SSTATE_DIR` along with
9399 the cached task output. The ``siginfo`` files contain exactly the
9400 same information as ``sigdata`` files.
9401
94023. Run ``bitbake-dumpsig`` on the ``sigdata`` or ``siginfo`` file. Here
9403 is an example:
9404 ::
9405
9406 $ bitbake-dumpsig ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
9407
9408 In the output of the above command, you will find a line like the
9409 following, which lists all the (inferred) variable dependencies for
9410 the task. This list also includes indirect dependencies from
9411 variables depending on other variables, recursively.
9412 ::
9413
9414 Task dependencies: ['PV', 'SRCREV', 'SRC_URI', 'SRC_URI[md5sum]', 'SRC_URI[sha256sum]', 'base_do_fetch']
9415
9416 .. note::
9417
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009418 Functions (e.g. ``base_do_fetch``) also count as variable dependencies.
9419 These functions in turn depend on the variables they reference.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009420
9421 The output of ``bitbake-dumpsig`` also includes the value each
9422 variable had, a list of dependencies for each variable, and
9423 :term:`bitbake:BB_HASHBASE_WHITELIST`
9424 information.
9425
9426There is also a ``bitbake-diffsigs`` command for comparing two
9427``siginfo`` or ``sigdata`` files. This command can be helpful when
9428trying to figure out what changed between two versions of a task. If you
9429call ``bitbake-diffsigs`` with just one file, the command behaves like
9430``bitbake-dumpsig``.
9431
9432You can also use BitBake to dump out the signature construction
9433information without executing tasks by using either of the following
9434BitBake command-line options:
9435::
9436
9437 ‐‐dump-signatures=SIGNATURE_HANDLER
9438 -S SIGNATURE_HANDLER
9439
9440
9441.. note::
9442
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009443 Two common values for `SIGNATURE_HANDLER` are "none" and "printdiff", which
9444 dump only the signature or compare the dumped signature with the cached one,
9445 respectively.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009446
9447Using BitBake with either of these options causes BitBake to dump out
9448``sigdata`` files in the ``stamps`` directory for every task it would
9449have executed instead of building the specified target package.
9450
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009451Viewing Metadata Used to Create the Input Signature of a Shared State Task
9452--------------------------------------------------------------------------
9453
9454Seeing what metadata went into creating the input signature of a shared
9455state (sstate) task can be a useful debugging aid. This information is
9456available in signature information (``siginfo``) files in
9457:term:`SSTATE_DIR`. For
9458information on how to view and interpret information in ``siginfo``
9459files, see the "`Viewing Task Variable
9460Dependencies <#dev-viewing-task-variable-dependencies>`__" section.
9461
9462For conceptual information on shared state, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06009463":ref:`overview-manual/concepts:shared state`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009464section in the Yocto Project Overview and Concepts Manual.
9465
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009466Invalidating Shared State to Force a Task to Run
9467------------------------------------------------
9468
9469The OpenEmbedded build system uses
Andrew Geissler09209ee2020-12-13 08:44:15 -06009470:ref:`checksums <overview-manual/concepts:checksums (signatures)>` and
9471:ref:`overview-manual/concepts:shared state` cache to avoid unnecessarily
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009472rebuilding tasks. Collectively, this scheme is known as "shared state
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009473code".
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009474
9475As with all schemes, this one has some drawbacks. It is possible that
9476you could make implicit changes to your code that the checksum
9477calculations do not take into account. These implicit changes affect a
9478task's output but do not trigger the shared state code into rebuilding a
9479recipe. Consider an example during which a tool changes its output.
9480Assume that the output of ``rpmdeps`` changes. The result of the change
9481should be that all the ``package`` and ``package_write_rpm`` shared
9482state cache items become invalid. However, because the change to the
9483output is external to the code and therefore implicit, the associated
9484shared state cache items do not become invalidated. In this case, the
9485build process uses the cached items rather than running the task again.
9486Obviously, these types of implicit changes can cause problems.
9487
9488To avoid these problems during the build, you need to understand the
9489effects of any changes you make. Realize that changes you make directly
9490to a function are automatically factored into the checksum calculation.
9491Thus, these explicit changes invalidate the associated area of shared
9492state cache. However, you need to be aware of any implicit changes that
9493are not obvious changes to the code and could affect the output of a
9494given task.
9495
9496When you identify an implicit change, you can easily take steps to
9497invalidate the cache and force the tasks to run. The steps you can take
9498are as simple as changing a function's comments in the source code. For
9499example, to invalidate package shared state files, change the comment
9500statements of
9501:ref:`ref-tasks-package` or the
9502comments of one of the functions it calls. Even though the change is
9503purely cosmetic, it causes the checksum to be recalculated and forces
9504the build system to run the task again.
9505
9506.. note::
9507
9508 For an example of a commit that makes a cosmetic change to invalidate
9509 shared state, see this
Andrew Geissler09209ee2020-12-13 08:44:15 -06009510 :yocto_git:`commit </poky/commit/meta/classes/package.bbclass?id=737f8bbb4f27b4837047cb9b4fbfe01dfde36d54>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009511
9512Running Specific Tasks
9513----------------------
9514
9515Any given recipe consists of a set of tasks. The standard BitBake
9516behavior in most cases is: ``do_fetch``, ``do_unpack``, ``do_patch``,
9517``do_configure``, ``do_compile``, ``do_install``, ``do_package``,
9518``do_package_write_*``, and ``do_build``. The default task is
9519``do_build`` and any tasks on which it depends build first. Some tasks,
9520such as ``do_devshell``, are not part of the default build chain. If you
9521wish to run a task that is not part of the default build chain, you can
9522use the ``-c`` option in BitBake. Here is an example:
9523::
9524
9525 $ bitbake matchbox-desktop -c devshell
9526
9527The ``-c`` option respects task dependencies, which means that all other
9528tasks (including tasks from other recipes) that the specified task
9529depends on will be run before the task. Even when you manually specify a
9530task to run with ``-c``, BitBake will only run the task if it considers
9531it "out of date". See the
Andrew Geissler09209ee2020-12-13 08:44:15 -06009532":ref:`overview-manual/concepts:stamp files and the rerunning of tasks`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009533section in the Yocto Project Overview and Concepts Manual for how
9534BitBake determines whether a task is "out of date".
9535
9536If you want to force an up-to-date task to be rerun (e.g. because you
9537made manual modifications to the recipe's
9538:term:`WORKDIR` that you want to try
9539out), then you can use the ``-f`` option.
9540
9541.. note::
9542
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009543 The reason ``-f`` is never required when running the
9544 :ref:`ref-tasks-devshell` task is because the
9545 [\ :ref:`nostamp <bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ]
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009546 variable flag is already set for the task.
9547
9548The following example shows one way you can use the ``-f`` option:
9549::
9550
9551 $ bitbake matchbox-desktop
9552 .
9553 .
9554 make some changes to the source code in the work directory
9555 .
9556 .
9557 $ bitbake matchbox-desktop -c compile -f
9558 $ bitbake matchbox-desktop
9559
9560This sequence first builds and then recompiles ``matchbox-desktop``. The
9561last command reruns all tasks (basically the packaging tasks) after the
9562compile. BitBake recognizes that the ``do_compile`` task was rerun and
9563therefore understands that the other tasks also need to be run again.
9564
9565Another, shorter way to rerun a task and all
Andrew Geissler09209ee2020-12-13 08:44:15 -06009566:ref:`ref-manual/tasks:normal recipe build tasks`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009567that depend on it is to use the ``-C`` option.
9568
9569.. note::
9570
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009571 This option is upper-cased and is separate from the ``-c``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009572 option, which is lower-cased.
9573
9574Using this option invalidates the given task and then runs the
9575:ref:`ref-tasks-build` task, which is
9576the default task if no task is given, and the tasks on which it depends.
9577You could replace the final two commands in the previous example with
9578the following single command:
9579::
9580
9581 $ bitbake matchbox-desktop -C compile
9582
9583Internally, the ``-f`` and ``-C`` options work by tainting (modifying)
9584the input checksum of the specified task. This tainting indirectly
9585causes the task and its dependent tasks to be rerun through the normal
9586task dependency mechanisms.
9587
9588.. note::
9589
9590 BitBake explicitly keeps track of which tasks have been tainted in
9591 this fashion, and will print warnings such as the following for
9592 builds involving such tasks:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009593
9594 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009595
9596 WARNING: /home/ulf/poky/meta/recipes-sato/matchbox-desktop/matchbox-desktop_2.1.bb.do_compile is tainted from a forced run
9597
9598
9599 The purpose of the warning is to let you know that the work directory
9600 and build output might not be in the clean state they would be in for
9601 a "normal" build, depending on what actions you took. To get rid of
9602 such warnings, you can remove the work directory and rebuild the
9603 recipe, as follows:
9604 ::
9605
9606 $ bitbake matchbox-desktop -c clean
9607 $ bitbake matchbox-desktop
9608
9609
9610You can view a list of tasks in a given package by running the
9611``do_listtasks`` task as follows:
9612::
9613
9614 $ bitbake matchbox-desktop -c listtasks
9615
9616The results appear as output to the console and are also in
9617the file ``${WORKDIR}/temp/log.do_listtasks``.
9618
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009619General BitBake Problems
9620------------------------
9621
9622You can see debug output from BitBake by using the ``-D`` option. The
9623debug output gives more information about what BitBake is doing and the
9624reason behind it. Each ``-D`` option you use increases the logging
9625level. The most common usage is ``-DDD``.
9626
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009627The output from ``bitbake -DDD -v targetname`` can reveal why BitBake
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009628chose a certain version of a package or why BitBake picked a certain
9629provider. This command could also help you in a situation where you
9630think BitBake did something unexpected.
9631
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009632Building with No Dependencies
9633-----------------------------
9634
9635To build a specific recipe (``.bb`` file), you can use the following
9636command form:
9637::
9638
9639 $ bitbake -b somepath/somerecipe.bb
9640
9641This command form does
9642not check for dependencies. Consequently, you should use it only when
9643you know existing dependencies have been met.
9644
9645.. note::
9646
9647 You can also specify fragments of the filename. In this case, BitBake
9648 checks for a unique match.
9649
9650Recipe Logging Mechanisms
9651-------------------------
9652
9653The Yocto Project provides several logging functions for producing
9654debugging output and reporting errors and warnings. For Python
9655functions, the following logging functions exist. All of these functions
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009656log to ``${T}/log.do_``\ `task`, and can also log to standard output
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009657(stdout) with the right settings:
9658
9659- ``bb.plain(msg)``: Writes msg as is to the log while also
9660 logging to stdout.
9661
9662- ``bb.note(msg)``: Writes "NOTE: msg" to the log. Also logs to
9663 stdout if BitBake is called with "-v".
9664
9665- ``bb.debug(level, msg)``: Writes "DEBUG: msg" to the
9666 log. Also logs to stdout if the log level is greater than or equal to
9667 level. See the ":ref:`-D <bitbake:bitbake-user-manual/bitbake-user-manual-intro:usage and syntax>`" option
9668 in the BitBake User Manual for more information.
9669
9670- ``bb.warn(msg)``: Writes "WARNING: msg" to the log while also
9671 logging to stdout.
9672
9673- ``bb.error(msg)``: Writes "ERROR: msg" to the log while also
9674 logging to standard out (stdout).
9675
9676 .. note::
9677
9678 Calling this function does not cause the task to fail.
9679
9680- ``bb.fatal(``\ msg\ ``)``: This logging function is similar to
9681 ``bb.error(``\ msg\ ``)`` but also causes the calling task to fail.
9682
9683 .. note::
9684
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009685 ``bb.fatal()`` raises an exception, which means you do not need to put a
9686 "return" statement after the function.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009687
9688The same logging functions are also available in shell functions, under
9689the names ``bbplain``, ``bbnote``, ``bbdebug``, ``bbwarn``, ``bberror``,
9690and ``bbfatal``. The
9691:ref:`logging <ref-classes-logging>` class
9692implements these functions. See that class in the ``meta/classes``
9693folder of the :term:`Source Directory` for information.
9694
9695Logging With Python
9696~~~~~~~~~~~~~~~~~~~
9697
9698When creating recipes using Python and inserting code that handles build
9699logs, keep in mind the goal is to have informative logs while keeping
9700the console as "silent" as possible. Also, if you want status messages
9701in the log, use the "debug" loglevel.
9702
9703Following is an example written in Python. The code handles logging for
9704a function that determines the number of tasks needed to be run. See the
9705":ref:`ref-tasks-listtasks`"
9706section for additional information:
9707::
9708
9709 python do_listtasks() {
9710 bb.debug(2, "Starting to figure out the task list")
9711 if noteworthy_condition:
9712 bb.note("There are 47 tasks to run")
9713 bb.debug(2, "Got to point xyz")
9714 if warning_trigger:
9715 bb.warn("Detected warning_trigger, this might be a problem later.")
9716 if recoverable_error:
9717 bb.error("Hit recoverable_error, you really need to fix this!")
9718 if fatal_error:
9719 bb.fatal("fatal_error detected, unable to print the task list")
9720 bb.plain("The tasks present are abc")
9721 bb.debug(2, "Finished figuring out the tasklist")
9722 }
9723
9724Logging With Bash
9725~~~~~~~~~~~~~~~~~
9726
9727When creating recipes using Bash and inserting code that handles build
9728logs, you have the same goals - informative with minimal console output.
9729The syntax you use for recipes written in Bash is similar to that of
9730recipes written in Python described in the previous section.
9731
9732Following is an example written in Bash. The code logs the progress of
9733the ``do_my_function`` function.
9734::
9735
9736 do_my_function() {
9737 bbdebug 2 "Running do_my_function"
9738 if [ exceptional_condition ]; then
9739 bbnote "Hit exceptional_condition"
9740 fi
9741 bbdebug 2 "Got to point xyz"
9742 if [ warning_trigger ]; then
9743 bbwarn "Detected warning_trigger, this might cause a problem later."
9744 fi
9745 if [ recoverable_error ]; then
9746 bberror "Hit recoverable_error, correcting"
9747 fi
9748 if [ fatal_error ]; then
9749 bbfatal "fatal_error detected"
9750 fi
9751 bbdebug 2 "Completed do_my_function"
9752 }
9753
9754
9755Debugging Parallel Make Races
9756-----------------------------
9757
9758A parallel ``make`` race occurs when the build consists of several parts
9759that are run simultaneously and a situation occurs when the output or
9760result of one part is not ready for use with a different part of the
9761build that depends on that output. Parallel make races are annoying and
9762can sometimes be difficult to reproduce and fix. However, some simple
9763tips and tricks exist that can help you debug and fix them. This section
9764presents a real-world example of an error encountered on the Yocto
9765Project autobuilder and the process used to fix it.
9766
9767.. note::
9768
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009769 If you cannot properly fix a ``make`` race condition, you can work around it
9770 by clearing either the :term:`PARALLEL_MAKE` or :term:`PARALLEL_MAKEINST`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009771 variables.
9772
9773The Failure
9774~~~~~~~~~~~
9775
9776For this example, assume that you are building an image that depends on
9777the "neard" package. And, during the build, BitBake runs into problems
9778and creates the following output.
9779
9780.. note::
9781
9782 This example log file has longer lines artificially broken to make
9783 the listing easier to read.
9784
9785If you examine the output or the log file, you see the failure during
9786``make``:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009787
9788.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009789
9790 | DEBUG: SITE files ['endian-little', 'bit-32', 'ix86-common', 'common-linux', 'common-glibc', 'i586-linux', 'common']
9791 | DEBUG: Executing shell function do_compile
9792 | NOTE: make -j 16
9793 | make --no-print-directory all-am
9794 | /bin/mkdir -p include/near
9795 | /bin/mkdir -p include/near
9796 | /bin/mkdir -p include/near
9797 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9798 0.14-r0/neard-0.14/include/types.h include/near/types.h
9799 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9800 0.14-r0/neard-0.14/include/log.h include/near/log.h
9801 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9802 0.14-r0/neard-0.14/include/plugin.h include/near/plugin.h
9803 | /bin/mkdir -p include/near
9804 | /bin/mkdir -p include/near
9805 | /bin/mkdir -p include/near
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/tag.h include/near/tag.h
9808 | /bin/mkdir -p include/near
9809 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9810 0.14-r0/neard-0.14/include/adapter.h include/near/adapter.h
9811 | /bin/mkdir -p include/near
9812 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9813 0.14-r0/neard-0.14/include/ndef.h include/near/ndef.h
9814 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9815 0.14-r0/neard-0.14/include/tlv.h include/near/tlv.h
9816 | /bin/mkdir -p include/near
9817 | /bin/mkdir -p include/near
9818 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9819 0.14-r0/neard-0.14/include/setting.h include/near/setting.h
9820 | /bin/mkdir -p include/near
9821 | /bin/mkdir -p include/near
9822 | /bin/mkdir -p include/near
9823 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9824 0.14-r0/neard-0.14/include/device.h include/near/device.h
9825 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9826 0.14-r0/neard-0.14/include/nfc_copy.h include/near/nfc_copy.h
9827 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9828 0.14-r0/neard-0.14/include/snep.h include/near/snep.h
9829 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9830 0.14-r0/neard-0.14/include/version.h include/near/version.h
9831 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9832 0.14-r0/neard-0.14/include/dbus.h include/near/dbus.h
9833 | ./src/genbuiltin nfctype1 nfctype2 nfctype3 nfctype4 p2p > src/builtin.h
9834 | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/
9835 build/build/tmp/sysroots/qemux86 -DHAVE_CONFIG_H -I. -I./include -I./src -I./gdbus -I/home/pokybuild/
9836 yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/glib-2.0
9837 -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/
9838 lib/glib-2.0/include -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/
9839 tmp/sysroots/qemux86/usr/include/dbus-1.0 -I/home/pokybuild/yocto-autobuilder/yocto-slave/
9840 nightly-x86/build/build/tmp/sysroots/qemux86/usr/lib/dbus-1.0/include -I/home/pokybuild/yocto-autobuilder/
9841 yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/libnl3
9842 -DNEAR_PLUGIN_BUILTIN -DPLUGINDIR=\""/usr/lib/near/plugins"\"
9843 -DCONFIGDIR=\""/etc/neard\"" -O2 -pipe -g -feliminate-unused-debug-types -c
9844 -o tools/snep-send.o tools/snep-send.c
9845 | In file included from tools/snep-send.c:16:0:
9846 | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
9847 | #include <near/dbus.h>
9848 | ^
9849 | compilation terminated.
9850 | make[1]: *** [tools/snep-send.o] Error 1
9851 | make[1]: *** Waiting for unfinished jobs....
9852 | make: *** [all] Error 2
9853 | ERROR: oe_runmake failed
9854
9855Reproducing the Error
9856~~~~~~~~~~~~~~~~~~~~~
9857
9858Because race conditions are intermittent, they do not manifest
9859themselves every time you do the build. In fact, most times the build
9860will complete without problems even though the potential race condition
9861exists. Thus, once the error surfaces, you need a way to reproduce it.
9862
9863In this example, compiling the "neard" package is causing the problem.
9864So the first thing to do is build "neard" locally. Before you start the
9865build, set the
9866:term:`PARALLEL_MAKE` variable
9867in your ``local.conf`` file to a high number (e.g. "-j 20"). Using a
9868high value for ``PARALLEL_MAKE`` increases the chances of the race
9869condition showing up:
9870::
9871
9872 $ bitbake neard
9873
9874Once the local build for "neard" completes, start a ``devshell`` build:
9875::
9876
9877 $ bitbake neard -c devshell
9878
9879For information on how to use a
9880``devshell``, see the "`Using a Development
9881Shell <#platdev-appdev-devshell>`__" section.
9882
9883In the ``devshell``, do the following:
9884::
9885
9886 $ make clean
9887 $ make tools/snep-send.o
9888
9889The ``devshell`` commands cause the failure to clearly
9890be visible. In this case, a missing dependency exists for the "neard"
9891Makefile target. Here is some abbreviated, sample output with the
9892missing dependency clearly visible at the end:
9893::
9894
9895 i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/scott-lenovo/......
9896 .
9897 .
9898 .
9899 tools/snep-send.c
9900 In file included from tools/snep-send.c:16:0:
9901 tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
9902 #include <near/dbus.h>
9903 ^
9904 compilation terminated.
9905 make: *** [tools/snep-send.o] Error 1
9906 $
9907
9908
9909Creating a Patch for the Fix
9910~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9911
9912Because there is a missing dependency for the Makefile target, you need
9913to patch the ``Makefile.am`` file, which is generated from
9914``Makefile.in``. You can use Quilt to create the patch:
9915::
9916
9917 $ quilt new parallelmake.patch
9918 Patch patches/parallelmake.patch is now on top
9919 $ quilt add Makefile.am
9920 File Makefile.am added to patch patches/parallelmake.patch
9921
9922For more information on using Quilt, see the
9923"`Using Quilt in Your Workflow <#using-a-quilt-workflow>`__" section.
9924
9925At this point you need to make the edits to ``Makefile.am`` to add the
9926missing dependency. For our example, you have to add the following line
9927to the file:
9928::
9929
9930 tools/snep-send.$(OBJEXT): include/near/dbus.h
9931
9932Once you have edited the file, use the ``refresh`` command to create the
9933patch:
9934::
9935
9936 $ quilt refresh
9937 Refreshed patch patches/parallelmake.patch
9938
9939Once
9940the patch file exists, you need to add it back to the originating recipe
9941folder. Here is an example assuming a top-level
9942:term:`Source Directory` named ``poky``:
9943::
9944
9945 $ cp patches/parallelmake.patch poky/meta/recipes-connectivity/neard/neard
9946
9947The final thing you need to do to implement the fix in the build is to
9948update the "neard" recipe (i.e. ``neard-0.14.bb``) so that the
9949:term:`SRC_URI` statement includes
9950the patch file. The recipe file is in the folder above the patch. Here
9951is what the edited ``SRC_URI`` statement would look like:
9952::
9953
9954 SRC_URI = "${KERNELORG_MIRROR}/linux/network/nfc/${BPN}-${PV}.tar.xz \
9955 file://neard.in \
9956 file://neard.service.in \
9957 file://parallelmake.patch \
9958 "
9959
9960With the patch complete and moved to the correct folder and the
9961``SRC_URI`` statement updated, you can exit the ``devshell``:
9962::
9963
9964 $ exit
9965
9966Testing the Build
9967~~~~~~~~~~~~~~~~~
9968
9969With everything in place, you can get back to trying the build again
9970locally:
9971::
9972
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009973 $ bitbake neard
9974
9975This build should succeed.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009976
9977Now you can open up a ``devshell`` again and repeat the clean and make
9978operations as follows:
9979::
9980
9981 $ bitbake neard -c devshell
9982 $ make clean
9983 $ make tools/snep-send.o
9984
9985The build should work without issue.
9986
9987As with all solved problems, if they originated upstream, you need to
9988submit the fix for the recipe in OE-Core and upstream so that the
9989problem is taken care of at its source. See the "`Submitting a Change to
9990the Yocto Project <#how-to-submit-a-change>`__" section for more
9991information.
9992
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009993Debugging With the GNU Project Debugger (GDB) Remotely
9994------------------------------------------------------
9995
9996GDB allows you to examine running programs, which in turn helps you to
9997understand and fix problems. It also allows you to perform post-mortem
9998style analysis of program crashes. GDB is available as a package within
9999the Yocto Project and is installed in SDK images by default. See the
Andrew Geissler09209ee2020-12-13 08:44:15 -060010000":ref:`ref-manual/images:Images`" chapter in the Yocto
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010001Project Reference Manual for a description of these images. You can find
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010002information on GDB at https://sourceware.org/gdb/.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010003
10004.. note::
10005
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010006 For best results, install debug (``-dbg``) packages for the applications you
10007 are going to debug. Doing so makes extra debug symbols available that give
10008 you more meaningful output.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010009
10010Sometimes, due to memory or disk space constraints, it is not possible
10011to use GDB directly on the remote target to debug applications. These
10012constraints arise because GDB needs to load the debugging information
10013and the binaries of the process being debugged. Additionally, GDB needs
10014to perform many computations to locate information such as function
10015names, variable names and values, stack traces and so forth - even
10016before starting the debugging process. These extra computations place
10017more load on the target system and can alter the characteristics of the
10018program being debugged.
10019
10020To help get past the previously mentioned constraints, you can use
10021gdbserver, which runs on the remote target and does not load any
10022debugging information from the debugged process. Instead, a GDB instance
10023processes the debugging information that is run on a remote computer -
10024the host GDB. The host GDB then sends control commands to gdbserver to
10025make it stop or start the debugged program, as well as read or write
10026memory regions of that debugged program. All the debugging information
10027loaded and processed as well as all the heavy debugging is done by the
10028host GDB. Offloading these processes gives the gdbserver running on the
10029target a chance to remain small and fast.
10030
10031Because the host GDB is responsible for loading the debugging
10032information and for doing the necessary processing to make actual
10033debugging happen, you have to make sure the host can access the
10034unstripped binaries complete with their debugging information and also
10035be sure the target is compiled with no optimizations. The host GDB must
10036also have local access to all the libraries used by the debugged
10037program. Because gdbserver does not need any local debugging
10038information, the binaries on the remote target can remain stripped.
10039However, the binaries must also be compiled without optimization so they
10040match the host's binaries.
10041
10042To remain consistent with GDB documentation and terminology, the binary
10043being debugged on the remote target machine is referred to as the
10044"inferior" binary. For documentation on GDB see the `GDB
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010045site <https://sourceware.org/gdb/documentation/>`__.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010046
10047The following steps show you how to debug using the GNU project
10048debugger.
10049
100501. *Configure your build system to construct the companion debug
10051 filesystem:*
10052
10053 In your ``local.conf`` file, set the following:
10054 ::
10055
10056 IMAGE_GEN_DEBUGFS = "1"
10057 IMAGE_FSTYPES_DEBUGFS = "tar.bz2"
10058
10059 These options cause the
10060 OpenEmbedded build system to generate a special companion filesystem
10061 fragment, which contains the matching source and debug symbols to
10062 your deployable filesystem. The build system does this by looking at
10063 what is in the deployed filesystem, and pulling the corresponding
10064 ``-dbg`` packages.
10065
10066 The companion debug filesystem is not a complete filesystem, but only
10067 contains the debug fragments. This filesystem must be combined with
10068 the full filesystem for debugging. Subsequent steps in this procedure
10069 show how to combine the partial filesystem with the full filesystem.
10070
100712. *Configure the system to include gdbserver in the target filesystem:*
10072
10073 Make the following addition in either your ``local.conf`` file or in
10074 an image recipe:
10075 ::
10076
10077 IMAGE_INSTALL_append = " gdbserver"
10078
10079 The change makes
10080 sure the ``gdbserver`` package is included.
10081
100823. *Build the environment:*
10083
10084 Use the following command to construct the image and the companion
10085 Debug Filesystem:
10086 ::
10087
10088 $ bitbake image
10089
10090 Build the cross GDB component and
10091 make it available for debugging. Build the SDK that matches the
10092 image. Building the SDK is best for a production build that can be
10093 used later for debugging, especially during long term maintenance:
10094 ::
10095
10096 $ bitbake -c populate_sdk image
10097
10098 Alternatively, you can build the minimal toolchain components that
10099 match the target. Doing so creates a smaller than typical SDK and
10100 only contains a minimal set of components with which to build simple
10101 test applications, as well as run the debugger:
10102 ::
10103
10104 $ bitbake meta-toolchain
10105
10106 A final method is to build Gdb itself within the build system:
10107 ::
10108
10109 $ bitbake gdb-cross-<architecture>
10110
10111 Doing so produces a temporary copy of
10112 ``cross-gdb`` you can use for debugging during development. While
10113 this is the quickest approach, the two previous methods in this step
10114 are better when considering long-term maintenance strategies.
10115
10116 .. note::
10117
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010118 If you run ``bitbake gdb-cross``, the OpenEmbedded build system suggests
10119 the actual image (e.g. ``gdb-cross-i586``). The suggestion is usually the
10120 actual name you want to use.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010121
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500101224. *Set up the* ``debugfs``\ *:*
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010123
10124 Run the following commands to set up the ``debugfs``:
10125 ::
10126
10127 $ mkdir debugfs
10128 $ cd debugfs
10129 $ tar xvfj build-dir/tmp-glibc/deploy/images/machine/image.rootfs.tar.bz2
10130 $ tar xvfj build-dir/tmp-glibc/deploy/images/machine/image-dbg.rootfs.tar.bz2
10131
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500101325. *Set up GDB:*
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010133
10134 Install the SDK (if you built one) and then source the correct
10135 environment file. Sourcing the environment file puts the SDK in your
10136 ``PATH`` environment variable.
10137
10138 If you are using the build system, Gdb is located in
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010139 `build-dir`\ ``/tmp/sysroots/``\ `host`\ ``/usr/bin/``\ `architecture`\ ``/``\ `architecture`\ ``-gdb``
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010140
101416. *Boot the target:*
10142
10143 For information on how to run QEMU, see the `QEMU
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010144 Documentation <https://wiki.qemu.org/Documentation/GettingStartedDevelopers>`__.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010145
10146 .. note::
10147
10148 Be sure to verify that your host can access the target via TCP.
10149
101507. *Debug a program:*
10151
10152 Debugging a program involves running gdbserver on the target and then
10153 running Gdb on the host. The example in this step debugs ``gzip``:
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010154
10155 .. code-block:: shell
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010156
10157 root@qemux86:~# gdbserver localhost:1234 /bin/gzip —help
10158
10159 For
10160 additional gdbserver options, see the `GDB Server
10161 Documentation <https://www.gnu.org/software/gdb/documentation/>`__.
10162
10163 After running gdbserver on the target, you need to run Gdb on the
10164 host and configure it and connect to the target. Use these commands:
10165 ::
10166
10167 $ cd directory-holding-the-debugfs-directory
10168 $ arch-gdb
10169 (gdb) set sysroot debugfs
10170 (gdb) set substitute-path /usr/src/debug debugfs/usr/src/debug
10171 (gdb) target remote IP-of-target:1234
10172
10173 At this
10174 point, everything should automatically load (i.e. matching binaries,
10175 symbols and headers).
10176
10177 .. note::
10178
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010179 The Gdb ``set`` commands in the previous example can be placed into the
10180 users ``~/.gdbinit`` file. Upon starting, Gdb automatically runs whatever
10181 commands are in that file.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010182
101838. *Deploying without a full image rebuild:*
10184
10185 In many cases, during development you want a quick method to deploy a
10186 new binary to the target and debug it, without waiting for a full
10187 image build.
10188
10189 One approach to solving this situation is to just build the component
10190 you want to debug. Once you have built the component, copy the
10191 executable directly to both the target and the host ``debugfs``.
10192
10193 If the binary is processed through the debug splitting in
10194 OpenEmbedded, you should also copy the debug items (i.e. ``.debug``
10195 contents and corresponding ``/usr/src/debug`` files) from the work
10196 directory. Here is an example:
10197 ::
10198
10199 $ bitbake bash
10200 $ bitbake -c devshell bash
10201 $ cd ..
10202 $ scp packages-split/bash/bin/bash target:/bin/bash
10203 $ cp -a packages-split/bash-dbg/\* path/debugfs
10204
10205Debugging with the GNU Project Debugger (GDB) on the Target
10206-----------------------------------------------------------
10207
10208The previous section addressed using GDB remotely for debugging
10209purposes, which is the most usual case due to the inherent hardware
10210limitations on many embedded devices. However, debugging in the target
10211hardware itself is also possible with more powerful devices. This
10212section describes what you need to do in order to support using GDB to
10213debug on the target hardware.
10214
10215To support this kind of debugging, you need do the following:
10216
10217- Ensure that GDB is on the target. You can do this by adding "gdb" to
10218 :term:`IMAGE_INSTALL`:
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010219 ::
10220
10221 IMAGE_INSTALL_append = " gdb"
10222
10223 Alternatively, you can add "tools-debug" to :term:`IMAGE_FEATURES`:
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010224 ::
10225
10226 IMAGE_FEATURES_append = " tools-debug"
10227
10228- Ensure that debug symbols are present. You can make sure these
10229 symbols are present by installing ``-dbg``:
10230 ::
10231
10232 IMAGE_INSTALL_append = "packagename-dbg"
10233
10234 Alternatively, you can do the following to include
10235 all the debug symbols:
10236 ::
10237
10238 IMAGE_FEATURES_append = " dbg-pkgs"
10239
10240.. note::
10241
10242 To improve the debug information accuracy, you can reduce the level
10243 of optimization used by the compiler. For example, when adding the
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010244 following line to your ``local.conf`` file, you will reduce optimization
10245 from :term:`FULL_OPTIMIZATION` of "-O2" to :term:`DEBUG_OPTIMIZATION`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010246 of "-O -fno-omit-frame-pointer":
10247 ::
10248
10249 DEBUG_BUILD = "1"
10250
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010251 Consider that this will reduce the application's performance and is
10252 recommended only for debugging purposes.
10253
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010254Other Debugging Tips
10255--------------------
10256
10257Here are some other tips that you might find useful:
10258
10259- When adding new packages, it is worth watching for undesirable items
10260 making their way into compiler command lines. For example, you do not
10261 want references to local system files like ``/usr/lib/`` or
10262 ``/usr/include/``.
10263
10264- If you want to remove the ``psplash`` boot splashscreen, add
10265 ``psplash=false`` to the kernel command line. Doing so prevents
10266 ``psplash`` from loading and thus allows you to see the console. It
10267 is also possible to switch out of the splashscreen by switching the
10268 virtual console (e.g. Fn+Left or Fn+Right on a Zaurus).
10269
10270- Removing :term:`TMPDIR` (usually
10271 ``tmp/``, within the
10272 :term:`Build Directory`) can often fix
10273 temporary build issues. Removing ``TMPDIR`` is usually a relatively
10274 cheap operation, because task output will be cached in
10275 :term:`SSTATE_DIR` (usually
10276 ``sstate-cache/``, which is also in the Build Directory).
10277
10278 .. note::
10279
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010280 Removing ``TMPDIR`` might be a workaround rather than a fix.
10281 Consequently, trying to determine the underlying cause of an issue before
10282 removing the directory is a good idea.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010283
10284- Understanding how a feature is used in practice within existing
10285 recipes can be very helpful. It is recommended that you configure
10286 some method that allows you to quickly search through files.
10287
10288 Using GNU Grep, you can use the following shell function to
10289 recursively search through common recipe-related files, skipping
10290 binary files, ``.git`` directories, and the Build Directory (assuming
10291 its name starts with "build"):
10292 ::
10293
10294 g() {
10295 grep -Ir \
10296 --exclude-dir=.git \
10297 --exclude-dir='build*' \
10298 --include='*.bb*' \
10299 --include='*.inc*' \
10300 --include='*.conf*' \
10301 --include='*.py*' \
10302 "$@"
10303 }
10304
10305 Following are some usage examples:
10306 ::
10307
10308 $ g FOO # Search recursively for "FOO"
10309 $ g -i foo # Search recursively for "foo", ignoring case
10310 $ g -w FOO # Search recursively for "FOO" as a word, ignoring e.g. "FOOBAR"
10311
10312 If figuring
10313 out how some feature works requires a lot of searching, it might
10314 indicate that the documentation should be extended or improved. In
10315 such cases, consider filing a documentation bug using the Yocto
10316 Project implementation of
10317 :yocto_bugs:`Bugzilla <>`. For information on
10318 how to submit a bug against the Yocto Project, see the Yocto Project
Andrew Geissler09209ee2020-12-13 08:44:15 -060010319 Bugzilla :yocto_wiki:`wiki page </Bugzilla_Configuration_and_Bug_Tracking>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010320 and the "`Submitting a Defect Against the Yocto
10321 Project <#submitting-a-defect-against-the-yocto-project>`__" section.
10322
10323 .. note::
10324
10325 The manuals might not be the right place to document variables
10326 that are purely internal and have a limited scope (e.g. internal
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010327 variables used to implement a single ``.bbclass`` file).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010328
10329Making Changes to the Yocto Project
10330===================================
10331
10332Because the Yocto Project is an open-source, community-based project,
10333you can effect changes to the project. This section presents procedures
10334that show you how to submit a defect against the project and how to
10335submit a change.
10336
10337Submitting a Defect Against the Yocto Project
10338---------------------------------------------
10339
10340Use the Yocto Project implementation of
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010341`Bugzilla <https://www.bugzilla.org/about/>`__ to submit a defect (bug)
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010342against the Yocto Project. For additional information on this
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010343implementation of Bugzilla see the ":ref:`Yocto Project
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010344Bugzilla <resources-bugtracker>`" section in the
10345Yocto Project Reference Manual. For more detail on any of the following
10346steps, see the Yocto Project
Andrew Geissler09209ee2020-12-13 08:44:15 -060010347:yocto_wiki:`Bugzilla wiki page </Bugzilla_Configuration_and_Bug_Tracking>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010348
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010349Use the following general steps to submit a bug:
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010350
103511. Open the Yocto Project implementation of :yocto_bugs:`Bugzilla <>`.
10352
103532. Click "File a Bug" to enter a new bug.
10354
103553. Choose the appropriate "Classification", "Product", and "Component"
10356 for which the bug was found. Bugs for the Yocto Project fall into
10357 one of several classifications, which in turn break down into
10358 several products and components. For example, for a bug against the
10359 ``meta-intel`` layer, you would choose "Build System, Metadata &
10360 Runtime", "BSPs", and "bsps-meta-intel", respectively.
10361
103624. Choose the "Version" of the Yocto Project for which you found the
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010363 bug (e.g. &DISTRO;).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010364
103655. Determine and select the "Severity" of the bug. The severity
10366 indicates how the bug impacted your work.
10367
103686. Choose the "Hardware" that the bug impacts.
10369
103707. Choose the "Architecture" that the bug impacts.
10371
103728. Choose a "Documentation change" item for the bug. Fixing a bug might
10373 or might not affect the Yocto Project documentation. If you are
10374 unsure of the impact to the documentation, select "Don't Know".
10375
103769. Provide a brief "Summary" of the bug. Try to limit your summary to
10377 just a line or two and be sure to capture the essence of the bug.
10378
1037910. Provide a detailed "Description" of the bug. You should provide as
10380 much detail as you can about the context, behavior, output, and so
10381 forth that surrounds the bug. You can even attach supporting files
10382 for output from logs by using the "Add an attachment" button.
10383
1038411. Click the "Submit Bug" button submit the bug. A new Bugzilla number
10385 is assigned to the bug and the defect is logged in the bug tracking
10386 system.
10387
10388Once you file a bug, the bug is processed by the Yocto Project Bug
10389Triage Team and further details concerning the bug are assigned (e.g.
10390priority and owner). You are the "Submitter" of the bug and any further
10391categorization, progress, or comments on the bug result in Bugzilla
10392sending you an automated email concerning the particular change or
10393progress to the bug.
10394
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010395Submitting a Change to the Yocto Project
10396----------------------------------------
10397
10398Contributions to the Yocto Project and OpenEmbedded are very welcome.
10399Because the system is extremely configurable and flexible, we recognize
10400that developers will want to extend, configure or optimize it for their
10401specific uses.
10402
10403The Yocto Project uses a mailing list and a patch-based workflow that is
10404similar to the Linux kernel but contains important differences. In
10405general, a mailing list exists through which you can submit patches. You
10406should send patches to the appropriate mailing list so that they can be
10407reviewed and merged by the appropriate maintainer. The specific mailing
10408list you need to use depends on the location of the code you are
10409changing. Each component (e.g. layer) should have a ``README`` file that
10410indicates where to send the changes and which process to follow.
10411
10412You can send the patch to the mailing list using whichever approach you
10413feel comfortable with to generate the patch. Once sent, the patch is
10414usually reviewed by the community at large. If somebody has concerns
10415with the patch, they will usually voice their concern over the mailing
10416list. If a patch does not receive any negative reviews, the maintainer
10417of the affected layer typically takes the patch, tests it, and then
10418based on successful testing, merges the patch.
10419
10420The "poky" repository, which is the Yocto Project's reference build
10421environment, is a hybrid repository that contains several individual
10422pieces (e.g. BitBake, Metadata, documentation, and so forth) built using
10423the combo-layer tool. The upstream location used for submitting changes
10424varies by component:
10425
10426- *Core Metadata:* Send your patch to the
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010427 :oe_lists:`openembedded-core </g/openembedded-core>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010428 mailing list. For example, a change to anything under the ``meta`` or
10429 ``scripts`` directories should be sent to this mailing list.
10430
10431- *BitBake:* For changes to BitBake (i.e. anything under the
10432 ``bitbake`` directory), send your patch to the
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010433 :oe_lists:`bitbake-devel </g/bitbake-devel>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010434 mailing list.
10435
Andrew Geisslerc3d88e42020-10-02 09:45:00 -050010436- *"meta-\*" trees:* These trees contain Metadata. Use the
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010437 :yocto_lists:`poky </g/poky>` mailing list.
Andrew Geisslerc3d88e42020-10-02 09:45:00 -050010438
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010439- *Documentation*: For changes to the Yocto Project documentation, use the
10440 :yocto_lists:`docs </g/docs>` mailing list.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010441
10442For changes to other layers hosted in the Yocto Project source
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010443repositories (i.e. ``yoctoproject.org``) and tools use the
10444:yocto_lists:`Yocto Project </g/yocto/>` general mailing list.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010445
10446.. note::
10447
10448 Sometimes a layer's documentation specifies to use a particular
10449 mailing list. If so, use that list.
10450
10451For additional recipes that do not fit into the core Metadata, you
10452should determine which layer the recipe should go into and submit the
10453change in the manner recommended by the documentation (e.g. the
10454``README`` file) supplied with the layer. If in doubt, please ask on the
10455Yocto general mailing list or on the openembedded-devel mailing list.
10456
10457You can also push a change upstream and request a maintainer to pull the
10458change into the component's upstream repository. You do this by pushing
Andrew Geissler09209ee2020-12-13 08:44:15 -060010459to a contribution repository that is upstream. See the
10460":ref:`overview-manual/development-environment:git workflows and the yocto project`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010461section in the Yocto Project Overview and Concepts Manual for additional
10462concepts on working in the Yocto Project development environment.
10463
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010464Maintainers commonly use ``-next`` branches to test submissions prior to
10465merging patches. Thus, you can get an idea of the status of a patch based on
10466whether the patch has been merged into one of these branches. The commonly
10467used testing branches for OpenEmbedded-Core are as follows:
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010468
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010469- *openembedded-core "master-next" branch:* This branch is part of the
10470 :oe_git:`openembedded-core </openembedded-core/>` repository and contains
10471 proposed changes to the core metadata.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010472
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010473- *poky "master-next" branch:* This branch is part of the
Andrew Geissler09209ee2020-12-13 08:44:15 -060010474 :yocto_git:`poky </poky/>` repository and combines proposed
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010475 changes to bitbake, the core metadata and the poky distro.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010476
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010477Similarly, stable branches maintained by the project may have corresponding
10478``-next`` branches which collect proposed changes. For example,
10479``&DISTRO_NAME_NO_CAP;-next`` and ``&DISTRO_NAME_NO_CAP_MINUS_ONE;-next``
10480branches in both the "openembdedded-core" and "poky" repositories.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010481
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010482Other layers may have similar testing branches but there is no formal
10483requirement or standard for these so please check the documentation for the
10484layers you are contributing to.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010485
10486The following sections provide procedures for submitting a change.
10487
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010488Preparing Changes for Submission
10489~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010490
104911. *Make Your Changes Locally:* Make your changes in your local Git
10492 repository. You should make small, controlled, isolated changes.
10493 Keeping changes small and isolated aids review, makes
10494 merging/rebasing easier and keeps the change history clean should
10495 anyone need to refer to it in future.
10496
104972. *Stage Your Changes:* Stage your changes by using the ``git add``
10498 command on each file you changed.
10499
105003. *Commit Your Changes:* Commit the change by using the ``git commit``
10501 command. Make sure your commit information follows standards by
10502 following these accepted conventions:
10503
10504 - Be sure to include a "Signed-off-by:" line in the same style as
10505 required by the Linux kernel. Adding this line signifies that you,
10506 the submitter, have agreed to the Developer's Certificate of
10507 Origin 1.1 as follows:
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010508
10509 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010510
10511 Developer's Certificate of Origin 1.1
10512
10513 By making a contribution to this project, I certify that:
10514
10515 (a) The contribution was created in whole or in part by me and I
10516 have the right to submit it under the open source license
10517 indicated in the file; or
10518
10519 (b) The contribution is based upon previous work that, to the best
10520 of my knowledge, is covered under an appropriate open source
10521 license and I have the right under that license to submit that
10522 work with modifications, whether created in whole or in part
10523 by me, under the same open source license (unless I am
10524 permitted to submit under a different license), as indicated
10525 in the file; or
10526
10527 (c) The contribution was provided directly to me by some other
10528 person who certified (a), (b) or (c) and I have not modified
10529 it.
10530
10531 (d) I understand and agree that this project and the contribution
10532 are public and that a record of the contribution (including all
10533 personal information I submit with it, including my sign-off) is
10534 maintained indefinitely and may be redistributed consistent with
10535 this project or the open source license(s) involved.
10536
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010537 - Provide a single-line summary of the change and, if more
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010538 explanation is needed, provide more detail in the body of the
10539 commit. This summary is typically viewable in the "shortlist" of
10540 changes. Thus, providing something short and descriptive that
10541 gives the reader a summary of the change is useful when viewing a
10542 list of many commits. You should prefix this short description
10543 with the recipe name (if changing a recipe), or else with the
10544 short form path to the file being changed.
10545
10546 - For the body of the commit message, provide detailed information
10547 that describes what you changed, why you made the change, and the
10548 approach you used. It might also be helpful if you mention how you
10549 tested the change. Provide as much detail as you can in the body
10550 of the commit message.
10551
10552 .. note::
10553
10554 You do not need to provide a more detailed explanation of a
10555 change if the change is minor to the point of the single line
10556 summary providing all the information.
10557
10558 - If the change addresses a specific bug or issue that is associated
10559 with a bug-tracking ID, include a reference to that ID in your
10560 detailed description. For example, the Yocto Project uses a
10561 specific convention for bug references - any commit that addresses
10562 a specific bug should use the following form for the detailed
10563 description. Be sure to use the actual bug-tracking ID from
10564 Bugzilla for bug-id:
10565 ::
10566
10567 Fixes [YOCTO #bug-id]
10568
10569 detailed description of change
10570
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010571Using Email to Submit a Patch
10572~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10573
10574Depending on the components changed, you need to submit the email to a
10575specific mailing list. For some guidance on which mailing list to use,
10576see the `list <#figuring-out-the-mailing-list-to-use>`__ at the
10577beginning of this section. For a description of all the available
10578mailing lists, see the ":ref:`Mailing Lists <resources-mailinglist>`" section in the
10579Yocto Project Reference Manual.
10580
10581Here is the general procedure on how to submit a patch through email
10582without using the scripts once the steps in
Andrew Geissler09209ee2020-12-13 08:44:15 -060010583:ref:`dev-manual/common-tasks:preparing changes for submission` have been followed:
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010584
105851. *Format the Commit:* Format the commit into an email message. To
10586 format commits, use the ``git format-patch`` command. When you
10587 provide the command, you must include a revision list or a number of
10588 patches as part of the command. For example, either of these two
10589 commands takes your most recent single commit and formats it as an
10590 email message in the current directory:
10591 ::
10592
10593 $ git format-patch -1
10594
10595 or ::
10596
10597 $ git format-patch HEAD~
10598
10599 After the command is run, the current directory contains a numbered
10600 ``.patch`` file for the commit.
10601
10602 If you provide several commits as part of the command, the
10603 ``git format-patch`` command produces a series of numbered files in
10604 the current directory – one for each commit. If you have more than
10605 one patch, you should also use the ``--cover`` option with the
10606 command, which generates a cover letter as the first "patch" in the
10607 series. You can then edit the cover letter to provide a description
10608 for the series of patches. For information on the
10609 ``git format-patch`` command, see ``GIT_FORMAT_PATCH(1)`` displayed
10610 using the ``man git-format-patch`` command.
10611
10612 .. note::
10613
10614 If you are or will be a frequent contributor to the Yocto Project
10615 or to OpenEmbedded, you might consider requesting a contrib area
10616 and the necessary associated rights.
10617
106182. *Send the patches via email:* Send the patches to the recipients and
10619 relevant mailing lists by using the ``git send-email`` command.
10620
10621 .. note::
10622
10623 In order to use ``git send-email``, you must have the proper Git packages
10624 installed on your host.
10625 For Ubuntu, Debian, and Fedora the package is ``git-email``.
10626
10627 The ``git send-email`` command sends email by using a local or remote
10628 Mail Transport Agent (MTA) such as ``msmtp``, ``sendmail``, or
10629 through a direct ``smtp`` configuration in your Git ``~/.gitconfig``
10630 file. If you are submitting patches through email only, it is very
10631 important that you submit them without any whitespace or HTML
10632 formatting that either you or your mailer introduces. The maintainer
10633 that receives your patches needs to be able to save and apply them
10634 directly from your emails. A good way to verify that what you are
10635 sending will be applicable by the maintainer is to do a dry run and
10636 send them to yourself and then save and apply them as the maintainer
10637 would.
10638
10639 The ``git send-email`` command is the preferred method for sending
10640 your patches using email since there is no risk of compromising
10641 whitespace in the body of the message, which can occur when you use
10642 your own mail client. The command also has several options that let
10643 you specify recipients and perform further editing of the email
10644 message. For information on how to use the ``git send-email``
10645 command, see ``GIT-SEND-EMAIL(1)`` displayed using the
10646 ``man git-send-email`` command.
10647
10648The Yocto Project uses a `Patchwork instance <https://patchwork.openembedded.org/>`__
10649to track the status of patches submitted to the various mailing lists and to
10650support automated patch testing. Each submitted patch is checked for common
10651mistakes and deviations from the expected patch format and submitters are
10652notified by patchtest if such mistakes are found. This process helps to
10653reduce the burden of patch review on maintainers.
10654
10655.. note::
10656
10657 This system is imperfect and changes can sometimes get lost in the flow.
10658 Asking about the status of a patch or change is reasonable if the change
10659 has been idle for a while with no feedback.
10660
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010661Using Scripts to Push a Change Upstream and Request a Pull
10662~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10663
10664For larger patch series it is preferable to send a pull request which not
10665only includes the patch but also a pointer to a branch that can be pulled
10666from. This involves making a local branch for your changes, pushing this
10667branch to an accessible repository and then using the ``create-pull-request``
10668and ``send-pull-request`` scripts from openembedded-core to create and send a
10669patch series with a link to the branch for review.
10670
10671Follow this procedure to push a change to an upstream "contrib" Git
Andrew Geissler09209ee2020-12-13 08:44:15 -060010672repository once the steps in :ref:`dev-manual/common-tasks:preparing changes for submission` have
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010673been followed:
10674
10675.. note::
10676
10677 You can find general Git information on how to push a change upstream
10678 in the
10679 `Git Community Book <https://git-scm.com/book/en/v2/Distributed-Git-Distributed-Workflows>`__.
10680
106811. *Push Your Commits to a "Contrib" Upstream:* If you have arranged for
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010682 permissions to push to an upstream contrib repository, push the
10683 change to that repository:
10684 ::
10685
10686 $ git push upstream_remote_repo local_branch_name
10687
10688 For example, suppose you have permissions to push
10689 into the upstream ``meta-intel-contrib`` repository and you are
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010690 working in a local branch named `your_name`\ ``/README``. The following
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010691 command pushes your local commits to the ``meta-intel-contrib``
10692 upstream repository and puts the commit in a branch named
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010693 `your_name`\ ``/README``:
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010694 ::
10695
10696 $ git push meta-intel-contrib your_name/README
10697
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600106982. *Determine Who to Notify:* Determine the maintainer or the mailing
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010699 list that you need to notify for the change.
10700
10701 Before submitting any change, you need to be sure who the maintainer
10702 is or what mailing list that you need to notify. Use either these
10703 methods to find out:
10704
10705 - *Maintenance File:* Examine the ``maintainers.inc`` file, which is
10706 located in the :term:`Source Directory` at
10707 ``meta/conf/distro/include``, to see who is responsible for code.
10708
Andrew Geissler09209ee2020-12-13 08:44:15 -060010709 - *Search by File:* Using :ref:`overview-manual/development-environment:git`, you can
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010710 enter the following command to bring up a short list of all
10711 commits against a specific file:
10712 ::
10713
10714 git shortlog -- filename
10715
10716 Just provide the name of the file for which you are interested. The
10717 information returned is not ordered by history but does include a
10718 list of everyone who has committed grouped by name. From the list,
10719 you can see who is responsible for the bulk of the changes against
10720 the file.
10721
10722 - *Examine the List of Mailing Lists:* For a list of the Yocto
10723 Project and related mailing lists, see the ":ref:`Mailing
10724 lists <resources-mailinglist>`" section in
10725 the Yocto Project Reference Manual.
10726
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600107273. *Make a Pull Request:* Notify the maintainer or the mailing list that
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010728 you have pushed a change by making a pull request.
10729
10730 The Yocto Project provides two scripts that conveniently let you
10731 generate and send pull requests to the Yocto Project. These scripts
10732 are ``create-pull-request`` and ``send-pull-request``. You can find
10733 these scripts in the ``scripts`` directory within the
10734 :term:`Source Directory` (e.g.
10735 ``~/poky/scripts``).
10736
10737 Using these scripts correctly formats the requests without
10738 introducing any whitespace or HTML formatting. The maintainer that
10739 receives your patches either directly or through the mailing list
10740 needs to be able to save and apply them directly from your emails.
10741 Using these scripts is the preferred method for sending patches.
10742
10743 First, create the pull request. For example, the following command
10744 runs the script, specifies the upstream repository in the contrib
10745 directory into which you pushed the change, and provides a subject
10746 line in the created patch files:
10747 ::
10748
10749 $ ~/poky/scripts/create-pull-request -u meta-intel-contrib -s "Updated Manual Section Reference in README"
10750
10751 Running this script forms ``*.patch`` files in a folder named
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010752 ``pull-``\ `PID` in the current directory. One of the patch files is a
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010753 cover letter.
10754
10755 Before running the ``send-pull-request`` script, you must edit the
10756 cover letter patch to insert information about your change. After
10757 editing the cover letter, send the pull request. For example, the
10758 following command runs the script and specifies the patch directory
10759 and email address. In this example, the email address is a mailing
10760 list:
10761 ::
10762
10763 $ ~/poky/scripts/send-pull-request -p ~/meta-intel/pull-10565 -t meta-intel@yoctoproject.org
10764
10765 You need to follow the prompts as the script is interactive.
10766
10767 .. note::
10768
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010769 For help on using these scripts, simply provide the ``-h``
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010770 argument as follows:
10771 ::
10772
10773 $ poky/scripts/create-pull-request -h
10774 $ poky/scripts/send-pull-request -h
10775
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010776Responding to Patch Review
10777~~~~~~~~~~~~~~~~~~~~~~~~~~
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010778
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010779You may get feedback on your submitted patches from other community members
10780or from the automated patchtest service. If issues are identified in your
10781patch then it is usually necessary to address these before the patch will be
10782accepted into the project. In this case you should amend the patch according
10783to the feedback and submit an updated version to the relevant mailing list,
10784copying in the reviewers who provided feedback to the previous version of the
10785patch.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010786
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010787The patch should be amended using ``git commit --amend`` or perhaps ``git
10788rebase`` for more expert git users. You should also modify the ``[PATCH]``
10789tag in the email subject line when sending the revised patch to mark the new
10790iteration as ``[PATCH v2]``, ``[PATCH v3]``, etc as appropriate. This can be
10791done by passing the ``-v`` argument to ``git format-patch`` with a version
10792number.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010793
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010794Lastly please ensure that you also test your revised changes. In particular
10795please don't just edit the patch file written out by ``git format-patch`` and
10796resend it.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010797
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010798Submitting Changes to Stable Release Branches
10799~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010800
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010801The process for proposing changes to a Yocto Project stable branch differs
10802from the steps described above. Changes to a stable branch must address
10803identified bugs or CVEs and should be made carefully in order to avoid the
10804risk of introducing new bugs or breaking backwards compatibility. Typically
10805bug fixes must already be accepted into the master branch before they can be
10806backported to a stable branch unless the bug in question does not affect the
10807master branch or the fix on the master branch is unsuitable for backporting.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010808
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010809The list of stable branches along with the status and maintainer for each
10810branch can be obtained from the
Andrew Geissler09209ee2020-12-13 08:44:15 -060010811:yocto_wiki:`Releases wiki page </Releases>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010812
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010813.. note::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010814
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010815 Changes will not typically be accepted for branches which are marked as
10816 End-Of-Life (EOL).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010817
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010818With this in mind, the steps to submit a change for a stable branch are as
10819follows:
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010820
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600108211. *Identify the bug or CVE to be fixed:* This information should be
10822 collected so that it can be included in your submission.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010823
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600108242. *Check if the fix is already present in the master branch:* This will
10825 result in the most straightforward path into the stable branch for the
10826 fix.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010827
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010828 a. *If the fix is present in the master branch - Submit a backport request
10829 by email:* You should send an email to the relevant stable branch
10830 maintainer and the mailing list with details of the bug or CVE to be
10831 fixed, the commit hash on the master branch that fixes the issue and
10832 the stable branches which you would like this fix to be backported to.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010833
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010834 b. *If the fix is not present in the master branch - Submit the fix to the
10835 master branch first:* This will ensure that the fix passes through the
10836 project's usual patch review and test processes before being accepted.
10837 It will also ensure that bugs are not left unresolved in the master
10838 branch itself. Once the fix is accepted in the master branch a backport
10839 request can be submitted as above.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010840
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010841 c. *If the fix is unsuitable for the master branch - Submit a patch
10842 directly for the stable branch:* This method should be considered as a
10843 last resort. It is typically necessary when the master branch is using
10844 a newer version of the software which includes an upstream fix for the
10845 issue or when the issue has been fixed on the master branch in a way
10846 that introduces backwards incompatible changes. In this case follow the
Andrew Geissler09209ee2020-12-13 08:44:15 -060010847 steps in :ref:`dev-manual/common-tasks:preparing changes for submission` and
10848 :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 -060010849 email to include the name of the stable branch which you are
10850 targetting. This can be done using the ``--subject-prefix`` argument to
10851 ``git format-patch``, for example to submit a patch to the dunfell
10852 branch use
10853 ``git format-patch --subject-prefix='&DISTRO_NAME_NO_CAP_MINUS_ONE;][PATCH' ...``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010854
10855Working With Licenses
10856=====================
10857
Andrew Geissler09209ee2020-12-13 08:44:15 -060010858As mentioned in the ":ref:`overview-manual/development-environment:licensing`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010859section in the Yocto Project Overview and Concepts Manual, open source
10860projects are open to the public and they consequently have different
10861licensing structures in place. This section describes the mechanism by
10862which the :term:`OpenEmbedded Build System`
10863tracks changes to
10864licensing text and covers how to maintain open source license compliance
10865during your project's lifecycle. The section also describes how to
10866enable commercially licensed recipes, which by default are disabled.
10867
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010868Tracking License Changes
10869------------------------
10870
10871The license of an upstream project might change in the future. In order
10872to prevent these changes going unnoticed, the
10873:term:`LIC_FILES_CHKSUM`
10874variable tracks changes to the license text. The checksums are validated
10875at the end of the configure step, and if the checksums do not match, the
10876build will fail.
10877
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010878Specifying the ``LIC_FILES_CHKSUM`` Variable
10879~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10880
10881The ``LIC_FILES_CHKSUM`` variable contains checksums of the license text
10882in the source code for the recipe. Following is an example of how to
10883specify ``LIC_FILES_CHKSUM``:
10884::
10885
10886 LIC_FILES_CHKSUM = "file://COPYING;md5=xxxx \
10887 file://licfile1.txt;beginline=5;endline=29;md5=yyyy \
10888 file://licfile2.txt;endline=50;md5=zzzz \
10889 ..."
10890
10891.. note::
10892
10893 - When using "beginline" and "endline", realize that line numbering
10894 begins with one and not zero. Also, the included lines are
10895 inclusive (i.e. lines five through and including 29 in the
10896 previous example for ``licfile1.txt``).
10897
10898 - When a license check fails, the selected license text is included
10899 as part of the QA message. Using this output, you can determine
10900 the exact start and finish for the needed license text.
10901
10902The build system uses the :term:`S`
10903variable as the default directory when searching files listed in
10904``LIC_FILES_CHKSUM``. The previous example employs the default
10905directory.
10906
10907Consider this next example:
10908::
10909
10910 LIC_FILES_CHKSUM = "file://src/ls.c;beginline=5;endline=16;\
10911 md5=bb14ed3c4cda583abc85401304b5cd4e"
10912 LIC_FILES_CHKSUM = "file://${WORKDIR}/license.html;md5=5c94767cedb5d6987c902ac850ded2c6"
10913
10914The first line locates a file in ``${S}/src/ls.c`` and isolates lines
10915five through 16 as license text. The second line refers to a file in
10916:term:`WORKDIR`.
10917
10918Note that ``LIC_FILES_CHKSUM`` variable is mandatory for all recipes,
10919unless the ``LICENSE`` variable is set to "CLOSED".
10920
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010921Explanation of Syntax
10922~~~~~~~~~~~~~~~~~~~~~
10923
10924As mentioned in the previous section, the ``LIC_FILES_CHKSUM`` variable
10925lists all the important files that contain the license text for the
10926source code. It is possible to specify a checksum for an entire file, or
10927a specific section of a file (specified by beginning and ending line
10928numbers with the "beginline" and "endline" parameters, respectively).
10929The latter is useful for source files with a license notice header,
10930README documents, and so forth. If you do not use the "beginline"
10931parameter, then it is assumed that the text begins on the first line of
10932the file. Similarly, if you do not use the "endline" parameter, it is
10933assumed that the license text ends with the last line of the file.
10934
10935The "md5" parameter stores the md5 checksum of the license text. If the
10936license text changes in any way as compared to this parameter then a
10937mismatch occurs. This mismatch triggers a build failure and notifies the
10938developer. Notification allows the developer to review and address the
10939license text changes. Also note that if a mismatch occurs during the
10940build, the correct md5 checksum is placed in the build log and can be
10941easily copied to the recipe.
10942
10943There is no limit to how many files you can specify using the
10944``LIC_FILES_CHKSUM`` variable. Generally, however, every project
10945requires a few specifications for license tracking. Many projects have a
10946"COPYING" file that stores the license information for all the source
10947code files. This practice allows you to just track the "COPYING" file as
10948long as it is kept up to date.
10949
10950.. note::
10951
10952 - If you specify an empty or invalid "md5" parameter,
10953 :term:`BitBake` returns an md5
10954 mis-match error and displays the correct "md5" parameter value
10955 during the build. The correct parameter is also captured in the
10956 build log.
10957
10958 - If the whole file contains only license text, you do not need to
10959 use the "beginline" and "endline" parameters.
10960
10961Enabling Commercially Licensed Recipes
10962--------------------------------------
10963
10964By default, the OpenEmbedded build system disables components that have
10965commercial or other special licensing requirements. Such requirements
10966are defined on a recipe-by-recipe basis through the
10967:term:`LICENSE_FLAGS` variable
10968definition in the affected recipe. For instance, the
10969``poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly`` recipe
10970contains the following statement:
10971::
10972
10973 LICENSE_FLAGS = "commercial"
10974
10975Here is a
10976slightly more complicated example that contains both an explicit recipe
10977name and version (after variable expansion):
10978::
10979
10980 LICENSE_FLAGS = "license_${PN}_${PV}"
10981
10982In order for a component restricted by a
10983``LICENSE_FLAGS`` definition to be enabled and included in an image, it
10984needs to have a matching entry in the global
10985:term:`LICENSE_FLAGS_WHITELIST`
10986variable, which is a variable typically defined in your ``local.conf``
10987file. For example, to enable the
10988``poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly`` package, you
10989could add either the string "commercial_gst-plugins-ugly" or the more
10990general string "commercial" to ``LICENSE_FLAGS_WHITELIST``. See the
10991"`License Flag Matching <#license-flag-matching>`__" section for a full
10992explanation of how ``LICENSE_FLAGS`` matching works. Here is the
10993example:
10994::
10995
10996 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly"
10997
10998Likewise, to additionally enable the package built from the recipe
10999containing ``LICENSE_FLAGS = "license_${PN}_${PV}"``, and assuming that
11000the actual recipe name was ``emgd_1.10.bb``, the following string would
11001enable that package as well as the original ``gst-plugins-ugly``
11002package:
11003::
11004
11005 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly license_emgd_1.10"
11006
11007As a convenience, you do not need to specify the
11008complete license string in the whitelist for every package. You can use
11009an abbreviated form, which consists of just the first portion or
11010portions of the license string before the initial underscore character
11011or characters. A partial string will match any license that contains the
11012given string as the first portion of its license. For example, the
11013following whitelist string will also match both of the packages
11014previously mentioned as well as any other packages that have licenses
11015starting with "commercial" or "license".
11016::
11017
11018 LICENSE_FLAGS_WHITELIST = "commercial license"
11019
11020License Flag Matching
11021~~~~~~~~~~~~~~~~~~~~~
11022
11023License flag matching allows you to control what recipes the
11024OpenEmbedded build system includes in the build. Fundamentally, the
11025build system attempts to match ``LICENSE_FLAGS`` strings found in
11026recipes against ``LICENSE_FLAGS_WHITELIST`` strings found in the
11027whitelist. A match causes the build system to include a recipe in the
11028build, while failure to find a match causes the build system to exclude
11029a recipe.
11030
11031In general, license flag matching is simple. However, understanding some
11032concepts will help you correctly and effectively use matching.
11033
11034Before a flag defined by a particular recipe is tested against the
11035contents of the whitelist, the expanded string ``_${PN}`` is appended to
11036the flag. This expansion makes each ``LICENSE_FLAGS`` value
11037recipe-specific. After expansion, the string is then matched against the
11038whitelist. Thus, specifying ``LICENSE_FLAGS = "commercial"`` in recipe
11039"foo", for example, results in the string ``"commercial_foo"``. And, to
11040create a match, that string must appear in the whitelist.
11041
11042Judicious use of the ``LICENSE_FLAGS`` strings and the contents of the
11043``LICENSE_FLAGS_WHITELIST`` variable allows you a lot of flexibility for
11044including or excluding recipes based on licensing. For example, you can
11045broaden the matching capabilities by using license flags string subsets
11046in the whitelist.
11047
11048.. note::
11049
11050 When using a string subset, be sure to use the part of the expanded
11051 string that precedes the appended underscore character (e.g.
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011052 ``usethispart_1.3``, ``usethispart_1.4``, and so forth).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011053
11054For example, simply specifying the string "commercial" in the whitelist
11055matches any expanded ``LICENSE_FLAGS`` definition that starts with the
11056string "commercial" such as "commercial_foo" and "commercial_bar", which
11057are the strings the build system automatically generates for
11058hypothetical recipes named "foo" and "bar" assuming those recipes simply
11059specify the following:
11060::
11061
11062 LICENSE_FLAGS = "commercial"
11063
11064Thus, you can choose
11065to exhaustively enumerate each license flag in the whitelist and allow
11066only specific recipes into the image, or you can use a string subset
11067that causes a broader range of matches to allow a range of recipes into
11068the image.
11069
11070This scheme works even if the ``LICENSE_FLAGS`` string already has
11071``_${PN}`` appended. For example, the build system turns the license
11072flag "commercial_1.2_foo" into "commercial_1.2_foo_foo" and would match
11073both the general "commercial" and the specific "commercial_1.2_foo"
11074strings found in the whitelist, as expected.
11075
11076Here are some other scenarios:
11077
11078- You can specify a versioned string in the recipe such as
11079 "commercial_foo_1.2" in a "foo" recipe. The build system expands this
11080 string to "commercial_foo_1.2_foo". Combine this license flag with a
11081 whitelist that has the string "commercial" and you match the flag
11082 along with any other flag that starts with the string "commercial".
11083
11084- Under the same circumstances, you can use "commercial_foo" in the
11085 whitelist and the build system not only matches "commercial_foo_1.2"
11086 but also matches any license flag with the string "commercial_foo",
11087 regardless of the version.
11088
11089- You can be very specific and use both the package and version parts
11090 in the whitelist (e.g. "commercial_foo_1.2") to specifically match a
11091 versioned recipe.
11092
11093Other Variables Related to Commercial Licenses
11094~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11095
11096Other helpful variables related to commercial license handling exist and
11097are defined in the
11098``poky/meta/conf/distro/include/default-distrovars.inc`` file:
11099::
11100
11101 COMMERCIAL_AUDIO_PLUGINS ?= ""
11102 COMMERCIAL_VIDEO_PLUGINS ?= ""
11103
11104If you
11105want to enable these components, you can do so by making sure you have
11106statements similar to the following in your ``local.conf`` configuration
11107file:
11108::
11109
11110 COMMERCIAL_AUDIO_PLUGINS = "gst-plugins-ugly-mad \
11111 gst-plugins-ugly-mpegaudioparse"
11112 COMMERCIAL_VIDEO_PLUGINS = "gst-plugins-ugly-mpeg2dec \
11113 gst-plugins-ugly-mpegstream gst-plugins-bad-mpegvideoparse"
11114 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly commercial_gst-plugins-bad commercial_qmmp"
11115
11116
11117Of course, you could also create a matching whitelist for those
11118components using the more general "commercial" in the whitelist, but
11119that would also enable all the other packages with ``LICENSE_FLAGS``
11120containing "commercial", which you may or may not want:
11121::
11122
11123 LICENSE_FLAGS_WHITELIST = "commercial"
11124
11125Specifying audio and video plugins as part of the
11126``COMMERCIAL_AUDIO_PLUGINS`` and ``COMMERCIAL_VIDEO_PLUGINS`` statements
11127(along with the enabling ``LICENSE_FLAGS_WHITELIST``) includes the
11128plugins or components into built images, thus adding support for media
11129formats or components.
11130
11131Maintaining Open Source License Compliance During Your Product's Lifecycle
11132--------------------------------------------------------------------------
11133
11134One of the concerns for a development organization using open source
11135software is how to maintain compliance with various open source
11136licensing during the lifecycle of the product. While this section does
11137not provide legal advice or comprehensively cover all scenarios, it does
11138present methods that you can use to assist you in meeting the compliance
11139requirements during a software release.
11140
11141With hundreds of different open source licenses that the Yocto Project
11142tracks, it is difficult to know the requirements of each and every
11143license. However, the requirements of the major FLOSS licenses can begin
11144to be covered by assuming that three main areas of concern exist:
11145
11146- Source code must be provided.
11147
11148- License text for the software must be provided.
11149
11150- Compilation scripts and modifications to the source code must be
11151 provided.
11152
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011153- spdx files can be provided.
11154
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011155There are other requirements beyond the scope of these three and the
11156methods described in this section (e.g. the mechanism through which
11157source code is distributed).
11158
11159As different organizations have different methods of complying with open
11160source licensing, this section is not meant to imply that there is only
11161one single way to meet your compliance obligations, but rather to
11162describe one method of achieving compliance. The remainder of this
11163section describes methods supported to meet the previously mentioned
11164three requirements. Once you take steps to meet these requirements, and
11165prior to releasing images, sources, and the build system, you should
11166audit all artifacts to ensure completeness.
11167
11168.. note::
11169
11170 The Yocto Project generates a license manifest during image creation
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011171 that is located in ``${DEPLOY_DIR}/licenses/``\ `image_name`\ ``-``\ `datestamp`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011172 to assist with any audits.
11173
11174Providing the Source Code
11175~~~~~~~~~~~~~~~~~~~~~~~~~
11176
11177Compliance activities should begin before you generate the final image.
11178The first thing you should look at is the requirement that tops the list
11179for most compliance groups - providing the source. The Yocto Project has
11180a few ways of meeting this requirement.
11181
11182One of the easiest ways to meet this requirement is to provide the
11183entire :term:`DL_DIR` used by the
11184build. This method, however, has a few issues. The most obvious is the
11185size of the directory since it includes all sources used in the build
11186and not just the source used in the released image. It will include
11187toolchain source, and other artifacts, which you would not generally
11188release. However, the more serious issue for most companies is
11189accidental release of proprietary software. The Yocto Project provides
11190an :ref:`archiver <ref-classes-archiver>` class to
11191help avoid some of these concerns.
11192
11193Before you employ ``DL_DIR`` or the ``archiver`` class, you need to
11194decide how you choose to provide source. The source ``archiver`` class
11195can generate tarballs and SRPMs and can create them with various levels
11196of compliance in mind.
11197
11198One way of doing this (but certainly not the only way) is to release
11199just the source as a tarball. You can do this by adding the following to
11200the ``local.conf`` file found in the
11201:term:`Build Directory`:
11202::
11203
11204 INHERIT += "archiver"
11205 ARCHIVER_MODE[src] = "original"
11206
11207During the creation of your
11208image, the source from all recipes that deploy packages to the image is
11209placed within subdirectories of ``DEPLOY_DIR/sources`` based on the
11210:term:`LICENSE` for each recipe.
11211Releasing the entire directory enables you to comply with requirements
11212concerning providing the unmodified source. It is important to note that
11213the size of the directory can get large.
11214
11215A way to help mitigate the size issue is to only release tarballs for
11216licenses that require the release of source. Let us assume you are only
11217concerned with GPL code as identified by running the following script:
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011218
11219.. code-block:: shell
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011220
11221 # Script to archive a subset of packages matching specific license(s)
11222 # Source and license files are copied into sub folders of package folder
11223 # Must be run from build folder
11224 #!/bin/bash
11225 src_release_dir="source-release"
11226 mkdir -p $src_release_dir
11227 for a in tmp/deploy/sources/*; do
11228 for d in $a/*; do
11229 # Get package name from path
11230 p=`basename $d`
11231 p=${p%-*}
11232 p=${p%-*}
11233 # Only archive GPL packages (update *GPL* regex for your license check)
11234 numfiles=`ls tmp/deploy/licenses/$p/*GPL* 2> /dev/null | wc -l`
11235 if [ $numfiles -gt 1 ]; then
11236 echo Archiving $p
11237 mkdir -p $src_release_dir/$p/source
11238 cp $d/* $src_release_dir/$p/source 2> /dev/null
11239 mkdir -p $src_release_dir/$p/license
11240 cp tmp/deploy/licenses/$p/* $src_release_dir/$p/license 2> /dev/null
11241 fi
11242 done
11243 done
11244
11245At this point, you
11246could create a tarball from the ``gpl_source_release`` directory and
11247provide that to the end user. This method would be a step toward
11248achieving compliance with section 3a of GPLv2 and with section 6 of
11249GPLv3.
11250
11251Providing License Text
11252~~~~~~~~~~~~~~~~~~~~~~
11253
11254One requirement that is often overlooked is inclusion of license text.
11255This requirement also needs to be dealt with prior to generating the
11256final image. Some licenses require the license text to accompany the
11257binary. You can achieve this by adding the following to your
11258``local.conf`` file:
11259::
11260
11261 COPY_LIC_MANIFEST = "1"
11262 COPY_LIC_DIRS = "1"
11263 LICENSE_CREATE_PACKAGE = "1"
11264
11265Adding these statements to the
11266configuration file ensures that the licenses collected during package
11267generation are included on your image.
11268
11269.. note::
11270
11271 Setting all three variables to "1" results in the image having two
11272 copies of the same license file. One copy resides in
11273 ``/usr/share/common-licenses`` and the other resides in
11274 ``/usr/share/license``.
11275
11276 The reason for this behavior is because
11277 :term:`COPY_LIC_DIRS` and
11278 :term:`COPY_LIC_MANIFEST`
11279 add a copy of the license when the image is built but do not offer a
11280 path for adding licenses for newly installed packages to an image.
11281 :term:`LICENSE_CREATE_PACKAGE`
11282 adds a separate package and an upgrade path for adding licenses to an
11283 image.
11284
11285As the source ``archiver`` class has already archived the original
11286unmodified source that contains the license files, you would have
11287already met the requirements for inclusion of the license information
11288with source as defined by the GPL and other open source licenses.
11289
11290Providing Compilation Scripts and Source Code Modifications
11291~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11292
11293At this point, we have addressed all we need to prior to generating the
11294image. The next two requirements are addressed during the final
11295packaging of the release.
11296
11297By releasing the version of the OpenEmbedded build system and the layers
11298used during the build, you will be providing both compilation scripts
11299and the source code modifications in one step.
11300
Andrew Geissler09209ee2020-12-13 08:44:15 -060011301If the deployment team has a :ref:`overview-manual/concepts:bsp layer`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011302and a distro layer, and those
11303those layers are used to patch, compile, package, or modify (in any way)
11304any open source software included in your released images, you might be
11305required to release those layers under section 3 of GPLv2 or section 1
11306of GPLv3. One way of doing that is with a clean checkout of the version
11307of the Yocto Project and layers used during your build. Here is an
11308example:
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011309
11310.. code-block:: shell
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011311
11312 # We built using the dunfell branch of the poky repo
11313 $ git clone -b dunfell git://git.yoctoproject.org/poky
11314 $ cd poky
11315 # We built using the release_branch for our layers
11316 $ git clone -b release_branch git://git.mycompany.com/meta-my-bsp-layer
11317 $ git clone -b release_branch git://git.mycompany.com/meta-my-software-layer
11318 # clean up the .git repos
11319 $ find . -name ".git" -type d -exec rm -rf {} \;
11320
11321One
11322thing a development organization might want to consider for end-user
11323convenience is to modify ``meta-poky/conf/bblayers.conf.sample`` to
11324ensure that when the end user utilizes the released build system to
11325build an image, the development organization's layers are included in
11326the ``bblayers.conf`` file automatically:
11327::
11328
11329 # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
11330 # changes incompatibly
11331 POKY_BBLAYERS_CONF_VERSION = "2"
11332
11333 BBPATH = "${TOPDIR}"
11334 BBFILES ?= ""
11335
11336 BBLAYERS ?= " \
11337 ##OEROOT##/meta \
11338 ##OEROOT##/meta-poky \
11339 ##OEROOT##/meta-yocto-bsp \
11340 ##OEROOT##/meta-mylayer \
11341 "
11342
11343Creating and
11344providing an archive of the :term:`Metadata`
11345layers (recipes, configuration files, and so forth) enables you to meet
11346your requirements to include the scripts to control compilation as well
11347as any modifications to the original source.
11348
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011349Providing spdx files
11350~~~~~~~~~~~~~~~~~~~~~~~~~
11351
11352The spdx module has been integrated to a layer named meta-spdxscanner.
11353meta-spdxscanner provides several kinds of scanner. If you want to enable
11354this function, you have to follow the following steps:
11355
113561. Add meta-spdxscanner layer into ``bblayers.conf``.
11357
113582. Refer to the README in meta-spdxscanner to setup the environment (e.g,
11359 setup a fossology server) needed for the scanner.
11360
113613. Meta-spdxscanner provides several methods within the bbclass to create spdx files.
11362 Please choose one that you want to use and enable the spdx task. You have to
11363 add some config options in ``local.conf`` file in your :term:`Build
11364 Directory`. The following is an example showing how to generate spdx files
11365 during bitbake using the fossology-python.bbclass::
11366
11367 # Select fossology-python.bbclass.
11368 INHERIT += "fossology-python"
11369 # For fossology-python.bbclass, TOKEN is necessary, so, after setup a
11370 # Fossology server, you have to create a token.
11371 TOKEN = "eyJ0eXAiO..."
11372 # The fossology server is necessary for fossology-python.bbclass.
11373 FOSSOLOGY_SERVER = "http://xx.xx.xx.xx:8081/repo"
11374 # If you want to upload the source code to a special folder:
11375 FOLDER_NAME = "xxxx" //Optional
11376 # If you don't want to put spdx files in tmp/deploy/spdx, you can enable:
11377 SPDX_DEPLOY_DIR = "${DEPLOY_DIR}" //Optional
11378
11379For more usage information refer to :yocto_git:`the meta-spdxscanner repository
Andrew Geissler09209ee2020-12-13 08:44:15 -060011380</meta-spdxscanner/>`.
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011381
11382
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011383Copying Licenses that Do Not Exist
11384----------------------------------
11385
11386Some packages, such as the linux-firmware package, have many licenses
11387that are not in any way common. You can avoid adding a lot of these
11388types of common license files, which are only applicable to a specific
11389package, by using the
11390:term:`NO_GENERIC_LICENSE`
11391variable. Using this variable also avoids QA errors when you use a
11392non-common, non-CLOSED license in a recipe.
11393
11394The following is an example that uses the ``LICENSE.Abilis.txt`` file as
11395the license from the fetched source:
11396::
11397
11398 NO_GENERIC_LICENSE[Firmware-Abilis] = "LICENSE.Abilis.txt"
11399
11400Using the Error Reporting Tool
11401==============================
11402
11403The error reporting tool allows you to submit errors encountered during
11404builds to a central database. Outside of the build environment, you can
11405use a web interface to browse errors, view statistics, and query for
11406errors. The tool works using a client-server system where the client
11407portion is integrated with the installed Yocto Project
11408:term:`Source Directory` (e.g. ``poky``).
11409The server receives the information collected and saves it in a
11410database.
11411
11412A live instance of the error reporting server exists at
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011413https://errors.yoctoproject.org. This server exists so that when
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011414you want to get help with build failures, you can submit all of the
11415information on the failure easily and then point to the URL in your bug
11416report or send an email to the mailing list.
11417
11418.. note::
11419
11420 If you send error reports to this server, the reports become publicly
11421 visible.
11422
11423Enabling and Using the Tool
11424---------------------------
11425
11426By default, the error reporting tool is disabled. You can enable it by
11427inheriting the
11428:ref:`report-error <ref-classes-report-error>`
11429class by adding the following statement to the end of your
11430``local.conf`` file in your
11431:term:`Build Directory`.
11432::
11433
11434 INHERIT += "report-error"
11435
11436By default, the error reporting feature stores information in
11437``${``\ :term:`LOG_DIR`\ ``}/error-report``.
11438However, you can specify a directory to use by adding the following to
11439your ``local.conf`` file:
11440::
11441
11442 ERR_REPORT_DIR = "path"
11443
11444Enabling error
11445reporting causes the build process to collect the errors and store them
11446in a file as previously described. When the build system encounters an
11447error, it includes a command as part of the console output. You can run
11448the command to send the error file to the server. For example, the
11449following command sends the errors to an upstream server:
11450::
11451
11452 $ send-error-report /home/brandusa/project/poky/build/tmp/log/error-report/error_report_201403141617.txt
11453
11454In the previous example, the errors are sent to a public database
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011455available at https://errors.yoctoproject.org, which is used by the
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011456entire community. If you specify a particular server, you can send the
11457errors to a different database. Use the following command for more
11458information on available options:
11459::
11460
11461 $ send-error-report --help
11462
11463When sending the error file, you are prompted to review the data being
11464sent as well as to provide a name and optional email address. Once you
11465satisfy these prompts, the command returns a link from the server that
11466corresponds to your entry in the database. For example, here is a
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011467typical link: https://errors.yoctoproject.org/Errors/Details/9522/
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011468
11469Following the link takes you to a web interface where you can browse,
11470query the errors, and view statistics.
11471
11472Disabling the Tool
11473------------------
11474
11475To disable the error reporting feature, simply remove or comment out the
11476following statement from the end of your ``local.conf`` file in your
11477:term:`Build Directory`.
11478::
11479
11480 INHERIT += "report-error"
11481
11482Setting Up Your Own Error Reporting Server
11483------------------------------------------
11484
11485If you want to set up your own error reporting server, you can obtain
Andrew Geissler09209ee2020-12-13 08:44:15 -060011486the code from the Git repository at :yocto_git:`/error-report-web/`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011487Instructions on how to set it up are in the README document.
11488
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011489Using Wayland and Weston
11490========================
11491
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011492`Wayland <https://en.wikipedia.org/wiki/Wayland_(display_server_protocol)>`__
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011493is a computer display server protocol that provides a method for
11494compositing window managers to communicate directly with applications
11495and video hardware and expects them to communicate with input hardware
11496using other libraries. Using Wayland with supporting targets can result
11497in better control over graphics frame rendering than an application
11498might otherwise achieve.
11499
11500The Yocto Project provides the Wayland protocol libraries and the
11501reference
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011502`Weston <https://en.wikipedia.org/wiki/Wayland_(display_server_protocol)#Weston>`__
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011503compositor as part of its release. You can find the integrated packages
11504in the ``meta`` layer of the :term:`Source Directory`.
11505Specifically, you
11506can find the recipes that build both Wayland and Weston at
11507``meta/recipes-graphics/wayland``.
11508
11509You can build both the Wayland and Weston packages for use only with
11510targets that accept the `Mesa 3D and Direct Rendering
11511Infrastructure <https://en.wikipedia.org/wiki/Mesa_(computer_graphics)>`__,
11512which is also known as Mesa DRI. This implies that you cannot build and
11513use the packages if your target uses, for example, the Intel Embedded
11514Media and Graphics Driver (Intel EMGD) that overrides Mesa DRI.
11515
11516.. note::
11517
11518 Due to lack of EGL support, Weston 1.0.3 will not run directly on the
11519 emulated QEMU hardware. However, this version of Weston will run
11520 under X emulation without issues.
11521
11522This section describes what you need to do to implement Wayland and use
11523the Weston compositor when building an image for a supporting target.
11524
11525Enabling Wayland in an Image
11526----------------------------
11527
11528To enable Wayland, you need to enable it to be built and enable it to be
11529included (installed) in the image.
11530
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011531Building Wayland
11532~~~~~~~~~~~~~~~~
11533
11534To cause Mesa to build the ``wayland-egl`` platform and Weston to build
11535Wayland with Kernel Mode Setting
11536(`KMS <https://wiki.archlinux.org/index.php/Kernel_Mode_Setting>`__)
11537support, include the "wayland" flag in the
11538:term:`DISTRO_FEATURES`
11539statement in your ``local.conf`` file:
11540::
11541
11542 DISTRO_FEATURES_append = " wayland"
11543
11544.. note::
11545
11546 If X11 has been enabled elsewhere, Weston will build Wayland with X11
11547 support
11548
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011549Installing Wayland and Weston
11550~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11551
11552To install the Wayland feature into an image, you must include the
11553following
11554:term:`CORE_IMAGE_EXTRA_INSTALL`
11555statement in your ``local.conf`` file:
11556::
11557
11558 CORE_IMAGE_EXTRA_INSTALL += "wayland weston"
11559
11560Running Weston
11561--------------
11562
11563To run Weston inside X11, enabling it as described earlier and building
11564a Sato image is sufficient. If you are running your image under Sato, a
11565Weston Launcher appears in the "Utility" category.
11566
11567Alternatively, you can run Weston through the command-line interpretor
11568(CLI), which is better suited for development work. To run Weston under
11569the CLI, you need to do the following after your image is built:
11570
115711. Run these commands to export ``XDG_RUNTIME_DIR``:
11572 ::
11573
11574 mkdir -p /tmp/$USER-weston
11575 chmod 0700 /tmp/$USER-weston
11576 export XDG_RUNTIME_DIR=/tmp/$USER-weston
11577
115782. Launch Weston in the shell:
11579 ::
11580
11581 weston