blob: c111355ccd9d946a2af9be51571147b70ac64101 [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
Andrew Geissler595f6302022-01-24 19:11:47 +000027.. note::
28
29 It is very easy to create your own layers to use with the OpenEmbedded
30 build system, as the Yocto Project ships with tools that speed up creating
31 layers. This section describes the steps you perform by hand to create
32 layers so that you can better understand them. For information about the
33 layer-creation tools, see the
34 ":ref:`bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script`"
35 section in the Yocto Project Board Support Package (BSP) Developer's
36 Guide and the ":ref:`dev-manual/common-tasks:creating a general layer using the \`\`bitbake-layers\`\` script`"
37 section further down in this manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050038
39Follow these general steps to create your layer without using tools:
40
411. *Check Existing Layers:* Before creating a new layer, you should be
42 sure someone has not already created a layer containing the Metadata
Andrew Geisslerd1e89492021-02-12 15:35:20 -060043 you need. You can see the :oe_layerindex:`OpenEmbedded Metadata Index <>`
44 for a list of layers from the OpenEmbedded community that can be used in
Andrew Geisslerc9f78652020-09-18 14:11:35 -050045 the Yocto Project. You could find a layer that is identical or close
46 to what you need.
47
482. *Create a Directory:* Create the directory for your layer. When you
49 create the layer, be sure to create the directory in an area not
50 associated with the Yocto Project :term:`Source Directory`
51 (e.g. the cloned ``poky`` repository).
52
53 While not strictly required, prepend the name of the directory with
Andrew Geisslerc926e172021-05-07 16:11:35 -050054 the string "meta-". For example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050055
56 meta-mylayer
57 meta-GUI_xyz
58 meta-mymachine
59
Andrew Geisslerc926e172021-05-07 16:11:35 -050060 With rare exceptions, a layer's name follows this form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050061
62 meta-root_name
63
64 Following this layer naming convention can save
65 you trouble later when tools, components, or variables "assume" your
66 layer name begins with "meta-". A notable example is in configuration
67 files as shown in the following step where layer names without the
68 "meta-" string are appended to several variables used in the
69 configuration.
70
713. *Create a Layer Configuration File:* Inside your new layer folder,
72 you need to create a ``conf/layer.conf`` file. It is easiest to take
73 an existing layer configuration file and copy that to your layer's
74 ``conf`` directory and then modify the file as needed.
75
76 The ``meta-yocto-bsp/conf/layer.conf`` file in the Yocto Project
Andrew Geissler09209ee2020-12-13 08:44:15 -060077 :yocto_git:`Source Repositories </poky/tree/meta-yocto-bsp/conf>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050078 demonstrates the required syntax. For your layer, you need to replace
79 "yoctobsp" with a unique identifier for your layer (e.g. "machinexyz"
Andrew Geisslerc926e172021-05-07 16:11:35 -050080 for a layer named "meta-machinexyz")::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050081
82 # We have a conf and classes directory, add to BBPATH
83 BBPATH .= ":${LAYERDIR}"
84
Andrew Geissler4c19ea12020-10-27 13:52:24 -050085 # We have recipes-* directories, add to BBFILES
Andrew Geisslerc9f78652020-09-18 14:11:35 -050086 BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
87 ${LAYERDIR}/recipes-*/*/*.bbappend"
88
89 BBFILE_COLLECTIONS += "yoctobsp"
90 BBFILE_PATTERN_yoctobsp = "^${LAYERDIR}/"
91 BBFILE_PRIORITY_yoctobsp = "5"
92 LAYERVERSION_yoctobsp = "4"
93 LAYERSERIES_COMPAT_yoctobsp = "dunfell"
94
95 Following is an explanation of the layer configuration file:
96
97 - :term:`BBPATH`: Adds the layer's
98 root directory to BitBake's search path. Through the use of the
Andrew Geissler09036742021-06-25 14:25:14 -050099 :term:`BBPATH` variable, BitBake locates class files (``.bbclass``),
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500100 configuration files, and files that are included with ``include``
101 and ``require`` statements. For these cases, BitBake uses the
Andrew Geissler09036742021-06-25 14:25:14 -0500102 first file that matches the name found in :term:`BBPATH`. This is
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500103 similar to the way the ``PATH`` variable is used for binaries. It
104 is recommended, therefore, that you use unique class and
105 configuration filenames in your custom layer.
106
107 - :term:`BBFILES`: Defines the
108 location for all recipes in the layer.
109
110 - :term:`BBFILE_COLLECTIONS`:
111 Establishes the current layer through a unique identifier that is
112 used throughout the OpenEmbedded build system to refer to the
113 layer. In this example, the identifier "yoctobsp" is the
114 representation for the container layer named "meta-yocto-bsp".
115
116 - :term:`BBFILE_PATTERN`:
117 Expands immediately during parsing to provide the directory of the
118 layer.
119
120 - :term:`BBFILE_PRIORITY`:
121 Establishes a priority to use for recipes in the layer when the
122 OpenEmbedded build finds recipes of the same name in different
123 layers.
124
125 - :term:`LAYERVERSION`:
126 Establishes a version number for the layer. You can use this
127 version number to specify this exact version of the layer as a
128 dependency when using the
129 :term:`LAYERDEPENDS`
130 variable.
131
132 - :term:`LAYERDEPENDS`:
133 Lists all layers on which this layer depends (if any).
134
135 - :term:`LAYERSERIES_COMPAT`:
Andrew Geissler09209ee2020-12-13 08:44:15 -0600136 Lists the :yocto_wiki:`Yocto Project </Releases>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500137 releases for which the current version is compatible. This
138 variable is a good way to indicate if your particular layer is
139 current.
140
1414. *Add Content:* Depending on the type of layer, add the content. If
142 the layer adds support for a machine, add the machine configuration
143 in a ``conf/machine/`` file within the layer. If the layer adds
144 distro policy, add the distro configuration in a ``conf/distro/``
145 file within the layer. If the layer introduces new recipes, put the
146 recipes you need in ``recipes-*`` subdirectories within the layer.
147
148 .. note::
149
150 For an explanation of layer hierarchy that is compliant with the
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500151 Yocto Project, see the ":ref:`bsp-guide/bsp:example filesystem layout`"
152 section in the Yocto Project Board Support Package (BSP) Developer's Guide.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500153
1545. *Optionally Test for Compatibility:* If you want permission to use
155 the Yocto Project Compatibility logo with your layer or application
156 that uses your layer, perform the steps to apply for compatibility.
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500157 See the
158 ":ref:`dev-manual/common-tasks:making sure your layer is compatible with yocto project`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500159 section for more information.
160
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500161Following Best Practices When Creating Layers
162---------------------------------------------
163
164To create layers that are easier to maintain and that will not impact
165builds for other machines, you should consider the information in the
166following list:
167
168- *Avoid "Overlaying" Entire Recipes from Other Layers in Your
169 Configuration:* In other words, do not copy an entire recipe into
170 your layer and then modify it. Rather, use an append file
171 (``.bbappend``) to override only those parts of the original recipe
172 you need to modify.
173
174- *Avoid Duplicating Include Files:* Use append files (``.bbappend``)
175 for each recipe that uses an include file. Or, if you are introducing
176 a new recipe that requires the included file, use the path relative
177 to the original layer directory to refer to the file. For example,
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500178 use ``require recipes-core/``\ `package`\ ``/``\ `file`\ ``.inc`` instead
179 of ``require`` `file`\ ``.inc``. If you're finding you have to overlay
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500180 the include file, it could indicate a deficiency in the include file
181 in the layer to which it originally belongs. If this is the case, you
182 should try to address that deficiency instead of overlaying the
183 include file. For example, you could address this by getting the
184 maintainer of the include file to add a variable or variables to make
185 it easy to override the parts needing to be overridden.
186
187- *Structure Your Layers:* Proper use of overrides within append files
188 and placement of machine-specific files within your layer can ensure
189 that a build is not using the wrong Metadata and negatively impacting
190 a build for a different machine. Following are some examples:
191
192 - *Modify Variables to Support a Different Machine:* Suppose you
193 have a layer named ``meta-one`` that adds support for building
194 machine "one". To do so, you use an append file named
195 ``base-files.bbappend`` and create a dependency on "foo" by
196 altering the :term:`DEPENDS`
Andrew Geisslerc926e172021-05-07 16:11:35 -0500197 variable::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500198
199 DEPENDS = "foo"
200
201 The dependency is created during any
202 build that includes the layer ``meta-one``. However, you might not
203 want this dependency for all machines. For example, suppose you
204 are building for machine "two" but your ``bblayers.conf`` file has
205 the ``meta-one`` layer included. During the build, the
206 ``base-files`` for machine "two" will also have the dependency on
207 ``foo``.
208
209 To make sure your changes apply only when building machine "one",
Andrew Geissler09036742021-06-25 14:25:14 -0500210 use a machine override with the :term:`DEPENDS` statement::
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500211
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500212 DEPENDS:one = "foo"
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500213
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500214 You should follow the same strategy when using ``:append``
215 and ``:prepend`` operations::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500216
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500217 DEPENDS:append:one = " foo"
218 DEPENDS:prepend:one = "foo "
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500219
220 As an actual example, here's a
221 snippet from the generic kernel include file ``linux-yocto.inc``,
222 wherein the kernel compile and link options are adjusted in the
Andrew Geisslerc926e172021-05-07 16:11:35 -0500223 case of a subset of the supported architectures::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500224
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500225 DEPENDS:append:aarch64 = " libgcc"
226 KERNEL_CC:append:aarch64 = " ${TOOLCHAIN_OPTIONS}"
227 KERNEL_LD:append:aarch64 = " ${TOOLCHAIN_OPTIONS}"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500228
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500229 DEPENDS:append:nios2 = " libgcc"
230 KERNEL_CC:append:nios2 = " ${TOOLCHAIN_OPTIONS}"
231 KERNEL_LD:append:nios2 = " ${TOOLCHAIN_OPTIONS}"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500232
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500233 DEPENDS:append:arc = " libgcc"
234 KERNEL_CC:append:arc = " ${TOOLCHAIN_OPTIONS}"
235 KERNEL_LD:append:arc = " ${TOOLCHAIN_OPTIONS}"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500236
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500237 KERNEL_FEATURES:append:qemuall=" features/debug/printk.scc"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500238
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500239 - *Place Machine-Specific Files in Machine-Specific Locations:* When
240 you have a base recipe, such as ``base-files.bb``, that contains a
241 :term:`SRC_URI` statement to a
242 file, you can use an append file to cause the build to use your
243 own version of the file. For example, an append file in your layer
244 at ``meta-one/recipes-core/base-files/base-files.bbappend`` could
Andrew Geisslerc926e172021-05-07 16:11:35 -0500245 extend :term:`FILESPATH` using :term:`FILESEXTRAPATHS` as follows::
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500246
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500247 FILESEXTRAPATHS:prepend := "${THISDIR}/${BPN}:"
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500248
249 The build for machine "one" will pick up your machine-specific file as
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500250 long as you have the file in
251 ``meta-one/recipes-core/base-files/base-files/``. However, if you
252 are building for a different machine and the ``bblayers.conf``
253 file includes the ``meta-one`` layer and the location of your
254 machine-specific file is the first location where that file is
Andrew Geissler09036742021-06-25 14:25:14 -0500255 found according to :term:`FILESPATH`, builds for all machines will
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500256 also use that machine-specific file.
257
258 You can make sure that a machine-specific file is used for a
259 particular machine by putting the file in a subdirectory specific
260 to the machine. For example, rather than placing the file in
261 ``meta-one/recipes-core/base-files/base-files/`` as shown above,
262 put it in ``meta-one/recipes-core/base-files/base-files/one/``.
263 Not only does this make sure the file is used only when building
264 for machine "one", but the build process locates the file more
265 quickly.
266
267 In summary, you need to place all files referenced from
Andrew Geissler5f350902021-07-23 13:09:54 -0400268 :term:`SRC_URI` in a machine-specific subdirectory within the layer in
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500269 order to restrict those files to machine-specific builds.
270
271- *Perform Steps to Apply for Yocto Project Compatibility:* If you want
272 permission to use the Yocto Project Compatibility logo with your
273 layer or application that uses your layer, perform the steps to apply
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500274 for compatibility. See the
275 ":ref:`dev-manual/common-tasks:making sure your layer is compatible with yocto project`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500276 section for more information.
277
278- *Follow the Layer Naming Convention:* Store custom layers in a Git
279 repository that use the ``meta-layer_name`` format.
280
281- *Group Your Layers Locally:* Clone your repository alongside other
282 cloned ``meta`` directories from the :term:`Source Directory`.
283
284Making Sure Your Layer is Compatible With Yocto Project
285-------------------------------------------------------
286
287When you create a layer used with the Yocto Project, it is advantageous
288to make sure that the layer interacts well with existing Yocto Project
289layers (i.e. the layer is compatible with the Yocto Project). Ensuring
290compatibility makes the layer easy to be consumed by others in the Yocto
291Project community and could allow you permission to use the Yocto
292Project Compatible Logo.
293
294.. note::
295
296 Only Yocto Project member organizations are permitted to use the
297 Yocto Project Compatible Logo. The logo is not available for general
298 use. For information on how to become a Yocto Project member
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500299 organization, see the :yocto_home:`Yocto Project Website <>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500300
301The Yocto Project Compatibility Program consists of a layer application
302process that requests permission to use the Yocto Project Compatibility
303Logo for your layer and application. The process consists of two parts:
304
3051. Successfully passing a script (``yocto-check-layer``) that when run
306 against your layer, tests it against constraints based on experiences
307 of how layers have worked in the real world and where pitfalls have
308 been found. Getting a "PASS" result from the script is required for
309 successful compatibility registration.
310
3112. Completion of an application acceptance form, which you can find at
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600312 :yocto_home:`/webform/yocto-project-compatible-registration`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500313
314To be granted permission to use the logo, you need to satisfy the
315following:
316
317- Be able to check the box indicating that you got a "PASS" when
318 running the script against your layer.
319
320- Answer "Yes" to the questions on the form or have an acceptable
321 explanation for any questions answered "No".
322
323- Be a Yocto Project Member Organization.
324
325The remainder of this section presents information on the registration
326form and on the ``yocto-check-layer`` script.
327
328Yocto Project Compatible Program Application
329~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
330
331Use the form to apply for your layer's approval. Upon successful
332application, you can use the Yocto Project Compatibility Logo with your
333layer and the application that uses your layer.
334
335To access the form, use this link:
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600336:yocto_home:`/webform/yocto-project-compatible-registration`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500337Follow the instructions on the form to complete your application.
338
339The application consists of the following sections:
340
341- *Contact Information:* Provide your contact information as the fields
342 require. Along with your information, provide the released versions
343 of the Yocto Project for which your layer is compatible.
344
345- *Acceptance Criteria:* Provide "Yes" or "No" answers for each of the
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700346 items in the checklist. There is space at the bottom of the form for
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500347 any explanations for items for which you answered "No".
348
349- *Recommendations:* Provide answers for the questions regarding Linux
350 kernel use and build success.
351
352``yocto-check-layer`` Script
353~~~~~~~~~~~~~~~~~~~~~~~~~~~~
354
355The ``yocto-check-layer`` script provides you a way to assess how
356compatible your layer is with the Yocto Project. You should run this
357script prior to using the form to apply for compatibility as described
358in the previous section. You need to achieve a "PASS" result in order to
359have your application form successfully processed.
360
361The script divides tests into three areas: COMMON, BSP, and DISTRO. For
362example, given a distribution layer (DISTRO), the layer must pass both
363the COMMON and DISTRO related tests. Furthermore, if your layer is a BSP
364layer, the layer must pass the COMMON and BSP set of tests.
365
366To execute the script, enter the following commands from your build
Andrew Geisslerc926e172021-05-07 16:11:35 -0500367directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500368
369 $ source oe-init-build-env
370 $ yocto-check-layer your_layer_directory
371
372Be sure to provide the actual directory for your
373layer as part of the command.
374
375Entering the command causes the script to determine the type of layer
376and then to execute a set of specific tests against the layer. The
377following list overviews the test:
378
379- ``common.test_readme``: Tests if a ``README`` file exists in the
380 layer and the file is not empty.
381
382- ``common.test_parse``: Tests to make sure that BitBake can parse the
383 files without error (i.e. ``bitbake -p``).
384
385- ``common.test_show_environment``: Tests that the global or per-recipe
386 environment is in order without errors (i.e. ``bitbake -e``).
387
388- ``common.test_world``: Verifies that ``bitbake world`` works.
389
390- ``common.test_signatures``: Tests to be sure that BSP and DISTRO
391 layers do not come with recipes that change signatures.
392
393- ``common.test_layerseries_compat``: Verifies layer compatibility is
394 set properly.
395
396- ``bsp.test_bsp_defines_machines``: Tests if a BSP layer has machine
397 configurations.
398
399- ``bsp.test_bsp_no_set_machine``: Tests to ensure a BSP layer does not
400 set the machine when the layer is added.
401
402- ``bsp.test_machine_world``: Verifies that ``bitbake world`` works
403 regardless of which machine is selected.
404
405- ``bsp.test_machine_signatures``: Verifies that building for a
406 particular machine affects only the signature of tasks specific to
407 that machine.
408
409- ``distro.test_distro_defines_distros``: Tests if a DISTRO layer has
410 distro configurations.
411
412- ``distro.test_distro_no_set_distros``: Tests to ensure a DISTRO layer
413 does not set the distribution when the layer is added.
414
415Enabling Your Layer
416-------------------
417
418Before the OpenEmbedded build system can use your new layer, you need to
419enable it. To enable your layer, simply add your layer's path to the
Andrew Geissler09036742021-06-25 14:25:14 -0500420:term:`BBLAYERS` variable in your ``conf/bblayers.conf`` file, which is
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500421found in the :term:`Build Directory`.
Andrew Geissler5199d832021-09-24 16:47:35 -0500422The following example shows how to enable your new
423``meta-mylayer`` layer (note how your new layer exists outside of
424the official ``poky`` repository which you would have checked out earlier)::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500425
426 # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
427 # changes incompatibly
428 POKY_BBLAYERS_CONF_VERSION = "2"
429 BBPATH = "${TOPDIR}"
430 BBFILES ?= ""
431 BBLAYERS ?= " \
432 /home/user/poky/meta \
433 /home/user/poky/meta-poky \
434 /home/user/poky/meta-yocto-bsp \
Andrew Geissler5199d832021-09-24 16:47:35 -0500435 /home/user/mystuff/meta-mylayer \
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500436 "
437
438BitBake parses each ``conf/layer.conf`` file from the top down as
Andrew Geissler09036742021-06-25 14:25:14 -0500439specified in the :term:`BBLAYERS` variable within the ``conf/bblayers.conf``
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500440file. During the processing of each ``conf/layer.conf`` file, BitBake
441adds the recipes, classes and configurations contained within the
442particular layer to the source directory.
443
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500444Appending Other Layers Metadata With Your Layer
445-----------------------------------------------
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500446
447A recipe that appends Metadata to another recipe is called a BitBake
448append file. A BitBake append file uses the ``.bbappend`` file type
449suffix, while the corresponding recipe to which Metadata is being
450appended uses the ``.bb`` file type suffix.
451
452You can use a ``.bbappend`` file in your layer to make additions or
453changes to the content of another layer's recipe without having to copy
454the other layer's recipe into your layer. Your ``.bbappend`` file
455resides in your layer, while the main ``.bb`` recipe file to which you
456are appending Metadata resides in a different layer.
457
458Being able to append information to an existing recipe not only avoids
459duplication, but also automatically applies recipe changes from a
460different layer into your layer. If you were copying recipes, you would
461have to manually merge changes as they occur.
462
463When you create an append file, you must use the same root name as the
464corresponding recipe file. For example, the append file
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500465``someapp_3.1.bbappend`` must apply to ``someapp_3.1.bb``. This
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500466means the original recipe and append filenames are version
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500467number-specific. If the corresponding recipe is renamed to update to a
468newer version, you must also rename and possibly update the
469corresponding ``.bbappend`` as well. During the build process, BitBake
470displays an error on starting if it detects a ``.bbappend`` file that
471does not have a corresponding recipe with a matching name. See the
472:term:`BB_DANGLINGAPPENDS_WARNONLY`
473variable for information on how to handle this error.
474
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500475Overlaying a File Using Your Layer
476~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
477
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500478As an example, consider the main formfactor recipe and a corresponding
479formfactor append file both from the :term:`Source Directory`.
480Here is the main
481formfactor recipe, which is named ``formfactor_0.0.bb`` and located in
Andrew Geisslerc926e172021-05-07 16:11:35 -0500482the "meta" layer at ``meta/recipes-bsp/formfactor``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500483
484 SUMMARY = "Device formfactor information"
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500485 DESCRIPTION = "A formfactor configuration file provides information about the \
486 target hardware for which the image is being built and information that the \
487 build system cannot obtain from other sources such as the kernel."
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500488 SECTION = "base"
489 LICENSE = "MIT"
490 LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
491 PR = "r45"
492
493 SRC_URI = "file://config file://machconfig"
494 S = "${WORKDIR}"
495
496 PACKAGE_ARCH = "${MACHINE_ARCH}"
497 INHIBIT_DEFAULT_DEPS = "1"
498
499 do_install() {
500 # Install file only if it has contents
501 install -d ${D}${sysconfdir}/formfactor/
502 install -m 0644 ${S}/config ${D}${sysconfdir}/formfactor/
503 if [ -s "${S}/machconfig" ]; then
504 install -m 0644 ${S}/machconfig ${D}${sysconfdir}/formfactor/
505 fi
506 }
507
508In the main recipe, note the :term:`SRC_URI`
509variable, which tells the OpenEmbedded build system where to find files
510during the build.
511
512Following is the append file, which is named ``formfactor_0.0.bbappend``
513and is from the Raspberry Pi BSP Layer named ``meta-raspberrypi``. The
Andrew Geisslerc926e172021-05-07 16:11:35 -0500514file is in the layer at ``recipes-bsp/formfactor``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500515
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500516 FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500517
518By default, the build system uses the
519:term:`FILESPATH` variable to
520locate files. This append file extends the locations by setting the
521:term:`FILESEXTRAPATHS`
522variable. Setting this variable in the ``.bbappend`` file is the most
523reliable and recommended method for adding directories to the search
524path used by the build system to find files.
525
526The statement in this example extends the directories to include
527``${``\ :term:`THISDIR`\ ``}/${``\ :term:`PN`\ ``}``,
528which resolves to a directory named ``formfactor`` in the same directory
529in which the append file resides (i.e.
530``meta-raspberrypi/recipes-bsp/formfactor``. This implies that you must
531have the supporting directory structure set up that will contain any
532files or patches you will be including from the layer.
533
534Using the immediate expansion assignment operator ``:=`` is important
Andrew Geissler09036742021-06-25 14:25:14 -0500535because of the reference to :term:`THISDIR`. The trailing colon character is
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500536important as it ensures that items in the list remain colon-separated.
537
538.. note::
539
Andrew Geissler09036742021-06-25 14:25:14 -0500540 BitBake automatically defines the :term:`THISDIR` variable. You should
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500541 never set this variable yourself. Using ":prepend" as part of the
Andrew Geissler09036742021-06-25 14:25:14 -0500542 :term:`FILESEXTRAPATHS` ensures your path will be searched prior to other
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500543 paths in the final list.
544
545 Also, not all append files add extra files. Many append files simply
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700546 allow to add build options (e.g. ``systemd``). For these cases, your
Andrew Geissler09036742021-06-25 14:25:14 -0500547 append file would not even use the :term:`FILESEXTRAPATHS` statement.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500548
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500549The end result of this ``.bbappend`` file is that on a Raspberry Pi, where
550``rpi`` will exist in the list of :term:`OVERRIDES`, the file
551``meta-raspberrypi/recipes-bsp/formfactor/formfactor/rpi/machconfig`` will be
552used during :ref:`ref-tasks-fetch` and the test for a non-zero file size in
553:ref:`ref-tasks-install` will return true, and the file will be installed.
554
Andrew Geissler5199d832021-09-24 16:47:35 -0500555Installing Additional Files Using Your Layer
556~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
557
558As another example, consider the main ``xserver-xf86-config`` recipe and a
559corresponding ``xserver-xf86-config`` append file both from the :term:`Source
560Directory`. Here is the main ``xserver-xf86-config`` recipe, which is named
561``xserver-xf86-config_0.1.bb`` and located in the "meta" layer at
562``meta/recipes-graphics/xorg-xserver``::
563
564 SUMMARY = "X.Org X server configuration file"
565 HOMEPAGE = "http://www.x.org"
566 SECTION = "x11/base"
567 LICENSE = "MIT-X"
568 LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
569 PR = "r33"
570
571 SRC_URI = "file://xorg.conf"
572
573 S = "${WORKDIR}"
574
575 CONFFILES:${PN} = "${sysconfdir}/X11/xorg.conf"
576
577 PACKAGE_ARCH = "${MACHINE_ARCH}"
578 ALLOW_EMPTY:${PN} = "1"
579
580 do_install () {
581 if test -s ${WORKDIR}/xorg.conf; then
582 install -d ${D}/${sysconfdir}/X11
583 install -m 0644 ${WORKDIR}/xorg.conf ${D}/${sysconfdir}/X11/
584 fi
585 }
586
587Following is the append file, which is named ``xserver-xf86-config_%.bbappend``
588and is from the Raspberry Pi BSP Layer named ``meta-raspberrypi``. The
589file is in the layer at ``recipes-graphics/xorg-xserver``::
590
591 FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
592
593 SRC_URI:append:rpi = " \
594 file://xorg.conf.d/98-pitft.conf \
595 file://xorg.conf.d/99-calibration.conf \
596 "
597 do_install:append:rpi () {
598 PITFT="${@bb.utils.contains("MACHINE_FEATURES", "pitft", "1", "0", d)}"
599 if [ "${PITFT}" = "1" ]; then
600 install -d ${D}/${sysconfdir}/X11/xorg.conf.d/
601 install -m 0644 ${WORKDIR}/xorg.conf.d/98-pitft.conf ${D}/${sysconfdir}/X11/xorg.conf.d/
602 install -m 0644 ${WORKDIR}/xorg.conf.d/99-calibration.conf ${D}/${sysconfdir}/X11/xorg.conf.d/
603 fi
604 }
605
606 FILES:${PN}:append:rpi = " ${sysconfdir}/X11/xorg.conf.d/*"
607
608Building off of the previous example, we once again are setting the
609:term:`FILESEXTRAPATHS` variable. In this case we are also using
610:term:`SRC_URI` to list additional source files to use when ``rpi`` is found in
611the list of :term:`OVERRIDES`. The :ref:`ref-tasks-install` task will then perform a
612check for an additional :term:`MACHINE_FEATURES` that if set will cause these
613additional files to be installed. These additional files are listed in
614:term:`FILES` so that they will be packaged.
615
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500616Prioritizing Your Layer
617-----------------------
618
619Each layer is assigned a priority value. Priority values control which
620layer takes precedence if there are recipe files with the same name in
621multiple layers. For these cases, the recipe file from the layer with a
622higher priority number takes precedence. Priority values also affect the
623order in which multiple ``.bbappend`` files for the same recipe are
624applied. You can either specify the priority manually, or allow the
625build system to calculate it based on the layer's dependencies.
626
627To specify the layer's priority manually, use the
628:term:`BBFILE_PRIORITY`
Andrew Geisslerc926e172021-05-07 16:11:35 -0500629variable and append the layer's root name::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500630
631 BBFILE_PRIORITY_mylayer = "1"
632
633.. note::
634
635 It is possible for a recipe with a lower version number
636 :term:`PV` in a layer that has a higher
637 priority to take precedence.
638
639 Also, the layer priority does not currently affect the precedence
640 order of ``.conf`` or ``.bbclass`` files. Future versions of BitBake
641 might address this.
642
643Managing Layers
644---------------
645
646You can use the BitBake layer management tool ``bitbake-layers`` to
647provide a view into the structure of recipes across a multi-layer
648project. Being able to generate output that reports on configured layers
649with their paths and priorities and on ``.bbappend`` files and their
650applicable recipes can help to reveal potential problems.
651
652For help on the BitBake layer management tool, use the following
Andrew Geisslerc926e172021-05-07 16:11:35 -0500653command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500654
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500655 $ bitbake-layers --help
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500656 NOTE: Starting bitbake server...
657 usage: bitbake-layers [-d] [-q] [-F] [--color COLOR] [-h] <subcommand> ...
658
659 BitBake layers utility
660
661 optional arguments:
662 -d, --debug Enable debug output
663 -q, --quiet Print only errors
664 -F, --force Force add without recipe parse verification
665 --color COLOR Colorize output (where COLOR is auto, always, never)
666 -h, --help show this help message and exit
667
668 subcommands:
669 <subcommand>
670 layerindex-fetch Fetches a layer from a layer index along with its
671 dependent layers, and adds them to conf/bblayers.conf.
672 layerindex-show-depends
673 Find layer dependencies from layer index.
674 add-layer Add one or more layers to bblayers.conf.
675 remove-layer Remove one or more layers from bblayers.conf.
676 flatten flatten layer configuration into a separate output
677 directory.
678 show-layers show current configured layers.
679 show-overlayed list overlayed recipes (where the same recipe exists
680 in another layer)
681 show-recipes list available recipes, showing the layer they are
682 provided by
683 show-appends list bbappend files and recipe files they apply to
684 show-cross-depends Show dependencies between recipes that cross layer
685 boundaries.
686 create-layer Create a basic layer
687
688 Use bitbake-layers <subcommand> --help to get help on a specific command
689
690The following list describes the available commands:
691
692- ``help:`` Displays general help or help on a specified command.
693
694- ``show-layers:`` Shows the current configured layers.
695
696- ``show-overlayed:`` Lists overlayed recipes. A recipe is overlayed
697 when a recipe with the same name exists in another layer that has a
698 higher layer priority.
699
700- ``show-recipes:`` Lists available recipes and the layers that
701 provide them.
702
703- ``show-appends:`` Lists ``.bbappend`` files and the recipe files to
704 which they apply.
705
706- ``show-cross-depends:`` Lists dependency relationships between
707 recipes that cross layer boundaries.
708
709- ``add-layer:`` Adds a layer to ``bblayers.conf``.
710
711- ``remove-layer:`` Removes a layer from ``bblayers.conf``
712
713- ``flatten:`` Flattens the layer configuration into a separate
714 output directory. Flattening your layer configuration builds a
715 "flattened" directory that contains the contents of all layers, with
716 any overlayed recipes removed and any ``.bbappend`` files appended to
717 the corresponding recipes. You might have to perform some manual
718 cleanup of the flattened layer as follows:
719
720 - Non-recipe files (such as patches) are overwritten. The flatten
721 command shows a warning for these files.
722
723 - Anything beyond the normal layer setup has been added to the
724 ``layer.conf`` file. Only the lowest priority layer's
725 ``layer.conf`` is used.
726
727 - Overridden and appended items from ``.bbappend`` files need to be
728 cleaned up. The contents of each ``.bbappend`` end up in the
729 flattened recipe. However, if there are appended or changed
730 variable values, you need to tidy these up yourself. Consider the
731 following example. Here, the ``bitbake-layers`` command adds the
732 line ``#### bbappended ...`` so that you know where the following
Andrew Geisslerc926e172021-05-07 16:11:35 -0500733 lines originate::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500734
735 ...
736 DESCRIPTION = "A useful utility"
737 ...
738 EXTRA_OECONF = "--enable-something"
739 ...
740
741 #### bbappended from meta-anotherlayer ####
742
743 DESCRIPTION = "Customized utility"
744 EXTRA_OECONF += "--enable-somethingelse"
745
746
Andrew Geisslerc926e172021-05-07 16:11:35 -0500747 Ideally, you would tidy up these utilities as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500748
749 ...
750 DESCRIPTION = "Customized utility"
751 ...
752 EXTRA_OECONF = "--enable-something --enable-somethingelse"
753 ...
754
755- ``layerindex-fetch``: Fetches a layer from a layer index, along
756 with its dependent layers, and adds the layers to the
757 ``conf/bblayers.conf`` file.
758
759- ``layerindex-show-depends``: Finds layer dependencies from the
760 layer index.
761
762- ``create-layer``: Creates a basic layer.
763
764Creating a General Layer Using the ``bitbake-layers`` Script
765------------------------------------------------------------
766
767The ``bitbake-layers`` script with the ``create-layer`` subcommand
768simplifies creating a new general layer.
769
770.. note::
771
772 - For information on BSP layers, see the ":ref:`bsp-guide/bsp:bsp layers`"
773 section in the Yocto
774 Project Board Specific (BSP) Developer's Guide.
775
776 - In order to use a layer with the OpenEmbedded build system, you
777 need to add the layer to your ``bblayers.conf`` configuration
Andrew Geissler09209ee2020-12-13 08:44:15 -0600778 file. See the ":ref:`dev-manual/common-tasks:adding a layer using the \`\`bitbake-layers\`\` script`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500779 section for more information.
780
781The default mode of the script's operation with this subcommand is to
782create a layer with the following:
783
784- A layer priority of 6.
785
786- A ``conf`` subdirectory that contains a ``layer.conf`` file.
787
788- A ``recipes-example`` subdirectory that contains a further
789 subdirectory named ``example``, which contains an ``example.bb``
790 recipe file.
791
792- A ``COPYING.MIT``, which is the license statement for the layer. The
793 script assumes you want to use the MIT license, which is typical for
794 most layers, for the contents of the layer itself.
795
796- A ``README`` file, which is a file describing the contents of your
797 new layer.
798
799In its simplest form, you can use the following command form to create a
800layer. The command creates a layer whose name corresponds to
Andrew Geisslerc926e172021-05-07 16:11:35 -0500801"your_layer_name" in the current directory::
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500802
803 $ bitbake-layers create-layer your_layer_name
804
805As an example, the following command creates a layer named ``meta-scottrif``
Andrew Geisslerc926e172021-05-07 16:11:35 -0500806in your home directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500807
808 $ cd /usr/home
809 $ bitbake-layers create-layer meta-scottrif
810 NOTE: Starting bitbake server...
811 Add your new layer with 'bitbake-layers add-layer meta-scottrif'
812
813If you want to set the priority of the layer to other than the default
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500814value of "6", you can either use the ``--priority`` option or you
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500815can edit the
816:term:`BBFILE_PRIORITY` value
817in the ``conf/layer.conf`` after the script creates it. Furthermore, if
818you want to give the example recipe file some name other than the
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500819default, you can use the ``--example-recipe-name`` option.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500820
821The easiest way to see how the ``bitbake-layers create-layer`` command
822works is to experiment with the script. You can also read the usage
Andrew Geisslerc926e172021-05-07 16:11:35 -0500823information by entering the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500824
825 $ bitbake-layers create-layer --help
826 NOTE: Starting bitbake server...
827 usage: bitbake-layers create-layer [-h] [--priority PRIORITY]
828 [--example-recipe-name EXAMPLERECIPE]
829 layerdir
830
831 Create a basic layer
832
833 positional arguments:
834 layerdir Layer directory to create
835
836 optional arguments:
837 -h, --help show this help message and exit
838 --priority PRIORITY, -p PRIORITY
839 Layer directory to create
840 --example-recipe-name EXAMPLERECIPE, -e EXAMPLERECIPE
841 Filename of the example recipe
842
843Adding a Layer Using the ``bitbake-layers`` Script
844--------------------------------------------------
845
846Once you create your general layer, you must add it to your
847``bblayers.conf`` file. Adding the layer to this configuration file
848makes the OpenEmbedded build system aware of your layer so that it can
849search it for metadata.
850
Andrew Geisslerc926e172021-05-07 16:11:35 -0500851Add your layer by using the ``bitbake-layers add-layer`` command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500852
853 $ bitbake-layers add-layer your_layer_name
854
855Here is an example that adds a
856layer named ``meta-scottrif`` to the configuration file. Following the
857command that adds the layer is another ``bitbake-layers`` command that
Andrew Geisslerc926e172021-05-07 16:11:35 -0500858shows the layers that are in your ``bblayers.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500859
860 $ bitbake-layers add-layer meta-scottrif
861 NOTE: Starting bitbake server...
862 Parsing recipes: 100% |##########################################################| Time: 0:00:49
863 Parsing of 1441 .bb files complete (0 cached, 1441 parsed). 2055 targets, 56 skipped, 0 masked, 0 errors.
864 $ bitbake-layers show-layers
865 NOTE: Starting bitbake server...
866 layer path priority
867 ==========================================================================
868 meta /home/scottrif/poky/meta 5
869 meta-poky /home/scottrif/poky/meta-poky 5
870 meta-yocto-bsp /home/scottrif/poky/meta-yocto-bsp 5
871 workspace /home/scottrif/poky/build/workspace 99
872 meta-scottrif /home/scottrif/poky/build/meta-scottrif 6
873
874
875Adding the layer to this file
876enables the build system to locate the layer during the build.
877
878.. note::
879
880 During a build, the OpenEmbedded build system looks in the layers
881 from the top of the list down to the bottom in that order.
882
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500883Customizing Images
884==================
885
886You can customize images to satisfy particular requirements. This
887section describes several methods and provides guidelines for each.
888
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500889Customizing Images Using ``local.conf``
890---------------------------------------
891
892Probably the easiest way to customize an image is to add a package by
893way of the ``local.conf`` configuration file. Because it is limited to
894local use, this method generally only allows you to add packages and is
895not as flexible as creating your own customized image. When you add
896packages using local variables this way, you need to realize that these
897variable changes are in effect for every build and consequently affect
898all images, which might not be what you require.
899
900To add a package to your image using the local configuration file, use
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500901the :term:`IMAGE_INSTALL` variable with the ``:append`` operator::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500902
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500903 IMAGE_INSTALL:append = " strace"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500904
Andrew Geissler5199d832021-09-24 16:47:35 -0500905Use of the syntax is important; specifically, the leading space
906after the opening quote and before the package name, which is
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500907``strace`` in this example. This space is required since the ``:append``
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500908operator does not add the space.
909
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500910Furthermore, you must use ``:append`` instead of the ``+=`` operator if
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500911you want to avoid ordering issues. The reason for this is because doing
912so unconditionally appends to the variable and avoids ordering problems
913due to the variable being set in image recipes and ``.bbclass`` files
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500914with operators like ``?=``. Using ``:append`` ensures the operation
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500915takes effect.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500916
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500917As shown in its simplest use, ``IMAGE_INSTALL:append`` affects all
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500918images. It is possible to extend the syntax so that the variable applies
Andrew Geisslerc926e172021-05-07 16:11:35 -0500919to a specific image only. Here is an example::
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500920
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500921 IMAGE_INSTALL:append:pn-core-image-minimal = " strace"
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500922
923This example adds ``strace`` to the ``core-image-minimal`` image only.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500924
925You can add packages using a similar approach through the
Andrew Geissler09036742021-06-25 14:25:14 -0500926:term:`CORE_IMAGE_EXTRA_INSTALL` variable. If you use this variable, only
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500927``core-image-*`` images are affected.
928
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500929Customizing Images Using Custom ``IMAGE_FEATURES`` and ``EXTRA_IMAGE_FEATURES``
930-------------------------------------------------------------------------------
931
932Another method for customizing your image is to enable or disable
933high-level image features by using the
934:term:`IMAGE_FEATURES` and
935:term:`EXTRA_IMAGE_FEATURES`
936variables. Although the functions for both variables are nearly
Andrew Geissler09036742021-06-25 14:25:14 -0500937equivalent, best practices dictate using :term:`IMAGE_FEATURES` from within
938a recipe and using :term:`EXTRA_IMAGE_FEATURES` from within your
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500939``local.conf`` file, which is found in the
940:term:`Build Directory`.
941
942To understand how these features work, the best reference is
Andrew Geissler595f6302022-01-24 19:11:47 +0000943:ref:`meta/classes/image.bbclass <ref-classes-image>`.
944This class lists out the available
Andrew Geissler09036742021-06-25 14:25:14 -0500945:term:`IMAGE_FEATURES` of which most map to package groups while some, such
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500946as ``debug-tweaks`` and ``read-only-rootfs``, resolve as general
947configuration settings.
948
Andrew Geissler09036742021-06-25 14:25:14 -0500949In summary, the file looks at the contents of the :term:`IMAGE_FEATURES`
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500950variable and then maps or configures the feature accordingly. Based on
951this information, the build system automatically adds the appropriate
952packages or configurations to the
953:term:`IMAGE_INSTALL` variable.
954Effectively, you are enabling extra features by extending the class or
955creating a custom class for use with specialized image ``.bb`` files.
956
Andrew Geissler09036742021-06-25 14:25:14 -0500957Use the :term:`EXTRA_IMAGE_FEATURES` variable from within your local
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500958configuration file. Using a separate area from which to enable features
959with this variable helps you avoid overwriting the features in the image
Andrew Geissler09036742021-06-25 14:25:14 -0500960recipe that are enabled with :term:`IMAGE_FEATURES`. The value of
961:term:`EXTRA_IMAGE_FEATURES` is added to :term:`IMAGE_FEATURES` within
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500962``meta/conf/bitbake.conf``.
963
964To illustrate how you can use these variables to modify your image,
965consider an example that selects the SSH server. The Yocto Project ships
966with two SSH servers you can use with your images: Dropbear and OpenSSH.
967Dropbear is a minimal SSH server appropriate for resource-constrained
968environments, while OpenSSH is a well-known standard SSH server
969implementation. By default, the ``core-image-sato`` image is configured
970to use Dropbear. The ``core-image-full-cmdline`` and ``core-image-lsb``
971images both include OpenSSH. The ``core-image-minimal`` image does not
972contain an SSH server.
973
974You can customize your image and change these defaults. Edit the
Andrew Geissler09036742021-06-25 14:25:14 -0500975:term:`IMAGE_FEATURES` variable in your recipe or use the
976:term:`EXTRA_IMAGE_FEATURES` in your ``local.conf`` file so that it
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500977configures the image you are working with to include
978``ssh-server-dropbear`` or ``ssh-server-openssh``.
979
980.. note::
981
Andrew Geissler09209ee2020-12-13 08:44:15 -0600982 See the ":ref:`ref-manual/features:image features`" section in the Yocto
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500983 Project Reference Manual for a complete list of image features that ship
984 with the Yocto Project.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500985
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500986Customizing Images Using Custom .bb Files
987-----------------------------------------
988
989You can also customize an image by creating a custom recipe that defines
990additional software as part of the image. The following example shows
Andrew Geisslerc926e172021-05-07 16:11:35 -0500991the form for the two lines you need::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500992
993 IMAGE_INSTALL = "packagegroup-core-x11-base package1 package2"
994 inherit core-image
995
996Defining the software using a custom recipe gives you total control over
997the contents of the image. It is important to use the correct names of
Andrew Geissler09036742021-06-25 14:25:14 -0500998packages in the :term:`IMAGE_INSTALL` variable. You must use the
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500999OpenEmbedded notation and not the Debian notation for the names (e.g.
1000``glibc-dev`` instead of ``libc6-dev``).
1001
1002The other method for creating a custom image is to base it on an
1003existing image. For example, if you want to create an image based on
1004``core-image-sato`` but add the additional package ``strace`` to the
1005image, copy the ``meta/recipes-sato/images/core-image-sato.bb`` to a new
Andrew Geisslerc926e172021-05-07 16:11:35 -05001006``.bb`` and add the following line to the end of the copy::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001007
1008 IMAGE_INSTALL += "strace"
1009
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001010Customizing Images Using Custom Package Groups
1011----------------------------------------------
1012
1013For complex custom images, the best approach for customizing an image is
1014to create a custom package group recipe that is used to build the image
1015or images. A good example of a package group recipe is
1016``meta/recipes-core/packagegroups/packagegroup-base.bb``.
1017
Andrew Geissler09036742021-06-25 14:25:14 -05001018If you examine that recipe, you see that the :term:`PACKAGES` variable lists
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001019the package group packages to produce. The ``inherit packagegroup``
1020statement sets appropriate default values and automatically adds
1021``-dev``, ``-dbg``, and ``-ptest`` complementary packages for each
Andrew Geissler09036742021-06-25 14:25:14 -05001022package specified in the :term:`PACKAGES` statement.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001023
1024.. note::
1025
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001026 The ``inherit packagegroup`` line should be located near the top of the
Andrew Geissler09036742021-06-25 14:25:14 -05001027 recipe, certainly before the :term:`PACKAGES` statement.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001028
Andrew Geissler09036742021-06-25 14:25:14 -05001029For each package you specify in :term:`PACKAGES`, you can use :term:`RDEPENDS`
1030and :term:`RRECOMMENDS` entries to provide a list of packages the parent
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001031task package should contain. You can see examples of these further down
1032in the ``packagegroup-base.bb`` recipe.
1033
1034Here is a short, fabricated example showing the same basic pieces for a
1035hypothetical packagegroup defined in ``packagegroup-custom.bb``, where
Andrew Geissler09036742021-06-25 14:25:14 -05001036the variable :term:`PN` is the standard way to abbreviate the reference to
Andrew Geisslerc926e172021-05-07 16:11:35 -05001037the full packagegroup name ``packagegroup-custom``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001038
1039 DESCRIPTION = "My Custom Package Groups"
1040
1041 inherit packagegroup
1042
1043 PACKAGES = "\
1044 ${PN}-apps \
1045 ${PN}-tools \
1046 "
1047
Patrick Williams0ca19cc2021-08-16 14:03:13 -05001048 RDEPENDS:${PN}-apps = "\
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001049 dropbear \
1050 portmap \
1051 psplash"
1052
Patrick Williams0ca19cc2021-08-16 14:03:13 -05001053 RDEPENDS:${PN}-tools = "\
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001054 oprofile \
1055 oprofileui-server \
1056 lttng-tools"
1057
Patrick Williams0ca19cc2021-08-16 14:03:13 -05001058 RRECOMMENDS:${PN}-tools = "\
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001059 kernel-module-oprofile"
1060
1061In the previous example, two package group packages are created with
1062their dependencies and their recommended package dependencies listed:
1063``packagegroup-custom-apps``, and ``packagegroup-custom-tools``. To
1064build an image using these package group packages, you need to add
1065``packagegroup-custom-apps`` and/or ``packagegroup-custom-tools`` to
Andrew Geissler09036742021-06-25 14:25:14 -05001066:term:`IMAGE_INSTALL`. For other forms of image dependencies see the other
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001067areas of this section.
1068
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001069Customizing an Image Hostname
1070-----------------------------
1071
1072By default, the configured hostname (i.e. ``/etc/hostname``) in an image
1073is the same as the machine name. For example, if
1074:term:`MACHINE` equals "qemux86", the
1075configured hostname written to ``/etc/hostname`` is "qemux86".
1076
1077You can customize this name by altering the value of the "hostname"
1078variable in the ``base-files`` recipe using either an append file or a
Andrew Geisslerc926e172021-05-07 16:11:35 -05001079configuration file. Use the following in an append file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001080
1081 hostname = "myhostname"
1082
Andrew Geisslerc926e172021-05-07 16:11:35 -05001083Use the following in a configuration file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001084
Patrick Williams0ca19cc2021-08-16 14:03:13 -05001085 hostname:pn-base-files = "myhostname"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001086
1087Changing the default value of the variable "hostname" can be useful in
1088certain situations. For example, suppose you need to do extensive
1089testing on an image and you would like to easily identify the image
1090under test from existing images with typical default hostnames. In this
1091situation, you could change the default hostname to "testme", which
1092results in all the images using the name "testme". Once testing is
1093complete and you do not need to rebuild the image for test any longer,
1094you can easily reset the default hostname.
1095
1096Another point of interest is that if you unset the variable, the image
1097will have no default hostname in the filesystem. Here is an example that
Andrew Geisslerc926e172021-05-07 16:11:35 -05001098unsets the variable in a configuration file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001099
Patrick Williams0ca19cc2021-08-16 14:03:13 -05001100 hostname:pn-base-files = ""
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001101
1102Having no default hostname in the filesystem is suitable for
1103environments that use dynamic hostnames such as virtual machines.
1104
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001105Writing a New Recipe
1106====================
1107
1108Recipes (``.bb`` files) are fundamental components in the Yocto Project
1109environment. Each software component built by the OpenEmbedded build
1110system requires a recipe to define the component. This section describes
1111how to create, write, and test a new recipe.
1112
1113.. note::
1114
1115 For information on variables that are useful for recipes and for
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001116 information about recipe naming issues, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001117 ":ref:`ref-manual/varlocality:recipes`" section of the Yocto Project
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001118 Reference Manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001119
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001120Overview
1121--------
1122
1123The following figure shows the basic process for creating a new recipe.
1124The remainder of the section provides details for the steps.
1125
1126.. image:: figures/recipe-workflow.png
1127 :align: center
1128
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001129Locate or Automatically Create a Base Recipe
1130--------------------------------------------
1131
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001132You can always write a recipe from scratch. However, there are three choices
1133that can help you quickly get started with a new recipe:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001134
1135- ``devtool add``: A command that assists in creating a recipe and an
1136 environment conducive to development.
1137
1138- ``recipetool create``: A command provided by the Yocto Project that
1139 automates creation of a base recipe based on the source files.
1140
1141- *Existing Recipes:* Location and modification of an existing recipe
1142 that is similar in function to the recipe you need.
1143
1144.. note::
1145
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001146 For information on recipe syntax, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001147 ":ref:`dev-manual/common-tasks:recipe syntax`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001148
1149Creating the Base Recipe Using ``devtool add``
1150~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1151
1152The ``devtool add`` command uses the same logic for auto-creating the
1153recipe as ``recipetool create``, which is listed below. Additionally,
1154however, ``devtool add`` sets up an environment that makes it easy for
1155you to patch the source and to make changes to the recipe as is often
1156necessary when adding a recipe to build a new piece of software to be
1157included in a build.
1158
1159You can find a complete description of the ``devtool add`` command in
Andrew Geissler09209ee2020-12-13 08:44:15 -06001160the ":ref:`sdk-manual/extensible:a closer look at \`\`devtool add\`\``" section
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001161in the Yocto Project Application Development and the Extensible Software
1162Development Kit (eSDK) manual.
1163
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001164Creating the Base Recipe Using ``recipetool create``
1165~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1166
1167``recipetool create`` automates creation of a base recipe given a set of
1168source code files. As long as you can extract or point to the source
1169files, the tool will construct a recipe and automatically configure all
1170pre-build information into the recipe. For example, suppose you have an
1171application that builds using Autotools. Creating the base recipe using
1172``recipetool`` results in a recipe that has the pre-build dependencies,
1173license requirements, and checksums configured.
1174
1175To run the tool, you just need to be in your
1176:term:`Build Directory` and have sourced the
1177build environment setup script (i.e.
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001178:ref:`structure-core-script`).
Andrew Geisslerc926e172021-05-07 16:11:35 -05001179To get help on the tool, use the following command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001180
1181 $ recipetool -h
1182 NOTE: Starting bitbake server...
1183 usage: recipetool [-d] [-q] [--color COLOR] [-h] <subcommand> ...
1184
1185 OpenEmbedded recipe tool
1186
1187 options:
1188 -d, --debug Enable debug output
1189 -q, --quiet Print only errors
1190 --color COLOR Colorize output (where COLOR is auto, always, never)
1191 -h, --help show this help message and exit
1192
1193 subcommands:
1194 create Create a new recipe
1195 newappend Create a bbappend for the specified target in the specified
1196 layer
1197 setvar Set a variable within a recipe
1198 appendfile Create/update a bbappend to replace a target file
1199 appendsrcfiles Create/update a bbappend to add or replace source files
1200 appendsrcfile Create/update a bbappend to add or replace a source file
1201 Use recipetool <subcommand> --help to get help on a specific command
1202
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001203Running ``recipetool create -o OUTFILE`` creates the base recipe and
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001204locates it properly in the layer that contains your source files.
1205Following are some syntax examples:
1206
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001207 - Use this syntax to generate a recipe based on source. Once generated,
Andrew Geisslerc926e172021-05-07 16:11:35 -05001208 the recipe resides in the existing source code layer::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001209
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001210 recipetool create -o OUTFILE source
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001211
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001212 - Use this syntax to generate a recipe using code that
1213 you extract from source. The extracted code is placed in its own layer
Andrew Geissler09036742021-06-25 14:25:14 -05001214 defined by :term:`EXTERNALSRC`.
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001215 ::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001216
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001217 recipetool create -o OUTFILE -x EXTERNALSRC source
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001218
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001219 - Use this syntax to generate a recipe based on source. The options
1220 direct ``recipetool`` to generate debugging information. Once generated,
Andrew Geisslerc926e172021-05-07 16:11:35 -05001221 the recipe resides in the existing source code layer::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001222
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001223 recipetool create -d -o OUTFILE source
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001224
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001225Locating and Using a Similar Recipe
1226~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1227
1228Before writing a recipe from scratch, it is often useful to discover
1229whether someone else has already written one that meets (or comes close
1230to meeting) your needs. The Yocto Project and OpenEmbedded communities
1231maintain many recipes that might be candidates for what you are doing.
Andrew Geisslerd1e89492021-02-12 15:35:20 -06001232You can find a good central index of these recipes in the
1233:oe_layerindex:`OpenEmbedded Layer Index <>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001234
1235Working from an existing recipe or a skeleton recipe is the best way to
1236get started. Here are some points on both methods:
1237
1238- *Locate and modify a recipe that is close to what you want to do:*
1239 This method works when you are familiar with the current recipe
1240 space. The method does not work so well for those new to the Yocto
1241 Project or writing recipes.
1242
1243 Some risks associated with this method are using a recipe that has
1244 areas totally unrelated to what you are trying to accomplish with
1245 your recipe, not recognizing areas of the recipe that you might have
1246 to add from scratch, and so forth. All these risks stem from
1247 unfamiliarity with the existing recipe space.
1248
1249- *Use and modify the following skeleton recipe:* If for some reason
1250 you do not want to use ``recipetool`` and you cannot find an existing
1251 recipe that is close to meeting your needs, you can use the following
1252 structure to provide the fundamental areas of a new recipe.
1253 ::
1254
1255 DESCRIPTION = ""
1256 HOMEPAGE = ""
1257 LICENSE = ""
1258 SECTION = ""
1259 DEPENDS = ""
1260 LIC_FILES_CHKSUM = ""
1261
1262 SRC_URI = ""
1263
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001264Storing and Naming the Recipe
1265-----------------------------
1266
1267Once you have your base recipe, you should put it in your own layer and
1268name it appropriately. Locating it correctly ensures that the
1269OpenEmbedded build system can find it when you use BitBake to process
1270the recipe.
1271
1272- *Storing Your Recipe:* The OpenEmbedded build system locates your
1273 recipe through the layer's ``conf/layer.conf`` file and the
1274 :term:`BBFILES` variable. This
1275 variable sets up a path from which the build system can locate
Andrew Geisslerc926e172021-05-07 16:11:35 -05001276 recipes. Here is the typical use::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001277
1278 BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
1279 ${LAYERDIR}/recipes-*/*/*.bbappend"
1280
1281 Consequently, you need to be sure you locate your new recipe inside
1282 your layer such that it can be found.
1283
1284 You can find more information on how layers are structured in the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001285 ":ref:`dev-manual/common-tasks:understanding and creating layers`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001286
1287- *Naming Your Recipe:* When you name your recipe, you need to follow
Andrew Geisslerc926e172021-05-07 16:11:35 -05001288 this naming convention::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001289
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001290 basename_version.bb
1291
1292 Use lower-cased characters and do not include the reserved suffixes
1293 ``-native``, ``-cross``, ``-initial``, or ``-dev`` casually (i.e. do not use
1294 them as part of your recipe name unless the string applies). Here are some
1295 examples:
1296
1297 .. code-block:: none
1298
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001299 cups_1.7.0.bb
1300 gawk_4.0.2.bb
1301 irssi_0.8.16-rc1.bb
1302
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001303Running a Build on the Recipe
1304-----------------------------
1305
1306Creating a new recipe is usually an iterative process that requires
1307using BitBake to process the recipe multiple times in order to
1308progressively discover and add information to the recipe file.
1309
1310Assuming you have sourced the build environment setup script (i.e.
1311:ref:`structure-core-script`) and you are in
1312the :term:`Build Directory`, use
1313BitBake to process your recipe. All you need to provide is the
Andrew Geisslerc926e172021-05-07 16:11:35 -05001314``basename`` of the recipe as described in the previous section::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001315
1316 $ bitbake basename
1317
1318During the build, the OpenEmbedded build system creates a temporary work
1319directory for each recipe
1320(``${``\ :term:`WORKDIR`\ ``}``)
1321where it keeps extracted source files, log files, intermediate
1322compilation and packaging files, and so forth.
1323
1324The path to the per-recipe temporary work directory depends on the
1325context in which it is being built. The quickest way to find this path
Andrew Geisslerc926e172021-05-07 16:11:35 -05001326is to have BitBake return it by running the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001327
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001328 $ bitbake -e basename | grep ^WORKDIR=
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001329
1330As an example, assume a Source Directory
1331top-level folder named ``poky``, a default Build Directory at
1332``poky/build``, and a ``qemux86-poky-linux`` machine target system.
1333Furthermore, suppose your recipe is named ``foo_1.3.0.bb``. In this
1334case, the work directory the build system uses to build the package
Andrew Geisslerc926e172021-05-07 16:11:35 -05001335would be as follows::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001336
1337 poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
1338
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001339Inside this directory you can find sub-directories such as ``image``,
1340``packages-split``, and ``temp``. After the build, you can examine these
1341to determine how well the build went.
1342
1343.. note::
1344
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001345 You can find log files for each task in the recipe's ``temp``
1346 directory (e.g. ``poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0/temp``).
1347 Log files are named ``log.taskname`` (e.g. ``log.do_configure``,
1348 ``log.do_fetch``, and ``log.do_compile``).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001349
1350You can find more information about the build process in
Andrew Geissler09209ee2020-12-13 08:44:15 -06001351":doc:`/overview-manual/development-environment`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001352chapter of the Yocto Project Overview and Concepts Manual.
1353
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001354Fetching Code
1355-------------
1356
1357The first thing your recipe must do is specify how to fetch the source
1358files. Fetching is controlled mainly through the
1359:term:`SRC_URI` variable. Your recipe
Andrew Geissler09036742021-06-25 14:25:14 -05001360must have a :term:`SRC_URI` variable that points to where the source is
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001361located. For a graphical representation of source locations, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001362":ref:`overview-manual/concepts:sources`" section in
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001363the Yocto Project Overview and Concepts Manual.
1364
1365The :ref:`ref-tasks-fetch` task uses
Andrew Geissler09036742021-06-25 14:25:14 -05001366the prefix of each entry in the :term:`SRC_URI` variable value to determine
Andrew Geissler09209ee2020-12-13 08:44:15 -06001367which :ref:`fetcher <bitbake:bitbake-user-manual/bitbake-user-manual-fetching:fetchers>` to use to get your
Andrew Geissler09036742021-06-25 14:25:14 -05001368source files. It is the :term:`SRC_URI` variable that triggers the fetcher.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001369The :ref:`ref-tasks-patch` task uses
1370the variable after source is fetched to apply patches. The OpenEmbedded
1371build system uses
1372:term:`FILESOVERRIDES` for
Andrew Geissler09036742021-06-25 14:25:14 -05001373scanning directory locations for local files in :term:`SRC_URI`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001374
Andrew Geissler09036742021-06-25 14:25:14 -05001375The :term:`SRC_URI` variable in your recipe must define each unique location
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001376for your source files. It is good practice to not hard-code version
Andrew Geissler5f350902021-07-23 13:09:54 -04001377numbers in a URL used in :term:`SRC_URI`. Rather than hard-code these
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001378values, use ``${``\ :term:`PV`\ ``}``,
1379which causes the fetch process to use the version specified in the
1380recipe filename. Specifying the version in this manner means that
1381upgrading the recipe to a future version is as simple as renaming the
1382recipe to match the new version.
1383
1384Here is a simple example from the
1385``meta/recipes-devtools/strace/strace_5.5.bb`` recipe where the source
1386comes from a single tarball. Notice the use of the
Andrew Geisslerc926e172021-05-07 16:11:35 -05001387:term:`PV` variable::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001388
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001389 SRC_URI = "https://strace.io/files/${PV}/strace-${PV}.tar.xz \
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001390
Andrew Geissler09036742021-06-25 14:25:14 -05001391Files mentioned in :term:`SRC_URI` whose names end in a typical archive
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001392extension (e.g. ``.tar``, ``.tar.gz``, ``.tar.bz2``, ``.zip``, and so
1393forth), are automatically extracted during the
1394:ref:`ref-tasks-unpack` task. For
1395another example that specifies these types of files, see the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001396":ref:`dev-manual/common-tasks:autotooled package`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001397
1398Another way of specifying source is from an SCM. For Git repositories,
1399you must specify :term:`SRCREV` and
1400you should specify :term:`PV` to include
1401the revision with :term:`SRCPV`. Here
1402is an example from the recipe
Andrew Geisslerc926e172021-05-07 16:11:35 -05001403``meta/recipes-kernel/blktrace/blktrace_git.bb``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001404
1405 SRCREV = "d6918c8832793b4205ed3bfede78c2f915c23385"
1406
1407 PR = "r6"
1408 PV = "1.0.5+git${SRCPV}"
1409
1410 SRC_URI = "git://git.kernel.dk/blktrace.git \
1411 file://ldflags.patch"
1412
Andrew Geissler09036742021-06-25 14:25:14 -05001413If your :term:`SRC_URI` statement includes URLs pointing to individual files
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001414fetched from a remote server other than a version control system,
1415BitBake attempts to verify the files against checksums defined in your
1416recipe to ensure they have not been tampered with or otherwise modified
1417since the recipe was written. Two checksums are used:
1418``SRC_URI[md5sum]`` and ``SRC_URI[sha256sum]``.
1419
Andrew Geissler09036742021-06-25 14:25:14 -05001420If your :term:`SRC_URI` variable points to more than a single URL (excluding
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001421SCM URLs), you need to provide the ``md5`` and ``sha256`` checksums for
1422each URL. For these cases, you provide a name for each URL as part of
Andrew Geissler09036742021-06-25 14:25:14 -05001423the :term:`SRC_URI` and then reference that name in the subsequent checksum
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001424statements. Here is an example combining lines from the files
Andrew Geisslerc926e172021-05-07 16:11:35 -05001425``git.inc`` and ``git_2.24.1.bb``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001426
1427 SRC_URI = "${KERNELORG_MIRROR}/software/scm/git/git-${PV}.tar.gz;name=tarball \
1428 ${KERNELORG_MIRROR}/software/scm/git/git-manpages-${PV}.tar.gz;name=manpages"
1429
1430 SRC_URI[tarball.md5sum] = "166bde96adbbc11c8843d4f8f4f9811b"
1431 SRC_URI[tarball.sha256sum] = "ad5334956301c86841eb1e5b1bb20884a6bad89a10a6762c958220c7cf64da02"
1432 SRC_URI[manpages.md5sum] = "31c2272a8979022497ba3d4202df145d"
1433 SRC_URI[manpages.sha256sum] = "9a7ae3a093bea39770eb96ca3e5b40bff7af0b9f6123f089d7821d0e5b8e1230"
1434
1435Proper values for ``md5`` and ``sha256`` checksums might be available
1436with other signatures on the download page for the upstream source (e.g.
1437``md5``, ``sha1``, ``sha256``, ``GPG``, and so forth). Because the
1438OpenEmbedded build system only deals with ``sha256sum`` and ``md5sum``,
1439you should verify all the signatures you find by hand.
1440
Andrew Geissler09036742021-06-25 14:25:14 -05001441If no :term:`SRC_URI` checksums are specified when you attempt to build the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001442recipe, or you provide an incorrect checksum, the build will produce an
1443error for each missing or incorrect checksum. As part of the error
1444message, the build system provides the checksum string corresponding to
1445the fetched file. Once you have the correct checksums, you can copy and
1446paste them into your recipe and then run the build again to continue.
1447
1448.. note::
1449
1450 As mentioned, if the upstream source provides signatures for
1451 verifying the downloaded source code, you should verify those
1452 manually before setting the checksum values in the recipe and
1453 continuing with the build.
1454
1455This final example is a bit more complicated and is from the
1456``meta/recipes-sato/rxvt-unicode/rxvt-unicode_9.20.bb`` recipe. The
Andrew Geissler09036742021-06-25 14:25:14 -05001457example's :term:`SRC_URI` statement identifies multiple files as the source
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001458files for the recipe: a tarball, a patch file, a desktop file, and an
1459icon.
1460::
1461
1462 SRC_URI = "http://dist.schmorp.de/rxvt-unicode/Attic/rxvt-unicode-${PV}.tar.bz2 \
1463 file://xwc.patch \
1464 file://rxvt.desktop \
1465 file://rxvt.png"
1466
1467When you specify local files using the ``file://`` URI protocol, the
1468build system fetches files from the local machine. The path is relative
1469to the :term:`FILESPATH` variable
1470and searches specific directories in a certain order:
1471``${``\ :term:`BP`\ ``}``,
1472``${``\ :term:`BPN`\ ``}``, and
1473``files``. The directories are assumed to be subdirectories of the
1474directory in which the recipe or append file resides. For another
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001475example that specifies these types of files, see the
1476":ref:`dev-manual/common-tasks:single .c file package (hello world!)`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001477
1478The previous example also specifies a patch file. Patch files are files
1479whose names usually end in ``.patch`` or ``.diff`` but can end with
1480compressed suffixes such as ``diff.gz`` and ``patch.bz2``, for example.
1481The build system automatically applies patches as described in the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001482":ref:`dev-manual/common-tasks:patching code`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001483
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001484Unpacking Code
1485--------------
1486
1487During the build, the
1488:ref:`ref-tasks-unpack` task unpacks
1489the source with ``${``\ :term:`S`\ ``}``
1490pointing to where it is unpacked.
1491
1492If you are fetching your source files from an upstream source archived
1493tarball and the tarball's internal structure matches the common
1494convention of a top-level subdirectory named
1495``${``\ :term:`BPN`\ ``}-${``\ :term:`PV`\ ``}``,
Andrew Geissler09036742021-06-25 14:25:14 -05001496then you do not need to set :term:`S`. However, if :term:`SRC_URI` specifies to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001497fetch source from an archive that does not use this convention, or from
Andrew Geissler09036742021-06-25 14:25:14 -05001498an SCM like Git or Subversion, your recipe needs to define :term:`S`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001499
1500If processing your recipe using BitBake successfully unpacks the source
1501files, you need to be sure that the directory pointed to by ``${S}``
1502matches the structure of the source.
1503
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001504Patching Code
1505-------------
1506
1507Sometimes it is necessary to patch code after it has been fetched. Any
Andrew Geissler09036742021-06-25 14:25:14 -05001508files mentioned in :term:`SRC_URI` whose names end in ``.patch`` or
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001509``.diff`` or compressed versions of these suffixes (e.g. ``diff.gz`` are
1510treated as patches. The
1511:ref:`ref-tasks-patch` task
1512automatically applies these patches.
1513
1514The build system should be able to apply patches with the "-p1" option
1515(i.e. one directory level in the path will be stripped off). If your
1516patch needs to have more directory levels stripped off, specify the
Andrew Geissler09036742021-06-25 14:25:14 -05001517number of levels using the "striplevel" option in the :term:`SRC_URI` entry
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001518for the patch. Alternatively, if your patch needs to be applied in a
1519specific subdirectory that is not specified in the patch file, use the
1520"patchdir" option in the entry.
1521
1522As with all local files referenced in
1523:term:`SRC_URI` using ``file://``,
1524you should place patch files in a directory next to the recipe either
1525named the same as the base name of the recipe
1526(:term:`BP` and
1527:term:`BPN`) or "files".
1528
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001529Licensing
1530---------
1531
1532Your recipe needs to have both the
1533:term:`LICENSE` and
1534:term:`LIC_FILES_CHKSUM`
1535variables:
1536
Andrew Geissler09036742021-06-25 14:25:14 -05001537- :term:`LICENSE`: This variable specifies the license for the software.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001538 If you do not know the license under which the software you are
1539 building is distributed, you should go to the source code and look
1540 for that information. Typical files containing this information
Andrew Geissler09036742021-06-25 14:25:14 -05001541 include ``COPYING``, :term:`LICENSE`, and ``README`` files. You could
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001542 also find the information near the top of a source file. For example,
1543 given a piece of software licensed under the GNU General Public
Andrew Geissler09036742021-06-25 14:25:14 -05001544 License version 2, you would set :term:`LICENSE` as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001545
1546 LICENSE = "GPLv2"
1547
Andrew Geissler09036742021-06-25 14:25:14 -05001548 The licenses you specify within :term:`LICENSE` can have any name as long
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001549 as you do not use spaces, since spaces are used as separators between
1550 license names. For standard licenses, use the names of the files in
Andrew Geissler09036742021-06-25 14:25:14 -05001551 ``meta/files/common-licenses/`` or the :term:`SPDXLICENSEMAP` flag names
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001552 defined in ``meta/conf/licenses.conf``.
1553
Andrew Geissler09036742021-06-25 14:25:14 -05001554- :term:`LIC_FILES_CHKSUM`: The OpenEmbedded build system uses this
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001555 variable to make sure the license text has not changed. If it has,
1556 the build produces an error and it affords you the chance to figure
1557 it out and correct the problem.
1558
1559 You need to specify all applicable licensing files for the software.
1560 At the end of the configuration step, the build process will compare
1561 the checksums of the files to be sure the text has not changed. Any
1562 differences result in an error with the message containing the
1563 current checksum. For more explanation and examples of how to set the
Andrew Geissler09036742021-06-25 14:25:14 -05001564 :term:`LIC_FILES_CHKSUM` variable, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001565 ":ref:`dev-manual/common-tasks:tracking license changes`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001566
1567 To determine the correct checksum string, you can list the
Andrew Geissler09036742021-06-25 14:25:14 -05001568 appropriate files in the :term:`LIC_FILES_CHKSUM` variable with incorrect
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001569 md5 strings, attempt to build the software, and then note the
1570 resulting error messages that will report the correct md5 strings.
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001571 See the ":ref:`dev-manual/common-tasks:fetching code`" section for
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001572 additional information.
1573
Andrew Geisslerc926e172021-05-07 16:11:35 -05001574 Here is an example that assumes the software has a ``COPYING`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001575
1576 LIC_FILES_CHKSUM = "file://COPYING;md5=xxx"
1577
1578 When you try to build the
1579 software, the build system will produce an error and give you the
1580 correct string that you can substitute into the recipe file for a
1581 subsequent build.
1582
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001583Dependencies
1584------------
1585
1586Most software packages have a short list of other packages that they
1587require, which are called dependencies. These dependencies fall into two
1588main categories: build-time dependencies, which are required when the
1589software is built; and runtime dependencies, which are required to be
1590installed on the target in order for the software to run.
1591
1592Within a recipe, you specify build-time dependencies using the
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001593:term:`DEPENDS` variable. Although there are nuances,
Andrew Geissler09036742021-06-25 14:25:14 -05001594items specified in :term:`DEPENDS` should be names of other
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001595recipes. It is important that you specify all build-time dependencies
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001596explicitly.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001597
1598Another consideration is that configure scripts might automatically
1599check for optional dependencies and enable corresponding functionality
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001600if those dependencies are found. If you wish to make a recipe that is
1601more generally useful (e.g. publish the recipe in a layer for others to
1602use), instead of hard-disabling the functionality, you can use the
1603:term:`PACKAGECONFIG` variable to allow functionality and the
1604corresponding dependencies to be enabled and disabled easily by other
1605users of the recipe.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001606
1607Similar to build-time dependencies, you specify runtime dependencies
1608through a variable -
1609:term:`RDEPENDS`, which is
1610package-specific. All variables that are package-specific need to have
1611the name of the package added to the end as an override. Since the main
1612package for a recipe has the same name as the recipe, and the recipe's
1613name can be found through the
1614``${``\ :term:`PN`\ ``}`` variable, then
1615you specify the dependencies for the main package by setting
Patrick Williams0ca19cc2021-08-16 14:03:13 -05001616``RDEPENDS:${PN}``. If the package were named ``${PN}-tools``, then you
1617would set ``RDEPENDS:${PN}-tools``, and so forth.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001618
1619Some runtime dependencies will be set automatically at packaging time.
1620These dependencies include any shared library dependencies (i.e. if a
1621package "example" contains "libexample" and another package "mypackage"
1622contains a binary that links to "libexample" then the OpenEmbedded build
1623system will automatically add a runtime dependency to "mypackage" on
1624"example"). See the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001625":ref:`overview-manual/concepts:automatically added runtime dependencies`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001626section in the Yocto Project Overview and Concepts Manual for further
1627details.
1628
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001629Configuring the Recipe
1630----------------------
1631
1632Most software provides some means of setting build-time configuration
1633options before compilation. Typically, setting these options is
1634accomplished by running a configure script with options, or by modifying
1635a build configuration file.
1636
1637.. note::
1638
1639 As of Yocto Project Release 1.7, some of the core recipes that
1640 package binary configuration scripts now disable the scripts due to
1641 the scripts previously requiring error-prone path substitution. The
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001642 OpenEmbedded build system uses ``pkg-config`` now, which is much more
1643 robust. You can find a list of the ``*-config`` scripts that are disabled
1644 in the ":ref:`migration-1.7-binary-configuration-scripts-disabled`" section
1645 in the Yocto Project Reference Manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001646
1647A major part of build-time configuration is about checking for
1648build-time dependencies and possibly enabling optional functionality as
1649a result. You need to specify any build-time dependencies for the
1650software you are building in your recipe's
1651:term:`DEPENDS` value, in terms of
1652other recipes that satisfy those dependencies. You can often find
1653build-time or runtime dependencies described in the software's
1654documentation.
1655
1656The following list provides configuration items of note based on how
1657your software is built:
1658
1659- *Autotools:* If your source files have a ``configure.ac`` file, then
1660 your software is built using Autotools. If this is the case, you just
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001661 need to modify the configuration.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001662
1663 When using Autotools, your recipe needs to inherit the
1664 :ref:`autotools <ref-classes-autotools>` class
1665 and your recipe does not have to contain a
1666 :ref:`ref-tasks-configure` task.
1667 However, you might still want to make some adjustments. For example,
1668 you can set
1669 :term:`EXTRA_OECONF` or
1670 :term:`PACKAGECONFIG_CONFARGS`
1671 to pass any needed configure options that are specific to the recipe.
1672
1673- *CMake:* If your source files have a ``CMakeLists.txt`` file, then
1674 your software is built using CMake. If this is the case, you just
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001675 need to modify the configuration.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001676
1677 When you use CMake, your recipe needs to inherit the
1678 :ref:`cmake <ref-classes-cmake>` class and your
1679 recipe does not have to contain a
1680 :ref:`ref-tasks-configure` task.
1681 You can make some adjustments by setting
1682 :term:`EXTRA_OECMAKE` to
1683 pass any needed configure options that are specific to the recipe.
1684
1685 .. note::
1686
1687 If you need to install one or more custom CMake toolchain files
1688 that are supplied by the application you are building, install the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001689 files to ``${D}${datadir}/cmake/Modules`` during ``do_install``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001690
1691- *Other:* If your source files do not have a ``configure.ac`` or
1692 ``CMakeLists.txt`` file, then your software is built using some
1693 method other than Autotools or CMake. If this is the case, you
1694 normally need to provide a
1695 :ref:`ref-tasks-configure` task
1696 in your recipe unless, of course, there is nothing to configure.
1697
1698 Even if your software is not being built by Autotools or CMake, you
1699 still might not need to deal with any configuration issues. You need
1700 to determine if configuration is even a required step. You might need
1701 to modify a Makefile or some configuration file used for the build to
1702 specify necessary build options. Or, perhaps you might need to run a
1703 provided, custom configure script with the appropriate options.
1704
1705 For the case involving a custom configure script, you would run
1706 ``./configure --help`` and look for the options you need to set.
1707
1708Once configuration succeeds, it is always good practice to look at the
1709``log.do_configure`` file to ensure that the appropriate options have
1710been enabled and no additional build-time dependencies need to be added
Andrew Geissler09036742021-06-25 14:25:14 -05001711to :term:`DEPENDS`. For example, if the configure script reports that it
1712found something not mentioned in :term:`DEPENDS`, or that it did not find
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001713something that it needed for some desired optional functionality, then
Andrew Geissler09036742021-06-25 14:25:14 -05001714you would need to add those to :term:`DEPENDS`. Looking at the log might
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001715also reveal items being checked for, enabled, or both that you do not
Andrew Geissler09036742021-06-25 14:25:14 -05001716want, or items not being found that are in :term:`DEPENDS`, in which case
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001717you would need to look at passing extra options to the configure script
1718as needed. For reference information on configure options specific to
1719the software you are building, you can consult the output of the
1720``./configure --help`` command within ``${S}`` or consult the software's
1721upstream documentation.
1722
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001723Using Headers to Interface with Devices
1724---------------------------------------
1725
1726If your recipe builds an application that needs to communicate with some
1727device or needs an API into a custom kernel, you will need to provide
1728appropriate header files. Under no circumstances should you ever modify
1729the existing
1730``meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc`` file.
1731These headers are used to build ``libc`` and must not be compromised
1732with custom or machine-specific header information. If you customize
1733``libc`` through modified headers all other applications that use
1734``libc`` thus become affected.
1735
1736.. note::
1737
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001738 Never copy and customize the ``libc`` header file (i.e.
1739 ``meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc``).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001740
1741The correct way to interface to a device or custom kernel is to use a
1742separate package that provides the additional headers for the driver or
1743other unique interfaces. When doing so, your application also becomes
1744responsible for creating a dependency on that specific provider.
1745
1746Consider the following:
1747
1748- Never modify ``linux-libc-headers.inc``. Consider that file to be
1749 part of the ``libc`` system, and not something you use to access the
1750 kernel directly. You should access ``libc`` through specific ``libc``
1751 calls.
1752
1753- Applications that must talk directly to devices should either provide
1754 necessary headers themselves, or establish a dependency on a special
1755 headers package that is specific to that driver.
1756
1757For example, suppose you want to modify an existing header that adds I/O
1758control or network support. If the modifications are used by a small
1759number programs, providing a unique version of a header is easy and has
1760little impact. When doing so, bear in mind the guidelines in the
1761previous list.
1762
1763.. note::
1764
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001765 If for some reason your changes need to modify the behavior of the ``libc``,
1766 and subsequently all other applications on the system, use a ``.bbappend``
1767 to modify the ``linux-kernel-headers.inc`` file. However, take care to not
1768 make the changes machine specific.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001769
1770Consider a case where your kernel is older and you need an older
1771``libc`` ABI. The headers installed by your recipe should still be a
1772standard mainline kernel, not your own custom one.
1773
1774When you use custom kernel headers you need to get them from
1775:term:`STAGING_KERNEL_DIR`,
1776which is the directory with kernel headers that are required to build
Andrew Geisslerc926e172021-05-07 16:11:35 -05001777out-of-tree modules. Your recipe will also need the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001778
1779 do_configure[depends] += "virtual/kernel:do_shared_workdir"
1780
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001781Compilation
1782-----------
1783
1784During a build, the ``do_compile`` task happens after source is fetched,
1785unpacked, and configured. If the recipe passes through ``do_compile``
1786successfully, nothing needs to be done.
1787
1788However, if the compile step fails, you need to diagnose the failure.
1789Here are some common issues that cause failures.
1790
1791.. note::
1792
1793 For cases where improper paths are detected for configuration files
1794 or for when libraries/headers cannot be found, be sure you are using
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001795 the more robust ``pkg-config``. See the note in section
Andrew Geissler09209ee2020-12-13 08:44:15 -06001796 ":ref:`dev-manual/common-tasks:Configuring the Recipe`" for additional information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001797
1798- *Parallel build failures:* These failures manifest themselves as
1799 intermittent errors, or errors reporting that a file or directory
1800 that should be created by some other part of the build process could
1801 not be found. This type of failure can occur even if, upon
1802 inspection, the file or directory does exist after the build has
1803 failed, because that part of the build process happened in the wrong
1804 order.
1805
1806 To fix the problem, you need to either satisfy the missing dependency
1807 in the Makefile or whatever script produced the Makefile, or (as a
Andrew Geisslerc926e172021-05-07 16:11:35 -05001808 workaround) set :term:`PARALLEL_MAKE` to an empty string::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001809
1810 PARALLEL_MAKE = ""
1811
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001812 For information on parallel Makefile issues, see the
1813 ":ref:`dev-manual/common-tasks:debugging parallel make races`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001814
1815- *Improper host path usage:* This failure applies to recipes building
1816 for the target or ``nativesdk`` only. The failure occurs when the
1817 compilation process uses improper headers, libraries, or other files
1818 from the host system when cross-compiling for the target.
1819
1820 To fix the problem, examine the ``log.do_compile`` file to identify
1821 the host paths being used (e.g. ``/usr/include``, ``/usr/lib``, and
1822 so forth) and then either add configure options, apply a patch, or do
1823 both.
1824
1825- *Failure to find required libraries/headers:* If a build-time
1826 dependency is missing because it has not been declared in
1827 :term:`DEPENDS`, or because the
1828 dependency exists but the path used by the build process to find the
1829 file is incorrect and the configure step did not detect it, the
1830 compilation process could fail. For either of these failures, the
1831 compilation process notes that files could not be found. In these
1832 cases, you need to go back and add additional options to the
1833 configure script as well as possibly add additional build-time
Andrew Geissler09036742021-06-25 14:25:14 -05001834 dependencies to :term:`DEPENDS`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001835
1836 Occasionally, it is necessary to apply a patch to the source to
1837 ensure the correct paths are used. If you need to specify paths to
1838 find files staged into the sysroot from other recipes, use the
1839 variables that the OpenEmbedded build system provides (e.g.
Andrew Geissler09036742021-06-25 14:25:14 -05001840 :term:`STAGING_BINDIR`, :term:`STAGING_INCDIR`, :term:`STAGING_DATADIR`, and so
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001841 forth).
1842
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001843Installing
1844----------
1845
1846During ``do_install``, the task copies the built files along with their
1847hierarchy to locations that would mirror their locations on the target
1848device. The installation process copies files from the
1849``${``\ :term:`S`\ ``}``,
1850``${``\ :term:`B`\ ``}``, and
1851``${``\ :term:`WORKDIR`\ ``}``
1852directories to the ``${``\ :term:`D`\ ``}``
1853directory to create the structure as it should appear on the target
1854system.
1855
1856How your software is built affects what you must do to be sure your
1857software is installed correctly. The following list describes what you
1858must do for installation depending on the type of build system used by
1859the software being built:
1860
1861- *Autotools and CMake:* If the software your recipe is building uses
1862 Autotools or CMake, the OpenEmbedded build system understands how to
1863 install the software. Consequently, you do not have to have a
1864 ``do_install`` task as part of your recipe. You just need to make
1865 sure the install portion of the build completes with no issues.
1866 However, if you wish to install additional files not already being
1867 installed by ``make install``, you should do this using a
Patrick Williams0ca19cc2021-08-16 14:03:13 -05001868 ``do_install:append`` function using the install command as described
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001869 in the "Manual" bulleted item later in this list.
1870
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001871- *Other (using* ``make install``\ *)*: You need to define a ``do_install``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001872 function in your recipe. The function should call
1873 ``oe_runmake install`` and will likely need to pass in the
1874 destination directory as well. How you pass that path is dependent on
1875 how the ``Makefile`` being run is written (e.g. ``DESTDIR=${D}``,
1876 ``PREFIX=${D}``, ``INSTALLROOT=${D}``, and so forth).
1877
1878 For an example recipe using ``make install``, see the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001879 ":ref:`dev-manual/common-tasks:makefile-based package`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001880
1881- *Manual:* You need to define a ``do_install`` function in your
1882 recipe. The function must first use ``install -d`` to create the
1883 directories under
1884 ``${``\ :term:`D`\ ``}``. Once the
1885 directories exist, your function can use ``install`` to manually
1886 install the built software into the directories.
1887
1888 You can find more information on ``install`` at
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001889 https://www.gnu.org/software/coreutils/manual/html_node/install-invocation.html.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001890
1891For the scenarios that do not use Autotools or CMake, you need to track
1892the installation and diagnose and fix any issues until everything
1893installs correctly. You need to look in the default location of
1894``${D}``, which is ``${WORKDIR}/image``, to be sure your files have been
1895installed correctly.
1896
1897.. note::
1898
1899 - During the installation process, you might need to modify some of
1900 the installed files to suit the target layout. For example, you
1901 might need to replace hard-coded paths in an initscript with
1902 values of variables provided by the build system, such as
1903 replacing ``/usr/bin/`` with ``${bindir}``. If you do perform such
1904 modifications during ``do_install``, be sure to modify the
1905 destination file after copying rather than before copying.
1906 Modifying after copying ensures that the build system can
1907 re-execute ``do_install`` if needed.
1908
1909 - ``oe_runmake install``, which can be run directly or can be run
1910 indirectly by the
1911 :ref:`autotools <ref-classes-autotools>` and
1912 :ref:`cmake <ref-classes-cmake>` classes,
1913 runs ``make install`` in parallel. Sometimes, a Makefile can have
1914 missing dependencies between targets that can result in race
1915 conditions. If you experience intermittent failures during
1916 ``do_install``, you might be able to work around them by disabling
Andrew Geisslerc926e172021-05-07 16:11:35 -05001917 parallel Makefile installs by adding the following to the recipe::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001918
1919 PARALLEL_MAKEINST = ""
1920
1921 See :term:`PARALLEL_MAKEINST` for additional information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001922
1923 - If you need to install one or more custom CMake toolchain files
1924 that are supplied by the application you are building, install the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001925 files to ``${D}${datadir}/cmake/Modules`` during
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001926 :ref:`ref-tasks-install`.
1927
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001928Enabling System Services
1929------------------------
1930
1931If you want to install a service, which is a process that usually starts
1932on boot and runs in the background, then you must include some
1933additional definitions in your recipe.
1934
1935If you are adding services and the service initialization script or the
1936service file itself is not installed, you must provide for that
Patrick Williams0ca19cc2021-08-16 14:03:13 -05001937installation in your recipe using a ``do_install:append`` function. If
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001938your recipe already has a ``do_install`` function, update the function
Patrick Williams0ca19cc2021-08-16 14:03:13 -05001939near its end rather than adding an additional ``do_install:append``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001940function.
1941
1942When you create the installation for your services, you need to
1943accomplish what is normally done by ``make install``. In other words,
1944make sure your installation arranges the output similar to how it is
1945arranged on the target system.
1946
1947The OpenEmbedded build system provides support for starting services two
1948different ways:
1949
1950- *SysVinit:* SysVinit is a system and service manager that manages the
1951 init system used to control the very basic functions of your system.
1952 The init program is the first program started by the Linux kernel
1953 when the system boots. Init then controls the startup, running and
1954 shutdown of all other programs.
1955
1956 To enable a service using SysVinit, your recipe needs to inherit the
1957 :ref:`update-rc.d <ref-classes-update-rc.d>`
1958 class. The class helps facilitate safely installing the package on
1959 the target.
1960
1961 You will need to set the
1962 :term:`INITSCRIPT_PACKAGES`,
1963 :term:`INITSCRIPT_NAME`,
1964 and
1965 :term:`INITSCRIPT_PARAMS`
1966 variables within your recipe.
1967
1968- *systemd:* System Management Daemon (systemd) was designed to replace
1969 SysVinit and to provide enhanced management of services. For more
1970 information on systemd, see the systemd homepage at
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001971 https://freedesktop.org/wiki/Software/systemd/.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001972
1973 To enable a service using systemd, your recipe needs to inherit the
1974 :ref:`systemd <ref-classes-systemd>` class. See
1975 the ``systemd.bbclass`` file located in your :term:`Source Directory`
1976 section for
1977 more information.
1978
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001979Packaging
1980---------
1981
1982Successful packaging is a combination of automated processes performed
1983by the OpenEmbedded build system and some specific steps you need to
1984take. The following list describes the process:
1985
1986- *Splitting Files*: The ``do_package`` task splits the files produced
1987 by the recipe into logical components. Even software that produces a
1988 single binary might still have debug symbols, documentation, and
1989 other logical components that should be split out. The ``do_package``
1990 task ensures that files are split up and packaged correctly.
1991
1992- *Running QA Checks*: The
1993 :ref:`insane <ref-classes-insane>` class adds a
1994 step to the package generation process so that output quality
1995 assurance checks are generated by the OpenEmbedded build system. This
1996 step performs a range of checks to be sure the build's output is free
1997 of common problems that show up during runtime. For information on
1998 these checks, see the
1999 :ref:`insane <ref-classes-insane>` class and
Andrew Geissler09209ee2020-12-13 08:44:15 -06002000 the ":ref:`ref-manual/qa-checks:qa error and warning messages`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002001 chapter in the Yocto Project Reference Manual.
2002
2003- *Hand-Checking Your Packages*: After you build your software, you
2004 need to be sure your packages are correct. Examine the
2005 ``${``\ :term:`WORKDIR`\ ``}/packages-split``
2006 directory and make sure files are where you expect them to be. If you
2007 discover problems, you can set
2008 :term:`PACKAGES`,
2009 :term:`FILES`,
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002010 ``do_install(:append)``, and so forth as needed.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002011
2012- *Splitting an Application into Multiple Packages*: If you need to
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05002013 split an application into several packages, see the
2014 ":ref:`dev-manual/common-tasks:splitting an application into multiple packages`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002015 section for an example.
2016
2017- *Installing a Post-Installation Script*: For an example showing how
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05002018 to install a post-installation script, see the
2019 ":ref:`dev-manual/common-tasks:post-installation scripts`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002020
2021- *Marking Package Architecture*: Depending on what your recipe is
2022 building and how it is configured, it might be important to mark the
2023 packages produced as being specific to a particular machine, or to
2024 mark them as not being specific to a particular machine or
2025 architecture at all.
2026
2027 By default, packages apply to any machine with the same architecture
2028 as the target machine. When a recipe produces packages that are
2029 machine-specific (e.g. the
2030 :term:`MACHINE` value is passed
2031 into the configure script or a patch is applied only for a particular
2032 machine), you should mark them as such by adding the following to the
Andrew Geisslerc926e172021-05-07 16:11:35 -05002033 recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002034
2035 PACKAGE_ARCH = "${MACHINE_ARCH}"
2036
2037 On the other hand, if the recipe produces packages that do not
2038 contain anything specific to the target machine or architecture at
2039 all (e.g. recipes that simply package script files or configuration
2040 files), you should use the
2041 :ref:`allarch <ref-classes-allarch>` class to
Andrew Geisslerc926e172021-05-07 16:11:35 -05002042 do this for you by adding this to your recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002043
2044 inherit allarch
2045
2046 Ensuring that the package architecture is correct is not critical
2047 while you are doing the first few builds of your recipe. However, it
2048 is important in order to ensure that your recipe rebuilds (or does
2049 not rebuild) appropriately in response to changes in configuration,
2050 and to ensure that you get the appropriate packages installed on the
2051 target machine, particularly if you run separate builds for more than
2052 one target machine.
2053
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002054Sharing Files Between Recipes
2055-----------------------------
2056
2057Recipes often need to use files provided by other recipes on the build
2058host. For example, an application linking to a common library needs
2059access to the library itself and its associated headers. The way this
2060access is accomplished is by populating a sysroot with files. Each
2061recipe has two sysroots in its work directory, one for target files
2062(``recipe-sysroot``) and one for files that are native to the build host
2063(``recipe-sysroot-native``).
2064
2065.. note::
2066
2067 You could find the term "staging" used within the Yocto project
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002068 regarding files populating sysroots (e.g. the :term:`STAGING_DIR`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002069 variable).
2070
2071Recipes should never populate the sysroot directly (i.e. write files
2072into sysroot). Instead, files should be installed into standard
2073locations during the
2074:ref:`ref-tasks-install` task within
2075the ``${``\ :term:`D`\ ``}`` directory. The
2076reason for this limitation is that almost all files that populate the
2077sysroot are cataloged in manifests in order to ensure the files can be
2078removed later when a recipe is either modified or removed. Thus, the
2079sysroot is able to remain free from stale files.
2080
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05002081A subset of the files installed by the :ref:`ref-tasks-install` task are
2082used by the :ref:`ref-tasks-populate_sysroot` task as defined by the the
2083:term:`SYSROOT_DIRS` variable to automatically populate the sysroot. It
2084is possible to modify the list of directories that populate the sysroot.
2085The following example shows how you could add the ``/opt`` directory to
Andrew Geisslerc926e172021-05-07 16:11:35 -05002086the list of directories within a recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002087
2088 SYSROOT_DIRS += "/opt"
2089
Andrew Geisslerd1e89492021-02-12 15:35:20 -06002090.. note::
2091
2092 The `/sysroot-only` is to be used by recipes that generate artifacts
2093 that are not included in the target filesystem, allowing them to share
Andrew Geissler09036742021-06-25 14:25:14 -05002094 these artifacts without needing to use the :term:`DEPLOY_DIR`.
Andrew Geisslerd1e89492021-02-12 15:35:20 -06002095
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05002096For a more complete description of the :ref:`ref-tasks-populate_sysroot`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002097task and its associated functions, see the
2098:ref:`staging <ref-classes-staging>` class.
2099
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002100Using Virtual Providers
2101-----------------------
2102
2103Prior to a build, if you know that several different recipes provide the
2104same functionality, you can use a virtual provider (i.e. ``virtual/*``)
2105as a placeholder for the actual provider. The actual provider is
2106determined at build-time.
2107
2108A common scenario where a virtual provider is used would be for the
2109kernel recipe. Suppose you have three kernel recipes whose
2110:term:`PN` values map to ``kernel-big``,
2111``kernel-mid``, and ``kernel-small``. Furthermore, each of these recipes
2112in some way uses a :term:`PROVIDES`
2113statement that essentially identifies itself as being able to provide
2114``virtual/kernel``. Here is one way through the
Andrew Geisslerc926e172021-05-07 16:11:35 -05002115:ref:`kernel <ref-classes-kernel>` class::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002116
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002117 PROVIDES += "virtual/kernel"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002118
Andrew Geissler595f6302022-01-24 19:11:47 +00002119Any recipe that inherits the :ref:`kernel <ref-classes-kernel>` class is
Andrew Geissler09036742021-06-25 14:25:14 -05002120going to utilize a :term:`PROVIDES` statement that identifies that recipe as
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002121being able to provide the ``virtual/kernel`` item.
2122
2123Now comes the time to actually build an image and you need a kernel
2124recipe, but which one? You can configure your build to call out the
Andrew Geissler09209ee2020-12-13 08:44:15 -06002125kernel recipe you want by using the :term:`PREFERRED_PROVIDER` variable. As
2126an example, consider the :yocto_git:`x86-base.inc
Andrew Geisslerd159c7f2021-09-02 21:05:58 -05002127</poky/tree/meta/conf/machine/include/x86/x86-base.inc>` include file, which is a
Andrew Geissler09209ee2020-12-13 08:44:15 -06002128machine (i.e. :term:`MACHINE`) configuration file. This include file is the
2129reason all x86-based machines use the ``linux-yocto`` kernel. Here are the
Andrew Geisslerc926e172021-05-07 16:11:35 -05002130relevant lines from the include file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002131
2132 PREFERRED_PROVIDER_virtual/kernel ??= "linux-yocto"
2133 PREFERRED_VERSION_linux-yocto ??= "4.15%"
2134
2135When you use a virtual provider, you do not have to "hard code" a recipe
2136name as a build dependency. You can use the
2137:term:`DEPENDS` variable to state the
Andrew Geisslerc926e172021-05-07 16:11:35 -05002138build is dependent on ``virtual/kernel`` for example::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002139
2140 DEPENDS = "virtual/kernel"
2141
2142During the build, the OpenEmbedded build system picks
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002143the correct recipe needed for the ``virtual/kernel`` dependency based on
Andrew Geissler09036742021-06-25 14:25:14 -05002144the :term:`PREFERRED_PROVIDER` variable. If you want to use the small kernel
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002145mentioned at the beginning of this section, configure your build as
Andrew Geisslerc926e172021-05-07 16:11:35 -05002146follows::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002147
2148 PREFERRED_PROVIDER_virtual/kernel ??= "kernel-small"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002149
2150.. note::
2151
Andrew Geissler09036742021-06-25 14:25:14 -05002152 Any recipe that :term:`PROVIDES` a ``virtual/*`` item that is ultimately not
2153 selected through :term:`PREFERRED_PROVIDER` does not get built. Preventing these
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002154 recipes from building is usually the desired behavior since this mechanism's
2155 purpose is to select between mutually exclusive alternative providers.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002156
2157The following lists specific examples of virtual providers:
2158
2159- ``virtual/kernel``: Provides the name of the kernel recipe to use
2160 when building a kernel image.
2161
2162- ``virtual/bootloader``: Provides the name of the bootloader to use
2163 when building an image.
2164
2165- ``virtual/libgbm``: Provides ``gbm.pc``.
2166
2167- ``virtual/egl``: Provides ``egl.pc`` and possibly ``wayland-egl.pc``.
2168
2169- ``virtual/libgl``: Provides ``gl.pc`` (i.e. libGL).
2170
2171- ``virtual/libgles1``: Provides ``glesv1_cm.pc`` (i.e. libGLESv1_CM).
2172
2173- ``virtual/libgles2``: Provides ``glesv2.pc`` (i.e. libGLESv2).
2174
2175.. note::
2176
2177 Virtual providers only apply to build time dependencies specified with
2178 :term:`PROVIDES` and :term:`DEPENDS`. They do not apply to runtime
2179 dependencies specified with :term:`RPROVIDES` and :term:`RDEPENDS`.
2180
2181Properly Versioning Pre-Release Recipes
2182---------------------------------------
2183
2184Sometimes the name of a recipe can lead to versioning problems when the
2185recipe is upgraded to a final release. For example, consider the
2186``irssi_0.8.16-rc1.bb`` recipe file in the list of example recipes in
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05002187the ":ref:`dev-manual/common-tasks:storing and naming the recipe`" section.
2188This recipe is at a release candidate stage (i.e. "rc1"). When the recipe is
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002189released, the recipe filename becomes ``irssi_0.8.16.bb``. The version
2190change from ``0.8.16-rc1`` to ``0.8.16`` is seen as a decrease by the
2191build system and package managers, so the resulting packages will not
2192correctly trigger an upgrade.
2193
2194In order to ensure the versions compare properly, the recommended
2195convention is to set :term:`PV` within the
2196recipe to "previous_version+current_version". You can use an additional
2197variable so that you can use the current version elsewhere. Here is an
Andrew Geisslerc926e172021-05-07 16:11:35 -05002198example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002199
2200 REALPV = "0.8.16-rc1"
2201 PV = "0.8.15+${REALPV}"
2202
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002203Post-Installation Scripts
2204-------------------------
2205
2206Post-installation scripts run immediately after installing a package on
2207the target or during image creation when a package is included in an
2208image. To add a post-installation script to a package, add a
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002209``pkg_postinst:``\ `PACKAGENAME`\ ``()`` function to the recipe file
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002210(``.bb``) and replace `PACKAGENAME` with the name of the package you want
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002211to attach to the ``postinst`` script. To apply the post-installation
2212script to the main package for the recipe, which is usually what is
2213required, specify
2214``${``\ :term:`PN`\ ``}`` in place of
2215PACKAGENAME.
2216
Andrew Geisslerc926e172021-05-07 16:11:35 -05002217A post-installation function has the following structure::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002218
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002219 pkg_postinst:PACKAGENAME() {
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002220 # Commands to carry out
2221 }
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002222
2223The script defined in the post-installation function is called when the
2224root filesystem is created. If the script succeeds, the package is
2225marked as installed.
2226
2227.. note::
2228
2229 Any RPM post-installation script that runs on the target should
2230 return a 0 exit code. RPM does not allow non-zero exit codes for
2231 these scripts, and the RPM package manager will cause the package to
2232 fail installation on the target.
2233
2234Sometimes it is necessary for the execution of a post-installation
2235script to be delayed until the first boot. For example, the script might
2236need to be executed on the device itself. To delay script execution
2237until boot time, you must explicitly mark post installs to defer to the
2238target. You can use ``pkg_postinst_ontarget()`` or call
2239``postinst_intercept delay_to_first_boot`` from ``pkg_postinst()``. Any
2240failure of a ``pkg_postinst()`` script (including exit 1) triggers an
2241error during the
2242:ref:`ref-tasks-rootfs` task.
2243
2244If you have recipes that use ``pkg_postinst`` function and they require
2245the use of non-standard native tools that have dependencies during
Andrew Geissler595f6302022-01-24 19:11:47 +00002246root filesystem construction, you need to use the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002247:term:`PACKAGE_WRITE_DEPS`
2248variable in your recipe to list these tools. If you do not use this
2249variable, the tools might be missing and execution of the
2250post-installation script is deferred until first boot. Deferring the
Andrew Geissler595f6302022-01-24 19:11:47 +00002251script to the first boot is undesirable and impossible for read-only
2252root filesystems.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002253
2254.. note::
2255
William A. Kennington IIIac69b482021-06-02 12:28:27 -07002256 There is equivalent support for pre-install, pre-uninstall, and post-uninstall
2257 scripts by way of ``pkg_preinst``, ``pkg_prerm``, and ``pkg_postrm``,
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002258 respectively. These scrips work in exactly the same way as does
2259 ``pkg_postinst`` with the exception that they run at different times. Also,
2260 because of when they run, they are not applicable to being run at image
2261 creation time like ``pkg_postinst``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002262
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002263Testing
2264-------
2265
2266The final step for completing your recipe is to be sure that the
2267software you built runs correctly. To accomplish runtime testing, add
2268the build's output packages to your image and test them on the target.
2269
2270For information on how to customize your image by adding specific
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05002271packages, see ":ref:`dev-manual/common-tasks:customizing images`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002272
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002273Examples
2274--------
2275
2276To help summarize how to write a recipe, this section provides some
2277examples given various scenarios:
2278
2279- Recipes that use local files
2280
2281- Using an Autotooled package
2282
2283- Using a Makefile-based package
2284
2285- Splitting an application into multiple packages
2286
2287- Adding binaries to an image
2288
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002289Single .c File Package (Hello World!)
2290~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2291
2292Building an application from a single file that is stored locally (e.g.
2293under ``files``) requires a recipe that has the file listed in the
Andrew Geissler09036742021-06-25 14:25:14 -05002294:term:`SRC_URI` variable. Additionally, you need to manually write the
2295``do_compile`` and ``do_install`` tasks. The :term:`S` variable defines the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002296directory containing the source code, which is set to
2297:term:`WORKDIR` in this case - the
2298directory BitBake uses for the build.
2299::
2300
2301 SUMMARY = "Simple helloworld application"
2302 SECTION = "examples"
2303 LICENSE = "MIT"
2304 LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
2305
2306 SRC_URI = "file://helloworld.c"
2307
2308 S = "${WORKDIR}"
2309
2310 do_compile() {
Andrew Geisslerd1e89492021-02-12 15:35:20 -06002311 ${CC} ${LDFLAGS} helloworld.c -o helloworld
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002312 }
2313
2314 do_install() {
2315 install -d ${D}${bindir}
2316 install -m 0755 helloworld ${D}${bindir}
2317 }
2318
2319By default, the ``helloworld``, ``helloworld-dbg``, and
2320``helloworld-dev`` packages are built. For information on how to
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05002321customize the packaging process, see the
2322":ref:`dev-manual/common-tasks:splitting an application into multiple packages`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002323section.
2324
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002325Autotooled Package
2326~~~~~~~~~~~~~~~~~~
2327
2328Applications that use Autotools such as ``autoconf`` and ``automake``
Andrew Geissler09036742021-06-25 14:25:14 -05002329require a recipe that has a source archive listed in :term:`SRC_URI` and
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002330also inherit the
2331:ref:`autotools <ref-classes-autotools>` class,
2332which contains the definitions of all the steps needed to build an
2333Autotool-based application. The result of the build is automatically
2334packaged. And, if the application uses NLS for localization, packages
2335with local information are generated (one package per language).
2336Following is one example: (``hello_2.3.bb``)
2337::
2338
2339 SUMMARY = "GNU Helloworld application"
2340 SECTION = "examples"
2341 LICENSE = "GPLv2+"
2342 LIC_FILES_CHKSUM = "file://COPYING;md5=751419260aa954499f7abaabaa882bbe"
2343
2344 SRC_URI = "${GNU_MIRROR}/hello/hello-${PV}.tar.gz"
2345
2346 inherit autotools gettext
2347
Andrew Geissler09036742021-06-25 14:25:14 -05002348The variable :term:`LIC_FILES_CHKSUM` is used to track source license
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002349changes as described in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06002350":ref:`dev-manual/common-tasks:tracking license changes`" section in
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002351the Yocto Project Overview and Concepts Manual. You can quickly create
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002352Autotool-based recipes in a manner similar to the previous example.
2353
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002354Makefile-Based Package
2355~~~~~~~~~~~~~~~~~~~~~~
2356
2357Applications that use GNU ``make`` also require a recipe that has the
Andrew Geissler09036742021-06-25 14:25:14 -05002358source archive listed in :term:`SRC_URI`. You do not need to add a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002359``do_compile`` step since by default BitBake starts the ``make`` command
2360to compile the application. If you need additional ``make`` options, you
2361should store them in the
2362:term:`EXTRA_OEMAKE` or
2363:term:`PACKAGECONFIG_CONFARGS`
2364variables. BitBake passes these options into the GNU ``make``
2365invocation. Note that a ``do_install`` task is still required.
2366Otherwise, BitBake runs an empty ``do_install`` task by default.
2367
2368Some applications might require extra parameters to be passed to the
2369compiler. For example, the application might need an additional header
Andrew Geissler09036742021-06-25 14:25:14 -05002370path. You can accomplish this by adding to the :term:`CFLAGS` variable. The
Andrew Geisslerc926e172021-05-07 16:11:35 -05002371following example shows this::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002372
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002373 CFLAGS:prepend = "-I ${S}/include "
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002374
Andrew Geisslerc926e172021-05-07 16:11:35 -05002375In the following example, ``mtd-utils`` is a makefile-based package::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002376
2377 SUMMARY = "Tools for managing memory technology devices"
2378 SECTION = "base"
2379 DEPENDS = "zlib lzo e2fsprogs util-linux"
2380 HOMEPAGE = "http://www.linux-mtd.infradead.org/"
2381 LICENSE = "GPLv2+"
2382 LIC_FILES_CHKSUM = "file://COPYING;md5=0636e73ff0215e8d672dc4c32c317bb3 \
2383 file://include/common.h;beginline=1;endline=17;md5=ba05b07912a44ea2bf81ce409380049c"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002384
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002385 # Use the latest version at 26 Oct, 2013
2386 SRCREV = "9f107132a6a073cce37434ca9cda6917dd8d866b"
2387 SRC_URI = "git://git.infradead.org/mtd-utils.git \
2388 file://add-exclusion-to-mkfs-jffs2-git-2.patch \
2389 "
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002390
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002391 PV = "1.5.1+git${SRCPV}"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002392
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002393 S = "${WORKDIR}/git"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002394
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002395 EXTRA_OEMAKE = "'CC=${CC}' 'RANLIB=${RANLIB}' 'AR=${AR}' 'CFLAGS=${CFLAGS} -I${S}/include -DWITHOUT_XATTR' 'BUILDDIR=${S}'"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002396
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002397 do_install () {
2398 oe_runmake install DESTDIR=${D} SBINDIR=${sbindir} MANDIR=${mandir} INCLUDEDIR=${includedir}
2399 }
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002400
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002401 PACKAGES =+ "mtd-utils-jffs2 mtd-utils-ubifs mtd-utils-misc"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002402
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002403 FILES:mtd-utils-jffs2 = "${sbindir}/mkfs.jffs2 ${sbindir}/jffs2dump ${sbindir}/jffs2reader ${sbindir}/sumtool"
2404 FILES:mtd-utils-ubifs = "${sbindir}/mkfs.ubifs ${sbindir}/ubi*"
2405 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 -05002406
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002407 PARALLEL_MAKE = ""
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002408
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002409 BBCLASSEXTEND = "native"
2410
2411Splitting an Application into Multiple Packages
2412~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2413
Andrew Geissler09036742021-06-25 14:25:14 -05002414You can use the variables :term:`PACKAGES` and :term:`FILES` to split an
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002415application into multiple packages.
2416
2417Following is an example that uses the ``libxpm`` recipe. By default,
2418this recipe generates a single package that contains the library along
2419with a few binaries. You can modify the recipe to split the binaries
Andrew Geisslerc926e172021-05-07 16:11:35 -05002420into separate packages::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002421
2422 require xorg-lib-common.inc
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002423
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002424 SUMMARY = "Xpm: X Pixmap extension library"
Andrew Geissler5199d832021-09-24 16:47:35 -05002425 LICENSE = "MIT"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002426 LIC_FILES_CHKSUM = "file://COPYING;md5=51f4270b012ecd4ab1a164f5f4ed6cf7"
2427 DEPENDS += "libxext libsm libxt"
2428 PE = "1"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002429
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002430 XORG_PN = "libXpm"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002431
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002432 PACKAGES =+ "sxpm cxpm"
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002433 FILES:cxpm = "${bindir}/cxpm"
2434 FILES:sxpm = "${bindir}/sxpm"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002435
2436In the previous example, we want to ship the ``sxpm`` and ``cxpm``
2437binaries in separate packages. Since ``bindir`` would be packaged into
Andrew Geissler09036742021-06-25 14:25:14 -05002438the main :term:`PN` package by default, we prepend the :term:`PACKAGES` variable
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002439so additional package names are added to the start of list. This results
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002440in the extra ``FILES:*`` variables then containing information that
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002441define which files and directories go into which packages. Files
2442included by earlier packages are skipped by latter packages. Thus, the
Andrew Geissler09036742021-06-25 14:25:14 -05002443main :term:`PN` package does not include the above listed files.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002444
2445Packaging Externally Produced Binaries
2446~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2447
2448Sometimes, you need to add pre-compiled binaries to an image. For
William A. Kennington IIIac69b482021-06-02 12:28:27 -07002449example, suppose that there are binaries for proprietary code,
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002450created by a particular division of a company. Your part of the company
2451needs to use those binaries as part of an image that you are building
2452using the OpenEmbedded build system. Since you only have the binaries
2453and not the source code, you cannot use a typical recipe that expects to
2454fetch the source specified in
2455:term:`SRC_URI` and then compile it.
2456
2457One method is to package the binaries and then install them as part of
2458the image. Generally, it is not a good idea to package binaries since,
2459among other things, it can hinder the ability to reproduce builds and
2460could lead to compatibility problems with ABI in the future. However,
2461sometimes you have no choice.
2462
2463The easiest solution is to create a recipe that uses the
2464:ref:`bin_package <ref-classes-bin-package>` class
2465and to be sure that you are using default locations for build artifacts.
Andrew Geissler595f6302022-01-24 19:11:47 +00002466In most cases, the :ref:`bin_package <ref-classes-bin-package>` class handles "skipping" the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002467configure and compile steps as well as sets things up to grab packages
2468from the appropriate area. In particular, this class sets ``noexec`` on
2469both the :ref:`ref-tasks-configure`
2470and :ref:`ref-tasks-compile` tasks,
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002471sets ``FILES:${PN}`` to "/" so that it picks up all files, and sets up a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002472:ref:`ref-tasks-install` task, which
2473effectively copies all files from ``${S}`` to ``${D}``. The
Andrew Geissler595f6302022-01-24 19:11:47 +00002474:ref:`bin_package <ref-classes-bin-package>` class works well when the files extracted into ``${S}``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002475are already laid out in the way they should be laid out on the target.
2476For more information on these variables, see the
2477:term:`FILES`,
2478:term:`PN`,
2479:term:`S`, and
2480:term:`D` variables in the Yocto Project
2481Reference Manual's variable glossary.
2482
2483.. note::
2484
2485 - Using :term:`DEPENDS` is a good
2486 idea even for components distributed in binary form, and is often
2487 necessary for shared libraries. For a shared library, listing the
Andrew Geissler09036742021-06-25 14:25:14 -05002488 library dependencies in :term:`DEPENDS` makes sure that the libraries
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002489 are available in the staging sysroot when other recipes link
2490 against the library, which might be necessary for successful
2491 linking.
2492
Andrew Geissler09036742021-06-25 14:25:14 -05002493 - Using :term:`DEPENDS` also allows runtime dependencies between
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002494 packages to be added automatically. See the
Andrew Geissler09209ee2020-12-13 08:44:15 -06002495 ":ref:`overview-manual/concepts:automatically added runtime dependencies`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002496 section in the Yocto Project Overview and Concepts Manual for more
2497 information.
2498
Andrew Geissler595f6302022-01-24 19:11:47 +00002499If you cannot use the :ref:`bin_package <ref-classes-bin-package>` class, you need to be sure you are
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002500doing the following:
2501
2502- Create a recipe where the
2503 :ref:`ref-tasks-configure` and
2504 :ref:`ref-tasks-compile` tasks do
2505 nothing: It is usually sufficient to just not define these tasks in
2506 the recipe, because the default implementations do nothing unless a
2507 Makefile is found in
2508 ``${``\ :term:`S`\ ``}``.
2509
2510 If ``${S}`` might contain a Makefile, or if you inherit some class
2511 that replaces ``do_configure`` and ``do_compile`` with custom
2512 versions, then you can use the
2513 ``[``\ :ref:`noexec <bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ``]``
Andrew Geisslerc926e172021-05-07 16:11:35 -05002514 flag to turn the tasks into no-ops, as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002515
2516 do_configure[noexec] = "1"
2517 do_compile[noexec] = "1"
2518
2519 Unlike
2520 :ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:deleting a task`,
2521 using the flag preserves the dependency chain from the
2522 :ref:`ref-tasks-fetch`,
2523 :ref:`ref-tasks-unpack`, and
2524 :ref:`ref-tasks-patch` tasks to the
2525 :ref:`ref-tasks-install` task.
2526
2527- Make sure your ``do_install`` task installs the binaries
2528 appropriately.
2529
2530- Ensure that you set up :term:`FILES`
2531 (usually
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002532 ``FILES:${``\ :term:`PN`\ ``}``) to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002533 point to the files you have installed, which of course depends on
2534 where you have installed them and whether those files are in
2535 different locations than the defaults.
2536
Andrew Geissler6ce62a22020-11-30 19:58:47 -06002537.. note::
2538
Andrew Geissler595f6302022-01-24 19:11:47 +00002539 If image prelinking is enabled (e.g. :ref:`image-prelink <ref-classes-image-prelink>` is in :term:`USER_CLASSES`
Andrew Geissler6ce62a22020-11-30 19:58:47 -06002540 which it is by default), prelink will change the binaries in the generated images
2541 and this often catches people out. Remove that class to ensure binaries are
2542 preserved exactly if that is necessary.
2543
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002544Following Recipe Style Guidelines
2545---------------------------------
2546
2547When writing recipes, it is good to conform to existing style
Andrew Geisslerd1e89492021-02-12 15:35:20 -06002548guidelines. The :oe_wiki:`OpenEmbedded Styleguide </Styleguide>` wiki page
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002549provides rough guidelines for preferred recipe style.
2550
2551It is common for existing recipes to deviate a bit from this style.
2552However, aiming for at least a consistent style is a good idea. Some
2553practices, such as omitting spaces around ``=`` operators in assignments
2554or ordering recipe components in an erratic way, are widely seen as poor
2555style.
2556
2557Recipe Syntax
2558-------------
2559
2560Understanding recipe file syntax is important for writing recipes. The
2561following list overviews the basic items that make up a BitBake recipe
2562file. For more complete BitBake syntax descriptions, see the
2563":doc:`bitbake-user-manual/bitbake-user-manual-metadata`"
2564chapter of the BitBake User Manual.
2565
2566- *Variable Assignments and Manipulations:* Variable assignments allow
2567 a value to be assigned to a variable. The assignment can be static
2568 text or might include the contents of other variables. In addition to
2569 the assignment, appending and prepending operations are also
2570 supported.
2571
2572 The following example shows some of the ways you can use variables in
Andrew Geisslerc926e172021-05-07 16:11:35 -05002573 recipes::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002574
2575 S = "${WORKDIR}/postfix-${PV}"
2576 CFLAGS += "-DNO_ASM"
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002577 SRC_URI:append = " file://fixup.patch"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002578
2579- *Functions:* Functions provide a series of actions to be performed.
2580 You usually use functions to override the default implementation of a
2581 task function or to complement a default function (i.e. append or
2582 prepend to an existing function). Standard functions use ``sh`` shell
2583 syntax, although access to OpenEmbedded variables and internal
2584 methods are also available.
2585
William A. Kennington IIIac69b482021-06-02 12:28:27 -07002586 Here is an example function from the ``sed`` recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002587
2588 do_install () {
2589 autotools_do_install
2590 install -d ${D}${base_bindir}
2591 mv ${D}${bindir}/sed ${D}${base_bindir}/sed
2592 rmdir ${D}${bindir}/
2593 }
2594
2595 It is
2596 also possible to implement new functions that are called between
2597 existing tasks as long as the new functions are not replacing or
2598 complementing the default functions. You can implement functions in
2599 Python instead of shell. Both of these options are not seen in the
2600 majority of recipes.
2601
2602- *Keywords:* BitBake recipes use only a few keywords. You use keywords
2603 to include common functions (``inherit``), load parts of a recipe
2604 from other files (``include`` and ``require``) and export variables
2605 to the environment (``export``).
2606
Andrew Geisslerc926e172021-05-07 16:11:35 -05002607 The following example shows the use of some of these keywords::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002608
2609 export POSTCONF = "${STAGING_BINDIR}/postconf"
2610 inherit autoconf
2611 require otherfile.inc
2612
2613- *Comments (#):* Any lines that begin with the hash character (``#``)
Andrew Geisslerc926e172021-05-07 16:11:35 -05002614 are treated as comment lines and are ignored::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002615
2616 # This is a comment
2617
2618This next list summarizes the most important and most commonly used
2619parts of the recipe syntax. For more information on these parts of the
2620syntax, you can reference the
2621:doc:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata` chapter
2622in the BitBake User Manual.
2623
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002624- *Line Continuation (\\):* Use the backward slash (``\``) character to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002625 split a statement over multiple lines. Place the slash character at
Andrew Geisslerc926e172021-05-07 16:11:35 -05002626 the end of the line that is to be continued on the next line::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002627
2628 VAR = "A really long \
2629 line"
2630
2631 .. note::
2632
2633 You cannot have any characters including spaces or tabs after the
2634 slash character.
2635
2636- *Using Variables (${VARNAME}):* Use the ``${VARNAME}`` syntax to
Andrew Geisslerc926e172021-05-07 16:11:35 -05002637 access the contents of a variable::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002638
2639 SRC_URI = "${SOURCEFORGE_MIRROR}/libpng/zlib-${PV}.tar.gz"
2640
2641 .. note::
2642
2643 It is important to understand that the value of a variable
2644 expressed in this form does not get substituted automatically. The
2645 expansion of these expressions happens on-demand later (e.g.
2646 usually when a function that makes reference to the variable
2647 executes). This behavior ensures that the values are most
2648 appropriate for the context in which they are finally used. On the
2649 rare occasion that you do need the variable expression to be
2650 expanded immediately, you can use the
2651 :=
2652 operator instead of
2653 =
2654 when you make the assignment, but this is not generally needed.
2655
2656- *Quote All Assignments ("value"):* Use double quotes around values in
Andrew Geisslerc926e172021-05-07 16:11:35 -05002657 all variable assignments (e.g. ``"value"``). Following is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002658
2659 VAR1 = "${OTHERVAR}"
2660 VAR2 = "The version is ${PV}"
2661
2662- *Conditional Assignment (?=):* Conditional assignment is used to
2663 assign a value to a variable, but only when the variable is currently
2664 unset. Use the question mark followed by the equal sign (``?=``) to
2665 make a "soft" assignment used for conditional assignment. Typically,
2666 "soft" assignments are used in the ``local.conf`` file for variables
2667 that are allowed to come through from the external environment.
2668
2669 Here is an example where ``VAR1`` is set to "New value" if it is
2670 currently empty. However, if ``VAR1`` has already been set, it
Andrew Geisslerc926e172021-05-07 16:11:35 -05002671 remains unchanged::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002672
2673 VAR1 ?= "New value"
2674
Andrew Geisslerc926e172021-05-07 16:11:35 -05002675 In this next example, ``VAR1`` is left with the value "Original value"::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002676
2677 VAR1 = "Original value"
2678 VAR1 ?= "New value"
2679
2680- *Appending (+=):* Use the plus character followed by the equals sign
2681 (``+=``) to append values to existing variables.
2682
2683 .. note::
2684
2685 This operator adds a space between the existing content of the
2686 variable and the new content.
2687
Andrew Geisslerc926e172021-05-07 16:11:35 -05002688 Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002689
2690 SRC_URI += "file://fix-makefile.patch"
2691
2692- *Prepending (=+):* Use the equals sign followed by the plus character
2693 (``=+``) to prepend values to existing variables.
2694
2695 .. note::
2696
2697 This operator adds a space between the new content and the
2698 existing content of the variable.
2699
Andrew Geisslerc926e172021-05-07 16:11:35 -05002700 Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002701
2702 VAR =+ "Starts"
2703
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002704- *Appending (:append):* Use the ``:append`` operator to append values
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002705 to existing variables. This operator does not add any additional
2706 space. Also, the operator is applied after all the ``+=``, and ``=+``
2707 operators have been applied and after all ``=`` assignments have
2708 occurred.
2709
2710 The following example shows the space being explicitly added to the
2711 start to ensure the appended value is not merged with the existing
Andrew Geisslerc926e172021-05-07 16:11:35 -05002712 value::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002713
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002714 SRC_URI:append = " file://fix-makefile.patch"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002715
2716 You can also use
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002717 the ``:append`` operator with overrides, which results in the actions
Andrew Geisslerc926e172021-05-07 16:11:35 -05002718 only being performed for the specified target or machine::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002719
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002720 SRC_URI:append:sh4 = " file://fix-makefile.patch"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002721
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002722- *Prepending (:prepend):* Use the ``:prepend`` operator to prepend
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002723 values to existing variables. This operator does not add any
2724 additional space. Also, the operator is applied after all the ``+=``,
2725 and ``=+`` operators have been applied and after all ``=``
2726 assignments have occurred.
2727
2728 The following example shows the space being explicitly added to the
2729 end to ensure the prepended value is not merged with the existing
Andrew Geisslerc926e172021-05-07 16:11:35 -05002730 value::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002731
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002732 CFLAGS:prepend = "-I${S}/myincludes "
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002733
2734 You can also use the
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002735 ``:prepend`` operator with overrides, which results in the actions
Andrew Geisslerc926e172021-05-07 16:11:35 -05002736 only being performed for the specified target or machine::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002737
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002738 CFLAGS:prepend:sh4 = "-I${S}/myincludes "
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002739
2740- *Overrides:* You can use overrides to set a value conditionally,
2741 typically based on how the recipe is being built. For example, to set
2742 the :term:`KBRANCH` variable's
2743 value to "standard/base" for any target
2744 :term:`MACHINE`, except for
2745 qemuarm where it should be set to "standard/arm-versatile-926ejs",
Andrew Geisslerc926e172021-05-07 16:11:35 -05002746 you would do the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002747
2748 KBRANCH = "standard/base"
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002749 KBRANCH:qemuarm = "standard/arm-versatile-926ejs"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002750
2751 Overrides are also used to separate
2752 alternate values of a variable in other situations. For example, when
2753 setting variables such as
2754 :term:`FILES` and
2755 :term:`RDEPENDS` that are
2756 specific to individual packages produced by a recipe, you should
2757 always use an override that specifies the name of the package.
2758
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002759- *Indentation:* Use spaces for indentation rather than tabs. For
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002760 shell functions, both currently work. However, it is a policy
2761 decision of the Yocto Project to use tabs in shell functions. Realize
2762 that some layers have a policy to use spaces for all indentation.
2763
2764- *Using Python for Complex Operations:* For more advanced processing,
2765 it is possible to use Python code during variable assignments (e.g.
2766 search and replacement on a variable).
2767
2768 You indicate Python code using the ``${@python_code}`` syntax for the
Andrew Geisslerc926e172021-05-07 16:11:35 -05002769 variable assignment::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002770
2771 SRC_URI = "ftp://ftp.info-zip.org/pub/infozip/src/zip${@d.getVar('PV',1).replace('.', '')}.tgz
2772
2773- *Shell Function Syntax:* Write shell functions as if you were writing
2774 a shell script when you describe a list of actions to take. You
2775 should ensure that your script works with a generic ``sh`` and that
2776 it does not require any ``bash`` or other shell-specific
2777 functionality. The same considerations apply to various system
2778 utilities (e.g. ``sed``, ``grep``, ``awk``, and so forth) that you
2779 might wish to use. If in doubt, you should check with multiple
2780 implementations - including those from BusyBox.
2781
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002782Adding a New Machine
2783====================
2784
2785Adding a new machine to the Yocto Project is a straightforward process.
2786This section describes how to add machines that are similar to those
2787that the Yocto Project already supports.
2788
2789.. note::
2790
2791 Although well within the capabilities of the Yocto Project, adding a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002792 totally new architecture might require changes to ``gcc``/``glibc``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002793 and to the site information, which is beyond the scope of this
2794 manual.
2795
2796For a complete example that shows how to add a new machine, see the
2797":ref:`bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script`"
2798section in the Yocto Project Board Support Package (BSP) Developer's
2799Guide.
2800
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002801Adding the Machine Configuration File
2802-------------------------------------
2803
2804To add a new machine, you need to add a new machine configuration file
2805to the layer's ``conf/machine`` directory. This configuration file
2806provides details about the device you are adding.
2807
2808The OpenEmbedded build system uses the root name of the machine
2809configuration file to reference the new machine. For example, given a
2810machine configuration file named ``crownbay.conf``, the build system
2811recognizes the machine as "crownbay".
2812
2813The most important variables you must set in your machine configuration
2814file or include from a lower-level configuration file are as follows:
2815
Andrew Geissler5f350902021-07-23 13:09:54 -04002816- :term:`TARGET_ARCH` (e.g. "arm")
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002817
2818- ``PREFERRED_PROVIDER_virtual/kernel``
2819
Andrew Geissler09036742021-06-25 14:25:14 -05002820- :term:`MACHINE_FEATURES` (e.g. "apm screen wifi")
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002821
2822You might also need these variables:
2823
Andrew Geissler5f350902021-07-23 13:09:54 -04002824- :term:`SERIAL_CONSOLES` (e.g. "115200;ttyS0 115200;ttyS1")
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002825
Andrew Geissler5f350902021-07-23 13:09:54 -04002826- :term:`KERNEL_IMAGETYPE` (e.g. "zImage")
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002827
Andrew Geissler09036742021-06-25 14:25:14 -05002828- :term:`IMAGE_FSTYPES` (e.g. "tar.gz jffs2")
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002829
2830You can find full details on these variables in the reference section.
2831You can leverage existing machine ``.conf`` files from
2832``meta-yocto-bsp/conf/machine/``.
2833
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002834Adding a Kernel for the Machine
2835-------------------------------
2836
2837The OpenEmbedded build system needs to be able to build a kernel for the
2838machine. You need to either create a new kernel recipe for this machine,
2839or extend an existing kernel recipe. You can find several kernel recipe
2840examples in the Source Directory at ``meta/recipes-kernel/linux`` that
2841you can use as references.
2842
2843If you are creating a new kernel recipe, normal recipe-writing rules
Andrew Geissler09036742021-06-25 14:25:14 -05002844apply for setting up a :term:`SRC_URI`. Thus, you need to specify any
2845necessary patches and set :term:`S` to point at the source code. You need to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002846create a ``do_configure`` task that configures the unpacked kernel with
2847a ``defconfig`` file. You can do this by using a ``make defconfig``
2848command or, more commonly, by copying in a suitable ``defconfig`` file
2849and then running ``make oldconfig``. By making use of ``inherit kernel``
2850and potentially some of the ``linux-*.inc`` files, most other
2851functionality is centralized and the defaults of the class normally work
2852well.
2853
2854If you are extending an existing kernel recipe, it is usually a matter
2855of adding a suitable ``defconfig`` file. The file needs to be added into
2856a location similar to ``defconfig`` files used for other machines in a
2857given kernel recipe. A possible way to do this is by listing the file in
Andrew Geissler09036742021-06-25 14:25:14 -05002858the :term:`SRC_URI` and adding the machine to the expression in
2859:term:`COMPATIBLE_MACHINE`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002860
2861 COMPATIBLE_MACHINE = '(qemux86|qemumips)'
2862
2863For more information on ``defconfig`` files, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06002864":ref:`kernel-dev/common:changing the configuration`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002865section in the Yocto Project Linux Kernel Development Manual.
2866
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002867Adding a Formfactor Configuration File
2868--------------------------------------
2869
2870A formfactor configuration file provides information about the target
2871hardware for which the image is being built and information that the
2872build system cannot obtain from other sources such as the kernel. Some
2873examples of information contained in a formfactor configuration file
2874include framebuffer orientation, whether or not the system has a
2875keyboard, the positioning of the keyboard in relation to the screen, and
2876the screen resolution.
2877
2878The build system uses reasonable defaults in most cases. However, if
2879customization is necessary, you need to create a ``machconfig`` file in
2880the ``meta/recipes-bsp/formfactor/files`` directory. This directory
2881contains directories for specific machines such as ``qemuarm`` and
2882``qemux86``. For information about the settings available and the
2883defaults, see the ``meta/recipes-bsp/formfactor/files/config`` file
2884found in the same area.
2885
Andrew Geisslerc926e172021-05-07 16:11:35 -05002886Following is an example for "qemuarm" machine::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002887
2888 HAVE_TOUCHSCREEN=1
2889 HAVE_KEYBOARD=1
2890 DISPLAY_CAN_ROTATE=0
2891 DISPLAY_ORIENTATION=0
2892 #DISPLAY_WIDTH_PIXELS=640
2893 #DISPLAY_HEIGHT_PIXELS=480
2894 #DISPLAY_BPP=16
2895 DISPLAY_DPI=150
2896 DISPLAY_SUBPIXEL_ORDER=vrgb
2897
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002898Upgrading Recipes
2899=================
2900
2901Over time, upstream developers publish new versions for software built
2902by layer recipes. It is recommended to keep recipes up-to-date with
2903upstream version releases.
2904
William A. Kennington IIIac69b482021-06-02 12:28:27 -07002905While there are several methods to upgrade a recipe, you might
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002906consider checking on the upgrade status of a recipe first. You can do so
2907using the ``devtool check-upgrade-status`` command. See the
2908":ref:`devtool-checking-on-the-upgrade-status-of-a-recipe`"
2909section in the Yocto Project Reference Manual for more information.
2910
2911The remainder of this section describes three ways you can upgrade a
2912recipe. You can use the Automated Upgrade Helper (AUH) to set up
2913automatic version upgrades. Alternatively, you can use
2914``devtool upgrade`` to set up semi-automatic version upgrades. Finally,
2915you can manually upgrade a recipe by editing the recipe itself.
2916
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002917Using the Auto Upgrade Helper (AUH)
2918-----------------------------------
2919
2920The AUH utility works in conjunction with the OpenEmbedded build system
2921in order to automatically generate upgrades for recipes based on new
2922versions being published upstream. Use AUH when you want to create a
2923service that performs the upgrades automatically and optionally sends
2924you an email with the results.
2925
2926AUH allows you to update several recipes with a single use. You can also
2927optionally perform build and integration tests using images with the
2928results saved to your hard drive and emails of results optionally sent
2929to recipe maintainers. Finally, AUH creates Git commits with appropriate
2930commit messages in the layer's tree for the changes made to recipes.
2931
2932.. note::
2933
William A. Kennington IIIac69b482021-06-02 12:28:27 -07002934 In some conditions, you should not use AUH to upgrade recipes
2935 and should instead use either ``devtool upgrade`` or upgrade your
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002936 recipes manually:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002937
2938 - When AUH cannot complete the upgrade sequence. This situation
2939 usually results because custom patches carried by the recipe
2940 cannot be automatically rebased to the new version. In this case,
2941 ``devtool upgrade`` allows you to manually resolve conflicts.
2942
2943 - When for any reason you want fuller control over the upgrade
2944 process. For example, when you want special arrangements for
2945 testing.
2946
2947The following steps describe how to set up the AUH utility:
2948
29491. *Be Sure the Development Host is Set Up:* You need to be sure that
2950 your development host is set up to use the Yocto Project. For
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002951 information on how to set up your host, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06002952 ":ref:`dev-manual/start:Preparing the Build Host`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002953
29542. *Make Sure Git is Configured:* The AUH utility requires Git to be
2955 configured because AUH uses Git to save upgrades. Thus, you must have
2956 Git user and email configured. The following command shows your
Andrew Geisslerc926e172021-05-07 16:11:35 -05002957 configurations::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002958
2959 $ git config --list
2960
2961 If you do not have the user and
Andrew Geisslerc926e172021-05-07 16:11:35 -05002962 email configured, you can use the following commands to do so::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002963
2964 $ git config --global user.name some_name
2965 $ git config --global user.email username@domain.com
2966
29673. *Clone the AUH Repository:* To use AUH, you must clone the repository
2968 onto your development host. The following command uses Git to create
Andrew Geisslerc926e172021-05-07 16:11:35 -05002969 a local copy of the repository on your system::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002970
2971 $ git clone git://git.yoctoproject.org/auto-upgrade-helper
2972 Cloning into 'auto-upgrade-helper'... remote: Counting objects: 768, done.
2973 remote: Compressing objects: 100% (300/300), done.
2974 remote: Total 768 (delta 499), reused 703 (delta 434)
2975 Receiving objects: 100% (768/768), 191.47 KiB | 98.00 KiB/s, done.
2976 Resolving deltas: 100% (499/499), done.
2977 Checking connectivity... done.
2978
2979 AUH is not part of the :term:`OpenEmbedded-Core (OE-Core)` or
2980 :term:`Poky` repositories.
2981
29824. *Create a Dedicated Build Directory:* Run the
2983 :ref:`structure-core-script`
2984 script to create a fresh build directory that you use exclusively for
Andrew Geisslerc926e172021-05-07 16:11:35 -05002985 running the AUH utility::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002986
Andrew Geissler95ac1b82021-03-31 14:34:31 -05002987 $ cd poky
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002988 $ source oe-init-build-env your_AUH_build_directory
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002989
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002990 Re-using an existing build directory and its configurations is not
2991 recommended as existing settings could cause AUH to fail or behave
2992 undesirably.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002993
29945. *Make Configurations in Your Local Configuration File:* Several
William A. Kennington IIIac69b482021-06-02 12:28:27 -07002995 settings are needed in the ``local.conf`` file in the build
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002996 directory you just created for AUH. Make these following
2997 configurations:
2998
2999 - If you want to enable :ref:`Build
Andrew Geissler09209ee2020-12-13 08:44:15 -06003000 History <dev-manual/common-tasks:maintaining build output quality>`,
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003001 which is optional, you need the following lines in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05003002 ``conf/local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003003
3004 INHERIT =+ "buildhistory"
3005 BUILDHISTORY_COMMIT = "1"
3006
3007 With this configuration and a successful
3008 upgrade, a build history "diff" file appears in the
3009 ``upgrade-helper/work/recipe/buildhistory-diff.txt`` file found in
3010 your build directory.
3011
3012 - If you want to enable testing through the
3013 :ref:`testimage <ref-classes-testimage*>`
3014 class, which is optional, you need to have the following set in
Andrew Geisslerc926e172021-05-07 16:11:35 -05003015 your ``conf/local.conf`` file::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003016
3017 INHERIT += "testimage"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003018
3019 .. note::
3020
3021 If your distro does not enable by default ptest, which Poky
Andrew Geisslerc926e172021-05-07 16:11:35 -05003022 does, you need the following in your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003023
Patrick Williams0ca19cc2021-08-16 14:03:13 -05003024 DISTRO_FEATURES:append = " ptest"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003025
3026
30276. *Optionally Start a vncserver:* If you are running in a server
Andrew Geisslerc926e172021-05-07 16:11:35 -05003028 without an X11 session, you need to start a vncserver::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003029
3030 $ vncserver :1
3031 $ export DISPLAY=:1
3032
30337. *Create and Edit an AUH Configuration File:* You need to have the
3034 ``upgrade-helper/upgrade-helper.conf`` configuration file in your
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003035 build directory. You can find a sample configuration file in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003036 :yocto_git:`AUH source repository </auto-upgrade-helper/tree/>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003037
3038 Read through the sample file and make configurations as needed. For
3039 example, if you enabled build history in your ``local.conf`` as
3040 described earlier, you must enable it in ``upgrade-helper.conf``.
3041
3042 Also, if you are using the default ``maintainers.inc`` file supplied
3043 with Poky and located in ``meta-yocto`` and you do not set a
3044 "maintainers_whitelist" or "global_maintainer_override" in the
3045 ``upgrade-helper.conf`` configuration, and you specify "-e all" on
3046 the AUH command-line, the utility automatically sends out emails to
3047 all the default maintainers. Please avoid this.
3048
3049This next set of examples describes how to use the AUH:
3050
3051- *Upgrading a Specific Recipe:* To upgrade a specific recipe, use the
Andrew Geisslerc926e172021-05-07 16:11:35 -05003052 following form::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003053
3054 $ upgrade-helper.py recipe_name
3055
Andrew Geisslerc926e172021-05-07 16:11:35 -05003056 For example, this command upgrades the ``xmodmap`` recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003057
3058 $ upgrade-helper.py xmodmap
3059
3060- *Upgrading a Specific Recipe to a Particular Version:* To upgrade a
Andrew Geisslerc926e172021-05-07 16:11:35 -05003061 specific recipe to a particular version, use the following form::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003062
3063 $ upgrade-helper.py recipe_name -t version
3064
Andrew Geisslerc926e172021-05-07 16:11:35 -05003065 For example, this command upgrades the ``xmodmap`` recipe to version 1.2.3::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003066
3067 $ upgrade-helper.py xmodmap -t 1.2.3
3068
3069- *Upgrading all Recipes to the Latest Versions and Suppressing Email
3070 Notifications:* To upgrade all recipes to their most recent versions
Andrew Geisslerc926e172021-05-07 16:11:35 -05003071 and suppress the email notifications, use the following command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003072
3073 $ upgrade-helper.py all
3074
3075- *Upgrading all Recipes to the Latest Versions and Send Email
3076 Notifications:* To upgrade all recipes to their most recent versions
3077 and send email messages to maintainers for each attempted recipe as
Andrew Geisslerc926e172021-05-07 16:11:35 -05003078 well as a status email, use the following command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003079
3080 $ upgrade-helper.py -e all
3081
3082Once you have run the AUH utility, you can find the results in the AUH
Andrew Geisslerc926e172021-05-07 16:11:35 -05003083build directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003084
3085 ${BUILDDIR}/upgrade-helper/timestamp
3086
3087The AUH utility
3088also creates recipe update commits from successful upgrade attempts in
3089the layer tree.
3090
3091You can easily set up to run the AUH utility on a regular basis by using
3092a cron job. See the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003093:yocto_git:`weeklyjob.sh </auto-upgrade-helper/tree/weeklyjob.sh>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003094file distributed with the utility for an example.
3095
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003096Using ``devtool upgrade``
3097-------------------------
3098
3099As mentioned earlier, an alternative method for upgrading recipes to
3100newer versions is to use
Andrew Geissler09209ee2020-12-13 08:44:15 -06003101:doc:`devtool upgrade </ref-manual/devtool-reference>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003102You can read about ``devtool upgrade`` in general in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003103":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 -05003104section in the Yocto Project Application Development and the Extensible
3105Software Development Kit (eSDK) Manual.
3106
3107To see all the command-line options available with ``devtool upgrade``,
Andrew Geisslerc926e172021-05-07 16:11:35 -05003108use the following help command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003109
3110 $ devtool upgrade -h
3111
3112If you want to find out what version a recipe is currently at upstream
3113without any attempt to upgrade your local version of the recipe, you can
Andrew Geisslerc926e172021-05-07 16:11:35 -05003114use the following command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003115
3116 $ devtool latest-version recipe_name
3117
3118As mentioned in the previous section describing AUH, ``devtool upgrade``
3119works in a less-automated manner than AUH. Specifically,
3120``devtool upgrade`` only works on a single recipe that you name on the
3121command line, cannot perform build and integration testing using images,
3122and does not automatically generate commits for changes in the source
3123tree. Despite all these "limitations", ``devtool upgrade`` updates the
3124recipe file to the new upstream version and attempts to rebase custom
3125patches contained by the recipe as needed.
3126
3127.. note::
3128
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003129 AUH uses much of ``devtool upgrade`` behind the scenes making AUH somewhat
3130 of a "wrapper" application for ``devtool upgrade``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003131
3132A typical scenario involves having used Git to clone an upstream
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003133repository that you use during build operations. Because you have built the
3134recipe in the past, the layer is likely added to your
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003135configuration already. If for some reason, the layer is not added, you
3136could add it easily using the
3137":ref:`bitbake-layers <bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script>`"
3138script. For example, suppose you use the ``nano.bb`` recipe from the
3139``meta-oe`` layer in the ``meta-openembedded`` repository. For this
Andrew Geisslerc926e172021-05-07 16:11:35 -05003140example, assume that the layer has been cloned into following area::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003141
3142 /home/scottrif/meta-openembedded
3143
3144The following command from your
3145:term:`Build Directory` adds the layer to
Andrew Geisslerc926e172021-05-07 16:11:35 -05003146your build configuration (i.e. ``${BUILDDIR}/conf/bblayers.conf``)::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003147
3148 $ bitbake-layers add-layer /home/scottrif/meta-openembedded/meta-oe
3149 NOTE: Starting bitbake server...
3150 Parsing recipes: 100% |##########################################| Time: 0:00:55
3151 Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
3152 Removing 12 recipes from the x86_64 sysroot: 100% |##############| Time: 0:00:00
3153 Removing 1 recipes from the x86_64_i586 sysroot: 100% |##########| Time: 0:00:00
3154 Removing 5 recipes from the i586 sysroot: 100% |#################| Time: 0:00:00
3155 Removing 5 recipes from the qemux86 sysroot: 100% |##############| Time: 0:00:00
3156
3157For this example, assume that the ``nano.bb`` recipe that
3158is upstream has a 2.9.3 version number. However, the version in the
3159local repository is 2.7.4. The following command from your build
3160directory automatically upgrades the recipe for you:
3161
3162.. note::
3163
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003164 Using the ``-V`` option is not necessary. Omitting the version number causes
3165 ``devtool upgrade`` to upgrade the recipe to the most recent version.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003166
3167::
3168
3169 $ devtool upgrade nano -V 2.9.3
3170 NOTE: Starting bitbake server...
3171 NOTE: Creating workspace layer in /home/scottrif/poky/build/workspace
3172 Parsing recipes: 100% |##########################################| Time: 0:00:46
3173 Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
3174 NOTE: Extracting current version source...
3175 NOTE: Resolving any missing task queue dependencies
3176 .
3177 .
3178 .
3179 NOTE: Executing SetScene Tasks
3180 NOTE: Executing RunQueue Tasks
3181 NOTE: Tasks Summary: Attempted 74 tasks of which 72 didn't need to be rerun and all succeeded.
3182 Adding changed files: 100% |#####################################| Time: 0:00:00
3183 NOTE: Upgraded source extracted to /home/scottrif/poky/build/workspace/sources/nano
3184 NOTE: New recipe is /home/scottrif/poky/build/workspace/recipes/nano/nano_2.9.3.bb
3185
3186Continuing with this example, you can use ``devtool build`` to build the
Andrew Geisslerc926e172021-05-07 16:11:35 -05003187newly upgraded recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003188
3189 $ devtool build nano
3190 NOTE: Starting bitbake server...
3191 Loading cache: 100% |################################################################################################| Time: 0:00:01
3192 Loaded 2040 entries from dependency cache.
3193 Parsing recipes: 100% |##############################################################################################| Time: 0:00:00
3194 Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
3195 NOTE: Resolving any missing task queue dependencies
3196 .
3197 .
3198 .
3199 NOTE: Executing SetScene Tasks
3200 NOTE: Executing RunQueue Tasks
3201 NOTE: nano: compiling from external source tree /home/scottrif/poky/build/workspace/sources/nano
3202 NOTE: Tasks Summary: Attempted 520 tasks of which 304 didn't need to be rerun and all succeeded.
3203
William A. Kennington IIIac69b482021-06-02 12:28:27 -07003204Within the ``devtool upgrade`` workflow, you can
3205deploy and test your rebuilt software. For this example,
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003206however, running ``devtool finish`` cleans up the workspace once the
3207source in your workspace is clean. This usually means using Git to stage
3208and submit commits for the changes generated by the upgrade process.
3209
3210Once the tree is clean, you can clean things up in this example with the
3211following command from the ``${BUILDDIR}/workspace/sources/nano``
Andrew Geisslerc926e172021-05-07 16:11:35 -05003212directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003213
3214 $ devtool finish nano meta-oe
3215 NOTE: Starting bitbake server...
3216 Loading cache: 100% |################################################################################################| Time: 0:00:00
3217 Loaded 2040 entries from dependency cache.
3218 Parsing recipes: 100% |##############################################################################################| Time: 0:00:01
3219 Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
3220 NOTE: Adding new patch 0001-nano.bb-Stuff-I-changed-when-upgrading-nano.bb.patch
3221 NOTE: Updating recipe nano_2.9.3.bb
3222 NOTE: Removing file /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano/nano_2.7.4.bb
3223 NOTE: Moving recipe file to /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano
3224 NOTE: Leaving source tree /home/scottrif/poky/build/workspace/sources/nano as-is; if you no longer need it then please delete it manually
3225
3226
3227Using the ``devtool finish`` command cleans up the workspace and creates a patch
3228file based on your commits. The tool puts all patch files back into the
3229source directory in a sub-directory named ``nano`` in this case.
3230
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003231Manually Upgrading a Recipe
3232---------------------------
3233
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003234If for some reason you choose not to upgrade recipes using
Andrew Geissler09209ee2020-12-13 08:44:15 -06003235:ref:`dev-manual/common-tasks:Using the Auto Upgrade Helper (AUH)` or
3236by :ref:`dev-manual/common-tasks:Using \`\`devtool upgrade\`\``,
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003237you can manually edit the recipe files to upgrade the versions.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003238
3239.. note::
3240
3241 Manually updating multiple recipes scales poorly and involves many
3242 steps. The recommendation to upgrade recipe versions is through AUH
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003243 or ``devtool upgrade``, both of which automate some steps and provide
3244 guidance for others needed for the manual process.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003245
3246To manually upgrade recipe versions, follow these general steps:
3247
32481. *Change the Version:* Rename the recipe such that the version (i.e.
3249 the :term:`PV` part of the recipe name)
3250 changes appropriately. If the version is not part of the recipe name,
Andrew Geissler09036742021-06-25 14:25:14 -05003251 change the value as it is set for :term:`PV` within the recipe itself.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003252
Andrew Geissler09036742021-06-25 14:25:14 -050032532. *Update* :term:`SRCREV` *if Needed*: If the source code your recipe builds
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003254 is fetched from Git or some other version control system, update
3255 :term:`SRCREV` to point to the
3256 commit hash that matches the new version.
3257
32583. *Build the Software:* Try to build the recipe using BitBake. Typical
3259 build failures include the following:
3260
3261 - License statements were updated for the new version. For this
3262 case, you need to review any changes to the license and update the
3263 values of :term:`LICENSE` and
3264 :term:`LIC_FILES_CHKSUM`
3265 as needed.
3266
3267 .. note::
3268
3269 License changes are often inconsequential. For example, the
3270 license text's copyright year might have changed.
3271
3272 - Custom patches carried by the older version of the recipe might
3273 fail to apply to the new version. For these cases, you need to
3274 review the failures. Patches might not be necessary for the new
3275 version of the software if the upgraded version has fixed those
3276 issues. If a patch is necessary and failing, you need to rebase it
3277 into the new version.
3278
32794. *Optionally Attempt to Build for Several Architectures:* Once you
3280 successfully build the new software for a given architecture, you
3281 could test the build for other architectures by changing the
3282 :term:`MACHINE` variable and
3283 rebuilding the software. This optional step is especially important
3284 if the recipe is to be released publicly.
3285
32865. *Check the Upstream Change Log or Release Notes:* Checking both these
William A. Kennington IIIac69b482021-06-02 12:28:27 -07003287 reveals if there are new features that could break
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003288 backwards-compatibility. If so, you need to take steps to mitigate or
3289 eliminate that situation.
3290
32916. *Optionally Create a Bootable Image and Test:* If you want, you can
3292 test the new software by booting it onto actual hardware.
3293
32947. *Create a Commit with the Change in the Layer Repository:* After all
3295 builds work and any testing is successful, you can create commits for
3296 any changes in the layer holding your upgraded recipe.
3297
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003298Finding Temporary Source Code
3299=============================
3300
3301You might find it helpful during development to modify the temporary
3302source code used by recipes to build packages. For example, suppose you
3303are developing a patch and you need to experiment a bit to figure out
3304your solution. After you have initially built the package, you can
3305iteratively tweak the source code, which is located in the
3306:term:`Build Directory`, and then you can
3307force a re-compile and quickly test your altered code. Once you settle
3308on a solution, you can then preserve your changes in the form of
3309patches.
3310
3311During a build, the unpacked temporary source code used by recipes to
3312build packages is available in the Build Directory as defined by the
3313:term:`S` variable. Below is the default
Andrew Geissler09036742021-06-25 14:25:14 -05003314value for the :term:`S` variable as defined in the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003315``meta/conf/bitbake.conf`` configuration file in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05003316:term:`Source Directory`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003317
3318 S = "${WORKDIR}/${BP}"
3319
3320You should be aware that many recipes override the
Andrew Geissler09036742021-06-25 14:25:14 -05003321:term:`S` variable. For example, recipes that fetch their source from Git
3322usually set :term:`S` to ``${WORKDIR}/git``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003323
3324.. note::
3325
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003326 The :term:`BP` represents the base recipe name, which consists of the name
Andrew Geisslerc926e172021-05-07 16:11:35 -05003327 and version::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003328
3329 BP = "${BPN}-${PV}"
3330
3331
3332The path to the work directory for the recipe
3333(:term:`WORKDIR`) is defined as
Andrew Geisslerc926e172021-05-07 16:11:35 -05003334follows::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003335
3336 ${TMPDIR}/work/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR}
3337
3338The actual directory depends on several things:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003339
3340- :term:`TMPDIR`: The top-level build
3341 output directory.
3342
3343- :term:`MULTIMACH_TARGET_SYS`:
3344 The target system identifier.
3345
3346- :term:`PN`: The recipe name.
3347
3348- :term:`EXTENDPE`: The epoch - (if
3349 :term:`PE` is not specified, which is
Andrew Geissler5f350902021-07-23 13:09:54 -04003350 usually the case for most recipes, then :term:`EXTENDPE` is blank).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003351
3352- :term:`PV`: The recipe version.
3353
3354- :term:`PR`: The recipe revision.
3355
3356As an example, assume a Source Directory top-level folder named
3357``poky``, a default Build Directory at ``poky/build``, and a
3358``qemux86-poky-linux`` machine target system. Furthermore, suppose your
3359recipe is named ``foo_1.3.0.bb``. In this case, the work directory the
Andrew Geisslerc926e172021-05-07 16:11:35 -05003360build system uses to build the package would be as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003361
3362 poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
3363
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003364Using Quilt in Your Workflow
3365============================
3366
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003367`Quilt <https://savannah.nongnu.org/projects/quilt>`__ is a powerful tool
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003368that allows you to capture source code changes without having a clean
3369source tree. This section outlines the typical workflow you can use to
3370modify source code, test changes, and then preserve the changes in the
3371form of a patch all using Quilt.
3372
3373.. note::
3374
3375 With regard to preserving changes to source files, if you clean a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003376 recipe or have ``rm_work`` enabled, the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003377 :ref:`devtool workflow <sdk-manual/extensible:using \`\`devtool\`\` in your sdk workflow>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003378 as described in the Yocto Project Application Development and the
3379 Extensible Software Development Kit (eSDK) manual is a safer
3380 development flow than the flow that uses Quilt.
3381
3382Follow these general steps:
3383
33841. *Find the Source Code:* Temporary source code used by the
3385 OpenEmbedded build system is kept in the
3386 :term:`Build Directory`. See the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05003387 ":ref:`dev-manual/common-tasks:finding temporary source code`" section to
3388 learn how to locate the directory that has the temporary source code for a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003389 particular package.
3390
33912. *Change Your Working Directory:* You need to be in the directory that
3392 has the temporary source code. That directory is defined by the
3393 :term:`S` variable.
3394
33953. *Create a New Patch:* Before modifying source code, you need to
3396 create a new patch. To create a new patch file, use ``quilt new`` as
Andrew Geisslerc926e172021-05-07 16:11:35 -05003397 below::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003398
3399 $ quilt new my_changes.patch
3400
34014. *Notify Quilt and Add Files:* After creating the patch, you need to
3402 notify Quilt about the files you plan to edit. You notify Quilt by
Andrew Geisslerc926e172021-05-07 16:11:35 -05003403 adding the files to the patch you just created::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003404
3405 $ quilt add file1.c file2.c file3.c
3406
34075. *Edit the Files:* Make your changes in the source code to the files
3408 you added to the patch.
3409
34106. *Test Your Changes:* Once you have modified the source code, the
3411 easiest way to test your changes is by calling the ``do_compile``
Andrew Geisslerc926e172021-05-07 16:11:35 -05003412 task as shown in the following example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003413
3414 $ bitbake -c compile -f package
3415
3416 The ``-f`` or ``--force`` option forces the specified task to
3417 execute. If you find problems with your code, you can just keep
3418 editing and re-testing iteratively until things work as expected.
3419
3420 .. note::
3421
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003422 All the modifications you make to the temporary source code disappear
3423 once you run the ``do_clean`` or ``do_cleanall`` tasks using BitBake
3424 (i.e. ``bitbake -c clean package`` and ``bitbake -c cleanall package``).
3425 Modifications will also disappear if you use the ``rm_work`` feature as
3426 described in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003427 ":ref:`dev-manual/common-tasks:conserving disk space during builds`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003428 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003429
34307. *Generate the Patch:* Once your changes work as expected, you need to
3431 use Quilt to generate the final patch that contains all your
3432 modifications.
3433 ::
3434
3435 $ quilt refresh
3436
3437 At this point, the
3438 ``my_changes.patch`` file has all your edits made to the ``file1.c``,
3439 ``file2.c``, and ``file3.c`` files.
3440
3441 You can find the resulting patch file in the ``patches/``
Andrew Geissler09036742021-06-25 14:25:14 -05003442 subdirectory of the source (:term:`S`) directory.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003443
34448. *Copy the Patch File:* For simplicity, copy the patch file into a
3445 directory named ``files``, which you can create in the same directory
3446 that holds the recipe (``.bb``) file or the append (``.bbappend``)
3447 file. Placing the patch here guarantees that the OpenEmbedded build
Andrew Geissler09036742021-06-25 14:25:14 -05003448 system will find the patch. Next, add the patch into the :term:`SRC_URI`
Andrew Geisslerc926e172021-05-07 16:11:35 -05003449 of the recipe. Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003450
3451 SRC_URI += "file://my_changes.patch"
3452
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003453Using a Development Shell
3454=========================
3455
3456When debugging certain commands or even when just editing packages,
3457``devshell`` can be a useful tool. When you invoke ``devshell``, all
3458tasks up to and including
3459:ref:`ref-tasks-patch` are run for the
3460specified target. Then, a new terminal is opened and you are placed in
3461``${``\ :term:`S`\ ``}``, the source
3462directory. In the new terminal, all the OpenEmbedded build-related
3463environment variables are still defined so you can use commands such as
3464``configure`` and ``make``. The commands execute just as if the
3465OpenEmbedded build system were executing them. Consequently, working
3466this way can be helpful when debugging a build or preparing software to
3467be used with the OpenEmbedded build system.
3468
3469Following is an example that uses ``devshell`` on a target named
Andrew Geisslerc926e172021-05-07 16:11:35 -05003470``matchbox-desktop``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003471
3472 $ bitbake matchbox-desktop -c devshell
3473
3474This command spawns a terminal with a shell prompt within the
3475OpenEmbedded build environment. The
3476:term:`OE_TERMINAL` variable
3477controls what type of shell is opened.
3478
3479For spawned terminals, the following occurs:
3480
3481- The ``PATH`` variable includes the cross-toolchain.
3482
3483- The ``pkgconfig`` variables find the correct ``.pc`` files.
3484
3485- The ``configure`` command finds the Yocto Project site files as well
3486 as any other necessary files.
3487
3488Within this environment, you can run configure or compile commands as if
3489they were being run by the OpenEmbedded build system itself. As noted
3490earlier, the working directory also automatically changes to the Source
3491Directory (:term:`S`).
3492
3493To manually run a specific task using ``devshell``, run the
3494corresponding ``run.*`` script in the
3495``${``\ :term:`WORKDIR`\ ``}/temp``
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003496directory (e.g., ``run.do_configure.``\ `pid`). If a task's script does
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003497not exist, which would be the case if the task was skipped by way of the
3498sstate cache, you can create the task by first running it outside of the
Andrew Geisslerc926e172021-05-07 16:11:35 -05003499``devshell``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003500
3501 $ bitbake -c task
3502
3503.. note::
3504
3505 - Execution of a task's ``run.*`` script and BitBake's execution of
3506 a task are identical. In other words, running the script re-runs
3507 the task just as it would be run using the ``bitbake -c`` command.
3508
3509 - Any ``run.*`` file that does not have a ``.pid`` extension is a
3510 symbolic link (symlink) to the most recent version of that file.
3511
3512Remember, that the ``devshell`` is a mechanism that allows you to get
3513into the BitBake task execution environment. And as such, all commands
3514must be called just as BitBake would call them. That means you need to
3515provide the appropriate options for cross-compilation and so forth as
3516applicable.
3517
3518When you are finished using ``devshell``, exit the shell or close the
3519terminal window.
3520
3521.. note::
3522
3523 - It is worth remembering that when using ``devshell`` you need to
3524 use the full compiler name such as ``arm-poky-linux-gnueabi-gcc``
3525 instead of just using ``gcc``. The same applies to other
3526 applications such as ``binutils``, ``libtool`` and so forth.
Andrew Geissler09036742021-06-25 14:25:14 -05003527 BitBake sets up environment variables such as :term:`CC` to assist
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003528 applications, such as ``make`` to find the correct tools.
3529
3530 - It is also worth noting that ``devshell`` still works over X11
3531 forwarding and similar situations.
3532
Andrew Geisslereff27472021-10-29 15:35:00 -05003533Using a Python Development Shell
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003534================================
3535
3536Similar to working within a development shell as described in the
3537previous section, you can also spawn and work within an interactive
3538Python development shell. When debugging certain commands or even when
Andrew Geisslereff27472021-10-29 15:35:00 -05003539just editing packages, ``pydevshell`` can be a useful tool. When you
3540invoke the ``pydevshell`` task, all tasks up to and including
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003541:ref:`ref-tasks-patch` are run for the
3542specified target. Then a new terminal is opened. Additionally, key
3543Python objects and code are available in the same way they are to
3544BitBake tasks, in particular, the data store 'd'. So, commands such as
3545the following are useful when exploring the data store and running
Andrew Geisslerc926e172021-05-07 16:11:35 -05003546functions::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003547
3548 pydevshell> d.getVar("STAGING_DIR")
3549 '/media/build1/poky/build/tmp/sysroots'
Andrew Geissler5199d832021-09-24 16:47:35 -05003550 pydevshell> d.getVar("STAGING_DIR", False)
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003551 '${TMPDIR}/sysroots'
3552 pydevshell> d.setVar("FOO", "bar")
3553 pydevshell> d.getVar("FOO")
3554 'bar'
3555 pydevshell> d.delVar("FOO")
3556 pydevshell> d.getVar("FOO")
3557 pydevshell> bb.build.exec_func("do_unpack", d)
3558 pydevshell>
3559
3560The commands execute just as if the OpenEmbedded build
3561system were executing them. Consequently, working this way can be
3562helpful when debugging a build or preparing software to be used with the
3563OpenEmbedded build system.
3564
Andrew Geisslereff27472021-10-29 15:35:00 -05003565Following is an example that uses ``pydevshell`` on a target named
Andrew Geisslerc926e172021-05-07 16:11:35 -05003566``matchbox-desktop``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003567
Andrew Geisslereff27472021-10-29 15:35:00 -05003568 $ bitbake matchbox-desktop -c pydevshell
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003569
3570This command spawns a terminal and places you in an interactive Python
3571interpreter within the OpenEmbedded build environment. The
3572:term:`OE_TERMINAL` variable
3573controls what type of shell is opened.
3574
Andrew Geisslereff27472021-10-29 15:35:00 -05003575When you are finished using ``pydevshell``, you can exit the shell
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003576either by using Ctrl+d or closing the terminal window.
3577
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003578Building
3579========
3580
Andrew Geissler5199d832021-09-24 16:47:35 -05003581This section describes various build procedures, such as the steps
3582needed for a simple build, building a target for multiple configurations,
3583generating an image for more than one machine, and so forth.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003584
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003585Building a Simple Image
3586-----------------------
3587
3588In the development environment, you need to build an image whenever you
3589change hardware support, add or change system libraries, or add or
William A. Kennington IIIac69b482021-06-02 12:28:27 -07003590change services that have dependencies. There are several methods that allow
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003591you to build an image within the Yocto Project. This section presents
3592the basic steps you need to build a simple image using BitBake from a
3593build host running Linux.
3594
3595.. note::
3596
3597 - For information on how to build an image using
3598 :term:`Toaster`, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003599 :doc:`/toaster-manual/index`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003600
3601 - For information on how to use ``devtool`` to build images, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003602 ":ref:`sdk-manual/extensible:using \`\`devtool\`\` in your sdk workflow`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003603 section in the Yocto Project Application Development and the
3604 Extensible Software Development Kit (eSDK) manual.
3605
3606 - For a quick example on how to build an image using the
3607 OpenEmbedded build system, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003608 :doc:`/brief-yoctoprojectqs/index` document.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003609
3610The build process creates an entire Linux distribution from source and
3611places it in your :term:`Build Directory` under
3612``tmp/deploy/images``. For detailed information on the build process
Andrew Geissler09209ee2020-12-13 08:44:15 -06003613using BitBake, see the ":ref:`overview-manual/concepts:images`" section in the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003614Yocto Project Overview and Concepts Manual.
3615
3616The following figure and list overviews the build process:
3617
3618.. image:: figures/bitbake-build-flow.png
3619 :align: center
3620
36211. *Set up Your Host Development System to Support Development Using the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003622 Yocto Project*: See the ":doc:`start`" section for options on how to get a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003623 build host ready to use the Yocto Project.
3624
36252. *Initialize the Build Environment:* Initialize the build environment
3626 by sourcing the build environment script (i.e.
Andrew Geisslerc926e172021-05-07 16:11:35 -05003627 :ref:`structure-core-script`)::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003628
3629 $ source oe-init-build-env [build_dir]
3630
3631 When you use the initialization script, the OpenEmbedded build system
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003632 uses ``build`` as the default :term:`Build Directory` in your current work
3633 directory. You can use a `build_dir` argument with the script to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003634 specify a different build directory.
3635
3636 .. note::
3637
3638 A common practice is to use a different Build Directory for
Andrew Geissler5199d832021-09-24 16:47:35 -05003639 different targets; for example, ``~/build/x86`` for a ``qemux86``
3640 target, and ``~/build/arm`` for a ``qemuarm`` target. In any
3641 event, it's typically cleaner to locate the build directory
3642 somewhere outside of your source directory.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003643
Andrew Geissler4c19ea12020-10-27 13:52:24 -050036443. *Make Sure Your* ``local.conf`` *File is Correct*: Ensure the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003645 ``conf/local.conf`` configuration file, which is found in the Build
3646 Directory, is set up how you want it. This file defines many aspects
3647 of the build environment including the target machine architecture
Andrew Geissler09036742021-06-25 14:25:14 -05003648 through the :term:`MACHINE` variable, the packaging format used during
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003649 the build
3650 (:term:`PACKAGE_CLASSES`),
3651 and a centralized tarball download directory through the
3652 :term:`DL_DIR` variable.
3653
Andrew Geisslerc926e172021-05-07 16:11:35 -050036544. *Build the Image:* Build the image using the ``bitbake`` command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003655
3656 $ bitbake target
3657
3658 .. note::
3659
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003660 For information on BitBake, see the :doc:`bitbake:index`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003661
3662 The target is the name of the recipe you want to build. Common
3663 targets are the images in ``meta/recipes-core/images``,
3664 ``meta/recipes-sato/images``, and so forth all found in the
Andrew Geissler5199d832021-09-24 16:47:35 -05003665 :term:`Source Directory`. Alternatively, the target
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003666 can be the name of a recipe for a specific piece of software such as
3667 BusyBox. For more details about the images the OpenEmbedded build
3668 system supports, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003669 ":ref:`ref-manual/images:Images`" chapter in the Yocto
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003670 Project Reference Manual.
3671
3672 As an example, the following command builds the
Andrew Geisslerc926e172021-05-07 16:11:35 -05003673 ``core-image-minimal`` image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003674
3675 $ bitbake core-image-minimal
3676
3677 Once an
3678 image has been built, it often needs to be installed. The images and
3679 kernels built by the OpenEmbedded build system are placed in the
3680 Build Directory in ``tmp/deploy/images``. For information on how to
3681 run pre-built images such as ``qemux86`` and ``qemuarm``, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003682 :doc:`/sdk-manual/index` manual. For
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003683 information about how to install these images, see the documentation
3684 for your particular board or machine.
3685
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003686Building Images for Multiple Targets Using Multiple Configurations
3687------------------------------------------------------------------
3688
3689You can use a single ``bitbake`` command to build multiple images or
3690packages for different targets where each image or package requires a
3691different configuration (multiple configuration builds). The builds, in
3692this scenario, are sometimes referred to as "multiconfigs", and this
3693section uses that term throughout.
3694
3695This section describes how to set up for multiple configuration builds
3696and how to account for cross-build dependencies between the
3697multiconfigs.
3698
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003699Setting Up and Running a Multiple Configuration Build
3700~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3701
3702To accomplish a multiple configuration build, you must define each
3703target's configuration separately using a parallel configuration file in
3704the :term:`Build Directory`, and you
3705must follow a required file hierarchy. Additionally, you must enable the
3706multiple configuration builds in your ``local.conf`` file.
3707
3708Follow these steps to set up and execute multiple configuration builds:
3709
3710- *Create Separate Configuration Files*: You need to create a single
3711 configuration file for each build target (each multiconfig).
3712 Minimally, each configuration file must define the machine and the
3713 temporary directory BitBake uses for the build. Suggested practice
3714 dictates that you do not overlap the temporary directories used
3715 during the builds. However, it is possible that you can share the
3716 temporary directory
3717 (:term:`TMPDIR`). For example,
3718 consider a scenario with two different multiconfigs for the same
3719 :term:`MACHINE`: "qemux86" built
3720 for two distributions such as "poky" and "poky-lsb". In this case,
Andrew Geissler09036742021-06-25 14:25:14 -05003721 you might want to use the same :term:`TMPDIR`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003722
3723 Here is an example showing the minimal statements needed in a
3724 configuration file for a "qemux86" target whose temporary build
Andrew Geisslerc926e172021-05-07 16:11:35 -05003725 directory is ``tmpmultix86``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003726
3727 MACHINE = "qemux86"
3728 TMPDIR = "${TOPDIR}/tmpmultix86"
3729
3730 The location for these multiconfig configuration files is specific.
3731 They must reside in the current build directory in a sub-directory of
3732 ``conf`` named ``multiconfig``. Following is an example that defines
3733 two configuration files for the "x86" and "arm" multiconfigs:
3734
3735 .. image:: figures/multiconfig_files.png
3736 :align: center
3737
Andrew Geissler09036742021-06-25 14:25:14 -05003738 The reason for this required file hierarchy is because the :term:`BBPATH`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003739 variable is not constructed until the layers are parsed.
3740 Consequently, using the configuration file as a pre-configuration
3741 file is not possible unless it is located in the current working
3742 directory.
3743
3744- *Add the BitBake Multi-configuration Variable to the Local
3745 Configuration File*: Use the
3746 :term:`BBMULTICONFIG`
3747 variable in your ``conf/local.conf`` configuration file to specify
3748 each multiconfig. Continuing with the example from the previous
Andrew Geissler09036742021-06-25 14:25:14 -05003749 figure, the :term:`BBMULTICONFIG` variable needs to enable two
Andrew Geisslerc926e172021-05-07 16:11:35 -05003750 multiconfigs: "x86" and "arm" by specifying each configuration file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003751
3752 BBMULTICONFIG = "x86 arm"
3753
3754 .. note::
3755
3756 A "default" configuration already exists by definition. This
3757 configuration is named: "" (i.e. empty string) and is defined by
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003758 the variables coming from your ``local.conf``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003759 file. Consequently, the previous example actually adds two
3760 additional configurations to your build: "arm" and "x86" along
3761 with "".
3762
3763- *Launch BitBake*: Use the following BitBake command form to launch
Andrew Geisslerc926e172021-05-07 16:11:35 -05003764 the multiple configuration build::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003765
3766 $ bitbake [mc:multiconfigname:]target [[[mc:multiconfigname:]target] ... ]
3767
Andrew Geisslerc926e172021-05-07 16:11:35 -05003768 For the example in this section, the following command applies::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003769
3770 $ bitbake mc:x86:core-image-minimal mc:arm:core-image-sato mc::core-image-base
3771
3772 The previous BitBake command builds a ``core-image-minimal`` image
3773 that is configured through the ``x86.conf`` configuration file, a
3774 ``core-image-sato`` image that is configured through the ``arm.conf``
3775 configuration file and a ``core-image-base`` that is configured
3776 through your ``local.conf`` configuration file.
3777
3778.. note::
3779
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003780 Support for multiple configuration builds in the Yocto Project &DISTRO;
3781 (&DISTRO_NAME;) Release does not include Shared State (sstate)
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003782 optimizations. Consequently, if a build uses the same object twice
Andrew Geissler09036742021-06-25 14:25:14 -05003783 in, for example, two different :term:`TMPDIR`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003784 directories, the build either loads from an existing sstate cache for
3785 that build at the start or builds the object fresh.
3786
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003787Enabling Multiple Configuration Build Dependencies
3788~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3789
3790Sometimes dependencies can exist between targets (multiconfigs) in a
3791multiple configuration build. For example, suppose that in order to
3792build a ``core-image-sato`` image for an "x86" multiconfig, the root
3793filesystem of an "arm" multiconfig must exist. This dependency is
3794essentially that the
3795:ref:`ref-tasks-image` task in the
3796``core-image-sato`` recipe depends on the completion of the
3797:ref:`ref-tasks-rootfs` task of the
3798``core-image-minimal`` recipe.
3799
3800To enable dependencies in a multiple configuration build, you must
3801declare the dependencies in the recipe using the following statement
Andrew Geisslerc926e172021-05-07 16:11:35 -05003802form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003803
3804 task_or_package[mcdepends] = "mc:from_multiconfig:to_multiconfig:recipe_name:task_on_which_to_depend"
3805
3806To better show how to use this statement, consider the example scenario
3807from the first paragraph of this section. The following statement needs
Andrew Geisslerc926e172021-05-07 16:11:35 -05003808to be added to the recipe that builds the ``core-image-sato`` image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003809
3810 do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_rootfs"
3811
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003812In this example, the `from_multiconfig` is "x86". The `to_multiconfig` is "arm". The
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003813task on which the ``do_image`` task in the recipe depends is the
3814``do_rootfs`` task from the ``core-image-minimal`` recipe associated
3815with the "arm" multiconfig.
3816
3817Once you set up this dependency, you can build the "x86" multiconfig
Andrew Geisslerc926e172021-05-07 16:11:35 -05003818using a BitBake command as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003819
3820 $ bitbake mc:x86:core-image-sato
3821
3822This command executes all the tasks needed to create the
3823``core-image-sato`` image for the "x86" multiconfig. Because of the
3824dependency, BitBake also executes through the ``do_rootfs`` task for the
3825"arm" multiconfig build.
3826
3827Having a recipe depend on the root filesystem of another build might not
3828seem that useful. Consider this change to the statement in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05003829``core-image-sato`` recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003830
3831 do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_image"
3832
3833In this case, BitBake must
3834create the ``core-image-minimal`` image for the "arm" build since the
3835"x86" build depends on it.
3836
3837Because "x86" and "arm" are enabled for multiple configuration builds
3838and have separate configuration files, BitBake places the artifacts for
3839each build in the respective temporary build directories (i.e.
3840:term:`TMPDIR`).
3841
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003842Building an Initial RAM Filesystem (initramfs) Image
3843----------------------------------------------------
3844
3845An initial RAM filesystem (initramfs) image provides a temporary root
3846filesystem used for early system initialization (e.g. loading of modules
3847needed to locate and mount the "real" root filesystem).
3848
3849.. note::
3850
3851 The initramfs image is the successor of initial RAM disk (initrd). It
3852 is a "copy in and out" (cpio) archive of the initial filesystem that
3853 gets loaded into memory during the Linux startup process. Because
3854 Linux uses the contents of the archive during initialization, the
3855 initramfs image needs to contain all of the device drivers and tools
3856 needed to mount the final root filesystem.
3857
3858Follow these steps to create an initramfs image:
3859
38601. *Create the initramfs Image Recipe:* You can reference the
3861 ``core-image-minimal-initramfs.bb`` recipe found in the
3862 ``meta/recipes-core`` directory of the :term:`Source Directory`
3863 as an example
3864 from which to work.
3865
38662. *Decide if You Need to Bundle the initramfs Image Into the Kernel
3867 Image:* If you want the initramfs image that is built to be bundled
3868 in with the kernel image, set the
3869 :term:`INITRAMFS_IMAGE_BUNDLE`
3870 variable to "1" in your ``local.conf`` configuration file and set the
3871 :term:`INITRAMFS_IMAGE`
3872 variable in the recipe that builds the kernel image.
3873
3874 .. note::
3875
Andrew Geissler5199d832021-09-24 16:47:35 -05003876 It is recommended that you bundle the initramfs image with the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003877 kernel image to avoid circular dependencies between the kernel
3878 recipe and the initramfs recipe should the initramfs image include
3879 kernel modules.
3880
Andrew Geissler09036742021-06-25 14:25:14 -05003881 Setting the :term:`INITRAMFS_IMAGE_BUNDLE` flag causes the initramfs
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003882 image to be unpacked into the ``${B}/usr/`` directory. The unpacked
3883 initramfs image is then passed to the kernel's ``Makefile`` using the
3884 :term:`CONFIG_INITRAMFS_SOURCE`
3885 variable, allowing the initramfs image to be built into the kernel
3886 normally.
3887
3888 .. note::
3889
Patrick Williams93c203f2021-10-06 16:15:23 -05003890 Bundling the initramfs with the kernel conflates the code in the initramfs
3891 with the GPLv2 licensed Linux kernel binary. Thus only GPLv2 compatible
3892 software may be part of a bundled initramfs.
3893
3894 .. note::
3895
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003896 If you choose to not bundle the initramfs image with the kernel
3897 image, you are essentially using an
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003898 `Initial RAM Disk (initrd) <https://en.wikipedia.org/wiki/Initrd>`__.
3899 Creating an initrd is handled primarily through the :term:`INITRD_IMAGE`,
3900 ``INITRD_LIVE``, and ``INITRD_IMAGE_LIVE`` variables. For more
3901 information, see the :ref:`ref-classes-image-live` file.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003902
39033. *Optionally Add Items to the initramfs Image Through the initramfs
3904 Image Recipe:* If you add items to the initramfs image by way of its
3905 recipe, you should use
3906 :term:`PACKAGE_INSTALL`
3907 rather than
3908 :term:`IMAGE_INSTALL`.
Andrew Geissler09036742021-06-25 14:25:14 -05003909 :term:`PACKAGE_INSTALL` gives more direct control of what is added to the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003910 image as compared to the defaults you might not necessarily want that
3911 are set by the :ref:`image <ref-classes-image>`
3912 or :ref:`core-image <ref-classes-core-image>`
3913 classes.
3914
39154. *Build the Kernel Image and the initramfs Image:* Build your kernel
3916 image using BitBake. Because the initramfs image recipe is a
3917 dependency of the kernel image, the initramfs image is built as well
3918 and bundled with the kernel image if you used the
3919 :term:`INITRAMFS_IMAGE_BUNDLE`
3920 variable described earlier.
3921
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00003922Bundling an Initramfs Image From a Separate Multiconfig
3923~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3924
3925There may be a case where we want to build an initramfs image which does not
3926inherit the same distro policy as our main image, for example, we may want
3927our main image to use ``TCLIBC="glibc"``, but to use ``TCLIBC="musl"`` in our initramfs
3928image to keep a smaller footprint. However, by performing the steps mentioned
3929above the initramfs image will inherit ``TCLIBC="glibc"`` without allowing us
3930to override it.
3931
3932To achieve this, you need to perform some additional steps:
3933
39341. *Create a multiconfig for your initramfs image:* You can perform the steps
3935 on ":ref:`dev-manual/common-tasks:building images for multiple targets using multiple configurations`" to create a separate multiconfig.
3936 For the sake of simplicity let's assume such multiconfig is called: ``initramfscfg.conf`` and
3937 contains the variables::
3938
3939 TMPDIR="${TOPDIR}/tmp-initramfscfg"
3940 TCLIBC="musl"
3941
39422. *Set additional initramfs variables on your main configuration:*
3943 Additionally, on your main configuration (``local.conf``) you need to set the
3944 variables::
3945
3946 INITRAMFS_MULTICONFIG = "initramfscfg"
3947 INITRAMFS_DEPLOY_DIR_IMAGE = "${TOPDIR}/tmp-initramfscfg/deploy/images/${MACHINE}"
3948
3949 The variables :term:`INITRAMFS_MULTICONFIG` and :term:`INITRAMFS_DEPLOY_DIR_IMAGE`
3950 are used to create a multiconfig dependency from the kernel to the :term:`INITRAMFS_IMAGE`
3951 to be built coming from the ``initramfscfg`` multiconfig, and to let the
3952 buildsystem know where the :term:`INITRAMFS_IMAGE` will be located.
3953
3954 Building a system with such configuration will build the kernel using the
3955 main configuration but the ``do_bundle_initramfs`` task will grab the
3956 selected :term:`INITRAMFS_IMAGE` from :term:`INITRAMFS_DEPLOY_DIR_IMAGE`
3957 instead, resulting in a musl based initramfs image bundled in the kernel
3958 but a glibc based main image.
3959
3960 The same is applicable to avoid inheriting :term:`DISTRO_FEATURES` on :term:`INITRAMFS_IMAGE`
3961 or to build a different :term:`DISTRO` for it such as ``poky-tiny``.
3962
3963
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003964Building a Tiny System
3965----------------------
3966
3967Very small distributions have some significant advantages such as
3968requiring less on-die or in-package memory (cheaper), better performance
3969through efficient cache usage, lower power requirements due to less
3970memory, faster boot times, and reduced development overhead. Some
3971real-world examples where a very small distribution gives you distinct
3972advantages are digital cameras, medical devices, and small headless
3973systems.
3974
3975This section presents information that shows you how you can trim your
3976distribution to even smaller sizes than the ``poky-tiny`` distribution,
3977which is around 5 Mbytes, that can be built out-of-the-box using the
3978Yocto Project.
3979
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003980Tiny System Overview
3981~~~~~~~~~~~~~~~~~~~~
3982
3983The following list presents the overall steps you need to consider and
3984perform to create distributions with smaller root filesystems, achieve
3985faster boot times, maintain your critical functionality, and avoid
3986initial RAM disks:
3987
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05003988- :ref:`Determine your goals and guiding principles
3989 <dev-manual/common-tasks:goals and guiding principles>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003990
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05003991- :ref:`dev-manual/common-tasks:understand what contributes to your image size`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003992
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05003993- :ref:`Reduce the size of the root filesystem
3994 <dev-manual/common-tasks:trim the root filesystem>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003995
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05003996- :ref:`Reduce the size of the kernel <dev-manual/common-tasks:trim the kernel>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003997
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05003998- :ref:`dev-manual/common-tasks:remove package management requirements`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003999
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004000- :ref:`dev-manual/common-tasks:look for other ways to minimize size`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004001
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004002- :ref:`dev-manual/common-tasks:iterate on the process`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004003
4004Goals and Guiding Principles
4005~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4006
4007Before you can reach your destination, you need to know where you are
4008going. Here is an example list that you can use as a guide when creating
4009very small distributions:
4010
4011- Determine how much space you need (e.g. a kernel that is 1 Mbyte or
4012 less and a root filesystem that is 3 Mbytes or less).
4013
4014- Find the areas that are currently taking 90% of the space and
4015 concentrate on reducing those areas.
4016
4017- Do not create any difficult "hacks" to achieve your goals.
4018
4019- Leverage the device-specific options.
4020
4021- Work in a separate layer so that you keep changes isolated. For
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004022 information on how to create layers, see the
4023 ":ref:`dev-manual/common-tasks:understanding and creating layers`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004024
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004025Understand What Contributes to Your Image Size
4026~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4027
4028It is easiest to have something to start with when creating your own
4029distribution. You can use the Yocto Project out-of-the-box to create the
4030``poky-tiny`` distribution. Ultimately, you will want to make changes in
4031your own distribution that are likely modeled after ``poky-tiny``.
4032
4033.. note::
4034
Andrew Geissler09036742021-06-25 14:25:14 -05004035 To use ``poky-tiny`` in your build, set the :term:`DISTRO` variable in your
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004036 ``local.conf`` file to "poky-tiny" as described in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06004037 ":ref:`dev-manual/common-tasks:creating your own distribution`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004038 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004039
4040Understanding some memory concepts will help you reduce the system size.
4041Memory consists of static, dynamic, and temporary memory. Static memory
4042is the TEXT (code), DATA (initialized data in the code), and BSS
4043(uninitialized data) sections. Dynamic memory represents memory that is
4044allocated at runtime: stacks, hash tables, and so forth. Temporary
4045memory is recovered after the boot process. This memory consists of
4046memory used for decompressing the kernel and for the ``__init__``
4047functions.
4048
4049To help you see where you currently are with kernel and root filesystem
4050sizes, you can use two tools found in the :term:`Source Directory`
4051in the
4052``scripts/tiny/`` directory:
4053
4054- ``ksize.py``: Reports component sizes for the kernel build objects.
4055
4056- ``dirsize.py``: Reports component sizes for the root filesystem.
4057
4058This next tool and command help you organize configuration fragments and
4059view file dependencies in a human-readable form:
4060
4061- ``merge_config.sh``: Helps you manage configuration files and
4062 fragments within the kernel. With this tool, you can merge individual
4063 configuration fragments together. The tool allows you to make
4064 overrides and warns you of any missing configuration options. The
4065 tool is ideal for allowing you to iterate on configurations, create
4066 minimal configurations, and create configuration files for different
4067 machines without having to duplicate your process.
4068
4069 The ``merge_config.sh`` script is part of the Linux Yocto kernel Git
4070 repositories (i.e. ``linux-yocto-3.14``, ``linux-yocto-3.10``,
4071 ``linux-yocto-3.8``, and so forth) in the ``scripts/kconfig``
4072 directory.
4073
4074 For more information on configuration fragments, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06004075 ":ref:`kernel-dev/common:creating configuration fragments`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004076 section in the Yocto Project Linux Kernel Development Manual.
4077
4078- ``bitbake -u taskexp -g bitbake_target``: Using the BitBake command
4079 with these options brings up a Dependency Explorer from which you can
4080 view file dependencies. Understanding these dependencies allows you
4081 to make informed decisions when cutting out various pieces of the
4082 kernel and root filesystem.
4083
4084Trim the Root Filesystem
4085~~~~~~~~~~~~~~~~~~~~~~~~
4086
4087The root filesystem is made up of packages for booting, libraries, and
4088applications. To change things, you can configure how the packaging
4089happens, which changes the way you build them. You can also modify the
4090filesystem itself or select a different filesystem.
4091
4092First, find out what is hogging your root filesystem by running the
Andrew Geisslerc926e172021-05-07 16:11:35 -05004093``dirsize.py`` script from your root directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004094
4095 $ cd root-directory-of-image
4096 $ dirsize.py 100000 > dirsize-100k.log
4097 $ cat dirsize-100k.log
4098
4099You can apply a filter to the script to ignore files
4100under a certain size. The previous example filters out any files below
4101100 Kbytes. The sizes reported by the tool are uncompressed, and thus
4102will be smaller by a relatively constant factor in a compressed root
4103filesystem. When you examine your log file, you can focus on areas of
4104the root filesystem that take up large amounts of memory.
4105
4106You need to be sure that what you eliminate does not cripple the
4107functionality you need. One way to see how packages relate to each other
Andrew Geisslerc926e172021-05-07 16:11:35 -05004108is by using the Dependency Explorer UI with the BitBake command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004109
4110 $ cd image-directory
4111 $ bitbake -u taskexp -g image
4112
4113Use the interface to
4114select potential packages you wish to eliminate and see their dependency
4115relationships.
4116
4117When deciding how to reduce the size, get rid of packages that result in
4118minimal impact on the feature set. For example, you might not need a VGA
4119display. Or, you might be able to get by with ``devtmpfs`` and ``mdev``
4120instead of ``udev``.
4121
4122Use your ``local.conf`` file to make changes. For example, to eliminate
4123``udev`` and ``glib``, set the following in the local configuration
Andrew Geisslerc926e172021-05-07 16:11:35 -05004124file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004125
4126 VIRTUAL-RUNTIME_dev_manager = ""
4127
4128Finally, you should consider exactly the type of root filesystem you
4129need to meet your needs while also reducing its size. For example,
4130consider ``cramfs``, ``squashfs``, ``ubifs``, ``ext2``, or an
4131``initramfs`` using ``initramfs``. Be aware that ``ext3`` requires a 1
4132Mbyte journal. If you are okay with running read-only, you do not need
4133this journal.
4134
4135.. note::
4136
4137 After each round of elimination, you need to rebuild your system and
4138 then use the tools to see the effects of your reductions.
4139
4140Trim the Kernel
4141~~~~~~~~~~~~~~~
4142
4143The kernel is built by including policies for hardware-independent
4144aspects. What subsystems do you enable? For what architecture are you
4145building? Which drivers do you build by default?
4146
4147.. note::
4148
4149 You can modify the kernel source if you want to help with boot time.
4150
4151Run the ``ksize.py`` script from the top-level Linux build directory to
Andrew Geisslerc926e172021-05-07 16:11:35 -05004152get an idea of what is making up the kernel::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004153
4154 $ cd top-level-linux-build-directory
4155 $ ksize.py > ksize.log
4156 $ cat ksize.log
4157
4158When you examine the log, you will see how much space is taken up with
4159the built-in ``.o`` files for drivers, networking, core kernel files,
4160filesystem, sound, and so forth. The sizes reported by the tool are
4161uncompressed, and thus will be smaller by a relatively constant factor
4162in a compressed kernel image. Look to reduce the areas that are large
4163and taking up around the "90% rule."
4164
4165To examine, or drill down, into any particular area, use the ``-d``
Andrew Geisslerc926e172021-05-07 16:11:35 -05004166option with the script::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004167
4168 $ ksize.py -d > ksize.log
4169
4170Using this option
4171breaks out the individual file information for each area of the kernel
4172(e.g. drivers, networking, and so forth).
4173
4174Use your log file to see what you can eliminate from the kernel based on
4175features you can let go. For example, if you are not going to need
4176sound, you do not need any drivers that support sound.
4177
4178After figuring out what to eliminate, you need to reconfigure the kernel
4179to reflect those changes during the next build. You could run
4180``menuconfig`` and make all your changes at once. However, that makes it
4181difficult to see the effects of your individual eliminations and also
4182makes it difficult to replicate the changes for perhaps another target
4183device. A better method is to start with no configurations using
4184``allnoconfig``, create configuration fragments for individual changes,
4185and then manage the fragments into a single configuration file using
4186``merge_config.sh``. The tool makes it easy for you to iterate using the
4187configuration change and build cycle.
4188
4189Each time you make configuration changes, you need to rebuild the kernel
4190and check to see what impact your changes had on the overall size.
4191
4192Remove Package Management Requirements
4193~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4194
4195Packaging requirements add size to the image. One way to reduce the size
4196of the image is to remove all the packaging requirements from the image.
4197This reduction includes both removing the package manager and its unique
4198dependencies as well as removing the package management data itself.
4199
4200To eliminate all the packaging requirements for an image, be sure that
4201"package-management" is not part of your
4202:term:`IMAGE_FEATURES`
4203statement for the image. When you remove this feature, you are removing
4204the package manager as well as its dependencies from the root
4205filesystem.
4206
4207Look for Other Ways to Minimize Size
4208~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4209
4210Depending on your particular circumstances, other areas that you can
4211trim likely exist. The key to finding these areas is through tools and
4212methods described here combined with experimentation and iteration. Here
4213are a couple of areas to experiment with:
4214
4215- ``glibc``: In general, follow this process:
4216
4217 1. Remove ``glibc`` features from
4218 :term:`DISTRO_FEATURES`
4219 that you think you do not need.
4220
4221 2. Build your distribution.
4222
4223 3. If the build fails due to missing symbols in a package, determine
4224 if you can reconfigure the package to not need those features. For
4225 example, change the configuration to not support wide character
4226 support as is done for ``ncurses``. Or, if support for those
4227 characters is needed, determine what ``glibc`` features provide
4228 the support and restore the configuration.
4229
4230 4. Rebuild and repeat the process.
4231
4232- ``busybox``: For BusyBox, use a process similar as described for
4233 ``glibc``. A difference is you will need to boot the resulting system
4234 to see if you are able to do everything you expect from the running
4235 system. You need to be sure to integrate configuration fragments into
4236 Busybox because BusyBox handles its own core features and then allows
4237 you to add configuration fragments on top.
4238
4239Iterate on the Process
4240~~~~~~~~~~~~~~~~~~~~~~
4241
4242If you have not reached your goals on system size, you need to iterate
4243on the process. The process is the same. Use the tools and see just what
4244is taking up 90% of the root filesystem and the kernel. Decide what you
4245can eliminate without limiting your device beyond what you need.
4246
4247Depending on your system, a good place to look might be Busybox, which
4248provides a stripped down version of Unix tools in a single, executable
4249file. You might be able to drop virtual terminal services or perhaps
4250ipv6.
4251
4252Building Images for More than One Machine
4253-----------------------------------------
4254
4255A common scenario developers face is creating images for several
4256different machines that use the same software environment. In this
4257situation, it is tempting to set the tunings and optimization flags for
4258each build specifically for the targeted hardware (i.e. "maxing out" the
4259tunings). Doing so can considerably add to build times and package feed
4260maintenance collectively for the machines. For example, selecting tunes
4261that are extremely specific to a CPU core used in a system might enable
4262some micro optimizations in GCC for that particular system but would
4263otherwise not gain you much of a performance difference across the other
4264systems as compared to using a more general tuning across all the builds
4265(e.g. setting :term:`DEFAULTTUNE`
4266specifically for each machine's build). Rather than "max out" each
4267build's tunings, you can take steps that cause the OpenEmbedded build
4268system to reuse software across the various machines where it makes
4269sense.
4270
4271If build speed and package feed maintenance are considerations, you
4272should consider the points in this section that can help you optimize
4273your tunings to best consider build times and package feed maintenance.
4274
4275- *Share the Build Directory:* If at all possible, share the
4276 :term:`TMPDIR` across builds. The
4277 Yocto Project supports switching between different
4278 :term:`MACHINE` values in the same
Andrew Geissler09036742021-06-25 14:25:14 -05004279 :term:`TMPDIR`. This practice is well supported and regularly used by
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004280 developers when building for multiple machines. When you use the same
Andrew Geissler09036742021-06-25 14:25:14 -05004281 :term:`TMPDIR` for multiple machine builds, the OpenEmbedded build system
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004282 can reuse the existing native and often cross-recipes for multiple
4283 machines. Thus, build time decreases.
4284
4285 .. note::
4286
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004287 If :term:`DISTRO` settings change or fundamental configuration settings
Andrew Geissler09036742021-06-25 14:25:14 -05004288 such as the filesystem layout, you need to work with a clean :term:`TMPDIR`.
4289 Sharing :term:`TMPDIR` under these circumstances might work but since it is
Andrew Geissler5f350902021-07-23 13:09:54 -04004290 not guaranteed, you should use a clean :term:`TMPDIR`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004291
4292- *Enable the Appropriate Package Architecture:* By default, the
4293 OpenEmbedded build system enables three levels of package
4294 architectures: "all", "tune" or "package", and "machine". Any given
4295 recipe usually selects one of these package architectures (types) for
4296 its output. Depending for what a given recipe creates packages,
4297 making sure you enable the appropriate package architecture can
4298 directly impact the build time.
4299
4300 A recipe that just generates scripts can enable "all" architecture
4301 because there are no binaries to build. To specifically enable "all"
4302 architecture, be sure your recipe inherits the
4303 :ref:`allarch <ref-classes-allarch>` class.
4304 This class is useful for "all" architectures because it configures
4305 many variables so packages can be used across multiple architectures.
4306
4307 If your recipe needs to generate packages that are machine-specific
4308 or when one of the build or runtime dependencies is already
4309 machine-architecture dependent, which makes your recipe also
4310 machine-architecture dependent, make sure your recipe enables the
4311 "machine" package architecture through the
4312 :term:`MACHINE_ARCH`
Andrew Geisslerc926e172021-05-07 16:11:35 -05004313 variable::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004314
4315 PACKAGE_ARCH = "${MACHINE_ARCH}"
4316
4317 When you do not
4318 specifically enable a package architecture through the
4319 :term:`PACKAGE_ARCH`, The
4320 OpenEmbedded build system defaults to the
Andrew Geisslerc926e172021-05-07 16:11:35 -05004321 :term:`TUNE_PKGARCH` setting::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004322
4323 PACKAGE_ARCH = "${TUNE_PKGARCH}"
4324
4325- *Choose a Generic Tuning File if Possible:* Some tunes are more
4326 generic and can run on multiple targets (e.g. an ``armv5`` set of
4327 packages could run on ``armv6`` and ``armv7`` processors in most
4328 cases). Similarly, ``i486`` binaries could work on ``i586`` and
4329 higher processors. You should realize, however, that advances on
4330 newer processor versions would not be used.
4331
4332 If you select the same tune for several different machines, the
4333 OpenEmbedded build system reuses software previously built, thus
4334 speeding up the overall build time. Realize that even though a new
4335 sysroot for each machine is generated, the software is not recompiled
4336 and only one package feed exists.
4337
William A. Kennington IIIac69b482021-06-02 12:28:27 -07004338- *Manage Granular Level Packaging:* Sometimes there are cases where
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004339 injecting another level of package architecture beyond the three
4340 higher levels noted earlier can be useful. For example, consider how
4341 NXP (formerly Freescale) allows for the easy reuse of binary packages
4342 in their layer
Andrew Geissler09209ee2020-12-13 08:44:15 -06004343 :yocto_git:`meta-freescale </meta-freescale/>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004344 In this example, the
Andrew Geissler09209ee2020-12-13 08:44:15 -06004345 :yocto_git:`fsl-dynamic-packagearch </meta-freescale/tree/classes/fsl-dynamic-packagearch.bbclass>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004346 class shares GPU packages for i.MX53 boards because all boards share
4347 the AMD GPU. The i.MX6-based boards can do the same because all
4348 boards share the Vivante GPU. This class inspects the BitBake
4349 datastore to identify if the package provides or depends on one of
4350 the sub-architecture values. If so, the class sets the
4351 :term:`PACKAGE_ARCH` value
4352 based on the ``MACHINE_SUBARCH`` value. If the package does not
4353 provide or depend on one of the sub-architecture values but it
4354 matches a value in the machine-specific filter, it sets
4355 :term:`MACHINE_ARCH`. This
4356 behavior reduces the number of packages built and saves build time by
4357 reusing binaries.
4358
4359- *Use Tools to Debug Issues:* Sometimes you can run into situations
4360 where software is being rebuilt when you think it should not be. For
4361 example, the OpenEmbedded build system might not be using shared
4362 state between machines when you think it should be. These types of
4363 situations are usually due to references to machine-specific
4364 variables such as :term:`MACHINE`,
4365 :term:`SERIAL_CONSOLES`,
4366 :term:`XSERVER`,
4367 :term:`MACHINE_FEATURES`,
4368 and so forth in code that is supposed to only be tune-specific or
4369 when the recipe depends
4370 (:term:`DEPENDS`,
4371 :term:`RDEPENDS`,
4372 :term:`RRECOMMENDS`,
4373 :term:`RSUGGESTS`, and so forth)
4374 on some other recipe that already has
4375 :term:`PACKAGE_ARCH` defined
4376 as "${MACHINE_ARCH}".
4377
4378 .. note::
4379
4380 Patches to fix any issues identified are most welcome as these
4381 issues occasionally do occur.
4382
4383 For such cases, you can use some tools to help you sort out the
4384 situation:
4385
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004386 - ``state-diff-machines.sh``*:* You can find this tool in the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004387 ``scripts`` directory of the Source Repositories. See the comments
4388 in the script for information on how to use the tool.
4389
4390 - *BitBake's "-S printdiff" Option:* Using this option causes
4391 BitBake to try to establish the closest signature match it can
4392 (e.g. in the shared state cache) and then run ``bitbake-diffsigs``
4393 over the matches to determine the stamps and delta where these two
4394 stamp trees diverge.
4395
4396Building Software from an External Source
4397-----------------------------------------
4398
4399By default, the OpenEmbedded build system uses the
4400:term:`Build Directory` when building source
4401code. The build process involves fetching the source files, unpacking
4402them, and then patching them if necessary before the build takes place.
4403
William A. Kennington IIIac69b482021-06-02 12:28:27 -07004404There are situations where you might want to build software from source
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004405files that are external to and thus outside of the OpenEmbedded build
4406system. For example, suppose you have a project that includes a new BSP
4407with a heavily customized kernel. And, you want to minimize exposing the
4408build system to the development team so that they can focus on their
4409project and maintain everyone's workflow as much as possible. In this
4410case, you want a kernel source directory on the development machine
4411where the development occurs. You want the recipe's
4412:term:`SRC_URI` variable to point to
4413the external directory and use it as is, not copy it.
4414
4415To build from software that comes from an external source, all you need
4416to do is inherit the
4417:ref:`externalsrc <ref-classes-externalsrc>` class
4418and then set the
4419:term:`EXTERNALSRC` variable to
4420point to your external source code. Here are the statements to put in
Andrew Geisslerc926e172021-05-07 16:11:35 -05004421your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004422
4423 INHERIT += "externalsrc"
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004424 EXTERNALSRC:pn-myrecipe = "path-to-your-source-tree"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004425
4426This next example shows how to accomplish the same thing by setting
Andrew Geissler09036742021-06-25 14:25:14 -05004427:term:`EXTERNALSRC` in the recipe itself or in the recipe's append file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004428
4429 EXTERNALSRC = "path"
4430 EXTERNALSRC_BUILD = "path"
4431
4432.. note::
4433
4434 In order for these settings to take effect, you must globally or
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004435 locally inherit the :ref:`externalsrc <ref-classes-externalsrc>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004436 class.
4437
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00004438By default, :ref:`ref-classes-externalsrc` builds the source code in a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004439directory separate from the external source directory as specified by
4440:term:`EXTERNALSRC`. If you need
4441to have the source built in the same directory in which it resides, or
4442some other nominated directory, you can set
4443:term:`EXTERNALSRC_BUILD`
Andrew Geisslerc926e172021-05-07 16:11:35 -05004444to point to that directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004445
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004446 EXTERNALSRC_BUILD:pn-myrecipe = "path-to-your-source-tree"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004447
4448Replicating a Build Offline
4449---------------------------
4450
4451It can be useful to take a "snapshot" of upstream sources used in a
4452build and then use that "snapshot" later to replicate the build offline.
4453To do so, you need to first prepare and populate your downloads
4454directory your "snapshot" of files. Once your downloads directory is
4455ready, you can use it at any time and from any machine to replicate your
4456build.
4457
4458Follow these steps to populate your Downloads directory:
4459
44601. *Create a Clean Downloads Directory:* Start with an empty downloads
4461 directory (:term:`DL_DIR`). You
4462 start with an empty downloads directory by either removing the files
Andrew Geissler09036742021-06-25 14:25:14 -05004463 in the existing directory or by setting :term:`DL_DIR` to point to either
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004464 an empty location or one that does not yet exist.
4465
44662. *Generate Tarballs of the Source Git Repositories:* Edit your
Andrew Geisslerc926e172021-05-07 16:11:35 -05004467 ``local.conf`` configuration file as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004468
4469 DL_DIR = "/home/your-download-dir/"
4470 BB_GENERATE_MIRROR_TARBALLS = "1"
4471
4472 During
4473 the fetch process in the next step, BitBake gathers the source files
Andrew Geissler09036742021-06-25 14:25:14 -05004474 and creates tarballs in the directory pointed to by :term:`DL_DIR`. See
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004475 the
4476 :term:`BB_GENERATE_MIRROR_TARBALLS`
4477 variable for more information.
4478
44793. *Populate Your Downloads Directory Without Building:* Use BitBake to
Andrew Geisslerc926e172021-05-07 16:11:35 -05004480 fetch your sources but inhibit the build::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004481
4482 $ bitbake target --runonly=fetch
4483
4484 The downloads directory (i.e. ``${DL_DIR}``) now has
4485 a "snapshot" of the source files in the form of tarballs, which can
4486 be used for the build.
4487
44884. *Optionally Remove Any Git or other SCM Subdirectories From the
4489 Downloads Directory:* If you want, you can clean up your downloads
4490 directory by removing any Git or other Source Control Management
4491 (SCM) subdirectories such as ``${DL_DIR}/git2/*``. The tarballs
4492 already contain these subdirectories.
4493
4494Once your downloads directory has everything it needs regarding source
4495files, you can create your "own-mirror" and build your target.
4496Understand that you can use the files to build the target offline from
4497any machine and at any time.
4498
4499Follow these steps to build your target using the files in the downloads
4500directory:
4501
45021. *Using Local Files Only:* Inside your ``local.conf`` file, add the
Andrew Geissler595f6302022-01-24 19:11:47 +00004503 :term:`SOURCE_MIRROR_URL` variable, inherit the
4504 :ref:`own-mirrors <ref-classes-own-mirrors>` class, and use the
4505 :term:`BB_NO_NETWORK` variable to your ``local.conf``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004506 ::
4507
4508 SOURCE_MIRROR_URL ?= "file:///home/your-download-dir/"
4509 INHERIT += "own-mirrors"
4510 BB_NO_NETWORK = "1"
4511
Andrew Geissler595f6302022-01-24 19:11:47 +00004512 The :term:`SOURCE_MIRROR_URL` and :ref:`own-mirrors <ref-classes-own-mirrors>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004513 class set up the system to use the downloads directory as your "own
Andrew Geissler09036742021-06-25 14:25:14 -05004514 mirror". Using the :term:`BB_NO_NETWORK` variable makes sure that
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004515 BitBake's fetching process in step 3 stays local, which means files
4516 from your "own-mirror" are used.
4517
45182. *Start With a Clean Build:* You can start with a clean build by
4519 removing the
4520 ``${``\ :term:`TMPDIR`\ ``}``
4521 directory or using a new :term:`Build Directory`.
4522
Andrew Geisslerc926e172021-05-07 16:11:35 -050045233. *Build Your Target:* Use BitBake to build your target::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004524
4525 $ bitbake target
4526
4527 The build completes using the known local "snapshot" of source
4528 files from your mirror. The resulting tarballs for your "snapshot" of
4529 source files are in the downloads directory.
4530
4531 .. note::
4532
4533 The offline build does not work if recipes attempt to find the
4534 latest version of software by setting
4535 :term:`SRCREV` to
Andrew Geisslerc926e172021-05-07 16:11:35 -05004536 ``${``\ :term:`AUTOREV`\ ``}``::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004537
4538 SRCREV = "${AUTOREV}"
4539
Andrew Geissler09036742021-06-25 14:25:14 -05004540 When a recipe sets :term:`SRCREV` to
Andrew Geissler5199d832021-09-24 16:47:35 -05004541 ``${``\ :term:`AUTOREV`\ ``}``, the build system accesses the network in an
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004542 attempt to determine the latest version of software from the SCM.
Andrew Geissler09036742021-06-25 14:25:14 -05004543 Typically, recipes that use :term:`AUTOREV` are custom or modified
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004544 recipes. Recipes that reside in public repositories usually do not
Andrew Geissler09036742021-06-25 14:25:14 -05004545 use :term:`AUTOREV`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004546
Andrew Geissler09036742021-06-25 14:25:14 -05004547 If you do have recipes that use :term:`AUTOREV`, you can take steps to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004548 still use the recipes in an offline build. Do the following:
4549
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004550 1. Use a configuration generated by enabling :ref:`build
4551 history <dev-manual/common-tasks:maintaining build output quality>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004552
4553 2. Use the ``buildhistory-collect-srcrevs`` command to collect the
Andrew Geissler09036742021-06-25 14:25:14 -05004554 stored :term:`SRCREV` values from the build's history. For more
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004555 information on collecting these values, see the
4556 ":ref:`dev-manual/common-tasks:build history package information`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004557 section.
4558
4559 3. Once you have the correct source revisions, you can modify
Andrew Geissler09036742021-06-25 14:25:14 -05004560 those recipes to set :term:`SRCREV` to specific versions of the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004561 software.
4562
4563Speeding Up a Build
4564===================
4565
4566Build time can be an issue. By default, the build system uses simple
4567controls to try and maximize build efficiency. In general, the default
4568settings for all the following variables result in the most efficient
4569build times when dealing with single socket systems (i.e. a single CPU).
4570If you have multiple CPUs, you might try increasing the default values
4571to gain more speed. See the descriptions in the glossary for each
4572variable for more information:
4573
4574- :term:`BB_NUMBER_THREADS`:
4575 The maximum number of threads BitBake simultaneously executes.
4576
Patrick Williams213cb262021-08-07 19:21:33 -05004577- :term:`BB_NUMBER_PARSE_THREADS`:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004578 The number of threads BitBake uses during parsing.
4579
4580- :term:`PARALLEL_MAKE`: Extra
4581 options passed to the ``make`` command during the
4582 :ref:`ref-tasks-compile` task in
4583 order to specify parallel compilation on the local build host.
4584
4585- :term:`PARALLEL_MAKEINST`:
4586 Extra options passed to the ``make`` command during the
4587 :ref:`ref-tasks-install` task in
4588 order to specify parallel installation on the local build host.
4589
4590As mentioned, these variables all scale to the number of processor cores
4591available on the build system. For single socket systems, this
4592auto-scaling ensures that the build system fundamentally takes advantage
4593of potential parallel operations during the build based on the build
4594machine's capabilities.
4595
4596Following are additional factors that can affect build speed:
4597
4598- File system type: The file system type that the build is being
4599 performed on can also influence performance. Using ``ext4`` is
4600 recommended as compared to ``ext2`` and ``ext3`` due to ``ext4``
4601 improved features such as extents.
4602
4603- Disabling the updating of access time using ``noatime``: The
4604 ``noatime`` mount option prevents the build system from updating file
4605 and directory access times.
4606
4607- Setting a longer commit: Using the "commit=" mount option increases
4608 the interval in seconds between disk cache writes. Changing this
4609 interval from the five second default to something longer increases
4610 the risk of data loss but decreases the need to write to the disk,
4611 thus increasing the build performance.
4612
4613- Choosing the packaging backend: Of the available packaging backends,
4614 IPK is the fastest. Additionally, selecting a singular packaging
4615 backend also helps.
4616
4617- Using ``tmpfs`` for :term:`TMPDIR`
4618 as a temporary file system: While this can help speed up the build,
4619 the benefits are limited due to the compiler using ``-pipe``. The
4620 build system goes to some lengths to avoid ``sync()`` calls into the
4621 file system on the principle that if there was a significant failure,
4622 the :term:`Build Directory`
4623 contents could easily be rebuilt.
4624
4625- Inheriting the
4626 :ref:`rm_work <ref-classes-rm-work>` class:
4627 Inheriting this class has shown to speed up builds due to
4628 significantly lower amounts of data stored in the data cache as well
4629 as on disk. Inheriting this class also makes cleanup of
4630 :term:`TMPDIR` faster, at the
4631 expense of being easily able to dive into the source code. File
4632 system maintainers have recommended that the fastest way to clean up
4633 large numbers of files is to reformat partitions rather than delete
4634 files due to the linear nature of partitions. This, of course,
4635 assumes you structure the disk partitions and file systems in a way
4636 that this is practical.
4637
4638Aside from the previous list, you should keep some trade offs in mind
4639that can help you speed up the build:
4640
4641- Remove items from
4642 :term:`DISTRO_FEATURES`
4643 that you might not need.
4644
4645- Exclude debug symbols and other debug information: If you do not need
4646 these symbols and other debug information, disabling the ``*-dbg``
4647 package generation can speed up the build. You can disable this
4648 generation by setting the
4649 :term:`INHIBIT_PACKAGE_DEBUG_SPLIT`
4650 variable to "1".
4651
4652- Disable static library generation for recipes derived from
4653 ``autoconf`` or ``libtool``: Following is an example showing how to
4654 disable static libraries and still provide an override to handle
Andrew Geisslerc926e172021-05-07 16:11:35 -05004655 exceptions::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004656
4657 STATICLIBCONF = "--disable-static"
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004658 STATICLIBCONF:sqlite3-native = ""
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004659 EXTRA_OECONF += "${STATICLIBCONF}"
4660
4661 .. note::
4662
4663 - Some recipes need static libraries in order to work correctly
4664 (e.g. ``pseudo-native`` needs ``sqlite3-native``). Overrides,
4665 as in the previous example, account for these kinds of
4666 exceptions.
4667
4668 - Some packages have packaging code that assumes the presence of
4669 the static libraries. If so, you might need to exclude them as
4670 well.
4671
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004672Working With Libraries
4673======================
4674
4675Libraries are an integral part of your system. This section describes
4676some common practices you might find helpful when working with libraries
4677to build your system:
4678
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004679- :ref:`How to include static library files
4680 <dev-manual/common-tasks:including static library files>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004681
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004682- :ref:`How to use the Multilib feature to combine multiple versions of
4683 library files into a single image
4684 <dev-manual/common-tasks:combining multiple versions of library files into one image>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004685
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004686- :ref:`How to install multiple versions of the same library in parallel on
4687 the same system
4688 <dev-manual/common-tasks:installing multiple versions of the same library>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004689
4690Including Static Library Files
4691------------------------------
4692
4693If you are building a library and the library offers static linking, you
4694can control which static library files (``*.a`` files) get included in
4695the built library.
4696
4697The :term:`PACKAGES` and
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004698:term:`FILES:* <FILES>` variables in the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004699``meta/conf/bitbake.conf`` configuration file define how files installed
Andrew Geissler09036742021-06-25 14:25:14 -05004700by the ``do_install`` task are packaged. By default, the :term:`PACKAGES`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004701variable includes ``${PN}-staticdev``, which represents all static
4702library files.
4703
4704.. note::
4705
4706 Some previously released versions of the Yocto Project defined the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004707 static library files through ``${PN}-dev``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004708
4709Following is part of the BitBake configuration file, where you can see
Andrew Geisslerc926e172021-05-07 16:11:35 -05004710how the static library files are defined::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004711
4712 PACKAGE_BEFORE_PN ?= ""
Andrew Geissler595f6302022-01-24 19:11:47 +00004713 PACKAGES = "${PN}-src ${PN}-dbg ${PN}-staticdev ${PN}-dev ${PN}-doc ${PN}-locale ${PACKAGE_BEFORE_PN} ${PN}"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004714 PACKAGES_DYNAMIC = "^${PN}-locale-.*"
4715 FILES = ""
4716
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004717 FILES:${PN} = "${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*${SOLIBS} \
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004718 ${sysconfdir} ${sharedstatedir} ${localstatedir} \
4719 ${base_bindir}/* ${base_sbindir}/* \
4720 ${base_libdir}/*${SOLIBS} \
Andrew Geissler595f6302022-01-24 19:11:47 +00004721 ${base_prefix}/lib/udev ${prefix}/lib/udev \
4722 ${base_libdir}/udev ${libdir}/udev \
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004723 ${datadir}/${BPN} ${libdir}/${BPN}/* \
4724 ${datadir}/pixmaps ${datadir}/applications \
4725 ${datadir}/idl ${datadir}/omf ${datadir}/sounds \
4726 ${libdir}/bonobo/servers"
4727
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004728 FILES:${PN}-bin = "${bindir}/* ${sbindir}/*"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004729
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004730 FILES:${PN}-doc = "${docdir} ${mandir} ${infodir} ${datadir}/gtk-doc \
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004731 ${datadir}/gnome/help"
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004732 SECTION:${PN}-doc = "doc"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004733
4734 FILES_SOLIBSDEV ?= "${base_libdir}/lib*${SOLIBSDEV} ${libdir}/lib*${SOLIBSDEV}"
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004735 FILES:${PN}-dev = "${includedir} ${FILES_SOLIBSDEV} ${libdir}/*.la \
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004736 ${libdir}/*.o ${libdir}/pkgconfig ${datadir}/pkgconfig \
4737 ${datadir}/aclocal ${base_libdir}/*.o \
Andrew Geissler595f6302022-01-24 19:11:47 +00004738 ${libdir}/${BPN}/*.la ${base_libdir}/*.la \
4739 ${libdir}/cmake ${datadir}/cmake"
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004740 SECTION:${PN}-dev = "devel"
4741 ALLOW_EMPTY:${PN}-dev = "1"
4742 RDEPENDS:${PN}-dev = "${PN} (= ${EXTENDPKGV})"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004743
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004744 FILES:${PN}-staticdev = "${libdir}/*.a ${base_libdir}/*.a ${libdir}/${BPN}/*.a"
4745 SECTION:${PN}-staticdev = "devel"
4746 RDEPENDS:${PN}-staticdev = "${PN}-dev (= ${EXTENDPKGV})"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004747
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004748Combining Multiple Versions of Library Files into One Image
4749-----------------------------------------------------------
4750
4751The build system offers the ability to build libraries with different
4752target optimizations or architecture formats and combine these together
4753into one system image. You can link different binaries in the image
4754against the different libraries as needed for specific use cases. This
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004755feature is called "Multilib".
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004756
4757An example would be where you have most of a system compiled in 32-bit
4758mode using 32-bit libraries, but you have something large, like a
4759database engine, that needs to be a 64-bit application and uses 64-bit
4760libraries. Multilib allows you to get the best of both 32-bit and 64-bit
4761libraries.
4762
4763While the Multilib feature is most commonly used for 32 and 64-bit
4764differences, the approach the build system uses facilitates different
4765target optimizations. You could compile some binaries to use one set of
4766libraries and other binaries to use a different set of libraries. The
4767libraries could differ in architecture, compiler options, or other
4768optimizations.
4769
William A. Kennington IIIac69b482021-06-02 12:28:27 -07004770There are several examples in the ``meta-skeleton`` layer found in the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004771:term:`Source Directory`:
4772
Andrew Geissler595f6302022-01-24 19:11:47 +00004773- :oe_git:`conf/multilib-example.conf </openembedded-core/tree/meta-skeleton/conf/multilib-example.conf>`
4774 configuration file.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004775
Andrew Geissler595f6302022-01-24 19:11:47 +00004776- :oe_git:`conf/multilib-example2.conf </openembedded-core/tree/meta-skeleton/conf/multilib-example2.conf>`
4777 configuration file.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004778
Andrew Geissler595f6302022-01-24 19:11:47 +00004779- :oe_git:`recipes-multilib/images/core-image-multilib-example.bb </openembedded-core/tree/meta-skeleton/recipes-multilib/images/core-image-multilib-example.bb>`
4780 recipe
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004781
4782Preparing to Use Multilib
4783~~~~~~~~~~~~~~~~~~~~~~~~~
4784
4785User-specific requirements drive the Multilib feature. Consequently,
William A. Kennington IIIac69b482021-06-02 12:28:27 -07004786there is no one "out-of-the-box" configuration that would
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004787meet your needs.
4788
4789In order to enable Multilib, you first need to ensure your recipe is
4790extended to support multiple libraries. Many standard recipes are
4791already extended and support multiple libraries. You can check in the
4792``meta/conf/multilib.conf`` configuration file in the
4793:term:`Source Directory` to see how this is
4794done using the
4795:term:`BBCLASSEXTEND` variable.
4796Eventually, all recipes will be covered and this list will not be
4797needed.
4798
Andrew Geissler595f6302022-01-24 19:11:47 +00004799For the most part, the :ref:`Multilib <ref-classes-multilib*>`
4800class extension works automatically to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004801extend the package name from ``${PN}`` to ``${MLPREFIX}${PN}``, where
Andrew Geissler5f350902021-07-23 13:09:54 -04004802:term:`MLPREFIX` is the particular multilib (e.g. "lib32-" or "lib64-").
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004803Standard variables such as
4804:term:`DEPENDS`,
4805:term:`RDEPENDS`,
4806:term:`RPROVIDES`,
4807:term:`RRECOMMENDS`,
4808:term:`PACKAGES`, and
4809:term:`PACKAGES_DYNAMIC` are
4810automatically extended by the system. If you are extending any manual
4811code in the recipe, you can use the ``${MLPREFIX}`` variable to ensure
Andrew Geissler595f6302022-01-24 19:11:47 +00004812those names are extended correctly.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004813
4814Using Multilib
4815~~~~~~~~~~~~~~
4816
4817After you have set up the recipes, you need to define the actual
4818combination of multiple libraries you want to build. You accomplish this
4819through your ``local.conf`` configuration file in the
4820:term:`Build Directory`. An example
Andrew Geisslerc926e172021-05-07 16:11:35 -05004821configuration would be as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004822
4823 MACHINE = "qemux86-64"
4824 require conf/multilib.conf
4825 MULTILIBS = "multilib:lib32"
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004826 DEFAULTTUNE:virtclass-multilib-lib32 = "x86"
4827 IMAGE_INSTALL:append = "lib32-glib-2.0"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004828
4829This example enables an additional library named
4830``lib32`` alongside the normal target packages. When combining these
4831"lib32" alternatives, the example uses "x86" for tuning. For information
4832on this particular tuning, see
4833``meta/conf/machine/include/ia32/arch-ia32.inc``.
4834
4835The example then includes ``lib32-glib-2.0`` in all the images, which
4836illustrates one method of including a multiple library dependency. You
Andrew Geisslerc926e172021-05-07 16:11:35 -05004837can use a normal image build to include this dependency, for example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004838
4839 $ bitbake core-image-sato
4840
4841You can also build Multilib packages
Andrew Geisslerc926e172021-05-07 16:11:35 -05004842specifically with a command like this::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004843
4844 $ bitbake lib32-glib-2.0
4845
4846Additional Implementation Details
4847~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4848
William A. Kennington IIIac69b482021-06-02 12:28:27 -07004849There are generic implementation details as well as details that are specific to
4850package management systems. Following are implementation details
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004851that exist regardless of the package management system:
4852
4853- The typical convention used for the class extension code as used by
4854 Multilib assumes that all package names specified in
4855 :term:`PACKAGES` that contain
4856 ``${PN}`` have ``${PN}`` at the start of the name. When that
4857 convention is not followed and ``${PN}`` appears at the middle or the
4858 end of a name, problems occur.
4859
4860- The :term:`TARGET_VENDOR`
4861 value under Multilib will be extended to "-vendormlmultilib" (e.g.
4862 "-pokymllib32" for a "lib32" Multilib with Poky). The reason for this
4863 slightly unwieldy contraction is that any "-" characters in the
4864 vendor string presently break Autoconf's ``config.sub``, and other
4865 separators are problematic for different reasons.
4866
William A. Kennington IIIac69b482021-06-02 12:28:27 -07004867Here are the implementation details for the RPM Package Management System:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004868
4869- A unique architecture is defined for the Multilib packages, along
4870 with creating a unique deploy folder under ``tmp/deploy/rpm`` in the
4871 :term:`Build Directory`. For
4872 example, consider ``lib32`` in a ``qemux86-64`` image. The possible
4873 architectures in the system are "all", "qemux86_64",
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004874 "lib32:qemux86_64", and "lib32:x86".
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004875
4876- The ``${MLPREFIX}`` variable is stripped from ``${PN}`` during RPM
4877 packaging. The naming for a normal RPM package and a Multilib RPM
4878 package in a ``qemux86-64`` system resolves to something similar to
4879 ``bash-4.1-r2.x86_64.rpm`` and ``bash-4.1.r2.lib32_x86.rpm``,
4880 respectively.
4881
4882- When installing a Multilib image, the RPM backend first installs the
4883 base image and then installs the Multilib libraries.
4884
4885- The build system relies on RPM to resolve the identical files in the
4886 two (or more) Multilib packages.
4887
William A. Kennington IIIac69b482021-06-02 12:28:27 -07004888Here are the implementation details for the IPK Package Management System:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004889
4890- The ``${MLPREFIX}`` is not stripped from ``${PN}`` during IPK
4891 packaging. The naming for a normal RPM package and a Multilib IPK
4892 package in a ``qemux86-64`` system resolves to something like
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004893 ``bash_4.1-r2.x86_64.ipk`` and ``lib32-bash_4.1-rw:x86.ipk``,
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004894 respectively.
4895
4896- The IPK deploy folder is not modified with ``${MLPREFIX}`` because
4897 packages with and without the Multilib feature can exist in the same
4898 folder due to the ``${PN}`` differences.
4899
4900- IPK defines a sanity check for Multilib installation using certain
4901 rules for file comparison, overridden, etc.
4902
4903Installing Multiple Versions of the Same Library
4904------------------------------------------------
4905
William A. Kennington IIIac69b482021-06-02 12:28:27 -07004906There are be situations where you need to install and use multiple versions
4907of the same library on the same system at the same time. This
4908almost always happens when a library API changes and you have
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004909multiple pieces of software that depend on the separate versions of the
4910library. To accommodate these situations, you can install multiple
4911versions of the same library in parallel on the same system.
4912
4913The process is straightforward as long as the libraries use proper
4914versioning. With properly versioned libraries, all you need to do to
4915individually specify the libraries is create separate, appropriately
4916named recipes where the :term:`PN` part of
4917the name includes a portion that differentiates each library version
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004918(e.g. the major part of the version number). Thus, instead of having a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004919single recipe that loads one version of a library (e.g. ``clutter``),
4920you provide multiple recipes that result in different versions of the
4921libraries you want. As an example, the following two recipes would allow
4922the two separate versions of the ``clutter`` library to co-exist on the
4923same system:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004924
4925.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004926
4927 clutter-1.6_1.6.20.bb
4928 clutter-1.8_1.8.4.bb
4929
4930Additionally, if
4931you have other recipes that depend on a given library, you need to use
4932the :term:`DEPENDS` variable to
4933create the dependency. Continuing with the same example, if you want to
4934have a recipe depend on the 1.8 version of the ``clutter`` library, use
Andrew Geisslerc926e172021-05-07 16:11:35 -05004935the following in your recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004936
4937 DEPENDS = "clutter-1.8"
4938
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00004939Working with Pre-Built Libraries
4940================================
4941
4942Introduction
4943-------------
4944
4945Some library vendors do not release source code for their software but do
4946release pre-built binaries. When shared libraries are built, they should
4947be versioned (see `this article
4948<https://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html>`__
4949for some background), but sometimes this is not done.
4950
4951To summarize, a versioned library must meet two conditions:
4952
4953#. The filename must have the version appended, for example: ``libfoo.so.1.2.3``.
4954#. The library must have the ELF tag ``SONAME`` set to the major version
4955 of the library, for example: ``libfoo.so.1``. You can check this by
4956 running ``readelf -d filename | grep SONAME``.
4957
4958This section shows how to deal with both versioned and unversioned
4959pre-built libraries.
4960
4961Versioned Libraries
4962-------------------
4963
4964In this example we work with pre-built libraries for the FT4222H USB I/O chip.
4965Libraries are built for several target architecture variants and packaged in
4966an archive as follows::
4967
4968 ├── build-arm-hisiv300
4969 │   └── libft4222.so.1.4.4.44
4970 ├── build-arm-v5-sf
4971 │   └── libft4222.so.1.4.4.44
4972 ├── build-arm-v6-hf
4973 │   └── libft4222.so.1.4.4.44
4974 ├── build-arm-v7-hf
4975 │   └── libft4222.so.1.4.4.44
4976 ├── build-arm-v8
4977 │   └── libft4222.so.1.4.4.44
4978 ├── build-i386
4979 │   └── libft4222.so.1.4.4.44
4980 ├── build-i486
4981 │   └── libft4222.so.1.4.4.44
4982 ├── build-mips-eglibc-hf
4983 │   └── libft4222.so.1.4.4.44
4984 ├── build-pentium
4985 │   └── libft4222.so.1.4.4.44
4986 ├── build-x86_64
4987 │   └── libft4222.so.1.4.4.44
4988 ├── examples
4989 │   ├── get-version.c
4990 │   ├── i2cm.c
4991 │   ├── spim.c
4992 │   └── spis.c
4993 ├── ftd2xx.h
4994 ├── install4222.sh
4995 ├── libft4222.h
4996 ├── ReadMe.txt
4997 └── WinTypes.h
4998
4999To write a recipe to use such a library in your system:
5000
5001- The vendor will probably have a proprietary licence, so set
5002 :term:`LICENSE_FLAGS` in your recipe.
5003- The vendor provides a tarball containing libraries so set :term:`SRC_URI`
5004 appropriately.
5005- Set :term:`COMPATIBLE_HOST` so that the recipe cannot be used with an
5006 unsupported architecture. In the following example, we only support the 32
5007 and 64 bit variants of the ``x86`` architecture.
5008- As the vendor provides versioned libraries, we can use ``oe_soinstall``
5009 from :ref:`ref-classes-utils` to install the shared library and create
5010 symbolic links. If the vendor does not do this, we need to follow the
5011 non-versioned library guidelines in the next section.
5012- As the vendor likely used :term:`LDFLAGS` different from those in your Yocto
5013 Project build, disable the corresponding checks by adding ``ldflags``
5014 to :term:`INSANE_SKIP`.
5015- The vendor will typically ship release builds without debugging symbols.
5016 Avoid errors by preventing the packaging task from stripping out the symbols
5017 and adding them to a separate debug package. This is done by setting the
5018 ``INHIBIT_`` flags shown below.
5019
5020The complete recipe would look like this::
5021
5022 SUMMARY = "FTDI FT4222H Library"
5023 SECTION = "libs"
5024 LICENSE_FLAGS = "ftdi"
5025 LICENSE = "CLOSED"
5026
5027 COMPATIBLE_HOST = "(i.86|x86_64).*-linux"
5028
5029 # Sources available in a .tgz file in .zip archive
5030 # at https://ftdichip.com/wp-content/uploads/2021/01/libft4222-linux-1.4.4.44.zip
5031 # Found on https://ftdichip.com/software-examples/ft4222h-software-examples/
5032 # Since dealing with this particular type of archive is out of topic here,
5033 # we use a local link.
5034 SRC_URI = "file://libft4222-linux-${PV}.tgz"
5035
5036 S = "${WORKDIR}"
5037
5038 ARCH_DIR:x86-64 = "build-x86_64"
5039 ARCH_DIR:i586 = "build-i386"
5040 ARCH_DIR:i686 = "build-i386"
5041
5042 INSANE_SKIP:${PN} = "ldflags"
5043 INHIBIT_PACKAGE_STRIP = "1"
5044 INHIBIT_SYSROOT_STRIP = "1"
5045 INHIBIT_PACKAGE_DEBUG_SPLIT = "1"
5046
5047 do_install () {
5048 install -m 0755 -d ${D}${libdir}
5049 oe_soinstall ${S}/${ARCH_DIR}/libft4222.so.${PV} ${D}${libdir}
5050 install -d ${D}${includedir}
5051 install -m 0755 ${S}/*.h ${D}${includedir}
5052 }
5053
5054If the precompiled binaries are not statically linked and have dependencies on
5055other libraries, then by adding those libraries to :term:`DEPENDS`, the linking
5056can be examined and the appropriate :term:`RDEPENDS` automatically added.
5057
5058Non-Versioned Libraries
5059-----------------------
5060
5061Some Background
5062~~~~~~~~~~~~~~~
5063
5064Libraries in Linux systems are generally versioned so that it is possible
5065to have multiple versions of the same library installed, which eases upgrades
5066and support for older software. For example, suppose that in a versioned
5067library, an actual library is called ``libfoo.so.1.2``, a symbolic link named
5068``libfoo.so.1`` points to ``libfoo.so.1.2``, and a symbolic link named
5069``libfoo.so`` points to ``libfoo.so.1.2``. Given these conditions, when you
5070link a binary against a library, you typically provide the unversioned file
5071name (i.e. ``-lfoo`` to the linker). However, the linker follows the symbolic
5072link and actually links against the versioned filename. The unversioned symbolic
5073link is only used at development time. Consequently, the library is packaged
5074along with the headers in the development package ``${PN}-dev`` along with the
5075actual library and versioned symbolic links in ``${PN}``. Because versioned
5076libraries are far more common than unversioned libraries, the default packaging
5077rules assume versioned libraries.
5078
5079Yocto Library Packaging Overview
5080~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5081
5082It follows that packaging an unversioned library requires a bit of work in the
5083recipe. By default, ``libfoo.so`` gets packaged into ``${PN}-dev``, which
5084triggers a QA warning that a non-symlink library is in a ``-dev`` package,
5085and binaries in the same recipe link to the library in ``${PN}-dev``,
5086which triggers more QA warnings. To solve this problem, you need to package the
5087unversioned library into ``${PN}`` where it belongs. The following are the abridged
5088default :term:`FILES` variables in ``bitbake.conf``::
5089
5090 SOLIBS = ".so.*"
5091 SOLIBSDEV = ".so"
5092 FILES_${PN} = "... ${libdir}/lib*${SOLIBS} ..."
5093 FILES_SOLIBSDEV ?= "... ${libdir}/lib*${SOLIBSDEV} ..."
5094 FILES_${PN}-dev = "... ${FILES_SOLIBSDEV} ..."
5095
5096:term:`SOLIBS` defines a pattern that matches real shared object libraries.
5097:term:`SOLIBSDEV` matches the development form (unversioned symlink). These two
5098variables are then used in ``FILES:${PN}`` and ``FILES:${PN}-dev``, which puts
5099the real libraries into ``${PN}`` and the unversioned symbolic link into ``${PN}-dev``.
5100To package unversioned libraries, you need to modify the variables in the recipe
5101as follows::
5102
5103 SOLIBS = ".so"
5104 FILES_SOLIBSDEV = ""
5105
5106The modifications cause the ``.so`` file to be the real library
5107and unset :term:`FILES_SOLIBSDEV` so that no libraries get packaged into
5108``${PN}-dev``. The changes are required because unless :term:`PACKAGES` is changed,
5109``${PN}-dev`` collects files before `${PN}`. ``${PN}-dev`` must not collect any of
5110the files you want in ``${PN}``.
5111
5112Finally, loadable modules, essentially unversioned libraries that are linked
5113at runtime using ``dlopen()`` instead of at build time, should generally be
5114installed in a private directory. However, if they are installed in ``${libdir}``,
5115then the modules can be treated as unversioned libraries.
5116
5117Example
5118~~~~~~~
5119
5120The example below installs an unversioned x86-64 pre-built library named
5121``libfoo.so``. The :term:`COMPATIBLE_HOST` variable limits recipes to the
5122x86-64 architecture while the :term:`INSANE_SKIP`, :term:`INHIBIT_PACKAGE_STRIP`
5123and :term:`INHIBIT_SYSROOT_STRIP` variables are all set as in the above
5124versioned library example. The "magic" is setting the :term:`SOLIBS` and
5125:term:`FILES_SOLIBSDEV` variables as explained above::
5126
5127 SUMMARY = "libfoo sample recipe"
5128 SECTION = "libs"
5129 LICENSE = "CLOSED"
5130
5131 SRC_URI = "file://libfoo.so"
5132
5133 COMPATIBLE_HOST = "x86_64.*-linux"
5134
5135 INSANE_SKIP:${PN} = "ldflags"
5136 INHIBIT_PACKAGE_STRIP = "1"
5137 INHIBIT_SYSROOT_STRIP = "1"
5138 SOLIBS = ".so"
5139 FILES_SOLIBSDEV = ""
5140
5141 do_install () {
5142 install -d ${D}${libdir}
5143 install -m 0755 ${WORKDIR}/libfoo.so ${D}${libdir}
5144 }
5145
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005146Using x32 psABI
5147===============
5148
5149x32 processor-specific Application Binary Interface (`x32
5150psABI <https://software.intel.com/en-us/node/628948>`__) is a native
515132-bit processor-specific ABI for Intel 64 (x86-64) architectures. An
5152ABI defines the calling conventions between functions in a processing
5153environment. The interface determines what registers are used and what
5154the sizes are for various C data types.
5155
5156Some processing environments prefer using 32-bit applications even when
5157running on Intel 64-bit platforms. Consider the i386 psABI, which is a
5158very old 32-bit ABI for Intel 64-bit platforms. The i386 psABI does not
5159provide efficient use and access of the Intel 64-bit processor
5160resources, leaving the system underutilized. Now consider the x86_64
5161psABI. This ABI is newer and uses 64-bits for data sizes and program
5162pointers. The extra bits increase the footprint size of the programs,
5163libraries, and also increases the memory and file system size
5164requirements. Executing under the x32 psABI enables user programs to
5165utilize CPU and system resources more efficiently while keeping the
5166memory footprint of the applications low. Extra bits are used for
5167registers but not for addressing mechanisms.
5168
5169The Yocto Project supports the final specifications of x32 psABI as
5170follows:
5171
5172- You can create packages and images in x32 psABI format on x86_64
5173 architecture targets.
5174
5175- You can successfully build recipes with the x32 toolchain.
5176
5177- You can create and boot ``core-image-minimal`` and
5178 ``core-image-sato`` images.
5179
William A. Kennington IIIac69b482021-06-02 12:28:27 -07005180- There is RPM Package Manager (RPM) support for x32 binaries.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005181
William A. Kennington IIIac69b482021-06-02 12:28:27 -07005182- There is support for large images.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005183
5184To use the x32 psABI, you need to edit your ``conf/local.conf``
Andrew Geisslerc926e172021-05-07 16:11:35 -05005185configuration file as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005186
5187 MACHINE = "qemux86-64"
5188 DEFAULTTUNE = "x86-64-x32"
Patrick Williams0ca19cc2021-08-16 14:03:13 -05005189 baselib = "${@d.getVar('BASE_LIB:tune-' + (d.getVar('DEFAULTTUNE') \
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005190 or 'INVALID')) or 'lib'}"
5191
5192Once you have set
5193up your configuration file, use BitBake to build an image that supports
Andrew Geisslerc926e172021-05-07 16:11:35 -05005194the x32 psABI. Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005195
5196 $ bitbake core-image-sato
5197
5198Enabling GObject Introspection Support
5199======================================
5200
Andrew Geissler595f6302022-01-24 19:11:47 +00005201`GObject introspection <https://gi.readthedocs.io/en/latest/>`__
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005202is the standard mechanism for accessing GObject-based software from
5203runtime environments. GObject is a feature of the GLib library that
5204provides an object framework for the GNOME desktop and related software.
5205GObject Introspection adds information to GObject that allows objects
5206created within it to be represented across different programming
5207languages. If you want to construct GStreamer pipelines using Python, or
5208control UPnP infrastructure using Javascript and GUPnP, GObject
5209introspection is the only way to do it.
5210
5211This section describes the Yocto Project support for generating and
5212packaging GObject introspection data. GObject introspection data is a
Andrew Geissler595f6302022-01-24 19:11:47 +00005213description of the API provided by libraries built on top of the GLib
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005214framework, and, in particular, that framework's GObject mechanism.
5215GObject Introspection Repository (GIR) files go to ``-dev`` packages,
5216``typelib`` files go to main packages as they are packaged together with
5217libraries that are introspected.
5218
5219The data is generated when building such a library, by linking the
5220library with a small executable binary that asks the library to describe
5221itself, and then executing the binary and processing its output.
5222
5223Generating this data in a cross-compilation environment is difficult
5224because the library is produced for the target architecture, but its
5225code needs to be executed on the build host. This problem is solved with
5226the OpenEmbedded build system by running the code through QEMU, which
5227allows precisely that. Unfortunately, QEMU does not always work
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05005228perfectly as mentioned in the ":ref:`dev-manual/common-tasks:known issues`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005229section.
5230
5231Enabling the Generation of Introspection Data
5232---------------------------------------------
5233
5234Enabling the generation of introspection data (GIR files) in your
5235library package involves the following:
5236
52371. Inherit the
5238 :ref:`gobject-introspection <ref-classes-gobject-introspection>`
5239 class.
5240
52412. Make sure introspection is not disabled anywhere in the recipe or
5242 from anything the recipe includes. Also, make sure that
5243 "gobject-introspection-data" is not in
5244 :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`
5245 and that "qemu-usermode" is not in
5246 :term:`MACHINE_FEATURES_BACKFILL_CONSIDERED`.
William A. Kennington IIIac69b482021-06-02 12:28:27 -07005247 In either of these conditions, nothing will happen.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005248
52493. Try to build the recipe. If you encounter build errors that look like
5250 something is unable to find ``.so`` libraries, check where these
5251 libraries are located in the source tree and add the following to the
Andrew Geisslerc926e172021-05-07 16:11:35 -05005252 recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005253
5254 GIR_EXTRA_LIBS_PATH = "${B}/something/.libs"
5255
5256 .. note::
5257
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005258 See recipes in the ``oe-core`` repository that use that
Andrew Geissler595f6302022-01-24 19:11:47 +00005259 :term:`GIR_EXTRA_LIBS_PATH` variable as an example.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005260
52614. Look for any other errors, which probably mean that introspection
5262 support in a package is not entirely standard, and thus breaks down
5263 in a cross-compilation environment. For such cases, custom-made fixes
5264 are needed. A good place to ask and receive help in these cases is
5265 the :ref:`Yocto Project mailing
5266 lists <resources-mailinglist>`.
5267
5268.. note::
5269
5270 Using a library that no longer builds against the latest Yocto
5271 Project release and prints introspection related errors is a good
5272 candidate for the previous procedure.
5273
5274Disabling the Generation of Introspection Data
5275----------------------------------------------
5276
5277You might find that you do not want to generate introspection data. Or,
5278perhaps QEMU does not work on your build host and target architecture
5279combination. If so, you can use either of the following methods to
5280disable GIR file generations:
5281
Andrew Geisslerc926e172021-05-07 16:11:35 -05005282- Add the following to your distro configuration::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005283
5284 DISTRO_FEATURES_BACKFILL_CONSIDERED = "gobject-introspection-data"
5285
5286 Adding this statement disables generating introspection data using
5287 QEMU but will still enable building introspection tools and libraries
5288 (i.e. building them does not require the use of QEMU).
5289
Andrew Geisslerc926e172021-05-07 16:11:35 -05005290- Add the following to your machine configuration::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005291
5292 MACHINE_FEATURES_BACKFILL_CONSIDERED = "qemu-usermode"
5293
5294 Adding this statement disables the use of QEMU when building packages for your
5295 machine. Currently, this feature is used only by introspection
5296 recipes and has the same effect as the previously described option.
5297
5298 .. note::
5299
5300 Future releases of the Yocto Project might have other features
5301 affected by this option.
5302
5303If you disable introspection data, you can still obtain it through other
5304means such as copying the data from a suitable sysroot, or by generating
5305it on the target hardware. The OpenEmbedded build system does not
5306currently provide specific support for these techniques.
5307
5308Testing that Introspection Works in an Image
5309--------------------------------------------
5310
5311Use the following procedure to test if generating introspection data is
5312working in an image:
5313
53141. Make sure that "gobject-introspection-data" is not in
5315 :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`
5316 and that "qemu-usermode" is not in
5317 :term:`MACHINE_FEATURES_BACKFILL_CONSIDERED`.
5318
53192. Build ``core-image-sato``.
5320
53213. Launch a Terminal and then start Python in the terminal.
5322
Andrew Geisslerc926e172021-05-07 16:11:35 -050053234. Enter the following in the terminal::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005324
5325 >>> from gi.repository import GLib
5326 >>> GLib.get_host_name()
5327
53285. For something a little more advanced, enter the following see:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005329 https://python-gtk-3-tutorial.readthedocs.io/en/latest/introduction.html
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005330
5331Known Issues
5332------------
5333
William A. Kennington IIIac69b482021-06-02 12:28:27 -07005334Here are know issues in GObject Introspection Support:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005335
5336- ``qemu-ppc64`` immediately crashes. Consequently, you cannot build
5337 introspection data on that architecture.
5338
5339- x32 is not supported by QEMU. Consequently, introspection data is
5340 disabled.
5341
5342- musl causes transient GLib binaries to crash on assertion failures.
5343 Consequently, generating introspection data is disabled.
5344
5345- Because QEMU is not able to run the binaries correctly, introspection
5346 is disabled for some specific packages under specific architectures
5347 (e.g. ``gcr``, ``libsecret``, and ``webkit``).
5348
5349- QEMU usermode might not work properly when running 64-bit binaries
5350 under 32-bit host machines. In particular, "qemumips64" is known to
5351 not work under i686.
5352
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005353Optionally Using an External Toolchain
5354======================================
5355
5356You might want to use an external toolchain as part of your development.
5357If this is the case, the fundamental steps you need to accomplish are as
5358follows:
5359
5360- Understand where the installed toolchain resides. For cases where you
5361 need to build the external toolchain, you would need to take separate
5362 steps to build and install the toolchain.
5363
5364- Make sure you add the layer that contains the toolchain to your
5365 ``bblayers.conf`` file through the
5366 :term:`BBLAYERS` variable.
5367
5368- Set the ``EXTERNAL_TOOLCHAIN`` variable in your ``local.conf`` file
5369 to the location in which you installed the toolchain.
5370
5371A good example of an external toolchain used with the Yocto Project is
5372Mentor Graphics Sourcery G++ Toolchain. You can see information on how
5373to use that particular layer in the ``README`` file at
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005374https://github.com/MentorEmbedded/meta-sourcery/. You can find
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005375further information by reading about the
5376:term:`TCMODE` variable in the Yocto
5377Project Reference Manual's variable glossary.
5378
5379Creating Partitioned Images Using Wic
5380=====================================
5381
5382Creating an image for a particular hardware target using the
5383OpenEmbedded build system does not necessarily mean you can boot that
5384image as is on your device. Physical devices accept and boot images in
5385various ways depending on the specifics of the device. Usually,
5386information about the hardware can tell you what image format the device
5387requires. Should your device require multiple partitions on an SD card,
5388flash, or an HDD, you can use the OpenEmbedded Image Creator, Wic, to
5389create the properly partitioned image.
5390
5391The ``wic`` command generates partitioned images from existing
5392OpenEmbedded build artifacts. Image generation is driven by partitioning
5393commands contained in an Openembedded kickstart file (``.wks``)
5394specified either directly on the command line or as one of a selection
5395of canned kickstart files as shown with the ``wic list images`` command
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05005396in the
5397":ref:`dev-manual/common-tasks:generate an image using an existing kickstart file`"
5398section. When you apply the command to a given set of build artifacts, the
5399result is an image or set of images that can be directly written onto media and
5400used on a particular system.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005401
5402.. note::
5403
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005404 For a kickstart file reference, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06005405 ":ref:`ref-manual/kickstart:openembedded kickstart (\`\`.wks\`\`) reference`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005406 Chapter in the Yocto Project Reference Manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005407
5408The ``wic`` command and the infrastructure it is based on is by
5409definition incomplete. The purpose of the command is to allow the
5410generation of customized images, and as such, was designed to be
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05005411completely extensible through a plugin interface. See the
5412":ref:`dev-manual/common-tasks:using the wic plugin interface`" section
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005413for information on these plugins.
5414
5415This section provides some background information on Wic, describes what
5416you need to have in place to run the tool, provides instruction on how
5417to use the Wic utility, provides information on using the Wic plugins
5418interface, and provides several examples that show how to use Wic.
5419
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005420Background
5421----------
5422
5423This section provides some background on the Wic utility. While none of
5424this information is required to use Wic, you might find it interesting.
5425
5426- The name "Wic" is derived from OpenEmbedded Image Creator (oeic). The
5427 "oe" diphthong in "oeic" was promoted to the letter "w", because
5428 "oeic" is both difficult to remember and to pronounce.
5429
5430- Wic is loosely based on the Meego Image Creator (``mic``) framework.
5431 The Wic implementation has been heavily modified to make direct use
5432 of OpenEmbedded build artifacts instead of package installation and
5433 configuration, which are already incorporated within the OpenEmbedded
5434 artifacts.
5435
5436- Wic is a completely independent standalone utility that initially
5437 provides easier-to-use and more flexible replacements for an existing
5438 functionality in OE-Core's
5439 :ref:`image-live <ref-classes-image-live>`
5440 class. The difference between Wic and those examples is that with Wic
5441 the functionality of those scripts is implemented by a
5442 general-purpose partitioning language, which is based on Redhat
5443 kickstart syntax.
5444
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005445Requirements
5446------------
5447
5448In order to use the Wic utility with the OpenEmbedded Build system, your
5449system needs to meet the following requirements:
5450
5451- The Linux distribution on your development host must support the
5452 Yocto Project. See the ":ref:`detailed-supported-distros`"
5453 section in the Yocto Project Reference Manual for the list of
5454 distributions that support the Yocto Project.
5455
5456- The standard system utilities, such as ``cp``, must be installed on
5457 your development host system.
5458
5459- You must have sourced the build environment setup script (i.e.
5460 :ref:`structure-core-script`) found in the
5461 :term:`Build Directory`.
5462
5463- You need to have the build artifacts already available, which
5464 typically means that you must have already created an image using the
5465 Openembedded build system (e.g. ``core-image-minimal``). While it
5466 might seem redundant to generate an image in order to create an image
5467 using Wic, the current version of Wic requires the artifacts in the
5468 form generated by the OpenEmbedded build system.
5469
5470- You must build several native tools, which are built to run on the
Andrew Geisslerc926e172021-05-07 16:11:35 -05005471 build system::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005472
5473 $ bitbake parted-native dosfstools-native mtools-native
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005474
5475- Include "wic" as part of the
5476 :term:`IMAGE_FSTYPES`
5477 variable.
5478
5479- Include the name of the :ref:`wic kickstart file <openembedded-kickstart-wks-reference>`
5480 as part of the :term:`WKS_FILE` variable
5481
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005482Getting Help
5483------------
5484
5485You can get general help for the ``wic`` command by entering the ``wic``
5486command by itself or by entering the command with a help argument as
Andrew Geisslerc926e172021-05-07 16:11:35 -05005487follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005488
5489 $ wic -h
5490 $ wic --help
5491 $ wic help
5492
5493Currently, Wic supports seven commands: ``cp``, ``create``, ``help``,
5494``list``, ``ls``, ``rm``, and ``write``. You can get help for all these
Andrew Geisslerc926e172021-05-07 16:11:35 -05005495commands except "help" by using the following form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005496
5497 $ wic help command
5498
5499For example, the following command returns help for the ``write``
Andrew Geisslerc926e172021-05-07 16:11:35 -05005500command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005501
5502 $ wic help write
5503
5504Wic supports help for three topics: ``overview``, ``plugins``, and
Andrew Geisslerc926e172021-05-07 16:11:35 -05005505``kickstart``. You can get help for any topic using the following form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005506
5507 $ wic help topic
5508
Andrew Geisslerc926e172021-05-07 16:11:35 -05005509For example, the following returns overview help for Wic::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005510
5511 $ wic help overview
5512
William A. Kennington IIIac69b482021-06-02 12:28:27 -07005513There is one additional level of help for Wic. You can get help on
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005514individual images through the ``list`` command. You can use the ``list``
Andrew Geisslerc926e172021-05-07 16:11:35 -05005515command to return the available Wic images as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005516
5517 $ wic list images
5518 genericx86 Create an EFI disk image for genericx86*
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005519 edgerouter Create SD card image for Edgerouter
Andrew Geissler5199d832021-09-24 16:47:35 -05005520 beaglebone-yocto Create SD card image for Beaglebone
5521 qemux86-directdisk Create a qemu machine 'pcbios' direct disk image
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005522 systemd-bootdisk Create an EFI disk image with systemd-boot
5523 mkhybridiso Create a hybrid ISO image
Andrew Geissler5199d832021-09-24 16:47:35 -05005524 mkefidisk Create an EFI disk image
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005525 sdimage-bootpart Create SD card image with a boot partition
5526 directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
Andrew Geissler5199d832021-09-24 16:47:35 -05005527 directdisk Create a 'pcbios' direct disk image
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005528 directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
Andrew Geissler5199d832021-09-24 16:47:35 -05005529 qemuriscv Create qcow2 image for RISC-V QEMU machines
5530 directdisk-gpt Create a 'pcbios' direct disk image
5531 efi-bootdisk
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005532
5533Once you know the list of available
5534Wic images, you can use ``help`` with the command to get help on a
5535particular image. For example, the following command returns help on the
Andrew Geisslerc926e172021-05-07 16:11:35 -05005536"beaglebone-yocto" image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005537
5538 $ wic list beaglebone-yocto help
5539
5540 Creates a partitioned SD card image for Beaglebone.
5541 Boot files are located in the first vfat partition.
5542
5543Operational Modes
5544-----------------
5545
5546You can use Wic in two different modes, depending on how much control
5547you need for specifying the Openembedded build artifacts that are used
5548for creating the image: Raw and Cooked:
5549
5550- *Raw Mode:* You explicitly specify build artifacts through Wic
5551 command-line arguments.
5552
5553- *Cooked Mode:* The current
5554 :term:`MACHINE` setting and image
5555 name are used to automatically locate and provide the build
5556 artifacts. You just supply a kickstart file and the name of the image
5557 from which to use artifacts.
5558
5559Regardless of the mode you use, you need to have the build artifacts
5560ready and available.
5561
5562Raw Mode
5563~~~~~~~~
5564
5565Running Wic in raw mode allows you to specify all the partitions through
5566the ``wic`` command line. The primary use for raw mode is if you have
5567built your kernel outside of the Yocto Project
5568:term:`Build Directory`. In other words, you
5569can point to arbitrary kernel, root filesystem locations, and so forth.
5570Contrast this behavior with cooked mode where Wic looks in the Build
5571Directory (e.g. ``tmp/deploy/images/``\ machine).
5572
Andrew Geisslerc926e172021-05-07 16:11:35 -05005573The general form of the ``wic`` command in raw mode is::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005574
5575 $ wic create wks_file options ...
5576
5577 Where:
5578
5579 wks_file:
5580 An OpenEmbedded kickstart file. You can provide
5581 your own custom file or use a file from a set of
5582 existing files as described by further options.
5583
5584 optional arguments:
5585 -h, --help show this help message and exit
5586 -o OUTDIR, --outdir OUTDIR
5587 name of directory to create image in
5588 -e IMAGE_NAME, --image-name IMAGE_NAME
5589 name of the image to use the artifacts from e.g. core-
5590 image-sato
5591 -r ROOTFS_DIR, --rootfs-dir ROOTFS_DIR
5592 path to the /rootfs dir to use as the .wks rootfs
5593 source
5594 -b BOOTIMG_DIR, --bootimg-dir BOOTIMG_DIR
5595 path to the dir containing the boot artifacts (e.g.
5596 /EFI or /syslinux dirs) to use as the .wks bootimg
5597 source
5598 -k KERNEL_DIR, --kernel-dir KERNEL_DIR
5599 path to the dir containing the kernel to use in the
5600 .wks bootimg
5601 -n NATIVE_SYSROOT, --native-sysroot NATIVE_SYSROOT
5602 path to the native sysroot containing the tools to use
5603 to build the image
5604 -s, --skip-build-check
5605 skip the build check
5606 -f, --build-rootfs build rootfs
5607 -c {gzip,bzip2,xz}, --compress-with {gzip,bzip2,xz}
5608 compress image with specified compressor
5609 -m, --bmap generate .bmap
5610 --no-fstab-update Do not change fstab file.
5611 -v VARS_DIR, --vars VARS_DIR
5612 directory with <image>.env files that store bitbake
5613 variables
5614 -D, --debug output debug information
5615
5616.. note::
5617
5618 You do not need root privileges to run Wic. In fact, you should not
5619 run as root when using the utility.
5620
5621Cooked Mode
5622~~~~~~~~~~~
5623
5624Running Wic in cooked mode leverages off artifacts in the Build
5625Directory. In other words, you do not have to specify kernel or root
5626filesystem locations as part of the command. All you need to provide is
5627a kickstart file and the name of the image from which to use artifacts
5628by using the "-e" option. Wic looks in the Build Directory (e.g.
5629``tmp/deploy/images/``\ machine) for artifacts.
5630
Andrew Geisslerc926e172021-05-07 16:11:35 -05005631The general form of the ``wic`` command using Cooked Mode is as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005632
5633 $ wic create wks_file -e IMAGE_NAME
5634
5635 Where:
5636
5637 wks_file:
5638 An OpenEmbedded kickstart file. You can provide
5639 your own custom file or use a file from a set of
5640 existing files provided with the Yocto Project
5641 release.
5642
5643 required argument:
5644 -e IMAGE_NAME, --image-name IMAGE_NAME
5645 name of the image to use the artifacts from e.g. core-
5646 image-sato
5647
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005648Using an Existing Kickstart File
5649--------------------------------
5650
5651If you do not want to create your own kickstart file, you can use an
5652existing file provided by the Wic installation. As shipped, kickstart
Andrew Geissler09209ee2020-12-13 08:44:15 -06005653files can be found in the :ref:`overview-manual/development-environment:yocto project source repositories` in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05005654following two locations::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005655
5656 poky/meta-yocto-bsp/wic
5657 poky/scripts/lib/wic/canned-wks
5658
Andrew Geisslerc926e172021-05-07 16:11:35 -05005659Use the following command to list the available kickstart files::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005660
5661 $ wic list images
5662 genericx86 Create an EFI disk image for genericx86*
5663 beaglebone-yocto Create SD card image for Beaglebone
5664 edgerouter Create SD card image for Edgerouter
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05005665 qemux86-directdisk Create a QEMU machine 'pcbios' direct disk image
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005666 directdisk-gpt Create a 'pcbios' direct disk image
5667 mkefidisk Create an EFI disk image
5668 directdisk Create a 'pcbios' direct disk image
5669 systemd-bootdisk Create an EFI disk image with systemd-boot
5670 mkhybridiso Create a hybrid ISO image
5671 sdimage-bootpart Create SD card image with a boot partition
5672 directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
5673 directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
5674
5675When you use an existing file, you
5676do not have to use the ``.wks`` extension. Here is an example in Raw
Andrew Geisslerc926e172021-05-07 16:11:35 -05005677Mode that uses the ``directdisk`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005678
5679 $ wic create directdisk -r rootfs_dir -b bootimg_dir \
5680 -k kernel_dir -n native_sysroot
5681
5682Here are the actual partition language commands used in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05005683``genericx86.wks`` file to generate an image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005684
5685 # short-description: Create an EFI disk image for genericx86*
5686 # long-description: Creates a partitioned EFI disk image for genericx86* machines
5687 part /boot --source bootimg-efi --sourceparams="loader=grub-efi" --ondisk sda --label msdos --active --align 1024
5688 part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid
5689 part swap --ondisk sda --size 44 --label swap1 --fstype=swap
5690
5691 bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=ttyS0,115200 console=tty0"
5692
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005693Using the Wic Plugin Interface
5694------------------------------
5695
5696You can extend and specialize Wic functionality by using Wic plugins.
5697This section explains the Wic plugin interface.
5698
5699.. note::
5700
5701 Wic plugins consist of "source" and "imager" plugins. Imager plugins
5702 are beyond the scope of this section.
5703
5704Source plugins provide a mechanism to customize partition content during
5705the Wic image generation process. You can use source plugins to map
5706values that you specify using ``--source`` commands in kickstart files
5707(i.e. ``*.wks``) to a plugin implementation used to populate a given
5708partition.
5709
5710.. note::
5711
5712 If you use plugins that have build-time dependencies (e.g. native
5713 tools, bootloaders, and so forth) when building a Wic image, you need
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005714 to specify those dependencies using the :term:`WKS_FILE_DEPENDS`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005715 variable.
5716
5717Source plugins are subclasses defined in plugin files. As shipped, the
5718Yocto Project provides several plugin files. You can see the source
5719plugin files that ship with the Yocto Project
Andrew Geissler09209ee2020-12-13 08:44:15 -06005720:yocto_git:`here </poky/tree/scripts/lib/wic/plugins/source>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005721Each of these plugin files contains source plugins that are designed to
5722populate a specific Wic image partition.
5723
5724Source plugins are subclasses of the ``SourcePlugin`` class, which is
5725defined in the ``poky/scripts/lib/wic/pluginbase.py`` file. For example,
5726the ``BootimgEFIPlugin`` source plugin found in the ``bootimg-efi.py``
5727file is a subclass of the ``SourcePlugin`` class, which is found in the
5728``pluginbase.py`` file.
5729
5730You can also implement source plugins in a layer outside of the Source
5731Repositories (external layer). To do so, be sure that your plugin files
5732are located in a directory whose path is
5733``scripts/lib/wic/plugins/source/`` within your external layer. When the
5734plugin files are located there, the source plugins they contain are made
5735available to Wic.
5736
5737When the Wic implementation needs to invoke a partition-specific
5738implementation, it looks for the plugin with the same name as the
5739``--source`` parameter used in the kickstart file given to that
5740partition. For example, if the partition is set up using the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05005741command in a kickstart file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005742
5743 part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024
5744
5745The methods defined as class
5746members of the matching source plugin (i.e. ``bootimg-pcbios``) in the
5747``bootimg-pcbios.py`` plugin file are used.
5748
5749To be more concrete, here is the corresponding plugin definition from
5750the ``bootimg-pcbios.py`` file for the previous command along with an
5751example method called by the Wic implementation when it needs to prepare
Andrew Geisslerc926e172021-05-07 16:11:35 -05005752a partition using an implementation-specific function::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005753
5754 .
5755 .
5756 .
5757 class BootimgPcbiosPlugin(SourcePlugin):
5758 """
5759 Create MBR boot partition and install syslinux on it.
5760 """
5761
5762 name = 'bootimg-pcbios'
5763 .
5764 .
5765 .
5766 @classmethod
5767 def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
5768 oe_builddir, bootimg_dir, kernel_dir,
5769 rootfs_dir, native_sysroot):
5770 """
5771 Called to do the actual content population for a partition i.e. it
5772 'prepares' the partition to be incorporated into the image.
5773 In this case, prepare content for legacy bios boot partition.
5774 """
5775 .
5776 .
5777 .
5778
5779If a
5780subclass (plugin) itself does not implement a particular function, Wic
5781locates and uses the default version in the superclass. It is for this
5782reason that all source plugins are derived from the ``SourcePlugin``
5783class.
5784
5785The ``SourcePlugin`` class defined in the ``pluginbase.py`` file defines
5786a set of methods that source plugins can implement or override. Any
5787plugins (subclass of ``SourcePlugin``) that do not implement a
5788particular method inherit the implementation of the method from the
5789``SourcePlugin`` class. For more information, see the ``SourcePlugin``
5790class in the ``pluginbase.py`` file for details:
5791
5792The following list describes the methods implemented in the
5793``SourcePlugin`` class:
5794
5795- ``do_prepare_partition()``: Called to populate a partition with
5796 actual content. In other words, the method prepares the final
5797 partition image that is incorporated into the disk image.
5798
5799- ``do_configure_partition()``: Called before
5800 ``do_prepare_partition()`` to create custom configuration files for a
5801 partition (e.g. syslinux or grub configuration files).
5802
5803- ``do_install_disk()``: Called after all partitions have been
5804 prepared and assembled into a disk image. This method provides a hook
5805 to allow finalization of a disk image (e.g. writing an MBR).
5806
5807- ``do_stage_partition()``: Special content-staging hook called
5808 before ``do_prepare_partition()``. This method is normally empty.
5809
5810 Typically, a partition just uses the passed-in parameters (e.g. the
5811 unmodified value of ``bootimg_dir``). However, in some cases, things
5812 might need to be more tailored. As an example, certain files might
5813 additionally need to be taken from ``bootimg_dir + /boot``. This hook
5814 allows those files to be staged in a customized fashion.
5815
5816 .. note::
5817
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005818 ``get_bitbake_var()`` allows you to access non-standard variables that
5819 you might want to use for this behavior.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005820
5821You can extend the source plugin mechanism. To add more hooks, create
5822more source plugin methods within ``SourcePlugin`` and the corresponding
5823derived subclasses. The code that calls the plugin methods uses the
5824``plugin.get_source_plugin_methods()`` function to find the method or
5825methods needed by the call. Retrieval of those methods is accomplished
5826by filling up a dict with keys that contain the method names of
5827interest. On success, these will be filled in with the actual methods.
5828See the Wic implementation for examples and details.
5829
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005830Wic Examples
5831------------
5832
5833This section provides several examples that show how to use the Wic
5834utility. All the examples assume the list of requirements in the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05005835":ref:`dev-manual/common-tasks:requirements`" section have been met. The
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005836examples assume the previously generated image is
5837``core-image-minimal``.
5838
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005839Generate an Image using an Existing Kickstart File
5840~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5841
5842This example runs in Cooked Mode and uses the ``mkefidisk`` kickstart
Andrew Geisslerc926e172021-05-07 16:11:35 -05005843file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005844
5845 $ wic create mkefidisk -e core-image-minimal
5846 INFO: Building wic-tools...
5847 .
5848 .
5849 .
5850 INFO: The new image(s) can be found here:
5851 ./mkefidisk-201804191017-sda.direct
5852
5853 The following build artifacts were used to create the image(s):
Andrew Geissler595f6302022-01-24 19:11:47 +00005854 ROOTFS_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
5855 BOOTIMG_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
5856 KERNEL_DIR: /home/stephano/yocto/build/tmp-glibc/deploy/images/qemux86
5857 NATIVE_SYSROOT: /home/stephano/yocto/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005858
5859 INFO: The image(s) were created using OE kickstart file:
Andrew Geissler595f6302022-01-24 19:11:47 +00005860 /home/stephano/yocto/openembedded-core/scripts/lib/wic/canned-wks/mkefidisk.wks
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005861
5862The previous example shows the easiest way to create an image by running
5863in cooked mode and supplying a kickstart file and the "-e" option to
5864point to the existing build artifacts. Your ``local.conf`` file needs to
5865have the :term:`MACHINE` variable set
5866to the machine you are using, which is "qemux86" in this example.
5867
5868Once the image builds, the output provides image location, artifact use,
5869and kickstart file information.
5870
5871.. note::
5872
5873 You should always verify the details provided in the output to make
5874 sure that the image was indeed created exactly as expected.
5875
5876Continuing with the example, you can now write the image from the Build
5877Directory onto a USB stick, or whatever media for which you built your
5878image, and boot from the media. You can write the image by using
Andrew Geisslerc926e172021-05-07 16:11:35 -05005879``bmaptool`` or ``dd``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005880
5881 $ oe-run-native bmaptool copy mkefidisk-201804191017-sda.direct /dev/sdX
5882
5883or ::
5884
5885 $ sudo dd if=mkefidisk-201804191017-sda.direct of=/dev/sdX
5886
5887.. note::
5888
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005889 For more information on how to use the ``bmaptool``
5890 to flash a device with an image, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06005891 ":ref:`dev-manual/common-tasks:flashing images using \`\`bmaptool\`\``"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005892 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005893
5894Using a Modified Kickstart File
5895~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5896
5897Because partitioned image creation is driven by the kickstart file, it
5898is easy to affect image creation by changing the parameters in the file.
5899This next example demonstrates that through modification of the
5900``directdisk-gpt`` kickstart file.
5901
5902As mentioned earlier, you can use the command ``wic list images`` to
5903show the list of existing kickstart files. The directory in which the
5904``directdisk-gpt.wks`` file resides is
5905``scripts/lib/image/canned-wks/``, which is located in the
5906:term:`Source Directory` (e.g. ``poky``).
5907Because available files reside in this directory, you can create and add
5908your own custom files to the directory. Subsequent use of the
5909``wic list images`` command would then include your kickstart files.
5910
5911In this example, the existing ``directdisk-gpt`` file already does most
5912of what is needed. However, for the hardware in this example, the image
5913will need to boot from ``sdb`` instead of ``sda``, which is what the
5914``directdisk-gpt`` kickstart file uses.
5915
5916The example begins by making a copy of the ``directdisk-gpt.wks`` file
5917in the ``scripts/lib/image/canned-wks`` directory and then by changing
5918the lines that specify the target disk from which to boot.
5919::
5920
Andrew Geissler595f6302022-01-24 19:11:47 +00005921 $ cp /home/stephano/yocto/poky/scripts/lib/wic/canned-wks/directdisk-gpt.wks \
5922 /home/stephano/yocto/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005923
5924Next, the example modifies the ``directdisksdb-gpt.wks`` file and
5925changes all instances of "``--ondisk sda``" to "``--ondisk sdb``". The
5926example changes the following two lines and leaves the remaining lines
Andrew Geisslerc926e172021-05-07 16:11:35 -05005927untouched::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005928
5929 part /boot --source bootimg-pcbios --ondisk sdb --label boot --active --align 1024
5930 part / --source rootfs --ondisk sdb --fstype=ext4 --label platform --align 1024 --use-uuid
5931
5932Once the lines are changed, the
5933example generates the ``directdisksdb-gpt`` image. The command points
5934the process at the ``core-image-minimal`` artifacts for the Next Unit of
5935Computing (nuc) :term:`MACHINE` the
5936``local.conf``.
5937::
5938
5939 $ wic create directdisksdb-gpt -e core-image-minimal
5940 INFO: Building wic-tools...
5941 .
5942 .
5943 .
5944 Initialising tasks: 100% |#######################################| Time: 0:00:01
5945 NOTE: Executing SetScene Tasks
5946 NOTE: Executing RunQueue Tasks
5947 NOTE: Tasks Summary: Attempted 1161 tasks of which 1157 didn't need to be rerun and all succeeded.
5948 INFO: Creating image(s)...
5949
5950 INFO: The new image(s) can be found here:
5951 ./directdisksdb-gpt-201710090938-sdb.direct
5952
5953 The following build artifacts were used to create the image(s):
Andrew Geissler595f6302022-01-24 19:11:47 +00005954 ROOTFS_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
5955 BOOTIMG_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
5956 KERNEL_DIR: /home/stephano/yocto/build/tmp-glibc/deploy/images/qemux86
5957 NATIVE_SYSROOT: /home/stephano/yocto/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005958
5959 INFO: The image(s) were created using OE kickstart file:
Andrew Geissler595f6302022-01-24 19:11:47 +00005960 /home/stephano/yocto/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005961
5962Continuing with the example, you can now directly ``dd`` the image to a
5963USB stick, or whatever media for which you built your image, and boot
Andrew Geisslerc926e172021-05-07 16:11:35 -05005964the resulting media::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005965
5966 $ sudo dd if=directdisksdb-gpt-201710090938-sdb.direct of=/dev/sdb
5967 140966+0 records in
5968 140966+0 records out
5969 72174592 bytes (72 MB, 69 MiB) copied, 78.0282 s, 925 kB/s
5970 $ sudo eject /dev/sdb
5971
5972Using a Modified Kickstart File and Running in Raw Mode
5973~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5974
5975This next example manually specifies each build artifact (runs in Raw
5976Mode) and uses a modified kickstart file. The example also uses the
5977``-o`` option to cause Wic to create the output somewhere other than the
Andrew Geisslerc926e172021-05-07 16:11:35 -05005978default output directory, which is the current directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005979
Andrew Geissler595f6302022-01-24 19:11:47 +00005980 $ wic create test.wks -o /home/stephano/testwic \
5981 --rootfs-dir /home/stephano/yocto/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/rootfs \
5982 --bootimg-dir /home/stephano/yocto/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share \
5983 --kernel-dir /home/stephano/yocto/build/tmp/deploy/images/qemux86 \
5984 --native-sysroot /home/stephano/yocto/build/tmp/work/i586-poky-linux/wic-tools/1.0-r0/recipe-sysroot-native
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005985
5986 INFO: Creating image(s)...
5987
5988 INFO: The new image(s) can be found here:
5989 /home/stephano/testwic/test-201710091445-sdb.direct
5990
5991 The following build artifacts were used to create the image(s):
Andrew Geissler595f6302022-01-24 19:11:47 +00005992 ROOTFS_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
5993 BOOTIMG_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
5994 KERNEL_DIR: /home/stephano/yocto/build/tmp-glibc/deploy/images/qemux86
5995 NATIVE_SYSROOT: /home/stephano/yocto/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005996
5997 INFO: The image(s) were created using OE kickstart file:
Andrew Geissler595f6302022-01-24 19:11:47 +00005998 test.wks
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005999
6000For this example,
6001:term:`MACHINE` did not have to be
6002specified in the ``local.conf`` file since the artifact is manually
6003specified.
6004
6005Using Wic to Manipulate an Image
6006~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6007
6008Wic image manipulation allows you to shorten turnaround time during
6009image development. For example, you can use Wic to delete the kernel
6010partition of a Wic image and then insert a newly built kernel. This
6011saves you time from having to rebuild the entire image each time you
6012modify the kernel.
6013
6014.. note::
6015
6016 In order to use Wic to manipulate a Wic image as in this example,
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006017 your development machine must have the ``mtools`` package installed.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006018
6019The following example examines the contents of the Wic image, deletes
6020the existing kernel, and then inserts a new kernel:
6021
60221. *List the Partitions:* Use the ``wic ls`` command to list all the
Andrew Geisslerc926e172021-05-07 16:11:35 -05006023 partitions in the Wic image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006024
6025 $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic
6026 Num Start End Size Fstype
6027 1 1048576 25041919 23993344 fat16
6028 2 25165824 72157183 46991360 ext4
6029
6030 The previous output shows two partitions in the
6031 ``core-image-minimal-qemux86.wic`` image.
6032
60332. *Examine a Particular Partition:* Use the ``wic ls`` command again
6034 but in a different form to examine a particular partition.
6035
6036 .. note::
6037
6038 You can get command usage on any Wic command using the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05006039 form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006040
6041 $ wic help command
6042
6043
6044 For example, the following command shows you the various ways to
6045 use the
6046 wic ls
Andrew Geisslerc926e172021-05-07 16:11:35 -05006047 command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006048
6049 $ wic help ls
6050
6051
Andrew Geisslerc926e172021-05-07 16:11:35 -05006052 The following command shows what is in partition one::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006053
6054 $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1
6055 Volume in drive : is boot
6056 Volume Serial Number is E894-1809
6057 Directory for ::/
6058
6059 libcom32 c32 186500 2017-10-09 16:06
6060 libutil c32 24148 2017-10-09 16:06
6061 syslinux cfg 220 2017-10-09 16:06
6062 vesamenu c32 27104 2017-10-09 16:06
6063 vmlinuz 6904608 2017-10-09 16:06
6064 5 files 7 142 580 bytes
6065 16 582 656 bytes free
6066
6067 The previous output shows five files, with the
6068 ``vmlinuz`` being the kernel.
6069
6070 .. note::
6071
6072 If you see the following error, you need to update or create a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006073 ``~/.mtoolsrc`` file and be sure to have the line "mtools_skip_check=1"
Andrew Geisslerc926e172021-05-07 16:11:35 -05006074 in the file. Then, run the Wic command again::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006075
6076 ERROR: _exec_cmd: /usr/bin/mdir -i /tmp/wic-parttfokuwra ::/ returned '1' instead of 0
6077 output: Total number of sectors (47824) not a multiple of sectors per track (32)!
6078 Add mtools_skip_check=1 to your .mtoolsrc file to skip this test
6079
6080
60813. *Remove the Old Kernel:* Use the ``wic rm`` command to remove the
Andrew Geisslerc926e172021-05-07 16:11:35 -05006082 ``vmlinuz`` file (kernel)::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006083
6084 $ wic rm tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
6085
60864. *Add In the New Kernel:* Use the ``wic cp`` command to add the
6087 updated kernel to the Wic image. Depending on how you built your
6088 kernel, it could be in different places. If you used ``devtool`` and
6089 an SDK to build your kernel, it resides in the ``tmp/work`` directory
6090 of the extensible SDK. If you used ``make`` to build the kernel, the
6091 kernel will be in the ``workspace/sources`` area.
6092
6093 The following example assumes ``devtool`` was used to build the
Andrew Geisslerc926e172021-05-07 16:11:35 -05006094 kernel::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006095
Andrew Geissler95ac1b82021-03-31 14:34:31 -05006096 $ 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 \
6097 poky/build/tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006098
6099 Once the new kernel is added back into the image, you can use the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006100 ``dd`` command or :ref:`bmaptool
Andrew Geissler09209ee2020-12-13 08:44:15 -06006101 <dev-manual/common-tasks:flashing images using \`\`bmaptool\`\`>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006102 to flash your wic image onto an SD card or USB stick and test your
6103 target.
6104
6105 .. note::
6106
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006107 Using ``bmaptool`` is generally 10 to 20 times faster than using ``dd``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006108
6109Flashing Images Using ``bmaptool``
6110==================================
6111
6112A fast and easy way to flash an image to a bootable device is to use
6113Bmaptool, which is integrated into the OpenEmbedded build system.
6114Bmaptool is a generic tool that creates a file's block map (bmap) and
6115then uses that map to copy the file. As compared to traditional tools
6116such as dd or cp, Bmaptool can copy (or flash) large files like raw
6117system image files much faster.
6118
6119.. note::
6120
6121 - If you are using Ubuntu or Debian distributions, you can install
6122 the ``bmap-tools`` package using the following command and then
6123 use the tool without specifying ``PATH`` even from the root
Andrew Geisslerc926e172021-05-07 16:11:35 -05006124 account::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006125
Andrew Geisslereff27472021-10-29 15:35:00 -05006126 $ sudo apt install bmap-tools
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006127
6128 - If you are unable to install the ``bmap-tools`` package, you will
Andrew Geisslerc926e172021-05-07 16:11:35 -05006129 need to build Bmaptool before using it. Use the following command::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006130
6131 $ bitbake bmap-tools-native
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006132
6133Following, is an example that shows how to flash a Wic image. Realize
6134that while this example uses a Wic image, you can use Bmaptool to flash
6135any type of image. Use these steps to flash an image using Bmaptool:
6136
61371. *Update your local.conf File:* You need to have the following set
Andrew Geisslerc926e172021-05-07 16:11:35 -05006138 in your ``local.conf`` file before building your image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006139
6140 IMAGE_FSTYPES += "wic wic.bmap"
6141
61422. *Get Your Image:* Either have your image ready (pre-built with the
6143 :term:`IMAGE_FSTYPES`
Andrew Geisslerc926e172021-05-07 16:11:35 -05006144 setting previously mentioned) or take the step to build the image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006145
6146 $ bitbake image
6147
61483. *Flash the Device:* Flash the device with the image by using Bmaptool
6149 depending on your particular setup. The following commands assume the
6150 image resides in the Build Directory's ``deploy/images/`` area:
6151
Andrew Geisslerc926e172021-05-07 16:11:35 -05006152 - If you have write access to the media, use this command form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006153
6154 $ oe-run-native bmap-tools-native bmaptool copy build-directory/tmp/deploy/images/machine/image.wic /dev/sdX
6155
6156 - If you do not have write access to the media, set your permissions
Andrew Geisslerc926e172021-05-07 16:11:35 -05006157 first and then use the same command form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006158
6159 $ sudo chmod 666 /dev/sdX
6160 $ oe-run-native bmap-tools-native bmaptool copy build-directory/tmp/deploy/images/machine/image.wic /dev/sdX
6161
Andrew Geisslerc926e172021-05-07 16:11:35 -05006162For help on the ``bmaptool`` command, use the following command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006163
6164 $ bmaptool --help
6165
6166Making Images More Secure
6167=========================
6168
6169Security is of increasing concern for embedded devices. Consider the
6170issues and problems discussed in just this sampling of work found across
6171the Internet:
6172
6173- *"*\ `Security Risks of Embedded
6174 Systems <https://www.schneier.com/blog/archives/2014/01/security_risks_9.html>`__\ *"*
6175 by Bruce Schneier
6176
6177- *"*\ `Internet Census
6178 2012 <http://census2012.sourceforge.net/paper.html>`__\ *"* by Carna
6179 Botnet
6180
6181- *"*\ `Security Issues for Embedded
Andrew Geisslerd1e89492021-02-12 15:35:20 -06006182 Devices <https://elinux.org/images/6/6f/Security-issues.pdf>`__\ *"*
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006183 by Jake Edge
6184
6185When securing your image is of concern, there are steps, tools, and
6186variables that you can consider to help you reach the security goals you
6187need for your particular device. Not all situations are identical when
6188it comes to making an image secure. Consequently, this section provides
6189some guidance and suggestions for consideration when you want to make
6190your image more secure.
6191
6192.. note::
6193
6194 Because the security requirements and risks are different for every
6195 type of device, this section cannot provide a complete reference on
6196 securing your custom OS. It is strongly recommended that you also
6197 consult other sources of information on embedded Linux system
6198 hardening and on security.
6199
6200General Considerations
6201----------------------
6202
William A. Kennington IIIac69b482021-06-02 12:28:27 -07006203There are general considerations that help you create more secure images.
6204You should consider the following suggestions to make your device
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006205more secure:
6206
6207- Scan additional code you are adding to the system (e.g. application
6208 code) by using static analysis tools. Look for buffer overflows and
6209 other potential security problems.
6210
6211- Pay particular attention to the security for any web-based
6212 administration interface.
6213
6214 Web interfaces typically need to perform administrative functions and
6215 tend to need to run with elevated privileges. Thus, the consequences
6216 resulting from the interface's security becoming compromised can be
6217 serious. Look for common web vulnerabilities such as
6218 cross-site-scripting (XSS), unvalidated inputs, and so forth.
6219
6220 As with system passwords, the default credentials for accessing a
6221 web-based interface should not be the same across all devices. This
6222 is particularly true if the interface is enabled by default as it can
6223 be assumed that many end-users will not change the credentials.
6224
6225- Ensure you can update the software on the device to mitigate
6226 vulnerabilities discovered in the future. This consideration
6227 especially applies when your device is network-enabled.
6228
6229- Ensure you remove or disable debugging functionality before producing
6230 the final image. For information on how to do this, see the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006231 ":ref:`dev-manual/common-tasks:considerations specific to the openembedded build system`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006232 section.
6233
6234- Ensure you have no network services listening that are not needed.
6235
6236- Remove any software from the image that is not needed.
6237
6238- Enable hardware support for secure boot functionality when your
6239 device supports this functionality.
6240
6241Security Flags
6242--------------
6243
6244The Yocto Project has security flags that you can enable that help make
6245your build output more secure. The security flags are in the
6246``meta/conf/distro/include/security_flags.inc`` file in your
6247:term:`Source Directory` (e.g. ``poky``).
6248
6249.. note::
6250
6251 Depending on the recipe, certain security flags are enabled and
6252 disabled by default.
6253
6254Use the following line in your ``local.conf`` file or in your custom
6255distribution configuration file to enable the security compiler and
Andrew Geisslerc926e172021-05-07 16:11:35 -05006256linker flags for your build::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006257
6258 require conf/distro/include/security_flags.inc
6259
6260Considerations Specific to the OpenEmbedded Build System
6261--------------------------------------------------------
6262
6263You can take some steps that are specific to the OpenEmbedded build
6264system to make your images more secure:
6265
6266- Ensure "debug-tweaks" is not one of your selected
6267 :term:`IMAGE_FEATURES`.
6268 When creating a new project, the default is to provide you with an
6269 initial ``local.conf`` file that enables this feature using the
6270 :term:`EXTRA_IMAGE_FEATURES`
Andrew Geisslerc926e172021-05-07 16:11:35 -05006271 variable with the line::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006272
6273 EXTRA_IMAGE_FEATURES = "debug-tweaks"
6274
6275 To disable that feature, simply comment out that line in your
Andrew Geissler09036742021-06-25 14:25:14 -05006276 ``local.conf`` file, or make sure :term:`IMAGE_FEATURES` does not contain
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006277 "debug-tweaks" before producing your final image. Among other things,
6278 leaving this in place sets the root password as blank, which makes
6279 logging in for debugging or inspection easy during development but
6280 also means anyone can easily log in during production.
6281
6282- It is possible to set a root password for the image and also to set
6283 passwords for any extra users you might add (e.g. administrative or
6284 service type users). When you set up passwords for multiple images or
6285 users, you should not duplicate passwords.
6286
6287 To set up passwords, use the
6288 :ref:`extrausers <ref-classes-extrausers>`
6289 class, which is the preferred method. For an example on how to set up
6290 both root and user passwords, see the
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00006291 ":ref:`ref-classes-extrausers`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006292
6293 .. note::
6294
6295 When adding extra user accounts or setting a root password, be
6296 cautious about setting the same password on every device. If you
6297 do this, and the password you have set is exposed, then every
6298 device is now potentially compromised. If you need this access but
6299 want to ensure security, consider setting a different, random
6300 password for each device. Typically, you do this as a separate
6301 step after you deploy the image onto the device.
6302
6303- Consider enabling a Mandatory Access Control (MAC) framework such as
6304 SMACK or SELinux and tuning it appropriately for your device's usage.
6305 You can find more information in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06006306 :yocto_git:`meta-selinux </meta-selinux/>` layer.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006307
6308Tools for Hardening Your Image
6309------------------------------
6310
6311The Yocto Project provides tools for making your image more secure. You
6312can find these tools in the ``meta-security`` layer of the
6313:yocto_git:`Yocto Project Source Repositories <>`.
6314
6315Creating Your Own Distribution
6316==============================
6317
6318When you build an image using the Yocto Project and do not alter any
6319distribution :term:`Metadata`, you are
6320creating a Poky distribution. If you wish to gain more control over
6321package alternative selections, compile-time options, and other
6322low-level configurations, you can create your own distribution.
6323
6324To create your own distribution, the basic steps consist of creating
6325your own distribution layer, creating your own distribution
6326configuration file, and then adding any needed code and Metadata to the
6327layer. The following steps provide some more detail:
6328
6329- *Create a layer for your new distro:* Create your distribution layer
6330 so that you can keep your Metadata and code for the distribution
6331 separate. It is strongly recommended that you create and use your own
6332 layer for configuration and code. Using your own layer as compared to
6333 just placing configurations in a ``local.conf`` configuration file
6334 makes it easier to reproduce the same build configuration when using
6335 multiple build machines. See the
Andrew Geissler09209ee2020-12-13 08:44:15 -06006336 ":ref:`dev-manual/common-tasks:creating a general layer using the \`\`bitbake-layers\`\` script`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006337 section for information on how to quickly set up a layer.
6338
6339- *Create the distribution configuration file:* The distribution
6340 configuration file needs to be created in the ``conf/distro``
6341 directory of your layer. You need to name it using your distribution
6342 name (e.g. ``mydistro.conf``).
6343
6344 .. note::
6345
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006346 The :term:`DISTRO` variable in your ``local.conf`` file determines the
6347 name of your distribution.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006348
6349 You can split out parts of your configuration file into include files
6350 and then "require" them from within your distribution configuration
6351 file. Be sure to place the include files in the
6352 ``conf/distro/include`` directory of your layer. A common example
6353 usage of include files would be to separate out the selection of
6354 desired version and revisions for individual recipes.
6355
6356 Your configuration file needs to set the following required
6357 variables:
6358
6359 - :term:`DISTRO_NAME`
6360
6361 - :term:`DISTRO_VERSION`
6362
6363 These following variables are optional and you typically set them
6364 from the distribution configuration file:
6365
6366 - :term:`DISTRO_FEATURES`
6367
6368 - :term:`DISTRO_EXTRA_RDEPENDS`
6369
6370 - :term:`DISTRO_EXTRA_RRECOMMENDS`
6371
6372 - :term:`TCLIBC`
6373
6374 .. tip::
6375
6376 If you want to base your distribution configuration file on the
6377 very basic configuration from OE-Core, you can use
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006378 ``conf/distro/defaultsetup.conf`` as a reference and just include
6379 variables that differ as compared to ``defaultsetup.conf``.
6380 Alternatively, you can create a distribution configuration file
6381 from scratch using the ``defaultsetup.conf`` file or configuration files
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00006382 from another distribution such as Poky as a reference.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006383
6384- *Provide miscellaneous variables:* Be sure to define any other
6385 variables for which you want to create a default or enforce as part
6386 of the distribution configuration. You can include nearly any
6387 variable from the ``local.conf`` file. The variables you use are not
6388 limited to the list in the previous bulleted item.
6389
6390- *Point to Your distribution configuration file:* In your
6391 ``local.conf`` file in the :term:`Build Directory`,
6392 set your
6393 :term:`DISTRO` variable to point to
6394 your distribution's configuration file. For example, if your
6395 distribution's configuration file is named ``mydistro.conf``, then
Andrew Geisslerc926e172021-05-07 16:11:35 -05006396 you point to it as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006397
6398 DISTRO = "mydistro"
6399
6400- *Add more to the layer if necessary:* Use your layer to hold other
6401 information needed for the distribution:
6402
6403 - Add recipes for installing distro-specific configuration files
6404 that are not already installed by another recipe. If you have
6405 distro-specific configuration files that are included by an
6406 existing recipe, you should add an append file (``.bbappend``) for
6407 those. For general information and recommendations on how to add
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006408 recipes to your layer, see the
6409 ":ref:`dev-manual/common-tasks:creating your own layer`" and
6410 ":ref:`dev-manual/common-tasks:following best practices when creating layers`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006411 sections.
6412
6413 - Add any image recipes that are specific to your distribution.
6414
6415 - Add a ``psplash`` append file for a branded splash screen. For
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006416 information on append files, see the
Patrick Williams0ca19cc2021-08-16 14:03:13 -05006417 ":ref:`dev-manual/common-tasks:appending other layers metadata with your layer`"
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006418 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006419
6420 - Add any other append files to make custom changes that are
6421 specific to individual recipes.
6422
6423Creating a Custom Template Configuration Directory
6424==================================================
6425
6426If you are producing your own customized version of the build system for
6427use by other users, you might want to customize the message shown by the
6428setup script or you might want to change the template configuration
6429files (i.e. ``local.conf`` and ``bblayers.conf``) that are created in a
6430new build directory.
6431
6432The OpenEmbedded build system uses the environment variable
6433``TEMPLATECONF`` to locate the directory from which it gathers
6434configuration information that ultimately ends up in the
6435:term:`Build Directory` ``conf`` directory.
6436By default, ``TEMPLATECONF`` is set as follows in the ``poky``
Andrew Geisslerc926e172021-05-07 16:11:35 -05006437repository::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006438
6439 TEMPLATECONF=${TEMPLATECONF:-meta-poky/conf}
6440
6441This is the
6442directory used by the build system to find templates from which to build
6443some key configuration files. If you look at this directory, you will
6444see the ``bblayers.conf.sample``, ``local.conf.sample``, and
6445``conf-notes.txt`` files. The build system uses these files to form the
6446respective ``bblayers.conf`` file, ``local.conf`` file, and display the
6447list of BitBake targets when running the setup script.
6448
6449To override these default configuration files with configurations you
6450want used within every new Build Directory, simply set the
6451``TEMPLATECONF`` variable to your directory. The ``TEMPLATECONF``
6452variable is set in the ``.templateconf`` file, which is in the top-level
6453:term:`Source Directory` folder
6454(e.g. ``poky``). Edit the ``.templateconf`` so that it can locate your
6455directory.
6456
6457Best practices dictate that you should keep your template configuration
6458directory in your custom distribution layer. For example, suppose you
6459have a layer named ``meta-mylayer`` located in your home directory and
6460you want your template configuration directory named ``myconf``.
6461Changing the ``.templateconf`` as follows causes the OpenEmbedded build
6462system to look in your directory and base its configuration files on the
6463``*.sample`` configuration files it finds. The final configuration files
6464(i.e. ``local.conf`` and ``bblayers.conf`` ultimately still end up in
6465your Build Directory, but they are based on your ``*.sample`` files.
6466::
6467
6468 TEMPLATECONF=${TEMPLATECONF:-meta-mylayer/myconf}
6469
6470Aside from the ``*.sample`` configuration files, the ``conf-notes.txt``
6471also resides in the default ``meta-poky/conf`` directory. The script
6472that sets up the build environment (i.e.
6473:ref:`structure-core-script`) uses this file to
6474display BitBake targets as part of the script output. Customizing this
6475``conf-notes.txt`` file is a good way to make sure your list of custom
6476targets appears as part of the script's output.
6477
6478Here is the default list of targets displayed as a result of running
Andrew Geisslerc926e172021-05-07 16:11:35 -05006479either of the setup scripts::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006480
6481 You can now run 'bitbake <target>'
6482
6483 Common targets are:
6484 core-image-minimal
6485 core-image-sato
6486 meta-toolchain
6487 meta-ide-support
6488
6489Changing the listed common targets is as easy as editing your version of
6490``conf-notes.txt`` in your custom template configuration directory and
6491making sure you have ``TEMPLATECONF`` set to your directory.
6492
Andrew Geissler595f6302022-01-24 19:11:47 +00006493Conserving Disk Space
6494=====================
6495
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006496Conserving Disk Space During Builds
Andrew Geissler595f6302022-01-24 19:11:47 +00006497-----------------------------------
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006498
6499To help conserve disk space during builds, you can add the following
6500statement to your project's ``local.conf`` configuration file found in
Andrew Geisslerc926e172021-05-07 16:11:35 -05006501the :term:`Build Directory`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006502
6503 INHERIT += "rm_work"
6504
6505Adding this statement deletes the work directory used for
6506building a recipe once the recipe is built. For more information on
6507"rm_work", see the
6508:ref:`rm_work <ref-classes-rm-work>` class in the
6509Yocto Project Reference Manual.
6510
Andrew Geissler595f6302022-01-24 19:11:47 +00006511Purging Duplicate Shared State Cache Files
6512-------------------------------------------
6513
6514After multiple build iterations, the Shared State (sstate) cache can contain
6515duplicate cache files for a given package, while only the most recent one
6516is likely to be reusable. The following command purges all but the
6517newest sstate cache file for each package::
6518
6519 sstate-cache-management.sh --remove-duplicated --cache-dir=build/sstate-cache
6520
6521This command will ask you to confirm the deletions it identifies.
6522
6523Note::
6524
6525 The duplicated sstate cache files of one package must have the same
6526 architecture, which means that sstate cache files with multiple
6527 architectures are not considered as duplicate.
6528
6529Run ``sstate-cache-management.sh`` for more details about this script.
6530
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006531Working with Packages
6532=====================
6533
6534This section describes a few tasks that involve packages:
6535
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006536- :ref:`dev-manual/common-tasks:excluding packages from an image`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006537
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006538- :ref:`dev-manual/common-tasks:incrementing a package version`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006539
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006540- :ref:`dev-manual/common-tasks:handling optional module packaging`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006541
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006542- :ref:`dev-manual/common-tasks:using runtime package management`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006543
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006544- :ref:`dev-manual/common-tasks:generating and using signed packages`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006545
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006546- :ref:`Setting up and running package test
6547 (ptest) <dev-manual/common-tasks:testing packages with ptest>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006548
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006549- :ref:`dev-manual/common-tasks:creating node package manager (npm) packages`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006550
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006551- :ref:`dev-manual/common-tasks:adding custom metadata to packages`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006552
6553Excluding Packages from an Image
6554--------------------------------
6555
6556You might find it necessary to prevent specific packages from being
6557installed into an image. If so, you can use several variables to direct
6558the build system to essentially ignore installing recommended packages
6559or to not install a package at all.
6560
6561The following list introduces variables you can use to prevent packages
6562from being installed into your image. Each of these variables only works
William A. Kennington IIIac69b482021-06-02 12:28:27 -07006563with IPK and RPM package types, not for Debian packages.
6564Also, you can use these variables from your ``local.conf`` file
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006565or attach them to a specific image recipe by using a recipe name
6566override. For more detail on the variables, see the descriptions in the
6567Yocto Project Reference Manual's glossary chapter.
6568
6569- :term:`BAD_RECOMMENDATIONS`:
6570 Use this variable to specify "recommended-only" packages that you do
6571 not want installed.
6572
6573- :term:`NO_RECOMMENDATIONS`:
6574 Use this variable to prevent all "recommended-only" packages from
6575 being installed.
6576
6577- :term:`PACKAGE_EXCLUDE`:
6578 Use this variable to prevent specific packages from being installed
6579 regardless of whether they are "recommended-only" or not. You need to
6580 realize that the build process could fail with an error when you
6581 prevent the installation of a package whose presence is required by
6582 an installed package.
6583
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006584Incrementing a Package Version
6585------------------------------
6586
6587This section provides some background on how binary package versioning
6588is accomplished and presents some of the services, variables, and
6589terminology involved.
6590
6591In order to understand binary package versioning, you need to consider
6592the following:
6593
6594- Binary Package: The binary package that is eventually built and
6595 installed into an image.
6596
6597- Binary Package Version: The binary package version is composed of two
6598 components - a version and a revision.
6599
6600 .. note::
6601
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006602 Technically, a third component, the "epoch" (i.e. :term:`PE`) is involved
Andrew Geissler09036742021-06-25 14:25:14 -05006603 but this discussion for the most part ignores :term:`PE`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006604
6605 The version and revision are taken from the
6606 :term:`PV` and
6607 :term:`PR` variables, respectively.
6608
Andrew Geissler09036742021-06-25 14:25:14 -05006609- :term:`PV`: The recipe version. :term:`PV` represents the version of the
6610 software being packaged. Do not confuse :term:`PV` with the binary
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006611 package version.
6612
Andrew Geissler5f350902021-07-23 13:09:54 -04006613- :term:`PR`: The recipe revision.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006614
6615- :term:`SRCPV`: The OpenEmbedded
Andrew Geissler09036742021-06-25 14:25:14 -05006616 build system uses this string to help define the value of :term:`PV` when
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006617 the source code revision needs to be included in it.
6618
Andrew Geissler09209ee2020-12-13 08:44:15 -06006619- :yocto_wiki:`PR Service </PR_Service>`: A
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006620 network-based service that helps automate keeping package feeds
6621 compatible with existing package manager applications such as RPM,
6622 APT, and OPKG.
6623
6624Whenever the binary package content changes, the binary package version
6625must change. Changing the binary package version is accomplished by
Andrew Geissler09036742021-06-25 14:25:14 -05006626changing or "bumping" the :term:`PR` and/or :term:`PV` values. Increasing these
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006627values occurs one of two ways:
6628
6629- Automatically using a Package Revision Service (PR Service).
6630
Andrew Geissler09036742021-06-25 14:25:14 -05006631- Manually incrementing the :term:`PR` and/or :term:`PV` variables.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006632
6633Given a primary challenge of any build system and its users is how to
6634maintain a package feed that is compatible with existing package manager
6635applications such as RPM, APT, and OPKG, using an automated system is
6636much preferred over a manual system. In either system, the main
6637requirement is that binary package version numbering increases in a
William A. Kennington IIIac69b482021-06-02 12:28:27 -07006638linear fashion and that there is a number of version components that
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006639support that linear progression. For information on how to ensure
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006640package revisioning remains linear, see the
6641":ref:`dev-manual/common-tasks:automatically incrementing a package version number`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006642section.
6643
6644The following three sections provide related information on the PR
Andrew Geissler09036742021-06-25 14:25:14 -05006645Service, the manual method for "bumping" :term:`PR` and/or :term:`PV`, and on
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006646how to ensure binary package revisioning remains linear.
6647
6648Working With a PR Service
6649~~~~~~~~~~~~~~~~~~~~~~~~~
6650
6651As mentioned, attempting to maintain revision numbers in the
6652:term:`Metadata` is error prone, inaccurate,
6653and causes problems for people submitting recipes. Conversely, the PR
6654Service automatically generates increasing numbers, particularly the
6655revision field, which removes the human element.
6656
6657.. note::
6658
6659 For additional information on using a PR Service, you can see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06006660 :yocto_wiki:`PR Service </PR_Service>` wiki page.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006661
6662The Yocto Project uses variables in order of decreasing priority to
6663facilitate revision numbering (i.e.
6664:term:`PE`,
6665:term:`PV`, and
6666:term:`PR` for epoch, version, and
6667revision, respectively). The values are highly dependent on the policies
6668and procedures of a given distribution and package feed.
6669
6670Because the OpenEmbedded build system uses
Andrew Geissler09209ee2020-12-13 08:44:15 -06006671":ref:`signatures <overview-manual/concepts:checksums (signatures)>`", which are
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006672unique to a given build, the build system knows when to rebuild
6673packages. All the inputs into a given task are represented by a
6674signature, which can trigger a rebuild when different. Thus, the build
Andrew Geissler09036742021-06-25 14:25:14 -05006675system itself does not rely on the :term:`PR`, :term:`PV`, and :term:`PE` numbers to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006676trigger a rebuild. The signatures, however, can be used to generate
6677these values.
6678
6679The PR Service works with both ``OEBasic`` and ``OEBasicHash``
Andrew Geissler09036742021-06-25 14:25:14 -05006680generators. The value of :term:`PR` bumps when the checksum changes and the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006681different generator mechanisms change signatures under different
6682circumstances.
6683
6684As implemented, the build system includes values from the PR Service
Andrew Geissler09036742021-06-25 14:25:14 -05006685into the :term:`PR` field as an addition using the form "``.x``" so ``r0``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006686becomes ``r0.1``, ``r0.2`` and so forth. This scheme allows existing
Andrew Geissler09036742021-06-25 14:25:14 -05006687:term:`PR` values to be used for whatever reasons, which include manual
6688:term:`PR` bumps, should it be necessary.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006689
6690By default, the PR Service is not enabled or running. Thus, the packages
6691generated are just "self consistent". The build system adds and removes
6692packages and there are no guarantees about upgrade paths but images will
6693be consistent and correct with the latest changes.
6694
William A. Kennington IIIac69b482021-06-02 12:28:27 -07006695The simplest form for a PR Service is for a single host
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006696development system that builds the package feed (building system). For
6697this scenario, you can enable a local PR Service by setting
6698:term:`PRSERV_HOST` in your
Andrew Geisslerc926e172021-05-07 16:11:35 -05006699``local.conf`` file in the :term:`Build Directory`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006700
6701 PRSERV_HOST = "localhost:0"
6702
6703Once the service is started, packages will automatically
Andrew Geissler09036742021-06-25 14:25:14 -05006704get increasing :term:`PR` values and BitBake takes care of starting and
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006705stopping the server.
6706
6707If you have a more complex setup where multiple host development systems
6708work against a common, shared package feed, you have a single PR Service
6709running and it is connected to each building system. For this scenario,
Andrew Geisslerc926e172021-05-07 16:11:35 -05006710you need to start the PR Service using the ``bitbake-prserv`` command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006711
6712 bitbake-prserv --host ip --port port --start
6713
6714In addition to
6715hand-starting the service, you need to update the ``local.conf`` file of
6716each building system as described earlier so each system points to the
6717server and port.
6718
6719It is also recommended you use build history, which adds some sanity
6720checks to binary package versions, in conjunction with the server that
6721is running the PR Service. To enable build history, add the following to
Andrew Geisslerc926e172021-05-07 16:11:35 -05006722each building system's ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006723
6724 # It is recommended to activate "buildhistory" for testing the PR service
6725 INHERIT += "buildhistory"
6726 BUILDHISTORY_COMMIT = "1"
6727
6728For information on build
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006729history, see the
6730":ref:`dev-manual/common-tasks:maintaining build output quality`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006731
6732.. note::
6733
Andrew Geissler09036742021-06-25 14:25:14 -05006734 The OpenEmbedded build system does not maintain :term:`PR` information as
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006735 part of the shared state (sstate) packages. If you maintain an sstate
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006736 feed, it's expected that either all your building systems that
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006737 contribute to the sstate feed use a shared PR Service, or you do not
6738 run a PR Service on any of your building systems. Having some systems
6739 use a PR Service while others do not leads to obvious problems.
6740
6741 For more information on shared state, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06006742 ":ref:`overview-manual/concepts:shared state cache`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006743 section in the Yocto Project Overview and Concepts Manual.
6744
6745Manually Bumping PR
6746~~~~~~~~~~~~~~~~~~~
6747
6748The alternative to setting up a PR Service is to manually "bump" the
6749:term:`PR` variable.
6750
6751If a committed change results in changing the package output, then the
6752value of the PR variable needs to be increased (or "bumped") as part of
Andrew Geissler09036742021-06-25 14:25:14 -05006753that commit. For new recipes you should add the :term:`PR` variable and set
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006754its initial value equal to "r0", which is the default. Even though the
6755default value is "r0", the practice of adding it to a new recipe makes
6756it harder to forget to bump the variable when you make changes to the
6757recipe in future.
6758
6759If you are sharing a common ``.inc`` file with multiple recipes, you can
Andrew Geissler09036742021-06-25 14:25:14 -05006760also use the :term:`INC_PR` variable to ensure that the recipes sharing the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006761``.inc`` file are rebuilt when the ``.inc`` file itself is changed. The
Andrew Geissler09036742021-06-25 14:25:14 -05006762``.inc`` file must set :term:`INC_PR` (initially to "r0"), and all recipes
6763referring to it should set :term:`PR` to "${INC_PR}.0" initially,
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006764incrementing the last number when the recipe is changed. If the ``.inc``
Andrew Geissler09036742021-06-25 14:25:14 -05006765file is changed then its :term:`INC_PR` should be incremented.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006766
Andrew Geissler09036742021-06-25 14:25:14 -05006767When upgrading the version of a binary package, assuming the :term:`PV`
6768changes, the :term:`PR` variable should be reset to "r0" (or "${INC_PR}.0"
6769if you are using :term:`INC_PR`).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006770
6771Usually, version increases occur only to binary packages. However, if
Andrew Geissler09036742021-06-25 14:25:14 -05006772for some reason :term:`PV` changes but does not increase, you can increase
6773the :term:`PE` variable (Package Epoch). The :term:`PE` variable defaults to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006774"0".
6775
6776Binary package version numbering strives to follow the `Debian Version
6777Field Policy
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006778Guidelines <https://www.debian.org/doc/debian-policy/ch-controlfields.html>`__.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006779These guidelines define how versions are compared and what "increasing"
6780a version means.
6781
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006782Automatically Incrementing a Package Version Number
6783~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6784
6785When fetching a repository, BitBake uses the
6786:term:`SRCREV` variable to determine
6787the specific source code revision from which to build. You set the
Andrew Geissler09036742021-06-25 14:25:14 -05006788:term:`SRCREV` variable to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006789:term:`AUTOREV` to cause the
6790OpenEmbedded build system to automatically use the latest revision of
Andrew Geisslerc926e172021-05-07 16:11:35 -05006791the software::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006792
6793 SRCREV = "${AUTOREV}"
6794
Andrew Geissler09036742021-06-25 14:25:14 -05006795Furthermore, you need to reference :term:`SRCPV` in :term:`PV` in order to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006796automatically update the version whenever the revision of the source
Andrew Geisslerc926e172021-05-07 16:11:35 -05006797code changes. Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006798
6799 PV = "1.0+git${SRCPV}"
6800
Andrew Geissler09036742021-06-25 14:25:14 -05006801The OpenEmbedded build system substitutes :term:`SRCPV` with the following:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006802
6803.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006804
6805 AUTOINC+source_code_revision
6806
6807The build system replaces the ``AUTOINC``
6808with a number. The number used depends on the state of the PR Service:
6809
6810- If PR Service is enabled, the build system increments the number,
6811 which is similar to the behavior of
6812 :term:`PR`. This behavior results in
6813 linearly increasing package versions, which is desirable. Here is an
6814 example:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006815
6816 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006817
6818 hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
6819 hello-world-git_0.0+git1+dd2f5c3565-r0.0_armv7a-neon.ipk
6820
6821- If PR Service is not enabled, the build system replaces the
6822 ``AUTOINC`` placeholder with zero (i.e. "0"). This results in
6823 changing the package version since the source revision is included.
6824 However, package versions are not increased linearly. Here is an
6825 example:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006826
6827 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006828
6829 hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
6830 hello-world-git_0.0+git0+dd2f5c3565-r0.0_armv7a-neon.ipk
6831
6832In summary, the OpenEmbedded build system does not track the history of
6833binary package versions for this purpose. ``AUTOINC``, in this case, is
Andrew Geissler09036742021-06-25 14:25:14 -05006834comparable to :term:`PR`. If PR server is not enabled, ``AUTOINC`` in the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006835package version is simply replaced by "0". If PR server is enabled, the
6836build system keeps track of the package versions and bumps the number
6837when the package revision changes.
6838
6839Handling Optional Module Packaging
6840----------------------------------
6841
6842Many pieces of software split functionality into optional modules (or
6843plugins) and the plugins that are built might depend on configuration
6844options. To avoid having to duplicate the logic that determines what
6845modules are available in your recipe or to avoid having to package each
6846module by hand, the OpenEmbedded build system provides functionality to
6847handle module packaging dynamically.
6848
6849To handle optional module packaging, you need to do two things:
6850
6851- Ensure the module packaging is actually done.
6852
6853- Ensure that any dependencies on optional modules from other recipes
6854 are satisfied by your recipe.
6855
6856Making Sure the Packaging is Done
6857~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6858
6859To ensure the module packaging actually gets done, you use the
6860``do_split_packages`` function within the ``populate_packages`` Python
6861function in your recipe. The ``do_split_packages`` function searches for
6862a pattern of files or directories under a specified path and creates a
6863package for each one it finds by appending to the
6864:term:`PACKAGES` variable and
Patrick Williams0ca19cc2021-08-16 14:03:13 -05006865setting the appropriate values for ``FILES:packagename``,
6866``RDEPENDS:packagename``, ``DESCRIPTION:packagename``, and so forth.
Andrew Geisslerc926e172021-05-07 16:11:35 -05006867Here is an example from the ``lighttpd`` recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006868
Patrick Williams0ca19cc2021-08-16 14:03:13 -05006869 python populate_packages:prepend () {
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006870 lighttpd_libdir = d.expand('${libdir}')
6871 do_split_packages(d, lighttpd_libdir, '^mod_(.*).so$',
6872 'lighttpd-module-%s', 'Lighttpd module for %s',
6873 extra_depends='')
6874 }
6875
6876The previous example specifies a number of things in the call to
6877``do_split_packages``.
6878
6879- A directory within the files installed by your recipe through
6880 ``do_install`` in which to search.
6881
6882- A regular expression used to match module files in that directory. In
6883 the example, note the parentheses () that mark the part of the
6884 expression from which the module name should be derived.
6885
6886- A pattern to use for the package names.
6887
6888- A description for each package.
6889
6890- An empty string for ``extra_depends``, which disables the default
6891 dependency on the main ``lighttpd`` package. Thus, if a file in
6892 ``${libdir}`` called ``mod_alias.so`` is found, a package called
6893 ``lighttpd-module-alias`` is created for it and the
6894 :term:`DESCRIPTION` is set to
6895 "Lighttpd module for alias".
6896
6897Often, packaging modules is as simple as the previous example. However,
William A. Kennington IIIac69b482021-06-02 12:28:27 -07006898there are more advanced options that you can use within
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006899``do_split_packages`` to modify its behavior. And, if you need to, you
6900can add more logic by specifying a hook function that is called for each
6901package. It is also perfectly acceptable to call ``do_split_packages``
6902multiple times if you have more than one set of modules to package.
6903
6904For more examples that show how to use ``do_split_packages``, see the
6905``connman.inc`` file in the ``meta/recipes-connectivity/connman/``
Andrew Geissler09209ee2020-12-13 08:44:15 -06006906directory of the ``poky`` :ref:`source repository <overview-manual/development-environment:yocto project source repositories>`. You can
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006907also find examples in ``meta/classes/kernel.bbclass``.
6908
6909Following is a reference that shows ``do_split_packages`` mandatory and
Andrew Geisslerc926e172021-05-07 16:11:35 -05006910optional arguments::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006911
6912 Mandatory arguments
6913
6914 root
6915 The path in which to search
6916 file_regex
6917 Regular expression to match searched files.
6918 Use parentheses () to mark the part of this
6919 expression that should be used to derive the
6920 module name (to be substituted where %s is
6921 used in other function arguments as noted below)
6922 output_pattern
6923 Pattern to use for the package names. Must
6924 include %s.
6925 description
6926 Description to set for each package. Must
6927 include %s.
6928
6929 Optional arguments
6930
6931 postinst
6932 Postinstall script to use for all packages
6933 (as a string)
6934 recursive
6935 True to perform a recursive search - default
6936 False
6937 hook
6938 A hook function to be called for every match.
6939 The function will be called with the following
6940 arguments (in the order listed):
6941
6942 f
6943 Full path to the file/directory match
6944 pkg
6945 The package name
6946 file_regex
6947 As above
6948 output_pattern
6949 As above
6950 modulename
6951 The module name derived using file_regex
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006952 extra_depends
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006953 Extra runtime dependencies (RDEPENDS) to be
6954 set for all packages. The default value of None
6955 causes a dependency on the main package
6956 (${PN}) - if you do not want this, pass empty
6957 string '' for this parameter.
6958 aux_files_pattern
6959 Extra item(s) to be added to FILES for each
6960 package. Can be a single string item or a list
6961 of strings for multiple items. Must include %s.
6962 postrm
6963 postrm script to use for all packages (as a
6964 string)
6965 allow_dirs
6966 True to allow directories to be matched -
6967 default False
6968 prepend
6969 If True, prepend created packages to PACKAGES
6970 instead of the default False which appends them
6971 match_path
6972 match file_regex on the whole relative path to
Patrick Williams0ca19cc2021-08-16 14:03:13 -05006973 the root rather than just the filename
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006974 aux_files_pattern_verbatim
6975 Extra item(s) to be added to FILES for each
6976 package, using the actual derived module name
6977 rather than converting it to something legal
6978 for a package name. Can be a single string item
6979 or a list of strings for multiple items. Must
6980 include %s.
6981 allow_links
6982 True to allow symlinks to be matched - default
6983 False
6984 summary
6985 Summary to set for each package. Must include %s;
6986 defaults to description if not set.
6987
6988
6989
6990Satisfying Dependencies
6991~~~~~~~~~~~~~~~~~~~~~~~
6992
6993The second part for handling optional module packaging is to ensure that
6994any dependencies on optional modules from other recipes are satisfied by
6995your recipe. You can be sure these dependencies are satisfied by using
6996the :term:`PACKAGES_DYNAMIC`
6997variable. Here is an example that continues with the ``lighttpd`` recipe
Andrew Geisslerc926e172021-05-07 16:11:35 -05006998shown earlier::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006999
7000 PACKAGES_DYNAMIC = "lighttpd-module-.*"
7001
7002The name
7003specified in the regular expression can of course be anything. In this
7004example, it is ``lighttpd-module-`` and is specified as the prefix to
7005ensure that any :term:`RDEPENDS` and
7006:term:`RRECOMMENDS` on a package
7007name starting with the prefix are satisfied during build time. If you
7008are using ``do_split_packages`` as described in the previous section,
Andrew Geissler09036742021-06-25 14:25:14 -05007009the value you put in :term:`PACKAGES_DYNAMIC` should correspond to the name
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007010pattern specified in the call to ``do_split_packages``.
7011
7012Using Runtime Package Management
7013--------------------------------
7014
7015During a build, BitBake always transforms a recipe into one or more
7016packages. For example, BitBake takes the ``bash`` recipe and produces a
7017number of packages (e.g. ``bash``, ``bash-bashbug``,
7018``bash-completion``, ``bash-completion-dbg``, ``bash-completion-dev``,
7019``bash-completion-extra``, ``bash-dbg``, and so forth). Not all
7020generated packages are included in an image.
7021
7022In several situations, you might need to update, add, remove, or query
7023the packages on a target device at runtime (i.e. without having to
7024generate a new image). Examples of such situations include:
7025
7026- You want to provide in-the-field updates to deployed devices (e.g.
7027 security updates).
7028
7029- You want to have a fast turn-around development cycle for one or more
7030 applications that run on your device.
7031
7032- You want to temporarily install the "debug" packages of various
7033 applications on your device so that debugging can be greatly improved
7034 by allowing access to symbols and source debugging.
7035
7036- You want to deploy a more minimal package selection of your device
7037 but allow in-the-field updates to add a larger selection for
7038 customization.
7039
7040In all these situations, you have something similar to a more
7041traditional Linux distribution in that in-field devices are able to
7042receive pre-compiled packages from a server for installation or update.
7043Being able to install these packages on a running, in-field device is
7044what is termed "runtime package management".
7045
7046In order to use runtime package management, you need a host or server
7047machine that serves up the pre-compiled packages plus the required
7048metadata. You also need package manipulation tools on the target. The
7049build machine is a likely candidate to act as the server. However, that
7050machine does not necessarily have to be the package server. The build
7051machine could push its artifacts to another machine that acts as the
7052server (e.g. Internet-facing). In fact, doing so is advantageous for a
7053production environment as getting the packages away from the development
7054system's build directory prevents accidental overwrites.
7055
7056A simple build that targets just one device produces more than one
7057package database. In other words, the packages produced by a build are
7058separated out into a couple of different package groupings based on
7059criteria such as the target's CPU architecture, the target board, or the
7060C library used on the target. For example, a build targeting the
7061``qemux86`` device produces the following three package databases:
7062``noarch``, ``i586``, and ``qemux86``. If you wanted your ``qemux86``
7063device to be aware of all the packages that were available to it, you
7064would need to point it to each of these databases individually. In a
7065similar way, a traditional Linux distribution usually is configured to
7066be aware of a number of software repositories from which it retrieves
7067packages.
7068
7069Using runtime package management is completely optional and not required
7070for a successful build or deployment in any way. But if you want to make
7071use of runtime package management, you need to do a couple things above
7072and beyond the basics. The remainder of this section describes what you
7073need to do.
7074
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007075Build Considerations
7076~~~~~~~~~~~~~~~~~~~~
7077
7078This section describes build considerations of which you need to be
7079aware in order to provide support for runtime package management.
7080
7081When BitBake generates packages, it needs to know what format or formats
7082to use. In your configuration, you use the
7083:term:`PACKAGE_CLASSES`
7084variable to specify the format:
7085
70861. Open the ``local.conf`` file inside your
7087 :term:`Build Directory` (e.g.
Andrew Geissler95ac1b82021-03-31 14:34:31 -05007088 ``poky/build/conf/local.conf``).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007089
Andrew Geisslerc926e172021-05-07 16:11:35 -050070902. Select the desired package format as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007091
7092 PACKAGE_CLASSES ?= "package_packageformat"
7093
7094 where packageformat can be "ipk", "rpm",
7095 "deb", or "tar" which are the supported package formats.
7096
7097 .. note::
7098
7099 Because the Yocto Project supports four different package formats,
7100 you can set the variable with more than one argument. However, the
7101 OpenEmbedded build system only uses the first argument when
7102 creating an image or Software Development Kit (SDK).
7103
7104If you would like your image to start off with a basic package database
7105containing the packages in your current build as well as to have the
7106relevant tools available on the target for runtime package management,
7107you can include "package-management" in the
7108:term:`IMAGE_FEATURES`
7109variable. Including "package-management" in this configuration variable
7110ensures that when the image is assembled for your target, the image
7111includes the currently-known package databases as well as the
7112target-specific tools required for runtime package management to be
7113performed on the target. However, this is not strictly necessary. You
7114could start your image off without any databases but only include the
7115required on-target package tool(s). As an example, you could include
7116"opkg" in your
7117:term:`IMAGE_INSTALL` variable
7118if you are using the IPK package format. You can then initialize your
7119target's package database(s) later once your image is up and running.
7120
7121Whenever you perform any sort of build step that can potentially
7122generate a package or modify existing package, it is always a good idea
7123to re-generate the package index after the build by using the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05007124command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007125
7126 $ bitbake package-index
7127
7128It might be tempting to build the
7129package and the package index at the same time with a command such as
Andrew Geisslerc926e172021-05-07 16:11:35 -05007130the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007131
7132 $ bitbake some-package package-index
7133
7134Do not do this as
7135BitBake does not schedule the package index for after the completion of
7136the package you are building. Consequently, you cannot be sure of the
7137package index including information for the package you just built.
7138Thus, be sure to run the package update step separately after building
7139any packages.
7140
7141You can use the
7142:term:`PACKAGE_FEED_ARCHS`,
7143:term:`PACKAGE_FEED_BASE_PATHS`,
7144and
7145:term:`PACKAGE_FEED_URIS`
7146variables to pre-configure target images to use a package feed. If you
7147do not define these variables, then manual steps as described in the
7148subsequent sections are necessary to configure the target. You should
7149set these variables before building the image in order to produce a
7150correctly configured image.
7151
7152When your build is complete, your packages reside in the
7153``${TMPDIR}/deploy/packageformat`` directory. For example, if
7154``${``\ :term:`TMPDIR`\ ``}`` is
7155``tmp`` and your selected package type is RPM, then your RPM packages
7156are available in ``tmp/deploy/rpm``.
7157
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007158Host or Server Machine Setup
7159~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7160
7161Although other protocols are possible, a server using HTTP typically
7162serves packages. If you want to use HTTP, then set up and configure a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007163web server such as Apache 2, lighttpd, or Python web server on the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007164machine serving the packages.
7165
7166To keep things simple, this section describes how to set up a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007167Python web server to share package feeds from the developer's
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007168machine. Although this server might not be the best for a production
7169environment, the setup is simple and straight forward. Should you want
7170to use a different server more suited for production (e.g. Apache 2,
7171Lighttpd, or Nginx), take the appropriate steps to do so.
7172
7173From within the build directory where you have built an image based on
7174your packaging choice (i.e. the
7175:term:`PACKAGE_CLASSES`
7176setting), simply start the server. The following example assumes a build
Andrew Geissler09036742021-06-25 14:25:14 -05007177directory of ``poky/build/tmp/deploy/rpm`` and a :term:`PACKAGE_CLASSES`
Andrew Geisslerc926e172021-05-07 16:11:35 -05007178setting of "package_rpm"::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007179
Andrew Geissler95ac1b82021-03-31 14:34:31 -05007180 $ cd poky/build/tmp/deploy/rpm
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007181 $ python3 -m http.server
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007182
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007183Target Setup
7184~~~~~~~~~~~~
7185
7186Setting up the target differs depending on the package management
7187system. This section provides information for RPM, IPK, and DEB.
7188
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007189Using RPM
7190^^^^^^^^^
7191
7192The `Dandified Packaging
7193Tool <https://en.wikipedia.org/wiki/DNF_(software)>`__ (DNF) performs
7194runtime package management of RPM packages. In order to use DNF for
7195runtime package management, you must perform an initial setup on the
7196target machine for cases where the ``PACKAGE_FEED_*`` variables were not
7197set as part of the image that is running on the target. This means if
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05007198you built your image and did not use these variables as part of the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007199build and your image is now running on the target, you need to perform
7200the steps in this section if you want to use runtime package management.
7201
7202.. note::
7203
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007204 For information on the ``PACKAGE_FEED_*`` variables, see
7205 :term:`PACKAGE_FEED_ARCHS`, :term:`PACKAGE_FEED_BASE_PATHS`, and
7206 :term:`PACKAGE_FEED_URIS` in the Yocto Project Reference Manual variables
7207 glossary.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007208
7209On the target, you must inform DNF that package databases are available.
7210You do this by creating a file named
7211``/etc/yum.repos.d/oe-packages.repo`` and defining the ``oe-packages``.
7212
7213As an example, assume the target is able to use the following package
7214databases: ``all``, ``i586``, and ``qemux86`` from a server named
7215``my.server``. The specifics for setting up the web server are up to
7216you. The critical requirement is that the URIs in the target repository
7217configuration point to the correct remote location for the feeds.
7218
7219.. note::
7220
7221 For development purposes, you can point the web server to the build
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007222 system's ``deploy`` directory. However, for production use, it is better to
7223 copy the package directories to a location outside of the build area and use
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007224 that location. Doing so avoids situations where the build system
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007225 overwrites or changes the ``deploy`` directory.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007226
7227When telling DNF where to look for the package databases, you must
7228declare individual locations per architecture or a single location used
7229for all architectures. You cannot do both:
7230
7231- *Create an Explicit List of Architectures:* Define individual base
7232 URLs to identify where each package database is located:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007233
7234 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007235
7236 [oe-packages]
7237 baseurl=http://my.server/rpm/i586 http://my.server/rpm/qemux86 http://my.server/rpm/all
7238
7239 This example
7240 informs DNF about individual package databases for all three
7241 architectures.
7242
7243- *Create a Single (Full) Package Index:* Define a single base URL that
Andrew Geisslerc926e172021-05-07 16:11:35 -05007244 identifies where a full package database is located::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007245
7246 [oe-packages]
7247 baseurl=http://my.server/rpm
7248
7249 This example informs DNF about a single
7250 package database that contains all the package index information for
7251 all supported architectures.
7252
7253Once you have informed DNF where to find the package databases, you need
7254to fetch them:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007255
7256.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007257
7258 # dnf makecache
7259
7260DNF is now able to find, install, and
7261upgrade packages from the specified repository or repositories.
7262
7263.. note::
7264
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007265 See the `DNF documentation <https://dnf.readthedocs.io/en/latest/>`__ for
7266 additional information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007267
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007268Using IPK
7269^^^^^^^^^
7270
7271The ``opkg`` application performs runtime package management of IPK
7272packages. You must perform an initial setup for ``opkg`` on the target
7273machine if the
7274:term:`PACKAGE_FEED_ARCHS`,
7275:term:`PACKAGE_FEED_BASE_PATHS`,
7276and
7277:term:`PACKAGE_FEED_URIS`
7278variables have not been set or the target image was built before the
7279variables were set.
7280
7281The ``opkg`` application uses configuration files to find available
7282package databases. Thus, you need to create a configuration file inside
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00007283the ``/etc/opkg/`` directory, which informs ``opkg`` of any repository
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007284you want to use.
7285
7286As an example, suppose you are serving packages from a ``ipk/``
7287directory containing the ``i586``, ``all``, and ``qemux86`` databases
7288through an HTTP server named ``my.server``. On the target, create a
7289configuration file (e.g. ``my_repo.conf``) inside the ``/etc/opkg/``
7290directory containing the following:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007291
7292.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007293
7294 src/gz all http://my.server/ipk/all
7295 src/gz i586 http://my.server/ipk/i586
7296 src/gz qemux86 http://my.server/ipk/qemux86
7297
7298Next, instruct ``opkg`` to fetch the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007299repository information:
7300
7301.. code-block:: none
7302
7303 # opkg update
7304
7305The ``opkg`` application is now able to find, install, and upgrade packages
7306from the specified repository.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007307
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007308Using DEB
7309^^^^^^^^^
7310
7311The ``apt`` application performs runtime package management of DEB
7312packages. This application uses a source list file to find available
7313package databases. You must perform an initial setup for ``apt`` on the
7314target machine if the
7315:term:`PACKAGE_FEED_ARCHS`,
7316:term:`PACKAGE_FEED_BASE_PATHS`,
7317and
7318:term:`PACKAGE_FEED_URIS`
7319variables have not been set or the target image was built before the
7320variables were set.
7321
7322To inform ``apt`` of the repository you want to use, you might create a
7323list file (e.g. ``my_repo.list``) inside the
7324``/etc/apt/sources.list.d/`` directory. As an example, suppose you are
7325serving packages from a ``deb/`` directory containing the ``i586``,
7326``all``, and ``qemux86`` databases through an HTTP server named
7327``my.server``. The list file should contain:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007328
7329.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007330
7331 deb http://my.server/deb/all ./
7332 deb http://my.server/deb/i586 ./
7333 deb http://my.server/deb/qemux86 ./
7334
7335Next, instruct the ``apt`` application
7336to fetch the repository information:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007337
7338.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007339
Andrew Geisslereff27472021-10-29 15:35:00 -05007340 $ sudo apt update
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007341
7342After this step,
7343``apt`` is able to find, install, and upgrade packages from the
7344specified repository.
7345
7346Generating and Using Signed Packages
7347------------------------------------
7348
7349In order to add security to RPM packages used during a build, you can
7350take steps to securely sign them. Once a signature is verified, the
7351OpenEmbedded build system can use the package in the build. If security
Andrew Geissler595f6302022-01-24 19:11:47 +00007352fails for a signed package, the build system stops the build.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007353
7354This section describes how to sign RPM packages during a build and how
7355to use signed package feeds (repositories) when doing a build.
7356
7357Signing RPM Packages
7358~~~~~~~~~~~~~~~~~~~~
7359
7360To enable signing RPM packages, you must set up the following
7361configurations in either your ``local.config`` or ``distro.config``
Andrew Geisslerc926e172021-05-07 16:11:35 -05007362file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007363
7364 # Inherit sign_rpm.bbclass to enable signing functionality
7365 INHERIT += " sign_rpm"
7366 # Define the GPG key that will be used for signing.
7367 RPM_GPG_NAME = "key_name"
7368 # Provide passphrase for the key
7369 RPM_GPG_PASSPHRASE = "passphrase"
7370
7371.. note::
7372
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007373 Be sure to supply appropriate values for both `key_name` and
7374 `passphrase`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007375
7376Aside from the ``RPM_GPG_NAME`` and ``RPM_GPG_PASSPHRASE`` variables in
William A. Kennington IIIac69b482021-06-02 12:28:27 -07007377the previous example, two optional variables related to signing are available:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007378
7379- *GPG_BIN:* Specifies a ``gpg`` binary/wrapper that is executed
7380 when the package is signed.
7381
7382- *GPG_PATH:* Specifies the ``gpg`` home directory used when the
7383 package is signed.
7384
7385Processing Package Feeds
7386~~~~~~~~~~~~~~~~~~~~~~~~
7387
7388In addition to being able to sign RPM packages, you can also enable
7389signed package feeds for IPK and RPM packages.
7390
7391The steps you need to take to enable signed package feed use are similar
7392to the steps used to sign RPM packages. You must define the following in
Andrew Geisslerc926e172021-05-07 16:11:35 -05007393your ``local.config`` or ``distro.config`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007394
7395 INHERIT += "sign_package_feed"
7396 PACKAGE_FEED_GPG_NAME = "key_name"
7397 PACKAGE_FEED_GPG_PASSPHRASE_FILE = "path_to_file_containing_passphrase"
7398
William A. Kennington IIIac69b482021-06-02 12:28:27 -07007399For signed package feeds, the passphrase must be specified in a separate file,
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007400which is pointed to by the ``PACKAGE_FEED_GPG_PASSPHRASE_FILE``
7401variable. Regarding security, keeping a plain text passphrase out of the
7402configuration is more secure.
7403
7404Aside from the ``PACKAGE_FEED_GPG_NAME`` and
7405``PACKAGE_FEED_GPG_PASSPHRASE_FILE`` variables, three optional variables
William A. Kennington IIIac69b482021-06-02 12:28:27 -07007406related to signed package feeds are available:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007407
7408- *GPG_BIN* Specifies a ``gpg`` binary/wrapper that is executed
7409 when the package is signed.
7410
7411- *GPG_PATH:* Specifies the ``gpg`` home directory used when the
7412 package is signed.
7413
7414- *PACKAGE_FEED_GPG_SIGNATURE_TYPE:* Specifies the type of ``gpg``
7415 signature. This variable applies only to RPM and IPK package feeds.
7416 Allowable values for the ``PACKAGE_FEED_GPG_SIGNATURE_TYPE`` are
7417 "ASC", which is the default and specifies ascii armored, and "BIN",
7418 which specifies binary.
7419
7420Testing Packages With ptest
7421---------------------------
7422
7423A Package Test (ptest) runs tests against packages built by the
7424OpenEmbedded build system on the target machine. A ptest contains at
7425least two items: the actual test, and a shell script (``run-ptest``)
7426that starts the test. The shell script that starts the test must not
7427contain the actual test - the script only starts the test. On the other
7428hand, the test can be anything from a simple shell script that runs a
7429binary and checks the output to an elaborate system of test binaries and
7430data files.
7431
Andrew Geisslerc926e172021-05-07 16:11:35 -05007432The test generates output in the format used by Automake::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007433
7434 result: testname
7435
7436where the result can be ``PASS``, ``FAIL``, or ``SKIP``, and
7437the testname can be any identifying string.
7438
7439For a list of Yocto Project recipes that are already enabled with ptest,
Andrew Geissler09209ee2020-12-13 08:44:15 -06007440see the :yocto_wiki:`Ptest </Ptest>` wiki page.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007441
7442.. note::
7443
7444 A recipe is "ptest-enabled" if it inherits the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007445 :ref:`ptest <ref-classes-ptest>` class.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007446
7447Adding ptest to Your Build
7448~~~~~~~~~~~~~~~~~~~~~~~~~~
7449
7450To add package testing to your build, add the
7451:term:`DISTRO_FEATURES` and
7452:term:`EXTRA_IMAGE_FEATURES`
7453variables to your ``local.conf`` file, which is found in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05007454:term:`Build Directory`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007455
Patrick Williams0ca19cc2021-08-16 14:03:13 -05007456 DISTRO_FEATURES:append = " ptest"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007457 EXTRA_IMAGE_FEATURES += "ptest-pkgs"
7458
7459Once your build is complete, the ptest files are installed into the
7460``/usr/lib/package/ptest`` directory within the image, where ``package``
7461is the name of the package.
7462
7463Running ptest
7464~~~~~~~~~~~~~
7465
7466The ``ptest-runner`` package installs a shell script that loops through
7467all installed ptest test suites and runs them in sequence. Consequently,
7468you might want to add this package to your image.
7469
7470Getting Your Package Ready
7471~~~~~~~~~~~~~~~~~~~~~~~~~~
7472
7473In order to enable a recipe to run installed ptests on target hardware,
7474you need to prepare the recipes that build the packages you want to
7475test. Here is what you have to do for each recipe:
7476
7477- *Be sure the recipe inherits
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007478 the* :ref:`ptest <ref-classes-ptest>` *class:*
Andrew Geisslerc926e172021-05-07 16:11:35 -05007479 Include the following line in each recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007480
7481 inherit ptest
7482
7483- *Create run-ptest:* This script starts your test. Locate the
7484 script where you will refer to it using
7485 :term:`SRC_URI`. Here is an
Andrew Geisslerc926e172021-05-07 16:11:35 -05007486 example that starts a test for ``dbus``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007487
7488 #!/bin/sh
7489 cd test
7490 make -k runtest-TESTS
7491
7492- *Ensure dependencies are met:* If the test adds build or runtime
7493 dependencies that normally do not exist for the package (such as
7494 requiring "make" to run the test suite), use the
7495 :term:`DEPENDS` and
7496 :term:`RDEPENDS` variables in
7497 your recipe in order for the package to meet the dependencies. Here
Andrew Geisslerc926e172021-05-07 16:11:35 -05007498 is an example where the package has a runtime dependency on "make"::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007499
Patrick Williams0ca19cc2021-08-16 14:03:13 -05007500 RDEPENDS:${PN}-ptest += "make"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007501
7502- *Add a function to build the test suite:* Not many packages support
7503 cross-compilation of their test suites. Consequently, you usually
7504 need to add a cross-compilation function to the package.
7505
7506 Many packages based on Automake compile and run the test suite by
7507 using a single command such as ``make check``. However, the host
7508 ``make check`` builds and runs on the same computer, while
7509 cross-compiling requires that the package is built on the host but
7510 executed for the target architecture (though often, as in the case
7511 for ptest, the execution occurs on the host). The built version of
7512 Automake that ships with the Yocto Project includes a patch that
7513 separates building and execution. Consequently, packages that use the
7514 unaltered, patched version of ``make check`` automatically
7515 cross-compiles.
7516
7517 Regardless, you still must add a ``do_compile_ptest`` function to
7518 build the test suite. Add a function similar to the following to your
Andrew Geisslerc926e172021-05-07 16:11:35 -05007519 recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007520
7521 do_compile_ptest() {
7522 oe_runmake buildtest-TESTS
7523 }
7524
7525- *Ensure special configurations are set:* If the package requires
7526 special configurations prior to compiling the test code, you must
7527 insert a ``do_configure_ptest`` function into the recipe.
7528
7529- *Install the test suite:* The ``ptest`` class automatically copies
7530 the file ``run-ptest`` to the target and then runs make
7531 ``install-ptest`` to run the tests. If this is not enough, you need
7532 to create a ``do_install_ptest`` function and make sure it gets
7533 called after the "make install-ptest" completes.
7534
7535Creating Node Package Manager (NPM) Packages
7536--------------------------------------------
7537
7538`NPM <https://en.wikipedia.org/wiki/Npm_(software)>`__ is a package
7539manager for the JavaScript programming language. The Yocto Project
Andrew Geissler09209ee2020-12-13 08:44:15 -06007540supports the NPM :ref:`fetcher <bitbake:bitbake-user-manual/bitbake-user-manual-fetching:fetchers>`. You can
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007541use this fetcher in combination with
Andrew Geissler09209ee2020-12-13 08:44:15 -06007542:doc:`devtool </ref-manual/devtool-reference>` to create
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007543recipes that produce NPM packages.
7544
William A. Kennington IIIac69b482021-06-02 12:28:27 -07007545There are two workflows that allow you to create NPM packages using
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007546``devtool``: the NPM registry modules method and the NPM project code
7547method.
7548
7549.. note::
7550
7551 While it is possible to create NPM recipes manually, using
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007552 ``devtool`` is far simpler.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007553
7554Additionally, some requirements and caveats exist.
7555
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007556Requirements and Caveats
7557~~~~~~~~~~~~~~~~~~~~~~~~
7558
7559You need to be aware of the following before using ``devtool`` to create
7560NPM packages:
7561
7562- Of the two methods that you can use ``devtool`` to create NPM
7563 packages, the registry approach is slightly simpler. However, you
7564 might consider the project approach because you do not have to
7565 publish your module in the NPM registry
7566 (`npm-registry <https://docs.npmjs.com/misc/registry>`_), which
7567 is NPM's public registry.
7568
7569- Be familiar with
Andrew Geissler09209ee2020-12-13 08:44:15 -06007570 :doc:`devtool </ref-manual/devtool-reference>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007571
7572- The NPM host tools need the native ``nodejs-npm`` package, which is
7573 part of the OpenEmbedded environment. You need to get the package by
7574 cloning the https://github.com/openembedded/meta-openembedded
7575 repository out of GitHub. Be sure to add the path to your local copy
7576 to your ``bblayers.conf`` file.
7577
7578- ``devtool`` cannot detect native libraries in module dependencies.
7579 Consequently, you must manually add packages to your recipe.
7580
7581- While deploying NPM packages, ``devtool`` cannot determine which
7582 dependent packages are missing on the target (e.g. the node runtime
7583 ``nodejs``). Consequently, you need to find out what files are
7584 missing and be sure they are on the target.
7585
7586- Although you might not need NPM to run your node package, it is
7587 useful to have NPM on your target. The NPM package name is
7588 ``nodejs-npm``.
7589
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007590Using the Registry Modules Method
7591~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7592
7593This section presents an example that uses the ``cute-files`` module,
7594which is a file browser web application.
7595
7596.. note::
7597
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007598 You must know the ``cute-files`` module version.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007599
7600The first thing you need to do is use ``devtool`` and the NPM fetcher to
Andrew Geisslerc926e172021-05-07 16:11:35 -05007601create the recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007602
7603 $ devtool add "npm://registry.npmjs.org;package=cute-files;version=1.0.2"
7604
7605The
7606``devtool add`` command runs ``recipetool create`` and uses the same
7607fetch URI to download each dependency and capture license details where
7608possible. The result is a generated recipe.
7609
7610The recipe file is fairly simple and contains every license that
7611``recipetool`` finds and includes the licenses in the recipe's
7612:term:`LIC_FILES_CHKSUM`
7613variables. You need to examine the variables and look for those with
7614"unknown" in the :term:`LICENSE`
7615field. You need to track down the license information for "unknown"
7616modules and manually add the information to the recipe.
7617
7618``recipetool`` creates a "shrinkwrap" file for your recipe. Shrinkwrap
7619files capture the version of all dependent modules. Many packages do not
7620provide shrinkwrap files. ``recipetool`` create a shrinkwrap file as it
7621runs.
7622
7623.. note::
7624
7625 A package is created for each sub-module. This policy is the only
7626 practical way to have the licenses for all of the dependencies
7627 represented in the license manifest of the image.
7628
Andrew Geisslerc926e172021-05-07 16:11:35 -05007629The ``devtool edit-recipe`` command lets you take a look at the recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007630
7631 $ devtool edit-recipe cute-files
7632 SUMMARY = "Turn any folder on your computer into a cute file browser, available on the local network."
7633 LICENSE = "MIT & ISC & Unknown"
7634 LIC_FILES_CHKSUM = "file://LICENSE;md5=71d98c0a1db42956787b1909c74a86ca \
7635 file://node_modules/toidentifier/LICENSE;md5=1a261071a044d02eb6f2bb47f51a3502 \
7636 file://node_modules/debug/LICENSE;md5=ddd815a475e7338b0be7a14d8ee35a99 \
7637 ...
7638 SRC_URI = " \
7639 npm://registry.npmjs.org/;package=cute-files;version=${PV} \
7640 npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \
7641 "
7642 S = "${WORKDIR}/npm"
Patrick Williams213cb262021-08-07 19:21:33 -05007643 inherit npm
Patrick Williams0ca19cc2021-08-16 14:03:13 -05007644 LICENSE:${PN} = "MIT"
7645 LICENSE:${PN}-accepts = "MIT"
7646 LICENSE:${PN}-array-flatten = "MIT"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007647 ...
Patrick Williams0ca19cc2021-08-16 14:03:13 -05007648 LICENSE:${PN}-vary = "MIT"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007649
William A. Kennington IIIac69b482021-06-02 12:28:27 -07007650Here are three key points in the previous example:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007651
7652- :term:`SRC_URI` uses the NPM
7653 scheme so that the NPM fetcher is used.
7654
7655- ``recipetool`` collects all the license information. If a
7656 sub-module's license is unavailable, the sub-module's name appears in
7657 the comments.
7658
7659- The ``inherit npm`` statement causes the
7660 :ref:`npm <ref-classes-npm>` class to package
7661 up all the modules.
7662
Andrew Geisslerc926e172021-05-07 16:11:35 -05007663You can run the following command to build the ``cute-files`` package::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007664
7665 $ devtool build cute-files
7666
7667Remember that ``nodejs`` must be installed on
7668the target before your package.
7669
7670Assuming 192.168.7.2 for the target's IP address, use the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05007671command to deploy your package::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007672
7673 $ devtool deploy-target -s cute-files root@192.168.7.2
7674
7675Once the package is installed on the target, you can
7676test the application:
7677
7678.. note::
7679
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007680 Because of a known issue, you cannot simply run ``cute-files`` as you would
7681 if you had run ``npm install``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007682
7683::
7684
7685 $ cd /usr/lib/node_modules/cute-files
7686 $ node cute-files.js
7687
7688On a browser,
7689go to ``http://192.168.7.2:3000`` and you see the following:
7690
7691.. image:: figures/cute-files-npm-example.png
7692 :align: center
7693
7694You can find the recipe in ``workspace/recipes/cute-files``. You can use
7695the recipe in any layer you choose.
7696
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007697Using the NPM Projects Code Method
7698~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7699
7700Although it is useful to package modules already in the NPM registry,
7701adding ``node.js`` projects under development is a more common developer
7702use case.
7703
7704This section covers the NPM projects code method, which is very similar
7705to the "registry" approach described in the previous section. In the NPM
7706projects method, you provide ``devtool`` with an URL that points to the
7707source files.
7708
7709Replicating the same example, (i.e. ``cute-files``) use the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05007710command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007711
7712 $ devtool add https://github.com/martinaglv/cute-files.git
7713
7714The
7715recipe this command generates is very similar to the recipe created in
Andrew Geissler09036742021-06-25 14:25:14 -05007716the previous section. However, the :term:`SRC_URI` looks like the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007717
7718 SRC_URI = " \
7719 git://github.com/martinaglv/cute-files.git;protocol=https \
7720 npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \
7721 "
7722
7723In this example,
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007724the main module is taken from the Git repository and dependencies are
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007725taken from the NPM registry. Other than those differences, the recipe is
7726basically the same between the two methods. You can build and deploy the
7727package exactly as described in the previous section that uses the
7728registry modules method.
7729
7730Adding custom metadata to packages
7731----------------------------------
7732
7733The variable
7734:term:`PACKAGE_ADD_METADATA`
7735can be used to add additional metadata to packages. This is reflected in
7736the package control/spec file. To take the ipk format for example, the
7737CONTROL file stored inside would contain the additional metadata as
7738additional lines.
7739
7740The variable can be used in multiple ways, including using suffixes to
7741set it for a specific package type and/or package. Note that the order
7742of precedence is the same as this list:
7743
Patrick Williams0ca19cc2021-08-16 14:03:13 -05007744- ``PACKAGE_ADD_METADATA_<PKGTYPE>:<PN>``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007745
7746- ``PACKAGE_ADD_METADATA_<PKGTYPE>``
7747
Patrick Williams0ca19cc2021-08-16 14:03:13 -05007748- ``PACKAGE_ADD_METADATA:<PN>``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007749
Andrew Geissler09036742021-06-25 14:25:14 -05007750- :term:`PACKAGE_ADD_METADATA`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007751
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007752`<PKGTYPE>` is a parameter and expected to be a distinct name of specific
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007753package type:
7754
7755- IPK for .ipk packages
7756
7757- DEB for .deb packages
7758
7759- RPM for .rpm packages
7760
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007761`<PN>` is a parameter and expected to be a package name.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007762
7763The variable can contain multiple [one-line] metadata fields separated
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007764by the literal sequence '\\n'. The separator can be redefined using the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007765variable flag ``separator``.
7766
William A. Kennington IIIac69b482021-06-02 12:28:27 -07007767Here is an example that adds two custom fields for ipk
Andrew Geisslerc926e172021-05-07 16:11:35 -05007768packages::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007769
7770 PACKAGE_ADD_METADATA_IPK = "Vendor: CustomIpk\nGroup:Applications/Spreadsheets"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007771
7772Efficiently Fetching Source Files During a Build
7773================================================
7774
7775The OpenEmbedded build system works with source files located through
7776the :term:`SRC_URI` variable. When
7777you build something using BitBake, a big part of the operation is
7778locating and downloading all the source tarballs. For images,
7779downloading all the source for various packages can take a significant
7780amount of time.
7781
7782This section shows you how you can use mirrors to speed up fetching
7783source files and how you can pre-fetch files all of which leads to more
7784efficient use of resources and time.
7785
7786Setting up Effective Mirrors
7787----------------------------
7788
7789A good deal that goes into a Yocto Project build is simply downloading
7790all of the source tarballs. Maybe you have been working with another
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00007791build system for which you have built up a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007792sizable directory of source tarballs. Or, perhaps someone else has such
7793a directory for which you have read access. If so, you can save time by
7794adding statements to your configuration file so that the build process
7795checks local directories first for existing tarballs before checking the
7796Internet.
7797
Andrew Geisslerc926e172021-05-07 16:11:35 -05007798Here is an efficient way to set it up in your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007799
7800 SOURCE_MIRROR_URL ?= "file:///home/you/your-download-dir/"
7801 INHERIT += "own-mirrors"
7802 BB_GENERATE_MIRROR_TARBALLS = "1"
7803 # BB_NO_NETWORK = "1"
7804
7805In the previous example, the
7806:term:`BB_GENERATE_MIRROR_TARBALLS`
7807variable causes the OpenEmbedded build system to generate tarballs of
7808the Git repositories and store them in the
7809:term:`DL_DIR` directory. Due to
7810performance reasons, generating and storing these tarballs is not the
7811build system's default behavior.
7812
7813You can also use the
7814:term:`PREMIRRORS` variable. For
7815an example, see the variable's glossary entry in the Yocto Project
7816Reference Manual.
7817
7818Getting Source Files and Suppressing the Build
7819----------------------------------------------
7820
7821Another technique you can use to ready yourself for a successive string
7822of build operations, is to pre-fetch all the source files without
7823actually starting a build. This technique lets you work through any
7824download issues and ultimately gathers all the source files into your
7825download directory :ref:`structure-build-downloads`,
7826which is located with :term:`DL_DIR`.
7827
7828Use the following BitBake command form to fetch all the necessary
Andrew Geisslerc926e172021-05-07 16:11:35 -05007829sources without starting the build::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007830
7831 $ bitbake target --runall=fetch
7832
7833This
7834variation of the BitBake command guarantees that you have all the
7835sources for that BitBake target should you disconnect from the Internet
7836and want to do the build later offline.
7837
7838Selecting an Initialization Manager
7839===================================
7840
7841By default, the Yocto Project uses SysVinit as the initialization
William A. Kennington IIIac69b482021-06-02 12:28:27 -07007842manager. However, there is also support for systemd, which is a full
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007843replacement for init with parallel starting of services, reduced shell
7844overhead and other features that are used by many distributions.
7845
7846Within the system, SysVinit treats system components as services. These
7847services are maintained as shell scripts stored in the ``/etc/init.d/``
7848directory. Services organize into different run levels. This
7849organization is maintained by putting links to the services in the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007850``/etc/rcN.d/`` directories, where `N/` is one of the following options:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007851"S", "0", "1", "2", "3", "4", "5", or "6".
7852
7853.. note::
7854
7855 Each runlevel has a dependency on the previous runlevel. This
7856 dependency allows the services to work properly.
7857
7858In comparison, systemd treats components as units. Using units is a
7859broader concept as compared to using a service. A unit includes several
7860different types of entities. Service is one of the types of entities.
7861The runlevel concept in SysVinit corresponds to the concept of a target
7862in systemd, where target is also a type of supported unit.
7863
7864In a SysVinit-based system, services load sequentially (i.e. one by one)
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007865during init and parallelization is not supported. With systemd, services
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007866start in parallel. Needless to say, the method can have an impact on
7867system startup performance.
7868
7869If you want to use SysVinit, you do not have to do anything. But, if you
7870want to use systemd, you must take some steps as described in the
7871following sections.
7872
7873Using systemd Exclusively
7874-------------------------
7875
Andrew Geisslerc926e172021-05-07 16:11:35 -05007876Set these variables in your distribution configuration file as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007877
Patrick Williams0ca19cc2021-08-16 14:03:13 -05007878 DISTRO_FEATURES:append = " systemd"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007879 VIRTUAL-RUNTIME_init_manager = "systemd"
7880
7881You can also prevent the SysVinit distribution feature from
Andrew Geisslerc926e172021-05-07 16:11:35 -05007882being automatically enabled as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007883
7884 DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
7885
7886Doing so removes any
7887redundant SysVinit scripts.
7888
7889To remove initscripts from your image altogether, set this variable
Andrew Geisslerc926e172021-05-07 16:11:35 -05007890also::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007891
7892 VIRTUAL-RUNTIME_initscripts = ""
7893
7894For information on the backfill variable, see
7895:term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`.
7896
7897Using systemd for the Main Image and Using SysVinit for the Rescue Image
7898------------------------------------------------------------------------
7899
Andrew Geisslerc926e172021-05-07 16:11:35 -05007900Set these variables in your distribution configuration file as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007901
Patrick Williams0ca19cc2021-08-16 14:03:13 -05007902 DISTRO_FEATURES:append = " systemd"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007903 VIRTUAL-RUNTIME_init_manager = "systemd"
7904
7905Doing so causes your main image to use the
7906``packagegroup-core-boot.bb`` recipe and systemd. The rescue/minimal
7907image cannot use this package group. However, it can install SysVinit
7908and the appropriate packages will have support for both systemd and
7909SysVinit.
7910
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007911Selecting a Device Manager
7912==========================
7913
7914The Yocto Project provides multiple ways to manage the device manager
7915(``/dev``):
7916
Andrew Geissler5199d832021-09-24 16:47:35 -05007917- Persistent and Pre-Populated ``/dev``: For this case, the ``/dev``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007918 directory is persistent and the required device nodes are created
7919 during the build.
7920
7921- Use ``devtmpfs`` with a Device Manager: For this case, the ``/dev``
7922 directory is provided by the kernel as an in-memory file system and
7923 is automatically populated by the kernel at runtime. Additional
7924 configuration of device nodes is done in user space by a device
7925 manager like ``udev`` or ``busybox-mdev``.
7926
Andrew Geissler5199d832021-09-24 16:47:35 -05007927Using Persistent and Pre-Populated ``/dev``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007928--------------------------------------------
7929
7930To use the static method for device population, you need to set the
7931:term:`USE_DEVFS` variable to "0"
Andrew Geisslerc926e172021-05-07 16:11:35 -05007932as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007933
7934 USE_DEVFS = "0"
7935
7936The content of the resulting ``/dev`` directory is defined in a Device
7937Table file. The
7938:term:`IMAGE_DEVICE_TABLES`
7939variable defines the Device Table to use and should be set in the
7940machine or distro configuration file. Alternatively, you can set this
7941variable in your ``local.conf`` configuration file.
7942
Andrew Geissler09036742021-06-25 14:25:14 -05007943If you do not define the :term:`IMAGE_DEVICE_TABLES` variable, the default
Andrew Geisslerc926e172021-05-07 16:11:35 -05007944``device_table-minimal.txt`` is used::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007945
7946 IMAGE_DEVICE_TABLES = "device_table-mymachine.txt"
7947
7948The population is handled by the ``makedevs`` utility during image
7949creation:
7950
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007951Using ``devtmpfs`` and a Device Manager
7952---------------------------------------
7953
7954To use the dynamic method for device population, you need to use (or be
7955sure to set) the :term:`USE_DEVFS`
Andrew Geisslerc926e172021-05-07 16:11:35 -05007956variable to "1", which is the default::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007957
7958 USE_DEVFS = "1"
7959
7960With this
7961setting, the resulting ``/dev`` directory is populated by the kernel
7962using ``devtmpfs``. Make sure the corresponding kernel configuration
7963variable ``CONFIG_DEVTMPFS`` is set when building you build a Linux
7964kernel.
7965
7966All devices created by ``devtmpfs`` will be owned by ``root`` and have
7967permissions ``0600``.
7968
7969To have more control over the device nodes, you can use a device manager
7970like ``udev`` or ``busybox-mdev``. You choose the device manager by
7971defining the ``VIRTUAL-RUNTIME_dev_manager`` variable in your machine or
7972distro configuration file. Alternatively, you can set this variable in
Andrew Geisslerc926e172021-05-07 16:11:35 -05007973your ``local.conf`` configuration file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007974
7975 VIRTUAL-RUNTIME_dev_manager = "udev"
7976
7977 # Some alternative values
7978 # VIRTUAL-RUNTIME_dev_manager = "busybox-mdev"
7979 # VIRTUAL-RUNTIME_dev_manager = "systemd"
7980
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007981Using an External SCM
7982=====================
7983
7984If you're working on a recipe that pulls from an external Source Code
7985Manager (SCM), it is possible to have the OpenEmbedded build system
7986notice new recipe changes added to the SCM and then build the resulting
7987packages that depend on the new recipes by using the latest versions.
7988This only works for SCMs from which it is possible to get a sensible
7989revision number for changes. Currently, you can do this with Apache
7990Subversion (SVN), Git, and Bazaar (BZR) repositories.
7991
7992To enable this behavior, the :term:`PV` of
7993the recipe needs to reference
Andrew Geisslerc926e172021-05-07 16:11:35 -05007994:term:`SRCPV`. Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007995
7996 PV = "1.2.3+git${SRCPV}"
7997
7998Then, you can add the following to your
Andrew Geisslerc926e172021-05-07 16:11:35 -05007999``local.conf``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008000
Patrick Williams0ca19cc2021-08-16 14:03:13 -05008001 SRCREV:pn-PN = "${AUTOREV}"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008002
8003:term:`PN` is the name of the recipe for
8004which you want to enable automatic source revision updating.
8005
8006If you do not want to update your local configuration file, you can add
Andrew Geisslerc926e172021-05-07 16:11:35 -05008007the following directly to the recipe to finish enabling the feature::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008008
8009 SRCREV = "${AUTOREV}"
8010
8011The Yocto Project provides a distribution named ``poky-bleeding``, whose
Andrew Geisslerc926e172021-05-07 16:11:35 -05008012configuration file contains the line::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008013
8014 require conf/distro/include/poky-floating-revisions.inc
8015
8016This line pulls in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05008017listed include file that contains numerous lines of exactly that form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008018
Patrick Williams0ca19cc2021-08-16 14:03:13 -05008019 #SRCREV:pn-opkg-native ?= "${AUTOREV}"
8020 #SRCREV:pn-opkg-sdk ?= "${AUTOREV}"
8021 #SRCREV:pn-opkg ?= "${AUTOREV}"
8022 #SRCREV:pn-opkg-utils-native ?= "${AUTOREV}"
8023 #SRCREV:pn-opkg-utils ?= "${AUTOREV}"
8024 SRCREV:pn-gconf-dbus ?= "${AUTOREV}"
8025 SRCREV:pn-matchbox-common ?= "${AUTOREV}"
8026 SRCREV:pn-matchbox-config-gtk ?= "${AUTOREV}"
8027 SRCREV:pn-matchbox-desktop ?= "${AUTOREV}"
8028 SRCREV:pn-matchbox-keyboard ?= "${AUTOREV}"
8029 SRCREV:pn-matchbox-panel-2 ?= "${AUTOREV}"
8030 SRCREV:pn-matchbox-themes-extra ?= "${AUTOREV}"
8031 SRCREV:pn-matchbox-terminal ?= "${AUTOREV}"
8032 SRCREV:pn-matchbox-wm ?= "${AUTOREV}"
8033 SRCREV:pn-settings-daemon ?= "${AUTOREV}"
8034 SRCREV:pn-screenshot ?= "${AUTOREV}"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008035 . . .
8036
8037These lines allow you to
8038experiment with building a distribution that tracks the latest
8039development source for numerous packages.
8040
8041.. note::
8042
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008043 The ``poky-bleeding`` distribution is not tested on a regular basis. Keep
8044 this in mind if you use it.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008045
8046Creating a Read-Only Root Filesystem
8047====================================
8048
8049Suppose, for security reasons, you need to disable your target device's
8050root filesystem's write permissions (i.e. you need a read-only root
8051filesystem). Or, perhaps you are running the device's operating system
8052from a read-only storage device. For either case, you can customize your
8053image for that behavior.
8054
8055.. note::
8056
8057 Supporting a read-only root filesystem requires that the system and
8058 applications do not try to write to the root filesystem. You must
8059 configure all parts of the target system to write elsewhere, or to
8060 gracefully fail in the event of attempting to write to the root
8061 filesystem.
8062
8063Creating the Root Filesystem
8064----------------------------
8065
8066To create the read-only root filesystem, simply add the
8067"read-only-rootfs" feature to your image, normally in one of two ways.
8068The first way is to add the "read-only-rootfs" image feature in the
Andrew Geissler09036742021-06-25 14:25:14 -05008069image's recipe file via the :term:`IMAGE_FEATURES` variable::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008070
8071 IMAGE_FEATURES += "read-only-rootfs"
8072
8073As an alternative, you can add the same feature
8074from within your build directory's ``local.conf`` file with the
Andrew Geissler09036742021-06-25 14:25:14 -05008075associated :term:`EXTRA_IMAGE_FEATURES` variable, as in::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008076
8077 EXTRA_IMAGE_FEATURES = "read-only-rootfs"
8078
8079For more information on how to use these variables, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06008080":ref:`dev-manual/common-tasks:Customizing Images Using Custom \`\`IMAGE_FEATURES\`\` and \`\`EXTRA_IMAGE_FEATURES\`\``"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008081section. For information on the variables, see
8082:term:`IMAGE_FEATURES` and
8083:term:`EXTRA_IMAGE_FEATURES`.
8084
8085Post-Installation Scripts and Read-Only Root Filesystem
8086-------------------------------------------------------
8087
8088It is very important that you make sure all post-Installation
8089(``pkg_postinst``) scripts for packages that are installed into the
8090image can be run at the time when the root filesystem is created during
8091the build on the host system. These scripts cannot attempt to run during
Patrick Williams0ca19cc2021-08-16 14:03:13 -05008092the first boot on the target device. With the "read-only-rootfs" feature
8093enabled, the build system makes sure that all post-installation scripts
8094succeed at file system creation time. If any of these scripts
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008095still need to be run after the root filesystem is created, the build
8096immediately fails. These build-time checks ensure that the build fails
8097rather than the target device fails later during its initial boot
8098operation.
8099
8100Most of the common post-installation scripts generated by the build
8101system for the out-of-the-box Yocto Project are engineered so that they
8102can run during root filesystem creation (e.g. post-installation scripts
8103for caching fonts). However, if you create and add custom scripts, you
8104need to be sure they can be run during this file system creation.
8105
8106Here are some common problems that prevent post-installation scripts
8107from running during root filesystem creation:
8108
8109- *Not using $D in front of absolute paths:* The build system defines
8110 ``$``\ :term:`D` when the root
8111 filesystem is created. Furthermore, ``$D`` is blank when the script
8112 is run on the target device. This implies two purposes for ``$D``:
8113 ensuring paths are valid in both the host and target environments,
8114 and checking to determine which environment is being used as a method
8115 for taking appropriate actions.
8116
8117- *Attempting to run processes that are specific to or dependent on the
8118 target architecture:* You can work around these attempts by using
8119 native tools, which run on the host system, to accomplish the same
8120 tasks, or by alternatively running the processes under QEMU, which
8121 has the ``qemu_run_binary`` function. For more information, see the
8122 :ref:`qemu <ref-classes-qemu>` class.
8123
8124Areas With Write Access
8125-----------------------
8126
8127With the "read-only-rootfs" feature enabled, any attempt by the target
8128to write to the root filesystem at runtime fails. Consequently, you must
8129make sure that you configure processes and applications that attempt
8130these types of writes do so to directories with write access (e.g.
8131``/tmp`` or ``/var/run``).
8132
8133Maintaining Build Output Quality
8134================================
8135
8136Many factors can influence the quality of a build. For example, if you
8137upgrade a recipe to use a new version of an upstream software package or
8138you experiment with some new configuration options, subtle changes can
8139occur that you might not detect until later. Consider the case where
8140your recipe is using a newer version of an upstream package. In this
8141case, a new version of a piece of software might introduce an optional
8142dependency on another library, which is auto-detected. If that library
8143has already been built when the software is building, the software will
8144link to the built library and that library will be pulled into your
8145image along with the new software even if you did not want the library.
8146
8147The :ref:`buildhistory <ref-classes-buildhistory>`
William A. Kennington IIIac69b482021-06-02 12:28:27 -07008148class helps you maintain the quality of your build output. You
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008149can use the class to highlight unexpected and possibly unwanted changes
8150in the build output. When you enable build history, it records
8151information about the contents of each package and image and then
8152commits that information to a local Git repository where you can examine
8153the information.
8154
8155The remainder of this section describes the following:
8156
Andrew Geissler09209ee2020-12-13 08:44:15 -06008157- :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 -05008158
Andrew Geissler09209ee2020-12-13 08:44:15 -06008159- :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 -05008160
Andrew Geissler09209ee2020-12-13 08:44:15 -06008161- :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 -05008162
Andrew Geissler09209ee2020-12-13 08:44:15 -06008163- :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 -05008164
8165Enabling and Disabling Build History
8166------------------------------------
8167
8168Build history is disabled by default. To enable it, add the following
Andrew Geissler09036742021-06-25 14:25:14 -05008169:term:`INHERIT` statement and set the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008170:term:`BUILDHISTORY_COMMIT`
8171variable to "1" at the end of your ``conf/local.conf`` file found in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05008172:term:`Build Directory`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008173
8174 INHERIT += "buildhistory"
8175 BUILDHISTORY_COMMIT = "1"
8176
8177Enabling build history as
8178previously described causes the OpenEmbedded build system to collect
8179build output information and commit it as a single commit to a local
Andrew Geissler09209ee2020-12-13 08:44:15 -06008180:ref:`overview-manual/development-environment:git` repository.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008181
8182.. note::
8183
8184 Enabling build history increases your build times slightly,
8185 particularly for images, and increases the amount of disk space used
8186 during the build.
8187
8188You can disable build history by removing the previous statements from
8189your ``conf/local.conf`` file.
8190
8191Understanding What the Build History Contains
8192---------------------------------------------
8193
8194Build history information is kept in
8195``${``\ :term:`TOPDIR`\ ``}/buildhistory``
8196in the Build Directory as defined by the
8197:term:`BUILDHISTORY_DIR`
William A. Kennington IIIac69b482021-06-02 12:28:27 -07008198variable. Here is an example abbreviated listing:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008199
8200.. image:: figures/buildhistory.png
8201 :align: center
8202
William A. Kennington IIIac69b482021-06-02 12:28:27 -07008203At the top level, there is a ``metadata-revs`` file that lists the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008204revisions of the repositories for the enabled layers when the build was
8205produced. The rest of the data splits into separate ``packages``,
8206``images`` and ``sdk`` directories, the contents of which are described
8207as follows.
8208
8209Build History Package Information
8210~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8211
8212The history for each package contains a text file that has name-value
8213pairs with information about the package. For example,
8214``buildhistory/packages/i586-poky-linux/busybox/busybox/latest``
8215contains the following:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008216
8217.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008218
8219 PV = 1.22.1
8220 PR = r32
8221 RPROVIDES =
8222 RDEPENDS = glibc (>= 2.20) update-alternatives-opkg
8223 RRECOMMENDS = busybox-syslog busybox-udhcpc update-rc.d
8224 PKGSIZE = 540168
8225 FILES = /usr/bin/* /usr/sbin/* /usr/lib/busybox/* /usr/lib/lib*.so.* \
8226 /etc /com /var /bin/* /sbin/* /lib/*.so.* /lib/udev/rules.d \
8227 /usr/lib/udev/rules.d /usr/share/busybox /usr/lib/busybox/* \
8228 /usr/share/pixmaps /usr/share/applications /usr/share/idl \
8229 /usr/share/omf /usr/share/sounds /usr/lib/bonobo/servers
8230 FILELIST = /bin/busybox /bin/busybox.nosuid /bin/busybox.suid /bin/sh \
8231 /etc/busybox.links.nosuid /etc/busybox.links.suid
8232
8233Most of these
8234name-value pairs correspond to variables used to produce the package.
8235The exceptions are ``FILELIST``, which is the actual list of files in
8236the package, and ``PKGSIZE``, which is the total size of files in the
8237package in bytes.
8238
William A. Kennington IIIac69b482021-06-02 12:28:27 -07008239There is also a file that corresponds to the recipe from which the package
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008240came (e.g. ``buildhistory/packages/i586-poky-linux/busybox/latest``):
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008241
8242.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008243
8244 PV = 1.22.1
8245 PR = r32
8246 DEPENDS = initscripts kern-tools-native update-rc.d-native \
8247 virtual/i586-poky-linux-compilerlibs virtual/i586-poky-linux-gcc \
8248 virtual/libc virtual/update-alternatives
8249 PACKAGES = busybox-ptest busybox-httpd busybox-udhcpd busybox-udhcpc \
8250 busybox-syslog busybox-mdev busybox-hwclock busybox-dbg \
8251 busybox-staticdev busybox-dev busybox-doc busybox-locale busybox
8252
8253Finally, for those recipes fetched from a version control system (e.g.,
William A. Kennington IIIac69b482021-06-02 12:28:27 -07008254Git), there is a file that lists source revisions that are specified in
8255the recipe and the actual revisions used during the build. Listed
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008256and actual revisions might differ when
8257:term:`SRCREV` is set to
8258${:term:`AUTOREV`}. Here is an
8259example assuming
Andrew Geisslerc926e172021-05-07 16:11:35 -05008260``buildhistory/packages/qemux86-poky-linux/linux-yocto/latest_srcrev``)::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008261
8262 # SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
8263 SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
8264 # SRCREV_meta = "a227f20eff056e511d504b2e490f3774ab260d6f"
8265 SRCREV_meta ="a227f20eff056e511d504b2e490f3774ab260d6f"
8266
8267You can use the
8268``buildhistory-collect-srcrevs`` command with the ``-a`` option to
Andrew Geissler09036742021-06-25 14:25:14 -05008269collect the stored :term:`SRCREV` values from build history and report them
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008270in a format suitable for use in global configuration (e.g.,
8271``local.conf`` or a distro include file) to override floating
Andrew Geissler09036742021-06-25 14:25:14 -05008272:term:`AUTOREV` values to a fixed set of revisions. Here is some example
Andrew Geisslerc926e172021-05-07 16:11:35 -05008273output from this command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008274
8275 $ buildhistory-collect-srcrevs -a
8276 # i586-poky-linux
Patrick Williams0ca19cc2021-08-16 14:03:13 -05008277 SRCREV:pn-glibc = "b8079dd0d360648e4e8de48656c5c38972621072"
8278 SRCREV:pn-glibc-initial = "b8079dd0d360648e4e8de48656c5c38972621072"
8279 SRCREV:pn-opkg-utils = "53274f087565fd45d8452c5367997ba6a682a37a"
8280 SRCREV:pn-kmod = "fd56638aed3fe147015bfa10ed4a5f7491303cb4"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008281 # x86_64-linux
Patrick Williams0ca19cc2021-08-16 14:03:13 -05008282 SRCREV:pn-gtk-doc-stub-native = "1dea266593edb766d6d898c79451ef193eb17cfa"
8283 SRCREV:pn-dtc-native = "65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf"
8284 SRCREV:pn-update-rc.d-native = "eca680ddf28d024954895f59a241a622dd575c11"
8285 SRCREV_glibc:pn-cross-localedef-native = "b8079dd0d360648e4e8de48656c5c38972621072"
8286 SRCREV_localedef:pn-cross-localedef-native = "c833367348d39dad7ba018990bfdaffaec8e9ed3"
8287 SRCREV:pn-prelink-native = "faa069deec99bf61418d0bab831c83d7c1b797ca"
8288 SRCREV:pn-opkg-utils-native = "53274f087565fd45d8452c5367997ba6a682a37a"
8289 SRCREV:pn-kern-tools-native = "23345b8846fe4bd167efdf1bd8a1224b2ba9a5ff"
8290 SRCREV:pn-kmod-native = "fd56638aed3fe147015bfa10ed4a5f7491303cb4"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008291 # qemux86-poky-linux
Patrick Williams0ca19cc2021-08-16 14:03:13 -05008292 SRCREV_machine:pn-linux-yocto = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
8293 SRCREV_meta:pn-linux-yocto = "a227f20eff056e511d504b2e490f3774ab260d6f"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008294 # all-poky-linux
Patrick Williams0ca19cc2021-08-16 14:03:13 -05008295 SRCREV:pn-update-rc.d = "eca680ddf28d024954895f59a241a622dd575c11"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008296
8297.. note::
8298
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008299 Here are some notes on using the ``buildhistory-collect-srcrevs`` command:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008300
Andrew Geissler09036742021-06-25 14:25:14 -05008301 - By default, only values where the :term:`SRCREV` was not hardcoded
Andrew Geissler5f350902021-07-23 13:09:54 -04008302 (usually when :term:`AUTOREV` is used) are reported. Use the ``-a``
8303 option to see all :term:`SRCREV` values.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008304
8305 - The output statements might not have any effect if overrides are
8306 applied elsewhere in the build system configuration. Use the
8307 ``-f`` option to add the ``forcevariable`` override to each output
8308 line if you need to work around this restriction.
8309
8310 - The script does apply special handling when building for multiple
8311 machines. However, the script does place a comment before each set
8312 of values that specifies which triplet to which they belong as
8313 previously shown (e.g., ``i586-poky-linux``).
8314
8315Build History Image Information
8316~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8317
8318The files produced for each image are as follows:
8319
8320- ``image-files:`` A directory containing selected files from the root
8321 filesystem. The files are defined by
8322 :term:`BUILDHISTORY_IMAGE_FILES`.
8323
8324- ``build-id.txt:`` Human-readable information about the build
8325 configuration and metadata source revisions. This file contains the
8326 full build header as printed by BitBake.
8327
8328- ``*.dot:`` Dependency graphs for the image that are compatible with
8329 ``graphviz``.
8330
8331- ``files-in-image.txt:`` A list of files in the image with
8332 permissions, owner, group, size, and symlink information.
8333
8334- ``image-info.txt:`` A text file containing name-value pairs with
8335 information about the image. See the following listing example for
8336 more information.
8337
8338- ``installed-package-names.txt:`` A list of installed packages by name
8339 only.
8340
8341- ``installed-package-sizes.txt:`` A list of installed packages ordered
8342 by size.
8343
8344- ``installed-packages.txt:`` A list of installed packages with full
8345 package filenames.
8346
8347.. note::
8348
8349 Installed package information is able to be gathered and produced
8350 even if package management is disabled for the final image.
8351
8352Here is an example of ``image-info.txt``:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008353
8354.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008355
8356 DISTRO = poky
8357 DISTRO_VERSION = 1.7
Andrew Geissler5f350902021-07-23 13:09:54 -04008358 USER_CLASSES = buildstats image-prelink
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008359 IMAGE_CLASSES = image_types
8360 IMAGE_FEATURES = debug-tweaks
8361 IMAGE_LINGUAS =
8362 IMAGE_INSTALL = packagegroup-core-boot run-postinsts
8363 BAD_RECOMMENDATIONS =
8364 NO_RECOMMENDATIONS =
8365 PACKAGE_EXCLUDE =
8366 ROOTFS_POSTPROCESS_COMMAND = write_package_manifest; license_create_manifest; \
8367 write_image_manifest ; buildhistory_list_installed_image ; \
8368 buildhistory_get_image_installed ; ssh_allow_empty_password; \
8369 postinst_enable_logging; rootfs_update_timestamp ; ssh_disable_dns_lookup ;
8370 IMAGE_POSTPROCESS_COMMAND = buildhistory_get_imageinfo ;
8371 IMAGESIZE = 6900
8372
8373Other than ``IMAGESIZE``,
8374which is the total size of the files in the image in Kbytes, the
8375name-value pairs are variables that may have influenced the content of
8376the image. This information is often useful when you are trying to
8377determine why a change in the package or file listings has occurred.
8378
8379Using Build History to Gather Image Information Only
8380~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8381
8382As you can see, build history produces image information, including
8383dependency graphs, so you can see why something was pulled into the
8384image. If you are just interested in this information and not interested
8385in collecting specific package or SDK information, you can enable
8386writing only image information without any history by adding the
8387following to your ``conf/local.conf`` file found in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05008388:term:`Build Directory`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008389
8390 INHERIT += "buildhistory"
8391 BUILDHISTORY_COMMIT = "0"
8392 BUILDHISTORY_FEATURES = "image"
8393
8394Here, you set the
8395:term:`BUILDHISTORY_FEATURES`
8396variable to use the image feature only.
8397
8398Build History SDK Information
8399~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8400
8401Build history collects similar information on the contents of SDKs (e.g.
8402``bitbake -c populate_sdk imagename``) as compared to information it
8403collects for images. Furthermore, this information differs depending on
8404whether an extensible or standard SDK is being produced.
8405
8406The following list shows the files produced for SDKs:
8407
8408- ``files-in-sdk.txt:`` A list of files in the SDK with permissions,
8409 owner, group, size, and symlink information. This list includes both
8410 the host and target parts of the SDK.
8411
8412- ``sdk-info.txt:`` A text file containing name-value pairs with
8413 information about the SDK. See the following listing example for more
8414 information.
8415
8416- ``sstate-task-sizes.txt:`` A text file containing name-value pairs
8417 with information about task group sizes (e.g. ``do_populate_sysroot``
8418 tasks have a total size). The ``sstate-task-sizes.txt`` file exists
8419 only when an extensible SDK is created.
8420
8421- ``sstate-package-sizes.txt:`` A text file containing name-value pairs
8422 with information for the shared-state packages and sizes in the SDK.
8423 The ``sstate-package-sizes.txt`` file exists only when an extensible
8424 SDK is created.
8425
8426- ``sdk-files:`` A folder that contains copies of the files mentioned
8427 in ``BUILDHISTORY_SDK_FILES`` if the files are present in the output.
8428 Additionally, the default value of ``BUILDHISTORY_SDK_FILES`` is
8429 specific to the extensible SDK although you can set it differently if
8430 you would like to pull in specific files from the standard SDK.
8431
8432 The default files are ``conf/local.conf``, ``conf/bblayers.conf``,
8433 ``conf/auto.conf``, ``conf/locked-sigs.inc``, and
8434 ``conf/devtool.conf``. Thus, for an extensible SDK, these files get
8435 copied into the ``sdk-files`` directory.
8436
8437- The following information appears under each of the ``host`` and
8438 ``target`` directories for the portions of the SDK that run on the
8439 host and on the target, respectively:
8440
8441 .. note::
8442
8443 The following files for the most part are empty when producing an
8444 extensible SDK because this type of SDK is not constructed from
8445 packages as is the standard SDK.
8446
8447 - ``depends.dot:`` Dependency graph for the SDK that is compatible
8448 with ``graphviz``.
8449
8450 - ``installed-package-names.txt:`` A list of installed packages by
8451 name only.
8452
8453 - ``installed-package-sizes.txt:`` A list of installed packages
8454 ordered by size.
8455
8456 - ``installed-packages.txt:`` A list of installed packages with full
8457 package filenames.
8458
8459Here is an example of ``sdk-info.txt``:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008460
8461.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008462
8463 DISTRO = poky
8464 DISTRO_VERSION = 1.3+snapshot-20130327
8465 SDK_NAME = poky-glibc-i686-arm
8466 SDK_VERSION = 1.3+snapshot
8467 SDKMACHINE =
8468 SDKIMAGE_FEATURES = dev-pkgs dbg-pkgs
8469 BAD_RECOMMENDATIONS =
8470 SDKSIZE = 352712
8471
8472Other than ``SDKSIZE``, which is
8473the total size of the files in the SDK in Kbytes, the name-value pairs
8474are variables that might have influenced the content of the SDK. This
8475information is often useful when you are trying to determine why a
8476change in the package or file listings has occurred.
8477
8478Examining Build History Information
8479~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8480
8481You can examine build history output from the command line or from a web
8482interface.
8483
8484To see any changes that have occurred (assuming you have
8485:term:`BUILDHISTORY_COMMIT` = "1"),
8486you can simply use any Git command that allows you to view the history
Andrew Geisslerc926e172021-05-07 16:11:35 -05008487of a repository. Here is one method::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008488
8489 $ git log -p
8490
8491You need to realize,
8492however, that this method does show changes that are not significant
8493(e.g. a package's size changing by a few bytes).
8494
William A. Kennington IIIac69b482021-06-02 12:28:27 -07008495There is a command-line tool called ``buildhistory-diff``, though,
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008496that queries the Git repository and prints just the differences that
Andrew Geisslerc926e172021-05-07 16:11:35 -05008497might be significant in human-readable form. Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008498
Andrew Geissler95ac1b82021-03-31 14:34:31 -05008499 $ poky/poky/scripts/buildhistory-diff . HEAD^
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008500 Changes to images/qemux86_64/glibc/core-image-minimal (files-in-image.txt):
8501 /etc/anotherpkg.conf was added
8502 /sbin/anotherpkg was added
8503 * (installed-package-names.txt):
8504 * anotherpkg was added
8505 Changes to images/qemux86_64/glibc/core-image-minimal (installed-package-names.txt):
8506 anotherpkg was added
8507 packages/qemux86_64-poky-linux/v86d: PACKAGES: added "v86d-extras"
8508 * PR changed from "r0" to "r1"
8509 * PV changed from "0.1.10" to "0.1.12"
8510 packages/qemux86_64-poky-linux/v86d/v86d: PKGSIZE changed from 110579 to 144381 (+30%)
8511 * PR changed from "r0" to "r1"
8512 * PV changed from "0.1.10" to "0.1.12"
8513
8514.. note::
8515
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008516 The ``buildhistory-diff`` tool requires the ``GitPython``
Andrew Geisslerc926e172021-05-07 16:11:35 -05008517 package. Be sure to install it using Pip3 as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008518
8519 $ pip3 install GitPython --user
8520
8521
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008522 Alternatively, you can install ``python3-git`` using the appropriate
Andrew Geisslereff27472021-10-29 15:35:00 -05008523 distribution package manager (e.g. ``apt``, ``dnf``, or ``zipper``).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008524
8525To see changes to the build history using a web interface, follow the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008526instruction in the ``README`` file
Andrew Geissler09209ee2020-12-13 08:44:15 -06008527:yocto_git:`here </buildhistory-web/>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008528
8529Here is a sample screenshot of the interface:
8530
8531.. image:: figures/buildhistory-web.png
8532 :align: center
8533
8534Performing Automated Runtime Testing
8535====================================
8536
8537The OpenEmbedded build system makes available a series of automated
8538tests for images to verify runtime functionality. You can run these
8539tests on either QEMU or actual target hardware. Tests are written in
8540Python making use of the ``unittest`` module, and the majority of them
8541run commands on the target system over SSH. This section describes how
8542you set up the environment to use these tests, run available tests, and
8543write and add your own tests.
8544
8545For information on the test and QA infrastructure available within the
Andrew Geissler09209ee2020-12-13 08:44:15 -06008546Yocto Project, see the ":ref:`ref-manual/release-process:testing and quality assurance`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008547section in the Yocto Project Reference Manual.
8548
8549Enabling Tests
8550--------------
8551
8552Depending on whether you are planning to run tests using QEMU or on the
8553hardware, you have to take different steps to enable the tests. See the
8554following subsections for information on how to enable both types of
8555tests.
8556
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008557Enabling Runtime Tests on QEMU
8558~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8559
8560In order to run tests, you need to do the following:
8561
8562- *Set up to avoid interaction with sudo for networking:* To
8563 accomplish this, you must do one of the following:
8564
8565 - Add ``NOPASSWD`` for your user in ``/etc/sudoers`` either for all
8566 commands or just for ``runqemu-ifup``. You must provide the full
8567 path as that can change if you are using multiple clones of the
8568 source repository.
8569
8570 .. note::
8571
8572 On some distributions, you also need to comment out "Defaults
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008573 requiretty" in ``/etc/sudoers``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008574
8575 - Manually configure a tap interface for your system.
8576
8577 - Run as root the script in ``scripts/runqemu-gen-tapdevs``, which
8578 should generate a list of tap devices. This is the option
8579 typically chosen for Autobuilder-type environments.
8580
8581 .. note::
8582
8583 - Be sure to use an absolute path when calling this script
8584 with sudo.
8585
8586 - The package recipe ``qemu-helper-native`` is required to run
Andrew Geisslerc926e172021-05-07 16:11:35 -05008587 this script. Build the package using the following command::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008588
8589 $ bitbake qemu-helper-native
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008590
8591- *Set the DISPLAY variable:* You need to set this variable so that
8592 you have an X server available (e.g. start ``vncserver`` for a
8593 headless machine).
8594
8595- *Be sure your host's firewall accepts incoming connections from
8596 192.168.7.0/24:* Some of the tests (in particular DNF tests) start an
8597 HTTP server on a random high number port, which is used to serve
8598 files to the target. The DNF module serves
8599 ``${WORKDIR}/oe-rootfs-repo`` so it can run DNF channel commands.
8600 That means your host's firewall must accept incoming connections from
8601 192.168.7.0/24, which is the default IP range used for tap devices by
8602 ``runqemu``.
8603
8604- *Be sure your host has the correct packages installed:* Depending
8605 your host's distribution, you need to have the following packages
8606 installed:
8607
8608 - Ubuntu and Debian: ``sysstat`` and ``iproute2``
8609
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05008610 - openSUSE: ``sysstat`` and ``iproute2``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008611
8612 - Fedora: ``sysstat`` and ``iproute``
8613
8614 - CentOS: ``sysstat`` and ``iproute``
8615
8616Once you start running the tests, the following happens:
8617
86181. A copy of the root filesystem is written to ``${WORKDIR}/testimage``.
8619
86202. The image is booted under QEMU using the standard ``runqemu`` script.
8621
86223. A default timeout of 500 seconds occurs to allow for the boot process
8623 to reach the login prompt. You can change the timeout period by
8624 setting
8625 :term:`TEST_QEMUBOOT_TIMEOUT`
8626 in the ``local.conf`` file.
8627
86284. Once the boot process is reached and the login prompt appears, the
8629 tests run. The full boot log is written to
8630 ``${WORKDIR}/testimage/qemu_boot_log``.
8631
Andrew Geissler09036742021-06-25 14:25:14 -050086325. Each test module loads in the order found in :term:`TEST_SUITES`. You can
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008633 find the full output of the commands run over SSH in
8634 ``${WORKDIR}/testimgage/ssh_target_log``.
8635
86366. If no failures occur, the task running the tests ends successfully.
8637 You can find the output from the ``unittest`` in the task log at
8638 ``${WORKDIR}/temp/log.do_testimage``.
8639
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008640Enabling Runtime Tests on Hardware
8641~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8642
8643The OpenEmbedded build system can run tests on real hardware, and for
8644certain devices it can also deploy the image to be tested onto the
8645device beforehand.
8646
Andrew Geissler595f6302022-01-24 19:11:47 +00008647For automated deployment, a "controller image" is installed onto the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008648hardware once as part of setup. Then, each time tests are to be run, the
8649following occurs:
8650
Andrew Geissler595f6302022-01-24 19:11:47 +000086511. The controller image is booted into and used to write the image to be
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008652 tested to a second partition.
8653
86542. The device is then rebooted using an external script that you need to
8655 provide.
8656
86573. The device boots into the image to be tested.
8658
8659When running tests (independent of whether the image has been deployed
8660automatically or not), the device is expected to be connected to a
8661network on a pre-determined IP address. You can either use static IP
8662addresses written into the image, or set the image to use DHCP and have
8663your DHCP server on the test network assign a known IP address based on
8664the MAC address of the device.
8665
Andrew Geissler09036742021-06-25 14:25:14 -05008666In order to run tests on hardware, you need to set :term:`TEST_TARGET` to an
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008667appropriate value. For QEMU, you do not have to change anything, the
8668default value is "qemu". For running tests on hardware, the following
William A. Kennington IIIac69b482021-06-02 12:28:27 -07008669options are available:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008670
8671- *"simpleremote":* Choose "simpleremote" if you are going to run tests
8672 on a target system that is already running the image to be tested and
8673 is available on the network. You can use "simpleremote" in
8674 conjunction with either real hardware or an image running within a
8675 separately started QEMU or any other virtual machine manager.
8676
8677- *"SystemdbootTarget":* Choose "SystemdbootTarget" if your hardware is
8678 an EFI-based machine with ``systemd-boot`` as bootloader and
8679 ``core-image-testmaster`` (or something similar) is installed. Also,
8680 your hardware under test must be in a DHCP-enabled network that gives
8681 it the same IP address for each reboot.
8682
8683 If you choose "SystemdbootTarget", there are additional requirements
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05008684 and considerations. See the
8685 ":ref:`dev-manual/common-tasks:selecting systemdboottarget`" section, which
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008686 follows, for more information.
8687
8688- *"BeagleBoneTarget":* Choose "BeagleBoneTarget" if you are deploying
8689 images and running tests on the BeagleBone "Black" or original
8690 "White" hardware. For information on how to use these tests, see the
8691 comments at the top of the BeagleBoneTarget
8692 ``meta-yocto-bsp/lib/oeqa/controllers/beaglebonetarget.py`` file.
8693
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008694- *"EdgeRouterTarget":* Choose "EdgeRouterTarget" if you are deploying
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008695 images and running tests on the Ubiquiti Networks EdgeRouter Lite.
8696 For information on how to use these tests, see the comments at the
8697 top of the EdgeRouterTarget
8698 ``meta-yocto-bsp/lib/oeqa/controllers/edgeroutertarget.py`` file.
8699
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008700- *"GrubTarget":* Choose "GrubTarget" if you are deploying images and running
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008701 tests on any generic PC that boots using GRUB. For information on how
8702 to use these tests, see the comments at the top of the GrubTarget
8703 ``meta-yocto-bsp/lib/oeqa/controllers/grubtarget.py`` file.
8704
8705- *"your-target":* Create your own custom target if you want to run
8706 tests when you are deploying images and running tests on a custom
8707 machine within your BSP layer. To do this, you need to add a Python
8708 unit that defines the target class under ``lib/oeqa/controllers/``
8709 within your layer. You must also provide an empty ``__init__.py``.
8710 For examples, see files in ``meta-yocto-bsp/lib/oeqa/controllers/``.
8711
8712Selecting SystemdbootTarget
8713~~~~~~~~~~~~~~~~~~~~~~~~~~~
8714
Andrew Geissler09036742021-06-25 14:25:14 -05008715If you did not set :term:`TEST_TARGET` to "SystemdbootTarget", then you do
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008716not need any information in this section. You can skip down to the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05008717":ref:`dev-manual/common-tasks:running tests`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008718
Andrew Geissler09036742021-06-25 14:25:14 -05008719If you did set :term:`TEST_TARGET` to "SystemdbootTarget", you also need to
Andrew Geissler595f6302022-01-24 19:11:47 +00008720perform a one-time setup of your controller image by doing the following:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008721
Andrew Geissler09036742021-06-25 14:25:14 -050087221. *Set EFI_PROVIDER:* Be sure that :term:`EFI_PROVIDER` is as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008723
8724 EFI_PROVIDER = "systemd-boot"
8725
Andrew Geissler595f6302022-01-24 19:11:47 +000087262. *Build the controller image:* Build the ``core-image-testmaster`` image.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008727 The ``core-image-testmaster`` recipe is provided as an example for a
Andrew Geissler595f6302022-01-24 19:11:47 +00008728 "controller" image and you can customize the image recipe as you would
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008729 any other recipe.
8730
8731 Here are the image recipe requirements:
8732
8733 - Inherits ``core-image`` so that kernel modules are installed.
8734
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05008735 - Installs normal linux utilities not BusyBox ones (e.g. ``bash``,
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008736 ``coreutils``, ``tar``, ``gzip``, and ``kmod``).
8737
8738 - Uses a custom Initial RAM Disk (initramfs) image with a custom
8739 installer. A normal image that you can install usually creates a
Andrew Geissler595f6302022-01-24 19:11:47 +00008740 single root filesystem partition. This image uses another installer that
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008741 creates a specific partition layout. Not all Board Support
8742 Packages (BSPs) can use an installer. For such cases, you need to
8743 manually create the following partition layout on the target:
8744
8745 - First partition mounted under ``/boot``, labeled "boot".
8746
Andrew Geissler595f6302022-01-24 19:11:47 +00008747 - The main root filesystem partition where this image gets installed,
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008748 which is mounted under ``/``.
8749
8750 - Another partition labeled "testrootfs" where test images get
8751 deployed.
8752
87533. *Install image:* Install the image that you just built on the target
8754 system.
8755
Andrew Geissler09036742021-06-25 14:25:14 -05008756The final thing you need to do when setting :term:`TEST_TARGET` to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008757"SystemdbootTarget" is to set up the test image:
8758
87591. *Set up your local.conf file:* Make sure you have the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05008760 statements in your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008761
8762 IMAGE_FSTYPES += "tar.gz"
8763 INHERIT += "testimage"
8764 TEST_TARGET = "SystemdbootTarget"
8765 TEST_TARGET_IP = "192.168.2.3"
8766
Andrew Geisslerc926e172021-05-07 16:11:35 -050087672. *Build your test image:* Use BitBake to build the image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008768
8769 $ bitbake core-image-sato
8770
8771Power Control
8772~~~~~~~~~~~~~
8773
8774For most hardware targets other than "simpleremote", you can control
8775power:
8776
Andrew Geissler09036742021-06-25 14:25:14 -05008777- You can use :term:`TEST_POWERCONTROL_CMD` together with
8778 :term:`TEST_POWERCONTROL_EXTRA_ARGS` as a command that runs on the host
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008779 and does power cycling. The test code passes one argument to that
8780 command: off, on or cycle (off then on). Here is an example that
Andrew Geisslerc926e172021-05-07 16:11:35 -05008781 could appear in your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008782
8783 TEST_POWERCONTROL_CMD = "powercontrol.exp test 10.11.12.1 nuc1"
8784
8785 In this example, the expect
8786 script does the following:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008787
8788 .. code-block:: shell
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008789
8790 ssh test@10.11.12.1 "pyctl nuc1 arg"
8791
8792 It then runs a Python script that controls power for a label called
8793 ``nuc1``.
8794
8795 .. note::
8796
Andrew Geissler09036742021-06-25 14:25:14 -05008797 You need to customize :term:`TEST_POWERCONTROL_CMD` and
8798 :term:`TEST_POWERCONTROL_EXTRA_ARGS` for your own setup. The one requirement
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008799 is that it accepts "on", "off", and "cycle" as the last argument.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008800
8801- When no command is defined, it connects to the device over SSH and
8802 uses the classic reboot command to reboot the device. Classic reboot
8803 is fine as long as the machine actually reboots (i.e. the SSH test
8804 has not failed). It is useful for scenarios where you have a simple
8805 setup, typically with a single board, and where some manual
8806 interaction is okay from time to time.
8807
8808If you have no hardware to automatically perform power control but still
8809wish to experiment with automated hardware testing, you can use the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008810``dialog-power-control`` script that shows a dialog prompting you to perform
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008811the required power action. This script requires either KDialog or Zenity
8812to be installed. To use this script, set the
8813:term:`TEST_POWERCONTROL_CMD`
Andrew Geisslerc926e172021-05-07 16:11:35 -05008814variable as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008815
8816 TEST_POWERCONTROL_CMD = "${COREBASE}/scripts/contrib/dialog-power-control"
8817
8818Serial Console Connection
8819~~~~~~~~~~~~~~~~~~~~~~~~~
8820
8821For test target classes requiring a serial console to interact with the
8822bootloader (e.g. BeagleBoneTarget, EdgeRouterTarget, and GrubTarget),
8823you need to specify a command to use to connect to the serial console of
8824the target machine by using the
8825:term:`TEST_SERIALCONTROL_CMD`
8826variable and optionally the
8827:term:`TEST_SERIALCONTROL_EXTRA_ARGS`
8828variable.
8829
8830These cases could be a serial terminal program if the machine is
8831connected to a local serial port, or a ``telnet`` or ``ssh`` command
8832connecting to a remote console server. Regardless of the case, the
8833command simply needs to connect to the serial console and forward that
8834connection to standard input and output as any normal terminal program
8835does. For example, to use the picocom terminal program on serial device
Andrew Geisslerc926e172021-05-07 16:11:35 -05008836``/dev/ttyUSB0`` at 115200bps, you would set the variable as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008837
8838 TEST_SERIALCONTROL_CMD = "picocom /dev/ttyUSB0 -b 115200"
8839
8840For local
8841devices where the serial port device disappears when the device reboots,
8842an additional "serdevtry" wrapper script is provided. To use this
8843wrapper, simply prefix the terminal command with
Andrew Geisslerc926e172021-05-07 16:11:35 -05008844``${COREBASE}/scripts/contrib/serdevtry``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008845
8846 TEST_SERIALCONTROL_CMD = "${COREBASE}/scripts/contrib/serdevtry picocom -b 115200 /dev/ttyUSB0"
8847
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008848Running Tests
8849-------------
8850
8851You can start the tests automatically or manually:
8852
8853- *Automatically running tests:* To run the tests automatically after
8854 the OpenEmbedded build system successfully creates an image, first
8855 set the
8856 :term:`TESTIMAGE_AUTO`
8857 variable to "1" in your ``local.conf`` file in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05008858 :term:`Build Directory`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008859
8860 TESTIMAGE_AUTO = "1"
8861
8862 Next, build your image. If the image successfully builds, the
Andrew Geisslerc926e172021-05-07 16:11:35 -05008863 tests run::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008864
8865 bitbake core-image-sato
8866
8867- *Manually running tests:* To manually run the tests, first globally
8868 inherit the
8869 :ref:`testimage <ref-classes-testimage*>` class
Andrew Geisslerc926e172021-05-07 16:11:35 -05008870 by editing your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008871
8872 INHERIT += "testimage"
8873
Andrew Geisslerc926e172021-05-07 16:11:35 -05008874 Next, use BitBake to run the tests::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008875
8876 bitbake -c testimage image
8877
8878All test files reside in ``meta/lib/oeqa/runtime`` in the
8879:term:`Source Directory`. A test name maps
8880directly to a Python module. Each test module may contain a number of
8881individual tests. Tests are usually grouped together by the area tested
8882(e.g tests for systemd reside in ``meta/lib/oeqa/runtime/systemd.py``).
8883
8884You can add tests to any layer provided you place them in the proper
8885area and you extend :term:`BBPATH` in
8886the ``local.conf`` file as normal. Be sure that tests reside in
8887``layer/lib/oeqa/runtime``.
8888
8889.. note::
8890
8891 Be sure that module names do not collide with module names used in
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008892 the default set of test modules in ``meta/lib/oeqa/runtime``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008893
8894You can change the set of tests run by appending or overriding
8895:term:`TEST_SUITES` variable in
Andrew Geissler09036742021-06-25 14:25:14 -05008896``local.conf``. Each name in :term:`TEST_SUITES` represents a required test
8897for the image. Test modules named within :term:`TEST_SUITES` cannot be
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008898skipped even if a test is not suitable for an image (e.g. running the
8899RPM tests on an image without ``rpm``). Appending "auto" to
Andrew Geissler09036742021-06-25 14:25:14 -05008900:term:`TEST_SUITES` causes the build system to try to run all tests that are
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008901suitable for the image (i.e. each test module may elect to skip itself).
8902
Andrew Geissler09036742021-06-25 14:25:14 -05008903The order you list tests in :term:`TEST_SUITES` is important and influences
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008904test dependencies. Consequently, tests that depend on other tests should
8905be added after the test on which they depend. For example, since the
8906``ssh`` test depends on the ``ping`` test, "ssh" needs to come after
8907"ping" in the list. The test class provides no re-ordering or dependency
8908handling.
8909
8910.. note::
8911
8912 Each module can have multiple classes with multiple test methods.
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008913 And, Python ``unittest`` rules apply.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008914
8915Here are some things to keep in mind when running tests:
8916
Andrew Geisslerc926e172021-05-07 16:11:35 -05008917- The default tests for the image are defined as::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008918
Patrick Williams0ca19cc2021-08-16 14:03:13 -05008919 DEFAULT_TEST_SUITES:pn-image = "ping ssh df connman syslog xorg scp vnc date rpm dnf dmesg"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008920
Andrew Geisslerc926e172021-05-07 16:11:35 -05008921- Add your own test to the list of the by using the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008922
Patrick Williams0ca19cc2021-08-16 14:03:13 -05008923 TEST_SUITES:append = " mytest"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008924
Andrew Geisslerc926e172021-05-07 16:11:35 -05008925- Run a specific list of tests as follows::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008926
8927 TEST_SUITES = "test1 test2 test3"
8928
8929 Remember, order is important. Be sure to place a test that is
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008930 dependent on another test later in the order.
8931
8932Exporting Tests
8933---------------
8934
8935You can export tests so that they can run independently of the build
8936system. Exporting tests is required if you want to be able to hand the
8937test execution off to a scheduler. You can only export tests that are
8938defined in :term:`TEST_SUITES`.
8939
8940If your image is already built, make sure the following are set in your
Andrew Geisslerc926e172021-05-07 16:11:35 -05008941``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008942
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008943 INHERIT += "testexport"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008944 TEST_TARGET_IP = "IP-address-for-the-test-target"
8945 TEST_SERVER_IP = "IP-address-for-the-test-server"
8946
8947You can then export the tests with the
Andrew Geisslerc926e172021-05-07 16:11:35 -05008948following BitBake command form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008949
8950 $ bitbake image -c testexport
8951
8952Exporting the tests places them in the
8953:term:`Build Directory` in
8954``tmp/testexport/``\ image, which is controlled by the
Andrew Geissler09036742021-06-25 14:25:14 -05008955:term:`TEST_EXPORT_DIR` variable.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008956
Andrew Geisslerc926e172021-05-07 16:11:35 -05008957You can now run the tests outside of the build environment::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008958
8959 $ cd tmp/testexport/image
8960 $ ./runexported.py testdata.json
8961
8962Here is a complete example that shows IP addresses and uses the
Andrew Geisslerc926e172021-05-07 16:11:35 -05008963``core-image-sato`` image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008964
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008965 INHERIT += "testexport"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008966 TEST_TARGET_IP = "192.168.7.2"
8967 TEST_SERVER_IP = "192.168.7.1"
8968
Andrew Geisslerc926e172021-05-07 16:11:35 -05008969Use BitBake to export the tests::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008970
8971 $ bitbake core-image-sato -c testexport
8972
8973Run the tests outside of
Andrew Geisslerc926e172021-05-07 16:11:35 -05008974the build environment using the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008975
8976 $ cd tmp/testexport/core-image-sato
8977 $ ./runexported.py testdata.json
8978
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008979Writing New Tests
8980-----------------
8981
8982As mentioned previously, all new test files need to be in the proper
8983place for the build system to find them. New tests for additional
8984functionality outside of the core should be added to the layer that adds
8985the functionality, in ``layer/lib/oeqa/runtime`` (as long as
8986:term:`BBPATH` is extended in the
8987layer's ``layer.conf`` file as normal). Just remember the following:
8988
8989- Filenames need to map directly to test (module) names.
8990
8991- Do not use module names that collide with existing core tests.
8992
William A. Kennington IIIac69b482021-06-02 12:28:27 -07008993- Minimally, an empty ``__init__.py`` file must be present in the runtime
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008994 directory.
8995
8996To create a new test, start by copying an existing module (e.g.
8997``syslog.py`` or ``gcc.py`` are good ones to use). Test modules can use
8998code from ``meta/lib/oeqa/utils``, which are helper classes.
8999
9000.. note::
9001
9002 Structure shell commands such that you rely on them and they return a
9003 single code for success. Be aware that sometimes you will need to
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009004 parse the output. See the ``df.py`` and ``date.py`` modules for examples.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009005
9006You will notice that all test classes inherit ``oeRuntimeTest``, which
9007is found in ``meta/lib/oetest.py``. This base class offers some helper
9008attributes, which are described in the following sections:
9009
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009010Class Methods
9011~~~~~~~~~~~~~
9012
9013Class methods are as follows:
9014
9015- *hasPackage(pkg):* Returns "True" if ``pkg`` is in the installed
9016 package list of the image, which is based on the manifest file that
9017 is generated during the ``do_rootfs`` task.
9018
9019- *hasFeature(feature):* Returns "True" if the feature is in
9020 :term:`IMAGE_FEATURES` or
9021 :term:`DISTRO_FEATURES`.
9022
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009023Class Attributes
9024~~~~~~~~~~~~~~~~
9025
9026Class attributes are as follows:
9027
9028- *pscmd:* Equals "ps -ef" if ``procps`` is installed in the image.
9029 Otherwise, ``pscmd`` equals "ps" (busybox).
9030
9031- *tc:* The called test context, which gives access to the
9032 following attributes:
9033
9034 - *d:* The BitBake datastore, which allows you to use stuff such
9035 as ``oeRuntimeTest.tc.d.getVar("VIRTUAL-RUNTIME_init_manager")``.
9036
9037 - *testslist and testsrequired:* Used internally. The tests
9038 do not need these.
9039
9040 - *filesdir:* The absolute path to
9041 ``meta/lib/oeqa/runtime/files``, which contains helper files for
9042 tests meant for copying on the target such as small files written
9043 in C for compilation.
9044
9045 - *target:* The target controller object used to deploy and
9046 start an image on a particular target (e.g. Qemu, SimpleRemote,
9047 and SystemdbootTarget). Tests usually use the following:
9048
9049 - *ip:* The target's IP address.
9050
9051 - *server_ip:* The host's IP address, which is usually used
9052 by the DNF test suite.
9053
9054 - *run(cmd, timeout=None):* The single, most used method.
9055 This command is a wrapper for: ``ssh root@host "cmd"``. The
9056 command returns a tuple: (status, output), which are what their
9057 names imply - the return code of "cmd" and whatever output it
9058 produces. The optional timeout argument represents the number
9059 of seconds the test should wait for "cmd" to return. If the
9060 argument is "None", the test uses the default instance's
9061 timeout period, which is 300 seconds. If the argument is "0",
9062 the test runs until the command returns.
9063
9064 - *copy_to(localpath, remotepath):*
9065 ``scp localpath root@ip:remotepath``.
9066
9067 - *copy_from(remotepath, localpath):*
9068 ``scp root@host:remotepath localpath``.
9069
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009070Instance Attributes
9071~~~~~~~~~~~~~~~~~~~
9072
William A. Kennington IIIac69b482021-06-02 12:28:27 -07009073There is a single instance attribute, which is ``target``. The ``target``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009074instance attribute is identical to the class attribute of the same name,
9075which is described in the previous section. This attribute exists as
9076both an instance and class attribute so tests can use
9077``self.target.run(cmd)`` in instance methods instead of
9078``oeRuntimeTest.tc.target.run(cmd)``.
9079
9080Installing Packages in the DUT Without the Package Manager
9081----------------------------------------------------------
9082
9083When a test requires a package built by BitBake, it is possible to
9084install that package. Installing the package does not require a package
9085manager be installed in the device under test (DUT). It does, however,
9086require an SSH connection and the target must be using the
9087``sshcontrol`` class.
9088
9089.. note::
9090
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009091 This method uses ``scp`` to copy files from the host to the target, which
9092 causes permissions and special attributes to be lost.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009093
9094A JSON file is used to define the packages needed by a test. This file
9095must be in the same path as the file used to define the tests.
9096Furthermore, the filename must map directly to the test module name with
9097a ``.json`` extension.
9098
9099The JSON file must include an object with the test name as keys of an
9100object or an array. This object (or array of objects) uses the following
9101data:
9102
9103- "pkg" - A mandatory string that is the name of the package to be
9104 installed.
9105
9106- "rm" - An optional boolean, which defaults to "false", that specifies
9107 to remove the package after the test.
9108
9109- "extract" - An optional boolean, which defaults to "false", that
9110 specifies if the package must be extracted from the package format.
9111 When set to "true", the package is not automatically installed into
9112 the DUT.
9113
9114Following is an example JSON file that handles test "foo" installing
9115package "bar" and test "foobar" installing packages "foo" and "bar".
9116Once the test is complete, the packages are removed from the DUT.
9117::
9118
9119 {
9120 "foo": {
9121 "pkg": "bar"
9122 },
9123 "foobar": [
9124 {
9125 "pkg": "foo",
9126 "rm": true
9127 },
9128 {
9129 "pkg": "bar",
9130 "rm": true
9131 }
9132 ]
9133 }
9134
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009135Debugging Tools and Techniques
9136==============================
9137
9138The exact method for debugging build failures depends on the nature of
9139the problem and on the system's area from which the bug originates.
9140Standard debugging practices such as comparison against the last known
9141working version with examination of the changes and the re-application
9142of steps to identify the one causing the problem are valid for the Yocto
9143Project just as they are for any other system. Even though it is
9144impossible to detail every possible potential failure, this section
9145provides some general tips to aid in debugging given a variety of
9146situations.
9147
9148.. note::
9149
9150 A useful feature for debugging is the error reporting tool.
9151 Configuring the Yocto Project to use this tool causes the
9152 OpenEmbedded build system to produce error reporting commands as part
9153 of the console output. You can enter the commands after the build
9154 completes to log error information into a common database, that can
9155 help you figure out what might be going wrong. For information on how
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009156 to enable and use this feature, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06009157 ":ref:`dev-manual/common-tasks:using the error reporting tool`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009158 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009159
9160The following list shows the debugging topics in the remainder of this
9161section:
9162
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009163- ":ref:`dev-manual/common-tasks:viewing logs from failed tasks`" describes
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009164 how to find and view logs from tasks that failed during the build
9165 process.
9166
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009167- ":ref:`dev-manual/common-tasks:viewing variable values`" describes how to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009168 use the BitBake ``-e`` option to examine variable values after a
9169 recipe has been parsed.
9170
Andrew Geissler09209ee2020-12-13 08:44:15 -06009171- ":ref:`dev-manual/common-tasks:viewing package information with \`\`oe-pkgdata-util\`\``"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009172 describes how to use the ``oe-pkgdata-util`` utility to query
9173 :term:`PKGDATA_DIR` and
9174 display package-related information for built packages.
9175
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009176- ":ref:`dev-manual/common-tasks:viewing dependencies between recipes and tasks`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009177 describes how to use the BitBake ``-g`` option to display recipe
9178 dependency information used during the build.
9179
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009180- ":ref:`dev-manual/common-tasks:viewing task variable dependencies`" describes
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009181 how to use the ``bitbake-dumpsig`` command in conjunction with key
9182 subdirectories in the
9183 :term:`Build Directory` to determine
9184 variable dependencies.
9185
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009186- ":ref:`dev-manual/common-tasks:running specific tasks`" describes
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009187 how to use several BitBake options (e.g. ``-c``, ``-C``, and ``-f``)
9188 to run specific tasks in the build chain. It can be useful to run
9189 tasks "out-of-order" when trying isolate build issues.
9190
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009191- ":ref:`dev-manual/common-tasks:general bitbake problems`" describes how
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009192 to use BitBake's ``-D`` debug output option to reveal more about what
9193 BitBake is doing during the build.
9194
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009195- ":ref:`dev-manual/common-tasks:building with no dependencies`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009196 describes how to use the BitBake ``-b`` option to build a recipe
9197 while ignoring dependencies.
9198
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009199- ":ref:`dev-manual/common-tasks:recipe logging mechanisms`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009200 describes how to use the many recipe logging functions to produce
9201 debugging output and report errors and warnings.
9202
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009203- ":ref:`dev-manual/common-tasks:debugging parallel make races`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009204 describes how to debug situations where the build consists of several
9205 parts that are run simultaneously and when the output or result of
9206 one part is not ready for use with a different part of the build that
9207 depends on that output.
9208
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009209- ":ref:`dev-manual/common-tasks:debugging with the gnu project debugger (gdb) remotely`"
9210 describes how to use GDB to allow you to examine running programs, which can
9211 help you fix problems.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009212
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009213- ":ref:`dev-manual/common-tasks:debugging with the gnu project debugger (gdb) on the target`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009214 describes how to use GDB directly on target hardware for debugging.
9215
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009216- ":ref:`dev-manual/common-tasks:other debugging tips`" describes
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009217 miscellaneous debugging tips that can be useful.
9218
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009219Viewing Logs from Failed Tasks
9220------------------------------
9221
9222You can find the log for a task in the file
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009223``${``\ :term:`WORKDIR`\ ``}/temp/log.do_``\ `taskname`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009224For example, the log for the
9225:ref:`ref-tasks-compile` task of the
9226QEMU minimal image for the x86 machine (``qemux86``) might be in
9227``tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/temp/log.do_compile``.
9228To see the commands :term:`BitBake` ran
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009229to generate a log, look at the corresponding ``run.do_``\ `taskname` file
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009230in the same directory.
9231
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009232``log.do_``\ `taskname` and ``run.do_``\ `taskname` are actually symbolic
9233links to ``log.do_``\ `taskname`\ ``.``\ `pid` and
9234``log.run_``\ `taskname`\ ``.``\ `pid`, where `pid` is the PID the task had
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009235when it ran. The symlinks always point to the files corresponding to the
9236most recent run.
9237
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009238Viewing Variable Values
9239-----------------------
9240
9241Sometimes you need to know the value of a variable as a result of
9242BitBake's parsing step. This could be because some unexpected behavior
9243occurred in your project. Perhaps an attempt to :ref:`modify a variable
9244<bitbake:bitbake-user-manual/bitbake-user-manual-metadata:modifying existing
9245variables>` did not work out as expected.
9246
9247BitBake's ``-e`` option is used to display variable values after
9248parsing. The following command displays the variable values after the
9249configuration files (i.e. ``local.conf``, ``bblayers.conf``,
Andrew Geisslerc926e172021-05-07 16:11:35 -05009250``bitbake.conf`` and so forth) have been parsed::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009251
9252 $ bitbake -e
9253
9254The following command displays variable values after a specific recipe has
Andrew Geisslerc926e172021-05-07 16:11:35 -05009255been parsed. The variables include those from the configuration as well::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009256
9257 $ bitbake -e recipename
9258
9259.. note::
9260
9261 Each recipe has its own private set of variables (datastore).
9262 Internally, after parsing the configuration, a copy of the resulting
9263 datastore is made prior to parsing each recipe. This copying implies
9264 that variables set in one recipe will not be visible to other
9265 recipes.
9266
9267 Likewise, each task within a recipe gets a private datastore based on
9268 the recipe datastore, which means that variables set within one task
9269 will not be visible to other tasks.
9270
9271In the output of ``bitbake -e``, each variable is preceded by a
9272description of how the variable got its value, including temporary
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009273values that were later overridden. This description also includes
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009274variable flags (varflags) set on the variable. The output can be very
9275helpful during debugging.
9276
9277Variables that are exported to the environment are preceded by
Andrew Geisslerc926e172021-05-07 16:11:35 -05009278``export`` in the output of ``bitbake -e``. See the following example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009279
9280 export CC="i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/ulf/poky/build/tmp/sysroots/qemux86"
9281
9282In addition to variable values, the output of the ``bitbake -e`` and
9283``bitbake -e`` recipe commands includes the following information:
9284
9285- The output starts with a tree listing all configuration files and
9286 classes included globally, recursively listing the files they include
9287 or inherit in turn. Much of the behavior of the OpenEmbedded build
Andrew Geissler09209ee2020-12-13 08:44:15 -06009288 system (including the behavior of the :ref:`ref-manual/tasks:normal recipe build tasks`) is
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009289 implemented in the
9290 :ref:`base <ref-classes-base>` class and the
9291 classes it inherits, rather than being built into BitBake itself.
9292
9293- After the variable values, all functions appear in the output. For
9294 shell functions, variables referenced within the function body are
9295 expanded. If a function has been modified using overrides or using
Patrick Williams0ca19cc2021-08-16 14:03:13 -05009296 override-style operators like ``:append`` and ``:prepend``, then the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009297 final assembled function body appears in the output.
9298
9299Viewing Package Information with ``oe-pkgdata-util``
9300----------------------------------------------------
9301
9302You can use the ``oe-pkgdata-util`` command-line utility to query
9303:term:`PKGDATA_DIR` and display
9304various package-related information. When you use the utility, you must
9305use it to view information on packages that have already been built.
9306
9307Following are a few of the available ``oe-pkgdata-util`` subcommands.
9308
9309.. note::
9310
9311 You can use the standard \* and ? globbing wildcards as part of
9312 package names and paths.
9313
9314- ``oe-pkgdata-util list-pkgs [pattern]``: Lists all packages
9315 that have been built, optionally limiting the match to packages that
9316 match pattern.
9317
9318- ``oe-pkgdata-util list-pkg-files package ...``: Lists the
9319 files and directories contained in the given packages.
9320
9321 .. note::
9322
9323 A different way to view the contents of a package is to look at
9324 the
9325 ``${``\ :term:`WORKDIR`\ ``}/packages-split``
9326 directory of the recipe that generates the package. This directory
9327 is created by the
9328 :ref:`ref-tasks-package` task
9329 and has one subdirectory for each package the recipe generates,
9330 which contains the files stored in that package.
9331
9332 If you want to inspect the ``${WORKDIR}/packages-split``
9333 directory, make sure that
9334 :ref:`rm_work <ref-classes-rm-work>` is not
9335 enabled when you build the recipe.
9336
9337- ``oe-pkgdata-util find-path path ...``: Lists the names of
9338 the packages that contain the given paths. For example, the following
9339 tells us that ``/usr/share/man/man1/make.1`` is contained in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05009340 ``make-doc`` package::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009341
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009342 $ oe-pkgdata-util find-path /usr/share/man/man1/make.1
9343 make-doc: /usr/share/man/man1/make.1
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009344
9345- ``oe-pkgdata-util lookup-recipe package ...``: Lists the name
9346 of the recipes that produce the given packages.
9347
9348For more information on the ``oe-pkgdata-util`` command, use the help
Andrew Geisslerc926e172021-05-07 16:11:35 -05009349facility::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009350
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009351 $ oe-pkgdata-util --help
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009352 $ oe-pkgdata-util subcommand --help
9353
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009354Viewing Dependencies Between Recipes and Tasks
9355----------------------------------------------
9356
9357Sometimes it can be hard to see why BitBake wants to build other recipes
9358before the one you have specified. Dependency information can help you
9359understand why a recipe is built.
9360
9361To generate dependency information for a recipe, run the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05009362command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009363
9364 $ bitbake -g recipename
9365
9366This command writes the following files in the current directory:
9367
9368- ``pn-buildlist``: A list of recipes/targets involved in building
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009369 `recipename`. "Involved" here means that at least one task from the
9370 recipe needs to run when building `recipename` from scratch. Targets
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009371 that are in
9372 :term:`ASSUME_PROVIDED`
9373 are not listed.
9374
9375- ``task-depends.dot``: A graph showing dependencies between tasks.
9376
9377The graphs are in
9378`DOT <https://en.wikipedia.org/wiki/DOT_%28graph_description_language%29>`__
9379format and can be converted to images (e.g. using the ``dot`` tool from
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009380`Graphviz <https://www.graphviz.org/>`__).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009381
9382.. note::
9383
9384 - DOT files use a plain text format. The graphs generated using the
9385 ``bitbake -g`` command are often so large as to be difficult to
9386 read without special pruning (e.g. with Bitbake's ``-I`` option)
9387 and processing. Despite the form and size of the graphs, the
9388 corresponding ``.dot`` files can still be possible to read and
9389 provide useful information.
9390
9391 As an example, the ``task-depends.dot`` file contains lines such
Andrew Geisslerc926e172021-05-07 16:11:35 -05009392 as the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009393
9394 "libxslt.do_configure" -> "libxml2.do_populate_sysroot"
9395
9396 The above example line reveals that the
9397 :ref:`ref-tasks-configure`
9398 task in ``libxslt`` depends on the
9399 :ref:`ref-tasks-populate_sysroot`
9400 task in ``libxml2``, which is a normal
9401 :term:`DEPENDS` dependency
9402 between the two recipes.
9403
9404 - For an example of how ``.dot`` files can be processed, see the
9405 ``scripts/contrib/graph-tool`` Python script, which finds and
9406 displays paths between graph nodes.
9407
9408You can use a different method to view dependency information by using
Andrew Geisslerc926e172021-05-07 16:11:35 -05009409the following command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009410
9411 $ bitbake -g -u taskexp recipename
9412
9413This command
9414displays a GUI window from which you can view build-time and runtime
9415dependencies for the recipes involved in building recipename.
9416
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009417Viewing Task Variable Dependencies
9418----------------------------------
9419
9420As mentioned in the
9421":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-execution:checksums (signatures)`" section of the BitBake
9422User Manual, BitBake tries to automatically determine what variables a
9423task depends on so that it can rerun the task if any values of the
9424variables change. This determination is usually reliable. However, if
9425you do things like construct variable names at runtime, then you might
9426have to manually declare dependencies on those variables using
9427``vardeps`` as described in the
9428":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags`" section of the BitBake
9429User Manual.
9430
9431If you are unsure whether a variable dependency is being picked up
9432automatically for a given task, you can list the variable dependencies
9433BitBake has determined by doing the following:
9434
Andrew Geisslerc926e172021-05-07 16:11:35 -050094351. Build the recipe containing the task::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009436
9437 $ bitbake recipename
9438
94392. Inside the :term:`STAMPS_DIR`
9440 directory, find the signature data (``sigdata``) file that
9441 corresponds to the task. The ``sigdata`` files contain a pickled
9442 Python database of all the metadata that went into creating the input
9443 checksum for the task. As an example, for the
9444 :ref:`ref-tasks-fetch` task of the
9445 ``db`` recipe, the ``sigdata`` file might be found in the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05009446 location::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009447
9448 ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
9449
9450 For tasks that are accelerated through the shared state
Andrew Geissler09209ee2020-12-13 08:44:15 -06009451 (:ref:`sstate <overview-manual/concepts:shared state cache>`) cache, an
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009452 additional ``siginfo`` file is written into
9453 :term:`SSTATE_DIR` along with
9454 the cached task output. The ``siginfo`` files contain exactly the
9455 same information as ``sigdata`` files.
9456
94573. Run ``bitbake-dumpsig`` on the ``sigdata`` or ``siginfo`` file. Here
Andrew Geisslerc926e172021-05-07 16:11:35 -05009458 is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009459
9460 $ bitbake-dumpsig ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
9461
9462 In the output of the above command, you will find a line like the
9463 following, which lists all the (inferred) variable dependencies for
9464 the task. This list also includes indirect dependencies from
9465 variables depending on other variables, recursively.
9466 ::
9467
9468 Task dependencies: ['PV', 'SRCREV', 'SRC_URI', 'SRC_URI[md5sum]', 'SRC_URI[sha256sum]', 'base_do_fetch']
9469
9470 .. note::
9471
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009472 Functions (e.g. ``base_do_fetch``) also count as variable dependencies.
9473 These functions in turn depend on the variables they reference.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009474
9475 The output of ``bitbake-dumpsig`` also includes the value each
9476 variable had, a list of dependencies for each variable, and
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00009477 :term:`BB_BASEHASH_IGNORE_VARS`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009478 information.
9479
9480There is also a ``bitbake-diffsigs`` command for comparing two
9481``siginfo`` or ``sigdata`` files. This command can be helpful when
9482trying to figure out what changed between two versions of a task. If you
9483call ``bitbake-diffsigs`` with just one file, the command behaves like
9484``bitbake-dumpsig``.
9485
9486You can also use BitBake to dump out the signature construction
9487information without executing tasks by using either of the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05009488BitBake command-line options::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009489
9490 ‐‐dump-signatures=SIGNATURE_HANDLER
9491 -S SIGNATURE_HANDLER
9492
9493
9494.. note::
9495
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009496 Two common values for `SIGNATURE_HANDLER` are "none" and "printdiff", which
9497 dump only the signature or compare the dumped signature with the cached one,
9498 respectively.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009499
9500Using BitBake with either of these options causes BitBake to dump out
9501``sigdata`` files in the ``stamps`` directory for every task it would
9502have executed instead of building the specified target package.
9503
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009504Viewing Metadata Used to Create the Input Signature of a Shared State Task
9505--------------------------------------------------------------------------
9506
9507Seeing what metadata went into creating the input signature of a shared
9508state (sstate) task can be a useful debugging aid. This information is
9509available in signature information (``siginfo``) files in
9510:term:`SSTATE_DIR`. For
9511information on how to view and interpret information in ``siginfo``
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009512files, see the
9513":ref:`dev-manual/common-tasks:viewing task variable dependencies`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009514
9515For conceptual information on shared state, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06009516":ref:`overview-manual/concepts:shared state`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009517section in the Yocto Project Overview and Concepts Manual.
9518
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009519Invalidating Shared State to Force a Task to Run
9520------------------------------------------------
9521
9522The OpenEmbedded build system uses
Andrew Geissler09209ee2020-12-13 08:44:15 -06009523:ref:`checksums <overview-manual/concepts:checksums (signatures)>` and
9524:ref:`overview-manual/concepts:shared state` cache to avoid unnecessarily
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009525rebuilding tasks. Collectively, this scheme is known as "shared state
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009526code".
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009527
9528As with all schemes, this one has some drawbacks. It is possible that
9529you could make implicit changes to your code that the checksum
9530calculations do not take into account. These implicit changes affect a
9531task's output but do not trigger the shared state code into rebuilding a
9532recipe. Consider an example during which a tool changes its output.
9533Assume that the output of ``rpmdeps`` changes. The result of the change
9534should be that all the ``package`` and ``package_write_rpm`` shared
9535state cache items become invalid. However, because the change to the
9536output is external to the code and therefore implicit, the associated
9537shared state cache items do not become invalidated. In this case, the
9538build process uses the cached items rather than running the task again.
9539Obviously, these types of implicit changes can cause problems.
9540
9541To avoid these problems during the build, you need to understand the
9542effects of any changes you make. Realize that changes you make directly
9543to a function are automatically factored into the checksum calculation.
9544Thus, these explicit changes invalidate the associated area of shared
9545state cache. However, you need to be aware of any implicit changes that
9546are not obvious changes to the code and could affect the output of a
9547given task.
9548
9549When you identify an implicit change, you can easily take steps to
9550invalidate the cache and force the tasks to run. The steps you can take
9551are as simple as changing a function's comments in the source code. For
9552example, to invalidate package shared state files, change the comment
9553statements of
9554:ref:`ref-tasks-package` or the
9555comments of one of the functions it calls. Even though the change is
9556purely cosmetic, it causes the checksum to be recalculated and forces
9557the build system to run the task again.
9558
9559.. note::
9560
9561 For an example of a commit that makes a cosmetic change to invalidate
9562 shared state, see this
Andrew Geissler09209ee2020-12-13 08:44:15 -06009563 :yocto_git:`commit </poky/commit/meta/classes/package.bbclass?id=737f8bbb4f27b4837047cb9b4fbfe01dfde36d54>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009564
9565Running Specific Tasks
9566----------------------
9567
9568Any given recipe consists of a set of tasks. The standard BitBake
9569behavior in most cases is: ``do_fetch``, ``do_unpack``, ``do_patch``,
9570``do_configure``, ``do_compile``, ``do_install``, ``do_package``,
9571``do_package_write_*``, and ``do_build``. The default task is
9572``do_build`` and any tasks on which it depends build first. Some tasks,
9573such as ``do_devshell``, are not part of the default build chain. If you
9574wish to run a task that is not part of the default build chain, you can
Andrew Geisslerc926e172021-05-07 16:11:35 -05009575use the ``-c`` option in BitBake. Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009576
9577 $ bitbake matchbox-desktop -c devshell
9578
9579The ``-c`` option respects task dependencies, which means that all other
9580tasks (including tasks from other recipes) that the specified task
9581depends on will be run before the task. Even when you manually specify a
9582task to run with ``-c``, BitBake will only run the task if it considers
9583it "out of date". See the
Andrew Geissler09209ee2020-12-13 08:44:15 -06009584":ref:`overview-manual/concepts:stamp files and the rerunning of tasks`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009585section in the Yocto Project Overview and Concepts Manual for how
9586BitBake determines whether a task is "out of date".
9587
9588If you want to force an up-to-date task to be rerun (e.g. because you
9589made manual modifications to the recipe's
9590:term:`WORKDIR` that you want to try
9591out), then you can use the ``-f`` option.
9592
9593.. note::
9594
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009595 The reason ``-f`` is never required when running the
9596 :ref:`ref-tasks-devshell` task is because the
9597 [\ :ref:`nostamp <bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ]
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009598 variable flag is already set for the task.
9599
Andrew Geisslerc926e172021-05-07 16:11:35 -05009600The following example shows one way you can use the ``-f`` option::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009601
9602 $ bitbake matchbox-desktop
9603 .
9604 .
9605 make some changes to the source code in the work directory
9606 .
9607 .
9608 $ bitbake matchbox-desktop -c compile -f
9609 $ bitbake matchbox-desktop
9610
9611This sequence first builds and then recompiles ``matchbox-desktop``. The
9612last command reruns all tasks (basically the packaging tasks) after the
9613compile. BitBake recognizes that the ``do_compile`` task was rerun and
9614therefore understands that the other tasks also need to be run again.
9615
9616Another, shorter way to rerun a task and all
Andrew Geissler09209ee2020-12-13 08:44:15 -06009617:ref:`ref-manual/tasks:normal recipe build tasks`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009618that depend on it is to use the ``-C`` option.
9619
9620.. note::
9621
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009622 This option is upper-cased and is separate from the ``-c``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009623 option, which is lower-cased.
9624
9625Using this option invalidates the given task and then runs the
9626:ref:`ref-tasks-build` task, which is
9627the default task if no task is given, and the tasks on which it depends.
9628You could replace the final two commands in the previous example with
Andrew Geisslerc926e172021-05-07 16:11:35 -05009629the following single command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009630
9631 $ bitbake matchbox-desktop -C compile
9632
9633Internally, the ``-f`` and ``-C`` options work by tainting (modifying)
9634the input checksum of the specified task. This tainting indirectly
9635causes the task and its dependent tasks to be rerun through the normal
9636task dependency mechanisms.
9637
9638.. note::
9639
9640 BitBake explicitly keeps track of which tasks have been tainted in
9641 this fashion, and will print warnings such as the following for
9642 builds involving such tasks:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009643
9644 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009645
9646 WARNING: /home/ulf/poky/meta/recipes-sato/matchbox-desktop/matchbox-desktop_2.1.bb.do_compile is tainted from a forced run
9647
9648
9649 The purpose of the warning is to let you know that the work directory
9650 and build output might not be in the clean state they would be in for
9651 a "normal" build, depending on what actions you took. To get rid of
9652 such warnings, you can remove the work directory and rebuild the
Andrew Geisslerc926e172021-05-07 16:11:35 -05009653 recipe, as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009654
9655 $ bitbake matchbox-desktop -c clean
9656 $ bitbake matchbox-desktop
9657
9658
9659You can view a list of tasks in a given package by running the
Andrew Geisslerc926e172021-05-07 16:11:35 -05009660``do_listtasks`` task as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009661
9662 $ bitbake matchbox-desktop -c listtasks
9663
9664The results appear as output to the console and are also in
9665the file ``${WORKDIR}/temp/log.do_listtasks``.
9666
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009667General BitBake Problems
9668------------------------
9669
9670You can see debug output from BitBake by using the ``-D`` option. The
9671debug output gives more information about what BitBake is doing and the
9672reason behind it. Each ``-D`` option you use increases the logging
9673level. The most common usage is ``-DDD``.
9674
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009675The output from ``bitbake -DDD -v targetname`` can reveal why BitBake
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009676chose a certain version of a package or why BitBake picked a certain
9677provider. This command could also help you in a situation where you
9678think BitBake did something unexpected.
9679
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009680Building with No Dependencies
9681-----------------------------
9682
9683To build a specific recipe (``.bb`` file), you can use the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05009684command form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009685
9686 $ bitbake -b somepath/somerecipe.bb
9687
9688This command form does
9689not check for dependencies. Consequently, you should use it only when
9690you know existing dependencies have been met.
9691
9692.. note::
9693
9694 You can also specify fragments of the filename. In this case, BitBake
9695 checks for a unique match.
9696
9697Recipe Logging Mechanisms
9698-------------------------
9699
9700The Yocto Project provides several logging functions for producing
9701debugging output and reporting errors and warnings. For Python
William A. Kennington IIIac69b482021-06-02 12:28:27 -07009702functions, the following logging functions are available. All of these functions
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009703log to ``${T}/log.do_``\ `task`, and can also log to standard output
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009704(stdout) with the right settings:
9705
9706- ``bb.plain(msg)``: Writes msg as is to the log while also
9707 logging to stdout.
9708
9709- ``bb.note(msg)``: Writes "NOTE: msg" to the log. Also logs to
9710 stdout if BitBake is called with "-v".
9711
9712- ``bb.debug(level, msg)``: Writes "DEBUG: msg" to the
9713 log. Also logs to stdout if the log level is greater than or equal to
Patrick Williams213cb262021-08-07 19:21:33 -05009714 level. See the ":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-intro:usage and syntax`" option
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009715 in the BitBake User Manual for more information.
9716
9717- ``bb.warn(msg)``: Writes "WARNING: msg" to the log while also
9718 logging to stdout.
9719
9720- ``bb.error(msg)``: Writes "ERROR: msg" to the log while also
9721 logging to standard out (stdout).
9722
9723 .. note::
9724
9725 Calling this function does not cause the task to fail.
9726
Andrew Geisslereff27472021-10-29 15:35:00 -05009727- ``bb.fatal(msg)``: This logging function is similar to
9728 ``bb.error(msg)`` but also causes the calling task to fail.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009729
9730 .. note::
9731
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009732 ``bb.fatal()`` raises an exception, which means you do not need to put a
9733 "return" statement after the function.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009734
9735The same logging functions are also available in shell functions, under
9736the names ``bbplain``, ``bbnote``, ``bbdebug``, ``bbwarn``, ``bberror``,
9737and ``bbfatal``. The
9738:ref:`logging <ref-classes-logging>` class
9739implements these functions. See that class in the ``meta/classes``
9740folder of the :term:`Source Directory` for information.
9741
9742Logging With Python
9743~~~~~~~~~~~~~~~~~~~
9744
9745When creating recipes using Python and inserting code that handles build
9746logs, keep in mind the goal is to have informative logs while keeping
9747the console as "silent" as possible. Also, if you want status messages
9748in the log, use the "debug" loglevel.
9749
9750Following is an example written in Python. The code handles logging for
9751a function that determines the number of tasks needed to be run. See the
9752":ref:`ref-tasks-listtasks`"
Andrew Geisslerc926e172021-05-07 16:11:35 -05009753section for additional information::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009754
9755 python do_listtasks() {
9756 bb.debug(2, "Starting to figure out the task list")
9757 if noteworthy_condition:
9758 bb.note("There are 47 tasks to run")
9759 bb.debug(2, "Got to point xyz")
9760 if warning_trigger:
9761 bb.warn("Detected warning_trigger, this might be a problem later.")
9762 if recoverable_error:
9763 bb.error("Hit recoverable_error, you really need to fix this!")
9764 if fatal_error:
9765 bb.fatal("fatal_error detected, unable to print the task list")
9766 bb.plain("The tasks present are abc")
9767 bb.debug(2, "Finished figuring out the tasklist")
9768 }
9769
9770Logging With Bash
9771~~~~~~~~~~~~~~~~~
9772
9773When creating recipes using Bash and inserting code that handles build
9774logs, you have the same goals - informative with minimal console output.
9775The syntax you use for recipes written in Bash is similar to that of
9776recipes written in Python described in the previous section.
9777
9778Following is an example written in Bash. The code logs the progress of
9779the ``do_my_function`` function.
9780::
9781
9782 do_my_function() {
9783 bbdebug 2 "Running do_my_function"
9784 if [ exceptional_condition ]; then
9785 bbnote "Hit exceptional_condition"
9786 fi
9787 bbdebug 2 "Got to point xyz"
9788 if [ warning_trigger ]; then
9789 bbwarn "Detected warning_trigger, this might cause a problem later."
9790 fi
9791 if [ recoverable_error ]; then
9792 bberror "Hit recoverable_error, correcting"
9793 fi
9794 if [ fatal_error ]; then
9795 bbfatal "fatal_error detected"
9796 fi
9797 bbdebug 2 "Completed do_my_function"
9798 }
9799
9800
9801Debugging Parallel Make Races
9802-----------------------------
9803
9804A parallel ``make`` race occurs when the build consists of several parts
9805that are run simultaneously and a situation occurs when the output or
9806result of one part is not ready for use with a different part of the
9807build that depends on that output. Parallel make races are annoying and
William A. Kennington IIIac69b482021-06-02 12:28:27 -07009808can sometimes be difficult to reproduce and fix. However, there are some simple
9809tips and tricks that can help you debug and fix them. This section
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009810presents a real-world example of an error encountered on the Yocto
9811Project autobuilder and the process used to fix it.
9812
9813.. note::
9814
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009815 If you cannot properly fix a ``make`` race condition, you can work around it
9816 by clearing either the :term:`PARALLEL_MAKE` or :term:`PARALLEL_MAKEINST`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009817 variables.
9818
9819The Failure
9820~~~~~~~~~~~
9821
9822For this example, assume that you are building an image that depends on
9823the "neard" package. And, during the build, BitBake runs into problems
9824and creates the following output.
9825
9826.. note::
9827
9828 This example log file has longer lines artificially broken to make
9829 the listing easier to read.
9830
9831If you examine the output or the log file, you see the failure during
9832``make``:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009833
9834.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009835
9836 | DEBUG: SITE files ['endian-little', 'bit-32', 'ix86-common', 'common-linux', 'common-glibc', 'i586-linux', 'common']
9837 | DEBUG: Executing shell function do_compile
9838 | NOTE: make -j 16
9839 | make --no-print-directory all-am
9840 | /bin/mkdir -p include/near
9841 | /bin/mkdir -p include/near
9842 | /bin/mkdir -p include/near
Andrew Geissler595f6302022-01-24 19:11:47 +00009843 | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009844 0.14-r0/neard-0.14/include/types.h include/near/types.h
Andrew Geissler595f6302022-01-24 19:11:47 +00009845 | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009846 0.14-r0/neard-0.14/include/log.h include/near/log.h
Andrew Geissler595f6302022-01-24 19:11:47 +00009847 | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009848 0.14-r0/neard-0.14/include/plugin.h include/near/plugin.h
9849 | /bin/mkdir -p include/near
9850 | /bin/mkdir -p include/near
9851 | /bin/mkdir -p include/near
Andrew Geissler595f6302022-01-24 19:11:47 +00009852 | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009853 0.14-r0/neard-0.14/include/tag.h include/near/tag.h
9854 | /bin/mkdir -p include/near
Andrew Geissler595f6302022-01-24 19:11:47 +00009855 | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009856 0.14-r0/neard-0.14/include/adapter.h include/near/adapter.h
9857 | /bin/mkdir -p include/near
Andrew Geissler595f6302022-01-24 19:11:47 +00009858 | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009859 0.14-r0/neard-0.14/include/ndef.h include/near/ndef.h
Andrew Geissler595f6302022-01-24 19:11:47 +00009860 | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009861 0.14-r0/neard-0.14/include/tlv.h include/near/tlv.h
9862 | /bin/mkdir -p include/near
9863 | /bin/mkdir -p include/near
Andrew Geissler595f6302022-01-24 19:11:47 +00009864 | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009865 0.14-r0/neard-0.14/include/setting.h include/near/setting.h
9866 | /bin/mkdir -p include/near
9867 | /bin/mkdir -p include/near
9868 | /bin/mkdir -p include/near
Andrew Geissler595f6302022-01-24 19:11:47 +00009869 | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009870 0.14-r0/neard-0.14/include/device.h include/near/device.h
Andrew Geissler595f6302022-01-24 19:11:47 +00009871 | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009872 0.14-r0/neard-0.14/include/nfc_copy.h include/near/nfc_copy.h
Andrew Geissler595f6302022-01-24 19:11:47 +00009873 | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009874 0.14-r0/neard-0.14/include/snep.h include/near/snep.h
Andrew Geissler595f6302022-01-24 19:11:47 +00009875 | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009876 0.14-r0/neard-0.14/include/version.h include/near/version.h
Andrew Geissler595f6302022-01-24 19:11:47 +00009877 | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009878 0.14-r0/neard-0.14/include/dbus.h include/near/dbus.h
9879 | ./src/genbuiltin nfctype1 nfctype2 nfctype3 nfctype4 p2p > src/builtin.h
Andrew Geissler595f6302022-01-24 19:11:47 +00009880 | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/pokybuild/yocto-autobuilder/nightly-x86/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009881 build/build/tmp/sysroots/qemux86 -DHAVE_CONFIG_H -I. -I./include -I./src -I./gdbus -I/home/pokybuild/
Andrew Geissler595f6302022-01-24 19:11:47 +00009882 yocto-autobuilder/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/glib-2.0
9883 -I/home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/sysroots/qemux86/usr/
9884 lib/glib-2.0/include -I/home/pokybuild/yocto-autobuilder/nightly-x86/build/build/
9885 tmp/sysroots/qemux86/usr/include/dbus-1.0 -I/home/pokybuild/yocto-autobuilder/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009886 nightly-x86/build/build/tmp/sysroots/qemux86/usr/lib/dbus-1.0/include -I/home/pokybuild/yocto-autobuilder/
Andrew Geissler595f6302022-01-24 19:11:47 +00009887 nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/libnl3
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009888 -DNEAR_PLUGIN_BUILTIN -DPLUGINDIR=\""/usr/lib/near/plugins"\"
9889 -DCONFIGDIR=\""/etc/neard\"" -O2 -pipe -g -feliminate-unused-debug-types -c
9890 -o tools/snep-send.o tools/snep-send.c
9891 | In file included from tools/snep-send.c:16:0:
9892 | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
9893 | #include <near/dbus.h>
9894 | ^
9895 | compilation terminated.
9896 | make[1]: *** [tools/snep-send.o] Error 1
9897 | make[1]: *** Waiting for unfinished jobs....
9898 | make: *** [all] Error 2
9899 | ERROR: oe_runmake failed
9900
9901Reproducing the Error
9902~~~~~~~~~~~~~~~~~~~~~
9903
9904Because race conditions are intermittent, they do not manifest
9905themselves every time you do the build. In fact, most times the build
9906will complete without problems even though the potential race condition
9907exists. Thus, once the error surfaces, you need a way to reproduce it.
9908
9909In this example, compiling the "neard" package is causing the problem.
9910So the first thing to do is build "neard" locally. Before you start the
9911build, set the
9912:term:`PARALLEL_MAKE` variable
9913in your ``local.conf`` file to a high number (e.g. "-j 20"). Using a
Andrew Geissler09036742021-06-25 14:25:14 -05009914high value for :term:`PARALLEL_MAKE` increases the chances of the race
Andrew Geisslerc926e172021-05-07 16:11:35 -05009915condition showing up::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009916
9917 $ bitbake neard
9918
Andrew Geisslerc926e172021-05-07 16:11:35 -05009919Once the local build for "neard" completes, start a ``devshell`` build::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009920
9921 $ bitbake neard -c devshell
9922
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009923For information on how to use a ``devshell``, see the
9924":ref:`dev-manual/common-tasks:using a development shell`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009925
Andrew Geisslerc926e172021-05-07 16:11:35 -05009926In the ``devshell``, do the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009927
9928 $ make clean
9929 $ make tools/snep-send.o
9930
9931The ``devshell`` commands cause the failure to clearly
William A. Kennington IIIac69b482021-06-02 12:28:27 -07009932be visible. In this case, there is a missing dependency for the ``neard``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009933Makefile target. Here is some abbreviated, sample output with the
Andrew Geisslerc926e172021-05-07 16:11:35 -05009934missing dependency clearly visible at the end::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009935
9936 i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/scott-lenovo/......
9937 .
9938 .
9939 .
9940 tools/snep-send.c
9941 In file included from tools/snep-send.c:16:0:
9942 tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
9943 #include <near/dbus.h>
9944 ^
9945 compilation terminated.
9946 make: *** [tools/snep-send.o] Error 1
9947 $
9948
9949
9950Creating a Patch for the Fix
9951~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9952
9953Because there is a missing dependency for the Makefile target, you need
9954to patch the ``Makefile.am`` file, which is generated from
Andrew Geisslerc926e172021-05-07 16:11:35 -05009955``Makefile.in``. You can use Quilt to create the patch::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009956
9957 $ quilt new parallelmake.patch
9958 Patch patches/parallelmake.patch is now on top
9959 $ quilt add Makefile.am
9960 File Makefile.am added to patch patches/parallelmake.patch
9961
9962For more information on using Quilt, see the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009963":ref:`dev-manual/common-tasks:using quilt in your workflow`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009964
9965At this point you need to make the edits to ``Makefile.am`` to add the
9966missing dependency. For our example, you have to add the following line
Andrew Geisslerc926e172021-05-07 16:11:35 -05009967to the file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009968
9969 tools/snep-send.$(OBJEXT): include/near/dbus.h
9970
9971Once you have edited the file, use the ``refresh`` command to create the
Andrew Geisslerc926e172021-05-07 16:11:35 -05009972patch::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009973
9974 $ quilt refresh
9975 Refreshed patch patches/parallelmake.patch
9976
William A. Kennington IIIac69b482021-06-02 12:28:27 -07009977Once the patch file is created, you need to add it back to the originating
9978recipe folder. Here is an example assuming a top-level
Andrew Geisslerc926e172021-05-07 16:11:35 -05009979:term:`Source Directory` named ``poky``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009980
9981 $ cp patches/parallelmake.patch poky/meta/recipes-connectivity/neard/neard
9982
9983The final thing you need to do to implement the fix in the build is to
9984update the "neard" recipe (i.e. ``neard-0.14.bb``) so that the
9985:term:`SRC_URI` statement includes
9986the patch file. The recipe file is in the folder above the patch. Here
Andrew Geissler09036742021-06-25 14:25:14 -05009987is what the edited :term:`SRC_URI` statement would look like::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009988
9989 SRC_URI = "${KERNELORG_MIRROR}/linux/network/nfc/${BPN}-${PV}.tar.xz \
9990 file://neard.in \
9991 file://neard.service.in \
9992 file://parallelmake.patch \
9993 "
9994
9995With the patch complete and moved to the correct folder and the
Andrew Geissler09036742021-06-25 14:25:14 -05009996:term:`SRC_URI` statement updated, you can exit the ``devshell``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009997
9998 $ exit
9999
10000Testing the Build
10001~~~~~~~~~~~~~~~~~
10002
10003With everything in place, you can get back to trying the build again
Andrew Geisslerc926e172021-05-07 16:11:35 -050010004locally::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010005
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010006 $ bitbake neard
10007
10008This build should succeed.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010009
10010Now you can open up a ``devshell`` again and repeat the clean and make
Andrew Geisslerc926e172021-05-07 16:11:35 -050010011operations as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010012
10013 $ bitbake neard -c devshell
10014 $ make clean
10015 $ make tools/snep-send.o
10016
10017The build should work without issue.
10018
10019As with all solved problems, if they originated upstream, you need to
10020submit the fix for the recipe in OE-Core and upstream so that the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050010021problem is taken care of at its source. See the
10022":ref:`dev-manual/common-tasks:submitting a change to the yocto project`"
10023section for more information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010024
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010025Debugging With the GNU Project Debugger (GDB) Remotely
10026------------------------------------------------------
10027
10028GDB allows you to examine running programs, which in turn helps you to
10029understand and fix problems. It also allows you to perform post-mortem
10030style analysis of program crashes. GDB is available as a package within
10031the Yocto Project and is installed in SDK images by default. See the
Andrew Geissler09209ee2020-12-13 08:44:15 -060010032":ref:`ref-manual/images:Images`" chapter in the Yocto
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010033Project Reference Manual for a description of these images. You can find
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010034information on GDB at https://sourceware.org/gdb/.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010035
10036.. note::
10037
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010038 For best results, install debug (``-dbg``) packages for the applications you
10039 are going to debug. Doing so makes extra debug symbols available that give
10040 you more meaningful output.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010041
10042Sometimes, due to memory or disk space constraints, it is not possible
10043to use GDB directly on the remote target to debug applications. These
10044constraints arise because GDB needs to load the debugging information
10045and the binaries of the process being debugged. Additionally, GDB needs
10046to perform many computations to locate information such as function
10047names, variable names and values, stack traces and so forth - even
10048before starting the debugging process. These extra computations place
10049more load on the target system and can alter the characteristics of the
10050program being debugged.
10051
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010052To help get past the previously mentioned constraints, there are two
10053methods you can use: running a debuginfod server and using gdbserver.
10054
10055Using the debuginfod server method
10056~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10057
Andrew Geisslerc926e172021-05-07 16:11:35 -050010058``debuginfod`` from ``elfutils`` is a way to distribute ``debuginfo`` files.
10059Running a ``debuginfod`` server makes debug symbols readily available,
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010060which means you don't need to download debugging information
10061and the binaries of the process being debugged. You can just fetch
10062debug symbols from the server.
10063
Andrew Geisslerc926e172021-05-07 16:11:35 -050010064To run a ``debuginfod`` server, you need to do the following:
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010065
Andrew Geisslerc926e172021-05-07 16:11:35 -050010066- Ensure that ``debuginfod`` is present in :term:`DISTRO_FEATURES`
10067 (it already is in ``OpenEmbedded-core`` defaults and ``poky`` reference distribution).
10068 If not, set in your distro config file or in ``local.conf``::
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010069
Patrick Williams0ca19cc2021-08-16 14:03:13 -050010070 DISTRO_FEATURES:append = " debuginfod"
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010071
Andrew Geisslerc926e172021-05-07 16:11:35 -050010072 This distro feature enables the server and client library in ``elfutils``,
10073 and enables ``debuginfod`` support in clients (at the moment, ``gdb`` and ``binutils``).
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010074
Andrew Geisslerc926e172021-05-07 16:11:35 -050010075- Run the following commands to launch the ``debuginfod`` server on the host::
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010076
10077 $ oe-debuginfod
10078
Andrew Geisslerc926e172021-05-07 16:11:35 -050010079- To use ``debuginfod`` on the target, you need to know the ip:port where
10080 ``debuginfod`` is listening on the host (port defaults to 8002), and export
10081 that into the shell environment, for example in ``qemu``::
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010082
Andrew Geisslerc926e172021-05-07 16:11:35 -050010083 root@qemux86-64:~# export DEBUGINFOD_URLS="http://192.168.7.1:8002/"
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010084
Andrew Geisslerc926e172021-05-07 16:11:35 -050010085- Then debug info fetching should simply work when running the target ``gdb``,
10086 ``readelf`` or ``objdump``, for example::
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010087
Andrew Geisslerc926e172021-05-07 16:11:35 -050010088 root@qemux86-64:~# gdb /bin/cat
10089 ...
10090 Reading symbols from /bin/cat...
10091 Downloading separate debug info for /bin/cat...
10092 Reading symbols from /home/root/.cache/debuginfod_client/923dc4780cfbc545850c616bffa884b6b5eaf322/debuginfo...
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010093
Andrew Geisslerc926e172021-05-07 16:11:35 -050010094- It's also possible to use ``debuginfod-find`` to just query the server::
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010095
Andrew Geisslerc926e172021-05-07 16:11:35 -050010096 root@qemux86-64:~# debuginfod-find debuginfo /bin/ls
10097 /home/root/.cache/debuginfod_client/356edc585f7f82d46f94fcb87a86a3fe2d2e60bd/debuginfo
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010098
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010099
10100Using the gdbserver method
10101~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10102
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010103gdbserver, which runs on the remote target and does not load any
10104debugging information from the debugged process. Instead, a GDB instance
10105processes the debugging information that is run on a remote computer -
10106the host GDB. The host GDB then sends control commands to gdbserver to
10107make it stop or start the debugged program, as well as read or write
10108memory regions of that debugged program. All the debugging information
10109loaded and processed as well as all the heavy debugging is done by the
10110host GDB. Offloading these processes gives the gdbserver running on the
10111target a chance to remain small and fast.
10112
10113Because the host GDB is responsible for loading the debugging
10114information and for doing the necessary processing to make actual
10115debugging happen, you have to make sure the host can access the
10116unstripped binaries complete with their debugging information and also
10117be sure the target is compiled with no optimizations. The host GDB must
10118also have local access to all the libraries used by the debugged
10119program. Because gdbserver does not need any local debugging
10120information, the binaries on the remote target can remain stripped.
10121However, the binaries must also be compiled without optimization so they
10122match the host's binaries.
10123
10124To remain consistent with GDB documentation and terminology, the binary
10125being debugged on the remote target machine is referred to as the
10126"inferior" binary. For documentation on GDB see the `GDB
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010127site <https://sourceware.org/gdb/documentation/>`__.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010128
10129The following steps show you how to debug using the GNU project
10130debugger.
10131
101321. *Configure your build system to construct the companion debug
10133 filesystem:*
10134
Andrew Geisslerc926e172021-05-07 16:11:35 -050010135 In your ``local.conf`` file, set the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010136
10137 IMAGE_GEN_DEBUGFS = "1"
10138 IMAGE_FSTYPES_DEBUGFS = "tar.bz2"
10139
10140 These options cause the
10141 OpenEmbedded build system to generate a special companion filesystem
10142 fragment, which contains the matching source and debug symbols to
10143 your deployable filesystem. The build system does this by looking at
10144 what is in the deployed filesystem, and pulling the corresponding
10145 ``-dbg`` packages.
10146
10147 The companion debug filesystem is not a complete filesystem, but only
10148 contains the debug fragments. This filesystem must be combined with
10149 the full filesystem for debugging. Subsequent steps in this procedure
10150 show how to combine the partial filesystem with the full filesystem.
10151
101522. *Configure the system to include gdbserver in the target filesystem:*
10153
10154 Make the following addition in either your ``local.conf`` file or in
Andrew Geisslerc926e172021-05-07 16:11:35 -050010155 an image recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010156
Patrick Williams0ca19cc2021-08-16 14:03:13 -050010157 IMAGE_INSTALL:append = " gdbserver"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010158
10159 The change makes
10160 sure the ``gdbserver`` package is included.
10161
101623. *Build the environment:*
10163
10164 Use the following command to construct the image and the companion
Andrew Geisslerc926e172021-05-07 16:11:35 -050010165 Debug Filesystem::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010166
10167 $ bitbake image
10168
10169 Build the cross GDB component and
10170 make it available for debugging. Build the SDK that matches the
10171 image. Building the SDK is best for a production build that can be
Andrew Geisslerc926e172021-05-07 16:11:35 -050010172 used later for debugging, especially during long term maintenance::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010173
10174 $ bitbake -c populate_sdk image
10175
10176 Alternatively, you can build the minimal toolchain components that
10177 match the target. Doing so creates a smaller than typical SDK and
10178 only contains a minimal set of components with which to build simple
Andrew Geisslerc926e172021-05-07 16:11:35 -050010179 test applications, as well as run the debugger::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010180
10181 $ bitbake meta-toolchain
10182
Andrew Geisslerc926e172021-05-07 16:11:35 -050010183 A final method is to build Gdb itself within the build system::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010184
10185 $ bitbake gdb-cross-<architecture>
10186
10187 Doing so produces a temporary copy of
10188 ``cross-gdb`` you can use for debugging during development. While
10189 this is the quickest approach, the two previous methods in this step
10190 are better when considering long-term maintenance strategies.
10191
10192 .. note::
10193
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010194 If you run ``bitbake gdb-cross``, the OpenEmbedded build system suggests
10195 the actual image (e.g. ``gdb-cross-i586``). The suggestion is usually the
10196 actual name you want to use.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010197
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500101984. *Set up the* ``debugfs``\ *:*
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010199
Andrew Geisslerc926e172021-05-07 16:11:35 -050010200 Run the following commands to set up the ``debugfs``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010201
10202 $ mkdir debugfs
10203 $ cd debugfs
10204 $ tar xvfj build-dir/tmp-glibc/deploy/images/machine/image.rootfs.tar.bz2
10205 $ tar xvfj build-dir/tmp-glibc/deploy/images/machine/image-dbg.rootfs.tar.bz2
10206
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500102075. *Set up GDB:*
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010208
10209 Install the SDK (if you built one) and then source the correct
10210 environment file. Sourcing the environment file puts the SDK in your
10211 ``PATH`` environment variable.
10212
10213 If you are using the build system, Gdb is located in
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010214 `build-dir`\ ``/tmp/sysroots/``\ `host`\ ``/usr/bin/``\ `architecture`\ ``/``\ `architecture`\ ``-gdb``
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010215
102166. *Boot the target:*
10217
10218 For information on how to run QEMU, see the `QEMU
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010219 Documentation <https://wiki.qemu.org/Documentation/GettingStartedDevelopers>`__.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010220
10221 .. note::
10222
10223 Be sure to verify that your host can access the target via TCP.
10224
102257. *Debug a program:*
10226
10227 Debugging a program involves running gdbserver on the target and then
10228 running Gdb on the host. The example in this step debugs ``gzip``:
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010229
10230 .. code-block:: shell
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010231
10232 root@qemux86:~# gdbserver localhost:1234 /bin/gzip —help
10233
10234 For
10235 additional gdbserver options, see the `GDB Server
10236 Documentation <https://www.gnu.org/software/gdb/documentation/>`__.
10237
10238 After running gdbserver on the target, you need to run Gdb on the
Andrew Geisslerc926e172021-05-07 16:11:35 -050010239 host and configure it and connect to the target. Use these commands::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010240
10241 $ cd directory-holding-the-debugfs-directory
10242 $ arch-gdb
10243 (gdb) set sysroot debugfs
10244 (gdb) set substitute-path /usr/src/debug debugfs/usr/src/debug
10245 (gdb) target remote IP-of-target:1234
10246
10247 At this
10248 point, everything should automatically load (i.e. matching binaries,
10249 symbols and headers).
10250
10251 .. note::
10252
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010253 The Gdb ``set`` commands in the previous example can be placed into the
10254 users ``~/.gdbinit`` file. Upon starting, Gdb automatically runs whatever
10255 commands are in that file.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010256
102578. *Deploying without a full image rebuild:*
10258
10259 In many cases, during development you want a quick method to deploy a
10260 new binary to the target and debug it, without waiting for a full
10261 image build.
10262
10263 One approach to solving this situation is to just build the component
10264 you want to debug. Once you have built the component, copy the
10265 executable directly to both the target and the host ``debugfs``.
10266
10267 If the binary is processed through the debug splitting in
10268 OpenEmbedded, you should also copy the debug items (i.e. ``.debug``
10269 contents and corresponding ``/usr/src/debug`` files) from the work
Andrew Geisslerc926e172021-05-07 16:11:35 -050010270 directory. Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010271
10272 $ bitbake bash
10273 $ bitbake -c devshell bash
10274 $ cd ..
10275 $ scp packages-split/bash/bin/bash target:/bin/bash
10276 $ cp -a packages-split/bash-dbg/\* path/debugfs
10277
10278Debugging with the GNU Project Debugger (GDB) on the Target
10279-----------------------------------------------------------
10280
10281The previous section addressed using GDB remotely for debugging
10282purposes, which is the most usual case due to the inherent hardware
10283limitations on many embedded devices. However, debugging in the target
10284hardware itself is also possible with more powerful devices. This
10285section describes what you need to do in order to support using GDB to
10286debug on the target hardware.
10287
10288To support this kind of debugging, you need do the following:
10289
10290- Ensure that GDB is on the target. You can do this by adding "gdb" to
Andrew Geisslerc926e172021-05-07 16:11:35 -050010291 :term:`IMAGE_INSTALL`::
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010292
Patrick Williams0ca19cc2021-08-16 14:03:13 -050010293 IMAGE_INSTALL:append = " gdb"
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010294
Andrew Geisslerc926e172021-05-07 16:11:35 -050010295 Alternatively, you can add "tools-debug" to :term:`IMAGE_FEATURES`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010296
Patrick Williams0ca19cc2021-08-16 14:03:13 -050010297 IMAGE_FEATURES:append = " tools-debug"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010298
10299- Ensure that debug symbols are present. You can make sure these
Andrew Geisslerc926e172021-05-07 16:11:35 -050010300 symbols are present by installing ``-dbg``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010301
Patrick Williams0ca19cc2021-08-16 14:03:13 -050010302 IMAGE_INSTALL:append = "packagename-dbg"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010303
10304 Alternatively, you can do the following to include
Andrew Geisslerc926e172021-05-07 16:11:35 -050010305 all the debug symbols::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010306
Patrick Williams0ca19cc2021-08-16 14:03:13 -050010307 IMAGE_FEATURES:append = " dbg-pkgs"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010308
10309.. note::
10310
10311 To improve the debug information accuracy, you can reduce the level
10312 of optimization used by the compiler. For example, when adding the
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010313 following line to your ``local.conf`` file, you will reduce optimization
10314 from :term:`FULL_OPTIMIZATION` of "-O2" to :term:`DEBUG_OPTIMIZATION`
Andrew Geisslerc926e172021-05-07 16:11:35 -050010315 of "-O -fno-omit-frame-pointer"::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010316
10317 DEBUG_BUILD = "1"
10318
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010319 Consider that this will reduce the application's performance and is
10320 recommended only for debugging purposes.
10321
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010322Other Debugging Tips
10323--------------------
10324
10325Here are some other tips that you might find useful:
10326
10327- When adding new packages, it is worth watching for undesirable items
10328 making their way into compiler command lines. For example, you do not
10329 want references to local system files like ``/usr/lib/`` or
10330 ``/usr/include/``.
10331
10332- If you want to remove the ``psplash`` boot splashscreen, add
10333 ``psplash=false`` to the kernel command line. Doing so prevents
10334 ``psplash`` from loading and thus allows you to see the console. It
10335 is also possible to switch out of the splashscreen by switching the
10336 virtual console (e.g. Fn+Left or Fn+Right on a Zaurus).
10337
10338- Removing :term:`TMPDIR` (usually
10339 ``tmp/``, within the
10340 :term:`Build Directory`) can often fix
Andrew Geissler09036742021-06-25 14:25:14 -050010341 temporary build issues. Removing :term:`TMPDIR` is usually a relatively
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010342 cheap operation, because task output will be cached in
10343 :term:`SSTATE_DIR` (usually
10344 ``sstate-cache/``, which is also in the Build Directory).
10345
10346 .. note::
10347
Andrew Geissler09036742021-06-25 14:25:14 -050010348 Removing :term:`TMPDIR` might be a workaround rather than a fix.
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010349 Consequently, trying to determine the underlying cause of an issue before
10350 removing the directory is a good idea.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010351
10352- Understanding how a feature is used in practice within existing
10353 recipes can be very helpful. It is recommended that you configure
10354 some method that allows you to quickly search through files.
10355
10356 Using GNU Grep, you can use the following shell function to
10357 recursively search through common recipe-related files, skipping
10358 binary files, ``.git`` directories, and the Build Directory (assuming
Andrew Geisslerc926e172021-05-07 16:11:35 -050010359 its name starts with "build")::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010360
10361 g() {
10362 grep -Ir \
10363 --exclude-dir=.git \
10364 --exclude-dir='build*' \
10365 --include='*.bb*' \
10366 --include='*.inc*' \
10367 --include='*.conf*' \
10368 --include='*.py*' \
10369 "$@"
10370 }
10371
Andrew Geisslerc926e172021-05-07 16:11:35 -050010372 Following are some usage examples::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010373
10374 $ g FOO # Search recursively for "FOO"
10375 $ g -i foo # Search recursively for "foo", ignoring case
10376 $ g -w FOO # Search recursively for "FOO" as a word, ignoring e.g. "FOOBAR"
10377
10378 If figuring
10379 out how some feature works requires a lot of searching, it might
10380 indicate that the documentation should be extended or improved. In
10381 such cases, consider filing a documentation bug using the Yocto
10382 Project implementation of
10383 :yocto_bugs:`Bugzilla <>`. For information on
10384 how to submit a bug against the Yocto Project, see the Yocto Project
Andrew Geissler09209ee2020-12-13 08:44:15 -060010385 Bugzilla :yocto_wiki:`wiki page </Bugzilla_Configuration_and_Bug_Tracking>`
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050010386 and the
10387 ":ref:`dev-manual/common-tasks:submitting a defect against the yocto project`"
10388 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010389
10390 .. note::
10391
10392 The manuals might not be the right place to document variables
10393 that are purely internal and have a limited scope (e.g. internal
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010394 variables used to implement a single ``.bbclass`` file).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010395
10396Making Changes to the Yocto Project
10397===================================
10398
10399Because the Yocto Project is an open-source, community-based project,
10400you can effect changes to the project. This section presents procedures
10401that show you how to submit a defect against the project and how to
10402submit a change.
10403
10404Submitting a Defect Against the Yocto Project
10405---------------------------------------------
10406
10407Use the Yocto Project implementation of
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010408`Bugzilla <https://www.bugzilla.org/about/>`__ to submit a defect (bug)
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010409against the Yocto Project. For additional information on this
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010410implementation of Bugzilla see the ":ref:`Yocto Project
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010411Bugzilla <resources-bugtracker>`" section in the
10412Yocto Project Reference Manual. For more detail on any of the following
10413steps, see the Yocto Project
Andrew Geissler09209ee2020-12-13 08:44:15 -060010414:yocto_wiki:`Bugzilla wiki page </Bugzilla_Configuration_and_Bug_Tracking>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010415
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010416Use the following general steps to submit a bug:
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010417
104181. Open the Yocto Project implementation of :yocto_bugs:`Bugzilla <>`.
10419
104202. Click "File a Bug" to enter a new bug.
10421
104223. Choose the appropriate "Classification", "Product", and "Component"
10423 for which the bug was found. Bugs for the Yocto Project fall into
10424 one of several classifications, which in turn break down into
10425 several products and components. For example, for a bug against the
10426 ``meta-intel`` layer, you would choose "Build System, Metadata &
10427 Runtime", "BSPs", and "bsps-meta-intel", respectively.
10428
104294. Choose the "Version" of the Yocto Project for which you found the
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010430 bug (e.g. &DISTRO;).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010431
104325. Determine and select the "Severity" of the bug. The severity
10433 indicates how the bug impacted your work.
10434
104356. Choose the "Hardware" that the bug impacts.
10436
104377. Choose the "Architecture" that the bug impacts.
10438
104398. Choose a "Documentation change" item for the bug. Fixing a bug might
10440 or might not affect the Yocto Project documentation. If you are
10441 unsure of the impact to the documentation, select "Don't Know".
10442
104439. Provide a brief "Summary" of the bug. Try to limit your summary to
10444 just a line or two and be sure to capture the essence of the bug.
10445
1044610. Provide a detailed "Description" of the bug. You should provide as
10447 much detail as you can about the context, behavior, output, and so
10448 forth that surrounds the bug. You can even attach supporting files
10449 for output from logs by using the "Add an attachment" button.
10450
1045111. Click the "Submit Bug" button submit the bug. A new Bugzilla number
10452 is assigned to the bug and the defect is logged in the bug tracking
10453 system.
10454
10455Once you file a bug, the bug is processed by the Yocto Project Bug
10456Triage Team and further details concerning the bug are assigned (e.g.
10457priority and owner). You are the "Submitter" of the bug and any further
10458categorization, progress, or comments on the bug result in Bugzilla
10459sending you an automated email concerning the particular change or
10460progress to the bug.
10461
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010462Submitting a Change to the Yocto Project
10463----------------------------------------
10464
10465Contributions to the Yocto Project and OpenEmbedded are very welcome.
10466Because the system is extremely configurable and flexible, we recognize
10467that developers will want to extend, configure or optimize it for their
10468specific uses.
10469
10470The Yocto Project uses a mailing list and a patch-based workflow that is
10471similar to the Linux kernel but contains important differences. In
William A. Kennington IIIac69b482021-06-02 12:28:27 -070010472general, there is a mailing list through which you can submit patches. You
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010473should send patches to the appropriate mailing list so that they can be
10474reviewed and merged by the appropriate maintainer. The specific mailing
10475list you need to use depends on the location of the code you are
10476changing. Each component (e.g. layer) should have a ``README`` file that
10477indicates where to send the changes and which process to follow.
10478
10479You can send the patch to the mailing list using whichever approach you
10480feel comfortable with to generate the patch. Once sent, the patch is
10481usually reviewed by the community at large. If somebody has concerns
10482with the patch, they will usually voice their concern over the mailing
10483list. If a patch does not receive any negative reviews, the maintainer
10484of the affected layer typically takes the patch, tests it, and then
10485based on successful testing, merges the patch.
10486
10487The "poky" repository, which is the Yocto Project's reference build
10488environment, is a hybrid repository that contains several individual
10489pieces (e.g. BitBake, Metadata, documentation, and so forth) built using
10490the combo-layer tool. The upstream location used for submitting changes
10491varies by component:
10492
10493- *Core Metadata:* Send your patch to the
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010494 :oe_lists:`openembedded-core </g/openembedded-core>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010495 mailing list. For example, a change to anything under the ``meta`` or
10496 ``scripts`` directories should be sent to this mailing list.
10497
10498- *BitBake:* For changes to BitBake (i.e. anything under the
10499 ``bitbake`` directory), send your patch to the
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010500 :oe_lists:`bitbake-devel </g/bitbake-devel>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010501 mailing list.
10502
Andrew Geisslerc3d88e42020-10-02 09:45:00 -050010503- *"meta-\*" trees:* These trees contain Metadata. Use the
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010504 :yocto_lists:`poky </g/poky>` mailing list.
Andrew Geisslerc3d88e42020-10-02 09:45:00 -050010505
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010506- *Documentation*: For changes to the Yocto Project documentation, use the
10507 :yocto_lists:`docs </g/docs>` mailing list.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010508
10509For changes to other layers hosted in the Yocto Project source
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010510repositories (i.e. ``yoctoproject.org``) and tools use the
10511:yocto_lists:`Yocto Project </g/yocto/>` general mailing list.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010512
10513.. note::
10514
10515 Sometimes a layer's documentation specifies to use a particular
10516 mailing list. If so, use that list.
10517
10518For additional recipes that do not fit into the core Metadata, you
10519should determine which layer the recipe should go into and submit the
10520change in the manner recommended by the documentation (e.g. the
10521``README`` file) supplied with the layer. If in doubt, please ask on the
10522Yocto general mailing list or on the openembedded-devel mailing list.
10523
10524You can also push a change upstream and request a maintainer to pull the
10525change into the component's upstream repository. You do this by pushing
Andrew Geissler09209ee2020-12-13 08:44:15 -060010526to a contribution repository that is upstream. See the
10527":ref:`overview-manual/development-environment:git workflows and the yocto project`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010528section in the Yocto Project Overview and Concepts Manual for additional
10529concepts on working in the Yocto Project development environment.
10530
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010531Maintainers commonly use ``-next`` branches to test submissions prior to
10532merging patches. Thus, you can get an idea of the status of a patch based on
10533whether the patch has been merged into one of these branches. The commonly
10534used testing branches for OpenEmbedded-Core are as follows:
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010535
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010536- *openembedded-core "master-next" branch:* This branch is part of the
10537 :oe_git:`openembedded-core </openembedded-core/>` repository and contains
10538 proposed changes to the core metadata.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010539
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010540- *poky "master-next" branch:* This branch is part of the
Andrew Geissler09209ee2020-12-13 08:44:15 -060010541 :yocto_git:`poky </poky/>` repository and combines proposed
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010542 changes to bitbake, the core metadata and the poky distro.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010543
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010544Similarly, stable branches maintained by the project may have corresponding
10545``-next`` branches which collect proposed changes. For example,
10546``&DISTRO_NAME_NO_CAP;-next`` and ``&DISTRO_NAME_NO_CAP_MINUS_ONE;-next``
10547branches in both the "openembdedded-core" and "poky" repositories.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010548
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010549Other layers may have similar testing branches but there is no formal
10550requirement or standard for these so please check the documentation for the
10551layers you are contributing to.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010552
10553The following sections provide procedures for submitting a change.
10554
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010555Preparing Changes for Submission
10556~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010557
105581. *Make Your Changes Locally:* Make your changes in your local Git
10559 repository. You should make small, controlled, isolated changes.
10560 Keeping changes small and isolated aids review, makes
10561 merging/rebasing easier and keeps the change history clean should
10562 anyone need to refer to it in future.
10563
105642. *Stage Your Changes:* Stage your changes by using the ``git add``
10565 command on each file you changed.
10566
105673. *Commit Your Changes:* Commit the change by using the ``git commit``
10568 command. Make sure your commit information follows standards by
10569 following these accepted conventions:
10570
10571 - Be sure to include a "Signed-off-by:" line in the same style as
10572 required by the Linux kernel. Adding this line signifies that you,
10573 the submitter, have agreed to the Developer's Certificate of
10574 Origin 1.1 as follows:
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010575
10576 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010577
10578 Developer's Certificate of Origin 1.1
10579
10580 By making a contribution to this project, I certify that:
10581
10582 (a) The contribution was created in whole or in part by me and I
10583 have the right to submit it under the open source license
10584 indicated in the file; or
10585
10586 (b) The contribution is based upon previous work that, to the best
10587 of my knowledge, is covered under an appropriate open source
10588 license and I have the right under that license to submit that
10589 work with modifications, whether created in whole or in part
10590 by me, under the same open source license (unless I am
10591 permitted to submit under a different license), as indicated
10592 in the file; or
10593
10594 (c) The contribution was provided directly to me by some other
10595 person who certified (a), (b) or (c) and I have not modified
10596 it.
10597
10598 (d) I understand and agree that this project and the contribution
10599 are public and that a record of the contribution (including all
10600 personal information I submit with it, including my sign-off) is
10601 maintained indefinitely and may be redistributed consistent with
10602 this project or the open source license(s) involved.
10603
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010604 - Provide a single-line summary of the change and, if more
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010605 explanation is needed, provide more detail in the body of the
10606 commit. This summary is typically viewable in the "shortlist" of
10607 changes. Thus, providing something short and descriptive that
10608 gives the reader a summary of the change is useful when viewing a
10609 list of many commits. You should prefix this short description
10610 with the recipe name (if changing a recipe), or else with the
10611 short form path to the file being changed.
10612
10613 - For the body of the commit message, provide detailed information
10614 that describes what you changed, why you made the change, and the
10615 approach you used. It might also be helpful if you mention how you
10616 tested the change. Provide as much detail as you can in the body
10617 of the commit message.
10618
10619 .. note::
10620
10621 You do not need to provide a more detailed explanation of a
10622 change if the change is minor to the point of the single line
10623 summary providing all the information.
10624
10625 - If the change addresses a specific bug or issue that is associated
10626 with a bug-tracking ID, include a reference to that ID in your
10627 detailed description. For example, the Yocto Project uses a
10628 specific convention for bug references - any commit that addresses
10629 a specific bug should use the following form for the detailed
10630 description. Be sure to use the actual bug-tracking ID from
Andrew Geisslerc926e172021-05-07 16:11:35 -050010631 Bugzilla for bug-id::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010632
10633 Fixes [YOCTO #bug-id]
10634
10635 detailed description of change
10636
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010637Using Email to Submit a Patch
10638~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10639
10640Depending on the components changed, you need to submit the email to a
10641specific mailing list. For some guidance on which mailing list to use,
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050010642see the
10643:ref:`list <dev-manual/common-tasks:submitting a change to the yocto project>`
10644at the beginning of this section. For a description of all the available
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010645mailing lists, see the ":ref:`Mailing Lists <resources-mailinglist>`" section in the
10646Yocto Project Reference Manual.
10647
10648Here is the general procedure on how to submit a patch through email
10649without using the scripts once the steps in
Andrew Geissler09209ee2020-12-13 08:44:15 -060010650:ref:`dev-manual/common-tasks:preparing changes for submission` have been followed:
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010651
106521. *Format the Commit:* Format the commit into an email message. To
10653 format commits, use the ``git format-patch`` command. When you
10654 provide the command, you must include a revision list or a number of
10655 patches as part of the command. For example, either of these two
10656 commands takes your most recent single commit and formats it as an
Andrew Geisslerc926e172021-05-07 16:11:35 -050010657 email message in the current directory::
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010658
10659 $ git format-patch -1
10660
10661 or ::
10662
10663 $ git format-patch HEAD~
10664
10665 After the command is run, the current directory contains a numbered
10666 ``.patch`` file for the commit.
10667
10668 If you provide several commits as part of the command, the
10669 ``git format-patch`` command produces a series of numbered files in
10670 the current directory – one for each commit. If you have more than
10671 one patch, you should also use the ``--cover`` option with the
10672 command, which generates a cover letter as the first "patch" in the
10673 series. You can then edit the cover letter to provide a description
10674 for the series of patches. For information on the
10675 ``git format-patch`` command, see ``GIT_FORMAT_PATCH(1)`` displayed
10676 using the ``man git-format-patch`` command.
10677
10678 .. note::
10679
10680 If you are or will be a frequent contributor to the Yocto Project
10681 or to OpenEmbedded, you might consider requesting a contrib area
10682 and the necessary associated rights.
10683
106842. *Send the patches via email:* Send the patches to the recipients and
10685 relevant mailing lists by using the ``git send-email`` command.
10686
10687 .. note::
10688
10689 In order to use ``git send-email``, you must have the proper Git packages
10690 installed on your host.
10691 For Ubuntu, Debian, and Fedora the package is ``git-email``.
10692
10693 The ``git send-email`` command sends email by using a local or remote
10694 Mail Transport Agent (MTA) such as ``msmtp``, ``sendmail``, or
10695 through a direct ``smtp`` configuration in your Git ``~/.gitconfig``
10696 file. If you are submitting patches through email only, it is very
10697 important that you submit them without any whitespace or HTML
10698 formatting that either you or your mailer introduces. The maintainer
10699 that receives your patches needs to be able to save and apply them
10700 directly from your emails. A good way to verify that what you are
10701 sending will be applicable by the maintainer is to do a dry run and
10702 send them to yourself and then save and apply them as the maintainer
10703 would.
10704
10705 The ``git send-email`` command is the preferred method for sending
10706 your patches using email since there is no risk of compromising
10707 whitespace in the body of the message, which can occur when you use
10708 your own mail client. The command also has several options that let
10709 you specify recipients and perform further editing of the email
10710 message. For information on how to use the ``git send-email``
10711 command, see ``GIT-SEND-EMAIL(1)`` displayed using the
10712 ``man git-send-email`` command.
10713
10714The Yocto Project uses a `Patchwork instance <https://patchwork.openembedded.org/>`__
10715to track the status of patches submitted to the various mailing lists and to
10716support automated patch testing. Each submitted patch is checked for common
10717mistakes and deviations from the expected patch format and submitters are
10718notified by patchtest if such mistakes are found. This process helps to
10719reduce the burden of patch review on maintainers.
10720
10721.. note::
10722
10723 This system is imperfect and changes can sometimes get lost in the flow.
10724 Asking about the status of a patch or change is reasonable if the change
10725 has been idle for a while with no feedback.
10726
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010727Using Scripts to Push a Change Upstream and Request a Pull
10728~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10729
10730For larger patch series it is preferable to send a pull request which not
10731only includes the patch but also a pointer to a branch that can be pulled
10732from. This involves making a local branch for your changes, pushing this
10733branch to an accessible repository and then using the ``create-pull-request``
10734and ``send-pull-request`` scripts from openembedded-core to create and send a
10735patch series with a link to the branch for review.
10736
10737Follow this procedure to push a change to an upstream "contrib" Git
Andrew Geissler09209ee2020-12-13 08:44:15 -060010738repository once the steps in :ref:`dev-manual/common-tasks:preparing changes for submission` have
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010739been followed:
10740
10741.. note::
10742
10743 You can find general Git information on how to push a change upstream
10744 in the
10745 `Git Community Book <https://git-scm.com/book/en/v2/Distributed-Git-Distributed-Workflows>`__.
10746
107471. *Push Your Commits to a "Contrib" Upstream:* If you have arranged for
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010748 permissions to push to an upstream contrib repository, push the
Andrew Geisslerc926e172021-05-07 16:11:35 -050010749 change to that repository::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010750
10751 $ git push upstream_remote_repo local_branch_name
10752
10753 For example, suppose you have permissions to push
10754 into the upstream ``meta-intel-contrib`` repository and you are
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010755 working in a local branch named `your_name`\ ``/README``. The following
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010756 command pushes your local commits to the ``meta-intel-contrib``
10757 upstream repository and puts the commit in a branch named
Andrew Geisslerc926e172021-05-07 16:11:35 -050010758 `your_name`\ ``/README``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010759
10760 $ git push meta-intel-contrib your_name/README
10761
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600107622. *Determine Who to Notify:* Determine the maintainer or the mailing
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010763 list that you need to notify for the change.
10764
10765 Before submitting any change, you need to be sure who the maintainer
10766 is or what mailing list that you need to notify. Use either these
10767 methods to find out:
10768
10769 - *Maintenance File:* Examine the ``maintainers.inc`` file, which is
10770 located in the :term:`Source Directory` at
10771 ``meta/conf/distro/include``, to see who is responsible for code.
10772
Andrew Geissler09209ee2020-12-13 08:44:15 -060010773 - *Search by File:* Using :ref:`overview-manual/development-environment:git`, you can
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010774 enter the following command to bring up a short list of all
Andrew Geisslerc926e172021-05-07 16:11:35 -050010775 commits against a specific file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010776
10777 git shortlog -- filename
10778
10779 Just provide the name of the file for which you are interested. The
10780 information returned is not ordered by history but does include a
10781 list of everyone who has committed grouped by name. From the list,
10782 you can see who is responsible for the bulk of the changes against
10783 the file.
10784
10785 - *Examine the List of Mailing Lists:* For a list of the Yocto
10786 Project and related mailing lists, see the ":ref:`Mailing
10787 lists <resources-mailinglist>`" section in
10788 the Yocto Project Reference Manual.
10789
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600107903. *Make a Pull Request:* Notify the maintainer or the mailing list that
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010791 you have pushed a change by making a pull request.
10792
10793 The Yocto Project provides two scripts that conveniently let you
10794 generate and send pull requests to the Yocto Project. These scripts
10795 are ``create-pull-request`` and ``send-pull-request``. You can find
10796 these scripts in the ``scripts`` directory within the
10797 :term:`Source Directory` (e.g.
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010798 ``poky/scripts``).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010799
10800 Using these scripts correctly formats the requests without
10801 introducing any whitespace or HTML formatting. The maintainer that
10802 receives your patches either directly or through the mailing list
10803 needs to be able to save and apply them directly from your emails.
10804 Using these scripts is the preferred method for sending patches.
10805
10806 First, create the pull request. For example, the following command
10807 runs the script, specifies the upstream repository in the contrib
10808 directory into which you pushed the change, and provides a subject
Andrew Geisslerc926e172021-05-07 16:11:35 -050010809 line in the created patch files::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010810
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010811 $ poky/scripts/create-pull-request -u meta-intel-contrib -s "Updated Manual Section Reference in README"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010812
10813 Running this script forms ``*.patch`` files in a folder named
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010814 ``pull-``\ `PID` in the current directory. One of the patch files is a
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010815 cover letter.
10816
10817 Before running the ``send-pull-request`` script, you must edit the
10818 cover letter patch to insert information about your change. After
10819 editing the cover letter, send the pull request. For example, the
10820 following command runs the script and specifies the patch directory
10821 and email address. In this example, the email address is a mailing
Andrew Geisslerc926e172021-05-07 16:11:35 -050010822 list::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010823
Andrew Geissler5199d832021-09-24 16:47:35 -050010824 $ poky/scripts/send-pull-request -p ~/meta-intel/pull-10565 -t meta-intel@lists.yoctoproject.org
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010825
10826 You need to follow the prompts as the script is interactive.
10827
10828 .. note::
10829
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010830 For help on using these scripts, simply provide the ``-h``
Andrew Geisslerc926e172021-05-07 16:11:35 -050010831 argument as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010832
10833 $ poky/scripts/create-pull-request -h
10834 $ poky/scripts/send-pull-request -h
10835
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010836Responding to Patch Review
10837~~~~~~~~~~~~~~~~~~~~~~~~~~
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010838
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010839You may get feedback on your submitted patches from other community members
10840or from the automated patchtest service. If issues are identified in your
10841patch then it is usually necessary to address these before the patch will be
10842accepted into the project. In this case you should amend the patch according
10843to the feedback and submit an updated version to the relevant mailing list,
10844copying in the reviewers who provided feedback to the previous version of the
10845patch.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010846
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010847The patch should be amended using ``git commit --amend`` or perhaps ``git
10848rebase`` for more expert git users. You should also modify the ``[PATCH]``
10849tag in the email subject line when sending the revised patch to mark the new
10850iteration as ``[PATCH v2]``, ``[PATCH v3]``, etc as appropriate. This can be
10851done by passing the ``-v`` argument to ``git format-patch`` with a version
10852number.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010853
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010854Lastly please ensure that you also test your revised changes. In particular
10855please don't just edit the patch file written out by ``git format-patch`` and
10856resend it.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010857
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010858Submitting Changes to Stable Release Branches
10859~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010860
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010861The process for proposing changes to a Yocto Project stable branch differs
10862from the steps described above. Changes to a stable branch must address
10863identified bugs or CVEs and should be made carefully in order to avoid the
10864risk of introducing new bugs or breaking backwards compatibility. Typically
10865bug fixes must already be accepted into the master branch before they can be
10866backported to a stable branch unless the bug in question does not affect the
10867master branch or the fix on the master branch is unsuitable for backporting.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010868
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010869The list of stable branches along with the status and maintainer for each
10870branch can be obtained from the
Andrew Geissler09209ee2020-12-13 08:44:15 -060010871:yocto_wiki:`Releases wiki page </Releases>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010872
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010873.. note::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010874
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010875 Changes will not typically be accepted for branches which are marked as
10876 End-Of-Life (EOL).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010877
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010878With this in mind, the steps to submit a change for a stable branch are as
10879follows:
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010880
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600108811. *Identify the bug or CVE to be fixed:* This information should be
10882 collected so that it can be included in your submission.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010883
Patrick Williams213cb262021-08-07 19:21:33 -050010884 See :ref:`dev-manual/common-tasks:checking for vulnerabilities`
10885 for details about CVE tracking.
10886
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600108872. *Check if the fix is already present in the master branch:* This will
10888 result in the most straightforward path into the stable branch for the
10889 fix.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010890
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010891 a. *If the fix is present in the master branch - Submit a backport request
10892 by email:* You should send an email to the relevant stable branch
10893 maintainer and the mailing list with details of the bug or CVE to be
10894 fixed, the commit hash on the master branch that fixes the issue and
10895 the stable branches which you would like this fix to be backported to.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010896
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010897 b. *If the fix is not present in the master branch - Submit the fix to the
10898 master branch first:* This will ensure that the fix passes through the
10899 project's usual patch review and test processes before being accepted.
10900 It will also ensure that bugs are not left unresolved in the master
10901 branch itself. Once the fix is accepted in the master branch a backport
10902 request can be submitted as above.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010903
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010904 c. *If the fix is unsuitable for the master branch - Submit a patch
10905 directly for the stable branch:* This method should be considered as a
10906 last resort. It is typically necessary when the master branch is using
10907 a newer version of the software which includes an upstream fix for the
10908 issue or when the issue has been fixed on the master branch in a way
10909 that introduces backwards incompatible changes. In this case follow the
Andrew Geissler09209ee2020-12-13 08:44:15 -060010910 steps in :ref:`dev-manual/common-tasks:preparing changes for submission` and
10911 :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 -060010912 email to include the name of the stable branch which you are
10913 targetting. This can be done using the ``--subject-prefix`` argument to
10914 ``git format-patch``, for example to submit a patch to the dunfell
10915 branch use
10916 ``git format-patch --subject-prefix='&DISTRO_NAME_NO_CAP_MINUS_ONE;][PATCH' ...``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010917
10918Working With Licenses
10919=====================
10920
Andrew Geissler09209ee2020-12-13 08:44:15 -060010921As mentioned in the ":ref:`overview-manual/development-environment:licensing`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010922section in the Yocto Project Overview and Concepts Manual, open source
10923projects are open to the public and they consequently have different
10924licensing structures in place. This section describes the mechanism by
10925which the :term:`OpenEmbedded Build System`
10926tracks changes to
10927licensing text and covers how to maintain open source license compliance
10928during your project's lifecycle. The section also describes how to
10929enable commercially licensed recipes, which by default are disabled.
10930
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010931Tracking License Changes
10932------------------------
10933
10934The license of an upstream project might change in the future. In order
10935to prevent these changes going unnoticed, the
10936:term:`LIC_FILES_CHKSUM`
10937variable tracks changes to the license text. The checksums are validated
10938at the end of the configure step, and if the checksums do not match, the
10939build will fail.
10940
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010941Specifying the ``LIC_FILES_CHKSUM`` Variable
10942~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10943
Andrew Geissler09036742021-06-25 14:25:14 -050010944The :term:`LIC_FILES_CHKSUM` variable contains checksums of the license text
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010945in the source code for the recipe. Following is an example of how to
Andrew Geissler09036742021-06-25 14:25:14 -050010946specify :term:`LIC_FILES_CHKSUM`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010947
10948 LIC_FILES_CHKSUM = "file://COPYING;md5=xxxx \
10949 file://licfile1.txt;beginline=5;endline=29;md5=yyyy \
10950 file://licfile2.txt;endline=50;md5=zzzz \
10951 ..."
10952
10953.. note::
10954
10955 - When using "beginline" and "endline", realize that line numbering
10956 begins with one and not zero. Also, the included lines are
10957 inclusive (i.e. lines five through and including 29 in the
10958 previous example for ``licfile1.txt``).
10959
10960 - When a license check fails, the selected license text is included
10961 as part of the QA message. Using this output, you can determine
10962 the exact start and finish for the needed license text.
10963
10964The build system uses the :term:`S`
10965variable as the default directory when searching files listed in
Andrew Geissler09036742021-06-25 14:25:14 -050010966:term:`LIC_FILES_CHKSUM`. The previous example employs the default
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010967directory.
10968
Andrew Geisslerc926e172021-05-07 16:11:35 -050010969Consider this next example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010970
10971 LIC_FILES_CHKSUM = "file://src/ls.c;beginline=5;endline=16;\
10972 md5=bb14ed3c4cda583abc85401304b5cd4e"
10973 LIC_FILES_CHKSUM = "file://${WORKDIR}/license.html;md5=5c94767cedb5d6987c902ac850ded2c6"
10974
10975The first line locates a file in ``${S}/src/ls.c`` and isolates lines
10976five through 16 as license text. The second line refers to a file in
10977:term:`WORKDIR`.
10978
Andrew Geissler09036742021-06-25 14:25:14 -050010979Note that :term:`LIC_FILES_CHKSUM` variable is mandatory for all recipes,
10980unless the :term:`LICENSE` variable is set to "CLOSED".
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010981
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010982Explanation of Syntax
10983~~~~~~~~~~~~~~~~~~~~~
10984
Andrew Geissler09036742021-06-25 14:25:14 -050010985As mentioned in the previous section, the :term:`LIC_FILES_CHKSUM` variable
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010986lists all the important files that contain the license text for the
10987source code. It is possible to specify a checksum for an entire file, or
10988a specific section of a file (specified by beginning and ending line
10989numbers with the "beginline" and "endline" parameters, respectively).
10990The latter is useful for source files with a license notice header,
10991README documents, and so forth. If you do not use the "beginline"
10992parameter, then it is assumed that the text begins on the first line of
10993the file. Similarly, if you do not use the "endline" parameter, it is
10994assumed that the license text ends with the last line of the file.
10995
10996The "md5" parameter stores the md5 checksum of the license text. If the
10997license text changes in any way as compared to this parameter then a
10998mismatch occurs. This mismatch triggers a build failure and notifies the
10999developer. Notification allows the developer to review and address the
11000license text changes. Also note that if a mismatch occurs during the
11001build, the correct md5 checksum is placed in the build log and can be
11002easily copied to the recipe.
11003
11004There is no limit to how many files you can specify using the
Andrew Geissler09036742021-06-25 14:25:14 -050011005:term:`LIC_FILES_CHKSUM` variable. Generally, however, every project
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011006requires a few specifications for license tracking. Many projects have a
11007"COPYING" file that stores the license information for all the source
11008code files. This practice allows you to just track the "COPYING" file as
11009long as it is kept up to date.
11010
11011.. note::
11012
11013 - If you specify an empty or invalid "md5" parameter,
11014 :term:`BitBake` returns an md5
11015 mis-match error and displays the correct "md5" parameter value
11016 during the build. The correct parameter is also captured in the
11017 build log.
11018
11019 - If the whole file contains only license text, you do not need to
11020 use the "beginline" and "endline" parameters.
11021
11022Enabling Commercially Licensed Recipes
11023--------------------------------------
11024
11025By default, the OpenEmbedded build system disables components that have
11026commercial or other special licensing requirements. Such requirements
11027are defined on a recipe-by-recipe basis through the
11028:term:`LICENSE_FLAGS` variable
11029definition in the affected recipe. For instance, the
11030``poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly`` recipe
Andrew Geisslerc926e172021-05-07 16:11:35 -050011031contains the following statement::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011032
11033 LICENSE_FLAGS = "commercial"
11034
11035Here is a
11036slightly more complicated example that contains both an explicit recipe
Andrew Geisslerc926e172021-05-07 16:11:35 -050011037name and version (after variable expansion)::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011038
11039 LICENSE_FLAGS = "license_${PN}_${PV}"
11040
11041In order for a component restricted by a
Andrew Geissler09036742021-06-25 14:25:14 -050011042:term:`LICENSE_FLAGS` definition to be enabled and included in an image, it
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011043needs to have a matching entry in the global
11044:term:`LICENSE_FLAGS_WHITELIST`
11045variable, which is a variable typically defined in your ``local.conf``
11046file. For example, to enable the
11047``poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly`` package, you
11048could add either the string "commercial_gst-plugins-ugly" or the more
Andrew Geissler09036742021-06-25 14:25:14 -050011049general string "commercial" to :term:`LICENSE_FLAGS_WHITELIST`. See the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050011050":ref:`dev-manual/common-tasks:license flag matching`" section for a full
Andrew Geissler09036742021-06-25 14:25:14 -050011051explanation of how :term:`LICENSE_FLAGS` matching works. Here is the
Andrew Geisslerc926e172021-05-07 16:11:35 -050011052example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011053
11054 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly"
11055
11056Likewise, to additionally enable the package built from the recipe
11057containing ``LICENSE_FLAGS = "license_${PN}_${PV}"``, and assuming that
11058the actual recipe name was ``emgd_1.10.bb``, the following string would
11059enable that package as well as the original ``gst-plugins-ugly``
Andrew Geisslerc926e172021-05-07 16:11:35 -050011060package::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011061
11062 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly license_emgd_1.10"
11063
11064As a convenience, you do not need to specify the
Andrew Geissler595f6302022-01-24 19:11:47 +000011065complete license string for every package. You can use
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011066an abbreviated form, which consists of just the first portion or
11067portions of the license string before the initial underscore character
11068or characters. A partial string will match any license that contains the
11069given string as the first portion of its license. For example, the
Andrew Geissler595f6302022-01-24 19:11:47 +000011070following value will also match both of the packages
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011071previously mentioned as well as any other packages that have licenses
11072starting with "commercial" or "license".
11073::
11074
11075 LICENSE_FLAGS_WHITELIST = "commercial license"
11076
11077License Flag Matching
11078~~~~~~~~~~~~~~~~~~~~~
11079
11080License flag matching allows you to control what recipes the
11081OpenEmbedded build system includes in the build. Fundamentally, the
Andrew Geissler09036742021-06-25 14:25:14 -050011082build system attempts to match :term:`LICENSE_FLAGS` strings found in
Andrew Geissler595f6302022-01-24 19:11:47 +000011083recipes against strings found in :term:`LICENSE_FLAGS_WHITELIST`.
11084A match causes the build system to include a recipe in the
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011085build, while failure to find a match causes the build system to exclude
11086a recipe.
11087
11088In general, license flag matching is simple. However, understanding some
11089concepts will help you correctly and effectively use matching.
11090
11091Before a flag defined by a particular recipe is tested against the
Andrew Geissler595f6302022-01-24 19:11:47 +000011092entries of :term:`LICENSE_FLAGS_WHITELIST`, the expanded
11093string ``_${PN}`` is appended to the flag. This expansion makes each
11094:term:`LICENSE_FLAGS` value recipe-specific. After expansion, the
11095string is then matched against the entries. Thus, specifying
11096``LICENSE_FLAGS = "commercial"`` in recipe "foo", for example, results
11097in the string ``"commercial_foo"``. And, to create a match, that string
11098must appear among the entries of :term:`LICENSE_FLAGS_WHITELIST`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011099
Andrew Geissler09036742021-06-25 14:25:14 -050011100Judicious use of the :term:`LICENSE_FLAGS` strings and the contents of the
11101:term:`LICENSE_FLAGS_WHITELIST` variable allows you a lot of flexibility for
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011102including or excluding recipes based on licensing. For example, you can
11103broaden the matching capabilities by using license flags string subsets
Andrew Geissler595f6302022-01-24 19:11:47 +000011104in :term:`LICENSE_FLAGS_WHITELIST`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011105
11106.. note::
11107
11108 When using a string subset, be sure to use the part of the expanded
11109 string that precedes the appended underscore character (e.g.
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011110 ``usethispart_1.3``, ``usethispart_1.4``, and so forth).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011111
Andrew Geissler595f6302022-01-24 19:11:47 +000011112For example, simply specifying the string "commercial" in the
11113:term:`LICENSE_FLAGS_WHITELIST` variable matches any expanded
11114:term:`LICENSE_FLAGS` definition that starts with the string
11115"commercial" such as "commercial_foo" and "commercial_bar", which
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011116are the strings the build system automatically generates for
11117hypothetical recipes named "foo" and "bar" assuming those recipes simply
Andrew Geisslerc926e172021-05-07 16:11:35 -050011118specify the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011119
11120 LICENSE_FLAGS = "commercial"
11121
Andrew Geissler595f6302022-01-24 19:11:47 +000011122Thus, you can choose to exhaustively enumerate each license flag in the
11123list and allow only specific recipes into the image, or you can use a
11124string subset that causes a broader range of matches to allow a range of
11125recipes into the image.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011126
Andrew Geissler09036742021-06-25 14:25:14 -050011127This scheme works even if the :term:`LICENSE_FLAGS` string already has
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011128``_${PN}`` appended. For example, the build system turns the license
11129flag "commercial_1.2_foo" into "commercial_1.2_foo_foo" and would match
11130both the general "commercial" and the specific "commercial_1.2_foo"
Andrew Geissler595f6302022-01-24 19:11:47 +000011131strings found in the :term:`LICENSE_FLAGS_WHITELIST` variable, as expected.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011132
11133Here are some other scenarios:
11134
11135- You can specify a versioned string in the recipe such as
11136 "commercial_foo_1.2" in a "foo" recipe. The build system expands this
11137 string to "commercial_foo_1.2_foo". Combine this license flag with a
Andrew Geissler595f6302022-01-24 19:11:47 +000011138 :term:`LICENSE_FLAGS_WHITELIST` variable that has the string
11139 "commercial" and you match the flag along with any other flag that
11140 starts with the string "commercial".
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011141
Andrew Geissler595f6302022-01-24 19:11:47 +000011142- Under the same circumstances, you can add "commercial_foo" in the
11143 :term:`LICENSE_FLAGS_WHITELIST` variable and the build system not only
11144 matches "commercial_foo_1.2" but also matches any license flag with
11145 the string "commercial_foo", regardless of the version.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011146
11147- You can be very specific and use both the package and version parts
Andrew Geissler595f6302022-01-24 19:11:47 +000011148 in the :term:`LICENSE_FLAGS_WHITELIST` list (e.g.
11149 "commercial_foo_1.2") to specifically match a versioned recipe.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011150
11151Other Variables Related to Commercial Licenses
11152~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11153
William A. Kennington IIIac69b482021-06-02 12:28:27 -070011154There are other helpful variables related to commercial license handling,
11155defined in the
Andrew Geisslerc926e172021-05-07 16:11:35 -050011156``poky/meta/conf/distro/include/default-distrovars.inc`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011157
11158 COMMERCIAL_AUDIO_PLUGINS ?= ""
11159 COMMERCIAL_VIDEO_PLUGINS ?= ""
11160
11161If you
11162want to enable these components, you can do so by making sure you have
11163statements similar to the following in your ``local.conf`` configuration
Andrew Geisslerc926e172021-05-07 16:11:35 -050011164file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011165
11166 COMMERCIAL_AUDIO_PLUGINS = "gst-plugins-ugly-mad \
11167 gst-plugins-ugly-mpegaudioparse"
11168 COMMERCIAL_VIDEO_PLUGINS = "gst-plugins-ugly-mpeg2dec \
11169 gst-plugins-ugly-mpegstream gst-plugins-bad-mpegvideoparse"
11170 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly commercial_gst-plugins-bad commercial_qmmp"
11171
11172
Andrew Geissler595f6302022-01-24 19:11:47 +000011173Of course, you could also create a matching list for those
11174components using the more general "commercial" in the
11175:term:`LICENSE_FLAGS_WHITELIST` variable, but that would also enable all
11176the other packages with :term:`LICENSE_FLAGS`
Andrew Geisslerc926e172021-05-07 16:11:35 -050011177containing "commercial", which you may or may not want::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011178
11179 LICENSE_FLAGS_WHITELIST = "commercial"
11180
11181Specifying audio and video plugins as part of the
11182``COMMERCIAL_AUDIO_PLUGINS`` and ``COMMERCIAL_VIDEO_PLUGINS`` statements
Andrew Geissler09036742021-06-25 14:25:14 -050011183(along with the enabling :term:`LICENSE_FLAGS_WHITELIST`) includes the
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011184plugins or components into built images, thus adding support for media
11185formats or components.
11186
11187Maintaining Open Source License Compliance During Your Product's Lifecycle
11188--------------------------------------------------------------------------
11189
11190One of the concerns for a development organization using open source
11191software is how to maintain compliance with various open source
11192licensing during the lifecycle of the product. While this section does
11193not provide legal advice or comprehensively cover all scenarios, it does
11194present methods that you can use to assist you in meeting the compliance
11195requirements during a software release.
11196
11197With hundreds of different open source licenses that the Yocto Project
11198tracks, it is difficult to know the requirements of each and every
11199license. However, the requirements of the major FLOSS licenses can begin
William A. Kennington IIIac69b482021-06-02 12:28:27 -070011200to be covered by assuming that there are three main areas of concern:
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011201
11202- Source code must be provided.
11203
11204- License text for the software must be provided.
11205
11206- Compilation scripts and modifications to the source code must be
11207 provided.
11208
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011209- spdx files can be provided.
11210
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011211There are other requirements beyond the scope of these three and the
11212methods described in this section (e.g. the mechanism through which
11213source code is distributed).
11214
11215As different organizations have different methods of complying with open
11216source licensing, this section is not meant to imply that there is only
11217one single way to meet your compliance obligations, but rather to
11218describe one method of achieving compliance. The remainder of this
11219section describes methods supported to meet the previously mentioned
11220three requirements. Once you take steps to meet these requirements, and
11221prior to releasing images, sources, and the build system, you should
11222audit all artifacts to ensure completeness.
11223
11224.. note::
11225
11226 The Yocto Project generates a license manifest during image creation
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011227 that is located in ``${DEPLOY_DIR}/licenses/``\ `image_name`\ ``-``\ `datestamp`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011228 to assist with any audits.
11229
11230Providing the Source Code
11231~~~~~~~~~~~~~~~~~~~~~~~~~
11232
11233Compliance activities should begin before you generate the final image.
11234The first thing you should look at is the requirement that tops the list
11235for most compliance groups - providing the source. The Yocto Project has
11236a few ways of meeting this requirement.
11237
11238One of the easiest ways to meet this requirement is to provide the
11239entire :term:`DL_DIR` used by the
11240build. This method, however, has a few issues. The most obvious is the
11241size of the directory since it includes all sources used in the build
11242and not just the source used in the released image. It will include
11243toolchain source, and other artifacts, which you would not generally
11244release. However, the more serious issue for most companies is
11245accidental release of proprietary software. The Yocto Project provides
11246an :ref:`archiver <ref-classes-archiver>` class to
11247help avoid some of these concerns.
11248
Andrew Geissler595f6302022-01-24 19:11:47 +000011249Before you employ :term:`DL_DIR` or the :ref:`archiver <ref-classes-archiver>` class, you need to
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011250decide how you choose to provide source. The source ``archiver`` class
11251can generate tarballs and SRPMs and can create them with various levels
11252of compliance in mind.
11253
11254One way of doing this (but certainly not the only way) is to release
11255just the source as a tarball. You can do this by adding the following to
11256the ``local.conf`` file found in the
Andrew Geisslerc926e172021-05-07 16:11:35 -050011257:term:`Build Directory`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011258
11259 INHERIT += "archiver"
11260 ARCHIVER_MODE[src] = "original"
11261
11262During the creation of your
11263image, the source from all recipes that deploy packages to the image is
11264placed within subdirectories of ``DEPLOY_DIR/sources`` based on the
11265:term:`LICENSE` for each recipe.
11266Releasing the entire directory enables you to comply with requirements
11267concerning providing the unmodified source. It is important to note that
11268the size of the directory can get large.
11269
11270A way to help mitigate the size issue is to only release tarballs for
11271licenses that require the release of source. Let us assume you are only
11272concerned with GPL code as identified by running the following script:
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011273
11274.. code-block:: shell
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011275
11276 # Script to archive a subset of packages matching specific license(s)
11277 # Source and license files are copied into sub folders of package folder
11278 # Must be run from build folder
11279 #!/bin/bash
11280 src_release_dir="source-release"
11281 mkdir -p $src_release_dir
11282 for a in tmp/deploy/sources/*; do
11283 for d in $a/*; do
11284 # Get package name from path
11285 p=`basename $d`
11286 p=${p%-*}
11287 p=${p%-*}
11288 # Only archive GPL packages (update *GPL* regex for your license check)
11289 numfiles=`ls tmp/deploy/licenses/$p/*GPL* 2> /dev/null | wc -l`
Patrick Williams213cb262021-08-07 19:21:33 -050011290 if [ $numfiles -ge 1 ]; then
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011291 echo Archiving $p
11292 mkdir -p $src_release_dir/$p/source
11293 cp $d/* $src_release_dir/$p/source 2> /dev/null
11294 mkdir -p $src_release_dir/$p/license
11295 cp tmp/deploy/licenses/$p/* $src_release_dir/$p/license 2> /dev/null
11296 fi
11297 done
11298 done
11299
11300At this point, you
11301could create a tarball from the ``gpl_source_release`` directory and
11302provide that to the end user. This method would be a step toward
11303achieving compliance with section 3a of GPLv2 and with section 6 of
11304GPLv3.
11305
11306Providing License Text
11307~~~~~~~~~~~~~~~~~~~~~~
11308
11309One requirement that is often overlooked is inclusion of license text.
11310This requirement also needs to be dealt with prior to generating the
11311final image. Some licenses require the license text to accompany the
11312binary. You can achieve this by adding the following to your
Andrew Geisslerc926e172021-05-07 16:11:35 -050011313``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011314
11315 COPY_LIC_MANIFEST = "1"
11316 COPY_LIC_DIRS = "1"
11317 LICENSE_CREATE_PACKAGE = "1"
11318
11319Adding these statements to the
11320configuration file ensures that the licenses collected during package
11321generation are included on your image.
11322
11323.. note::
11324
11325 Setting all three variables to "1" results in the image having two
11326 copies of the same license file. One copy resides in
11327 ``/usr/share/common-licenses`` and the other resides in
11328 ``/usr/share/license``.
11329
11330 The reason for this behavior is because
11331 :term:`COPY_LIC_DIRS` and
11332 :term:`COPY_LIC_MANIFEST`
11333 add a copy of the license when the image is built but do not offer a
11334 path for adding licenses for newly installed packages to an image.
11335 :term:`LICENSE_CREATE_PACKAGE`
11336 adds a separate package and an upgrade path for adding licenses to an
11337 image.
11338
11339As the source ``archiver`` class has already archived the original
11340unmodified source that contains the license files, you would have
11341already met the requirements for inclusion of the license information
11342with source as defined by the GPL and other open source licenses.
11343
11344Providing Compilation Scripts and Source Code Modifications
11345~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11346
11347At this point, we have addressed all we need to prior to generating the
11348image. The next two requirements are addressed during the final
11349packaging of the release.
11350
11351By releasing the version of the OpenEmbedded build system and the layers
11352used during the build, you will be providing both compilation scripts
11353and the source code modifications in one step.
11354
Andrew Geissler09209ee2020-12-13 08:44:15 -060011355If the deployment team has a :ref:`overview-manual/concepts:bsp layer`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011356and a distro layer, and those
11357those layers are used to patch, compile, package, or modify (in any way)
11358any open source software included in your released images, you might be
11359required to release those layers under section 3 of GPLv2 or section 1
11360of GPLv3. One way of doing that is with a clean checkout of the version
11361of the Yocto Project and layers used during your build. Here is an
11362example:
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011363
11364.. code-block:: shell
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011365
11366 # We built using the dunfell branch of the poky repo
11367 $ git clone -b dunfell git://git.yoctoproject.org/poky
11368 $ cd poky
11369 # We built using the release_branch for our layers
11370 $ git clone -b release_branch git://git.mycompany.com/meta-my-bsp-layer
11371 $ git clone -b release_branch git://git.mycompany.com/meta-my-software-layer
11372 # clean up the .git repos
11373 $ find . -name ".git" -type d -exec rm -rf {} \;
11374
11375One
11376thing a development organization might want to consider for end-user
11377convenience is to modify ``meta-poky/conf/bblayers.conf.sample`` to
11378ensure that when the end user utilizes the released build system to
11379build an image, the development organization's layers are included in
Andrew Geisslerc926e172021-05-07 16:11:35 -050011380the ``bblayers.conf`` file automatically::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011381
11382 # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
11383 # changes incompatibly
11384 POKY_BBLAYERS_CONF_VERSION = "2"
11385
11386 BBPATH = "${TOPDIR}"
11387 BBFILES ?= ""
11388
11389 BBLAYERS ?= " \
11390 ##OEROOT##/meta \
11391 ##OEROOT##/meta-poky \
11392 ##OEROOT##/meta-yocto-bsp \
11393 ##OEROOT##/meta-mylayer \
11394 "
11395
11396Creating and
11397providing an archive of the :term:`Metadata`
11398layers (recipes, configuration files, and so forth) enables you to meet
11399your requirements to include the scripts to control compilation as well
11400as any modifications to the original source.
11401
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011402Providing spdx files
11403~~~~~~~~~~~~~~~~~~~~~~~~~
11404
11405The spdx module has been integrated to a layer named meta-spdxscanner.
11406meta-spdxscanner provides several kinds of scanner. If you want to enable
11407this function, you have to follow the following steps:
11408
114091. Add meta-spdxscanner layer into ``bblayers.conf``.
11410
114112. Refer to the README in meta-spdxscanner to setup the environment (e.g,
11412 setup a fossology server) needed for the scanner.
11413
114143. Meta-spdxscanner provides several methods within the bbclass to create spdx files.
11415 Please choose one that you want to use and enable the spdx task. You have to
11416 add some config options in ``local.conf`` file in your :term:`Build
William A. Kennington IIIac69b482021-06-02 12:28:27 -070011417 Directory`. Here is an example showing how to generate spdx files
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011418 during bitbake using the fossology-python.bbclass::
11419
11420 # Select fossology-python.bbclass.
11421 INHERIT += "fossology-python"
11422 # For fossology-python.bbclass, TOKEN is necessary, so, after setup a
11423 # Fossology server, you have to create a token.
11424 TOKEN = "eyJ0eXAiO..."
11425 # The fossology server is necessary for fossology-python.bbclass.
11426 FOSSOLOGY_SERVER = "http://xx.xx.xx.xx:8081/repo"
11427 # If you want to upload the source code to a special folder:
11428 FOLDER_NAME = "xxxx" //Optional
11429 # If you don't want to put spdx files in tmp/deploy/spdx, you can enable:
11430 SPDX_DEPLOY_DIR = "${DEPLOY_DIR}" //Optional
11431
11432For more usage information refer to :yocto_git:`the meta-spdxscanner repository
Andrew Geissler09209ee2020-12-13 08:44:15 -060011433</meta-spdxscanner/>`.
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011434
Andrew Geisslereff27472021-10-29 15:35:00 -050011435Compliance Limitations with Executables Built from Static Libraries
11436~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011437
Andrew Geisslereff27472021-10-29 15:35:00 -050011438When package A is added to an image via the :term:`RDEPENDS` or :term:`RRECOMMENDS`
11439mechanisms as well as explicitly included in the image recipe with
11440:term:`IMAGE_INSTALL`, and depends on a static linked library recipe B
11441(``DEPENDS += "B"``), package B will neither appear in the generated license
11442manifest nor in the generated source tarballs. This occurs as the
11443:ref:`license <ref-classes-license>` and :ref:`archiver <ref-classes-archiver>`
11444classes assume that only packages included via :term:`RDEPENDS` or :term:`RRECOMMENDS`
11445end up in the image.
11446
11447As a result, potential obligations regarding license compliance for package B
11448may not be met.
11449
11450The Yocto Project doesn't enable static libraries by default, in part because
11451of this issue. Before a solution to this limitation is found, you need to
11452keep in mind that if your root filesystem is built from static libraries,
11453you will need to manually ensure that your deliveries are compliant
11454with the licenses of these libraries.
11455
11456Copying Non Standard Licenses
11457-----------------------------
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011458
11459Some packages, such as the linux-firmware package, have many licenses
11460that are not in any way common. You can avoid adding a lot of these
11461types of common license files, which are only applicable to a specific
11462package, by using the
11463:term:`NO_GENERIC_LICENSE`
11464variable. Using this variable also avoids QA errors when you use a
11465non-common, non-CLOSED license in a recipe.
11466
William A. Kennington IIIac69b482021-06-02 12:28:27 -070011467Here is an example that uses the ``LICENSE.Abilis.txt`` file as
Andrew Geisslerc926e172021-05-07 16:11:35 -050011468the license from the fetched source::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011469
11470 NO_GENERIC_LICENSE[Firmware-Abilis] = "LICENSE.Abilis.txt"
11471
Patrick Williams213cb262021-08-07 19:21:33 -050011472Checking for Vulnerabilities
11473============================
11474
11475Vulnerabilities in images
11476-------------------------
11477
11478The Yocto Project has an infrastructure to track and address unfixed
11479known security vulnerabilities, as tracked by the public
11480`Common Vulnerabilities and Exposures (CVE) <https://en.wikipedia.org/wiki/Common_Vulnerabilities_and_Exposures>`__
11481database.
11482
11483To know which packages are vulnerable to known security vulnerabilities,
11484add the following setting to your configuration::
11485
11486 INHERIT += "cve-check"
11487
11488This way, at build time, BitBake will warn you about known CVEs
11489as in the example below::
11490
11491 WARNING: flex-2.6.4-r0 do_cve_check: Found unpatched CVE (CVE-2019-6293), for more information check /poky/build/tmp/work/core2-64-poky-linux/flex/2.6.4-r0/temp/cve.log
11492 WARNING: libarchive-3.5.1-r0 do_cve_check: Found unpatched CVE (CVE-2021-36976), for more information check /poky/build/tmp/work/core2-64-poky-linux/libarchive/3.5.1-r0/temp/cve.log
11493
11494It is also possible to check the CVE status of individual packages as follows::
11495
11496 bitbake -c cve_check flex libarchive
11497
11498Note that OpenEmbedded-Core keeps a list of known unfixed CVE issues which can
11499be ignored. You can pass this list to the check as follows::
11500
11501 bitbake -c cve_check libarchive -R conf/distro/include/cve-extra-exclusions.inc
11502
11503Enabling vulnerabily tracking in recipes
11504----------------------------------------
11505
11506The :term:`CVE_PRODUCT` variable defines the name used to match the recipe name
11507against the name in the upstream `NIST CVE database <https://nvd.nist.gov/>`__.
11508
Patrick Williams0ca19cc2021-08-16 14:03:13 -050011509Editing recipes to fix vulnerabilities
11510--------------------------------------
11511
11512To fix a given known vulnerability, you need to add a patch file to your recipe. Here's
11513an example from the :oe_layerindex:`ffmpeg recipe</layerindex/recipe/47350>`::
11514
11515 SRC_URI = "https://www.ffmpeg.org/releases/${BP}.tar.xz \
11516 file://0001-libavutil-include-assembly-with-full-path-from-sourc.patch \
11517 file://fix-CVE-2020-20446.patch \
11518 file://fix-CVE-2020-20453.patch \
11519 file://fix-CVE-2020-22015.patch \
11520 file://fix-CVE-2020-22021.patch \
11521 file://fix-CVE-2020-22033-CVE-2020-22019.patch \
11522 file://fix-CVE-2021-33815.patch \
11523
11524The :ref:`cve-check <ref-classes-cve-check>` class defines two ways of
11525supplying a patch for a given CVE. The first
11526way is to use a patch filename that matches the below pattern::
11527
11528 cve_file_name_match = re.compile(".*([Cc][Vv][Ee]\-\d{4}\-\d+)")
11529
11530As shown in the example above, multiple CVE IDs can appear in a patch filename,
11531but the :ref:`cve-check <ref-classes-cve-check>` class will only consider
11532the last CVE ID in the filename as patched.
11533
11534The second way to recognize a patched CVE ID is when a line matching the
11535below pattern is found in any patch file provided by the recipe::
11536
11537 cve_match = re.compile("CVE:( CVE\-\d{4}\-\d+)+")
11538
11539This allows a single patch file to address multiple CVE IDs at the same time.
11540
11541Of course, another way to fix vulnerabilities is to upgrade to a version
11542of the package which is not impacted, typically a more recent one.
11543The NIST database knows which versions are vulnerable and which ones
11544are not.
11545
11546Last but not least, you can choose to ignore vulnerabilities through
11547the :term:`CVE_CHECK_PN_WHITELIST` and :term:`CVE_CHECK_WHITELIST`
11548variables.
11549
11550Implementation details
11551----------------------
11552
11553Here's what the :ref:`cve-check <ref-classes-cve-check>` class does to
11554find unpatched CVE IDs.
11555
11556First the code goes through each patch file provided by a recipe. If a valid CVE ID
11557is found in the name of the file, the corresponding CVE is considered as patched.
11558Don't forget that if multiple CVE IDs are found in the filename, only the last
11559one is considered. Then, the code looks for ``CVE: CVE-ID`` lines in the patch
11560file. The found CVE IDs are also considered as patched.
11561
11562Then, the code looks up all the CVE IDs in the NIST database for all the
11563products defined in :term:`CVE_PRODUCT`. Then, for each found CVE:
11564
11565 - If the package name (:term:`PN`) is part of
11566 :term:`CVE_CHECK_PN_WHITELIST`, it is considered as patched.
11567
11568 - If the CVE ID is part of :term:`CVE_CHECK_WHITELIST`, it is
11569 considered as patched too.
11570
11571 - If the CVE ID is part of the patched CVE for the recipe, it is
11572 already considered as patched.
11573
11574 - Otherwise, the code checks whether the recipe version (:term:`PV`)
11575 is within the range of versions impacted by the CVE. If so, the CVE
11576 is considered as unpatched.
11577
Patrick Williams213cb262021-08-07 19:21:33 -050011578The CVE database is stored in :term:`DL_DIR` and can be inspected using
11579``sqlite3`` command as follows::
11580
11581 sqlite3 downloads/CVE_CHECK/nvdcve_1.1.db .dump | grep CVE-2021-37462
11582
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011583Using the Error Reporting Tool
11584==============================
11585
11586The error reporting tool allows you to submit errors encountered during
11587builds to a central database. Outside of the build environment, you can
11588use a web interface to browse errors, view statistics, and query for
11589errors. The tool works using a client-server system where the client
11590portion is integrated with the installed Yocto Project
11591:term:`Source Directory` (e.g. ``poky``).
11592The server receives the information collected and saves it in a
11593database.
11594
William A. Kennington IIIac69b482021-06-02 12:28:27 -070011595There is a live instance of the error reporting server at
11596https://errors.yoctoproject.org.
11597When you want to get help with build failures, you can submit all of the
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011598information on the failure easily and then point to the URL in your bug
11599report or send an email to the mailing list.
11600
11601.. note::
11602
11603 If you send error reports to this server, the reports become publicly
11604 visible.
11605
11606Enabling and Using the Tool
11607---------------------------
11608
11609By default, the error reporting tool is disabled. You can enable it by
11610inheriting the
11611:ref:`report-error <ref-classes-report-error>`
11612class by adding the following statement to the end of your
11613``local.conf`` file in your
11614:term:`Build Directory`.
11615::
11616
11617 INHERIT += "report-error"
11618
11619By default, the error reporting feature stores information in
11620``${``\ :term:`LOG_DIR`\ ``}/error-report``.
11621However, you can specify a directory to use by adding the following to
Andrew Geisslerc926e172021-05-07 16:11:35 -050011622your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011623
11624 ERR_REPORT_DIR = "path"
11625
11626Enabling error
11627reporting causes the build process to collect the errors and store them
11628in a file as previously described. When the build system encounters an
11629error, it includes a command as part of the console output. You can run
11630the command to send the error file to the server. For example, the
Andrew Geisslerc926e172021-05-07 16:11:35 -050011631following command sends the errors to an upstream server::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011632
11633 $ send-error-report /home/brandusa/project/poky/build/tmp/log/error-report/error_report_201403141617.txt
11634
11635In the previous example, the errors are sent to a public database
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011636available at https://errors.yoctoproject.org, which is used by the
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011637entire community. If you specify a particular server, you can send the
11638errors to a different database. Use the following command for more
Andrew Geisslerc926e172021-05-07 16:11:35 -050011639information on available options::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011640
11641 $ send-error-report --help
11642
11643When sending the error file, you are prompted to review the data being
11644sent as well as to provide a name and optional email address. Once you
11645satisfy these prompts, the command returns a link from the server that
11646corresponds to your entry in the database. For example, here is a
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011647typical link: https://errors.yoctoproject.org/Errors/Details/9522/
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011648
11649Following the link takes you to a web interface where you can browse,
11650query the errors, and view statistics.
11651
11652Disabling the Tool
11653------------------
11654
11655To disable the error reporting feature, simply remove or comment out the
11656following statement from the end of your ``local.conf`` file in your
11657:term:`Build Directory`.
11658::
11659
11660 INHERIT += "report-error"
11661
11662Setting Up Your Own Error Reporting Server
11663------------------------------------------
11664
11665If you want to set up your own error reporting server, you can obtain
Andrew Geissler09209ee2020-12-13 08:44:15 -060011666the code from the Git repository at :yocto_git:`/error-report-web/`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011667Instructions on how to set it up are in the README document.
11668
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011669Using Wayland and Weston
11670========================
11671
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011672`Wayland <https://en.wikipedia.org/wiki/Wayland_(display_server_protocol)>`__
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011673is a computer display server protocol that provides a method for
11674compositing window managers to communicate directly with applications
11675and video hardware and expects them to communicate with input hardware
11676using other libraries. Using Wayland with supporting targets can result
11677in better control over graphics frame rendering than an application
11678might otherwise achieve.
11679
11680The Yocto Project provides the Wayland protocol libraries and the
11681reference
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011682`Weston <https://en.wikipedia.org/wiki/Wayland_(display_server_protocol)#Weston>`__
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011683compositor as part of its release. You can find the integrated packages
11684in the ``meta`` layer of the :term:`Source Directory`.
11685Specifically, you
11686can find the recipes that build both Wayland and Weston at
11687``meta/recipes-graphics/wayland``.
11688
11689You can build both the Wayland and Weston packages for use only with
11690targets that accept the `Mesa 3D and Direct Rendering
11691Infrastructure <https://en.wikipedia.org/wiki/Mesa_(computer_graphics)>`__,
11692which is also known as Mesa DRI. This implies that you cannot build and
11693use the packages if your target uses, for example, the Intel Embedded
11694Media and Graphics Driver (Intel EMGD) that overrides Mesa DRI.
11695
11696.. note::
11697
11698 Due to lack of EGL support, Weston 1.0.3 will not run directly on the
11699 emulated QEMU hardware. However, this version of Weston will run
11700 under X emulation without issues.
11701
11702This section describes what you need to do to implement Wayland and use
11703the Weston compositor when building an image for a supporting target.
11704
11705Enabling Wayland in an Image
11706----------------------------
11707
11708To enable Wayland, you need to enable it to be built and enable it to be
11709included (installed) in the image.
11710
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011711Building Wayland
11712~~~~~~~~~~~~~~~~
11713
11714To cause Mesa to build the ``wayland-egl`` platform and Weston to build
11715Wayland with Kernel Mode Setting
11716(`KMS <https://wiki.archlinux.org/index.php/Kernel_Mode_Setting>`__)
11717support, include the "wayland" flag in the
11718:term:`DISTRO_FEATURES`
Andrew Geisslerc926e172021-05-07 16:11:35 -050011719statement in your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011720
Patrick Williams0ca19cc2021-08-16 14:03:13 -050011721 DISTRO_FEATURES:append = " wayland"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011722
11723.. note::
11724
11725 If X11 has been enabled elsewhere, Weston will build Wayland with X11
11726 support
11727
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011728Installing Wayland and Weston
11729~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11730
11731To install the Wayland feature into an image, you must include the
11732following
11733:term:`CORE_IMAGE_EXTRA_INSTALL`
Andrew Geisslerc926e172021-05-07 16:11:35 -050011734statement in your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011735
11736 CORE_IMAGE_EXTRA_INSTALL += "wayland weston"
11737
11738Running Weston
11739--------------
11740
11741To run Weston inside X11, enabling it as described earlier and building
11742a Sato image is sufficient. If you are running your image under Sato, a
11743Weston Launcher appears in the "Utility" category.
11744
11745Alternatively, you can run Weston through the command-line interpretor
11746(CLI), which is better suited for development work. To run Weston under
11747the CLI, you need to do the following after your image is built:
11748
Andrew Geisslerc926e172021-05-07 16:11:35 -0500117491. Run these commands to export ``XDG_RUNTIME_DIR``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011750
11751 mkdir -p /tmp/$USER-weston
11752 chmod 0700 /tmp/$USER-weston
11753 export XDG_RUNTIME_DIR=/tmp/$USER-weston
11754
Andrew Geisslerc926e172021-05-07 16:11:35 -0500117552. Launch Weston in the shell::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011756
11757 weston