blob: 37c7a19bfa6a8d6c302fca04288a552fedb06d0f [file] [log] [blame]
Andrew Geisslerf0343792020-11-18 10:42:21 -06001.. SPDX-License-Identifier: CC-BY-SA-2.0-UK
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002
3************
4Common Tasks
5************
6
7This chapter describes fundamental procedures such as creating layers,
8adding new software packages, extending or customizing images, porting
9work to new hardware (adding a new machine), and so forth. You will find
10that the procedures documented here occur often in the development cycle
11using the Yocto Project.
12
13Understanding and Creating Layers
14=================================
15
16The OpenEmbedded build system supports organizing
17:term:`Metadata` into multiple layers.
18Layers allow you to isolate different types of customizations from each
19other. For introductory information on the Yocto Project Layer Model,
20see the
Andrew Geissler09209ee2020-12-13 08:44:15 -060021":ref:`overview-manual/yp-intro:the yocto project layer model`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050022section in the Yocto Project Overview and Concepts Manual.
23
24Creating Your Own Layer
25-----------------------
26
27It is very easy to create your own layers to use with the OpenEmbedded
28build system. The Yocto Project ships with tools that speed up creating
29layers. This section describes the steps you perform by hand to create
30layers so that you can better understand them. For information about the
31layer-creation tools, see the
32":ref:`bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script`"
33section in the Yocto Project Board Support Package (BSP) Developer's
Andrew Geissler09209ee2020-12-13 08:44:15 -060034Guide and the ":ref:`dev-manual/common-tasks:creating a general layer using the \`\`bitbake-layers\`\` script`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050035section further down in this manual.
36
37Follow these general steps to create your layer without using tools:
38
391. *Check Existing Layers:* Before creating a new layer, you should be
40 sure someone has not already created a layer containing the Metadata
Andrew Geisslerd1e89492021-02-12 15:35:20 -060041 you need. You can see the :oe_layerindex:`OpenEmbedded Metadata Index <>`
42 for a list of layers from the OpenEmbedded community that can be used in
Andrew Geisslerc9f78652020-09-18 14:11:35 -050043 the Yocto Project. You could find a layer that is identical or close
44 to what you need.
45
462. *Create a Directory:* Create the directory for your layer. When you
47 create the layer, be sure to create the directory in an area not
48 associated with the Yocto Project :term:`Source Directory`
49 (e.g. the cloned ``poky`` repository).
50
51 While not strictly required, prepend the name of the directory with
Andrew Geisslerc926e172021-05-07 16:11:35 -050052 the string "meta-". For example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050053
54 meta-mylayer
55 meta-GUI_xyz
56 meta-mymachine
57
Andrew Geisslerc926e172021-05-07 16:11:35 -050058 With rare exceptions, a layer's name follows this form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050059
60 meta-root_name
61
62 Following this layer naming convention can save
63 you trouble later when tools, components, or variables "assume" your
64 layer name begins with "meta-". A notable example is in configuration
65 files as shown in the following step where layer names without the
66 "meta-" string are appended to several variables used in the
67 configuration.
68
693. *Create a Layer Configuration File:* Inside your new layer folder,
70 you need to create a ``conf/layer.conf`` file. It is easiest to take
71 an existing layer configuration file and copy that to your layer's
72 ``conf`` directory and then modify the file as needed.
73
74 The ``meta-yocto-bsp/conf/layer.conf`` file in the Yocto Project
Andrew Geissler09209ee2020-12-13 08:44:15 -060075 :yocto_git:`Source Repositories </poky/tree/meta-yocto-bsp/conf>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050076 demonstrates the required syntax. For your layer, you need to replace
77 "yoctobsp" with a unique identifier for your layer (e.g. "machinexyz"
Andrew Geisslerc926e172021-05-07 16:11:35 -050078 for a layer named "meta-machinexyz")::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050079
80 # We have a conf and classes directory, add to BBPATH
81 BBPATH .= ":${LAYERDIR}"
82
Andrew Geissler4c19ea12020-10-27 13:52:24 -050083 # We have recipes-* directories, add to BBFILES
Andrew Geisslerc9f78652020-09-18 14:11:35 -050084 BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
85 ${LAYERDIR}/recipes-*/*/*.bbappend"
86
87 BBFILE_COLLECTIONS += "yoctobsp"
88 BBFILE_PATTERN_yoctobsp = "^${LAYERDIR}/"
89 BBFILE_PRIORITY_yoctobsp = "5"
90 LAYERVERSION_yoctobsp = "4"
91 LAYERSERIES_COMPAT_yoctobsp = "dunfell"
92
93 Following is an explanation of the layer configuration file:
94
95 - :term:`BBPATH`: Adds the layer's
96 root directory to BitBake's search path. Through the use of the
97 ``BBPATH`` variable, BitBake locates class files (``.bbclass``),
98 configuration files, and files that are included with ``include``
99 and ``require`` statements. For these cases, BitBake uses the
100 first file that matches the name found in ``BBPATH``. This is
101 similar to the way the ``PATH`` variable is used for binaries. It
102 is recommended, therefore, that you use unique class and
103 configuration filenames in your custom layer.
104
105 - :term:`BBFILES`: Defines the
106 location for all recipes in the layer.
107
108 - :term:`BBFILE_COLLECTIONS`:
109 Establishes the current layer through a unique identifier that is
110 used throughout the OpenEmbedded build system to refer to the
111 layer. In this example, the identifier "yoctobsp" is the
112 representation for the container layer named "meta-yocto-bsp".
113
114 - :term:`BBFILE_PATTERN`:
115 Expands immediately during parsing to provide the directory of the
116 layer.
117
118 - :term:`BBFILE_PRIORITY`:
119 Establishes a priority to use for recipes in the layer when the
120 OpenEmbedded build finds recipes of the same name in different
121 layers.
122
123 - :term:`LAYERVERSION`:
124 Establishes a version number for the layer. You can use this
125 version number to specify this exact version of the layer as a
126 dependency when using the
127 :term:`LAYERDEPENDS`
128 variable.
129
130 - :term:`LAYERDEPENDS`:
131 Lists all layers on which this layer depends (if any).
132
133 - :term:`LAYERSERIES_COMPAT`:
Andrew Geissler09209ee2020-12-13 08:44:15 -0600134 Lists the :yocto_wiki:`Yocto Project </Releases>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500135 releases for which the current version is compatible. This
136 variable is a good way to indicate if your particular layer is
137 current.
138
1394. *Add Content:* Depending on the type of layer, add the content. If
140 the layer adds support for a machine, add the machine configuration
141 in a ``conf/machine/`` file within the layer. If the layer adds
142 distro policy, add the distro configuration in a ``conf/distro/``
143 file within the layer. If the layer introduces new recipes, put the
144 recipes you need in ``recipes-*`` subdirectories within the layer.
145
146 .. note::
147
148 For an explanation of layer hierarchy that is compliant with the
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500149 Yocto Project, see the ":ref:`bsp-guide/bsp:example filesystem layout`"
150 section in the Yocto Project Board Support Package (BSP) Developer's Guide.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500151
1525. *Optionally Test for Compatibility:* If you want permission to use
153 the Yocto Project Compatibility logo with your layer or application
154 that uses your layer, perform the steps to apply for compatibility.
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500155 See the
156 ":ref:`dev-manual/common-tasks:making sure your layer is compatible with yocto project`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500157 section for more information.
158
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500159Following Best Practices When Creating Layers
160---------------------------------------------
161
162To create layers that are easier to maintain and that will not impact
163builds for other machines, you should consider the information in the
164following list:
165
166- *Avoid "Overlaying" Entire Recipes from Other Layers in Your
167 Configuration:* In other words, do not copy an entire recipe into
168 your layer and then modify it. Rather, use an append file
169 (``.bbappend``) to override only those parts of the original recipe
170 you need to modify.
171
172- *Avoid Duplicating Include Files:* Use append files (``.bbappend``)
173 for each recipe that uses an include file. Or, if you are introducing
174 a new recipe that requires the included file, use the path relative
175 to the original layer directory to refer to the file. For example,
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500176 use ``require recipes-core/``\ `package`\ ``/``\ `file`\ ``.inc`` instead
177 of ``require`` `file`\ ``.inc``. If you're finding you have to overlay
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500178 the include file, it could indicate a deficiency in the include file
179 in the layer to which it originally belongs. If this is the case, you
180 should try to address that deficiency instead of overlaying the
181 include file. For example, you could address this by getting the
182 maintainer of the include file to add a variable or variables to make
183 it easy to override the parts needing to be overridden.
184
185- *Structure Your Layers:* Proper use of overrides within append files
186 and placement of machine-specific files within your layer can ensure
187 that a build is not using the wrong Metadata and negatively impacting
188 a build for a different machine. Following are some examples:
189
190 - *Modify Variables to Support a Different Machine:* Suppose you
191 have a layer named ``meta-one`` that adds support for building
192 machine "one". To do so, you use an append file named
193 ``base-files.bbappend`` and create a dependency on "foo" by
194 altering the :term:`DEPENDS`
Andrew Geisslerc926e172021-05-07 16:11:35 -0500195 variable::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500196
197 DEPENDS = "foo"
198
199 The dependency is created during any
200 build that includes the layer ``meta-one``. However, you might not
201 want this dependency for all machines. For example, suppose you
202 are building for machine "two" but your ``bblayers.conf`` file has
203 the ``meta-one`` layer included. During the build, the
204 ``base-files`` for machine "two" will also have the dependency on
205 ``foo``.
206
207 To make sure your changes apply only when building machine "one",
Andrew Geisslerc926e172021-05-07 16:11:35 -0500208 use a machine override with the ``DEPENDS`` statement::
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500209
210 DEPENDS_one = "foo"
211
212 You should follow the same strategy when using ``_append``
Andrew Geisslerc926e172021-05-07 16:11:35 -0500213 and ``_prepend`` operations::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500214
215 DEPENDS_append_one = " foo"
216 DEPENDS_prepend_one = "foo "
217
218 As an actual example, here's a
219 snippet from the generic kernel include file ``linux-yocto.inc``,
220 wherein the kernel compile and link options are adjusted in the
Andrew Geisslerc926e172021-05-07 16:11:35 -0500221 case of a subset of the supported architectures::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500222
223 DEPENDS_append_aarch64 = " libgcc"
224 KERNEL_CC_append_aarch64 = " ${TOOLCHAIN_OPTIONS}"
225 KERNEL_LD_append_aarch64 = " ${TOOLCHAIN_OPTIONS}"
226
227 DEPENDS_append_nios2 = " libgcc"
228 KERNEL_CC_append_nios2 = " ${TOOLCHAIN_OPTIONS}"
229 KERNEL_LD_append_nios2 = " ${TOOLCHAIN_OPTIONS}"
230
231 DEPENDS_append_arc = " libgcc"
232 KERNEL_CC_append_arc = " ${TOOLCHAIN_OPTIONS}"
233 KERNEL_LD_append_arc = " ${TOOLCHAIN_OPTIONS}"
234
235 KERNEL_FEATURES_append_qemuall=" features/debug/printk.scc"
236
237 .. note::
238
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500239 Avoiding "+=" and "=+" and using machine-specific ``_append``
240 and ``_prepend`` operations is recommended as well.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500241
242 - *Place Machine-Specific Files in Machine-Specific Locations:* When
243 you have a base recipe, such as ``base-files.bb``, that contains a
244 :term:`SRC_URI` statement to a
245 file, you can use an append file to cause the build to use your
246 own version of the file. For example, an append file in your layer
247 at ``meta-one/recipes-core/base-files/base-files.bbappend`` could
Andrew Geisslerc926e172021-05-07 16:11:35 -0500248 extend :term:`FILESPATH` using :term:`FILESEXTRAPATHS` as follows::
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500249
250 FILESEXTRAPATHS_prepend := "${THISDIR}/${BPN}:"
251
252 The build for machine "one" will pick up your machine-specific file as
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500253 long as you have the file in
254 ``meta-one/recipes-core/base-files/base-files/``. However, if you
255 are building for a different machine and the ``bblayers.conf``
256 file includes the ``meta-one`` layer and the location of your
257 machine-specific file is the first location where that file is
258 found according to ``FILESPATH``, builds for all machines will
259 also use that machine-specific file.
260
261 You can make sure that a machine-specific file is used for a
262 particular machine by putting the file in a subdirectory specific
263 to the machine. For example, rather than placing the file in
264 ``meta-one/recipes-core/base-files/base-files/`` as shown above,
265 put it in ``meta-one/recipes-core/base-files/base-files/one/``.
266 Not only does this make sure the file is used only when building
267 for machine "one", but the build process locates the file more
268 quickly.
269
270 In summary, you need to place all files referenced from
271 ``SRC_URI`` in a machine-specific subdirectory within the layer in
272 order to restrict those files to machine-specific builds.
273
274- *Perform Steps to Apply for Yocto Project Compatibility:* If you want
275 permission to use the Yocto Project Compatibility logo with your
276 layer or application that uses your layer, perform the steps to apply
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500277 for compatibility. See the
278 ":ref:`dev-manual/common-tasks:making sure your layer is compatible with yocto project`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500279 section for more information.
280
281- *Follow the Layer Naming Convention:* Store custom layers in a Git
282 repository that use the ``meta-layer_name`` format.
283
284- *Group Your Layers Locally:* Clone your repository alongside other
285 cloned ``meta`` directories from the :term:`Source Directory`.
286
287Making Sure Your Layer is Compatible With Yocto Project
288-------------------------------------------------------
289
290When you create a layer used with the Yocto Project, it is advantageous
291to make sure that the layer interacts well with existing Yocto Project
292layers (i.e. the layer is compatible with the Yocto Project). Ensuring
293compatibility makes the layer easy to be consumed by others in the Yocto
294Project community and could allow you permission to use the Yocto
295Project Compatible Logo.
296
297.. note::
298
299 Only Yocto Project member organizations are permitted to use the
300 Yocto Project Compatible Logo. The logo is not available for general
301 use. For information on how to become a Yocto Project member
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500302 organization, see the :yocto_home:`Yocto Project Website <>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500303
304The Yocto Project Compatibility Program consists of a layer application
305process that requests permission to use the Yocto Project Compatibility
306Logo for your layer and application. The process consists of two parts:
307
3081. Successfully passing a script (``yocto-check-layer``) that when run
309 against your layer, tests it against constraints based on experiences
310 of how layers have worked in the real world and where pitfalls have
311 been found. Getting a "PASS" result from the script is required for
312 successful compatibility registration.
313
3142. Completion of an application acceptance form, which you can find at
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600315 :yocto_home:`/webform/yocto-project-compatible-registration`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500316
317To be granted permission to use the logo, you need to satisfy the
318following:
319
320- Be able to check the box indicating that you got a "PASS" when
321 running the script against your layer.
322
323- Answer "Yes" to the questions on the form or have an acceptable
324 explanation for any questions answered "No".
325
326- Be a Yocto Project Member Organization.
327
328The remainder of this section presents information on the registration
329form and on the ``yocto-check-layer`` script.
330
331Yocto Project Compatible Program Application
332~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
333
334Use the form to apply for your layer's approval. Upon successful
335application, you can use the Yocto Project Compatibility Logo with your
336layer and the application that uses your layer.
337
338To access the form, use this link:
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600339:yocto_home:`/webform/yocto-project-compatible-registration`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500340Follow the instructions on the form to complete your application.
341
342The application consists of the following sections:
343
344- *Contact Information:* Provide your contact information as the fields
345 require. Along with your information, provide the released versions
346 of the Yocto Project for which your layer is compatible.
347
348- *Acceptance Criteria:* Provide "Yes" or "No" answers for each of the
349 items in the checklist. Space exists at the bottom of the form for
350 any explanations for items for which you answered "No".
351
352- *Recommendations:* Provide answers for the questions regarding Linux
353 kernel use and build success.
354
355``yocto-check-layer`` Script
356~~~~~~~~~~~~~~~~~~~~~~~~~~~~
357
358The ``yocto-check-layer`` script provides you a way to assess how
359compatible your layer is with the Yocto Project. You should run this
360script prior to using the form to apply for compatibility as described
361in the previous section. You need to achieve a "PASS" result in order to
362have your application form successfully processed.
363
364The script divides tests into three areas: COMMON, BSP, and DISTRO. For
365example, given a distribution layer (DISTRO), the layer must pass both
366the COMMON and DISTRO related tests. Furthermore, if your layer is a BSP
367layer, the layer must pass the COMMON and BSP set of tests.
368
369To execute the script, enter the following commands from your build
Andrew Geisslerc926e172021-05-07 16:11:35 -0500370directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500371
372 $ source oe-init-build-env
373 $ yocto-check-layer your_layer_directory
374
375Be sure to provide the actual directory for your
376layer as part of the command.
377
378Entering the command causes the script to determine the type of layer
379and then to execute a set of specific tests against the layer. The
380following list overviews the test:
381
382- ``common.test_readme``: Tests if a ``README`` file exists in the
383 layer and the file is not empty.
384
385- ``common.test_parse``: Tests to make sure that BitBake can parse the
386 files without error (i.e. ``bitbake -p``).
387
388- ``common.test_show_environment``: Tests that the global or per-recipe
389 environment is in order without errors (i.e. ``bitbake -e``).
390
391- ``common.test_world``: Verifies that ``bitbake world`` works.
392
393- ``common.test_signatures``: Tests to be sure that BSP and DISTRO
394 layers do not come with recipes that change signatures.
395
396- ``common.test_layerseries_compat``: Verifies layer compatibility is
397 set properly.
398
399- ``bsp.test_bsp_defines_machines``: Tests if a BSP layer has machine
400 configurations.
401
402- ``bsp.test_bsp_no_set_machine``: Tests to ensure a BSP layer does not
403 set the machine when the layer is added.
404
405- ``bsp.test_machine_world``: Verifies that ``bitbake world`` works
406 regardless of which machine is selected.
407
408- ``bsp.test_machine_signatures``: Verifies that building for a
409 particular machine affects only the signature of tasks specific to
410 that machine.
411
412- ``distro.test_distro_defines_distros``: Tests if a DISTRO layer has
413 distro configurations.
414
415- ``distro.test_distro_no_set_distros``: Tests to ensure a DISTRO layer
416 does not set the distribution when the layer is added.
417
418Enabling Your Layer
419-------------------
420
421Before the OpenEmbedded build system can use your new layer, you need to
422enable it. To enable your layer, simply add your layer's path to the
423``BBLAYERS`` variable in your ``conf/bblayers.conf`` file, which is
424found in the :term:`Build Directory`.
425The following example shows how to enable a layer named
Andrew Geisslerc926e172021-05-07 16:11:35 -0500426``meta-mylayer``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500427
428 # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
429 # changes incompatibly
430 POKY_BBLAYERS_CONF_VERSION = "2"
431 BBPATH = "${TOPDIR}"
432 BBFILES ?= ""
433 BBLAYERS ?= " \
434 /home/user/poky/meta \
435 /home/user/poky/meta-poky \
436 /home/user/poky/meta-yocto-bsp \
437 /home/user/poky/meta-mylayer \
438 "
439
440BitBake parses each ``conf/layer.conf`` file from the top down as
441specified in the ``BBLAYERS`` variable within the ``conf/bblayers.conf``
442file. During the processing of each ``conf/layer.conf`` file, BitBake
443adds the recipes, classes and configurations contained within the
444particular layer to the source directory.
445
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500446Using .bbappend Files in Your Layer
447-----------------------------------
448
449A recipe that appends Metadata to another recipe is called a BitBake
450append file. A BitBake append file uses the ``.bbappend`` file type
451suffix, while the corresponding recipe to which Metadata is being
452appended uses the ``.bb`` file type suffix.
453
454You can use a ``.bbappend`` file in your layer to make additions or
455changes to the content of another layer's recipe without having to copy
456the other layer's recipe into your layer. Your ``.bbappend`` file
457resides in your layer, while the main ``.bb`` recipe file to which you
458are appending Metadata resides in a different layer.
459
460Being able to append information to an existing recipe not only avoids
461duplication, but also automatically applies recipe changes from a
462different layer into your layer. If you were copying recipes, you would
463have to manually merge changes as they occur.
464
465When you create an append file, you must use the same root name as the
466corresponding recipe file. For example, the append file
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500467``someapp_3.1.bbappend`` must apply to ``someapp_3.1.bb``. This
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500468means the original recipe and append file names are version
469number-specific. If the corresponding recipe is renamed to update to a
470newer version, you must also rename and possibly update the
471corresponding ``.bbappend`` as well. During the build process, BitBake
472displays an error on starting if it detects a ``.bbappend`` file that
473does not have a corresponding recipe with a matching name. See the
474:term:`BB_DANGLINGAPPENDS_WARNONLY`
475variable for information on how to handle this error.
476
477As an example, consider the main formfactor recipe and a corresponding
478formfactor append file both from the :term:`Source Directory`.
479Here is the main
480formfactor recipe, which is named ``formfactor_0.0.bb`` and located in
Andrew Geisslerc926e172021-05-07 16:11:35 -0500481the "meta" layer at ``meta/recipes-bsp/formfactor``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500482
483 SUMMARY = "Device formfactor information"
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500484 DESCRIPTION = "A formfactor configuration file provides information about the \
485 target hardware for which the image is being built and information that the \
486 build system cannot obtain from other sources such as the kernel."
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500487 SECTION = "base"
488 LICENSE = "MIT"
489 LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
490 PR = "r45"
491
492 SRC_URI = "file://config file://machconfig"
493 S = "${WORKDIR}"
494
495 PACKAGE_ARCH = "${MACHINE_ARCH}"
496 INHIBIT_DEFAULT_DEPS = "1"
497
498 do_install() {
499 # Install file only if it has contents
500 install -d ${D}${sysconfdir}/formfactor/
501 install -m 0644 ${S}/config ${D}${sysconfdir}/formfactor/
502 if [ -s "${S}/machconfig" ]; then
503 install -m 0644 ${S}/machconfig ${D}${sysconfdir}/formfactor/
504 fi
505 }
506
507In the main recipe, note the :term:`SRC_URI`
508variable, which tells the OpenEmbedded build system where to find files
509during the build.
510
511Following is the append file, which is named ``formfactor_0.0.bbappend``
512and is from the Raspberry Pi BSP Layer named ``meta-raspberrypi``. The
Andrew Geisslerc926e172021-05-07 16:11:35 -0500513file is in the layer at ``recipes-bsp/formfactor``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500514
515 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
516
517By default, the build system uses the
518:term:`FILESPATH` variable to
519locate files. This append file extends the locations by setting the
520:term:`FILESEXTRAPATHS`
521variable. Setting this variable in the ``.bbappend`` file is the most
522reliable and recommended method for adding directories to the search
523path used by the build system to find files.
524
525The statement in this example extends the directories to include
526``${``\ :term:`THISDIR`\ ``}/${``\ :term:`PN`\ ``}``,
527which resolves to a directory named ``formfactor`` in the same directory
528in which the append file resides (i.e.
529``meta-raspberrypi/recipes-bsp/formfactor``. This implies that you must
530have the supporting directory structure set up that will contain any
531files or patches you will be including from the layer.
532
533Using the immediate expansion assignment operator ``:=`` is important
534because of the reference to ``THISDIR``. The trailing colon character is
535important as it ensures that items in the list remain colon-separated.
536
537.. note::
538
539 BitBake automatically defines the ``THISDIR`` variable. You should
540 never set this variable yourself. Using "_prepend" as part of the
541 ``FILESEXTRAPATHS`` ensures your path will be searched prior to other
542 paths in the final list.
543
544 Also, not all append files add extra files. Many append files simply
545 exist to add build options (e.g. ``systemd``). For these cases, your
546 append file would not even use the ``FILESEXTRAPATHS`` statement.
547
548Prioritizing Your Layer
549-----------------------
550
551Each layer is assigned a priority value. Priority values control which
552layer takes precedence if there are recipe files with the same name in
553multiple layers. For these cases, the recipe file from the layer with a
554higher priority number takes precedence. Priority values also affect the
555order in which multiple ``.bbappend`` files for the same recipe are
556applied. You can either specify the priority manually, or allow the
557build system to calculate it based on the layer's dependencies.
558
559To specify the layer's priority manually, use the
560:term:`BBFILE_PRIORITY`
Andrew Geisslerc926e172021-05-07 16:11:35 -0500561variable and append the layer's root name::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500562
563 BBFILE_PRIORITY_mylayer = "1"
564
565.. note::
566
567 It is possible for a recipe with a lower version number
568 :term:`PV` in a layer that has a higher
569 priority to take precedence.
570
571 Also, the layer priority does not currently affect the precedence
572 order of ``.conf`` or ``.bbclass`` files. Future versions of BitBake
573 might address this.
574
575Managing Layers
576---------------
577
578You can use the BitBake layer management tool ``bitbake-layers`` to
579provide a view into the structure of recipes across a multi-layer
580project. Being able to generate output that reports on configured layers
581with their paths and priorities and on ``.bbappend`` files and their
582applicable recipes can help to reveal potential problems.
583
584For help on the BitBake layer management tool, use the following
Andrew Geisslerc926e172021-05-07 16:11:35 -0500585command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500586
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500587 $ bitbake-layers --help
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500588 NOTE: Starting bitbake server...
589 usage: bitbake-layers [-d] [-q] [-F] [--color COLOR] [-h] <subcommand> ...
590
591 BitBake layers utility
592
593 optional arguments:
594 -d, --debug Enable debug output
595 -q, --quiet Print only errors
596 -F, --force Force add without recipe parse verification
597 --color COLOR Colorize output (where COLOR is auto, always, never)
598 -h, --help show this help message and exit
599
600 subcommands:
601 <subcommand>
602 layerindex-fetch Fetches a layer from a layer index along with its
603 dependent layers, and adds them to conf/bblayers.conf.
604 layerindex-show-depends
605 Find layer dependencies from layer index.
606 add-layer Add one or more layers to bblayers.conf.
607 remove-layer Remove one or more layers from bblayers.conf.
608 flatten flatten layer configuration into a separate output
609 directory.
610 show-layers show current configured layers.
611 show-overlayed list overlayed recipes (where the same recipe exists
612 in another layer)
613 show-recipes list available recipes, showing the layer they are
614 provided by
615 show-appends list bbappend files and recipe files they apply to
616 show-cross-depends Show dependencies between recipes that cross layer
617 boundaries.
618 create-layer Create a basic layer
619
620 Use bitbake-layers <subcommand> --help to get help on a specific command
621
622The following list describes the available commands:
623
624- ``help:`` Displays general help or help on a specified command.
625
626- ``show-layers:`` Shows the current configured layers.
627
628- ``show-overlayed:`` Lists overlayed recipes. A recipe is overlayed
629 when a recipe with the same name exists in another layer that has a
630 higher layer priority.
631
632- ``show-recipes:`` Lists available recipes and the layers that
633 provide them.
634
635- ``show-appends:`` Lists ``.bbappend`` files and the recipe files to
636 which they apply.
637
638- ``show-cross-depends:`` Lists dependency relationships between
639 recipes that cross layer boundaries.
640
641- ``add-layer:`` Adds a layer to ``bblayers.conf``.
642
643- ``remove-layer:`` Removes a layer from ``bblayers.conf``
644
645- ``flatten:`` Flattens the layer configuration into a separate
646 output directory. Flattening your layer configuration builds a
647 "flattened" directory that contains the contents of all layers, with
648 any overlayed recipes removed and any ``.bbappend`` files appended to
649 the corresponding recipes. You might have to perform some manual
650 cleanup of the flattened layer as follows:
651
652 - Non-recipe files (such as patches) are overwritten. The flatten
653 command shows a warning for these files.
654
655 - Anything beyond the normal layer setup has been added to the
656 ``layer.conf`` file. Only the lowest priority layer's
657 ``layer.conf`` is used.
658
659 - Overridden and appended items from ``.bbappend`` files need to be
660 cleaned up. The contents of each ``.bbappend`` end up in the
661 flattened recipe. However, if there are appended or changed
662 variable values, you need to tidy these up yourself. Consider the
663 following example. Here, the ``bitbake-layers`` command adds the
664 line ``#### bbappended ...`` so that you know where the following
Andrew Geisslerc926e172021-05-07 16:11:35 -0500665 lines originate::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500666
667 ...
668 DESCRIPTION = "A useful utility"
669 ...
670 EXTRA_OECONF = "--enable-something"
671 ...
672
673 #### bbappended from meta-anotherlayer ####
674
675 DESCRIPTION = "Customized utility"
676 EXTRA_OECONF += "--enable-somethingelse"
677
678
Andrew Geisslerc926e172021-05-07 16:11:35 -0500679 Ideally, you would tidy up these utilities as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500680
681 ...
682 DESCRIPTION = "Customized utility"
683 ...
684 EXTRA_OECONF = "--enable-something --enable-somethingelse"
685 ...
686
687- ``layerindex-fetch``: Fetches a layer from a layer index, along
688 with its dependent layers, and adds the layers to the
689 ``conf/bblayers.conf`` file.
690
691- ``layerindex-show-depends``: Finds layer dependencies from the
692 layer index.
693
694- ``create-layer``: Creates a basic layer.
695
696Creating a General Layer Using the ``bitbake-layers`` Script
697------------------------------------------------------------
698
699The ``bitbake-layers`` script with the ``create-layer`` subcommand
700simplifies creating a new general layer.
701
702.. note::
703
704 - For information on BSP layers, see the ":ref:`bsp-guide/bsp:bsp layers`"
705 section in the Yocto
706 Project Board Specific (BSP) Developer's Guide.
707
708 - In order to use a layer with the OpenEmbedded build system, you
709 need to add the layer to your ``bblayers.conf`` configuration
Andrew Geissler09209ee2020-12-13 08:44:15 -0600710 file. See the ":ref:`dev-manual/common-tasks:adding a layer using the \`\`bitbake-layers\`\` script`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500711 section for more information.
712
713The default mode of the script's operation with this subcommand is to
714create a layer with the following:
715
716- A layer priority of 6.
717
718- A ``conf`` subdirectory that contains a ``layer.conf`` file.
719
720- A ``recipes-example`` subdirectory that contains a further
721 subdirectory named ``example``, which contains an ``example.bb``
722 recipe file.
723
724- A ``COPYING.MIT``, which is the license statement for the layer. The
725 script assumes you want to use the MIT license, which is typical for
726 most layers, for the contents of the layer itself.
727
728- A ``README`` file, which is a file describing the contents of your
729 new layer.
730
731In its simplest form, you can use the following command form to create a
732layer. The command creates a layer whose name corresponds to
Andrew Geisslerc926e172021-05-07 16:11:35 -0500733"your_layer_name" in the current directory::
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500734
735 $ bitbake-layers create-layer your_layer_name
736
737As an example, the following command creates a layer named ``meta-scottrif``
Andrew Geisslerc926e172021-05-07 16:11:35 -0500738in your home directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500739
740 $ cd /usr/home
741 $ bitbake-layers create-layer meta-scottrif
742 NOTE: Starting bitbake server...
743 Add your new layer with 'bitbake-layers add-layer meta-scottrif'
744
745If you want to set the priority of the layer to other than the default
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500746value of "6", you can either use the ``--priority`` option or you
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500747can edit the
748:term:`BBFILE_PRIORITY` value
749in the ``conf/layer.conf`` after the script creates it. Furthermore, if
750you want to give the example recipe file some name other than the
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500751default, you can use the ``--example-recipe-name`` option.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500752
753The easiest way to see how the ``bitbake-layers create-layer`` command
754works is to experiment with the script. You can also read the usage
Andrew Geisslerc926e172021-05-07 16:11:35 -0500755information by entering the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500756
757 $ bitbake-layers create-layer --help
758 NOTE: Starting bitbake server...
759 usage: bitbake-layers create-layer [-h] [--priority PRIORITY]
760 [--example-recipe-name EXAMPLERECIPE]
761 layerdir
762
763 Create a basic layer
764
765 positional arguments:
766 layerdir Layer directory to create
767
768 optional arguments:
769 -h, --help show this help message and exit
770 --priority PRIORITY, -p PRIORITY
771 Layer directory to create
772 --example-recipe-name EXAMPLERECIPE, -e EXAMPLERECIPE
773 Filename of the example recipe
774
775Adding a Layer Using the ``bitbake-layers`` Script
776--------------------------------------------------
777
778Once you create your general layer, you must add it to your
779``bblayers.conf`` file. Adding the layer to this configuration file
780makes the OpenEmbedded build system aware of your layer so that it can
781search it for metadata.
782
Andrew Geisslerc926e172021-05-07 16:11:35 -0500783Add your layer by using the ``bitbake-layers add-layer`` command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500784
785 $ bitbake-layers add-layer your_layer_name
786
787Here is an example that adds a
788layer named ``meta-scottrif`` to the configuration file. Following the
789command that adds the layer is another ``bitbake-layers`` command that
Andrew Geisslerc926e172021-05-07 16:11:35 -0500790shows the layers that are in your ``bblayers.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500791
792 $ bitbake-layers add-layer meta-scottrif
793 NOTE: Starting bitbake server...
794 Parsing recipes: 100% |##########################################################| Time: 0:00:49
795 Parsing of 1441 .bb files complete (0 cached, 1441 parsed). 2055 targets, 56 skipped, 0 masked, 0 errors.
796 $ bitbake-layers show-layers
797 NOTE: Starting bitbake server...
798 layer path priority
799 ==========================================================================
800 meta /home/scottrif/poky/meta 5
801 meta-poky /home/scottrif/poky/meta-poky 5
802 meta-yocto-bsp /home/scottrif/poky/meta-yocto-bsp 5
803 workspace /home/scottrif/poky/build/workspace 99
804 meta-scottrif /home/scottrif/poky/build/meta-scottrif 6
805
806
807Adding the layer to this file
808enables the build system to locate the layer during the build.
809
810.. note::
811
812 During a build, the OpenEmbedded build system looks in the layers
813 from the top of the list down to the bottom in that order.
814
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500815Customizing Images
816==================
817
818You can customize images to satisfy particular requirements. This
819section describes several methods and provides guidelines for each.
820
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500821Customizing Images Using ``local.conf``
822---------------------------------------
823
824Probably the easiest way to customize an image is to add a package by
825way of the ``local.conf`` configuration file. Because it is limited to
826local use, this method generally only allows you to add packages and is
827not as flexible as creating your own customized image. When you add
828packages using local variables this way, you need to realize that these
829variable changes are in effect for every build and consequently affect
830all images, which might not be what you require.
831
832To add a package to your image using the local configuration file, use
Andrew Geisslerc926e172021-05-07 16:11:35 -0500833the ``IMAGE_INSTALL`` variable with the ``_append`` operator::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500834
835 IMAGE_INSTALL_append = " strace"
836
837Use of the syntax is important -
838specifically, the space between the quote and the package name, which is
839``strace`` in this example. This space is required since the ``_append``
840operator does not add the space.
841
842Furthermore, you must use ``_append`` instead of the ``+=`` operator if
843you want to avoid ordering issues. The reason for this is because doing
844so unconditionally appends to the variable and avoids ordering problems
845due to the variable being set in image recipes and ``.bbclass`` files
846with operators like ``?=``. Using ``_append`` ensures the operation
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500847takes effect.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500848
849As shown in its simplest use, ``IMAGE_INSTALL_append`` affects all
850images. It is possible to extend the syntax so that the variable applies
Andrew Geisslerc926e172021-05-07 16:11:35 -0500851to a specific image only. Here is an example::
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500852
853 IMAGE_INSTALL_append_pn-core-image-minimal = " strace"
854
855This example adds ``strace`` to the ``core-image-minimal`` image only.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500856
857You can add packages using a similar approach through the
858``CORE_IMAGE_EXTRA_INSTALL`` variable. If you use this variable, only
859``core-image-*`` images are affected.
860
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500861Customizing Images Using Custom ``IMAGE_FEATURES`` and ``EXTRA_IMAGE_FEATURES``
862-------------------------------------------------------------------------------
863
864Another method for customizing your image is to enable or disable
865high-level image features by using the
866:term:`IMAGE_FEATURES` and
867:term:`EXTRA_IMAGE_FEATURES`
868variables. Although the functions for both variables are nearly
869equivalent, best practices dictate using ``IMAGE_FEATURES`` from within
870a recipe and using ``EXTRA_IMAGE_FEATURES`` from within your
871``local.conf`` file, which is found in the
872:term:`Build Directory`.
873
874To understand how these features work, the best reference is
875``meta/classes/core-image.bbclass``. This class lists out the available
876``IMAGE_FEATURES`` of which most map to package groups while some, such
877as ``debug-tweaks`` and ``read-only-rootfs``, resolve as general
878configuration settings.
879
880In summary, the file looks at the contents of the ``IMAGE_FEATURES``
881variable and then maps or configures the feature accordingly. Based on
882this information, the build system automatically adds the appropriate
883packages or configurations to the
884:term:`IMAGE_INSTALL` variable.
885Effectively, you are enabling extra features by extending the class or
886creating a custom class for use with specialized image ``.bb`` files.
887
888Use the ``EXTRA_IMAGE_FEATURES`` variable from within your local
889configuration file. Using a separate area from which to enable features
890with this variable helps you avoid overwriting the features in the image
891recipe that are enabled with ``IMAGE_FEATURES``. The value of
892``EXTRA_IMAGE_FEATURES`` is added to ``IMAGE_FEATURES`` within
893``meta/conf/bitbake.conf``.
894
895To illustrate how you can use these variables to modify your image,
896consider an example that selects the SSH server. The Yocto Project ships
897with two SSH servers you can use with your images: Dropbear and OpenSSH.
898Dropbear is a minimal SSH server appropriate for resource-constrained
899environments, while OpenSSH is a well-known standard SSH server
900implementation. By default, the ``core-image-sato`` image is configured
901to use Dropbear. The ``core-image-full-cmdline`` and ``core-image-lsb``
902images both include OpenSSH. The ``core-image-minimal`` image does not
903contain an SSH server.
904
905You can customize your image and change these defaults. Edit the
906``IMAGE_FEATURES`` variable in your recipe or use the
907``EXTRA_IMAGE_FEATURES`` in your ``local.conf`` file so that it
908configures the image you are working with to include
909``ssh-server-dropbear`` or ``ssh-server-openssh``.
910
911.. note::
912
Andrew Geissler09209ee2020-12-13 08:44:15 -0600913 See the ":ref:`ref-manual/features:image features`" section in the Yocto
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500914 Project Reference Manual for a complete list of image features that ship
915 with the Yocto Project.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500916
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500917Customizing Images Using Custom .bb Files
918-----------------------------------------
919
920You can also customize an image by creating a custom recipe that defines
921additional software as part of the image. The following example shows
Andrew Geisslerc926e172021-05-07 16:11:35 -0500922the form for the two lines you need::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500923
924 IMAGE_INSTALL = "packagegroup-core-x11-base package1 package2"
925 inherit core-image
926
927Defining the software using a custom recipe gives you total control over
928the contents of the image. It is important to use the correct names of
929packages in the ``IMAGE_INSTALL`` variable. You must use the
930OpenEmbedded notation and not the Debian notation for the names (e.g.
931``glibc-dev`` instead of ``libc6-dev``).
932
933The other method for creating a custom image is to base it on an
934existing image. For example, if you want to create an image based on
935``core-image-sato`` but add the additional package ``strace`` to the
936image, copy the ``meta/recipes-sato/images/core-image-sato.bb`` to a new
Andrew Geisslerc926e172021-05-07 16:11:35 -0500937``.bb`` and add the following line to the end of the copy::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500938
939 IMAGE_INSTALL += "strace"
940
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500941Customizing Images Using Custom Package Groups
942----------------------------------------------
943
944For complex custom images, the best approach for customizing an image is
945to create a custom package group recipe that is used to build the image
946or images. A good example of a package group recipe is
947``meta/recipes-core/packagegroups/packagegroup-base.bb``.
948
949If you examine that recipe, you see that the ``PACKAGES`` variable lists
950the package group packages to produce. The ``inherit packagegroup``
951statement sets appropriate default values and automatically adds
952``-dev``, ``-dbg``, and ``-ptest`` complementary packages for each
953package specified in the ``PACKAGES`` statement.
954
955.. note::
956
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500957 The ``inherit packagegroup`` line should be located near the top of the
958 recipe, certainly before the ``PACKAGES`` statement.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500959
960For each package you specify in ``PACKAGES``, you can use ``RDEPENDS``
961and ``RRECOMMENDS`` entries to provide a list of packages the parent
962task package should contain. You can see examples of these further down
963in the ``packagegroup-base.bb`` recipe.
964
965Here is a short, fabricated example showing the same basic pieces for a
966hypothetical packagegroup defined in ``packagegroup-custom.bb``, where
967the variable ``PN`` is the standard way to abbreviate the reference to
Andrew Geisslerc926e172021-05-07 16:11:35 -0500968the full packagegroup name ``packagegroup-custom``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500969
970 DESCRIPTION = "My Custom Package Groups"
971
972 inherit packagegroup
973
974 PACKAGES = "\
975 ${PN}-apps \
976 ${PN}-tools \
977 "
978
979 RDEPENDS_${PN}-apps = "\
980 dropbear \
981 portmap \
982 psplash"
983
984 RDEPENDS_${PN}-tools = "\
985 oprofile \
986 oprofileui-server \
987 lttng-tools"
988
989 RRECOMMENDS_${PN}-tools = "\
990 kernel-module-oprofile"
991
992In the previous example, two package group packages are created with
993their dependencies and their recommended package dependencies listed:
994``packagegroup-custom-apps``, and ``packagegroup-custom-tools``. To
995build an image using these package group packages, you need to add
996``packagegroup-custom-apps`` and/or ``packagegroup-custom-tools`` to
997``IMAGE_INSTALL``. For other forms of image dependencies see the other
998areas of this section.
999
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001000Customizing an Image Hostname
1001-----------------------------
1002
1003By default, the configured hostname (i.e. ``/etc/hostname``) in an image
1004is the same as the machine name. For example, if
1005:term:`MACHINE` equals "qemux86", the
1006configured hostname written to ``/etc/hostname`` is "qemux86".
1007
1008You can customize this name by altering the value of the "hostname"
1009variable in the ``base-files`` recipe using either an append file or a
Andrew Geisslerc926e172021-05-07 16:11:35 -05001010configuration file. Use the following in an append file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001011
1012 hostname = "myhostname"
1013
Andrew Geisslerc926e172021-05-07 16:11:35 -05001014Use the following in a configuration file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001015
1016 hostname_pn-base-files = "myhostname"
1017
1018Changing the default value of the variable "hostname" can be useful in
1019certain situations. For example, suppose you need to do extensive
1020testing on an image and you would like to easily identify the image
1021under test from existing images with typical default hostnames. In this
1022situation, you could change the default hostname to "testme", which
1023results in all the images using the name "testme". Once testing is
1024complete and you do not need to rebuild the image for test any longer,
1025you can easily reset the default hostname.
1026
1027Another point of interest is that if you unset the variable, the image
1028will have no default hostname in the filesystem. Here is an example that
Andrew Geisslerc926e172021-05-07 16:11:35 -05001029unsets the variable in a configuration file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001030
1031 hostname_pn-base-files = ""
1032
1033Having no default hostname in the filesystem is suitable for
1034environments that use dynamic hostnames such as virtual machines.
1035
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001036Writing a New Recipe
1037====================
1038
1039Recipes (``.bb`` files) are fundamental components in the Yocto Project
1040environment. Each software component built by the OpenEmbedded build
1041system requires a recipe to define the component. This section describes
1042how to create, write, and test a new recipe.
1043
1044.. note::
1045
1046 For information on variables that are useful for recipes and for
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001047 information about recipe naming issues, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001048 ":ref:`ref-manual/varlocality:recipes`" section of the Yocto Project
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001049 Reference Manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001050
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001051Overview
1052--------
1053
1054The following figure shows the basic process for creating a new recipe.
1055The remainder of the section provides details for the steps.
1056
1057.. image:: figures/recipe-workflow.png
1058 :align: center
1059
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001060Locate or Automatically Create a Base Recipe
1061--------------------------------------------
1062
1063You can always write a recipe from scratch. However, three choices exist
1064that can help you quickly get a start on a new recipe:
1065
1066- ``devtool add``: A command that assists in creating a recipe and an
1067 environment conducive to development.
1068
1069- ``recipetool create``: A command provided by the Yocto Project that
1070 automates creation of a base recipe based on the source files.
1071
1072- *Existing Recipes:* Location and modification of an existing recipe
1073 that is similar in function to the recipe you need.
1074
1075.. note::
1076
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001077 For information on recipe syntax, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001078 ":ref:`dev-manual/common-tasks:recipe syntax`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001079
1080Creating the Base Recipe Using ``devtool add``
1081~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1082
1083The ``devtool add`` command uses the same logic for auto-creating the
1084recipe as ``recipetool create``, which is listed below. Additionally,
1085however, ``devtool add`` sets up an environment that makes it easy for
1086you to patch the source and to make changes to the recipe as is often
1087necessary when adding a recipe to build a new piece of software to be
1088included in a build.
1089
1090You can find a complete description of the ``devtool add`` command in
Andrew Geissler09209ee2020-12-13 08:44:15 -06001091the ":ref:`sdk-manual/extensible:a closer look at \`\`devtool add\`\``" section
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001092in the Yocto Project Application Development and the Extensible Software
1093Development Kit (eSDK) manual.
1094
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001095Creating the Base Recipe Using ``recipetool create``
1096~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1097
1098``recipetool create`` automates creation of a base recipe given a set of
1099source code files. As long as you can extract or point to the source
1100files, the tool will construct a recipe and automatically configure all
1101pre-build information into the recipe. For example, suppose you have an
1102application that builds using Autotools. Creating the base recipe using
1103``recipetool`` results in a recipe that has the pre-build dependencies,
1104license requirements, and checksums configured.
1105
1106To run the tool, you just need to be in your
1107:term:`Build Directory` and have sourced the
1108build environment setup script (i.e.
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001109:ref:`structure-core-script`).
Andrew Geisslerc926e172021-05-07 16:11:35 -05001110To get help on the tool, use the following command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001111
1112 $ recipetool -h
1113 NOTE: Starting bitbake server...
1114 usage: recipetool [-d] [-q] [--color COLOR] [-h] <subcommand> ...
1115
1116 OpenEmbedded recipe tool
1117
1118 options:
1119 -d, --debug Enable debug output
1120 -q, --quiet Print only errors
1121 --color COLOR Colorize output (where COLOR is auto, always, never)
1122 -h, --help show this help message and exit
1123
1124 subcommands:
1125 create Create a new recipe
1126 newappend Create a bbappend for the specified target in the specified
1127 layer
1128 setvar Set a variable within a recipe
1129 appendfile Create/update a bbappend to replace a target file
1130 appendsrcfiles Create/update a bbappend to add or replace source files
1131 appendsrcfile Create/update a bbappend to add or replace a source file
1132 Use recipetool <subcommand> --help to get help on a specific command
1133
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001134Running ``recipetool create -o OUTFILE`` creates the base recipe and
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001135locates it properly in the layer that contains your source files.
1136Following are some syntax examples:
1137
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001138 - Use this syntax to generate a recipe based on source. Once generated,
Andrew Geisslerc926e172021-05-07 16:11:35 -05001139 the recipe resides in the existing source code layer::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001140
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001141 recipetool create -o OUTFILE source
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001142
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001143 - Use this syntax to generate a recipe using code that
1144 you extract from source. The extracted code is placed in its own layer
1145 defined by ``EXTERNALSRC``.
1146 ::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001147
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001148 recipetool create -o OUTFILE -x EXTERNALSRC source
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001149
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001150 - Use this syntax to generate a recipe based on source. The options
1151 direct ``recipetool`` to generate debugging information. Once generated,
Andrew Geisslerc926e172021-05-07 16:11:35 -05001152 the recipe resides in the existing source code layer::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001153
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001154 recipetool create -d -o OUTFILE source
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001155
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001156Locating and Using a Similar Recipe
1157~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1158
1159Before writing a recipe from scratch, it is often useful to discover
1160whether someone else has already written one that meets (or comes close
1161to meeting) your needs. The Yocto Project and OpenEmbedded communities
1162maintain many recipes that might be candidates for what you are doing.
Andrew Geisslerd1e89492021-02-12 15:35:20 -06001163You can find a good central index of these recipes in the
1164:oe_layerindex:`OpenEmbedded Layer Index <>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001165
1166Working from an existing recipe or a skeleton recipe is the best way to
1167get started. Here are some points on both methods:
1168
1169- *Locate and modify a recipe that is close to what you want to do:*
1170 This method works when you are familiar with the current recipe
1171 space. The method does not work so well for those new to the Yocto
1172 Project or writing recipes.
1173
1174 Some risks associated with this method are using a recipe that has
1175 areas totally unrelated to what you are trying to accomplish with
1176 your recipe, not recognizing areas of the recipe that you might have
1177 to add from scratch, and so forth. All these risks stem from
1178 unfamiliarity with the existing recipe space.
1179
1180- *Use and modify the following skeleton recipe:* If for some reason
1181 you do not want to use ``recipetool`` and you cannot find an existing
1182 recipe that is close to meeting your needs, you can use the following
1183 structure to provide the fundamental areas of a new recipe.
1184 ::
1185
1186 DESCRIPTION = ""
1187 HOMEPAGE = ""
1188 LICENSE = ""
1189 SECTION = ""
1190 DEPENDS = ""
1191 LIC_FILES_CHKSUM = ""
1192
1193 SRC_URI = ""
1194
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001195Storing and Naming the Recipe
1196-----------------------------
1197
1198Once you have your base recipe, you should put it in your own layer and
1199name it appropriately. Locating it correctly ensures that the
1200OpenEmbedded build system can find it when you use BitBake to process
1201the recipe.
1202
1203- *Storing Your Recipe:* The OpenEmbedded build system locates your
1204 recipe through the layer's ``conf/layer.conf`` file and the
1205 :term:`BBFILES` variable. This
1206 variable sets up a path from which the build system can locate
Andrew Geisslerc926e172021-05-07 16:11:35 -05001207 recipes. Here is the typical use::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001208
1209 BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
1210 ${LAYERDIR}/recipes-*/*/*.bbappend"
1211
1212 Consequently, you need to be sure you locate your new recipe inside
1213 your layer such that it can be found.
1214
1215 You can find more information on how layers are structured in the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001216 ":ref:`dev-manual/common-tasks:understanding and creating layers`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001217
1218- *Naming Your Recipe:* When you name your recipe, you need to follow
Andrew Geisslerc926e172021-05-07 16:11:35 -05001219 this naming convention::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001220
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001221 basename_version.bb
1222
1223 Use lower-cased characters and do not include the reserved suffixes
1224 ``-native``, ``-cross``, ``-initial``, or ``-dev`` casually (i.e. do not use
1225 them as part of your recipe name unless the string applies). Here are some
1226 examples:
1227
1228 .. code-block:: none
1229
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001230 cups_1.7.0.bb
1231 gawk_4.0.2.bb
1232 irssi_0.8.16-rc1.bb
1233
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001234Running a Build on the Recipe
1235-----------------------------
1236
1237Creating a new recipe is usually an iterative process that requires
1238using BitBake to process the recipe multiple times in order to
1239progressively discover and add information to the recipe file.
1240
1241Assuming you have sourced the build environment setup script (i.e.
1242:ref:`structure-core-script`) and you are in
1243the :term:`Build Directory`, use
1244BitBake to process your recipe. All you need to provide is the
Andrew Geisslerc926e172021-05-07 16:11:35 -05001245``basename`` of the recipe as described in the previous section::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001246
1247 $ bitbake basename
1248
1249During the build, the OpenEmbedded build system creates a temporary work
1250directory for each recipe
1251(``${``\ :term:`WORKDIR`\ ``}``)
1252where it keeps extracted source files, log files, intermediate
1253compilation and packaging files, and so forth.
1254
1255The path to the per-recipe temporary work directory depends on the
1256context in which it is being built. The quickest way to find this path
Andrew Geisslerc926e172021-05-07 16:11:35 -05001257is to have BitBake return it by running the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001258
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001259 $ bitbake -e basename | grep ^WORKDIR=
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001260
1261As an example, assume a Source Directory
1262top-level folder named ``poky``, a default Build Directory at
1263``poky/build``, and a ``qemux86-poky-linux`` machine target system.
1264Furthermore, suppose your recipe is named ``foo_1.3.0.bb``. In this
1265case, the work directory the build system uses to build the package
Andrew Geisslerc926e172021-05-07 16:11:35 -05001266would be as follows::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001267
1268 poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
1269
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001270Inside this directory you can find sub-directories such as ``image``,
1271``packages-split``, and ``temp``. After the build, you can examine these
1272to determine how well the build went.
1273
1274.. note::
1275
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001276 You can find log files for each task in the recipe's ``temp``
1277 directory (e.g. ``poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0/temp``).
1278 Log files are named ``log.taskname`` (e.g. ``log.do_configure``,
1279 ``log.do_fetch``, and ``log.do_compile``).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001280
1281You can find more information about the build process in
Andrew Geissler09209ee2020-12-13 08:44:15 -06001282":doc:`/overview-manual/development-environment`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001283chapter of the Yocto Project Overview and Concepts Manual.
1284
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001285Fetching Code
1286-------------
1287
1288The first thing your recipe must do is specify how to fetch the source
1289files. Fetching is controlled mainly through the
1290:term:`SRC_URI` variable. Your recipe
1291must have a ``SRC_URI`` variable that points to where the source is
1292located. For a graphical representation of source locations, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001293":ref:`overview-manual/concepts:sources`" section in
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001294the Yocto Project Overview and Concepts Manual.
1295
1296The :ref:`ref-tasks-fetch` task uses
1297the prefix of each entry in the ``SRC_URI`` variable value to determine
Andrew Geissler09209ee2020-12-13 08:44:15 -06001298which :ref:`fetcher <bitbake:bitbake-user-manual/bitbake-user-manual-fetching:fetchers>` to use to get your
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001299source files. It is the ``SRC_URI`` variable that triggers the fetcher.
1300The :ref:`ref-tasks-patch` task uses
1301the variable after source is fetched to apply patches. The OpenEmbedded
1302build system uses
1303:term:`FILESOVERRIDES` for
1304scanning directory locations for local files in ``SRC_URI``.
1305
1306The ``SRC_URI`` variable in your recipe must define each unique location
1307for your source files. It is good practice to not hard-code version
1308numbers in a URL used in ``SRC_URI``. Rather than hard-code these
1309values, use ``${``\ :term:`PV`\ ``}``,
1310which causes the fetch process to use the version specified in the
1311recipe filename. Specifying the version in this manner means that
1312upgrading the recipe to a future version is as simple as renaming the
1313recipe to match the new version.
1314
1315Here is a simple example from the
1316``meta/recipes-devtools/strace/strace_5.5.bb`` recipe where the source
1317comes from a single tarball. Notice the use of the
Andrew Geisslerc926e172021-05-07 16:11:35 -05001318:term:`PV` variable::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001319
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001320 SRC_URI = "https://strace.io/files/${PV}/strace-${PV}.tar.xz \
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001321
1322Files mentioned in ``SRC_URI`` whose names end in a typical archive
1323extension (e.g. ``.tar``, ``.tar.gz``, ``.tar.bz2``, ``.zip``, and so
1324forth), are automatically extracted during the
1325:ref:`ref-tasks-unpack` task. For
1326another example that specifies these types of files, see the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001327":ref:`dev-manual/common-tasks:autotooled package`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001328
1329Another way of specifying source is from an SCM. For Git repositories,
1330you must specify :term:`SRCREV` and
1331you should specify :term:`PV` to include
1332the revision with :term:`SRCPV`. Here
1333is an example from the recipe
Andrew Geisslerc926e172021-05-07 16:11:35 -05001334``meta/recipes-kernel/blktrace/blktrace_git.bb``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001335
1336 SRCREV = "d6918c8832793b4205ed3bfede78c2f915c23385"
1337
1338 PR = "r6"
1339 PV = "1.0.5+git${SRCPV}"
1340
1341 SRC_URI = "git://git.kernel.dk/blktrace.git \
1342 file://ldflags.patch"
1343
1344If your ``SRC_URI`` statement includes URLs pointing to individual files
1345fetched from a remote server other than a version control system,
1346BitBake attempts to verify the files against checksums defined in your
1347recipe to ensure they have not been tampered with or otherwise modified
1348since the recipe was written. Two checksums are used:
1349``SRC_URI[md5sum]`` and ``SRC_URI[sha256sum]``.
1350
1351If your ``SRC_URI`` variable points to more than a single URL (excluding
1352SCM URLs), you need to provide the ``md5`` and ``sha256`` checksums for
1353each URL. For these cases, you provide a name for each URL as part of
1354the ``SRC_URI`` and then reference that name in the subsequent checksum
1355statements. Here is an example combining lines from the files
Andrew Geisslerc926e172021-05-07 16:11:35 -05001356``git.inc`` and ``git_2.24.1.bb``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001357
1358 SRC_URI = "${KERNELORG_MIRROR}/software/scm/git/git-${PV}.tar.gz;name=tarball \
1359 ${KERNELORG_MIRROR}/software/scm/git/git-manpages-${PV}.tar.gz;name=manpages"
1360
1361 SRC_URI[tarball.md5sum] = "166bde96adbbc11c8843d4f8f4f9811b"
1362 SRC_URI[tarball.sha256sum] = "ad5334956301c86841eb1e5b1bb20884a6bad89a10a6762c958220c7cf64da02"
1363 SRC_URI[manpages.md5sum] = "31c2272a8979022497ba3d4202df145d"
1364 SRC_URI[manpages.sha256sum] = "9a7ae3a093bea39770eb96ca3e5b40bff7af0b9f6123f089d7821d0e5b8e1230"
1365
1366Proper values for ``md5`` and ``sha256`` checksums might be available
1367with other signatures on the download page for the upstream source (e.g.
1368``md5``, ``sha1``, ``sha256``, ``GPG``, and so forth). Because the
1369OpenEmbedded build system only deals with ``sha256sum`` and ``md5sum``,
1370you should verify all the signatures you find by hand.
1371
1372If no ``SRC_URI`` checksums are specified when you attempt to build the
1373recipe, or you provide an incorrect checksum, the build will produce an
1374error for each missing or incorrect checksum. As part of the error
1375message, the build system provides the checksum string corresponding to
1376the fetched file. Once you have the correct checksums, you can copy and
1377paste them into your recipe and then run the build again to continue.
1378
1379.. note::
1380
1381 As mentioned, if the upstream source provides signatures for
1382 verifying the downloaded source code, you should verify those
1383 manually before setting the checksum values in the recipe and
1384 continuing with the build.
1385
1386This final example is a bit more complicated and is from the
1387``meta/recipes-sato/rxvt-unicode/rxvt-unicode_9.20.bb`` recipe. The
1388example's ``SRC_URI`` statement identifies multiple files as the source
1389files for the recipe: a tarball, a patch file, a desktop file, and an
1390icon.
1391::
1392
1393 SRC_URI = "http://dist.schmorp.de/rxvt-unicode/Attic/rxvt-unicode-${PV}.tar.bz2 \
1394 file://xwc.patch \
1395 file://rxvt.desktop \
1396 file://rxvt.png"
1397
1398When you specify local files using the ``file://`` URI protocol, the
1399build system fetches files from the local machine. The path is relative
1400to the :term:`FILESPATH` variable
1401and searches specific directories in a certain order:
1402``${``\ :term:`BP`\ ``}``,
1403``${``\ :term:`BPN`\ ``}``, and
1404``files``. The directories are assumed to be subdirectories of the
1405directory in which the recipe or append file resides. For another
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001406example that specifies these types of files, see the
1407":ref:`dev-manual/common-tasks:single .c file package (hello world!)`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001408
1409The previous example also specifies a patch file. Patch files are files
1410whose names usually end in ``.patch`` or ``.diff`` but can end with
1411compressed suffixes such as ``diff.gz`` and ``patch.bz2``, for example.
1412The build system automatically applies patches as described in the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001413":ref:`dev-manual/common-tasks:patching code`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001414
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001415Unpacking Code
1416--------------
1417
1418During the build, the
1419:ref:`ref-tasks-unpack` task unpacks
1420the source with ``${``\ :term:`S`\ ``}``
1421pointing to where it is unpacked.
1422
1423If you are fetching your source files from an upstream source archived
1424tarball and the tarball's internal structure matches the common
1425convention of a top-level subdirectory named
1426``${``\ :term:`BPN`\ ``}-${``\ :term:`PV`\ ``}``,
1427then you do not need to set ``S``. However, if ``SRC_URI`` specifies to
1428fetch source from an archive that does not use this convention, or from
1429an SCM like Git or Subversion, your recipe needs to define ``S``.
1430
1431If processing your recipe using BitBake successfully unpacks the source
1432files, you need to be sure that the directory pointed to by ``${S}``
1433matches the structure of the source.
1434
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001435Patching Code
1436-------------
1437
1438Sometimes it is necessary to patch code after it has been fetched. Any
1439files mentioned in ``SRC_URI`` whose names end in ``.patch`` or
1440``.diff`` or compressed versions of these suffixes (e.g. ``diff.gz`` are
1441treated as patches. The
1442:ref:`ref-tasks-patch` task
1443automatically applies these patches.
1444
1445The build system should be able to apply patches with the "-p1" option
1446(i.e. one directory level in the path will be stripped off). If your
1447patch needs to have more directory levels stripped off, specify the
1448number of levels using the "striplevel" option in the ``SRC_URI`` entry
1449for the patch. Alternatively, if your patch needs to be applied in a
1450specific subdirectory that is not specified in the patch file, use the
1451"patchdir" option in the entry.
1452
1453As with all local files referenced in
1454:term:`SRC_URI` using ``file://``,
1455you should place patch files in a directory next to the recipe either
1456named the same as the base name of the recipe
1457(:term:`BP` and
1458:term:`BPN`) or "files".
1459
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001460Licensing
1461---------
1462
1463Your recipe needs to have both the
1464:term:`LICENSE` and
1465:term:`LIC_FILES_CHKSUM`
1466variables:
1467
1468- ``LICENSE``: This variable specifies the license for the software.
1469 If you do not know the license under which the software you are
1470 building is distributed, you should go to the source code and look
1471 for that information. Typical files containing this information
1472 include ``COPYING``, ``LICENSE``, and ``README`` files. You could
1473 also find the information near the top of a source file. For example,
1474 given a piece of software licensed under the GNU General Public
Andrew Geisslerc926e172021-05-07 16:11:35 -05001475 License version 2, you would set ``LICENSE`` as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001476
1477 LICENSE = "GPLv2"
1478
1479 The licenses you specify within ``LICENSE`` can have any name as long
1480 as you do not use spaces, since spaces are used as separators between
1481 license names. For standard licenses, use the names of the files in
1482 ``meta/files/common-licenses/`` or the ``SPDXLICENSEMAP`` flag names
1483 defined in ``meta/conf/licenses.conf``.
1484
1485- ``LIC_FILES_CHKSUM``: The OpenEmbedded build system uses this
1486 variable to make sure the license text has not changed. If it has,
1487 the build produces an error and it affords you the chance to figure
1488 it out and correct the problem.
1489
1490 You need to specify all applicable licensing files for the software.
1491 At the end of the configuration step, the build process will compare
1492 the checksums of the files to be sure the text has not changed. Any
1493 differences result in an error with the message containing the
1494 current checksum. For more explanation and examples of how to set the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001495 ``LIC_FILES_CHKSUM`` variable, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001496 ":ref:`dev-manual/common-tasks:tracking license changes`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001497
1498 To determine the correct checksum string, you can list the
1499 appropriate files in the ``LIC_FILES_CHKSUM`` variable with incorrect
1500 md5 strings, attempt to build the software, and then note the
1501 resulting error messages that will report the correct md5 strings.
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001502 See the ":ref:`dev-manual/common-tasks:fetching code`" section for
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001503 additional information.
1504
Andrew Geisslerc926e172021-05-07 16:11:35 -05001505 Here is an example that assumes the software has a ``COPYING`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001506
1507 LIC_FILES_CHKSUM = "file://COPYING;md5=xxx"
1508
1509 When you try to build the
1510 software, the build system will produce an error and give you the
1511 correct string that you can substitute into the recipe file for a
1512 subsequent build.
1513
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001514Dependencies
1515------------
1516
1517Most software packages have a short list of other packages that they
1518require, which are called dependencies. These dependencies fall into two
1519main categories: build-time dependencies, which are required when the
1520software is built; and runtime dependencies, which are required to be
1521installed on the target in order for the software to run.
1522
1523Within a recipe, you specify build-time dependencies using the
1524:term:`DEPENDS` variable. Although
1525nuances exist, items specified in ``DEPENDS`` should be names of other
1526recipes. It is important that you specify all build-time dependencies
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001527explicitly.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001528
1529Another consideration is that configure scripts might automatically
1530check for optional dependencies and enable corresponding functionality
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001531if those dependencies are found. If you wish to make a recipe that is
1532more generally useful (e.g. publish the recipe in a layer for others to
1533use), instead of hard-disabling the functionality, you can use the
1534:term:`PACKAGECONFIG` variable to allow functionality and the
1535corresponding dependencies to be enabled and disabled easily by other
1536users of the recipe.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001537
1538Similar to build-time dependencies, you specify runtime dependencies
1539through a variable -
1540:term:`RDEPENDS`, which is
1541package-specific. All variables that are package-specific need to have
1542the name of the package added to the end as an override. Since the main
1543package for a recipe has the same name as the recipe, and the recipe's
1544name can be found through the
1545``${``\ :term:`PN`\ ``}`` variable, then
1546you specify the dependencies for the main package by setting
1547``RDEPENDS_${PN}``. If the package were named ``${PN}-tools``, then you
1548would set ``RDEPENDS_${PN}-tools``, and so forth.
1549
1550Some runtime dependencies will be set automatically at packaging time.
1551These dependencies include any shared library dependencies (i.e. if a
1552package "example" contains "libexample" and another package "mypackage"
1553contains a binary that links to "libexample" then the OpenEmbedded build
1554system will automatically add a runtime dependency to "mypackage" on
1555"example"). See the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001556":ref:`overview-manual/concepts:automatically added runtime dependencies`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001557section in the Yocto Project Overview and Concepts Manual for further
1558details.
1559
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001560Configuring the Recipe
1561----------------------
1562
1563Most software provides some means of setting build-time configuration
1564options before compilation. Typically, setting these options is
1565accomplished by running a configure script with options, or by modifying
1566a build configuration file.
1567
1568.. note::
1569
1570 As of Yocto Project Release 1.7, some of the core recipes that
1571 package binary configuration scripts now disable the scripts due to
1572 the scripts previously requiring error-prone path substitution. The
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001573 OpenEmbedded build system uses ``pkg-config`` now, which is much more
1574 robust. You can find a list of the ``*-config`` scripts that are disabled
1575 in the ":ref:`migration-1.7-binary-configuration-scripts-disabled`" section
1576 in the Yocto Project Reference Manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001577
1578A major part of build-time configuration is about checking for
1579build-time dependencies and possibly enabling optional functionality as
1580a result. You need to specify any build-time dependencies for the
1581software you are building in your recipe's
1582:term:`DEPENDS` value, in terms of
1583other recipes that satisfy those dependencies. You can often find
1584build-time or runtime dependencies described in the software's
1585documentation.
1586
1587The following list provides configuration items of note based on how
1588your software is built:
1589
1590- *Autotools:* If your source files have a ``configure.ac`` file, then
1591 your software is built using Autotools. If this is the case, you just
1592 need to worry about modifying the configuration.
1593
1594 When using Autotools, your recipe needs to inherit the
1595 :ref:`autotools <ref-classes-autotools>` class
1596 and your recipe does not have to contain a
1597 :ref:`ref-tasks-configure` task.
1598 However, you might still want to make some adjustments. For example,
1599 you can set
1600 :term:`EXTRA_OECONF` or
1601 :term:`PACKAGECONFIG_CONFARGS`
1602 to pass any needed configure options that are specific to the recipe.
1603
1604- *CMake:* If your source files have a ``CMakeLists.txt`` file, then
1605 your software is built using CMake. If this is the case, you just
1606 need to worry about modifying the configuration.
1607
1608 When you use CMake, your recipe needs to inherit the
1609 :ref:`cmake <ref-classes-cmake>` class and your
1610 recipe does not have to contain a
1611 :ref:`ref-tasks-configure` task.
1612 You can make some adjustments by setting
1613 :term:`EXTRA_OECMAKE` to
1614 pass any needed configure options that are specific to the recipe.
1615
1616 .. note::
1617
1618 If you need to install one or more custom CMake toolchain files
1619 that are supplied by the application you are building, install the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001620 files to ``${D}${datadir}/cmake/Modules`` during ``do_install``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001621
1622- *Other:* If your source files do not have a ``configure.ac`` or
1623 ``CMakeLists.txt`` file, then your software is built using some
1624 method other than Autotools or CMake. If this is the case, you
1625 normally need to provide a
1626 :ref:`ref-tasks-configure` task
1627 in your recipe unless, of course, there is nothing to configure.
1628
1629 Even if your software is not being built by Autotools or CMake, you
1630 still might not need to deal with any configuration issues. You need
1631 to determine if configuration is even a required step. You might need
1632 to modify a Makefile or some configuration file used for the build to
1633 specify necessary build options. Or, perhaps you might need to run a
1634 provided, custom configure script with the appropriate options.
1635
1636 For the case involving a custom configure script, you would run
1637 ``./configure --help`` and look for the options you need to set.
1638
1639Once configuration succeeds, it is always good practice to look at the
1640``log.do_configure`` file to ensure that the appropriate options have
1641been enabled and no additional build-time dependencies need to be added
1642to ``DEPENDS``. For example, if the configure script reports that it
1643found something not mentioned in ``DEPENDS``, or that it did not find
1644something that it needed for some desired optional functionality, then
1645you would need to add those to ``DEPENDS``. Looking at the log might
1646also reveal items being checked for, enabled, or both that you do not
1647want, or items not being found that are in ``DEPENDS``, in which case
1648you would need to look at passing extra options to the configure script
1649as needed. For reference information on configure options specific to
1650the software you are building, you can consult the output of the
1651``./configure --help`` command within ``${S}`` or consult the software's
1652upstream documentation.
1653
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001654Using Headers to Interface with Devices
1655---------------------------------------
1656
1657If your recipe builds an application that needs to communicate with some
1658device or needs an API into a custom kernel, you will need to provide
1659appropriate header files. Under no circumstances should you ever modify
1660the existing
1661``meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc`` file.
1662These headers are used to build ``libc`` and must not be compromised
1663with custom or machine-specific header information. If you customize
1664``libc`` through modified headers all other applications that use
1665``libc`` thus become affected.
1666
1667.. note::
1668
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001669 Never copy and customize the ``libc`` header file (i.e.
1670 ``meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc``).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001671
1672The correct way to interface to a device or custom kernel is to use a
1673separate package that provides the additional headers for the driver or
1674other unique interfaces. When doing so, your application also becomes
1675responsible for creating a dependency on that specific provider.
1676
1677Consider the following:
1678
1679- Never modify ``linux-libc-headers.inc``. Consider that file to be
1680 part of the ``libc`` system, and not something you use to access the
1681 kernel directly. You should access ``libc`` through specific ``libc``
1682 calls.
1683
1684- Applications that must talk directly to devices should either provide
1685 necessary headers themselves, or establish a dependency on a special
1686 headers package that is specific to that driver.
1687
1688For example, suppose you want to modify an existing header that adds I/O
1689control or network support. If the modifications are used by a small
1690number programs, providing a unique version of a header is easy and has
1691little impact. When doing so, bear in mind the guidelines in the
1692previous list.
1693
1694.. note::
1695
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001696 If for some reason your changes need to modify the behavior of the ``libc``,
1697 and subsequently all other applications on the system, use a ``.bbappend``
1698 to modify the ``linux-kernel-headers.inc`` file. However, take care to not
1699 make the changes machine specific.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001700
1701Consider a case where your kernel is older and you need an older
1702``libc`` ABI. The headers installed by your recipe should still be a
1703standard mainline kernel, not your own custom one.
1704
1705When you use custom kernel headers you need to get them from
1706:term:`STAGING_KERNEL_DIR`,
1707which is the directory with kernel headers that are required to build
Andrew Geisslerc926e172021-05-07 16:11:35 -05001708out-of-tree modules. Your recipe will also need the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001709
1710 do_configure[depends] += "virtual/kernel:do_shared_workdir"
1711
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001712Compilation
1713-----------
1714
1715During a build, the ``do_compile`` task happens after source is fetched,
1716unpacked, and configured. If the recipe passes through ``do_compile``
1717successfully, nothing needs to be done.
1718
1719However, if the compile step fails, you need to diagnose the failure.
1720Here are some common issues that cause failures.
1721
1722.. note::
1723
1724 For cases where improper paths are detected for configuration files
1725 or for when libraries/headers cannot be found, be sure you are using
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001726 the more robust ``pkg-config``. See the note in section
Andrew Geissler09209ee2020-12-13 08:44:15 -06001727 ":ref:`dev-manual/common-tasks:Configuring the Recipe`" for additional information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001728
1729- *Parallel build failures:* These failures manifest themselves as
1730 intermittent errors, or errors reporting that a file or directory
1731 that should be created by some other part of the build process could
1732 not be found. This type of failure can occur even if, upon
1733 inspection, the file or directory does exist after the build has
1734 failed, because that part of the build process happened in the wrong
1735 order.
1736
1737 To fix the problem, you need to either satisfy the missing dependency
1738 in the Makefile or whatever script produced the Makefile, or (as a
Andrew Geisslerc926e172021-05-07 16:11:35 -05001739 workaround) set :term:`PARALLEL_MAKE` to an empty string::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001740
1741 PARALLEL_MAKE = ""
1742
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001743 For information on parallel Makefile issues, see the
1744 ":ref:`dev-manual/common-tasks:debugging parallel make races`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001745
1746- *Improper host path usage:* This failure applies to recipes building
1747 for the target or ``nativesdk`` only. The failure occurs when the
1748 compilation process uses improper headers, libraries, or other files
1749 from the host system when cross-compiling for the target.
1750
1751 To fix the problem, examine the ``log.do_compile`` file to identify
1752 the host paths being used (e.g. ``/usr/include``, ``/usr/lib``, and
1753 so forth) and then either add configure options, apply a patch, or do
1754 both.
1755
1756- *Failure to find required libraries/headers:* If a build-time
1757 dependency is missing because it has not been declared in
1758 :term:`DEPENDS`, or because the
1759 dependency exists but the path used by the build process to find the
1760 file is incorrect and the configure step did not detect it, the
1761 compilation process could fail. For either of these failures, the
1762 compilation process notes that files could not be found. In these
1763 cases, you need to go back and add additional options to the
1764 configure script as well as possibly add additional build-time
1765 dependencies to ``DEPENDS``.
1766
1767 Occasionally, it is necessary to apply a patch to the source to
1768 ensure the correct paths are used. If you need to specify paths to
1769 find files staged into the sysroot from other recipes, use the
1770 variables that the OpenEmbedded build system provides (e.g.
1771 ``STAGING_BINDIR``, ``STAGING_INCDIR``, ``STAGING_DATADIR``, and so
1772 forth).
1773
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001774Installing
1775----------
1776
1777During ``do_install``, the task copies the built files along with their
1778hierarchy to locations that would mirror their locations on the target
1779device. The installation process copies files from the
1780``${``\ :term:`S`\ ``}``,
1781``${``\ :term:`B`\ ``}``, and
1782``${``\ :term:`WORKDIR`\ ``}``
1783directories to the ``${``\ :term:`D`\ ``}``
1784directory to create the structure as it should appear on the target
1785system.
1786
1787How your software is built affects what you must do to be sure your
1788software is installed correctly. The following list describes what you
1789must do for installation depending on the type of build system used by
1790the software being built:
1791
1792- *Autotools and CMake:* If the software your recipe is building uses
1793 Autotools or CMake, the OpenEmbedded build system understands how to
1794 install the software. Consequently, you do not have to have a
1795 ``do_install`` task as part of your recipe. You just need to make
1796 sure the install portion of the build completes with no issues.
1797 However, if you wish to install additional files not already being
1798 installed by ``make install``, you should do this using a
1799 ``do_install_append`` function using the install command as described
1800 in the "Manual" bulleted item later in this list.
1801
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001802- *Other (using* ``make install``\ *)*: You need to define a ``do_install``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001803 function in your recipe. The function should call
1804 ``oe_runmake install`` and will likely need to pass in the
1805 destination directory as well. How you pass that path is dependent on
1806 how the ``Makefile`` being run is written (e.g. ``DESTDIR=${D}``,
1807 ``PREFIX=${D}``, ``INSTALLROOT=${D}``, and so forth).
1808
1809 For an example recipe using ``make install``, see the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001810 ":ref:`dev-manual/common-tasks:makefile-based package`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001811
1812- *Manual:* You need to define a ``do_install`` function in your
1813 recipe. The function must first use ``install -d`` to create the
1814 directories under
1815 ``${``\ :term:`D`\ ``}``. Once the
1816 directories exist, your function can use ``install`` to manually
1817 install the built software into the directories.
1818
1819 You can find more information on ``install`` at
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001820 https://www.gnu.org/software/coreutils/manual/html_node/install-invocation.html.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001821
1822For the scenarios that do not use Autotools or CMake, you need to track
1823the installation and diagnose and fix any issues until everything
1824installs correctly. You need to look in the default location of
1825``${D}``, which is ``${WORKDIR}/image``, to be sure your files have been
1826installed correctly.
1827
1828.. note::
1829
1830 - During the installation process, you might need to modify some of
1831 the installed files to suit the target layout. For example, you
1832 might need to replace hard-coded paths in an initscript with
1833 values of variables provided by the build system, such as
1834 replacing ``/usr/bin/`` with ``${bindir}``. If you do perform such
1835 modifications during ``do_install``, be sure to modify the
1836 destination file after copying rather than before copying.
1837 Modifying after copying ensures that the build system can
1838 re-execute ``do_install`` if needed.
1839
1840 - ``oe_runmake install``, which can be run directly or can be run
1841 indirectly by the
1842 :ref:`autotools <ref-classes-autotools>` and
1843 :ref:`cmake <ref-classes-cmake>` classes,
1844 runs ``make install`` in parallel. Sometimes, a Makefile can have
1845 missing dependencies between targets that can result in race
1846 conditions. If you experience intermittent failures during
1847 ``do_install``, you might be able to work around them by disabling
Andrew Geisslerc926e172021-05-07 16:11:35 -05001848 parallel Makefile installs by adding the following to the recipe::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001849
1850 PARALLEL_MAKEINST = ""
1851
1852 See :term:`PARALLEL_MAKEINST` for additional information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001853
1854 - If you need to install one or more custom CMake toolchain files
1855 that are supplied by the application you are building, install the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001856 files to ``${D}${datadir}/cmake/Modules`` during
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001857 :ref:`ref-tasks-install`.
1858
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001859Enabling System Services
1860------------------------
1861
1862If you want to install a service, which is a process that usually starts
1863on boot and runs in the background, then you must include some
1864additional definitions in your recipe.
1865
1866If you are adding services and the service initialization script or the
1867service file itself is not installed, you must provide for that
1868installation in your recipe using a ``do_install_append`` function. If
1869your recipe already has a ``do_install`` function, update the function
1870near its end rather than adding an additional ``do_install_append``
1871function.
1872
1873When you create the installation for your services, you need to
1874accomplish what is normally done by ``make install``. In other words,
1875make sure your installation arranges the output similar to how it is
1876arranged on the target system.
1877
1878The OpenEmbedded build system provides support for starting services two
1879different ways:
1880
1881- *SysVinit:* SysVinit is a system and service manager that manages the
1882 init system used to control the very basic functions of your system.
1883 The init program is the first program started by the Linux kernel
1884 when the system boots. Init then controls the startup, running and
1885 shutdown of all other programs.
1886
1887 To enable a service using SysVinit, your recipe needs to inherit the
1888 :ref:`update-rc.d <ref-classes-update-rc.d>`
1889 class. The class helps facilitate safely installing the package on
1890 the target.
1891
1892 You will need to set the
1893 :term:`INITSCRIPT_PACKAGES`,
1894 :term:`INITSCRIPT_NAME`,
1895 and
1896 :term:`INITSCRIPT_PARAMS`
1897 variables within your recipe.
1898
1899- *systemd:* System Management Daemon (systemd) was designed to replace
1900 SysVinit and to provide enhanced management of services. For more
1901 information on systemd, see the systemd homepage at
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001902 https://freedesktop.org/wiki/Software/systemd/.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001903
1904 To enable a service using systemd, your recipe needs to inherit the
1905 :ref:`systemd <ref-classes-systemd>` class. See
1906 the ``systemd.bbclass`` file located in your :term:`Source Directory`
1907 section for
1908 more information.
1909
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001910Packaging
1911---------
1912
1913Successful packaging is a combination of automated processes performed
1914by the OpenEmbedded build system and some specific steps you need to
1915take. The following list describes the process:
1916
1917- *Splitting Files*: The ``do_package`` task splits the files produced
1918 by the recipe into logical components. Even software that produces a
1919 single binary might still have debug symbols, documentation, and
1920 other logical components that should be split out. The ``do_package``
1921 task ensures that files are split up and packaged correctly.
1922
1923- *Running QA Checks*: The
1924 :ref:`insane <ref-classes-insane>` class adds a
1925 step to the package generation process so that output quality
1926 assurance checks are generated by the OpenEmbedded build system. This
1927 step performs a range of checks to be sure the build's output is free
1928 of common problems that show up during runtime. For information on
1929 these checks, see the
1930 :ref:`insane <ref-classes-insane>` class and
Andrew Geissler09209ee2020-12-13 08:44:15 -06001931 the ":ref:`ref-manual/qa-checks:qa error and warning messages`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001932 chapter in the Yocto Project Reference Manual.
1933
1934- *Hand-Checking Your Packages*: After you build your software, you
1935 need to be sure your packages are correct. Examine the
1936 ``${``\ :term:`WORKDIR`\ ``}/packages-split``
1937 directory and make sure files are where you expect them to be. If you
1938 discover problems, you can set
1939 :term:`PACKAGES`,
1940 :term:`FILES`,
1941 ``do_install(_append)``, and so forth as needed.
1942
1943- *Splitting an Application into Multiple Packages*: If you need to
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001944 split an application into several packages, see the
1945 ":ref:`dev-manual/common-tasks:splitting an application into multiple packages`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001946 section for an example.
1947
1948- *Installing a Post-Installation Script*: For an example showing how
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001949 to install a post-installation script, see the
1950 ":ref:`dev-manual/common-tasks:post-installation scripts`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001951
1952- *Marking Package Architecture*: Depending on what your recipe is
1953 building and how it is configured, it might be important to mark the
1954 packages produced as being specific to a particular machine, or to
1955 mark them as not being specific to a particular machine or
1956 architecture at all.
1957
1958 By default, packages apply to any machine with the same architecture
1959 as the target machine. When a recipe produces packages that are
1960 machine-specific (e.g. the
1961 :term:`MACHINE` value is passed
1962 into the configure script or a patch is applied only for a particular
1963 machine), you should mark them as such by adding the following to the
Andrew Geisslerc926e172021-05-07 16:11:35 -05001964 recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001965
1966 PACKAGE_ARCH = "${MACHINE_ARCH}"
1967
1968 On the other hand, if the recipe produces packages that do not
1969 contain anything specific to the target machine or architecture at
1970 all (e.g. recipes that simply package script files or configuration
1971 files), you should use the
1972 :ref:`allarch <ref-classes-allarch>` class to
Andrew Geisslerc926e172021-05-07 16:11:35 -05001973 do this for you by adding this to your recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001974
1975 inherit allarch
1976
1977 Ensuring that the package architecture is correct is not critical
1978 while you are doing the first few builds of your recipe. However, it
1979 is important in order to ensure that your recipe rebuilds (or does
1980 not rebuild) appropriately in response to changes in configuration,
1981 and to ensure that you get the appropriate packages installed on the
1982 target machine, particularly if you run separate builds for more than
1983 one target machine.
1984
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001985Sharing Files Between Recipes
1986-----------------------------
1987
1988Recipes often need to use files provided by other recipes on the build
1989host. For example, an application linking to a common library needs
1990access to the library itself and its associated headers. The way this
1991access is accomplished is by populating a sysroot with files. Each
1992recipe has two sysroots in its work directory, one for target files
1993(``recipe-sysroot``) and one for files that are native to the build host
1994(``recipe-sysroot-native``).
1995
1996.. note::
1997
1998 You could find the term "staging" used within the Yocto project
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001999 regarding files populating sysroots (e.g. the :term:`STAGING_DIR`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002000 variable).
2001
2002Recipes should never populate the sysroot directly (i.e. write files
2003into sysroot). Instead, files should be installed into standard
2004locations during the
2005:ref:`ref-tasks-install` task within
2006the ``${``\ :term:`D`\ ``}`` directory. The
2007reason for this limitation is that almost all files that populate the
2008sysroot are cataloged in manifests in order to ensure the files can be
2009removed later when a recipe is either modified or removed. Thus, the
2010sysroot is able to remain free from stale files.
2011
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05002012A subset of the files installed by the :ref:`ref-tasks-install` task are
2013used by the :ref:`ref-tasks-populate_sysroot` task as defined by the the
2014:term:`SYSROOT_DIRS` variable to automatically populate the sysroot. It
2015is possible to modify the list of directories that populate the sysroot.
2016The following example shows how you could add the ``/opt`` directory to
Andrew Geisslerc926e172021-05-07 16:11:35 -05002017the list of directories within a recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002018
2019 SYSROOT_DIRS += "/opt"
2020
Andrew Geisslerd1e89492021-02-12 15:35:20 -06002021.. note::
2022
2023 The `/sysroot-only` is to be used by recipes that generate artifacts
2024 that are not included in the target filesystem, allowing them to share
2025 these artifacts without needing to use the ``DEPLOY_DIR``.
2026
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05002027For a more complete description of the :ref:`ref-tasks-populate_sysroot`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002028task and its associated functions, see the
2029:ref:`staging <ref-classes-staging>` class.
2030
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002031Using Virtual Providers
2032-----------------------
2033
2034Prior to a build, if you know that several different recipes provide the
2035same functionality, you can use a virtual provider (i.e. ``virtual/*``)
2036as a placeholder for the actual provider. The actual provider is
2037determined at build-time.
2038
2039A common scenario where a virtual provider is used would be for the
2040kernel recipe. Suppose you have three kernel recipes whose
2041:term:`PN` values map to ``kernel-big``,
2042``kernel-mid``, and ``kernel-small``. Furthermore, each of these recipes
2043in some way uses a :term:`PROVIDES`
2044statement that essentially identifies itself as being able to provide
2045``virtual/kernel``. Here is one way through the
Andrew Geisslerc926e172021-05-07 16:11:35 -05002046:ref:`kernel <ref-classes-kernel>` class::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002047
2048 PROVIDES += "${@ "virtual/kernel" if (d.getVar("KERNEL_PACKAGE_NAME") == "kernel") else "" }"
2049
2050Any recipe that inherits the ``kernel`` class is
2051going to utilize a ``PROVIDES`` statement that identifies that recipe as
2052being able to provide the ``virtual/kernel`` item.
2053
2054Now comes the time to actually build an image and you need a kernel
2055recipe, but which one? You can configure your build to call out the
Andrew Geissler09209ee2020-12-13 08:44:15 -06002056kernel recipe you want by using the :term:`PREFERRED_PROVIDER` variable. As
2057an example, consider the :yocto_git:`x86-base.inc
2058</poky/tree/meta/conf/machine/include/x86-base.inc>` include file, which is a
2059machine (i.e. :term:`MACHINE`) configuration file. This include file is the
2060reason all x86-based machines use the ``linux-yocto`` kernel. Here are the
Andrew Geisslerc926e172021-05-07 16:11:35 -05002061relevant lines from the include file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002062
2063 PREFERRED_PROVIDER_virtual/kernel ??= "linux-yocto"
2064 PREFERRED_VERSION_linux-yocto ??= "4.15%"
2065
2066When you use a virtual provider, you do not have to "hard code" a recipe
2067name as a build dependency. You can use the
2068:term:`DEPENDS` variable to state the
Andrew Geisslerc926e172021-05-07 16:11:35 -05002069build is dependent on ``virtual/kernel`` for example::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002070
2071 DEPENDS = "virtual/kernel"
2072
2073During the build, the OpenEmbedded build system picks
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002074the correct recipe needed for the ``virtual/kernel`` dependency based on
2075the ``PREFERRED_PROVIDER`` variable. If you want to use the small kernel
2076mentioned at the beginning of this section, configure your build as
Andrew Geisslerc926e172021-05-07 16:11:35 -05002077follows::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002078
2079 PREFERRED_PROVIDER_virtual/kernel ??= "kernel-small"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002080
2081.. note::
2082
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002083 Any recipe that ``PROVIDES`` a ``virtual/*`` item that is ultimately not
2084 selected through ``PREFERRED_PROVIDER`` does not get built. Preventing these
2085 recipes from building is usually the desired behavior since this mechanism's
2086 purpose is to select between mutually exclusive alternative providers.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002087
2088The following lists specific examples of virtual providers:
2089
2090- ``virtual/kernel``: Provides the name of the kernel recipe to use
2091 when building a kernel image.
2092
2093- ``virtual/bootloader``: Provides the name of the bootloader to use
2094 when building an image.
2095
2096- ``virtual/libgbm``: Provides ``gbm.pc``.
2097
2098- ``virtual/egl``: Provides ``egl.pc`` and possibly ``wayland-egl.pc``.
2099
2100- ``virtual/libgl``: Provides ``gl.pc`` (i.e. libGL).
2101
2102- ``virtual/libgles1``: Provides ``glesv1_cm.pc`` (i.e. libGLESv1_CM).
2103
2104- ``virtual/libgles2``: Provides ``glesv2.pc`` (i.e. libGLESv2).
2105
2106.. note::
2107
2108 Virtual providers only apply to build time dependencies specified with
2109 :term:`PROVIDES` and :term:`DEPENDS`. They do not apply to runtime
2110 dependencies specified with :term:`RPROVIDES` and :term:`RDEPENDS`.
2111
2112Properly Versioning Pre-Release Recipes
2113---------------------------------------
2114
2115Sometimes the name of a recipe can lead to versioning problems when the
2116recipe is upgraded to a final release. For example, consider the
2117``irssi_0.8.16-rc1.bb`` recipe file in the list of example recipes in
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05002118the ":ref:`dev-manual/common-tasks:storing and naming the recipe`" section.
2119This recipe is at a release candidate stage (i.e. "rc1"). When the recipe is
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002120released, the recipe filename becomes ``irssi_0.8.16.bb``. The version
2121change from ``0.8.16-rc1`` to ``0.8.16`` is seen as a decrease by the
2122build system and package managers, so the resulting packages will not
2123correctly trigger an upgrade.
2124
2125In order to ensure the versions compare properly, the recommended
2126convention is to set :term:`PV` within the
2127recipe to "previous_version+current_version". You can use an additional
2128variable so that you can use the current version elsewhere. Here is an
Andrew Geisslerc926e172021-05-07 16:11:35 -05002129example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002130
2131 REALPV = "0.8.16-rc1"
2132 PV = "0.8.15+${REALPV}"
2133
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002134Post-Installation Scripts
2135-------------------------
2136
2137Post-installation scripts run immediately after installing a package on
2138the target or during image creation when a package is included in an
2139image. To add a post-installation script to a package, add a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002140``pkg_postinst_``\ `PACKAGENAME`\ ``()`` function to the recipe file
2141(``.bb``) and replace `PACKAGENAME` with the name of the package you want
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002142to attach to the ``postinst`` script. To apply the post-installation
2143script to the main package for the recipe, which is usually what is
2144required, specify
2145``${``\ :term:`PN`\ ``}`` in place of
2146PACKAGENAME.
2147
Andrew Geisslerc926e172021-05-07 16:11:35 -05002148A post-installation function has the following structure::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002149
2150 pkg_postinst_PACKAGENAME() {
2151 # Commands to carry out
2152 }
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002153
2154The script defined in the post-installation function is called when the
2155root filesystem is created. If the script succeeds, the package is
2156marked as installed.
2157
2158.. note::
2159
2160 Any RPM post-installation script that runs on the target should
2161 return a 0 exit code. RPM does not allow non-zero exit codes for
2162 these scripts, and the RPM package manager will cause the package to
2163 fail installation on the target.
2164
2165Sometimes it is necessary for the execution of a post-installation
2166script to be delayed until the first boot. For example, the script might
2167need to be executed on the device itself. To delay script execution
2168until boot time, you must explicitly mark post installs to defer to the
2169target. You can use ``pkg_postinst_ontarget()`` or call
2170``postinst_intercept delay_to_first_boot`` from ``pkg_postinst()``. Any
2171failure of a ``pkg_postinst()`` script (including exit 1) triggers an
2172error during the
2173:ref:`ref-tasks-rootfs` task.
2174
2175If you have recipes that use ``pkg_postinst`` function and they require
2176the use of non-standard native tools that have dependencies during
2177rootfs construction, you need to use the
2178:term:`PACKAGE_WRITE_DEPS`
2179variable in your recipe to list these tools. If you do not use this
2180variable, the tools might be missing and execution of the
2181post-installation script is deferred until first boot. Deferring the
2182script to first boot is undesirable and for read-only rootfs impossible.
2183
2184.. note::
2185
2186 Equivalent support for pre-install, pre-uninstall, and post-uninstall
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002187 scripts exist by way of ``pkg_preinst``, ``pkg_prerm``, and ``pkg_postrm``,
2188 respectively. These scrips work in exactly the same way as does
2189 ``pkg_postinst`` with the exception that they run at different times. Also,
2190 because of when they run, they are not applicable to being run at image
2191 creation time like ``pkg_postinst``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002192
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002193Testing
2194-------
2195
2196The final step for completing your recipe is to be sure that the
2197software you built runs correctly. To accomplish runtime testing, add
2198the build's output packages to your image and test them on the target.
2199
2200For information on how to customize your image by adding specific
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05002201packages, see ":ref:`dev-manual/common-tasks:customizing images`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002202
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002203Examples
2204--------
2205
2206To help summarize how to write a recipe, this section provides some
2207examples given various scenarios:
2208
2209- Recipes that use local files
2210
2211- Using an Autotooled package
2212
2213- Using a Makefile-based package
2214
2215- Splitting an application into multiple packages
2216
2217- Adding binaries to an image
2218
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002219Single .c File Package (Hello World!)
2220~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2221
2222Building an application from a single file that is stored locally (e.g.
2223under ``files``) requires a recipe that has the file listed in the
2224``SRC_URI`` variable. Additionally, you need to manually write the
2225``do_compile`` and ``do_install`` tasks. The ``S`` variable defines the
2226directory containing the source code, which is set to
2227:term:`WORKDIR` in this case - the
2228directory BitBake uses for the build.
2229::
2230
2231 SUMMARY = "Simple helloworld application"
2232 SECTION = "examples"
2233 LICENSE = "MIT"
2234 LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
2235
2236 SRC_URI = "file://helloworld.c"
2237
2238 S = "${WORKDIR}"
2239
2240 do_compile() {
Andrew Geisslerd1e89492021-02-12 15:35:20 -06002241 ${CC} ${LDFLAGS} helloworld.c -o helloworld
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002242 }
2243
2244 do_install() {
2245 install -d ${D}${bindir}
2246 install -m 0755 helloworld ${D}${bindir}
2247 }
2248
2249By default, the ``helloworld``, ``helloworld-dbg``, and
2250``helloworld-dev`` packages are built. For information on how to
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05002251customize the packaging process, see the
2252":ref:`dev-manual/common-tasks:splitting an application into multiple packages`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002253section.
2254
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002255Autotooled Package
2256~~~~~~~~~~~~~~~~~~
2257
2258Applications that use Autotools such as ``autoconf`` and ``automake``
2259require a recipe that has a source archive listed in ``SRC_URI`` and
2260also inherit the
2261:ref:`autotools <ref-classes-autotools>` class,
2262which contains the definitions of all the steps needed to build an
2263Autotool-based application. The result of the build is automatically
2264packaged. And, if the application uses NLS for localization, packages
2265with local information are generated (one package per language).
2266Following is one example: (``hello_2.3.bb``)
2267::
2268
2269 SUMMARY = "GNU Helloworld application"
2270 SECTION = "examples"
2271 LICENSE = "GPLv2+"
2272 LIC_FILES_CHKSUM = "file://COPYING;md5=751419260aa954499f7abaabaa882bbe"
2273
2274 SRC_URI = "${GNU_MIRROR}/hello/hello-${PV}.tar.gz"
2275
2276 inherit autotools gettext
2277
2278The variable ``LIC_FILES_CHKSUM`` is used to track source license
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002279changes as described in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06002280":ref:`dev-manual/common-tasks:tracking license changes`" section in
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002281the Yocto Project Overview and Concepts Manual. You can quickly create
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002282Autotool-based recipes in a manner similar to the previous example.
2283
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002284Makefile-Based Package
2285~~~~~~~~~~~~~~~~~~~~~~
2286
2287Applications that use GNU ``make`` also require a recipe that has the
2288source archive listed in ``SRC_URI``. You do not need to add a
2289``do_compile`` step since by default BitBake starts the ``make`` command
2290to compile the application. If you need additional ``make`` options, you
2291should store them in the
2292:term:`EXTRA_OEMAKE` or
2293:term:`PACKAGECONFIG_CONFARGS`
2294variables. BitBake passes these options into the GNU ``make``
2295invocation. Note that a ``do_install`` task is still required.
2296Otherwise, BitBake runs an empty ``do_install`` task by default.
2297
2298Some applications might require extra parameters to be passed to the
2299compiler. For example, the application might need an additional header
2300path. You can accomplish this by adding to the ``CFLAGS`` variable. The
Andrew Geisslerc926e172021-05-07 16:11:35 -05002301following example shows this::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002302
2303 CFLAGS_prepend = "-I ${S}/include "
2304
Andrew Geisslerc926e172021-05-07 16:11:35 -05002305In the following example, ``mtd-utils`` is a makefile-based package::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002306
2307 SUMMARY = "Tools for managing memory technology devices"
2308 SECTION = "base"
2309 DEPENDS = "zlib lzo e2fsprogs util-linux"
2310 HOMEPAGE = "http://www.linux-mtd.infradead.org/"
2311 LICENSE = "GPLv2+"
2312 LIC_FILES_CHKSUM = "file://COPYING;md5=0636e73ff0215e8d672dc4c32c317bb3 \
2313 file://include/common.h;beginline=1;endline=17;md5=ba05b07912a44ea2bf81ce409380049c"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002314
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002315 # Use the latest version at 26 Oct, 2013
2316 SRCREV = "9f107132a6a073cce37434ca9cda6917dd8d866b"
2317 SRC_URI = "git://git.infradead.org/mtd-utils.git \
2318 file://add-exclusion-to-mkfs-jffs2-git-2.patch \
2319 "
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002320
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002321 PV = "1.5.1+git${SRCPV}"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002322
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002323 S = "${WORKDIR}/git"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002324
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002325 EXTRA_OEMAKE = "'CC=${CC}' 'RANLIB=${RANLIB}' 'AR=${AR}' 'CFLAGS=${CFLAGS} -I${S}/include -DWITHOUT_XATTR' 'BUILDDIR=${S}'"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002326
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002327 do_install () {
2328 oe_runmake install DESTDIR=${D} SBINDIR=${sbindir} MANDIR=${mandir} INCLUDEDIR=${includedir}
2329 }
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002330
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002331 PACKAGES =+ "mtd-utils-jffs2 mtd-utils-ubifs mtd-utils-misc"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002332
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002333 FILES_mtd-utils-jffs2 = "${sbindir}/mkfs.jffs2 ${sbindir}/jffs2dump ${sbindir}/jffs2reader ${sbindir}/sumtool"
2334 FILES_mtd-utils-ubifs = "${sbindir}/mkfs.ubifs ${sbindir}/ubi*"
2335 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 -05002336
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002337 PARALLEL_MAKE = ""
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002338
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002339 BBCLASSEXTEND = "native"
2340
2341Splitting an Application into Multiple Packages
2342~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2343
2344You can use the variables ``PACKAGES`` and ``FILES`` to split an
2345application into multiple packages.
2346
2347Following is an example that uses the ``libxpm`` recipe. By default,
2348this recipe generates a single package that contains the library along
2349with a few binaries. You can modify the recipe to split the binaries
Andrew Geisslerc926e172021-05-07 16:11:35 -05002350into separate packages::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002351
2352 require xorg-lib-common.inc
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002353
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002354 SUMMARY = "Xpm: X Pixmap extension library"
2355 LICENSE = "BSD"
2356 LIC_FILES_CHKSUM = "file://COPYING;md5=51f4270b012ecd4ab1a164f5f4ed6cf7"
2357 DEPENDS += "libxext libsm libxt"
2358 PE = "1"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002359
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002360 XORG_PN = "libXpm"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002361
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002362 PACKAGES =+ "sxpm cxpm"
2363 FILES_cxpm = "${bindir}/cxpm"
2364 FILES_sxpm = "${bindir}/sxpm"
2365
2366In the previous example, we want to ship the ``sxpm`` and ``cxpm``
2367binaries in separate packages. Since ``bindir`` would be packaged into
2368the main ``PN`` package by default, we prepend the ``PACKAGES`` variable
2369so additional package names are added to the start of list. This results
2370in the extra ``FILES_*`` variables then containing information that
2371define which files and directories go into which packages. Files
2372included by earlier packages are skipped by latter packages. Thus, the
2373main ``PN`` package does not include the above listed files.
2374
2375Packaging Externally Produced Binaries
2376~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2377
2378Sometimes, you need to add pre-compiled binaries to an image. For
2379example, suppose that binaries for proprietary code exist, which are
2380created by a particular division of a company. Your part of the company
2381needs to use those binaries as part of an image that you are building
2382using the OpenEmbedded build system. Since you only have the binaries
2383and not the source code, you cannot use a typical recipe that expects to
2384fetch the source specified in
2385:term:`SRC_URI` and then compile it.
2386
2387One method is to package the binaries and then install them as part of
2388the image. Generally, it is not a good idea to package binaries since,
2389among other things, it can hinder the ability to reproduce builds and
2390could lead to compatibility problems with ABI in the future. However,
2391sometimes you have no choice.
2392
2393The easiest solution is to create a recipe that uses the
2394:ref:`bin_package <ref-classes-bin-package>` class
2395and to be sure that you are using default locations for build artifacts.
2396In most cases, the ``bin_package`` class handles "skipping" the
2397configure and compile steps as well as sets things up to grab packages
2398from the appropriate area. In particular, this class sets ``noexec`` on
2399both the :ref:`ref-tasks-configure`
2400and :ref:`ref-tasks-compile` tasks,
2401sets ``FILES_${PN}`` to "/" so that it picks up all files, and sets up a
2402:ref:`ref-tasks-install` task, which
2403effectively copies all files from ``${S}`` to ``${D}``. The
2404``bin_package`` class works well when the files extracted into ``${S}``
2405are already laid out in the way they should be laid out on the target.
2406For more information on these variables, see the
2407:term:`FILES`,
2408:term:`PN`,
2409:term:`S`, and
2410:term:`D` variables in the Yocto Project
2411Reference Manual's variable glossary.
2412
2413.. note::
2414
2415 - Using :term:`DEPENDS` is a good
2416 idea even for components distributed in binary form, and is often
2417 necessary for shared libraries. For a shared library, listing the
2418 library dependencies in ``DEPENDS`` makes sure that the libraries
2419 are available in the staging sysroot when other recipes link
2420 against the library, which might be necessary for successful
2421 linking.
2422
2423 - Using ``DEPENDS`` also allows runtime dependencies between
2424 packages to be added automatically. See the
Andrew Geissler09209ee2020-12-13 08:44:15 -06002425 ":ref:`overview-manual/concepts:automatically added runtime dependencies`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002426 section in the Yocto Project Overview and Concepts Manual for more
2427 information.
2428
2429If you cannot use the ``bin_package`` class, you need to be sure you are
2430doing the following:
2431
2432- Create a recipe where the
2433 :ref:`ref-tasks-configure` and
2434 :ref:`ref-tasks-compile` tasks do
2435 nothing: It is usually sufficient to just not define these tasks in
2436 the recipe, because the default implementations do nothing unless a
2437 Makefile is found in
2438 ``${``\ :term:`S`\ ``}``.
2439
2440 If ``${S}`` might contain a Makefile, or if you inherit some class
2441 that replaces ``do_configure`` and ``do_compile`` with custom
2442 versions, then you can use the
2443 ``[``\ :ref:`noexec <bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ``]``
Andrew Geisslerc926e172021-05-07 16:11:35 -05002444 flag to turn the tasks into no-ops, as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002445
2446 do_configure[noexec] = "1"
2447 do_compile[noexec] = "1"
2448
2449 Unlike
2450 :ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:deleting a task`,
2451 using the flag preserves the dependency chain from the
2452 :ref:`ref-tasks-fetch`,
2453 :ref:`ref-tasks-unpack`, and
2454 :ref:`ref-tasks-patch` tasks to the
2455 :ref:`ref-tasks-install` task.
2456
2457- Make sure your ``do_install`` task installs the binaries
2458 appropriately.
2459
2460- Ensure that you set up :term:`FILES`
2461 (usually
2462 ``FILES_${``\ :term:`PN`\ ``}``) to
2463 point to the files you have installed, which of course depends on
2464 where you have installed them and whether those files are in
2465 different locations than the defaults.
2466
Andrew Geissler6ce62a22020-11-30 19:58:47 -06002467.. note::
2468
2469 If image prelinking is enabled (e.g. "image-prelink" is in :term:`USER_CLASSES`
2470 which it is by default), prelink will change the binaries in the generated images
2471 and this often catches people out. Remove that class to ensure binaries are
2472 preserved exactly if that is necessary.
2473
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002474Following Recipe Style Guidelines
2475---------------------------------
2476
2477When writing recipes, it is good to conform to existing style
Andrew Geisslerd1e89492021-02-12 15:35:20 -06002478guidelines. The :oe_wiki:`OpenEmbedded Styleguide </Styleguide>` wiki page
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002479provides rough guidelines for preferred recipe style.
2480
2481It is common for existing recipes to deviate a bit from this style.
2482However, aiming for at least a consistent style is a good idea. Some
2483practices, such as omitting spaces around ``=`` operators in assignments
2484or ordering recipe components in an erratic way, are widely seen as poor
2485style.
2486
2487Recipe Syntax
2488-------------
2489
2490Understanding recipe file syntax is important for writing recipes. The
2491following list overviews the basic items that make up a BitBake recipe
2492file. For more complete BitBake syntax descriptions, see the
2493":doc:`bitbake-user-manual/bitbake-user-manual-metadata`"
2494chapter of the BitBake User Manual.
2495
2496- *Variable Assignments and Manipulations:* Variable assignments allow
2497 a value to be assigned to a variable. The assignment can be static
2498 text or might include the contents of other variables. In addition to
2499 the assignment, appending and prepending operations are also
2500 supported.
2501
2502 The following example shows some of the ways you can use variables in
Andrew Geisslerc926e172021-05-07 16:11:35 -05002503 recipes::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002504
2505 S = "${WORKDIR}/postfix-${PV}"
2506 CFLAGS += "-DNO_ASM"
2507 SRC_URI_append = " file://fixup.patch"
2508
2509- *Functions:* Functions provide a series of actions to be performed.
2510 You usually use functions to override the default implementation of a
2511 task function or to complement a default function (i.e. append or
2512 prepend to an existing function). Standard functions use ``sh`` shell
2513 syntax, although access to OpenEmbedded variables and internal
2514 methods are also available.
2515
Andrew Geisslerc926e172021-05-07 16:11:35 -05002516 The following is an example function from the ``sed`` recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002517
2518 do_install () {
2519 autotools_do_install
2520 install -d ${D}${base_bindir}
2521 mv ${D}${bindir}/sed ${D}${base_bindir}/sed
2522 rmdir ${D}${bindir}/
2523 }
2524
2525 It is
2526 also possible to implement new functions that are called between
2527 existing tasks as long as the new functions are not replacing or
2528 complementing the default functions. You can implement functions in
2529 Python instead of shell. Both of these options are not seen in the
2530 majority of recipes.
2531
2532- *Keywords:* BitBake recipes use only a few keywords. You use keywords
2533 to include common functions (``inherit``), load parts of a recipe
2534 from other files (``include`` and ``require``) and export variables
2535 to the environment (``export``).
2536
Andrew Geisslerc926e172021-05-07 16:11:35 -05002537 The following example shows the use of some of these keywords::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002538
2539 export POSTCONF = "${STAGING_BINDIR}/postconf"
2540 inherit autoconf
2541 require otherfile.inc
2542
2543- *Comments (#):* Any lines that begin with the hash character (``#``)
Andrew Geisslerc926e172021-05-07 16:11:35 -05002544 are treated as comment lines and are ignored::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002545
2546 # This is a comment
2547
2548This next list summarizes the most important and most commonly used
2549parts of the recipe syntax. For more information on these parts of the
2550syntax, you can reference the
2551:doc:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata` chapter
2552in the BitBake User Manual.
2553
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002554- *Line Continuation (\\):* Use the backward slash (``\``) character to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002555 split a statement over multiple lines. Place the slash character at
Andrew Geisslerc926e172021-05-07 16:11:35 -05002556 the end of the line that is to be continued on the next line::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002557
2558 VAR = "A really long \
2559 line"
2560
2561 .. note::
2562
2563 You cannot have any characters including spaces or tabs after the
2564 slash character.
2565
2566- *Using Variables (${VARNAME}):* Use the ``${VARNAME}`` syntax to
Andrew Geisslerc926e172021-05-07 16:11:35 -05002567 access the contents of a variable::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002568
2569 SRC_URI = "${SOURCEFORGE_MIRROR}/libpng/zlib-${PV}.tar.gz"
2570
2571 .. note::
2572
2573 It is important to understand that the value of a variable
2574 expressed in this form does not get substituted automatically. The
2575 expansion of these expressions happens on-demand later (e.g.
2576 usually when a function that makes reference to the variable
2577 executes). This behavior ensures that the values are most
2578 appropriate for the context in which they are finally used. On the
2579 rare occasion that you do need the variable expression to be
2580 expanded immediately, you can use the
2581 :=
2582 operator instead of
2583 =
2584 when you make the assignment, but this is not generally needed.
2585
2586- *Quote All Assignments ("value"):* Use double quotes around values in
Andrew Geisslerc926e172021-05-07 16:11:35 -05002587 all variable assignments (e.g. ``"value"``). Following is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002588
2589 VAR1 = "${OTHERVAR}"
2590 VAR2 = "The version is ${PV}"
2591
2592- *Conditional Assignment (?=):* Conditional assignment is used to
2593 assign a value to a variable, but only when the variable is currently
2594 unset. Use the question mark followed by the equal sign (``?=``) to
2595 make a "soft" assignment used for conditional assignment. Typically,
2596 "soft" assignments are used in the ``local.conf`` file for variables
2597 that are allowed to come through from the external environment.
2598
2599 Here is an example where ``VAR1`` is set to "New value" if it is
2600 currently empty. However, if ``VAR1`` has already been set, it
Andrew Geisslerc926e172021-05-07 16:11:35 -05002601 remains unchanged::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002602
2603 VAR1 ?= "New value"
2604
Andrew Geisslerc926e172021-05-07 16:11:35 -05002605 In this next example, ``VAR1`` is left with the value "Original value"::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002606
2607 VAR1 = "Original value"
2608 VAR1 ?= "New value"
2609
2610- *Appending (+=):* Use the plus character followed by the equals sign
2611 (``+=``) to append values to existing variables.
2612
2613 .. note::
2614
2615 This operator adds a space between the existing content of the
2616 variable and the new content.
2617
Andrew Geisslerc926e172021-05-07 16:11:35 -05002618 Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002619
2620 SRC_URI += "file://fix-makefile.patch"
2621
2622- *Prepending (=+):* Use the equals sign followed by the plus character
2623 (``=+``) to prepend values to existing variables.
2624
2625 .. note::
2626
2627 This operator adds a space between the new content and the
2628 existing content of the variable.
2629
Andrew Geisslerc926e172021-05-07 16:11:35 -05002630 Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002631
2632 VAR =+ "Starts"
2633
2634- *Appending (_append):* Use the ``_append`` operator to append values
2635 to existing variables. This operator does not add any additional
2636 space. Also, the operator is applied after all the ``+=``, and ``=+``
2637 operators have been applied and after all ``=`` assignments have
2638 occurred.
2639
2640 The following example shows the space being explicitly added to the
2641 start to ensure the appended value is not merged with the existing
Andrew Geisslerc926e172021-05-07 16:11:35 -05002642 value::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002643
2644 SRC_URI_append = " file://fix-makefile.patch"
2645
2646 You can also use
2647 the ``_append`` operator with overrides, which results in the actions
Andrew Geisslerc926e172021-05-07 16:11:35 -05002648 only being performed for the specified target or machine::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002649
2650 SRC_URI_append_sh4 = " file://fix-makefile.patch"
2651
2652- *Prepending (_prepend):* Use the ``_prepend`` operator to prepend
2653 values to existing variables. This operator does not add any
2654 additional space. Also, the operator is applied after all the ``+=``,
2655 and ``=+`` operators have been applied and after all ``=``
2656 assignments have occurred.
2657
2658 The following example shows the space being explicitly added to the
2659 end to ensure the prepended value is not merged with the existing
Andrew Geisslerc926e172021-05-07 16:11:35 -05002660 value::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002661
2662 CFLAGS_prepend = "-I${S}/myincludes "
2663
2664 You can also use the
2665 ``_prepend`` operator with overrides, which results in the actions
Andrew Geisslerc926e172021-05-07 16:11:35 -05002666 only being performed for the specified target or machine::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002667
2668 CFLAGS_prepend_sh4 = "-I${S}/myincludes "
2669
2670- *Overrides:* You can use overrides to set a value conditionally,
2671 typically based on how the recipe is being built. For example, to set
2672 the :term:`KBRANCH` variable's
2673 value to "standard/base" for any target
2674 :term:`MACHINE`, except for
2675 qemuarm where it should be set to "standard/arm-versatile-926ejs",
Andrew Geisslerc926e172021-05-07 16:11:35 -05002676 you would do the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002677
2678 KBRANCH = "standard/base"
2679 KBRANCH_qemuarm = "standard/arm-versatile-926ejs"
2680
2681 Overrides are also used to separate
2682 alternate values of a variable in other situations. For example, when
2683 setting variables such as
2684 :term:`FILES` and
2685 :term:`RDEPENDS` that are
2686 specific to individual packages produced by a recipe, you should
2687 always use an override that specifies the name of the package.
2688
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002689- *Indentation:* Use spaces for indentation rather than tabs. For
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002690 shell functions, both currently work. However, it is a policy
2691 decision of the Yocto Project to use tabs in shell functions. Realize
2692 that some layers have a policy to use spaces for all indentation.
2693
2694- *Using Python for Complex Operations:* For more advanced processing,
2695 it is possible to use Python code during variable assignments (e.g.
2696 search and replacement on a variable).
2697
2698 You indicate Python code using the ``${@python_code}`` syntax for the
Andrew Geisslerc926e172021-05-07 16:11:35 -05002699 variable assignment::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002700
2701 SRC_URI = "ftp://ftp.info-zip.org/pub/infozip/src/zip${@d.getVar('PV',1).replace('.', '')}.tgz
2702
2703- *Shell Function Syntax:* Write shell functions as if you were writing
2704 a shell script when you describe a list of actions to take. You
2705 should ensure that your script works with a generic ``sh`` and that
2706 it does not require any ``bash`` or other shell-specific
2707 functionality. The same considerations apply to various system
2708 utilities (e.g. ``sed``, ``grep``, ``awk``, and so forth) that you
2709 might wish to use. If in doubt, you should check with multiple
2710 implementations - including those from BusyBox.
2711
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002712Adding a New Machine
2713====================
2714
2715Adding a new machine to the Yocto Project is a straightforward process.
2716This section describes how to add machines that are similar to those
2717that the Yocto Project already supports.
2718
2719.. note::
2720
2721 Although well within the capabilities of the Yocto Project, adding a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002722 totally new architecture might require changes to ``gcc``/``glibc``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002723 and to the site information, which is beyond the scope of this
2724 manual.
2725
2726For a complete example that shows how to add a new machine, see the
2727":ref:`bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script`"
2728section in the Yocto Project Board Support Package (BSP) Developer's
2729Guide.
2730
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002731Adding the Machine Configuration File
2732-------------------------------------
2733
2734To add a new machine, you need to add a new machine configuration file
2735to the layer's ``conf/machine`` directory. This configuration file
2736provides details about the device you are adding.
2737
2738The OpenEmbedded build system uses the root name of the machine
2739configuration file to reference the new machine. For example, given a
2740machine configuration file named ``crownbay.conf``, the build system
2741recognizes the machine as "crownbay".
2742
2743The most important variables you must set in your machine configuration
2744file or include from a lower-level configuration file are as follows:
2745
2746- ``TARGET_ARCH`` (e.g. "arm")
2747
2748- ``PREFERRED_PROVIDER_virtual/kernel``
2749
2750- ``MACHINE_FEATURES`` (e.g. "apm screen wifi")
2751
2752You might also need these variables:
2753
2754- ``SERIAL_CONSOLES`` (e.g. "115200;ttyS0 115200;ttyS1")
2755
2756- ``KERNEL_IMAGETYPE`` (e.g. "zImage")
2757
2758- ``IMAGE_FSTYPES`` (e.g. "tar.gz jffs2")
2759
2760You can find full details on these variables in the reference section.
2761You can leverage existing machine ``.conf`` files from
2762``meta-yocto-bsp/conf/machine/``.
2763
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002764Adding a Kernel for the Machine
2765-------------------------------
2766
2767The OpenEmbedded build system needs to be able to build a kernel for the
2768machine. You need to either create a new kernel recipe for this machine,
2769or extend an existing kernel recipe. You can find several kernel recipe
2770examples in the Source Directory at ``meta/recipes-kernel/linux`` that
2771you can use as references.
2772
2773If you are creating a new kernel recipe, normal recipe-writing rules
2774apply for setting up a ``SRC_URI``. Thus, you need to specify any
2775necessary patches and set ``S`` to point at the source code. You need to
2776create a ``do_configure`` task that configures the unpacked kernel with
2777a ``defconfig`` file. You can do this by using a ``make defconfig``
2778command or, more commonly, by copying in a suitable ``defconfig`` file
2779and then running ``make oldconfig``. By making use of ``inherit kernel``
2780and potentially some of the ``linux-*.inc`` files, most other
2781functionality is centralized and the defaults of the class normally work
2782well.
2783
2784If you are extending an existing kernel recipe, it is usually a matter
2785of adding a suitable ``defconfig`` file. The file needs to be added into
2786a location similar to ``defconfig`` files used for other machines in a
2787given kernel recipe. A possible way to do this is by listing the file in
2788the ``SRC_URI`` and adding the machine to the expression in
Andrew Geisslerc926e172021-05-07 16:11:35 -05002789``COMPATIBLE_MACHINE``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002790
2791 COMPATIBLE_MACHINE = '(qemux86|qemumips)'
2792
2793For more information on ``defconfig`` files, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06002794":ref:`kernel-dev/common:changing the configuration`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002795section in the Yocto Project Linux Kernel Development Manual.
2796
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002797Adding a Formfactor Configuration File
2798--------------------------------------
2799
2800A formfactor configuration file provides information about the target
2801hardware for which the image is being built and information that the
2802build system cannot obtain from other sources such as the kernel. Some
2803examples of information contained in a formfactor configuration file
2804include framebuffer orientation, whether or not the system has a
2805keyboard, the positioning of the keyboard in relation to the screen, and
2806the screen resolution.
2807
2808The build system uses reasonable defaults in most cases. However, if
2809customization is necessary, you need to create a ``machconfig`` file in
2810the ``meta/recipes-bsp/formfactor/files`` directory. This directory
2811contains directories for specific machines such as ``qemuarm`` and
2812``qemux86``. For information about the settings available and the
2813defaults, see the ``meta/recipes-bsp/formfactor/files/config`` file
2814found in the same area.
2815
Andrew Geisslerc926e172021-05-07 16:11:35 -05002816Following is an example for "qemuarm" machine::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002817
2818 HAVE_TOUCHSCREEN=1
2819 HAVE_KEYBOARD=1
2820 DISPLAY_CAN_ROTATE=0
2821 DISPLAY_ORIENTATION=0
2822 #DISPLAY_WIDTH_PIXELS=640
2823 #DISPLAY_HEIGHT_PIXELS=480
2824 #DISPLAY_BPP=16
2825 DISPLAY_DPI=150
2826 DISPLAY_SUBPIXEL_ORDER=vrgb
2827
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002828Upgrading Recipes
2829=================
2830
2831Over time, upstream developers publish new versions for software built
2832by layer recipes. It is recommended to keep recipes up-to-date with
2833upstream version releases.
2834
2835While several methods exist that allow you upgrade a recipe, you might
2836consider checking on the upgrade status of a recipe first. You can do so
2837using the ``devtool check-upgrade-status`` command. See the
2838":ref:`devtool-checking-on-the-upgrade-status-of-a-recipe`"
2839section in the Yocto Project Reference Manual for more information.
2840
2841The remainder of this section describes three ways you can upgrade a
2842recipe. You can use the Automated Upgrade Helper (AUH) to set up
2843automatic version upgrades. Alternatively, you can use
2844``devtool upgrade`` to set up semi-automatic version upgrades. Finally,
2845you can manually upgrade a recipe by editing the recipe itself.
2846
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002847Using the Auto Upgrade Helper (AUH)
2848-----------------------------------
2849
2850The AUH utility works in conjunction with the OpenEmbedded build system
2851in order to automatically generate upgrades for recipes based on new
2852versions being published upstream. Use AUH when you want to create a
2853service that performs the upgrades automatically and optionally sends
2854you an email with the results.
2855
2856AUH allows you to update several recipes with a single use. You can also
2857optionally perform build and integration tests using images with the
2858results saved to your hard drive and emails of results optionally sent
2859to recipe maintainers. Finally, AUH creates Git commits with appropriate
2860commit messages in the layer's tree for the changes made to recipes.
2861
2862.. note::
2863
2864 Conditions do exist when you should not use AUH to upgrade recipes
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002865 and you should instead use either ``devtool upgrade`` or upgrade your
2866 recipes manually:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002867
2868 - When AUH cannot complete the upgrade sequence. This situation
2869 usually results because custom patches carried by the recipe
2870 cannot be automatically rebased to the new version. In this case,
2871 ``devtool upgrade`` allows you to manually resolve conflicts.
2872
2873 - When for any reason you want fuller control over the upgrade
2874 process. For example, when you want special arrangements for
2875 testing.
2876
2877The following steps describe how to set up the AUH utility:
2878
28791. *Be Sure the Development Host is Set Up:* You need to be sure that
2880 your development host is set up to use the Yocto Project. For
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002881 information on how to set up your host, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06002882 ":ref:`dev-manual/start:Preparing the Build Host`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002883
28842. *Make Sure Git is Configured:* The AUH utility requires Git to be
2885 configured because AUH uses Git to save upgrades. Thus, you must have
2886 Git user and email configured. The following command shows your
Andrew Geisslerc926e172021-05-07 16:11:35 -05002887 configurations::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002888
2889 $ git config --list
2890
2891 If you do not have the user and
Andrew Geisslerc926e172021-05-07 16:11:35 -05002892 email configured, you can use the following commands to do so::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002893
2894 $ git config --global user.name some_name
2895 $ git config --global user.email username@domain.com
2896
28973. *Clone the AUH Repository:* To use AUH, you must clone the repository
2898 onto your development host. The following command uses Git to create
Andrew Geisslerc926e172021-05-07 16:11:35 -05002899 a local copy of the repository on your system::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002900
2901 $ git clone git://git.yoctoproject.org/auto-upgrade-helper
2902 Cloning into 'auto-upgrade-helper'... remote: Counting objects: 768, done.
2903 remote: Compressing objects: 100% (300/300), done.
2904 remote: Total 768 (delta 499), reused 703 (delta 434)
2905 Receiving objects: 100% (768/768), 191.47 KiB | 98.00 KiB/s, done.
2906 Resolving deltas: 100% (499/499), done.
2907 Checking connectivity... done.
2908
2909 AUH is not part of the :term:`OpenEmbedded-Core (OE-Core)` or
2910 :term:`Poky` repositories.
2911
29124. *Create a Dedicated Build Directory:* Run the
2913 :ref:`structure-core-script`
2914 script to create a fresh build directory that you use exclusively for
Andrew Geisslerc926e172021-05-07 16:11:35 -05002915 running the AUH utility::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002916
Andrew Geissler95ac1b82021-03-31 14:34:31 -05002917 $ cd poky
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002918 $ source oe-init-build-env your_AUH_build_directory
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002919
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002920 Re-using an existing build directory and its configurations is not
2921 recommended as existing settings could cause AUH to fail or behave
2922 undesirably.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002923
29245. *Make Configurations in Your Local Configuration File:* Several
2925 settings need to exist in the ``local.conf`` file in the build
2926 directory you just created for AUH. Make these following
2927 configurations:
2928
2929 - If you want to enable :ref:`Build
Andrew Geissler09209ee2020-12-13 08:44:15 -06002930 History <dev-manual/common-tasks:maintaining build output quality>`,
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002931 which is optional, you need the following lines in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05002932 ``conf/local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002933
2934 INHERIT =+ "buildhistory"
2935 BUILDHISTORY_COMMIT = "1"
2936
2937 With this configuration and a successful
2938 upgrade, a build history "diff" file appears in the
2939 ``upgrade-helper/work/recipe/buildhistory-diff.txt`` file found in
2940 your build directory.
2941
2942 - If you want to enable testing through the
2943 :ref:`testimage <ref-classes-testimage*>`
2944 class, which is optional, you need to have the following set in
Andrew Geisslerc926e172021-05-07 16:11:35 -05002945 your ``conf/local.conf`` file::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002946
2947 INHERIT += "testimage"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002948
2949 .. note::
2950
2951 If your distro does not enable by default ptest, which Poky
Andrew Geisslerc926e172021-05-07 16:11:35 -05002952 does, you need the following in your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002953
2954 DISTRO_FEATURES_append = " ptest"
2955
2956
29576. *Optionally Start a vncserver:* If you are running in a server
Andrew Geisslerc926e172021-05-07 16:11:35 -05002958 without an X11 session, you need to start a vncserver::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002959
2960 $ vncserver :1
2961 $ export DISPLAY=:1
2962
29637. *Create and Edit an AUH Configuration File:* You need to have the
2964 ``upgrade-helper/upgrade-helper.conf`` configuration file in your
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002965 build directory. You can find a sample configuration file in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06002966 :yocto_git:`AUH source repository </auto-upgrade-helper/tree/>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002967
2968 Read through the sample file and make configurations as needed. For
2969 example, if you enabled build history in your ``local.conf`` as
2970 described earlier, you must enable it in ``upgrade-helper.conf``.
2971
2972 Also, if you are using the default ``maintainers.inc`` file supplied
2973 with Poky and located in ``meta-yocto`` and you do not set a
2974 "maintainers_whitelist" or "global_maintainer_override" in the
2975 ``upgrade-helper.conf`` configuration, and you specify "-e all" on
2976 the AUH command-line, the utility automatically sends out emails to
2977 all the default maintainers. Please avoid this.
2978
2979This next set of examples describes how to use the AUH:
2980
2981- *Upgrading a Specific Recipe:* To upgrade a specific recipe, use the
Andrew Geisslerc926e172021-05-07 16:11:35 -05002982 following form::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002983
2984 $ upgrade-helper.py recipe_name
2985
Andrew Geisslerc926e172021-05-07 16:11:35 -05002986 For example, this command upgrades the ``xmodmap`` recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002987
2988 $ upgrade-helper.py xmodmap
2989
2990- *Upgrading a Specific Recipe to a Particular Version:* To upgrade a
Andrew Geisslerc926e172021-05-07 16:11:35 -05002991 specific recipe to a particular version, use the following form::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002992
2993 $ upgrade-helper.py recipe_name -t version
2994
Andrew Geisslerc926e172021-05-07 16:11:35 -05002995 For example, this command upgrades the ``xmodmap`` recipe to version 1.2.3::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002996
2997 $ upgrade-helper.py xmodmap -t 1.2.3
2998
2999- *Upgrading all Recipes to the Latest Versions and Suppressing Email
3000 Notifications:* To upgrade all recipes to their most recent versions
Andrew Geisslerc926e172021-05-07 16:11:35 -05003001 and suppress the email notifications, use the following command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003002
3003 $ upgrade-helper.py all
3004
3005- *Upgrading all Recipes to the Latest Versions and Send Email
3006 Notifications:* To upgrade all recipes to their most recent versions
3007 and send email messages to maintainers for each attempted recipe as
Andrew Geisslerc926e172021-05-07 16:11:35 -05003008 well as a status email, use the following command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003009
3010 $ upgrade-helper.py -e all
3011
3012Once you have run the AUH utility, you can find the results in the AUH
Andrew Geisslerc926e172021-05-07 16:11:35 -05003013build directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003014
3015 ${BUILDDIR}/upgrade-helper/timestamp
3016
3017The AUH utility
3018also creates recipe update commits from successful upgrade attempts in
3019the layer tree.
3020
3021You can easily set up to run the AUH utility on a regular basis by using
3022a cron job. See the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003023:yocto_git:`weeklyjob.sh </auto-upgrade-helper/tree/weeklyjob.sh>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003024file distributed with the utility for an example.
3025
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003026Using ``devtool upgrade``
3027-------------------------
3028
3029As mentioned earlier, an alternative method for upgrading recipes to
3030newer versions is to use
Andrew Geissler09209ee2020-12-13 08:44:15 -06003031:doc:`devtool upgrade </ref-manual/devtool-reference>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003032You can read about ``devtool upgrade`` in general in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003033":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 -05003034section in the Yocto Project Application Development and the Extensible
3035Software Development Kit (eSDK) Manual.
3036
3037To see all the command-line options available with ``devtool upgrade``,
Andrew Geisslerc926e172021-05-07 16:11:35 -05003038use the following help command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003039
3040 $ devtool upgrade -h
3041
3042If you want to find out what version a recipe is currently at upstream
3043without any attempt to upgrade your local version of the recipe, you can
Andrew Geisslerc926e172021-05-07 16:11:35 -05003044use the following command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003045
3046 $ devtool latest-version recipe_name
3047
3048As mentioned in the previous section describing AUH, ``devtool upgrade``
3049works in a less-automated manner than AUH. Specifically,
3050``devtool upgrade`` only works on a single recipe that you name on the
3051command line, cannot perform build and integration testing using images,
3052and does not automatically generate commits for changes in the source
3053tree. Despite all these "limitations", ``devtool upgrade`` updates the
3054recipe file to the new upstream version and attempts to rebase custom
3055patches contained by the recipe as needed.
3056
3057.. note::
3058
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003059 AUH uses much of ``devtool upgrade`` behind the scenes making AUH somewhat
3060 of a "wrapper" application for ``devtool upgrade``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003061
3062A typical scenario involves having used Git to clone an upstream
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003063repository that you use during build operations. Because you have built the
3064recipe in the past, the layer is likely added to your
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003065configuration already. If for some reason, the layer is not added, you
3066could add it easily using the
3067":ref:`bitbake-layers <bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script>`"
3068script. For example, suppose you use the ``nano.bb`` recipe from the
3069``meta-oe`` layer in the ``meta-openembedded`` repository. For this
Andrew Geisslerc926e172021-05-07 16:11:35 -05003070example, assume that the layer has been cloned into following area::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003071
3072 /home/scottrif/meta-openembedded
3073
3074The following command from your
3075:term:`Build Directory` adds the layer to
Andrew Geisslerc926e172021-05-07 16:11:35 -05003076your build configuration (i.e. ``${BUILDDIR}/conf/bblayers.conf``)::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003077
3078 $ bitbake-layers add-layer /home/scottrif/meta-openembedded/meta-oe
3079 NOTE: Starting bitbake server...
3080 Parsing recipes: 100% |##########################################| Time: 0:00:55
3081 Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
3082 Removing 12 recipes from the x86_64 sysroot: 100% |##############| Time: 0:00:00
3083 Removing 1 recipes from the x86_64_i586 sysroot: 100% |##########| Time: 0:00:00
3084 Removing 5 recipes from the i586 sysroot: 100% |#################| Time: 0:00:00
3085 Removing 5 recipes from the qemux86 sysroot: 100% |##############| Time: 0:00:00
3086
3087For this example, assume that the ``nano.bb`` recipe that
3088is upstream has a 2.9.3 version number. However, the version in the
3089local repository is 2.7.4. The following command from your build
3090directory automatically upgrades the recipe for you:
3091
3092.. note::
3093
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003094 Using the ``-V`` option is not necessary. Omitting the version number causes
3095 ``devtool upgrade`` to upgrade the recipe to the most recent version.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003096
3097::
3098
3099 $ devtool upgrade nano -V 2.9.3
3100 NOTE: Starting bitbake server...
3101 NOTE: Creating workspace layer in /home/scottrif/poky/build/workspace
3102 Parsing recipes: 100% |##########################################| Time: 0:00:46
3103 Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
3104 NOTE: Extracting current version source...
3105 NOTE: Resolving any missing task queue dependencies
3106 .
3107 .
3108 .
3109 NOTE: Executing SetScene Tasks
3110 NOTE: Executing RunQueue Tasks
3111 NOTE: Tasks Summary: Attempted 74 tasks of which 72 didn't need to be rerun and all succeeded.
3112 Adding changed files: 100% |#####################################| Time: 0:00:00
3113 NOTE: Upgraded source extracted to /home/scottrif/poky/build/workspace/sources/nano
3114 NOTE: New recipe is /home/scottrif/poky/build/workspace/recipes/nano/nano_2.9.3.bb
3115
3116Continuing with this example, you can use ``devtool build`` to build the
Andrew Geisslerc926e172021-05-07 16:11:35 -05003117newly upgraded recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003118
3119 $ devtool build nano
3120 NOTE: Starting bitbake server...
3121 Loading cache: 100% |################################################################################################| Time: 0:00:01
3122 Loaded 2040 entries from dependency cache.
3123 Parsing recipes: 100% |##############################################################################################| Time: 0:00:00
3124 Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
3125 NOTE: Resolving any missing task queue dependencies
3126 .
3127 .
3128 .
3129 NOTE: Executing SetScene Tasks
3130 NOTE: Executing RunQueue Tasks
3131 NOTE: nano: compiling from external source tree /home/scottrif/poky/build/workspace/sources/nano
3132 NOTE: Tasks Summary: Attempted 520 tasks of which 304 didn't need to be rerun and all succeeded.
3133
3134Within the ``devtool upgrade`` workflow, opportunity
3135exists to deploy and test your rebuilt software. For this example,
3136however, running ``devtool finish`` cleans up the workspace once the
3137source in your workspace is clean. This usually means using Git to stage
3138and submit commits for the changes generated by the upgrade process.
3139
3140Once the tree is clean, you can clean things up in this example with the
3141following command from the ``${BUILDDIR}/workspace/sources/nano``
Andrew Geisslerc926e172021-05-07 16:11:35 -05003142directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003143
3144 $ devtool finish nano meta-oe
3145 NOTE: Starting bitbake server...
3146 Loading cache: 100% |################################################################################################| Time: 0:00:00
3147 Loaded 2040 entries from dependency cache.
3148 Parsing recipes: 100% |##############################################################################################| Time: 0:00:01
3149 Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
3150 NOTE: Adding new patch 0001-nano.bb-Stuff-I-changed-when-upgrading-nano.bb.patch
3151 NOTE: Updating recipe nano_2.9.3.bb
3152 NOTE: Removing file /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano/nano_2.7.4.bb
3153 NOTE: Moving recipe file to /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano
3154 NOTE: Leaving source tree /home/scottrif/poky/build/workspace/sources/nano as-is; if you no longer need it then please delete it manually
3155
3156
3157Using the ``devtool finish`` command cleans up the workspace and creates a patch
3158file based on your commits. The tool puts all patch files back into the
3159source directory in a sub-directory named ``nano`` in this case.
3160
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003161Manually Upgrading a Recipe
3162---------------------------
3163
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003164If for some reason you choose not to upgrade recipes using
Andrew Geissler09209ee2020-12-13 08:44:15 -06003165:ref:`dev-manual/common-tasks:Using the Auto Upgrade Helper (AUH)` or
3166by :ref:`dev-manual/common-tasks:Using \`\`devtool upgrade\`\``,
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003167you can manually edit the recipe files to upgrade the versions.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003168
3169.. note::
3170
3171 Manually updating multiple recipes scales poorly and involves many
3172 steps. The recommendation to upgrade recipe versions is through AUH
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003173 or ``devtool upgrade``, both of which automate some steps and provide
3174 guidance for others needed for the manual process.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003175
3176To manually upgrade recipe versions, follow these general steps:
3177
31781. *Change the Version:* Rename the recipe such that the version (i.e.
3179 the :term:`PV` part of the recipe name)
3180 changes appropriately. If the version is not part of the recipe name,
3181 change the value as it is set for ``PV`` within the recipe itself.
3182
Andrew Geissler4c19ea12020-10-27 13:52:24 -050031832. *Update* ``SRCREV`` *if Needed*: If the source code your recipe builds
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003184 is fetched from Git or some other version control system, update
3185 :term:`SRCREV` to point to the
3186 commit hash that matches the new version.
3187
31883. *Build the Software:* Try to build the recipe using BitBake. Typical
3189 build failures include the following:
3190
3191 - License statements were updated for the new version. For this
3192 case, you need to review any changes to the license and update the
3193 values of :term:`LICENSE` and
3194 :term:`LIC_FILES_CHKSUM`
3195 as needed.
3196
3197 .. note::
3198
3199 License changes are often inconsequential. For example, the
3200 license text's copyright year might have changed.
3201
3202 - Custom patches carried by the older version of the recipe might
3203 fail to apply to the new version. For these cases, you need to
3204 review the failures. Patches might not be necessary for the new
3205 version of the software if the upgraded version has fixed those
3206 issues. If a patch is necessary and failing, you need to rebase it
3207 into the new version.
3208
32094. *Optionally Attempt to Build for Several Architectures:* Once you
3210 successfully build the new software for a given architecture, you
3211 could test the build for other architectures by changing the
3212 :term:`MACHINE` variable and
3213 rebuilding the software. This optional step is especially important
3214 if the recipe is to be released publicly.
3215
32165. *Check the Upstream Change Log or Release Notes:* Checking both these
3217 reveals if new features exist that could break
3218 backwards-compatibility. If so, you need to take steps to mitigate or
3219 eliminate that situation.
3220
32216. *Optionally Create a Bootable Image and Test:* If you want, you can
3222 test the new software by booting it onto actual hardware.
3223
32247. *Create a Commit with the Change in the Layer Repository:* After all
3225 builds work and any testing is successful, you can create commits for
3226 any changes in the layer holding your upgraded recipe.
3227
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003228Finding Temporary Source Code
3229=============================
3230
3231You might find it helpful during development to modify the temporary
3232source code used by recipes to build packages. For example, suppose you
3233are developing a patch and you need to experiment a bit to figure out
3234your solution. After you have initially built the package, you can
3235iteratively tweak the source code, which is located in the
3236:term:`Build Directory`, and then you can
3237force a re-compile and quickly test your altered code. Once you settle
3238on a solution, you can then preserve your changes in the form of
3239patches.
3240
3241During a build, the unpacked temporary source code used by recipes to
3242build packages is available in the Build Directory as defined by the
3243:term:`S` variable. Below is the default
3244value for the ``S`` variable as defined in the
3245``meta/conf/bitbake.conf`` configuration file in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05003246:term:`Source Directory`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003247
3248 S = "${WORKDIR}/${BP}"
3249
3250You should be aware that many recipes override the
3251``S`` variable. For example, recipes that fetch their source from Git
3252usually set ``S`` to ``${WORKDIR}/git``.
3253
3254.. note::
3255
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003256 The :term:`BP` represents the base recipe name, which consists of the name
Andrew Geisslerc926e172021-05-07 16:11:35 -05003257 and version::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003258
3259 BP = "${BPN}-${PV}"
3260
3261
3262The path to the work directory for the recipe
3263(:term:`WORKDIR`) is defined as
Andrew Geisslerc926e172021-05-07 16:11:35 -05003264follows::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003265
3266 ${TMPDIR}/work/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR}
3267
3268The actual directory depends on several things:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003269
3270- :term:`TMPDIR`: The top-level build
3271 output directory.
3272
3273- :term:`MULTIMACH_TARGET_SYS`:
3274 The target system identifier.
3275
3276- :term:`PN`: The recipe name.
3277
3278- :term:`EXTENDPE`: The epoch - (if
3279 :term:`PE` is not specified, which is
3280 usually the case for most recipes, then ``EXTENDPE`` is blank).
3281
3282- :term:`PV`: The recipe version.
3283
3284- :term:`PR`: The recipe revision.
3285
3286As an example, assume a Source Directory top-level folder named
3287``poky``, a default Build Directory at ``poky/build``, and a
3288``qemux86-poky-linux`` machine target system. Furthermore, suppose your
3289recipe is named ``foo_1.3.0.bb``. In this case, the work directory the
Andrew Geisslerc926e172021-05-07 16:11:35 -05003290build system uses to build the package would be as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003291
3292 poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
3293
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003294Using Quilt in Your Workflow
3295============================
3296
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003297`Quilt <https://savannah.nongnu.org/projects/quilt>`__ is a powerful tool
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003298that allows you to capture source code changes without having a clean
3299source tree. This section outlines the typical workflow you can use to
3300modify source code, test changes, and then preserve the changes in the
3301form of a patch all using Quilt.
3302
3303.. note::
3304
3305 With regard to preserving changes to source files, if you clean a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003306 recipe or have ``rm_work`` enabled, the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003307 :ref:`devtool workflow <sdk-manual/extensible:using \`\`devtool\`\` in your sdk workflow>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003308 as described in the Yocto Project Application Development and the
3309 Extensible Software Development Kit (eSDK) manual is a safer
3310 development flow than the flow that uses Quilt.
3311
3312Follow these general steps:
3313
33141. *Find the Source Code:* Temporary source code used by the
3315 OpenEmbedded build system is kept in the
3316 :term:`Build Directory`. See the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05003317 ":ref:`dev-manual/common-tasks:finding temporary source code`" section to
3318 learn how to locate the directory that has the temporary source code for a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003319 particular package.
3320
33212. *Change Your Working Directory:* You need to be in the directory that
3322 has the temporary source code. That directory is defined by the
3323 :term:`S` variable.
3324
33253. *Create a New Patch:* Before modifying source code, you need to
3326 create a new patch. To create a new patch file, use ``quilt new`` as
Andrew Geisslerc926e172021-05-07 16:11:35 -05003327 below::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003328
3329 $ quilt new my_changes.patch
3330
33314. *Notify Quilt and Add Files:* After creating the patch, you need to
3332 notify Quilt about the files you plan to edit. You notify Quilt by
Andrew Geisslerc926e172021-05-07 16:11:35 -05003333 adding the files to the patch you just created::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003334
3335 $ quilt add file1.c file2.c file3.c
3336
33375. *Edit the Files:* Make your changes in the source code to the files
3338 you added to the patch.
3339
33406. *Test Your Changes:* Once you have modified the source code, the
3341 easiest way to test your changes is by calling the ``do_compile``
Andrew Geisslerc926e172021-05-07 16:11:35 -05003342 task as shown in the following example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003343
3344 $ bitbake -c compile -f package
3345
3346 The ``-f`` or ``--force`` option forces the specified task to
3347 execute. If you find problems with your code, you can just keep
3348 editing and re-testing iteratively until things work as expected.
3349
3350 .. note::
3351
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003352 All the modifications you make to the temporary source code disappear
3353 once you run the ``do_clean`` or ``do_cleanall`` tasks using BitBake
3354 (i.e. ``bitbake -c clean package`` and ``bitbake -c cleanall package``).
3355 Modifications will also disappear if you use the ``rm_work`` feature as
3356 described in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003357 ":ref:`dev-manual/common-tasks:conserving disk space during builds`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003358 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003359
33607. *Generate the Patch:* Once your changes work as expected, you need to
3361 use Quilt to generate the final patch that contains all your
3362 modifications.
3363 ::
3364
3365 $ quilt refresh
3366
3367 At this point, the
3368 ``my_changes.patch`` file has all your edits made to the ``file1.c``,
3369 ``file2.c``, and ``file3.c`` files.
3370
3371 You can find the resulting patch file in the ``patches/``
3372 subdirectory of the source (``S``) directory.
3373
33748. *Copy the Patch File:* For simplicity, copy the patch file into a
3375 directory named ``files``, which you can create in the same directory
3376 that holds the recipe (``.bb``) file or the append (``.bbappend``)
3377 file. Placing the patch here guarantees that the OpenEmbedded build
3378 system will find the patch. Next, add the patch into the ``SRC_URI``
Andrew Geisslerc926e172021-05-07 16:11:35 -05003379 of the recipe. Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003380
3381 SRC_URI += "file://my_changes.patch"
3382
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003383Using a Development Shell
3384=========================
3385
3386When debugging certain commands or even when just editing packages,
3387``devshell`` can be a useful tool. When you invoke ``devshell``, all
3388tasks up to and including
3389:ref:`ref-tasks-patch` are run for the
3390specified target. Then, a new terminal is opened and you are placed in
3391``${``\ :term:`S`\ ``}``, the source
3392directory. In the new terminal, all the OpenEmbedded build-related
3393environment variables are still defined so you can use commands such as
3394``configure`` and ``make``. The commands execute just as if the
3395OpenEmbedded build system were executing them. Consequently, working
3396this way can be helpful when debugging a build or preparing software to
3397be used with the OpenEmbedded build system.
3398
3399Following is an example that uses ``devshell`` on a target named
Andrew Geisslerc926e172021-05-07 16:11:35 -05003400``matchbox-desktop``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003401
3402 $ bitbake matchbox-desktop -c devshell
3403
3404This command spawns a terminal with a shell prompt within the
3405OpenEmbedded build environment. The
3406:term:`OE_TERMINAL` variable
3407controls what type of shell is opened.
3408
3409For spawned terminals, the following occurs:
3410
3411- The ``PATH`` variable includes the cross-toolchain.
3412
3413- The ``pkgconfig`` variables find the correct ``.pc`` files.
3414
3415- The ``configure`` command finds the Yocto Project site files as well
3416 as any other necessary files.
3417
3418Within this environment, you can run configure or compile commands as if
3419they were being run by the OpenEmbedded build system itself. As noted
3420earlier, the working directory also automatically changes to the Source
3421Directory (:term:`S`).
3422
3423To manually run a specific task using ``devshell``, run the
3424corresponding ``run.*`` script in the
3425``${``\ :term:`WORKDIR`\ ``}/temp``
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003426directory (e.g., ``run.do_configure.``\ `pid`). If a task's script does
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003427not exist, which would be the case if the task was skipped by way of the
3428sstate cache, you can create the task by first running it outside of the
Andrew Geisslerc926e172021-05-07 16:11:35 -05003429``devshell``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003430
3431 $ bitbake -c task
3432
3433.. note::
3434
3435 - Execution of a task's ``run.*`` script and BitBake's execution of
3436 a task are identical. In other words, running the script re-runs
3437 the task just as it would be run using the ``bitbake -c`` command.
3438
3439 - Any ``run.*`` file that does not have a ``.pid`` extension is a
3440 symbolic link (symlink) to the most recent version of that file.
3441
3442Remember, that the ``devshell`` is a mechanism that allows you to get
3443into the BitBake task execution environment. And as such, all commands
3444must be called just as BitBake would call them. That means you need to
3445provide the appropriate options for cross-compilation and so forth as
3446applicable.
3447
3448When you are finished using ``devshell``, exit the shell or close the
3449terminal window.
3450
3451.. note::
3452
3453 - It is worth remembering that when using ``devshell`` you need to
3454 use the full compiler name such as ``arm-poky-linux-gnueabi-gcc``
3455 instead of just using ``gcc``. The same applies to other
3456 applications such as ``binutils``, ``libtool`` and so forth.
3457 BitBake sets up environment variables such as ``CC`` to assist
3458 applications, such as ``make`` to find the correct tools.
3459
3460 - It is also worth noting that ``devshell`` still works over X11
3461 forwarding and similar situations.
3462
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003463Using a Development Python Shell
3464================================
3465
3466Similar to working within a development shell as described in the
3467previous section, you can also spawn and work within an interactive
3468Python development shell. When debugging certain commands or even when
3469just editing packages, ``devpyshell`` can be a useful tool. When you
3470invoke ``devpyshell``, all tasks up to and including
3471:ref:`ref-tasks-patch` are run for the
3472specified target. Then a new terminal is opened. Additionally, key
3473Python objects and code are available in the same way they are to
3474BitBake tasks, in particular, the data store 'd'. So, commands such as
3475the following are useful when exploring the data store and running
Andrew Geisslerc926e172021-05-07 16:11:35 -05003476functions::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003477
3478 pydevshell> d.getVar("STAGING_DIR")
3479 '/media/build1/poky/build/tmp/sysroots'
3480 pydevshell> d.getVar("STAGING_DIR")
3481 '${TMPDIR}/sysroots'
3482 pydevshell> d.setVar("FOO", "bar")
3483 pydevshell> d.getVar("FOO")
3484 'bar'
3485 pydevshell> d.delVar("FOO")
3486 pydevshell> d.getVar("FOO")
3487 pydevshell> bb.build.exec_func("do_unpack", d)
3488 pydevshell>
3489
3490The commands execute just as if the OpenEmbedded build
3491system were executing them. Consequently, working this way can be
3492helpful when debugging a build or preparing software to be used with the
3493OpenEmbedded build system.
3494
3495Following is an example that uses ``devpyshell`` on a target named
Andrew Geisslerc926e172021-05-07 16:11:35 -05003496``matchbox-desktop``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003497
3498 $ bitbake matchbox-desktop -c devpyshell
3499
3500This command spawns a terminal and places you in an interactive Python
3501interpreter within the OpenEmbedded build environment. The
3502:term:`OE_TERMINAL` variable
3503controls what type of shell is opened.
3504
3505When you are finished using ``devpyshell``, you can exit the shell
3506either by using Ctrl+d or closing the terminal window.
3507
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003508Building
3509========
3510
3511This section describes various build procedures. For example, the steps
3512needed for a simple build, a target that uses multiple configurations,
3513building an image for more than one machine, and so forth.
3514
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003515Building a Simple Image
3516-----------------------
3517
3518In the development environment, you need to build an image whenever you
3519change hardware support, add or change system libraries, or add or
3520change services that have dependencies. Several methods exist that allow
3521you to build an image within the Yocto Project. This section presents
3522the basic steps you need to build a simple image using BitBake from a
3523build host running Linux.
3524
3525.. note::
3526
3527 - For information on how to build an image using
3528 :term:`Toaster`, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003529 :doc:`/toaster-manual/index`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003530
3531 - For information on how to use ``devtool`` to build images, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003532 ":ref:`sdk-manual/extensible:using \`\`devtool\`\` in your sdk workflow`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003533 section in the Yocto Project Application Development and the
3534 Extensible Software Development Kit (eSDK) manual.
3535
3536 - For a quick example on how to build an image using the
3537 OpenEmbedded build system, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003538 :doc:`/brief-yoctoprojectqs/index` document.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003539
3540The build process creates an entire Linux distribution from source and
3541places it in your :term:`Build Directory` under
3542``tmp/deploy/images``. For detailed information on the build process
Andrew Geissler09209ee2020-12-13 08:44:15 -06003543using BitBake, see the ":ref:`overview-manual/concepts:images`" section in the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003544Yocto Project Overview and Concepts Manual.
3545
3546The following figure and list overviews the build process:
3547
3548.. image:: figures/bitbake-build-flow.png
3549 :align: center
3550
35511. *Set up Your Host Development System to Support Development Using the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003552 Yocto Project*: See the ":doc:`start`" section for options on how to get a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003553 build host ready to use the Yocto Project.
3554
35552. *Initialize the Build Environment:* Initialize the build environment
3556 by sourcing the build environment script (i.e.
Andrew Geisslerc926e172021-05-07 16:11:35 -05003557 :ref:`structure-core-script`)::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003558
3559 $ source oe-init-build-env [build_dir]
3560
3561 When you use the initialization script, the OpenEmbedded build system
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003562 uses ``build`` as the default :term:`Build Directory` in your current work
3563 directory. You can use a `build_dir` argument with the script to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003564 specify a different build directory.
3565
3566 .. note::
3567
3568 A common practice is to use a different Build Directory for
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003569 different targets. For example, ``~/build/x86`` for a ``qemux86``
3570 target, and ``~/build/arm`` for a ``qemuarm`` target.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003571
Andrew Geissler4c19ea12020-10-27 13:52:24 -050035723. *Make Sure Your* ``local.conf`` *File is Correct*: Ensure the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003573 ``conf/local.conf`` configuration file, which is found in the Build
3574 Directory, is set up how you want it. This file defines many aspects
3575 of the build environment including the target machine architecture
3576 through the ``MACHINE`` variable, the packaging format used during
3577 the build
3578 (:term:`PACKAGE_CLASSES`),
3579 and a centralized tarball download directory through the
3580 :term:`DL_DIR` variable.
3581
Andrew Geisslerc926e172021-05-07 16:11:35 -050035824. *Build the Image:* Build the image using the ``bitbake`` command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003583
3584 $ bitbake target
3585
3586 .. note::
3587
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003588 For information on BitBake, see the :doc:`bitbake:index`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003589
3590 The target is the name of the recipe you want to build. Common
3591 targets are the images in ``meta/recipes-core/images``,
3592 ``meta/recipes-sato/images``, and so forth all found in the
3593 :term:`Source Directory`. Or, the target
3594 can be the name of a recipe for a specific piece of software such as
3595 BusyBox. For more details about the images the OpenEmbedded build
3596 system supports, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003597 ":ref:`ref-manual/images:Images`" chapter in the Yocto
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003598 Project Reference Manual.
3599
3600 As an example, the following command builds the
Andrew Geisslerc926e172021-05-07 16:11:35 -05003601 ``core-image-minimal`` image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003602
3603 $ bitbake core-image-minimal
3604
3605 Once an
3606 image has been built, it often needs to be installed. The images and
3607 kernels built by the OpenEmbedded build system are placed in the
3608 Build Directory in ``tmp/deploy/images``. For information on how to
3609 run pre-built images such as ``qemux86`` and ``qemuarm``, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003610 :doc:`/sdk-manual/index` manual. For
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003611 information about how to install these images, see the documentation
3612 for your particular board or machine.
3613
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003614Building Images for Multiple Targets Using Multiple Configurations
3615------------------------------------------------------------------
3616
3617You can use a single ``bitbake`` command to build multiple images or
3618packages for different targets where each image or package requires a
3619different configuration (multiple configuration builds). The builds, in
3620this scenario, are sometimes referred to as "multiconfigs", and this
3621section uses that term throughout.
3622
3623This section describes how to set up for multiple configuration builds
3624and how to account for cross-build dependencies between the
3625multiconfigs.
3626
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003627Setting Up and Running a Multiple Configuration Build
3628~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3629
3630To accomplish a multiple configuration build, you must define each
3631target's configuration separately using a parallel configuration file in
3632the :term:`Build Directory`, and you
3633must follow a required file hierarchy. Additionally, you must enable the
3634multiple configuration builds in your ``local.conf`` file.
3635
3636Follow these steps to set up and execute multiple configuration builds:
3637
3638- *Create Separate Configuration Files*: You need to create a single
3639 configuration file for each build target (each multiconfig).
3640 Minimally, each configuration file must define the machine and the
3641 temporary directory BitBake uses for the build. Suggested practice
3642 dictates that you do not overlap the temporary directories used
3643 during the builds. However, it is possible that you can share the
3644 temporary directory
3645 (:term:`TMPDIR`). For example,
3646 consider a scenario with two different multiconfigs for the same
3647 :term:`MACHINE`: "qemux86" built
3648 for two distributions such as "poky" and "poky-lsb". In this case,
3649 you might want to use the same ``TMPDIR``.
3650
3651 Here is an example showing the minimal statements needed in a
3652 configuration file for a "qemux86" target whose temporary build
Andrew Geisslerc926e172021-05-07 16:11:35 -05003653 directory is ``tmpmultix86``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003654
3655 MACHINE = "qemux86"
3656 TMPDIR = "${TOPDIR}/tmpmultix86"
3657
3658 The location for these multiconfig configuration files is specific.
3659 They must reside in the current build directory in a sub-directory of
3660 ``conf`` named ``multiconfig``. Following is an example that defines
3661 two configuration files for the "x86" and "arm" multiconfigs:
3662
3663 .. image:: figures/multiconfig_files.png
3664 :align: center
3665
3666 The reason for this required file hierarchy is because the ``BBPATH``
3667 variable is not constructed until the layers are parsed.
3668 Consequently, using the configuration file as a pre-configuration
3669 file is not possible unless it is located in the current working
3670 directory.
3671
3672- *Add the BitBake Multi-configuration Variable to the Local
3673 Configuration File*: Use the
3674 :term:`BBMULTICONFIG`
3675 variable in your ``conf/local.conf`` configuration file to specify
3676 each multiconfig. Continuing with the example from the previous
3677 figure, the ``BBMULTICONFIG`` variable needs to enable two
Andrew Geisslerc926e172021-05-07 16:11:35 -05003678 multiconfigs: "x86" and "arm" by specifying each configuration file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003679
3680 BBMULTICONFIG = "x86 arm"
3681
3682 .. note::
3683
3684 A "default" configuration already exists by definition. This
3685 configuration is named: "" (i.e. empty string) and is defined by
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003686 the variables coming from your ``local.conf``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003687 file. Consequently, the previous example actually adds two
3688 additional configurations to your build: "arm" and "x86" along
3689 with "".
3690
3691- *Launch BitBake*: Use the following BitBake command form to launch
Andrew Geisslerc926e172021-05-07 16:11:35 -05003692 the multiple configuration build::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003693
3694 $ bitbake [mc:multiconfigname:]target [[[mc:multiconfigname:]target] ... ]
3695
Andrew Geisslerc926e172021-05-07 16:11:35 -05003696 For the example in this section, the following command applies::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003697
3698 $ bitbake mc:x86:core-image-minimal mc:arm:core-image-sato mc::core-image-base
3699
3700 The previous BitBake command builds a ``core-image-minimal`` image
3701 that is configured through the ``x86.conf`` configuration file, a
3702 ``core-image-sato`` image that is configured through the ``arm.conf``
3703 configuration file and a ``core-image-base`` that is configured
3704 through your ``local.conf`` configuration file.
3705
3706.. note::
3707
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003708 Support for multiple configuration builds in the Yocto Project &DISTRO;
3709 (&DISTRO_NAME;) Release does not include Shared State (sstate)
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003710 optimizations. Consequently, if a build uses the same object twice
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003711 in, for example, two different ``TMPDIR``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003712 directories, the build either loads from an existing sstate cache for
3713 that build at the start or builds the object fresh.
3714
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003715Enabling Multiple Configuration Build Dependencies
3716~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3717
3718Sometimes dependencies can exist between targets (multiconfigs) in a
3719multiple configuration build. For example, suppose that in order to
3720build a ``core-image-sato`` image for an "x86" multiconfig, the root
3721filesystem of an "arm" multiconfig must exist. This dependency is
3722essentially that the
3723:ref:`ref-tasks-image` task in the
3724``core-image-sato`` recipe depends on the completion of the
3725:ref:`ref-tasks-rootfs` task of the
3726``core-image-minimal`` recipe.
3727
3728To enable dependencies in a multiple configuration build, you must
3729declare the dependencies in the recipe using the following statement
Andrew Geisslerc926e172021-05-07 16:11:35 -05003730form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003731
3732 task_or_package[mcdepends] = "mc:from_multiconfig:to_multiconfig:recipe_name:task_on_which_to_depend"
3733
3734To better show how to use this statement, consider the example scenario
3735from the first paragraph of this section. The following statement needs
Andrew Geisslerc926e172021-05-07 16:11:35 -05003736to be added to the recipe that builds the ``core-image-sato`` image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003737
3738 do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_rootfs"
3739
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003740In this example, the `from_multiconfig` is "x86". The `to_multiconfig` is "arm". The
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003741task on which the ``do_image`` task in the recipe depends is the
3742``do_rootfs`` task from the ``core-image-minimal`` recipe associated
3743with the "arm" multiconfig.
3744
3745Once you set up this dependency, you can build the "x86" multiconfig
Andrew Geisslerc926e172021-05-07 16:11:35 -05003746using a BitBake command as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003747
3748 $ bitbake mc:x86:core-image-sato
3749
3750This command executes all the tasks needed to create the
3751``core-image-sato`` image for the "x86" multiconfig. Because of the
3752dependency, BitBake also executes through the ``do_rootfs`` task for the
3753"arm" multiconfig build.
3754
3755Having a recipe depend on the root filesystem of another build might not
3756seem that useful. Consider this change to the statement in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05003757``core-image-sato`` recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003758
3759 do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_image"
3760
3761In this case, BitBake must
3762create the ``core-image-minimal`` image for the "arm" build since the
3763"x86" build depends on it.
3764
3765Because "x86" and "arm" are enabled for multiple configuration builds
3766and have separate configuration files, BitBake places the artifacts for
3767each build in the respective temporary build directories (i.e.
3768:term:`TMPDIR`).
3769
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003770Building an Initial RAM Filesystem (initramfs) Image
3771----------------------------------------------------
3772
3773An initial RAM filesystem (initramfs) image provides a temporary root
3774filesystem used for early system initialization (e.g. loading of modules
3775needed to locate and mount the "real" root filesystem).
3776
3777.. note::
3778
3779 The initramfs image is the successor of initial RAM disk (initrd). It
3780 is a "copy in and out" (cpio) archive of the initial filesystem that
3781 gets loaded into memory during the Linux startup process. Because
3782 Linux uses the contents of the archive during initialization, the
3783 initramfs image needs to contain all of the device drivers and tools
3784 needed to mount the final root filesystem.
3785
3786Follow these steps to create an initramfs image:
3787
37881. *Create the initramfs Image Recipe:* You can reference the
3789 ``core-image-minimal-initramfs.bb`` recipe found in the
3790 ``meta/recipes-core`` directory of the :term:`Source Directory`
3791 as an example
3792 from which to work.
3793
37942. *Decide if You Need to Bundle the initramfs Image Into the Kernel
3795 Image:* If you want the initramfs image that is built to be bundled
3796 in with the kernel image, set the
3797 :term:`INITRAMFS_IMAGE_BUNDLE`
3798 variable to "1" in your ``local.conf`` configuration file and set the
3799 :term:`INITRAMFS_IMAGE`
3800 variable in the recipe that builds the kernel image.
3801
3802 .. note::
3803
3804 It is recommended that you do bundle the initramfs image with the
3805 kernel image to avoid circular dependencies between the kernel
3806 recipe and the initramfs recipe should the initramfs image include
3807 kernel modules.
3808
3809 Setting the ``INITRAMFS_IMAGE_BUNDLE`` flag causes the initramfs
3810 image to be unpacked into the ``${B}/usr/`` directory. The unpacked
3811 initramfs image is then passed to the kernel's ``Makefile`` using the
3812 :term:`CONFIG_INITRAMFS_SOURCE`
3813 variable, allowing the initramfs image to be built into the kernel
3814 normally.
3815
3816 .. note::
3817
3818 If you choose to not bundle the initramfs image with the kernel
3819 image, you are essentially using an
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003820 `Initial RAM Disk (initrd) <https://en.wikipedia.org/wiki/Initrd>`__.
3821 Creating an initrd is handled primarily through the :term:`INITRD_IMAGE`,
3822 ``INITRD_LIVE``, and ``INITRD_IMAGE_LIVE`` variables. For more
3823 information, see the :ref:`ref-classes-image-live` file.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003824
38253. *Optionally Add Items to the initramfs Image Through the initramfs
3826 Image Recipe:* If you add items to the initramfs image by way of its
3827 recipe, you should use
3828 :term:`PACKAGE_INSTALL`
3829 rather than
3830 :term:`IMAGE_INSTALL`.
3831 ``PACKAGE_INSTALL`` gives more direct control of what is added to the
3832 image as compared to the defaults you might not necessarily want that
3833 are set by the :ref:`image <ref-classes-image>`
3834 or :ref:`core-image <ref-classes-core-image>`
3835 classes.
3836
38374. *Build the Kernel Image and the initramfs Image:* Build your kernel
3838 image using BitBake. Because the initramfs image recipe is a
3839 dependency of the kernel image, the initramfs image is built as well
3840 and bundled with the kernel image if you used the
3841 :term:`INITRAMFS_IMAGE_BUNDLE`
3842 variable described earlier.
3843
3844Building a Tiny System
3845----------------------
3846
3847Very small distributions have some significant advantages such as
3848requiring less on-die or in-package memory (cheaper), better performance
3849through efficient cache usage, lower power requirements due to less
3850memory, faster boot times, and reduced development overhead. Some
3851real-world examples where a very small distribution gives you distinct
3852advantages are digital cameras, medical devices, and small headless
3853systems.
3854
3855This section presents information that shows you how you can trim your
3856distribution to even smaller sizes than the ``poky-tiny`` distribution,
3857which is around 5 Mbytes, that can be built out-of-the-box using the
3858Yocto Project.
3859
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003860Tiny System Overview
3861~~~~~~~~~~~~~~~~~~~~
3862
3863The following list presents the overall steps you need to consider and
3864perform to create distributions with smaller root filesystems, achieve
3865faster boot times, maintain your critical functionality, and avoid
3866initial RAM disks:
3867
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05003868- :ref:`Determine your goals and guiding principles
3869 <dev-manual/common-tasks:goals and guiding principles>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003870
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05003871- :ref:`dev-manual/common-tasks:understand what contributes to your image size`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003872
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05003873- :ref:`Reduce the size of the root filesystem
3874 <dev-manual/common-tasks:trim the root filesystem>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003875
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05003876- :ref:`Reduce the size of the kernel <dev-manual/common-tasks:trim the kernel>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003877
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05003878- :ref:`dev-manual/common-tasks:remove package management requirements`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003879
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05003880- :ref:`dev-manual/common-tasks:look for other ways to minimize size`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003881
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05003882- :ref:`dev-manual/common-tasks:iterate on the process`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003883
3884Goals and Guiding Principles
3885~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3886
3887Before you can reach your destination, you need to know where you are
3888going. Here is an example list that you can use as a guide when creating
3889very small distributions:
3890
3891- Determine how much space you need (e.g. a kernel that is 1 Mbyte or
3892 less and a root filesystem that is 3 Mbytes or less).
3893
3894- Find the areas that are currently taking 90% of the space and
3895 concentrate on reducing those areas.
3896
3897- Do not create any difficult "hacks" to achieve your goals.
3898
3899- Leverage the device-specific options.
3900
3901- Work in a separate layer so that you keep changes isolated. For
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05003902 information on how to create layers, see the
3903 ":ref:`dev-manual/common-tasks:understanding and creating layers`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003904
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003905Understand What Contributes to Your Image Size
3906~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3907
3908It is easiest to have something to start with when creating your own
3909distribution. You can use the Yocto Project out-of-the-box to create the
3910``poky-tiny`` distribution. Ultimately, you will want to make changes in
3911your own distribution that are likely modeled after ``poky-tiny``.
3912
3913.. note::
3914
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003915 To use ``poky-tiny`` in your build, set the ``DISTRO`` variable in your
3916 ``local.conf`` file to "poky-tiny" as described in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003917 ":ref:`dev-manual/common-tasks:creating your own distribution`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003918 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003919
3920Understanding some memory concepts will help you reduce the system size.
3921Memory consists of static, dynamic, and temporary memory. Static memory
3922is the TEXT (code), DATA (initialized data in the code), and BSS
3923(uninitialized data) sections. Dynamic memory represents memory that is
3924allocated at runtime: stacks, hash tables, and so forth. Temporary
3925memory is recovered after the boot process. This memory consists of
3926memory used for decompressing the kernel and for the ``__init__``
3927functions.
3928
3929To help you see where you currently are with kernel and root filesystem
3930sizes, you can use two tools found in the :term:`Source Directory`
3931in the
3932``scripts/tiny/`` directory:
3933
3934- ``ksize.py``: Reports component sizes for the kernel build objects.
3935
3936- ``dirsize.py``: Reports component sizes for the root filesystem.
3937
3938This next tool and command help you organize configuration fragments and
3939view file dependencies in a human-readable form:
3940
3941- ``merge_config.sh``: Helps you manage configuration files and
3942 fragments within the kernel. With this tool, you can merge individual
3943 configuration fragments together. The tool allows you to make
3944 overrides and warns you of any missing configuration options. The
3945 tool is ideal for allowing you to iterate on configurations, create
3946 minimal configurations, and create configuration files for different
3947 machines without having to duplicate your process.
3948
3949 The ``merge_config.sh`` script is part of the Linux Yocto kernel Git
3950 repositories (i.e. ``linux-yocto-3.14``, ``linux-yocto-3.10``,
3951 ``linux-yocto-3.8``, and so forth) in the ``scripts/kconfig``
3952 directory.
3953
3954 For more information on configuration fragments, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003955 ":ref:`kernel-dev/common:creating configuration fragments`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003956 section in the Yocto Project Linux Kernel Development Manual.
3957
3958- ``bitbake -u taskexp -g bitbake_target``: Using the BitBake command
3959 with these options brings up a Dependency Explorer from which you can
3960 view file dependencies. Understanding these dependencies allows you
3961 to make informed decisions when cutting out various pieces of the
3962 kernel and root filesystem.
3963
3964Trim the Root Filesystem
3965~~~~~~~~~~~~~~~~~~~~~~~~
3966
3967The root filesystem is made up of packages for booting, libraries, and
3968applications. To change things, you can configure how the packaging
3969happens, which changes the way you build them. You can also modify the
3970filesystem itself or select a different filesystem.
3971
3972First, find out what is hogging your root filesystem by running the
Andrew Geisslerc926e172021-05-07 16:11:35 -05003973``dirsize.py`` script from your root directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003974
3975 $ cd root-directory-of-image
3976 $ dirsize.py 100000 > dirsize-100k.log
3977 $ cat dirsize-100k.log
3978
3979You can apply a filter to the script to ignore files
3980under a certain size. The previous example filters out any files below
3981100 Kbytes. The sizes reported by the tool are uncompressed, and thus
3982will be smaller by a relatively constant factor in a compressed root
3983filesystem. When you examine your log file, you can focus on areas of
3984the root filesystem that take up large amounts of memory.
3985
3986You need to be sure that what you eliminate does not cripple the
3987functionality you need. One way to see how packages relate to each other
Andrew Geisslerc926e172021-05-07 16:11:35 -05003988is by using the Dependency Explorer UI with the BitBake command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003989
3990 $ cd image-directory
3991 $ bitbake -u taskexp -g image
3992
3993Use the interface to
3994select potential packages you wish to eliminate and see their dependency
3995relationships.
3996
3997When deciding how to reduce the size, get rid of packages that result in
3998minimal impact on the feature set. For example, you might not need a VGA
3999display. Or, you might be able to get by with ``devtmpfs`` and ``mdev``
4000instead of ``udev``.
4001
4002Use your ``local.conf`` file to make changes. For example, to eliminate
4003``udev`` and ``glib``, set the following in the local configuration
Andrew Geisslerc926e172021-05-07 16:11:35 -05004004file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004005
4006 VIRTUAL-RUNTIME_dev_manager = ""
4007
4008Finally, you should consider exactly the type of root filesystem you
4009need to meet your needs while also reducing its size. For example,
4010consider ``cramfs``, ``squashfs``, ``ubifs``, ``ext2``, or an
4011``initramfs`` using ``initramfs``. Be aware that ``ext3`` requires a 1
4012Mbyte journal. If you are okay with running read-only, you do not need
4013this journal.
4014
4015.. note::
4016
4017 After each round of elimination, you need to rebuild your system and
4018 then use the tools to see the effects of your reductions.
4019
4020Trim the Kernel
4021~~~~~~~~~~~~~~~
4022
4023The kernel is built by including policies for hardware-independent
4024aspects. What subsystems do you enable? For what architecture are you
4025building? Which drivers do you build by default?
4026
4027.. note::
4028
4029 You can modify the kernel source if you want to help with boot time.
4030
4031Run the ``ksize.py`` script from the top-level Linux build directory to
Andrew Geisslerc926e172021-05-07 16:11:35 -05004032get an idea of what is making up the kernel::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004033
4034 $ cd top-level-linux-build-directory
4035 $ ksize.py > ksize.log
4036 $ cat ksize.log
4037
4038When you examine the log, you will see how much space is taken up with
4039the built-in ``.o`` files for drivers, networking, core kernel files,
4040filesystem, sound, and so forth. The sizes reported by the tool are
4041uncompressed, and thus will be smaller by a relatively constant factor
4042in a compressed kernel image. Look to reduce the areas that are large
4043and taking up around the "90% rule."
4044
4045To examine, or drill down, into any particular area, use the ``-d``
Andrew Geisslerc926e172021-05-07 16:11:35 -05004046option with the script::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004047
4048 $ ksize.py -d > ksize.log
4049
4050Using this option
4051breaks out the individual file information for each area of the kernel
4052(e.g. drivers, networking, and so forth).
4053
4054Use your log file to see what you can eliminate from the kernel based on
4055features you can let go. For example, if you are not going to need
4056sound, you do not need any drivers that support sound.
4057
4058After figuring out what to eliminate, you need to reconfigure the kernel
4059to reflect those changes during the next build. You could run
4060``menuconfig`` and make all your changes at once. However, that makes it
4061difficult to see the effects of your individual eliminations and also
4062makes it difficult to replicate the changes for perhaps another target
4063device. A better method is to start with no configurations using
4064``allnoconfig``, create configuration fragments for individual changes,
4065and then manage the fragments into a single configuration file using
4066``merge_config.sh``. The tool makes it easy for you to iterate using the
4067configuration change and build cycle.
4068
4069Each time you make configuration changes, you need to rebuild the kernel
4070and check to see what impact your changes had on the overall size.
4071
4072Remove Package Management Requirements
4073~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4074
4075Packaging requirements add size to the image. One way to reduce the size
4076of the image is to remove all the packaging requirements from the image.
4077This reduction includes both removing the package manager and its unique
4078dependencies as well as removing the package management data itself.
4079
4080To eliminate all the packaging requirements for an image, be sure that
4081"package-management" is not part of your
4082:term:`IMAGE_FEATURES`
4083statement for the image. When you remove this feature, you are removing
4084the package manager as well as its dependencies from the root
4085filesystem.
4086
4087Look for Other Ways to Minimize Size
4088~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4089
4090Depending on your particular circumstances, other areas that you can
4091trim likely exist. The key to finding these areas is through tools and
4092methods described here combined with experimentation and iteration. Here
4093are a couple of areas to experiment with:
4094
4095- ``glibc``: In general, follow this process:
4096
4097 1. Remove ``glibc`` features from
4098 :term:`DISTRO_FEATURES`
4099 that you think you do not need.
4100
4101 2. Build your distribution.
4102
4103 3. If the build fails due to missing symbols in a package, determine
4104 if you can reconfigure the package to not need those features. For
4105 example, change the configuration to not support wide character
4106 support as is done for ``ncurses``. Or, if support for those
4107 characters is needed, determine what ``glibc`` features provide
4108 the support and restore the configuration.
4109
4110 4. Rebuild and repeat the process.
4111
4112- ``busybox``: For BusyBox, use a process similar as described for
4113 ``glibc``. A difference is you will need to boot the resulting system
4114 to see if you are able to do everything you expect from the running
4115 system. You need to be sure to integrate configuration fragments into
4116 Busybox because BusyBox handles its own core features and then allows
4117 you to add configuration fragments on top.
4118
4119Iterate on the Process
4120~~~~~~~~~~~~~~~~~~~~~~
4121
4122If you have not reached your goals on system size, you need to iterate
4123on the process. The process is the same. Use the tools and see just what
4124is taking up 90% of the root filesystem and the kernel. Decide what you
4125can eliminate without limiting your device beyond what you need.
4126
4127Depending on your system, a good place to look might be Busybox, which
4128provides a stripped down version of Unix tools in a single, executable
4129file. You might be able to drop virtual terminal services or perhaps
4130ipv6.
4131
4132Building Images for More than One Machine
4133-----------------------------------------
4134
4135A common scenario developers face is creating images for several
4136different machines that use the same software environment. In this
4137situation, it is tempting to set the tunings and optimization flags for
4138each build specifically for the targeted hardware (i.e. "maxing out" the
4139tunings). Doing so can considerably add to build times and package feed
4140maintenance collectively for the machines. For example, selecting tunes
4141that are extremely specific to a CPU core used in a system might enable
4142some micro optimizations in GCC for that particular system but would
4143otherwise not gain you much of a performance difference across the other
4144systems as compared to using a more general tuning across all the builds
4145(e.g. setting :term:`DEFAULTTUNE`
4146specifically for each machine's build). Rather than "max out" each
4147build's tunings, you can take steps that cause the OpenEmbedded build
4148system to reuse software across the various machines where it makes
4149sense.
4150
4151If build speed and package feed maintenance are considerations, you
4152should consider the points in this section that can help you optimize
4153your tunings to best consider build times and package feed maintenance.
4154
4155- *Share the Build Directory:* If at all possible, share the
4156 :term:`TMPDIR` across builds. The
4157 Yocto Project supports switching between different
4158 :term:`MACHINE` values in the same
4159 ``TMPDIR``. This practice is well supported and regularly used by
4160 developers when building for multiple machines. When you use the same
4161 ``TMPDIR`` for multiple machine builds, the OpenEmbedded build system
4162 can reuse the existing native and often cross-recipes for multiple
4163 machines. Thus, build time decreases.
4164
4165 .. note::
4166
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004167 If :term:`DISTRO` settings change or fundamental configuration settings
4168 such as the filesystem layout, you need to work with a clean ``TMPDIR``.
4169 Sharing ``TMPDIR`` under these circumstances might work but since it is
4170 not guaranteed, you should use a clean ``TMPDIR``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004171
4172- *Enable the Appropriate Package Architecture:* By default, the
4173 OpenEmbedded build system enables three levels of package
4174 architectures: "all", "tune" or "package", and "machine". Any given
4175 recipe usually selects one of these package architectures (types) for
4176 its output. Depending for what a given recipe creates packages,
4177 making sure you enable the appropriate package architecture can
4178 directly impact the build time.
4179
4180 A recipe that just generates scripts can enable "all" architecture
4181 because there are no binaries to build. To specifically enable "all"
4182 architecture, be sure your recipe inherits the
4183 :ref:`allarch <ref-classes-allarch>` class.
4184 This class is useful for "all" architectures because it configures
4185 many variables so packages can be used across multiple architectures.
4186
4187 If your recipe needs to generate packages that are machine-specific
4188 or when one of the build or runtime dependencies is already
4189 machine-architecture dependent, which makes your recipe also
4190 machine-architecture dependent, make sure your recipe enables the
4191 "machine" package architecture through the
4192 :term:`MACHINE_ARCH`
Andrew Geisslerc926e172021-05-07 16:11:35 -05004193 variable::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004194
4195 PACKAGE_ARCH = "${MACHINE_ARCH}"
4196
4197 When you do not
4198 specifically enable a package architecture through the
4199 :term:`PACKAGE_ARCH`, The
4200 OpenEmbedded build system defaults to the
Andrew Geisslerc926e172021-05-07 16:11:35 -05004201 :term:`TUNE_PKGARCH` setting::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004202
4203 PACKAGE_ARCH = "${TUNE_PKGARCH}"
4204
4205- *Choose a Generic Tuning File if Possible:* Some tunes are more
4206 generic and can run on multiple targets (e.g. an ``armv5`` set of
4207 packages could run on ``armv6`` and ``armv7`` processors in most
4208 cases). Similarly, ``i486`` binaries could work on ``i586`` and
4209 higher processors. You should realize, however, that advances on
4210 newer processor versions would not be used.
4211
4212 If you select the same tune for several different machines, the
4213 OpenEmbedded build system reuses software previously built, thus
4214 speeding up the overall build time. Realize that even though a new
4215 sysroot for each machine is generated, the software is not recompiled
4216 and only one package feed exists.
4217
4218- *Manage Granular Level Packaging:* Sometimes cases exist where
4219 injecting another level of package architecture beyond the three
4220 higher levels noted earlier can be useful. For example, consider how
4221 NXP (formerly Freescale) allows for the easy reuse of binary packages
4222 in their layer
Andrew Geissler09209ee2020-12-13 08:44:15 -06004223 :yocto_git:`meta-freescale </meta-freescale/>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004224 In this example, the
Andrew Geissler09209ee2020-12-13 08:44:15 -06004225 :yocto_git:`fsl-dynamic-packagearch </meta-freescale/tree/classes/fsl-dynamic-packagearch.bbclass>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004226 class shares GPU packages for i.MX53 boards because all boards share
4227 the AMD GPU. The i.MX6-based boards can do the same because all
4228 boards share the Vivante GPU. This class inspects the BitBake
4229 datastore to identify if the package provides or depends on one of
4230 the sub-architecture values. If so, the class sets the
4231 :term:`PACKAGE_ARCH` value
4232 based on the ``MACHINE_SUBARCH`` value. If the package does not
4233 provide or depend on one of the sub-architecture values but it
4234 matches a value in the machine-specific filter, it sets
4235 :term:`MACHINE_ARCH`. This
4236 behavior reduces the number of packages built and saves build time by
4237 reusing binaries.
4238
4239- *Use Tools to Debug Issues:* Sometimes you can run into situations
4240 where software is being rebuilt when you think it should not be. For
4241 example, the OpenEmbedded build system might not be using shared
4242 state between machines when you think it should be. These types of
4243 situations are usually due to references to machine-specific
4244 variables such as :term:`MACHINE`,
4245 :term:`SERIAL_CONSOLES`,
4246 :term:`XSERVER`,
4247 :term:`MACHINE_FEATURES`,
4248 and so forth in code that is supposed to only be tune-specific or
4249 when the recipe depends
4250 (:term:`DEPENDS`,
4251 :term:`RDEPENDS`,
4252 :term:`RRECOMMENDS`,
4253 :term:`RSUGGESTS`, and so forth)
4254 on some other recipe that already has
4255 :term:`PACKAGE_ARCH` defined
4256 as "${MACHINE_ARCH}".
4257
4258 .. note::
4259
4260 Patches to fix any issues identified are most welcome as these
4261 issues occasionally do occur.
4262
4263 For such cases, you can use some tools to help you sort out the
4264 situation:
4265
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004266 - ``state-diff-machines.sh``*:* You can find this tool in the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004267 ``scripts`` directory of the Source Repositories. See the comments
4268 in the script for information on how to use the tool.
4269
4270 - *BitBake's "-S printdiff" Option:* Using this option causes
4271 BitBake to try to establish the closest signature match it can
4272 (e.g. in the shared state cache) and then run ``bitbake-diffsigs``
4273 over the matches to determine the stamps and delta where these two
4274 stamp trees diverge.
4275
4276Building Software from an External Source
4277-----------------------------------------
4278
4279By default, the OpenEmbedded build system uses the
4280:term:`Build Directory` when building source
4281code. The build process involves fetching the source files, unpacking
4282them, and then patching them if necessary before the build takes place.
4283
4284Situations exist where you might want to build software from source
4285files that are external to and thus outside of the OpenEmbedded build
4286system. For example, suppose you have a project that includes a new BSP
4287with a heavily customized kernel. And, you want to minimize exposing the
4288build system to the development team so that they can focus on their
4289project and maintain everyone's workflow as much as possible. In this
4290case, you want a kernel source directory on the development machine
4291where the development occurs. You want the recipe's
4292:term:`SRC_URI` variable to point to
4293the external directory and use it as is, not copy it.
4294
4295To build from software that comes from an external source, all you need
4296to do is inherit the
4297:ref:`externalsrc <ref-classes-externalsrc>` class
4298and then set the
4299:term:`EXTERNALSRC` variable to
4300point to your external source code. Here are the statements to put in
Andrew Geisslerc926e172021-05-07 16:11:35 -05004301your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004302
4303 INHERIT += "externalsrc"
4304 EXTERNALSRC_pn-myrecipe = "path-to-your-source-tree"
4305
4306This next example shows how to accomplish the same thing by setting
Andrew Geisslerc926e172021-05-07 16:11:35 -05004307``EXTERNALSRC`` in the recipe itself or in the recipe's append file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004308
4309 EXTERNALSRC = "path"
4310 EXTERNALSRC_BUILD = "path"
4311
4312.. note::
4313
4314 In order for these settings to take effect, you must globally or
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004315 locally inherit the :ref:`externalsrc <ref-classes-externalsrc>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004316 class.
4317
4318By default, ``externalsrc.bbclass`` builds the source code in a
4319directory separate from the external source directory as specified by
4320:term:`EXTERNALSRC`. If you need
4321to have the source built in the same directory in which it resides, or
4322some other nominated directory, you can set
4323:term:`EXTERNALSRC_BUILD`
Andrew Geisslerc926e172021-05-07 16:11:35 -05004324to point to that directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004325
4326 EXTERNALSRC_BUILD_pn-myrecipe = "path-to-your-source-tree"
4327
4328Replicating a Build Offline
4329---------------------------
4330
4331It can be useful to take a "snapshot" of upstream sources used in a
4332build and then use that "snapshot" later to replicate the build offline.
4333To do so, you need to first prepare and populate your downloads
4334directory your "snapshot" of files. Once your downloads directory is
4335ready, you can use it at any time and from any machine to replicate your
4336build.
4337
4338Follow these steps to populate your Downloads directory:
4339
43401. *Create a Clean Downloads Directory:* Start with an empty downloads
4341 directory (:term:`DL_DIR`). You
4342 start with an empty downloads directory by either removing the files
4343 in the existing directory or by setting ``DL_DIR`` to point to either
4344 an empty location or one that does not yet exist.
4345
43462. *Generate Tarballs of the Source Git Repositories:* Edit your
Andrew Geisslerc926e172021-05-07 16:11:35 -05004347 ``local.conf`` configuration file as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004348
4349 DL_DIR = "/home/your-download-dir/"
4350 BB_GENERATE_MIRROR_TARBALLS = "1"
4351
4352 During
4353 the fetch process in the next step, BitBake gathers the source files
4354 and creates tarballs in the directory pointed to by ``DL_DIR``. See
4355 the
4356 :term:`BB_GENERATE_MIRROR_TARBALLS`
4357 variable for more information.
4358
43593. *Populate Your Downloads Directory Without Building:* Use BitBake to
Andrew Geisslerc926e172021-05-07 16:11:35 -05004360 fetch your sources but inhibit the build::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004361
4362 $ bitbake target --runonly=fetch
4363
4364 The downloads directory (i.e. ``${DL_DIR}``) now has
4365 a "snapshot" of the source files in the form of tarballs, which can
4366 be used for the build.
4367
43684. *Optionally Remove Any Git or other SCM Subdirectories From the
4369 Downloads Directory:* If you want, you can clean up your downloads
4370 directory by removing any Git or other Source Control Management
4371 (SCM) subdirectories such as ``${DL_DIR}/git2/*``. The tarballs
4372 already contain these subdirectories.
4373
4374Once your downloads directory has everything it needs regarding source
4375files, you can create your "own-mirror" and build your target.
4376Understand that you can use the files to build the target offline from
4377any machine and at any time.
4378
4379Follow these steps to build your target using the files in the downloads
4380directory:
4381
43821. *Using Local Files Only:* Inside your ``local.conf`` file, add the
4383 :term:`SOURCE_MIRROR_URL`
4384 variable, inherit the
4385 :ref:`own-mirrors <ref-classes-own-mirrors>`
4386 class, and use the
4387 :term:`bitbake:BB_NO_NETWORK`
4388 variable to your ``local.conf``.
4389 ::
4390
4391 SOURCE_MIRROR_URL ?= "file:///home/your-download-dir/"
4392 INHERIT += "own-mirrors"
4393 BB_NO_NETWORK = "1"
4394
4395 The ``SOURCE_MIRROR_URL`` and ``own-mirror``
4396 class set up the system to use the downloads directory as your "own
4397 mirror". Using the ``BB_NO_NETWORK`` variable makes sure that
4398 BitBake's fetching process in step 3 stays local, which means files
4399 from your "own-mirror" are used.
4400
44012. *Start With a Clean Build:* You can start with a clean build by
4402 removing the
4403 ``${``\ :term:`TMPDIR`\ ``}``
4404 directory or using a new :term:`Build Directory`.
4405
Andrew Geisslerc926e172021-05-07 16:11:35 -050044063. *Build Your Target:* Use BitBake to build your target::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004407
4408 $ bitbake target
4409
4410 The build completes using the known local "snapshot" of source
4411 files from your mirror. The resulting tarballs for your "snapshot" of
4412 source files are in the downloads directory.
4413
4414 .. note::
4415
4416 The offline build does not work if recipes attempt to find the
4417 latest version of software by setting
4418 :term:`SRCREV` to
Andrew Geisslerc926e172021-05-07 16:11:35 -05004419 ``${``\ :term:`AUTOREV`\ ``}``::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004420
4421 SRCREV = "${AUTOREV}"
4422
4423 When a recipe sets ``SRCREV`` to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004424 ``${AUTOREV}``, the build system accesses the network in an
4425 attempt to determine the latest version of software from the SCM.
4426 Typically, recipes that use ``AUTOREV`` are custom or modified
4427 recipes. Recipes that reside in public repositories usually do not
4428 use ``AUTOREV``.
4429
4430 If you do have recipes that use ``AUTOREV``, you can take steps to
4431 still use the recipes in an offline build. Do the following:
4432
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004433 1. Use a configuration generated by enabling :ref:`build
4434 history <dev-manual/common-tasks:maintaining build output quality>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004435
4436 2. Use the ``buildhistory-collect-srcrevs`` command to collect the
4437 stored ``SRCREV`` values from the build's history. For more
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004438 information on collecting these values, see the
4439 ":ref:`dev-manual/common-tasks:build history package information`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004440 section.
4441
4442 3. Once you have the correct source revisions, you can modify
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004443 those recipes to set ``SRCREV`` to specific versions of the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004444 software.
4445
4446Speeding Up a Build
4447===================
4448
4449Build time can be an issue. By default, the build system uses simple
4450controls to try and maximize build efficiency. In general, the default
4451settings for all the following variables result in the most efficient
4452build times when dealing with single socket systems (i.e. a single CPU).
4453If you have multiple CPUs, you might try increasing the default values
4454to gain more speed. See the descriptions in the glossary for each
4455variable for more information:
4456
4457- :term:`BB_NUMBER_THREADS`:
4458 The maximum number of threads BitBake simultaneously executes.
4459
4460- :term:`bitbake:BB_NUMBER_PARSE_THREADS`:
4461 The number of threads BitBake uses during parsing.
4462
4463- :term:`PARALLEL_MAKE`: Extra
4464 options passed to the ``make`` command during the
4465 :ref:`ref-tasks-compile` task in
4466 order to specify parallel compilation on the local build host.
4467
4468- :term:`PARALLEL_MAKEINST`:
4469 Extra options passed to the ``make`` command during the
4470 :ref:`ref-tasks-install` task in
4471 order to specify parallel installation on the local build host.
4472
4473As mentioned, these variables all scale to the number of processor cores
4474available on the build system. For single socket systems, this
4475auto-scaling ensures that the build system fundamentally takes advantage
4476of potential parallel operations during the build based on the build
4477machine's capabilities.
4478
4479Following are additional factors that can affect build speed:
4480
4481- File system type: The file system type that the build is being
4482 performed on can also influence performance. Using ``ext4`` is
4483 recommended as compared to ``ext2`` and ``ext3`` due to ``ext4``
4484 improved features such as extents.
4485
4486- Disabling the updating of access time using ``noatime``: The
4487 ``noatime`` mount option prevents the build system from updating file
4488 and directory access times.
4489
4490- Setting a longer commit: Using the "commit=" mount option increases
4491 the interval in seconds between disk cache writes. Changing this
4492 interval from the five second default to something longer increases
4493 the risk of data loss but decreases the need to write to the disk,
4494 thus increasing the build performance.
4495
4496- Choosing the packaging backend: Of the available packaging backends,
4497 IPK is the fastest. Additionally, selecting a singular packaging
4498 backend also helps.
4499
4500- Using ``tmpfs`` for :term:`TMPDIR`
4501 as a temporary file system: While this can help speed up the build,
4502 the benefits are limited due to the compiler using ``-pipe``. The
4503 build system goes to some lengths to avoid ``sync()`` calls into the
4504 file system on the principle that if there was a significant failure,
4505 the :term:`Build Directory`
4506 contents could easily be rebuilt.
4507
4508- Inheriting the
4509 :ref:`rm_work <ref-classes-rm-work>` class:
4510 Inheriting this class has shown to speed up builds due to
4511 significantly lower amounts of data stored in the data cache as well
4512 as on disk. Inheriting this class also makes cleanup of
4513 :term:`TMPDIR` faster, at the
4514 expense of being easily able to dive into the source code. File
4515 system maintainers have recommended that the fastest way to clean up
4516 large numbers of files is to reformat partitions rather than delete
4517 files due to the linear nature of partitions. This, of course,
4518 assumes you structure the disk partitions and file systems in a way
4519 that this is practical.
4520
4521Aside from the previous list, you should keep some trade offs in mind
4522that can help you speed up the build:
4523
4524- Remove items from
4525 :term:`DISTRO_FEATURES`
4526 that you might not need.
4527
4528- Exclude debug symbols and other debug information: If you do not need
4529 these symbols and other debug information, disabling the ``*-dbg``
4530 package generation can speed up the build. You can disable this
4531 generation by setting the
4532 :term:`INHIBIT_PACKAGE_DEBUG_SPLIT`
4533 variable to "1".
4534
4535- Disable static library generation for recipes derived from
4536 ``autoconf`` or ``libtool``: Following is an example showing how to
4537 disable static libraries and still provide an override to handle
Andrew Geisslerc926e172021-05-07 16:11:35 -05004538 exceptions::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004539
4540 STATICLIBCONF = "--disable-static"
4541 STATICLIBCONF_sqlite3-native = ""
4542 EXTRA_OECONF += "${STATICLIBCONF}"
4543
4544 .. note::
4545
4546 - Some recipes need static libraries in order to work correctly
4547 (e.g. ``pseudo-native`` needs ``sqlite3-native``). Overrides,
4548 as in the previous example, account for these kinds of
4549 exceptions.
4550
4551 - Some packages have packaging code that assumes the presence of
4552 the static libraries. If so, you might need to exclude them as
4553 well.
4554
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004555Working With Libraries
4556======================
4557
4558Libraries are an integral part of your system. This section describes
4559some common practices you might find helpful when working with libraries
4560to build your system:
4561
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004562- :ref:`How to include static library files
4563 <dev-manual/common-tasks:including static library files>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004564
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004565- :ref:`How to use the Multilib feature to combine multiple versions of
4566 library files into a single image
4567 <dev-manual/common-tasks:combining multiple versions of library files into one image>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004568
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004569- :ref:`How to install multiple versions of the same library in parallel on
4570 the same system
4571 <dev-manual/common-tasks:installing multiple versions of the same library>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004572
4573Including Static Library Files
4574------------------------------
4575
4576If you are building a library and the library offers static linking, you
4577can control which static library files (``*.a`` files) get included in
4578the built library.
4579
4580The :term:`PACKAGES` and
4581:term:`FILES_* <FILES>` variables in the
4582``meta/conf/bitbake.conf`` configuration file define how files installed
4583by the ``do_install`` task are packaged. By default, the ``PACKAGES``
4584variable includes ``${PN}-staticdev``, which represents all static
4585library files.
4586
4587.. note::
4588
4589 Some previously released versions of the Yocto Project defined the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004590 static library files through ``${PN}-dev``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004591
4592Following is part of the BitBake configuration file, where you can see
Andrew Geisslerc926e172021-05-07 16:11:35 -05004593how the static library files are defined::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004594
4595 PACKAGE_BEFORE_PN ?= ""
4596 PACKAGES = "${PN}-dbg ${PN}-staticdev ${PN}-dev ${PN}-doc ${PN}-locale ${PACKAGE_BEFORE_PN} ${PN}"
4597 PACKAGES_DYNAMIC = "^${PN}-locale-.*"
4598 FILES = ""
4599
4600 FILES_${PN} = "${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*${SOLIBS} \
4601 ${sysconfdir} ${sharedstatedir} ${localstatedir} \
4602 ${base_bindir}/* ${base_sbindir}/* \
4603 ${base_libdir}/*${SOLIBS} \
4604 ${base_prefix}/lib/udev/rules.d ${prefix}/lib/udev/rules.d \
4605 ${datadir}/${BPN} ${libdir}/${BPN}/* \
4606 ${datadir}/pixmaps ${datadir}/applications \
4607 ${datadir}/idl ${datadir}/omf ${datadir}/sounds \
4608 ${libdir}/bonobo/servers"
4609
4610 FILES_${PN}-bin = "${bindir}/* ${sbindir}/*"
4611
4612 FILES_${PN}-doc = "${docdir} ${mandir} ${infodir} ${datadir}/gtk-doc \
4613 ${datadir}/gnome/help"
4614 SECTION_${PN}-doc = "doc"
4615
4616 FILES_SOLIBSDEV ?= "${base_libdir}/lib*${SOLIBSDEV} ${libdir}/lib*${SOLIBSDEV}"
4617 FILES_${PN}-dev = "${includedir} ${FILES_SOLIBSDEV} ${libdir}/*.la \
4618 ${libdir}/*.o ${libdir}/pkgconfig ${datadir}/pkgconfig \
4619 ${datadir}/aclocal ${base_libdir}/*.o \
4620 ${libdir}/${BPN}/*.la ${base_libdir}/*.la"
4621 SECTION_${PN}-dev = "devel"
4622 ALLOW_EMPTY_${PN}-dev = "1"
4623 RDEPENDS_${PN}-dev = "${PN} (= ${EXTENDPKGV})"
4624
4625 FILES_${PN}-staticdev = "${libdir}/*.a ${base_libdir}/*.a ${libdir}/${BPN}/*.a"
4626 SECTION_${PN}-staticdev = "devel"
4627 RDEPENDS_${PN}-staticdev = "${PN}-dev (= ${EXTENDPKGV})"
4628
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004629Combining Multiple Versions of Library Files into One Image
4630-----------------------------------------------------------
4631
4632The build system offers the ability to build libraries with different
4633target optimizations or architecture formats and combine these together
4634into one system image. You can link different binaries in the image
4635against the different libraries as needed for specific use cases. This
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004636feature is called "Multilib".
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004637
4638An example would be where you have most of a system compiled in 32-bit
4639mode using 32-bit libraries, but you have something large, like a
4640database engine, that needs to be a 64-bit application and uses 64-bit
4641libraries. Multilib allows you to get the best of both 32-bit and 64-bit
4642libraries.
4643
4644While the Multilib feature is most commonly used for 32 and 64-bit
4645differences, the approach the build system uses facilitates different
4646target optimizations. You could compile some binaries to use one set of
4647libraries and other binaries to use a different set of libraries. The
4648libraries could differ in architecture, compiler options, or other
4649optimizations.
4650
4651Several examples exist in the ``meta-skeleton`` layer found in the
4652:term:`Source Directory`:
4653
4654- ``conf/multilib-example.conf`` configuration file
4655
4656- ``conf/multilib-example2.conf`` configuration file
4657
4658- ``recipes-multilib/images/core-image-multilib-example.bb`` recipe
4659
4660Preparing to Use Multilib
4661~~~~~~~~~~~~~~~~~~~~~~~~~
4662
4663User-specific requirements drive the Multilib feature. Consequently,
4664there is no one "out-of-the-box" configuration that likely exists to
4665meet your needs.
4666
4667In order to enable Multilib, you first need to ensure your recipe is
4668extended to support multiple libraries. Many standard recipes are
4669already extended and support multiple libraries. You can check in the
4670``meta/conf/multilib.conf`` configuration file in the
4671:term:`Source Directory` to see how this is
4672done using the
4673:term:`BBCLASSEXTEND` variable.
4674Eventually, all recipes will be covered and this list will not be
4675needed.
4676
4677For the most part, the Multilib class extension works automatically to
4678extend the package name from ``${PN}`` to ``${MLPREFIX}${PN}``, where
4679``MLPREFIX`` is the particular multilib (e.g. "lib32-" or "lib64-").
4680Standard variables such as
4681:term:`DEPENDS`,
4682:term:`RDEPENDS`,
4683:term:`RPROVIDES`,
4684:term:`RRECOMMENDS`,
4685:term:`PACKAGES`, and
4686:term:`PACKAGES_DYNAMIC` are
4687automatically extended by the system. If you are extending any manual
4688code in the recipe, you can use the ``${MLPREFIX}`` variable to ensure
4689those names are extended correctly. This automatic extension code
4690resides in ``multilib.bbclass``.
4691
4692Using Multilib
4693~~~~~~~~~~~~~~
4694
4695After you have set up the recipes, you need to define the actual
4696combination of multiple libraries you want to build. You accomplish this
4697through your ``local.conf`` configuration file in the
4698:term:`Build Directory`. An example
Andrew Geisslerc926e172021-05-07 16:11:35 -05004699configuration would be as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004700
4701 MACHINE = "qemux86-64"
4702 require conf/multilib.conf
4703 MULTILIBS = "multilib:lib32"
4704 DEFAULTTUNE_virtclass-multilib-lib32 = "x86"
4705 IMAGE_INSTALL_append = "lib32-glib-2.0"
4706
4707This example enables an additional library named
4708``lib32`` alongside the normal target packages. When combining these
4709"lib32" alternatives, the example uses "x86" for tuning. For information
4710on this particular tuning, see
4711``meta/conf/machine/include/ia32/arch-ia32.inc``.
4712
4713The example then includes ``lib32-glib-2.0`` in all the images, which
4714illustrates one method of including a multiple library dependency. You
Andrew Geisslerc926e172021-05-07 16:11:35 -05004715can use a normal image build to include this dependency, for example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004716
4717 $ bitbake core-image-sato
4718
4719You can also build Multilib packages
Andrew Geisslerc926e172021-05-07 16:11:35 -05004720specifically with a command like this::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004721
4722 $ bitbake lib32-glib-2.0
4723
4724Additional Implementation Details
4725~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4726
4727Generic implementation details as well as details that are specific to
4728package management systems exist. Following are implementation details
4729that exist regardless of the package management system:
4730
4731- The typical convention used for the class extension code as used by
4732 Multilib assumes that all package names specified in
4733 :term:`PACKAGES` that contain
4734 ``${PN}`` have ``${PN}`` at the start of the name. When that
4735 convention is not followed and ``${PN}`` appears at the middle or the
4736 end of a name, problems occur.
4737
4738- The :term:`TARGET_VENDOR`
4739 value under Multilib will be extended to "-vendormlmultilib" (e.g.
4740 "-pokymllib32" for a "lib32" Multilib with Poky). The reason for this
4741 slightly unwieldy contraction is that any "-" characters in the
4742 vendor string presently break Autoconf's ``config.sub``, and other
4743 separators are problematic for different reasons.
4744
4745For the RPM Package Management System, the following implementation
4746details exist:
4747
4748- A unique architecture is defined for the Multilib packages, along
4749 with creating a unique deploy folder under ``tmp/deploy/rpm`` in the
4750 :term:`Build Directory`. For
4751 example, consider ``lib32`` in a ``qemux86-64`` image. The possible
4752 architectures in the system are "all", "qemux86_64",
4753 "lib32_qemux86_64", and "lib32_x86".
4754
4755- The ``${MLPREFIX}`` variable is stripped from ``${PN}`` during RPM
4756 packaging. The naming for a normal RPM package and a Multilib RPM
4757 package in a ``qemux86-64`` system resolves to something similar to
4758 ``bash-4.1-r2.x86_64.rpm`` and ``bash-4.1.r2.lib32_x86.rpm``,
4759 respectively.
4760
4761- When installing a Multilib image, the RPM backend first installs the
4762 base image and then installs the Multilib libraries.
4763
4764- The build system relies on RPM to resolve the identical files in the
4765 two (or more) Multilib packages.
4766
4767For the IPK Package Management System, the following implementation
4768details exist:
4769
4770- The ``${MLPREFIX}`` is not stripped from ``${PN}`` during IPK
4771 packaging. The naming for a normal RPM package and a Multilib IPK
4772 package in a ``qemux86-64`` system resolves to something like
4773 ``bash_4.1-r2.x86_64.ipk`` and ``lib32-bash_4.1-rw_x86.ipk``,
4774 respectively.
4775
4776- The IPK deploy folder is not modified with ``${MLPREFIX}`` because
4777 packages with and without the Multilib feature can exist in the same
4778 folder due to the ``${PN}`` differences.
4779
4780- IPK defines a sanity check for Multilib installation using certain
4781 rules for file comparison, overridden, etc.
4782
4783Installing Multiple Versions of the Same Library
4784------------------------------------------------
4785
4786Situations can exist where you need to install and use multiple versions
4787of the same library on the same system at the same time. These
4788situations almost always exist when a library API changes and you have
4789multiple pieces of software that depend on the separate versions of the
4790library. To accommodate these situations, you can install multiple
4791versions of the same library in parallel on the same system.
4792
4793The process is straightforward as long as the libraries use proper
4794versioning. With properly versioned libraries, all you need to do to
4795individually specify the libraries is create separate, appropriately
4796named recipes where the :term:`PN` part of
4797the name includes a portion that differentiates each library version
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004798(e.g. the major part of the version number). Thus, instead of having a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004799single recipe that loads one version of a library (e.g. ``clutter``),
4800you provide multiple recipes that result in different versions of the
4801libraries you want. As an example, the following two recipes would allow
4802the two separate versions of the ``clutter`` library to co-exist on the
4803same system:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004804
4805.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004806
4807 clutter-1.6_1.6.20.bb
4808 clutter-1.8_1.8.4.bb
4809
4810Additionally, if
4811you have other recipes that depend on a given library, you need to use
4812the :term:`DEPENDS` variable to
4813create the dependency. Continuing with the same example, if you want to
4814have a recipe depend on the 1.8 version of the ``clutter`` library, use
Andrew Geisslerc926e172021-05-07 16:11:35 -05004815the following in your recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004816
4817 DEPENDS = "clutter-1.8"
4818
4819Using x32 psABI
4820===============
4821
4822x32 processor-specific Application Binary Interface (`x32
4823psABI <https://software.intel.com/en-us/node/628948>`__) is a native
482432-bit processor-specific ABI for Intel 64 (x86-64) architectures. An
4825ABI defines the calling conventions between functions in a processing
4826environment. The interface determines what registers are used and what
4827the sizes are for various C data types.
4828
4829Some processing environments prefer using 32-bit applications even when
4830running on Intel 64-bit platforms. Consider the i386 psABI, which is a
4831very old 32-bit ABI for Intel 64-bit platforms. The i386 psABI does not
4832provide efficient use and access of the Intel 64-bit processor
4833resources, leaving the system underutilized. Now consider the x86_64
4834psABI. This ABI is newer and uses 64-bits for data sizes and program
4835pointers. The extra bits increase the footprint size of the programs,
4836libraries, and also increases the memory and file system size
4837requirements. Executing under the x32 psABI enables user programs to
4838utilize CPU and system resources more efficiently while keeping the
4839memory footprint of the applications low. Extra bits are used for
4840registers but not for addressing mechanisms.
4841
4842The Yocto Project supports the final specifications of x32 psABI as
4843follows:
4844
4845- You can create packages and images in x32 psABI format on x86_64
4846 architecture targets.
4847
4848- You can successfully build recipes with the x32 toolchain.
4849
4850- You can create and boot ``core-image-minimal`` and
4851 ``core-image-sato`` images.
4852
4853- RPM Package Manager (RPM) support exists for x32 binaries.
4854
4855- Support for large images exists.
4856
4857To use the x32 psABI, you need to edit your ``conf/local.conf``
Andrew Geisslerc926e172021-05-07 16:11:35 -05004858configuration file as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004859
4860 MACHINE = "qemux86-64"
4861 DEFAULTTUNE = "x86-64-x32"
4862 baselib = "${@d.getVar('BASE_LIB_tune-' + (d.getVar('DEFAULTTUNE') \
4863 or 'INVALID')) or 'lib'}"
4864
4865Once you have set
4866up your configuration file, use BitBake to build an image that supports
Andrew Geisslerc926e172021-05-07 16:11:35 -05004867the x32 psABI. Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004868
4869 $ bitbake core-image-sato
4870
4871Enabling GObject Introspection Support
4872======================================
4873
4874`GObject
4875introspection <https://wiki.gnome.org/Projects/GObjectIntrospection>`__
4876is the standard mechanism for accessing GObject-based software from
4877runtime environments. GObject is a feature of the GLib library that
4878provides an object framework for the GNOME desktop and related software.
4879GObject Introspection adds information to GObject that allows objects
4880created within it to be represented across different programming
4881languages. If you want to construct GStreamer pipelines using Python, or
4882control UPnP infrastructure using Javascript and GUPnP, GObject
4883introspection is the only way to do it.
4884
4885This section describes the Yocto Project support for generating and
4886packaging GObject introspection data. GObject introspection data is a
4887description of the API provided by libraries built on top of GLib
4888framework, and, in particular, that framework's GObject mechanism.
4889GObject Introspection Repository (GIR) files go to ``-dev`` packages,
4890``typelib`` files go to main packages as they are packaged together with
4891libraries that are introspected.
4892
4893The data is generated when building such a library, by linking the
4894library with a small executable binary that asks the library to describe
4895itself, and then executing the binary and processing its output.
4896
4897Generating this data in a cross-compilation environment is difficult
4898because the library is produced for the target architecture, but its
4899code needs to be executed on the build host. This problem is solved with
4900the OpenEmbedded build system by running the code through QEMU, which
4901allows precisely that. Unfortunately, QEMU does not always work
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004902perfectly as mentioned in the ":ref:`dev-manual/common-tasks:known issues`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004903section.
4904
4905Enabling the Generation of Introspection Data
4906---------------------------------------------
4907
4908Enabling the generation of introspection data (GIR files) in your
4909library package involves the following:
4910
49111. Inherit the
4912 :ref:`gobject-introspection <ref-classes-gobject-introspection>`
4913 class.
4914
49152. Make sure introspection is not disabled anywhere in the recipe or
4916 from anything the recipe includes. Also, make sure that
4917 "gobject-introspection-data" is not in
4918 :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`
4919 and that "qemu-usermode" is not in
4920 :term:`MACHINE_FEATURES_BACKFILL_CONSIDERED`.
4921 If either of these conditions exist, nothing will happen.
4922
49233. Try to build the recipe. If you encounter build errors that look like
4924 something is unable to find ``.so`` libraries, check where these
4925 libraries are located in the source tree and add the following to the
Andrew Geisslerc926e172021-05-07 16:11:35 -05004926 recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004927
4928 GIR_EXTRA_LIBS_PATH = "${B}/something/.libs"
4929
4930 .. note::
4931
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004932 See recipes in the ``oe-core`` repository that use that
4933 ``GIR_EXTRA_LIBS_PATH`` variable as an example.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004934
49354. Look for any other errors, which probably mean that introspection
4936 support in a package is not entirely standard, and thus breaks down
4937 in a cross-compilation environment. For such cases, custom-made fixes
4938 are needed. A good place to ask and receive help in these cases is
4939 the :ref:`Yocto Project mailing
4940 lists <resources-mailinglist>`.
4941
4942.. note::
4943
4944 Using a library that no longer builds against the latest Yocto
4945 Project release and prints introspection related errors is a good
4946 candidate for the previous procedure.
4947
4948Disabling the Generation of Introspection Data
4949----------------------------------------------
4950
4951You might find that you do not want to generate introspection data. Or,
4952perhaps QEMU does not work on your build host and target architecture
4953combination. If so, you can use either of the following methods to
4954disable GIR file generations:
4955
Andrew Geisslerc926e172021-05-07 16:11:35 -05004956- Add the following to your distro configuration::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004957
4958 DISTRO_FEATURES_BACKFILL_CONSIDERED = "gobject-introspection-data"
4959
4960 Adding this statement disables generating introspection data using
4961 QEMU but will still enable building introspection tools and libraries
4962 (i.e. building them does not require the use of QEMU).
4963
Andrew Geisslerc926e172021-05-07 16:11:35 -05004964- Add the following to your machine configuration::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004965
4966 MACHINE_FEATURES_BACKFILL_CONSIDERED = "qemu-usermode"
4967
4968 Adding this statement disables the use of QEMU when building packages for your
4969 machine. Currently, this feature is used only by introspection
4970 recipes and has the same effect as the previously described option.
4971
4972 .. note::
4973
4974 Future releases of the Yocto Project might have other features
4975 affected by this option.
4976
4977If you disable introspection data, you can still obtain it through other
4978means such as copying the data from a suitable sysroot, or by generating
4979it on the target hardware. The OpenEmbedded build system does not
4980currently provide specific support for these techniques.
4981
4982Testing that Introspection Works in an Image
4983--------------------------------------------
4984
4985Use the following procedure to test if generating introspection data is
4986working in an image:
4987
49881. Make sure that "gobject-introspection-data" is not in
4989 :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`
4990 and that "qemu-usermode" is not in
4991 :term:`MACHINE_FEATURES_BACKFILL_CONSIDERED`.
4992
49932. Build ``core-image-sato``.
4994
49953. Launch a Terminal and then start Python in the terminal.
4996
Andrew Geisslerc926e172021-05-07 16:11:35 -050049974. Enter the following in the terminal::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004998
4999 >>> from gi.repository import GLib
5000 >>> GLib.get_host_name()
5001
50025. For something a little more advanced, enter the following see:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005003 https://python-gtk-3-tutorial.readthedocs.io/en/latest/introduction.html
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005004
5005Known Issues
5006------------
5007
5008The following know issues exist for GObject Introspection Support:
5009
5010- ``qemu-ppc64`` immediately crashes. Consequently, you cannot build
5011 introspection data on that architecture.
5012
5013- x32 is not supported by QEMU. Consequently, introspection data is
5014 disabled.
5015
5016- musl causes transient GLib binaries to crash on assertion failures.
5017 Consequently, generating introspection data is disabled.
5018
5019- Because QEMU is not able to run the binaries correctly, introspection
5020 is disabled for some specific packages under specific architectures
5021 (e.g. ``gcr``, ``libsecret``, and ``webkit``).
5022
5023- QEMU usermode might not work properly when running 64-bit binaries
5024 under 32-bit host machines. In particular, "qemumips64" is known to
5025 not work under i686.
5026
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005027Optionally Using an External Toolchain
5028======================================
5029
5030You might want to use an external toolchain as part of your development.
5031If this is the case, the fundamental steps you need to accomplish are as
5032follows:
5033
5034- Understand where the installed toolchain resides. For cases where you
5035 need to build the external toolchain, you would need to take separate
5036 steps to build and install the toolchain.
5037
5038- Make sure you add the layer that contains the toolchain to your
5039 ``bblayers.conf`` file through the
5040 :term:`BBLAYERS` variable.
5041
5042- Set the ``EXTERNAL_TOOLCHAIN`` variable in your ``local.conf`` file
5043 to the location in which you installed the toolchain.
5044
5045A good example of an external toolchain used with the Yocto Project is
5046Mentor Graphics Sourcery G++ Toolchain. You can see information on how
5047to use that particular layer in the ``README`` file at
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005048https://github.com/MentorEmbedded/meta-sourcery/. You can find
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005049further information by reading about the
5050:term:`TCMODE` variable in the Yocto
5051Project Reference Manual's variable glossary.
5052
5053Creating Partitioned Images Using Wic
5054=====================================
5055
5056Creating an image for a particular hardware target using the
5057OpenEmbedded build system does not necessarily mean you can boot that
5058image as is on your device. Physical devices accept and boot images in
5059various ways depending on the specifics of the device. Usually,
5060information about the hardware can tell you what image format the device
5061requires. Should your device require multiple partitions on an SD card,
5062flash, or an HDD, you can use the OpenEmbedded Image Creator, Wic, to
5063create the properly partitioned image.
5064
5065The ``wic`` command generates partitioned images from existing
5066OpenEmbedded build artifacts. Image generation is driven by partitioning
5067commands contained in an Openembedded kickstart file (``.wks``)
5068specified either directly on the command line or as one of a selection
5069of canned kickstart files as shown with the ``wic list images`` command
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05005070in the
5071":ref:`dev-manual/common-tasks:generate an image using an existing kickstart file`"
5072section. When you apply the command to a given set of build artifacts, the
5073result is an image or set of images that can be directly written onto media and
5074used on a particular system.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005075
5076.. note::
5077
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005078 For a kickstart file reference, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06005079 ":ref:`ref-manual/kickstart:openembedded kickstart (\`\`.wks\`\`) reference`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005080 Chapter in the Yocto Project Reference Manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005081
5082The ``wic`` command and the infrastructure it is based on is by
5083definition incomplete. The purpose of the command is to allow the
5084generation of customized images, and as such, was designed to be
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05005085completely extensible through a plugin interface. See the
5086":ref:`dev-manual/common-tasks:using the wic plugin interface`" section
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005087for information on these plugins.
5088
5089This section provides some background information on Wic, describes what
5090you need to have in place to run the tool, provides instruction on how
5091to use the Wic utility, provides information on using the Wic plugins
5092interface, and provides several examples that show how to use Wic.
5093
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005094Background
5095----------
5096
5097This section provides some background on the Wic utility. While none of
5098this information is required to use Wic, you might find it interesting.
5099
5100- The name "Wic" is derived from OpenEmbedded Image Creator (oeic). The
5101 "oe" diphthong in "oeic" was promoted to the letter "w", because
5102 "oeic" is both difficult to remember and to pronounce.
5103
5104- Wic is loosely based on the Meego Image Creator (``mic``) framework.
5105 The Wic implementation has been heavily modified to make direct use
5106 of OpenEmbedded build artifacts instead of package installation and
5107 configuration, which are already incorporated within the OpenEmbedded
5108 artifacts.
5109
5110- Wic is a completely independent standalone utility that initially
5111 provides easier-to-use and more flexible replacements for an existing
5112 functionality in OE-Core's
5113 :ref:`image-live <ref-classes-image-live>`
5114 class. The difference between Wic and those examples is that with Wic
5115 the functionality of those scripts is implemented by a
5116 general-purpose partitioning language, which is based on Redhat
5117 kickstart syntax.
5118
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005119Requirements
5120------------
5121
5122In order to use the Wic utility with the OpenEmbedded Build system, your
5123system needs to meet the following requirements:
5124
5125- The Linux distribution on your development host must support the
5126 Yocto Project. See the ":ref:`detailed-supported-distros`"
5127 section in the Yocto Project Reference Manual for the list of
5128 distributions that support the Yocto Project.
5129
5130- The standard system utilities, such as ``cp``, must be installed on
5131 your development host system.
5132
5133- You must have sourced the build environment setup script (i.e.
5134 :ref:`structure-core-script`) found in the
5135 :term:`Build Directory`.
5136
5137- You need to have the build artifacts already available, which
5138 typically means that you must have already created an image using the
5139 Openembedded build system (e.g. ``core-image-minimal``). While it
5140 might seem redundant to generate an image in order to create an image
5141 using Wic, the current version of Wic requires the artifacts in the
5142 form generated by the OpenEmbedded build system.
5143
5144- You must build several native tools, which are built to run on the
Andrew Geisslerc926e172021-05-07 16:11:35 -05005145 build system::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005146
5147 $ bitbake parted-native dosfstools-native mtools-native
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005148
5149- Include "wic" as part of the
5150 :term:`IMAGE_FSTYPES`
5151 variable.
5152
5153- Include the name of the :ref:`wic kickstart file <openembedded-kickstart-wks-reference>`
5154 as part of the :term:`WKS_FILE` variable
5155
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005156Getting Help
5157------------
5158
5159You can get general help for the ``wic`` command by entering the ``wic``
5160command by itself or by entering the command with a help argument as
Andrew Geisslerc926e172021-05-07 16:11:35 -05005161follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005162
5163 $ wic -h
5164 $ wic --help
5165 $ wic help
5166
5167Currently, Wic supports seven commands: ``cp``, ``create``, ``help``,
5168``list``, ``ls``, ``rm``, and ``write``. You can get help for all these
Andrew Geisslerc926e172021-05-07 16:11:35 -05005169commands except "help" by using the following form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005170
5171 $ wic help command
5172
5173For example, the following command returns help for the ``write``
Andrew Geisslerc926e172021-05-07 16:11:35 -05005174command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005175
5176 $ wic help write
5177
5178Wic supports help for three topics: ``overview``, ``plugins``, and
Andrew Geisslerc926e172021-05-07 16:11:35 -05005179``kickstart``. You can get help for any topic using the following form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005180
5181 $ wic help topic
5182
Andrew Geisslerc926e172021-05-07 16:11:35 -05005183For example, the following returns overview help for Wic::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005184
5185 $ wic help overview
5186
5187One additional level of help exists for Wic. You can get help on
5188individual images through the ``list`` command. You can use the ``list``
Andrew Geisslerc926e172021-05-07 16:11:35 -05005189command to return the available Wic images as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005190
5191 $ wic list images
5192 genericx86 Create an EFI disk image for genericx86*
5193 beaglebone-yocto Create SD card image for Beaglebone
5194 edgerouter Create SD card image for Edgerouter
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05005195 qemux86-directdisk Create a QEMU machine 'pcbios' direct disk image
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005196 directdisk-gpt Create a 'pcbios' direct disk image
5197 mkefidisk Create an EFI disk image
5198 directdisk Create a 'pcbios' direct disk image
5199 systemd-bootdisk Create an EFI disk image with systemd-boot
5200 mkhybridiso Create a hybrid ISO image
5201 sdimage-bootpart Create SD card image with a boot partition
5202 directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
5203 directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
5204
5205Once you know the list of available
5206Wic images, you can use ``help`` with the command to get help on a
5207particular image. For example, the following command returns help on the
Andrew Geisslerc926e172021-05-07 16:11:35 -05005208"beaglebone-yocto" image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005209
5210 $ wic list beaglebone-yocto help
5211
5212 Creates a partitioned SD card image for Beaglebone.
5213 Boot files are located in the first vfat partition.
5214
5215Operational Modes
5216-----------------
5217
5218You can use Wic in two different modes, depending on how much control
5219you need for specifying the Openembedded build artifacts that are used
5220for creating the image: Raw and Cooked:
5221
5222- *Raw Mode:* You explicitly specify build artifacts through Wic
5223 command-line arguments.
5224
5225- *Cooked Mode:* The current
5226 :term:`MACHINE` setting and image
5227 name are used to automatically locate and provide the build
5228 artifacts. You just supply a kickstart file and the name of the image
5229 from which to use artifacts.
5230
5231Regardless of the mode you use, you need to have the build artifacts
5232ready and available.
5233
5234Raw Mode
5235~~~~~~~~
5236
5237Running Wic in raw mode allows you to specify all the partitions through
5238the ``wic`` command line. The primary use for raw mode is if you have
5239built your kernel outside of the Yocto Project
5240:term:`Build Directory`. In other words, you
5241can point to arbitrary kernel, root filesystem locations, and so forth.
5242Contrast this behavior with cooked mode where Wic looks in the Build
5243Directory (e.g. ``tmp/deploy/images/``\ machine).
5244
Andrew Geisslerc926e172021-05-07 16:11:35 -05005245The general form of the ``wic`` command in raw mode is::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005246
5247 $ wic create wks_file options ...
5248
5249 Where:
5250
5251 wks_file:
5252 An OpenEmbedded kickstart file. You can provide
5253 your own custom file or use a file from a set of
5254 existing files as described by further options.
5255
5256 optional arguments:
5257 -h, --help show this help message and exit
5258 -o OUTDIR, --outdir OUTDIR
5259 name of directory to create image in
5260 -e IMAGE_NAME, --image-name IMAGE_NAME
5261 name of the image to use the artifacts from e.g. core-
5262 image-sato
5263 -r ROOTFS_DIR, --rootfs-dir ROOTFS_DIR
5264 path to the /rootfs dir to use as the .wks rootfs
5265 source
5266 -b BOOTIMG_DIR, --bootimg-dir BOOTIMG_DIR
5267 path to the dir containing the boot artifacts (e.g.
5268 /EFI or /syslinux dirs) to use as the .wks bootimg
5269 source
5270 -k KERNEL_DIR, --kernel-dir KERNEL_DIR
5271 path to the dir containing the kernel to use in the
5272 .wks bootimg
5273 -n NATIVE_SYSROOT, --native-sysroot NATIVE_SYSROOT
5274 path to the native sysroot containing the tools to use
5275 to build the image
5276 -s, --skip-build-check
5277 skip the build check
5278 -f, --build-rootfs build rootfs
5279 -c {gzip,bzip2,xz}, --compress-with {gzip,bzip2,xz}
5280 compress image with specified compressor
5281 -m, --bmap generate .bmap
5282 --no-fstab-update Do not change fstab file.
5283 -v VARS_DIR, --vars VARS_DIR
5284 directory with <image>.env files that store bitbake
5285 variables
5286 -D, --debug output debug information
5287
5288.. note::
5289
5290 You do not need root privileges to run Wic. In fact, you should not
5291 run as root when using the utility.
5292
5293Cooked Mode
5294~~~~~~~~~~~
5295
5296Running Wic in cooked mode leverages off artifacts in the Build
5297Directory. In other words, you do not have to specify kernel or root
5298filesystem locations as part of the command. All you need to provide is
5299a kickstart file and the name of the image from which to use artifacts
5300by using the "-e" option. Wic looks in the Build Directory (e.g.
5301``tmp/deploy/images/``\ machine) for artifacts.
5302
Andrew Geisslerc926e172021-05-07 16:11:35 -05005303The general form of the ``wic`` command using Cooked Mode is as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005304
5305 $ wic create wks_file -e IMAGE_NAME
5306
5307 Where:
5308
5309 wks_file:
5310 An OpenEmbedded kickstart file. You can provide
5311 your own custom file or use a file from a set of
5312 existing files provided with the Yocto Project
5313 release.
5314
5315 required argument:
5316 -e IMAGE_NAME, --image-name IMAGE_NAME
5317 name of the image to use the artifacts from e.g. core-
5318 image-sato
5319
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005320Using an Existing Kickstart File
5321--------------------------------
5322
5323If you do not want to create your own kickstart file, you can use an
5324existing file provided by the Wic installation. As shipped, kickstart
Andrew Geissler09209ee2020-12-13 08:44:15 -06005325files can be found in the :ref:`overview-manual/development-environment:yocto project source repositories` in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05005326following two locations::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005327
5328 poky/meta-yocto-bsp/wic
5329 poky/scripts/lib/wic/canned-wks
5330
Andrew Geisslerc926e172021-05-07 16:11:35 -05005331Use the following command to list the available kickstart files::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005332
5333 $ wic list images
5334 genericx86 Create an EFI disk image for genericx86*
5335 beaglebone-yocto Create SD card image for Beaglebone
5336 edgerouter Create SD card image for Edgerouter
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05005337 qemux86-directdisk Create a QEMU machine 'pcbios' direct disk image
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005338 directdisk-gpt Create a 'pcbios' direct disk image
5339 mkefidisk Create an EFI disk image
5340 directdisk Create a 'pcbios' direct disk image
5341 systemd-bootdisk Create an EFI disk image with systemd-boot
5342 mkhybridiso Create a hybrid ISO image
5343 sdimage-bootpart Create SD card image with a boot partition
5344 directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
5345 directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
5346
5347When you use an existing file, you
5348do not have to use the ``.wks`` extension. Here is an example in Raw
Andrew Geisslerc926e172021-05-07 16:11:35 -05005349Mode that uses the ``directdisk`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005350
5351 $ wic create directdisk -r rootfs_dir -b bootimg_dir \
5352 -k kernel_dir -n native_sysroot
5353
5354Here are the actual partition language commands used in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05005355``genericx86.wks`` file to generate an image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005356
5357 # short-description: Create an EFI disk image for genericx86*
5358 # long-description: Creates a partitioned EFI disk image for genericx86* machines
5359 part /boot --source bootimg-efi --sourceparams="loader=grub-efi" --ondisk sda --label msdos --active --align 1024
5360 part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid
5361 part swap --ondisk sda --size 44 --label swap1 --fstype=swap
5362
5363 bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=ttyS0,115200 console=tty0"
5364
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005365Using the Wic Plugin Interface
5366------------------------------
5367
5368You can extend and specialize Wic functionality by using Wic plugins.
5369This section explains the Wic plugin interface.
5370
5371.. note::
5372
5373 Wic plugins consist of "source" and "imager" plugins. Imager plugins
5374 are beyond the scope of this section.
5375
5376Source plugins provide a mechanism to customize partition content during
5377the Wic image generation process. You can use source plugins to map
5378values that you specify using ``--source`` commands in kickstart files
5379(i.e. ``*.wks``) to a plugin implementation used to populate a given
5380partition.
5381
5382.. note::
5383
5384 If you use plugins that have build-time dependencies (e.g. native
5385 tools, bootloaders, and so forth) when building a Wic image, you need
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005386 to specify those dependencies using the :term:`WKS_FILE_DEPENDS`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005387 variable.
5388
5389Source plugins are subclasses defined in plugin files. As shipped, the
5390Yocto Project provides several plugin files. You can see the source
5391plugin files that ship with the Yocto Project
Andrew Geissler09209ee2020-12-13 08:44:15 -06005392:yocto_git:`here </poky/tree/scripts/lib/wic/plugins/source>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005393Each of these plugin files contains source plugins that are designed to
5394populate a specific Wic image partition.
5395
5396Source plugins are subclasses of the ``SourcePlugin`` class, which is
5397defined in the ``poky/scripts/lib/wic/pluginbase.py`` file. For example,
5398the ``BootimgEFIPlugin`` source plugin found in the ``bootimg-efi.py``
5399file is a subclass of the ``SourcePlugin`` class, which is found in the
5400``pluginbase.py`` file.
5401
5402You can also implement source plugins in a layer outside of the Source
5403Repositories (external layer). To do so, be sure that your plugin files
5404are located in a directory whose path is
5405``scripts/lib/wic/plugins/source/`` within your external layer. When the
5406plugin files are located there, the source plugins they contain are made
5407available to Wic.
5408
5409When the Wic implementation needs to invoke a partition-specific
5410implementation, it looks for the plugin with the same name as the
5411``--source`` parameter used in the kickstart file given to that
5412partition. For example, if the partition is set up using the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05005413command in a kickstart file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005414
5415 part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024
5416
5417The methods defined as class
5418members of the matching source plugin (i.e. ``bootimg-pcbios``) in the
5419``bootimg-pcbios.py`` plugin file are used.
5420
5421To be more concrete, here is the corresponding plugin definition from
5422the ``bootimg-pcbios.py`` file for the previous command along with an
5423example method called by the Wic implementation when it needs to prepare
Andrew Geisslerc926e172021-05-07 16:11:35 -05005424a partition using an implementation-specific function::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005425
5426 .
5427 .
5428 .
5429 class BootimgPcbiosPlugin(SourcePlugin):
5430 """
5431 Create MBR boot partition and install syslinux on it.
5432 """
5433
5434 name = 'bootimg-pcbios'
5435 .
5436 .
5437 .
5438 @classmethod
5439 def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
5440 oe_builddir, bootimg_dir, kernel_dir,
5441 rootfs_dir, native_sysroot):
5442 """
5443 Called to do the actual content population for a partition i.e. it
5444 'prepares' the partition to be incorporated into the image.
5445 In this case, prepare content for legacy bios boot partition.
5446 """
5447 .
5448 .
5449 .
5450
5451If a
5452subclass (plugin) itself does not implement a particular function, Wic
5453locates and uses the default version in the superclass. It is for this
5454reason that all source plugins are derived from the ``SourcePlugin``
5455class.
5456
5457The ``SourcePlugin`` class defined in the ``pluginbase.py`` file defines
5458a set of methods that source plugins can implement or override. Any
5459plugins (subclass of ``SourcePlugin``) that do not implement a
5460particular method inherit the implementation of the method from the
5461``SourcePlugin`` class. For more information, see the ``SourcePlugin``
5462class in the ``pluginbase.py`` file for details:
5463
5464The following list describes the methods implemented in the
5465``SourcePlugin`` class:
5466
5467- ``do_prepare_partition()``: Called to populate a partition with
5468 actual content. In other words, the method prepares the final
5469 partition image that is incorporated into the disk image.
5470
5471- ``do_configure_partition()``: Called before
5472 ``do_prepare_partition()`` to create custom configuration files for a
5473 partition (e.g. syslinux or grub configuration files).
5474
5475- ``do_install_disk()``: Called after all partitions have been
5476 prepared and assembled into a disk image. This method provides a hook
5477 to allow finalization of a disk image (e.g. writing an MBR).
5478
5479- ``do_stage_partition()``: Special content-staging hook called
5480 before ``do_prepare_partition()``. This method is normally empty.
5481
5482 Typically, a partition just uses the passed-in parameters (e.g. the
5483 unmodified value of ``bootimg_dir``). However, in some cases, things
5484 might need to be more tailored. As an example, certain files might
5485 additionally need to be taken from ``bootimg_dir + /boot``. This hook
5486 allows those files to be staged in a customized fashion.
5487
5488 .. note::
5489
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005490 ``get_bitbake_var()`` allows you to access non-standard variables that
5491 you might want to use for this behavior.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005492
5493You can extend the source plugin mechanism. To add more hooks, create
5494more source plugin methods within ``SourcePlugin`` and the corresponding
5495derived subclasses. The code that calls the plugin methods uses the
5496``plugin.get_source_plugin_methods()`` function to find the method or
5497methods needed by the call. Retrieval of those methods is accomplished
5498by filling up a dict with keys that contain the method names of
5499interest. On success, these will be filled in with the actual methods.
5500See the Wic implementation for examples and details.
5501
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005502Wic Examples
5503------------
5504
5505This section provides several examples that show how to use the Wic
5506utility. All the examples assume the list of requirements in the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05005507":ref:`dev-manual/common-tasks:requirements`" section have been met. The
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005508examples assume the previously generated image is
5509``core-image-minimal``.
5510
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005511Generate an Image using an Existing Kickstart File
5512~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5513
5514This example runs in Cooked Mode and uses the ``mkefidisk`` kickstart
Andrew Geisslerc926e172021-05-07 16:11:35 -05005515file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005516
5517 $ wic create mkefidisk -e core-image-minimal
5518 INFO: Building wic-tools...
5519 .
5520 .
5521 .
5522 INFO: The new image(s) can be found here:
5523 ./mkefidisk-201804191017-sda.direct
5524
5525 The following build artifacts were used to create the image(s):
5526 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
5527 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
5528 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
5529 NATIVE_SYSROOT: /home/stephano/build/master/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
5530
5531 INFO: The image(s) were created using OE kickstart file:
5532 /home/stephano/build/master/openembedded-core/scripts/lib/wic/canned-wks/mkefidisk.wks
5533
5534The previous example shows the easiest way to create an image by running
5535in cooked mode and supplying a kickstart file and the "-e" option to
5536point to the existing build artifacts. Your ``local.conf`` file needs to
5537have the :term:`MACHINE` variable set
5538to the machine you are using, which is "qemux86" in this example.
5539
5540Once the image builds, the output provides image location, artifact use,
5541and kickstart file information.
5542
5543.. note::
5544
5545 You should always verify the details provided in the output to make
5546 sure that the image was indeed created exactly as expected.
5547
5548Continuing with the example, you can now write the image from the Build
5549Directory onto a USB stick, or whatever media for which you built your
5550image, and boot from the media. You can write the image by using
Andrew Geisslerc926e172021-05-07 16:11:35 -05005551``bmaptool`` or ``dd``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005552
5553 $ oe-run-native bmaptool copy mkefidisk-201804191017-sda.direct /dev/sdX
5554
5555or ::
5556
5557 $ sudo dd if=mkefidisk-201804191017-sda.direct of=/dev/sdX
5558
5559.. note::
5560
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005561 For more information on how to use the ``bmaptool``
5562 to flash a device with an image, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06005563 ":ref:`dev-manual/common-tasks:flashing images using \`\`bmaptool\`\``"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005564 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005565
5566Using a Modified Kickstart File
5567~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5568
5569Because partitioned image creation is driven by the kickstart file, it
5570is easy to affect image creation by changing the parameters in the file.
5571This next example demonstrates that through modification of the
5572``directdisk-gpt`` kickstart file.
5573
5574As mentioned earlier, you can use the command ``wic list images`` to
5575show the list of existing kickstart files. The directory in which the
5576``directdisk-gpt.wks`` file resides is
5577``scripts/lib/image/canned-wks/``, which is located in the
5578:term:`Source Directory` (e.g. ``poky``).
5579Because available files reside in this directory, you can create and add
5580your own custom files to the directory. Subsequent use of the
5581``wic list images`` command would then include your kickstart files.
5582
5583In this example, the existing ``directdisk-gpt`` file already does most
5584of what is needed. However, for the hardware in this example, the image
5585will need to boot from ``sdb`` instead of ``sda``, which is what the
5586``directdisk-gpt`` kickstart file uses.
5587
5588The example begins by making a copy of the ``directdisk-gpt.wks`` file
5589in the ``scripts/lib/image/canned-wks`` directory and then by changing
5590the lines that specify the target disk from which to boot.
5591::
5592
5593 $ cp /home/stephano/poky/scripts/lib/wic/canned-wks/directdisk-gpt.wks \
5594 /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
5595
5596Next, the example modifies the ``directdisksdb-gpt.wks`` file and
5597changes all instances of "``--ondisk sda``" to "``--ondisk sdb``". The
5598example changes the following two lines and leaves the remaining lines
Andrew Geisslerc926e172021-05-07 16:11:35 -05005599untouched::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005600
5601 part /boot --source bootimg-pcbios --ondisk sdb --label boot --active --align 1024
5602 part / --source rootfs --ondisk sdb --fstype=ext4 --label platform --align 1024 --use-uuid
5603
5604Once the lines are changed, the
5605example generates the ``directdisksdb-gpt`` image. The command points
5606the process at the ``core-image-minimal`` artifacts for the Next Unit of
5607Computing (nuc) :term:`MACHINE` the
5608``local.conf``.
5609::
5610
5611 $ wic create directdisksdb-gpt -e core-image-minimal
5612 INFO: Building wic-tools...
5613 .
5614 .
5615 .
5616 Initialising tasks: 100% |#######################################| Time: 0:00:01
5617 NOTE: Executing SetScene Tasks
5618 NOTE: Executing RunQueue Tasks
5619 NOTE: Tasks Summary: Attempted 1161 tasks of which 1157 didn't need to be rerun and all succeeded.
5620 INFO: Creating image(s)...
5621
5622 INFO: The new image(s) can be found here:
5623 ./directdisksdb-gpt-201710090938-sdb.direct
5624
5625 The following build artifacts were used to create the image(s):
5626 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
5627 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
5628 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
5629 NATIVE_SYSROOT: /home/stephano/build/master/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
5630
5631 INFO: The image(s) were created using OE kickstart file:
5632 /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
5633
5634Continuing with the example, you can now directly ``dd`` the image to a
5635USB stick, or whatever media for which you built your image, and boot
Andrew Geisslerc926e172021-05-07 16:11:35 -05005636the resulting media::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005637
5638 $ sudo dd if=directdisksdb-gpt-201710090938-sdb.direct of=/dev/sdb
5639 140966+0 records in
5640 140966+0 records out
5641 72174592 bytes (72 MB, 69 MiB) copied, 78.0282 s, 925 kB/s
5642 $ sudo eject /dev/sdb
5643
5644Using a Modified Kickstart File and Running in Raw Mode
5645~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5646
5647This next example manually specifies each build artifact (runs in Raw
5648Mode) and uses a modified kickstart file. The example also uses the
5649``-o`` option to cause Wic to create the output somewhere other than the
Andrew Geisslerc926e172021-05-07 16:11:35 -05005650default output directory, which is the current directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005651
5652 $ wic create /home/stephano/my_yocto/test.wks -o /home/stephano/testwic \
5653 --rootfs-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/rootfs \
5654 --bootimg-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share \
5655 --kernel-dir /home/stephano/build/master/build/tmp/deploy/images/qemux86 \
5656 --native-sysroot /home/stephano/build/master/build/tmp/work/i586-poky-linux/wic-tools/1.0-r0/recipe-sysroot-native
5657
5658 INFO: Creating image(s)...
5659
5660 INFO: The new image(s) can be found here:
5661 /home/stephano/testwic/test-201710091445-sdb.direct
5662
5663 The following build artifacts were used to create the image(s):
5664 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
5665 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
5666 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
5667 NATIVE_SYSROOT: /home/stephano/build/master/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
5668
5669 INFO: The image(s) were created using OE kickstart file:
5670 /home/stephano/my_yocto/test.wks
5671
5672For this example,
5673:term:`MACHINE` did not have to be
5674specified in the ``local.conf`` file since the artifact is manually
5675specified.
5676
5677Using Wic to Manipulate an Image
5678~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5679
5680Wic image manipulation allows you to shorten turnaround time during
5681image development. For example, you can use Wic to delete the kernel
5682partition of a Wic image and then insert a newly built kernel. This
5683saves you time from having to rebuild the entire image each time you
5684modify the kernel.
5685
5686.. note::
5687
5688 In order to use Wic to manipulate a Wic image as in this example,
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005689 your development machine must have the ``mtools`` package installed.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005690
5691The following example examines the contents of the Wic image, deletes
5692the existing kernel, and then inserts a new kernel:
5693
56941. *List the Partitions:* Use the ``wic ls`` command to list all the
Andrew Geisslerc926e172021-05-07 16:11:35 -05005695 partitions in the Wic image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005696
5697 $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic
5698 Num Start End Size Fstype
5699 1 1048576 25041919 23993344 fat16
5700 2 25165824 72157183 46991360 ext4
5701
5702 The previous output shows two partitions in the
5703 ``core-image-minimal-qemux86.wic`` image.
5704
57052. *Examine a Particular Partition:* Use the ``wic ls`` command again
5706 but in a different form to examine a particular partition.
5707
5708 .. note::
5709
5710 You can get command usage on any Wic command using the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05005711 form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005712
5713 $ wic help command
5714
5715
5716 For example, the following command shows you the various ways to
5717 use the
5718 wic ls
Andrew Geisslerc926e172021-05-07 16:11:35 -05005719 command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005720
5721 $ wic help ls
5722
5723
Andrew Geisslerc926e172021-05-07 16:11:35 -05005724 The following command shows what is in partition one::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005725
5726 $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1
5727 Volume in drive : is boot
5728 Volume Serial Number is E894-1809
5729 Directory for ::/
5730
5731 libcom32 c32 186500 2017-10-09 16:06
5732 libutil c32 24148 2017-10-09 16:06
5733 syslinux cfg 220 2017-10-09 16:06
5734 vesamenu c32 27104 2017-10-09 16:06
5735 vmlinuz 6904608 2017-10-09 16:06
5736 5 files 7 142 580 bytes
5737 16 582 656 bytes free
5738
5739 The previous output shows five files, with the
5740 ``vmlinuz`` being the kernel.
5741
5742 .. note::
5743
5744 If you see the following error, you need to update or create a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005745 ``~/.mtoolsrc`` file and be sure to have the line "mtools_skip_check=1"
Andrew Geisslerc926e172021-05-07 16:11:35 -05005746 in the file. Then, run the Wic command again::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005747
5748 ERROR: _exec_cmd: /usr/bin/mdir -i /tmp/wic-parttfokuwra ::/ returned '1' instead of 0
5749 output: Total number of sectors (47824) not a multiple of sectors per track (32)!
5750 Add mtools_skip_check=1 to your .mtoolsrc file to skip this test
5751
5752
57533. *Remove the Old Kernel:* Use the ``wic rm`` command to remove the
Andrew Geisslerc926e172021-05-07 16:11:35 -05005754 ``vmlinuz`` file (kernel)::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005755
5756 $ wic rm tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
5757
57584. *Add In the New Kernel:* Use the ``wic cp`` command to add the
5759 updated kernel to the Wic image. Depending on how you built your
5760 kernel, it could be in different places. If you used ``devtool`` and
5761 an SDK to build your kernel, it resides in the ``tmp/work`` directory
5762 of the extensible SDK. If you used ``make`` to build the kernel, the
5763 kernel will be in the ``workspace/sources`` area.
5764
5765 The following example assumes ``devtool`` was used to build the
Andrew Geisslerc926e172021-05-07 16:11:35 -05005766 kernel::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005767
Andrew Geissler95ac1b82021-03-31 14:34:31 -05005768 $ wic cp poky_sdk/tmp/work/qemux86-poky-linux/linux-yocto/4.12.12+git999-r0/linux-yocto-4.12.12+git999/arch/x86/boot/bzImage \
5769 poky/build/tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005770
5771 Once the new kernel is added back into the image, you can use the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005772 ``dd`` command or :ref:`bmaptool
Andrew Geissler09209ee2020-12-13 08:44:15 -06005773 <dev-manual/common-tasks:flashing images using \`\`bmaptool\`\`>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005774 to flash your wic image onto an SD card or USB stick and test your
5775 target.
5776
5777 .. note::
5778
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005779 Using ``bmaptool`` is generally 10 to 20 times faster than using ``dd``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005780
5781Flashing Images Using ``bmaptool``
5782==================================
5783
5784A fast and easy way to flash an image to a bootable device is to use
5785Bmaptool, which is integrated into the OpenEmbedded build system.
5786Bmaptool is a generic tool that creates a file's block map (bmap) and
5787then uses that map to copy the file. As compared to traditional tools
5788such as dd or cp, Bmaptool can copy (or flash) large files like raw
5789system image files much faster.
5790
5791.. note::
5792
5793 - If you are using Ubuntu or Debian distributions, you can install
5794 the ``bmap-tools`` package using the following command and then
5795 use the tool without specifying ``PATH`` even from the root
Andrew Geisslerc926e172021-05-07 16:11:35 -05005796 account::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005797
5798 $ sudo apt-get install bmap-tools
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005799
5800 - If you are unable to install the ``bmap-tools`` package, you will
Andrew Geisslerc926e172021-05-07 16:11:35 -05005801 need to build Bmaptool before using it. Use the following command::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005802
5803 $ bitbake bmap-tools-native
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005804
5805Following, is an example that shows how to flash a Wic image. Realize
5806that while this example uses a Wic image, you can use Bmaptool to flash
5807any type of image. Use these steps to flash an image using Bmaptool:
5808
58091. *Update your local.conf File:* You need to have the following set
Andrew Geisslerc926e172021-05-07 16:11:35 -05005810 in your ``local.conf`` file before building your image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005811
5812 IMAGE_FSTYPES += "wic wic.bmap"
5813
58142. *Get Your Image:* Either have your image ready (pre-built with the
5815 :term:`IMAGE_FSTYPES`
Andrew Geisslerc926e172021-05-07 16:11:35 -05005816 setting previously mentioned) or take the step to build the image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005817
5818 $ bitbake image
5819
58203. *Flash the Device:* Flash the device with the image by using Bmaptool
5821 depending on your particular setup. The following commands assume the
5822 image resides in the Build Directory's ``deploy/images/`` area:
5823
Andrew Geisslerc926e172021-05-07 16:11:35 -05005824 - If you have write access to the media, use this command form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005825
5826 $ oe-run-native bmap-tools-native bmaptool copy build-directory/tmp/deploy/images/machine/image.wic /dev/sdX
5827
5828 - If you do not have write access to the media, set your permissions
Andrew Geisslerc926e172021-05-07 16:11:35 -05005829 first and then use the same command form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005830
5831 $ sudo chmod 666 /dev/sdX
5832 $ oe-run-native bmap-tools-native bmaptool copy build-directory/tmp/deploy/images/machine/image.wic /dev/sdX
5833
Andrew Geisslerc926e172021-05-07 16:11:35 -05005834For help on the ``bmaptool`` command, use the following command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005835
5836 $ bmaptool --help
5837
5838Making Images More Secure
5839=========================
5840
5841Security is of increasing concern for embedded devices. Consider the
5842issues and problems discussed in just this sampling of work found across
5843the Internet:
5844
5845- *"*\ `Security Risks of Embedded
5846 Systems <https://www.schneier.com/blog/archives/2014/01/security_risks_9.html>`__\ *"*
5847 by Bruce Schneier
5848
5849- *"*\ `Internet Census
5850 2012 <http://census2012.sourceforge.net/paper.html>`__\ *"* by Carna
5851 Botnet
5852
5853- *"*\ `Security Issues for Embedded
Andrew Geisslerd1e89492021-02-12 15:35:20 -06005854 Devices <https://elinux.org/images/6/6f/Security-issues.pdf>`__\ *"*
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005855 by Jake Edge
5856
5857When securing your image is of concern, there are steps, tools, and
5858variables that you can consider to help you reach the security goals you
5859need for your particular device. Not all situations are identical when
5860it comes to making an image secure. Consequently, this section provides
5861some guidance and suggestions for consideration when you want to make
5862your image more secure.
5863
5864.. note::
5865
5866 Because the security requirements and risks are different for every
5867 type of device, this section cannot provide a complete reference on
5868 securing your custom OS. It is strongly recommended that you also
5869 consult other sources of information on embedded Linux system
5870 hardening and on security.
5871
5872General Considerations
5873----------------------
5874
5875General considerations exist that help you create more secure images.
5876You should consider the following suggestions to help make your device
5877more secure:
5878
5879- Scan additional code you are adding to the system (e.g. application
5880 code) by using static analysis tools. Look for buffer overflows and
5881 other potential security problems.
5882
5883- Pay particular attention to the security for any web-based
5884 administration interface.
5885
5886 Web interfaces typically need to perform administrative functions and
5887 tend to need to run with elevated privileges. Thus, the consequences
5888 resulting from the interface's security becoming compromised can be
5889 serious. Look for common web vulnerabilities such as
5890 cross-site-scripting (XSS), unvalidated inputs, and so forth.
5891
5892 As with system passwords, the default credentials for accessing a
5893 web-based interface should not be the same across all devices. This
5894 is particularly true if the interface is enabled by default as it can
5895 be assumed that many end-users will not change the credentials.
5896
5897- Ensure you can update the software on the device to mitigate
5898 vulnerabilities discovered in the future. This consideration
5899 especially applies when your device is network-enabled.
5900
5901- Ensure you remove or disable debugging functionality before producing
5902 the final image. For information on how to do this, see the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05005903 ":ref:`dev-manual/common-tasks:considerations specific to the openembedded build system`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005904 section.
5905
5906- Ensure you have no network services listening that are not needed.
5907
5908- Remove any software from the image that is not needed.
5909
5910- Enable hardware support for secure boot functionality when your
5911 device supports this functionality.
5912
5913Security Flags
5914--------------
5915
5916The Yocto Project has security flags that you can enable that help make
5917your build output more secure. The security flags are in the
5918``meta/conf/distro/include/security_flags.inc`` file in your
5919:term:`Source Directory` (e.g. ``poky``).
5920
5921.. note::
5922
5923 Depending on the recipe, certain security flags are enabled and
5924 disabled by default.
5925
5926Use the following line in your ``local.conf`` file or in your custom
5927distribution configuration file to enable the security compiler and
Andrew Geisslerc926e172021-05-07 16:11:35 -05005928linker flags for your build::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005929
5930 require conf/distro/include/security_flags.inc
5931
5932Considerations Specific to the OpenEmbedded Build System
5933--------------------------------------------------------
5934
5935You can take some steps that are specific to the OpenEmbedded build
5936system to make your images more secure:
5937
5938- Ensure "debug-tweaks" is not one of your selected
5939 :term:`IMAGE_FEATURES`.
5940 When creating a new project, the default is to provide you with an
5941 initial ``local.conf`` file that enables this feature using the
5942 :term:`EXTRA_IMAGE_FEATURES`
Andrew Geisslerc926e172021-05-07 16:11:35 -05005943 variable with the line::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005944
5945 EXTRA_IMAGE_FEATURES = "debug-tweaks"
5946
5947 To disable that feature, simply comment out that line in your
5948 ``local.conf`` file, or make sure ``IMAGE_FEATURES`` does not contain
5949 "debug-tweaks" before producing your final image. Among other things,
5950 leaving this in place sets the root password as blank, which makes
5951 logging in for debugging or inspection easy during development but
5952 also means anyone can easily log in during production.
5953
5954- It is possible to set a root password for the image and also to set
5955 passwords for any extra users you might add (e.g. administrative or
5956 service type users). When you set up passwords for multiple images or
5957 users, you should not duplicate passwords.
5958
5959 To set up passwords, use the
5960 :ref:`extrausers <ref-classes-extrausers>`
5961 class, which is the preferred method. For an example on how to set up
5962 both root and user passwords, see the
5963 ":ref:`extrausers.bbclass <ref-classes-extrausers>`"
5964 section.
5965
5966 .. note::
5967
5968 When adding extra user accounts or setting a root password, be
5969 cautious about setting the same password on every device. If you
5970 do this, and the password you have set is exposed, then every
5971 device is now potentially compromised. If you need this access but
5972 want to ensure security, consider setting a different, random
5973 password for each device. Typically, you do this as a separate
5974 step after you deploy the image onto the device.
5975
5976- Consider enabling a Mandatory Access Control (MAC) framework such as
5977 SMACK or SELinux and tuning it appropriately for your device's usage.
5978 You can find more information in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06005979 :yocto_git:`meta-selinux </meta-selinux/>` layer.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005980
5981Tools for Hardening Your Image
5982------------------------------
5983
5984The Yocto Project provides tools for making your image more secure. You
5985can find these tools in the ``meta-security`` layer of the
5986:yocto_git:`Yocto Project Source Repositories <>`.
5987
5988Creating Your Own Distribution
5989==============================
5990
5991When you build an image using the Yocto Project and do not alter any
5992distribution :term:`Metadata`, you are
5993creating a Poky distribution. If you wish to gain more control over
5994package alternative selections, compile-time options, and other
5995low-level configurations, you can create your own distribution.
5996
5997To create your own distribution, the basic steps consist of creating
5998your own distribution layer, creating your own distribution
5999configuration file, and then adding any needed code and Metadata to the
6000layer. The following steps provide some more detail:
6001
6002- *Create a layer for your new distro:* Create your distribution layer
6003 so that you can keep your Metadata and code for the distribution
6004 separate. It is strongly recommended that you create and use your own
6005 layer for configuration and code. Using your own layer as compared to
6006 just placing configurations in a ``local.conf`` configuration file
6007 makes it easier to reproduce the same build configuration when using
6008 multiple build machines. See the
Andrew Geissler09209ee2020-12-13 08:44:15 -06006009 ":ref:`dev-manual/common-tasks:creating a general layer using the \`\`bitbake-layers\`\` script`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006010 section for information on how to quickly set up a layer.
6011
6012- *Create the distribution configuration file:* The distribution
6013 configuration file needs to be created in the ``conf/distro``
6014 directory of your layer. You need to name it using your distribution
6015 name (e.g. ``mydistro.conf``).
6016
6017 .. note::
6018
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006019 The :term:`DISTRO` variable in your ``local.conf`` file determines the
6020 name of your distribution.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006021
6022 You can split out parts of your configuration file into include files
6023 and then "require" them from within your distribution configuration
6024 file. Be sure to place the include files in the
6025 ``conf/distro/include`` directory of your layer. A common example
6026 usage of include files would be to separate out the selection of
6027 desired version and revisions for individual recipes.
6028
6029 Your configuration file needs to set the following required
6030 variables:
6031
6032 - :term:`DISTRO_NAME`
6033
6034 - :term:`DISTRO_VERSION`
6035
6036 These following variables are optional and you typically set them
6037 from the distribution configuration file:
6038
6039 - :term:`DISTRO_FEATURES`
6040
6041 - :term:`DISTRO_EXTRA_RDEPENDS`
6042
6043 - :term:`DISTRO_EXTRA_RRECOMMENDS`
6044
6045 - :term:`TCLIBC`
6046
6047 .. tip::
6048
6049 If you want to base your distribution configuration file on the
6050 very basic configuration from OE-Core, you can use
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006051 ``conf/distro/defaultsetup.conf`` as a reference and just include
6052 variables that differ as compared to ``defaultsetup.conf``.
6053 Alternatively, you can create a distribution configuration file
6054 from scratch using the ``defaultsetup.conf`` file or configuration files
6055 from other distributions such as Poky or Angstrom as references.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006056
6057- *Provide miscellaneous variables:* Be sure to define any other
6058 variables for which you want to create a default or enforce as part
6059 of the distribution configuration. You can include nearly any
6060 variable from the ``local.conf`` file. The variables you use are not
6061 limited to the list in the previous bulleted item.
6062
6063- *Point to Your distribution configuration file:* In your
6064 ``local.conf`` file in the :term:`Build Directory`,
6065 set your
6066 :term:`DISTRO` variable to point to
6067 your distribution's configuration file. For example, if your
6068 distribution's configuration file is named ``mydistro.conf``, then
Andrew Geisslerc926e172021-05-07 16:11:35 -05006069 you point to it as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006070
6071 DISTRO = "mydistro"
6072
6073- *Add more to the layer if necessary:* Use your layer to hold other
6074 information needed for the distribution:
6075
6076 - Add recipes for installing distro-specific configuration files
6077 that are not already installed by another recipe. If you have
6078 distro-specific configuration files that are included by an
6079 existing recipe, you should add an append file (``.bbappend``) for
6080 those. For general information and recommendations on how to add
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006081 recipes to your layer, see the
6082 ":ref:`dev-manual/common-tasks:creating your own layer`" and
6083 ":ref:`dev-manual/common-tasks:following best practices when creating layers`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006084 sections.
6085
6086 - Add any image recipes that are specific to your distribution.
6087
6088 - Add a ``psplash`` append file for a branded splash screen. For
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006089 information on append files, see the
6090 ":ref:`dev-manual/common-tasks:using .bbappend files in your layer`"
6091 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006092
6093 - Add any other append files to make custom changes that are
6094 specific to individual recipes.
6095
6096Creating a Custom Template Configuration Directory
6097==================================================
6098
6099If you are producing your own customized version of the build system for
6100use by other users, you might want to customize the message shown by the
6101setup script or you might want to change the template configuration
6102files (i.e. ``local.conf`` and ``bblayers.conf``) that are created in a
6103new build directory.
6104
6105The OpenEmbedded build system uses the environment variable
6106``TEMPLATECONF`` to locate the directory from which it gathers
6107configuration information that ultimately ends up in the
6108:term:`Build Directory` ``conf`` directory.
6109By default, ``TEMPLATECONF`` is set as follows in the ``poky``
Andrew Geisslerc926e172021-05-07 16:11:35 -05006110repository::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006111
6112 TEMPLATECONF=${TEMPLATECONF:-meta-poky/conf}
6113
6114This is the
6115directory used by the build system to find templates from which to build
6116some key configuration files. If you look at this directory, you will
6117see the ``bblayers.conf.sample``, ``local.conf.sample``, and
6118``conf-notes.txt`` files. The build system uses these files to form the
6119respective ``bblayers.conf`` file, ``local.conf`` file, and display the
6120list of BitBake targets when running the setup script.
6121
6122To override these default configuration files with configurations you
6123want used within every new Build Directory, simply set the
6124``TEMPLATECONF`` variable to your directory. The ``TEMPLATECONF``
6125variable is set in the ``.templateconf`` file, which is in the top-level
6126:term:`Source Directory` folder
6127(e.g. ``poky``). Edit the ``.templateconf`` so that it can locate your
6128directory.
6129
6130Best practices dictate that you should keep your template configuration
6131directory in your custom distribution layer. For example, suppose you
6132have a layer named ``meta-mylayer`` located in your home directory and
6133you want your template configuration directory named ``myconf``.
6134Changing the ``.templateconf`` as follows causes the OpenEmbedded build
6135system to look in your directory and base its configuration files on the
6136``*.sample`` configuration files it finds. The final configuration files
6137(i.e. ``local.conf`` and ``bblayers.conf`` ultimately still end up in
6138your Build Directory, but they are based on your ``*.sample`` files.
6139::
6140
6141 TEMPLATECONF=${TEMPLATECONF:-meta-mylayer/myconf}
6142
6143Aside from the ``*.sample`` configuration files, the ``conf-notes.txt``
6144also resides in the default ``meta-poky/conf`` directory. The script
6145that sets up the build environment (i.e.
6146:ref:`structure-core-script`) uses this file to
6147display BitBake targets as part of the script output. Customizing this
6148``conf-notes.txt`` file is a good way to make sure your list of custom
6149targets appears as part of the script's output.
6150
6151Here is the default list of targets displayed as a result of running
Andrew Geisslerc926e172021-05-07 16:11:35 -05006152either of the setup scripts::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006153
6154 You can now run 'bitbake <target>'
6155
6156 Common targets are:
6157 core-image-minimal
6158 core-image-sato
6159 meta-toolchain
6160 meta-ide-support
6161
6162Changing the listed common targets is as easy as editing your version of
6163``conf-notes.txt`` in your custom template configuration directory and
6164making sure you have ``TEMPLATECONF`` set to your directory.
6165
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006166Conserving Disk Space During Builds
6167===================================
6168
6169To help conserve disk space during builds, you can add the following
6170statement to your project's ``local.conf`` configuration file found in
Andrew Geisslerc926e172021-05-07 16:11:35 -05006171the :term:`Build Directory`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006172
6173 INHERIT += "rm_work"
6174
6175Adding this statement deletes the work directory used for
6176building a recipe once the recipe is built. For more information on
6177"rm_work", see the
6178:ref:`rm_work <ref-classes-rm-work>` class in the
6179Yocto Project Reference Manual.
6180
6181Working with Packages
6182=====================
6183
6184This section describes a few tasks that involve packages:
6185
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006186- :ref:`dev-manual/common-tasks:excluding packages from an image`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006187
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006188- :ref:`dev-manual/common-tasks:incrementing a package version`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006189
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006190- :ref:`dev-manual/common-tasks:handling optional module packaging`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006191
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006192- :ref:`dev-manual/common-tasks:using runtime package management`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006193
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006194- :ref:`dev-manual/common-tasks:generating and using signed packages`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006195
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006196- :ref:`Setting up and running package test
6197 (ptest) <dev-manual/common-tasks:testing packages with ptest>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006198
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006199- :ref:`dev-manual/common-tasks:creating node package manager (npm) packages`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006200
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006201- :ref:`dev-manual/common-tasks:adding custom metadata to packages`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006202
6203Excluding Packages from an Image
6204--------------------------------
6205
6206You might find it necessary to prevent specific packages from being
6207installed into an image. If so, you can use several variables to direct
6208the build system to essentially ignore installing recommended packages
6209or to not install a package at all.
6210
6211The following list introduces variables you can use to prevent packages
6212from being installed into your image. Each of these variables only works
6213with IPK and RPM package types. Support for Debian packages does not
6214exist. Also, you can use these variables from your ``local.conf`` file
6215or attach them to a specific image recipe by using a recipe name
6216override. For more detail on the variables, see the descriptions in the
6217Yocto Project Reference Manual's glossary chapter.
6218
6219- :term:`BAD_RECOMMENDATIONS`:
6220 Use this variable to specify "recommended-only" packages that you do
6221 not want installed.
6222
6223- :term:`NO_RECOMMENDATIONS`:
6224 Use this variable to prevent all "recommended-only" packages from
6225 being installed.
6226
6227- :term:`PACKAGE_EXCLUDE`:
6228 Use this variable to prevent specific packages from being installed
6229 regardless of whether they are "recommended-only" or not. You need to
6230 realize that the build process could fail with an error when you
6231 prevent the installation of a package whose presence is required by
6232 an installed package.
6233
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006234Incrementing a Package Version
6235------------------------------
6236
6237This section provides some background on how binary package versioning
6238is accomplished and presents some of the services, variables, and
6239terminology involved.
6240
6241In order to understand binary package versioning, you need to consider
6242the following:
6243
6244- Binary Package: The binary package that is eventually built and
6245 installed into an image.
6246
6247- Binary Package Version: The binary package version is composed of two
6248 components - a version and a revision.
6249
6250 .. note::
6251
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006252 Technically, a third component, the "epoch" (i.e. :term:`PE`) is involved
6253 but this discussion for the most part ignores ``PE``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006254
6255 The version and revision are taken from the
6256 :term:`PV` and
6257 :term:`PR` variables, respectively.
6258
6259- ``PV``: The recipe version. ``PV`` represents the version of the
6260 software being packaged. Do not confuse ``PV`` with the binary
6261 package version.
6262
6263- ``PR``: The recipe revision.
6264
6265- :term:`SRCPV`: The OpenEmbedded
6266 build system uses this string to help define the value of ``PV`` when
6267 the source code revision needs to be included in it.
6268
Andrew Geissler09209ee2020-12-13 08:44:15 -06006269- :yocto_wiki:`PR Service </PR_Service>`: A
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006270 network-based service that helps automate keeping package feeds
6271 compatible with existing package manager applications such as RPM,
6272 APT, and OPKG.
6273
6274Whenever the binary package content changes, the binary package version
6275must change. Changing the binary package version is accomplished by
6276changing or "bumping" the ``PR`` and/or ``PV`` values. Increasing these
6277values occurs one of two ways:
6278
6279- Automatically using a Package Revision Service (PR Service).
6280
6281- Manually incrementing the ``PR`` and/or ``PV`` variables.
6282
6283Given a primary challenge of any build system and its users is how to
6284maintain a package feed that is compatible with existing package manager
6285applications such as RPM, APT, and OPKG, using an automated system is
6286much preferred over a manual system. In either system, the main
6287requirement is that binary package version numbering increases in a
6288linear fashion and that a number of version components exist that
6289support that linear progression. For information on how to ensure
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006290package revisioning remains linear, see the
6291":ref:`dev-manual/common-tasks:automatically incrementing a package version number`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006292section.
6293
6294The following three sections provide related information on the PR
6295Service, the manual method for "bumping" ``PR`` and/or ``PV``, and on
6296how to ensure binary package revisioning remains linear.
6297
6298Working With a PR Service
6299~~~~~~~~~~~~~~~~~~~~~~~~~
6300
6301As mentioned, attempting to maintain revision numbers in the
6302:term:`Metadata` is error prone, inaccurate,
6303and causes problems for people submitting recipes. Conversely, the PR
6304Service automatically generates increasing numbers, particularly the
6305revision field, which removes the human element.
6306
6307.. note::
6308
6309 For additional information on using a PR Service, you can see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06006310 :yocto_wiki:`PR Service </PR_Service>` wiki page.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006311
6312The Yocto Project uses variables in order of decreasing priority to
6313facilitate revision numbering (i.e.
6314:term:`PE`,
6315:term:`PV`, and
6316:term:`PR` for epoch, version, and
6317revision, respectively). The values are highly dependent on the policies
6318and procedures of a given distribution and package feed.
6319
6320Because the OpenEmbedded build system uses
Andrew Geissler09209ee2020-12-13 08:44:15 -06006321":ref:`signatures <overview-manual/concepts:checksums (signatures)>`", which are
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006322unique to a given build, the build system knows when to rebuild
6323packages. All the inputs into a given task are represented by a
6324signature, which can trigger a rebuild when different. Thus, the build
6325system itself does not rely on the ``PR``, ``PV``, and ``PE`` numbers to
6326trigger a rebuild. The signatures, however, can be used to generate
6327these values.
6328
6329The PR Service works with both ``OEBasic`` and ``OEBasicHash``
6330generators. The value of ``PR`` bumps when the checksum changes and the
6331different generator mechanisms change signatures under different
6332circumstances.
6333
6334As implemented, the build system includes values from the PR Service
6335into the ``PR`` field as an addition using the form "``.x``" so ``r0``
6336becomes ``r0.1``, ``r0.2`` and so forth. This scheme allows existing
6337``PR`` values to be used for whatever reasons, which include manual
6338``PR`` bumps, should it be necessary.
6339
6340By default, the PR Service is not enabled or running. Thus, the packages
6341generated are just "self consistent". The build system adds and removes
6342packages and there are no guarantees about upgrade paths but images will
6343be consistent and correct with the latest changes.
6344
6345The simplest form for a PR Service is for it to exist for a single host
6346development system that builds the package feed (building system). For
6347this scenario, you can enable a local PR Service by setting
6348:term:`PRSERV_HOST` in your
Andrew Geisslerc926e172021-05-07 16:11:35 -05006349``local.conf`` file in the :term:`Build Directory`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006350
6351 PRSERV_HOST = "localhost:0"
6352
6353Once the service is started, packages will automatically
6354get increasing ``PR`` values and BitBake takes care of starting and
6355stopping the server.
6356
6357If you have a more complex setup where multiple host development systems
6358work against a common, shared package feed, you have a single PR Service
6359running and it is connected to each building system. For this scenario,
Andrew Geisslerc926e172021-05-07 16:11:35 -05006360you need to start the PR Service using the ``bitbake-prserv`` command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006361
6362 bitbake-prserv --host ip --port port --start
6363
6364In addition to
6365hand-starting the service, you need to update the ``local.conf`` file of
6366each building system as described earlier so each system points to the
6367server and port.
6368
6369It is also recommended you use build history, which adds some sanity
6370checks to binary package versions, in conjunction with the server that
6371is running the PR Service. To enable build history, add the following to
Andrew Geisslerc926e172021-05-07 16:11:35 -05006372each building system's ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006373
6374 # It is recommended to activate "buildhistory" for testing the PR service
6375 INHERIT += "buildhistory"
6376 BUILDHISTORY_COMMIT = "1"
6377
6378For information on build
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006379history, see the
6380":ref:`dev-manual/common-tasks:maintaining build output quality`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006381
6382.. note::
6383
6384 The OpenEmbedded build system does not maintain ``PR`` information as
6385 part of the shared state (sstate) packages. If you maintain an sstate
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006386 feed, it's expected that either all your building systems that
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006387 contribute to the sstate feed use a shared PR Service, or you do not
6388 run a PR Service on any of your building systems. Having some systems
6389 use a PR Service while others do not leads to obvious problems.
6390
6391 For more information on shared state, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06006392 ":ref:`overview-manual/concepts:shared state cache`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006393 section in the Yocto Project Overview and Concepts Manual.
6394
6395Manually Bumping PR
6396~~~~~~~~~~~~~~~~~~~
6397
6398The alternative to setting up a PR Service is to manually "bump" the
6399:term:`PR` variable.
6400
6401If a committed change results in changing the package output, then the
6402value of the PR variable needs to be increased (or "bumped") as part of
6403that commit. For new recipes you should add the ``PR`` variable and set
6404its initial value equal to "r0", which is the default. Even though the
6405default value is "r0", the practice of adding it to a new recipe makes
6406it harder to forget to bump the variable when you make changes to the
6407recipe in future.
6408
6409If you are sharing a common ``.inc`` file with multiple recipes, you can
6410also use the ``INC_PR`` variable to ensure that the recipes sharing the
6411``.inc`` file are rebuilt when the ``.inc`` file itself is changed. The
6412``.inc`` file must set ``INC_PR`` (initially to "r0"), and all recipes
6413referring to it should set ``PR`` to "${INC_PR}.0" initially,
6414incrementing the last number when the recipe is changed. If the ``.inc``
6415file is changed then its ``INC_PR`` should be incremented.
6416
6417When upgrading the version of a binary package, assuming the ``PV``
6418changes, the ``PR`` variable should be reset to "r0" (or "${INC_PR}.0"
6419if you are using ``INC_PR``).
6420
6421Usually, version increases occur only to binary packages. However, if
6422for some reason ``PV`` changes but does not increase, you can increase
6423the ``PE`` variable (Package Epoch). The ``PE`` variable defaults to
6424"0".
6425
6426Binary package version numbering strives to follow the `Debian Version
6427Field Policy
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006428Guidelines <https://www.debian.org/doc/debian-policy/ch-controlfields.html>`__.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006429These guidelines define how versions are compared and what "increasing"
6430a version means.
6431
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006432Automatically Incrementing a Package Version Number
6433~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6434
6435When fetching a repository, BitBake uses the
6436:term:`SRCREV` variable to determine
6437the specific source code revision from which to build. You set the
6438``SRCREV`` variable to
6439:term:`AUTOREV` to cause the
6440OpenEmbedded build system to automatically use the latest revision of
Andrew Geisslerc926e172021-05-07 16:11:35 -05006441the software::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006442
6443 SRCREV = "${AUTOREV}"
6444
6445Furthermore, you need to reference ``SRCPV`` in ``PV`` in order to
6446automatically update the version whenever the revision of the source
Andrew Geisslerc926e172021-05-07 16:11:35 -05006447code changes. Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006448
6449 PV = "1.0+git${SRCPV}"
6450
6451The OpenEmbedded build system substitutes ``SRCPV`` with the following:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006452
6453.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006454
6455 AUTOINC+source_code_revision
6456
6457The build system replaces the ``AUTOINC``
6458with a number. The number used depends on the state of the PR Service:
6459
6460- If PR Service is enabled, the build system increments the number,
6461 which is similar to the behavior of
6462 :term:`PR`. This behavior results in
6463 linearly increasing package versions, which is desirable. Here is an
6464 example:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006465
6466 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006467
6468 hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
6469 hello-world-git_0.0+git1+dd2f5c3565-r0.0_armv7a-neon.ipk
6470
6471- If PR Service is not enabled, the build system replaces the
6472 ``AUTOINC`` placeholder with zero (i.e. "0"). This results in
6473 changing the package version since the source revision is included.
6474 However, package versions are not increased linearly. Here is an
6475 example:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006476
6477 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006478
6479 hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
6480 hello-world-git_0.0+git0+dd2f5c3565-r0.0_armv7a-neon.ipk
6481
6482In summary, the OpenEmbedded build system does not track the history of
6483binary package versions for this purpose. ``AUTOINC``, in this case, is
6484comparable to ``PR``. If PR server is not enabled, ``AUTOINC`` in the
6485package version is simply replaced by "0". If PR server is enabled, the
6486build system keeps track of the package versions and bumps the number
6487when the package revision changes.
6488
6489Handling Optional Module Packaging
6490----------------------------------
6491
6492Many pieces of software split functionality into optional modules (or
6493plugins) and the plugins that are built might depend on configuration
6494options. To avoid having to duplicate the logic that determines what
6495modules are available in your recipe or to avoid having to package each
6496module by hand, the OpenEmbedded build system provides functionality to
6497handle module packaging dynamically.
6498
6499To handle optional module packaging, you need to do two things:
6500
6501- Ensure the module packaging is actually done.
6502
6503- Ensure that any dependencies on optional modules from other recipes
6504 are satisfied by your recipe.
6505
6506Making Sure the Packaging is Done
6507~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6508
6509To ensure the module packaging actually gets done, you use the
6510``do_split_packages`` function within the ``populate_packages`` Python
6511function in your recipe. The ``do_split_packages`` function searches for
6512a pattern of files or directories under a specified path and creates a
6513package for each one it finds by appending to the
6514:term:`PACKAGES` variable and
6515setting the appropriate values for ``FILES_packagename``,
6516``RDEPENDS_packagename``, ``DESCRIPTION_packagename``, and so forth.
Andrew Geisslerc926e172021-05-07 16:11:35 -05006517Here is an example from the ``lighttpd`` recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006518
6519 python populate_packages_prepend () {
6520 lighttpd_libdir = d.expand('${libdir}')
6521 do_split_packages(d, lighttpd_libdir, '^mod_(.*).so$',
6522 'lighttpd-module-%s', 'Lighttpd module for %s',
6523 extra_depends='')
6524 }
6525
6526The previous example specifies a number of things in the call to
6527``do_split_packages``.
6528
6529- A directory within the files installed by your recipe through
6530 ``do_install`` in which to search.
6531
6532- A regular expression used to match module files in that directory. In
6533 the example, note the parentheses () that mark the part of the
6534 expression from which the module name should be derived.
6535
6536- A pattern to use for the package names.
6537
6538- A description for each package.
6539
6540- An empty string for ``extra_depends``, which disables the default
6541 dependency on the main ``lighttpd`` package. Thus, if a file in
6542 ``${libdir}`` called ``mod_alias.so`` is found, a package called
6543 ``lighttpd-module-alias`` is created for it and the
6544 :term:`DESCRIPTION` is set to
6545 "Lighttpd module for alias".
6546
6547Often, packaging modules is as simple as the previous example. However,
6548more advanced options exist that you can use within
6549``do_split_packages`` to modify its behavior. And, if you need to, you
6550can add more logic by specifying a hook function that is called for each
6551package. It is also perfectly acceptable to call ``do_split_packages``
6552multiple times if you have more than one set of modules to package.
6553
6554For more examples that show how to use ``do_split_packages``, see the
6555``connman.inc`` file in the ``meta/recipes-connectivity/connman/``
Andrew Geissler09209ee2020-12-13 08:44:15 -06006556directory of the ``poky`` :ref:`source repository <overview-manual/development-environment:yocto project source repositories>`. You can
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006557also find examples in ``meta/classes/kernel.bbclass``.
6558
6559Following is a reference that shows ``do_split_packages`` mandatory and
Andrew Geisslerc926e172021-05-07 16:11:35 -05006560optional arguments::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006561
6562 Mandatory arguments
6563
6564 root
6565 The path in which to search
6566 file_regex
6567 Regular expression to match searched files.
6568 Use parentheses () to mark the part of this
6569 expression that should be used to derive the
6570 module name (to be substituted where %s is
6571 used in other function arguments as noted below)
6572 output_pattern
6573 Pattern to use for the package names. Must
6574 include %s.
6575 description
6576 Description to set for each package. Must
6577 include %s.
6578
6579 Optional arguments
6580
6581 postinst
6582 Postinstall script to use for all packages
6583 (as a string)
6584 recursive
6585 True to perform a recursive search - default
6586 False
6587 hook
6588 A hook function to be called for every match.
6589 The function will be called with the following
6590 arguments (in the order listed):
6591
6592 f
6593 Full path to the file/directory match
6594 pkg
6595 The package name
6596 file_regex
6597 As above
6598 output_pattern
6599 As above
6600 modulename
6601 The module name derived using file_regex
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006602 extra_depends
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006603 Extra runtime dependencies (RDEPENDS) to be
6604 set for all packages. The default value of None
6605 causes a dependency on the main package
6606 (${PN}) - if you do not want this, pass empty
6607 string '' for this parameter.
6608 aux_files_pattern
6609 Extra item(s) to be added to FILES for each
6610 package. Can be a single string item or a list
6611 of strings for multiple items. Must include %s.
6612 postrm
6613 postrm script to use for all packages (as a
6614 string)
6615 allow_dirs
6616 True to allow directories to be matched -
6617 default False
6618 prepend
6619 If True, prepend created packages to PACKAGES
6620 instead of the default False which appends them
6621 match_path
6622 match file_regex on the whole relative path to
6623 the root rather than just the file name
6624 aux_files_pattern_verbatim
6625 Extra item(s) to be added to FILES for each
6626 package, using the actual derived module name
6627 rather than converting it to something legal
6628 for a package name. Can be a single string item
6629 or a list of strings for multiple items. Must
6630 include %s.
6631 allow_links
6632 True to allow symlinks to be matched - default
6633 False
6634 summary
6635 Summary to set for each package. Must include %s;
6636 defaults to description if not set.
6637
6638
6639
6640Satisfying Dependencies
6641~~~~~~~~~~~~~~~~~~~~~~~
6642
6643The second part for handling optional module packaging is to ensure that
6644any dependencies on optional modules from other recipes are satisfied by
6645your recipe. You can be sure these dependencies are satisfied by using
6646the :term:`PACKAGES_DYNAMIC`
6647variable. Here is an example that continues with the ``lighttpd`` recipe
Andrew Geisslerc926e172021-05-07 16:11:35 -05006648shown earlier::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006649
6650 PACKAGES_DYNAMIC = "lighttpd-module-.*"
6651
6652The name
6653specified in the regular expression can of course be anything. In this
6654example, it is ``lighttpd-module-`` and is specified as the prefix to
6655ensure that any :term:`RDEPENDS` and
6656:term:`RRECOMMENDS` on a package
6657name starting with the prefix are satisfied during build time. If you
6658are using ``do_split_packages`` as described in the previous section,
6659the value you put in ``PACKAGES_DYNAMIC`` should correspond to the name
6660pattern specified in the call to ``do_split_packages``.
6661
6662Using Runtime Package Management
6663--------------------------------
6664
6665During a build, BitBake always transforms a recipe into one or more
6666packages. For example, BitBake takes the ``bash`` recipe and produces a
6667number of packages (e.g. ``bash``, ``bash-bashbug``,
6668``bash-completion``, ``bash-completion-dbg``, ``bash-completion-dev``,
6669``bash-completion-extra``, ``bash-dbg``, and so forth). Not all
6670generated packages are included in an image.
6671
6672In several situations, you might need to update, add, remove, or query
6673the packages on a target device at runtime (i.e. without having to
6674generate a new image). Examples of such situations include:
6675
6676- You want to provide in-the-field updates to deployed devices (e.g.
6677 security updates).
6678
6679- You want to have a fast turn-around development cycle for one or more
6680 applications that run on your device.
6681
6682- You want to temporarily install the "debug" packages of various
6683 applications on your device so that debugging can be greatly improved
6684 by allowing access to symbols and source debugging.
6685
6686- You want to deploy a more minimal package selection of your device
6687 but allow in-the-field updates to add a larger selection for
6688 customization.
6689
6690In all these situations, you have something similar to a more
6691traditional Linux distribution in that in-field devices are able to
6692receive pre-compiled packages from a server for installation or update.
6693Being able to install these packages on a running, in-field device is
6694what is termed "runtime package management".
6695
6696In order to use runtime package management, you need a host or server
6697machine that serves up the pre-compiled packages plus the required
6698metadata. You also need package manipulation tools on the target. The
6699build machine is a likely candidate to act as the server. However, that
6700machine does not necessarily have to be the package server. The build
6701machine could push its artifacts to another machine that acts as the
6702server (e.g. Internet-facing). In fact, doing so is advantageous for a
6703production environment as getting the packages away from the development
6704system's build directory prevents accidental overwrites.
6705
6706A simple build that targets just one device produces more than one
6707package database. In other words, the packages produced by a build are
6708separated out into a couple of different package groupings based on
6709criteria such as the target's CPU architecture, the target board, or the
6710C library used on the target. For example, a build targeting the
6711``qemux86`` device produces the following three package databases:
6712``noarch``, ``i586``, and ``qemux86``. If you wanted your ``qemux86``
6713device to be aware of all the packages that were available to it, you
6714would need to point it to each of these databases individually. In a
6715similar way, a traditional Linux distribution usually is configured to
6716be aware of a number of software repositories from which it retrieves
6717packages.
6718
6719Using runtime package management is completely optional and not required
6720for a successful build or deployment in any way. But if you want to make
6721use of runtime package management, you need to do a couple things above
6722and beyond the basics. The remainder of this section describes what you
6723need to do.
6724
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006725Build Considerations
6726~~~~~~~~~~~~~~~~~~~~
6727
6728This section describes build considerations of which you need to be
6729aware in order to provide support for runtime package management.
6730
6731When BitBake generates packages, it needs to know what format or formats
6732to use. In your configuration, you use the
6733:term:`PACKAGE_CLASSES`
6734variable to specify the format:
6735
67361. Open the ``local.conf`` file inside your
6737 :term:`Build Directory` (e.g.
Andrew Geissler95ac1b82021-03-31 14:34:31 -05006738 ``poky/build/conf/local.conf``).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006739
Andrew Geisslerc926e172021-05-07 16:11:35 -050067402. Select the desired package format as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006741
6742 PACKAGE_CLASSES ?= "package_packageformat"
6743
6744 where packageformat can be "ipk", "rpm",
6745 "deb", or "tar" which are the supported package formats.
6746
6747 .. note::
6748
6749 Because the Yocto Project supports four different package formats,
6750 you can set the variable with more than one argument. However, the
6751 OpenEmbedded build system only uses the first argument when
6752 creating an image or Software Development Kit (SDK).
6753
6754If you would like your image to start off with a basic package database
6755containing the packages in your current build as well as to have the
6756relevant tools available on the target for runtime package management,
6757you can include "package-management" in the
6758:term:`IMAGE_FEATURES`
6759variable. Including "package-management" in this configuration variable
6760ensures that when the image is assembled for your target, the image
6761includes the currently-known package databases as well as the
6762target-specific tools required for runtime package management to be
6763performed on the target. However, this is not strictly necessary. You
6764could start your image off without any databases but only include the
6765required on-target package tool(s). As an example, you could include
6766"opkg" in your
6767:term:`IMAGE_INSTALL` variable
6768if you are using the IPK package format. You can then initialize your
6769target's package database(s) later once your image is up and running.
6770
6771Whenever you perform any sort of build step that can potentially
6772generate a package or modify existing package, it is always a good idea
6773to re-generate the package index after the build by using the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05006774command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006775
6776 $ bitbake package-index
6777
6778It might be tempting to build the
6779package and the package index at the same time with a command such as
Andrew Geisslerc926e172021-05-07 16:11:35 -05006780the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006781
6782 $ bitbake some-package package-index
6783
6784Do not do this as
6785BitBake does not schedule the package index for after the completion of
6786the package you are building. Consequently, you cannot be sure of the
6787package index including information for the package you just built.
6788Thus, be sure to run the package update step separately after building
6789any packages.
6790
6791You can use the
6792:term:`PACKAGE_FEED_ARCHS`,
6793:term:`PACKAGE_FEED_BASE_PATHS`,
6794and
6795:term:`PACKAGE_FEED_URIS`
6796variables to pre-configure target images to use a package feed. If you
6797do not define these variables, then manual steps as described in the
6798subsequent sections are necessary to configure the target. You should
6799set these variables before building the image in order to produce a
6800correctly configured image.
6801
6802When your build is complete, your packages reside in the
6803``${TMPDIR}/deploy/packageformat`` directory. For example, if
6804``${``\ :term:`TMPDIR`\ ``}`` is
6805``tmp`` and your selected package type is RPM, then your RPM packages
6806are available in ``tmp/deploy/rpm``.
6807
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006808Host or Server Machine Setup
6809~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6810
6811Although other protocols are possible, a server using HTTP typically
6812serves packages. If you want to use HTTP, then set up and configure a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006813web server such as Apache 2, lighttpd, or Python web server on the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006814machine serving the packages.
6815
6816To keep things simple, this section describes how to set up a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006817Python web server to share package feeds from the developer's
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006818machine. Although this server might not be the best for a production
6819environment, the setup is simple and straight forward. Should you want
6820to use a different server more suited for production (e.g. Apache 2,
6821Lighttpd, or Nginx), take the appropriate steps to do so.
6822
6823From within the build directory where you have built an image based on
6824your packaging choice (i.e. the
6825:term:`PACKAGE_CLASSES`
6826setting), simply start the server. The following example assumes a build
Andrew Geissler95ac1b82021-03-31 14:34:31 -05006827directory of ``poky/build/tmp/deploy/rpm`` and a ``PACKAGE_CLASSES``
Andrew Geisslerc926e172021-05-07 16:11:35 -05006828setting of "package_rpm"::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006829
Andrew Geissler95ac1b82021-03-31 14:34:31 -05006830 $ cd poky/build/tmp/deploy/rpm
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006831 $ python3 -m http.server
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006832
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006833Target Setup
6834~~~~~~~~~~~~
6835
6836Setting up the target differs depending on the package management
6837system. This section provides information for RPM, IPK, and DEB.
6838
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006839Using RPM
6840^^^^^^^^^
6841
6842The `Dandified Packaging
6843Tool <https://en.wikipedia.org/wiki/DNF_(software)>`__ (DNF) performs
6844runtime package management of RPM packages. In order to use DNF for
6845runtime package management, you must perform an initial setup on the
6846target machine for cases where the ``PACKAGE_FEED_*`` variables were not
6847set as part of the image that is running on the target. This means if
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006848you built your image and did not use these variables as part of the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006849build and your image is now running on the target, you need to perform
6850the steps in this section if you want to use runtime package management.
6851
6852.. note::
6853
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006854 For information on the ``PACKAGE_FEED_*`` variables, see
6855 :term:`PACKAGE_FEED_ARCHS`, :term:`PACKAGE_FEED_BASE_PATHS`, and
6856 :term:`PACKAGE_FEED_URIS` in the Yocto Project Reference Manual variables
6857 glossary.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006858
6859On the target, you must inform DNF that package databases are available.
6860You do this by creating a file named
6861``/etc/yum.repos.d/oe-packages.repo`` and defining the ``oe-packages``.
6862
6863As an example, assume the target is able to use the following package
6864databases: ``all``, ``i586``, and ``qemux86`` from a server named
6865``my.server``. The specifics for setting up the web server are up to
6866you. The critical requirement is that the URIs in the target repository
6867configuration point to the correct remote location for the feeds.
6868
6869.. note::
6870
6871 For development purposes, you can point the web server to the build
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006872 system's ``deploy`` directory. However, for production use, it is better to
6873 copy the package directories to a location outside of the build area and use
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006874 that location. Doing so avoids situations where the build system
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006875 overwrites or changes the ``deploy`` directory.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006876
6877When telling DNF where to look for the package databases, you must
6878declare individual locations per architecture or a single location used
6879for all architectures. You cannot do both:
6880
6881- *Create an Explicit List of Architectures:* Define individual base
6882 URLs to identify where each package database is located:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006883
6884 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006885
6886 [oe-packages]
6887 baseurl=http://my.server/rpm/i586 http://my.server/rpm/qemux86 http://my.server/rpm/all
6888
6889 This example
6890 informs DNF about individual package databases for all three
6891 architectures.
6892
6893- *Create a Single (Full) Package Index:* Define a single base URL that
Andrew Geisslerc926e172021-05-07 16:11:35 -05006894 identifies where a full package database is located::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006895
6896 [oe-packages]
6897 baseurl=http://my.server/rpm
6898
6899 This example informs DNF about a single
6900 package database that contains all the package index information for
6901 all supported architectures.
6902
6903Once you have informed DNF where to find the package databases, you need
6904to fetch them:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006905
6906.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006907
6908 # dnf makecache
6909
6910DNF is now able to find, install, and
6911upgrade packages from the specified repository or repositories.
6912
6913.. note::
6914
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006915 See the `DNF documentation <https://dnf.readthedocs.io/en/latest/>`__ for
6916 additional information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006917
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006918Using IPK
6919^^^^^^^^^
6920
6921The ``opkg`` application performs runtime package management of IPK
6922packages. You must perform an initial setup for ``opkg`` on the target
6923machine if the
6924:term:`PACKAGE_FEED_ARCHS`,
6925:term:`PACKAGE_FEED_BASE_PATHS`,
6926and
6927:term:`PACKAGE_FEED_URIS`
6928variables have not been set or the target image was built before the
6929variables were set.
6930
6931The ``opkg`` application uses configuration files to find available
6932package databases. Thus, you need to create a configuration file inside
6933the ``/etc/opkg/`` direction, which informs ``opkg`` of any repository
6934you want to use.
6935
6936As an example, suppose you are serving packages from a ``ipk/``
6937directory containing the ``i586``, ``all``, and ``qemux86`` databases
6938through an HTTP server named ``my.server``. On the target, create a
6939configuration file (e.g. ``my_repo.conf``) inside the ``/etc/opkg/``
6940directory containing the following:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006941
6942.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006943
6944 src/gz all http://my.server/ipk/all
6945 src/gz i586 http://my.server/ipk/i586
6946 src/gz qemux86 http://my.server/ipk/qemux86
6947
6948Next, instruct ``opkg`` to fetch the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006949repository information:
6950
6951.. code-block:: none
6952
6953 # opkg update
6954
6955The ``opkg`` application is now able to find, install, and upgrade packages
6956from the specified repository.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006957
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006958Using DEB
6959^^^^^^^^^
6960
6961The ``apt`` application performs runtime package management of DEB
6962packages. This application uses a source list file to find available
6963package databases. You must perform an initial setup for ``apt`` on the
6964target machine if the
6965:term:`PACKAGE_FEED_ARCHS`,
6966:term:`PACKAGE_FEED_BASE_PATHS`,
6967and
6968:term:`PACKAGE_FEED_URIS`
6969variables have not been set or the target image was built before the
6970variables were set.
6971
6972To inform ``apt`` of the repository you want to use, you might create a
6973list file (e.g. ``my_repo.list``) inside the
6974``/etc/apt/sources.list.d/`` directory. As an example, suppose you are
6975serving packages from a ``deb/`` directory containing the ``i586``,
6976``all``, and ``qemux86`` databases through an HTTP server named
6977``my.server``. The list file should contain:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006978
6979.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006980
6981 deb http://my.server/deb/all ./
6982 deb http://my.server/deb/i586 ./
6983 deb http://my.server/deb/qemux86 ./
6984
6985Next, instruct the ``apt`` application
6986to fetch the repository information:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006987
6988.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006989
6990 # apt-get update
6991
6992After this step,
6993``apt`` is able to find, install, and upgrade packages from the
6994specified repository.
6995
6996Generating and Using Signed Packages
6997------------------------------------
6998
6999In order to add security to RPM packages used during a build, you can
7000take steps to securely sign them. Once a signature is verified, the
7001OpenEmbedded build system can use the package in the build. If security
7002fails for a signed package, the build system aborts the build.
7003
7004This section describes how to sign RPM packages during a build and how
7005to use signed package feeds (repositories) when doing a build.
7006
7007Signing RPM Packages
7008~~~~~~~~~~~~~~~~~~~~
7009
7010To enable signing RPM packages, you must set up the following
7011configurations in either your ``local.config`` or ``distro.config``
Andrew Geisslerc926e172021-05-07 16:11:35 -05007012file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007013
7014 # Inherit sign_rpm.bbclass to enable signing functionality
7015 INHERIT += " sign_rpm"
7016 # Define the GPG key that will be used for signing.
7017 RPM_GPG_NAME = "key_name"
7018 # Provide passphrase for the key
7019 RPM_GPG_PASSPHRASE = "passphrase"
7020
7021.. note::
7022
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007023 Be sure to supply appropriate values for both `key_name` and
7024 `passphrase`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007025
7026Aside from the ``RPM_GPG_NAME`` and ``RPM_GPG_PASSPHRASE`` variables in
7027the previous example, two optional variables related to signing exist:
7028
7029- *GPG_BIN:* Specifies a ``gpg`` binary/wrapper that is executed
7030 when the package is signed.
7031
7032- *GPG_PATH:* Specifies the ``gpg`` home directory used when the
7033 package is signed.
7034
7035Processing Package Feeds
7036~~~~~~~~~~~~~~~~~~~~~~~~
7037
7038In addition to being able to sign RPM packages, you can also enable
7039signed package feeds for IPK and RPM packages.
7040
7041The steps you need to take to enable signed package feed use are similar
7042to the steps used to sign RPM packages. You must define the following in
Andrew Geisslerc926e172021-05-07 16:11:35 -05007043your ``local.config`` or ``distro.config`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007044
7045 INHERIT += "sign_package_feed"
7046 PACKAGE_FEED_GPG_NAME = "key_name"
7047 PACKAGE_FEED_GPG_PASSPHRASE_FILE = "path_to_file_containing_passphrase"
7048
7049For signed package feeds, the passphrase must exist in a separate file,
7050which is pointed to by the ``PACKAGE_FEED_GPG_PASSPHRASE_FILE``
7051variable. Regarding security, keeping a plain text passphrase out of the
7052configuration is more secure.
7053
7054Aside from the ``PACKAGE_FEED_GPG_NAME`` and
7055``PACKAGE_FEED_GPG_PASSPHRASE_FILE`` variables, three optional variables
7056related to signed package feeds exist:
7057
7058- *GPG_BIN* Specifies a ``gpg`` binary/wrapper that is executed
7059 when the package is signed.
7060
7061- *GPG_PATH:* Specifies the ``gpg`` home directory used when the
7062 package is signed.
7063
7064- *PACKAGE_FEED_GPG_SIGNATURE_TYPE:* Specifies the type of ``gpg``
7065 signature. This variable applies only to RPM and IPK package feeds.
7066 Allowable values for the ``PACKAGE_FEED_GPG_SIGNATURE_TYPE`` are
7067 "ASC", which is the default and specifies ascii armored, and "BIN",
7068 which specifies binary.
7069
7070Testing Packages With ptest
7071---------------------------
7072
7073A Package Test (ptest) runs tests against packages built by the
7074OpenEmbedded build system on the target machine. A ptest contains at
7075least two items: the actual test, and a shell script (``run-ptest``)
7076that starts the test. The shell script that starts the test must not
7077contain the actual test - the script only starts the test. On the other
7078hand, the test can be anything from a simple shell script that runs a
7079binary and checks the output to an elaborate system of test binaries and
7080data files.
7081
Andrew Geisslerc926e172021-05-07 16:11:35 -05007082The test generates output in the format used by Automake::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007083
7084 result: testname
7085
7086where the result can be ``PASS``, ``FAIL``, or ``SKIP``, and
7087the testname can be any identifying string.
7088
7089For a list of Yocto Project recipes that are already enabled with ptest,
Andrew Geissler09209ee2020-12-13 08:44:15 -06007090see the :yocto_wiki:`Ptest </Ptest>` wiki page.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007091
7092.. note::
7093
7094 A recipe is "ptest-enabled" if it inherits the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007095 :ref:`ptest <ref-classes-ptest>` class.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007096
7097Adding ptest to Your Build
7098~~~~~~~~~~~~~~~~~~~~~~~~~~
7099
7100To add package testing to your build, add the
7101:term:`DISTRO_FEATURES` and
7102:term:`EXTRA_IMAGE_FEATURES`
7103variables to your ``local.conf`` file, which is found in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05007104:term:`Build Directory`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007105
7106 DISTRO_FEATURES_append = " ptest"
7107 EXTRA_IMAGE_FEATURES += "ptest-pkgs"
7108
7109Once your build is complete, the ptest files are installed into the
7110``/usr/lib/package/ptest`` directory within the image, where ``package``
7111is the name of the package.
7112
7113Running ptest
7114~~~~~~~~~~~~~
7115
7116The ``ptest-runner`` package installs a shell script that loops through
7117all installed ptest test suites and runs them in sequence. Consequently,
7118you might want to add this package to your image.
7119
7120Getting Your Package Ready
7121~~~~~~~~~~~~~~~~~~~~~~~~~~
7122
7123In order to enable a recipe to run installed ptests on target hardware,
7124you need to prepare the recipes that build the packages you want to
7125test. Here is what you have to do for each recipe:
7126
7127- *Be sure the recipe inherits
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007128 the* :ref:`ptest <ref-classes-ptest>` *class:*
Andrew Geisslerc926e172021-05-07 16:11:35 -05007129 Include the following line in each recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007130
7131 inherit ptest
7132
7133- *Create run-ptest:* This script starts your test. Locate the
7134 script where you will refer to it using
7135 :term:`SRC_URI`. Here is an
Andrew Geisslerc926e172021-05-07 16:11:35 -05007136 example that starts a test for ``dbus``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007137
7138 #!/bin/sh
7139 cd test
7140 make -k runtest-TESTS
7141
7142- *Ensure dependencies are met:* If the test adds build or runtime
7143 dependencies that normally do not exist for the package (such as
7144 requiring "make" to run the test suite), use the
7145 :term:`DEPENDS` and
7146 :term:`RDEPENDS` variables in
7147 your recipe in order for the package to meet the dependencies. Here
Andrew Geisslerc926e172021-05-07 16:11:35 -05007148 is an example where the package has a runtime dependency on "make"::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007149
7150 RDEPENDS_${PN}-ptest += "make"
7151
7152- *Add a function to build the test suite:* Not many packages support
7153 cross-compilation of their test suites. Consequently, you usually
7154 need to add a cross-compilation function to the package.
7155
7156 Many packages based on Automake compile and run the test suite by
7157 using a single command such as ``make check``. However, the host
7158 ``make check`` builds and runs on the same computer, while
7159 cross-compiling requires that the package is built on the host but
7160 executed for the target architecture (though often, as in the case
7161 for ptest, the execution occurs on the host). The built version of
7162 Automake that ships with the Yocto Project includes a patch that
7163 separates building and execution. Consequently, packages that use the
7164 unaltered, patched version of ``make check`` automatically
7165 cross-compiles.
7166
7167 Regardless, you still must add a ``do_compile_ptest`` function to
7168 build the test suite. Add a function similar to the following to your
Andrew Geisslerc926e172021-05-07 16:11:35 -05007169 recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007170
7171 do_compile_ptest() {
7172 oe_runmake buildtest-TESTS
7173 }
7174
7175- *Ensure special configurations are set:* If the package requires
7176 special configurations prior to compiling the test code, you must
7177 insert a ``do_configure_ptest`` function into the recipe.
7178
7179- *Install the test suite:* The ``ptest`` class automatically copies
7180 the file ``run-ptest`` to the target and then runs make
7181 ``install-ptest`` to run the tests. If this is not enough, you need
7182 to create a ``do_install_ptest`` function and make sure it gets
7183 called after the "make install-ptest" completes.
7184
7185Creating Node Package Manager (NPM) Packages
7186--------------------------------------------
7187
7188`NPM <https://en.wikipedia.org/wiki/Npm_(software)>`__ is a package
7189manager for the JavaScript programming language. The Yocto Project
Andrew Geissler09209ee2020-12-13 08:44:15 -06007190supports the NPM :ref:`fetcher <bitbake:bitbake-user-manual/bitbake-user-manual-fetching:fetchers>`. You can
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007191use this fetcher in combination with
Andrew Geissler09209ee2020-12-13 08:44:15 -06007192:doc:`devtool </ref-manual/devtool-reference>` to create
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007193recipes that produce NPM packages.
7194
7195Two workflows exist that allow you to create NPM packages using
7196``devtool``: the NPM registry modules method and the NPM project code
7197method.
7198
7199.. note::
7200
7201 While it is possible to create NPM recipes manually, using
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007202 ``devtool`` is far simpler.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007203
7204Additionally, some requirements and caveats exist.
7205
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007206Requirements and Caveats
7207~~~~~~~~~~~~~~~~~~~~~~~~
7208
7209You need to be aware of the following before using ``devtool`` to create
7210NPM packages:
7211
7212- Of the two methods that you can use ``devtool`` to create NPM
7213 packages, the registry approach is slightly simpler. However, you
7214 might consider the project approach because you do not have to
7215 publish your module in the NPM registry
7216 (`npm-registry <https://docs.npmjs.com/misc/registry>`_), which
7217 is NPM's public registry.
7218
7219- Be familiar with
Andrew Geissler09209ee2020-12-13 08:44:15 -06007220 :doc:`devtool </ref-manual/devtool-reference>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007221
7222- The NPM host tools need the native ``nodejs-npm`` package, which is
7223 part of the OpenEmbedded environment. You need to get the package by
7224 cloning the https://github.com/openembedded/meta-openembedded
7225 repository out of GitHub. Be sure to add the path to your local copy
7226 to your ``bblayers.conf`` file.
7227
7228- ``devtool`` cannot detect native libraries in module dependencies.
7229 Consequently, you must manually add packages to your recipe.
7230
7231- While deploying NPM packages, ``devtool`` cannot determine which
7232 dependent packages are missing on the target (e.g. the node runtime
7233 ``nodejs``). Consequently, you need to find out what files are
7234 missing and be sure they are on the target.
7235
7236- Although you might not need NPM to run your node package, it is
7237 useful to have NPM on your target. The NPM package name is
7238 ``nodejs-npm``.
7239
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007240Using the Registry Modules Method
7241~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7242
7243This section presents an example that uses the ``cute-files`` module,
7244which is a file browser web application.
7245
7246.. note::
7247
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007248 You must know the ``cute-files`` module version.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007249
7250The first thing you need to do is use ``devtool`` and the NPM fetcher to
Andrew Geisslerc926e172021-05-07 16:11:35 -05007251create the recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007252
7253 $ devtool add "npm://registry.npmjs.org;package=cute-files;version=1.0.2"
7254
7255The
7256``devtool add`` command runs ``recipetool create`` and uses the same
7257fetch URI to download each dependency and capture license details where
7258possible. The result is a generated recipe.
7259
7260The recipe file is fairly simple and contains every license that
7261``recipetool`` finds and includes the licenses in the recipe's
7262:term:`LIC_FILES_CHKSUM`
7263variables. You need to examine the variables and look for those with
7264"unknown" in the :term:`LICENSE`
7265field. You need to track down the license information for "unknown"
7266modules and manually add the information to the recipe.
7267
7268``recipetool`` creates a "shrinkwrap" file for your recipe. Shrinkwrap
7269files capture the version of all dependent modules. Many packages do not
7270provide shrinkwrap files. ``recipetool`` create a shrinkwrap file as it
7271runs.
7272
7273.. note::
7274
7275 A package is created for each sub-module. This policy is the only
7276 practical way to have the licenses for all of the dependencies
7277 represented in the license manifest of the image.
7278
Andrew Geisslerc926e172021-05-07 16:11:35 -05007279The ``devtool edit-recipe`` command lets you take a look at the recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007280
7281 $ devtool edit-recipe cute-files
7282 SUMMARY = "Turn any folder on your computer into a cute file browser, available on the local network."
7283 LICENSE = "MIT & ISC & Unknown"
7284 LIC_FILES_CHKSUM = "file://LICENSE;md5=71d98c0a1db42956787b1909c74a86ca \
7285 file://node_modules/toidentifier/LICENSE;md5=1a261071a044d02eb6f2bb47f51a3502 \
7286 file://node_modules/debug/LICENSE;md5=ddd815a475e7338b0be7a14d8ee35a99 \
7287 ...
7288 SRC_URI = " \
7289 npm://registry.npmjs.org/;package=cute-files;version=${PV} \
7290 npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \
7291 "
7292 S = "${WORKDIR}/npm"
7293 inherit npm LICENSE_${PN} = "MIT"
7294 LICENSE_${PN}-accepts = "MIT"
7295 LICENSE_${PN}-array-flatten = "MIT"
7296 ...
7297 LICENSE_${PN}-vary = "MIT"
7298
7299Three key points exist in the previous example:
7300
7301- :term:`SRC_URI` uses the NPM
7302 scheme so that the NPM fetcher is used.
7303
7304- ``recipetool`` collects all the license information. If a
7305 sub-module's license is unavailable, the sub-module's name appears in
7306 the comments.
7307
7308- The ``inherit npm`` statement causes the
7309 :ref:`npm <ref-classes-npm>` class to package
7310 up all the modules.
7311
Andrew Geisslerc926e172021-05-07 16:11:35 -05007312You can run the following command to build the ``cute-files`` package::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007313
7314 $ devtool build cute-files
7315
7316Remember that ``nodejs`` must be installed on
7317the target before your package.
7318
7319Assuming 192.168.7.2 for the target's IP address, use the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05007320command to deploy your package::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007321
7322 $ devtool deploy-target -s cute-files root@192.168.7.2
7323
7324Once the package is installed on the target, you can
7325test the application:
7326
7327.. note::
7328
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007329 Because of a known issue, you cannot simply run ``cute-files`` as you would
7330 if you had run ``npm install``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007331
7332::
7333
7334 $ cd /usr/lib/node_modules/cute-files
7335 $ node cute-files.js
7336
7337On a browser,
7338go to ``http://192.168.7.2:3000`` and you see the following:
7339
7340.. image:: figures/cute-files-npm-example.png
7341 :align: center
7342
7343You can find the recipe in ``workspace/recipes/cute-files``. You can use
7344the recipe in any layer you choose.
7345
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007346Using the NPM Projects Code Method
7347~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7348
7349Although it is useful to package modules already in the NPM registry,
7350adding ``node.js`` projects under development is a more common developer
7351use case.
7352
7353This section covers the NPM projects code method, which is very similar
7354to the "registry" approach described in the previous section. In the NPM
7355projects method, you provide ``devtool`` with an URL that points to the
7356source files.
7357
7358Replicating the same example, (i.e. ``cute-files``) use the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05007359command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007360
7361 $ devtool add https://github.com/martinaglv/cute-files.git
7362
7363The
7364recipe this command generates is very similar to the recipe created in
Andrew Geisslerc926e172021-05-07 16:11:35 -05007365the previous section. However, the ``SRC_URI`` looks like the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007366
7367 SRC_URI = " \
7368 git://github.com/martinaglv/cute-files.git;protocol=https \
7369 npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \
7370 "
7371
7372In this example,
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007373the main module is taken from the Git repository and dependencies are
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007374taken from the NPM registry. Other than those differences, the recipe is
7375basically the same between the two methods. You can build and deploy the
7376package exactly as described in the previous section that uses the
7377registry modules method.
7378
7379Adding custom metadata to packages
7380----------------------------------
7381
7382The variable
7383:term:`PACKAGE_ADD_METADATA`
7384can be used to add additional metadata to packages. This is reflected in
7385the package control/spec file. To take the ipk format for example, the
7386CONTROL file stored inside would contain the additional metadata as
7387additional lines.
7388
7389The variable can be used in multiple ways, including using suffixes to
7390set it for a specific package type and/or package. Note that the order
7391of precedence is the same as this list:
7392
7393- ``PACKAGE_ADD_METADATA_<PKGTYPE>_<PN>``
7394
7395- ``PACKAGE_ADD_METADATA_<PKGTYPE>``
7396
7397- ``PACKAGE_ADD_METADATA_<PN>``
7398
7399- ``PACKAGE_ADD_METADATA``
7400
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007401`<PKGTYPE>` is a parameter and expected to be a distinct name of specific
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007402package type:
7403
7404- IPK for .ipk packages
7405
7406- DEB for .deb packages
7407
7408- RPM for .rpm packages
7409
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007410`<PN>` is a parameter and expected to be a package name.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007411
7412The variable can contain multiple [one-line] metadata fields separated
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007413by the literal sequence '\\n'. The separator can be redefined using the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007414variable flag ``separator``.
7415
7416The following is an example that adds two custom fields for ipk
Andrew Geisslerc926e172021-05-07 16:11:35 -05007417packages::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007418
7419 PACKAGE_ADD_METADATA_IPK = "Vendor: CustomIpk\nGroup:Applications/Spreadsheets"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007420
7421Efficiently Fetching Source Files During a Build
7422================================================
7423
7424The OpenEmbedded build system works with source files located through
7425the :term:`SRC_URI` variable. When
7426you build something using BitBake, a big part of the operation is
7427locating and downloading all the source tarballs. For images,
7428downloading all the source for various packages can take a significant
7429amount of time.
7430
7431This section shows you how you can use mirrors to speed up fetching
7432source files and how you can pre-fetch files all of which leads to more
7433efficient use of resources and time.
7434
7435Setting up Effective Mirrors
7436----------------------------
7437
7438A good deal that goes into a Yocto Project build is simply downloading
7439all of the source tarballs. Maybe you have been working with another
7440build system (OpenEmbedded or Angstrom) for which you have built up a
7441sizable directory of source tarballs. Or, perhaps someone else has such
7442a directory for which you have read access. If so, you can save time by
7443adding statements to your configuration file so that the build process
7444checks local directories first for existing tarballs before checking the
7445Internet.
7446
Andrew Geisslerc926e172021-05-07 16:11:35 -05007447Here is an efficient way to set it up in your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007448
7449 SOURCE_MIRROR_URL ?= "file:///home/you/your-download-dir/"
7450 INHERIT += "own-mirrors"
7451 BB_GENERATE_MIRROR_TARBALLS = "1"
7452 # BB_NO_NETWORK = "1"
7453
7454In the previous example, the
7455:term:`BB_GENERATE_MIRROR_TARBALLS`
7456variable causes the OpenEmbedded build system to generate tarballs of
7457the Git repositories and store them in the
7458:term:`DL_DIR` directory. Due to
7459performance reasons, generating and storing these tarballs is not the
7460build system's default behavior.
7461
7462You can also use the
7463:term:`PREMIRRORS` variable. For
7464an example, see the variable's glossary entry in the Yocto Project
7465Reference Manual.
7466
7467Getting Source Files and Suppressing the Build
7468----------------------------------------------
7469
7470Another technique you can use to ready yourself for a successive string
7471of build operations, is to pre-fetch all the source files without
7472actually starting a build. This technique lets you work through any
7473download issues and ultimately gathers all the source files into your
7474download directory :ref:`structure-build-downloads`,
7475which is located with :term:`DL_DIR`.
7476
7477Use the following BitBake command form to fetch all the necessary
Andrew Geisslerc926e172021-05-07 16:11:35 -05007478sources without starting the build::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007479
7480 $ bitbake target --runall=fetch
7481
7482This
7483variation of the BitBake command guarantees that you have all the
7484sources for that BitBake target should you disconnect from the Internet
7485and want to do the build later offline.
7486
7487Selecting an Initialization Manager
7488===================================
7489
7490By default, the Yocto Project uses SysVinit as the initialization
7491manager. However, support also exists for systemd, which is a full
7492replacement for init with parallel starting of services, reduced shell
7493overhead and other features that are used by many distributions.
7494
7495Within the system, SysVinit treats system components as services. These
7496services are maintained as shell scripts stored in the ``/etc/init.d/``
7497directory. Services organize into different run levels. This
7498organization is maintained by putting links to the services in the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007499``/etc/rcN.d/`` directories, where `N/` is one of the following options:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007500"S", "0", "1", "2", "3", "4", "5", or "6".
7501
7502.. note::
7503
7504 Each runlevel has a dependency on the previous runlevel. This
7505 dependency allows the services to work properly.
7506
7507In comparison, systemd treats components as units. Using units is a
7508broader concept as compared to using a service. A unit includes several
7509different types of entities. Service is one of the types of entities.
7510The runlevel concept in SysVinit corresponds to the concept of a target
7511in systemd, where target is also a type of supported unit.
7512
7513In a SysVinit-based system, services load sequentially (i.e. one by one)
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007514during init and parallelization is not supported. With systemd, services
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007515start in parallel. Needless to say, the method can have an impact on
7516system startup performance.
7517
7518If you want to use SysVinit, you do not have to do anything. But, if you
7519want to use systemd, you must take some steps as described in the
7520following sections.
7521
7522Using systemd Exclusively
7523-------------------------
7524
Andrew Geisslerc926e172021-05-07 16:11:35 -05007525Set these variables in your distribution configuration file as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007526
7527 DISTRO_FEATURES_append = " systemd"
7528 VIRTUAL-RUNTIME_init_manager = "systemd"
7529
7530You can also prevent the SysVinit distribution feature from
Andrew Geisslerc926e172021-05-07 16:11:35 -05007531being automatically enabled as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007532
7533 DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
7534
7535Doing so removes any
7536redundant SysVinit scripts.
7537
7538To remove initscripts from your image altogether, set this variable
Andrew Geisslerc926e172021-05-07 16:11:35 -05007539also::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007540
7541 VIRTUAL-RUNTIME_initscripts = ""
7542
7543For information on the backfill variable, see
7544:term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`.
7545
7546Using systemd for the Main Image and Using SysVinit for the Rescue Image
7547------------------------------------------------------------------------
7548
Andrew Geisslerc926e172021-05-07 16:11:35 -05007549Set these variables in your distribution configuration file as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007550
7551 DISTRO_FEATURES_append = " systemd"
7552 VIRTUAL-RUNTIME_init_manager = "systemd"
7553
7554Doing so causes your main image to use the
7555``packagegroup-core-boot.bb`` recipe and systemd. The rescue/minimal
7556image cannot use this package group. However, it can install SysVinit
7557and the appropriate packages will have support for both systemd and
7558SysVinit.
7559
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007560Selecting a Device Manager
7561==========================
7562
7563The Yocto Project provides multiple ways to manage the device manager
7564(``/dev``):
7565
7566- Persistent and Pre-Populated\ ``/dev``: For this case, the ``/dev``
7567 directory is persistent and the required device nodes are created
7568 during the build.
7569
7570- Use ``devtmpfs`` with a Device Manager: For this case, the ``/dev``
7571 directory is provided by the kernel as an in-memory file system and
7572 is automatically populated by the kernel at runtime. Additional
7573 configuration of device nodes is done in user space by a device
7574 manager like ``udev`` or ``busybox-mdev``.
7575
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007576Using Persistent and Pre-Populated\ ``/dev``
7577--------------------------------------------
7578
7579To use the static method for device population, you need to set the
7580:term:`USE_DEVFS` variable to "0"
Andrew Geisslerc926e172021-05-07 16:11:35 -05007581as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007582
7583 USE_DEVFS = "0"
7584
7585The content of the resulting ``/dev`` directory is defined in a Device
7586Table file. The
7587:term:`IMAGE_DEVICE_TABLES`
7588variable defines the Device Table to use and should be set in the
7589machine or distro configuration file. Alternatively, you can set this
7590variable in your ``local.conf`` configuration file.
7591
7592If you do not define the ``IMAGE_DEVICE_TABLES`` variable, the default
Andrew Geisslerc926e172021-05-07 16:11:35 -05007593``device_table-minimal.txt`` is used::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007594
7595 IMAGE_DEVICE_TABLES = "device_table-mymachine.txt"
7596
7597The population is handled by the ``makedevs`` utility during image
7598creation:
7599
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007600Using ``devtmpfs`` and a Device Manager
7601---------------------------------------
7602
7603To use the dynamic method for device population, you need to use (or be
7604sure to set) the :term:`USE_DEVFS`
Andrew Geisslerc926e172021-05-07 16:11:35 -05007605variable to "1", which is the default::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007606
7607 USE_DEVFS = "1"
7608
7609With this
7610setting, the resulting ``/dev`` directory is populated by the kernel
7611using ``devtmpfs``. Make sure the corresponding kernel configuration
7612variable ``CONFIG_DEVTMPFS`` is set when building you build a Linux
7613kernel.
7614
7615All devices created by ``devtmpfs`` will be owned by ``root`` and have
7616permissions ``0600``.
7617
7618To have more control over the device nodes, you can use a device manager
7619like ``udev`` or ``busybox-mdev``. You choose the device manager by
7620defining the ``VIRTUAL-RUNTIME_dev_manager`` variable in your machine or
7621distro configuration file. Alternatively, you can set this variable in
Andrew Geisslerc926e172021-05-07 16:11:35 -05007622your ``local.conf`` configuration file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007623
7624 VIRTUAL-RUNTIME_dev_manager = "udev"
7625
7626 # Some alternative values
7627 # VIRTUAL-RUNTIME_dev_manager = "busybox-mdev"
7628 # VIRTUAL-RUNTIME_dev_manager = "systemd"
7629
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007630Using an External SCM
7631=====================
7632
7633If you're working on a recipe that pulls from an external Source Code
7634Manager (SCM), it is possible to have the OpenEmbedded build system
7635notice new recipe changes added to the SCM and then build the resulting
7636packages that depend on the new recipes by using the latest versions.
7637This only works for SCMs from which it is possible to get a sensible
7638revision number for changes. Currently, you can do this with Apache
7639Subversion (SVN), Git, and Bazaar (BZR) repositories.
7640
7641To enable this behavior, the :term:`PV` of
7642the recipe needs to reference
Andrew Geisslerc926e172021-05-07 16:11:35 -05007643:term:`SRCPV`. Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007644
7645 PV = "1.2.3+git${SRCPV}"
7646
7647Then, you can add the following to your
Andrew Geisslerc926e172021-05-07 16:11:35 -05007648``local.conf``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007649
7650 SRCREV_pn-PN = "${AUTOREV}"
7651
7652:term:`PN` is the name of the recipe for
7653which you want to enable automatic source revision updating.
7654
7655If you do not want to update your local configuration file, you can add
Andrew Geisslerc926e172021-05-07 16:11:35 -05007656the following directly to the recipe to finish enabling the feature::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007657
7658 SRCREV = "${AUTOREV}"
7659
7660The Yocto Project provides a distribution named ``poky-bleeding``, whose
Andrew Geisslerc926e172021-05-07 16:11:35 -05007661configuration file contains the line::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007662
7663 require conf/distro/include/poky-floating-revisions.inc
7664
7665This line pulls in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05007666listed include file that contains numerous lines of exactly that form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007667
7668 #SRCREV_pn-opkg-native ?= "${AUTOREV}"
7669 #SRCREV_pn-opkg-sdk ?= "${AUTOREV}"
7670 #SRCREV_pn-opkg ?= "${AUTOREV}"
7671 #SRCREV_pn-opkg-utils-native ?= "${AUTOREV}"
7672 #SRCREV_pn-opkg-utils ?= "${AUTOREV}"
7673 SRCREV_pn-gconf-dbus ?= "${AUTOREV}"
7674 SRCREV_pn-matchbox-common ?= "${AUTOREV}"
7675 SRCREV_pn-matchbox-config-gtk ?= "${AUTOREV}"
7676 SRCREV_pn-matchbox-desktop ?= "${AUTOREV}"
7677 SRCREV_pn-matchbox-keyboard ?= "${AUTOREV}"
7678 SRCREV_pn-matchbox-panel-2 ?= "${AUTOREV}"
7679 SRCREV_pn-matchbox-themes-extra ?= "${AUTOREV}"
7680 SRCREV_pn-matchbox-terminal ?= "${AUTOREV}"
7681 SRCREV_pn-matchbox-wm ?= "${AUTOREV}"
7682 SRCREV_pn-settings-daemon ?= "${AUTOREV}"
7683 SRCREV_pn-screenshot ?= "${AUTOREV}"
7684 . . .
7685
7686These lines allow you to
7687experiment with building a distribution that tracks the latest
7688development source for numerous packages.
7689
7690.. note::
7691
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007692 The ``poky-bleeding`` distribution is not tested on a regular basis. Keep
7693 this in mind if you use it.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007694
7695Creating a Read-Only Root Filesystem
7696====================================
7697
7698Suppose, for security reasons, you need to disable your target device's
7699root filesystem's write permissions (i.e. you need a read-only root
7700filesystem). Or, perhaps you are running the device's operating system
7701from a read-only storage device. For either case, you can customize your
7702image for that behavior.
7703
7704.. note::
7705
7706 Supporting a read-only root filesystem requires that the system and
7707 applications do not try to write to the root filesystem. You must
7708 configure all parts of the target system to write elsewhere, or to
7709 gracefully fail in the event of attempting to write to the root
7710 filesystem.
7711
7712Creating the Root Filesystem
7713----------------------------
7714
7715To create the read-only root filesystem, simply add the
7716"read-only-rootfs" feature to your image, normally in one of two ways.
7717The first way is to add the "read-only-rootfs" image feature in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05007718image's recipe file via the ``IMAGE_FEATURES`` variable::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007719
7720 IMAGE_FEATURES += "read-only-rootfs"
7721
7722As an alternative, you can add the same feature
7723from within your build directory's ``local.conf`` file with the
Andrew Geisslerc926e172021-05-07 16:11:35 -05007724associated ``EXTRA_IMAGE_FEATURES`` variable, as in::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007725
7726 EXTRA_IMAGE_FEATURES = "read-only-rootfs"
7727
7728For more information on how to use these variables, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06007729":ref:`dev-manual/common-tasks:Customizing Images Using Custom \`\`IMAGE_FEATURES\`\` and \`\`EXTRA_IMAGE_FEATURES\`\``"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007730section. For information on the variables, see
7731:term:`IMAGE_FEATURES` and
7732:term:`EXTRA_IMAGE_FEATURES`.
7733
7734Post-Installation Scripts and Read-Only Root Filesystem
7735-------------------------------------------------------
7736
7737It is very important that you make sure all post-Installation
7738(``pkg_postinst``) scripts for packages that are installed into the
7739image can be run at the time when the root filesystem is created during
7740the build on the host system. These scripts cannot attempt to run during
7741first-boot on the target device. With the "read-only-rootfs" feature
7742enabled, the build system checks during root filesystem creation to make
7743sure all post-installation scripts succeed. If any of these scripts
7744still need to be run after the root filesystem is created, the build
7745immediately fails. These build-time checks ensure that the build fails
7746rather than the target device fails later during its initial boot
7747operation.
7748
7749Most of the common post-installation scripts generated by the build
7750system for the out-of-the-box Yocto Project are engineered so that they
7751can run during root filesystem creation (e.g. post-installation scripts
7752for caching fonts). However, if you create and add custom scripts, you
7753need to be sure they can be run during this file system creation.
7754
7755Here are some common problems that prevent post-installation scripts
7756from running during root filesystem creation:
7757
7758- *Not using $D in front of absolute paths:* The build system defines
7759 ``$``\ :term:`D` when the root
7760 filesystem is created. Furthermore, ``$D`` is blank when the script
7761 is run on the target device. This implies two purposes for ``$D``:
7762 ensuring paths are valid in both the host and target environments,
7763 and checking to determine which environment is being used as a method
7764 for taking appropriate actions.
7765
7766- *Attempting to run processes that are specific to or dependent on the
7767 target architecture:* You can work around these attempts by using
7768 native tools, which run on the host system, to accomplish the same
7769 tasks, or by alternatively running the processes under QEMU, which
7770 has the ``qemu_run_binary`` function. For more information, see the
7771 :ref:`qemu <ref-classes-qemu>` class.
7772
7773Areas With Write Access
7774-----------------------
7775
7776With the "read-only-rootfs" feature enabled, any attempt by the target
7777to write to the root filesystem at runtime fails. Consequently, you must
7778make sure that you configure processes and applications that attempt
7779these types of writes do so to directories with write access (e.g.
7780``/tmp`` or ``/var/run``).
7781
7782Maintaining Build Output Quality
7783================================
7784
7785Many factors can influence the quality of a build. For example, if you
7786upgrade a recipe to use a new version of an upstream software package or
7787you experiment with some new configuration options, subtle changes can
7788occur that you might not detect until later. Consider the case where
7789your recipe is using a newer version of an upstream package. In this
7790case, a new version of a piece of software might introduce an optional
7791dependency on another library, which is auto-detected. If that library
7792has already been built when the software is building, the software will
7793link to the built library and that library will be pulled into your
7794image along with the new software even if you did not want the library.
7795
7796The :ref:`buildhistory <ref-classes-buildhistory>`
7797class exists to help you maintain the quality of your build output. You
7798can use the class to highlight unexpected and possibly unwanted changes
7799in the build output. When you enable build history, it records
7800information about the contents of each package and image and then
7801commits that information to a local Git repository where you can examine
7802the information.
7803
7804The remainder of this section describes the following:
7805
Andrew Geissler09209ee2020-12-13 08:44:15 -06007806- :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 -05007807
Andrew Geissler09209ee2020-12-13 08:44:15 -06007808- :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 -05007809
Andrew Geissler09209ee2020-12-13 08:44:15 -06007810- :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 -05007811
Andrew Geissler09209ee2020-12-13 08:44:15 -06007812- :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 -05007813
7814Enabling and Disabling Build History
7815------------------------------------
7816
7817Build history is disabled by default. To enable it, add the following
7818``INHERIT`` statement and set the
7819:term:`BUILDHISTORY_COMMIT`
7820variable to "1" at the end of your ``conf/local.conf`` file found in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05007821:term:`Build Directory`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007822
7823 INHERIT += "buildhistory"
7824 BUILDHISTORY_COMMIT = "1"
7825
7826Enabling build history as
7827previously described causes the OpenEmbedded build system to collect
7828build output information and commit it as a single commit to a local
Andrew Geissler09209ee2020-12-13 08:44:15 -06007829:ref:`overview-manual/development-environment:git` repository.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007830
7831.. note::
7832
7833 Enabling build history increases your build times slightly,
7834 particularly for images, and increases the amount of disk space used
7835 during the build.
7836
7837You can disable build history by removing the previous statements from
7838your ``conf/local.conf`` file.
7839
7840Understanding What the Build History Contains
7841---------------------------------------------
7842
7843Build history information is kept in
7844``${``\ :term:`TOPDIR`\ ``}/buildhistory``
7845in the Build Directory as defined by the
7846:term:`BUILDHISTORY_DIR`
7847variable. The following is an example abbreviated listing:
7848
7849.. image:: figures/buildhistory.png
7850 :align: center
7851
7852At the top level, a ``metadata-revs`` file exists that lists the
7853revisions of the repositories for the enabled layers when the build was
7854produced. The rest of the data splits into separate ``packages``,
7855``images`` and ``sdk`` directories, the contents of which are described
7856as follows.
7857
7858Build History Package Information
7859~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7860
7861The history for each package contains a text file that has name-value
7862pairs with information about the package. For example,
7863``buildhistory/packages/i586-poky-linux/busybox/busybox/latest``
7864contains the following:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007865
7866.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007867
7868 PV = 1.22.1
7869 PR = r32
7870 RPROVIDES =
7871 RDEPENDS = glibc (>= 2.20) update-alternatives-opkg
7872 RRECOMMENDS = busybox-syslog busybox-udhcpc update-rc.d
7873 PKGSIZE = 540168
7874 FILES = /usr/bin/* /usr/sbin/* /usr/lib/busybox/* /usr/lib/lib*.so.* \
7875 /etc /com /var /bin/* /sbin/* /lib/*.so.* /lib/udev/rules.d \
7876 /usr/lib/udev/rules.d /usr/share/busybox /usr/lib/busybox/* \
7877 /usr/share/pixmaps /usr/share/applications /usr/share/idl \
7878 /usr/share/omf /usr/share/sounds /usr/lib/bonobo/servers
7879 FILELIST = /bin/busybox /bin/busybox.nosuid /bin/busybox.suid /bin/sh \
7880 /etc/busybox.links.nosuid /etc/busybox.links.suid
7881
7882Most of these
7883name-value pairs correspond to variables used to produce the package.
7884The exceptions are ``FILELIST``, which is the actual list of files in
7885the package, and ``PKGSIZE``, which is the total size of files in the
7886package in bytes.
7887
7888A file also exists that corresponds to the recipe from which the package
7889came (e.g. ``buildhistory/packages/i586-poky-linux/busybox/latest``):
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007890
7891.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007892
7893 PV = 1.22.1
7894 PR = r32
7895 DEPENDS = initscripts kern-tools-native update-rc.d-native \
7896 virtual/i586-poky-linux-compilerlibs virtual/i586-poky-linux-gcc \
7897 virtual/libc virtual/update-alternatives
7898 PACKAGES = busybox-ptest busybox-httpd busybox-udhcpd busybox-udhcpc \
7899 busybox-syslog busybox-mdev busybox-hwclock busybox-dbg \
7900 busybox-staticdev busybox-dev busybox-doc busybox-locale busybox
7901
7902Finally, for those recipes fetched from a version control system (e.g.,
7903Git), a file exists that lists source revisions that are specified in
7904the recipe and lists the actual revisions used during the build. Listed
7905and actual revisions might differ when
7906:term:`SRCREV` is set to
7907${:term:`AUTOREV`}. Here is an
7908example assuming
Andrew Geisslerc926e172021-05-07 16:11:35 -05007909``buildhistory/packages/qemux86-poky-linux/linux-yocto/latest_srcrev``)::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007910
7911 # SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
7912 SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
7913 # SRCREV_meta = "a227f20eff056e511d504b2e490f3774ab260d6f"
7914 SRCREV_meta ="a227f20eff056e511d504b2e490f3774ab260d6f"
7915
7916You can use the
7917``buildhistory-collect-srcrevs`` command with the ``-a`` option to
7918collect the stored ``SRCREV`` values from build history and report them
7919in a format suitable for use in global configuration (e.g.,
7920``local.conf`` or a distro include file) to override floating
7921``AUTOREV`` values to a fixed set of revisions. Here is some example
Andrew Geisslerc926e172021-05-07 16:11:35 -05007922output from this command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007923
7924 $ buildhistory-collect-srcrevs -a
7925 # i586-poky-linux
7926 SRCREV_pn-glibc = "b8079dd0d360648e4e8de48656c5c38972621072"
7927 SRCREV_pn-glibc-initial = "b8079dd0d360648e4e8de48656c5c38972621072"
7928 SRCREV_pn-opkg-utils = "53274f087565fd45d8452c5367997ba6a682a37a"
7929 SRCREV_pn-kmod = "fd56638aed3fe147015bfa10ed4a5f7491303cb4"
7930 # x86_64-linux
7931 SRCREV_pn-gtk-doc-stub-native = "1dea266593edb766d6d898c79451ef193eb17cfa"
7932 SRCREV_pn-dtc-native = "65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf"
7933 SRCREV_pn-update-rc.d-native = "eca680ddf28d024954895f59a241a622dd575c11"
7934 SRCREV_glibc_pn-cross-localedef-native = "b8079dd0d360648e4e8de48656c5c38972621072"
7935 SRCREV_localedef_pn-cross-localedef-native = "c833367348d39dad7ba018990bfdaffaec8e9ed3"
7936 SRCREV_pn-prelink-native = "faa069deec99bf61418d0bab831c83d7c1b797ca"
7937 SRCREV_pn-opkg-utils-native = "53274f087565fd45d8452c5367997ba6a682a37a"
7938 SRCREV_pn-kern-tools-native = "23345b8846fe4bd167efdf1bd8a1224b2ba9a5ff"
7939 SRCREV_pn-kmod-native = "fd56638aed3fe147015bfa10ed4a5f7491303cb4"
7940 # qemux86-poky-linux
7941 SRCREV_machine_pn-linux-yocto = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
7942 SRCREV_meta_pn-linux-yocto = "a227f20eff056e511d504b2e490f3774ab260d6f"
7943 # all-poky-linux
7944 SRCREV_pn-update-rc.d = "eca680ddf28d024954895f59a241a622dd575c11"
7945
7946.. note::
7947
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007948 Here are some notes on using the ``buildhistory-collect-srcrevs`` command:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007949
7950 - By default, only values where the ``SRCREV`` was not hardcoded
7951 (usually when ``AUTOREV`` is used) are reported. Use the ``-a``
7952 option to see all ``SRCREV`` values.
7953
7954 - The output statements might not have any effect if overrides are
7955 applied elsewhere in the build system configuration. Use the
7956 ``-f`` option to add the ``forcevariable`` override to each output
7957 line if you need to work around this restriction.
7958
7959 - The script does apply special handling when building for multiple
7960 machines. However, the script does place a comment before each set
7961 of values that specifies which triplet to which they belong as
7962 previously shown (e.g., ``i586-poky-linux``).
7963
7964Build History Image Information
7965~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7966
7967The files produced for each image are as follows:
7968
7969- ``image-files:`` A directory containing selected files from the root
7970 filesystem. The files are defined by
7971 :term:`BUILDHISTORY_IMAGE_FILES`.
7972
7973- ``build-id.txt:`` Human-readable information about the build
7974 configuration and metadata source revisions. This file contains the
7975 full build header as printed by BitBake.
7976
7977- ``*.dot:`` Dependency graphs for the image that are compatible with
7978 ``graphviz``.
7979
7980- ``files-in-image.txt:`` A list of files in the image with
7981 permissions, owner, group, size, and symlink information.
7982
7983- ``image-info.txt:`` A text file containing name-value pairs with
7984 information about the image. See the following listing example for
7985 more information.
7986
7987- ``installed-package-names.txt:`` A list of installed packages by name
7988 only.
7989
7990- ``installed-package-sizes.txt:`` A list of installed packages ordered
7991 by size.
7992
7993- ``installed-packages.txt:`` A list of installed packages with full
7994 package filenames.
7995
7996.. note::
7997
7998 Installed package information is able to be gathered and produced
7999 even if package management is disabled for the final image.
8000
8001Here is an example of ``image-info.txt``:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008002
8003.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008004
8005 DISTRO = poky
8006 DISTRO_VERSION = 1.7
8007 USER_CLASSES = buildstats image-mklibs image-prelink
8008 IMAGE_CLASSES = image_types
8009 IMAGE_FEATURES = debug-tweaks
8010 IMAGE_LINGUAS =
8011 IMAGE_INSTALL = packagegroup-core-boot run-postinsts
8012 BAD_RECOMMENDATIONS =
8013 NO_RECOMMENDATIONS =
8014 PACKAGE_EXCLUDE =
8015 ROOTFS_POSTPROCESS_COMMAND = write_package_manifest; license_create_manifest; \
8016 write_image_manifest ; buildhistory_list_installed_image ; \
8017 buildhistory_get_image_installed ; ssh_allow_empty_password; \
8018 postinst_enable_logging; rootfs_update_timestamp ; ssh_disable_dns_lookup ;
8019 IMAGE_POSTPROCESS_COMMAND = buildhistory_get_imageinfo ;
8020 IMAGESIZE = 6900
8021
8022Other than ``IMAGESIZE``,
8023which is the total size of the files in the image in Kbytes, the
8024name-value pairs are variables that may have influenced the content of
8025the image. This information is often useful when you are trying to
8026determine why a change in the package or file listings has occurred.
8027
8028Using Build History to Gather Image Information Only
8029~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8030
8031As you can see, build history produces image information, including
8032dependency graphs, so you can see why something was pulled into the
8033image. If you are just interested in this information and not interested
8034in collecting specific package or SDK information, you can enable
8035writing only image information without any history by adding the
8036following to your ``conf/local.conf`` file found in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05008037:term:`Build Directory`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008038
8039 INHERIT += "buildhistory"
8040 BUILDHISTORY_COMMIT = "0"
8041 BUILDHISTORY_FEATURES = "image"
8042
8043Here, you set the
8044:term:`BUILDHISTORY_FEATURES`
8045variable to use the image feature only.
8046
8047Build History SDK Information
8048~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8049
8050Build history collects similar information on the contents of SDKs (e.g.
8051``bitbake -c populate_sdk imagename``) as compared to information it
8052collects for images. Furthermore, this information differs depending on
8053whether an extensible or standard SDK is being produced.
8054
8055The following list shows the files produced for SDKs:
8056
8057- ``files-in-sdk.txt:`` A list of files in the SDK with permissions,
8058 owner, group, size, and symlink information. This list includes both
8059 the host and target parts of the SDK.
8060
8061- ``sdk-info.txt:`` A text file containing name-value pairs with
8062 information about the SDK. See the following listing example for more
8063 information.
8064
8065- ``sstate-task-sizes.txt:`` A text file containing name-value pairs
8066 with information about task group sizes (e.g. ``do_populate_sysroot``
8067 tasks have a total size). The ``sstate-task-sizes.txt`` file exists
8068 only when an extensible SDK is created.
8069
8070- ``sstate-package-sizes.txt:`` A text file containing name-value pairs
8071 with information for the shared-state packages and sizes in the SDK.
8072 The ``sstate-package-sizes.txt`` file exists only when an extensible
8073 SDK is created.
8074
8075- ``sdk-files:`` A folder that contains copies of the files mentioned
8076 in ``BUILDHISTORY_SDK_FILES`` if the files are present in the output.
8077 Additionally, the default value of ``BUILDHISTORY_SDK_FILES`` is
8078 specific to the extensible SDK although you can set it differently if
8079 you would like to pull in specific files from the standard SDK.
8080
8081 The default files are ``conf/local.conf``, ``conf/bblayers.conf``,
8082 ``conf/auto.conf``, ``conf/locked-sigs.inc``, and
8083 ``conf/devtool.conf``. Thus, for an extensible SDK, these files get
8084 copied into the ``sdk-files`` directory.
8085
8086- The following information appears under each of the ``host`` and
8087 ``target`` directories for the portions of the SDK that run on the
8088 host and on the target, respectively:
8089
8090 .. note::
8091
8092 The following files for the most part are empty when producing an
8093 extensible SDK because this type of SDK is not constructed from
8094 packages as is the standard SDK.
8095
8096 - ``depends.dot:`` Dependency graph for the SDK that is compatible
8097 with ``graphviz``.
8098
8099 - ``installed-package-names.txt:`` A list of installed packages by
8100 name only.
8101
8102 - ``installed-package-sizes.txt:`` A list of installed packages
8103 ordered by size.
8104
8105 - ``installed-packages.txt:`` A list of installed packages with full
8106 package filenames.
8107
8108Here is an example of ``sdk-info.txt``:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008109
8110.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008111
8112 DISTRO = poky
8113 DISTRO_VERSION = 1.3+snapshot-20130327
8114 SDK_NAME = poky-glibc-i686-arm
8115 SDK_VERSION = 1.3+snapshot
8116 SDKMACHINE =
8117 SDKIMAGE_FEATURES = dev-pkgs dbg-pkgs
8118 BAD_RECOMMENDATIONS =
8119 SDKSIZE = 352712
8120
8121Other than ``SDKSIZE``, which is
8122the total size of the files in the SDK in Kbytes, the name-value pairs
8123are variables that might have influenced the content of the SDK. This
8124information is often useful when you are trying to determine why a
8125change in the package or file listings has occurred.
8126
8127Examining Build History Information
8128~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8129
8130You can examine build history output from the command line or from a web
8131interface.
8132
8133To see any changes that have occurred (assuming you have
8134:term:`BUILDHISTORY_COMMIT` = "1"),
8135you can simply use any Git command that allows you to view the history
Andrew Geisslerc926e172021-05-07 16:11:35 -05008136of a repository. Here is one method::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008137
8138 $ git log -p
8139
8140You need to realize,
8141however, that this method does show changes that are not significant
8142(e.g. a package's size changing by a few bytes).
8143
8144A command-line tool called ``buildhistory-diff`` does exist, though,
8145that queries the Git repository and prints just the differences that
Andrew Geisslerc926e172021-05-07 16:11:35 -05008146might be significant in human-readable form. Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008147
Andrew Geissler95ac1b82021-03-31 14:34:31 -05008148 $ poky/poky/scripts/buildhistory-diff . HEAD^
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008149 Changes to images/qemux86_64/glibc/core-image-minimal (files-in-image.txt):
8150 /etc/anotherpkg.conf was added
8151 /sbin/anotherpkg was added
8152 * (installed-package-names.txt):
8153 * anotherpkg was added
8154 Changes to images/qemux86_64/glibc/core-image-minimal (installed-package-names.txt):
8155 anotherpkg was added
8156 packages/qemux86_64-poky-linux/v86d: PACKAGES: added "v86d-extras"
8157 * PR changed from "r0" to "r1"
8158 * PV changed from "0.1.10" to "0.1.12"
8159 packages/qemux86_64-poky-linux/v86d/v86d: PKGSIZE changed from 110579 to 144381 (+30%)
8160 * PR changed from "r0" to "r1"
8161 * PV changed from "0.1.10" to "0.1.12"
8162
8163.. note::
8164
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008165 The ``buildhistory-diff`` tool requires the ``GitPython``
Andrew Geisslerc926e172021-05-07 16:11:35 -05008166 package. Be sure to install it using Pip3 as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008167
8168 $ pip3 install GitPython --user
8169
8170
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008171 Alternatively, you can install ``python3-git`` using the appropriate
8172 distribution package manager (e.g. ``apt-get``, ``dnf``, or ``zipper``).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008173
8174To see changes to the build history using a web interface, follow the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008175instruction in the ``README`` file
Andrew Geissler09209ee2020-12-13 08:44:15 -06008176:yocto_git:`here </buildhistory-web/>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008177
8178Here is a sample screenshot of the interface:
8179
8180.. image:: figures/buildhistory-web.png
8181 :align: center
8182
8183Performing Automated Runtime Testing
8184====================================
8185
8186The OpenEmbedded build system makes available a series of automated
8187tests for images to verify runtime functionality. You can run these
8188tests on either QEMU or actual target hardware. Tests are written in
8189Python making use of the ``unittest`` module, and the majority of them
8190run commands on the target system over SSH. This section describes how
8191you set up the environment to use these tests, run available tests, and
8192write and add your own tests.
8193
8194For information on the test and QA infrastructure available within the
Andrew Geissler09209ee2020-12-13 08:44:15 -06008195Yocto Project, see the ":ref:`ref-manual/release-process:testing and quality assurance`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008196section in the Yocto Project Reference Manual.
8197
8198Enabling Tests
8199--------------
8200
8201Depending on whether you are planning to run tests using QEMU or on the
8202hardware, you have to take different steps to enable the tests. See the
8203following subsections for information on how to enable both types of
8204tests.
8205
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008206Enabling Runtime Tests on QEMU
8207~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8208
8209In order to run tests, you need to do the following:
8210
8211- *Set up to avoid interaction with sudo for networking:* To
8212 accomplish this, you must do one of the following:
8213
8214 - Add ``NOPASSWD`` for your user in ``/etc/sudoers`` either for all
8215 commands or just for ``runqemu-ifup``. You must provide the full
8216 path as that can change if you are using multiple clones of the
8217 source repository.
8218
8219 .. note::
8220
8221 On some distributions, you also need to comment out "Defaults
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008222 requiretty" in ``/etc/sudoers``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008223
8224 - Manually configure a tap interface for your system.
8225
8226 - Run as root the script in ``scripts/runqemu-gen-tapdevs``, which
8227 should generate a list of tap devices. This is the option
8228 typically chosen for Autobuilder-type environments.
8229
8230 .. note::
8231
8232 - Be sure to use an absolute path when calling this script
8233 with sudo.
8234
8235 - The package recipe ``qemu-helper-native`` is required to run
Andrew Geisslerc926e172021-05-07 16:11:35 -05008236 this script. Build the package using the following command::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008237
8238 $ bitbake qemu-helper-native
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008239
8240- *Set the DISPLAY variable:* You need to set this variable so that
8241 you have an X server available (e.g. start ``vncserver`` for a
8242 headless machine).
8243
8244- *Be sure your host's firewall accepts incoming connections from
8245 192.168.7.0/24:* Some of the tests (in particular DNF tests) start an
8246 HTTP server on a random high number port, which is used to serve
8247 files to the target. The DNF module serves
8248 ``${WORKDIR}/oe-rootfs-repo`` so it can run DNF channel commands.
8249 That means your host's firewall must accept incoming connections from
8250 192.168.7.0/24, which is the default IP range used for tap devices by
8251 ``runqemu``.
8252
8253- *Be sure your host has the correct packages installed:* Depending
8254 your host's distribution, you need to have the following packages
8255 installed:
8256
8257 - Ubuntu and Debian: ``sysstat`` and ``iproute2``
8258
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05008259 - openSUSE: ``sysstat`` and ``iproute2``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008260
8261 - Fedora: ``sysstat`` and ``iproute``
8262
8263 - CentOS: ``sysstat`` and ``iproute``
8264
8265Once you start running the tests, the following happens:
8266
82671. A copy of the root filesystem is written to ``${WORKDIR}/testimage``.
8268
82692. The image is booted under QEMU using the standard ``runqemu`` script.
8270
82713. A default timeout of 500 seconds occurs to allow for the boot process
8272 to reach the login prompt. You can change the timeout period by
8273 setting
8274 :term:`TEST_QEMUBOOT_TIMEOUT`
8275 in the ``local.conf`` file.
8276
82774. Once the boot process is reached and the login prompt appears, the
8278 tests run. The full boot log is written to
8279 ``${WORKDIR}/testimage/qemu_boot_log``.
8280
82815. Each test module loads in the order found in ``TEST_SUITES``. You can
8282 find the full output of the commands run over SSH in
8283 ``${WORKDIR}/testimgage/ssh_target_log``.
8284
82856. If no failures occur, the task running the tests ends successfully.
8286 You can find the output from the ``unittest`` in the task log at
8287 ``${WORKDIR}/temp/log.do_testimage``.
8288
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008289Enabling Runtime Tests on Hardware
8290~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8291
8292The OpenEmbedded build system can run tests on real hardware, and for
8293certain devices it can also deploy the image to be tested onto the
8294device beforehand.
8295
8296For automated deployment, a "master image" is installed onto the
8297hardware once as part of setup. Then, each time tests are to be run, the
8298following occurs:
8299
83001. The master image is booted into and used to write the image to be
8301 tested to a second partition.
8302
83032. The device is then rebooted using an external script that you need to
8304 provide.
8305
83063. The device boots into the image to be tested.
8307
8308When running tests (independent of whether the image has been deployed
8309automatically or not), the device is expected to be connected to a
8310network on a pre-determined IP address. You can either use static IP
8311addresses written into the image, or set the image to use DHCP and have
8312your DHCP server on the test network assign a known IP address based on
8313the MAC address of the device.
8314
8315In order to run tests on hardware, you need to set ``TEST_TARGET`` to an
8316appropriate value. For QEMU, you do not have to change anything, the
8317default value is "qemu". For running tests on hardware, the following
8318options exist:
8319
8320- *"simpleremote":* Choose "simpleremote" if you are going to run tests
8321 on a target system that is already running the image to be tested and
8322 is available on the network. You can use "simpleremote" in
8323 conjunction with either real hardware or an image running within a
8324 separately started QEMU or any other virtual machine manager.
8325
8326- *"SystemdbootTarget":* Choose "SystemdbootTarget" if your hardware is
8327 an EFI-based machine with ``systemd-boot`` as bootloader and
8328 ``core-image-testmaster`` (or something similar) is installed. Also,
8329 your hardware under test must be in a DHCP-enabled network that gives
8330 it the same IP address for each reboot.
8331
8332 If you choose "SystemdbootTarget", there are additional requirements
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05008333 and considerations. See the
8334 ":ref:`dev-manual/common-tasks:selecting systemdboottarget`" section, which
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008335 follows, for more information.
8336
8337- *"BeagleBoneTarget":* Choose "BeagleBoneTarget" if you are deploying
8338 images and running tests on the BeagleBone "Black" or original
8339 "White" hardware. For information on how to use these tests, see the
8340 comments at the top of the BeagleBoneTarget
8341 ``meta-yocto-bsp/lib/oeqa/controllers/beaglebonetarget.py`` file.
8342
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008343- *"EdgeRouterTarget":* Choose "EdgeRouterTarget" if you are deploying
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008344 images and running tests on the Ubiquiti Networks EdgeRouter Lite.
8345 For information on how to use these tests, see the comments at the
8346 top of the EdgeRouterTarget
8347 ``meta-yocto-bsp/lib/oeqa/controllers/edgeroutertarget.py`` file.
8348
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008349- *"GrubTarget":* Choose "GrubTarget" if you are deploying images and running
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008350 tests on any generic PC that boots using GRUB. For information on how
8351 to use these tests, see the comments at the top of the GrubTarget
8352 ``meta-yocto-bsp/lib/oeqa/controllers/grubtarget.py`` file.
8353
8354- *"your-target":* Create your own custom target if you want to run
8355 tests when you are deploying images and running tests on a custom
8356 machine within your BSP layer. To do this, you need to add a Python
8357 unit that defines the target class under ``lib/oeqa/controllers/``
8358 within your layer. You must also provide an empty ``__init__.py``.
8359 For examples, see files in ``meta-yocto-bsp/lib/oeqa/controllers/``.
8360
8361Selecting SystemdbootTarget
8362~~~~~~~~~~~~~~~~~~~~~~~~~~~
8363
8364If you did not set ``TEST_TARGET`` to "SystemdbootTarget", then you do
8365not need any information in this section. You can skip down to the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05008366":ref:`dev-manual/common-tasks:running tests`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008367
8368If you did set ``TEST_TARGET`` to "SystemdbootTarget", you also need to
8369perform a one-time setup of your master image by doing the following:
8370
Andrew Geisslerc926e172021-05-07 16:11:35 -050083711. *Set EFI_PROVIDER:* Be sure that ``EFI_PROVIDER`` is as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008372
8373 EFI_PROVIDER = "systemd-boot"
8374
83752. *Build the master image:* Build the ``core-image-testmaster`` image.
8376 The ``core-image-testmaster`` recipe is provided as an example for a
8377 "master" image and you can customize the image recipe as you would
8378 any other recipe.
8379
8380 Here are the image recipe requirements:
8381
8382 - Inherits ``core-image`` so that kernel modules are installed.
8383
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05008384 - Installs normal linux utilities not BusyBox ones (e.g. ``bash``,
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008385 ``coreutils``, ``tar``, ``gzip``, and ``kmod``).
8386
8387 - Uses a custom Initial RAM Disk (initramfs) image with a custom
8388 installer. A normal image that you can install usually creates a
8389 single rootfs partition. This image uses another installer that
8390 creates a specific partition layout. Not all Board Support
8391 Packages (BSPs) can use an installer. For such cases, you need to
8392 manually create the following partition layout on the target:
8393
8394 - First partition mounted under ``/boot``, labeled "boot".
8395
8396 - The main rootfs partition where this image gets installed,
8397 which is mounted under ``/``.
8398
8399 - Another partition labeled "testrootfs" where test images get
8400 deployed.
8401
84023. *Install image:* Install the image that you just built on the target
8403 system.
8404
8405The final thing you need to do when setting ``TEST_TARGET`` to
8406"SystemdbootTarget" is to set up the test image:
8407
84081. *Set up your local.conf file:* Make sure you have the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05008409 statements in your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008410
8411 IMAGE_FSTYPES += "tar.gz"
8412 INHERIT += "testimage"
8413 TEST_TARGET = "SystemdbootTarget"
8414 TEST_TARGET_IP = "192.168.2.3"
8415
Andrew Geisslerc926e172021-05-07 16:11:35 -050084162. *Build your test image:* Use BitBake to build the image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008417
8418 $ bitbake core-image-sato
8419
8420Power Control
8421~~~~~~~~~~~~~
8422
8423For most hardware targets other than "simpleremote", you can control
8424power:
8425
8426- You can use ``TEST_POWERCONTROL_CMD`` together with
8427 ``TEST_POWERCONTROL_EXTRA_ARGS`` as a command that runs on the host
8428 and does power cycling. The test code passes one argument to that
8429 command: off, on or cycle (off then on). Here is an example that
Andrew Geisslerc926e172021-05-07 16:11:35 -05008430 could appear in your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008431
8432 TEST_POWERCONTROL_CMD = "powercontrol.exp test 10.11.12.1 nuc1"
8433
8434 In this example, the expect
8435 script does the following:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008436
8437 .. code-block:: shell
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008438
8439 ssh test@10.11.12.1 "pyctl nuc1 arg"
8440
8441 It then runs a Python script that controls power for a label called
8442 ``nuc1``.
8443
8444 .. note::
8445
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008446 You need to customize ``TEST_POWERCONTROL_CMD`` and
8447 ``TEST_POWERCONTROL_EXTRA_ARGS`` for your own setup. The one requirement
8448 is that it accepts "on", "off", and "cycle" as the last argument.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008449
8450- When no command is defined, it connects to the device over SSH and
8451 uses the classic reboot command to reboot the device. Classic reboot
8452 is fine as long as the machine actually reboots (i.e. the SSH test
8453 has not failed). It is useful for scenarios where you have a simple
8454 setup, typically with a single board, and where some manual
8455 interaction is okay from time to time.
8456
8457If you have no hardware to automatically perform power control but still
8458wish to experiment with automated hardware testing, you can use the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008459``dialog-power-control`` script that shows a dialog prompting you to perform
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008460the required power action. This script requires either KDialog or Zenity
8461to be installed. To use this script, set the
8462:term:`TEST_POWERCONTROL_CMD`
Andrew Geisslerc926e172021-05-07 16:11:35 -05008463variable as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008464
8465 TEST_POWERCONTROL_CMD = "${COREBASE}/scripts/contrib/dialog-power-control"
8466
8467Serial Console Connection
8468~~~~~~~~~~~~~~~~~~~~~~~~~
8469
8470For test target classes requiring a serial console to interact with the
8471bootloader (e.g. BeagleBoneTarget, EdgeRouterTarget, and GrubTarget),
8472you need to specify a command to use to connect to the serial console of
8473the target machine by using the
8474:term:`TEST_SERIALCONTROL_CMD`
8475variable and optionally the
8476:term:`TEST_SERIALCONTROL_EXTRA_ARGS`
8477variable.
8478
8479These cases could be a serial terminal program if the machine is
8480connected to a local serial port, or a ``telnet`` or ``ssh`` command
8481connecting to a remote console server. Regardless of the case, the
8482command simply needs to connect to the serial console and forward that
8483connection to standard input and output as any normal terminal program
8484does. For example, to use the picocom terminal program on serial device
Andrew Geisslerc926e172021-05-07 16:11:35 -05008485``/dev/ttyUSB0`` at 115200bps, you would set the variable as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008486
8487 TEST_SERIALCONTROL_CMD = "picocom /dev/ttyUSB0 -b 115200"
8488
8489For local
8490devices where the serial port device disappears when the device reboots,
8491an additional "serdevtry" wrapper script is provided. To use this
8492wrapper, simply prefix the terminal command with
Andrew Geisslerc926e172021-05-07 16:11:35 -05008493``${COREBASE}/scripts/contrib/serdevtry``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008494
8495 TEST_SERIALCONTROL_CMD = "${COREBASE}/scripts/contrib/serdevtry picocom -b 115200 /dev/ttyUSB0"
8496
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008497Running Tests
8498-------------
8499
8500You can start the tests automatically or manually:
8501
8502- *Automatically running tests:* To run the tests automatically after
8503 the OpenEmbedded build system successfully creates an image, first
8504 set the
8505 :term:`TESTIMAGE_AUTO`
8506 variable to "1" in your ``local.conf`` file in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05008507 :term:`Build Directory`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008508
8509 TESTIMAGE_AUTO = "1"
8510
8511 Next, build your image. If the image successfully builds, the
Andrew Geisslerc926e172021-05-07 16:11:35 -05008512 tests run::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008513
8514 bitbake core-image-sato
8515
8516- *Manually running tests:* To manually run the tests, first globally
8517 inherit the
8518 :ref:`testimage <ref-classes-testimage*>` class
Andrew Geisslerc926e172021-05-07 16:11:35 -05008519 by editing your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008520
8521 INHERIT += "testimage"
8522
Andrew Geisslerc926e172021-05-07 16:11:35 -05008523 Next, use BitBake to run the tests::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008524
8525 bitbake -c testimage image
8526
8527All test files reside in ``meta/lib/oeqa/runtime`` in the
8528:term:`Source Directory`. A test name maps
8529directly to a Python module. Each test module may contain a number of
8530individual tests. Tests are usually grouped together by the area tested
8531(e.g tests for systemd reside in ``meta/lib/oeqa/runtime/systemd.py``).
8532
8533You can add tests to any layer provided you place them in the proper
8534area and you extend :term:`BBPATH` in
8535the ``local.conf`` file as normal. Be sure that tests reside in
8536``layer/lib/oeqa/runtime``.
8537
8538.. note::
8539
8540 Be sure that module names do not collide with module names used in
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008541 the default set of test modules in ``meta/lib/oeqa/runtime``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008542
8543You can change the set of tests run by appending or overriding
8544:term:`TEST_SUITES` variable in
8545``local.conf``. Each name in ``TEST_SUITES`` represents a required test
8546for the image. Test modules named within ``TEST_SUITES`` cannot be
8547skipped even if a test is not suitable for an image (e.g. running the
8548RPM tests on an image without ``rpm``). Appending "auto" to
8549``TEST_SUITES`` causes the build system to try to run all tests that are
8550suitable for the image (i.e. each test module may elect to skip itself).
8551
8552The order you list tests in ``TEST_SUITES`` is important and influences
8553test dependencies. Consequently, tests that depend on other tests should
8554be added after the test on which they depend. For example, since the
8555``ssh`` test depends on the ``ping`` test, "ssh" needs to come after
8556"ping" in the list. The test class provides no re-ordering or dependency
8557handling.
8558
8559.. note::
8560
8561 Each module can have multiple classes with multiple test methods.
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008562 And, Python ``unittest`` rules apply.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008563
8564Here are some things to keep in mind when running tests:
8565
Andrew Geisslerc926e172021-05-07 16:11:35 -05008566- The default tests for the image are defined as::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008567
8568 DEFAULT_TEST_SUITES_pn-image = "ping ssh df connman syslog xorg scp vnc date rpm dnf dmesg"
8569
Andrew Geisslerc926e172021-05-07 16:11:35 -05008570- Add your own test to the list of the by using the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008571
8572 TEST_SUITES_append = " mytest"
8573
Andrew Geisslerc926e172021-05-07 16:11:35 -05008574- Run a specific list of tests as follows::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008575
8576 TEST_SUITES = "test1 test2 test3"
8577
8578 Remember, order is important. Be sure to place a test that is
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008579 dependent on another test later in the order.
8580
8581Exporting Tests
8582---------------
8583
8584You can export tests so that they can run independently of the build
8585system. Exporting tests is required if you want to be able to hand the
8586test execution off to a scheduler. You can only export tests that are
8587defined in :term:`TEST_SUITES`.
8588
8589If your image is already built, make sure the following are set in your
Andrew Geisslerc926e172021-05-07 16:11:35 -05008590``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008591
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008592 INHERIT += "testexport"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008593 TEST_TARGET_IP = "IP-address-for-the-test-target"
8594 TEST_SERVER_IP = "IP-address-for-the-test-server"
8595
8596You can then export the tests with the
Andrew Geisslerc926e172021-05-07 16:11:35 -05008597following BitBake command form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008598
8599 $ bitbake image -c testexport
8600
8601Exporting the tests places them in the
8602:term:`Build Directory` in
8603``tmp/testexport/``\ image, which is controlled by the
8604``TEST_EXPORT_DIR`` variable.
8605
Andrew Geisslerc926e172021-05-07 16:11:35 -05008606You can now run the tests outside of the build environment::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008607
8608 $ cd tmp/testexport/image
8609 $ ./runexported.py testdata.json
8610
8611Here is a complete example that shows IP addresses and uses the
Andrew Geisslerc926e172021-05-07 16:11:35 -05008612``core-image-sato`` image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008613
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008614 INHERIT += "testexport"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008615 TEST_TARGET_IP = "192.168.7.2"
8616 TEST_SERVER_IP = "192.168.7.1"
8617
Andrew Geisslerc926e172021-05-07 16:11:35 -05008618Use BitBake to export the tests::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008619
8620 $ bitbake core-image-sato -c testexport
8621
8622Run the tests outside of
Andrew Geisslerc926e172021-05-07 16:11:35 -05008623the build environment using the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008624
8625 $ cd tmp/testexport/core-image-sato
8626 $ ./runexported.py testdata.json
8627
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008628Writing New Tests
8629-----------------
8630
8631As mentioned previously, all new test files need to be in the proper
8632place for the build system to find them. New tests for additional
8633functionality outside of the core should be added to the layer that adds
8634the functionality, in ``layer/lib/oeqa/runtime`` (as long as
8635:term:`BBPATH` is extended in the
8636layer's ``layer.conf`` file as normal). Just remember the following:
8637
8638- Filenames need to map directly to test (module) names.
8639
8640- Do not use module names that collide with existing core tests.
8641
8642- Minimally, an empty ``__init__.py`` file must exist in the runtime
8643 directory.
8644
8645To create a new test, start by copying an existing module (e.g.
8646``syslog.py`` or ``gcc.py`` are good ones to use). Test modules can use
8647code from ``meta/lib/oeqa/utils``, which are helper classes.
8648
8649.. note::
8650
8651 Structure shell commands such that you rely on them and they return a
8652 single code for success. Be aware that sometimes you will need to
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008653 parse the output. See the ``df.py`` and ``date.py`` modules for examples.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008654
8655You will notice that all test classes inherit ``oeRuntimeTest``, which
8656is found in ``meta/lib/oetest.py``. This base class offers some helper
8657attributes, which are described in the following sections:
8658
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008659Class Methods
8660~~~~~~~~~~~~~
8661
8662Class methods are as follows:
8663
8664- *hasPackage(pkg):* Returns "True" if ``pkg`` is in the installed
8665 package list of the image, which is based on the manifest file that
8666 is generated during the ``do_rootfs`` task.
8667
8668- *hasFeature(feature):* Returns "True" if the feature is in
8669 :term:`IMAGE_FEATURES` or
8670 :term:`DISTRO_FEATURES`.
8671
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008672Class Attributes
8673~~~~~~~~~~~~~~~~
8674
8675Class attributes are as follows:
8676
8677- *pscmd:* Equals "ps -ef" if ``procps`` is installed in the image.
8678 Otherwise, ``pscmd`` equals "ps" (busybox).
8679
8680- *tc:* The called test context, which gives access to the
8681 following attributes:
8682
8683 - *d:* The BitBake datastore, which allows you to use stuff such
8684 as ``oeRuntimeTest.tc.d.getVar("VIRTUAL-RUNTIME_init_manager")``.
8685
8686 - *testslist and testsrequired:* Used internally. The tests
8687 do not need these.
8688
8689 - *filesdir:* The absolute path to
8690 ``meta/lib/oeqa/runtime/files``, which contains helper files for
8691 tests meant for copying on the target such as small files written
8692 in C for compilation.
8693
8694 - *target:* The target controller object used to deploy and
8695 start an image on a particular target (e.g. Qemu, SimpleRemote,
8696 and SystemdbootTarget). Tests usually use the following:
8697
8698 - *ip:* The target's IP address.
8699
8700 - *server_ip:* The host's IP address, which is usually used
8701 by the DNF test suite.
8702
8703 - *run(cmd, timeout=None):* The single, most used method.
8704 This command is a wrapper for: ``ssh root@host "cmd"``. The
8705 command returns a tuple: (status, output), which are what their
8706 names imply - the return code of "cmd" and whatever output it
8707 produces. The optional timeout argument represents the number
8708 of seconds the test should wait for "cmd" to return. If the
8709 argument is "None", the test uses the default instance's
8710 timeout period, which is 300 seconds. If the argument is "0",
8711 the test runs until the command returns.
8712
8713 - *copy_to(localpath, remotepath):*
8714 ``scp localpath root@ip:remotepath``.
8715
8716 - *copy_from(remotepath, localpath):*
8717 ``scp root@host:remotepath localpath``.
8718
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008719Instance Attributes
8720~~~~~~~~~~~~~~~~~~~
8721
8722A single instance attribute exists, which is ``target``. The ``target``
8723instance attribute is identical to the class attribute of the same name,
8724which is described in the previous section. This attribute exists as
8725both an instance and class attribute so tests can use
8726``self.target.run(cmd)`` in instance methods instead of
8727``oeRuntimeTest.tc.target.run(cmd)``.
8728
8729Installing Packages in the DUT Without the Package Manager
8730----------------------------------------------------------
8731
8732When a test requires a package built by BitBake, it is possible to
8733install that package. Installing the package does not require a package
8734manager be installed in the device under test (DUT). It does, however,
8735require an SSH connection and the target must be using the
8736``sshcontrol`` class.
8737
8738.. note::
8739
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008740 This method uses ``scp`` to copy files from the host to the target, which
8741 causes permissions and special attributes to be lost.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008742
8743A JSON file is used to define the packages needed by a test. This file
8744must be in the same path as the file used to define the tests.
8745Furthermore, the filename must map directly to the test module name with
8746a ``.json`` extension.
8747
8748The JSON file must include an object with the test name as keys of an
8749object or an array. This object (or array of objects) uses the following
8750data:
8751
8752- "pkg" - A mandatory string that is the name of the package to be
8753 installed.
8754
8755- "rm" - An optional boolean, which defaults to "false", that specifies
8756 to remove the package after the test.
8757
8758- "extract" - An optional boolean, which defaults to "false", that
8759 specifies if the package must be extracted from the package format.
8760 When set to "true", the package is not automatically installed into
8761 the DUT.
8762
8763Following is an example JSON file that handles test "foo" installing
8764package "bar" and test "foobar" installing packages "foo" and "bar".
8765Once the test is complete, the packages are removed from the DUT.
8766::
8767
8768 {
8769 "foo": {
8770 "pkg": "bar"
8771 },
8772 "foobar": [
8773 {
8774 "pkg": "foo",
8775 "rm": true
8776 },
8777 {
8778 "pkg": "bar",
8779 "rm": true
8780 }
8781 ]
8782 }
8783
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008784Debugging Tools and Techniques
8785==============================
8786
8787The exact method for debugging build failures depends on the nature of
8788the problem and on the system's area from which the bug originates.
8789Standard debugging practices such as comparison against the last known
8790working version with examination of the changes and the re-application
8791of steps to identify the one causing the problem are valid for the Yocto
8792Project just as they are for any other system. Even though it is
8793impossible to detail every possible potential failure, this section
8794provides some general tips to aid in debugging given a variety of
8795situations.
8796
8797.. note::
8798
8799 A useful feature for debugging is the error reporting tool.
8800 Configuring the Yocto Project to use this tool causes the
8801 OpenEmbedded build system to produce error reporting commands as part
8802 of the console output. You can enter the commands after the build
8803 completes to log error information into a common database, that can
8804 help you figure out what might be going wrong. For information on how
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008805 to enable and use this feature, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06008806 ":ref:`dev-manual/common-tasks:using the error reporting tool`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008807 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008808
8809The following list shows the debugging topics in the remainder of this
8810section:
8811
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05008812- ":ref:`dev-manual/common-tasks:viewing logs from failed tasks`" describes
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008813 how to find and view logs from tasks that failed during the build
8814 process.
8815
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05008816- ":ref:`dev-manual/common-tasks:viewing variable values`" describes how to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008817 use the BitBake ``-e`` option to examine variable values after a
8818 recipe has been parsed.
8819
Andrew Geissler09209ee2020-12-13 08:44:15 -06008820- ":ref:`dev-manual/common-tasks:viewing package information with \`\`oe-pkgdata-util\`\``"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008821 describes how to use the ``oe-pkgdata-util`` utility to query
8822 :term:`PKGDATA_DIR` and
8823 display package-related information for built packages.
8824
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05008825- ":ref:`dev-manual/common-tasks:viewing dependencies between recipes and tasks`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008826 describes how to use the BitBake ``-g`` option to display recipe
8827 dependency information used during the build.
8828
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05008829- ":ref:`dev-manual/common-tasks:viewing task variable dependencies`" describes
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008830 how to use the ``bitbake-dumpsig`` command in conjunction with key
8831 subdirectories in the
8832 :term:`Build Directory` to determine
8833 variable dependencies.
8834
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05008835- ":ref:`dev-manual/common-tasks:running specific tasks`" describes
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008836 how to use several BitBake options (e.g. ``-c``, ``-C``, and ``-f``)
8837 to run specific tasks in the build chain. It can be useful to run
8838 tasks "out-of-order" when trying isolate build issues.
8839
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05008840- ":ref:`dev-manual/common-tasks:general bitbake problems`" describes how
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008841 to use BitBake's ``-D`` debug output option to reveal more about what
8842 BitBake is doing during the build.
8843
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05008844- ":ref:`dev-manual/common-tasks:building with no dependencies`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008845 describes how to use the BitBake ``-b`` option to build a recipe
8846 while ignoring dependencies.
8847
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05008848- ":ref:`dev-manual/common-tasks:recipe logging mechanisms`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008849 describes how to use the many recipe logging functions to produce
8850 debugging output and report errors and warnings.
8851
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05008852- ":ref:`dev-manual/common-tasks:debugging parallel make races`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008853 describes how to debug situations where the build consists of several
8854 parts that are run simultaneously and when the output or result of
8855 one part is not ready for use with a different part of the build that
8856 depends on that output.
8857
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05008858- ":ref:`dev-manual/common-tasks:debugging with the gnu project debugger (gdb) remotely`"
8859 describes how to use GDB to allow you to examine running programs, which can
8860 help you fix problems.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008861
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05008862- ":ref:`dev-manual/common-tasks:debugging with the gnu project debugger (gdb) on the target`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008863 describes how to use GDB directly on target hardware for debugging.
8864
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05008865- ":ref:`dev-manual/common-tasks:other debugging tips`" describes
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008866 miscellaneous debugging tips that can be useful.
8867
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008868Viewing Logs from Failed Tasks
8869------------------------------
8870
8871You can find the log for a task in the file
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008872``${``\ :term:`WORKDIR`\ ``}/temp/log.do_``\ `taskname`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008873For example, the log for the
8874:ref:`ref-tasks-compile` task of the
8875QEMU minimal image for the x86 machine (``qemux86``) might be in
8876``tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/temp/log.do_compile``.
8877To see the commands :term:`BitBake` ran
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008878to generate a log, look at the corresponding ``run.do_``\ `taskname` file
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008879in the same directory.
8880
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008881``log.do_``\ `taskname` and ``run.do_``\ `taskname` are actually symbolic
8882links to ``log.do_``\ `taskname`\ ``.``\ `pid` and
8883``log.run_``\ `taskname`\ ``.``\ `pid`, where `pid` is the PID the task had
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008884when it ran. The symlinks always point to the files corresponding to the
8885most recent run.
8886
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008887Viewing Variable Values
8888-----------------------
8889
8890Sometimes you need to know the value of a variable as a result of
8891BitBake's parsing step. This could be because some unexpected behavior
8892occurred in your project. Perhaps an attempt to :ref:`modify a variable
8893<bitbake:bitbake-user-manual/bitbake-user-manual-metadata:modifying existing
8894variables>` did not work out as expected.
8895
8896BitBake's ``-e`` option is used to display variable values after
8897parsing. The following command displays the variable values after the
8898configuration files (i.e. ``local.conf``, ``bblayers.conf``,
Andrew Geisslerc926e172021-05-07 16:11:35 -05008899``bitbake.conf`` and so forth) have been parsed::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008900
8901 $ bitbake -e
8902
8903The following command displays variable values after a specific recipe has
Andrew Geisslerc926e172021-05-07 16:11:35 -05008904been parsed. The variables include those from the configuration as well::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008905
8906 $ bitbake -e recipename
8907
8908.. note::
8909
8910 Each recipe has its own private set of variables (datastore).
8911 Internally, after parsing the configuration, a copy of the resulting
8912 datastore is made prior to parsing each recipe. This copying implies
8913 that variables set in one recipe will not be visible to other
8914 recipes.
8915
8916 Likewise, each task within a recipe gets a private datastore based on
8917 the recipe datastore, which means that variables set within one task
8918 will not be visible to other tasks.
8919
8920In the output of ``bitbake -e``, each variable is preceded by a
8921description of how the variable got its value, including temporary
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008922values that were later overridden. This description also includes
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008923variable flags (varflags) set on the variable. The output can be very
8924helpful during debugging.
8925
8926Variables that are exported to the environment are preceded by
Andrew Geisslerc926e172021-05-07 16:11:35 -05008927``export`` in the output of ``bitbake -e``. See the following example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008928
8929 export CC="i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/ulf/poky/build/tmp/sysroots/qemux86"
8930
8931In addition to variable values, the output of the ``bitbake -e`` and
8932``bitbake -e`` recipe commands includes the following information:
8933
8934- The output starts with a tree listing all configuration files and
8935 classes included globally, recursively listing the files they include
8936 or inherit in turn. Much of the behavior of the OpenEmbedded build
Andrew Geissler09209ee2020-12-13 08:44:15 -06008937 system (including the behavior of the :ref:`ref-manual/tasks:normal recipe build tasks`) is
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008938 implemented in the
8939 :ref:`base <ref-classes-base>` class and the
8940 classes it inherits, rather than being built into BitBake itself.
8941
8942- After the variable values, all functions appear in the output. For
8943 shell functions, variables referenced within the function body are
8944 expanded. If a function has been modified using overrides or using
8945 override-style operators like ``_append`` and ``_prepend``, then the
8946 final assembled function body appears in the output.
8947
8948Viewing Package Information with ``oe-pkgdata-util``
8949----------------------------------------------------
8950
8951You can use the ``oe-pkgdata-util`` command-line utility to query
8952:term:`PKGDATA_DIR` and display
8953various package-related information. When you use the utility, you must
8954use it to view information on packages that have already been built.
8955
8956Following are a few of the available ``oe-pkgdata-util`` subcommands.
8957
8958.. note::
8959
8960 You can use the standard \* and ? globbing wildcards as part of
8961 package names and paths.
8962
8963- ``oe-pkgdata-util list-pkgs [pattern]``: Lists all packages
8964 that have been built, optionally limiting the match to packages that
8965 match pattern.
8966
8967- ``oe-pkgdata-util list-pkg-files package ...``: Lists the
8968 files and directories contained in the given packages.
8969
8970 .. note::
8971
8972 A different way to view the contents of a package is to look at
8973 the
8974 ``${``\ :term:`WORKDIR`\ ``}/packages-split``
8975 directory of the recipe that generates the package. This directory
8976 is created by the
8977 :ref:`ref-tasks-package` task
8978 and has one subdirectory for each package the recipe generates,
8979 which contains the files stored in that package.
8980
8981 If you want to inspect the ``${WORKDIR}/packages-split``
8982 directory, make sure that
8983 :ref:`rm_work <ref-classes-rm-work>` is not
8984 enabled when you build the recipe.
8985
8986- ``oe-pkgdata-util find-path path ...``: Lists the names of
8987 the packages that contain the given paths. For example, the following
8988 tells us that ``/usr/share/man/man1/make.1`` is contained in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05008989 ``make-doc`` package::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008990
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008991 $ oe-pkgdata-util find-path /usr/share/man/man1/make.1
8992 make-doc: /usr/share/man/man1/make.1
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008993
8994- ``oe-pkgdata-util lookup-recipe package ...``: Lists the name
8995 of the recipes that produce the given packages.
8996
8997For more information on the ``oe-pkgdata-util`` command, use the help
Andrew Geisslerc926e172021-05-07 16:11:35 -05008998facility::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008999
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009000 $ oe-pkgdata-util --help
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009001 $ oe-pkgdata-util subcommand --help
9002
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009003Viewing Dependencies Between Recipes and Tasks
9004----------------------------------------------
9005
9006Sometimes it can be hard to see why BitBake wants to build other recipes
9007before the one you have specified. Dependency information can help you
9008understand why a recipe is built.
9009
9010To generate dependency information for a recipe, run the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05009011command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009012
9013 $ bitbake -g recipename
9014
9015This command writes the following files in the current directory:
9016
9017- ``pn-buildlist``: A list of recipes/targets involved in building
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009018 `recipename`. "Involved" here means that at least one task from the
9019 recipe needs to run when building `recipename` from scratch. Targets
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009020 that are in
9021 :term:`ASSUME_PROVIDED`
9022 are not listed.
9023
9024- ``task-depends.dot``: A graph showing dependencies between tasks.
9025
9026The graphs are in
9027`DOT <https://en.wikipedia.org/wiki/DOT_%28graph_description_language%29>`__
9028format and can be converted to images (e.g. using the ``dot`` tool from
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009029`Graphviz <https://www.graphviz.org/>`__).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009030
9031.. note::
9032
9033 - DOT files use a plain text format. The graphs generated using the
9034 ``bitbake -g`` command are often so large as to be difficult to
9035 read without special pruning (e.g. with Bitbake's ``-I`` option)
9036 and processing. Despite the form and size of the graphs, the
9037 corresponding ``.dot`` files can still be possible to read and
9038 provide useful information.
9039
9040 As an example, the ``task-depends.dot`` file contains lines such
Andrew Geisslerc926e172021-05-07 16:11:35 -05009041 as the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009042
9043 "libxslt.do_configure" -> "libxml2.do_populate_sysroot"
9044
9045 The above example line reveals that the
9046 :ref:`ref-tasks-configure`
9047 task in ``libxslt`` depends on the
9048 :ref:`ref-tasks-populate_sysroot`
9049 task in ``libxml2``, which is a normal
9050 :term:`DEPENDS` dependency
9051 between the two recipes.
9052
9053 - For an example of how ``.dot`` files can be processed, see the
9054 ``scripts/contrib/graph-tool`` Python script, which finds and
9055 displays paths between graph nodes.
9056
9057You can use a different method to view dependency information by using
Andrew Geisslerc926e172021-05-07 16:11:35 -05009058the following command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009059
9060 $ bitbake -g -u taskexp recipename
9061
9062This command
9063displays a GUI window from which you can view build-time and runtime
9064dependencies for the recipes involved in building recipename.
9065
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009066Viewing Task Variable Dependencies
9067----------------------------------
9068
9069As mentioned in the
9070":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-execution:checksums (signatures)`" section of the BitBake
9071User Manual, BitBake tries to automatically determine what variables a
9072task depends on so that it can rerun the task if any values of the
9073variables change. This determination is usually reliable. However, if
9074you do things like construct variable names at runtime, then you might
9075have to manually declare dependencies on those variables using
9076``vardeps`` as described in the
9077":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags`" section of the BitBake
9078User Manual.
9079
9080If you are unsure whether a variable dependency is being picked up
9081automatically for a given task, you can list the variable dependencies
9082BitBake has determined by doing the following:
9083
Andrew Geisslerc926e172021-05-07 16:11:35 -050090841. Build the recipe containing the task::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009085
9086 $ bitbake recipename
9087
90882. Inside the :term:`STAMPS_DIR`
9089 directory, find the signature data (``sigdata``) file that
9090 corresponds to the task. The ``sigdata`` files contain a pickled
9091 Python database of all the metadata that went into creating the input
9092 checksum for the task. As an example, for the
9093 :ref:`ref-tasks-fetch` task of the
9094 ``db`` recipe, the ``sigdata`` file might be found in the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05009095 location::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009096
9097 ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
9098
9099 For tasks that are accelerated through the shared state
Andrew Geissler09209ee2020-12-13 08:44:15 -06009100 (:ref:`sstate <overview-manual/concepts:shared state cache>`) cache, an
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009101 additional ``siginfo`` file is written into
9102 :term:`SSTATE_DIR` along with
9103 the cached task output. The ``siginfo`` files contain exactly the
9104 same information as ``sigdata`` files.
9105
91063. Run ``bitbake-dumpsig`` on the ``sigdata`` or ``siginfo`` file. Here
Andrew Geisslerc926e172021-05-07 16:11:35 -05009107 is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009108
9109 $ bitbake-dumpsig ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
9110
9111 In the output of the above command, you will find a line like the
9112 following, which lists all the (inferred) variable dependencies for
9113 the task. This list also includes indirect dependencies from
9114 variables depending on other variables, recursively.
9115 ::
9116
9117 Task dependencies: ['PV', 'SRCREV', 'SRC_URI', 'SRC_URI[md5sum]', 'SRC_URI[sha256sum]', 'base_do_fetch']
9118
9119 .. note::
9120
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009121 Functions (e.g. ``base_do_fetch``) also count as variable dependencies.
9122 These functions in turn depend on the variables they reference.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009123
9124 The output of ``bitbake-dumpsig`` also includes the value each
9125 variable had, a list of dependencies for each variable, and
9126 :term:`bitbake:BB_HASHBASE_WHITELIST`
9127 information.
9128
9129There is also a ``bitbake-diffsigs`` command for comparing two
9130``siginfo`` or ``sigdata`` files. This command can be helpful when
9131trying to figure out what changed between two versions of a task. If you
9132call ``bitbake-diffsigs`` with just one file, the command behaves like
9133``bitbake-dumpsig``.
9134
9135You can also use BitBake to dump out the signature construction
9136information without executing tasks by using either of the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05009137BitBake command-line options::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009138
9139 ‐‐dump-signatures=SIGNATURE_HANDLER
9140 -S SIGNATURE_HANDLER
9141
9142
9143.. note::
9144
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009145 Two common values for `SIGNATURE_HANDLER` are "none" and "printdiff", which
9146 dump only the signature or compare the dumped signature with the cached one,
9147 respectively.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009148
9149Using BitBake with either of these options causes BitBake to dump out
9150``sigdata`` files in the ``stamps`` directory for every task it would
9151have executed instead of building the specified target package.
9152
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009153Viewing Metadata Used to Create the Input Signature of a Shared State Task
9154--------------------------------------------------------------------------
9155
9156Seeing what metadata went into creating the input signature of a shared
9157state (sstate) task can be a useful debugging aid. This information is
9158available in signature information (``siginfo``) files in
9159:term:`SSTATE_DIR`. For
9160information on how to view and interpret information in ``siginfo``
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009161files, see the
9162":ref:`dev-manual/common-tasks:viewing task variable dependencies`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009163
9164For conceptual information on shared state, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06009165":ref:`overview-manual/concepts:shared state`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009166section in the Yocto Project Overview and Concepts Manual.
9167
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009168Invalidating Shared State to Force a Task to Run
9169------------------------------------------------
9170
9171The OpenEmbedded build system uses
Andrew Geissler09209ee2020-12-13 08:44:15 -06009172:ref:`checksums <overview-manual/concepts:checksums (signatures)>` and
9173:ref:`overview-manual/concepts:shared state` cache to avoid unnecessarily
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009174rebuilding tasks. Collectively, this scheme is known as "shared state
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009175code".
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009176
9177As with all schemes, this one has some drawbacks. It is possible that
9178you could make implicit changes to your code that the checksum
9179calculations do not take into account. These implicit changes affect a
9180task's output but do not trigger the shared state code into rebuilding a
9181recipe. Consider an example during which a tool changes its output.
9182Assume that the output of ``rpmdeps`` changes. The result of the change
9183should be that all the ``package`` and ``package_write_rpm`` shared
9184state cache items become invalid. However, because the change to the
9185output is external to the code and therefore implicit, the associated
9186shared state cache items do not become invalidated. In this case, the
9187build process uses the cached items rather than running the task again.
9188Obviously, these types of implicit changes can cause problems.
9189
9190To avoid these problems during the build, you need to understand the
9191effects of any changes you make. Realize that changes you make directly
9192to a function are automatically factored into the checksum calculation.
9193Thus, these explicit changes invalidate the associated area of shared
9194state cache. However, you need to be aware of any implicit changes that
9195are not obvious changes to the code and could affect the output of a
9196given task.
9197
9198When you identify an implicit change, you can easily take steps to
9199invalidate the cache and force the tasks to run. The steps you can take
9200are as simple as changing a function's comments in the source code. For
9201example, to invalidate package shared state files, change the comment
9202statements of
9203:ref:`ref-tasks-package` or the
9204comments of one of the functions it calls. Even though the change is
9205purely cosmetic, it causes the checksum to be recalculated and forces
9206the build system to run the task again.
9207
9208.. note::
9209
9210 For an example of a commit that makes a cosmetic change to invalidate
9211 shared state, see this
Andrew Geissler09209ee2020-12-13 08:44:15 -06009212 :yocto_git:`commit </poky/commit/meta/classes/package.bbclass?id=737f8bbb4f27b4837047cb9b4fbfe01dfde36d54>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009213
9214Running Specific Tasks
9215----------------------
9216
9217Any given recipe consists of a set of tasks. The standard BitBake
9218behavior in most cases is: ``do_fetch``, ``do_unpack``, ``do_patch``,
9219``do_configure``, ``do_compile``, ``do_install``, ``do_package``,
9220``do_package_write_*``, and ``do_build``. The default task is
9221``do_build`` and any tasks on which it depends build first. Some tasks,
9222such as ``do_devshell``, are not part of the default build chain. If you
9223wish to run a task that is not part of the default build chain, you can
Andrew Geisslerc926e172021-05-07 16:11:35 -05009224use the ``-c`` option in BitBake. Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009225
9226 $ bitbake matchbox-desktop -c devshell
9227
9228The ``-c`` option respects task dependencies, which means that all other
9229tasks (including tasks from other recipes) that the specified task
9230depends on will be run before the task. Even when you manually specify a
9231task to run with ``-c``, BitBake will only run the task if it considers
9232it "out of date". See the
Andrew Geissler09209ee2020-12-13 08:44:15 -06009233":ref:`overview-manual/concepts:stamp files and the rerunning of tasks`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009234section in the Yocto Project Overview and Concepts Manual for how
9235BitBake determines whether a task is "out of date".
9236
9237If you want to force an up-to-date task to be rerun (e.g. because you
9238made manual modifications to the recipe's
9239:term:`WORKDIR` that you want to try
9240out), then you can use the ``-f`` option.
9241
9242.. note::
9243
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009244 The reason ``-f`` is never required when running the
9245 :ref:`ref-tasks-devshell` task is because the
9246 [\ :ref:`nostamp <bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ]
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009247 variable flag is already set for the task.
9248
Andrew Geisslerc926e172021-05-07 16:11:35 -05009249The following example shows one way you can use the ``-f`` option::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009250
9251 $ bitbake matchbox-desktop
9252 .
9253 .
9254 make some changes to the source code in the work directory
9255 .
9256 .
9257 $ bitbake matchbox-desktop -c compile -f
9258 $ bitbake matchbox-desktop
9259
9260This sequence first builds and then recompiles ``matchbox-desktop``. The
9261last command reruns all tasks (basically the packaging tasks) after the
9262compile. BitBake recognizes that the ``do_compile`` task was rerun and
9263therefore understands that the other tasks also need to be run again.
9264
9265Another, shorter way to rerun a task and all
Andrew Geissler09209ee2020-12-13 08:44:15 -06009266:ref:`ref-manual/tasks:normal recipe build tasks`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009267that depend on it is to use the ``-C`` option.
9268
9269.. note::
9270
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009271 This option is upper-cased and is separate from the ``-c``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009272 option, which is lower-cased.
9273
9274Using this option invalidates the given task and then runs the
9275:ref:`ref-tasks-build` task, which is
9276the default task if no task is given, and the tasks on which it depends.
9277You could replace the final two commands in the previous example with
Andrew Geisslerc926e172021-05-07 16:11:35 -05009278the following single command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009279
9280 $ bitbake matchbox-desktop -C compile
9281
9282Internally, the ``-f`` and ``-C`` options work by tainting (modifying)
9283the input checksum of the specified task. This tainting indirectly
9284causes the task and its dependent tasks to be rerun through the normal
9285task dependency mechanisms.
9286
9287.. note::
9288
9289 BitBake explicitly keeps track of which tasks have been tainted in
9290 this fashion, and will print warnings such as the following for
9291 builds involving such tasks:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009292
9293 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009294
9295 WARNING: /home/ulf/poky/meta/recipes-sato/matchbox-desktop/matchbox-desktop_2.1.bb.do_compile is tainted from a forced run
9296
9297
9298 The purpose of the warning is to let you know that the work directory
9299 and build output might not be in the clean state they would be in for
9300 a "normal" build, depending on what actions you took. To get rid of
9301 such warnings, you can remove the work directory and rebuild the
Andrew Geisslerc926e172021-05-07 16:11:35 -05009302 recipe, as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009303
9304 $ bitbake matchbox-desktop -c clean
9305 $ bitbake matchbox-desktop
9306
9307
9308You can view a list of tasks in a given package by running the
Andrew Geisslerc926e172021-05-07 16:11:35 -05009309``do_listtasks`` task as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009310
9311 $ bitbake matchbox-desktop -c listtasks
9312
9313The results appear as output to the console and are also in
9314the file ``${WORKDIR}/temp/log.do_listtasks``.
9315
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009316General BitBake Problems
9317------------------------
9318
9319You can see debug output from BitBake by using the ``-D`` option. The
9320debug output gives more information about what BitBake is doing and the
9321reason behind it. Each ``-D`` option you use increases the logging
9322level. The most common usage is ``-DDD``.
9323
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009324The output from ``bitbake -DDD -v targetname`` can reveal why BitBake
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009325chose a certain version of a package or why BitBake picked a certain
9326provider. This command could also help you in a situation where you
9327think BitBake did something unexpected.
9328
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009329Building with No Dependencies
9330-----------------------------
9331
9332To build a specific recipe (``.bb`` file), you can use the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05009333command form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009334
9335 $ bitbake -b somepath/somerecipe.bb
9336
9337This command form does
9338not check for dependencies. Consequently, you should use it only when
9339you know existing dependencies have been met.
9340
9341.. note::
9342
9343 You can also specify fragments of the filename. In this case, BitBake
9344 checks for a unique match.
9345
9346Recipe Logging Mechanisms
9347-------------------------
9348
9349The Yocto Project provides several logging functions for producing
9350debugging output and reporting errors and warnings. For Python
9351functions, the following logging functions exist. All of these functions
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009352log to ``${T}/log.do_``\ `task`, and can also log to standard output
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009353(stdout) with the right settings:
9354
9355- ``bb.plain(msg)``: Writes msg as is to the log while also
9356 logging to stdout.
9357
9358- ``bb.note(msg)``: Writes "NOTE: msg" to the log. Also logs to
9359 stdout if BitBake is called with "-v".
9360
9361- ``bb.debug(level, msg)``: Writes "DEBUG: msg" to the
9362 log. Also logs to stdout if the log level is greater than or equal to
9363 level. See the ":ref:`-D <bitbake:bitbake-user-manual/bitbake-user-manual-intro:usage and syntax>`" option
9364 in the BitBake User Manual for more information.
9365
9366- ``bb.warn(msg)``: Writes "WARNING: msg" to the log while also
9367 logging to stdout.
9368
9369- ``bb.error(msg)``: Writes "ERROR: msg" to the log while also
9370 logging to standard out (stdout).
9371
9372 .. note::
9373
9374 Calling this function does not cause the task to fail.
9375
9376- ``bb.fatal(``\ msg\ ``)``: This logging function is similar to
9377 ``bb.error(``\ msg\ ``)`` but also causes the calling task to fail.
9378
9379 .. note::
9380
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009381 ``bb.fatal()`` raises an exception, which means you do not need to put a
9382 "return" statement after the function.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009383
9384The same logging functions are also available in shell functions, under
9385the names ``bbplain``, ``bbnote``, ``bbdebug``, ``bbwarn``, ``bberror``,
9386and ``bbfatal``. The
9387:ref:`logging <ref-classes-logging>` class
9388implements these functions. See that class in the ``meta/classes``
9389folder of the :term:`Source Directory` for information.
9390
9391Logging With Python
9392~~~~~~~~~~~~~~~~~~~
9393
9394When creating recipes using Python and inserting code that handles build
9395logs, keep in mind the goal is to have informative logs while keeping
9396the console as "silent" as possible. Also, if you want status messages
9397in the log, use the "debug" loglevel.
9398
9399Following is an example written in Python. The code handles logging for
9400a function that determines the number of tasks needed to be run. See the
9401":ref:`ref-tasks-listtasks`"
Andrew Geisslerc926e172021-05-07 16:11:35 -05009402section for additional information::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009403
9404 python do_listtasks() {
9405 bb.debug(2, "Starting to figure out the task list")
9406 if noteworthy_condition:
9407 bb.note("There are 47 tasks to run")
9408 bb.debug(2, "Got to point xyz")
9409 if warning_trigger:
9410 bb.warn("Detected warning_trigger, this might be a problem later.")
9411 if recoverable_error:
9412 bb.error("Hit recoverable_error, you really need to fix this!")
9413 if fatal_error:
9414 bb.fatal("fatal_error detected, unable to print the task list")
9415 bb.plain("The tasks present are abc")
9416 bb.debug(2, "Finished figuring out the tasklist")
9417 }
9418
9419Logging With Bash
9420~~~~~~~~~~~~~~~~~
9421
9422When creating recipes using Bash and inserting code that handles build
9423logs, you have the same goals - informative with minimal console output.
9424The syntax you use for recipes written in Bash is similar to that of
9425recipes written in Python described in the previous section.
9426
9427Following is an example written in Bash. The code logs the progress of
9428the ``do_my_function`` function.
9429::
9430
9431 do_my_function() {
9432 bbdebug 2 "Running do_my_function"
9433 if [ exceptional_condition ]; then
9434 bbnote "Hit exceptional_condition"
9435 fi
9436 bbdebug 2 "Got to point xyz"
9437 if [ warning_trigger ]; then
9438 bbwarn "Detected warning_trigger, this might cause a problem later."
9439 fi
9440 if [ recoverable_error ]; then
9441 bberror "Hit recoverable_error, correcting"
9442 fi
9443 if [ fatal_error ]; then
9444 bbfatal "fatal_error detected"
9445 fi
9446 bbdebug 2 "Completed do_my_function"
9447 }
9448
9449
9450Debugging Parallel Make Races
9451-----------------------------
9452
9453A parallel ``make`` race occurs when the build consists of several parts
9454that are run simultaneously and a situation occurs when the output or
9455result of one part is not ready for use with a different part of the
9456build that depends on that output. Parallel make races are annoying and
9457can sometimes be difficult to reproduce and fix. However, some simple
9458tips and tricks exist that can help you debug and fix them. This section
9459presents a real-world example of an error encountered on the Yocto
9460Project autobuilder and the process used to fix it.
9461
9462.. note::
9463
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009464 If you cannot properly fix a ``make`` race condition, you can work around it
9465 by clearing either the :term:`PARALLEL_MAKE` or :term:`PARALLEL_MAKEINST`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009466 variables.
9467
9468The Failure
9469~~~~~~~~~~~
9470
9471For this example, assume that you are building an image that depends on
9472the "neard" package. And, during the build, BitBake runs into problems
9473and creates the following output.
9474
9475.. note::
9476
9477 This example log file has longer lines artificially broken to make
9478 the listing easier to read.
9479
9480If you examine the output or the log file, you see the failure during
9481``make``:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009482
9483.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009484
9485 | DEBUG: SITE files ['endian-little', 'bit-32', 'ix86-common', 'common-linux', 'common-glibc', 'i586-linux', 'common']
9486 | DEBUG: Executing shell function do_compile
9487 | NOTE: make -j 16
9488 | make --no-print-directory all-am
9489 | /bin/mkdir -p include/near
9490 | /bin/mkdir -p include/near
9491 | /bin/mkdir -p include/near
9492 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9493 0.14-r0/neard-0.14/include/types.h include/near/types.h
9494 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9495 0.14-r0/neard-0.14/include/log.h include/near/log.h
9496 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9497 0.14-r0/neard-0.14/include/plugin.h include/near/plugin.h
9498 | /bin/mkdir -p include/near
9499 | /bin/mkdir -p include/near
9500 | /bin/mkdir -p include/near
9501 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9502 0.14-r0/neard-0.14/include/tag.h include/near/tag.h
9503 | /bin/mkdir -p include/near
9504 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9505 0.14-r0/neard-0.14/include/adapter.h include/near/adapter.h
9506 | /bin/mkdir -p include/near
9507 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9508 0.14-r0/neard-0.14/include/ndef.h include/near/ndef.h
9509 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9510 0.14-r0/neard-0.14/include/tlv.h include/near/tlv.h
9511 | /bin/mkdir -p include/near
9512 | /bin/mkdir -p include/near
9513 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9514 0.14-r0/neard-0.14/include/setting.h include/near/setting.h
9515 | /bin/mkdir -p include/near
9516 | /bin/mkdir -p include/near
9517 | /bin/mkdir -p include/near
9518 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9519 0.14-r0/neard-0.14/include/device.h include/near/device.h
9520 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9521 0.14-r0/neard-0.14/include/nfc_copy.h include/near/nfc_copy.h
9522 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9523 0.14-r0/neard-0.14/include/snep.h include/near/snep.h
9524 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9525 0.14-r0/neard-0.14/include/version.h include/near/version.h
9526 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9527 0.14-r0/neard-0.14/include/dbus.h include/near/dbus.h
9528 | ./src/genbuiltin nfctype1 nfctype2 nfctype3 nfctype4 p2p > src/builtin.h
9529 | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/
9530 build/build/tmp/sysroots/qemux86 -DHAVE_CONFIG_H -I. -I./include -I./src -I./gdbus -I/home/pokybuild/
9531 yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/glib-2.0
9532 -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/
9533 lib/glib-2.0/include -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/
9534 tmp/sysroots/qemux86/usr/include/dbus-1.0 -I/home/pokybuild/yocto-autobuilder/yocto-slave/
9535 nightly-x86/build/build/tmp/sysroots/qemux86/usr/lib/dbus-1.0/include -I/home/pokybuild/yocto-autobuilder/
9536 yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/libnl3
9537 -DNEAR_PLUGIN_BUILTIN -DPLUGINDIR=\""/usr/lib/near/plugins"\"
9538 -DCONFIGDIR=\""/etc/neard\"" -O2 -pipe -g -feliminate-unused-debug-types -c
9539 -o tools/snep-send.o tools/snep-send.c
9540 | In file included from tools/snep-send.c:16:0:
9541 | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
9542 | #include <near/dbus.h>
9543 | ^
9544 | compilation terminated.
9545 | make[1]: *** [tools/snep-send.o] Error 1
9546 | make[1]: *** Waiting for unfinished jobs....
9547 | make: *** [all] Error 2
9548 | ERROR: oe_runmake failed
9549
9550Reproducing the Error
9551~~~~~~~~~~~~~~~~~~~~~
9552
9553Because race conditions are intermittent, they do not manifest
9554themselves every time you do the build. In fact, most times the build
9555will complete without problems even though the potential race condition
9556exists. Thus, once the error surfaces, you need a way to reproduce it.
9557
9558In this example, compiling the "neard" package is causing the problem.
9559So the first thing to do is build "neard" locally. Before you start the
9560build, set the
9561:term:`PARALLEL_MAKE` variable
9562in your ``local.conf`` file to a high number (e.g. "-j 20"). Using a
9563high value for ``PARALLEL_MAKE`` increases the chances of the race
Andrew Geisslerc926e172021-05-07 16:11:35 -05009564condition showing up::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009565
9566 $ bitbake neard
9567
Andrew Geisslerc926e172021-05-07 16:11:35 -05009568Once the local build for "neard" completes, start a ``devshell`` build::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009569
9570 $ bitbake neard -c devshell
9571
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009572For information on how to use a ``devshell``, see the
9573":ref:`dev-manual/common-tasks:using a development shell`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009574
Andrew Geisslerc926e172021-05-07 16:11:35 -05009575In the ``devshell``, do the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009576
9577 $ make clean
9578 $ make tools/snep-send.o
9579
9580The ``devshell`` commands cause the failure to clearly
9581be visible. In this case, a missing dependency exists for the "neard"
9582Makefile target. Here is some abbreviated, sample output with the
Andrew Geisslerc926e172021-05-07 16:11:35 -05009583missing dependency clearly visible at the end::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009584
9585 i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/scott-lenovo/......
9586 .
9587 .
9588 .
9589 tools/snep-send.c
9590 In file included from tools/snep-send.c:16:0:
9591 tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
9592 #include <near/dbus.h>
9593 ^
9594 compilation terminated.
9595 make: *** [tools/snep-send.o] Error 1
9596 $
9597
9598
9599Creating a Patch for the Fix
9600~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9601
9602Because there is a missing dependency for the Makefile target, you need
9603to patch the ``Makefile.am`` file, which is generated from
Andrew Geisslerc926e172021-05-07 16:11:35 -05009604``Makefile.in``. You can use Quilt to create the patch::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009605
9606 $ quilt new parallelmake.patch
9607 Patch patches/parallelmake.patch is now on top
9608 $ quilt add Makefile.am
9609 File Makefile.am added to patch patches/parallelmake.patch
9610
9611For more information on using Quilt, see the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009612":ref:`dev-manual/common-tasks:using quilt in your workflow`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009613
9614At this point you need to make the edits to ``Makefile.am`` to add the
9615missing dependency. For our example, you have to add the following line
Andrew Geisslerc926e172021-05-07 16:11:35 -05009616to the file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009617
9618 tools/snep-send.$(OBJEXT): include/near/dbus.h
9619
9620Once you have edited the file, use the ``refresh`` command to create the
Andrew Geisslerc926e172021-05-07 16:11:35 -05009621patch::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009622
9623 $ quilt refresh
9624 Refreshed patch patches/parallelmake.patch
9625
9626Once
9627the patch file exists, you need to add it back to the originating recipe
9628folder. Here is an example assuming a top-level
Andrew Geisslerc926e172021-05-07 16:11:35 -05009629:term:`Source Directory` named ``poky``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009630
9631 $ cp patches/parallelmake.patch poky/meta/recipes-connectivity/neard/neard
9632
9633The final thing you need to do to implement the fix in the build is to
9634update the "neard" recipe (i.e. ``neard-0.14.bb``) so that the
9635:term:`SRC_URI` statement includes
9636the patch file. The recipe file is in the folder above the patch. Here
Andrew Geisslerc926e172021-05-07 16:11:35 -05009637is what the edited ``SRC_URI`` statement would look like::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009638
9639 SRC_URI = "${KERNELORG_MIRROR}/linux/network/nfc/${BPN}-${PV}.tar.xz \
9640 file://neard.in \
9641 file://neard.service.in \
9642 file://parallelmake.patch \
9643 "
9644
9645With the patch complete and moved to the correct folder and the
Andrew Geisslerc926e172021-05-07 16:11:35 -05009646``SRC_URI`` statement updated, you can exit the ``devshell``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009647
9648 $ exit
9649
9650Testing the Build
9651~~~~~~~~~~~~~~~~~
9652
9653With everything in place, you can get back to trying the build again
Andrew Geisslerc926e172021-05-07 16:11:35 -05009654locally::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009655
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009656 $ bitbake neard
9657
9658This build should succeed.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009659
9660Now you can open up a ``devshell`` again and repeat the clean and make
Andrew Geisslerc926e172021-05-07 16:11:35 -05009661operations as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009662
9663 $ bitbake neard -c devshell
9664 $ make clean
9665 $ make tools/snep-send.o
9666
9667The build should work without issue.
9668
9669As with all solved problems, if they originated upstream, you need to
9670submit the fix for the recipe in OE-Core and upstream so that the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009671problem is taken care of at its source. See the
9672":ref:`dev-manual/common-tasks:submitting a change to the yocto project`"
9673section for more information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009674
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009675Debugging With the GNU Project Debugger (GDB) Remotely
9676------------------------------------------------------
9677
9678GDB allows you to examine running programs, which in turn helps you to
9679understand and fix problems. It also allows you to perform post-mortem
9680style analysis of program crashes. GDB is available as a package within
9681the Yocto Project and is installed in SDK images by default. See the
Andrew Geissler09209ee2020-12-13 08:44:15 -06009682":ref:`ref-manual/images:Images`" chapter in the Yocto
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009683Project Reference Manual for a description of these images. You can find
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009684information on GDB at https://sourceware.org/gdb/.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009685
9686.. note::
9687
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009688 For best results, install debug (``-dbg``) packages for the applications you
9689 are going to debug. Doing so makes extra debug symbols available that give
9690 you more meaningful output.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009691
9692Sometimes, due to memory or disk space constraints, it is not possible
9693to use GDB directly on the remote target to debug applications. These
9694constraints arise because GDB needs to load the debugging information
9695and the binaries of the process being debugged. Additionally, GDB needs
9696to perform many computations to locate information such as function
9697names, variable names and values, stack traces and so forth - even
9698before starting the debugging process. These extra computations place
9699more load on the target system and can alter the characteristics of the
9700program being debugged.
9701
Andrew Geissler95ac1b82021-03-31 14:34:31 -05009702To help get past the previously mentioned constraints, there are two
9703methods you can use: running a debuginfod server and using gdbserver.
9704
9705Using the debuginfod server method
9706~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9707
Andrew Geisslerc926e172021-05-07 16:11:35 -05009708``debuginfod`` from ``elfutils`` is a way to distribute ``debuginfo`` files.
9709Running a ``debuginfod`` server makes debug symbols readily available,
Andrew Geissler95ac1b82021-03-31 14:34:31 -05009710which means you don't need to download debugging information
9711and the binaries of the process being debugged. You can just fetch
9712debug symbols from the server.
9713
Andrew Geisslerc926e172021-05-07 16:11:35 -05009714To run a ``debuginfod`` server, you need to do the following:
Andrew Geissler95ac1b82021-03-31 14:34:31 -05009715
Andrew Geisslerc926e172021-05-07 16:11:35 -05009716- Ensure that ``debuginfod`` is present in :term:`DISTRO_FEATURES`
9717 (it already is in ``OpenEmbedded-core`` defaults and ``poky`` reference distribution).
9718 If not, set in your distro config file or in ``local.conf``::
Andrew Geissler95ac1b82021-03-31 14:34:31 -05009719
Andrew Geisslerc926e172021-05-07 16:11:35 -05009720 DISTRO_FEATURES_append = " debuginfod"
Andrew Geissler95ac1b82021-03-31 14:34:31 -05009721
Andrew Geisslerc926e172021-05-07 16:11:35 -05009722 This distro feature enables the server and client library in ``elfutils``,
9723 and enables ``debuginfod`` support in clients (at the moment, ``gdb`` and ``binutils``).
Andrew Geissler95ac1b82021-03-31 14:34:31 -05009724
Andrew Geisslerc926e172021-05-07 16:11:35 -05009725- Run the following commands to launch the ``debuginfod`` server on the host::
Andrew Geissler95ac1b82021-03-31 14:34:31 -05009726
9727 $ oe-debuginfod
9728
Andrew Geisslerc926e172021-05-07 16:11:35 -05009729- To use ``debuginfod`` on the target, you need to know the ip:port where
9730 ``debuginfod`` is listening on the host (port defaults to 8002), and export
9731 that into the shell environment, for example in ``qemu``::
Andrew Geissler95ac1b82021-03-31 14:34:31 -05009732
Andrew Geisslerc926e172021-05-07 16:11:35 -05009733 root@qemux86-64:~# export DEBUGINFOD_URLS="http://192.168.7.1:8002/"
Andrew Geissler95ac1b82021-03-31 14:34:31 -05009734
Andrew Geisslerc926e172021-05-07 16:11:35 -05009735- Then debug info fetching should simply work when running the target ``gdb``,
9736 ``readelf`` or ``objdump``, for example::
Andrew Geissler95ac1b82021-03-31 14:34:31 -05009737
Andrew Geisslerc926e172021-05-07 16:11:35 -05009738 root@qemux86-64:~# gdb /bin/cat
9739 ...
9740 Reading symbols from /bin/cat...
9741 Downloading separate debug info for /bin/cat...
9742 Reading symbols from /home/root/.cache/debuginfod_client/923dc4780cfbc545850c616bffa884b6b5eaf322/debuginfo...
Andrew Geissler95ac1b82021-03-31 14:34:31 -05009743
Andrew Geisslerc926e172021-05-07 16:11:35 -05009744- It's also possible to use ``debuginfod-find`` to just query the server::
Andrew Geissler95ac1b82021-03-31 14:34:31 -05009745
Andrew Geisslerc926e172021-05-07 16:11:35 -05009746 root@qemux86-64:~# debuginfod-find debuginfo /bin/ls
9747 /home/root/.cache/debuginfod_client/356edc585f7f82d46f94fcb87a86a3fe2d2e60bd/debuginfo
Andrew Geissler95ac1b82021-03-31 14:34:31 -05009748
Andrew Geissler95ac1b82021-03-31 14:34:31 -05009749
9750Using the gdbserver method
9751~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9752
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009753gdbserver, which runs on the remote target and does not load any
9754debugging information from the debugged process. Instead, a GDB instance
9755processes the debugging information that is run on a remote computer -
9756the host GDB. The host GDB then sends control commands to gdbserver to
9757make it stop or start the debugged program, as well as read or write
9758memory regions of that debugged program. All the debugging information
9759loaded and processed as well as all the heavy debugging is done by the
9760host GDB. Offloading these processes gives the gdbserver running on the
9761target a chance to remain small and fast.
9762
9763Because the host GDB is responsible for loading the debugging
9764information and for doing the necessary processing to make actual
9765debugging happen, you have to make sure the host can access the
9766unstripped binaries complete with their debugging information and also
9767be sure the target is compiled with no optimizations. The host GDB must
9768also have local access to all the libraries used by the debugged
9769program. Because gdbserver does not need any local debugging
9770information, the binaries on the remote target can remain stripped.
9771However, the binaries must also be compiled without optimization so they
9772match the host's binaries.
9773
9774To remain consistent with GDB documentation and terminology, the binary
9775being debugged on the remote target machine is referred to as the
9776"inferior" binary. For documentation on GDB see the `GDB
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009777site <https://sourceware.org/gdb/documentation/>`__.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009778
9779The following steps show you how to debug using the GNU project
9780debugger.
9781
97821. *Configure your build system to construct the companion debug
9783 filesystem:*
9784
Andrew Geisslerc926e172021-05-07 16:11:35 -05009785 In your ``local.conf`` file, set the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009786
9787 IMAGE_GEN_DEBUGFS = "1"
9788 IMAGE_FSTYPES_DEBUGFS = "tar.bz2"
9789
9790 These options cause the
9791 OpenEmbedded build system to generate a special companion filesystem
9792 fragment, which contains the matching source and debug symbols to
9793 your deployable filesystem. The build system does this by looking at
9794 what is in the deployed filesystem, and pulling the corresponding
9795 ``-dbg`` packages.
9796
9797 The companion debug filesystem is not a complete filesystem, but only
9798 contains the debug fragments. This filesystem must be combined with
9799 the full filesystem for debugging. Subsequent steps in this procedure
9800 show how to combine the partial filesystem with the full filesystem.
9801
98022. *Configure the system to include gdbserver in the target filesystem:*
9803
9804 Make the following addition in either your ``local.conf`` file or in
Andrew Geisslerc926e172021-05-07 16:11:35 -05009805 an image recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009806
9807 IMAGE_INSTALL_append = " gdbserver"
9808
9809 The change makes
9810 sure the ``gdbserver`` package is included.
9811
98123. *Build the environment:*
9813
9814 Use the following command to construct the image and the companion
Andrew Geisslerc926e172021-05-07 16:11:35 -05009815 Debug Filesystem::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009816
9817 $ bitbake image
9818
9819 Build the cross GDB component and
9820 make it available for debugging. Build the SDK that matches the
9821 image. Building the SDK is best for a production build that can be
Andrew Geisslerc926e172021-05-07 16:11:35 -05009822 used later for debugging, especially during long term maintenance::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009823
9824 $ bitbake -c populate_sdk image
9825
9826 Alternatively, you can build the minimal toolchain components that
9827 match the target. Doing so creates a smaller than typical SDK and
9828 only contains a minimal set of components with which to build simple
Andrew Geisslerc926e172021-05-07 16:11:35 -05009829 test applications, as well as run the debugger::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009830
9831 $ bitbake meta-toolchain
9832
Andrew Geisslerc926e172021-05-07 16:11:35 -05009833 A final method is to build Gdb itself within the build system::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009834
9835 $ bitbake gdb-cross-<architecture>
9836
9837 Doing so produces a temporary copy of
9838 ``cross-gdb`` you can use for debugging during development. While
9839 this is the quickest approach, the two previous methods in this step
9840 are better when considering long-term maintenance strategies.
9841
9842 .. note::
9843
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009844 If you run ``bitbake gdb-cross``, the OpenEmbedded build system suggests
9845 the actual image (e.g. ``gdb-cross-i586``). The suggestion is usually the
9846 actual name you want to use.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009847
Andrew Geissler4c19ea12020-10-27 13:52:24 -050098484. *Set up the* ``debugfs``\ *:*
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009849
Andrew Geisslerc926e172021-05-07 16:11:35 -05009850 Run the following commands to set up the ``debugfs``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009851
9852 $ mkdir debugfs
9853 $ cd debugfs
9854 $ tar xvfj build-dir/tmp-glibc/deploy/images/machine/image.rootfs.tar.bz2
9855 $ tar xvfj build-dir/tmp-glibc/deploy/images/machine/image-dbg.rootfs.tar.bz2
9856
Andrew Geissler4c19ea12020-10-27 13:52:24 -050098575. *Set up GDB:*
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009858
9859 Install the SDK (if you built one) and then source the correct
9860 environment file. Sourcing the environment file puts the SDK in your
9861 ``PATH`` environment variable.
9862
9863 If you are using the build system, Gdb is located in
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009864 `build-dir`\ ``/tmp/sysroots/``\ `host`\ ``/usr/bin/``\ `architecture`\ ``/``\ `architecture`\ ``-gdb``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009865
98666. *Boot the target:*
9867
9868 For information on how to run QEMU, see the `QEMU
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009869 Documentation <https://wiki.qemu.org/Documentation/GettingStartedDevelopers>`__.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009870
9871 .. note::
9872
9873 Be sure to verify that your host can access the target via TCP.
9874
98757. *Debug a program:*
9876
9877 Debugging a program involves running gdbserver on the target and then
9878 running Gdb on the host. The example in this step debugs ``gzip``:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009879
9880 .. code-block:: shell
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009881
9882 root@qemux86:~# gdbserver localhost:1234 /bin/gzip —help
9883
9884 For
9885 additional gdbserver options, see the `GDB Server
9886 Documentation <https://www.gnu.org/software/gdb/documentation/>`__.
9887
9888 After running gdbserver on the target, you need to run Gdb on the
Andrew Geisslerc926e172021-05-07 16:11:35 -05009889 host and configure it and connect to the target. Use these commands::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009890
9891 $ cd directory-holding-the-debugfs-directory
9892 $ arch-gdb
9893 (gdb) set sysroot debugfs
9894 (gdb) set substitute-path /usr/src/debug debugfs/usr/src/debug
9895 (gdb) target remote IP-of-target:1234
9896
9897 At this
9898 point, everything should automatically load (i.e. matching binaries,
9899 symbols and headers).
9900
9901 .. note::
9902
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009903 The Gdb ``set`` commands in the previous example can be placed into the
9904 users ``~/.gdbinit`` file. Upon starting, Gdb automatically runs whatever
9905 commands are in that file.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009906
99078. *Deploying without a full image rebuild:*
9908
9909 In many cases, during development you want a quick method to deploy a
9910 new binary to the target and debug it, without waiting for a full
9911 image build.
9912
9913 One approach to solving this situation is to just build the component
9914 you want to debug. Once you have built the component, copy the
9915 executable directly to both the target and the host ``debugfs``.
9916
9917 If the binary is processed through the debug splitting in
9918 OpenEmbedded, you should also copy the debug items (i.e. ``.debug``
9919 contents and corresponding ``/usr/src/debug`` files) from the work
Andrew Geisslerc926e172021-05-07 16:11:35 -05009920 directory. Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009921
9922 $ bitbake bash
9923 $ bitbake -c devshell bash
9924 $ cd ..
9925 $ scp packages-split/bash/bin/bash target:/bin/bash
9926 $ cp -a packages-split/bash-dbg/\* path/debugfs
9927
9928Debugging with the GNU Project Debugger (GDB) on the Target
9929-----------------------------------------------------------
9930
9931The previous section addressed using GDB remotely for debugging
9932purposes, which is the most usual case due to the inherent hardware
9933limitations on many embedded devices. However, debugging in the target
9934hardware itself is also possible with more powerful devices. This
9935section describes what you need to do in order to support using GDB to
9936debug on the target hardware.
9937
9938To support this kind of debugging, you need do the following:
9939
9940- Ensure that GDB is on the target. You can do this by adding "gdb" to
Andrew Geisslerc926e172021-05-07 16:11:35 -05009941 :term:`IMAGE_INSTALL`::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009942
9943 IMAGE_INSTALL_append = " gdb"
9944
Andrew Geisslerc926e172021-05-07 16:11:35 -05009945 Alternatively, you can add "tools-debug" to :term:`IMAGE_FEATURES`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009946
9947 IMAGE_FEATURES_append = " tools-debug"
9948
9949- Ensure that debug symbols are present. You can make sure these
Andrew Geisslerc926e172021-05-07 16:11:35 -05009950 symbols are present by installing ``-dbg``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009951
9952 IMAGE_INSTALL_append = "packagename-dbg"
9953
9954 Alternatively, you can do the following to include
Andrew Geisslerc926e172021-05-07 16:11:35 -05009955 all the debug symbols::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009956
9957 IMAGE_FEATURES_append = " dbg-pkgs"
9958
9959.. note::
9960
9961 To improve the debug information accuracy, you can reduce the level
9962 of optimization used by the compiler. For example, when adding the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009963 following line to your ``local.conf`` file, you will reduce optimization
9964 from :term:`FULL_OPTIMIZATION` of "-O2" to :term:`DEBUG_OPTIMIZATION`
Andrew Geisslerc926e172021-05-07 16:11:35 -05009965 of "-O -fno-omit-frame-pointer"::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009966
9967 DEBUG_BUILD = "1"
9968
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009969 Consider that this will reduce the application's performance and is
9970 recommended only for debugging purposes.
9971
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009972Other Debugging Tips
9973--------------------
9974
9975Here are some other tips that you might find useful:
9976
9977- When adding new packages, it is worth watching for undesirable items
9978 making their way into compiler command lines. For example, you do not
9979 want references to local system files like ``/usr/lib/`` or
9980 ``/usr/include/``.
9981
9982- If you want to remove the ``psplash`` boot splashscreen, add
9983 ``psplash=false`` to the kernel command line. Doing so prevents
9984 ``psplash`` from loading and thus allows you to see the console. It
9985 is also possible to switch out of the splashscreen by switching the
9986 virtual console (e.g. Fn+Left or Fn+Right on a Zaurus).
9987
9988- Removing :term:`TMPDIR` (usually
9989 ``tmp/``, within the
9990 :term:`Build Directory`) can often fix
9991 temporary build issues. Removing ``TMPDIR`` is usually a relatively
9992 cheap operation, because task output will be cached in
9993 :term:`SSTATE_DIR` (usually
9994 ``sstate-cache/``, which is also in the Build Directory).
9995
9996 .. note::
9997
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009998 Removing ``TMPDIR`` might be a workaround rather than a fix.
9999 Consequently, trying to determine the underlying cause of an issue before
10000 removing the directory is a good idea.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010001
10002- Understanding how a feature is used in practice within existing
10003 recipes can be very helpful. It is recommended that you configure
10004 some method that allows you to quickly search through files.
10005
10006 Using GNU Grep, you can use the following shell function to
10007 recursively search through common recipe-related files, skipping
10008 binary files, ``.git`` directories, and the Build Directory (assuming
Andrew Geisslerc926e172021-05-07 16:11:35 -050010009 its name starts with "build")::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010010
10011 g() {
10012 grep -Ir \
10013 --exclude-dir=.git \
10014 --exclude-dir='build*' \
10015 --include='*.bb*' \
10016 --include='*.inc*' \
10017 --include='*.conf*' \
10018 --include='*.py*' \
10019 "$@"
10020 }
10021
Andrew Geisslerc926e172021-05-07 16:11:35 -050010022 Following are some usage examples::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010023
10024 $ g FOO # Search recursively for "FOO"
10025 $ g -i foo # Search recursively for "foo", ignoring case
10026 $ g -w FOO # Search recursively for "FOO" as a word, ignoring e.g. "FOOBAR"
10027
10028 If figuring
10029 out how some feature works requires a lot of searching, it might
10030 indicate that the documentation should be extended or improved. In
10031 such cases, consider filing a documentation bug using the Yocto
10032 Project implementation of
10033 :yocto_bugs:`Bugzilla <>`. For information on
10034 how to submit a bug against the Yocto Project, see the Yocto Project
Andrew Geissler09209ee2020-12-13 08:44:15 -060010035 Bugzilla :yocto_wiki:`wiki page </Bugzilla_Configuration_and_Bug_Tracking>`
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050010036 and the
10037 ":ref:`dev-manual/common-tasks:submitting a defect against the yocto project`"
10038 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010039
10040 .. note::
10041
10042 The manuals might not be the right place to document variables
10043 that are purely internal and have a limited scope (e.g. internal
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010044 variables used to implement a single ``.bbclass`` file).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010045
10046Making Changes to the Yocto Project
10047===================================
10048
10049Because the Yocto Project is an open-source, community-based project,
10050you can effect changes to the project. This section presents procedures
10051that show you how to submit a defect against the project and how to
10052submit a change.
10053
10054Submitting a Defect Against the Yocto Project
10055---------------------------------------------
10056
10057Use the Yocto Project implementation of
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010058`Bugzilla <https://www.bugzilla.org/about/>`__ to submit a defect (bug)
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010059against the Yocto Project. For additional information on this
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010060implementation of Bugzilla see the ":ref:`Yocto Project
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010061Bugzilla <resources-bugtracker>`" section in the
10062Yocto Project Reference Manual. For more detail on any of the following
10063steps, see the Yocto Project
Andrew Geissler09209ee2020-12-13 08:44:15 -060010064:yocto_wiki:`Bugzilla wiki page </Bugzilla_Configuration_and_Bug_Tracking>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010065
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010066Use the following general steps to submit a bug:
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010067
100681. Open the Yocto Project implementation of :yocto_bugs:`Bugzilla <>`.
10069
100702. Click "File a Bug" to enter a new bug.
10071
100723. Choose the appropriate "Classification", "Product", and "Component"
10073 for which the bug was found. Bugs for the Yocto Project fall into
10074 one of several classifications, which in turn break down into
10075 several products and components. For example, for a bug against the
10076 ``meta-intel`` layer, you would choose "Build System, Metadata &
10077 Runtime", "BSPs", and "bsps-meta-intel", respectively.
10078
100794. Choose the "Version" of the Yocto Project for which you found the
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010080 bug (e.g. &DISTRO;).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010081
100825. Determine and select the "Severity" of the bug. The severity
10083 indicates how the bug impacted your work.
10084
100856. Choose the "Hardware" that the bug impacts.
10086
100877. Choose the "Architecture" that the bug impacts.
10088
100898. Choose a "Documentation change" item for the bug. Fixing a bug might
10090 or might not affect the Yocto Project documentation. If you are
10091 unsure of the impact to the documentation, select "Don't Know".
10092
100939. Provide a brief "Summary" of the bug. Try to limit your summary to
10094 just a line or two and be sure to capture the essence of the bug.
10095
1009610. Provide a detailed "Description" of the bug. You should provide as
10097 much detail as you can about the context, behavior, output, and so
10098 forth that surrounds the bug. You can even attach supporting files
10099 for output from logs by using the "Add an attachment" button.
10100
1010111. Click the "Submit Bug" button submit the bug. A new Bugzilla number
10102 is assigned to the bug and the defect is logged in the bug tracking
10103 system.
10104
10105Once you file a bug, the bug is processed by the Yocto Project Bug
10106Triage Team and further details concerning the bug are assigned (e.g.
10107priority and owner). You are the "Submitter" of the bug and any further
10108categorization, progress, or comments on the bug result in Bugzilla
10109sending you an automated email concerning the particular change or
10110progress to the bug.
10111
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010112Submitting a Change to the Yocto Project
10113----------------------------------------
10114
10115Contributions to the Yocto Project and OpenEmbedded are very welcome.
10116Because the system is extremely configurable and flexible, we recognize
10117that developers will want to extend, configure or optimize it for their
10118specific uses.
10119
10120The Yocto Project uses a mailing list and a patch-based workflow that is
10121similar to the Linux kernel but contains important differences. In
10122general, a mailing list exists through which you can submit patches. You
10123should send patches to the appropriate mailing list so that they can be
10124reviewed and merged by the appropriate maintainer. The specific mailing
10125list you need to use depends on the location of the code you are
10126changing. Each component (e.g. layer) should have a ``README`` file that
10127indicates where to send the changes and which process to follow.
10128
10129You can send the patch to the mailing list using whichever approach you
10130feel comfortable with to generate the patch. Once sent, the patch is
10131usually reviewed by the community at large. If somebody has concerns
10132with the patch, they will usually voice their concern over the mailing
10133list. If a patch does not receive any negative reviews, the maintainer
10134of the affected layer typically takes the patch, tests it, and then
10135based on successful testing, merges the patch.
10136
10137The "poky" repository, which is the Yocto Project's reference build
10138environment, is a hybrid repository that contains several individual
10139pieces (e.g. BitBake, Metadata, documentation, and so forth) built using
10140the combo-layer tool. The upstream location used for submitting changes
10141varies by component:
10142
10143- *Core Metadata:* Send your patch to the
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010144 :oe_lists:`openembedded-core </g/openembedded-core>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010145 mailing list. For example, a change to anything under the ``meta`` or
10146 ``scripts`` directories should be sent to this mailing list.
10147
10148- *BitBake:* For changes to BitBake (i.e. anything under the
10149 ``bitbake`` directory), send your patch to the
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010150 :oe_lists:`bitbake-devel </g/bitbake-devel>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010151 mailing list.
10152
Andrew Geisslerc3d88e42020-10-02 09:45:00 -050010153- *"meta-\*" trees:* These trees contain Metadata. Use the
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010154 :yocto_lists:`poky </g/poky>` mailing list.
Andrew Geisslerc3d88e42020-10-02 09:45:00 -050010155
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010156- *Documentation*: For changes to the Yocto Project documentation, use the
10157 :yocto_lists:`docs </g/docs>` mailing list.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010158
10159For changes to other layers hosted in the Yocto Project source
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010160repositories (i.e. ``yoctoproject.org``) and tools use the
10161:yocto_lists:`Yocto Project </g/yocto/>` general mailing list.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010162
10163.. note::
10164
10165 Sometimes a layer's documentation specifies to use a particular
10166 mailing list. If so, use that list.
10167
10168For additional recipes that do not fit into the core Metadata, you
10169should determine which layer the recipe should go into and submit the
10170change in the manner recommended by the documentation (e.g. the
10171``README`` file) supplied with the layer. If in doubt, please ask on the
10172Yocto general mailing list or on the openembedded-devel mailing list.
10173
10174You can also push a change upstream and request a maintainer to pull the
10175change into the component's upstream repository. You do this by pushing
Andrew Geissler09209ee2020-12-13 08:44:15 -060010176to a contribution repository that is upstream. See the
10177":ref:`overview-manual/development-environment:git workflows and the yocto project`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010178section in the Yocto Project Overview and Concepts Manual for additional
10179concepts on working in the Yocto Project development environment.
10180
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010181Maintainers commonly use ``-next`` branches to test submissions prior to
10182merging patches. Thus, you can get an idea of the status of a patch based on
10183whether the patch has been merged into one of these branches. The commonly
10184used testing branches for OpenEmbedded-Core are as follows:
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010185
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010186- *openembedded-core "master-next" branch:* This branch is part of the
10187 :oe_git:`openembedded-core </openembedded-core/>` repository and contains
10188 proposed changes to the core metadata.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010189
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010190- *poky "master-next" branch:* This branch is part of the
Andrew Geissler09209ee2020-12-13 08:44:15 -060010191 :yocto_git:`poky </poky/>` repository and combines proposed
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010192 changes to bitbake, the core metadata and the poky distro.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010193
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010194Similarly, stable branches maintained by the project may have corresponding
10195``-next`` branches which collect proposed changes. For example,
10196``&DISTRO_NAME_NO_CAP;-next`` and ``&DISTRO_NAME_NO_CAP_MINUS_ONE;-next``
10197branches in both the "openembdedded-core" and "poky" repositories.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010198
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010199Other layers may have similar testing branches but there is no formal
10200requirement or standard for these so please check the documentation for the
10201layers you are contributing to.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010202
10203The following sections provide procedures for submitting a change.
10204
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010205Preparing Changes for Submission
10206~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010207
102081. *Make Your Changes Locally:* Make your changes in your local Git
10209 repository. You should make small, controlled, isolated changes.
10210 Keeping changes small and isolated aids review, makes
10211 merging/rebasing easier and keeps the change history clean should
10212 anyone need to refer to it in future.
10213
102142. *Stage Your Changes:* Stage your changes by using the ``git add``
10215 command on each file you changed.
10216
102173. *Commit Your Changes:* Commit the change by using the ``git commit``
10218 command. Make sure your commit information follows standards by
10219 following these accepted conventions:
10220
10221 - Be sure to include a "Signed-off-by:" line in the same style as
10222 required by the Linux kernel. Adding this line signifies that you,
10223 the submitter, have agreed to the Developer's Certificate of
10224 Origin 1.1 as follows:
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010225
10226 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010227
10228 Developer's Certificate of Origin 1.1
10229
10230 By making a contribution to this project, I certify that:
10231
10232 (a) The contribution was created in whole or in part by me and I
10233 have the right to submit it under the open source license
10234 indicated in the file; or
10235
10236 (b) The contribution is based upon previous work that, to the best
10237 of my knowledge, is covered under an appropriate open source
10238 license and I have the right under that license to submit that
10239 work with modifications, whether created in whole or in part
10240 by me, under the same open source license (unless I am
10241 permitted to submit under a different license), as indicated
10242 in the file; or
10243
10244 (c) The contribution was provided directly to me by some other
10245 person who certified (a), (b) or (c) and I have not modified
10246 it.
10247
10248 (d) I understand and agree that this project and the contribution
10249 are public and that a record of the contribution (including all
10250 personal information I submit with it, including my sign-off) is
10251 maintained indefinitely and may be redistributed consistent with
10252 this project or the open source license(s) involved.
10253
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010254 - Provide a single-line summary of the change and, if more
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010255 explanation is needed, provide more detail in the body of the
10256 commit. This summary is typically viewable in the "shortlist" of
10257 changes. Thus, providing something short and descriptive that
10258 gives the reader a summary of the change is useful when viewing a
10259 list of many commits. You should prefix this short description
10260 with the recipe name (if changing a recipe), or else with the
10261 short form path to the file being changed.
10262
10263 - For the body of the commit message, provide detailed information
10264 that describes what you changed, why you made the change, and the
10265 approach you used. It might also be helpful if you mention how you
10266 tested the change. Provide as much detail as you can in the body
10267 of the commit message.
10268
10269 .. note::
10270
10271 You do not need to provide a more detailed explanation of a
10272 change if the change is minor to the point of the single line
10273 summary providing all the information.
10274
10275 - If the change addresses a specific bug or issue that is associated
10276 with a bug-tracking ID, include a reference to that ID in your
10277 detailed description. For example, the Yocto Project uses a
10278 specific convention for bug references - any commit that addresses
10279 a specific bug should use the following form for the detailed
10280 description. Be sure to use the actual bug-tracking ID from
Andrew Geisslerc926e172021-05-07 16:11:35 -050010281 Bugzilla for bug-id::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010282
10283 Fixes [YOCTO #bug-id]
10284
10285 detailed description of change
10286
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010287Using Email to Submit a Patch
10288~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10289
10290Depending on the components changed, you need to submit the email to a
10291specific mailing list. For some guidance on which mailing list to use,
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050010292see the
10293:ref:`list <dev-manual/common-tasks:submitting a change to the yocto project>`
10294at the beginning of this section. For a description of all the available
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010295mailing lists, see the ":ref:`Mailing Lists <resources-mailinglist>`" section in the
10296Yocto Project Reference Manual.
10297
10298Here is the general procedure on how to submit a patch through email
10299without using the scripts once the steps in
Andrew Geissler09209ee2020-12-13 08:44:15 -060010300:ref:`dev-manual/common-tasks:preparing changes for submission` have been followed:
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010301
103021. *Format the Commit:* Format the commit into an email message. To
10303 format commits, use the ``git format-patch`` command. When you
10304 provide the command, you must include a revision list or a number of
10305 patches as part of the command. For example, either of these two
10306 commands takes your most recent single commit and formats it as an
Andrew Geisslerc926e172021-05-07 16:11:35 -050010307 email message in the current directory::
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010308
10309 $ git format-patch -1
10310
10311 or ::
10312
10313 $ git format-patch HEAD~
10314
10315 After the command is run, the current directory contains a numbered
10316 ``.patch`` file for the commit.
10317
10318 If you provide several commits as part of the command, the
10319 ``git format-patch`` command produces a series of numbered files in
10320 the current directory – one for each commit. If you have more than
10321 one patch, you should also use the ``--cover`` option with the
10322 command, which generates a cover letter as the first "patch" in the
10323 series. You can then edit the cover letter to provide a description
10324 for the series of patches. For information on the
10325 ``git format-patch`` command, see ``GIT_FORMAT_PATCH(1)`` displayed
10326 using the ``man git-format-patch`` command.
10327
10328 .. note::
10329
10330 If you are or will be a frequent contributor to the Yocto Project
10331 or to OpenEmbedded, you might consider requesting a contrib area
10332 and the necessary associated rights.
10333
103342. *Send the patches via email:* Send the patches to the recipients and
10335 relevant mailing lists by using the ``git send-email`` command.
10336
10337 .. note::
10338
10339 In order to use ``git send-email``, you must have the proper Git packages
10340 installed on your host.
10341 For Ubuntu, Debian, and Fedora the package is ``git-email``.
10342
10343 The ``git send-email`` command sends email by using a local or remote
10344 Mail Transport Agent (MTA) such as ``msmtp``, ``sendmail``, or
10345 through a direct ``smtp`` configuration in your Git ``~/.gitconfig``
10346 file. If you are submitting patches through email only, it is very
10347 important that you submit them without any whitespace or HTML
10348 formatting that either you or your mailer introduces. The maintainer
10349 that receives your patches needs to be able to save and apply them
10350 directly from your emails. A good way to verify that what you are
10351 sending will be applicable by the maintainer is to do a dry run and
10352 send them to yourself and then save and apply them as the maintainer
10353 would.
10354
10355 The ``git send-email`` command is the preferred method for sending
10356 your patches using email since there is no risk of compromising
10357 whitespace in the body of the message, which can occur when you use
10358 your own mail client. The command also has several options that let
10359 you specify recipients and perform further editing of the email
10360 message. For information on how to use the ``git send-email``
10361 command, see ``GIT-SEND-EMAIL(1)`` displayed using the
10362 ``man git-send-email`` command.
10363
10364The Yocto Project uses a `Patchwork instance <https://patchwork.openembedded.org/>`__
10365to track the status of patches submitted to the various mailing lists and to
10366support automated patch testing. Each submitted patch is checked for common
10367mistakes and deviations from the expected patch format and submitters are
10368notified by patchtest if such mistakes are found. This process helps to
10369reduce the burden of patch review on maintainers.
10370
10371.. note::
10372
10373 This system is imperfect and changes can sometimes get lost in the flow.
10374 Asking about the status of a patch or change is reasonable if the change
10375 has been idle for a while with no feedback.
10376
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010377Using Scripts to Push a Change Upstream and Request a Pull
10378~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10379
10380For larger patch series it is preferable to send a pull request which not
10381only includes the patch but also a pointer to a branch that can be pulled
10382from. This involves making a local branch for your changes, pushing this
10383branch to an accessible repository and then using the ``create-pull-request``
10384and ``send-pull-request`` scripts from openembedded-core to create and send a
10385patch series with a link to the branch for review.
10386
10387Follow this procedure to push a change to an upstream "contrib" Git
Andrew Geissler09209ee2020-12-13 08:44:15 -060010388repository once the steps in :ref:`dev-manual/common-tasks:preparing changes for submission` have
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010389been followed:
10390
10391.. note::
10392
10393 You can find general Git information on how to push a change upstream
10394 in the
10395 `Git Community Book <https://git-scm.com/book/en/v2/Distributed-Git-Distributed-Workflows>`__.
10396
103971. *Push Your Commits to a "Contrib" Upstream:* If you have arranged for
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010398 permissions to push to an upstream contrib repository, push the
Andrew Geisslerc926e172021-05-07 16:11:35 -050010399 change to that repository::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010400
10401 $ git push upstream_remote_repo local_branch_name
10402
10403 For example, suppose you have permissions to push
10404 into the upstream ``meta-intel-contrib`` repository and you are
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010405 working in a local branch named `your_name`\ ``/README``. The following
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010406 command pushes your local commits to the ``meta-intel-contrib``
10407 upstream repository and puts the commit in a branch named
Andrew Geisslerc926e172021-05-07 16:11:35 -050010408 `your_name`\ ``/README``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010409
10410 $ git push meta-intel-contrib your_name/README
10411
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600104122. *Determine Who to Notify:* Determine the maintainer or the mailing
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010413 list that you need to notify for the change.
10414
10415 Before submitting any change, you need to be sure who the maintainer
10416 is or what mailing list that you need to notify. Use either these
10417 methods to find out:
10418
10419 - *Maintenance File:* Examine the ``maintainers.inc`` file, which is
10420 located in the :term:`Source Directory` at
10421 ``meta/conf/distro/include``, to see who is responsible for code.
10422
Andrew Geissler09209ee2020-12-13 08:44:15 -060010423 - *Search by File:* Using :ref:`overview-manual/development-environment:git`, you can
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010424 enter the following command to bring up a short list of all
Andrew Geisslerc926e172021-05-07 16:11:35 -050010425 commits against a specific file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010426
10427 git shortlog -- filename
10428
10429 Just provide the name of the file for which you are interested. The
10430 information returned is not ordered by history but does include a
10431 list of everyone who has committed grouped by name. From the list,
10432 you can see who is responsible for the bulk of the changes against
10433 the file.
10434
10435 - *Examine the List of Mailing Lists:* For a list of the Yocto
10436 Project and related mailing lists, see the ":ref:`Mailing
10437 lists <resources-mailinglist>`" section in
10438 the Yocto Project Reference Manual.
10439
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600104403. *Make a Pull Request:* Notify the maintainer or the mailing list that
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010441 you have pushed a change by making a pull request.
10442
10443 The Yocto Project provides two scripts that conveniently let you
10444 generate and send pull requests to the Yocto Project. These scripts
10445 are ``create-pull-request`` and ``send-pull-request``. You can find
10446 these scripts in the ``scripts`` directory within the
10447 :term:`Source Directory` (e.g.
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010448 ``poky/scripts``).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010449
10450 Using these scripts correctly formats the requests without
10451 introducing any whitespace or HTML formatting. The maintainer that
10452 receives your patches either directly or through the mailing list
10453 needs to be able to save and apply them directly from your emails.
10454 Using these scripts is the preferred method for sending patches.
10455
10456 First, create the pull request. For example, the following command
10457 runs the script, specifies the upstream repository in the contrib
10458 directory into which you pushed the change, and provides a subject
Andrew Geisslerc926e172021-05-07 16:11:35 -050010459 line in the created patch files::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010460
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010461 $ poky/scripts/create-pull-request -u meta-intel-contrib -s "Updated Manual Section Reference in README"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010462
10463 Running this script forms ``*.patch`` files in a folder named
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010464 ``pull-``\ `PID` in the current directory. One of the patch files is a
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010465 cover letter.
10466
10467 Before running the ``send-pull-request`` script, you must edit the
10468 cover letter patch to insert information about your change. After
10469 editing the cover letter, send the pull request. For example, the
10470 following command runs the script and specifies the patch directory
10471 and email address. In this example, the email address is a mailing
Andrew Geisslerc926e172021-05-07 16:11:35 -050010472 list::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010473
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010474 $ poky/scripts/send-pull-request -p ~/meta-intel/pull-10565 -t meta-intel@yoctoproject.org
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010475
10476 You need to follow the prompts as the script is interactive.
10477
10478 .. note::
10479
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010480 For help on using these scripts, simply provide the ``-h``
Andrew Geisslerc926e172021-05-07 16:11:35 -050010481 argument as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010482
10483 $ poky/scripts/create-pull-request -h
10484 $ poky/scripts/send-pull-request -h
10485
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010486Responding to Patch Review
10487~~~~~~~~~~~~~~~~~~~~~~~~~~
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010488
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010489You may get feedback on your submitted patches from other community members
10490or from the automated patchtest service. If issues are identified in your
10491patch then it is usually necessary to address these before the patch will be
10492accepted into the project. In this case you should amend the patch according
10493to the feedback and submit an updated version to the relevant mailing list,
10494copying in the reviewers who provided feedback to the previous version of the
10495patch.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010496
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010497The patch should be amended using ``git commit --amend`` or perhaps ``git
10498rebase`` for more expert git users. You should also modify the ``[PATCH]``
10499tag in the email subject line when sending the revised patch to mark the new
10500iteration as ``[PATCH v2]``, ``[PATCH v3]``, etc as appropriate. This can be
10501done by passing the ``-v`` argument to ``git format-patch`` with a version
10502number.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010503
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010504Lastly please ensure that you also test your revised changes. In particular
10505please don't just edit the patch file written out by ``git format-patch`` and
10506resend it.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010507
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010508Submitting Changes to Stable Release Branches
10509~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010510
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010511The process for proposing changes to a Yocto Project stable branch differs
10512from the steps described above. Changes to a stable branch must address
10513identified bugs or CVEs and should be made carefully in order to avoid the
10514risk of introducing new bugs or breaking backwards compatibility. Typically
10515bug fixes must already be accepted into the master branch before they can be
10516backported to a stable branch unless the bug in question does not affect the
10517master branch or the fix on the master branch is unsuitable for backporting.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010518
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010519The list of stable branches along with the status and maintainer for each
10520branch can be obtained from the
Andrew Geissler09209ee2020-12-13 08:44:15 -060010521:yocto_wiki:`Releases wiki page </Releases>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010522
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010523.. note::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010524
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010525 Changes will not typically be accepted for branches which are marked as
10526 End-Of-Life (EOL).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010527
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010528With this in mind, the steps to submit a change for a stable branch are as
10529follows:
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010530
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600105311. *Identify the bug or CVE to be fixed:* This information should be
10532 collected so that it can be included in your submission.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010533
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600105342. *Check if the fix is already present in the master branch:* This will
10535 result in the most straightforward path into the stable branch for the
10536 fix.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010537
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010538 a. *If the fix is present in the master branch - Submit a backport request
10539 by email:* You should send an email to the relevant stable branch
10540 maintainer and the mailing list with details of the bug or CVE to be
10541 fixed, the commit hash on the master branch that fixes the issue and
10542 the stable branches which you would like this fix to be backported to.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010543
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010544 b. *If the fix is not present in the master branch - Submit the fix to the
10545 master branch first:* This will ensure that the fix passes through the
10546 project's usual patch review and test processes before being accepted.
10547 It will also ensure that bugs are not left unresolved in the master
10548 branch itself. Once the fix is accepted in the master branch a backport
10549 request can be submitted as above.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010550
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010551 c. *If the fix is unsuitable for the master branch - Submit a patch
10552 directly for the stable branch:* This method should be considered as a
10553 last resort. It is typically necessary when the master branch is using
10554 a newer version of the software which includes an upstream fix for the
10555 issue or when the issue has been fixed on the master branch in a way
10556 that introduces backwards incompatible changes. In this case follow the
Andrew Geissler09209ee2020-12-13 08:44:15 -060010557 steps in :ref:`dev-manual/common-tasks:preparing changes for submission` and
10558 :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 -060010559 email to include the name of the stable branch which you are
10560 targetting. This can be done using the ``--subject-prefix`` argument to
10561 ``git format-patch``, for example to submit a patch to the dunfell
10562 branch use
10563 ``git format-patch --subject-prefix='&DISTRO_NAME_NO_CAP_MINUS_ONE;][PATCH' ...``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010564
10565Working With Licenses
10566=====================
10567
Andrew Geissler09209ee2020-12-13 08:44:15 -060010568As mentioned in the ":ref:`overview-manual/development-environment:licensing`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010569section in the Yocto Project Overview and Concepts Manual, open source
10570projects are open to the public and they consequently have different
10571licensing structures in place. This section describes the mechanism by
10572which the :term:`OpenEmbedded Build System`
10573tracks changes to
10574licensing text and covers how to maintain open source license compliance
10575during your project's lifecycle. The section also describes how to
10576enable commercially licensed recipes, which by default are disabled.
10577
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010578Tracking License Changes
10579------------------------
10580
10581The license of an upstream project might change in the future. In order
10582to prevent these changes going unnoticed, the
10583:term:`LIC_FILES_CHKSUM`
10584variable tracks changes to the license text. The checksums are validated
10585at the end of the configure step, and if the checksums do not match, the
10586build will fail.
10587
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010588Specifying the ``LIC_FILES_CHKSUM`` Variable
10589~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10590
10591The ``LIC_FILES_CHKSUM`` variable contains checksums of the license text
10592in the source code for the recipe. Following is an example of how to
Andrew Geisslerc926e172021-05-07 16:11:35 -050010593specify ``LIC_FILES_CHKSUM``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010594
10595 LIC_FILES_CHKSUM = "file://COPYING;md5=xxxx \
10596 file://licfile1.txt;beginline=5;endline=29;md5=yyyy \
10597 file://licfile2.txt;endline=50;md5=zzzz \
10598 ..."
10599
10600.. note::
10601
10602 - When using "beginline" and "endline", realize that line numbering
10603 begins with one and not zero. Also, the included lines are
10604 inclusive (i.e. lines five through and including 29 in the
10605 previous example for ``licfile1.txt``).
10606
10607 - When a license check fails, the selected license text is included
10608 as part of the QA message. Using this output, you can determine
10609 the exact start and finish for the needed license text.
10610
10611The build system uses the :term:`S`
10612variable as the default directory when searching files listed in
10613``LIC_FILES_CHKSUM``. The previous example employs the default
10614directory.
10615
Andrew Geisslerc926e172021-05-07 16:11:35 -050010616Consider this next example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010617
10618 LIC_FILES_CHKSUM = "file://src/ls.c;beginline=5;endline=16;\
10619 md5=bb14ed3c4cda583abc85401304b5cd4e"
10620 LIC_FILES_CHKSUM = "file://${WORKDIR}/license.html;md5=5c94767cedb5d6987c902ac850ded2c6"
10621
10622The first line locates a file in ``${S}/src/ls.c`` and isolates lines
10623five through 16 as license text. The second line refers to a file in
10624:term:`WORKDIR`.
10625
10626Note that ``LIC_FILES_CHKSUM`` variable is mandatory for all recipes,
10627unless the ``LICENSE`` variable is set to "CLOSED".
10628
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010629Explanation of Syntax
10630~~~~~~~~~~~~~~~~~~~~~
10631
10632As mentioned in the previous section, the ``LIC_FILES_CHKSUM`` variable
10633lists all the important files that contain the license text for the
10634source code. It is possible to specify a checksum for an entire file, or
10635a specific section of a file (specified by beginning and ending line
10636numbers with the "beginline" and "endline" parameters, respectively).
10637The latter is useful for source files with a license notice header,
10638README documents, and so forth. If you do not use the "beginline"
10639parameter, then it is assumed that the text begins on the first line of
10640the file. Similarly, if you do not use the "endline" parameter, it is
10641assumed that the license text ends with the last line of the file.
10642
10643The "md5" parameter stores the md5 checksum of the license text. If the
10644license text changes in any way as compared to this parameter then a
10645mismatch occurs. This mismatch triggers a build failure and notifies the
10646developer. Notification allows the developer to review and address the
10647license text changes. Also note that if a mismatch occurs during the
10648build, the correct md5 checksum is placed in the build log and can be
10649easily copied to the recipe.
10650
10651There is no limit to how many files you can specify using the
10652``LIC_FILES_CHKSUM`` variable. Generally, however, every project
10653requires a few specifications for license tracking. Many projects have a
10654"COPYING" file that stores the license information for all the source
10655code files. This practice allows you to just track the "COPYING" file as
10656long as it is kept up to date.
10657
10658.. note::
10659
10660 - If you specify an empty or invalid "md5" parameter,
10661 :term:`BitBake` returns an md5
10662 mis-match error and displays the correct "md5" parameter value
10663 during the build. The correct parameter is also captured in the
10664 build log.
10665
10666 - If the whole file contains only license text, you do not need to
10667 use the "beginline" and "endline" parameters.
10668
10669Enabling Commercially Licensed Recipes
10670--------------------------------------
10671
10672By default, the OpenEmbedded build system disables components that have
10673commercial or other special licensing requirements. Such requirements
10674are defined on a recipe-by-recipe basis through the
10675:term:`LICENSE_FLAGS` variable
10676definition in the affected recipe. For instance, the
10677``poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly`` recipe
Andrew Geisslerc926e172021-05-07 16:11:35 -050010678contains the following statement::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010679
10680 LICENSE_FLAGS = "commercial"
10681
10682Here is a
10683slightly more complicated example that contains both an explicit recipe
Andrew Geisslerc926e172021-05-07 16:11:35 -050010684name and version (after variable expansion)::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010685
10686 LICENSE_FLAGS = "license_${PN}_${PV}"
10687
10688In order for a component restricted by a
10689``LICENSE_FLAGS`` definition to be enabled and included in an image, it
10690needs to have a matching entry in the global
10691:term:`LICENSE_FLAGS_WHITELIST`
10692variable, which is a variable typically defined in your ``local.conf``
10693file. For example, to enable the
10694``poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly`` package, you
10695could add either the string "commercial_gst-plugins-ugly" or the more
10696general string "commercial" to ``LICENSE_FLAGS_WHITELIST``. See the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050010697":ref:`dev-manual/common-tasks:license flag matching`" section for a full
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010698explanation of how ``LICENSE_FLAGS`` matching works. Here is the
Andrew Geisslerc926e172021-05-07 16:11:35 -050010699example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010700
10701 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly"
10702
10703Likewise, to additionally enable the package built from the recipe
10704containing ``LICENSE_FLAGS = "license_${PN}_${PV}"``, and assuming that
10705the actual recipe name was ``emgd_1.10.bb``, the following string would
10706enable that package as well as the original ``gst-plugins-ugly``
Andrew Geisslerc926e172021-05-07 16:11:35 -050010707package::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010708
10709 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly license_emgd_1.10"
10710
10711As a convenience, you do not need to specify the
10712complete license string in the whitelist for every package. You can use
10713an abbreviated form, which consists of just the first portion or
10714portions of the license string before the initial underscore character
10715or characters. A partial string will match any license that contains the
10716given string as the first portion of its license. For example, the
10717following whitelist string will also match both of the packages
10718previously mentioned as well as any other packages that have licenses
10719starting with "commercial" or "license".
10720::
10721
10722 LICENSE_FLAGS_WHITELIST = "commercial license"
10723
10724License Flag Matching
10725~~~~~~~~~~~~~~~~~~~~~
10726
10727License flag matching allows you to control what recipes the
10728OpenEmbedded build system includes in the build. Fundamentally, the
10729build system attempts to match ``LICENSE_FLAGS`` strings found in
10730recipes against ``LICENSE_FLAGS_WHITELIST`` strings found in the
10731whitelist. A match causes the build system to include a recipe in the
10732build, while failure to find a match causes the build system to exclude
10733a recipe.
10734
10735In general, license flag matching is simple. However, understanding some
10736concepts will help you correctly and effectively use matching.
10737
10738Before a flag defined by a particular recipe is tested against the
10739contents of the whitelist, the expanded string ``_${PN}`` is appended to
10740the flag. This expansion makes each ``LICENSE_FLAGS`` value
10741recipe-specific. After expansion, the string is then matched against the
10742whitelist. Thus, specifying ``LICENSE_FLAGS = "commercial"`` in recipe
10743"foo", for example, results in the string ``"commercial_foo"``. And, to
10744create a match, that string must appear in the whitelist.
10745
10746Judicious use of the ``LICENSE_FLAGS`` strings and the contents of the
10747``LICENSE_FLAGS_WHITELIST`` variable allows you a lot of flexibility for
10748including or excluding recipes based on licensing. For example, you can
10749broaden the matching capabilities by using license flags string subsets
10750in the whitelist.
10751
10752.. note::
10753
10754 When using a string subset, be sure to use the part of the expanded
10755 string that precedes the appended underscore character (e.g.
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010756 ``usethispart_1.3``, ``usethispart_1.4``, and so forth).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010757
10758For example, simply specifying the string "commercial" in the whitelist
10759matches any expanded ``LICENSE_FLAGS`` definition that starts with the
10760string "commercial" such as "commercial_foo" and "commercial_bar", which
10761are the strings the build system automatically generates for
10762hypothetical recipes named "foo" and "bar" assuming those recipes simply
Andrew Geisslerc926e172021-05-07 16:11:35 -050010763specify the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010764
10765 LICENSE_FLAGS = "commercial"
10766
10767Thus, you can choose
10768to exhaustively enumerate each license flag in the whitelist and allow
10769only specific recipes into the image, or you can use a string subset
10770that causes a broader range of matches to allow a range of recipes into
10771the image.
10772
10773This scheme works even if the ``LICENSE_FLAGS`` string already has
10774``_${PN}`` appended. For example, the build system turns the license
10775flag "commercial_1.2_foo" into "commercial_1.2_foo_foo" and would match
10776both the general "commercial" and the specific "commercial_1.2_foo"
10777strings found in the whitelist, as expected.
10778
10779Here are some other scenarios:
10780
10781- You can specify a versioned string in the recipe such as
10782 "commercial_foo_1.2" in a "foo" recipe. The build system expands this
10783 string to "commercial_foo_1.2_foo". Combine this license flag with a
10784 whitelist that has the string "commercial" and you match the flag
10785 along with any other flag that starts with the string "commercial".
10786
10787- Under the same circumstances, you can use "commercial_foo" in the
10788 whitelist and the build system not only matches "commercial_foo_1.2"
10789 but also matches any license flag with the string "commercial_foo",
10790 regardless of the version.
10791
10792- You can be very specific and use both the package and version parts
10793 in the whitelist (e.g. "commercial_foo_1.2") to specifically match a
10794 versioned recipe.
10795
10796Other Variables Related to Commercial Licenses
10797~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10798
10799Other helpful variables related to commercial license handling exist and
10800are defined in the
Andrew Geisslerc926e172021-05-07 16:11:35 -050010801``poky/meta/conf/distro/include/default-distrovars.inc`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010802
10803 COMMERCIAL_AUDIO_PLUGINS ?= ""
10804 COMMERCIAL_VIDEO_PLUGINS ?= ""
10805
10806If you
10807want to enable these components, you can do so by making sure you have
10808statements similar to the following in your ``local.conf`` configuration
Andrew Geisslerc926e172021-05-07 16:11:35 -050010809file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010810
10811 COMMERCIAL_AUDIO_PLUGINS = "gst-plugins-ugly-mad \
10812 gst-plugins-ugly-mpegaudioparse"
10813 COMMERCIAL_VIDEO_PLUGINS = "gst-plugins-ugly-mpeg2dec \
10814 gst-plugins-ugly-mpegstream gst-plugins-bad-mpegvideoparse"
10815 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly commercial_gst-plugins-bad commercial_qmmp"
10816
10817
10818Of course, you could also create a matching whitelist for those
10819components using the more general "commercial" in the whitelist, but
10820that would also enable all the other packages with ``LICENSE_FLAGS``
Andrew Geisslerc926e172021-05-07 16:11:35 -050010821containing "commercial", which you may or may not want::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010822
10823 LICENSE_FLAGS_WHITELIST = "commercial"
10824
10825Specifying audio and video plugins as part of the
10826``COMMERCIAL_AUDIO_PLUGINS`` and ``COMMERCIAL_VIDEO_PLUGINS`` statements
10827(along with the enabling ``LICENSE_FLAGS_WHITELIST``) includes the
10828plugins or components into built images, thus adding support for media
10829formats or components.
10830
10831Maintaining Open Source License Compliance During Your Product's Lifecycle
10832--------------------------------------------------------------------------
10833
10834One of the concerns for a development organization using open source
10835software is how to maintain compliance with various open source
10836licensing during the lifecycle of the product. While this section does
10837not provide legal advice or comprehensively cover all scenarios, it does
10838present methods that you can use to assist you in meeting the compliance
10839requirements during a software release.
10840
10841With hundreds of different open source licenses that the Yocto Project
10842tracks, it is difficult to know the requirements of each and every
10843license. However, the requirements of the major FLOSS licenses can begin
10844to be covered by assuming that three main areas of concern exist:
10845
10846- Source code must be provided.
10847
10848- License text for the software must be provided.
10849
10850- Compilation scripts and modifications to the source code must be
10851 provided.
10852
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010853- spdx files can be provided.
10854
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010855There are other requirements beyond the scope of these three and the
10856methods described in this section (e.g. the mechanism through which
10857source code is distributed).
10858
10859As different organizations have different methods of complying with open
10860source licensing, this section is not meant to imply that there is only
10861one single way to meet your compliance obligations, but rather to
10862describe one method of achieving compliance. The remainder of this
10863section describes methods supported to meet the previously mentioned
10864three requirements. Once you take steps to meet these requirements, and
10865prior to releasing images, sources, and the build system, you should
10866audit all artifacts to ensure completeness.
10867
10868.. note::
10869
10870 The Yocto Project generates a license manifest during image creation
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010871 that is located in ``${DEPLOY_DIR}/licenses/``\ `image_name`\ ``-``\ `datestamp`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010872 to assist with any audits.
10873
10874Providing the Source Code
10875~~~~~~~~~~~~~~~~~~~~~~~~~
10876
10877Compliance activities should begin before you generate the final image.
10878The first thing you should look at is the requirement that tops the list
10879for most compliance groups - providing the source. The Yocto Project has
10880a few ways of meeting this requirement.
10881
10882One of the easiest ways to meet this requirement is to provide the
10883entire :term:`DL_DIR` used by the
10884build. This method, however, has a few issues. The most obvious is the
10885size of the directory since it includes all sources used in the build
10886and not just the source used in the released image. It will include
10887toolchain source, and other artifacts, which you would not generally
10888release. However, the more serious issue for most companies is
10889accidental release of proprietary software. The Yocto Project provides
10890an :ref:`archiver <ref-classes-archiver>` class to
10891help avoid some of these concerns.
10892
10893Before you employ ``DL_DIR`` or the ``archiver`` class, you need to
10894decide how you choose to provide source. The source ``archiver`` class
10895can generate tarballs and SRPMs and can create them with various levels
10896of compliance in mind.
10897
10898One way of doing this (but certainly not the only way) is to release
10899just the source as a tarball. You can do this by adding the following to
10900the ``local.conf`` file found in the
Andrew Geisslerc926e172021-05-07 16:11:35 -050010901:term:`Build Directory`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010902
10903 INHERIT += "archiver"
10904 ARCHIVER_MODE[src] = "original"
10905
10906During the creation of your
10907image, the source from all recipes that deploy packages to the image is
10908placed within subdirectories of ``DEPLOY_DIR/sources`` based on the
10909:term:`LICENSE` for each recipe.
10910Releasing the entire directory enables you to comply with requirements
10911concerning providing the unmodified source. It is important to note that
10912the size of the directory can get large.
10913
10914A way to help mitigate the size issue is to only release tarballs for
10915licenses that require the release of source. Let us assume you are only
10916concerned with GPL code as identified by running the following script:
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010917
10918.. code-block:: shell
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010919
10920 # Script to archive a subset of packages matching specific license(s)
10921 # Source and license files are copied into sub folders of package folder
10922 # Must be run from build folder
10923 #!/bin/bash
10924 src_release_dir="source-release"
10925 mkdir -p $src_release_dir
10926 for a in tmp/deploy/sources/*; do
10927 for d in $a/*; do
10928 # Get package name from path
10929 p=`basename $d`
10930 p=${p%-*}
10931 p=${p%-*}
10932 # Only archive GPL packages (update *GPL* regex for your license check)
10933 numfiles=`ls tmp/deploy/licenses/$p/*GPL* 2> /dev/null | wc -l`
10934 if [ $numfiles -gt 1 ]; then
10935 echo Archiving $p
10936 mkdir -p $src_release_dir/$p/source
10937 cp $d/* $src_release_dir/$p/source 2> /dev/null
10938 mkdir -p $src_release_dir/$p/license
10939 cp tmp/deploy/licenses/$p/* $src_release_dir/$p/license 2> /dev/null
10940 fi
10941 done
10942 done
10943
10944At this point, you
10945could create a tarball from the ``gpl_source_release`` directory and
10946provide that to the end user. This method would be a step toward
10947achieving compliance with section 3a of GPLv2 and with section 6 of
10948GPLv3.
10949
10950Providing License Text
10951~~~~~~~~~~~~~~~~~~~~~~
10952
10953One requirement that is often overlooked is inclusion of license text.
10954This requirement also needs to be dealt with prior to generating the
10955final image. Some licenses require the license text to accompany the
10956binary. You can achieve this by adding the following to your
Andrew Geisslerc926e172021-05-07 16:11:35 -050010957``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010958
10959 COPY_LIC_MANIFEST = "1"
10960 COPY_LIC_DIRS = "1"
10961 LICENSE_CREATE_PACKAGE = "1"
10962
10963Adding these statements to the
10964configuration file ensures that the licenses collected during package
10965generation are included on your image.
10966
10967.. note::
10968
10969 Setting all three variables to "1" results in the image having two
10970 copies of the same license file. One copy resides in
10971 ``/usr/share/common-licenses`` and the other resides in
10972 ``/usr/share/license``.
10973
10974 The reason for this behavior is because
10975 :term:`COPY_LIC_DIRS` and
10976 :term:`COPY_LIC_MANIFEST`
10977 add a copy of the license when the image is built but do not offer a
10978 path for adding licenses for newly installed packages to an image.
10979 :term:`LICENSE_CREATE_PACKAGE`
10980 adds a separate package and an upgrade path for adding licenses to an
10981 image.
10982
10983As the source ``archiver`` class has already archived the original
10984unmodified source that contains the license files, you would have
10985already met the requirements for inclusion of the license information
10986with source as defined by the GPL and other open source licenses.
10987
10988Providing Compilation Scripts and Source Code Modifications
10989~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10990
10991At this point, we have addressed all we need to prior to generating the
10992image. The next two requirements are addressed during the final
10993packaging of the release.
10994
10995By releasing the version of the OpenEmbedded build system and the layers
10996used during the build, you will be providing both compilation scripts
10997and the source code modifications in one step.
10998
Andrew Geissler09209ee2020-12-13 08:44:15 -060010999If the deployment team has a :ref:`overview-manual/concepts:bsp layer`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011000and a distro layer, and those
11001those layers are used to patch, compile, package, or modify (in any way)
11002any open source software included in your released images, you might be
11003required to release those layers under section 3 of GPLv2 or section 1
11004of GPLv3. One way of doing that is with a clean checkout of the version
11005of the Yocto Project and layers used during your build. Here is an
11006example:
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011007
11008.. code-block:: shell
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011009
11010 # We built using the dunfell branch of the poky repo
11011 $ git clone -b dunfell git://git.yoctoproject.org/poky
11012 $ cd poky
11013 # We built using the release_branch for our layers
11014 $ git clone -b release_branch git://git.mycompany.com/meta-my-bsp-layer
11015 $ git clone -b release_branch git://git.mycompany.com/meta-my-software-layer
11016 # clean up the .git repos
11017 $ find . -name ".git" -type d -exec rm -rf {} \;
11018
11019One
11020thing a development organization might want to consider for end-user
11021convenience is to modify ``meta-poky/conf/bblayers.conf.sample`` to
11022ensure that when the end user utilizes the released build system to
11023build an image, the development organization's layers are included in
Andrew Geisslerc926e172021-05-07 16:11:35 -050011024the ``bblayers.conf`` file automatically::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011025
11026 # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
11027 # changes incompatibly
11028 POKY_BBLAYERS_CONF_VERSION = "2"
11029
11030 BBPATH = "${TOPDIR}"
11031 BBFILES ?= ""
11032
11033 BBLAYERS ?= " \
11034 ##OEROOT##/meta \
11035 ##OEROOT##/meta-poky \
11036 ##OEROOT##/meta-yocto-bsp \
11037 ##OEROOT##/meta-mylayer \
11038 "
11039
11040Creating and
11041providing an archive of the :term:`Metadata`
11042layers (recipes, configuration files, and so forth) enables you to meet
11043your requirements to include the scripts to control compilation as well
11044as any modifications to the original source.
11045
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011046Providing spdx files
11047~~~~~~~~~~~~~~~~~~~~~~~~~
11048
11049The spdx module has been integrated to a layer named meta-spdxscanner.
11050meta-spdxscanner provides several kinds of scanner. If you want to enable
11051this function, you have to follow the following steps:
11052
110531. Add meta-spdxscanner layer into ``bblayers.conf``.
11054
110552. Refer to the README in meta-spdxscanner to setup the environment (e.g,
11056 setup a fossology server) needed for the scanner.
11057
110583. Meta-spdxscanner provides several methods within the bbclass to create spdx files.
11059 Please choose one that you want to use and enable the spdx task. You have to
11060 add some config options in ``local.conf`` file in your :term:`Build
11061 Directory`. The following is an example showing how to generate spdx files
11062 during bitbake using the fossology-python.bbclass::
11063
11064 # Select fossology-python.bbclass.
11065 INHERIT += "fossology-python"
11066 # For fossology-python.bbclass, TOKEN is necessary, so, after setup a
11067 # Fossology server, you have to create a token.
11068 TOKEN = "eyJ0eXAiO..."
11069 # The fossology server is necessary for fossology-python.bbclass.
11070 FOSSOLOGY_SERVER = "http://xx.xx.xx.xx:8081/repo"
11071 # If you want to upload the source code to a special folder:
11072 FOLDER_NAME = "xxxx" //Optional
11073 # If you don't want to put spdx files in tmp/deploy/spdx, you can enable:
11074 SPDX_DEPLOY_DIR = "${DEPLOY_DIR}" //Optional
11075
11076For more usage information refer to :yocto_git:`the meta-spdxscanner repository
Andrew Geissler09209ee2020-12-13 08:44:15 -060011077</meta-spdxscanner/>`.
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011078
11079
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011080Copying Licenses that Do Not Exist
11081----------------------------------
11082
11083Some packages, such as the linux-firmware package, have many licenses
11084that are not in any way common. You can avoid adding a lot of these
11085types of common license files, which are only applicable to a specific
11086package, by using the
11087:term:`NO_GENERIC_LICENSE`
11088variable. Using this variable also avoids QA errors when you use a
11089non-common, non-CLOSED license in a recipe.
11090
11091The following is an example that uses the ``LICENSE.Abilis.txt`` file as
Andrew Geisslerc926e172021-05-07 16:11:35 -050011092the license from the fetched source::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011093
11094 NO_GENERIC_LICENSE[Firmware-Abilis] = "LICENSE.Abilis.txt"
11095
11096Using the Error Reporting Tool
11097==============================
11098
11099The error reporting tool allows you to submit errors encountered during
11100builds to a central database. Outside of the build environment, you can
11101use a web interface to browse errors, view statistics, and query for
11102errors. The tool works using a client-server system where the client
11103portion is integrated with the installed Yocto Project
11104:term:`Source Directory` (e.g. ``poky``).
11105The server receives the information collected and saves it in a
11106database.
11107
11108A live instance of the error reporting server exists at
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011109https://errors.yoctoproject.org. This server exists so that when
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011110you want to get help with build failures, you can submit all of the
11111information on the failure easily and then point to the URL in your bug
11112report or send an email to the mailing list.
11113
11114.. note::
11115
11116 If you send error reports to this server, the reports become publicly
11117 visible.
11118
11119Enabling and Using the Tool
11120---------------------------
11121
11122By default, the error reporting tool is disabled. You can enable it by
11123inheriting the
11124:ref:`report-error <ref-classes-report-error>`
11125class by adding the following statement to the end of your
11126``local.conf`` file in your
11127:term:`Build Directory`.
11128::
11129
11130 INHERIT += "report-error"
11131
11132By default, the error reporting feature stores information in
11133``${``\ :term:`LOG_DIR`\ ``}/error-report``.
11134However, you can specify a directory to use by adding the following to
Andrew Geisslerc926e172021-05-07 16:11:35 -050011135your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011136
11137 ERR_REPORT_DIR = "path"
11138
11139Enabling error
11140reporting causes the build process to collect the errors and store them
11141in a file as previously described. When the build system encounters an
11142error, it includes a command as part of the console output. You can run
11143the command to send the error file to the server. For example, the
Andrew Geisslerc926e172021-05-07 16:11:35 -050011144following command sends the errors to an upstream server::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011145
11146 $ send-error-report /home/brandusa/project/poky/build/tmp/log/error-report/error_report_201403141617.txt
11147
11148In the previous example, the errors are sent to a public database
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011149available at https://errors.yoctoproject.org, which is used by the
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011150entire community. If you specify a particular server, you can send the
11151errors to a different database. Use the following command for more
Andrew Geisslerc926e172021-05-07 16:11:35 -050011152information on available options::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011153
11154 $ send-error-report --help
11155
11156When sending the error file, you are prompted to review the data being
11157sent as well as to provide a name and optional email address. Once you
11158satisfy these prompts, the command returns a link from the server that
11159corresponds to your entry in the database. For example, here is a
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011160typical link: https://errors.yoctoproject.org/Errors/Details/9522/
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011161
11162Following the link takes you to a web interface where you can browse,
11163query the errors, and view statistics.
11164
11165Disabling the Tool
11166------------------
11167
11168To disable the error reporting feature, simply remove or comment out the
11169following statement from the end of your ``local.conf`` file in your
11170:term:`Build Directory`.
11171::
11172
11173 INHERIT += "report-error"
11174
11175Setting Up Your Own Error Reporting Server
11176------------------------------------------
11177
11178If you want to set up your own error reporting server, you can obtain
Andrew Geissler09209ee2020-12-13 08:44:15 -060011179the code from the Git repository at :yocto_git:`/error-report-web/`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011180Instructions on how to set it up are in the README document.
11181
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011182Using Wayland and Weston
11183========================
11184
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011185`Wayland <https://en.wikipedia.org/wiki/Wayland_(display_server_protocol)>`__
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011186is a computer display server protocol that provides a method for
11187compositing window managers to communicate directly with applications
11188and video hardware and expects them to communicate with input hardware
11189using other libraries. Using Wayland with supporting targets can result
11190in better control over graphics frame rendering than an application
11191might otherwise achieve.
11192
11193The Yocto Project provides the Wayland protocol libraries and the
11194reference
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011195`Weston <https://en.wikipedia.org/wiki/Wayland_(display_server_protocol)#Weston>`__
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011196compositor as part of its release. You can find the integrated packages
11197in the ``meta`` layer of the :term:`Source Directory`.
11198Specifically, you
11199can find the recipes that build both Wayland and Weston at
11200``meta/recipes-graphics/wayland``.
11201
11202You can build both the Wayland and Weston packages for use only with
11203targets that accept the `Mesa 3D and Direct Rendering
11204Infrastructure <https://en.wikipedia.org/wiki/Mesa_(computer_graphics)>`__,
11205which is also known as Mesa DRI. This implies that you cannot build and
11206use the packages if your target uses, for example, the Intel Embedded
11207Media and Graphics Driver (Intel EMGD) that overrides Mesa DRI.
11208
11209.. note::
11210
11211 Due to lack of EGL support, Weston 1.0.3 will not run directly on the
11212 emulated QEMU hardware. However, this version of Weston will run
11213 under X emulation without issues.
11214
11215This section describes what you need to do to implement Wayland and use
11216the Weston compositor when building an image for a supporting target.
11217
11218Enabling Wayland in an Image
11219----------------------------
11220
11221To enable Wayland, you need to enable it to be built and enable it to be
11222included (installed) in the image.
11223
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011224Building Wayland
11225~~~~~~~~~~~~~~~~
11226
11227To cause Mesa to build the ``wayland-egl`` platform and Weston to build
11228Wayland with Kernel Mode Setting
11229(`KMS <https://wiki.archlinux.org/index.php/Kernel_Mode_Setting>`__)
11230support, include the "wayland" flag in the
11231:term:`DISTRO_FEATURES`
Andrew Geisslerc926e172021-05-07 16:11:35 -050011232statement in your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011233
11234 DISTRO_FEATURES_append = " wayland"
11235
11236.. note::
11237
11238 If X11 has been enabled elsewhere, Weston will build Wayland with X11
11239 support
11240
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011241Installing Wayland and Weston
11242~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11243
11244To install the Wayland feature into an image, you must include the
11245following
11246:term:`CORE_IMAGE_EXTRA_INSTALL`
Andrew Geisslerc926e172021-05-07 16:11:35 -050011247statement in your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011248
11249 CORE_IMAGE_EXTRA_INSTALL += "wayland weston"
11250
11251Running Weston
11252--------------
11253
11254To run Weston inside X11, enabling it as described earlier and building
11255a Sato image is sufficient. If you are running your image under Sato, a
11256Weston Launcher appears in the "Utility" category.
11257
11258Alternatively, you can run Weston through the command-line interpretor
11259(CLI), which is better suited for development work. To run Weston under
11260the CLI, you need to do the following after your image is built:
11261
Andrew Geisslerc926e172021-05-07 16:11:35 -0500112621. Run these commands to export ``XDG_RUNTIME_DIR``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011263
11264 mkdir -p /tmp/$USER-weston
11265 chmod 0700 /tmp/$USER-weston
11266 export XDG_RUNTIME_DIR=/tmp/$USER-weston
11267
Andrew Geisslerc926e172021-05-07 16:11:35 -0500112682. Launch Weston in the shell::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011269
11270 weston