blob: b9c467526a8b2699110460d42a1b71c960d13832 [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
Patrick Williams2390b1b2022-11-03 13:47:49 -0500421found in the :term:`Build Directory`. The following example shows how to
422enable your new ``meta-mylayer`` layer (note how your new layer exists
423outside of the official ``poky`` repository which you would have checked
424out 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"
Andrew Geissler9aee5002022-03-30 16:27:02 +0000567 LICENSE = "MIT"
Andrew Geissler5199d832021-09-24 16:47:35 -0500568 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
657The following list describes the available commands:
658
659- ``help:`` Displays general help or help on a specified command.
660
661- ``show-layers:`` Shows the current configured layers.
662
663- ``show-overlayed:`` Lists overlayed recipes. A recipe is overlayed
664 when a recipe with the same name exists in another layer that has a
665 higher layer priority.
666
667- ``show-recipes:`` Lists available recipes and the layers that
668 provide them.
669
670- ``show-appends:`` Lists ``.bbappend`` files and the recipe files to
671 which they apply.
672
673- ``show-cross-depends:`` Lists dependency relationships between
674 recipes that cross layer boundaries.
675
676- ``add-layer:`` Adds a layer to ``bblayers.conf``.
677
678- ``remove-layer:`` Removes a layer from ``bblayers.conf``
679
680- ``flatten:`` Flattens the layer configuration into a separate
681 output directory. Flattening your layer configuration builds a
682 "flattened" directory that contains the contents of all layers, with
683 any overlayed recipes removed and any ``.bbappend`` files appended to
684 the corresponding recipes. You might have to perform some manual
685 cleanup of the flattened layer as follows:
686
687 - Non-recipe files (such as patches) are overwritten. The flatten
688 command shows a warning for these files.
689
690 - Anything beyond the normal layer setup has been added to the
691 ``layer.conf`` file. Only the lowest priority layer's
692 ``layer.conf`` is used.
693
694 - Overridden and appended items from ``.bbappend`` files need to be
695 cleaned up. The contents of each ``.bbappend`` end up in the
696 flattened recipe. However, if there are appended or changed
697 variable values, you need to tidy these up yourself. Consider the
698 following example. Here, the ``bitbake-layers`` command adds the
699 line ``#### bbappended ...`` so that you know where the following
Andrew Geisslerc926e172021-05-07 16:11:35 -0500700 lines originate::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500701
702 ...
703 DESCRIPTION = "A useful utility"
704 ...
705 EXTRA_OECONF = "--enable-something"
706 ...
707
708 #### bbappended from meta-anotherlayer ####
709
710 DESCRIPTION = "Customized utility"
711 EXTRA_OECONF += "--enable-somethingelse"
712
713
Andrew Geisslerc926e172021-05-07 16:11:35 -0500714 Ideally, you would tidy up these utilities as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500715
716 ...
717 DESCRIPTION = "Customized utility"
718 ...
719 EXTRA_OECONF = "--enable-something --enable-somethingelse"
720 ...
721
722- ``layerindex-fetch``: Fetches a layer from a layer index, along
723 with its dependent layers, and adds the layers to the
724 ``conf/bblayers.conf`` file.
725
726- ``layerindex-show-depends``: Finds layer dependencies from the
727 layer index.
728
Andrew Geissler87f5cff2022-09-30 13:13:31 -0500729- ``save-build-conf``: Saves the currently active build configuration
730 (``conf/local.conf``, ``conf/bblayers.conf``) as a template into a layer.
731 This template can later be used for setting up builds via :term:``TEMPLATECONF``.
732 For information about saving and using configuration templates, see
733 ":ref:`dev-manual/common-tasks:creating a custom template configuration directory`".
734
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500735- ``create-layer``: Creates a basic layer.
736
Andrew Geissler87f5cff2022-09-30 13:13:31 -0500737- ``create-layers-setup``: Writes out a configuration file and/or a script that
738 can replicate the directory structure and revisions of the layers in a current build.
739 For more information, see ":ref:`dev-manual/common-tasks:saving and restoring the layers setup`".
740
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500741Creating a General Layer Using the ``bitbake-layers`` Script
742------------------------------------------------------------
743
744The ``bitbake-layers`` script with the ``create-layer`` subcommand
745simplifies creating a new general layer.
746
747.. note::
748
749 - For information on BSP layers, see the ":ref:`bsp-guide/bsp:bsp layers`"
750 section in the Yocto
751 Project Board Specific (BSP) Developer's Guide.
752
753 - In order to use a layer with the OpenEmbedded build system, you
754 need to add the layer to your ``bblayers.conf`` configuration
Andrew Geissler09209ee2020-12-13 08:44:15 -0600755 file. See the ":ref:`dev-manual/common-tasks:adding a layer using the \`\`bitbake-layers\`\` script`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500756 section for more information.
757
758The default mode of the script's operation with this subcommand is to
759create a layer with the following:
760
761- A layer priority of 6.
762
763- A ``conf`` subdirectory that contains a ``layer.conf`` file.
764
765- A ``recipes-example`` subdirectory that contains a further
766 subdirectory named ``example``, which contains an ``example.bb``
767 recipe file.
768
769- A ``COPYING.MIT``, which is the license statement for the layer. The
770 script assumes you want to use the MIT license, which is typical for
771 most layers, for the contents of the layer itself.
772
773- A ``README`` file, which is a file describing the contents of your
774 new layer.
775
776In its simplest form, you can use the following command form to create a
777layer. The command creates a layer whose name corresponds to
Andrew Geisslerc926e172021-05-07 16:11:35 -0500778"your_layer_name" in the current directory::
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500779
780 $ bitbake-layers create-layer your_layer_name
781
782As an example, the following command creates a layer named ``meta-scottrif``
Andrew Geisslerc926e172021-05-07 16:11:35 -0500783in your home directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500784
785 $ cd /usr/home
786 $ bitbake-layers create-layer meta-scottrif
787 NOTE: Starting bitbake server...
788 Add your new layer with 'bitbake-layers add-layer meta-scottrif'
789
790If you want to set the priority of the layer to other than the default
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500791value of "6", you can either use the ``--priority`` option or you
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500792can edit the
793:term:`BBFILE_PRIORITY` value
794in the ``conf/layer.conf`` after the script creates it. Furthermore, if
795you want to give the example recipe file some name other than the
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500796default, you can use the ``--example-recipe-name`` option.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500797
798The easiest way to see how the ``bitbake-layers create-layer`` command
799works is to experiment with the script. You can also read the usage
Andrew Geisslerc926e172021-05-07 16:11:35 -0500800information by entering the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500801
802 $ bitbake-layers create-layer --help
803 NOTE: Starting bitbake server...
804 usage: bitbake-layers create-layer [-h] [--priority PRIORITY]
805 [--example-recipe-name EXAMPLERECIPE]
806 layerdir
807
808 Create a basic layer
809
810 positional arguments:
811 layerdir Layer directory to create
812
813 optional arguments:
814 -h, --help show this help message and exit
815 --priority PRIORITY, -p PRIORITY
816 Layer directory to create
817 --example-recipe-name EXAMPLERECIPE, -e EXAMPLERECIPE
818 Filename of the example recipe
819
820Adding a Layer Using the ``bitbake-layers`` Script
821--------------------------------------------------
822
823Once you create your general layer, you must add it to your
824``bblayers.conf`` file. Adding the layer to this configuration file
825makes the OpenEmbedded build system aware of your layer so that it can
826search it for metadata.
827
Andrew Geisslerc926e172021-05-07 16:11:35 -0500828Add your layer by using the ``bitbake-layers add-layer`` command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500829
830 $ bitbake-layers add-layer your_layer_name
831
832Here is an example that adds a
833layer named ``meta-scottrif`` to the configuration file. Following the
834command that adds the layer is another ``bitbake-layers`` command that
Andrew Geisslerc926e172021-05-07 16:11:35 -0500835shows the layers that are in your ``bblayers.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500836
837 $ bitbake-layers add-layer meta-scottrif
838 NOTE: Starting bitbake server...
839 Parsing recipes: 100% |##########################################################| Time: 0:00:49
840 Parsing of 1441 .bb files complete (0 cached, 1441 parsed). 2055 targets, 56 skipped, 0 masked, 0 errors.
841 $ bitbake-layers show-layers
842 NOTE: Starting bitbake server...
843 layer path priority
844 ==========================================================================
845 meta /home/scottrif/poky/meta 5
846 meta-poky /home/scottrif/poky/meta-poky 5
847 meta-yocto-bsp /home/scottrif/poky/meta-yocto-bsp 5
848 workspace /home/scottrif/poky/build/workspace 99
849 meta-scottrif /home/scottrif/poky/build/meta-scottrif 6
850
851
852Adding the layer to this file
853enables the build system to locate the layer during the build.
854
855.. note::
856
857 During a build, the OpenEmbedded build system looks in the layers
858 from the top of the list down to the bottom in that order.
859
Andrew Geissler87f5cff2022-09-30 13:13:31 -0500860Saving and restoring the layers setup
861-------------------------------------
862
863Once you have a working build with the correct set of layers, it is beneficial
864to capture the layer setup --- what they are, which repositories they come from
865and which SCM revisions they're at --- into a configuration file, so that this
866setup can be easily replicated later, perhaps on a different machine. Here's
867how to do this::
868
869 $ bitbake-layers create-layers-setup /srv/work/alex/meta-alex/
870 NOTE: Starting bitbake server...
871 NOTE: Created /srv/work/alex/meta-alex/setup-layers.json
872 NOTE: Created /srv/work/alex/meta-alex/setup-layers
873
874The tool needs a single argument which tells where to place the output, consisting
875of a json formatted layer configuration, and a ``setup-layers`` script that can use that configuration
876to restore the layers in a different location, or on a different host machine. The argument
877can point to a custom layer (which is then deemed a "bootstrap" layer that needs to be
878checked out first), or into a completely independent location.
879
880The replication of the layers is performed by running the ``setup-layers`` script provided
881above:
882
8831. Clone the bootstrap layer or some other repository to obtain
884 the json config and the setup script that can use it.
885
8862. Run the script directly with no options::
887
888 alex@Zen2:/srv/work/alex/my-build$ meta-alex/setup-layers
889 Note: not checking out source meta-alex, use --force-bootstraplayer-checkout to override.
890
891 Setting up source meta-intel, revision 15.0-hardknott-3.3-310-g0a96edae, branch master
892 Running 'git init -q /srv/work/alex/my-build/meta-intel'
893 Running 'git remote remove origin > /dev/null 2>&1; git remote add origin git://git.yoctoproject.org/meta-intel' in /srv/work/alex/my-build/meta-intel
894 Running 'git fetch -q origin || true' in /srv/work/alex/my-build/meta-intel
895 Running 'git checkout -q 0a96edae609a3f48befac36af82cf1eed6786b4a' in /srv/work/alex/my-build/meta-intel
896
897 Setting up source poky, revision 4.1_M1-372-g55483d28f2, branch akanavin/setup-layers
898 Running 'git init -q /srv/work/alex/my-build/poky'
899 Running 'git remote remove origin > /dev/null 2>&1; git remote add origin git://git.yoctoproject.org/poky' in /srv/work/alex/my-build/poky
900 Running 'git fetch -q origin || true' in /srv/work/alex/my-build/poky
901 Running 'git remote remove poky-contrib > /dev/null 2>&1; git remote add poky-contrib ssh://git@push.yoctoproject.org/poky-contrib' in /srv/work/alex/my-build/poky
902 Running 'git fetch -q poky-contrib || true' in /srv/work/alex/my-build/poky
903 Running 'git checkout -q 11db0390b02acac1324e0f827beb0e2e3d0d1d63' in /srv/work/alex/my-build/poky
904
905.. note::
906 This will work to update an existing checkout as well.
907
908.. note::
909 The script is self-sufficient and requires only python3
910 and git on the build machine.
911
912.. note::
913 Both the ``create-layers-setup`` and the ``setup-layers`` provided several additional options
914 that customize their behavior - you are welcome to study them via ``--help`` command line parameter.
915
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500916Customizing Images
917==================
918
919You can customize images to satisfy particular requirements. This
920section describes several methods and provides guidelines for each.
921
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500922Customizing Images Using ``local.conf``
923---------------------------------------
924
925Probably the easiest way to customize an image is to add a package by
926way of the ``local.conf`` configuration file. Because it is limited to
927local use, this method generally only allows you to add packages and is
928not as flexible as creating your own customized image. When you add
929packages using local variables this way, you need to realize that these
930variable changes are in effect for every build and consequently affect
931all images, which might not be what you require.
932
933To add a package to your image using the local configuration file, use
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500934the :term:`IMAGE_INSTALL` variable with the ``:append`` operator::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500935
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500936 IMAGE_INSTALL:append = " strace"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500937
Andrew Geissler5199d832021-09-24 16:47:35 -0500938Use of the syntax is important; specifically, the leading space
939after the opening quote and before the package name, which is
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500940``strace`` in this example. This space is required since the ``:append``
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500941operator does not add the space.
942
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500943Furthermore, you must use ``:append`` instead of the ``+=`` operator if
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500944you want to avoid ordering issues. The reason for this is because doing
945so unconditionally appends to the variable and avoids ordering problems
946due to the variable being set in image recipes and ``.bbclass`` files
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500947with operators like ``?=``. Using ``:append`` ensures the operation
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500948takes effect.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500949
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500950As shown in its simplest use, ``IMAGE_INSTALL:append`` affects all
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500951images. It is possible to extend the syntax so that the variable applies
Andrew Geisslerc926e172021-05-07 16:11:35 -0500952to a specific image only. Here is an example::
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500953
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500954 IMAGE_INSTALL:append:pn-core-image-minimal = " strace"
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500955
956This example adds ``strace`` to the ``core-image-minimal`` image only.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500957
958You can add packages using a similar approach through the
Andrew Geissler09036742021-06-25 14:25:14 -0500959:term:`CORE_IMAGE_EXTRA_INSTALL` variable. If you use this variable, only
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500960``core-image-*`` images are affected.
961
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500962Customizing Images Using Custom ``IMAGE_FEATURES`` and ``EXTRA_IMAGE_FEATURES``
963-------------------------------------------------------------------------------
964
965Another method for customizing your image is to enable or disable
966high-level image features by using the
967:term:`IMAGE_FEATURES` and
968:term:`EXTRA_IMAGE_FEATURES`
969variables. Although the functions for both variables are nearly
Andrew Geissler09036742021-06-25 14:25:14 -0500970equivalent, best practices dictate using :term:`IMAGE_FEATURES` from within
971a recipe and using :term:`EXTRA_IMAGE_FEATURES` from within your
Patrick Williams2390b1b2022-11-03 13:47:49 -0500972``local.conf`` file, which is found in the :term:`Build Directory`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500973
974To understand how these features work, the best reference is
Patrick Williams975a06f2022-10-21 14:42:47 -0500975:ref:`meta/classes-recipe/image.bbclass <ref-classes-image>`.
Andrew Geissler595f6302022-01-24 19:11:47 +0000976This class lists out the available
Andrew Geissler09036742021-06-25 14:25:14 -0500977:term:`IMAGE_FEATURES` of which most map to package groups while some, such
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500978as ``debug-tweaks`` and ``read-only-rootfs``, resolve as general
979configuration settings.
980
Andrew Geissler09036742021-06-25 14:25:14 -0500981In summary, the file looks at the contents of the :term:`IMAGE_FEATURES`
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500982variable and then maps or configures the feature accordingly. Based on
983this information, the build system automatically adds the appropriate
984packages or configurations to the
985:term:`IMAGE_INSTALL` variable.
986Effectively, you are enabling extra features by extending the class or
987creating a custom class for use with specialized image ``.bb`` files.
988
Andrew Geissler09036742021-06-25 14:25:14 -0500989Use the :term:`EXTRA_IMAGE_FEATURES` variable from within your local
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500990configuration file. Using a separate area from which to enable features
991with this variable helps you avoid overwriting the features in the image
Andrew Geissler09036742021-06-25 14:25:14 -0500992recipe that are enabled with :term:`IMAGE_FEATURES`. The value of
993:term:`EXTRA_IMAGE_FEATURES` is added to :term:`IMAGE_FEATURES` within
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500994``meta/conf/bitbake.conf``.
995
996To illustrate how you can use these variables to modify your image,
997consider an example that selects the SSH server. The Yocto Project ships
998with two SSH servers you can use with your images: Dropbear and OpenSSH.
999Dropbear is a minimal SSH server appropriate for resource-constrained
1000environments, while OpenSSH is a well-known standard SSH server
1001implementation. By default, the ``core-image-sato`` image is configured
1002to use Dropbear. The ``core-image-full-cmdline`` and ``core-image-lsb``
1003images both include OpenSSH. The ``core-image-minimal`` image does not
1004contain an SSH server.
1005
1006You can customize your image and change these defaults. Edit the
Andrew Geissler09036742021-06-25 14:25:14 -05001007:term:`IMAGE_FEATURES` variable in your recipe or use the
1008:term:`EXTRA_IMAGE_FEATURES` in your ``local.conf`` file so that it
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001009configures the image you are working with to include
1010``ssh-server-dropbear`` or ``ssh-server-openssh``.
1011
1012.. note::
1013
Andrew Geissler09209ee2020-12-13 08:44:15 -06001014 See the ":ref:`ref-manual/features:image features`" section in the Yocto
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001015 Project Reference Manual for a complete list of image features that ship
1016 with the Yocto Project.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001017
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001018Customizing Images Using Custom .bb Files
1019-----------------------------------------
1020
1021You can also customize an image by creating a custom recipe that defines
1022additional software as part of the image. The following example shows
Andrew Geisslerc926e172021-05-07 16:11:35 -05001023the form for the two lines you need::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001024
1025 IMAGE_INSTALL = "packagegroup-core-x11-base package1 package2"
1026 inherit core-image
1027
1028Defining the software using a custom recipe gives you total control over
1029the contents of the image. It is important to use the correct names of
Andrew Geissler09036742021-06-25 14:25:14 -05001030packages in the :term:`IMAGE_INSTALL` variable. You must use the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001031OpenEmbedded notation and not the Debian notation for the names (e.g.
1032``glibc-dev`` instead of ``libc6-dev``).
1033
1034The other method for creating a custom image is to base it on an
1035existing image. For example, if you want to create an image based on
1036``core-image-sato`` but add the additional package ``strace`` to the
1037image, copy the ``meta/recipes-sato/images/core-image-sato.bb`` to a new
Andrew Geisslerc926e172021-05-07 16:11:35 -05001038``.bb`` and add the following line to the end of the copy::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001039
1040 IMAGE_INSTALL += "strace"
1041
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001042Customizing Images Using Custom Package Groups
1043----------------------------------------------
1044
1045For complex custom images, the best approach for customizing an image is
1046to create a custom package group recipe that is used to build the image
1047or images. A good example of a package group recipe is
1048``meta/recipes-core/packagegroups/packagegroup-base.bb``.
1049
Andrew Geissler09036742021-06-25 14:25:14 -05001050If you examine that recipe, you see that the :term:`PACKAGES` variable lists
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001051the package group packages to produce. The ``inherit packagegroup``
1052statement sets appropriate default values and automatically adds
1053``-dev``, ``-dbg``, and ``-ptest`` complementary packages for each
Andrew Geissler09036742021-06-25 14:25:14 -05001054package specified in the :term:`PACKAGES` statement.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001055
1056.. note::
1057
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001058 The ``inherit packagegroup`` line should be located near the top of the
Andrew Geissler09036742021-06-25 14:25:14 -05001059 recipe, certainly before the :term:`PACKAGES` statement.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001060
Andrew Geissler09036742021-06-25 14:25:14 -05001061For each package you specify in :term:`PACKAGES`, you can use :term:`RDEPENDS`
1062and :term:`RRECOMMENDS` entries to provide a list of packages the parent
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001063task package should contain. You can see examples of these further down
1064in the ``packagegroup-base.bb`` recipe.
1065
1066Here is a short, fabricated example showing the same basic pieces for a
1067hypothetical packagegroup defined in ``packagegroup-custom.bb``, where
Andrew Geissler09036742021-06-25 14:25:14 -05001068the variable :term:`PN` is the standard way to abbreviate the reference to
Andrew Geisslerc926e172021-05-07 16:11:35 -05001069the full packagegroup name ``packagegroup-custom``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001070
1071 DESCRIPTION = "My Custom Package Groups"
1072
1073 inherit packagegroup
1074
1075 PACKAGES = "\
1076 ${PN}-apps \
1077 ${PN}-tools \
1078 "
1079
Patrick Williams0ca19cc2021-08-16 14:03:13 -05001080 RDEPENDS:${PN}-apps = "\
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001081 dropbear \
1082 portmap \
1083 psplash"
1084
Patrick Williams0ca19cc2021-08-16 14:03:13 -05001085 RDEPENDS:${PN}-tools = "\
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001086 oprofile \
1087 oprofileui-server \
1088 lttng-tools"
1089
Patrick Williams0ca19cc2021-08-16 14:03:13 -05001090 RRECOMMENDS:${PN}-tools = "\
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001091 kernel-module-oprofile"
1092
1093In the previous example, two package group packages are created with
1094their dependencies and their recommended package dependencies listed:
1095``packagegroup-custom-apps``, and ``packagegroup-custom-tools``. To
1096build an image using these package group packages, you need to add
1097``packagegroup-custom-apps`` and/or ``packagegroup-custom-tools`` to
Andrew Geissler09036742021-06-25 14:25:14 -05001098:term:`IMAGE_INSTALL`. For other forms of image dependencies see the other
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001099areas of this section.
1100
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001101Customizing an Image Hostname
1102-----------------------------
1103
1104By default, the configured hostname (i.e. ``/etc/hostname``) in an image
1105is the same as the machine name. For example, if
1106:term:`MACHINE` equals "qemux86", the
1107configured hostname written to ``/etc/hostname`` is "qemux86".
1108
1109You can customize this name by altering the value of the "hostname"
1110variable in the ``base-files`` recipe using either an append file or a
Andrew Geisslerc926e172021-05-07 16:11:35 -05001111configuration file. Use the following in an append file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001112
1113 hostname = "myhostname"
1114
Andrew Geisslerc926e172021-05-07 16:11:35 -05001115Use the following in a configuration file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001116
Patrick Williams0ca19cc2021-08-16 14:03:13 -05001117 hostname:pn-base-files = "myhostname"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001118
1119Changing the default value of the variable "hostname" can be useful in
1120certain situations. For example, suppose you need to do extensive
1121testing on an image and you would like to easily identify the image
1122under test from existing images with typical default hostnames. In this
1123situation, you could change the default hostname to "testme", which
1124results in all the images using the name "testme". Once testing is
1125complete and you do not need to rebuild the image for test any longer,
1126you can easily reset the default hostname.
1127
1128Another point of interest is that if you unset the variable, the image
1129will have no default hostname in the filesystem. Here is an example that
Andrew Geisslerc926e172021-05-07 16:11:35 -05001130unsets the variable in a configuration file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001131
Patrick Williams0ca19cc2021-08-16 14:03:13 -05001132 hostname:pn-base-files = ""
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001133
1134Having no default hostname in the filesystem is suitable for
1135environments that use dynamic hostnames such as virtual machines.
1136
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001137Writing a New Recipe
1138====================
1139
1140Recipes (``.bb`` files) are fundamental components in the Yocto Project
1141environment. Each software component built by the OpenEmbedded build
1142system requires a recipe to define the component. This section describes
1143how to create, write, and test a new recipe.
1144
1145.. note::
1146
1147 For information on variables that are useful for recipes and for
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001148 information about recipe naming issues, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001149 ":ref:`ref-manual/varlocality:recipes`" section of the Yocto Project
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001150 Reference Manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001151
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001152Overview
1153--------
1154
1155The following figure shows the basic process for creating a new recipe.
1156The remainder of the section provides details for the steps.
1157
1158.. image:: figures/recipe-workflow.png
1159 :align: center
Andrew Geisslerd5838332022-05-27 11:33:10 -05001160 :width: 50%
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001161
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001162Locate or Automatically Create a Base Recipe
1163--------------------------------------------
1164
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001165You can always write a recipe from scratch. However, there are three choices
1166that can help you quickly get started with a new recipe:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001167
1168- ``devtool add``: A command that assists in creating a recipe and an
1169 environment conducive to development.
1170
1171- ``recipetool create``: A command provided by the Yocto Project that
1172 automates creation of a base recipe based on the source files.
1173
1174- *Existing Recipes:* Location and modification of an existing recipe
1175 that is similar in function to the recipe you need.
1176
1177.. note::
1178
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001179 For information on recipe syntax, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001180 ":ref:`dev-manual/common-tasks:recipe syntax`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001181
1182Creating the Base Recipe Using ``devtool add``
1183~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1184
1185The ``devtool add`` command uses the same logic for auto-creating the
1186recipe as ``recipetool create``, which is listed below. Additionally,
1187however, ``devtool add`` sets up an environment that makes it easy for
1188you to patch the source and to make changes to the recipe as is often
1189necessary when adding a recipe to build a new piece of software to be
1190included in a build.
1191
1192You can find a complete description of the ``devtool add`` command in
Andrew Geissler09209ee2020-12-13 08:44:15 -06001193the ":ref:`sdk-manual/extensible:a closer look at \`\`devtool add\`\``" section
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001194in the Yocto Project Application Development and the Extensible Software
1195Development Kit (eSDK) manual.
1196
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001197Creating the Base Recipe Using ``recipetool create``
1198~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1199
1200``recipetool create`` automates creation of a base recipe given a set of
1201source code files. As long as you can extract or point to the source
1202files, the tool will construct a recipe and automatically configure all
1203pre-build information into the recipe. For example, suppose you have an
1204application that builds using Autotools. Creating the base recipe using
1205``recipetool`` results in a recipe that has the pre-build dependencies,
1206license requirements, and checksums configured.
1207
Patrick Williams2390b1b2022-11-03 13:47:49 -05001208To run the tool, you just need to be in your :term:`Build Directory` and
1209have sourced the build environment setup script (i.e.
1210:ref:`structure-core-script`). To get help on the tool, use the following
1211command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001212
1213 $ recipetool -h
1214 NOTE: Starting bitbake server...
1215 usage: recipetool [-d] [-q] [--color COLOR] [-h] <subcommand> ...
1216
1217 OpenEmbedded recipe tool
1218
1219 options:
1220 -d, --debug Enable debug output
1221 -q, --quiet Print only errors
1222 --color COLOR Colorize output (where COLOR is auto, always, never)
1223 -h, --help show this help message and exit
1224
1225 subcommands:
1226 create Create a new recipe
1227 newappend Create a bbappend for the specified target in the specified
1228 layer
1229 setvar Set a variable within a recipe
1230 appendfile Create/update a bbappend to replace a target file
1231 appendsrcfiles Create/update a bbappend to add or replace source files
1232 appendsrcfile Create/update a bbappend to add or replace a source file
1233 Use recipetool <subcommand> --help to get help on a specific command
1234
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001235Running ``recipetool create -o OUTFILE`` creates the base recipe and
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001236locates it properly in the layer that contains your source files.
1237Following are some syntax examples:
1238
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001239 - Use this syntax to generate a recipe based on source. Once generated,
Andrew Geisslerc926e172021-05-07 16:11:35 -05001240 the recipe resides in the existing source code layer::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001241
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001242 recipetool create -o OUTFILE source
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001243
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001244 - Use this syntax to generate a recipe using code that
1245 you extract from source. The extracted code is placed in its own layer
Andrew Geissler09036742021-06-25 14:25:14 -05001246 defined by :term:`EXTERNALSRC`.
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001247 ::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001248
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001249 recipetool create -o OUTFILE -x EXTERNALSRC source
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001250
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001251 - Use this syntax to generate a recipe based on source. The options
1252 direct ``recipetool`` to generate debugging information. Once generated,
Andrew Geisslerc926e172021-05-07 16:11:35 -05001253 the recipe resides in the existing source code layer::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001254
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001255 recipetool create -d -o OUTFILE source
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001256
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001257Locating and Using a Similar Recipe
1258~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1259
1260Before writing a recipe from scratch, it is often useful to discover
1261whether someone else has already written one that meets (or comes close
1262to meeting) your needs. The Yocto Project and OpenEmbedded communities
1263maintain many recipes that might be candidates for what you are doing.
Andrew Geisslerd1e89492021-02-12 15:35:20 -06001264You can find a good central index of these recipes in the
1265:oe_layerindex:`OpenEmbedded Layer Index <>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001266
1267Working from an existing recipe or a skeleton recipe is the best way to
1268get started. Here are some points on both methods:
1269
1270- *Locate and modify a recipe that is close to what you want to do:*
1271 This method works when you are familiar with the current recipe
1272 space. The method does not work so well for those new to the Yocto
1273 Project or writing recipes.
1274
1275 Some risks associated with this method are using a recipe that has
1276 areas totally unrelated to what you are trying to accomplish with
1277 your recipe, not recognizing areas of the recipe that you might have
1278 to add from scratch, and so forth. All these risks stem from
1279 unfamiliarity with the existing recipe space.
1280
1281- *Use and modify the following skeleton recipe:* If for some reason
1282 you do not want to use ``recipetool`` and you cannot find an existing
1283 recipe that is close to meeting your needs, you can use the following
1284 structure to provide the fundamental areas of a new recipe.
1285 ::
1286
1287 DESCRIPTION = ""
1288 HOMEPAGE = ""
1289 LICENSE = ""
1290 SECTION = ""
1291 DEPENDS = ""
1292 LIC_FILES_CHKSUM = ""
1293
1294 SRC_URI = ""
1295
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001296Storing and Naming the Recipe
1297-----------------------------
1298
1299Once you have your base recipe, you should put it in your own layer and
1300name it appropriately. Locating it correctly ensures that the
1301OpenEmbedded build system can find it when you use BitBake to process
1302the recipe.
1303
1304- *Storing Your Recipe:* The OpenEmbedded build system locates your
1305 recipe through the layer's ``conf/layer.conf`` file and the
1306 :term:`BBFILES` variable. This
1307 variable sets up a path from which the build system can locate
Andrew Geisslerc926e172021-05-07 16:11:35 -05001308 recipes. Here is the typical use::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001309
1310 BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
1311 ${LAYERDIR}/recipes-*/*/*.bbappend"
1312
1313 Consequently, you need to be sure you locate your new recipe inside
1314 your layer such that it can be found.
1315
1316 You can find more information on how layers are structured in the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001317 ":ref:`dev-manual/common-tasks:understanding and creating layers`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001318
1319- *Naming Your Recipe:* When you name your recipe, you need to follow
Andrew Geisslerc926e172021-05-07 16:11:35 -05001320 this naming convention::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001321
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001322 basename_version.bb
1323
1324 Use lower-cased characters and do not include the reserved suffixes
1325 ``-native``, ``-cross``, ``-initial``, or ``-dev`` casually (i.e. do not use
1326 them as part of your recipe name unless the string applies). Here are some
1327 examples:
1328
1329 .. code-block:: none
1330
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001331 cups_1.7.0.bb
1332 gawk_4.0.2.bb
1333 irssi_0.8.16-rc1.bb
1334
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001335Running a Build on the Recipe
1336-----------------------------
1337
1338Creating a new recipe is usually an iterative process that requires
1339using BitBake to process the recipe multiple times in order to
1340progressively discover and add information to the recipe file.
1341
1342Assuming you have sourced the build environment setup script (i.e.
Patrick Williams2390b1b2022-11-03 13:47:49 -05001343:ref:`structure-core-script`) and you are in the :term:`Build Directory`, use
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001344BitBake to process your recipe. All you need to provide is the
Andrew Geisslerc926e172021-05-07 16:11:35 -05001345``basename`` of the recipe as described in the previous section::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001346
1347 $ bitbake basename
1348
1349During the build, the OpenEmbedded build system creates a temporary work
1350directory for each recipe
1351(``${``\ :term:`WORKDIR`\ ``}``)
1352where it keeps extracted source files, log files, intermediate
1353compilation and packaging files, and so forth.
1354
1355The path to the per-recipe temporary work directory depends on the
1356context in which it is being built. The quickest way to find this path
Andrew Geisslerc926e172021-05-07 16:11:35 -05001357is to have BitBake return it by running the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001358
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001359 $ bitbake -e basename | grep ^WORKDIR=
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001360
1361As an example, assume a Source Directory
Patrick Williams2390b1b2022-11-03 13:47:49 -05001362top-level folder named ``poky``, a default :term:`Build Directory` at
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001363``poky/build``, and a ``qemux86-poky-linux`` machine target system.
1364Furthermore, suppose your recipe is named ``foo_1.3.0.bb``. In this
1365case, the work directory the build system uses to build the package
Andrew Geisslerc926e172021-05-07 16:11:35 -05001366would be as follows::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001367
1368 poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
1369
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001370Inside this directory you can find sub-directories such as ``image``,
1371``packages-split``, and ``temp``. After the build, you can examine these
1372to determine how well the build went.
1373
1374.. note::
1375
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001376 You can find log files for each task in the recipe's ``temp``
1377 directory (e.g. ``poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0/temp``).
1378 Log files are named ``log.taskname`` (e.g. ``log.do_configure``,
1379 ``log.do_fetch``, and ``log.do_compile``).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001380
1381You can find more information about the build process in
Andrew Geissler09209ee2020-12-13 08:44:15 -06001382":doc:`/overview-manual/development-environment`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001383chapter of the Yocto Project Overview and Concepts Manual.
1384
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001385Fetching Code
1386-------------
1387
1388The first thing your recipe must do is specify how to fetch the source
1389files. Fetching is controlled mainly through the
1390:term:`SRC_URI` variable. Your recipe
Andrew Geissler09036742021-06-25 14:25:14 -05001391must have a :term:`SRC_URI` variable that points to where the source is
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001392located. For a graphical representation of source locations, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001393":ref:`overview-manual/concepts:sources`" section in
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001394the Yocto Project Overview and Concepts Manual.
1395
1396The :ref:`ref-tasks-fetch` task uses
Andrew Geissler09036742021-06-25 14:25:14 -05001397the prefix of each entry in the :term:`SRC_URI` variable value to determine
Andrew Geissler09209ee2020-12-13 08:44:15 -06001398which :ref:`fetcher <bitbake:bitbake-user-manual/bitbake-user-manual-fetching:fetchers>` to use to get your
Andrew Geissler09036742021-06-25 14:25:14 -05001399source files. It is the :term:`SRC_URI` variable that triggers the fetcher.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001400The :ref:`ref-tasks-patch` task uses
1401the variable after source is fetched to apply patches. The OpenEmbedded
1402build system uses
1403:term:`FILESOVERRIDES` for
Andrew Geissler09036742021-06-25 14:25:14 -05001404scanning directory locations for local files in :term:`SRC_URI`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001405
Andrew Geissler09036742021-06-25 14:25:14 -05001406The :term:`SRC_URI` variable in your recipe must define each unique location
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001407for your source files. It is good practice to not hard-code version
Andrew Geissler5f350902021-07-23 13:09:54 -04001408numbers in a URL used in :term:`SRC_URI`. Rather than hard-code these
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001409values, use ``${``\ :term:`PV`\ ``}``,
1410which causes the fetch process to use the version specified in the
1411recipe filename. Specifying the version in this manner means that
1412upgrading the recipe to a future version is as simple as renaming the
1413recipe to match the new version.
1414
1415Here is a simple example from the
1416``meta/recipes-devtools/strace/strace_5.5.bb`` recipe where the source
1417comes from a single tarball. Notice the use of the
Andrew Geisslerc926e172021-05-07 16:11:35 -05001418:term:`PV` variable::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001419
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001420 SRC_URI = "https://strace.io/files/${PV}/strace-${PV}.tar.xz \
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001421
Andrew Geissler09036742021-06-25 14:25:14 -05001422Files mentioned in :term:`SRC_URI` whose names end in a typical archive
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001423extension (e.g. ``.tar``, ``.tar.gz``, ``.tar.bz2``, ``.zip``, and so
1424forth), are automatically extracted during the
1425:ref:`ref-tasks-unpack` task. For
1426another example that specifies these types of files, see the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001427":ref:`dev-manual/common-tasks:autotooled package`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001428
1429Another way of specifying source is from an SCM. For Git repositories,
Andrew Geissler9aee5002022-03-30 16:27:02 +00001430you must specify :term:`SRCREV` and you should specify :term:`PV` to include
1431the revision with :term:`SRCPV`. Here is an example from the recipe
1432``meta/recipes-core/musl/gcompat_git.bb``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001433
Andrew Geissler9aee5002022-03-30 16:27:02 +00001434 SRC_URI = "git://git.adelielinux.org/adelie/gcompat.git;protocol=https;branch=current"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001435
Andrew Geissler9aee5002022-03-30 16:27:02 +00001436 PV = "1.0.0+1.1+git${SRCPV}"
1437 SRCREV = "af5a49e489fdc04b9cf02547650d7aeaccd43793"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001438
Andrew Geissler09036742021-06-25 14:25:14 -05001439If your :term:`SRC_URI` statement includes URLs pointing to individual files
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001440fetched from a remote server other than a version control system,
1441BitBake attempts to verify the files against checksums defined in your
1442recipe to ensure they have not been tampered with or otherwise modified
1443since the recipe was written. Two checksums are used:
1444``SRC_URI[md5sum]`` and ``SRC_URI[sha256sum]``.
1445
Andrew Geissler09036742021-06-25 14:25:14 -05001446If your :term:`SRC_URI` variable points to more than a single URL (excluding
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001447SCM URLs), you need to provide the ``md5`` and ``sha256`` checksums for
1448each URL. For these cases, you provide a name for each URL as part of
Andrew Geissler09036742021-06-25 14:25:14 -05001449the :term:`SRC_URI` and then reference that name in the subsequent checksum
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001450statements. Here is an example combining lines from the files
Andrew Geisslerc926e172021-05-07 16:11:35 -05001451``git.inc`` and ``git_2.24.1.bb``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001452
1453 SRC_URI = "${KERNELORG_MIRROR}/software/scm/git/git-${PV}.tar.gz;name=tarball \
1454 ${KERNELORG_MIRROR}/software/scm/git/git-manpages-${PV}.tar.gz;name=manpages"
1455
1456 SRC_URI[tarball.md5sum] = "166bde96adbbc11c8843d4f8f4f9811b"
1457 SRC_URI[tarball.sha256sum] = "ad5334956301c86841eb1e5b1bb20884a6bad89a10a6762c958220c7cf64da02"
1458 SRC_URI[manpages.md5sum] = "31c2272a8979022497ba3d4202df145d"
1459 SRC_URI[manpages.sha256sum] = "9a7ae3a093bea39770eb96ca3e5b40bff7af0b9f6123f089d7821d0e5b8e1230"
1460
1461Proper values for ``md5`` and ``sha256`` checksums might be available
1462with other signatures on the download page for the upstream source (e.g.
1463``md5``, ``sha1``, ``sha256``, ``GPG``, and so forth). Because the
1464OpenEmbedded build system only deals with ``sha256sum`` and ``md5sum``,
1465you should verify all the signatures you find by hand.
1466
Andrew Geissler09036742021-06-25 14:25:14 -05001467If no :term:`SRC_URI` checksums are specified when you attempt to build the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001468recipe, or you provide an incorrect checksum, the build will produce an
1469error for each missing or incorrect checksum. As part of the error
1470message, the build system provides the checksum string corresponding to
1471the fetched file. Once you have the correct checksums, you can copy and
1472paste them into your recipe and then run the build again to continue.
1473
1474.. note::
1475
1476 As mentioned, if the upstream source provides signatures for
1477 verifying the downloaded source code, you should verify those
1478 manually before setting the checksum values in the recipe and
1479 continuing with the build.
1480
1481This final example is a bit more complicated and is from the
1482``meta/recipes-sato/rxvt-unicode/rxvt-unicode_9.20.bb`` recipe. The
Andrew Geissler09036742021-06-25 14:25:14 -05001483example's :term:`SRC_URI` statement identifies multiple files as the source
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001484files for the recipe: a tarball, a patch file, a desktop file, and an
1485icon.
1486::
1487
1488 SRC_URI = "http://dist.schmorp.de/rxvt-unicode/Attic/rxvt-unicode-${PV}.tar.bz2 \
1489 file://xwc.patch \
1490 file://rxvt.desktop \
1491 file://rxvt.png"
1492
1493When you specify local files using the ``file://`` URI protocol, the
1494build system fetches files from the local machine. The path is relative
1495to the :term:`FILESPATH` variable
1496and searches specific directories in a certain order:
1497``${``\ :term:`BP`\ ``}``,
1498``${``\ :term:`BPN`\ ``}``, and
1499``files``. The directories are assumed to be subdirectories of the
1500directory in which the recipe or append file resides. For another
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001501example that specifies these types of files, see the
1502":ref:`dev-manual/common-tasks:single .c file package (hello world!)`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001503
1504The previous example also specifies a patch file. Patch files are files
1505whose names usually end in ``.patch`` or ``.diff`` but can end with
1506compressed suffixes such as ``diff.gz`` and ``patch.bz2``, for example.
1507The build system automatically applies patches as described in the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001508":ref:`dev-manual/common-tasks:patching code`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001509
Andrew Geissler9aee5002022-03-30 16:27:02 +00001510Fetching Code Through Firewalls
1511~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1512
1513Some users are behind firewalls and need to fetch code through a proxy.
1514See the ":doc:`/ref-manual/faq`" chapter for advice.
1515
1516Limiting the Number of Parallel Connections
1517~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1518
1519Some users are behind firewalls or use servers where the number of parallel
1520connections is limited. In such cases, you can limit the number of fetch
1521tasks being run in parallel by adding the following to your ``local.conf``
1522file::
1523
1524 do_fetch[number_threads] = "4"
1525
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001526Unpacking Code
1527--------------
1528
1529During the build, the
1530:ref:`ref-tasks-unpack` task unpacks
1531the source with ``${``\ :term:`S`\ ``}``
1532pointing to where it is unpacked.
1533
1534If you are fetching your source files from an upstream source archived
1535tarball and the tarball's internal structure matches the common
1536convention of a top-level subdirectory named
1537``${``\ :term:`BPN`\ ``}-${``\ :term:`PV`\ ``}``,
Andrew Geissler09036742021-06-25 14:25:14 -05001538then you do not need to set :term:`S`. However, if :term:`SRC_URI` specifies to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001539fetch source from an archive that does not use this convention, or from
Andrew Geissler09036742021-06-25 14:25:14 -05001540an SCM like Git or Subversion, your recipe needs to define :term:`S`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001541
1542If processing your recipe using BitBake successfully unpacks the source
1543files, you need to be sure that the directory pointed to by ``${S}``
1544matches the structure of the source.
1545
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001546Patching Code
1547-------------
1548
1549Sometimes it is necessary to patch code after it has been fetched. Any
Andrew Geissler09036742021-06-25 14:25:14 -05001550files mentioned in :term:`SRC_URI` whose names end in ``.patch`` or
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001551``.diff`` or compressed versions of these suffixes (e.g. ``diff.gz`` are
1552treated as patches. The
1553:ref:`ref-tasks-patch` task
1554automatically applies these patches.
1555
1556The build system should be able to apply patches with the "-p1" option
1557(i.e. one directory level in the path will be stripped off). If your
1558patch needs to have more directory levels stripped off, specify the
Andrew Geissler09036742021-06-25 14:25:14 -05001559number of levels using the "striplevel" option in the :term:`SRC_URI` entry
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001560for the patch. Alternatively, if your patch needs to be applied in a
1561specific subdirectory that is not specified in the patch file, use the
1562"patchdir" option in the entry.
1563
1564As with all local files referenced in
1565:term:`SRC_URI` using ``file://``,
1566you should place patch files in a directory next to the recipe either
1567named the same as the base name of the recipe
1568(:term:`BP` and
1569:term:`BPN`) or "files".
1570
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001571Licensing
1572---------
1573
1574Your recipe needs to have both the
1575:term:`LICENSE` and
1576:term:`LIC_FILES_CHKSUM`
1577variables:
1578
Andrew Geissler09036742021-06-25 14:25:14 -05001579- :term:`LICENSE`: This variable specifies the license for the software.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001580 If you do not know the license under which the software you are
1581 building is distributed, you should go to the source code and look
1582 for that information. Typical files containing this information
Andrew Geissler09036742021-06-25 14:25:14 -05001583 include ``COPYING``, :term:`LICENSE`, and ``README`` files. You could
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001584 also find the information near the top of a source file. For example,
1585 given a piece of software licensed under the GNU General Public
Andrew Geissler09036742021-06-25 14:25:14 -05001586 License version 2, you would set :term:`LICENSE` as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001587
Andrew Geissler9aee5002022-03-30 16:27:02 +00001588 LICENSE = "GPL-2.0-only"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001589
Andrew Geissler09036742021-06-25 14:25:14 -05001590 The licenses you specify within :term:`LICENSE` can have any name as long
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001591 as you do not use spaces, since spaces are used as separators between
1592 license names. For standard licenses, use the names of the files in
Andrew Geissler09036742021-06-25 14:25:14 -05001593 ``meta/files/common-licenses/`` or the :term:`SPDXLICENSEMAP` flag names
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001594 defined in ``meta/conf/licenses.conf``.
1595
Andrew Geissler09036742021-06-25 14:25:14 -05001596- :term:`LIC_FILES_CHKSUM`: The OpenEmbedded build system uses this
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001597 variable to make sure the license text has not changed. If it has,
1598 the build produces an error and it affords you the chance to figure
1599 it out and correct the problem.
1600
1601 You need to specify all applicable licensing files for the software.
1602 At the end of the configuration step, the build process will compare
1603 the checksums of the files to be sure the text has not changed. Any
1604 differences result in an error with the message containing the
1605 current checksum. For more explanation and examples of how to set the
Andrew Geissler09036742021-06-25 14:25:14 -05001606 :term:`LIC_FILES_CHKSUM` variable, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001607 ":ref:`dev-manual/common-tasks:tracking license changes`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001608
1609 To determine the correct checksum string, you can list the
Andrew Geissler09036742021-06-25 14:25:14 -05001610 appropriate files in the :term:`LIC_FILES_CHKSUM` variable with incorrect
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001611 md5 strings, attempt to build the software, and then note the
1612 resulting error messages that will report the correct md5 strings.
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001613 See the ":ref:`dev-manual/common-tasks:fetching code`" section for
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001614 additional information.
1615
Andrew Geisslerc926e172021-05-07 16:11:35 -05001616 Here is an example that assumes the software has a ``COPYING`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001617
1618 LIC_FILES_CHKSUM = "file://COPYING;md5=xxx"
1619
1620 When you try to build the
1621 software, the build system will produce an error and give you the
1622 correct string that you can substitute into the recipe file for a
1623 subsequent build.
1624
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001625Dependencies
1626------------
1627
1628Most software packages have a short list of other packages that they
1629require, which are called dependencies. These dependencies fall into two
1630main categories: build-time dependencies, which are required when the
1631software is built; and runtime dependencies, which are required to be
1632installed on the target in order for the software to run.
1633
1634Within a recipe, you specify build-time dependencies using the
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001635:term:`DEPENDS` variable. Although there are nuances,
Andrew Geissler09036742021-06-25 14:25:14 -05001636items specified in :term:`DEPENDS` should be names of other
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001637recipes. It is important that you specify all build-time dependencies
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001638explicitly.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001639
1640Another consideration is that configure scripts might automatically
1641check for optional dependencies and enable corresponding functionality
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001642if those dependencies are found. If you wish to make a recipe that is
1643more generally useful (e.g. publish the recipe in a layer for others to
1644use), instead of hard-disabling the functionality, you can use the
1645:term:`PACKAGECONFIG` variable to allow functionality and the
1646corresponding dependencies to be enabled and disabled easily by other
1647users of the recipe.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001648
1649Similar to build-time dependencies, you specify runtime dependencies
1650through a variable -
1651:term:`RDEPENDS`, which is
1652package-specific. All variables that are package-specific need to have
1653the name of the package added to the end as an override. Since the main
1654package for a recipe has the same name as the recipe, and the recipe's
1655name can be found through the
1656``${``\ :term:`PN`\ ``}`` variable, then
1657you specify the dependencies for the main package by setting
Patrick Williams0ca19cc2021-08-16 14:03:13 -05001658``RDEPENDS:${PN}``. If the package were named ``${PN}-tools``, then you
1659would set ``RDEPENDS:${PN}-tools``, and so forth.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001660
1661Some runtime dependencies will be set automatically at packaging time.
1662These dependencies include any shared library dependencies (i.e. if a
1663package "example" contains "libexample" and another package "mypackage"
1664contains a binary that links to "libexample" then the OpenEmbedded build
1665system will automatically add a runtime dependency to "mypackage" on
1666"example"). See the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001667":ref:`overview-manual/concepts:automatically added runtime dependencies`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001668section in the Yocto Project Overview and Concepts Manual for further
1669details.
1670
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001671Configuring the Recipe
1672----------------------
1673
1674Most software provides some means of setting build-time configuration
1675options before compilation. Typically, setting these options is
1676accomplished by running a configure script with options, or by modifying
1677a build configuration file.
1678
1679.. note::
1680
1681 As of Yocto Project Release 1.7, some of the core recipes that
1682 package binary configuration scripts now disable the scripts due to
1683 the scripts previously requiring error-prone path substitution. The
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001684 OpenEmbedded build system uses ``pkg-config`` now, which is much more
1685 robust. You can find a list of the ``*-config`` scripts that are disabled
1686 in the ":ref:`migration-1.7-binary-configuration-scripts-disabled`" section
1687 in the Yocto Project Reference Manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001688
1689A major part of build-time configuration is about checking for
1690build-time dependencies and possibly enabling optional functionality as
1691a result. You need to specify any build-time dependencies for the
1692software you are building in your recipe's
1693:term:`DEPENDS` value, in terms of
1694other recipes that satisfy those dependencies. You can often find
1695build-time or runtime dependencies described in the software's
1696documentation.
1697
1698The following list provides configuration items of note based on how
1699your software is built:
1700
1701- *Autotools:* If your source files have a ``configure.ac`` file, then
1702 your software is built using Autotools. If this is the case, you just
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001703 need to modify the configuration.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001704
1705 When using Autotools, your recipe needs to inherit the
1706 :ref:`autotools <ref-classes-autotools>` class
1707 and your recipe does not have to contain a
1708 :ref:`ref-tasks-configure` task.
1709 However, you might still want to make some adjustments. For example,
1710 you can set
1711 :term:`EXTRA_OECONF` or
1712 :term:`PACKAGECONFIG_CONFARGS`
1713 to pass any needed configure options that are specific to the recipe.
1714
1715- *CMake:* If your source files have a ``CMakeLists.txt`` file, then
1716 your software is built using CMake. If this is the case, you just
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001717 need to modify the configuration.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001718
1719 When you use CMake, your recipe needs to inherit the
1720 :ref:`cmake <ref-classes-cmake>` class and your
1721 recipe does not have to contain a
1722 :ref:`ref-tasks-configure` task.
1723 You can make some adjustments by setting
1724 :term:`EXTRA_OECMAKE` to
1725 pass any needed configure options that are specific to the recipe.
1726
1727 .. note::
1728
1729 If you need to install one or more custom CMake toolchain files
1730 that are supplied by the application you are building, install the
Patrick Williams2194f502022-10-16 14:26:09 -05001731 files to ``${D}${datadir}/cmake/Modules`` during :ref:`ref-tasks-install`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001732
1733- *Other:* If your source files do not have a ``configure.ac`` or
1734 ``CMakeLists.txt`` file, then your software is built using some
1735 method other than Autotools or CMake. If this is the case, you
1736 normally need to provide a
1737 :ref:`ref-tasks-configure` task
1738 in your recipe unless, of course, there is nothing to configure.
1739
1740 Even if your software is not being built by Autotools or CMake, you
1741 still might not need to deal with any configuration issues. You need
1742 to determine if configuration is even a required step. You might need
1743 to modify a Makefile or some configuration file used for the build to
1744 specify necessary build options. Or, perhaps you might need to run a
1745 provided, custom configure script with the appropriate options.
1746
1747 For the case involving a custom configure script, you would run
1748 ``./configure --help`` and look for the options you need to set.
1749
1750Once configuration succeeds, it is always good practice to look at the
1751``log.do_configure`` file to ensure that the appropriate options have
1752been enabled and no additional build-time dependencies need to be added
Andrew Geissler09036742021-06-25 14:25:14 -05001753to :term:`DEPENDS`. For example, if the configure script reports that it
1754found something not mentioned in :term:`DEPENDS`, or that it did not find
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001755something that it needed for some desired optional functionality, then
Andrew Geissler09036742021-06-25 14:25:14 -05001756you would need to add those to :term:`DEPENDS`. Looking at the log might
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001757also reveal items being checked for, enabled, or both that you do not
Andrew Geissler09036742021-06-25 14:25:14 -05001758want, or items not being found that are in :term:`DEPENDS`, in which case
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001759you would need to look at passing extra options to the configure script
1760as needed. For reference information on configure options specific to
1761the software you are building, you can consult the output of the
1762``./configure --help`` command within ``${S}`` or consult the software's
1763upstream documentation.
1764
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001765Using Headers to Interface with Devices
1766---------------------------------------
1767
1768If your recipe builds an application that needs to communicate with some
1769device or needs an API into a custom kernel, you will need to provide
1770appropriate header files. Under no circumstances should you ever modify
1771the existing
1772``meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc`` file.
1773These headers are used to build ``libc`` and must not be compromised
1774with custom or machine-specific header information. If you customize
1775``libc`` through modified headers all other applications that use
1776``libc`` thus become affected.
1777
1778.. note::
1779
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001780 Never copy and customize the ``libc`` header file (i.e.
1781 ``meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc``).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001782
1783The correct way to interface to a device or custom kernel is to use a
1784separate package that provides the additional headers for the driver or
1785other unique interfaces. When doing so, your application also becomes
1786responsible for creating a dependency on that specific provider.
1787
1788Consider the following:
1789
1790- Never modify ``linux-libc-headers.inc``. Consider that file to be
1791 part of the ``libc`` system, and not something you use to access the
1792 kernel directly. You should access ``libc`` through specific ``libc``
1793 calls.
1794
1795- Applications that must talk directly to devices should either provide
1796 necessary headers themselves, or establish a dependency on a special
1797 headers package that is specific to that driver.
1798
1799For example, suppose you want to modify an existing header that adds I/O
1800control or network support. If the modifications are used by a small
1801number programs, providing a unique version of a header is easy and has
1802little impact. When doing so, bear in mind the guidelines in the
1803previous list.
1804
1805.. note::
1806
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001807 If for some reason your changes need to modify the behavior of the ``libc``,
1808 and subsequently all other applications on the system, use a ``.bbappend``
1809 to modify the ``linux-kernel-headers.inc`` file. However, take care to not
1810 make the changes machine specific.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001811
1812Consider a case where your kernel is older and you need an older
1813``libc`` ABI. The headers installed by your recipe should still be a
1814standard mainline kernel, not your own custom one.
1815
1816When you use custom kernel headers you need to get them from
1817:term:`STAGING_KERNEL_DIR`,
1818which is the directory with kernel headers that are required to build
Andrew Geisslerc926e172021-05-07 16:11:35 -05001819out-of-tree modules. Your recipe will also need the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001820
1821 do_configure[depends] += "virtual/kernel:do_shared_workdir"
1822
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001823Compilation
1824-----------
1825
Patrick Williams2194f502022-10-16 14:26:09 -05001826During a build, the :ref:`ref-tasks-compile` task happens after source is fetched,
1827unpacked, and configured. If the recipe passes through :ref:`ref-tasks-compile`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001828successfully, nothing needs to be done.
1829
1830However, if the compile step fails, you need to diagnose the failure.
1831Here are some common issues that cause failures.
1832
1833.. note::
1834
1835 For cases where improper paths are detected for configuration files
1836 or for when libraries/headers cannot be found, be sure you are using
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001837 the more robust ``pkg-config``. See the note in section
Andrew Geissler09209ee2020-12-13 08:44:15 -06001838 ":ref:`dev-manual/common-tasks:Configuring the Recipe`" for additional information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001839
1840- *Parallel build failures:* These failures manifest themselves as
1841 intermittent errors, or errors reporting that a file or directory
1842 that should be created by some other part of the build process could
1843 not be found. This type of failure can occur even if, upon
1844 inspection, the file or directory does exist after the build has
1845 failed, because that part of the build process happened in the wrong
1846 order.
1847
1848 To fix the problem, you need to either satisfy the missing dependency
1849 in the Makefile or whatever script produced the Makefile, or (as a
Andrew Geisslerc926e172021-05-07 16:11:35 -05001850 workaround) set :term:`PARALLEL_MAKE` to an empty string::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001851
1852 PARALLEL_MAKE = ""
1853
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001854 For information on parallel Makefile issues, see the
1855 ":ref:`dev-manual/common-tasks:debugging parallel make races`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001856
1857- *Improper host path usage:* This failure applies to recipes building
1858 for the target or ``nativesdk`` only. The failure occurs when the
1859 compilation process uses improper headers, libraries, or other files
1860 from the host system when cross-compiling for the target.
1861
1862 To fix the problem, examine the ``log.do_compile`` file to identify
1863 the host paths being used (e.g. ``/usr/include``, ``/usr/lib``, and
1864 so forth) and then either add configure options, apply a patch, or do
1865 both.
1866
1867- *Failure to find required libraries/headers:* If a build-time
1868 dependency is missing because it has not been declared in
1869 :term:`DEPENDS`, or because the
1870 dependency exists but the path used by the build process to find the
1871 file is incorrect and the configure step did not detect it, the
1872 compilation process could fail. For either of these failures, the
1873 compilation process notes that files could not be found. In these
1874 cases, you need to go back and add additional options to the
1875 configure script as well as possibly add additional build-time
Andrew Geissler09036742021-06-25 14:25:14 -05001876 dependencies to :term:`DEPENDS`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001877
1878 Occasionally, it is necessary to apply a patch to the source to
1879 ensure the correct paths are used. If you need to specify paths to
1880 find files staged into the sysroot from other recipes, use the
1881 variables that the OpenEmbedded build system provides (e.g.
Andrew Geissler09036742021-06-25 14:25:14 -05001882 :term:`STAGING_BINDIR`, :term:`STAGING_INCDIR`, :term:`STAGING_DATADIR`, and so
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001883 forth).
1884
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001885Installing
1886----------
1887
Patrick Williams2194f502022-10-16 14:26:09 -05001888During :ref:`ref-tasks-install`, the task copies the built files along with their
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001889hierarchy to locations that would mirror their locations on the target
1890device. The installation process copies files from the
1891``${``\ :term:`S`\ ``}``,
1892``${``\ :term:`B`\ ``}``, and
1893``${``\ :term:`WORKDIR`\ ``}``
1894directories to the ``${``\ :term:`D`\ ``}``
1895directory to create the structure as it should appear on the target
1896system.
1897
1898How your software is built affects what you must do to be sure your
1899software is installed correctly. The following list describes what you
1900must do for installation depending on the type of build system used by
1901the software being built:
1902
1903- *Autotools and CMake:* If the software your recipe is building uses
1904 Autotools or CMake, the OpenEmbedded build system understands how to
1905 install the software. Consequently, you do not have to have a
Patrick Williams2194f502022-10-16 14:26:09 -05001906 :ref:`ref-tasks-install` task as part of your recipe. You just need to make
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001907 sure the install portion of the build completes with no issues.
1908 However, if you wish to install additional files not already being
1909 installed by ``make install``, you should do this using a
Patrick Williams0ca19cc2021-08-16 14:03:13 -05001910 ``do_install:append`` function using the install command as described
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001911 in the "Manual" bulleted item later in this list.
1912
Patrick Williams2194f502022-10-16 14:26:09 -05001913- *Other (using* ``make install``\ *)*: You need to define a :ref:`ref-tasks-install`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001914 function in your recipe. The function should call
1915 ``oe_runmake install`` and will likely need to pass in the
1916 destination directory as well. How you pass that path is dependent on
1917 how the ``Makefile`` being run is written (e.g. ``DESTDIR=${D}``,
1918 ``PREFIX=${D}``, ``INSTALLROOT=${D}``, and so forth).
1919
1920 For an example recipe using ``make install``, see the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001921 ":ref:`dev-manual/common-tasks:makefile-based package`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001922
Patrick Williams2194f502022-10-16 14:26:09 -05001923- *Manual:* You need to define a :ref:`ref-tasks-install` function in your
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001924 recipe. The function must first use ``install -d`` to create the
1925 directories under
1926 ``${``\ :term:`D`\ ``}``. Once the
1927 directories exist, your function can use ``install`` to manually
1928 install the built software into the directories.
1929
1930 You can find more information on ``install`` at
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001931 https://www.gnu.org/software/coreutils/manual/html_node/install-invocation.html.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001932
1933For the scenarios that do not use Autotools or CMake, you need to track
1934the installation and diagnose and fix any issues until everything
1935installs correctly. You need to look in the default location of
1936``${D}``, which is ``${WORKDIR}/image``, to be sure your files have been
1937installed correctly.
1938
1939.. note::
1940
1941 - During the installation process, you might need to modify some of
1942 the installed files to suit the target layout. For example, you
1943 might need to replace hard-coded paths in an initscript with
1944 values of variables provided by the build system, such as
1945 replacing ``/usr/bin/`` with ``${bindir}``. If you do perform such
Patrick Williams2194f502022-10-16 14:26:09 -05001946 modifications during :ref:`ref-tasks-install`, be sure to modify the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001947 destination file after copying rather than before copying.
1948 Modifying after copying ensures that the build system can
Patrick Williams2194f502022-10-16 14:26:09 -05001949 re-execute :ref:`ref-tasks-install` if needed.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001950
1951 - ``oe_runmake install``, which can be run directly or can be run
1952 indirectly by the
1953 :ref:`autotools <ref-classes-autotools>` and
1954 :ref:`cmake <ref-classes-cmake>` classes,
1955 runs ``make install`` in parallel. Sometimes, a Makefile can have
1956 missing dependencies between targets that can result in race
1957 conditions. If you experience intermittent failures during
Patrick Williams2194f502022-10-16 14:26:09 -05001958 :ref:`ref-tasks-install`, you might be able to work around them by disabling
Andrew Geisslerc926e172021-05-07 16:11:35 -05001959 parallel Makefile installs by adding the following to the recipe::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001960
1961 PARALLEL_MAKEINST = ""
1962
1963 See :term:`PARALLEL_MAKEINST` for additional information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001964
1965 - If you need to install one or more custom CMake toolchain files
1966 that are supplied by the application you are building, install the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001967 files to ``${D}${datadir}/cmake/Modules`` during
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001968 :ref:`ref-tasks-install`.
1969
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001970Enabling System Services
1971------------------------
1972
1973If you want to install a service, which is a process that usually starts
1974on boot and runs in the background, then you must include some
1975additional definitions in your recipe.
1976
1977If you are adding services and the service initialization script or the
1978service file itself is not installed, you must provide for that
Patrick Williams0ca19cc2021-08-16 14:03:13 -05001979installation in your recipe using a ``do_install:append`` function. If
Patrick Williams2194f502022-10-16 14:26:09 -05001980your recipe already has a :ref:`ref-tasks-install` function, update the function
Patrick Williams0ca19cc2021-08-16 14:03:13 -05001981near its end rather than adding an additional ``do_install:append``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001982function.
1983
1984When you create the installation for your services, you need to
1985accomplish what is normally done by ``make install``. In other words,
1986make sure your installation arranges the output similar to how it is
1987arranged on the target system.
1988
1989The OpenEmbedded build system provides support for starting services two
1990different ways:
1991
1992- *SysVinit:* SysVinit is a system and service manager that manages the
1993 init system used to control the very basic functions of your system.
1994 The init program is the first program started by the Linux kernel
1995 when the system boots. Init then controls the startup, running and
1996 shutdown of all other programs.
1997
1998 To enable a service using SysVinit, your recipe needs to inherit the
1999 :ref:`update-rc.d <ref-classes-update-rc.d>`
2000 class. The class helps facilitate safely installing the package on
2001 the target.
2002
2003 You will need to set the
2004 :term:`INITSCRIPT_PACKAGES`,
2005 :term:`INITSCRIPT_NAME`,
2006 and
2007 :term:`INITSCRIPT_PARAMS`
2008 variables within your recipe.
2009
2010- *systemd:* System Management Daemon (systemd) was designed to replace
2011 SysVinit and to provide enhanced management of services. For more
2012 information on systemd, see the systemd homepage at
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002013 https://freedesktop.org/wiki/Software/systemd/.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002014
2015 To enable a service using systemd, your recipe needs to inherit the
2016 :ref:`systemd <ref-classes-systemd>` class. See
2017 the ``systemd.bbclass`` file located in your :term:`Source Directory`
2018 section for
2019 more information.
2020
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002021Packaging
2022---------
2023
2024Successful packaging is a combination of automated processes performed
2025by the OpenEmbedded build system and some specific steps you need to
2026take. The following list describes the process:
2027
Patrick Williams2194f502022-10-16 14:26:09 -05002028- *Splitting Files*: The :ref:`ref-tasks-package` task splits the files produced
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002029 by the recipe into logical components. Even software that produces a
2030 single binary might still have debug symbols, documentation, and
Patrick Williams2194f502022-10-16 14:26:09 -05002031 other logical components that should be split out. The :ref:`ref-tasks-package`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002032 task ensures that files are split up and packaged correctly.
2033
2034- *Running QA Checks*: The
2035 :ref:`insane <ref-classes-insane>` class adds a
2036 step to the package generation process so that output quality
2037 assurance checks are generated by the OpenEmbedded build system. This
2038 step performs a range of checks to be sure the build's output is free
2039 of common problems that show up during runtime. For information on
2040 these checks, see the
2041 :ref:`insane <ref-classes-insane>` class and
Andrew Geissler09209ee2020-12-13 08:44:15 -06002042 the ":ref:`ref-manual/qa-checks:qa error and warning messages`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002043 chapter in the Yocto Project Reference Manual.
2044
2045- *Hand-Checking Your Packages*: After you build your software, you
2046 need to be sure your packages are correct. Examine the
2047 ``${``\ :term:`WORKDIR`\ ``}/packages-split``
2048 directory and make sure files are where you expect them to be. If you
2049 discover problems, you can set
2050 :term:`PACKAGES`,
2051 :term:`FILES`,
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002052 ``do_install(:append)``, and so forth as needed.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002053
2054- *Splitting an Application into Multiple Packages*: If you need to
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05002055 split an application into several packages, see the
2056 ":ref:`dev-manual/common-tasks:splitting an application into multiple packages`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002057 section for an example.
2058
2059- *Installing a Post-Installation Script*: For an example showing how
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05002060 to install a post-installation script, see the
2061 ":ref:`dev-manual/common-tasks:post-installation scripts`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002062
2063- *Marking Package Architecture*: Depending on what your recipe is
2064 building and how it is configured, it might be important to mark the
2065 packages produced as being specific to a particular machine, or to
2066 mark them as not being specific to a particular machine or
2067 architecture at all.
2068
2069 By default, packages apply to any machine with the same architecture
2070 as the target machine. When a recipe produces packages that are
2071 machine-specific (e.g. the
2072 :term:`MACHINE` value is passed
2073 into the configure script or a patch is applied only for a particular
2074 machine), you should mark them as such by adding the following to the
Andrew Geisslerc926e172021-05-07 16:11:35 -05002075 recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002076
2077 PACKAGE_ARCH = "${MACHINE_ARCH}"
2078
2079 On the other hand, if the recipe produces packages that do not
2080 contain anything specific to the target machine or architecture at
2081 all (e.g. recipes that simply package script files or configuration
2082 files), you should use the
2083 :ref:`allarch <ref-classes-allarch>` class to
Andrew Geisslerc926e172021-05-07 16:11:35 -05002084 do this for you by adding this to your recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002085
2086 inherit allarch
2087
2088 Ensuring that the package architecture is correct is not critical
2089 while you are doing the first few builds of your recipe. However, it
2090 is important in order to ensure that your recipe rebuilds (or does
2091 not rebuild) appropriately in response to changes in configuration,
2092 and to ensure that you get the appropriate packages installed on the
2093 target machine, particularly if you run separate builds for more than
2094 one target machine.
2095
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002096Sharing Files Between Recipes
2097-----------------------------
2098
2099Recipes often need to use files provided by other recipes on the build
2100host. For example, an application linking to a common library needs
2101access to the library itself and its associated headers. The way this
2102access is accomplished is by populating a sysroot with files. Each
2103recipe has two sysroots in its work directory, one for target files
2104(``recipe-sysroot``) and one for files that are native to the build host
2105(``recipe-sysroot-native``).
2106
2107.. note::
2108
2109 You could find the term "staging" used within the Yocto project
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002110 regarding files populating sysroots (e.g. the :term:`STAGING_DIR`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002111 variable).
2112
2113Recipes should never populate the sysroot directly (i.e. write files
2114into sysroot). Instead, files should be installed into standard
2115locations during the
2116:ref:`ref-tasks-install` task within
2117the ``${``\ :term:`D`\ ``}`` directory. The
2118reason for this limitation is that almost all files that populate the
2119sysroot are cataloged in manifests in order to ensure the files can be
2120removed later when a recipe is either modified or removed. Thus, the
2121sysroot is able to remain free from stale files.
2122
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05002123A subset of the files installed by the :ref:`ref-tasks-install` task are
Patrick Williams975a06f2022-10-21 14:42:47 -05002124used by the :ref:`ref-tasks-populate_sysroot` task as defined by the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05002125:term:`SYSROOT_DIRS` variable to automatically populate the sysroot. It
2126is possible to modify the list of directories that populate the sysroot.
2127The following example shows how you could add the ``/opt`` directory to
Andrew Geisslerc926e172021-05-07 16:11:35 -05002128the list of directories within a recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002129
2130 SYSROOT_DIRS += "/opt"
2131
Andrew Geisslerd1e89492021-02-12 15:35:20 -06002132.. note::
2133
2134 The `/sysroot-only` is to be used by recipes that generate artifacts
2135 that are not included in the target filesystem, allowing them to share
Andrew Geissler09036742021-06-25 14:25:14 -05002136 these artifacts without needing to use the :term:`DEPLOY_DIR`.
Andrew Geisslerd1e89492021-02-12 15:35:20 -06002137
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05002138For a more complete description of the :ref:`ref-tasks-populate_sysroot`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002139task and its associated functions, see the
2140:ref:`staging <ref-classes-staging>` class.
2141
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002142Using Virtual Providers
2143-----------------------
2144
2145Prior to a build, if you know that several different recipes provide the
2146same functionality, you can use a virtual provider (i.e. ``virtual/*``)
2147as a placeholder for the actual provider. The actual provider is
2148determined at build-time.
2149
2150A common scenario where a virtual provider is used would be for the
2151kernel recipe. Suppose you have three kernel recipes whose
2152:term:`PN` values map to ``kernel-big``,
2153``kernel-mid``, and ``kernel-small``. Furthermore, each of these recipes
2154in some way uses a :term:`PROVIDES`
2155statement that essentially identifies itself as being able to provide
2156``virtual/kernel``. Here is one way through the
Andrew Geisslerc926e172021-05-07 16:11:35 -05002157:ref:`kernel <ref-classes-kernel>` class::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002158
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002159 PROVIDES += "virtual/kernel"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002160
Andrew Geissler595f6302022-01-24 19:11:47 +00002161Any recipe that inherits the :ref:`kernel <ref-classes-kernel>` class is
Andrew Geissler09036742021-06-25 14:25:14 -05002162going to utilize a :term:`PROVIDES` statement that identifies that recipe as
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002163being able to provide the ``virtual/kernel`` item.
2164
2165Now comes the time to actually build an image and you need a kernel
2166recipe, but which one? You can configure your build to call out the
Andrew Geissler09209ee2020-12-13 08:44:15 -06002167kernel recipe you want by using the :term:`PREFERRED_PROVIDER` variable. As
2168an example, consider the :yocto_git:`x86-base.inc
Andrew Geisslerd159c7f2021-09-02 21:05:58 -05002169</poky/tree/meta/conf/machine/include/x86/x86-base.inc>` include file, which is a
Andrew Geissler09209ee2020-12-13 08:44:15 -06002170machine (i.e. :term:`MACHINE`) configuration file. This include file is the
2171reason all x86-based machines use the ``linux-yocto`` kernel. Here are the
Andrew Geisslerc926e172021-05-07 16:11:35 -05002172relevant lines from the include file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002173
2174 PREFERRED_PROVIDER_virtual/kernel ??= "linux-yocto"
2175 PREFERRED_VERSION_linux-yocto ??= "4.15%"
2176
2177When you use a virtual provider, you do not have to "hard code" a recipe
2178name as a build dependency. You can use the
2179:term:`DEPENDS` variable to state the
Andrew Geisslerc926e172021-05-07 16:11:35 -05002180build is dependent on ``virtual/kernel`` for example::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002181
2182 DEPENDS = "virtual/kernel"
2183
2184During the build, the OpenEmbedded build system picks
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002185the correct recipe needed for the ``virtual/kernel`` dependency based on
Andrew Geissler09036742021-06-25 14:25:14 -05002186the :term:`PREFERRED_PROVIDER` variable. If you want to use the small kernel
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002187mentioned at the beginning of this section, configure your build as
Andrew Geisslerc926e172021-05-07 16:11:35 -05002188follows::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002189
2190 PREFERRED_PROVIDER_virtual/kernel ??= "kernel-small"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002191
2192.. note::
2193
Andrew Geissler09036742021-06-25 14:25:14 -05002194 Any recipe that :term:`PROVIDES` a ``virtual/*`` item that is ultimately not
2195 selected through :term:`PREFERRED_PROVIDER` does not get built. Preventing these
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002196 recipes from building is usually the desired behavior since this mechanism's
2197 purpose is to select between mutually exclusive alternative providers.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002198
2199The following lists specific examples of virtual providers:
2200
2201- ``virtual/kernel``: Provides the name of the kernel recipe to use
2202 when building a kernel image.
2203
2204- ``virtual/bootloader``: Provides the name of the bootloader to use
2205 when building an image.
2206
2207- ``virtual/libgbm``: Provides ``gbm.pc``.
2208
2209- ``virtual/egl``: Provides ``egl.pc`` and possibly ``wayland-egl.pc``.
2210
2211- ``virtual/libgl``: Provides ``gl.pc`` (i.e. libGL).
2212
2213- ``virtual/libgles1``: Provides ``glesv1_cm.pc`` (i.e. libGLESv1_CM).
2214
2215- ``virtual/libgles2``: Provides ``glesv2.pc`` (i.e. libGLESv2).
2216
2217.. note::
2218
2219 Virtual providers only apply to build time dependencies specified with
2220 :term:`PROVIDES` and :term:`DEPENDS`. They do not apply to runtime
2221 dependencies specified with :term:`RPROVIDES` and :term:`RDEPENDS`.
2222
2223Properly Versioning Pre-Release Recipes
2224---------------------------------------
2225
2226Sometimes the name of a recipe can lead to versioning problems when the
2227recipe is upgraded to a final release. For example, consider the
2228``irssi_0.8.16-rc1.bb`` recipe file in the list of example recipes in
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05002229the ":ref:`dev-manual/common-tasks:storing and naming the recipe`" section.
2230This recipe is at a release candidate stage (i.e. "rc1"). When the recipe is
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002231released, the recipe filename becomes ``irssi_0.8.16.bb``. The version
2232change from ``0.8.16-rc1`` to ``0.8.16`` is seen as a decrease by the
2233build system and package managers, so the resulting packages will not
2234correctly trigger an upgrade.
2235
2236In order to ensure the versions compare properly, the recommended
2237convention is to set :term:`PV` within the
2238recipe to "previous_version+current_version". You can use an additional
2239variable so that you can use the current version elsewhere. Here is an
Andrew Geisslerc926e172021-05-07 16:11:35 -05002240example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002241
2242 REALPV = "0.8.16-rc1"
2243 PV = "0.8.15+${REALPV}"
2244
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002245Post-Installation Scripts
2246-------------------------
2247
2248Post-installation scripts run immediately after installing a package on
2249the target or during image creation when a package is included in an
2250image. To add a post-installation script to a package, add a
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002251``pkg_postinst:``\ `PACKAGENAME`\ ``()`` function to the recipe file
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002252(``.bb``) and replace `PACKAGENAME` with the name of the package you want
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002253to attach to the ``postinst`` script. To apply the post-installation
2254script to the main package for the recipe, which is usually what is
2255required, specify
2256``${``\ :term:`PN`\ ``}`` in place of
2257PACKAGENAME.
2258
Andrew Geisslerc926e172021-05-07 16:11:35 -05002259A post-installation function has the following structure::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002260
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002261 pkg_postinst:PACKAGENAME() {
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002262 # Commands to carry out
2263 }
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002264
2265The script defined in the post-installation function is called when the
2266root filesystem is created. If the script succeeds, the package is
2267marked as installed.
2268
2269.. note::
2270
2271 Any RPM post-installation script that runs on the target should
2272 return a 0 exit code. RPM does not allow non-zero exit codes for
2273 these scripts, and the RPM package manager will cause the package to
2274 fail installation on the target.
2275
2276Sometimes it is necessary for the execution of a post-installation
2277script to be delayed until the first boot. For example, the script might
2278need to be executed on the device itself. To delay script execution
2279until boot time, you must explicitly mark post installs to defer to the
2280target. You can use ``pkg_postinst_ontarget()`` or call
2281``postinst_intercept delay_to_first_boot`` from ``pkg_postinst()``. Any
2282failure of a ``pkg_postinst()`` script (including exit 1) triggers an
2283error during the
2284:ref:`ref-tasks-rootfs` task.
2285
2286If you have recipes that use ``pkg_postinst`` function and they require
2287the use of non-standard native tools that have dependencies during
Andrew Geissler595f6302022-01-24 19:11:47 +00002288root filesystem construction, you need to use the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002289:term:`PACKAGE_WRITE_DEPS`
2290variable in your recipe to list these tools. If you do not use this
2291variable, the tools might be missing and execution of the
2292post-installation script is deferred until first boot. Deferring the
Andrew Geissler595f6302022-01-24 19:11:47 +00002293script to the first boot is undesirable and impossible for read-only
2294root filesystems.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002295
2296.. note::
2297
William A. Kennington IIIac69b482021-06-02 12:28:27 -07002298 There is equivalent support for pre-install, pre-uninstall, and post-uninstall
2299 scripts by way of ``pkg_preinst``, ``pkg_prerm``, and ``pkg_postrm``,
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002300 respectively. These scrips work in exactly the same way as does
2301 ``pkg_postinst`` with the exception that they run at different times. Also,
2302 because of when they run, they are not applicable to being run at image
2303 creation time like ``pkg_postinst``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002304
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002305Testing
2306-------
2307
2308The final step for completing your recipe is to be sure that the
2309software you built runs correctly. To accomplish runtime testing, add
2310the build's output packages to your image and test them on the target.
2311
2312For information on how to customize your image by adding specific
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05002313packages, see ":ref:`dev-manual/common-tasks:customizing images`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002314
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002315Examples
2316--------
2317
2318To help summarize how to write a recipe, this section provides some
2319examples given various scenarios:
2320
2321- Recipes that use local files
2322
2323- Using an Autotooled package
2324
2325- Using a Makefile-based package
2326
2327- Splitting an application into multiple packages
2328
2329- Adding binaries to an image
2330
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002331Single .c File Package (Hello World!)
2332~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2333
2334Building an application from a single file that is stored locally (e.g.
2335under ``files``) requires a recipe that has the file listed in the
Andrew Geissler09036742021-06-25 14:25:14 -05002336:term:`SRC_URI` variable. Additionally, you need to manually write the
Patrick Williams2194f502022-10-16 14:26:09 -05002337:ref:`ref-tasks-compile` and :ref:`ref-tasks-install` tasks. The :term:`S` variable defines the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002338directory containing the source code, which is set to
Andrew Geissler615f2f12022-07-15 14:00:58 -05002339:term:`WORKDIR` in this case --- the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002340directory BitBake uses for the build.
2341::
2342
2343 SUMMARY = "Simple helloworld application"
2344 SECTION = "examples"
2345 LICENSE = "MIT"
2346 LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
2347
2348 SRC_URI = "file://helloworld.c"
2349
2350 S = "${WORKDIR}"
2351
2352 do_compile() {
Andrew Geisslerd1e89492021-02-12 15:35:20 -06002353 ${CC} ${LDFLAGS} helloworld.c -o helloworld
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002354 }
2355
2356 do_install() {
2357 install -d ${D}${bindir}
2358 install -m 0755 helloworld ${D}${bindir}
2359 }
2360
2361By default, the ``helloworld``, ``helloworld-dbg``, and
2362``helloworld-dev`` packages are built. For information on how to
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05002363customize the packaging process, see the
2364":ref:`dev-manual/common-tasks:splitting an application into multiple packages`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002365section.
2366
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002367Autotooled Package
2368~~~~~~~~~~~~~~~~~~
2369
2370Applications that use Autotools such as ``autoconf`` and ``automake``
Andrew Geissler09036742021-06-25 14:25:14 -05002371require a recipe that has a source archive listed in :term:`SRC_URI` and
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002372also inherit the
2373:ref:`autotools <ref-classes-autotools>` class,
2374which contains the definitions of all the steps needed to build an
2375Autotool-based application. The result of the build is automatically
2376packaged. And, if the application uses NLS for localization, packages
2377with local information are generated (one package per language).
2378Following is one example: (``hello_2.3.bb``)
2379::
2380
2381 SUMMARY = "GNU Helloworld application"
2382 SECTION = "examples"
Andrew Geissler9aee5002022-03-30 16:27:02 +00002383 LICENSE = "GPL-2.0-or-later"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002384 LIC_FILES_CHKSUM = "file://COPYING;md5=751419260aa954499f7abaabaa882bbe"
2385
2386 SRC_URI = "${GNU_MIRROR}/hello/hello-${PV}.tar.gz"
2387
2388 inherit autotools gettext
2389
Andrew Geissler09036742021-06-25 14:25:14 -05002390The variable :term:`LIC_FILES_CHKSUM` is used to track source license
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002391changes as described in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06002392":ref:`dev-manual/common-tasks:tracking license changes`" section in
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002393the Yocto Project Overview and Concepts Manual. You can quickly create
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002394Autotool-based recipes in a manner similar to the previous example.
2395
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002396Makefile-Based Package
2397~~~~~~~~~~~~~~~~~~~~~~
2398
2399Applications that use GNU ``make`` also require a recipe that has the
Andrew Geissler09036742021-06-25 14:25:14 -05002400source archive listed in :term:`SRC_URI`. You do not need to add a
Patrick Williams2194f502022-10-16 14:26:09 -05002401:ref:`ref-tasks-compile` step since by default BitBake starts the ``make`` command
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002402to compile the application. If you need additional ``make`` options, you
2403should store them in the
2404:term:`EXTRA_OEMAKE` or
2405:term:`PACKAGECONFIG_CONFARGS`
2406variables. BitBake passes these options into the GNU ``make``
Patrick Williams2194f502022-10-16 14:26:09 -05002407invocation. Note that a :ref:`ref-tasks-install` task is still required.
2408Otherwise, BitBake runs an empty :ref:`ref-tasks-install` task by default.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002409
2410Some applications might require extra parameters to be passed to the
2411compiler. For example, the application might need an additional header
Andrew Geissler09036742021-06-25 14:25:14 -05002412path. You can accomplish this by adding to the :term:`CFLAGS` variable. The
Andrew Geisslerc926e172021-05-07 16:11:35 -05002413following example shows this::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002414
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002415 CFLAGS:prepend = "-I ${S}/include "
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002416
Andrew Geissler9aee5002022-03-30 16:27:02 +00002417In the following example, ``lz4`` is a makefile-based package::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002418
Andrew Geissler9aee5002022-03-30 16:27:02 +00002419 SUMMARY = "Extremely Fast Compression algorithm"
2420 DESCRIPTION = "LZ4 is a very fast lossless compression algorithm, providing compression speed at 400 MB/s per core, scalable with multi-cores CPU. It also features an extremely fast decoder, with speed in multiple GB/s per core, typically reaching RAM speed limits on multi-core systems."
2421 HOMEPAGE = "https://github.com/lz4/lz4"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002422
Andrew Geissler9aee5002022-03-30 16:27:02 +00002423 LICENSE = "BSD-2-Clause | GPL-2.0-only"
2424 LIC_FILES_CHKSUM = "file://lib/LICENSE;md5=ebc2ea4814a64de7708f1571904b32cc \
2425 file://programs/COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263 \
2426 file://LICENSE;md5=d57c0d21cb917fb4e0af2454aa48b956 \
2427 "
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002428
Andrew Geissler9aee5002022-03-30 16:27:02 +00002429 PE = "1"
2430
2431 SRCREV = "d44371841a2f1728a3f36839fd4b7e872d0927d3"
2432
2433 SRC_URI = "git://github.com/lz4/lz4.git;branch=release;protocol=https \
2434 file://CVE-2021-3520.patch \
2435 "
2436 UPSTREAM_CHECK_GITTAGREGEX = "v(?P<pver>.*)"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002437
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002438 S = "${WORKDIR}/git"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002439
Andrew Geissler9aee5002022-03-30 16:27:02 +00002440 # Fixed in r118, which is larger than the current version.
2441 CVE_CHECK_IGNORE += "CVE-2014-4715"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002442
Andrew Geissler9aee5002022-03-30 16:27:02 +00002443 EXTRA_OEMAKE = "PREFIX=${prefix} CC='${CC}' CFLAGS='${CFLAGS}' DESTDIR=${D} LIBDIR=${libdir} INCLUDEDIR=${includedir} BUILD_STATIC=no"
2444
2445 do_install() {
2446 oe_runmake install
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002447 }
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002448
Andrew Geissler9aee5002022-03-30 16:27:02 +00002449 BBCLASSEXTEND = "native nativesdk"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002450
2451Splitting an Application into Multiple Packages
2452~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2453
Andrew Geissler09036742021-06-25 14:25:14 -05002454You can use the variables :term:`PACKAGES` and :term:`FILES` to split an
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002455application into multiple packages.
2456
2457Following is an example that uses the ``libxpm`` recipe. By default,
2458this recipe generates a single package that contains the library along
2459with a few binaries. You can modify the recipe to split the binaries
Andrew Geisslerc926e172021-05-07 16:11:35 -05002460into separate packages::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002461
2462 require xorg-lib-common.inc
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002463
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002464 SUMMARY = "Xpm: X Pixmap extension library"
Andrew Geissler5199d832021-09-24 16:47:35 -05002465 LICENSE = "MIT"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002466 LIC_FILES_CHKSUM = "file://COPYING;md5=51f4270b012ecd4ab1a164f5f4ed6cf7"
2467 DEPENDS += "libxext libsm libxt"
2468 PE = "1"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002469
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002470 XORG_PN = "libXpm"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002471
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002472 PACKAGES =+ "sxpm cxpm"
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002473 FILES:cxpm = "${bindir}/cxpm"
2474 FILES:sxpm = "${bindir}/sxpm"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002475
2476In the previous example, we want to ship the ``sxpm`` and ``cxpm``
2477binaries in separate packages. Since ``bindir`` would be packaged into
Andrew Geissler09036742021-06-25 14:25:14 -05002478the main :term:`PN` package by default, we prepend the :term:`PACKAGES` variable
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002479so additional package names are added to the start of list. This results
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002480in the extra ``FILES:*`` variables then containing information that
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002481define which files and directories go into which packages. Files
2482included by earlier packages are skipped by latter packages. Thus, the
Andrew Geissler09036742021-06-25 14:25:14 -05002483main :term:`PN` package does not include the above listed files.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002484
2485Packaging Externally Produced Binaries
2486~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2487
2488Sometimes, you need to add pre-compiled binaries to an image. For
William A. Kennington IIIac69b482021-06-02 12:28:27 -07002489example, suppose that there are binaries for proprietary code,
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002490created by a particular division of a company. Your part of the company
2491needs to use those binaries as part of an image that you are building
2492using the OpenEmbedded build system. Since you only have the binaries
2493and not the source code, you cannot use a typical recipe that expects to
2494fetch the source specified in
2495:term:`SRC_URI` and then compile it.
2496
2497One method is to package the binaries and then install them as part of
2498the image. Generally, it is not a good idea to package binaries since,
2499among other things, it can hinder the ability to reproduce builds and
2500could lead to compatibility problems with ABI in the future. However,
2501sometimes you have no choice.
2502
2503The easiest solution is to create a recipe that uses the
2504:ref:`bin_package <ref-classes-bin-package>` class
2505and to be sure that you are using default locations for build artifacts.
Andrew Geissler595f6302022-01-24 19:11:47 +00002506In most cases, the :ref:`bin_package <ref-classes-bin-package>` class handles "skipping" the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002507configure and compile steps as well as sets things up to grab packages
2508from the appropriate area. In particular, this class sets ``noexec`` on
2509both the :ref:`ref-tasks-configure`
2510and :ref:`ref-tasks-compile` tasks,
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002511sets ``FILES:${PN}`` to "/" so that it picks up all files, and sets up a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002512:ref:`ref-tasks-install` task, which
2513effectively copies all files from ``${S}`` to ``${D}``. The
Andrew Geissler595f6302022-01-24 19:11:47 +00002514:ref:`bin_package <ref-classes-bin-package>` class works well when the files extracted into ``${S}``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002515are already laid out in the way they should be laid out on the target.
2516For more information on these variables, see the
2517:term:`FILES`,
2518:term:`PN`,
2519:term:`S`, and
2520:term:`D` variables in the Yocto Project
2521Reference Manual's variable glossary.
2522
2523.. note::
2524
2525 - Using :term:`DEPENDS` is a good
2526 idea even for components distributed in binary form, and is often
2527 necessary for shared libraries. For a shared library, listing the
Andrew Geissler09036742021-06-25 14:25:14 -05002528 library dependencies in :term:`DEPENDS` makes sure that the libraries
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002529 are available in the staging sysroot when other recipes link
2530 against the library, which might be necessary for successful
2531 linking.
2532
Andrew Geissler09036742021-06-25 14:25:14 -05002533 - Using :term:`DEPENDS` also allows runtime dependencies between
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002534 packages to be added automatically. See the
Andrew Geissler09209ee2020-12-13 08:44:15 -06002535 ":ref:`overview-manual/concepts:automatically added runtime dependencies`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002536 section in the Yocto Project Overview and Concepts Manual for more
2537 information.
2538
Andrew Geissler595f6302022-01-24 19:11:47 +00002539If 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 -05002540doing the following:
2541
2542- Create a recipe where the
2543 :ref:`ref-tasks-configure` and
2544 :ref:`ref-tasks-compile` tasks do
2545 nothing: It is usually sufficient to just not define these tasks in
2546 the recipe, because the default implementations do nothing unless a
2547 Makefile is found in
2548 ``${``\ :term:`S`\ ``}``.
2549
2550 If ``${S}`` might contain a Makefile, or if you inherit some class
Patrick Williams2194f502022-10-16 14:26:09 -05002551 that replaces :ref:`ref-tasks-configure` and :ref:`ref-tasks-compile` with custom
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002552 versions, then you can use the
2553 ``[``\ :ref:`noexec <bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ``]``
Andrew Geisslerc926e172021-05-07 16:11:35 -05002554 flag to turn the tasks into no-ops, as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002555
2556 do_configure[noexec] = "1"
2557 do_compile[noexec] = "1"
2558
2559 Unlike
2560 :ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:deleting a task`,
2561 using the flag preserves the dependency chain from the
2562 :ref:`ref-tasks-fetch`,
2563 :ref:`ref-tasks-unpack`, and
2564 :ref:`ref-tasks-patch` tasks to the
2565 :ref:`ref-tasks-install` task.
2566
Patrick Williams2194f502022-10-16 14:26:09 -05002567- Make sure your :ref:`ref-tasks-install` task installs the binaries
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002568 appropriately.
2569
2570- Ensure that you set up :term:`FILES`
2571 (usually
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002572 ``FILES:${``\ :term:`PN`\ ``}``) to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002573 point to the files you have installed, which of course depends on
2574 where you have installed them and whether those files are in
2575 different locations than the defaults.
2576
2577Following Recipe Style Guidelines
2578---------------------------------
2579
2580When writing recipes, it is good to conform to existing style
Andrew Geisslerd1e89492021-02-12 15:35:20 -06002581guidelines. The :oe_wiki:`OpenEmbedded Styleguide </Styleguide>` wiki page
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002582provides rough guidelines for preferred recipe style.
2583
2584It is common for existing recipes to deviate a bit from this style.
2585However, aiming for at least a consistent style is a good idea. Some
2586practices, such as omitting spaces around ``=`` operators in assignments
2587or ordering recipe components in an erratic way, are widely seen as poor
2588style.
2589
2590Recipe Syntax
2591-------------
2592
2593Understanding recipe file syntax is important for writing recipes. The
2594following list overviews the basic items that make up a BitBake recipe
2595file. For more complete BitBake syntax descriptions, see the
Andrew Geissler615f2f12022-07-15 14:00:58 -05002596":doc:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002597chapter of the BitBake User Manual.
2598
2599- *Variable Assignments and Manipulations:* Variable assignments allow
2600 a value to be assigned to a variable. The assignment can be static
2601 text or might include the contents of other variables. In addition to
2602 the assignment, appending and prepending operations are also
2603 supported.
2604
2605 The following example shows some of the ways you can use variables in
Andrew Geisslerc926e172021-05-07 16:11:35 -05002606 recipes::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002607
2608 S = "${WORKDIR}/postfix-${PV}"
2609 CFLAGS += "-DNO_ASM"
Andrew Geissler87f5cff2022-09-30 13:13:31 -05002610 CFLAGS:append = " --enable-important-feature"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002611
2612- *Functions:* Functions provide a series of actions to be performed.
2613 You usually use functions to override the default implementation of a
2614 task function or to complement a default function (i.e. append or
2615 prepend to an existing function). Standard functions use ``sh`` shell
2616 syntax, although access to OpenEmbedded variables and internal
2617 methods are also available.
2618
William A. Kennington IIIac69b482021-06-02 12:28:27 -07002619 Here is an example function from the ``sed`` recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002620
2621 do_install () {
2622 autotools_do_install
2623 install -d ${D}${base_bindir}
2624 mv ${D}${bindir}/sed ${D}${base_bindir}/sed
2625 rmdir ${D}${bindir}/
2626 }
2627
2628 It is
2629 also possible to implement new functions that are called between
2630 existing tasks as long as the new functions are not replacing or
2631 complementing the default functions. You can implement functions in
2632 Python instead of shell. Both of these options are not seen in the
2633 majority of recipes.
2634
2635- *Keywords:* BitBake recipes use only a few keywords. You use keywords
2636 to include common functions (``inherit``), load parts of a recipe
2637 from other files (``include`` and ``require``) and export variables
2638 to the environment (``export``).
2639
Andrew Geisslerc926e172021-05-07 16:11:35 -05002640 The following example shows the use of some of these keywords::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002641
2642 export POSTCONF = "${STAGING_BINDIR}/postconf"
2643 inherit autoconf
2644 require otherfile.inc
2645
2646- *Comments (#):* Any lines that begin with the hash character (``#``)
Andrew Geisslerc926e172021-05-07 16:11:35 -05002647 are treated as comment lines and are ignored::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002648
2649 # This is a comment
2650
2651This next list summarizes the most important and most commonly used
2652parts of the recipe syntax. For more information on these parts of the
2653syntax, you can reference the
Andrew Geissler615f2f12022-07-15 14:00:58 -05002654":doc:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata`" chapter
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002655in the BitBake User Manual.
2656
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002657- *Line Continuation (\\):* Use the backward slash (``\``) character to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002658 split a statement over multiple lines. Place the slash character at
Andrew Geisslerc926e172021-05-07 16:11:35 -05002659 the end of the line that is to be continued on the next line::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002660
2661 VAR = "A really long \
2662 line"
2663
2664 .. note::
2665
2666 You cannot have any characters including spaces or tabs after the
2667 slash character.
2668
2669- *Using Variables (${VARNAME}):* Use the ``${VARNAME}`` syntax to
Andrew Geisslerc926e172021-05-07 16:11:35 -05002670 access the contents of a variable::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002671
2672 SRC_URI = "${SOURCEFORGE_MIRROR}/libpng/zlib-${PV}.tar.gz"
2673
2674 .. note::
2675
2676 It is important to understand that the value of a variable
2677 expressed in this form does not get substituted automatically. The
2678 expansion of these expressions happens on-demand later (e.g.
2679 usually when a function that makes reference to the variable
2680 executes). This behavior ensures that the values are most
2681 appropriate for the context in which they are finally used. On the
2682 rare occasion that you do need the variable expression to be
2683 expanded immediately, you can use the
2684 :=
2685 operator instead of
2686 =
2687 when you make the assignment, but this is not generally needed.
2688
2689- *Quote All Assignments ("value"):* Use double quotes around values in
Andrew Geisslerc926e172021-05-07 16:11:35 -05002690 all variable assignments (e.g. ``"value"``). Following is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002691
2692 VAR1 = "${OTHERVAR}"
2693 VAR2 = "The version is ${PV}"
2694
2695- *Conditional Assignment (?=):* Conditional assignment is used to
2696 assign a value to a variable, but only when the variable is currently
2697 unset. Use the question mark followed by the equal sign (``?=``) to
2698 make a "soft" assignment used for conditional assignment. Typically,
2699 "soft" assignments are used in the ``local.conf`` file for variables
2700 that are allowed to come through from the external environment.
2701
2702 Here is an example where ``VAR1`` is set to "New value" if it is
2703 currently empty. However, if ``VAR1`` has already been set, it
Andrew Geisslerc926e172021-05-07 16:11:35 -05002704 remains unchanged::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002705
2706 VAR1 ?= "New value"
2707
Andrew Geisslerc926e172021-05-07 16:11:35 -05002708 In this next example, ``VAR1`` is left with the value "Original value"::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002709
2710 VAR1 = "Original value"
2711 VAR1 ?= "New value"
2712
2713- *Appending (+=):* Use the plus character followed by the equals sign
2714 (``+=``) to append values to existing variables.
2715
2716 .. note::
2717
2718 This operator adds a space between the existing content of the
2719 variable and the new content.
2720
Andrew Geisslerc926e172021-05-07 16:11:35 -05002721 Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002722
2723 SRC_URI += "file://fix-makefile.patch"
2724
2725- *Prepending (=+):* Use the equals sign followed by the plus character
2726 (``=+``) to prepend values to existing variables.
2727
2728 .. note::
2729
2730 This operator adds a space between the new content and the
2731 existing content of the variable.
2732
Andrew Geisslerc926e172021-05-07 16:11:35 -05002733 Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002734
2735 VAR =+ "Starts"
2736
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002737- *Appending (:append):* Use the ``:append`` operator to append values
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002738 to existing variables. This operator does not add any additional
2739 space. Also, the operator is applied after all the ``+=``, and ``=+``
2740 operators have been applied and after all ``=`` assignments have
Andrew Geissler87f5cff2022-09-30 13:13:31 -05002741 occurred. This means that if ``:append`` is used in a recipe, it can
2742 only be overridden by another layer using the special ``:remove``
2743 operator, which in turn will prevent further layers from adding it back.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002744
2745 The following example shows the space being explicitly added to the
2746 start to ensure the appended value is not merged with the existing
Andrew Geisslerc926e172021-05-07 16:11:35 -05002747 value::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002748
Andrew Geissler87f5cff2022-09-30 13:13:31 -05002749 CFLAGS:append = " --enable-important-feature"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002750
2751 You can also use
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002752 the ``:append`` operator with overrides, which results in the actions
Andrew Geisslerc926e172021-05-07 16:11:35 -05002753 only being performed for the specified target or machine::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002754
Andrew Geissler87f5cff2022-09-30 13:13:31 -05002755 CFLAGS:append:sh4 = " --enable-important-sh4-specific-feature"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002756
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002757- *Prepending (:prepend):* Use the ``:prepend`` operator to prepend
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002758 values to existing variables. This operator does not add any
2759 additional space. Also, the operator is applied after all the ``+=``,
2760 and ``=+`` operators have been applied and after all ``=``
2761 assignments have occurred.
2762
2763 The following example shows the space being explicitly added to the
2764 end to ensure the prepended value is not merged with the existing
Andrew Geisslerc926e172021-05-07 16:11:35 -05002765 value::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002766
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002767 CFLAGS:prepend = "-I${S}/myincludes "
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002768
2769 You can also use the
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002770 ``:prepend`` operator with overrides, which results in the actions
Andrew Geisslerc926e172021-05-07 16:11:35 -05002771 only being performed for the specified target or machine::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002772
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002773 CFLAGS:prepend:sh4 = "-I${S}/myincludes "
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002774
2775- *Overrides:* You can use overrides to set a value conditionally,
2776 typically based on how the recipe is being built. For example, to set
2777 the :term:`KBRANCH` variable's
2778 value to "standard/base" for any target
2779 :term:`MACHINE`, except for
2780 qemuarm where it should be set to "standard/arm-versatile-926ejs",
Andrew Geisslerc926e172021-05-07 16:11:35 -05002781 you would do the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002782
2783 KBRANCH = "standard/base"
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002784 KBRANCH:qemuarm = "standard/arm-versatile-926ejs"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002785
2786 Overrides are also used to separate
2787 alternate values of a variable in other situations. For example, when
2788 setting variables such as
2789 :term:`FILES` and
2790 :term:`RDEPENDS` that are
2791 specific to individual packages produced by a recipe, you should
2792 always use an override that specifies the name of the package.
2793
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002794- *Indentation:* Use spaces for indentation rather than tabs. For
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002795 shell functions, both currently work. However, it is a policy
2796 decision of the Yocto Project to use tabs in shell functions. Realize
2797 that some layers have a policy to use spaces for all indentation.
2798
2799- *Using Python for Complex Operations:* For more advanced processing,
2800 it is possible to use Python code during variable assignments (e.g.
2801 search and replacement on a variable).
2802
2803 You indicate Python code using the ``${@python_code}`` syntax for the
Andrew Geisslerc926e172021-05-07 16:11:35 -05002804 variable assignment::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002805
2806 SRC_URI = "ftp://ftp.info-zip.org/pub/infozip/src/zip${@d.getVar('PV',1).replace('.', '')}.tgz
2807
2808- *Shell Function Syntax:* Write shell functions as if you were writing
2809 a shell script when you describe a list of actions to take. You
2810 should ensure that your script works with a generic ``sh`` and that
2811 it does not require any ``bash`` or other shell-specific
2812 functionality. The same considerations apply to various system
2813 utilities (e.g. ``sed``, ``grep``, ``awk``, and so forth) that you
2814 might wish to use. If in doubt, you should check with multiple
Andrew Geissler615f2f12022-07-15 14:00:58 -05002815 implementations --- including those from BusyBox.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002816
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002817Adding a New Machine
2818====================
2819
2820Adding a new machine to the Yocto Project is a straightforward process.
2821This section describes how to add machines that are similar to those
2822that the Yocto Project already supports.
2823
2824.. note::
2825
2826 Although well within the capabilities of the Yocto Project, adding a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002827 totally new architecture might require changes to ``gcc``/``glibc``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002828 and to the site information, which is beyond the scope of this
2829 manual.
2830
2831For a complete example that shows how to add a new machine, see the
2832":ref:`bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script`"
2833section in the Yocto Project Board Support Package (BSP) Developer's
2834Guide.
2835
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002836Adding the Machine Configuration File
2837-------------------------------------
2838
2839To add a new machine, you need to add a new machine configuration file
2840to the layer's ``conf/machine`` directory. This configuration file
2841provides details about the device you are adding.
2842
2843The OpenEmbedded build system uses the root name of the machine
2844configuration file to reference the new machine. For example, given a
2845machine configuration file named ``crownbay.conf``, the build system
2846recognizes the machine as "crownbay".
2847
2848The most important variables you must set in your machine configuration
2849file or include from a lower-level configuration file are as follows:
2850
Andrew Geissler5f350902021-07-23 13:09:54 -04002851- :term:`TARGET_ARCH` (e.g. "arm")
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002852
2853- ``PREFERRED_PROVIDER_virtual/kernel``
2854
Andrew Geissler09036742021-06-25 14:25:14 -05002855- :term:`MACHINE_FEATURES` (e.g. "apm screen wifi")
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002856
2857You might also need these variables:
2858
Andrew Geissler5f350902021-07-23 13:09:54 -04002859- :term:`SERIAL_CONSOLES` (e.g. "115200;ttyS0 115200;ttyS1")
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002860
Andrew Geissler5f350902021-07-23 13:09:54 -04002861- :term:`KERNEL_IMAGETYPE` (e.g. "zImage")
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002862
Andrew Geissler09036742021-06-25 14:25:14 -05002863- :term:`IMAGE_FSTYPES` (e.g. "tar.gz jffs2")
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002864
2865You can find full details on these variables in the reference section.
2866You can leverage existing machine ``.conf`` files from
2867``meta-yocto-bsp/conf/machine/``.
2868
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002869Adding a Kernel for the Machine
2870-------------------------------
2871
2872The OpenEmbedded build system needs to be able to build a kernel for the
2873machine. You need to either create a new kernel recipe for this machine,
2874or extend an existing kernel recipe. You can find several kernel recipe
2875examples in the Source Directory at ``meta/recipes-kernel/linux`` that
2876you can use as references.
2877
2878If you are creating a new kernel recipe, normal recipe-writing rules
Andrew Geissler09036742021-06-25 14:25:14 -05002879apply for setting up a :term:`SRC_URI`. Thus, you need to specify any
2880necessary patches and set :term:`S` to point at the source code. You need to
Patrick Williams2194f502022-10-16 14:26:09 -05002881create a :ref:`ref-tasks-configure` task that configures the unpacked kernel with
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002882a ``defconfig`` file. You can do this by using a ``make defconfig``
2883command or, more commonly, by copying in a suitable ``defconfig`` file
2884and then running ``make oldconfig``. By making use of ``inherit kernel``
2885and potentially some of the ``linux-*.inc`` files, most other
2886functionality is centralized and the defaults of the class normally work
2887well.
2888
2889If you are extending an existing kernel recipe, it is usually a matter
2890of adding a suitable ``defconfig`` file. The file needs to be added into
2891a location similar to ``defconfig`` files used for other machines in a
2892given kernel recipe. A possible way to do this is by listing the file in
Andrew Geissler09036742021-06-25 14:25:14 -05002893the :term:`SRC_URI` and adding the machine to the expression in
2894:term:`COMPATIBLE_MACHINE`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002895
2896 COMPATIBLE_MACHINE = '(qemux86|qemumips)'
2897
2898For more information on ``defconfig`` files, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06002899":ref:`kernel-dev/common:changing the configuration`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002900section in the Yocto Project Linux Kernel Development Manual.
2901
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002902Adding a Formfactor Configuration File
2903--------------------------------------
2904
2905A formfactor configuration file provides information about the target
2906hardware for which the image is being built and information that the
2907build system cannot obtain from other sources such as the kernel. Some
2908examples of information contained in a formfactor configuration file
2909include framebuffer orientation, whether or not the system has a
2910keyboard, the positioning of the keyboard in relation to the screen, and
2911the screen resolution.
2912
2913The build system uses reasonable defaults in most cases. However, if
2914customization is necessary, you need to create a ``machconfig`` file in
2915the ``meta/recipes-bsp/formfactor/files`` directory. This directory
2916contains directories for specific machines such as ``qemuarm`` and
2917``qemux86``. For information about the settings available and the
2918defaults, see the ``meta/recipes-bsp/formfactor/files/config`` file
2919found in the same area.
2920
Andrew Geisslerc926e172021-05-07 16:11:35 -05002921Following is an example for "qemuarm" machine::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002922
2923 HAVE_TOUCHSCREEN=1
2924 HAVE_KEYBOARD=1
2925 DISPLAY_CAN_ROTATE=0
2926 DISPLAY_ORIENTATION=0
2927 #DISPLAY_WIDTH_PIXELS=640
2928 #DISPLAY_HEIGHT_PIXELS=480
2929 #DISPLAY_BPP=16
2930 DISPLAY_DPI=150
2931 DISPLAY_SUBPIXEL_ORDER=vrgb
2932
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002933Upgrading Recipes
2934=================
2935
2936Over time, upstream developers publish new versions for software built
2937by layer recipes. It is recommended to keep recipes up-to-date with
2938upstream version releases.
2939
William A. Kennington IIIac69b482021-06-02 12:28:27 -07002940While there are several methods to upgrade a recipe, you might
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002941consider checking on the upgrade status of a recipe first. You can do so
2942using the ``devtool check-upgrade-status`` command. See the
2943":ref:`devtool-checking-on-the-upgrade-status-of-a-recipe`"
2944section in the Yocto Project Reference Manual for more information.
2945
2946The remainder of this section describes three ways you can upgrade a
2947recipe. You can use the Automated Upgrade Helper (AUH) to set up
2948automatic version upgrades. Alternatively, you can use
2949``devtool upgrade`` to set up semi-automatic version upgrades. Finally,
2950you can manually upgrade a recipe by editing the recipe itself.
2951
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002952Using the Auto Upgrade Helper (AUH)
2953-----------------------------------
2954
2955The AUH utility works in conjunction with the OpenEmbedded build system
2956in order to automatically generate upgrades for recipes based on new
2957versions being published upstream. Use AUH when you want to create a
2958service that performs the upgrades automatically and optionally sends
2959you an email with the results.
2960
2961AUH allows you to update several recipes with a single use. You can also
2962optionally perform build and integration tests using images with the
2963results saved to your hard drive and emails of results optionally sent
2964to recipe maintainers. Finally, AUH creates Git commits with appropriate
2965commit messages in the layer's tree for the changes made to recipes.
2966
2967.. note::
2968
William A. Kennington IIIac69b482021-06-02 12:28:27 -07002969 In some conditions, you should not use AUH to upgrade recipes
2970 and should instead use either ``devtool upgrade`` or upgrade your
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002971 recipes manually:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002972
2973 - When AUH cannot complete the upgrade sequence. This situation
2974 usually results because custom patches carried by the recipe
2975 cannot be automatically rebased to the new version. In this case,
2976 ``devtool upgrade`` allows you to manually resolve conflicts.
2977
2978 - When for any reason you want fuller control over the upgrade
2979 process. For example, when you want special arrangements for
2980 testing.
2981
2982The following steps describe how to set up the AUH utility:
2983
29841. *Be Sure the Development Host is Set Up:* You need to be sure that
2985 your development host is set up to use the Yocto Project. For
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002986 information on how to set up your host, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06002987 ":ref:`dev-manual/start:Preparing the Build Host`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002988
29892. *Make Sure Git is Configured:* The AUH utility requires Git to be
2990 configured because AUH uses Git to save upgrades. Thus, you must have
2991 Git user and email configured. The following command shows your
Andrew Geisslerc926e172021-05-07 16:11:35 -05002992 configurations::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002993
2994 $ git config --list
2995
2996 If you do not have the user and
Andrew Geisslerc926e172021-05-07 16:11:35 -05002997 email configured, you can use the following commands to do so::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002998
2999 $ git config --global user.name some_name
3000 $ git config --global user.email username@domain.com
3001
30023. *Clone the AUH Repository:* To use AUH, you must clone the repository
3003 onto your development host. The following command uses Git to create
Andrew Geisslerc926e172021-05-07 16:11:35 -05003004 a local copy of the repository on your system::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003005
3006 $ git clone git://git.yoctoproject.org/auto-upgrade-helper
3007 Cloning into 'auto-upgrade-helper'... remote: Counting objects: 768, done.
3008 remote: Compressing objects: 100% (300/300), done.
3009 remote: Total 768 (delta 499), reused 703 (delta 434)
3010 Receiving objects: 100% (768/768), 191.47 KiB | 98.00 KiB/s, done.
3011 Resolving deltas: 100% (499/499), done.
3012 Checking connectivity... done.
3013
3014 AUH is not part of the :term:`OpenEmbedded-Core (OE-Core)` or
3015 :term:`Poky` repositories.
3016
Patrick Williams2390b1b2022-11-03 13:47:49 -050030174. *Create a Dedicated Build Directory:* Run the :ref:`structure-core-script`
3018 script to create a fresh :term:`Build Directory` that you use exclusively
3019 for running the AUH utility::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003020
Andrew Geissler95ac1b82021-03-31 14:34:31 -05003021 $ cd poky
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003022 $ source oe-init-build-env your_AUH_build_directory
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003023
Patrick Williams2390b1b2022-11-03 13:47:49 -05003024 Re-using an existing :term:`Build Directory` and its configurations is not
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003025 recommended as existing settings could cause AUH to fail or behave
3026 undesirably.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003027
30285. *Make Configurations in Your Local Configuration File:* Several
William A. Kennington IIIac69b482021-06-02 12:28:27 -07003029 settings are needed in the ``local.conf`` file in the build
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003030 directory you just created for AUH. Make these following
3031 configurations:
3032
3033 - If you want to enable :ref:`Build
Andrew Geissler09209ee2020-12-13 08:44:15 -06003034 History <dev-manual/common-tasks:maintaining build output quality>`,
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003035 which is optional, you need the following lines in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05003036 ``conf/local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003037
3038 INHERIT =+ "buildhistory"
3039 BUILDHISTORY_COMMIT = "1"
3040
3041 With this configuration and a successful
3042 upgrade, a build history "diff" file appears in the
3043 ``upgrade-helper/work/recipe/buildhistory-diff.txt`` file found in
Patrick Williams2390b1b2022-11-03 13:47:49 -05003044 your :term:`Build Directory`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003045
3046 - If you want to enable testing through the
Patrick Williams975a06f2022-10-21 14:42:47 -05003047 :ref:`testimage <ref-classes-testimage>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003048 class, which is optional, you need to have the following set in
Andrew Geisslerc926e172021-05-07 16:11:35 -05003049 your ``conf/local.conf`` file::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003050
3051 INHERIT += "testimage"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003052
3053 .. note::
3054
3055 If your distro does not enable by default ptest, which Poky
Andrew Geisslerc926e172021-05-07 16:11:35 -05003056 does, you need the following in your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003057
Patrick Williams0ca19cc2021-08-16 14:03:13 -05003058 DISTRO_FEATURES:append = " ptest"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003059
3060
30616. *Optionally Start a vncserver:* If you are running in a server
Andrew Geisslerc926e172021-05-07 16:11:35 -05003062 without an X11 session, you need to start a vncserver::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003063
3064 $ vncserver :1
3065 $ export DISPLAY=:1
3066
30677. *Create and Edit an AUH Configuration File:* You need to have the
3068 ``upgrade-helper/upgrade-helper.conf`` configuration file in your
Patrick Williams2390b1b2022-11-03 13:47:49 -05003069 :term:`Build Directory`. You can find a sample configuration file in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003070 :yocto_git:`AUH source repository </auto-upgrade-helper/tree/>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003071
3072 Read through the sample file and make configurations as needed. For
3073 example, if you enabled build history in your ``local.conf`` as
3074 described earlier, you must enable it in ``upgrade-helper.conf``.
3075
3076 Also, if you are using the default ``maintainers.inc`` file supplied
3077 with Poky and located in ``meta-yocto`` and you do not set a
3078 "maintainers_whitelist" or "global_maintainer_override" in the
3079 ``upgrade-helper.conf`` configuration, and you specify "-e all" on
3080 the AUH command-line, the utility automatically sends out emails to
3081 all the default maintainers. Please avoid this.
3082
3083This next set of examples describes how to use the AUH:
3084
3085- *Upgrading a Specific Recipe:* To upgrade a specific recipe, use the
Andrew Geisslerc926e172021-05-07 16:11:35 -05003086 following form::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003087
3088 $ upgrade-helper.py recipe_name
3089
Andrew Geisslerc926e172021-05-07 16:11:35 -05003090 For example, this command upgrades the ``xmodmap`` recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003091
3092 $ upgrade-helper.py xmodmap
3093
3094- *Upgrading a Specific Recipe to a Particular Version:* To upgrade a
Andrew Geisslerc926e172021-05-07 16:11:35 -05003095 specific recipe to a particular version, use the following form::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003096
3097 $ upgrade-helper.py recipe_name -t version
3098
Andrew Geisslerc926e172021-05-07 16:11:35 -05003099 For example, this command upgrades the ``xmodmap`` recipe to version 1.2.3::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003100
3101 $ upgrade-helper.py xmodmap -t 1.2.3
3102
3103- *Upgrading all Recipes to the Latest Versions and Suppressing Email
3104 Notifications:* To upgrade all recipes to their most recent versions
Andrew Geisslerc926e172021-05-07 16:11:35 -05003105 and suppress the email notifications, use the following command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003106
3107 $ upgrade-helper.py all
3108
3109- *Upgrading all Recipes to the Latest Versions and Send Email
3110 Notifications:* To upgrade all recipes to their most recent versions
3111 and send email messages to maintainers for each attempted recipe as
Andrew Geisslerc926e172021-05-07 16:11:35 -05003112 well as a status email, use the following command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003113
3114 $ upgrade-helper.py -e all
3115
3116Once you have run the AUH utility, you can find the results in the AUH
Patrick Williams2390b1b2022-11-03 13:47:49 -05003117:term:`Build Directory`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003118
3119 ${BUILDDIR}/upgrade-helper/timestamp
3120
3121The AUH utility
3122also creates recipe update commits from successful upgrade attempts in
3123the layer tree.
3124
3125You can easily set up to run the AUH utility on a regular basis by using
3126a cron job. See the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003127:yocto_git:`weeklyjob.sh </auto-upgrade-helper/tree/weeklyjob.sh>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003128file distributed with the utility for an example.
3129
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003130Using ``devtool upgrade``
3131-------------------------
3132
3133As mentioned earlier, an alternative method for upgrading recipes to
3134newer versions is to use
Andrew Geissler09209ee2020-12-13 08:44:15 -06003135:doc:`devtool upgrade </ref-manual/devtool-reference>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003136You can read about ``devtool upgrade`` in general in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003137":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 -05003138section in the Yocto Project Application Development and the Extensible
3139Software Development Kit (eSDK) Manual.
3140
3141To see all the command-line options available with ``devtool upgrade``,
Andrew Geisslerc926e172021-05-07 16:11:35 -05003142use the following help command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003143
3144 $ devtool upgrade -h
3145
3146If you want to find out what version a recipe is currently at upstream
3147without any attempt to upgrade your local version of the recipe, you can
Andrew Geisslerc926e172021-05-07 16:11:35 -05003148use the following command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003149
3150 $ devtool latest-version recipe_name
3151
3152As mentioned in the previous section describing AUH, ``devtool upgrade``
3153works in a less-automated manner than AUH. Specifically,
3154``devtool upgrade`` only works on a single recipe that you name on the
3155command line, cannot perform build and integration testing using images,
3156and does not automatically generate commits for changes in the source
3157tree. Despite all these "limitations", ``devtool upgrade`` updates the
3158recipe file to the new upstream version and attempts to rebase custom
3159patches contained by the recipe as needed.
3160
3161.. note::
3162
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003163 AUH uses much of ``devtool upgrade`` behind the scenes making AUH somewhat
3164 of a "wrapper" application for ``devtool upgrade``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003165
3166A typical scenario involves having used Git to clone an upstream
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003167repository that you use during build operations. Because you have built the
3168recipe in the past, the layer is likely added to your
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003169configuration already. If for some reason, the layer is not added, you
3170could add it easily using the
3171":ref:`bitbake-layers <bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script>`"
3172script. For example, suppose you use the ``nano.bb`` recipe from the
3173``meta-oe`` layer in the ``meta-openembedded`` repository. For this
Andrew Geisslerc926e172021-05-07 16:11:35 -05003174example, assume that the layer has been cloned into following area::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003175
3176 /home/scottrif/meta-openembedded
3177
Patrick Williams2390b1b2022-11-03 13:47:49 -05003178The following command from your :term:`Build Directory` adds the layer to
Andrew Geisslerc926e172021-05-07 16:11:35 -05003179your build configuration (i.e. ``${BUILDDIR}/conf/bblayers.conf``)::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003180
3181 $ bitbake-layers add-layer /home/scottrif/meta-openembedded/meta-oe
3182 NOTE: Starting bitbake server...
3183 Parsing recipes: 100% |##########################################| Time: 0:00:55
3184 Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
3185 Removing 12 recipes from the x86_64 sysroot: 100% |##############| Time: 0:00:00
3186 Removing 1 recipes from the x86_64_i586 sysroot: 100% |##########| Time: 0:00:00
3187 Removing 5 recipes from the i586 sysroot: 100% |#################| Time: 0:00:00
3188 Removing 5 recipes from the qemux86 sysroot: 100% |##############| Time: 0:00:00
3189
3190For this example, assume that the ``nano.bb`` recipe that
3191is upstream has a 2.9.3 version number. However, the version in the
3192local repository is 2.7.4. The following command from your build
3193directory automatically upgrades the recipe for you:
3194
3195.. note::
3196
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003197 Using the ``-V`` option is not necessary. Omitting the version number causes
3198 ``devtool upgrade`` to upgrade the recipe to the most recent version.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003199
3200::
3201
3202 $ devtool upgrade nano -V 2.9.3
3203 NOTE: Starting bitbake server...
3204 NOTE: Creating workspace layer in /home/scottrif/poky/build/workspace
3205 Parsing recipes: 100% |##########################################| Time: 0:00:46
3206 Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
3207 NOTE: Extracting current version source...
3208 NOTE: Resolving any missing task queue dependencies
3209 .
3210 .
3211 .
3212 NOTE: Executing SetScene Tasks
3213 NOTE: Executing RunQueue Tasks
3214 NOTE: Tasks Summary: Attempted 74 tasks of which 72 didn't need to be rerun and all succeeded.
3215 Adding changed files: 100% |#####################################| Time: 0:00:00
3216 NOTE: Upgraded source extracted to /home/scottrif/poky/build/workspace/sources/nano
3217 NOTE: New recipe is /home/scottrif/poky/build/workspace/recipes/nano/nano_2.9.3.bb
3218
3219Continuing with this example, you can use ``devtool build`` to build the
Andrew Geisslerc926e172021-05-07 16:11:35 -05003220newly upgraded recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003221
3222 $ devtool build nano
3223 NOTE: Starting bitbake server...
3224 Loading cache: 100% |################################################################################################| Time: 0:00:01
3225 Loaded 2040 entries from dependency cache.
3226 Parsing recipes: 100% |##############################################################################################| Time: 0:00:00
3227 Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
3228 NOTE: Resolving any missing task queue dependencies
3229 .
3230 .
3231 .
3232 NOTE: Executing SetScene Tasks
3233 NOTE: Executing RunQueue Tasks
3234 NOTE: nano: compiling from external source tree /home/scottrif/poky/build/workspace/sources/nano
3235 NOTE: Tasks Summary: Attempted 520 tasks of which 304 didn't need to be rerun and all succeeded.
3236
William A. Kennington IIIac69b482021-06-02 12:28:27 -07003237Within the ``devtool upgrade`` workflow, you can
3238deploy and test your rebuilt software. For this example,
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003239however, running ``devtool finish`` cleans up the workspace once the
3240source in your workspace is clean. This usually means using Git to stage
3241and submit commits for the changes generated by the upgrade process.
3242
3243Once the tree is clean, you can clean things up in this example with the
3244following command from the ``${BUILDDIR}/workspace/sources/nano``
Andrew Geisslerc926e172021-05-07 16:11:35 -05003245directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003246
3247 $ devtool finish nano meta-oe
3248 NOTE: Starting bitbake server...
3249 Loading cache: 100% |################################################################################################| Time: 0:00:00
3250 Loaded 2040 entries from dependency cache.
3251 Parsing recipes: 100% |##############################################################################################| Time: 0:00:01
3252 Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
3253 NOTE: Adding new patch 0001-nano.bb-Stuff-I-changed-when-upgrading-nano.bb.patch
3254 NOTE: Updating recipe nano_2.9.3.bb
3255 NOTE: Removing file /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano/nano_2.7.4.bb
3256 NOTE: Moving recipe file to /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano
3257 NOTE: Leaving source tree /home/scottrif/poky/build/workspace/sources/nano as-is; if you no longer need it then please delete it manually
3258
3259
3260Using the ``devtool finish`` command cleans up the workspace and creates a patch
3261file based on your commits. The tool puts all patch files back into the
3262source directory in a sub-directory named ``nano`` in this case.
3263
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003264Manually Upgrading a Recipe
3265---------------------------
3266
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003267If for some reason you choose not to upgrade recipes using
Andrew Geissler09209ee2020-12-13 08:44:15 -06003268:ref:`dev-manual/common-tasks:Using the Auto Upgrade Helper (AUH)` or
3269by :ref:`dev-manual/common-tasks:Using \`\`devtool upgrade\`\``,
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003270you can manually edit the recipe files to upgrade the versions.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003271
3272.. note::
3273
3274 Manually updating multiple recipes scales poorly and involves many
3275 steps. The recommendation to upgrade recipe versions is through AUH
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003276 or ``devtool upgrade``, both of which automate some steps and provide
3277 guidance for others needed for the manual process.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003278
3279To manually upgrade recipe versions, follow these general steps:
3280
32811. *Change the Version:* Rename the recipe such that the version (i.e.
3282 the :term:`PV` part of the recipe name)
3283 changes appropriately. If the version is not part of the recipe name,
Andrew Geissler09036742021-06-25 14:25:14 -05003284 change the value as it is set for :term:`PV` within the recipe itself.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003285
Andrew Geissler09036742021-06-25 14:25:14 -050032862. *Update* :term:`SRCREV` *if Needed*: If the source code your recipe builds
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003287 is fetched from Git or some other version control system, update
3288 :term:`SRCREV` to point to the
3289 commit hash that matches the new version.
3290
32913. *Build the Software:* Try to build the recipe using BitBake. Typical
3292 build failures include the following:
3293
3294 - License statements were updated for the new version. For this
3295 case, you need to review any changes to the license and update the
3296 values of :term:`LICENSE` and
3297 :term:`LIC_FILES_CHKSUM`
3298 as needed.
3299
3300 .. note::
3301
3302 License changes are often inconsequential. For example, the
3303 license text's copyright year might have changed.
3304
3305 - Custom patches carried by the older version of the recipe might
3306 fail to apply to the new version. For these cases, you need to
3307 review the failures. Patches might not be necessary for the new
3308 version of the software if the upgraded version has fixed those
3309 issues. If a patch is necessary and failing, you need to rebase it
3310 into the new version.
3311
33124. *Optionally Attempt to Build for Several Architectures:* Once you
3313 successfully build the new software for a given architecture, you
3314 could test the build for other architectures by changing the
3315 :term:`MACHINE` variable and
3316 rebuilding the software. This optional step is especially important
3317 if the recipe is to be released publicly.
3318
33195. *Check the Upstream Change Log or Release Notes:* Checking both these
William A. Kennington IIIac69b482021-06-02 12:28:27 -07003320 reveals if there are new features that could break
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003321 backwards-compatibility. If so, you need to take steps to mitigate or
3322 eliminate that situation.
3323
33246. *Optionally Create a Bootable Image and Test:* If you want, you can
3325 test the new software by booting it onto actual hardware.
3326
33277. *Create a Commit with the Change in the Layer Repository:* After all
3328 builds work and any testing is successful, you can create commits for
3329 any changes in the layer holding your upgraded recipe.
3330
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003331Finding Temporary Source Code
3332=============================
3333
3334You might find it helpful during development to modify the temporary
3335source code used by recipes to build packages. For example, suppose you
3336are developing a patch and you need to experiment a bit to figure out
3337your solution. After you have initially built the package, you can
3338iteratively tweak the source code, which is located in the
Patrick Williams2390b1b2022-11-03 13:47:49 -05003339:term:`Build Directory`, and then you can force a re-compile and quickly
3340test your altered code. Once you settle on a solution, you can then preserve
3341your changes in the form of patches.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003342
3343During a build, the unpacked temporary source code used by recipes to
Patrick Williams2390b1b2022-11-03 13:47:49 -05003344build packages is available in the :term:`Build Directory` as defined by the
3345:term:`S` variable. Below is the default value for the :term:`S` variable as
3346defined in the ``meta/conf/bitbake.conf`` configuration file in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05003347:term:`Source Directory`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003348
3349 S = "${WORKDIR}/${BP}"
3350
3351You should be aware that many recipes override the
Andrew Geissler09036742021-06-25 14:25:14 -05003352:term:`S` variable. For example, recipes that fetch their source from Git
3353usually set :term:`S` to ``${WORKDIR}/git``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003354
3355.. note::
3356
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003357 The :term:`BP` represents the base recipe name, which consists of the name
Andrew Geisslerc926e172021-05-07 16:11:35 -05003358 and version::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003359
3360 BP = "${BPN}-${PV}"
3361
3362
3363The path to the work directory for the recipe
3364(:term:`WORKDIR`) is defined as
Andrew Geisslerc926e172021-05-07 16:11:35 -05003365follows::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003366
3367 ${TMPDIR}/work/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR}
3368
3369The actual directory depends on several things:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003370
3371- :term:`TMPDIR`: The top-level build
3372 output directory.
3373
3374- :term:`MULTIMACH_TARGET_SYS`:
3375 The target system identifier.
3376
3377- :term:`PN`: The recipe name.
3378
Andrew Geissler615f2f12022-07-15 14:00:58 -05003379- :term:`EXTENDPE`: The epoch --- if
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003380 :term:`PE` is not specified, which is
Andrew Geissler615f2f12022-07-15 14:00:58 -05003381 usually the case for most recipes, then :term:`EXTENDPE` is blank.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003382
3383- :term:`PV`: The recipe version.
3384
3385- :term:`PR`: The recipe revision.
3386
3387As an example, assume a Source Directory top-level folder named
Patrick Williams2390b1b2022-11-03 13:47:49 -05003388``poky``, a default :term:`Build Directory` at ``poky/build``, and a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003389``qemux86-poky-linux`` machine target system. Furthermore, suppose your
3390recipe is named ``foo_1.3.0.bb``. In this case, the work directory the
Andrew Geisslerc926e172021-05-07 16:11:35 -05003391build system uses to build the package would be as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003392
3393 poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
3394
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003395Using Quilt in Your Workflow
3396============================
3397
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003398`Quilt <https://savannah.nongnu.org/projects/quilt>`__ is a powerful tool
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003399that allows you to capture source code changes without having a clean
3400source tree. This section outlines the typical workflow you can use to
3401modify source code, test changes, and then preserve the changes in the
3402form of a patch all using Quilt.
3403
3404.. note::
3405
3406 With regard to preserving changes to source files, if you clean a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003407 recipe or have ``rm_work`` enabled, the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003408 :ref:`devtool workflow <sdk-manual/extensible:using \`\`devtool\`\` in your sdk workflow>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003409 as described in the Yocto Project Application Development and the
3410 Extensible Software Development Kit (eSDK) manual is a safer
3411 development flow than the flow that uses Quilt.
3412
3413Follow these general steps:
3414
34151. *Find the Source Code:* Temporary source code used by the
Patrick Williams2390b1b2022-11-03 13:47:49 -05003416 OpenEmbedded build system is kept in the :term:`Build Directory`. See the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05003417 ":ref:`dev-manual/common-tasks:finding temporary source code`" section to
3418 learn how to locate the directory that has the temporary source code for a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003419 particular package.
3420
34212. *Change Your Working Directory:* You need to be in the directory that
3422 has the temporary source code. That directory is defined by the
3423 :term:`S` variable.
3424
34253. *Create a New Patch:* Before modifying source code, you need to
3426 create a new patch. To create a new patch file, use ``quilt new`` as
Andrew Geisslerc926e172021-05-07 16:11:35 -05003427 below::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003428
3429 $ quilt new my_changes.patch
3430
34314. *Notify Quilt and Add Files:* After creating the patch, you need to
3432 notify Quilt about the files you plan to edit. You notify Quilt by
Andrew Geisslerc926e172021-05-07 16:11:35 -05003433 adding the files to the patch you just created::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003434
3435 $ quilt add file1.c file2.c file3.c
3436
34375. *Edit the Files:* Make your changes in the source code to the files
3438 you added to the patch.
3439
34406. *Test Your Changes:* Once you have modified the source code, the
Patrick Williams2194f502022-10-16 14:26:09 -05003441 easiest way to test your changes is by calling the :ref:`ref-tasks-compile`
Andrew Geisslerc926e172021-05-07 16:11:35 -05003442 task as shown in the following example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003443
3444 $ bitbake -c compile -f package
3445
3446 The ``-f`` or ``--force`` option forces the specified task to
3447 execute. If you find problems with your code, you can just keep
3448 editing and re-testing iteratively until things work as expected.
3449
3450 .. note::
3451
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003452 All the modifications you make to the temporary source code disappear
Patrick Williams2194f502022-10-16 14:26:09 -05003453 once you run the :ref:`ref-tasks-clean` or :ref:`ref-tasks-cleanall` tasks using BitBake
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003454 (i.e. ``bitbake -c clean package`` and ``bitbake -c cleanall package``).
3455 Modifications will also disappear if you use the ``rm_work`` feature as
3456 described in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003457 ":ref:`dev-manual/common-tasks:conserving disk space during builds`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003458 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003459
34607. *Generate the Patch:* Once your changes work as expected, you need to
3461 use Quilt to generate the final patch that contains all your
3462 modifications.
3463 ::
3464
3465 $ quilt refresh
3466
3467 At this point, the
3468 ``my_changes.patch`` file has all your edits made to the ``file1.c``,
3469 ``file2.c``, and ``file3.c`` files.
3470
3471 You can find the resulting patch file in the ``patches/``
Andrew Geissler09036742021-06-25 14:25:14 -05003472 subdirectory of the source (:term:`S`) directory.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003473
34748. *Copy the Patch File:* For simplicity, copy the patch file into a
3475 directory named ``files``, which you can create in the same directory
3476 that holds the recipe (``.bb``) file or the append (``.bbappend``)
3477 file. Placing the patch here guarantees that the OpenEmbedded build
Andrew Geissler09036742021-06-25 14:25:14 -05003478 system will find the patch. Next, add the patch into the :term:`SRC_URI`
Andrew Geisslerc926e172021-05-07 16:11:35 -05003479 of the recipe. Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003480
3481 SRC_URI += "file://my_changes.patch"
3482
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003483Using a Development Shell
3484=========================
3485
3486When debugging certain commands or even when just editing packages,
3487``devshell`` can be a useful tool. When you invoke ``devshell``, all
3488tasks up to and including
3489:ref:`ref-tasks-patch` are run for the
3490specified target. Then, a new terminal is opened and you are placed in
3491``${``\ :term:`S`\ ``}``, the source
3492directory. In the new terminal, all the OpenEmbedded build-related
3493environment variables are still defined so you can use commands such as
3494``configure`` and ``make``. The commands execute just as if the
3495OpenEmbedded build system were executing them. Consequently, working
3496this way can be helpful when debugging a build or preparing software to
3497be used with the OpenEmbedded build system.
3498
3499Following is an example that uses ``devshell`` on a target named
Andrew Geisslerc926e172021-05-07 16:11:35 -05003500``matchbox-desktop``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003501
3502 $ bitbake matchbox-desktop -c devshell
3503
3504This command spawns a terminal with a shell prompt within the
3505OpenEmbedded build environment. The
3506:term:`OE_TERMINAL` variable
3507controls what type of shell is opened.
3508
3509For spawned terminals, the following occurs:
3510
3511- The ``PATH`` variable includes the cross-toolchain.
3512
3513- The ``pkgconfig`` variables find the correct ``.pc`` files.
3514
3515- The ``configure`` command finds the Yocto Project site files as well
3516 as any other necessary files.
3517
3518Within this environment, you can run configure or compile commands as if
3519they were being run by the OpenEmbedded build system itself. As noted
3520earlier, the working directory also automatically changes to the Source
3521Directory (:term:`S`).
3522
3523To manually run a specific task using ``devshell``, run the
3524corresponding ``run.*`` script in the
3525``${``\ :term:`WORKDIR`\ ``}/temp``
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003526directory (e.g., ``run.do_configure.``\ `pid`). If a task's script does
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003527not exist, which would be the case if the task was skipped by way of the
3528sstate cache, you can create the task by first running it outside of the
Andrew Geisslerc926e172021-05-07 16:11:35 -05003529``devshell``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003530
3531 $ bitbake -c task
3532
3533.. note::
3534
3535 - Execution of a task's ``run.*`` script and BitBake's execution of
3536 a task are identical. In other words, running the script re-runs
3537 the task just as it would be run using the ``bitbake -c`` command.
3538
3539 - Any ``run.*`` file that does not have a ``.pid`` extension is a
3540 symbolic link (symlink) to the most recent version of that file.
3541
3542Remember, that the ``devshell`` is a mechanism that allows you to get
3543into the BitBake task execution environment. And as such, all commands
3544must be called just as BitBake would call them. That means you need to
3545provide the appropriate options for cross-compilation and so forth as
3546applicable.
3547
3548When you are finished using ``devshell``, exit the shell or close the
3549terminal window.
3550
3551.. note::
3552
3553 - It is worth remembering that when using ``devshell`` you need to
3554 use the full compiler name such as ``arm-poky-linux-gnueabi-gcc``
3555 instead of just using ``gcc``. The same applies to other
3556 applications such as ``binutils``, ``libtool`` and so forth.
Andrew Geissler09036742021-06-25 14:25:14 -05003557 BitBake sets up environment variables such as :term:`CC` to assist
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003558 applications, such as ``make`` to find the correct tools.
3559
3560 - It is also worth noting that ``devshell`` still works over X11
3561 forwarding and similar situations.
3562
Andrew Geisslereff27472021-10-29 15:35:00 -05003563Using a Python Development Shell
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003564================================
3565
3566Similar to working within a development shell as described in the
3567previous section, you can also spawn and work within an interactive
3568Python development shell. When debugging certain commands or even when
Andrew Geisslereff27472021-10-29 15:35:00 -05003569just editing packages, ``pydevshell`` can be a useful tool. When you
3570invoke the ``pydevshell`` task, all tasks up to and including
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003571:ref:`ref-tasks-patch` are run for the
3572specified target. Then a new terminal is opened. Additionally, key
3573Python objects and code are available in the same way they are to
3574BitBake tasks, in particular, the data store 'd'. So, commands such as
3575the following are useful when exploring the data store and running
Andrew Geisslerc926e172021-05-07 16:11:35 -05003576functions::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003577
3578 pydevshell> d.getVar("STAGING_DIR")
3579 '/media/build1/poky/build/tmp/sysroots'
Andrew Geissler5199d832021-09-24 16:47:35 -05003580 pydevshell> d.getVar("STAGING_DIR", False)
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003581 '${TMPDIR}/sysroots'
3582 pydevshell> d.setVar("FOO", "bar")
3583 pydevshell> d.getVar("FOO")
3584 'bar'
3585 pydevshell> d.delVar("FOO")
3586 pydevshell> d.getVar("FOO")
3587 pydevshell> bb.build.exec_func("do_unpack", d)
3588 pydevshell>
3589
Andrew Geissler87f5cff2022-09-30 13:13:31 -05003590See the ":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:functions you can call from within python`"
3591section in the BitBake User Manual for details about available functions.
3592
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003593The commands execute just as if the OpenEmbedded build
3594system were executing them. Consequently, working this way can be
3595helpful when debugging a build or preparing software to be used with the
3596OpenEmbedded build system.
3597
Andrew Geisslereff27472021-10-29 15:35:00 -05003598Following is an example that uses ``pydevshell`` on a target named
Andrew Geisslerc926e172021-05-07 16:11:35 -05003599``matchbox-desktop``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003600
Andrew Geisslereff27472021-10-29 15:35:00 -05003601 $ bitbake matchbox-desktop -c pydevshell
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003602
3603This command spawns a terminal and places you in an interactive Python
3604interpreter within the OpenEmbedded build environment. The
3605:term:`OE_TERMINAL` variable
3606controls what type of shell is opened.
3607
Andrew Geisslereff27472021-10-29 15:35:00 -05003608When you are finished using ``pydevshell``, you can exit the shell
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003609either by using Ctrl+d or closing the terminal window.
3610
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003611Building
3612========
3613
Andrew Geissler5199d832021-09-24 16:47:35 -05003614This section describes various build procedures, such as the steps
3615needed for a simple build, building a target for multiple configurations,
3616generating an image for more than one machine, and so forth.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003617
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003618Building a Simple Image
3619-----------------------
3620
3621In the development environment, you need to build an image whenever you
3622change hardware support, add or change system libraries, or add or
William A. Kennington IIIac69b482021-06-02 12:28:27 -07003623change services that have dependencies. There are several methods that allow
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003624you to build an image within the Yocto Project. This section presents
3625the basic steps you need to build a simple image using BitBake from a
3626build host running Linux.
3627
3628.. note::
3629
3630 - For information on how to build an image using
3631 :term:`Toaster`, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003632 :doc:`/toaster-manual/index`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003633
3634 - For information on how to use ``devtool`` to build images, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003635 ":ref:`sdk-manual/extensible:using \`\`devtool\`\` in your sdk workflow`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003636 section in the Yocto Project Application Development and the
3637 Extensible Software Development Kit (eSDK) manual.
3638
3639 - For a quick example on how to build an image using the
3640 OpenEmbedded build system, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003641 :doc:`/brief-yoctoprojectqs/index` document.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003642
3643The build process creates an entire Linux distribution from source and
Patrick Williams2390b1b2022-11-03 13:47:49 -05003644places it in your :term:`Build Directory` under ``tmp/deploy/images``. For
3645detailed information on the build process using BitBake, see the
3646":ref:`overview-manual/concepts:images`" section in the Yocto Project Overview
3647and Concepts Manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003648
3649The following figure and list overviews the build process:
3650
3651.. image:: figures/bitbake-build-flow.png
Andrew Geisslerd5838332022-05-27 11:33:10 -05003652 :width: 100%
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003653
36541. *Set up Your Host Development System to Support Development Using the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003655 Yocto Project*: See the ":doc:`start`" section for options on how to get a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003656 build host ready to use the Yocto Project.
3657
36582. *Initialize the Build Environment:* Initialize the build environment
3659 by sourcing the build environment script (i.e.
Andrew Geisslerc926e172021-05-07 16:11:35 -05003660 :ref:`structure-core-script`)::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003661
3662 $ source oe-init-build-env [build_dir]
3663
3664 When you use the initialization script, the OpenEmbedded build system
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003665 uses ``build`` as the default :term:`Build Directory` in your current work
3666 directory. You can use a `build_dir` argument with the script to
Patrick Williams2390b1b2022-11-03 13:47:49 -05003667 specify a different :term:`Build Directory`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003668
3669 .. note::
3670
Patrick Williams2390b1b2022-11-03 13:47:49 -05003671 A common practice is to use a different :term:`Build Directory` for
Andrew Geissler5199d832021-09-24 16:47:35 -05003672 different targets; for example, ``~/build/x86`` for a ``qemux86``
3673 target, and ``~/build/arm`` for a ``qemuarm`` target. In any
Patrick Williams2390b1b2022-11-03 13:47:49 -05003674 event, it's typically cleaner to locate the :term:`Build Directory`
Andrew Geissler5199d832021-09-24 16:47:35 -05003675 somewhere outside of your source directory.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003676
Andrew Geissler4c19ea12020-10-27 13:52:24 -050036773. *Make Sure Your* ``local.conf`` *File is Correct*: Ensure the
Patrick Williams2390b1b2022-11-03 13:47:49 -05003678 ``conf/local.conf`` configuration file, which is found in the
3679 :term:`Build Directory`, is set up how you want it. This file defines many
3680 aspects of the build environment including the target machine architecture
Andrew Geissler09036742021-06-25 14:25:14 -05003681 through the :term:`MACHINE` variable, the packaging format used during
Patrick Williams2390b1b2022-11-03 13:47:49 -05003682 the build (:term:`PACKAGE_CLASSES`), and a centralized tarball download
3683 directory through the :term:`DL_DIR` variable.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003684
Andrew Geisslerc926e172021-05-07 16:11:35 -050036854. *Build the Image:* Build the image using the ``bitbake`` command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003686
3687 $ bitbake target
3688
3689 .. note::
3690
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003691 For information on BitBake, see the :doc:`bitbake:index`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003692
3693 The target is the name of the recipe you want to build. Common
3694 targets are the images in ``meta/recipes-core/images``,
3695 ``meta/recipes-sato/images``, and so forth all found in the
Andrew Geissler5199d832021-09-24 16:47:35 -05003696 :term:`Source Directory`. Alternatively, the target
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003697 can be the name of a recipe for a specific piece of software such as
3698 BusyBox. For more details about the images the OpenEmbedded build
3699 system supports, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003700 ":ref:`ref-manual/images:Images`" chapter in the Yocto
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003701 Project Reference Manual.
3702
3703 As an example, the following command builds the
Andrew Geisslerc926e172021-05-07 16:11:35 -05003704 ``core-image-minimal`` image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003705
3706 $ bitbake core-image-minimal
3707
3708 Once an
3709 image has been built, it often needs to be installed. The images and
3710 kernels built by the OpenEmbedded build system are placed in the
Patrick Williams2390b1b2022-11-03 13:47:49 -05003711 :term:`Build Directory` in ``tmp/deploy/images``. For information on how to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003712 run pre-built images such as ``qemux86`` and ``qemuarm``, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003713 :doc:`/sdk-manual/index` manual. For
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003714 information about how to install these images, see the documentation
3715 for your particular board or machine.
3716
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003717Building Images for Multiple Targets Using Multiple Configurations
3718------------------------------------------------------------------
3719
3720You can use a single ``bitbake`` command to build multiple images or
3721packages for different targets where each image or package requires a
3722different configuration (multiple configuration builds). The builds, in
3723this scenario, are sometimes referred to as "multiconfigs", and this
3724section uses that term throughout.
3725
3726This section describes how to set up for multiple configuration builds
3727and how to account for cross-build dependencies between the
3728multiconfigs.
3729
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003730Setting Up and Running a Multiple Configuration Build
3731~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3732
3733To accomplish a multiple configuration build, you must define each
3734target's configuration separately using a parallel configuration file in
Andrew Geissler615f2f12022-07-15 14:00:58 -05003735the :term:`Build Directory` or configuration directory within a layer, and you
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003736must follow a required file hierarchy. Additionally, you must enable the
3737multiple configuration builds in your ``local.conf`` file.
3738
3739Follow these steps to set up and execute multiple configuration builds:
3740
3741- *Create Separate Configuration Files*: You need to create a single
3742 configuration file for each build target (each multiconfig).
Andrew Geissler615f2f12022-07-15 14:00:58 -05003743 The configuration definitions are implementation dependent but often
3744 each configuration file will define the machine and the
3745 temporary directory BitBake uses for the build. Whether the same
3746 temporary directory (:term:`TMPDIR`) can be shared will depend on what is
3747 similar and what is different between the configurations. Multiple MACHINE
3748 targets can share the same (:term:`TMPDIR`) as long as the rest of the
3749 configuration is the same, multiple DISTRO settings would need separate
3750 (:term:`TMPDIR`) directories.
3751
3752 For example, consider a scenario with two different multiconfigs for the same
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003753 :term:`MACHINE`: "qemux86" built
3754 for two distributions such as "poky" and "poky-lsb". In this case,
Andrew Geissler615f2f12022-07-15 14:00:58 -05003755 you would need to use the different :term:`TMPDIR`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003756
3757 Here is an example showing the minimal statements needed in a
3758 configuration file for a "qemux86" target whose temporary build
Andrew Geisslerc926e172021-05-07 16:11:35 -05003759 directory is ``tmpmultix86``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003760
3761 MACHINE = "qemux86"
3762 TMPDIR = "${TOPDIR}/tmpmultix86"
3763
3764 The location for these multiconfig configuration files is specific.
Patrick Williams2390b1b2022-11-03 13:47:49 -05003765 They must reside in the current :term:`Build Directory` in a sub-directory of
Andrew Geissler615f2f12022-07-15 14:00:58 -05003766 ``conf`` named ``multiconfig`` or within a layer's ``conf`` directory
3767 under a directory named ``multiconfig``. Following is an example that defines
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003768 two configuration files for the "x86" and "arm" multiconfigs:
3769
3770 .. image:: figures/multiconfig_files.png
3771 :align: center
Andrew Geisslerd5838332022-05-27 11:33:10 -05003772 :width: 50%
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003773
Andrew Geissler615f2f12022-07-15 14:00:58 -05003774 The usual :term:`BBPATH` search path is used to locate multiconfig files in
3775 a similar way to other conf files.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003776
3777- *Add the BitBake Multi-configuration Variable to the Local
3778 Configuration File*: Use the
3779 :term:`BBMULTICONFIG`
3780 variable in your ``conf/local.conf`` configuration file to specify
3781 each multiconfig. Continuing with the example from the previous
Andrew Geissler09036742021-06-25 14:25:14 -05003782 figure, the :term:`BBMULTICONFIG` variable needs to enable two
Andrew Geisslerc926e172021-05-07 16:11:35 -05003783 multiconfigs: "x86" and "arm" by specifying each configuration file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003784
3785 BBMULTICONFIG = "x86 arm"
3786
3787 .. note::
3788
3789 A "default" configuration already exists by definition. This
3790 configuration is named: "" (i.e. empty string) and is defined by
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003791 the variables coming from your ``local.conf``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003792 file. Consequently, the previous example actually adds two
3793 additional configurations to your build: "arm" and "x86" along
3794 with "".
3795
3796- *Launch BitBake*: Use the following BitBake command form to launch
Andrew Geisslerc926e172021-05-07 16:11:35 -05003797 the multiple configuration build::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003798
3799 $ bitbake [mc:multiconfigname:]target [[[mc:multiconfigname:]target] ... ]
3800
Andrew Geisslerc926e172021-05-07 16:11:35 -05003801 For the example in this section, the following command applies::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003802
3803 $ bitbake mc:x86:core-image-minimal mc:arm:core-image-sato mc::core-image-base
3804
3805 The previous BitBake command builds a ``core-image-minimal`` image
3806 that is configured through the ``x86.conf`` configuration file, a
3807 ``core-image-sato`` image that is configured through the ``arm.conf``
3808 configuration file and a ``core-image-base`` that is configured
3809 through your ``local.conf`` configuration file.
3810
3811.. note::
3812
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003813 Support for multiple configuration builds in the Yocto Project &DISTRO;
3814 (&DISTRO_NAME;) Release does not include Shared State (sstate)
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003815 optimizations. Consequently, if a build uses the same object twice
Andrew Geissler09036742021-06-25 14:25:14 -05003816 in, for example, two different :term:`TMPDIR`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003817 directories, the build either loads from an existing sstate cache for
3818 that build at the start or builds the object fresh.
3819
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003820Enabling Multiple Configuration Build Dependencies
3821~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3822
3823Sometimes dependencies can exist between targets (multiconfigs) in a
3824multiple configuration build. For example, suppose that in order to
3825build a ``core-image-sato`` image for an "x86" multiconfig, the root
3826filesystem of an "arm" multiconfig must exist. This dependency is
3827essentially that the
3828:ref:`ref-tasks-image` task in the
3829``core-image-sato`` recipe depends on the completion of the
3830:ref:`ref-tasks-rootfs` task of the
3831``core-image-minimal`` recipe.
3832
3833To enable dependencies in a multiple configuration build, you must
3834declare the dependencies in the recipe using the following statement
Andrew Geisslerc926e172021-05-07 16:11:35 -05003835form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003836
3837 task_or_package[mcdepends] = "mc:from_multiconfig:to_multiconfig:recipe_name:task_on_which_to_depend"
3838
3839To better show how to use this statement, consider the example scenario
3840from the first paragraph of this section. The following statement needs
Andrew Geisslerc926e172021-05-07 16:11:35 -05003841to be added to the recipe that builds the ``core-image-sato`` image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003842
3843 do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_rootfs"
3844
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003845In this example, the `from_multiconfig` is "x86". The `to_multiconfig` is "arm". The
Patrick Williams2194f502022-10-16 14:26:09 -05003846task on which the :ref:`ref-tasks-image` task in the recipe depends is the
3847:ref:`ref-tasks-rootfs` task from the ``core-image-minimal`` recipe associated
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003848with the "arm" multiconfig.
3849
3850Once you set up this dependency, you can build the "x86" multiconfig
Andrew Geisslerc926e172021-05-07 16:11:35 -05003851using a BitBake command as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003852
3853 $ bitbake mc:x86:core-image-sato
3854
3855This command executes all the tasks needed to create the
3856``core-image-sato`` image for the "x86" multiconfig. Because of the
Patrick Williams2194f502022-10-16 14:26:09 -05003857dependency, BitBake also executes through the :ref:`ref-tasks-rootfs` task for the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003858"arm" multiconfig build.
3859
3860Having a recipe depend on the root filesystem of another build might not
3861seem that useful. Consider this change to the statement in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05003862``core-image-sato`` recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003863
3864 do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_image"
3865
3866In this case, BitBake must
3867create the ``core-image-minimal`` image for the "arm" build since the
3868"x86" build depends on it.
3869
3870Because "x86" and "arm" are enabled for multiple configuration builds
3871and have separate configuration files, BitBake places the artifacts for
3872each build in the respective temporary build directories (i.e.
3873:term:`TMPDIR`).
3874
Patrick Williams2194f502022-10-16 14:26:09 -05003875Building an Initial RAM Filesystem (Initramfs) Image
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003876----------------------------------------------------
3877
Patrick Williams2194f502022-10-16 14:26:09 -05003878An initial RAM filesystem (:term:`Initramfs`) image provides a temporary root
3879filesystem used for early system initialization, typically providing tools and
3880loading modules needed to locate and mount the final root filesystem.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003881
Patrick Williams2194f502022-10-16 14:26:09 -05003882Follow these steps to create an :term:`Initramfs` image:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003883
Patrick Williams2194f502022-10-16 14:26:09 -050038841. *Create the Initramfs Image Recipe:* You can reference the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003885 ``core-image-minimal-initramfs.bb`` recipe found in the
3886 ``meta/recipes-core`` directory of the :term:`Source Directory`
Patrick Williams2194f502022-10-16 14:26:09 -05003887 as an example from which to work.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003888
Patrick Williams2194f502022-10-16 14:26:09 -050038892. *Decide if You Need to Bundle the Initramfs Image Into the Kernel
3890 Image:* If you want the :term:`Initramfs` image that is built to be bundled
3891 in with the kernel image, set the :term:`INITRAMFS_IMAGE_BUNDLE`
3892 variable to ``"1"`` in your ``local.conf`` configuration file and set the
3893 :term:`INITRAMFS_IMAGE` variable in the recipe that builds the kernel image.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003894
Patrick Williams2194f502022-10-16 14:26:09 -05003895 Setting the :term:`INITRAMFS_IMAGE_BUNDLE` flag causes the :term:`Initramfs`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003896 image to be unpacked into the ``${B}/usr/`` directory. The unpacked
Patrick Williams2194f502022-10-16 14:26:09 -05003897 :term:`Initramfs` image is then passed to the kernel's ``Makefile`` using the
3898 :term:`CONFIG_INITRAMFS_SOURCE` variable, allowing the :term:`Initramfs`
3899 image to be built into the kernel normally.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003900
Patrick Williams2194f502022-10-16 14:26:09 -050039013. *Optionally Add Items to the Initramfs Image Through the Initramfs
3902 Image Recipe:* If you add items to the :term:`Initramfs` image by way of its
3903 recipe, you should use :term:`PACKAGE_INSTALL` rather than
3904 :term:`IMAGE_INSTALL`. :term:`PACKAGE_INSTALL` gives more direct control of
3905 what is added to the image as compared to the defaults you might not
3906 necessarily want that are set by the :ref:`image <ref-classes-image>`
3907 or :ref:`core-image <ref-classes-core-image>` classes.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003908
Patrick Williams2194f502022-10-16 14:26:09 -050039094. *Build the Kernel Image and the Initramfs Image:* Build your kernel
3910 image using BitBake. Because the :term:`Initramfs` image recipe is a
3911 dependency of the kernel image, the :term:`Initramfs` image is built as well
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003912 and bundled with the kernel image if you used the
Patrick Williams2194f502022-10-16 14:26:09 -05003913 :term:`INITRAMFS_IMAGE_BUNDLE` variable described earlier.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003914
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00003915Bundling an Initramfs Image From a Separate Multiconfig
3916~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3917
Patrick Williams2194f502022-10-16 14:26:09 -05003918There may be a case where we want to build an :term:`Initramfs` image which does not
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00003919inherit the same distro policy as our main image, for example, we may want
Patrick Williams2194f502022-10-16 14:26:09 -05003920our main image to use ``TCLIBC="glibc"``, but to use ``TCLIBC="musl"`` in our :term:`Initramfs`
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00003921image to keep a smaller footprint. However, by performing the steps mentioned
Patrick Williams2194f502022-10-16 14:26:09 -05003922above the :term:`Initramfs` image will inherit ``TCLIBC="glibc"`` without allowing us
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00003923to override it.
3924
3925To achieve this, you need to perform some additional steps:
3926
Patrick Williams2194f502022-10-16 14:26:09 -050039271. *Create a multiconfig for your Initramfs image:* You can perform the steps
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00003928 on ":ref:`dev-manual/common-tasks:building images for multiple targets using multiple configurations`" to create a separate multiconfig.
3929 For the sake of simplicity let's assume such multiconfig is called: ``initramfscfg.conf`` and
3930 contains the variables::
3931
3932 TMPDIR="${TOPDIR}/tmp-initramfscfg"
3933 TCLIBC="musl"
3934
Patrick Williams2194f502022-10-16 14:26:09 -050039352. *Set additional Initramfs variables on your main configuration:*
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00003936 Additionally, on your main configuration (``local.conf``) you need to set the
3937 variables::
3938
3939 INITRAMFS_MULTICONFIG = "initramfscfg"
3940 INITRAMFS_DEPLOY_DIR_IMAGE = "${TOPDIR}/tmp-initramfscfg/deploy/images/${MACHINE}"
3941
3942 The variables :term:`INITRAMFS_MULTICONFIG` and :term:`INITRAMFS_DEPLOY_DIR_IMAGE`
3943 are used to create a multiconfig dependency from the kernel to the :term:`INITRAMFS_IMAGE`
3944 to be built coming from the ``initramfscfg`` multiconfig, and to let the
3945 buildsystem know where the :term:`INITRAMFS_IMAGE` will be located.
3946
3947 Building a system with such configuration will build the kernel using the
Patrick Williams2194f502022-10-16 14:26:09 -05003948 main configuration but the :ref:`ref-tasks-bundle_initramfs` task will grab the
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00003949 selected :term:`INITRAMFS_IMAGE` from :term:`INITRAMFS_DEPLOY_DIR_IMAGE`
Patrick Williams2194f502022-10-16 14:26:09 -05003950 instead, resulting in a musl based :term:`Initramfs` image bundled in the kernel
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00003951 but a glibc based main image.
3952
3953 The same is applicable to avoid inheriting :term:`DISTRO_FEATURES` on :term:`INITRAMFS_IMAGE`
3954 or to build a different :term:`DISTRO` for it such as ``poky-tiny``.
3955
3956
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003957Building a Tiny System
3958----------------------
3959
3960Very small distributions have some significant advantages such as
3961requiring less on-die or in-package memory (cheaper), better performance
3962through efficient cache usage, lower power requirements due to less
3963memory, faster boot times, and reduced development overhead. Some
3964real-world examples where a very small distribution gives you distinct
3965advantages are digital cameras, medical devices, and small headless
3966systems.
3967
3968This section presents information that shows you how you can trim your
3969distribution to even smaller sizes than the ``poky-tiny`` distribution,
3970which is around 5 Mbytes, that can be built out-of-the-box using the
3971Yocto Project.
3972
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003973Tiny System Overview
3974~~~~~~~~~~~~~~~~~~~~
3975
3976The following list presents the overall steps you need to consider and
3977perform to create distributions with smaller root filesystems, achieve
3978faster boot times, maintain your critical functionality, and avoid
3979initial RAM disks:
3980
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05003981- :ref:`Determine your goals and guiding principles
3982 <dev-manual/common-tasks:goals and guiding principles>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003983
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05003984- :ref:`dev-manual/common-tasks:understand what contributes to your image size`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003985
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05003986- :ref:`Reduce the size of the root filesystem
3987 <dev-manual/common-tasks:trim the root filesystem>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003988
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05003989- :ref:`Reduce the size of the kernel <dev-manual/common-tasks:trim the kernel>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003990
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05003991- :ref:`dev-manual/common-tasks:remove package management requirements`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003992
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05003993- :ref:`dev-manual/common-tasks:look for other ways to minimize size`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003994
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05003995- :ref:`dev-manual/common-tasks:iterate on the process`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003996
3997Goals and Guiding Principles
3998~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3999
4000Before you can reach your destination, you need to know where you are
4001going. Here is an example list that you can use as a guide when creating
4002very small distributions:
4003
4004- Determine how much space you need (e.g. a kernel that is 1 Mbyte or
4005 less and a root filesystem that is 3 Mbytes or less).
4006
4007- Find the areas that are currently taking 90% of the space and
4008 concentrate on reducing those areas.
4009
4010- Do not create any difficult "hacks" to achieve your goals.
4011
4012- Leverage the device-specific options.
4013
4014- Work in a separate layer so that you keep changes isolated. For
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004015 information on how to create layers, see the
4016 ":ref:`dev-manual/common-tasks:understanding and creating layers`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004017
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004018Understand What Contributes to Your Image Size
4019~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4020
4021It is easiest to have something to start with when creating your own
4022distribution. You can use the Yocto Project out-of-the-box to create the
4023``poky-tiny`` distribution. Ultimately, you will want to make changes in
4024your own distribution that are likely modeled after ``poky-tiny``.
4025
4026.. note::
4027
Andrew Geissler09036742021-06-25 14:25:14 -05004028 To use ``poky-tiny`` in your build, set the :term:`DISTRO` variable in your
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004029 ``local.conf`` file to "poky-tiny" as described in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06004030 ":ref:`dev-manual/common-tasks:creating your own distribution`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004031 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004032
4033Understanding some memory concepts will help you reduce the system size.
4034Memory consists of static, dynamic, and temporary memory. Static memory
4035is the TEXT (code), DATA (initialized data in the code), and BSS
4036(uninitialized data) sections. Dynamic memory represents memory that is
4037allocated at runtime: stacks, hash tables, and so forth. Temporary
4038memory is recovered after the boot process. This memory consists of
4039memory used for decompressing the kernel and for the ``__init__``
4040functions.
4041
4042To help you see where you currently are with kernel and root filesystem
4043sizes, you can use two tools found in the :term:`Source Directory`
4044in the
4045``scripts/tiny/`` directory:
4046
4047- ``ksize.py``: Reports component sizes for the kernel build objects.
4048
4049- ``dirsize.py``: Reports component sizes for the root filesystem.
4050
4051This next tool and command help you organize configuration fragments and
4052view file dependencies in a human-readable form:
4053
4054- ``merge_config.sh``: Helps you manage configuration files and
4055 fragments within the kernel. With this tool, you can merge individual
4056 configuration fragments together. The tool allows you to make
4057 overrides and warns you of any missing configuration options. The
4058 tool is ideal for allowing you to iterate on configurations, create
4059 minimal configurations, and create configuration files for different
4060 machines without having to duplicate your process.
4061
4062 The ``merge_config.sh`` script is part of the Linux Yocto kernel Git
4063 repositories (i.e. ``linux-yocto-3.14``, ``linux-yocto-3.10``,
4064 ``linux-yocto-3.8``, and so forth) in the ``scripts/kconfig``
4065 directory.
4066
4067 For more information on configuration fragments, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06004068 ":ref:`kernel-dev/common:creating configuration fragments`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004069 section in the Yocto Project Linux Kernel Development Manual.
4070
4071- ``bitbake -u taskexp -g bitbake_target``: Using the BitBake command
4072 with these options brings up a Dependency Explorer from which you can
4073 view file dependencies. Understanding these dependencies allows you
4074 to make informed decisions when cutting out various pieces of the
4075 kernel and root filesystem.
4076
4077Trim the Root Filesystem
4078~~~~~~~~~~~~~~~~~~~~~~~~
4079
4080The root filesystem is made up of packages for booting, libraries, and
4081applications. To change things, you can configure how the packaging
4082happens, which changes the way you build them. You can also modify the
4083filesystem itself or select a different filesystem.
4084
4085First, find out what is hogging your root filesystem by running the
Andrew Geisslerc926e172021-05-07 16:11:35 -05004086``dirsize.py`` script from your root directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004087
4088 $ cd root-directory-of-image
4089 $ dirsize.py 100000 > dirsize-100k.log
4090 $ cat dirsize-100k.log
4091
4092You can apply a filter to the script to ignore files
4093under a certain size. The previous example filters out any files below
4094100 Kbytes. The sizes reported by the tool are uncompressed, and thus
4095will be smaller by a relatively constant factor in a compressed root
4096filesystem. When you examine your log file, you can focus on areas of
4097the root filesystem that take up large amounts of memory.
4098
4099You need to be sure that what you eliminate does not cripple the
4100functionality you need. One way to see how packages relate to each other
Andrew Geisslerc926e172021-05-07 16:11:35 -05004101is by using the Dependency Explorer UI with the BitBake command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004102
4103 $ cd image-directory
4104 $ bitbake -u taskexp -g image
4105
4106Use the interface to
4107select potential packages you wish to eliminate and see their dependency
4108relationships.
4109
4110When deciding how to reduce the size, get rid of packages that result in
4111minimal impact on the feature set. For example, you might not need a VGA
4112display. Or, you might be able to get by with ``devtmpfs`` and ``mdev``
4113instead of ``udev``.
4114
4115Use your ``local.conf`` file to make changes. For example, to eliminate
4116``udev`` and ``glib``, set the following in the local configuration
Andrew Geisslerc926e172021-05-07 16:11:35 -05004117file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004118
4119 VIRTUAL-RUNTIME_dev_manager = ""
4120
4121Finally, you should consider exactly the type of root filesystem you
4122need to meet your needs while also reducing its size. For example,
4123consider ``cramfs``, ``squashfs``, ``ubifs``, ``ext2``, or an
Patrick Williams2194f502022-10-16 14:26:09 -05004124:term:`Initramfs` using ``initramfs``. Be aware that ``ext3`` requires a 1
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004125Mbyte journal. If you are okay with running read-only, you do not need
4126this journal.
4127
4128.. note::
4129
4130 After each round of elimination, you need to rebuild your system and
4131 then use the tools to see the effects of your reductions.
4132
4133Trim the Kernel
4134~~~~~~~~~~~~~~~
4135
4136The kernel is built by including policies for hardware-independent
4137aspects. What subsystems do you enable? For what architecture are you
4138building? Which drivers do you build by default?
4139
4140.. note::
4141
4142 You can modify the kernel source if you want to help with boot time.
4143
4144Run the ``ksize.py`` script from the top-level Linux build directory to
Andrew Geisslerc926e172021-05-07 16:11:35 -05004145get an idea of what is making up the kernel::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004146
4147 $ cd top-level-linux-build-directory
4148 $ ksize.py > ksize.log
4149 $ cat ksize.log
4150
4151When you examine the log, you will see how much space is taken up with
4152the built-in ``.o`` files for drivers, networking, core kernel files,
4153filesystem, sound, and so forth. The sizes reported by the tool are
4154uncompressed, and thus will be smaller by a relatively constant factor
4155in a compressed kernel image. Look to reduce the areas that are large
4156and taking up around the "90% rule."
4157
4158To examine, or drill down, into any particular area, use the ``-d``
Andrew Geisslerc926e172021-05-07 16:11:35 -05004159option with the script::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004160
4161 $ ksize.py -d > ksize.log
4162
4163Using this option
4164breaks out the individual file information for each area of the kernel
4165(e.g. drivers, networking, and so forth).
4166
4167Use your log file to see what you can eliminate from the kernel based on
4168features you can let go. For example, if you are not going to need
4169sound, you do not need any drivers that support sound.
4170
4171After figuring out what to eliminate, you need to reconfigure the kernel
4172to reflect those changes during the next build. You could run
4173``menuconfig`` and make all your changes at once. However, that makes it
4174difficult to see the effects of your individual eliminations and also
4175makes it difficult to replicate the changes for perhaps another target
4176device. A better method is to start with no configurations using
4177``allnoconfig``, create configuration fragments for individual changes,
4178and then manage the fragments into a single configuration file using
4179``merge_config.sh``. The tool makes it easy for you to iterate using the
4180configuration change and build cycle.
4181
4182Each time you make configuration changes, you need to rebuild the kernel
4183and check to see what impact your changes had on the overall size.
4184
4185Remove Package Management Requirements
4186~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4187
4188Packaging requirements add size to the image. One way to reduce the size
4189of the image is to remove all the packaging requirements from the image.
4190This reduction includes both removing the package manager and its unique
4191dependencies as well as removing the package management data itself.
4192
4193To eliminate all the packaging requirements for an image, be sure that
4194"package-management" is not part of your
4195:term:`IMAGE_FEATURES`
4196statement for the image. When you remove this feature, you are removing
4197the package manager as well as its dependencies from the root
4198filesystem.
4199
4200Look for Other Ways to Minimize Size
4201~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4202
4203Depending on your particular circumstances, other areas that you can
4204trim likely exist. The key to finding these areas is through tools and
4205methods described here combined with experimentation and iteration. Here
4206are a couple of areas to experiment with:
4207
4208- ``glibc``: In general, follow this process:
4209
4210 1. Remove ``glibc`` features from
4211 :term:`DISTRO_FEATURES`
4212 that you think you do not need.
4213
4214 2. Build your distribution.
4215
4216 3. If the build fails due to missing symbols in a package, determine
4217 if you can reconfigure the package to not need those features. For
4218 example, change the configuration to not support wide character
4219 support as is done for ``ncurses``. Or, if support for those
4220 characters is needed, determine what ``glibc`` features provide
4221 the support and restore the configuration.
4222
4223 4. Rebuild and repeat the process.
4224
4225- ``busybox``: For BusyBox, use a process similar as described for
4226 ``glibc``. A difference is you will need to boot the resulting system
4227 to see if you are able to do everything you expect from the running
4228 system. You need to be sure to integrate configuration fragments into
4229 Busybox because BusyBox handles its own core features and then allows
4230 you to add configuration fragments on top.
4231
4232Iterate on the Process
4233~~~~~~~~~~~~~~~~~~~~~~
4234
4235If you have not reached your goals on system size, you need to iterate
4236on the process. The process is the same. Use the tools and see just what
4237is taking up 90% of the root filesystem and the kernel. Decide what you
4238can eliminate without limiting your device beyond what you need.
4239
4240Depending on your system, a good place to look might be Busybox, which
4241provides a stripped down version of Unix tools in a single, executable
4242file. You might be able to drop virtual terminal services or perhaps
4243ipv6.
4244
4245Building Images for More than One Machine
4246-----------------------------------------
4247
4248A common scenario developers face is creating images for several
4249different machines that use the same software environment. In this
4250situation, it is tempting to set the tunings and optimization flags for
4251each build specifically for the targeted hardware (i.e. "maxing out" the
4252tunings). Doing so can considerably add to build times and package feed
4253maintenance collectively for the machines. For example, selecting tunes
4254that are extremely specific to a CPU core used in a system might enable
4255some micro optimizations in GCC for that particular system but would
4256otherwise not gain you much of a performance difference across the other
4257systems as compared to using a more general tuning across all the builds
4258(e.g. setting :term:`DEFAULTTUNE`
4259specifically for each machine's build). Rather than "max out" each
4260build's tunings, you can take steps that cause the OpenEmbedded build
4261system to reuse software across the various machines where it makes
4262sense.
4263
4264If build speed and package feed maintenance are considerations, you
4265should consider the points in this section that can help you optimize
4266your tunings to best consider build times and package feed maintenance.
4267
Patrick Williams2390b1b2022-11-03 13:47:49 -05004268- *Share the :term:`Build Directory`:* If at all possible, share the
4269 :term:`TMPDIR` across builds. The Yocto Project supports switching between
4270 different :term:`MACHINE` values in the same :term:`TMPDIR`. This practice
4271 is well supported and regularly used by developers when building for
4272 multiple machines. When you use the same :term:`TMPDIR` for multiple
4273 machine builds, the OpenEmbedded build system can reuse the existing native
4274 and often cross-recipes for multiple machines. Thus, build time decreases.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004275
4276 .. note::
4277
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004278 If :term:`DISTRO` settings change or fundamental configuration settings
Andrew Geissler09036742021-06-25 14:25:14 -05004279 such as the filesystem layout, you need to work with a clean :term:`TMPDIR`.
4280 Sharing :term:`TMPDIR` under these circumstances might work but since it is
Andrew Geissler5f350902021-07-23 13:09:54 -04004281 not guaranteed, you should use a clean :term:`TMPDIR`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004282
4283- *Enable the Appropriate Package Architecture:* By default, the
4284 OpenEmbedded build system enables three levels of package
4285 architectures: "all", "tune" or "package", and "machine". Any given
4286 recipe usually selects one of these package architectures (types) for
4287 its output. Depending for what a given recipe creates packages,
4288 making sure you enable the appropriate package architecture can
4289 directly impact the build time.
4290
4291 A recipe that just generates scripts can enable "all" architecture
4292 because there are no binaries to build. To specifically enable "all"
4293 architecture, be sure your recipe inherits the
4294 :ref:`allarch <ref-classes-allarch>` class.
4295 This class is useful for "all" architectures because it configures
4296 many variables so packages can be used across multiple architectures.
4297
4298 If your recipe needs to generate packages that are machine-specific
4299 or when one of the build or runtime dependencies is already
4300 machine-architecture dependent, which makes your recipe also
4301 machine-architecture dependent, make sure your recipe enables the
4302 "machine" package architecture through the
4303 :term:`MACHINE_ARCH`
Andrew Geisslerc926e172021-05-07 16:11:35 -05004304 variable::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004305
4306 PACKAGE_ARCH = "${MACHINE_ARCH}"
4307
4308 When you do not
4309 specifically enable a package architecture through the
4310 :term:`PACKAGE_ARCH`, The
4311 OpenEmbedded build system defaults to the
Andrew Geisslerc926e172021-05-07 16:11:35 -05004312 :term:`TUNE_PKGARCH` setting::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004313
4314 PACKAGE_ARCH = "${TUNE_PKGARCH}"
4315
4316- *Choose a Generic Tuning File if Possible:* Some tunes are more
4317 generic and can run on multiple targets (e.g. an ``armv5`` set of
4318 packages could run on ``armv6`` and ``armv7`` processors in most
4319 cases). Similarly, ``i486`` binaries could work on ``i586`` and
4320 higher processors. You should realize, however, that advances on
4321 newer processor versions would not be used.
4322
4323 If you select the same tune for several different machines, the
4324 OpenEmbedded build system reuses software previously built, thus
4325 speeding up the overall build time. Realize that even though a new
4326 sysroot for each machine is generated, the software is not recompiled
4327 and only one package feed exists.
4328
William A. Kennington IIIac69b482021-06-02 12:28:27 -07004329- *Manage Granular Level Packaging:* Sometimes there are cases where
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004330 injecting another level of package architecture beyond the three
4331 higher levels noted earlier can be useful. For example, consider how
4332 NXP (formerly Freescale) allows for the easy reuse of binary packages
4333 in their layer
Andrew Geissler09209ee2020-12-13 08:44:15 -06004334 :yocto_git:`meta-freescale </meta-freescale/>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004335 In this example, the
Andrew Geissler09209ee2020-12-13 08:44:15 -06004336 :yocto_git:`fsl-dynamic-packagearch </meta-freescale/tree/classes/fsl-dynamic-packagearch.bbclass>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004337 class shares GPU packages for i.MX53 boards because all boards share
4338 the AMD GPU. The i.MX6-based boards can do the same because all
4339 boards share the Vivante GPU. This class inspects the BitBake
4340 datastore to identify if the package provides or depends on one of
4341 the sub-architecture values. If so, the class sets the
4342 :term:`PACKAGE_ARCH` value
4343 based on the ``MACHINE_SUBARCH`` value. If the package does not
4344 provide or depend on one of the sub-architecture values but it
4345 matches a value in the machine-specific filter, it sets
4346 :term:`MACHINE_ARCH`. This
4347 behavior reduces the number of packages built and saves build time by
4348 reusing binaries.
4349
4350- *Use Tools to Debug Issues:* Sometimes you can run into situations
4351 where software is being rebuilt when you think it should not be. For
4352 example, the OpenEmbedded build system might not be using shared
4353 state between machines when you think it should be. These types of
4354 situations are usually due to references to machine-specific
4355 variables such as :term:`MACHINE`,
4356 :term:`SERIAL_CONSOLES`,
4357 :term:`XSERVER`,
4358 :term:`MACHINE_FEATURES`,
4359 and so forth in code that is supposed to only be tune-specific or
4360 when the recipe depends
4361 (:term:`DEPENDS`,
4362 :term:`RDEPENDS`,
4363 :term:`RRECOMMENDS`,
4364 :term:`RSUGGESTS`, and so forth)
4365 on some other recipe that already has
4366 :term:`PACKAGE_ARCH` defined
4367 as "${MACHINE_ARCH}".
4368
4369 .. note::
4370
4371 Patches to fix any issues identified are most welcome as these
4372 issues occasionally do occur.
4373
4374 For such cases, you can use some tools to help you sort out the
4375 situation:
4376
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004377 - ``state-diff-machines.sh``*:* You can find this tool in the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004378 ``scripts`` directory of the Source Repositories. See the comments
4379 in the script for information on how to use the tool.
4380
4381 - *BitBake's "-S printdiff" Option:* Using this option causes
4382 BitBake to try to establish the closest signature match it can
4383 (e.g. in the shared state cache) and then run ``bitbake-diffsigs``
4384 over the matches to determine the stamps and delta where these two
4385 stamp trees diverge.
4386
4387Building Software from an External Source
4388-----------------------------------------
4389
Patrick Williams2390b1b2022-11-03 13:47:49 -05004390By default, the OpenEmbedded build system uses the :term:`Build Directory`
4391when building source code. The build process involves fetching the source
4392files, unpacking them, and then patching them if necessary before the build
4393takes place.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004394
William A. Kennington IIIac69b482021-06-02 12:28:27 -07004395There are situations where you might want to build software from source
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004396files that are external to and thus outside of the OpenEmbedded build
4397system. For example, suppose you have a project that includes a new BSP
4398with a heavily customized kernel. And, you want to minimize exposing the
4399build system to the development team so that they can focus on their
4400project and maintain everyone's workflow as much as possible. In this
4401case, you want a kernel source directory on the development machine
4402where the development occurs. You want the recipe's
4403:term:`SRC_URI` variable to point to
4404the external directory and use it as is, not copy it.
4405
4406To build from software that comes from an external source, all you need
4407to do is inherit the
4408:ref:`externalsrc <ref-classes-externalsrc>` class
4409and then set the
4410:term:`EXTERNALSRC` variable to
4411point to your external source code. Here are the statements to put in
Andrew Geisslerc926e172021-05-07 16:11:35 -05004412your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004413
4414 INHERIT += "externalsrc"
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004415 EXTERNALSRC:pn-myrecipe = "path-to-your-source-tree"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004416
4417This next example shows how to accomplish the same thing by setting
Andrew Geissler09036742021-06-25 14:25:14 -05004418:term:`EXTERNALSRC` in the recipe itself or in the recipe's append file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004419
4420 EXTERNALSRC = "path"
4421 EXTERNALSRC_BUILD = "path"
4422
4423.. note::
4424
4425 In order for these settings to take effect, you must globally or
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004426 locally inherit the :ref:`externalsrc <ref-classes-externalsrc>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004427 class.
4428
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00004429By default, :ref:`ref-classes-externalsrc` builds the source code in a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004430directory separate from the external source directory as specified by
4431:term:`EXTERNALSRC`. If you need
4432to have the source built in the same directory in which it resides, or
4433some other nominated directory, you can set
4434:term:`EXTERNALSRC_BUILD`
Andrew Geisslerc926e172021-05-07 16:11:35 -05004435to point to that directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004436
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004437 EXTERNALSRC_BUILD:pn-myrecipe = "path-to-your-source-tree"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004438
4439Replicating a Build Offline
4440---------------------------
4441
4442It can be useful to take a "snapshot" of upstream sources used in a
4443build and then use that "snapshot" later to replicate the build offline.
4444To do so, you need to first prepare and populate your downloads
4445directory your "snapshot" of files. Once your downloads directory is
4446ready, you can use it at any time and from any machine to replicate your
4447build.
4448
4449Follow these steps to populate your Downloads directory:
4450
44511. *Create a Clean Downloads Directory:* Start with an empty downloads
4452 directory (:term:`DL_DIR`). You
4453 start with an empty downloads directory by either removing the files
Andrew Geissler09036742021-06-25 14:25:14 -05004454 in the existing directory or by setting :term:`DL_DIR` to point to either
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004455 an empty location or one that does not yet exist.
4456
44572. *Generate Tarballs of the Source Git Repositories:* Edit your
Andrew Geisslerc926e172021-05-07 16:11:35 -05004458 ``local.conf`` configuration file as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004459
4460 DL_DIR = "/home/your-download-dir/"
4461 BB_GENERATE_MIRROR_TARBALLS = "1"
4462
4463 During
4464 the fetch process in the next step, BitBake gathers the source files
Andrew Geissler09036742021-06-25 14:25:14 -05004465 and creates tarballs in the directory pointed to by :term:`DL_DIR`. See
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004466 the
4467 :term:`BB_GENERATE_MIRROR_TARBALLS`
4468 variable for more information.
4469
44703. *Populate Your Downloads Directory Without Building:* Use BitBake to
Andrew Geisslerc926e172021-05-07 16:11:35 -05004471 fetch your sources but inhibit the build::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004472
4473 $ bitbake target --runonly=fetch
4474
4475 The downloads directory (i.e. ``${DL_DIR}``) now has
4476 a "snapshot" of the source files in the form of tarballs, which can
4477 be used for the build.
4478
44794. *Optionally Remove Any Git or other SCM Subdirectories From the
4480 Downloads Directory:* If you want, you can clean up your downloads
4481 directory by removing any Git or other Source Control Management
4482 (SCM) subdirectories such as ``${DL_DIR}/git2/*``. The tarballs
4483 already contain these subdirectories.
4484
4485Once your downloads directory has everything it needs regarding source
4486files, you can create your "own-mirror" and build your target.
4487Understand that you can use the files to build the target offline from
4488any machine and at any time.
4489
4490Follow these steps to build your target using the files in the downloads
4491directory:
4492
44931. *Using Local Files Only:* Inside your ``local.conf`` file, add the
Andrew Geissler595f6302022-01-24 19:11:47 +00004494 :term:`SOURCE_MIRROR_URL` variable, inherit the
4495 :ref:`own-mirrors <ref-classes-own-mirrors>` class, and use the
4496 :term:`BB_NO_NETWORK` variable to your ``local.conf``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004497 ::
4498
4499 SOURCE_MIRROR_URL ?= "file:///home/your-download-dir/"
4500 INHERIT += "own-mirrors"
4501 BB_NO_NETWORK = "1"
4502
Andrew Geissler595f6302022-01-24 19:11:47 +00004503 The :term:`SOURCE_MIRROR_URL` and :ref:`own-mirrors <ref-classes-own-mirrors>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004504 class set up the system to use the downloads directory as your "own
Andrew Geissler09036742021-06-25 14:25:14 -05004505 mirror". Using the :term:`BB_NO_NETWORK` variable makes sure that
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004506 BitBake's fetching process in step 3 stays local, which means files
4507 from your "own-mirror" are used.
4508
45092. *Start With a Clean Build:* You can start with a clean build by
Patrick Williams2390b1b2022-11-03 13:47:49 -05004510 removing the ``${``\ :term:`TMPDIR`\ ``}`` directory or using a new
4511 :term:`Build Directory`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004512
Andrew Geisslerc926e172021-05-07 16:11:35 -050045133. *Build Your Target:* Use BitBake to build your target::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004514
4515 $ bitbake target
4516
4517 The build completes using the known local "snapshot" of source
4518 files from your mirror. The resulting tarballs for your "snapshot" of
4519 source files are in the downloads directory.
4520
4521 .. note::
4522
4523 The offline build does not work if recipes attempt to find the
4524 latest version of software by setting
4525 :term:`SRCREV` to
Andrew Geisslerc926e172021-05-07 16:11:35 -05004526 ``${``\ :term:`AUTOREV`\ ``}``::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004527
4528 SRCREV = "${AUTOREV}"
4529
Andrew Geissler09036742021-06-25 14:25:14 -05004530 When a recipe sets :term:`SRCREV` to
Andrew Geissler5199d832021-09-24 16:47:35 -05004531 ``${``\ :term:`AUTOREV`\ ``}``, the build system accesses the network in an
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004532 attempt to determine the latest version of software from the SCM.
Andrew Geissler09036742021-06-25 14:25:14 -05004533 Typically, recipes that use :term:`AUTOREV` are custom or modified
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004534 recipes. Recipes that reside in public repositories usually do not
Andrew Geissler09036742021-06-25 14:25:14 -05004535 use :term:`AUTOREV`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004536
Andrew Geissler09036742021-06-25 14:25:14 -05004537 If you do have recipes that use :term:`AUTOREV`, you can take steps to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004538 still use the recipes in an offline build. Do the following:
4539
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004540 1. Use a configuration generated by enabling :ref:`build
4541 history <dev-manual/common-tasks:maintaining build output quality>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004542
4543 2. Use the ``buildhistory-collect-srcrevs`` command to collect the
Andrew Geissler09036742021-06-25 14:25:14 -05004544 stored :term:`SRCREV` values from the build's history. For more
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004545 information on collecting these values, see the
4546 ":ref:`dev-manual/common-tasks:build history package information`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004547 section.
4548
4549 3. Once you have the correct source revisions, you can modify
Andrew Geissler09036742021-06-25 14:25:14 -05004550 those recipes to set :term:`SRCREV` to specific versions of the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004551 software.
4552
4553Speeding Up a Build
4554===================
4555
4556Build time can be an issue. By default, the build system uses simple
4557controls to try and maximize build efficiency. In general, the default
4558settings for all the following variables result in the most efficient
4559build times when dealing with single socket systems (i.e. a single CPU).
4560If you have multiple CPUs, you might try increasing the default values
4561to gain more speed. See the descriptions in the glossary for each
4562variable for more information:
4563
4564- :term:`BB_NUMBER_THREADS`:
4565 The maximum number of threads BitBake simultaneously executes.
4566
Patrick Williams213cb262021-08-07 19:21:33 -05004567- :term:`BB_NUMBER_PARSE_THREADS`:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004568 The number of threads BitBake uses during parsing.
4569
4570- :term:`PARALLEL_MAKE`: Extra
4571 options passed to the ``make`` command during the
4572 :ref:`ref-tasks-compile` task in
4573 order to specify parallel compilation on the local build host.
4574
4575- :term:`PARALLEL_MAKEINST`:
4576 Extra options passed to the ``make`` command during the
4577 :ref:`ref-tasks-install` task in
4578 order to specify parallel installation on the local build host.
4579
4580As mentioned, these variables all scale to the number of processor cores
4581available on the build system. For single socket systems, this
4582auto-scaling ensures that the build system fundamentally takes advantage
4583of potential parallel operations during the build based on the build
4584machine's capabilities.
4585
4586Following are additional factors that can affect build speed:
4587
4588- File system type: The file system type that the build is being
4589 performed on can also influence performance. Using ``ext4`` is
4590 recommended as compared to ``ext2`` and ``ext3`` due to ``ext4``
4591 improved features such as extents.
4592
4593- Disabling the updating of access time using ``noatime``: The
4594 ``noatime`` mount option prevents the build system from updating file
4595 and directory access times.
4596
4597- Setting a longer commit: Using the "commit=" mount option increases
4598 the interval in seconds between disk cache writes. Changing this
4599 interval from the five second default to something longer increases
4600 the risk of data loss but decreases the need to write to the disk,
4601 thus increasing the build performance.
4602
4603- Choosing the packaging backend: Of the available packaging backends,
4604 IPK is the fastest. Additionally, selecting a singular packaging
4605 backend also helps.
4606
4607- Using ``tmpfs`` for :term:`TMPDIR`
4608 as a temporary file system: While this can help speed up the build,
4609 the benefits are limited due to the compiler using ``-pipe``. The
4610 build system goes to some lengths to avoid ``sync()`` calls into the
4611 file system on the principle that if there was a significant failure,
Patrick Williams2390b1b2022-11-03 13:47:49 -05004612 the :term:`Build Directory` contents could easily be rebuilt.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004613
4614- Inheriting the
4615 :ref:`rm_work <ref-classes-rm-work>` class:
4616 Inheriting this class has shown to speed up builds due to
4617 significantly lower amounts of data stored in the data cache as well
4618 as on disk. Inheriting this class also makes cleanup of
4619 :term:`TMPDIR` faster, at the
4620 expense of being easily able to dive into the source code. File
4621 system maintainers have recommended that the fastest way to clean up
4622 large numbers of files is to reformat partitions rather than delete
4623 files due to the linear nature of partitions. This, of course,
4624 assumes you structure the disk partitions and file systems in a way
4625 that this is practical.
4626
4627Aside from the previous list, you should keep some trade offs in mind
4628that can help you speed up the build:
4629
4630- Remove items from
4631 :term:`DISTRO_FEATURES`
4632 that you might not need.
4633
4634- Exclude debug symbols and other debug information: If you do not need
4635 these symbols and other debug information, disabling the ``*-dbg``
4636 package generation can speed up the build. You can disable this
4637 generation by setting the
4638 :term:`INHIBIT_PACKAGE_DEBUG_SPLIT`
4639 variable to "1".
4640
4641- Disable static library generation for recipes derived from
4642 ``autoconf`` or ``libtool``: Following is an example showing how to
4643 disable static libraries and still provide an override to handle
Andrew Geisslerc926e172021-05-07 16:11:35 -05004644 exceptions::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004645
4646 STATICLIBCONF = "--disable-static"
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004647 STATICLIBCONF:sqlite3-native = ""
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004648 EXTRA_OECONF += "${STATICLIBCONF}"
4649
4650 .. note::
4651
4652 - Some recipes need static libraries in order to work correctly
4653 (e.g. ``pseudo-native`` needs ``sqlite3-native``). Overrides,
4654 as in the previous example, account for these kinds of
4655 exceptions.
4656
4657 - Some packages have packaging code that assumes the presence of
4658 the static libraries. If so, you might need to exclude them as
4659 well.
4660
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004661Working With Libraries
4662======================
4663
4664Libraries are an integral part of your system. This section describes
4665some common practices you might find helpful when working with libraries
4666to build your system:
4667
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004668- :ref:`How to include static library files
4669 <dev-manual/common-tasks:including static library files>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004670
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004671- :ref:`How to use the Multilib feature to combine multiple versions of
4672 library files into a single image
4673 <dev-manual/common-tasks:combining multiple versions of library files into one image>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004674
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004675- :ref:`How to install multiple versions of the same library in parallel on
4676 the same system
4677 <dev-manual/common-tasks:installing multiple versions of the same library>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004678
4679Including Static Library Files
4680------------------------------
4681
4682If you are building a library and the library offers static linking, you
4683can control which static library files (``*.a`` files) get included in
4684the built library.
4685
4686The :term:`PACKAGES` and
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004687:term:`FILES:* <FILES>` variables in the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004688``meta/conf/bitbake.conf`` configuration file define how files installed
Patrick Williams2194f502022-10-16 14:26:09 -05004689by the :ref:`ref-tasks-install` task are packaged. By default, the :term:`PACKAGES`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004690variable includes ``${PN}-staticdev``, which represents all static
4691library files.
4692
4693.. note::
4694
4695 Some previously released versions of the Yocto Project defined the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004696 static library files through ``${PN}-dev``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004697
4698Following is part of the BitBake configuration file, where you can see
Andrew Geisslerc926e172021-05-07 16:11:35 -05004699how the static library files are defined::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004700
4701 PACKAGE_BEFORE_PN ?= ""
Andrew Geissler595f6302022-01-24 19:11:47 +00004702 PACKAGES = "${PN}-src ${PN}-dbg ${PN}-staticdev ${PN}-dev ${PN}-doc ${PN}-locale ${PACKAGE_BEFORE_PN} ${PN}"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004703 PACKAGES_DYNAMIC = "^${PN}-locale-.*"
4704 FILES = ""
4705
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004706 FILES:${PN} = "${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*${SOLIBS} \
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004707 ${sysconfdir} ${sharedstatedir} ${localstatedir} \
4708 ${base_bindir}/* ${base_sbindir}/* \
4709 ${base_libdir}/*${SOLIBS} \
Andrew Geissler595f6302022-01-24 19:11:47 +00004710 ${base_prefix}/lib/udev ${prefix}/lib/udev \
4711 ${base_libdir}/udev ${libdir}/udev \
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004712 ${datadir}/${BPN} ${libdir}/${BPN}/* \
4713 ${datadir}/pixmaps ${datadir}/applications \
4714 ${datadir}/idl ${datadir}/omf ${datadir}/sounds \
4715 ${libdir}/bonobo/servers"
4716
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004717 FILES:${PN}-bin = "${bindir}/* ${sbindir}/*"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004718
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004719 FILES:${PN}-doc = "${docdir} ${mandir} ${infodir} ${datadir}/gtk-doc \
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004720 ${datadir}/gnome/help"
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004721 SECTION:${PN}-doc = "doc"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004722
4723 FILES_SOLIBSDEV ?= "${base_libdir}/lib*${SOLIBSDEV} ${libdir}/lib*${SOLIBSDEV}"
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004724 FILES:${PN}-dev = "${includedir} ${FILES_SOLIBSDEV} ${libdir}/*.la \
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004725 ${libdir}/*.o ${libdir}/pkgconfig ${datadir}/pkgconfig \
4726 ${datadir}/aclocal ${base_libdir}/*.o \
Andrew Geissler595f6302022-01-24 19:11:47 +00004727 ${libdir}/${BPN}/*.la ${base_libdir}/*.la \
4728 ${libdir}/cmake ${datadir}/cmake"
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004729 SECTION:${PN}-dev = "devel"
4730 ALLOW_EMPTY:${PN}-dev = "1"
4731 RDEPENDS:${PN}-dev = "${PN} (= ${EXTENDPKGV})"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004732
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004733 FILES:${PN}-staticdev = "${libdir}/*.a ${base_libdir}/*.a ${libdir}/${BPN}/*.a"
4734 SECTION:${PN}-staticdev = "devel"
4735 RDEPENDS:${PN}-staticdev = "${PN}-dev (= ${EXTENDPKGV})"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004736
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004737Combining Multiple Versions of Library Files into One Image
4738-----------------------------------------------------------
4739
4740The build system offers the ability to build libraries with different
4741target optimizations or architecture formats and combine these together
4742into one system image. You can link different binaries in the image
4743against the different libraries as needed for specific use cases. This
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004744feature is called "Multilib".
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004745
4746An example would be where you have most of a system compiled in 32-bit
4747mode using 32-bit libraries, but you have something large, like a
4748database engine, that needs to be a 64-bit application and uses 64-bit
4749libraries. Multilib allows you to get the best of both 32-bit and 64-bit
4750libraries.
4751
4752While the Multilib feature is most commonly used for 32 and 64-bit
4753differences, the approach the build system uses facilitates different
4754target optimizations. You could compile some binaries to use one set of
4755libraries and other binaries to use a different set of libraries. The
4756libraries could differ in architecture, compiler options, or other
4757optimizations.
4758
William A. Kennington IIIac69b482021-06-02 12:28:27 -07004759There are several examples in the ``meta-skeleton`` layer found in the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004760:term:`Source Directory`:
4761
Andrew Geissler595f6302022-01-24 19:11:47 +00004762- :oe_git:`conf/multilib-example.conf </openembedded-core/tree/meta-skeleton/conf/multilib-example.conf>`
4763 configuration file.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004764
Andrew Geissler595f6302022-01-24 19:11:47 +00004765- :oe_git:`conf/multilib-example2.conf </openembedded-core/tree/meta-skeleton/conf/multilib-example2.conf>`
4766 configuration file.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004767
Andrew Geissler595f6302022-01-24 19:11:47 +00004768- :oe_git:`recipes-multilib/images/core-image-multilib-example.bb </openembedded-core/tree/meta-skeleton/recipes-multilib/images/core-image-multilib-example.bb>`
4769 recipe
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004770
4771Preparing to Use Multilib
4772~~~~~~~~~~~~~~~~~~~~~~~~~
4773
4774User-specific requirements drive the Multilib feature. Consequently,
William A. Kennington IIIac69b482021-06-02 12:28:27 -07004775there is no one "out-of-the-box" configuration that would
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004776meet your needs.
4777
4778In order to enable Multilib, you first need to ensure your recipe is
4779extended to support multiple libraries. Many standard recipes are
4780already extended and support multiple libraries. You can check in the
4781``meta/conf/multilib.conf`` configuration file in the
4782:term:`Source Directory` to see how this is
4783done using the
4784:term:`BBCLASSEXTEND` variable.
4785Eventually, all recipes will be covered and this list will not be
4786needed.
4787
Andrew Geissler595f6302022-01-24 19:11:47 +00004788For the most part, the :ref:`Multilib <ref-classes-multilib*>`
4789class extension works automatically to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004790extend the package name from ``${PN}`` to ``${MLPREFIX}${PN}``, where
Andrew Geissler5f350902021-07-23 13:09:54 -04004791:term:`MLPREFIX` is the particular multilib (e.g. "lib32-" or "lib64-").
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004792Standard variables such as
4793:term:`DEPENDS`,
4794:term:`RDEPENDS`,
4795:term:`RPROVIDES`,
4796:term:`RRECOMMENDS`,
4797:term:`PACKAGES`, and
4798:term:`PACKAGES_DYNAMIC` are
4799automatically extended by the system. If you are extending any manual
4800code in the recipe, you can use the ``${MLPREFIX}`` variable to ensure
Andrew Geissler595f6302022-01-24 19:11:47 +00004801those names are extended correctly.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004802
4803Using Multilib
4804~~~~~~~~~~~~~~
4805
4806After you have set up the recipes, you need to define the actual
4807combination of multiple libraries you want to build. You accomplish this
4808through your ``local.conf`` configuration file in the
Patrick Williams2390b1b2022-11-03 13:47:49 -05004809:term:`Build Directory`. An example configuration would be as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004810
4811 MACHINE = "qemux86-64"
4812 require conf/multilib.conf
4813 MULTILIBS = "multilib:lib32"
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004814 DEFAULTTUNE:virtclass-multilib-lib32 = "x86"
Andrew Geisslerd5838332022-05-27 11:33:10 -05004815 IMAGE_INSTALL:append = " lib32-glib-2.0"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004816
4817This example enables an additional library named
4818``lib32`` alongside the normal target packages. When combining these
4819"lib32" alternatives, the example uses "x86" for tuning. For information
4820on this particular tuning, see
4821``meta/conf/machine/include/ia32/arch-ia32.inc``.
4822
4823The example then includes ``lib32-glib-2.0`` in all the images, which
4824illustrates one method of including a multiple library dependency. You
Andrew Geisslerc926e172021-05-07 16:11:35 -05004825can use a normal image build to include this dependency, for example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004826
4827 $ bitbake core-image-sato
4828
4829You can also build Multilib packages
Andrew Geisslerc926e172021-05-07 16:11:35 -05004830specifically with a command like this::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004831
4832 $ bitbake lib32-glib-2.0
4833
4834Additional Implementation Details
4835~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4836
William A. Kennington IIIac69b482021-06-02 12:28:27 -07004837There are generic implementation details as well as details that are specific to
4838package management systems. Following are implementation details
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004839that exist regardless of the package management system:
4840
4841- The typical convention used for the class extension code as used by
4842 Multilib assumes that all package names specified in
4843 :term:`PACKAGES` that contain
4844 ``${PN}`` have ``${PN}`` at the start of the name. When that
4845 convention is not followed and ``${PN}`` appears at the middle or the
4846 end of a name, problems occur.
4847
4848- The :term:`TARGET_VENDOR`
4849 value under Multilib will be extended to "-vendormlmultilib" (e.g.
4850 "-pokymllib32" for a "lib32" Multilib with Poky). The reason for this
4851 slightly unwieldy contraction is that any "-" characters in the
4852 vendor string presently break Autoconf's ``config.sub``, and other
4853 separators are problematic for different reasons.
4854
William A. Kennington IIIac69b482021-06-02 12:28:27 -07004855Here are the implementation details for the RPM Package Management System:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004856
4857- A unique architecture is defined for the Multilib packages, along
4858 with creating a unique deploy folder under ``tmp/deploy/rpm`` in the
Patrick Williams2390b1b2022-11-03 13:47:49 -05004859 :term:`Build Directory`. For example, consider ``lib32`` in a
4860 ``qemux86-64`` image. The possible architectures in the system are "all",
4861 "qemux86_64", "lib32:qemux86_64", and "lib32:x86".
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004862
4863- The ``${MLPREFIX}`` variable is stripped from ``${PN}`` during RPM
4864 packaging. The naming for a normal RPM package and a Multilib RPM
4865 package in a ``qemux86-64`` system resolves to something similar to
4866 ``bash-4.1-r2.x86_64.rpm`` and ``bash-4.1.r2.lib32_x86.rpm``,
4867 respectively.
4868
4869- When installing a Multilib image, the RPM backend first installs the
4870 base image and then installs the Multilib libraries.
4871
4872- The build system relies on RPM to resolve the identical files in the
4873 two (or more) Multilib packages.
4874
William A. Kennington IIIac69b482021-06-02 12:28:27 -07004875Here are the implementation details for the IPK Package Management System:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004876
4877- The ``${MLPREFIX}`` is not stripped from ``${PN}`` during IPK
4878 packaging. The naming for a normal RPM package and a Multilib IPK
4879 package in a ``qemux86-64`` system resolves to something like
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004880 ``bash_4.1-r2.x86_64.ipk`` and ``lib32-bash_4.1-rw:x86.ipk``,
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004881 respectively.
4882
4883- The IPK deploy folder is not modified with ``${MLPREFIX}`` because
4884 packages with and without the Multilib feature can exist in the same
4885 folder due to the ``${PN}`` differences.
4886
4887- IPK defines a sanity check for Multilib installation using certain
4888 rules for file comparison, overridden, etc.
4889
4890Installing Multiple Versions of the Same Library
4891------------------------------------------------
4892
William A. Kennington IIIac69b482021-06-02 12:28:27 -07004893There are be situations where you need to install and use multiple versions
4894of the same library on the same system at the same time. This
4895almost always happens when a library API changes and you have
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004896multiple pieces of software that depend on the separate versions of the
4897library. To accommodate these situations, you can install multiple
4898versions of the same library in parallel on the same system.
4899
4900The process is straightforward as long as the libraries use proper
4901versioning. With properly versioned libraries, all you need to do to
4902individually specify the libraries is create separate, appropriately
4903named recipes where the :term:`PN` part of
4904the name includes a portion that differentiates each library version
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004905(e.g. the major part of the version number). Thus, instead of having a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004906single recipe that loads one version of a library (e.g. ``clutter``),
4907you provide multiple recipes that result in different versions of the
4908libraries you want. As an example, the following two recipes would allow
4909the two separate versions of the ``clutter`` library to co-exist on the
4910same system:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004911
4912.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004913
4914 clutter-1.6_1.6.20.bb
4915 clutter-1.8_1.8.4.bb
4916
4917Additionally, if
4918you have other recipes that depend on a given library, you need to use
4919the :term:`DEPENDS` variable to
4920create the dependency. Continuing with the same example, if you want to
4921have a recipe depend on the 1.8 version of the ``clutter`` library, use
Andrew Geisslerc926e172021-05-07 16:11:35 -05004922the following in your recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004923
4924 DEPENDS = "clutter-1.8"
4925
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00004926Working with Pre-Built Libraries
4927================================
4928
4929Introduction
4930-------------
4931
4932Some library vendors do not release source code for their software but do
4933release pre-built binaries. When shared libraries are built, they should
4934be versioned (see `this article
4935<https://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html>`__
4936for some background), but sometimes this is not done.
4937
4938To summarize, a versioned library must meet two conditions:
4939
4940#. The filename must have the version appended, for example: ``libfoo.so.1.2.3``.
4941#. The library must have the ELF tag ``SONAME`` set to the major version
4942 of the library, for example: ``libfoo.so.1``. You can check this by
4943 running ``readelf -d filename | grep SONAME``.
4944
4945This section shows how to deal with both versioned and unversioned
4946pre-built libraries.
4947
4948Versioned Libraries
4949-------------------
4950
4951In this example we work with pre-built libraries for the FT4222H USB I/O chip.
4952Libraries are built for several target architecture variants and packaged in
4953an archive as follows::
4954
4955 ├── build-arm-hisiv300
4956 │   └── libft4222.so.1.4.4.44
4957 ├── build-arm-v5-sf
4958 │   └── libft4222.so.1.4.4.44
4959 ├── build-arm-v6-hf
4960 │   └── libft4222.so.1.4.4.44
4961 ├── build-arm-v7-hf
4962 │   └── libft4222.so.1.4.4.44
4963 ├── build-arm-v8
4964 │   └── libft4222.so.1.4.4.44
4965 ├── build-i386
4966 │   └── libft4222.so.1.4.4.44
4967 ├── build-i486
4968 │   └── libft4222.so.1.4.4.44
4969 ├── build-mips-eglibc-hf
4970 │   └── libft4222.so.1.4.4.44
4971 ├── build-pentium
4972 │   └── libft4222.so.1.4.4.44
4973 ├── build-x86_64
4974 │   └── libft4222.so.1.4.4.44
4975 ├── examples
4976 │   ├── get-version.c
4977 │   ├── i2cm.c
4978 │   ├── spim.c
4979 │   └── spis.c
4980 ├── ftd2xx.h
4981 ├── install4222.sh
4982 ├── libft4222.h
4983 ├── ReadMe.txt
4984 └── WinTypes.h
4985
4986To write a recipe to use such a library in your system:
4987
4988- The vendor will probably have a proprietary licence, so set
4989 :term:`LICENSE_FLAGS` in your recipe.
4990- The vendor provides a tarball containing libraries so set :term:`SRC_URI`
4991 appropriately.
4992- Set :term:`COMPATIBLE_HOST` so that the recipe cannot be used with an
4993 unsupported architecture. In the following example, we only support the 32
4994 and 64 bit variants of the ``x86`` architecture.
4995- As the vendor provides versioned libraries, we can use ``oe_soinstall``
4996 from :ref:`ref-classes-utils` to install the shared library and create
4997 symbolic links. If the vendor does not do this, we need to follow the
4998 non-versioned library guidelines in the next section.
4999- As the vendor likely used :term:`LDFLAGS` different from those in your Yocto
5000 Project build, disable the corresponding checks by adding ``ldflags``
5001 to :term:`INSANE_SKIP`.
5002- The vendor will typically ship release builds without debugging symbols.
5003 Avoid errors by preventing the packaging task from stripping out the symbols
5004 and adding them to a separate debug package. This is done by setting the
5005 ``INHIBIT_`` flags shown below.
5006
5007The complete recipe would look like this::
5008
5009 SUMMARY = "FTDI FT4222H Library"
5010 SECTION = "libs"
5011 LICENSE_FLAGS = "ftdi"
5012 LICENSE = "CLOSED"
5013
5014 COMPATIBLE_HOST = "(i.86|x86_64).*-linux"
5015
5016 # Sources available in a .tgz file in .zip archive
5017 # at https://ftdichip.com/wp-content/uploads/2021/01/libft4222-linux-1.4.4.44.zip
5018 # Found on https://ftdichip.com/software-examples/ft4222h-software-examples/
5019 # Since dealing with this particular type of archive is out of topic here,
5020 # we use a local link.
5021 SRC_URI = "file://libft4222-linux-${PV}.tgz"
5022
5023 S = "${WORKDIR}"
5024
5025 ARCH_DIR:x86-64 = "build-x86_64"
5026 ARCH_DIR:i586 = "build-i386"
5027 ARCH_DIR:i686 = "build-i386"
5028
5029 INSANE_SKIP:${PN} = "ldflags"
5030 INHIBIT_PACKAGE_STRIP = "1"
5031 INHIBIT_SYSROOT_STRIP = "1"
5032 INHIBIT_PACKAGE_DEBUG_SPLIT = "1"
5033
5034 do_install () {
5035 install -m 0755 -d ${D}${libdir}
5036 oe_soinstall ${S}/${ARCH_DIR}/libft4222.so.${PV} ${D}${libdir}
5037 install -d ${D}${includedir}
5038 install -m 0755 ${S}/*.h ${D}${includedir}
5039 }
5040
5041If the precompiled binaries are not statically linked and have dependencies on
5042other libraries, then by adding those libraries to :term:`DEPENDS`, the linking
5043can be examined and the appropriate :term:`RDEPENDS` automatically added.
5044
5045Non-Versioned Libraries
5046-----------------------
5047
5048Some Background
5049~~~~~~~~~~~~~~~
5050
5051Libraries in Linux systems are generally versioned so that it is possible
5052to have multiple versions of the same library installed, which eases upgrades
5053and support for older software. For example, suppose that in a versioned
5054library, an actual library is called ``libfoo.so.1.2``, a symbolic link named
5055``libfoo.so.1`` points to ``libfoo.so.1.2``, and a symbolic link named
5056``libfoo.so`` points to ``libfoo.so.1.2``. Given these conditions, when you
5057link a binary against a library, you typically provide the unversioned file
5058name (i.e. ``-lfoo`` to the linker). However, the linker follows the symbolic
5059link and actually links against the versioned filename. The unversioned symbolic
5060link is only used at development time. Consequently, the library is packaged
5061along with the headers in the development package ``${PN}-dev`` along with the
5062actual library and versioned symbolic links in ``${PN}``. Because versioned
5063libraries are far more common than unversioned libraries, the default packaging
5064rules assume versioned libraries.
5065
5066Yocto Library Packaging Overview
5067~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5068
5069It follows that packaging an unversioned library requires a bit of work in the
5070recipe. By default, ``libfoo.so`` gets packaged into ``${PN}-dev``, which
5071triggers a QA warning that a non-symlink library is in a ``-dev`` package,
5072and binaries in the same recipe link to the library in ``${PN}-dev``,
5073which triggers more QA warnings. To solve this problem, you need to package the
5074unversioned library into ``${PN}`` where it belongs. The following are the abridged
5075default :term:`FILES` variables in ``bitbake.conf``::
5076
5077 SOLIBS = ".so.*"
5078 SOLIBSDEV = ".so"
5079 FILES_${PN} = "... ${libdir}/lib*${SOLIBS} ..."
5080 FILES_SOLIBSDEV ?= "... ${libdir}/lib*${SOLIBSDEV} ..."
5081 FILES_${PN}-dev = "... ${FILES_SOLIBSDEV} ..."
5082
5083:term:`SOLIBS` defines a pattern that matches real shared object libraries.
5084:term:`SOLIBSDEV` matches the development form (unversioned symlink). These two
5085variables are then used in ``FILES:${PN}`` and ``FILES:${PN}-dev``, which puts
5086the real libraries into ``${PN}`` and the unversioned symbolic link into ``${PN}-dev``.
5087To package unversioned libraries, you need to modify the variables in the recipe
5088as follows::
5089
5090 SOLIBS = ".so"
5091 FILES_SOLIBSDEV = ""
5092
5093The modifications cause the ``.so`` file to be the real library
5094and unset :term:`FILES_SOLIBSDEV` so that no libraries get packaged into
5095``${PN}-dev``. The changes are required because unless :term:`PACKAGES` is changed,
5096``${PN}-dev`` collects files before `${PN}`. ``${PN}-dev`` must not collect any of
5097the files you want in ``${PN}``.
5098
5099Finally, loadable modules, essentially unversioned libraries that are linked
5100at runtime using ``dlopen()`` instead of at build time, should generally be
5101installed in a private directory. However, if they are installed in ``${libdir}``,
5102then the modules can be treated as unversioned libraries.
5103
5104Example
5105~~~~~~~
5106
5107The example below installs an unversioned x86-64 pre-built library named
5108``libfoo.so``. The :term:`COMPATIBLE_HOST` variable limits recipes to the
5109x86-64 architecture while the :term:`INSANE_SKIP`, :term:`INHIBIT_PACKAGE_STRIP`
5110and :term:`INHIBIT_SYSROOT_STRIP` variables are all set as in the above
5111versioned library example. The "magic" is setting the :term:`SOLIBS` and
5112:term:`FILES_SOLIBSDEV` variables as explained above::
5113
5114 SUMMARY = "libfoo sample recipe"
5115 SECTION = "libs"
5116 LICENSE = "CLOSED"
5117
5118 SRC_URI = "file://libfoo.so"
5119
5120 COMPATIBLE_HOST = "x86_64.*-linux"
5121
5122 INSANE_SKIP:${PN} = "ldflags"
5123 INHIBIT_PACKAGE_STRIP = "1"
5124 INHIBIT_SYSROOT_STRIP = "1"
5125 SOLIBS = ".so"
5126 FILES_SOLIBSDEV = ""
5127
5128 do_install () {
5129 install -d ${D}${libdir}
5130 install -m 0755 ${WORKDIR}/libfoo.so ${D}${libdir}
5131 }
5132
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005133Using x32 psABI
5134===============
5135
5136x32 processor-specific Application Binary Interface (`x32
5137psABI <https://software.intel.com/en-us/node/628948>`__) is a native
513832-bit processor-specific ABI for Intel 64 (x86-64) architectures. An
5139ABI defines the calling conventions between functions in a processing
5140environment. The interface determines what registers are used and what
5141the sizes are for various C data types.
5142
5143Some processing environments prefer using 32-bit applications even when
5144running on Intel 64-bit platforms. Consider the i386 psABI, which is a
5145very old 32-bit ABI for Intel 64-bit platforms. The i386 psABI does not
5146provide efficient use and access of the Intel 64-bit processor
5147resources, leaving the system underutilized. Now consider the x86_64
5148psABI. This ABI is newer and uses 64-bits for data sizes and program
5149pointers. The extra bits increase the footprint size of the programs,
5150libraries, and also increases the memory and file system size
5151requirements. Executing under the x32 psABI enables user programs to
5152utilize CPU and system resources more efficiently while keeping the
5153memory footprint of the applications low. Extra bits are used for
5154registers but not for addressing mechanisms.
5155
5156The Yocto Project supports the final specifications of x32 psABI as
5157follows:
5158
5159- You can create packages and images in x32 psABI format on x86_64
5160 architecture targets.
5161
5162- You can successfully build recipes with the x32 toolchain.
5163
5164- You can create and boot ``core-image-minimal`` and
5165 ``core-image-sato`` images.
5166
William A. Kennington IIIac69b482021-06-02 12:28:27 -07005167- There is RPM Package Manager (RPM) support for x32 binaries.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005168
William A. Kennington IIIac69b482021-06-02 12:28:27 -07005169- There is support for large images.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005170
5171To use the x32 psABI, you need to edit your ``conf/local.conf``
Andrew Geisslerc926e172021-05-07 16:11:35 -05005172configuration file as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005173
5174 MACHINE = "qemux86-64"
5175 DEFAULTTUNE = "x86-64-x32"
Patrick Williams0ca19cc2021-08-16 14:03:13 -05005176 baselib = "${@d.getVar('BASE_LIB:tune-' + (d.getVar('DEFAULTTUNE') \
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005177 or 'INVALID')) or 'lib'}"
5178
5179Once you have set
5180up your configuration file, use BitBake to build an image that supports
Andrew Geisslerc926e172021-05-07 16:11:35 -05005181the x32 psABI. Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005182
5183 $ bitbake core-image-sato
5184
5185Enabling GObject Introspection Support
5186======================================
5187
Andrew Geissler595f6302022-01-24 19:11:47 +00005188`GObject introspection <https://gi.readthedocs.io/en/latest/>`__
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005189is the standard mechanism for accessing GObject-based software from
5190runtime environments. GObject is a feature of the GLib library that
5191provides an object framework for the GNOME desktop and related software.
5192GObject Introspection adds information to GObject that allows objects
5193created within it to be represented across different programming
5194languages. If you want to construct GStreamer pipelines using Python, or
5195control UPnP infrastructure using Javascript and GUPnP, GObject
5196introspection is the only way to do it.
5197
5198This section describes the Yocto Project support for generating and
5199packaging GObject introspection data. GObject introspection data is a
Andrew Geissler595f6302022-01-24 19:11:47 +00005200description of the API provided by libraries built on top of the GLib
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005201framework, and, in particular, that framework's GObject mechanism.
5202GObject Introspection Repository (GIR) files go to ``-dev`` packages,
5203``typelib`` files go to main packages as they are packaged together with
5204libraries that are introspected.
5205
5206The data is generated when building such a library, by linking the
5207library with a small executable binary that asks the library to describe
5208itself, and then executing the binary and processing its output.
5209
5210Generating this data in a cross-compilation environment is difficult
5211because the library is produced for the target architecture, but its
5212code needs to be executed on the build host. This problem is solved with
5213the OpenEmbedded build system by running the code through QEMU, which
5214allows precisely that. Unfortunately, QEMU does not always work
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05005215perfectly as mentioned in the ":ref:`dev-manual/common-tasks:known issues`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005216section.
5217
5218Enabling the Generation of Introspection Data
5219---------------------------------------------
5220
5221Enabling the generation of introspection data (GIR files) in your
5222library package involves the following:
5223
52241. Inherit the
5225 :ref:`gobject-introspection <ref-classes-gobject-introspection>`
5226 class.
5227
52282. Make sure introspection is not disabled anywhere in the recipe or
5229 from anything the recipe includes. Also, make sure that
5230 "gobject-introspection-data" is not in
5231 :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`
5232 and that "qemu-usermode" is not in
5233 :term:`MACHINE_FEATURES_BACKFILL_CONSIDERED`.
William A. Kennington IIIac69b482021-06-02 12:28:27 -07005234 In either of these conditions, nothing will happen.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005235
52363. Try to build the recipe. If you encounter build errors that look like
5237 something is unable to find ``.so`` libraries, check where these
5238 libraries are located in the source tree and add the following to the
Andrew Geisslerc926e172021-05-07 16:11:35 -05005239 recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005240
5241 GIR_EXTRA_LIBS_PATH = "${B}/something/.libs"
5242
5243 .. note::
5244
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005245 See recipes in the ``oe-core`` repository that use that
Andrew Geissler595f6302022-01-24 19:11:47 +00005246 :term:`GIR_EXTRA_LIBS_PATH` variable as an example.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005247
52484. Look for any other errors, which probably mean that introspection
5249 support in a package is not entirely standard, and thus breaks down
5250 in a cross-compilation environment. For such cases, custom-made fixes
5251 are needed. A good place to ask and receive help in these cases is
5252 the :ref:`Yocto Project mailing
5253 lists <resources-mailinglist>`.
5254
5255.. note::
5256
5257 Using a library that no longer builds against the latest Yocto
5258 Project release and prints introspection related errors is a good
5259 candidate for the previous procedure.
5260
5261Disabling the Generation of Introspection Data
5262----------------------------------------------
5263
5264You might find that you do not want to generate introspection data. Or,
5265perhaps QEMU does not work on your build host and target architecture
5266combination. If so, you can use either of the following methods to
5267disable GIR file generations:
5268
Andrew Geisslerc926e172021-05-07 16:11:35 -05005269- Add the following to your distro configuration::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005270
5271 DISTRO_FEATURES_BACKFILL_CONSIDERED = "gobject-introspection-data"
5272
5273 Adding this statement disables generating introspection data using
5274 QEMU but will still enable building introspection tools and libraries
5275 (i.e. building them does not require the use of QEMU).
5276
Andrew Geisslerc926e172021-05-07 16:11:35 -05005277- Add the following to your machine configuration::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005278
5279 MACHINE_FEATURES_BACKFILL_CONSIDERED = "qemu-usermode"
5280
5281 Adding this statement disables the use of QEMU when building packages for your
5282 machine. Currently, this feature is used only by introspection
5283 recipes and has the same effect as the previously described option.
5284
5285 .. note::
5286
5287 Future releases of the Yocto Project might have other features
5288 affected by this option.
5289
5290If you disable introspection data, you can still obtain it through other
5291means such as copying the data from a suitable sysroot, or by generating
5292it on the target hardware. The OpenEmbedded build system does not
5293currently provide specific support for these techniques.
5294
5295Testing that Introspection Works in an Image
5296--------------------------------------------
5297
5298Use the following procedure to test if generating introspection data is
5299working in an image:
5300
53011. Make sure that "gobject-introspection-data" is not in
5302 :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`
5303 and that "qemu-usermode" is not in
5304 :term:`MACHINE_FEATURES_BACKFILL_CONSIDERED`.
5305
53062. Build ``core-image-sato``.
5307
53083. Launch a Terminal and then start Python in the terminal.
5309
Andrew Geisslerc926e172021-05-07 16:11:35 -050053104. Enter the following in the terminal::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005311
5312 >>> from gi.repository import GLib
5313 >>> GLib.get_host_name()
5314
53155. For something a little more advanced, enter the following see:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005316 https://python-gtk-3-tutorial.readthedocs.io/en/latest/introduction.html
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005317
5318Known Issues
5319------------
5320
William A. Kennington IIIac69b482021-06-02 12:28:27 -07005321Here are know issues in GObject Introspection Support:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005322
5323- ``qemu-ppc64`` immediately crashes. Consequently, you cannot build
5324 introspection data on that architecture.
5325
5326- x32 is not supported by QEMU. Consequently, introspection data is
5327 disabled.
5328
5329- musl causes transient GLib binaries to crash on assertion failures.
5330 Consequently, generating introspection data is disabled.
5331
5332- Because QEMU is not able to run the binaries correctly, introspection
5333 is disabled for some specific packages under specific architectures
5334 (e.g. ``gcr``, ``libsecret``, and ``webkit``).
5335
5336- QEMU usermode might not work properly when running 64-bit binaries
5337 under 32-bit host machines. In particular, "qemumips64" is known to
5338 not work under i686.
5339
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005340Optionally Using an External Toolchain
5341======================================
5342
5343You might want to use an external toolchain as part of your development.
5344If this is the case, the fundamental steps you need to accomplish are as
5345follows:
5346
5347- Understand where the installed toolchain resides. For cases where you
5348 need to build the external toolchain, you would need to take separate
5349 steps to build and install the toolchain.
5350
5351- Make sure you add the layer that contains the toolchain to your
5352 ``bblayers.conf`` file through the
5353 :term:`BBLAYERS` variable.
5354
5355- Set the ``EXTERNAL_TOOLCHAIN`` variable in your ``local.conf`` file
5356 to the location in which you installed the toolchain.
5357
5358A good example of an external toolchain used with the Yocto Project is
5359Mentor Graphics Sourcery G++ Toolchain. You can see information on how
5360to use that particular layer in the ``README`` file at
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005361https://github.com/MentorEmbedded/meta-sourcery/. You can find
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005362further information by reading about the
5363:term:`TCMODE` variable in the Yocto
5364Project Reference Manual's variable glossary.
5365
5366Creating Partitioned Images Using Wic
5367=====================================
5368
5369Creating an image for a particular hardware target using the
5370OpenEmbedded build system does not necessarily mean you can boot that
5371image as is on your device. Physical devices accept and boot images in
5372various ways depending on the specifics of the device. Usually,
5373information about the hardware can tell you what image format the device
5374requires. Should your device require multiple partitions on an SD card,
5375flash, or an HDD, you can use the OpenEmbedded Image Creator, Wic, to
5376create the properly partitioned image.
5377
5378The ``wic`` command generates partitioned images from existing
5379OpenEmbedded build artifacts. Image generation is driven by partitioning
Andrew Geisslerd5838332022-05-27 11:33:10 -05005380commands contained in an OpenEmbedded kickstart file (``.wks``)
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005381specified either directly on the command line or as one of a selection
5382of canned kickstart files as shown with the ``wic list images`` command
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05005383in the
5384":ref:`dev-manual/common-tasks:generate an image using an existing kickstart file`"
5385section. When you apply the command to a given set of build artifacts, the
5386result is an image or set of images that can be directly written onto media and
5387used on a particular system.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005388
5389.. note::
5390
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005391 For a kickstart file reference, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06005392 ":ref:`ref-manual/kickstart:openembedded kickstart (\`\`.wks\`\`) reference`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005393 Chapter in the Yocto Project Reference Manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005394
5395The ``wic`` command and the infrastructure it is based on is by
5396definition incomplete. The purpose of the command is to allow the
5397generation of customized images, and as such, was designed to be
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05005398completely extensible through a plugin interface. See the
5399":ref:`dev-manual/common-tasks:using the wic plugin interface`" section
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005400for information on these plugins.
5401
5402This section provides some background information on Wic, describes what
5403you need to have in place to run the tool, provides instruction on how
5404to use the Wic utility, provides information on using the Wic plugins
5405interface, and provides several examples that show how to use Wic.
5406
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005407Background
5408----------
5409
5410This section provides some background on the Wic utility. While none of
5411this information is required to use Wic, you might find it interesting.
5412
5413- The name "Wic" is derived from OpenEmbedded Image Creator (oeic). The
5414 "oe" diphthong in "oeic" was promoted to the letter "w", because
5415 "oeic" is both difficult to remember and to pronounce.
5416
5417- Wic is loosely based on the Meego Image Creator (``mic``) framework.
5418 The Wic implementation has been heavily modified to make direct use
5419 of OpenEmbedded build artifacts instead of package installation and
5420 configuration, which are already incorporated within the OpenEmbedded
5421 artifacts.
5422
5423- Wic is a completely independent standalone utility that initially
5424 provides easier-to-use and more flexible replacements for an existing
5425 functionality in OE-Core's
5426 :ref:`image-live <ref-classes-image-live>`
5427 class. The difference between Wic and those examples is that with Wic
5428 the functionality of those scripts is implemented by a
5429 general-purpose partitioning language, which is based on Redhat
5430 kickstart syntax.
5431
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005432Requirements
5433------------
5434
5435In order to use the Wic utility with the OpenEmbedded Build system, your
5436system needs to meet the following requirements:
5437
5438- The Linux distribution on your development host must support the
5439 Yocto Project. See the ":ref:`detailed-supported-distros`"
5440 section in the Yocto Project Reference Manual for the list of
5441 distributions that support the Yocto Project.
5442
5443- The standard system utilities, such as ``cp``, must be installed on
5444 your development host system.
5445
5446- You must have sourced the build environment setup script (i.e.
Patrick Williams2390b1b2022-11-03 13:47:49 -05005447 :ref:`structure-core-script`) found in the :term:`Build Directory`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005448
5449- You need to have the build artifacts already available, which
5450 typically means that you must have already created an image using the
Andrew Geisslerd5838332022-05-27 11:33:10 -05005451 OpenEmbedded build system (e.g. ``core-image-minimal``). While it
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005452 might seem redundant to generate an image in order to create an image
5453 using Wic, the current version of Wic requires the artifacts in the
5454 form generated by the OpenEmbedded build system.
5455
5456- You must build several native tools, which are built to run on the
Andrew Geisslerc926e172021-05-07 16:11:35 -05005457 build system::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005458
5459 $ bitbake parted-native dosfstools-native mtools-native
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005460
5461- Include "wic" as part of the
5462 :term:`IMAGE_FSTYPES`
5463 variable.
5464
5465- Include the name of the :ref:`wic kickstart file <openembedded-kickstart-wks-reference>`
Andrew Geisslerd5838332022-05-27 11:33:10 -05005466 as part of the :term:`WKS_FILE` variable. If multiple candidate files can
5467 be provided by different layers, specify all the possible names through the
5468 :term:`WKS_FILES` variable instead.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005469
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005470Getting Help
5471------------
5472
5473You can get general help for the ``wic`` command by entering the ``wic``
5474command by itself or by entering the command with a help argument as
Andrew Geisslerc926e172021-05-07 16:11:35 -05005475follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005476
5477 $ wic -h
5478 $ wic --help
5479 $ wic help
5480
5481Currently, Wic supports seven commands: ``cp``, ``create``, ``help``,
5482``list``, ``ls``, ``rm``, and ``write``. You can get help for all these
Andrew Geisslerc926e172021-05-07 16:11:35 -05005483commands except "help" by using the following form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005484
5485 $ wic help command
5486
5487For example, the following command returns help for the ``write``
Andrew Geisslerc926e172021-05-07 16:11:35 -05005488command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005489
5490 $ wic help write
5491
5492Wic supports help for three topics: ``overview``, ``plugins``, and
Andrew Geisslerc926e172021-05-07 16:11:35 -05005493``kickstart``. You can get help for any topic using the following form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005494
5495 $ wic help topic
5496
Andrew Geisslerc926e172021-05-07 16:11:35 -05005497For example, the following returns overview help for Wic::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005498
5499 $ wic help overview
5500
William A. Kennington IIIac69b482021-06-02 12:28:27 -07005501There is one additional level of help for Wic. You can get help on
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005502individual images through the ``list`` command. You can use the ``list``
Andrew Geisslerc926e172021-05-07 16:11:35 -05005503command to return the available Wic images as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005504
5505 $ wic list images
5506 genericx86 Create an EFI disk image for genericx86*
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005507 edgerouter Create SD card image for Edgerouter
Andrew Geissler5199d832021-09-24 16:47:35 -05005508 beaglebone-yocto Create SD card image for Beaglebone
5509 qemux86-directdisk Create a qemu machine 'pcbios' direct disk image
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005510 systemd-bootdisk Create an EFI disk image with systemd-boot
5511 mkhybridiso Create a hybrid ISO image
Andrew Geissler5199d832021-09-24 16:47:35 -05005512 mkefidisk Create an EFI disk image
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005513 sdimage-bootpart Create SD card image with a boot partition
5514 directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
Andrew Geissler5199d832021-09-24 16:47:35 -05005515 directdisk Create a 'pcbios' direct disk image
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005516 directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
Andrew Geissler5199d832021-09-24 16:47:35 -05005517 qemuriscv Create qcow2 image for RISC-V QEMU machines
5518 directdisk-gpt Create a 'pcbios' direct disk image
5519 efi-bootdisk
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005520
5521Once you know the list of available
5522Wic images, you can use ``help`` with the command to get help on a
5523particular image. For example, the following command returns help on the
Andrew Geisslerc926e172021-05-07 16:11:35 -05005524"beaglebone-yocto" image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005525
5526 $ wic list beaglebone-yocto help
5527
5528 Creates a partitioned SD card image for Beaglebone.
5529 Boot files are located in the first vfat partition.
5530
5531Operational Modes
5532-----------------
5533
5534You can use Wic in two different modes, depending on how much control
Andrew Geisslerd5838332022-05-27 11:33:10 -05005535you need for specifying the OpenEmbedded build artifacts that are used
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005536for creating the image: Raw and Cooked:
5537
5538- *Raw Mode:* You explicitly specify build artifacts through Wic
5539 command-line arguments.
5540
5541- *Cooked Mode:* The current
5542 :term:`MACHINE` setting and image
5543 name are used to automatically locate and provide the build
5544 artifacts. You just supply a kickstart file and the name of the image
5545 from which to use artifacts.
5546
5547Regardless of the mode you use, you need to have the build artifacts
5548ready and available.
5549
5550Raw Mode
5551~~~~~~~~
5552
5553Running Wic in raw mode allows you to specify all the partitions through
5554the ``wic`` command line. The primary use for raw mode is if you have
Patrick Williams2390b1b2022-11-03 13:47:49 -05005555built your kernel outside of the Yocto Project :term:`Build Directory`.
5556In other words, you can point to arbitrary kernel, root filesystem locations,
5557and so forth. Contrast this behavior with cooked mode where Wic looks in the
5558:term:`Build Directory` (e.g. ``tmp/deploy/images/``\ machine).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005559
Andrew Geisslerc926e172021-05-07 16:11:35 -05005560The general form of the ``wic`` command in raw mode is::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005561
5562 $ wic create wks_file options ...
5563
5564 Where:
5565
5566 wks_file:
5567 An OpenEmbedded kickstart file. You can provide
5568 your own custom file or use a file from a set of
5569 existing files as described by further options.
5570
5571 optional arguments:
5572 -h, --help show this help message and exit
5573 -o OUTDIR, --outdir OUTDIR
5574 name of directory to create image in
5575 -e IMAGE_NAME, --image-name IMAGE_NAME
5576 name of the image to use the artifacts from e.g. core-
5577 image-sato
5578 -r ROOTFS_DIR, --rootfs-dir ROOTFS_DIR
5579 path to the /rootfs dir to use as the .wks rootfs
5580 source
5581 -b BOOTIMG_DIR, --bootimg-dir BOOTIMG_DIR
5582 path to the dir containing the boot artifacts (e.g.
5583 /EFI or /syslinux dirs) to use as the .wks bootimg
5584 source
5585 -k KERNEL_DIR, --kernel-dir KERNEL_DIR
5586 path to the dir containing the kernel to use in the
5587 .wks bootimg
5588 -n NATIVE_SYSROOT, --native-sysroot NATIVE_SYSROOT
5589 path to the native sysroot containing the tools to use
5590 to build the image
5591 -s, --skip-build-check
5592 skip the build check
5593 -f, --build-rootfs build rootfs
5594 -c {gzip,bzip2,xz}, --compress-with {gzip,bzip2,xz}
5595 compress image with specified compressor
5596 -m, --bmap generate .bmap
5597 --no-fstab-update Do not change fstab file.
5598 -v VARS_DIR, --vars VARS_DIR
5599 directory with <image>.env files that store bitbake
5600 variables
5601 -D, --debug output debug information
5602
5603.. note::
5604
5605 You do not need root privileges to run Wic. In fact, you should not
5606 run as root when using the utility.
5607
5608Cooked Mode
5609~~~~~~~~~~~
5610
Patrick Williams2390b1b2022-11-03 13:47:49 -05005611Running Wic in cooked mode leverages off artifacts in the
5612:term:`Build Directory`. In other words, you do not have to specify kernel or
5613root filesystem locations as part of the command. All you need to provide is
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005614a kickstart file and the name of the image from which to use artifacts
Patrick Williams2390b1b2022-11-03 13:47:49 -05005615by using the "-e" option. Wic looks in the :term:`Build Directory` (e.g.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005616``tmp/deploy/images/``\ machine) for artifacts.
5617
Andrew Geisslerc926e172021-05-07 16:11:35 -05005618The general form of the ``wic`` command using Cooked Mode is as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005619
5620 $ wic create wks_file -e IMAGE_NAME
5621
5622 Where:
5623
5624 wks_file:
5625 An OpenEmbedded kickstart file. You can provide
5626 your own custom file or use a file from a set of
5627 existing files provided with the Yocto Project
5628 release.
5629
5630 required argument:
5631 -e IMAGE_NAME, --image-name IMAGE_NAME
5632 name of the image to use the artifacts from e.g. core-
5633 image-sato
5634
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005635Using an Existing Kickstart File
5636--------------------------------
5637
5638If you do not want to create your own kickstart file, you can use an
5639existing file provided by the Wic installation. As shipped, kickstart
Andrew Geissler09209ee2020-12-13 08:44:15 -06005640files can be found in the :ref:`overview-manual/development-environment:yocto project source repositories` in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05005641following two locations::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005642
5643 poky/meta-yocto-bsp/wic
5644 poky/scripts/lib/wic/canned-wks
5645
Andrew Geisslerc926e172021-05-07 16:11:35 -05005646Use the following command to list the available kickstart files::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005647
5648 $ wic list images
5649 genericx86 Create an EFI disk image for genericx86*
5650 beaglebone-yocto Create SD card image for Beaglebone
5651 edgerouter Create SD card image for Edgerouter
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05005652 qemux86-directdisk Create a QEMU machine 'pcbios' direct disk image
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005653 directdisk-gpt Create a 'pcbios' direct disk image
5654 mkefidisk Create an EFI disk image
5655 directdisk Create a 'pcbios' direct disk image
5656 systemd-bootdisk Create an EFI disk image with systemd-boot
5657 mkhybridiso Create a hybrid ISO image
5658 sdimage-bootpart Create SD card image with a boot partition
5659 directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
5660 directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
5661
5662When you use an existing file, you
5663do not have to use the ``.wks`` extension. Here is an example in Raw
Andrew Geisslerc926e172021-05-07 16:11:35 -05005664Mode that uses the ``directdisk`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005665
5666 $ wic create directdisk -r rootfs_dir -b bootimg_dir \
5667 -k kernel_dir -n native_sysroot
5668
5669Here are the actual partition language commands used in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05005670``genericx86.wks`` file to generate an image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005671
5672 # short-description: Create an EFI disk image for genericx86*
5673 # long-description: Creates a partitioned EFI disk image for genericx86* machines
5674 part /boot --source bootimg-efi --sourceparams="loader=grub-efi" --ondisk sda --label msdos --active --align 1024
5675 part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid
5676 part swap --ondisk sda --size 44 --label swap1 --fstype=swap
5677
5678 bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=ttyS0,115200 console=tty0"
5679
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005680Using the Wic Plugin Interface
5681------------------------------
5682
5683You can extend and specialize Wic functionality by using Wic plugins.
5684This section explains the Wic plugin interface.
5685
5686.. note::
5687
5688 Wic plugins consist of "source" and "imager" plugins. Imager plugins
5689 are beyond the scope of this section.
5690
5691Source plugins provide a mechanism to customize partition content during
5692the Wic image generation process. You can use source plugins to map
5693values that you specify using ``--source`` commands in kickstart files
5694(i.e. ``*.wks``) to a plugin implementation used to populate a given
5695partition.
5696
5697.. note::
5698
5699 If you use plugins that have build-time dependencies (e.g. native
5700 tools, bootloaders, and so forth) when building a Wic image, you need
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005701 to specify those dependencies using the :term:`WKS_FILE_DEPENDS`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005702 variable.
5703
5704Source plugins are subclasses defined in plugin files. As shipped, the
5705Yocto Project provides several plugin files. You can see the source
5706plugin files that ship with the Yocto Project
Andrew Geissler09209ee2020-12-13 08:44:15 -06005707:yocto_git:`here </poky/tree/scripts/lib/wic/plugins/source>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005708Each of these plugin files contains source plugins that are designed to
5709populate a specific Wic image partition.
5710
5711Source plugins are subclasses of the ``SourcePlugin`` class, which is
5712defined in the ``poky/scripts/lib/wic/pluginbase.py`` file. For example,
5713the ``BootimgEFIPlugin`` source plugin found in the ``bootimg-efi.py``
5714file is a subclass of the ``SourcePlugin`` class, which is found in the
5715``pluginbase.py`` file.
5716
5717You can also implement source plugins in a layer outside of the Source
5718Repositories (external layer). To do so, be sure that your plugin files
5719are located in a directory whose path is
5720``scripts/lib/wic/plugins/source/`` within your external layer. When the
5721plugin files are located there, the source plugins they contain are made
5722available to Wic.
5723
5724When the Wic implementation needs to invoke a partition-specific
5725implementation, it looks for the plugin with the same name as the
5726``--source`` parameter used in the kickstart file given to that
5727partition. For example, if the partition is set up using the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05005728command in a kickstart file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005729
5730 part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024
5731
5732The methods defined as class
5733members of the matching source plugin (i.e. ``bootimg-pcbios``) in the
5734``bootimg-pcbios.py`` plugin file are used.
5735
5736To be more concrete, here is the corresponding plugin definition from
5737the ``bootimg-pcbios.py`` file for the previous command along with an
5738example method called by the Wic implementation when it needs to prepare
Andrew Geisslerc926e172021-05-07 16:11:35 -05005739a partition using an implementation-specific function::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005740
5741 .
5742 .
5743 .
5744 class BootimgPcbiosPlugin(SourcePlugin):
5745 """
5746 Create MBR boot partition and install syslinux on it.
5747 """
5748
5749 name = 'bootimg-pcbios'
5750 .
5751 .
5752 .
5753 @classmethod
5754 def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
5755 oe_builddir, bootimg_dir, kernel_dir,
5756 rootfs_dir, native_sysroot):
5757 """
5758 Called to do the actual content population for a partition i.e. it
5759 'prepares' the partition to be incorporated into the image.
5760 In this case, prepare content for legacy bios boot partition.
5761 """
5762 .
5763 .
5764 .
5765
5766If a
5767subclass (plugin) itself does not implement a particular function, Wic
5768locates and uses the default version in the superclass. It is for this
5769reason that all source plugins are derived from the ``SourcePlugin``
5770class.
5771
5772The ``SourcePlugin`` class defined in the ``pluginbase.py`` file defines
5773a set of methods that source plugins can implement or override. Any
5774plugins (subclass of ``SourcePlugin``) that do not implement a
5775particular method inherit the implementation of the method from the
5776``SourcePlugin`` class. For more information, see the ``SourcePlugin``
5777class in the ``pluginbase.py`` file for details:
5778
5779The following list describes the methods implemented in the
5780``SourcePlugin`` class:
5781
5782- ``do_prepare_partition()``: Called to populate a partition with
5783 actual content. In other words, the method prepares the final
5784 partition image that is incorporated into the disk image.
5785
5786- ``do_configure_partition()``: Called before
5787 ``do_prepare_partition()`` to create custom configuration files for a
5788 partition (e.g. syslinux or grub configuration files).
5789
5790- ``do_install_disk()``: Called after all partitions have been
5791 prepared and assembled into a disk image. This method provides a hook
5792 to allow finalization of a disk image (e.g. writing an MBR).
5793
5794- ``do_stage_partition()``: Special content-staging hook called
5795 before ``do_prepare_partition()``. This method is normally empty.
5796
5797 Typically, a partition just uses the passed-in parameters (e.g. the
5798 unmodified value of ``bootimg_dir``). However, in some cases, things
5799 might need to be more tailored. As an example, certain files might
5800 additionally need to be taken from ``bootimg_dir + /boot``. This hook
5801 allows those files to be staged in a customized fashion.
5802
5803 .. note::
5804
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005805 ``get_bitbake_var()`` allows you to access non-standard variables that
5806 you might want to use for this behavior.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005807
5808You can extend the source plugin mechanism. To add more hooks, create
5809more source plugin methods within ``SourcePlugin`` and the corresponding
5810derived subclasses. The code that calls the plugin methods uses the
5811``plugin.get_source_plugin_methods()`` function to find the method or
5812methods needed by the call. Retrieval of those methods is accomplished
5813by filling up a dict with keys that contain the method names of
5814interest. On success, these will be filled in with the actual methods.
5815See the Wic implementation for examples and details.
5816
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005817Wic Examples
5818------------
5819
5820This section provides several examples that show how to use the Wic
5821utility. All the examples assume the list of requirements in the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05005822":ref:`dev-manual/common-tasks:requirements`" section have been met. The
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005823examples assume the previously generated image is
5824``core-image-minimal``.
5825
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005826Generate an Image using an Existing Kickstart File
5827~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5828
5829This example runs in Cooked Mode and uses the ``mkefidisk`` kickstart
Andrew Geisslerc926e172021-05-07 16:11:35 -05005830file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005831
5832 $ wic create mkefidisk -e core-image-minimal
5833 INFO: Building wic-tools...
5834 .
5835 .
5836 .
5837 INFO: The new image(s) can be found here:
5838 ./mkefidisk-201804191017-sda.direct
5839
5840 The following build artifacts were used to create the image(s):
Andrew Geissler595f6302022-01-24 19:11:47 +00005841 ROOTFS_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
5842 BOOTIMG_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
5843 KERNEL_DIR: /home/stephano/yocto/build/tmp-glibc/deploy/images/qemux86
5844 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 -05005845
5846 INFO: The image(s) were created using OE kickstart file:
Andrew Geissler595f6302022-01-24 19:11:47 +00005847 /home/stephano/yocto/openembedded-core/scripts/lib/wic/canned-wks/mkefidisk.wks
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005848
5849The previous example shows the easiest way to create an image by running
5850in cooked mode and supplying a kickstart file and the "-e" option to
5851point to the existing build artifacts. Your ``local.conf`` file needs to
5852have the :term:`MACHINE` variable set
5853to the machine you are using, which is "qemux86" in this example.
5854
5855Once the image builds, the output provides image location, artifact use,
5856and kickstart file information.
5857
5858.. note::
5859
5860 You should always verify the details provided in the output to make
5861 sure that the image was indeed created exactly as expected.
5862
Patrick Williams2390b1b2022-11-03 13:47:49 -05005863Continuing with the example, you can now write the image from the
5864:term:`Build Directory` onto a USB stick, or whatever media for which you
5865built your image, and boot from the media. You can write the image by using
Andrew Geisslerc926e172021-05-07 16:11:35 -05005866``bmaptool`` or ``dd``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005867
Andrew Geisslerd5838332022-05-27 11:33:10 -05005868 $ oe-run-native bmap-tools-native bmaptool copy mkefidisk-201804191017-sda.direct /dev/sdX
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005869
5870or ::
5871
5872 $ sudo dd if=mkefidisk-201804191017-sda.direct of=/dev/sdX
5873
5874.. note::
5875
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005876 For more information on how to use the ``bmaptool``
5877 to flash a device with an image, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06005878 ":ref:`dev-manual/common-tasks:flashing images using \`\`bmaptool\`\``"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005879 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005880
5881Using a Modified Kickstart File
5882~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5883
5884Because partitioned image creation is driven by the kickstart file, it
5885is easy to affect image creation by changing the parameters in the file.
5886This next example demonstrates that through modification of the
5887``directdisk-gpt`` kickstart file.
5888
5889As mentioned earlier, you can use the command ``wic list images`` to
5890show the list of existing kickstart files. The directory in which the
5891``directdisk-gpt.wks`` file resides is
5892``scripts/lib/image/canned-wks/``, which is located in the
5893:term:`Source Directory` (e.g. ``poky``).
5894Because available files reside in this directory, you can create and add
5895your own custom files to the directory. Subsequent use of the
5896``wic list images`` command would then include your kickstart files.
5897
5898In this example, the existing ``directdisk-gpt`` file already does most
5899of what is needed. However, for the hardware in this example, the image
5900will need to boot from ``sdb`` instead of ``sda``, which is what the
5901``directdisk-gpt`` kickstart file uses.
5902
5903The example begins by making a copy of the ``directdisk-gpt.wks`` file
5904in the ``scripts/lib/image/canned-wks`` directory and then by changing
5905the lines that specify the target disk from which to boot.
5906::
5907
Andrew Geissler595f6302022-01-24 19:11:47 +00005908 $ cp /home/stephano/yocto/poky/scripts/lib/wic/canned-wks/directdisk-gpt.wks \
5909 /home/stephano/yocto/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005910
5911Next, the example modifies the ``directdisksdb-gpt.wks`` file and
5912changes all instances of "``--ondisk sda``" to "``--ondisk sdb``". The
5913example changes the following two lines and leaves the remaining lines
Andrew Geisslerc926e172021-05-07 16:11:35 -05005914untouched::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005915
5916 part /boot --source bootimg-pcbios --ondisk sdb --label boot --active --align 1024
5917 part / --source rootfs --ondisk sdb --fstype=ext4 --label platform --align 1024 --use-uuid
5918
5919Once the lines are changed, the
5920example generates the ``directdisksdb-gpt`` image. The command points
5921the process at the ``core-image-minimal`` artifacts for the Next Unit of
5922Computing (nuc) :term:`MACHINE` the
5923``local.conf``.
5924::
5925
5926 $ wic create directdisksdb-gpt -e core-image-minimal
5927 INFO: Building wic-tools...
5928 .
5929 .
5930 .
5931 Initialising tasks: 100% |#######################################| Time: 0:00:01
5932 NOTE: Executing SetScene Tasks
5933 NOTE: Executing RunQueue Tasks
5934 NOTE: Tasks Summary: Attempted 1161 tasks of which 1157 didn't need to be rerun and all succeeded.
5935 INFO: Creating image(s)...
5936
5937 INFO: The new image(s) can be found here:
5938 ./directdisksdb-gpt-201710090938-sdb.direct
5939
5940 The following build artifacts were used to create the image(s):
Andrew Geissler595f6302022-01-24 19:11:47 +00005941 ROOTFS_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
5942 BOOTIMG_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
5943 KERNEL_DIR: /home/stephano/yocto/build/tmp-glibc/deploy/images/qemux86
5944 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 -05005945
5946 INFO: The image(s) were created using OE kickstart file:
Andrew Geissler595f6302022-01-24 19:11:47 +00005947 /home/stephano/yocto/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005948
5949Continuing with the example, you can now directly ``dd`` the image to a
5950USB stick, or whatever media for which you built your image, and boot
Andrew Geisslerc926e172021-05-07 16:11:35 -05005951the resulting media::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005952
5953 $ sudo dd if=directdisksdb-gpt-201710090938-sdb.direct of=/dev/sdb
5954 140966+0 records in
5955 140966+0 records out
5956 72174592 bytes (72 MB, 69 MiB) copied, 78.0282 s, 925 kB/s
5957 $ sudo eject /dev/sdb
5958
5959Using a Modified Kickstart File and Running in Raw Mode
5960~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5961
5962This next example manually specifies each build artifact (runs in Raw
5963Mode) and uses a modified kickstart file. The example also uses the
5964``-o`` option to cause Wic to create the output somewhere other than the
Andrew Geisslerc926e172021-05-07 16:11:35 -05005965default output directory, which is the current directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005966
Andrew Geissler595f6302022-01-24 19:11:47 +00005967 $ wic create test.wks -o /home/stephano/testwic \
5968 --rootfs-dir /home/stephano/yocto/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/rootfs \
5969 --bootimg-dir /home/stephano/yocto/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share \
5970 --kernel-dir /home/stephano/yocto/build/tmp/deploy/images/qemux86 \
5971 --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 -05005972
5973 INFO: Creating image(s)...
5974
5975 INFO: The new image(s) can be found here:
5976 /home/stephano/testwic/test-201710091445-sdb.direct
5977
5978 The following build artifacts were used to create the image(s):
Andrew Geissler595f6302022-01-24 19:11:47 +00005979 ROOTFS_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
5980 BOOTIMG_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
5981 KERNEL_DIR: /home/stephano/yocto/build/tmp-glibc/deploy/images/qemux86
5982 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 -05005983
5984 INFO: The image(s) were created using OE kickstart file:
Andrew Geissler595f6302022-01-24 19:11:47 +00005985 test.wks
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005986
5987For this example,
5988:term:`MACHINE` did not have to be
5989specified in the ``local.conf`` file since the artifact is manually
5990specified.
5991
5992Using Wic to Manipulate an Image
5993~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5994
5995Wic image manipulation allows you to shorten turnaround time during
5996image development. For example, you can use Wic to delete the kernel
5997partition of a Wic image and then insert a newly built kernel. This
5998saves you time from having to rebuild the entire image each time you
5999modify the kernel.
6000
6001.. note::
6002
6003 In order to use Wic to manipulate a Wic image as in this example,
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006004 your development machine must have the ``mtools`` package installed.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006005
6006The following example examines the contents of the Wic image, deletes
6007the existing kernel, and then inserts a new kernel:
6008
60091. *List the Partitions:* Use the ``wic ls`` command to list all the
Andrew Geisslerc926e172021-05-07 16:11:35 -05006010 partitions in the Wic image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006011
6012 $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic
6013 Num Start End Size Fstype
6014 1 1048576 25041919 23993344 fat16
6015 2 25165824 72157183 46991360 ext4
6016
6017 The previous output shows two partitions in the
6018 ``core-image-minimal-qemux86.wic`` image.
6019
60202. *Examine a Particular Partition:* Use the ``wic ls`` command again
6021 but in a different form to examine a particular partition.
6022
6023 .. note::
6024
6025 You can get command usage on any Wic command using the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05006026 form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006027
6028 $ wic help command
6029
6030
6031 For example, the following command shows you the various ways to
6032 use the
6033 wic ls
Andrew Geisslerc926e172021-05-07 16:11:35 -05006034 command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006035
6036 $ wic help ls
6037
6038
Andrew Geisslerc926e172021-05-07 16:11:35 -05006039 The following command shows what is in partition one::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006040
6041 $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1
6042 Volume in drive : is boot
6043 Volume Serial Number is E894-1809
6044 Directory for ::/
6045
6046 libcom32 c32 186500 2017-10-09 16:06
6047 libutil c32 24148 2017-10-09 16:06
6048 syslinux cfg 220 2017-10-09 16:06
6049 vesamenu c32 27104 2017-10-09 16:06
6050 vmlinuz 6904608 2017-10-09 16:06
6051 5 files 7 142 580 bytes
6052 16 582 656 bytes free
6053
6054 The previous output shows five files, with the
6055 ``vmlinuz`` being the kernel.
6056
6057 .. note::
6058
6059 If you see the following error, you need to update or create a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006060 ``~/.mtoolsrc`` file and be sure to have the line "mtools_skip_check=1"
Andrew Geisslerc926e172021-05-07 16:11:35 -05006061 in the file. Then, run the Wic command again::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006062
6063 ERROR: _exec_cmd: /usr/bin/mdir -i /tmp/wic-parttfokuwra ::/ returned '1' instead of 0
6064 output: Total number of sectors (47824) not a multiple of sectors per track (32)!
6065 Add mtools_skip_check=1 to your .mtoolsrc file to skip this test
6066
6067
60683. *Remove the Old Kernel:* Use the ``wic rm`` command to remove the
Andrew Geisslerc926e172021-05-07 16:11:35 -05006069 ``vmlinuz`` file (kernel)::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006070
6071 $ wic rm tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
6072
60734. *Add In the New Kernel:* Use the ``wic cp`` command to add the
6074 updated kernel to the Wic image. Depending on how you built your
6075 kernel, it could be in different places. If you used ``devtool`` and
6076 an SDK to build your kernel, it resides in the ``tmp/work`` directory
6077 of the extensible SDK. If you used ``make`` to build the kernel, the
6078 kernel will be in the ``workspace/sources`` area.
6079
6080 The following example assumes ``devtool`` was used to build the
Andrew Geisslerc926e172021-05-07 16:11:35 -05006081 kernel::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006082
Andrew Geissler95ac1b82021-03-31 14:34:31 -05006083 $ 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 \
6084 poky/build/tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006085
6086 Once the new kernel is added back into the image, you can use the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006087 ``dd`` command or :ref:`bmaptool
Andrew Geissler09209ee2020-12-13 08:44:15 -06006088 <dev-manual/common-tasks:flashing images using \`\`bmaptool\`\`>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006089 to flash your wic image onto an SD card or USB stick and test your
6090 target.
6091
6092 .. note::
6093
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006094 Using ``bmaptool`` is generally 10 to 20 times faster than using ``dd``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006095
6096Flashing Images Using ``bmaptool``
6097==================================
6098
6099A fast and easy way to flash an image to a bootable device is to use
6100Bmaptool, which is integrated into the OpenEmbedded build system.
6101Bmaptool is a generic tool that creates a file's block map (bmap) and
6102then uses that map to copy the file. As compared to traditional tools
6103such as dd or cp, Bmaptool can copy (or flash) large files like raw
6104system image files much faster.
6105
6106.. note::
6107
6108 - If you are using Ubuntu or Debian distributions, you can install
6109 the ``bmap-tools`` package using the following command and then
6110 use the tool without specifying ``PATH`` even from the root
Andrew Geisslerc926e172021-05-07 16:11:35 -05006111 account::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006112
Andrew Geisslereff27472021-10-29 15:35:00 -05006113 $ sudo apt install bmap-tools
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006114
6115 - If you are unable to install the ``bmap-tools`` package, you will
Andrew Geisslerc926e172021-05-07 16:11:35 -05006116 need to build Bmaptool before using it. Use the following command::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006117
6118 $ bitbake bmap-tools-native
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006119
6120Following, is an example that shows how to flash a Wic image. Realize
6121that while this example uses a Wic image, you can use Bmaptool to flash
6122any type of image. Use these steps to flash an image using Bmaptool:
6123
61241. *Update your local.conf File:* You need to have the following set
Andrew Geisslerc926e172021-05-07 16:11:35 -05006125 in your ``local.conf`` file before building your image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006126
6127 IMAGE_FSTYPES += "wic wic.bmap"
6128
61292. *Get Your Image:* Either have your image ready (pre-built with the
6130 :term:`IMAGE_FSTYPES`
Andrew Geisslerc926e172021-05-07 16:11:35 -05006131 setting previously mentioned) or take the step to build the image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006132
6133 $ bitbake image
6134
61353. *Flash the Device:* Flash the device with the image by using Bmaptool
6136 depending on your particular setup. The following commands assume the
Patrick Williams2390b1b2022-11-03 13:47:49 -05006137 image resides in the :term:`Build Directory`'s ``deploy/images/`` area:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006138
Andrew Geisslerc926e172021-05-07 16:11:35 -05006139 - If you have write access to the media, use this command form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006140
6141 $ oe-run-native bmap-tools-native bmaptool copy build-directory/tmp/deploy/images/machine/image.wic /dev/sdX
6142
6143 - If you do not have write access to the media, set your permissions
Andrew Geisslerc926e172021-05-07 16:11:35 -05006144 first and then use the same command form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006145
6146 $ sudo chmod 666 /dev/sdX
6147 $ oe-run-native bmap-tools-native bmaptool copy build-directory/tmp/deploy/images/machine/image.wic /dev/sdX
6148
Andrew Geisslerc926e172021-05-07 16:11:35 -05006149For help on the ``bmaptool`` command, use the following command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006150
6151 $ bmaptool --help
6152
6153Making Images More Secure
6154=========================
6155
6156Security is of increasing concern for embedded devices. Consider the
6157issues and problems discussed in just this sampling of work found across
6158the Internet:
6159
6160- *"*\ `Security Risks of Embedded
6161 Systems <https://www.schneier.com/blog/archives/2014/01/security_risks_9.html>`__\ *"*
6162 by Bruce Schneier
6163
6164- *"*\ `Internet Census
6165 2012 <http://census2012.sourceforge.net/paper.html>`__\ *"* by Carna
6166 Botnet
6167
6168- *"*\ `Security Issues for Embedded
Andrew Geisslerd1e89492021-02-12 15:35:20 -06006169 Devices <https://elinux.org/images/6/6f/Security-issues.pdf>`__\ *"*
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006170 by Jake Edge
6171
6172When securing your image is of concern, there are steps, tools, and
6173variables that you can consider to help you reach the security goals you
6174need for your particular device. Not all situations are identical when
6175it comes to making an image secure. Consequently, this section provides
6176some guidance and suggestions for consideration when you want to make
6177your image more secure.
6178
6179.. note::
6180
6181 Because the security requirements and risks are different for every
6182 type of device, this section cannot provide a complete reference on
6183 securing your custom OS. It is strongly recommended that you also
6184 consult other sources of information on embedded Linux system
6185 hardening and on security.
6186
6187General Considerations
6188----------------------
6189
William A. Kennington IIIac69b482021-06-02 12:28:27 -07006190There are general considerations that help you create more secure images.
6191You should consider the following suggestions to make your device
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006192more secure:
6193
6194- Scan additional code you are adding to the system (e.g. application
6195 code) by using static analysis tools. Look for buffer overflows and
6196 other potential security problems.
6197
6198- Pay particular attention to the security for any web-based
6199 administration interface.
6200
6201 Web interfaces typically need to perform administrative functions and
6202 tend to need to run with elevated privileges. Thus, the consequences
6203 resulting from the interface's security becoming compromised can be
6204 serious. Look for common web vulnerabilities such as
6205 cross-site-scripting (XSS), unvalidated inputs, and so forth.
6206
6207 As with system passwords, the default credentials for accessing a
6208 web-based interface should not be the same across all devices. This
6209 is particularly true if the interface is enabled by default as it can
6210 be assumed that many end-users will not change the credentials.
6211
6212- Ensure you can update the software on the device to mitigate
6213 vulnerabilities discovered in the future. This consideration
6214 especially applies when your device is network-enabled.
6215
Patrick Williams2390b1b2022-11-03 13:47:49 -05006216- Regularly scan and apply fixes for CVE security issues affecting
6217 all software components in the product, see ":ref:`dev-manual/common-tasks:checking for vulnerabilities`".
6218
6219- Regularly update your version of Poky and OE-Core from their upstream
6220 developers, e.g. to apply updates and security fixes from stable
6221 and LTS branches.
6222
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006223- Ensure you remove or disable debugging functionality before producing
6224 the final image. For information on how to do this, see the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006225 ":ref:`dev-manual/common-tasks:considerations specific to the openembedded build system`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006226 section.
6227
6228- Ensure you have no network services listening that are not needed.
6229
6230- Remove any software from the image that is not needed.
6231
6232- Enable hardware support for secure boot functionality when your
6233 device supports this functionality.
6234
6235Security Flags
6236--------------
6237
6238The Yocto Project has security flags that you can enable that help make
6239your build output more secure. The security flags are in the
6240``meta/conf/distro/include/security_flags.inc`` file in your
6241:term:`Source Directory` (e.g. ``poky``).
6242
6243.. note::
6244
6245 Depending on the recipe, certain security flags are enabled and
6246 disabled by default.
6247
6248Use the following line in your ``local.conf`` file or in your custom
6249distribution configuration file to enable the security compiler and
Andrew Geisslerc926e172021-05-07 16:11:35 -05006250linker flags for your build::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006251
6252 require conf/distro/include/security_flags.inc
6253
6254Considerations Specific to the OpenEmbedded Build System
6255--------------------------------------------------------
6256
6257You can take some steps that are specific to the OpenEmbedded build
6258system to make your images more secure:
6259
6260- Ensure "debug-tweaks" is not one of your selected
6261 :term:`IMAGE_FEATURES`.
6262 When creating a new project, the default is to provide you with an
6263 initial ``local.conf`` file that enables this feature using the
6264 :term:`EXTRA_IMAGE_FEATURES`
Andrew Geisslerc926e172021-05-07 16:11:35 -05006265 variable with the line::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006266
6267 EXTRA_IMAGE_FEATURES = "debug-tweaks"
6268
6269 To disable that feature, simply comment out that line in your
Andrew Geissler09036742021-06-25 14:25:14 -05006270 ``local.conf`` file, or make sure :term:`IMAGE_FEATURES` does not contain
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006271 "debug-tweaks" before producing your final image. Among other things,
6272 leaving this in place sets the root password as blank, which makes
6273 logging in for debugging or inspection easy during development but
6274 also means anyone can easily log in during production.
6275
6276- It is possible to set a root password for the image and also to set
6277 passwords for any extra users you might add (e.g. administrative or
6278 service type users). When you set up passwords for multiple images or
6279 users, you should not duplicate passwords.
6280
6281 To set up passwords, use the
6282 :ref:`extrausers <ref-classes-extrausers>`
6283 class, which is the preferred method. For an example on how to set up
6284 both root and user passwords, see the
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00006285 ":ref:`ref-classes-extrausers`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006286
6287 .. note::
6288
6289 When adding extra user accounts or setting a root password, be
6290 cautious about setting the same password on every device. If you
6291 do this, and the password you have set is exposed, then every
6292 device is now potentially compromised. If you need this access but
6293 want to ensure security, consider setting a different, random
6294 password for each device. Typically, you do this as a separate
6295 step after you deploy the image onto the device.
6296
6297- Consider enabling a Mandatory Access Control (MAC) framework such as
6298 SMACK or SELinux and tuning it appropriately for your device's usage.
6299 You can find more information in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06006300 :yocto_git:`meta-selinux </meta-selinux/>` layer.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006301
6302Tools for Hardening Your Image
6303------------------------------
6304
6305The Yocto Project provides tools for making your image more secure. You
6306can find these tools in the ``meta-security`` layer of the
6307:yocto_git:`Yocto Project Source Repositories <>`.
6308
6309Creating Your Own Distribution
6310==============================
6311
6312When you build an image using the Yocto Project and do not alter any
6313distribution :term:`Metadata`, you are
6314creating a Poky distribution. If you wish to gain more control over
6315package alternative selections, compile-time options, and other
6316low-level configurations, you can create your own distribution.
6317
6318To create your own distribution, the basic steps consist of creating
6319your own distribution layer, creating your own distribution
6320configuration file, and then adding any needed code and Metadata to the
6321layer. The following steps provide some more detail:
6322
6323- *Create a layer for your new distro:* Create your distribution layer
6324 so that you can keep your Metadata and code for the distribution
6325 separate. It is strongly recommended that you create and use your own
6326 layer for configuration and code. Using your own layer as compared to
6327 just placing configurations in a ``local.conf`` configuration file
6328 makes it easier to reproduce the same build configuration when using
6329 multiple build machines. See the
Andrew Geissler09209ee2020-12-13 08:44:15 -06006330 ":ref:`dev-manual/common-tasks:creating a general layer using the \`\`bitbake-layers\`\` script`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006331 section for information on how to quickly set up a layer.
6332
6333- *Create the distribution configuration file:* The distribution
6334 configuration file needs to be created in the ``conf/distro``
6335 directory of your layer. You need to name it using your distribution
6336 name (e.g. ``mydistro.conf``).
6337
6338 .. note::
6339
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006340 The :term:`DISTRO` variable in your ``local.conf`` file determines the
6341 name of your distribution.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006342
6343 You can split out parts of your configuration file into include files
6344 and then "require" them from within your distribution configuration
6345 file. Be sure to place the include files in the
6346 ``conf/distro/include`` directory of your layer. A common example
6347 usage of include files would be to separate out the selection of
6348 desired version and revisions for individual recipes.
6349
6350 Your configuration file needs to set the following required
6351 variables:
6352
6353 - :term:`DISTRO_NAME`
6354
6355 - :term:`DISTRO_VERSION`
6356
6357 These following variables are optional and you typically set them
6358 from the distribution configuration file:
6359
6360 - :term:`DISTRO_FEATURES`
6361
6362 - :term:`DISTRO_EXTRA_RDEPENDS`
6363
6364 - :term:`DISTRO_EXTRA_RRECOMMENDS`
6365
6366 - :term:`TCLIBC`
6367
6368 .. tip::
6369
6370 If you want to base your distribution configuration file on the
6371 very basic configuration from OE-Core, you can use
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006372 ``conf/distro/defaultsetup.conf`` as a reference and just include
6373 variables that differ as compared to ``defaultsetup.conf``.
6374 Alternatively, you can create a distribution configuration file
6375 from scratch using the ``defaultsetup.conf`` file or configuration files
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00006376 from another distribution such as Poky as a reference.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006377
6378- *Provide miscellaneous variables:* Be sure to define any other
6379 variables for which you want to create a default or enforce as part
6380 of the distribution configuration. You can include nearly any
6381 variable from the ``local.conf`` file. The variables you use are not
6382 limited to the list in the previous bulleted item.
6383
Patrick Williams2390b1b2022-11-03 13:47:49 -05006384- *Point to Your distribution configuration file:* In your ``local.conf``
6385 file in the :term:`Build Directory`, set your :term:`DISTRO` variable to
6386 point to your distribution's configuration file. For example, if your
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006387 distribution's configuration file is named ``mydistro.conf``, then
Andrew Geisslerc926e172021-05-07 16:11:35 -05006388 you point to it as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006389
6390 DISTRO = "mydistro"
6391
6392- *Add more to the layer if necessary:* Use your layer to hold other
6393 information needed for the distribution:
6394
6395 - Add recipes for installing distro-specific configuration files
6396 that are not already installed by another recipe. If you have
6397 distro-specific configuration files that are included by an
6398 existing recipe, you should add an append file (``.bbappend``) for
6399 those. For general information and recommendations on how to add
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006400 recipes to your layer, see the
6401 ":ref:`dev-manual/common-tasks:creating your own layer`" and
6402 ":ref:`dev-manual/common-tasks:following best practices when creating layers`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006403 sections.
6404
6405 - Add any image recipes that are specific to your distribution.
6406
6407 - Add a ``psplash`` append file for a branded splash screen. For
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006408 information on append files, see the
Patrick Williams0ca19cc2021-08-16 14:03:13 -05006409 ":ref:`dev-manual/common-tasks:appending other layers metadata with your layer`"
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006410 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006411
6412 - Add any other append files to make custom changes that are
6413 specific to individual recipes.
6414
6415Creating a Custom Template Configuration Directory
6416==================================================
6417
6418If you are producing your own customized version of the build system for
Andrew Geissler87f5cff2022-09-30 13:13:31 -05006419use by other users, you might want to provide a custom build configuration
6420that includes all the necessary settings and layers (i.e. ``local.conf`` and
Patrick Williams2390b1b2022-11-03 13:47:49 -05006421``bblayers.conf`` that are created in a new :term:`Build Directory`) and a custom
Andrew Geissler87f5cff2022-09-30 13:13:31 -05006422message that is shown when setting up the build. This can be done by
6423creating one or more template configuration directories in your
6424custom distribution layer.
6425
6426This can be done by using ``bitbake-layers save-build-conf``::
6427
6428 $ bitbake-layers save-build-conf ../../meta-alex/ test-1
6429 NOTE: Starting bitbake server...
6430 NOTE: Configuration template placed into /srv/work/alex/meta-alex/conf/templates/test-1
6431 Please review the files in there, and particularly provide a configuration description in /srv/work/alex/meta-alex/conf/templates/test-1/conf-notes.txt
6432 You can try out the configuration with
6433 TEMPLATECONF=/srv/work/alex/meta-alex/conf/templates/test-1 . /srv/work/alex/poky/oe-init-build-env build-try-test-1
6434
Patrick Williams2390b1b2022-11-03 13:47:49 -05006435The above command takes the config files from the currently active :term:`Build Directory` under ``conf``,
Andrew Geissler87f5cff2022-09-30 13:13:31 -05006436replaces site-specific paths in ``bblayers.conf`` with ``##OECORE##``-relative paths, and copies
6437the config files into a specified layer under a specified template name.
6438
6439To use those saved templates as a starting point for a build, users should point
6440to one of them with :term:`TEMPLATECONF` environment variable::
6441
6442 TEMPLATECONF=/srv/work/alex/meta-alex/conf/templates/test-1 . /srv/work/alex/poky/oe-init-build-env build-try-test-1
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006443
6444The OpenEmbedded build system uses the environment variable
Andrew Geisslerd5838332022-05-27 11:33:10 -05006445:term:`TEMPLATECONF` to locate the directory from which it gathers
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006446configuration information that ultimately ends up in the
6447:term:`Build Directory` ``conf`` directory.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006448
Andrew Geissler87f5cff2022-09-30 13:13:31 -05006449If :term:`TEMPLATECONF` is not set, the default value is obtained
6450from ``.templateconf`` file that is read from the same directory as
6451``oe-init-build-env`` script. For the Poky reference distribution this
6452would be::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006453
Andrew Geissler87f5cff2022-09-30 13:13:31 -05006454 TEMPLATECONF=${TEMPLATECONF:-meta-poky/conf/templates/default}
6455
6456If you look at a configuration template directory, you will
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006457see the ``bblayers.conf.sample``, ``local.conf.sample``, and
6458``conf-notes.txt`` files. The build system uses these files to form the
Andrew Geissler87f5cff2022-09-30 13:13:31 -05006459respective ``bblayers.conf`` file, ``local.conf`` file, and show
6460users a note about the build they're setting up
6461when running the ``oe-init-build-env`` setup script. These can be
6462edited further if needed to improve or change the build configurations
6463available to the users.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006464
Andrew Geissler595f6302022-01-24 19:11:47 +00006465Conserving Disk Space
6466=====================
6467
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006468Conserving Disk Space During Builds
Andrew Geissler595f6302022-01-24 19:11:47 +00006469-----------------------------------
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006470
6471To help conserve disk space during builds, you can add the following
6472statement to your project's ``local.conf`` configuration file found in
Andrew Geisslerc926e172021-05-07 16:11:35 -05006473the :term:`Build Directory`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006474
6475 INHERIT += "rm_work"
6476
6477Adding this statement deletes the work directory used for
6478building a recipe once the recipe is built. For more information on
6479"rm_work", see the
6480:ref:`rm_work <ref-classes-rm-work>` class in the
6481Yocto Project Reference Manual.
6482
Andrew Geissler595f6302022-01-24 19:11:47 +00006483Purging Duplicate Shared State Cache Files
6484-------------------------------------------
6485
6486After multiple build iterations, the Shared State (sstate) cache can contain
6487duplicate cache files for a given package, while only the most recent one
6488is likely to be reusable. The following command purges all but the
6489newest sstate cache file for each package::
6490
6491 sstate-cache-management.sh --remove-duplicated --cache-dir=build/sstate-cache
6492
6493This command will ask you to confirm the deletions it identifies.
6494
Patrick Williams92b42cb2022-09-03 06:53:57 -05006495.. note::
Andrew Geissler595f6302022-01-24 19:11:47 +00006496
6497 The duplicated sstate cache files of one package must have the same
6498 architecture, which means that sstate cache files with multiple
6499 architectures are not considered as duplicate.
6500
6501Run ``sstate-cache-management.sh`` for more details about this script.
6502
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006503Working with Packages
6504=====================
6505
6506This section describes a few tasks that involve packages:
6507
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006508- :ref:`dev-manual/common-tasks:excluding packages from an image`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006509
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006510- :ref:`dev-manual/common-tasks:incrementing a package version`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006511
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006512- :ref:`dev-manual/common-tasks:handling optional module packaging`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006513
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006514- :ref:`dev-manual/common-tasks:using runtime package management`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006515
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006516- :ref:`dev-manual/common-tasks:generating and using signed packages`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006517
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006518- :ref:`Setting up and running package test
6519 (ptest) <dev-manual/common-tasks:testing packages with ptest>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006520
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006521- :ref:`dev-manual/common-tasks:creating node package manager (npm) packages`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006522
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006523- :ref:`dev-manual/common-tasks:adding custom metadata to packages`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006524
6525Excluding Packages from an Image
6526--------------------------------
6527
6528You might find it necessary to prevent specific packages from being
6529installed into an image. If so, you can use several variables to direct
6530the build system to essentially ignore installing recommended packages
6531or to not install a package at all.
6532
6533The following list introduces variables you can use to prevent packages
6534from being installed into your image. Each of these variables only works
William A. Kennington IIIac69b482021-06-02 12:28:27 -07006535with IPK and RPM package types, not for Debian packages.
6536Also, you can use these variables from your ``local.conf`` file
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006537or attach them to a specific image recipe by using a recipe name
6538override. For more detail on the variables, see the descriptions in the
6539Yocto Project Reference Manual's glossary chapter.
6540
6541- :term:`BAD_RECOMMENDATIONS`:
6542 Use this variable to specify "recommended-only" packages that you do
6543 not want installed.
6544
6545- :term:`NO_RECOMMENDATIONS`:
6546 Use this variable to prevent all "recommended-only" packages from
6547 being installed.
6548
6549- :term:`PACKAGE_EXCLUDE`:
6550 Use this variable to prevent specific packages from being installed
6551 regardless of whether they are "recommended-only" or not. You need to
6552 realize that the build process could fail with an error when you
6553 prevent the installation of a package whose presence is required by
6554 an installed package.
6555
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006556Incrementing a Package Version
6557------------------------------
6558
6559This section provides some background on how binary package versioning
6560is accomplished and presents some of the services, variables, and
6561terminology involved.
6562
6563In order to understand binary package versioning, you need to consider
6564the following:
6565
6566- Binary Package: The binary package that is eventually built and
6567 installed into an image.
6568
6569- Binary Package Version: The binary package version is composed of two
Andrew Geissler615f2f12022-07-15 14:00:58 -05006570 components --- a version and a revision.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006571
6572 .. note::
6573
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006574 Technically, a third component, the "epoch" (i.e. :term:`PE`) is involved
Andrew Geissler09036742021-06-25 14:25:14 -05006575 but this discussion for the most part ignores :term:`PE`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006576
6577 The version and revision are taken from the
6578 :term:`PV` and
6579 :term:`PR` variables, respectively.
6580
Andrew Geissler09036742021-06-25 14:25:14 -05006581- :term:`PV`: The recipe version. :term:`PV` represents the version of the
6582 software being packaged. Do not confuse :term:`PV` with the binary
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006583 package version.
6584
Andrew Geissler5f350902021-07-23 13:09:54 -04006585- :term:`PR`: The recipe revision.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006586
6587- :term:`SRCPV`: The OpenEmbedded
Andrew Geissler09036742021-06-25 14:25:14 -05006588 build system uses this string to help define the value of :term:`PV` when
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006589 the source code revision needs to be included in it.
6590
Andrew Geissler09209ee2020-12-13 08:44:15 -06006591- :yocto_wiki:`PR Service </PR_Service>`: A
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006592 network-based service that helps automate keeping package feeds
6593 compatible with existing package manager applications such as RPM,
6594 APT, and OPKG.
6595
6596Whenever the binary package content changes, the binary package version
6597must change. Changing the binary package version is accomplished by
Andrew Geissler09036742021-06-25 14:25:14 -05006598changing or "bumping" the :term:`PR` and/or :term:`PV` values. Increasing these
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006599values occurs one of two ways:
6600
6601- Automatically using a Package Revision Service (PR Service).
6602
Andrew Geissler09036742021-06-25 14:25:14 -05006603- Manually incrementing the :term:`PR` and/or :term:`PV` variables.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006604
6605Given a primary challenge of any build system and its users is how to
6606maintain a package feed that is compatible with existing package manager
6607applications such as RPM, APT, and OPKG, using an automated system is
6608much preferred over a manual system. In either system, the main
6609requirement is that binary package version numbering increases in a
William A. Kennington IIIac69b482021-06-02 12:28:27 -07006610linear fashion and that there is a number of version components that
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006611support that linear progression. For information on how to ensure
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006612package revisioning remains linear, see the
6613":ref:`dev-manual/common-tasks:automatically incrementing a package version number`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006614section.
6615
6616The following three sections provide related information on the PR
Andrew Geissler09036742021-06-25 14:25:14 -05006617Service, the manual method for "bumping" :term:`PR` and/or :term:`PV`, and on
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006618how to ensure binary package revisioning remains linear.
6619
6620Working With a PR Service
6621~~~~~~~~~~~~~~~~~~~~~~~~~
6622
6623As mentioned, attempting to maintain revision numbers in the
6624:term:`Metadata` is error prone, inaccurate,
6625and causes problems for people submitting recipes. Conversely, the PR
6626Service automatically generates increasing numbers, particularly the
6627revision field, which removes the human element.
6628
6629.. note::
6630
6631 For additional information on using a PR Service, you can see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06006632 :yocto_wiki:`PR Service </PR_Service>` wiki page.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006633
6634The Yocto Project uses variables in order of decreasing priority to
6635facilitate revision numbering (i.e.
6636:term:`PE`,
6637:term:`PV`, and
6638:term:`PR` for epoch, version, and
6639revision, respectively). The values are highly dependent on the policies
6640and procedures of a given distribution and package feed.
6641
6642Because the OpenEmbedded build system uses
Andrew Geissler09209ee2020-12-13 08:44:15 -06006643":ref:`signatures <overview-manual/concepts:checksums (signatures)>`", which are
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006644unique to a given build, the build system knows when to rebuild
6645packages. All the inputs into a given task are represented by a
6646signature, which can trigger a rebuild when different. Thus, the build
Andrew Geissler09036742021-06-25 14:25:14 -05006647system itself does not rely on the :term:`PR`, :term:`PV`, and :term:`PE` numbers to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006648trigger a rebuild. The signatures, however, can be used to generate
6649these values.
6650
6651The PR Service works with both ``OEBasic`` and ``OEBasicHash``
Andrew Geissler09036742021-06-25 14:25:14 -05006652generators. The value of :term:`PR` bumps when the checksum changes and the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006653different generator mechanisms change signatures under different
6654circumstances.
6655
6656As implemented, the build system includes values from the PR Service
Andrew Geissler09036742021-06-25 14:25:14 -05006657into the :term:`PR` field as an addition using the form "``.x``" so ``r0``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006658becomes ``r0.1``, ``r0.2`` and so forth. This scheme allows existing
Andrew Geissler09036742021-06-25 14:25:14 -05006659:term:`PR` values to be used for whatever reasons, which include manual
6660:term:`PR` bumps, should it be necessary.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006661
6662By default, the PR Service is not enabled or running. Thus, the packages
6663generated are just "self consistent". The build system adds and removes
6664packages and there are no guarantees about upgrade paths but images will
6665be consistent and correct with the latest changes.
6666
Patrick Williams2390b1b2022-11-03 13:47:49 -05006667The simplest form for a PR Service is for a single host development system
6668that builds the package feed (building system). For this scenario, you can
6669enable a local PR Service by setting :term:`PRSERV_HOST` in your
Andrew Geisslerc926e172021-05-07 16:11:35 -05006670``local.conf`` file in the :term:`Build Directory`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006671
6672 PRSERV_HOST = "localhost:0"
6673
6674Once the service is started, packages will automatically
Andrew Geissler09036742021-06-25 14:25:14 -05006675get increasing :term:`PR` values and BitBake takes care of starting and
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006676stopping the server.
6677
6678If you have a more complex setup where multiple host development systems
6679work against a common, shared package feed, you have a single PR Service
6680running and it is connected to each building system. For this scenario,
Andrew Geisslerc926e172021-05-07 16:11:35 -05006681you need to start the PR Service using the ``bitbake-prserv`` command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006682
6683 bitbake-prserv --host ip --port port --start
6684
6685In addition to
6686hand-starting the service, you need to update the ``local.conf`` file of
6687each building system as described earlier so each system points to the
6688server and port.
6689
6690It is also recommended you use build history, which adds some sanity
6691checks to binary package versions, in conjunction with the server that
6692is running the PR Service. To enable build history, add the following to
Andrew Geisslerc926e172021-05-07 16:11:35 -05006693each building system's ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006694
6695 # It is recommended to activate "buildhistory" for testing the PR service
6696 INHERIT += "buildhistory"
6697 BUILDHISTORY_COMMIT = "1"
6698
6699For information on build
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006700history, see the
6701":ref:`dev-manual/common-tasks:maintaining build output quality`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006702
6703.. note::
6704
Andrew Geissler09036742021-06-25 14:25:14 -05006705 The OpenEmbedded build system does not maintain :term:`PR` information as
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006706 part of the shared state (sstate) packages. If you maintain an sstate
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006707 feed, it's expected that either all your building systems that
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006708 contribute to the sstate feed use a shared PR Service, or you do not
6709 run a PR Service on any of your building systems. Having some systems
6710 use a PR Service while others do not leads to obvious problems.
6711
6712 For more information on shared state, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06006713 ":ref:`overview-manual/concepts:shared state cache`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006714 section in the Yocto Project Overview and Concepts Manual.
6715
6716Manually Bumping PR
6717~~~~~~~~~~~~~~~~~~~
6718
6719The alternative to setting up a PR Service is to manually "bump" the
6720:term:`PR` variable.
6721
6722If a committed change results in changing the package output, then the
6723value of the PR variable needs to be increased (or "bumped") as part of
Andrew Geissler09036742021-06-25 14:25:14 -05006724that commit. For new recipes you should add the :term:`PR` variable and set
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006725its initial value equal to "r0", which is the default. Even though the
6726default value is "r0", the practice of adding it to a new recipe makes
6727it harder to forget to bump the variable when you make changes to the
6728recipe in future.
6729
6730If you are sharing a common ``.inc`` file with multiple recipes, you can
Andrew Geissler09036742021-06-25 14:25:14 -05006731also use the :term:`INC_PR` variable to ensure that the recipes sharing the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006732``.inc`` file are rebuilt when the ``.inc`` file itself is changed. The
Andrew Geissler09036742021-06-25 14:25:14 -05006733``.inc`` file must set :term:`INC_PR` (initially to "r0"), and all recipes
6734referring to it should set :term:`PR` to "${INC_PR}.0" initially,
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006735incrementing the last number when the recipe is changed. If the ``.inc``
Andrew Geissler09036742021-06-25 14:25:14 -05006736file is changed then its :term:`INC_PR` should be incremented.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006737
Andrew Geissler09036742021-06-25 14:25:14 -05006738When upgrading the version of a binary package, assuming the :term:`PV`
6739changes, the :term:`PR` variable should be reset to "r0" (or "${INC_PR}.0"
6740if you are using :term:`INC_PR`).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006741
6742Usually, version increases occur only to binary packages. However, if
Andrew Geissler09036742021-06-25 14:25:14 -05006743for some reason :term:`PV` changes but does not increase, you can increase
6744the :term:`PE` variable (Package Epoch). The :term:`PE` variable defaults to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006745"0".
6746
6747Binary package version numbering strives to follow the `Debian Version
6748Field Policy
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006749Guidelines <https://www.debian.org/doc/debian-policy/ch-controlfields.html>`__.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006750These guidelines define how versions are compared and what "increasing"
6751a version means.
6752
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006753Automatically Incrementing a Package Version Number
6754~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6755
6756When fetching a repository, BitBake uses the
6757:term:`SRCREV` variable to determine
6758the specific source code revision from which to build. You set the
Andrew Geissler09036742021-06-25 14:25:14 -05006759:term:`SRCREV` variable to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006760:term:`AUTOREV` to cause the
6761OpenEmbedded build system to automatically use the latest revision of
Andrew Geisslerc926e172021-05-07 16:11:35 -05006762the software::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006763
6764 SRCREV = "${AUTOREV}"
6765
Andrew Geissler09036742021-06-25 14:25:14 -05006766Furthermore, you need to reference :term:`SRCPV` in :term:`PV` in order to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006767automatically update the version whenever the revision of the source
Andrew Geisslerc926e172021-05-07 16:11:35 -05006768code changes. Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006769
6770 PV = "1.0+git${SRCPV}"
6771
Andrew Geissler09036742021-06-25 14:25:14 -05006772The OpenEmbedded build system substitutes :term:`SRCPV` with the following:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006773
6774.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006775
6776 AUTOINC+source_code_revision
6777
6778The build system replaces the ``AUTOINC``
6779with a number. The number used depends on the state of the PR Service:
6780
6781- If PR Service is enabled, the build system increments the number,
6782 which is similar to the behavior of
6783 :term:`PR`. This behavior results in
6784 linearly increasing package versions, which is desirable. Here is an
6785 example:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006786
6787 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006788
6789 hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
6790 hello-world-git_0.0+git1+dd2f5c3565-r0.0_armv7a-neon.ipk
6791
6792- If PR Service is not enabled, the build system replaces the
6793 ``AUTOINC`` placeholder with zero (i.e. "0"). This results in
6794 changing the package version since the source revision is included.
6795 However, package versions are not increased linearly. Here is an
6796 example:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006797
6798 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006799
6800 hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
6801 hello-world-git_0.0+git0+dd2f5c3565-r0.0_armv7a-neon.ipk
6802
6803In summary, the OpenEmbedded build system does not track the history of
6804binary package versions for this purpose. ``AUTOINC``, in this case, is
Andrew Geissler09036742021-06-25 14:25:14 -05006805comparable to :term:`PR`. If PR server is not enabled, ``AUTOINC`` in the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006806package version is simply replaced by "0". If PR server is enabled, the
6807build system keeps track of the package versions and bumps the number
6808when the package revision changes.
6809
6810Handling Optional Module Packaging
6811----------------------------------
6812
6813Many pieces of software split functionality into optional modules (or
6814plugins) and the plugins that are built might depend on configuration
6815options. To avoid having to duplicate the logic that determines what
6816modules are available in your recipe or to avoid having to package each
6817module by hand, the OpenEmbedded build system provides functionality to
6818handle module packaging dynamically.
6819
6820To handle optional module packaging, you need to do two things:
6821
6822- Ensure the module packaging is actually done.
6823
6824- Ensure that any dependencies on optional modules from other recipes
6825 are satisfied by your recipe.
6826
6827Making Sure the Packaging is Done
6828~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6829
6830To ensure the module packaging actually gets done, you use the
6831``do_split_packages`` function within the ``populate_packages`` Python
6832function in your recipe. The ``do_split_packages`` function searches for
6833a pattern of files or directories under a specified path and creates a
6834package for each one it finds by appending to the
6835:term:`PACKAGES` variable and
Patrick Williams0ca19cc2021-08-16 14:03:13 -05006836setting the appropriate values for ``FILES:packagename``,
6837``RDEPENDS:packagename``, ``DESCRIPTION:packagename``, and so forth.
Andrew Geisslerc926e172021-05-07 16:11:35 -05006838Here is an example from the ``lighttpd`` recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006839
Patrick Williams0ca19cc2021-08-16 14:03:13 -05006840 python populate_packages:prepend () {
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006841 lighttpd_libdir = d.expand('${libdir}')
6842 do_split_packages(d, lighttpd_libdir, '^mod_(.*).so$',
6843 'lighttpd-module-%s', 'Lighttpd module for %s',
6844 extra_depends='')
6845 }
6846
6847The previous example specifies a number of things in the call to
6848``do_split_packages``.
6849
6850- A directory within the files installed by your recipe through
Patrick Williams2194f502022-10-16 14:26:09 -05006851 :ref:`ref-tasks-install` in which to search.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006852
6853- A regular expression used to match module files in that directory. In
6854 the example, note the parentheses () that mark the part of the
6855 expression from which the module name should be derived.
6856
6857- A pattern to use for the package names.
6858
6859- A description for each package.
6860
6861- An empty string for ``extra_depends``, which disables the default
6862 dependency on the main ``lighttpd`` package. Thus, if a file in
6863 ``${libdir}`` called ``mod_alias.so`` is found, a package called
6864 ``lighttpd-module-alias`` is created for it and the
6865 :term:`DESCRIPTION` is set to
6866 "Lighttpd module for alias".
6867
6868Often, packaging modules is as simple as the previous example. However,
William A. Kennington IIIac69b482021-06-02 12:28:27 -07006869there are more advanced options that you can use within
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006870``do_split_packages`` to modify its behavior. And, if you need to, you
6871can add more logic by specifying a hook function that is called for each
6872package. It is also perfectly acceptable to call ``do_split_packages``
6873multiple times if you have more than one set of modules to package.
6874
6875For more examples that show how to use ``do_split_packages``, see the
6876``connman.inc`` file in the ``meta/recipes-connectivity/connman/``
Andrew Geissler09209ee2020-12-13 08:44:15 -06006877directory of the ``poky`` :ref:`source repository <overview-manual/development-environment:yocto project source repositories>`. You can
Patrick Williams975a06f2022-10-21 14:42:47 -05006878also find examples in ``meta/classes-recipe/kernel.bbclass``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006879
6880Following is a reference that shows ``do_split_packages`` mandatory and
Andrew Geisslerc926e172021-05-07 16:11:35 -05006881optional arguments::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006882
6883 Mandatory arguments
6884
6885 root
6886 The path in which to search
6887 file_regex
6888 Regular expression to match searched files.
6889 Use parentheses () to mark the part of this
6890 expression that should be used to derive the
6891 module name (to be substituted where %s is
6892 used in other function arguments as noted below)
6893 output_pattern
6894 Pattern to use for the package names. Must
6895 include %s.
6896 description
6897 Description to set for each package. Must
6898 include %s.
6899
6900 Optional arguments
6901
6902 postinst
6903 Postinstall script to use for all packages
6904 (as a string)
6905 recursive
Andrew Geissler615f2f12022-07-15 14:00:58 -05006906 True to perform a recursive search --- default
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006907 False
6908 hook
6909 A hook function to be called for every match.
6910 The function will be called with the following
6911 arguments (in the order listed):
6912
6913 f
6914 Full path to the file/directory match
6915 pkg
6916 The package name
6917 file_regex
6918 As above
6919 output_pattern
6920 As above
6921 modulename
6922 The module name derived using file_regex
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006923 extra_depends
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006924 Extra runtime dependencies (RDEPENDS) to be
6925 set for all packages. The default value of None
6926 causes a dependency on the main package
Andrew Geissler615f2f12022-07-15 14:00:58 -05006927 (${PN}) --- if you do not want this, pass empty
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006928 string '' for this parameter.
6929 aux_files_pattern
6930 Extra item(s) to be added to FILES for each
6931 package. Can be a single string item or a list
6932 of strings for multiple items. Must include %s.
6933 postrm
6934 postrm script to use for all packages (as a
6935 string)
6936 allow_dirs
6937 True to allow directories to be matched -
6938 default False
6939 prepend
6940 If True, prepend created packages to PACKAGES
6941 instead of the default False which appends them
6942 match_path
6943 match file_regex on the whole relative path to
Patrick Williams0ca19cc2021-08-16 14:03:13 -05006944 the root rather than just the filename
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006945 aux_files_pattern_verbatim
6946 Extra item(s) to be added to FILES for each
6947 package, using the actual derived module name
6948 rather than converting it to something legal
6949 for a package name. Can be a single string item
6950 or a list of strings for multiple items. Must
6951 include %s.
6952 allow_links
Andrew Geissler615f2f12022-07-15 14:00:58 -05006953 True to allow symlinks to be matched --- default
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006954 False
6955 summary
6956 Summary to set for each package. Must include %s;
6957 defaults to description if not set.
6958
6959
6960
6961Satisfying Dependencies
6962~~~~~~~~~~~~~~~~~~~~~~~
6963
6964The second part for handling optional module packaging is to ensure that
6965any dependencies on optional modules from other recipes are satisfied by
6966your recipe. You can be sure these dependencies are satisfied by using
6967the :term:`PACKAGES_DYNAMIC`
6968variable. Here is an example that continues with the ``lighttpd`` recipe
Andrew Geisslerc926e172021-05-07 16:11:35 -05006969shown earlier::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006970
6971 PACKAGES_DYNAMIC = "lighttpd-module-.*"
6972
6973The name
6974specified in the regular expression can of course be anything. In this
6975example, it is ``lighttpd-module-`` and is specified as the prefix to
6976ensure that any :term:`RDEPENDS` and
6977:term:`RRECOMMENDS` on a package
6978name starting with the prefix are satisfied during build time. If you
6979are using ``do_split_packages`` as described in the previous section,
Andrew Geissler09036742021-06-25 14:25:14 -05006980the value you put in :term:`PACKAGES_DYNAMIC` should correspond to the name
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006981pattern specified in the call to ``do_split_packages``.
6982
6983Using Runtime Package Management
6984--------------------------------
6985
6986During a build, BitBake always transforms a recipe into one or more
6987packages. For example, BitBake takes the ``bash`` recipe and produces a
6988number of packages (e.g. ``bash``, ``bash-bashbug``,
6989``bash-completion``, ``bash-completion-dbg``, ``bash-completion-dev``,
6990``bash-completion-extra``, ``bash-dbg``, and so forth). Not all
6991generated packages are included in an image.
6992
6993In several situations, you might need to update, add, remove, or query
6994the packages on a target device at runtime (i.e. without having to
6995generate a new image). Examples of such situations include:
6996
6997- You want to provide in-the-field updates to deployed devices (e.g.
6998 security updates).
6999
7000- You want to have a fast turn-around development cycle for one or more
7001 applications that run on your device.
7002
7003- You want to temporarily install the "debug" packages of various
7004 applications on your device so that debugging can be greatly improved
7005 by allowing access to symbols and source debugging.
7006
7007- You want to deploy a more minimal package selection of your device
7008 but allow in-the-field updates to add a larger selection for
7009 customization.
7010
7011In all these situations, you have something similar to a more
7012traditional Linux distribution in that in-field devices are able to
7013receive pre-compiled packages from a server for installation or update.
7014Being able to install these packages on a running, in-field device is
7015what is termed "runtime package management".
7016
7017In order to use runtime package management, you need a host or server
7018machine that serves up the pre-compiled packages plus the required
7019metadata. You also need package manipulation tools on the target. The
7020build machine is a likely candidate to act as the server. However, that
7021machine does not necessarily have to be the package server. The build
7022machine could push its artifacts to another machine that acts as the
7023server (e.g. Internet-facing). In fact, doing so is advantageous for a
7024production environment as getting the packages away from the development
Patrick Williams2390b1b2022-11-03 13:47:49 -05007025system's :term:`Build Directory` prevents accidental overwrites.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007026
7027A simple build that targets just one device produces more than one
7028package database. In other words, the packages produced by a build are
7029separated out into a couple of different package groupings based on
7030criteria such as the target's CPU architecture, the target board, or the
7031C library used on the target. For example, a build targeting the
7032``qemux86`` device produces the following three package databases:
7033``noarch``, ``i586``, and ``qemux86``. If you wanted your ``qemux86``
7034device to be aware of all the packages that were available to it, you
7035would need to point it to each of these databases individually. In a
7036similar way, a traditional Linux distribution usually is configured to
7037be aware of a number of software repositories from which it retrieves
7038packages.
7039
7040Using runtime package management is completely optional and not required
7041for a successful build or deployment in any way. But if you want to make
7042use of runtime package management, you need to do a couple things above
7043and beyond the basics. The remainder of this section describes what you
7044need to do.
7045
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007046Build Considerations
7047~~~~~~~~~~~~~~~~~~~~
7048
7049This section describes build considerations of which you need to be
7050aware in order to provide support for runtime package management.
7051
7052When BitBake generates packages, it needs to know what format or formats
7053to use. In your configuration, you use the
7054:term:`PACKAGE_CLASSES`
7055variable to specify the format:
7056
Patrick Williams2390b1b2022-11-03 13:47:49 -050070571. Open the ``local.conf`` file inside your :term:`Build Directory` (e.g.
Andrew Geissler95ac1b82021-03-31 14:34:31 -05007058 ``poky/build/conf/local.conf``).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007059
Andrew Geisslerc926e172021-05-07 16:11:35 -050070602. Select the desired package format as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007061
7062 PACKAGE_CLASSES ?= "package_packageformat"
7063
7064 where packageformat can be "ipk", "rpm",
7065 "deb", or "tar" which are the supported package formats.
7066
7067 .. note::
7068
7069 Because the Yocto Project supports four different package formats,
7070 you can set the variable with more than one argument. However, the
7071 OpenEmbedded build system only uses the first argument when
7072 creating an image or Software Development Kit (SDK).
7073
7074If you would like your image to start off with a basic package database
7075containing the packages in your current build as well as to have the
7076relevant tools available on the target for runtime package management,
7077you can include "package-management" in the
7078:term:`IMAGE_FEATURES`
7079variable. Including "package-management" in this configuration variable
7080ensures that when the image is assembled for your target, the image
7081includes the currently-known package databases as well as the
7082target-specific tools required for runtime package management to be
7083performed on the target. However, this is not strictly necessary. You
7084could start your image off without any databases but only include the
7085required on-target package tool(s). As an example, you could include
7086"opkg" in your
7087:term:`IMAGE_INSTALL` variable
7088if you are using the IPK package format. You can then initialize your
7089target's package database(s) later once your image is up and running.
7090
7091Whenever you perform any sort of build step that can potentially
7092generate a package or modify existing package, it is always a good idea
7093to re-generate the package index after the build by using the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05007094command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007095
7096 $ bitbake package-index
7097
7098It might be tempting to build the
7099package and the package index at the same time with a command such as
Andrew Geisslerc926e172021-05-07 16:11:35 -05007100the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007101
7102 $ bitbake some-package package-index
7103
7104Do not do this as
7105BitBake does not schedule the package index for after the completion of
7106the package you are building. Consequently, you cannot be sure of the
7107package index including information for the package you just built.
7108Thus, be sure to run the package update step separately after building
7109any packages.
7110
7111You can use the
7112:term:`PACKAGE_FEED_ARCHS`,
7113:term:`PACKAGE_FEED_BASE_PATHS`,
7114and
7115:term:`PACKAGE_FEED_URIS`
7116variables to pre-configure target images to use a package feed. If you
7117do not define these variables, then manual steps as described in the
7118subsequent sections are necessary to configure the target. You should
7119set these variables before building the image in order to produce a
7120correctly configured image.
7121
7122When your build is complete, your packages reside in the
7123``${TMPDIR}/deploy/packageformat`` directory. For example, if
7124``${``\ :term:`TMPDIR`\ ``}`` is
7125``tmp`` and your selected package type is RPM, then your RPM packages
7126are available in ``tmp/deploy/rpm``.
7127
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007128Host or Server Machine Setup
7129~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7130
7131Although other protocols are possible, a server using HTTP typically
7132serves packages. If you want to use HTTP, then set up and configure a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007133web server such as Apache 2, lighttpd, or Python web server on the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007134machine serving the packages.
7135
7136To keep things simple, this section describes how to set up a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007137Python web server to share package feeds from the developer's
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007138machine. Although this server might not be the best for a production
7139environment, the setup is simple and straight forward. Should you want
7140to use a different server more suited for production (e.g. Apache 2,
7141Lighttpd, or Nginx), take the appropriate steps to do so.
7142
Patrick Williams2390b1b2022-11-03 13:47:49 -05007143From within the :term:`Build Directory` where you have built an image based on
7144your packaging choice (i.e. the :term:`PACKAGE_CLASSES` setting), simply start
7145the server. The following example assumes a :term:`Build Directory` of ``poky/build``
7146and a :term:`PACKAGE_CLASSES` setting of "package_rpm"::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007147
Andrew Geissler95ac1b82021-03-31 14:34:31 -05007148 $ cd poky/build/tmp/deploy/rpm
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007149 $ python3 -m http.server
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007150
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007151Target Setup
7152~~~~~~~~~~~~
7153
7154Setting up the target differs depending on the package management
7155system. This section provides information for RPM, IPK, and DEB.
7156
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007157Using RPM
7158^^^^^^^^^
7159
Patrick Williams7784c422022-11-17 07:29:11 -06007160The :wikipedia:`Dandified Packaging <DNF_(software)>` (DNF) performs
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007161runtime package management of RPM packages. In order to use DNF for
7162runtime package management, you must perform an initial setup on the
7163target machine for cases where the ``PACKAGE_FEED_*`` variables were not
7164set as part of the image that is running on the target. This means if
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05007165you built your image and did not use these variables as part of the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007166build and your image is now running on the target, you need to perform
7167the steps in this section if you want to use runtime package management.
7168
7169.. note::
7170
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007171 For information on the ``PACKAGE_FEED_*`` variables, see
7172 :term:`PACKAGE_FEED_ARCHS`, :term:`PACKAGE_FEED_BASE_PATHS`, and
7173 :term:`PACKAGE_FEED_URIS` in the Yocto Project Reference Manual variables
7174 glossary.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007175
7176On the target, you must inform DNF that package databases are available.
7177You do this by creating a file named
7178``/etc/yum.repos.d/oe-packages.repo`` and defining the ``oe-packages``.
7179
7180As an example, assume the target is able to use the following package
7181databases: ``all``, ``i586``, and ``qemux86`` from a server named
7182``my.server``. The specifics for setting up the web server are up to
7183you. The critical requirement is that the URIs in the target repository
7184configuration point to the correct remote location for the feeds.
7185
7186.. note::
7187
7188 For development purposes, you can point the web server to the build
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007189 system's ``deploy`` directory. However, for production use, it is better to
7190 copy the package directories to a location outside of the build area and use
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007191 that location. Doing so avoids situations where the build system
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007192 overwrites or changes the ``deploy`` directory.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007193
7194When telling DNF where to look for the package databases, you must
7195declare individual locations per architecture or a single location used
7196for all architectures. You cannot do both:
7197
7198- *Create an Explicit List of Architectures:* Define individual base
7199 URLs to identify where each package database is located:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007200
7201 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007202
7203 [oe-packages]
7204 baseurl=http://my.server/rpm/i586 http://my.server/rpm/qemux86 http://my.server/rpm/all
7205
7206 This example
7207 informs DNF about individual package databases for all three
7208 architectures.
7209
7210- *Create a Single (Full) Package Index:* Define a single base URL that
Andrew Geisslerc926e172021-05-07 16:11:35 -05007211 identifies where a full package database is located::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007212
7213 [oe-packages]
7214 baseurl=http://my.server/rpm
7215
7216 This example informs DNF about a single
7217 package database that contains all the package index information for
7218 all supported architectures.
7219
7220Once you have informed DNF where to find the package databases, you need
7221to fetch them:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007222
7223.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007224
7225 # dnf makecache
7226
7227DNF is now able to find, install, and
7228upgrade packages from the specified repository or repositories.
7229
7230.. note::
7231
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007232 See the `DNF documentation <https://dnf.readthedocs.io/en/latest/>`__ for
7233 additional information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007234
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007235Using IPK
7236^^^^^^^^^
7237
7238The ``opkg`` application performs runtime package management of IPK
7239packages. You must perform an initial setup for ``opkg`` on the target
7240machine if the
7241:term:`PACKAGE_FEED_ARCHS`,
7242:term:`PACKAGE_FEED_BASE_PATHS`,
7243and
7244:term:`PACKAGE_FEED_URIS`
7245variables have not been set or the target image was built before the
7246variables were set.
7247
7248The ``opkg`` application uses configuration files to find available
7249package databases. Thus, you need to create a configuration file inside
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00007250the ``/etc/opkg/`` directory, which informs ``opkg`` of any repository
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007251you want to use.
7252
7253As an example, suppose you are serving packages from a ``ipk/``
7254directory containing the ``i586``, ``all``, and ``qemux86`` databases
7255through an HTTP server named ``my.server``. On the target, create a
7256configuration file (e.g. ``my_repo.conf``) inside the ``/etc/opkg/``
7257directory containing the following:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007258
7259.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007260
7261 src/gz all http://my.server/ipk/all
7262 src/gz i586 http://my.server/ipk/i586
7263 src/gz qemux86 http://my.server/ipk/qemux86
7264
7265Next, instruct ``opkg`` to fetch the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007266repository information:
7267
7268.. code-block:: none
7269
7270 # opkg update
7271
7272The ``opkg`` application is now able to find, install, and upgrade packages
7273from the specified repository.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007274
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007275Using DEB
7276^^^^^^^^^
7277
7278The ``apt`` application performs runtime package management of DEB
7279packages. This application uses a source list file to find available
7280package databases. You must perform an initial setup for ``apt`` on the
7281target machine if the
7282:term:`PACKAGE_FEED_ARCHS`,
7283:term:`PACKAGE_FEED_BASE_PATHS`,
7284and
7285:term:`PACKAGE_FEED_URIS`
7286variables have not been set or the target image was built before the
7287variables were set.
7288
7289To inform ``apt`` of the repository you want to use, you might create a
7290list file (e.g. ``my_repo.list``) inside the
7291``/etc/apt/sources.list.d/`` directory. As an example, suppose you are
7292serving packages from a ``deb/`` directory containing the ``i586``,
7293``all``, and ``qemux86`` databases through an HTTP server named
7294``my.server``. The list file should contain:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007295
7296.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007297
7298 deb http://my.server/deb/all ./
7299 deb http://my.server/deb/i586 ./
7300 deb http://my.server/deb/qemux86 ./
7301
7302Next, instruct the ``apt`` application
7303to fetch the repository information:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007304
7305.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007306
Andrew Geisslereff27472021-10-29 15:35:00 -05007307 $ sudo apt update
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007308
7309After this step,
7310``apt`` is able to find, install, and upgrade packages from the
7311specified repository.
7312
7313Generating and Using Signed Packages
7314------------------------------------
7315
7316In order to add security to RPM packages used during a build, you can
7317take steps to securely sign them. Once a signature is verified, the
7318OpenEmbedded build system can use the package in the build. If security
Andrew Geissler595f6302022-01-24 19:11:47 +00007319fails for a signed package, the build system stops the build.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007320
7321This section describes how to sign RPM packages during a build and how
7322to use signed package feeds (repositories) when doing a build.
7323
7324Signing RPM Packages
7325~~~~~~~~~~~~~~~~~~~~
7326
7327To enable signing RPM packages, you must set up the following
7328configurations in either your ``local.config`` or ``distro.config``
Andrew Geisslerc926e172021-05-07 16:11:35 -05007329file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007330
7331 # Inherit sign_rpm.bbclass to enable signing functionality
7332 INHERIT += " sign_rpm"
7333 # Define the GPG key that will be used for signing.
7334 RPM_GPG_NAME = "key_name"
7335 # Provide passphrase for the key
7336 RPM_GPG_PASSPHRASE = "passphrase"
7337
7338.. note::
7339
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007340 Be sure to supply appropriate values for both `key_name` and
7341 `passphrase`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007342
7343Aside from the ``RPM_GPG_NAME`` and ``RPM_GPG_PASSPHRASE`` variables in
William A. Kennington IIIac69b482021-06-02 12:28:27 -07007344the previous example, two optional variables related to signing are available:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007345
7346- *GPG_BIN:* Specifies a ``gpg`` binary/wrapper that is executed
7347 when the package is signed.
7348
7349- *GPG_PATH:* Specifies the ``gpg`` home directory used when the
7350 package is signed.
7351
7352Processing Package Feeds
7353~~~~~~~~~~~~~~~~~~~~~~~~
7354
7355In addition to being able to sign RPM packages, you can also enable
7356signed package feeds for IPK and RPM packages.
7357
7358The steps you need to take to enable signed package feed use are similar
7359to the steps used to sign RPM packages. You must define the following in
Andrew Geisslerc926e172021-05-07 16:11:35 -05007360your ``local.config`` or ``distro.config`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007361
7362 INHERIT += "sign_package_feed"
7363 PACKAGE_FEED_GPG_NAME = "key_name"
7364 PACKAGE_FEED_GPG_PASSPHRASE_FILE = "path_to_file_containing_passphrase"
7365
William A. Kennington IIIac69b482021-06-02 12:28:27 -07007366For signed package feeds, the passphrase must be specified in a separate file,
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007367which is pointed to by the ``PACKAGE_FEED_GPG_PASSPHRASE_FILE``
7368variable. Regarding security, keeping a plain text passphrase out of the
7369configuration is more secure.
7370
7371Aside from the ``PACKAGE_FEED_GPG_NAME`` and
7372``PACKAGE_FEED_GPG_PASSPHRASE_FILE`` variables, three optional variables
William A. Kennington IIIac69b482021-06-02 12:28:27 -07007373related to signed package feeds are available:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007374
7375- *GPG_BIN* Specifies a ``gpg`` binary/wrapper that is executed
7376 when the package is signed.
7377
7378- *GPG_PATH:* Specifies the ``gpg`` home directory used when the
7379 package is signed.
7380
7381- *PACKAGE_FEED_GPG_SIGNATURE_TYPE:* Specifies the type of ``gpg``
7382 signature. This variable applies only to RPM and IPK package feeds.
7383 Allowable values for the ``PACKAGE_FEED_GPG_SIGNATURE_TYPE`` are
7384 "ASC", which is the default and specifies ascii armored, and "BIN",
7385 which specifies binary.
7386
7387Testing Packages With ptest
7388---------------------------
7389
7390A Package Test (ptest) runs tests against packages built by the
7391OpenEmbedded build system on the target machine. A ptest contains at
7392least two items: the actual test, and a shell script (``run-ptest``)
7393that starts the test. The shell script that starts the test must not
Andrew Geissler615f2f12022-07-15 14:00:58 -05007394contain the actual test --- the script only starts the test. On the other
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007395hand, the test can be anything from a simple shell script that runs a
7396binary and checks the output to an elaborate system of test binaries and
7397data files.
7398
Andrew Geisslerc926e172021-05-07 16:11:35 -05007399The test generates output in the format used by Automake::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007400
7401 result: testname
7402
7403where the result can be ``PASS``, ``FAIL``, or ``SKIP``, and
7404the testname can be any identifying string.
7405
7406For a list of Yocto Project recipes that are already enabled with ptest,
Andrew Geissler09209ee2020-12-13 08:44:15 -06007407see the :yocto_wiki:`Ptest </Ptest>` wiki page.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007408
7409.. note::
7410
7411 A recipe is "ptest-enabled" if it inherits the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007412 :ref:`ptest <ref-classes-ptest>` class.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007413
7414Adding ptest to Your Build
7415~~~~~~~~~~~~~~~~~~~~~~~~~~
7416
Patrick Williams2390b1b2022-11-03 13:47:49 -05007417To add package testing to your build, add the :term:`DISTRO_FEATURES` and
7418:term:`EXTRA_IMAGE_FEATURES` variables to your ``local.conf`` file, which
7419is found in the :term:`Build Directory`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007420
Patrick Williams0ca19cc2021-08-16 14:03:13 -05007421 DISTRO_FEATURES:append = " ptest"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007422 EXTRA_IMAGE_FEATURES += "ptest-pkgs"
7423
7424Once your build is complete, the ptest files are installed into the
7425``/usr/lib/package/ptest`` directory within the image, where ``package``
7426is the name of the package.
7427
7428Running ptest
7429~~~~~~~~~~~~~
7430
7431The ``ptest-runner`` package installs a shell script that loops through
7432all installed ptest test suites and runs them in sequence. Consequently,
7433you might want to add this package to your image.
7434
7435Getting Your Package Ready
7436~~~~~~~~~~~~~~~~~~~~~~~~~~
7437
7438In order to enable a recipe to run installed ptests on target hardware,
7439you need to prepare the recipes that build the packages you want to
7440test. Here is what you have to do for each recipe:
7441
7442- *Be sure the recipe inherits
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007443 the* :ref:`ptest <ref-classes-ptest>` *class:*
Andrew Geisslerc926e172021-05-07 16:11:35 -05007444 Include the following line in each recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007445
7446 inherit ptest
7447
7448- *Create run-ptest:* This script starts your test. Locate the
7449 script where you will refer to it using
7450 :term:`SRC_URI`. Here is an
Andrew Geisslerc926e172021-05-07 16:11:35 -05007451 example that starts a test for ``dbus``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007452
7453 #!/bin/sh
7454 cd test
7455 make -k runtest-TESTS
7456
7457- *Ensure dependencies are met:* If the test adds build or runtime
7458 dependencies that normally do not exist for the package (such as
7459 requiring "make" to run the test suite), use the
7460 :term:`DEPENDS` and
7461 :term:`RDEPENDS` variables in
7462 your recipe in order for the package to meet the dependencies. Here
Andrew Geisslerc926e172021-05-07 16:11:35 -05007463 is an example where the package has a runtime dependency on "make"::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007464
Patrick Williams0ca19cc2021-08-16 14:03:13 -05007465 RDEPENDS:${PN}-ptest += "make"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007466
7467- *Add a function to build the test suite:* Not many packages support
7468 cross-compilation of their test suites. Consequently, you usually
7469 need to add a cross-compilation function to the package.
7470
7471 Many packages based on Automake compile and run the test suite by
7472 using a single command such as ``make check``. However, the host
7473 ``make check`` builds and runs on the same computer, while
7474 cross-compiling requires that the package is built on the host but
7475 executed for the target architecture (though often, as in the case
7476 for ptest, the execution occurs on the host). The built version of
7477 Automake that ships with the Yocto Project includes a patch that
7478 separates building and execution. Consequently, packages that use the
7479 unaltered, patched version of ``make check`` automatically
7480 cross-compiles.
7481
7482 Regardless, you still must add a ``do_compile_ptest`` function to
7483 build the test suite. Add a function similar to the following to your
Andrew Geisslerc926e172021-05-07 16:11:35 -05007484 recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007485
7486 do_compile_ptest() {
7487 oe_runmake buildtest-TESTS
7488 }
7489
7490- *Ensure special configurations are set:* If the package requires
7491 special configurations prior to compiling the test code, you must
7492 insert a ``do_configure_ptest`` function into the recipe.
7493
7494- *Install the test suite:* The ``ptest`` class automatically copies
7495 the file ``run-ptest`` to the target and then runs make
7496 ``install-ptest`` to run the tests. If this is not enough, you need
7497 to create a ``do_install_ptest`` function and make sure it gets
7498 called after the "make install-ptest" completes.
7499
7500Creating Node Package Manager (NPM) Packages
7501--------------------------------------------
7502
Patrick Williams7784c422022-11-17 07:29:11 -06007503:wikipedia:`NPM <Npm_(software)>` is a package
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007504manager for the JavaScript programming language. The Yocto Project
Andrew Geissler09209ee2020-12-13 08:44:15 -06007505supports the NPM :ref:`fetcher <bitbake:bitbake-user-manual/bitbake-user-manual-fetching:fetchers>`. You can
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007506use this fetcher in combination with
Andrew Geissler09209ee2020-12-13 08:44:15 -06007507:doc:`devtool </ref-manual/devtool-reference>` to create
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007508recipes that produce NPM packages.
7509
William A. Kennington IIIac69b482021-06-02 12:28:27 -07007510There are two workflows that allow you to create NPM packages using
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007511``devtool``: the NPM registry modules method and the NPM project code
7512method.
7513
7514.. note::
7515
7516 While it is possible to create NPM recipes manually, using
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007517 ``devtool`` is far simpler.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007518
7519Additionally, some requirements and caveats exist.
7520
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007521Requirements and Caveats
7522~~~~~~~~~~~~~~~~~~~~~~~~
7523
7524You need to be aware of the following before using ``devtool`` to create
7525NPM packages:
7526
7527- Of the two methods that you can use ``devtool`` to create NPM
7528 packages, the registry approach is slightly simpler. However, you
7529 might consider the project approach because you do not have to
Patrick Williams2390b1b2022-11-03 13:47:49 -05007530 publish your module in the `NPM registry <https://docs.npmjs.com/misc/registry>`__,
7531 which is NPM's public registry.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007532
7533- Be familiar with
Andrew Geissler09209ee2020-12-13 08:44:15 -06007534 :doc:`devtool </ref-manual/devtool-reference>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007535
7536- The NPM host tools need the native ``nodejs-npm`` package, which is
7537 part of the OpenEmbedded environment. You need to get the package by
Patrick Williams2390b1b2022-11-03 13:47:49 -05007538 cloning the :oe_git:`meta-openembedded </meta-openembedded>`
7539 repository. Be sure to add the path to your local copy
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007540 to your ``bblayers.conf`` file.
7541
7542- ``devtool`` cannot detect native libraries in module dependencies.
7543 Consequently, you must manually add packages to your recipe.
7544
7545- While deploying NPM packages, ``devtool`` cannot determine which
7546 dependent packages are missing on the target (e.g. the node runtime
7547 ``nodejs``). Consequently, you need to find out what files are
7548 missing and be sure they are on the target.
7549
7550- Although you might not need NPM to run your node package, it is
7551 useful to have NPM on your target. The NPM package name is
7552 ``nodejs-npm``.
7553
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007554Using the Registry Modules Method
7555~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7556
7557This section presents an example that uses the ``cute-files`` module,
7558which is a file browser web application.
7559
7560.. note::
7561
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007562 You must know the ``cute-files`` module version.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007563
7564The first thing you need to do is use ``devtool`` and the NPM fetcher to
Andrew Geisslerc926e172021-05-07 16:11:35 -05007565create the recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007566
7567 $ devtool add "npm://registry.npmjs.org;package=cute-files;version=1.0.2"
7568
7569The
7570``devtool add`` command runs ``recipetool create`` and uses the same
7571fetch URI to download each dependency and capture license details where
7572possible. The result is a generated recipe.
7573
Andrew Geissler615f2f12022-07-15 14:00:58 -05007574After running for quite a long time, in particular building the
7575``nodejs-native`` package, the command should end as follows::
7576
7577 INFO: Recipe /home/.../build/workspace/recipes/cute-files/cute-files_1.0.2.bb has been automatically created; further editing may be required to make it fully functional
7578
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007579The recipe file is fairly simple and contains every license that
7580``recipetool`` finds and includes the licenses in the recipe's
7581:term:`LIC_FILES_CHKSUM`
7582variables. You need to examine the variables and look for those with
7583"unknown" in the :term:`LICENSE`
7584field. You need to track down the license information for "unknown"
7585modules and manually add the information to the recipe.
7586
7587``recipetool`` creates a "shrinkwrap" file for your recipe. Shrinkwrap
7588files capture the version of all dependent modules. Many packages do not
Andrew Geissler615f2f12022-07-15 14:00:58 -05007589provide shrinkwrap files but ``recipetool`` will create a shrinkwrap file as it
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007590runs.
7591
7592.. note::
7593
7594 A package is created for each sub-module. This policy is the only
7595 practical way to have the licenses for all of the dependencies
7596 represented in the license manifest of the image.
7597
Andrew Geisslerc926e172021-05-07 16:11:35 -05007598The ``devtool edit-recipe`` command lets you take a look at the recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007599
7600 $ devtool edit-recipe cute-files
Andrew Geissler615f2f12022-07-15 14:00:58 -05007601 # Recipe created by recipetool
7602 # This is the basis of a recipe and may need further editing in order to be fully functional.
7603 # (Feel free to remove these comments when editing.)
7604
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007605 SUMMARY = "Turn any folder on your computer into a cute file browser, available on the local network."
Andrew Geissler615f2f12022-07-15 14:00:58 -05007606 # WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is
7607 # your responsibility to verify that the values are complete and correct.
7608 #
7609 # NOTE: multiple licenses have been detected; they have been separated with &
7610 # in the LICENSE value for now since it is a reasonable assumption that all
7611 # of the licenses apply. If instead there is a choice between the multiple
7612 # licenses then you should change the value to separate the licenses with |
7613 # instead of &. If there is any doubt, check the accompanying documentation
7614 # to determine which situation is applicable.
7615
7616 SUMMARY = "Turn any folder on your computer into a cute file browser, available on the local network."
7617 LICENSE = "BSD-3-Clause & ISC & MIT"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007618 LIC_FILES_CHKSUM = "file://LICENSE;md5=71d98c0a1db42956787b1909c74a86ca \
Andrew Geissler615f2f12022-07-15 14:00:58 -05007619 file://node_modules/accepts/LICENSE;md5=bf1f9ad1e2e1d507aef4883fff7103de \
7620 file://node_modules/array-flatten/LICENSE;md5=44088ba57cb871a58add36ce51b8de08 \
7621 ...
7622 file://node_modules/cookie-signature/Readme.md;md5=57ae8b42de3dd0c1f22d5f4cf191e15a"
7623
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007624 SRC_URI = " \
7625 npm://registry.npmjs.org/;package=cute-files;version=${PV} \
7626 npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \
7627 "
Andrew Geissler615f2f12022-07-15 14:00:58 -05007628
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007629 S = "${WORKDIR}/npm"
Andrew Geissler615f2f12022-07-15 14:00:58 -05007630
Patrick Williams213cb262021-08-07 19:21:33 -05007631 inherit npm
Andrew Geissler615f2f12022-07-15 14:00:58 -05007632
Patrick Williams0ca19cc2021-08-16 14:03:13 -05007633 LICENSE:${PN} = "MIT"
7634 LICENSE:${PN}-accepts = "MIT"
7635 LICENSE:${PN}-array-flatten = "MIT"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007636 ...
Patrick Williams0ca19cc2021-08-16 14:03:13 -05007637 LICENSE:${PN}-vary = "MIT"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007638
William A. Kennington IIIac69b482021-06-02 12:28:27 -07007639Here are three key points in the previous example:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007640
7641- :term:`SRC_URI` uses the NPM
7642 scheme so that the NPM fetcher is used.
7643
7644- ``recipetool`` collects all the license information. If a
7645 sub-module's license is unavailable, the sub-module's name appears in
7646 the comments.
7647
7648- The ``inherit npm`` statement causes the
7649 :ref:`npm <ref-classes-npm>` class to package
7650 up all the modules.
7651
Andrew Geisslerc926e172021-05-07 16:11:35 -05007652You can run the following command to build the ``cute-files`` package::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007653
7654 $ devtool build cute-files
7655
7656Remember that ``nodejs`` must be installed on
7657the target before your package.
7658
7659Assuming 192.168.7.2 for the target's IP address, use the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05007660command to deploy your package::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007661
7662 $ devtool deploy-target -s cute-files root@192.168.7.2
7663
7664Once the package is installed on the target, you can
Andrew Geissler615f2f12022-07-15 14:00:58 -05007665test the application to show the contents of any directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007666
7667 $ cd /usr/lib/node_modules/cute-files
Andrew Geissler615f2f12022-07-15 14:00:58 -05007668 $ cute-files
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007669
7670On a browser,
7671go to ``http://192.168.7.2:3000`` and you see the following:
7672
7673.. image:: figures/cute-files-npm-example.png
Andrew Geisslerd5838332022-05-27 11:33:10 -05007674 :width: 100%
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007675
7676You can find the recipe in ``workspace/recipes/cute-files``. You can use
7677the recipe in any layer you choose.
7678
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007679Using the NPM Projects Code Method
7680~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7681
7682Although it is useful to package modules already in the NPM registry,
7683adding ``node.js`` projects under development is a more common developer
7684use case.
7685
7686This section covers the NPM projects code method, which is very similar
7687to the "registry" approach described in the previous section. In the NPM
7688projects method, you provide ``devtool`` with an URL that points to the
7689source files.
7690
7691Replicating the same example, (i.e. ``cute-files``) use the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05007692command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007693
7694 $ devtool add https://github.com/martinaglv/cute-files.git
7695
Andrew Geissler615f2f12022-07-15 14:00:58 -05007696The recipe this command generates is very similar to the recipe created in
Andrew Geissler09036742021-06-25 14:25:14 -05007697the previous section. However, the :term:`SRC_URI` looks like the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007698
7699 SRC_URI = " \
Andrew Geissler615f2f12022-07-15 14:00:58 -05007700 git://github.com/martinaglv/cute-files.git;protocol=https;branch=master \
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007701 npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \
7702 "
7703
7704In this example,
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007705the main module is taken from the Git repository and dependencies are
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007706taken from the NPM registry. Other than those differences, the recipe is
7707basically the same between the two methods. You can build and deploy the
7708package exactly as described in the previous section that uses the
7709registry modules method.
7710
7711Adding custom metadata to packages
7712----------------------------------
7713
7714The variable
7715:term:`PACKAGE_ADD_METADATA`
7716can be used to add additional metadata to packages. This is reflected in
7717the package control/spec file. To take the ipk format for example, the
7718CONTROL file stored inside would contain the additional metadata as
7719additional lines.
7720
7721The variable can be used in multiple ways, including using suffixes to
7722set it for a specific package type and/or package. Note that the order
7723of precedence is the same as this list:
7724
Patrick Williams0ca19cc2021-08-16 14:03:13 -05007725- ``PACKAGE_ADD_METADATA_<PKGTYPE>:<PN>``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007726
7727- ``PACKAGE_ADD_METADATA_<PKGTYPE>``
7728
Patrick Williams0ca19cc2021-08-16 14:03:13 -05007729- ``PACKAGE_ADD_METADATA:<PN>``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007730
Andrew Geissler09036742021-06-25 14:25:14 -05007731- :term:`PACKAGE_ADD_METADATA`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007732
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007733`<PKGTYPE>` is a parameter and expected to be a distinct name of specific
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007734package type:
7735
7736- IPK for .ipk packages
7737
7738- DEB for .deb packages
7739
7740- RPM for .rpm packages
7741
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007742`<PN>` is a parameter and expected to be a package name.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007743
7744The variable can contain multiple [one-line] metadata fields separated
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007745by the literal sequence '\\n'. The separator can be redefined using the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007746variable flag ``separator``.
7747
William A. Kennington IIIac69b482021-06-02 12:28:27 -07007748Here is an example that adds two custom fields for ipk
Andrew Geisslerc926e172021-05-07 16:11:35 -05007749packages::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007750
7751 PACKAGE_ADD_METADATA_IPK = "Vendor: CustomIpk\nGroup:Applications/Spreadsheets"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007752
7753Efficiently Fetching Source Files During a Build
7754================================================
7755
7756The OpenEmbedded build system works with source files located through
7757the :term:`SRC_URI` variable. When
7758you build something using BitBake, a big part of the operation is
7759locating and downloading all the source tarballs. For images,
7760downloading all the source for various packages can take a significant
7761amount of time.
7762
7763This section shows you how you can use mirrors to speed up fetching
7764source files and how you can pre-fetch files all of which leads to more
7765efficient use of resources and time.
7766
7767Setting up Effective Mirrors
7768----------------------------
7769
7770A good deal that goes into a Yocto Project build is simply downloading
7771all of the source tarballs. Maybe you have been working with another
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00007772build system for which you have built up a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007773sizable directory of source tarballs. Or, perhaps someone else has such
7774a directory for which you have read access. If so, you can save time by
7775adding statements to your configuration file so that the build process
7776checks local directories first for existing tarballs before checking the
7777Internet.
7778
Andrew Geisslerc926e172021-05-07 16:11:35 -05007779Here is an efficient way to set it up in your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007780
7781 SOURCE_MIRROR_URL ?= "file:///home/you/your-download-dir/"
7782 INHERIT += "own-mirrors"
7783 BB_GENERATE_MIRROR_TARBALLS = "1"
7784 # BB_NO_NETWORK = "1"
7785
7786In the previous example, the
7787:term:`BB_GENERATE_MIRROR_TARBALLS`
7788variable causes the OpenEmbedded build system to generate tarballs of
7789the Git repositories and store them in the
7790:term:`DL_DIR` directory. Due to
7791performance reasons, generating and storing these tarballs is not the
7792build system's default behavior.
7793
7794You can also use the
7795:term:`PREMIRRORS` variable. For
7796an example, see the variable's glossary entry in the Yocto Project
7797Reference Manual.
7798
7799Getting Source Files and Suppressing the Build
7800----------------------------------------------
7801
7802Another technique you can use to ready yourself for a successive string
7803of build operations, is to pre-fetch all the source files without
7804actually starting a build. This technique lets you work through any
7805download issues and ultimately gathers all the source files into your
7806download directory :ref:`structure-build-downloads`,
7807which is located with :term:`DL_DIR`.
7808
7809Use the following BitBake command form to fetch all the necessary
Andrew Geisslerc926e172021-05-07 16:11:35 -05007810sources without starting the build::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007811
7812 $ bitbake target --runall=fetch
7813
7814This
7815variation of the BitBake command guarantees that you have all the
7816sources for that BitBake target should you disconnect from the Internet
7817and want to do the build later offline.
7818
7819Selecting an Initialization Manager
7820===================================
7821
7822By default, the Yocto Project uses SysVinit as the initialization
William A. Kennington IIIac69b482021-06-02 12:28:27 -07007823manager. However, there is also support for systemd, which is a full
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007824replacement for init with parallel starting of services, reduced shell
7825overhead and other features that are used by many distributions.
7826
7827Within the system, SysVinit treats system components as services. These
7828services are maintained as shell scripts stored in the ``/etc/init.d/``
7829directory. Services organize into different run levels. This
7830organization is maintained by putting links to the services in the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007831``/etc/rcN.d/`` directories, where `N/` is one of the following options:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007832"S", "0", "1", "2", "3", "4", "5", or "6".
7833
7834.. note::
7835
7836 Each runlevel has a dependency on the previous runlevel. This
7837 dependency allows the services to work properly.
7838
7839In comparison, systemd treats components as units. Using units is a
7840broader concept as compared to using a service. A unit includes several
7841different types of entities. Service is one of the types of entities.
7842The runlevel concept in SysVinit corresponds to the concept of a target
7843in systemd, where target is also a type of supported unit.
7844
7845In a SysVinit-based system, services load sequentially (i.e. one by one)
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007846during init and parallelization is not supported. With systemd, services
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007847start in parallel. Needless to say, the method can have an impact on
7848system startup performance.
7849
7850If you want to use SysVinit, you do not have to do anything. But, if you
7851want to use systemd, you must take some steps as described in the
7852following sections.
7853
7854Using systemd Exclusively
7855-------------------------
7856
Andrew Geisslerc926e172021-05-07 16:11:35 -05007857Set these variables in your distribution configuration file as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007858
Patrick Williams0ca19cc2021-08-16 14:03:13 -05007859 DISTRO_FEATURES:append = " systemd"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007860 VIRTUAL-RUNTIME_init_manager = "systemd"
7861
7862You can also prevent the SysVinit distribution feature from
Andrew Geisslerc926e172021-05-07 16:11:35 -05007863being automatically enabled as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007864
7865 DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
7866
7867Doing so removes any
7868redundant SysVinit scripts.
7869
7870To remove initscripts from your image altogether, set this variable
Andrew Geisslerc926e172021-05-07 16:11:35 -05007871also::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007872
7873 VIRTUAL-RUNTIME_initscripts = ""
7874
7875For information on the backfill variable, see
7876:term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`.
7877
7878Using systemd for the Main Image and Using SysVinit for the Rescue Image
7879------------------------------------------------------------------------
7880
Andrew Geisslerc926e172021-05-07 16:11:35 -05007881Set these variables in your distribution configuration file as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007882
Patrick Williams0ca19cc2021-08-16 14:03:13 -05007883 DISTRO_FEATURES:append = " systemd"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007884 VIRTUAL-RUNTIME_init_manager = "systemd"
7885
7886Doing so causes your main image to use the
7887``packagegroup-core-boot.bb`` recipe and systemd. The rescue/minimal
7888image cannot use this package group. However, it can install SysVinit
7889and the appropriate packages will have support for both systemd and
7890SysVinit.
7891
Andrew Geissler9aee5002022-03-30 16:27:02 +00007892Using systemd-journald without a traditional syslog daemon
7893----------------------------------------------------------
7894
7895Counter-intuitively, ``systemd-journald`` is not a syslog runtime or provider,
7896and the proper way to use systemd-journald as your sole logging mechanism is to
7897effectively disable syslog entirely by setting these variables in your distribution
7898configuration file::
7899
7900 VIRTUAL-RUNTIME_syslog = ""
7901 VIRTUAL-RUNTIME_base-utils-syslog = ""
7902
7903Doing so will prevent ``rsyslog`` / ``busybox-syslog`` from being pulled in by
7904default, leaving only ``journald``.
7905
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007906Selecting a Device Manager
7907==========================
7908
7909The Yocto Project provides multiple ways to manage the device manager
7910(``/dev``):
7911
Andrew Geissler5199d832021-09-24 16:47:35 -05007912- Persistent and Pre-Populated ``/dev``: For this case, the ``/dev``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007913 directory is persistent and the required device nodes are created
7914 during the build.
7915
7916- Use ``devtmpfs`` with a Device Manager: For this case, the ``/dev``
7917 directory is provided by the kernel as an in-memory file system and
7918 is automatically populated by the kernel at runtime. Additional
7919 configuration of device nodes is done in user space by a device
7920 manager like ``udev`` or ``busybox-mdev``.
7921
Andrew Geissler5199d832021-09-24 16:47:35 -05007922Using Persistent and Pre-Populated ``/dev``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007923--------------------------------------------
7924
7925To use the static method for device population, you need to set the
7926:term:`USE_DEVFS` variable to "0"
Andrew Geisslerc926e172021-05-07 16:11:35 -05007927as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007928
7929 USE_DEVFS = "0"
7930
7931The content of the resulting ``/dev`` directory is defined in a Device
7932Table file. The
7933:term:`IMAGE_DEVICE_TABLES`
7934variable defines the Device Table to use and should be set in the
7935machine or distro configuration file. Alternatively, you can set this
7936variable in your ``local.conf`` configuration file.
7937
Andrew Geissler09036742021-06-25 14:25:14 -05007938If you do not define the :term:`IMAGE_DEVICE_TABLES` variable, the default
Andrew Geisslerc926e172021-05-07 16:11:35 -05007939``device_table-minimal.txt`` is used::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007940
7941 IMAGE_DEVICE_TABLES = "device_table-mymachine.txt"
7942
7943The population is handled by the ``makedevs`` utility during image
7944creation:
7945
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007946Using ``devtmpfs`` and a Device Manager
7947---------------------------------------
7948
7949To use the dynamic method for device population, you need to use (or be
7950sure to set) the :term:`USE_DEVFS`
Andrew Geisslerc926e172021-05-07 16:11:35 -05007951variable to "1", which is the default::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007952
7953 USE_DEVFS = "1"
7954
7955With this
7956setting, the resulting ``/dev`` directory is populated by the kernel
7957using ``devtmpfs``. Make sure the corresponding kernel configuration
7958variable ``CONFIG_DEVTMPFS`` is set when building you build a Linux
7959kernel.
7960
7961All devices created by ``devtmpfs`` will be owned by ``root`` and have
7962permissions ``0600``.
7963
7964To have more control over the device nodes, you can use a device manager
7965like ``udev`` or ``busybox-mdev``. You choose the device manager by
7966defining the ``VIRTUAL-RUNTIME_dev_manager`` variable in your machine or
7967distro configuration file. Alternatively, you can set this variable in
Andrew Geisslerc926e172021-05-07 16:11:35 -05007968your ``local.conf`` configuration file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007969
7970 VIRTUAL-RUNTIME_dev_manager = "udev"
7971
7972 # Some alternative values
7973 # VIRTUAL-RUNTIME_dev_manager = "busybox-mdev"
7974 # VIRTUAL-RUNTIME_dev_manager = "systemd"
7975
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007976Using an External SCM
7977=====================
7978
7979If you're working on a recipe that pulls from an external Source Code
7980Manager (SCM), it is possible to have the OpenEmbedded build system
7981notice new recipe changes added to the SCM and then build the resulting
7982packages that depend on the new recipes by using the latest versions.
7983This only works for SCMs from which it is possible to get a sensible
7984revision number for changes. Currently, you can do this with Apache
7985Subversion (SVN), Git, and Bazaar (BZR) repositories.
7986
7987To enable this behavior, the :term:`PV` of
7988the recipe needs to reference
Andrew Geisslerc926e172021-05-07 16:11:35 -05007989:term:`SRCPV`. Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007990
7991 PV = "1.2.3+git${SRCPV}"
7992
7993Then, you can add the following to your
Andrew Geisslerc926e172021-05-07 16:11:35 -05007994``local.conf``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007995
Patrick Williams0ca19cc2021-08-16 14:03:13 -05007996 SRCREV:pn-PN = "${AUTOREV}"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007997
7998:term:`PN` is the name of the recipe for
7999which you want to enable automatic source revision updating.
8000
8001If you do not want to update your local configuration file, you can add
Andrew Geisslerc926e172021-05-07 16:11:35 -05008002the following directly to the recipe to finish enabling the feature::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008003
8004 SRCREV = "${AUTOREV}"
8005
8006The Yocto Project provides a distribution named ``poky-bleeding``, whose
Andrew Geisslerc926e172021-05-07 16:11:35 -05008007configuration file contains the line::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008008
8009 require conf/distro/include/poky-floating-revisions.inc
8010
8011This line pulls in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05008012listed include file that contains numerous lines of exactly that form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008013
Patrick Williams0ca19cc2021-08-16 14:03:13 -05008014 #SRCREV:pn-opkg-native ?= "${AUTOREV}"
8015 #SRCREV:pn-opkg-sdk ?= "${AUTOREV}"
8016 #SRCREV:pn-opkg ?= "${AUTOREV}"
8017 #SRCREV:pn-opkg-utils-native ?= "${AUTOREV}"
8018 #SRCREV:pn-opkg-utils ?= "${AUTOREV}"
8019 SRCREV:pn-gconf-dbus ?= "${AUTOREV}"
8020 SRCREV:pn-matchbox-common ?= "${AUTOREV}"
8021 SRCREV:pn-matchbox-config-gtk ?= "${AUTOREV}"
8022 SRCREV:pn-matchbox-desktop ?= "${AUTOREV}"
8023 SRCREV:pn-matchbox-keyboard ?= "${AUTOREV}"
8024 SRCREV:pn-matchbox-panel-2 ?= "${AUTOREV}"
8025 SRCREV:pn-matchbox-themes-extra ?= "${AUTOREV}"
8026 SRCREV:pn-matchbox-terminal ?= "${AUTOREV}"
8027 SRCREV:pn-matchbox-wm ?= "${AUTOREV}"
8028 SRCREV:pn-settings-daemon ?= "${AUTOREV}"
8029 SRCREV:pn-screenshot ?= "${AUTOREV}"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008030 . . .
8031
8032These lines allow you to
8033experiment with building a distribution that tracks the latest
8034development source for numerous packages.
8035
8036.. note::
8037
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008038 The ``poky-bleeding`` distribution is not tested on a regular basis. Keep
8039 this in mind if you use it.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008040
8041Creating a Read-Only Root Filesystem
8042====================================
8043
8044Suppose, for security reasons, you need to disable your target device's
8045root filesystem's write permissions (i.e. you need a read-only root
8046filesystem). Or, perhaps you are running the device's operating system
8047from a read-only storage device. For either case, you can customize your
8048image for that behavior.
8049
8050.. note::
8051
8052 Supporting a read-only root filesystem requires that the system and
8053 applications do not try to write to the root filesystem. You must
8054 configure all parts of the target system to write elsewhere, or to
8055 gracefully fail in the event of attempting to write to the root
8056 filesystem.
8057
8058Creating the Root Filesystem
8059----------------------------
8060
8061To create the read-only root filesystem, simply add the
8062"read-only-rootfs" feature to your image, normally in one of two ways.
8063The first way is to add the "read-only-rootfs" image feature in the
Andrew Geissler09036742021-06-25 14:25:14 -05008064image's recipe file via the :term:`IMAGE_FEATURES` variable::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008065
8066 IMAGE_FEATURES += "read-only-rootfs"
8067
8068As an alternative, you can add the same feature
Patrick Williams2390b1b2022-11-03 13:47:49 -05008069from within your :term:`Build Directory`'s ``local.conf`` file with the
Andrew Geissler09036742021-06-25 14:25:14 -05008070associated :term:`EXTRA_IMAGE_FEATURES` variable, as in::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008071
8072 EXTRA_IMAGE_FEATURES = "read-only-rootfs"
8073
8074For more information on how to use these variables, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06008075":ref:`dev-manual/common-tasks:Customizing Images Using Custom \`\`IMAGE_FEATURES\`\` and \`\`EXTRA_IMAGE_FEATURES\`\``"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008076section. For information on the variables, see
8077:term:`IMAGE_FEATURES` and
8078:term:`EXTRA_IMAGE_FEATURES`.
8079
8080Post-Installation Scripts and Read-Only Root Filesystem
8081-------------------------------------------------------
8082
8083It is very important that you make sure all post-Installation
8084(``pkg_postinst``) scripts for packages that are installed into the
8085image can be run at the time when the root filesystem is created during
8086the build on the host system. These scripts cannot attempt to run during
Patrick Williams0ca19cc2021-08-16 14:03:13 -05008087the first boot on the target device. With the "read-only-rootfs" feature
8088enabled, the build system makes sure that all post-installation scripts
8089succeed at file system creation time. If any of these scripts
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008090still need to be run after the root filesystem is created, the build
8091immediately fails. These build-time checks ensure that the build fails
8092rather than the target device fails later during its initial boot
8093operation.
8094
8095Most of the common post-installation scripts generated by the build
8096system for the out-of-the-box Yocto Project are engineered so that they
8097can run during root filesystem creation (e.g. post-installation scripts
8098for caching fonts). However, if you create and add custom scripts, you
8099need to be sure they can be run during this file system creation.
8100
8101Here are some common problems that prevent post-installation scripts
8102from running during root filesystem creation:
8103
8104- *Not using $D in front of absolute paths:* The build system defines
8105 ``$``\ :term:`D` when the root
8106 filesystem is created. Furthermore, ``$D`` is blank when the script
8107 is run on the target device. This implies two purposes for ``$D``:
8108 ensuring paths are valid in both the host and target environments,
8109 and checking to determine which environment is being used as a method
8110 for taking appropriate actions.
8111
8112- *Attempting to run processes that are specific to or dependent on the
8113 target architecture:* You can work around these attempts by using
8114 native tools, which run on the host system, to accomplish the same
8115 tasks, or by alternatively running the processes under QEMU, which
8116 has the ``qemu_run_binary`` function. For more information, see the
8117 :ref:`qemu <ref-classes-qemu>` class.
8118
8119Areas With Write Access
8120-----------------------
8121
8122With the "read-only-rootfs" feature enabled, any attempt by the target
8123to write to the root filesystem at runtime fails. Consequently, you must
8124make sure that you configure processes and applications that attempt
8125these types of writes do so to directories with write access (e.g.
8126``/tmp`` or ``/var/run``).
8127
8128Maintaining Build Output Quality
8129================================
8130
8131Many factors can influence the quality of a build. For example, if you
8132upgrade a recipe to use a new version of an upstream software package or
8133you experiment with some new configuration options, subtle changes can
8134occur that you might not detect until later. Consider the case where
8135your recipe is using a newer version of an upstream package. In this
8136case, a new version of a piece of software might introduce an optional
8137dependency on another library, which is auto-detected. If that library
8138has already been built when the software is building, the software will
8139link to the built library and that library will be pulled into your
8140image along with the new software even if you did not want the library.
8141
8142The :ref:`buildhistory <ref-classes-buildhistory>`
William A. Kennington IIIac69b482021-06-02 12:28:27 -07008143class helps you maintain the quality of your build output. You
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008144can use the class to highlight unexpected and possibly unwanted changes
8145in the build output. When you enable build history, it records
8146information about the contents of each package and image and then
8147commits that information to a local Git repository where you can examine
8148the information.
8149
8150The remainder of this section describes the following:
8151
Andrew Geissler09209ee2020-12-13 08:44:15 -06008152- :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 -05008153
Andrew Geissler09209ee2020-12-13 08:44:15 -06008154- :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 -05008155
Andrew Geissler09209ee2020-12-13 08:44:15 -06008156- :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 -05008157
Andrew Geissler09209ee2020-12-13 08:44:15 -06008158- :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 -05008159
8160Enabling and Disabling Build History
8161------------------------------------
8162
8163Build history is disabled by default. To enable it, add the following
Patrick Williams2390b1b2022-11-03 13:47:49 -05008164:term:`INHERIT` statement and set the :term:`BUILDHISTORY_COMMIT` variable to
8165"1" at the end of your ``conf/local.conf`` file found in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05008166:term:`Build Directory`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008167
8168 INHERIT += "buildhistory"
8169 BUILDHISTORY_COMMIT = "1"
8170
8171Enabling build history as
8172previously described causes the OpenEmbedded build system to collect
8173build output information and commit it as a single commit to a local
Andrew Geissler09209ee2020-12-13 08:44:15 -06008174:ref:`overview-manual/development-environment:git` repository.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008175
8176.. note::
8177
8178 Enabling build history increases your build times slightly,
8179 particularly for images, and increases the amount of disk space used
8180 during the build.
8181
8182You can disable build history by removing the previous statements from
8183your ``conf/local.conf`` file.
8184
8185Understanding What the Build History Contains
8186---------------------------------------------
8187
Patrick Williams2390b1b2022-11-03 13:47:49 -05008188Build history information is kept in ``${``\ :term:`TOPDIR`\ ``}/buildhistory``
8189in the :term:`Build Directory` as defined by the :term:`BUILDHISTORY_DIR`
William A. Kennington IIIac69b482021-06-02 12:28:27 -07008190variable. Here is an example abbreviated listing:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008191
8192.. image:: figures/buildhistory.png
8193 :align: center
Andrew Geisslerd5838332022-05-27 11:33:10 -05008194 :width: 50%
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008195
William A. Kennington IIIac69b482021-06-02 12:28:27 -07008196At the top level, there is a ``metadata-revs`` file that lists the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008197revisions of the repositories for the enabled layers when the build was
8198produced. The rest of the data splits into separate ``packages``,
8199``images`` and ``sdk`` directories, the contents of which are described
8200as follows.
8201
8202Build History Package Information
8203~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8204
8205The history for each package contains a text file that has name-value
8206pairs with information about the package. For example,
8207``buildhistory/packages/i586-poky-linux/busybox/busybox/latest``
8208contains the following:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008209
8210.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008211
8212 PV = 1.22.1
8213 PR = r32
8214 RPROVIDES =
8215 RDEPENDS = glibc (>= 2.20) update-alternatives-opkg
8216 RRECOMMENDS = busybox-syslog busybox-udhcpc update-rc.d
8217 PKGSIZE = 540168
8218 FILES = /usr/bin/* /usr/sbin/* /usr/lib/busybox/* /usr/lib/lib*.so.* \
8219 /etc /com /var /bin/* /sbin/* /lib/*.so.* /lib/udev/rules.d \
8220 /usr/lib/udev/rules.d /usr/share/busybox /usr/lib/busybox/* \
8221 /usr/share/pixmaps /usr/share/applications /usr/share/idl \
8222 /usr/share/omf /usr/share/sounds /usr/lib/bonobo/servers
8223 FILELIST = /bin/busybox /bin/busybox.nosuid /bin/busybox.suid /bin/sh \
8224 /etc/busybox.links.nosuid /etc/busybox.links.suid
8225
8226Most of these
8227name-value pairs correspond to variables used to produce the package.
8228The exceptions are ``FILELIST``, which is the actual list of files in
8229the package, and ``PKGSIZE``, which is the total size of files in the
8230package in bytes.
8231
William A. Kennington IIIac69b482021-06-02 12:28:27 -07008232There is also a file that corresponds to the recipe from which the package
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008233came (e.g. ``buildhistory/packages/i586-poky-linux/busybox/latest``):
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008234
8235.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008236
8237 PV = 1.22.1
8238 PR = r32
8239 DEPENDS = initscripts kern-tools-native update-rc.d-native \
8240 virtual/i586-poky-linux-compilerlibs virtual/i586-poky-linux-gcc \
8241 virtual/libc virtual/update-alternatives
8242 PACKAGES = busybox-ptest busybox-httpd busybox-udhcpd busybox-udhcpc \
8243 busybox-syslog busybox-mdev busybox-hwclock busybox-dbg \
8244 busybox-staticdev busybox-dev busybox-doc busybox-locale busybox
8245
8246Finally, for those recipes fetched from a version control system (e.g.,
William A. Kennington IIIac69b482021-06-02 12:28:27 -07008247Git), there is a file that lists source revisions that are specified in
8248the recipe and the actual revisions used during the build. Listed
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008249and actual revisions might differ when
8250:term:`SRCREV` is set to
8251${:term:`AUTOREV`}. Here is an
8252example assuming
Andrew Geisslerc926e172021-05-07 16:11:35 -05008253``buildhistory/packages/qemux86-poky-linux/linux-yocto/latest_srcrev``)::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008254
8255 # SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
8256 SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
8257 # SRCREV_meta = "a227f20eff056e511d504b2e490f3774ab260d6f"
8258 SRCREV_meta ="a227f20eff056e511d504b2e490f3774ab260d6f"
8259
8260You can use the
8261``buildhistory-collect-srcrevs`` command with the ``-a`` option to
Andrew Geissler09036742021-06-25 14:25:14 -05008262collect the stored :term:`SRCREV` values from build history and report them
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008263in a format suitable for use in global configuration (e.g.,
8264``local.conf`` or a distro include file) to override floating
Andrew Geissler09036742021-06-25 14:25:14 -05008265:term:`AUTOREV` values to a fixed set of revisions. Here is some example
Andrew Geisslerc926e172021-05-07 16:11:35 -05008266output from this command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008267
8268 $ buildhistory-collect-srcrevs -a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008269 # all-poky-linux
Andrew Geissler9aee5002022-03-30 16:27:02 +00008270 SRCREV:pn-ca-certificates = "07de54fdcc5806bde549e1edf60738c6bccf50e8"
8271 SRCREV:pn-update-rc.d = "8636cf478d426b568c1be11dbd9346f67e03adac"
8272 # core2-64-poky-linux
8273 SRCREV:pn-binutils = "87d4632d36323091e731eb07b8aa65f90293da66"
8274 SRCREV:pn-btrfs-tools = "8ad326b2f28c044cb6ed9016d7c3285e23b673c8"
8275 SRCREV_bzip2-tests:pn-bzip2 = "f9061c030a25de5b6829e1abf373057309c734c0"
8276 SRCREV:pn-e2fsprogs = "02540dedd3ddc52c6ae8aaa8a95ce75c3f8be1c0"
8277 SRCREV:pn-file = "504206e53a89fd6eed71aeaf878aa3512418eab1"
8278 SRCREV_glibc:pn-glibc = "24962427071fa532c3c48c918e9d64d719cc8a6c"
8279 SRCREV:pn-gnome-desktop-testing = "e346cd4ed2e2102c9b195b614f3c642d23f5f6e7"
8280 SRCREV:pn-init-system-helpers = "dbd9197569c0935029acd5c9b02b84c68fd937ee"
8281 SRCREV:pn-kmod = "b6ecfc916a17eab8f93be5b09f4e4f845aabd3d1"
8282 SRCREV:pn-libnsl2 = "82245c0c58add79a8e34ab0917358217a70e5100"
8283 SRCREV:pn-libseccomp = "57357d2741a3b3d3e8425889a6b79a130e0fa2f3"
8284 SRCREV:pn-libxcrypt = "50cf2b6dd4fdf04309445f2eec8de7051d953abf"
8285 SRCREV:pn-ncurses = "51d0fd9cc3edb975f04224f29f777f8f448e8ced"
8286 SRCREV:pn-procps = "19a508ea121c0c4ac6d0224575a036de745eaaf8"
8287 SRCREV:pn-psmisc = "5fab6b7ab385080f1db725d6803136ec1841a15f"
8288 SRCREV:pn-ptest-runner = "bcb82804daa8f725b6add259dcef2067e61a75aa"
8289 SRCREV:pn-shared-mime-info = "18e558fa1c8b90b86757ade09a4ba4d6a6cf8f70"
8290 SRCREV:pn-zstd = "e47e674cd09583ff0503f0f6defd6d23d8b718d3"
8291 # qemux86_64-poky-linux
8292 SRCREV_machine:pn-linux-yocto = "20301aeb1a64164b72bc72af58802b315e025c9c"
8293 SRCREV_meta:pn-linux-yocto = "2d38a472b21ae343707c8bd64ac68a9eaca066a0"
8294 # x86_64-linux
8295 SRCREV:pn-binutils-cross-x86_64 = "87d4632d36323091e731eb07b8aa65f90293da66"
8296 SRCREV_glibc:pn-cross-localedef-native = "24962427071fa532c3c48c918e9d64d719cc8a6c"
8297 SRCREV_localedef:pn-cross-localedef-native = "794da69788cbf9bf57b59a852f9f11307663fa87"
8298 SRCREV:pn-debianutils-native = "de14223e5bffe15e374a441302c528ffc1cbed57"
8299 SRCREV:pn-libmodulemd-native = "ee80309bc766d781a144e6879419b29f444d94eb"
8300 SRCREV:pn-virglrenderer-native = "363915595e05fb252e70d6514be2f0c0b5ca312b"
8301 SRCREV:pn-zstd-native = "e47e674cd09583ff0503f0f6defd6d23d8b718d3"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008302
8303.. note::
8304
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008305 Here are some notes on using the ``buildhistory-collect-srcrevs`` command:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008306
Andrew Geissler09036742021-06-25 14:25:14 -05008307 - By default, only values where the :term:`SRCREV` was not hardcoded
Andrew Geissler5f350902021-07-23 13:09:54 -04008308 (usually when :term:`AUTOREV` is used) are reported. Use the ``-a``
8309 option to see all :term:`SRCREV` values.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008310
8311 - The output statements might not have any effect if overrides are
8312 applied elsewhere in the build system configuration. Use the
8313 ``-f`` option to add the ``forcevariable`` override to each output
8314 line if you need to work around this restriction.
8315
8316 - The script does apply special handling when building for multiple
8317 machines. However, the script does place a comment before each set
8318 of values that specifies which triplet to which they belong as
8319 previously shown (e.g., ``i586-poky-linux``).
8320
8321Build History Image Information
8322~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8323
8324The files produced for each image are as follows:
8325
8326- ``image-files:`` A directory containing selected files from the root
8327 filesystem. The files are defined by
8328 :term:`BUILDHISTORY_IMAGE_FILES`.
8329
8330- ``build-id.txt:`` Human-readable information about the build
8331 configuration and metadata source revisions. This file contains the
8332 full build header as printed by BitBake.
8333
8334- ``*.dot:`` Dependency graphs for the image that are compatible with
8335 ``graphviz``.
8336
8337- ``files-in-image.txt:`` A list of files in the image with
8338 permissions, owner, group, size, and symlink information.
8339
8340- ``image-info.txt:`` A text file containing name-value pairs with
8341 information about the image. See the following listing example for
8342 more information.
8343
8344- ``installed-package-names.txt:`` A list of installed packages by name
8345 only.
8346
8347- ``installed-package-sizes.txt:`` A list of installed packages ordered
8348 by size.
8349
8350- ``installed-packages.txt:`` A list of installed packages with full
8351 package filenames.
8352
8353.. note::
8354
8355 Installed package information is able to be gathered and produced
8356 even if package management is disabled for the final image.
8357
8358Here is an example of ``image-info.txt``:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008359
8360.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008361
8362 DISTRO = poky
Andrew Geissler9aee5002022-03-30 16:27:02 +00008363 DISTRO_VERSION = 3.4+snapshot-a0245d7be08f3d24ea1875e9f8872aa6bbff93be
8364 USER_CLASSES = buildstats
8365 IMAGE_CLASSES = qemuboot qemuboot license_image
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008366 IMAGE_FEATURES = debug-tweaks
8367 IMAGE_LINGUAS =
Andrew Geissler9aee5002022-03-30 16:27:02 +00008368 IMAGE_INSTALL = packagegroup-core-boot speex speexdsp
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008369 BAD_RECOMMENDATIONS =
8370 NO_RECOMMENDATIONS =
8371 PACKAGE_EXCLUDE =
Andrew Geissler9aee5002022-03-30 16:27:02 +00008372 ROOTFS_POSTPROCESS_COMMAND = write_package_manifest; license_create_manifest; cve_check_write_rootfs_manifest; ssh_allow_empty_password; ssh_allow_root_login; postinst_enable_logging; rootfs_update_timestamp; write_image_test_data; empty_var_volatile; sort_passwd; rootfs_reproducible;
8373 IMAGE_POSTPROCESS_COMMAND = buildhistory_get_imageinfo ;
8374 IMAGESIZE = 9265
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008375
8376Other than ``IMAGESIZE``,
8377which is the total size of the files in the image in Kbytes, the
8378name-value pairs are variables that may have influenced the content of
8379the image. This information is often useful when you are trying to
8380determine why a change in the package or file listings has occurred.
8381
8382Using Build History to Gather Image Information Only
8383~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8384
8385As you can see, build history produces image information, including
8386dependency graphs, so you can see why something was pulled into the
8387image. If you are just interested in this information and not interested
8388in collecting specific package or SDK information, you can enable
8389writing only image information without any history by adding the
8390following to your ``conf/local.conf`` file found in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05008391:term:`Build Directory`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008392
8393 INHERIT += "buildhistory"
8394 BUILDHISTORY_COMMIT = "0"
8395 BUILDHISTORY_FEATURES = "image"
8396
8397Here, you set the
8398:term:`BUILDHISTORY_FEATURES`
8399variable to use the image feature only.
8400
8401Build History SDK Information
8402~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8403
8404Build history collects similar information on the contents of SDKs (e.g.
8405``bitbake -c populate_sdk imagename``) as compared to information it
8406collects for images. Furthermore, this information differs depending on
8407whether an extensible or standard SDK is being produced.
8408
8409The following list shows the files produced for SDKs:
8410
8411- ``files-in-sdk.txt:`` A list of files in the SDK with permissions,
8412 owner, group, size, and symlink information. This list includes both
8413 the host and target parts of the SDK.
8414
8415- ``sdk-info.txt:`` A text file containing name-value pairs with
8416 information about the SDK. See the following listing example for more
8417 information.
8418
8419- ``sstate-task-sizes.txt:`` A text file containing name-value pairs
Patrick Williams2194f502022-10-16 14:26:09 -05008420 with information about task group sizes (e.g. :ref:`ref-tasks-populate_sysroot`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008421 tasks have a total size). The ``sstate-task-sizes.txt`` file exists
8422 only when an extensible SDK is created.
8423
8424- ``sstate-package-sizes.txt:`` A text file containing name-value pairs
8425 with information for the shared-state packages and sizes in the SDK.
8426 The ``sstate-package-sizes.txt`` file exists only when an extensible
8427 SDK is created.
8428
8429- ``sdk-files:`` A folder that contains copies of the files mentioned
8430 in ``BUILDHISTORY_SDK_FILES`` if the files are present in the output.
8431 Additionally, the default value of ``BUILDHISTORY_SDK_FILES`` is
8432 specific to the extensible SDK although you can set it differently if
8433 you would like to pull in specific files from the standard SDK.
8434
8435 The default files are ``conf/local.conf``, ``conf/bblayers.conf``,
8436 ``conf/auto.conf``, ``conf/locked-sigs.inc``, and
8437 ``conf/devtool.conf``. Thus, for an extensible SDK, these files get
8438 copied into the ``sdk-files`` directory.
8439
8440- The following information appears under each of the ``host`` and
8441 ``target`` directories for the portions of the SDK that run on the
8442 host and on the target, respectively:
8443
8444 .. note::
8445
8446 The following files for the most part are empty when producing an
8447 extensible SDK because this type of SDK is not constructed from
8448 packages as is the standard SDK.
8449
8450 - ``depends.dot:`` Dependency graph for the SDK that is compatible
8451 with ``graphviz``.
8452
8453 - ``installed-package-names.txt:`` A list of installed packages by
8454 name only.
8455
8456 - ``installed-package-sizes.txt:`` A list of installed packages
8457 ordered by size.
8458
8459 - ``installed-packages.txt:`` A list of installed packages with full
8460 package filenames.
8461
8462Here is an example of ``sdk-info.txt``:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008463
8464.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008465
8466 DISTRO = poky
8467 DISTRO_VERSION = 1.3+snapshot-20130327
8468 SDK_NAME = poky-glibc-i686-arm
8469 SDK_VERSION = 1.3+snapshot
8470 SDKMACHINE =
8471 SDKIMAGE_FEATURES = dev-pkgs dbg-pkgs
8472 BAD_RECOMMENDATIONS =
8473 SDKSIZE = 352712
8474
8475Other than ``SDKSIZE``, which is
8476the total size of the files in the SDK in Kbytes, the name-value pairs
8477are variables that might have influenced the content of the SDK. This
8478information is often useful when you are trying to determine why a
8479change in the package or file listings has occurred.
8480
8481Examining Build History Information
8482~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8483
8484You can examine build history output from the command line or from a web
8485interface.
8486
8487To see any changes that have occurred (assuming you have
8488:term:`BUILDHISTORY_COMMIT` = "1"),
8489you can simply use any Git command that allows you to view the history
Andrew Geisslerc926e172021-05-07 16:11:35 -05008490of a repository. Here is one method::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008491
8492 $ git log -p
8493
8494You need to realize,
8495however, that this method does show changes that are not significant
8496(e.g. a package's size changing by a few bytes).
8497
William A. Kennington IIIac69b482021-06-02 12:28:27 -07008498There is a command-line tool called ``buildhistory-diff``, though,
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008499that queries the Git repository and prints just the differences that
Andrew Geisslerc926e172021-05-07 16:11:35 -05008500might be significant in human-readable form. Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008501
Andrew Geissler95ac1b82021-03-31 14:34:31 -05008502 $ poky/poky/scripts/buildhistory-diff . HEAD^
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008503 Changes to images/qemux86_64/glibc/core-image-minimal (files-in-image.txt):
8504 /etc/anotherpkg.conf was added
8505 /sbin/anotherpkg was added
8506 * (installed-package-names.txt):
8507 * anotherpkg was added
8508 Changes to images/qemux86_64/glibc/core-image-minimal (installed-package-names.txt):
8509 anotherpkg was added
8510 packages/qemux86_64-poky-linux/v86d: PACKAGES: added "v86d-extras"
8511 * PR changed from "r0" to "r1"
8512 * PV changed from "0.1.10" to "0.1.12"
8513 packages/qemux86_64-poky-linux/v86d/v86d: PKGSIZE changed from 110579 to 144381 (+30%)
8514 * PR changed from "r0" to "r1"
8515 * PV changed from "0.1.10" to "0.1.12"
8516
8517.. note::
8518
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008519 The ``buildhistory-diff`` tool requires the ``GitPython``
Andrew Geisslerc926e172021-05-07 16:11:35 -05008520 package. Be sure to install it using Pip3 as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008521
8522 $ pip3 install GitPython --user
8523
8524
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008525 Alternatively, you can install ``python3-git`` using the appropriate
Andrew Geisslereff27472021-10-29 15:35:00 -05008526 distribution package manager (e.g. ``apt``, ``dnf``, or ``zipper``).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008527
8528To see changes to the build history using a web interface, follow the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008529instruction in the ``README`` file
Andrew Geissler09209ee2020-12-13 08:44:15 -06008530:yocto_git:`here </buildhistory-web/>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008531
8532Here is a sample screenshot of the interface:
8533
8534.. image:: figures/buildhistory-web.png
Andrew Geisslerd5838332022-05-27 11:33:10 -05008535 :width: 100%
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008536
8537Performing Automated Runtime Testing
8538====================================
8539
8540The OpenEmbedded build system makes available a series of automated
8541tests for images to verify runtime functionality. You can run these
8542tests on either QEMU or actual target hardware. Tests are written in
8543Python making use of the ``unittest`` module, and the majority of them
8544run commands on the target system over SSH. This section describes how
8545you set up the environment to use these tests, run available tests, and
8546write and add your own tests.
8547
8548For information on the test and QA infrastructure available within the
Andrew Geissler09209ee2020-12-13 08:44:15 -06008549Yocto Project, see the ":ref:`ref-manual/release-process:testing and quality assurance`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008550section in the Yocto Project Reference Manual.
8551
8552Enabling Tests
8553--------------
8554
8555Depending on whether you are planning to run tests using QEMU or on the
8556hardware, you have to take different steps to enable the tests. See the
8557following subsections for information on how to enable both types of
8558tests.
8559
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008560Enabling Runtime Tests on QEMU
8561~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8562
8563In order to run tests, you need to do the following:
8564
8565- *Set up to avoid interaction with sudo for networking:* To
8566 accomplish this, you must do one of the following:
8567
8568 - Add ``NOPASSWD`` for your user in ``/etc/sudoers`` either for all
8569 commands or just for ``runqemu-ifup``. You must provide the full
8570 path as that can change if you are using multiple clones of the
8571 source repository.
8572
8573 .. note::
8574
8575 On some distributions, you also need to comment out "Defaults
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008576 requiretty" in ``/etc/sudoers``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008577
8578 - Manually configure a tap interface for your system.
8579
8580 - Run as root the script in ``scripts/runqemu-gen-tapdevs``, which
8581 should generate a list of tap devices. This is the option
8582 typically chosen for Autobuilder-type environments.
8583
8584 .. note::
8585
8586 - Be sure to use an absolute path when calling this script
8587 with sudo.
8588
8589 - The package recipe ``qemu-helper-native`` is required to run
Andrew Geisslerc926e172021-05-07 16:11:35 -05008590 this script. Build the package using the following command::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008591
8592 $ bitbake qemu-helper-native
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008593
8594- *Set the DISPLAY variable:* You need to set this variable so that
8595 you have an X server available (e.g. start ``vncserver`` for a
8596 headless machine).
8597
8598- *Be sure your host's firewall accepts incoming connections from
8599 192.168.7.0/24:* Some of the tests (in particular DNF tests) start an
8600 HTTP server on a random high number port, which is used to serve
8601 files to the target. The DNF module serves
8602 ``${WORKDIR}/oe-rootfs-repo`` so it can run DNF channel commands.
8603 That means your host's firewall must accept incoming connections from
8604 192.168.7.0/24, which is the default IP range used for tap devices by
8605 ``runqemu``.
8606
8607- *Be sure your host has the correct packages installed:* Depending
8608 your host's distribution, you need to have the following packages
8609 installed:
8610
8611 - Ubuntu and Debian: ``sysstat`` and ``iproute2``
8612
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05008613 - openSUSE: ``sysstat`` and ``iproute2``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008614
8615 - Fedora: ``sysstat`` and ``iproute``
8616
8617 - CentOS: ``sysstat`` and ``iproute``
8618
8619Once you start running the tests, the following happens:
8620
86211. A copy of the root filesystem is written to ``${WORKDIR}/testimage``.
8622
86232. The image is booted under QEMU using the standard ``runqemu`` script.
8624
86253. A default timeout of 500 seconds occurs to allow for the boot process
8626 to reach the login prompt. You can change the timeout period by
8627 setting
8628 :term:`TEST_QEMUBOOT_TIMEOUT`
8629 in the ``local.conf`` file.
8630
86314. Once the boot process is reached and the login prompt appears, the
8632 tests run. The full boot log is written to
8633 ``${WORKDIR}/testimage/qemu_boot_log``.
8634
Andrew Geissler09036742021-06-25 14:25:14 -050086355. Each test module loads in the order found in :term:`TEST_SUITES`. You can
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008636 find the full output of the commands run over SSH in
8637 ``${WORKDIR}/testimgage/ssh_target_log``.
8638
86396. If no failures occur, the task running the tests ends successfully.
8640 You can find the output from the ``unittest`` in the task log at
8641 ``${WORKDIR}/temp/log.do_testimage``.
8642
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008643Enabling Runtime Tests on Hardware
8644~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8645
8646The OpenEmbedded build system can run tests on real hardware, and for
8647certain devices it can also deploy the image to be tested onto the
8648device beforehand.
8649
Andrew Geissler595f6302022-01-24 19:11:47 +00008650For automated deployment, a "controller image" is installed onto the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008651hardware once as part of setup. Then, each time tests are to be run, the
8652following occurs:
8653
Andrew Geissler595f6302022-01-24 19:11:47 +000086541. The controller image is booted into and used to write the image to be
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008655 tested to a second partition.
8656
86572. The device is then rebooted using an external script that you need to
8658 provide.
8659
86603. The device boots into the image to be tested.
8661
8662When running tests (independent of whether the image has been deployed
8663automatically or not), the device is expected to be connected to a
8664network on a pre-determined IP address. You can either use static IP
8665addresses written into the image, or set the image to use DHCP and have
8666your DHCP server on the test network assign a known IP address based on
8667the MAC address of the device.
8668
Andrew Geissler09036742021-06-25 14:25:14 -05008669In order to run tests on hardware, you need to set :term:`TEST_TARGET` to an
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008670appropriate value. For QEMU, you do not have to change anything, the
8671default value is "qemu". For running tests on hardware, the following
William A. Kennington IIIac69b482021-06-02 12:28:27 -07008672options are available:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008673
8674- *"simpleremote":* Choose "simpleremote" if you are going to run tests
8675 on a target system that is already running the image to be tested and
8676 is available on the network. You can use "simpleremote" in
8677 conjunction with either real hardware or an image running within a
8678 separately started QEMU or any other virtual machine manager.
8679
8680- *"SystemdbootTarget":* Choose "SystemdbootTarget" if your hardware is
8681 an EFI-based machine with ``systemd-boot`` as bootloader and
8682 ``core-image-testmaster`` (or something similar) is installed. Also,
8683 your hardware under test must be in a DHCP-enabled network that gives
8684 it the same IP address for each reboot.
8685
8686 If you choose "SystemdbootTarget", there are additional requirements
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05008687 and considerations. See the
8688 ":ref:`dev-manual/common-tasks:selecting systemdboottarget`" section, which
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008689 follows, for more information.
8690
8691- *"BeagleBoneTarget":* Choose "BeagleBoneTarget" if you are deploying
8692 images and running tests on the BeagleBone "Black" or original
8693 "White" hardware. For information on how to use these tests, see the
8694 comments at the top of the BeagleBoneTarget
8695 ``meta-yocto-bsp/lib/oeqa/controllers/beaglebonetarget.py`` file.
8696
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008697- *"EdgeRouterTarget":* Choose "EdgeRouterTarget" if you are deploying
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008698 images and running tests on the Ubiquiti Networks EdgeRouter Lite.
8699 For information on how to use these tests, see the comments at the
8700 top of the EdgeRouterTarget
8701 ``meta-yocto-bsp/lib/oeqa/controllers/edgeroutertarget.py`` file.
8702
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008703- *"GrubTarget":* Choose "GrubTarget" if you are deploying images and running
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008704 tests on any generic PC that boots using GRUB. For information on how
8705 to use these tests, see the comments at the top of the GrubTarget
8706 ``meta-yocto-bsp/lib/oeqa/controllers/grubtarget.py`` file.
8707
8708- *"your-target":* Create your own custom target if you want to run
8709 tests when you are deploying images and running tests on a custom
8710 machine within your BSP layer. To do this, you need to add a Python
8711 unit that defines the target class under ``lib/oeqa/controllers/``
8712 within your layer. You must also provide an empty ``__init__.py``.
8713 For examples, see files in ``meta-yocto-bsp/lib/oeqa/controllers/``.
8714
8715Selecting SystemdbootTarget
8716~~~~~~~~~~~~~~~~~~~~~~~~~~~
8717
Andrew Geissler09036742021-06-25 14:25:14 -05008718If you did not set :term:`TEST_TARGET` to "SystemdbootTarget", then you do
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008719not need any information in this section. You can skip down to the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05008720":ref:`dev-manual/common-tasks:running tests`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008721
Andrew Geissler09036742021-06-25 14:25:14 -05008722If you did set :term:`TEST_TARGET` to "SystemdbootTarget", you also need to
Andrew Geissler595f6302022-01-24 19:11:47 +00008723perform a one-time setup of your controller image by doing the following:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008724
Andrew Geissler09036742021-06-25 14:25:14 -050087251. *Set EFI_PROVIDER:* Be sure that :term:`EFI_PROVIDER` is as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008726
8727 EFI_PROVIDER = "systemd-boot"
8728
Andrew Geissler595f6302022-01-24 19:11:47 +000087292. *Build the controller image:* Build the ``core-image-testmaster`` image.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008730 The ``core-image-testmaster`` recipe is provided as an example for a
Andrew Geissler595f6302022-01-24 19:11:47 +00008731 "controller" image and you can customize the image recipe as you would
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008732 any other recipe.
8733
8734 Here are the image recipe requirements:
8735
8736 - Inherits ``core-image`` so that kernel modules are installed.
8737
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05008738 - Installs normal linux utilities not BusyBox ones (e.g. ``bash``,
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008739 ``coreutils``, ``tar``, ``gzip``, and ``kmod``).
8740
Patrick Williams2194f502022-10-16 14:26:09 -05008741 - Uses a custom :term:`Initramfs` image with a custom
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008742 installer. A normal image that you can install usually creates a
Andrew Geissler595f6302022-01-24 19:11:47 +00008743 single root filesystem partition. This image uses another installer that
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008744 creates a specific partition layout. Not all Board Support
8745 Packages (BSPs) can use an installer. For such cases, you need to
8746 manually create the following partition layout on the target:
8747
8748 - First partition mounted under ``/boot``, labeled "boot".
8749
Andrew Geissler595f6302022-01-24 19:11:47 +00008750 - The main root filesystem partition where this image gets installed,
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008751 which is mounted under ``/``.
8752
8753 - Another partition labeled "testrootfs" where test images get
8754 deployed.
8755
87563. *Install image:* Install the image that you just built on the target
8757 system.
8758
Andrew Geissler09036742021-06-25 14:25:14 -05008759The final thing you need to do when setting :term:`TEST_TARGET` to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008760"SystemdbootTarget" is to set up the test image:
8761
87621. *Set up your local.conf file:* Make sure you have the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05008763 statements in your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008764
8765 IMAGE_FSTYPES += "tar.gz"
8766 INHERIT += "testimage"
8767 TEST_TARGET = "SystemdbootTarget"
8768 TEST_TARGET_IP = "192.168.2.3"
8769
Andrew Geisslerc926e172021-05-07 16:11:35 -050087702. *Build your test image:* Use BitBake to build the image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008771
8772 $ bitbake core-image-sato
8773
8774Power Control
8775~~~~~~~~~~~~~
8776
8777For most hardware targets other than "simpleremote", you can control
8778power:
8779
Andrew Geissler09036742021-06-25 14:25:14 -05008780- You can use :term:`TEST_POWERCONTROL_CMD` together with
8781 :term:`TEST_POWERCONTROL_EXTRA_ARGS` as a command that runs on the host
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008782 and does power cycling. The test code passes one argument to that
8783 command: off, on or cycle (off then on). Here is an example that
Andrew Geisslerc926e172021-05-07 16:11:35 -05008784 could appear in your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008785
8786 TEST_POWERCONTROL_CMD = "powercontrol.exp test 10.11.12.1 nuc1"
8787
8788 In this example, the expect
8789 script does the following:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008790
8791 .. code-block:: shell
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008792
8793 ssh test@10.11.12.1 "pyctl nuc1 arg"
8794
8795 It then runs a Python script that controls power for a label called
8796 ``nuc1``.
8797
8798 .. note::
8799
Andrew Geissler09036742021-06-25 14:25:14 -05008800 You need to customize :term:`TEST_POWERCONTROL_CMD` and
8801 :term:`TEST_POWERCONTROL_EXTRA_ARGS` for your own setup. The one requirement
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008802 is that it accepts "on", "off", and "cycle" as the last argument.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008803
8804- When no command is defined, it connects to the device over SSH and
8805 uses the classic reboot command to reboot the device. Classic reboot
8806 is fine as long as the machine actually reboots (i.e. the SSH test
8807 has not failed). It is useful for scenarios where you have a simple
8808 setup, typically with a single board, and where some manual
8809 interaction is okay from time to time.
8810
8811If you have no hardware to automatically perform power control but still
8812wish to experiment with automated hardware testing, you can use the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008813``dialog-power-control`` script that shows a dialog prompting you to perform
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008814the required power action. This script requires either KDialog or Zenity
8815to be installed. To use this script, set the
8816:term:`TEST_POWERCONTROL_CMD`
Andrew Geisslerc926e172021-05-07 16:11:35 -05008817variable as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008818
8819 TEST_POWERCONTROL_CMD = "${COREBASE}/scripts/contrib/dialog-power-control"
8820
8821Serial Console Connection
8822~~~~~~~~~~~~~~~~~~~~~~~~~
8823
8824For test target classes requiring a serial console to interact with the
8825bootloader (e.g. BeagleBoneTarget, EdgeRouterTarget, and GrubTarget),
8826you need to specify a command to use to connect to the serial console of
8827the target machine by using the
8828:term:`TEST_SERIALCONTROL_CMD`
8829variable and optionally the
8830:term:`TEST_SERIALCONTROL_EXTRA_ARGS`
8831variable.
8832
8833These cases could be a serial terminal program if the machine is
8834connected to a local serial port, or a ``telnet`` or ``ssh`` command
8835connecting to a remote console server. Regardless of the case, the
8836command simply needs to connect to the serial console and forward that
8837connection to standard input and output as any normal terminal program
8838does. For example, to use the picocom terminal program on serial device
Andrew Geisslerc926e172021-05-07 16:11:35 -05008839``/dev/ttyUSB0`` at 115200bps, you would set the variable as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008840
8841 TEST_SERIALCONTROL_CMD = "picocom /dev/ttyUSB0 -b 115200"
8842
8843For local
8844devices where the serial port device disappears when the device reboots,
8845an additional "serdevtry" wrapper script is provided. To use this
8846wrapper, simply prefix the terminal command with
Andrew Geisslerc926e172021-05-07 16:11:35 -05008847``${COREBASE}/scripts/contrib/serdevtry``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008848
8849 TEST_SERIALCONTROL_CMD = "${COREBASE}/scripts/contrib/serdevtry picocom -b 115200 /dev/ttyUSB0"
8850
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008851Running Tests
8852-------------
8853
8854You can start the tests automatically or manually:
8855
Patrick Williams2390b1b2022-11-03 13:47:49 -05008856- *Automatically running tests:* To run the tests automatically after the
8857 OpenEmbedded build system successfully creates an image, first set the
8858 :term:`TESTIMAGE_AUTO` variable to "1" in your ``local.conf`` file in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05008859 :term:`Build Directory`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008860
8861 TESTIMAGE_AUTO = "1"
8862
8863 Next, build your image. If the image successfully builds, the
Andrew Geisslerc926e172021-05-07 16:11:35 -05008864 tests run::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008865
8866 bitbake core-image-sato
8867
8868- *Manually running tests:* To manually run the tests, first globally
8869 inherit the
Patrick Williams975a06f2022-10-21 14:42:47 -05008870 :ref:`testimage <ref-classes-testimage>` class
Andrew Geisslerc926e172021-05-07 16:11:35 -05008871 by editing your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008872
8873 INHERIT += "testimage"
8874
Andrew Geisslerc926e172021-05-07 16:11:35 -05008875 Next, use BitBake to run the tests::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008876
8877 bitbake -c testimage image
8878
8879All test files reside in ``meta/lib/oeqa/runtime`` in the
8880:term:`Source Directory`. A test name maps
8881directly to a Python module. Each test module may contain a number of
8882individual tests. Tests are usually grouped together by the area tested
8883(e.g tests for systemd reside in ``meta/lib/oeqa/runtime/systemd.py``).
8884
8885You can add tests to any layer provided you place them in the proper
8886area and you extend :term:`BBPATH` in
8887the ``local.conf`` file as normal. Be sure that tests reside in
8888``layer/lib/oeqa/runtime``.
8889
8890.. note::
8891
8892 Be sure that module names do not collide with module names used in
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008893 the default set of test modules in ``meta/lib/oeqa/runtime``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008894
8895You can change the set of tests run by appending or overriding
8896:term:`TEST_SUITES` variable in
Andrew Geissler09036742021-06-25 14:25:14 -05008897``local.conf``. Each name in :term:`TEST_SUITES` represents a required test
8898for the image. Test modules named within :term:`TEST_SUITES` cannot be
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008899skipped even if a test is not suitable for an image (e.g. running the
8900RPM tests on an image without ``rpm``). Appending "auto" to
Andrew Geissler09036742021-06-25 14:25:14 -05008901:term:`TEST_SUITES` causes the build system to try to run all tests that are
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008902suitable for the image (i.e. each test module may elect to skip itself).
8903
Andrew Geissler09036742021-06-25 14:25:14 -05008904The order you list tests in :term:`TEST_SUITES` is important and influences
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008905test dependencies. Consequently, tests that depend on other tests should
8906be added after the test on which they depend. For example, since the
8907``ssh`` test depends on the ``ping`` test, "ssh" needs to come after
8908"ping" in the list. The test class provides no re-ordering or dependency
8909handling.
8910
8911.. note::
8912
8913 Each module can have multiple classes with multiple test methods.
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008914 And, Python ``unittest`` rules apply.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008915
8916Here are some things to keep in mind when running tests:
8917
Andrew Geisslerc926e172021-05-07 16:11:35 -05008918- The default tests for the image are defined as::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008919
Patrick Williams0ca19cc2021-08-16 14:03:13 -05008920 DEFAULT_TEST_SUITES:pn-image = "ping ssh df connman syslog xorg scp vnc date rpm dnf dmesg"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008921
Andrew Geisslerc926e172021-05-07 16:11:35 -05008922- Add your own test to the list of the by using the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008923
Patrick Williams0ca19cc2021-08-16 14:03:13 -05008924 TEST_SUITES:append = " mytest"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008925
Andrew Geisslerc926e172021-05-07 16:11:35 -05008926- Run a specific list of tests as follows::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008927
8928 TEST_SUITES = "test1 test2 test3"
8929
8930 Remember, order is important. Be sure to place a test that is
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008931 dependent on another test later in the order.
8932
8933Exporting Tests
8934---------------
8935
8936You can export tests so that they can run independently of the build
8937system. Exporting tests is required if you want to be able to hand the
8938test execution off to a scheduler. You can only export tests that are
8939defined in :term:`TEST_SUITES`.
8940
8941If your image is already built, make sure the following are set in your
Andrew Geisslerc926e172021-05-07 16:11:35 -05008942``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008943
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008944 INHERIT += "testexport"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008945 TEST_TARGET_IP = "IP-address-for-the-test-target"
8946 TEST_SERVER_IP = "IP-address-for-the-test-server"
8947
8948You can then export the tests with the
Andrew Geisslerc926e172021-05-07 16:11:35 -05008949following BitBake command form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008950
8951 $ bitbake image -c testexport
8952
Patrick Williams2390b1b2022-11-03 13:47:49 -05008953Exporting the tests places them in the :term:`Build Directory` in
8954``tmp/testexport/``\ image, which is controlled by the :term:`TEST_EXPORT_DIR`
8955variable.
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
Patrick Williams2194f502022-10-16 14:26:09 -05009017 is generated during the :ref:`ref-tasks-rootfs` task.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009018
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
Andrew Geissler615f2f12022-07-15 14:00:58 -05009103- "pkg" --- a mandatory string that is the name of the package to be
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009104 installed.
9105
Andrew Geissler615f2f12022-07-15 14:00:58 -05009106- "rm" --- an optional boolean, which defaults to "false", that specifies
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009107 to remove the package after the test.
9108
Andrew Geissler615f2f12022-07-15 14:00:58 -05009109- "extract" --- an optional boolean, which defaults to "false", that
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009110 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
Patrick Williams2390b1b2022-11-03 13:47:49 -05009182 subdirectories in the :term:`Build Directory` to determine variable
9183 dependencies.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009184
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009185- ":ref:`dev-manual/common-tasks:running specific tasks`" describes
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009186 how to use several BitBake options (e.g. ``-c``, ``-C``, and ``-f``)
9187 to run specific tasks in the build chain. It can be useful to run
9188 tasks "out-of-order" when trying isolate build issues.
9189
Andrew Geisslerd5838332022-05-27 11:33:10 -05009190- ":ref:`dev-manual/common-tasks:general BitBake problems`" describes how
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009191 to use BitBake's ``-D`` debug output option to reveal more about what
9192 BitBake is doing during the build.
9193
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009194- ":ref:`dev-manual/common-tasks:building with no dependencies`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009195 describes how to use the BitBake ``-b`` option to build a recipe
9196 while ignoring dependencies.
9197
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009198- ":ref:`dev-manual/common-tasks:recipe logging mechanisms`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009199 describes how to use the many recipe logging functions to produce
9200 debugging output and report errors and warnings.
9201
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009202- ":ref:`dev-manual/common-tasks:debugging parallel make races`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009203 describes how to debug situations where the build consists of several
9204 parts that are run simultaneously and when the output or result of
9205 one part is not ready for use with a different part of the build that
9206 depends on that output.
9207
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009208- ":ref:`dev-manual/common-tasks:debugging with the gnu project debugger (gdb) remotely`"
9209 describes how to use GDB to allow you to examine running programs, which can
9210 help you fix problems.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009211
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009212- ":ref:`dev-manual/common-tasks:debugging with the gnu project debugger (gdb) on the target`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009213 describes how to use GDB directly on target hardware for debugging.
9214
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009215- ":ref:`dev-manual/common-tasks:other debugging tips`" describes
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009216 miscellaneous debugging tips that can be useful.
9217
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009218Viewing Logs from Failed Tasks
9219------------------------------
9220
9221You can find the log for a task in the file
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009222``${``\ :term:`WORKDIR`\ ``}/temp/log.do_``\ `taskname`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009223For example, the log for the
9224:ref:`ref-tasks-compile` task of the
9225QEMU minimal image for the x86 machine (``qemux86``) might be in
9226``tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/temp/log.do_compile``.
9227To see the commands :term:`BitBake` ran
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009228to generate a log, look at the corresponding ``run.do_``\ `taskname` file
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009229in the same directory.
9230
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009231``log.do_``\ `taskname` and ``run.do_``\ `taskname` are actually symbolic
9232links to ``log.do_``\ `taskname`\ ``.``\ `pid` and
9233``log.run_``\ `taskname`\ ``.``\ `pid`, where `pid` is the PID the task had
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009234when it ran. The symlinks always point to the files corresponding to the
9235most recent run.
9236
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009237Viewing Variable Values
9238-----------------------
9239
9240Sometimes you need to know the value of a variable as a result of
9241BitBake's parsing step. This could be because some unexpected behavior
9242occurred in your project. Perhaps an attempt to :ref:`modify a variable
9243<bitbake:bitbake-user-manual/bitbake-user-manual-metadata:modifying existing
9244variables>` did not work out as expected.
9245
9246BitBake's ``-e`` option is used to display variable values after
9247parsing. The following command displays the variable values after the
9248configuration files (i.e. ``local.conf``, ``bblayers.conf``,
Andrew Geisslerc926e172021-05-07 16:11:35 -05009249``bitbake.conf`` and so forth) have been parsed::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009250
9251 $ bitbake -e
9252
9253The following command displays variable values after a specific recipe has
Andrew Geisslerc926e172021-05-07 16:11:35 -05009254been parsed. The variables include those from the configuration as well::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009255
9256 $ bitbake -e recipename
9257
9258.. note::
9259
9260 Each recipe has its own private set of variables (datastore).
9261 Internally, after parsing the configuration, a copy of the resulting
9262 datastore is made prior to parsing each recipe. This copying implies
9263 that variables set in one recipe will not be visible to other
9264 recipes.
9265
9266 Likewise, each task within a recipe gets a private datastore based on
9267 the recipe datastore, which means that variables set within one task
9268 will not be visible to other tasks.
9269
9270In the output of ``bitbake -e``, each variable is preceded by a
9271description of how the variable got its value, including temporary
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009272values that were later overridden. This description also includes
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009273variable flags (varflags) set on the variable. The output can be very
9274helpful during debugging.
9275
9276Variables that are exported to the environment are preceded by
Andrew Geisslerc926e172021-05-07 16:11:35 -05009277``export`` in the output of ``bitbake -e``. See the following example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009278
9279 export CC="i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/ulf/poky/build/tmp/sysroots/qemux86"
9280
9281In addition to variable values, the output of the ``bitbake -e`` and
9282``bitbake -e`` recipe commands includes the following information:
9283
9284- The output starts with a tree listing all configuration files and
9285 classes included globally, recursively listing the files they include
9286 or inherit in turn. Much of the behavior of the OpenEmbedded build
Andrew Geissler09209ee2020-12-13 08:44:15 -06009287 system (including the behavior of the :ref:`ref-manual/tasks:normal recipe build tasks`) is
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009288 implemented in the
9289 :ref:`base <ref-classes-base>` class and the
9290 classes it inherits, rather than being built into BitBake itself.
9291
9292- After the variable values, all functions appear in the output. For
9293 shell functions, variables referenced within the function body are
9294 expanded. If a function has been modified using overrides or using
Patrick Williams0ca19cc2021-08-16 14:03:13 -05009295 override-style operators like ``:append`` and ``:prepend``, then the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009296 final assembled function body appears in the output.
9297
9298Viewing Package Information with ``oe-pkgdata-util``
9299----------------------------------------------------
9300
9301You can use the ``oe-pkgdata-util`` command-line utility to query
9302:term:`PKGDATA_DIR` and display
9303various package-related information. When you use the utility, you must
9304use it to view information on packages that have already been built.
9305
9306Following are a few of the available ``oe-pkgdata-util`` subcommands.
9307
9308.. note::
9309
9310 You can use the standard \* and ? globbing wildcards as part of
9311 package names and paths.
9312
9313- ``oe-pkgdata-util list-pkgs [pattern]``: Lists all packages
9314 that have been built, optionally limiting the match to packages that
9315 match pattern.
9316
9317- ``oe-pkgdata-util list-pkg-files package ...``: Lists the
9318 files and directories contained in the given packages.
9319
9320 .. note::
9321
9322 A different way to view the contents of a package is to look at
9323 the
9324 ``${``\ :term:`WORKDIR`\ ``}/packages-split``
9325 directory of the recipe that generates the package. This directory
9326 is created by the
9327 :ref:`ref-tasks-package` task
9328 and has one subdirectory for each package the recipe generates,
9329 which contains the files stored in that package.
9330
9331 If you want to inspect the ``${WORKDIR}/packages-split``
9332 directory, make sure that
9333 :ref:`rm_work <ref-classes-rm-work>` is not
9334 enabled when you build the recipe.
9335
9336- ``oe-pkgdata-util find-path path ...``: Lists the names of
9337 the packages that contain the given paths. For example, the following
9338 tells us that ``/usr/share/man/man1/make.1`` is contained in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05009339 ``make-doc`` package::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009340
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009341 $ oe-pkgdata-util find-path /usr/share/man/man1/make.1
9342 make-doc: /usr/share/man/man1/make.1
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009343
9344- ``oe-pkgdata-util lookup-recipe package ...``: Lists the name
9345 of the recipes that produce the given packages.
9346
9347For more information on the ``oe-pkgdata-util`` command, use the help
Andrew Geisslerc926e172021-05-07 16:11:35 -05009348facility::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009349
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009350 $ oe-pkgdata-util --help
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009351 $ oe-pkgdata-util subcommand --help
9352
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009353Viewing Dependencies Between Recipes and Tasks
9354----------------------------------------------
9355
9356Sometimes it can be hard to see why BitBake wants to build other recipes
9357before the one you have specified. Dependency information can help you
9358understand why a recipe is built.
9359
9360To generate dependency information for a recipe, run the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05009361command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009362
9363 $ bitbake -g recipename
9364
9365This command writes the following files in the current directory:
9366
9367- ``pn-buildlist``: A list of recipes/targets involved in building
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009368 `recipename`. "Involved" here means that at least one task from the
9369 recipe needs to run when building `recipename` from scratch. Targets
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009370 that are in
9371 :term:`ASSUME_PROVIDED`
9372 are not listed.
9373
9374- ``task-depends.dot``: A graph showing dependencies between tasks.
9375
Patrick Williams7784c422022-11-17 07:29:11 -06009376The graphs are in :wikipedia:`DOT <DOT_%28graph_description_language%29>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009377format and can be converted to images (e.g. using the ``dot`` tool from
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009378`Graphviz <https://www.graphviz.org/>`__).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009379
9380.. note::
9381
9382 - DOT files use a plain text format. The graphs generated using the
9383 ``bitbake -g`` command are often so large as to be difficult to
Andrew Geisslerd5838332022-05-27 11:33:10 -05009384 read without special pruning (e.g. with BitBake's ``-I`` option)
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009385 and processing. Despite the form and size of the graphs, the
9386 corresponding ``.dot`` files can still be possible to read and
9387 provide useful information.
9388
9389 As an example, the ``task-depends.dot`` file contains lines such
Andrew Geisslerc926e172021-05-07 16:11:35 -05009390 as the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009391
9392 "libxslt.do_configure" -> "libxml2.do_populate_sysroot"
9393
9394 The above example line reveals that the
9395 :ref:`ref-tasks-configure`
9396 task in ``libxslt`` depends on the
9397 :ref:`ref-tasks-populate_sysroot`
9398 task in ``libxml2``, which is a normal
9399 :term:`DEPENDS` dependency
9400 between the two recipes.
9401
9402 - For an example of how ``.dot`` files can be processed, see the
9403 ``scripts/contrib/graph-tool`` Python script, which finds and
9404 displays paths between graph nodes.
9405
9406You can use a different method to view dependency information by using
Andrew Geisslerc926e172021-05-07 16:11:35 -05009407the following command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009408
9409 $ bitbake -g -u taskexp recipename
9410
9411This command
9412displays a GUI window from which you can view build-time and runtime
9413dependencies for the recipes involved in building recipename.
9414
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009415Viewing Task Variable Dependencies
9416----------------------------------
9417
9418As mentioned in the
9419":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-execution:checksums (signatures)`" section of the BitBake
9420User Manual, BitBake tries to automatically determine what variables a
9421task depends on so that it can rerun the task if any values of the
9422variables change. This determination is usually reliable. However, if
9423you do things like construct variable names at runtime, then you might
9424have to manually declare dependencies on those variables using
9425``vardeps`` as described in the
9426":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags`" section of the BitBake
9427User Manual.
9428
9429If you are unsure whether a variable dependency is being picked up
9430automatically for a given task, you can list the variable dependencies
9431BitBake has determined by doing the following:
9432
Andrew Geisslerc926e172021-05-07 16:11:35 -050094331. Build the recipe containing the task::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009434
9435 $ bitbake recipename
9436
94372. Inside the :term:`STAMPS_DIR`
9438 directory, find the signature data (``sigdata``) file that
9439 corresponds to the task. The ``sigdata`` files contain a pickled
9440 Python database of all the metadata that went into creating the input
9441 checksum for the task. As an example, for the
9442 :ref:`ref-tasks-fetch` task of the
9443 ``db`` recipe, the ``sigdata`` file might be found in the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05009444 location::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009445
9446 ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
9447
9448 For tasks that are accelerated through the shared state
Andrew Geissler09209ee2020-12-13 08:44:15 -06009449 (:ref:`sstate <overview-manual/concepts:shared state cache>`) cache, an
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009450 additional ``siginfo`` file is written into
9451 :term:`SSTATE_DIR` along with
9452 the cached task output. The ``siginfo`` files contain exactly the
9453 same information as ``sigdata`` files.
9454
94553. Run ``bitbake-dumpsig`` on the ``sigdata`` or ``siginfo`` file. Here
Andrew Geisslerc926e172021-05-07 16:11:35 -05009456 is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009457
9458 $ bitbake-dumpsig ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
9459
9460 In the output of the above command, you will find a line like the
9461 following, which lists all the (inferred) variable dependencies for
9462 the task. This list also includes indirect dependencies from
9463 variables depending on other variables, recursively.
9464 ::
9465
9466 Task dependencies: ['PV', 'SRCREV', 'SRC_URI', 'SRC_URI[md5sum]', 'SRC_URI[sha256sum]', 'base_do_fetch']
9467
9468 .. note::
9469
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009470 Functions (e.g. ``base_do_fetch``) also count as variable dependencies.
9471 These functions in turn depend on the variables they reference.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009472
9473 The output of ``bitbake-dumpsig`` also includes the value each
9474 variable had, a list of dependencies for each variable, and
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00009475 :term:`BB_BASEHASH_IGNORE_VARS`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009476 information.
9477
9478There is also a ``bitbake-diffsigs`` command for comparing two
9479``siginfo`` or ``sigdata`` files. This command can be helpful when
9480trying to figure out what changed between two versions of a task. If you
9481call ``bitbake-diffsigs`` with just one file, the command behaves like
9482``bitbake-dumpsig``.
9483
9484You can also use BitBake to dump out the signature construction
9485information without executing tasks by using either of the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05009486BitBake command-line options::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009487
9488 ‐‐dump-signatures=SIGNATURE_HANDLER
9489 -S SIGNATURE_HANDLER
9490
9491
9492.. note::
9493
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009494 Two common values for `SIGNATURE_HANDLER` are "none" and "printdiff", which
9495 dump only the signature or compare the dumped signature with the cached one,
9496 respectively.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009497
9498Using BitBake with either of these options causes BitBake to dump out
9499``sigdata`` files in the ``stamps`` directory for every task it would
9500have executed instead of building the specified target package.
9501
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009502Viewing Metadata Used to Create the Input Signature of a Shared State Task
9503--------------------------------------------------------------------------
9504
9505Seeing what metadata went into creating the input signature of a shared
9506state (sstate) task can be a useful debugging aid. This information is
9507available in signature information (``siginfo``) files in
9508:term:`SSTATE_DIR`. For
9509information on how to view and interpret information in ``siginfo``
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009510files, see the
9511":ref:`dev-manual/common-tasks:viewing task variable dependencies`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009512
9513For conceptual information on shared state, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06009514":ref:`overview-manual/concepts:shared state`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009515section in the Yocto Project Overview and Concepts Manual.
9516
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009517Invalidating Shared State to Force a Task to Run
9518------------------------------------------------
9519
9520The OpenEmbedded build system uses
Andrew Geissler09209ee2020-12-13 08:44:15 -06009521:ref:`checksums <overview-manual/concepts:checksums (signatures)>` and
9522:ref:`overview-manual/concepts:shared state` cache to avoid unnecessarily
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009523rebuilding tasks. Collectively, this scheme is known as "shared state
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009524code".
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009525
9526As with all schemes, this one has some drawbacks. It is possible that
9527you could make implicit changes to your code that the checksum
9528calculations do not take into account. These implicit changes affect a
9529task's output but do not trigger the shared state code into rebuilding a
9530recipe. Consider an example during which a tool changes its output.
9531Assume that the output of ``rpmdeps`` changes. The result of the change
9532should be that all the ``package`` and ``package_write_rpm`` shared
9533state cache items become invalid. However, because the change to the
9534output is external to the code and therefore implicit, the associated
9535shared state cache items do not become invalidated. In this case, the
9536build process uses the cached items rather than running the task again.
9537Obviously, these types of implicit changes can cause problems.
9538
9539To avoid these problems during the build, you need to understand the
9540effects of any changes you make. Realize that changes you make directly
9541to a function are automatically factored into the checksum calculation.
9542Thus, these explicit changes invalidate the associated area of shared
9543state cache. However, you need to be aware of any implicit changes that
9544are not obvious changes to the code and could affect the output of a
9545given task.
9546
9547When you identify an implicit change, you can easily take steps to
9548invalidate the cache and force the tasks to run. The steps you can take
9549are as simple as changing a function's comments in the source code. For
9550example, to invalidate package shared state files, change the comment
9551statements of
9552:ref:`ref-tasks-package` or the
9553comments of one of the functions it calls. Even though the change is
9554purely cosmetic, it causes the checksum to be recalculated and forces
9555the build system to run the task again.
9556
9557.. note::
9558
9559 For an example of a commit that makes a cosmetic change to invalidate
9560 shared state, see this
Andrew Geissler09209ee2020-12-13 08:44:15 -06009561 :yocto_git:`commit </poky/commit/meta/classes/package.bbclass?id=737f8bbb4f27b4837047cb9b4fbfe01dfde36d54>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009562
9563Running Specific Tasks
9564----------------------
9565
9566Any given recipe consists of a set of tasks. The standard BitBake
Patrick Williams2194f502022-10-16 14:26:09 -05009567behavior in most cases is: :ref:`ref-tasks-fetch`, :ref:`ref-tasks-unpack`, :ref:`ref-tasks-patch`,
9568:ref:`ref-tasks-configure`, :ref:`ref-tasks-compile`, :ref:`ref-tasks-install`, :ref:`ref-tasks-package`,
9569:ref:`do_package_write_* <ref-tasks-package_write_deb>`, and :ref:`ref-tasks-build`. The default task is
9570:ref:`ref-tasks-build` and any tasks on which it depends build first. Some tasks,
9571such as :ref:`ref-tasks-devshell`, are not part of the default build chain. If you
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009572wish to run a task that is not part of the default build chain, you can
Andrew Geisslerc926e172021-05-07 16:11:35 -05009573use the ``-c`` option in BitBake. Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009574
9575 $ bitbake matchbox-desktop -c devshell
9576
9577The ``-c`` option respects task dependencies, which means that all other
9578tasks (including tasks from other recipes) that the specified task
9579depends on will be run before the task. Even when you manually specify a
9580task to run with ``-c``, BitBake will only run the task if it considers
9581it "out of date". See the
Andrew Geissler09209ee2020-12-13 08:44:15 -06009582":ref:`overview-manual/concepts:stamp files and the rerunning of tasks`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009583section in the Yocto Project Overview and Concepts Manual for how
9584BitBake determines whether a task is "out of date".
9585
9586If you want to force an up-to-date task to be rerun (e.g. because you
9587made manual modifications to the recipe's
9588:term:`WORKDIR` that you want to try
9589out), then you can use the ``-f`` option.
9590
9591.. note::
9592
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009593 The reason ``-f`` is never required when running the
9594 :ref:`ref-tasks-devshell` task is because the
9595 [\ :ref:`nostamp <bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ]
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009596 variable flag is already set for the task.
9597
Andrew Geisslerc926e172021-05-07 16:11:35 -05009598The following example shows one way you can use the ``-f`` option::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009599
9600 $ bitbake matchbox-desktop
9601 .
9602 .
9603 make some changes to the source code in the work directory
9604 .
9605 .
9606 $ bitbake matchbox-desktop -c compile -f
9607 $ bitbake matchbox-desktop
9608
9609This sequence first builds and then recompiles ``matchbox-desktop``. The
9610last command reruns all tasks (basically the packaging tasks) after the
Patrick Williams2194f502022-10-16 14:26:09 -05009611compile. BitBake recognizes that the :ref:`ref-tasks-compile` task was rerun and
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009612therefore understands that the other tasks also need to be run again.
9613
9614Another, shorter way to rerun a task and all
Andrew Geissler09209ee2020-12-13 08:44:15 -06009615:ref:`ref-manual/tasks:normal recipe build tasks`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009616that depend on it is to use the ``-C`` option.
9617
9618.. note::
9619
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009620 This option is upper-cased and is separate from the ``-c``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009621 option, which is lower-cased.
9622
9623Using this option invalidates the given task and then runs the
9624:ref:`ref-tasks-build` task, which is
9625the default task if no task is given, and the tasks on which it depends.
9626You could replace the final two commands in the previous example with
Andrew Geisslerc926e172021-05-07 16:11:35 -05009627the following single command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009628
9629 $ bitbake matchbox-desktop -C compile
9630
9631Internally, the ``-f`` and ``-C`` options work by tainting (modifying)
9632the input checksum of the specified task. This tainting indirectly
9633causes the task and its dependent tasks to be rerun through the normal
9634task dependency mechanisms.
9635
9636.. note::
9637
9638 BitBake explicitly keeps track of which tasks have been tainted in
9639 this fashion, and will print warnings such as the following for
9640 builds involving such tasks:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009641
9642 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009643
9644 WARNING: /home/ulf/poky/meta/recipes-sato/matchbox-desktop/matchbox-desktop_2.1.bb.do_compile is tainted from a forced run
9645
9646
9647 The purpose of the warning is to let you know that the work directory
9648 and build output might not be in the clean state they would be in for
9649 a "normal" build, depending on what actions you took. To get rid of
9650 such warnings, you can remove the work directory and rebuild the
Andrew Geisslerc926e172021-05-07 16:11:35 -05009651 recipe, as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009652
9653 $ bitbake matchbox-desktop -c clean
9654 $ bitbake matchbox-desktop
9655
9656
9657You can view a list of tasks in a given package by running the
Patrick Williams2194f502022-10-16 14:26:09 -05009658:ref:`ref-tasks-listtasks` task as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009659
9660 $ bitbake matchbox-desktop -c listtasks
9661
9662The results appear as output to the console and are also in
9663the file ``${WORKDIR}/temp/log.do_listtasks``.
9664
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009665General BitBake Problems
9666------------------------
9667
9668You can see debug output from BitBake by using the ``-D`` option. The
9669debug output gives more information about what BitBake is doing and the
9670reason behind it. Each ``-D`` option you use increases the logging
9671level. The most common usage is ``-DDD``.
9672
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009673The output from ``bitbake -DDD -v targetname`` can reveal why BitBake
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009674chose a certain version of a package or why BitBake picked a certain
9675provider. This command could also help you in a situation where you
9676think BitBake did something unexpected.
9677
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009678Building with No Dependencies
9679-----------------------------
9680
9681To build a specific recipe (``.bb`` file), you can use the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05009682command form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009683
9684 $ bitbake -b somepath/somerecipe.bb
9685
9686This command form does
9687not check for dependencies. Consequently, you should use it only when
9688you know existing dependencies have been met.
9689
9690.. note::
9691
9692 You can also specify fragments of the filename. In this case, BitBake
9693 checks for a unique match.
9694
9695Recipe Logging Mechanisms
9696-------------------------
9697
9698The Yocto Project provides several logging functions for producing
9699debugging output and reporting errors and warnings. For Python
William A. Kennington IIIac69b482021-06-02 12:28:27 -07009700functions, the following logging functions are available. All of these functions
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009701log to ``${T}/log.do_``\ `task`, and can also log to standard output
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009702(stdout) with the right settings:
9703
9704- ``bb.plain(msg)``: Writes msg as is to the log while also
9705 logging to stdout.
9706
9707- ``bb.note(msg)``: Writes "NOTE: msg" to the log. Also logs to
9708 stdout if BitBake is called with "-v".
9709
9710- ``bb.debug(level, msg)``: Writes "DEBUG: msg" to the
9711 log. Also logs to stdout if the log level is greater than or equal to
Patrick Williams213cb262021-08-07 19:21:33 -05009712 level. See the ":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-intro:usage and syntax`" option
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009713 in the BitBake User Manual for more information.
9714
9715- ``bb.warn(msg)``: Writes "WARNING: msg" to the log while also
9716 logging to stdout.
9717
9718- ``bb.error(msg)``: Writes "ERROR: msg" to the log while also
9719 logging to standard out (stdout).
9720
9721 .. note::
9722
9723 Calling this function does not cause the task to fail.
9724
Andrew Geisslereff27472021-10-29 15:35:00 -05009725- ``bb.fatal(msg)``: This logging function is similar to
9726 ``bb.error(msg)`` but also causes the calling task to fail.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009727
9728 .. note::
9729
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009730 ``bb.fatal()`` raises an exception, which means you do not need to put a
9731 "return" statement after the function.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009732
9733The same logging functions are also available in shell functions, under
9734the names ``bbplain``, ``bbnote``, ``bbdebug``, ``bbwarn``, ``bberror``,
9735and ``bbfatal``. The
9736:ref:`logging <ref-classes-logging>` class
9737implements these functions. See that class in the ``meta/classes``
9738folder of the :term:`Source Directory` for information.
9739
9740Logging With Python
9741~~~~~~~~~~~~~~~~~~~
9742
9743When creating recipes using Python and inserting code that handles build
9744logs, keep in mind the goal is to have informative logs while keeping
9745the console as "silent" as possible. Also, if you want status messages
9746in the log, use the "debug" loglevel.
9747
9748Following is an example written in Python. The code handles logging for
9749a function that determines the number of tasks needed to be run. See the
9750":ref:`ref-tasks-listtasks`"
Andrew Geisslerc926e172021-05-07 16:11:35 -05009751section for additional information::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009752
9753 python do_listtasks() {
9754 bb.debug(2, "Starting to figure out the task list")
9755 if noteworthy_condition:
9756 bb.note("There are 47 tasks to run")
9757 bb.debug(2, "Got to point xyz")
9758 if warning_trigger:
9759 bb.warn("Detected warning_trigger, this might be a problem later.")
9760 if recoverable_error:
9761 bb.error("Hit recoverable_error, you really need to fix this!")
9762 if fatal_error:
9763 bb.fatal("fatal_error detected, unable to print the task list")
9764 bb.plain("The tasks present are abc")
9765 bb.debug(2, "Finished figuring out the tasklist")
9766 }
9767
9768Logging With Bash
9769~~~~~~~~~~~~~~~~~
9770
9771When creating recipes using Bash and inserting code that handles build
Andrew Geissler615f2f12022-07-15 14:00:58 -05009772logs, you have the same goals --- informative with minimal console output.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009773The syntax you use for recipes written in Bash is similar to that of
9774recipes written in Python described in the previous section.
9775
9776Following is an example written in Bash. The code logs the progress of
9777the ``do_my_function`` function.
9778::
9779
9780 do_my_function() {
9781 bbdebug 2 "Running do_my_function"
9782 if [ exceptional_condition ]; then
9783 bbnote "Hit exceptional_condition"
9784 fi
9785 bbdebug 2 "Got to point xyz"
9786 if [ warning_trigger ]; then
9787 bbwarn "Detected warning_trigger, this might cause a problem later."
9788 fi
9789 if [ recoverable_error ]; then
9790 bberror "Hit recoverable_error, correcting"
9791 fi
9792 if [ fatal_error ]; then
9793 bbfatal "fatal_error detected"
9794 fi
9795 bbdebug 2 "Completed do_my_function"
9796 }
9797
9798
9799Debugging Parallel Make Races
9800-----------------------------
9801
9802A parallel ``make`` race occurs when the build consists of several parts
9803that are run simultaneously and a situation occurs when the output or
9804result of one part is not ready for use with a different part of the
9805build that depends on that output. Parallel make races are annoying and
William A. Kennington IIIac69b482021-06-02 12:28:27 -07009806can sometimes be difficult to reproduce and fix. However, there are some simple
9807tips and tricks that can help you debug and fix them. This section
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009808presents a real-world example of an error encountered on the Yocto
9809Project autobuilder and the process used to fix it.
9810
9811.. note::
9812
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009813 If you cannot properly fix a ``make`` race condition, you can work around it
9814 by clearing either the :term:`PARALLEL_MAKE` or :term:`PARALLEL_MAKEINST`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009815 variables.
9816
9817The Failure
9818~~~~~~~~~~~
9819
9820For this example, assume that you are building an image that depends on
9821the "neard" package. And, during the build, BitBake runs into problems
9822and creates the following output.
9823
9824.. note::
9825
9826 This example log file has longer lines artificially broken to make
9827 the listing easier to read.
9828
9829If you examine the output or the log file, you see the failure during
9830``make``:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009831
9832.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009833
9834 | DEBUG: SITE files ['endian-little', 'bit-32', 'ix86-common', 'common-linux', 'common-glibc', 'i586-linux', 'common']
9835 | DEBUG: Executing shell function do_compile
9836 | NOTE: make -j 16
9837 | make --no-print-directory all-am
9838 | /bin/mkdir -p include/near
9839 | /bin/mkdir -p include/near
9840 | /bin/mkdir -p include/near
Andrew Geissler595f6302022-01-24 19:11:47 +00009841 | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009842 0.14-r0/neard-0.14/include/types.h include/near/types.h
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/log.h include/near/log.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/plugin.h include/near/plugin.h
9847 | /bin/mkdir -p include/near
9848 | /bin/mkdir -p include/near
9849 | /bin/mkdir -p include/near
Andrew Geissler595f6302022-01-24 19:11:47 +00009850 | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009851 0.14-r0/neard-0.14/include/tag.h include/near/tag.h
9852 | /bin/mkdir -p include/near
Andrew Geissler595f6302022-01-24 19:11:47 +00009853 | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009854 0.14-r0/neard-0.14/include/adapter.h include/near/adapter.h
9855 | /bin/mkdir -p include/near
Andrew Geissler595f6302022-01-24 19:11:47 +00009856 | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009857 0.14-r0/neard-0.14/include/ndef.h include/near/ndef.h
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/tlv.h include/near/tlv.h
9860 | /bin/mkdir -p include/near
9861 | /bin/mkdir -p include/near
Andrew Geissler595f6302022-01-24 19:11:47 +00009862 | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009863 0.14-r0/neard-0.14/include/setting.h include/near/setting.h
9864 | /bin/mkdir -p include/near
9865 | /bin/mkdir -p include/near
9866 | /bin/mkdir -p include/near
Andrew Geissler595f6302022-01-24 19:11:47 +00009867 | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009868 0.14-r0/neard-0.14/include/device.h include/near/device.h
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/nfc_copy.h include/near/nfc_copy.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/snep.h include/near/snep.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/version.h include/near/version.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/dbus.h include/near/dbus.h
9877 | ./src/genbuiltin nfctype1 nfctype2 nfctype3 nfctype4 p2p > src/builtin.h
Andrew Geissler595f6302022-01-24 19:11:47 +00009878 | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/pokybuild/yocto-autobuilder/nightly-x86/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009879 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 +00009880 yocto-autobuilder/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/glib-2.0
9881 -I/home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/sysroots/qemux86/usr/
9882 lib/glib-2.0/include -I/home/pokybuild/yocto-autobuilder/nightly-x86/build/build/
9883 tmp/sysroots/qemux86/usr/include/dbus-1.0 -I/home/pokybuild/yocto-autobuilder/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009884 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 +00009885 nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/libnl3
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009886 -DNEAR_PLUGIN_BUILTIN -DPLUGINDIR=\""/usr/lib/near/plugins"\"
9887 -DCONFIGDIR=\""/etc/neard\"" -O2 -pipe -g -feliminate-unused-debug-types -c
9888 -o tools/snep-send.o tools/snep-send.c
9889 | In file included from tools/snep-send.c:16:0:
9890 | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
9891 | #include <near/dbus.h>
9892 | ^
9893 | compilation terminated.
9894 | make[1]: *** [tools/snep-send.o] Error 1
9895 | make[1]: *** Waiting for unfinished jobs....
9896 | make: *** [all] Error 2
9897 | ERROR: oe_runmake failed
9898
9899Reproducing the Error
9900~~~~~~~~~~~~~~~~~~~~~
9901
9902Because race conditions are intermittent, they do not manifest
9903themselves every time you do the build. In fact, most times the build
9904will complete without problems even though the potential race condition
9905exists. Thus, once the error surfaces, you need a way to reproduce it.
9906
9907In this example, compiling the "neard" package is causing the problem.
9908So the first thing to do is build "neard" locally. Before you start the
9909build, set the
9910:term:`PARALLEL_MAKE` variable
9911in your ``local.conf`` file to a high number (e.g. "-j 20"). Using a
Andrew Geissler09036742021-06-25 14:25:14 -05009912high value for :term:`PARALLEL_MAKE` increases the chances of the race
Andrew Geisslerc926e172021-05-07 16:11:35 -05009913condition showing up::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009914
9915 $ bitbake neard
9916
Andrew Geisslerc926e172021-05-07 16:11:35 -05009917Once the local build for "neard" completes, start a ``devshell`` build::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009918
9919 $ bitbake neard -c devshell
9920
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009921For information on how to use a ``devshell``, see the
9922":ref:`dev-manual/common-tasks:using a development shell`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009923
Andrew Geisslerc926e172021-05-07 16:11:35 -05009924In the ``devshell``, do the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009925
9926 $ make clean
9927 $ make tools/snep-send.o
9928
9929The ``devshell`` commands cause the failure to clearly
William A. Kennington IIIac69b482021-06-02 12:28:27 -07009930be visible. In this case, there is a missing dependency for the ``neard``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009931Makefile target. Here is some abbreviated, sample output with the
Andrew Geisslerc926e172021-05-07 16:11:35 -05009932missing dependency clearly visible at the end::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009933
9934 i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/scott-lenovo/......
9935 .
9936 .
9937 .
9938 tools/snep-send.c
9939 In file included from tools/snep-send.c:16:0:
9940 tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
9941 #include <near/dbus.h>
9942 ^
9943 compilation terminated.
9944 make: *** [tools/snep-send.o] Error 1
9945 $
9946
9947
9948Creating a Patch for the Fix
9949~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9950
9951Because there is a missing dependency for the Makefile target, you need
9952to patch the ``Makefile.am`` file, which is generated from
Andrew Geisslerc926e172021-05-07 16:11:35 -05009953``Makefile.in``. You can use Quilt to create the patch::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009954
9955 $ quilt new parallelmake.patch
9956 Patch patches/parallelmake.patch is now on top
9957 $ quilt add Makefile.am
9958 File Makefile.am added to patch patches/parallelmake.patch
9959
9960For more information on using Quilt, see the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009961":ref:`dev-manual/common-tasks:using quilt in your workflow`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009962
9963At this point you need to make the edits to ``Makefile.am`` to add the
9964missing dependency. For our example, you have to add the following line
Andrew Geisslerc926e172021-05-07 16:11:35 -05009965to the file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009966
9967 tools/snep-send.$(OBJEXT): include/near/dbus.h
9968
9969Once you have edited the file, use the ``refresh`` command to create the
Andrew Geisslerc926e172021-05-07 16:11:35 -05009970patch::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009971
9972 $ quilt refresh
9973 Refreshed patch patches/parallelmake.patch
9974
William A. Kennington IIIac69b482021-06-02 12:28:27 -07009975Once the patch file is created, you need to add it back to the originating
9976recipe folder. Here is an example assuming a top-level
Andrew Geisslerc926e172021-05-07 16:11:35 -05009977:term:`Source Directory` named ``poky``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009978
9979 $ cp patches/parallelmake.patch poky/meta/recipes-connectivity/neard/neard
9980
9981The final thing you need to do to implement the fix in the build is to
9982update the "neard" recipe (i.e. ``neard-0.14.bb``) so that the
9983:term:`SRC_URI` statement includes
9984the patch file. The recipe file is in the folder above the patch. Here
Andrew Geissler09036742021-06-25 14:25:14 -05009985is what the edited :term:`SRC_URI` statement would look like::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009986
9987 SRC_URI = "${KERNELORG_MIRROR}/linux/network/nfc/${BPN}-${PV}.tar.xz \
9988 file://neard.in \
9989 file://neard.service.in \
9990 file://parallelmake.patch \
9991 "
9992
9993With the patch complete and moved to the correct folder and the
Andrew Geissler09036742021-06-25 14:25:14 -05009994:term:`SRC_URI` statement updated, you can exit the ``devshell``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009995
9996 $ exit
9997
9998Testing the Build
9999~~~~~~~~~~~~~~~~~
10000
10001With everything in place, you can get back to trying the build again
Andrew Geisslerc926e172021-05-07 16:11:35 -050010002locally::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010003
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010004 $ bitbake neard
10005
10006This build should succeed.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010007
10008Now you can open up a ``devshell`` again and repeat the clean and make
Andrew Geisslerc926e172021-05-07 16:11:35 -050010009operations as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010010
10011 $ bitbake neard -c devshell
10012 $ make clean
10013 $ make tools/snep-send.o
10014
10015The build should work without issue.
10016
10017As with all solved problems, if they originated upstream, you need to
10018submit the fix for the recipe in OE-Core and upstream so that the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050010019problem is taken care of at its source. See the
10020":ref:`dev-manual/common-tasks:submitting a change to the yocto project`"
10021section for more information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010022
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010023Debugging With the GNU Project Debugger (GDB) Remotely
10024------------------------------------------------------
10025
10026GDB allows you to examine running programs, which in turn helps you to
10027understand and fix problems. It also allows you to perform post-mortem
10028style analysis of program crashes. GDB is available as a package within
10029the Yocto Project and is installed in SDK images by default. See the
Andrew Geissler09209ee2020-12-13 08:44:15 -060010030":ref:`ref-manual/images:Images`" chapter in the Yocto
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010031Project Reference Manual for a description of these images. You can find
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010032information on GDB at https://sourceware.org/gdb/.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010033
10034.. note::
10035
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010036 For best results, install debug (``-dbg``) packages for the applications you
10037 are going to debug. Doing so makes extra debug symbols available that give
10038 you more meaningful output.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010039
10040Sometimes, due to memory or disk space constraints, it is not possible
10041to use GDB directly on the remote target to debug applications. These
10042constraints arise because GDB needs to load the debugging information
10043and the binaries of the process being debugged. Additionally, GDB needs
10044to perform many computations to locate information such as function
Andrew Geissler615f2f12022-07-15 14:00:58 -050010045names, variable names and values, stack traces and so forth --- even
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010046before starting the debugging process. These extra computations place
10047more load on the target system and can alter the characteristics of the
10048program being debugged.
10049
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010050To help get past the previously mentioned constraints, there are two
10051methods you can use: running a debuginfod server and using gdbserver.
10052
10053Using the debuginfod server method
10054~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10055
Andrew Geisslerc926e172021-05-07 16:11:35 -050010056``debuginfod`` from ``elfutils`` is a way to distribute ``debuginfo`` files.
10057Running a ``debuginfod`` server makes debug symbols readily available,
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010058which means you don't need to download debugging information
10059and the binaries of the process being debugged. You can just fetch
10060debug symbols from the server.
10061
Andrew Geisslerc926e172021-05-07 16:11:35 -050010062To run a ``debuginfod`` server, you need to do the following:
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010063
Andrew Geisslerc926e172021-05-07 16:11:35 -050010064- Ensure that ``debuginfod`` is present in :term:`DISTRO_FEATURES`
10065 (it already is in ``OpenEmbedded-core`` defaults and ``poky`` reference distribution).
10066 If not, set in your distro config file or in ``local.conf``::
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010067
Patrick Williams0ca19cc2021-08-16 14:03:13 -050010068 DISTRO_FEATURES:append = " debuginfod"
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010069
Andrew Geisslerc926e172021-05-07 16:11:35 -050010070 This distro feature enables the server and client library in ``elfutils``,
10071 and enables ``debuginfod`` support in clients (at the moment, ``gdb`` and ``binutils``).
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010072
Andrew Geisslerc926e172021-05-07 16:11:35 -050010073- Run the following commands to launch the ``debuginfod`` server on the host::
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010074
10075 $ oe-debuginfod
10076
Andrew Geisslerc926e172021-05-07 16:11:35 -050010077- To use ``debuginfod`` on the target, you need to know the ip:port where
10078 ``debuginfod`` is listening on the host (port defaults to 8002), and export
10079 that into the shell environment, for example in ``qemu``::
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010080
Andrew Geisslerc926e172021-05-07 16:11:35 -050010081 root@qemux86-64:~# export DEBUGINFOD_URLS="http://192.168.7.1:8002/"
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010082
Andrew Geisslerc926e172021-05-07 16:11:35 -050010083- Then debug info fetching should simply work when running the target ``gdb``,
10084 ``readelf`` or ``objdump``, for example::
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010085
Andrew Geisslerc926e172021-05-07 16:11:35 -050010086 root@qemux86-64:~# gdb /bin/cat
10087 ...
10088 Reading symbols from /bin/cat...
10089 Downloading separate debug info for /bin/cat...
10090 Reading symbols from /home/root/.cache/debuginfod_client/923dc4780cfbc545850c616bffa884b6b5eaf322/debuginfo...
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010091
Andrew Geisslerc926e172021-05-07 16:11:35 -050010092- It's also possible to use ``debuginfod-find`` to just query the server::
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010093
Andrew Geisslerc926e172021-05-07 16:11:35 -050010094 root@qemux86-64:~# debuginfod-find debuginfo /bin/ls
10095 /home/root/.cache/debuginfod_client/356edc585f7f82d46f94fcb87a86a3fe2d2e60bd/debuginfo
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010096
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010097
10098Using the gdbserver method
10099~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10100
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010101gdbserver, which runs on the remote target and does not load any
10102debugging information from the debugged process. Instead, a GDB instance
10103processes the debugging information that is run on a remote computer -
10104the host GDB. The host GDB then sends control commands to gdbserver to
10105make it stop or start the debugged program, as well as read or write
10106memory regions of that debugged program. All the debugging information
10107loaded and processed as well as all the heavy debugging is done by the
10108host GDB. Offloading these processes gives the gdbserver running on the
10109target a chance to remain small and fast.
10110
10111Because the host GDB is responsible for loading the debugging
10112information and for doing the necessary processing to make actual
10113debugging happen, you have to make sure the host can access the
10114unstripped binaries complete with their debugging information and also
10115be sure the target is compiled with no optimizations. The host GDB must
10116also have local access to all the libraries used by the debugged
10117program. Because gdbserver does not need any local debugging
10118information, the binaries on the remote target can remain stripped.
10119However, the binaries must also be compiled without optimization so they
10120match the host's binaries.
10121
10122To remain consistent with GDB documentation and terminology, the binary
10123being debugged on the remote target machine is referred to as the
10124"inferior" binary. For documentation on GDB see the `GDB
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010125site <https://sourceware.org/gdb/documentation/>`__.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010126
10127The following steps show you how to debug using the GNU project
10128debugger.
10129
101301. *Configure your build system to construct the companion debug
10131 filesystem:*
10132
Andrew Geisslerc926e172021-05-07 16:11:35 -050010133 In your ``local.conf`` file, set the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010134
10135 IMAGE_GEN_DEBUGFS = "1"
10136 IMAGE_FSTYPES_DEBUGFS = "tar.bz2"
10137
10138 These options cause the
10139 OpenEmbedded build system to generate a special companion filesystem
10140 fragment, which contains the matching source and debug symbols to
10141 your deployable filesystem. The build system does this by looking at
10142 what is in the deployed filesystem, and pulling the corresponding
10143 ``-dbg`` packages.
10144
10145 The companion debug filesystem is not a complete filesystem, but only
10146 contains the debug fragments. This filesystem must be combined with
10147 the full filesystem for debugging. Subsequent steps in this procedure
10148 show how to combine the partial filesystem with the full filesystem.
10149
101502. *Configure the system to include gdbserver in the target filesystem:*
10151
Andrew Geisslerd5838332022-05-27 11:33:10 -050010152 Make the following addition in your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010153
Andrew Geisslerd5838332022-05-27 11:33:10 -050010154 EXTRA_IMAGE_FEATURES:append = " tools-debug"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010155
10156 The change makes
10157 sure the ``gdbserver`` package is included.
10158
101593. *Build the environment:*
10160
10161 Use the following command to construct the image and the companion
Andrew Geisslerc926e172021-05-07 16:11:35 -050010162 Debug Filesystem::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010163
10164 $ bitbake image
10165
10166 Build the cross GDB component and
10167 make it available for debugging. Build the SDK that matches the
10168 image. Building the SDK is best for a production build that can be
Andrew Geisslerc926e172021-05-07 16:11:35 -050010169 used later for debugging, especially during long term maintenance::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010170
10171 $ bitbake -c populate_sdk image
10172
10173 Alternatively, you can build the minimal toolchain components that
10174 match the target. Doing so creates a smaller than typical SDK and
10175 only contains a minimal set of components with which to build simple
Andrew Geisslerc926e172021-05-07 16:11:35 -050010176 test applications, as well as run the debugger::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010177
10178 $ bitbake meta-toolchain
10179
Andrew Geisslerc926e172021-05-07 16:11:35 -050010180 A final method is to build Gdb itself within the build system::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010181
10182 $ bitbake gdb-cross-<architecture>
10183
10184 Doing so produces a temporary copy of
10185 ``cross-gdb`` you can use for debugging during development. While
10186 this is the quickest approach, the two previous methods in this step
10187 are better when considering long-term maintenance strategies.
10188
10189 .. note::
10190
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010191 If you run ``bitbake gdb-cross``, the OpenEmbedded build system suggests
10192 the actual image (e.g. ``gdb-cross-i586``). The suggestion is usually the
10193 actual name you want to use.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010194
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500101954. *Set up the* ``debugfs``\ *:*
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010196
Andrew Geisslerc926e172021-05-07 16:11:35 -050010197 Run the following commands to set up the ``debugfs``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010198
10199 $ mkdir debugfs
10200 $ cd debugfs
Andrew Geisslerd5838332022-05-27 11:33:10 -050010201 $ tar xvfj build-dir/tmp/deploy/images/machine/image.rootfs.tar.bz2
10202 $ tar xvfj build-dir/tmp/deploy/images/machine/image-dbg.rootfs.tar.bz2
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010203
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500102045. *Set up GDB:*
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010205
10206 Install the SDK (if you built one) and then source the correct
10207 environment file. Sourcing the environment file puts the SDK in your
Andrew Geisslerd5838332022-05-27 11:33:10 -050010208 ``PATH`` environment variable and sets ``$GDB`` to the SDK's debugger.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010209
10210 If you are using the build system, Gdb is located in
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010211 `build-dir`\ ``/tmp/sysroots/``\ `host`\ ``/usr/bin/``\ `architecture`\ ``/``\ `architecture`\ ``-gdb``
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010212
102136. *Boot the target:*
10214
10215 For information on how to run QEMU, see the `QEMU
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010216 Documentation <https://wiki.qemu.org/Documentation/GettingStartedDevelopers>`__.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010217
10218 .. note::
10219
10220 Be sure to verify that your host can access the target via TCP.
10221
102227. *Debug a program:*
10223
10224 Debugging a program involves running gdbserver on the target and then
10225 running Gdb on the host. The example in this step debugs ``gzip``:
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010226
10227 .. code-block:: shell
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010228
10229 root@qemux86:~# gdbserver localhost:1234 /bin/gzip —help
10230
10231 For
10232 additional gdbserver options, see the `GDB Server
10233 Documentation <https://www.gnu.org/software/gdb/documentation/>`__.
10234
10235 After running gdbserver on the target, you need to run Gdb on the
Andrew Geisslerc926e172021-05-07 16:11:35 -050010236 host and configure it and connect to the target. Use these commands::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010237
10238 $ cd directory-holding-the-debugfs-directory
10239 $ arch-gdb
10240 (gdb) set sysroot debugfs
10241 (gdb) set substitute-path /usr/src/debug debugfs/usr/src/debug
10242 (gdb) target remote IP-of-target:1234
10243
10244 At this
10245 point, everything should automatically load (i.e. matching binaries,
10246 symbols and headers).
10247
10248 .. note::
10249
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010250 The Gdb ``set`` commands in the previous example can be placed into the
10251 users ``~/.gdbinit`` file. Upon starting, Gdb automatically runs whatever
10252 commands are in that file.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010253
102548. *Deploying without a full image rebuild:*
10255
10256 In many cases, during development you want a quick method to deploy a
10257 new binary to the target and debug it, without waiting for a full
10258 image build.
10259
10260 One approach to solving this situation is to just build the component
10261 you want to debug. Once you have built the component, copy the
10262 executable directly to both the target and the host ``debugfs``.
10263
10264 If the binary is processed through the debug splitting in
10265 OpenEmbedded, you should also copy the debug items (i.e. ``.debug``
10266 contents and corresponding ``/usr/src/debug`` files) from the work
Andrew Geisslerc926e172021-05-07 16:11:35 -050010267 directory. Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010268
10269 $ bitbake bash
10270 $ bitbake -c devshell bash
10271 $ cd ..
10272 $ scp packages-split/bash/bin/bash target:/bin/bash
10273 $ cp -a packages-split/bash-dbg/\* path/debugfs
10274
10275Debugging with the GNU Project Debugger (GDB) on the Target
10276-----------------------------------------------------------
10277
10278The previous section addressed using GDB remotely for debugging
10279purposes, which is the most usual case due to the inherent hardware
10280limitations on many embedded devices. However, debugging in the target
10281hardware itself is also possible with more powerful devices. This
10282section describes what you need to do in order to support using GDB to
10283debug on the target hardware.
10284
10285To support this kind of debugging, you need do the following:
10286
Andrew Geisslerd5838332022-05-27 11:33:10 -050010287- Ensure that GDB is on the target. You can do this by making
10288 the following addition to your ``local.conf`` file::
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010289
Andrew Geisslerd5838332022-05-27 11:33:10 -050010290 EXTRA_IMAGE_FEATURES:append = " tools-debug"
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010291
Andrew Geisslerd5838332022-05-27 11:33:10 -050010292- Ensure that debug symbols are present. You can do so by adding the
10293 corresponding ``-dbg`` package to :term:`IMAGE_INSTALL`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010294
Andrew Geisslerd5838332022-05-27 11:33:10 -050010295 IMAGE_INSTALL:append = " packagename-dbg"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010296
Andrew Geisslerd5838332022-05-27 11:33:10 -050010297 Alternatively, you can add the following to ``local.conf`` to include
Andrew Geisslerc926e172021-05-07 16:11:35 -050010298 all the debug symbols::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010299
Andrew Geisslerd5838332022-05-27 11:33:10 -050010300 EXTRA_IMAGE_FEATURES:append = " dbg-pkgs"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010301
10302.. note::
10303
10304 To improve the debug information accuracy, you can reduce the level
10305 of optimization used by the compiler. For example, when adding the
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010306 following line to your ``local.conf`` file, you will reduce optimization
10307 from :term:`FULL_OPTIMIZATION` of "-O2" to :term:`DEBUG_OPTIMIZATION`
Andrew Geisslerc926e172021-05-07 16:11:35 -050010308 of "-O -fno-omit-frame-pointer"::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010309
10310 DEBUG_BUILD = "1"
10311
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010312 Consider that this will reduce the application's performance and is
10313 recommended only for debugging purposes.
10314
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010315Other Debugging Tips
10316--------------------
10317
10318Here are some other tips that you might find useful:
10319
10320- When adding new packages, it is worth watching for undesirable items
10321 making their way into compiler command lines. For example, you do not
10322 want references to local system files like ``/usr/lib/`` or
10323 ``/usr/include/``.
10324
10325- If you want to remove the ``psplash`` boot splashscreen, add
10326 ``psplash=false`` to the kernel command line. Doing so prevents
10327 ``psplash`` from loading and thus allows you to see the console. It
10328 is also possible to switch out of the splashscreen by switching the
10329 virtual console (e.g. Fn+Left or Fn+Right on a Zaurus).
10330
Patrick Williams2390b1b2022-11-03 13:47:49 -050010331- Removing :term:`TMPDIR` (usually ``tmp/``, within the
10332 :term:`Build Directory`) can often fix temporary build issues. Removing
10333 :term:`TMPDIR` is usually a relatively cheap operation, because task output
10334 will be cached in :term:`SSTATE_DIR` (usually ``sstate-cache/``, which is
10335 also in the :term:`Build Directory`).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010336
10337 .. note::
10338
Andrew Geissler09036742021-06-25 14:25:14 -050010339 Removing :term:`TMPDIR` might be a workaround rather than a fix.
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010340 Consequently, trying to determine the underlying cause of an issue before
10341 removing the directory is a good idea.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010342
10343- Understanding how a feature is used in practice within existing
10344 recipes can be very helpful. It is recommended that you configure
10345 some method that allows you to quickly search through files.
10346
10347 Using GNU Grep, you can use the following shell function to
10348 recursively search through common recipe-related files, skipping
Patrick Williams2390b1b2022-11-03 13:47:49 -050010349 binary files, ``.git`` directories, and the :term:`Build Directory`
10350 (assuming its name starts with "build")::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010351
10352 g() {
10353 grep -Ir \
10354 --exclude-dir=.git \
10355 --exclude-dir='build*' \
10356 --include='*.bb*' \
10357 --include='*.inc*' \
10358 --include='*.conf*' \
10359 --include='*.py*' \
10360 "$@"
10361 }
10362
Andrew Geisslerc926e172021-05-07 16:11:35 -050010363 Following are some usage examples::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010364
10365 $ g FOO # Search recursively for "FOO"
10366 $ g -i foo # Search recursively for "foo", ignoring case
10367 $ g -w FOO # Search recursively for "FOO" as a word, ignoring e.g. "FOOBAR"
10368
10369 If figuring
10370 out how some feature works requires a lot of searching, it might
10371 indicate that the documentation should be extended or improved. In
10372 such cases, consider filing a documentation bug using the Yocto
10373 Project implementation of
10374 :yocto_bugs:`Bugzilla <>`. For information on
10375 how to submit a bug against the Yocto Project, see the Yocto Project
Andrew Geissler09209ee2020-12-13 08:44:15 -060010376 Bugzilla :yocto_wiki:`wiki page </Bugzilla_Configuration_and_Bug_Tracking>`
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050010377 and the
10378 ":ref:`dev-manual/common-tasks:submitting a defect against the yocto project`"
10379 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010380
10381 .. note::
10382
10383 The manuals might not be the right place to document variables
10384 that are purely internal and have a limited scope (e.g. internal
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010385 variables used to implement a single ``.bbclass`` file).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010386
10387Making Changes to the Yocto Project
10388===================================
10389
10390Because the Yocto Project is an open-source, community-based project,
10391you can effect changes to the project. This section presents procedures
10392that show you how to submit a defect against the project and how to
10393submit a change.
10394
10395Submitting a Defect Against the Yocto Project
10396---------------------------------------------
10397
10398Use the Yocto Project implementation of
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010399`Bugzilla <https://www.bugzilla.org/about/>`__ to submit a defect (bug)
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010400against the Yocto Project. For additional information on this
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010401implementation of Bugzilla see the ":ref:`Yocto Project
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010402Bugzilla <resources-bugtracker>`" section in the
10403Yocto Project Reference Manual. For more detail on any of the following
10404steps, see the Yocto Project
Andrew Geissler09209ee2020-12-13 08:44:15 -060010405:yocto_wiki:`Bugzilla wiki page </Bugzilla_Configuration_and_Bug_Tracking>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010406
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010407Use the following general steps to submit a bug:
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010408
104091. Open the Yocto Project implementation of :yocto_bugs:`Bugzilla <>`.
10410
104112. Click "File a Bug" to enter a new bug.
10412
104133. Choose the appropriate "Classification", "Product", and "Component"
10414 for which the bug was found. Bugs for the Yocto Project fall into
10415 one of several classifications, which in turn break down into
10416 several products and components. For example, for a bug against the
10417 ``meta-intel`` layer, you would choose "Build System, Metadata &
10418 Runtime", "BSPs", and "bsps-meta-intel", respectively.
10419
104204. Choose the "Version" of the Yocto Project for which you found the
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010421 bug (e.g. &DISTRO;).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010422
104235. Determine and select the "Severity" of the bug. The severity
10424 indicates how the bug impacted your work.
10425
104266. Choose the "Hardware" that the bug impacts.
10427
104287. Choose the "Architecture" that the bug impacts.
10429
104308. Choose a "Documentation change" item for the bug. Fixing a bug might
10431 or might not affect the Yocto Project documentation. If you are
10432 unsure of the impact to the documentation, select "Don't Know".
10433
104349. Provide a brief "Summary" of the bug. Try to limit your summary to
10435 just a line or two and be sure to capture the essence of the bug.
10436
1043710. Provide a detailed "Description" of the bug. You should provide as
10438 much detail as you can about the context, behavior, output, and so
10439 forth that surrounds the bug. You can even attach supporting files
10440 for output from logs by using the "Add an attachment" button.
10441
1044211. Click the "Submit Bug" button submit the bug. A new Bugzilla number
10443 is assigned to the bug and the defect is logged in the bug tracking
10444 system.
10445
10446Once you file a bug, the bug is processed by the Yocto Project Bug
10447Triage Team and further details concerning the bug are assigned (e.g.
10448priority and owner). You are the "Submitter" of the bug and any further
10449categorization, progress, or comments on the bug result in Bugzilla
10450sending you an automated email concerning the particular change or
10451progress to the bug.
10452
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010453Submitting a Change to the Yocto Project
10454----------------------------------------
10455
10456Contributions to the Yocto Project and OpenEmbedded are very welcome.
10457Because the system is extremely configurable and flexible, we recognize
10458that developers will want to extend, configure or optimize it for their
10459specific uses.
10460
10461The Yocto Project uses a mailing list and a patch-based workflow that is
10462similar to the Linux kernel but contains important differences. In
William A. Kennington IIIac69b482021-06-02 12:28:27 -070010463general, there is a mailing list through which you can submit patches. You
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010464should send patches to the appropriate mailing list so that they can be
10465reviewed and merged by the appropriate maintainer. The specific mailing
10466list you need to use depends on the location of the code you are
10467changing. Each component (e.g. layer) should have a ``README`` file that
10468indicates where to send the changes and which process to follow.
10469
10470You can send the patch to the mailing list using whichever approach you
10471feel comfortable with to generate the patch. Once sent, the patch is
10472usually reviewed by the community at large. If somebody has concerns
10473with the patch, they will usually voice their concern over the mailing
10474list. If a patch does not receive any negative reviews, the maintainer
10475of the affected layer typically takes the patch, tests it, and then
10476based on successful testing, merges the patch.
10477
10478The "poky" repository, which is the Yocto Project's reference build
10479environment, is a hybrid repository that contains several individual
10480pieces (e.g. BitBake, Metadata, documentation, and so forth) built using
10481the combo-layer tool. The upstream location used for submitting changes
10482varies by component:
10483
10484- *Core Metadata:* Send your patch to the
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010485 :oe_lists:`openembedded-core </g/openembedded-core>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010486 mailing list. For example, a change to anything under the ``meta`` or
10487 ``scripts`` directories should be sent to this mailing list.
10488
10489- *BitBake:* For changes to BitBake (i.e. anything under the
10490 ``bitbake`` directory), send your patch to the
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010491 :oe_lists:`bitbake-devel </g/bitbake-devel>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010492 mailing list.
10493
Andrew Geisslerc3d88e42020-10-02 09:45:00 -050010494- *"meta-\*" trees:* These trees contain Metadata. Use the
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010495 :yocto_lists:`poky </g/poky>` mailing list.
Andrew Geisslerc3d88e42020-10-02 09:45:00 -050010496
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010497- *Documentation*: For changes to the Yocto Project documentation, use the
10498 :yocto_lists:`docs </g/docs>` mailing list.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010499
10500For changes to other layers hosted in the Yocto Project source
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010501repositories (i.e. ``yoctoproject.org``) and tools use the
10502:yocto_lists:`Yocto Project </g/yocto/>` general mailing list.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010503
10504.. note::
10505
10506 Sometimes a layer's documentation specifies to use a particular
10507 mailing list. If so, use that list.
10508
10509For additional recipes that do not fit into the core Metadata, you
10510should determine which layer the recipe should go into and submit the
10511change in the manner recommended by the documentation (e.g. the
10512``README`` file) supplied with the layer. If in doubt, please ask on the
10513Yocto general mailing list or on the openembedded-devel mailing list.
10514
10515You can also push a change upstream and request a maintainer to pull the
10516change into the component's upstream repository. You do this by pushing
Andrew Geissler09209ee2020-12-13 08:44:15 -060010517to a contribution repository that is upstream. See the
10518":ref:`overview-manual/development-environment:git workflows and the yocto project`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010519section in the Yocto Project Overview and Concepts Manual for additional
10520concepts on working in the Yocto Project development environment.
10521
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010522Maintainers commonly use ``-next`` branches to test submissions prior to
10523merging patches. Thus, you can get an idea of the status of a patch based on
10524whether the patch has been merged into one of these branches. The commonly
10525used testing branches for OpenEmbedded-Core are as follows:
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010526
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010527- *openembedded-core "master-next" branch:* This branch is part of the
10528 :oe_git:`openembedded-core </openembedded-core/>` repository and contains
10529 proposed changes to the core metadata.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010530
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010531- *poky "master-next" branch:* This branch is part of the
Andrew Geissler09209ee2020-12-13 08:44:15 -060010532 :yocto_git:`poky </poky/>` repository and combines proposed
Andrew Geisslerd5838332022-05-27 11:33:10 -050010533 changes to BitBake, the core metadata and the poky distro.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010534
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010535Similarly, stable branches maintained by the project may have corresponding
10536``-next`` branches which collect proposed changes. For example,
10537``&DISTRO_NAME_NO_CAP;-next`` and ``&DISTRO_NAME_NO_CAP_MINUS_ONE;-next``
10538branches in both the "openembdedded-core" and "poky" repositories.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010539
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010540Other layers may have similar testing branches but there is no formal
10541requirement or standard for these so please check the documentation for the
10542layers you are contributing to.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010543
10544The following sections provide procedures for submitting a change.
10545
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010546Preparing Changes for Submission
10547~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010548
105491. *Make Your Changes Locally:* Make your changes in your local Git
10550 repository. You should make small, controlled, isolated changes.
10551 Keeping changes small and isolated aids review, makes
10552 merging/rebasing easier and keeps the change history clean should
10553 anyone need to refer to it in future.
10554
105552. *Stage Your Changes:* Stage your changes by using the ``git add``
10556 command on each file you changed.
10557
105583. *Commit Your Changes:* Commit the change by using the ``git commit``
10559 command. Make sure your commit information follows standards by
10560 following these accepted conventions:
10561
10562 - Be sure to include a "Signed-off-by:" line in the same style as
Patrick Williams03907ee2022-05-01 06:28:52 -050010563 required by the Linux kernel. This can be done by using the
10564 ``git commit -s`` command. Adding this line signifies that you,
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010565 the submitter, have agreed to the Developer's Certificate of
10566 Origin 1.1 as follows:
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010567
10568 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010569
10570 Developer's Certificate of Origin 1.1
10571
10572 By making a contribution to this project, I certify that:
10573
10574 (a) The contribution was created in whole or in part by me and I
10575 have the right to submit it under the open source license
10576 indicated in the file; or
10577
10578 (b) The contribution is based upon previous work that, to the best
10579 of my knowledge, is covered under an appropriate open source
10580 license and I have the right under that license to submit that
10581 work with modifications, whether created in whole or in part
10582 by me, under the same open source license (unless I am
10583 permitted to submit under a different license), as indicated
10584 in the file; or
10585
10586 (c) The contribution was provided directly to me by some other
10587 person who certified (a), (b) or (c) and I have not modified
10588 it.
10589
10590 (d) I understand and agree that this project and the contribution
10591 are public and that a record of the contribution (including all
10592 personal information I submit with it, including my sign-off) is
10593 maintained indefinitely and may be redistributed consistent with
10594 this project or the open source license(s) involved.
10595
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010596 - Provide a single-line summary of the change and, if more
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010597 explanation is needed, provide more detail in the body of the
10598 commit. This summary is typically viewable in the "shortlist" of
10599 changes. Thus, providing something short and descriptive that
10600 gives the reader a summary of the change is useful when viewing a
10601 list of many commits. You should prefix this short description
10602 with the recipe name (if changing a recipe), or else with the
10603 short form path to the file being changed.
10604
10605 - For the body of the commit message, provide detailed information
10606 that describes what you changed, why you made the change, and the
10607 approach you used. It might also be helpful if you mention how you
10608 tested the change. Provide as much detail as you can in the body
10609 of the commit message.
10610
10611 .. note::
10612
10613 You do not need to provide a more detailed explanation of a
10614 change if the change is minor to the point of the single line
10615 summary providing all the information.
10616
10617 - If the change addresses a specific bug or issue that is associated
10618 with a bug-tracking ID, include a reference to that ID in your
10619 detailed description. For example, the Yocto Project uses a
Andrew Geissler615f2f12022-07-15 14:00:58 -050010620 specific convention for bug references --- any commit that addresses
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010621 a specific bug should use the following form for the detailed
10622 description. Be sure to use the actual bug-tracking ID from
Andrew Geisslerc926e172021-05-07 16:11:35 -050010623 Bugzilla for bug-id::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010624
10625 Fixes [YOCTO #bug-id]
10626
10627 detailed description of change
10628
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010629Using Email to Submit a Patch
10630~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10631
10632Depending on the components changed, you need to submit the email to a
10633specific mailing list. For some guidance on which mailing list to use,
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050010634see the
10635:ref:`list <dev-manual/common-tasks:submitting a change to the yocto project>`
10636at the beginning of this section. For a description of all the available
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010637mailing lists, see the ":ref:`Mailing Lists <resources-mailinglist>`" section in the
10638Yocto Project Reference Manual.
10639
10640Here is the general procedure on how to submit a patch through email
10641without using the scripts once the steps in
Andrew Geissler09209ee2020-12-13 08:44:15 -060010642:ref:`dev-manual/common-tasks:preparing changes for submission` have been followed:
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010643
106441. *Format the Commit:* Format the commit into an email message. To
10645 format commits, use the ``git format-patch`` command. When you
10646 provide the command, you must include a revision list or a number of
10647 patches as part of the command. For example, either of these two
10648 commands takes your most recent single commit and formats it as an
Andrew Geisslerc926e172021-05-07 16:11:35 -050010649 email message in the current directory::
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010650
10651 $ git format-patch -1
10652
10653 or ::
10654
10655 $ git format-patch HEAD~
10656
10657 After the command is run, the current directory contains a numbered
10658 ``.patch`` file for the commit.
10659
10660 If you provide several commits as part of the command, the
10661 ``git format-patch`` command produces a series of numbered files in
10662 the current directory – one for each commit. If you have more than
10663 one patch, you should also use the ``--cover`` option with the
10664 command, which generates a cover letter as the first "patch" in the
10665 series. You can then edit the cover letter to provide a description
10666 for the series of patches. For information on the
10667 ``git format-patch`` command, see ``GIT_FORMAT_PATCH(1)`` displayed
10668 using the ``man git-format-patch`` command.
10669
10670 .. note::
10671
10672 If you are or will be a frequent contributor to the Yocto Project
10673 or to OpenEmbedded, you might consider requesting a contrib area
10674 and the necessary associated rights.
10675
106762. *Send the patches via email:* Send the patches to the recipients and
10677 relevant mailing lists by using the ``git send-email`` command.
10678
10679 .. note::
10680
10681 In order to use ``git send-email``, you must have the proper Git packages
10682 installed on your host.
10683 For Ubuntu, Debian, and Fedora the package is ``git-email``.
10684
10685 The ``git send-email`` command sends email by using a local or remote
10686 Mail Transport Agent (MTA) such as ``msmtp``, ``sendmail``, or
10687 through a direct ``smtp`` configuration in your Git ``~/.gitconfig``
10688 file. If you are submitting patches through email only, it is very
10689 important that you submit them without any whitespace or HTML
10690 formatting that either you or your mailer introduces. The maintainer
10691 that receives your patches needs to be able to save and apply them
10692 directly from your emails. A good way to verify that what you are
10693 sending will be applicable by the maintainer is to do a dry run and
10694 send them to yourself and then save and apply them as the maintainer
10695 would.
10696
10697 The ``git send-email`` command is the preferred method for sending
10698 your patches using email since there is no risk of compromising
10699 whitespace in the body of the message, which can occur when you use
10700 your own mail client. The command also has several options that let
10701 you specify recipients and perform further editing of the email
10702 message. For information on how to use the ``git send-email``
10703 command, see ``GIT-SEND-EMAIL(1)`` displayed using the
10704 ``man git-send-email`` command.
10705
10706The Yocto Project uses a `Patchwork instance <https://patchwork.openembedded.org/>`__
10707to track the status of patches submitted to the various mailing lists and to
10708support automated patch testing. Each submitted patch is checked for common
10709mistakes and deviations from the expected patch format and submitters are
10710notified by patchtest if such mistakes are found. This process helps to
10711reduce the burden of patch review on maintainers.
10712
10713.. note::
10714
10715 This system is imperfect and changes can sometimes get lost in the flow.
10716 Asking about the status of a patch or change is reasonable if the change
10717 has been idle for a while with no feedback.
10718
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010719Using Scripts to Push a Change Upstream and Request a Pull
10720~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10721
10722For larger patch series it is preferable to send a pull request which not
10723only includes the patch but also a pointer to a branch that can be pulled
10724from. This involves making a local branch for your changes, pushing this
10725branch to an accessible repository and then using the ``create-pull-request``
10726and ``send-pull-request`` scripts from openembedded-core to create and send a
10727patch series with a link to the branch for review.
10728
10729Follow this procedure to push a change to an upstream "contrib" Git
Andrew Geissler09209ee2020-12-13 08:44:15 -060010730repository once the steps in :ref:`dev-manual/common-tasks:preparing changes for submission` have
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010731been followed:
10732
10733.. note::
10734
10735 You can find general Git information on how to push a change upstream
10736 in the
10737 `Git Community Book <https://git-scm.com/book/en/v2/Distributed-Git-Distributed-Workflows>`__.
10738
107391. *Push Your Commits to a "Contrib" Upstream:* If you have arranged for
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010740 permissions to push to an upstream contrib repository, push the
Andrew Geisslerc926e172021-05-07 16:11:35 -050010741 change to that repository::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010742
10743 $ git push upstream_remote_repo local_branch_name
10744
10745 For example, suppose you have permissions to push
10746 into the upstream ``meta-intel-contrib`` repository and you are
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010747 working in a local branch named `your_name`\ ``/README``. The following
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010748 command pushes your local commits to the ``meta-intel-contrib``
10749 upstream repository and puts the commit in a branch named
Andrew Geisslerc926e172021-05-07 16:11:35 -050010750 `your_name`\ ``/README``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010751
10752 $ git push meta-intel-contrib your_name/README
10753
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600107542. *Determine Who to Notify:* Determine the maintainer or the mailing
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010755 list that you need to notify for the change.
10756
10757 Before submitting any change, you need to be sure who the maintainer
10758 is or what mailing list that you need to notify. Use either these
10759 methods to find out:
10760
10761 - *Maintenance File:* Examine the ``maintainers.inc`` file, which is
10762 located in the :term:`Source Directory` at
10763 ``meta/conf/distro/include``, to see who is responsible for code.
10764
Andrew Geissler09209ee2020-12-13 08:44:15 -060010765 - *Search by File:* Using :ref:`overview-manual/development-environment:git`, you can
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010766 enter the following command to bring up a short list of all
Andrew Geisslerc926e172021-05-07 16:11:35 -050010767 commits against a specific file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010768
10769 git shortlog -- filename
10770
10771 Just provide the name of the file for which you are interested. The
10772 information returned is not ordered by history but does include a
10773 list of everyone who has committed grouped by name. From the list,
10774 you can see who is responsible for the bulk of the changes against
10775 the file.
10776
10777 - *Examine the List of Mailing Lists:* For a list of the Yocto
10778 Project and related mailing lists, see the ":ref:`Mailing
10779 lists <resources-mailinglist>`" section in
10780 the Yocto Project Reference Manual.
10781
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600107823. *Make a Pull Request:* Notify the maintainer or the mailing list that
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010783 you have pushed a change by making a pull request.
10784
10785 The Yocto Project provides two scripts that conveniently let you
10786 generate and send pull requests to the Yocto Project. These scripts
10787 are ``create-pull-request`` and ``send-pull-request``. You can find
10788 these scripts in the ``scripts`` directory within the
10789 :term:`Source Directory` (e.g.
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010790 ``poky/scripts``).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010791
10792 Using these scripts correctly formats the requests without
10793 introducing any whitespace or HTML formatting. The maintainer that
10794 receives your patches either directly or through the mailing list
10795 needs to be able to save and apply them directly from your emails.
10796 Using these scripts is the preferred method for sending patches.
10797
10798 First, create the pull request. For example, the following command
10799 runs the script, specifies the upstream repository in the contrib
10800 directory into which you pushed the change, and provides a subject
Andrew Geisslerc926e172021-05-07 16:11:35 -050010801 line in the created patch files::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010802
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010803 $ poky/scripts/create-pull-request -u meta-intel-contrib -s "Updated Manual Section Reference in README"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010804
10805 Running this script forms ``*.patch`` files in a folder named
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010806 ``pull-``\ `PID` in the current directory. One of the patch files is a
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010807 cover letter.
10808
10809 Before running the ``send-pull-request`` script, you must edit the
10810 cover letter patch to insert information about your change. After
10811 editing the cover letter, send the pull request. For example, the
10812 following command runs the script and specifies the patch directory
10813 and email address. In this example, the email address is a mailing
Andrew Geisslerc926e172021-05-07 16:11:35 -050010814 list::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010815
Andrew Geissler5199d832021-09-24 16:47:35 -050010816 $ poky/scripts/send-pull-request -p ~/meta-intel/pull-10565 -t meta-intel@lists.yoctoproject.org
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010817
10818 You need to follow the prompts as the script is interactive.
10819
10820 .. note::
10821
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010822 For help on using these scripts, simply provide the ``-h``
Andrew Geisslerc926e172021-05-07 16:11:35 -050010823 argument as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010824
10825 $ poky/scripts/create-pull-request -h
10826 $ poky/scripts/send-pull-request -h
10827
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010828Responding to Patch Review
10829~~~~~~~~~~~~~~~~~~~~~~~~~~
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010830
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010831You may get feedback on your submitted patches from other community members
10832or from the automated patchtest service. If issues are identified in your
10833patch then it is usually necessary to address these before the patch will be
10834accepted into the project. In this case you should amend the patch according
10835to the feedback and submit an updated version to the relevant mailing list,
10836copying in the reviewers who provided feedback to the previous version of the
10837patch.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010838
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010839The patch should be amended using ``git commit --amend`` or perhaps ``git
10840rebase`` for more expert git users. You should also modify the ``[PATCH]``
10841tag in the email subject line when sending the revised patch to mark the new
10842iteration as ``[PATCH v2]``, ``[PATCH v3]``, etc as appropriate. This can be
10843done by passing the ``-v`` argument to ``git format-patch`` with a version
10844number.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010845
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010846Lastly please ensure that you also test your revised changes. In particular
10847please don't just edit the patch file written out by ``git format-patch`` and
10848resend it.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010849
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010850Submitting Changes to Stable Release Branches
10851~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010852
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010853The process for proposing changes to a Yocto Project stable branch differs
10854from the steps described above. Changes to a stable branch must address
10855identified bugs or CVEs and should be made carefully in order to avoid the
10856risk of introducing new bugs or breaking backwards compatibility. Typically
10857bug fixes must already be accepted into the master branch before they can be
10858backported to a stable branch unless the bug in question does not affect the
10859master branch or the fix on the master branch is unsuitable for backporting.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010860
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010861The list of stable branches along with the status and maintainer for each
10862branch can be obtained from the
Andrew Geissler09209ee2020-12-13 08:44:15 -060010863:yocto_wiki:`Releases wiki page </Releases>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010864
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010865.. note::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010866
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010867 Changes will not typically be accepted for branches which are marked as
10868 End-Of-Life (EOL).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010869
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010870With this in mind, the steps to submit a change for a stable branch are as
10871follows:
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010872
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600108731. *Identify the bug or CVE to be fixed:* This information should be
10874 collected so that it can be included in your submission.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010875
Patrick Williams213cb262021-08-07 19:21:33 -050010876 See :ref:`dev-manual/common-tasks:checking for vulnerabilities`
10877 for details about CVE tracking.
10878
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600108792. *Check if the fix is already present in the master branch:* This will
10880 result in the most straightforward path into the stable branch for the
10881 fix.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010882
Andrew Geissler615f2f12022-07-15 14:00:58 -050010883 a. *If the fix is present in the master branch --- submit a backport request
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010884 by email:* You should send an email to the relevant stable branch
10885 maintainer and the mailing list with details of the bug or CVE to be
10886 fixed, the commit hash on the master branch that fixes the issue and
10887 the stable branches which you would like this fix to be backported to.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010888
Andrew Geissler615f2f12022-07-15 14:00:58 -050010889 b. *If the fix is not present in the master branch --- submit the fix to the
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010890 master branch first:* This will ensure that the fix passes through the
10891 project's usual patch review and test processes before being accepted.
10892 It will also ensure that bugs are not left unresolved in the master
10893 branch itself. Once the fix is accepted in the master branch a backport
10894 request can be submitted as above.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010895
Andrew Geissler615f2f12022-07-15 14:00:58 -050010896 c. *If the fix is unsuitable for the master branch --- submit a patch
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010897 directly for the stable branch:* This method should be considered as a
10898 last resort. It is typically necessary when the master branch is using
10899 a newer version of the software which includes an upstream fix for the
10900 issue or when the issue has been fixed on the master branch in a way
10901 that introduces backwards incompatible changes. In this case follow the
Andrew Geissler09209ee2020-12-13 08:44:15 -060010902 steps in :ref:`dev-manual/common-tasks:preparing changes for submission` and
10903 :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 -060010904 email to include the name of the stable branch which you are
10905 targetting. This can be done using the ``--subject-prefix`` argument to
10906 ``git format-patch``, for example to submit a patch to the dunfell
10907 branch use
10908 ``git format-patch --subject-prefix='&DISTRO_NAME_NO_CAP_MINUS_ONE;][PATCH' ...``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010909
10910Working With Licenses
10911=====================
10912
Andrew Geissler09209ee2020-12-13 08:44:15 -060010913As mentioned in the ":ref:`overview-manual/development-environment:licensing`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010914section in the Yocto Project Overview and Concepts Manual, open source
10915projects are open to the public and they consequently have different
10916licensing structures in place. This section describes the mechanism by
10917which the :term:`OpenEmbedded Build System`
10918tracks changes to
10919licensing text and covers how to maintain open source license compliance
10920during your project's lifecycle. The section also describes how to
10921enable commercially licensed recipes, which by default are disabled.
10922
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010923Tracking License Changes
10924------------------------
10925
10926The license of an upstream project might change in the future. In order
10927to prevent these changes going unnoticed, the
10928:term:`LIC_FILES_CHKSUM`
10929variable tracks changes to the license text. The checksums are validated
10930at the end of the configure step, and if the checksums do not match, the
10931build will fail.
10932
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010933Specifying the ``LIC_FILES_CHKSUM`` Variable
10934~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10935
Andrew Geissler09036742021-06-25 14:25:14 -050010936The :term:`LIC_FILES_CHKSUM` variable contains checksums of the license text
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010937in the source code for the recipe. Following is an example of how to
Andrew Geissler09036742021-06-25 14:25:14 -050010938specify :term:`LIC_FILES_CHKSUM`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010939
10940 LIC_FILES_CHKSUM = "file://COPYING;md5=xxxx \
10941 file://licfile1.txt;beginline=5;endline=29;md5=yyyy \
10942 file://licfile2.txt;endline=50;md5=zzzz \
10943 ..."
10944
10945.. note::
10946
10947 - When using "beginline" and "endline", realize that line numbering
10948 begins with one and not zero. Also, the included lines are
10949 inclusive (i.e. lines five through and including 29 in the
10950 previous example for ``licfile1.txt``).
10951
10952 - When a license check fails, the selected license text is included
10953 as part of the QA message. Using this output, you can determine
10954 the exact start and finish for the needed license text.
10955
10956The build system uses the :term:`S`
10957variable as the default directory when searching files listed in
Andrew Geissler09036742021-06-25 14:25:14 -050010958:term:`LIC_FILES_CHKSUM`. The previous example employs the default
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010959directory.
10960
Andrew Geisslerc926e172021-05-07 16:11:35 -050010961Consider this next example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010962
10963 LIC_FILES_CHKSUM = "file://src/ls.c;beginline=5;endline=16;\
10964 md5=bb14ed3c4cda583abc85401304b5cd4e"
10965 LIC_FILES_CHKSUM = "file://${WORKDIR}/license.html;md5=5c94767cedb5d6987c902ac850ded2c6"
10966
10967The first line locates a file in ``${S}/src/ls.c`` and isolates lines
10968five through 16 as license text. The second line refers to a file in
10969:term:`WORKDIR`.
10970
Andrew Geissler09036742021-06-25 14:25:14 -050010971Note that :term:`LIC_FILES_CHKSUM` variable is mandatory for all recipes,
10972unless the :term:`LICENSE` variable is set to "CLOSED".
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010973
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010974Explanation of Syntax
10975~~~~~~~~~~~~~~~~~~~~~
10976
Andrew Geissler09036742021-06-25 14:25:14 -050010977As mentioned in the previous section, the :term:`LIC_FILES_CHKSUM` variable
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010978lists all the important files that contain the license text for the
10979source code. It is possible to specify a checksum for an entire file, or
10980a specific section of a file (specified by beginning and ending line
10981numbers with the "beginline" and "endline" parameters, respectively).
10982The latter is useful for source files with a license notice header,
10983README documents, and so forth. If you do not use the "beginline"
10984parameter, then it is assumed that the text begins on the first line of
10985the file. Similarly, if you do not use the "endline" parameter, it is
10986assumed that the license text ends with the last line of the file.
10987
10988The "md5" parameter stores the md5 checksum of the license text. If the
10989license text changes in any way as compared to this parameter then a
10990mismatch occurs. This mismatch triggers a build failure and notifies the
10991developer. Notification allows the developer to review and address the
10992license text changes. Also note that if a mismatch occurs during the
10993build, the correct md5 checksum is placed in the build log and can be
10994easily copied to the recipe.
10995
10996There is no limit to how many files you can specify using the
Andrew Geissler09036742021-06-25 14:25:14 -050010997:term:`LIC_FILES_CHKSUM` variable. Generally, however, every project
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010998requires a few specifications for license tracking. Many projects have a
10999"COPYING" file that stores the license information for all the source
11000code files. This practice allows you to just track the "COPYING" file as
11001long as it is kept up to date.
11002
11003.. note::
11004
11005 - If you specify an empty or invalid "md5" parameter,
11006 :term:`BitBake` returns an md5
11007 mis-match error and displays the correct "md5" parameter value
11008 during the build. The correct parameter is also captured in the
11009 build log.
11010
11011 - If the whole file contains only license text, you do not need to
11012 use the "beginline" and "endline" parameters.
11013
11014Enabling Commercially Licensed Recipes
11015--------------------------------------
11016
11017By default, the OpenEmbedded build system disables components that have
11018commercial or other special licensing requirements. Such requirements
11019are defined on a recipe-by-recipe basis through the
11020:term:`LICENSE_FLAGS` variable
11021definition in the affected recipe. For instance, the
11022``poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly`` recipe
Andrew Geisslerc926e172021-05-07 16:11:35 -050011023contains the following statement::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011024
11025 LICENSE_FLAGS = "commercial"
11026
11027Here is a
11028slightly more complicated example that contains both an explicit recipe
Andrew Geisslerc926e172021-05-07 16:11:35 -050011029name and version (after variable expansion)::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011030
11031 LICENSE_FLAGS = "license_${PN}_${PV}"
11032
11033In order for a component restricted by a
Andrew Geissler09036742021-06-25 14:25:14 -050011034:term:`LICENSE_FLAGS` definition to be enabled and included in an image, it
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011035needs to have a matching entry in the global
Andrew Geissler9aee5002022-03-30 16:27:02 +000011036:term:`LICENSE_FLAGS_ACCEPTED`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011037variable, which is a variable typically defined in your ``local.conf``
11038file. For example, to enable the
11039``poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly`` package, you
11040could add either the string "commercial_gst-plugins-ugly" or the more
Andrew Geissler9aee5002022-03-30 16:27:02 +000011041general string "commercial" to :term:`LICENSE_FLAGS_ACCEPTED`. See the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050011042":ref:`dev-manual/common-tasks:license flag matching`" section for a full
Andrew Geissler09036742021-06-25 14:25:14 -050011043explanation of how :term:`LICENSE_FLAGS` matching works. Here is the
Andrew Geisslerc926e172021-05-07 16:11:35 -050011044example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011045
Andrew Geissler9aee5002022-03-30 16:27:02 +000011046 LICENSE_FLAGS_ACCEPTED = "commercial_gst-plugins-ugly"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011047
11048Likewise, to additionally enable the package built from the recipe
11049containing ``LICENSE_FLAGS = "license_${PN}_${PV}"``, and assuming that
11050the actual recipe name was ``emgd_1.10.bb``, the following string would
11051enable that package as well as the original ``gst-plugins-ugly``
Andrew Geisslerc926e172021-05-07 16:11:35 -050011052package::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011053
Andrew Geissler9aee5002022-03-30 16:27:02 +000011054 LICENSE_FLAGS_ACCEPTED = "commercial_gst-plugins-ugly license_emgd_1.10"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011055
11056As a convenience, you do not need to specify the
Andrew Geissler595f6302022-01-24 19:11:47 +000011057complete license string for every package. You can use
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011058an abbreviated form, which consists of just the first portion or
11059portions of the license string before the initial underscore character
11060or characters. A partial string will match any license that contains the
11061given string as the first portion of its license. For example, the
Andrew Geissler595f6302022-01-24 19:11:47 +000011062following value will also match both of the packages
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011063previously mentioned as well as any other packages that have licenses
11064starting with "commercial" or "license".
11065::
11066
Andrew Geissler9aee5002022-03-30 16:27:02 +000011067 LICENSE_FLAGS_ACCEPTED = "commercial license"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011068
11069License Flag Matching
11070~~~~~~~~~~~~~~~~~~~~~
11071
11072License flag matching allows you to control what recipes the
11073OpenEmbedded build system includes in the build. Fundamentally, the
Andrew Geissler09036742021-06-25 14:25:14 -050011074build system attempts to match :term:`LICENSE_FLAGS` strings found in
Andrew Geissler9aee5002022-03-30 16:27:02 +000011075recipes against strings found in :term:`LICENSE_FLAGS_ACCEPTED`.
Andrew Geissler595f6302022-01-24 19:11:47 +000011076A match causes the build system to include a recipe in the
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011077build, while failure to find a match causes the build system to exclude
11078a recipe.
11079
11080In general, license flag matching is simple. However, understanding some
11081concepts will help you correctly and effectively use matching.
11082
11083Before a flag defined by a particular recipe is tested against the
Andrew Geissler9aee5002022-03-30 16:27:02 +000011084entries of :term:`LICENSE_FLAGS_ACCEPTED`, the expanded
Andrew Geissler595f6302022-01-24 19:11:47 +000011085string ``_${PN}`` is appended to the flag. This expansion makes each
11086:term:`LICENSE_FLAGS` value recipe-specific. After expansion, the
11087string is then matched against the entries. Thus, specifying
11088``LICENSE_FLAGS = "commercial"`` in recipe "foo", for example, results
11089in the string ``"commercial_foo"``. And, to create a match, that string
Andrew Geissler9aee5002022-03-30 16:27:02 +000011090must appear among the entries of :term:`LICENSE_FLAGS_ACCEPTED`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011091
Andrew Geissler09036742021-06-25 14:25:14 -050011092Judicious use of the :term:`LICENSE_FLAGS` strings and the contents of the
Andrew Geissler9aee5002022-03-30 16:27:02 +000011093:term:`LICENSE_FLAGS_ACCEPTED` variable allows you a lot of flexibility for
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011094including or excluding recipes based on licensing. For example, you can
11095broaden the matching capabilities by using license flags string subsets
Andrew Geissler9aee5002022-03-30 16:27:02 +000011096in :term:`LICENSE_FLAGS_ACCEPTED`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011097
11098.. note::
11099
11100 When using a string subset, be sure to use the part of the expanded
11101 string that precedes the appended underscore character (e.g.
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011102 ``usethispart_1.3``, ``usethispart_1.4``, and so forth).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011103
Andrew Geissler595f6302022-01-24 19:11:47 +000011104For example, simply specifying the string "commercial" in the
Andrew Geissler9aee5002022-03-30 16:27:02 +000011105:term:`LICENSE_FLAGS_ACCEPTED` variable matches any expanded
Andrew Geissler595f6302022-01-24 19:11:47 +000011106:term:`LICENSE_FLAGS` definition that starts with the string
11107"commercial" such as "commercial_foo" and "commercial_bar", which
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011108are the strings the build system automatically generates for
11109hypothetical recipes named "foo" and "bar" assuming those recipes simply
Andrew Geisslerc926e172021-05-07 16:11:35 -050011110specify the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011111
11112 LICENSE_FLAGS = "commercial"
11113
Andrew Geissler595f6302022-01-24 19:11:47 +000011114Thus, you can choose to exhaustively enumerate each license flag in the
11115list and allow only specific recipes into the image, or you can use a
11116string subset that causes a broader range of matches to allow a range of
11117recipes into the image.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011118
Andrew Geissler09036742021-06-25 14:25:14 -050011119This scheme works even if the :term:`LICENSE_FLAGS` string already has
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011120``_${PN}`` appended. For example, the build system turns the license
11121flag "commercial_1.2_foo" into "commercial_1.2_foo_foo" and would match
11122both the general "commercial" and the specific "commercial_1.2_foo"
Andrew Geissler9aee5002022-03-30 16:27:02 +000011123strings found in the :term:`LICENSE_FLAGS_ACCEPTED` variable, as expected.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011124
11125Here are some other scenarios:
11126
11127- You can specify a versioned string in the recipe such as
11128 "commercial_foo_1.2" in a "foo" recipe. The build system expands this
11129 string to "commercial_foo_1.2_foo". Combine this license flag with a
Andrew Geissler9aee5002022-03-30 16:27:02 +000011130 :term:`LICENSE_FLAGS_ACCEPTED` variable that has the string
Andrew Geissler595f6302022-01-24 19:11:47 +000011131 "commercial" and you match the flag along with any other flag that
11132 starts with the string "commercial".
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011133
Andrew Geissler595f6302022-01-24 19:11:47 +000011134- Under the same circumstances, you can add "commercial_foo" in the
Andrew Geissler9aee5002022-03-30 16:27:02 +000011135 :term:`LICENSE_FLAGS_ACCEPTED` variable and the build system not only
Andrew Geissler595f6302022-01-24 19:11:47 +000011136 matches "commercial_foo_1.2" but also matches any license flag with
11137 the string "commercial_foo", regardless of the version.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011138
11139- You can be very specific and use both the package and version parts
Andrew Geissler9aee5002022-03-30 16:27:02 +000011140 in the :term:`LICENSE_FLAGS_ACCEPTED` list (e.g.
Andrew Geissler595f6302022-01-24 19:11:47 +000011141 "commercial_foo_1.2") to specifically match a versioned recipe.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011142
11143Other Variables Related to Commercial Licenses
11144~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11145
William A. Kennington IIIac69b482021-06-02 12:28:27 -070011146There are other helpful variables related to commercial license handling,
11147defined in the
Andrew Geisslerc926e172021-05-07 16:11:35 -050011148``poky/meta/conf/distro/include/default-distrovars.inc`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011149
11150 COMMERCIAL_AUDIO_PLUGINS ?= ""
11151 COMMERCIAL_VIDEO_PLUGINS ?= ""
11152
11153If you
11154want to enable these components, you can do so by making sure you have
11155statements similar to the following in your ``local.conf`` configuration
Andrew Geisslerc926e172021-05-07 16:11:35 -050011156file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011157
11158 COMMERCIAL_AUDIO_PLUGINS = "gst-plugins-ugly-mad \
11159 gst-plugins-ugly-mpegaudioparse"
11160 COMMERCIAL_VIDEO_PLUGINS = "gst-plugins-ugly-mpeg2dec \
11161 gst-plugins-ugly-mpegstream gst-plugins-bad-mpegvideoparse"
Andrew Geissler9aee5002022-03-30 16:27:02 +000011162 LICENSE_FLAGS_ACCEPTED = "commercial_gst-plugins-ugly commercial_gst-plugins-bad commercial_qmmp"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011163
11164
Andrew Geissler595f6302022-01-24 19:11:47 +000011165Of course, you could also create a matching list for those
11166components using the more general "commercial" in the
Andrew Geissler9aee5002022-03-30 16:27:02 +000011167:term:`LICENSE_FLAGS_ACCEPTED` variable, but that would also enable all
Andrew Geissler595f6302022-01-24 19:11:47 +000011168the other packages with :term:`LICENSE_FLAGS`
Andrew Geisslerc926e172021-05-07 16:11:35 -050011169containing "commercial", which you may or may not want::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011170
Andrew Geissler9aee5002022-03-30 16:27:02 +000011171 LICENSE_FLAGS_ACCEPTED = "commercial"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011172
11173Specifying audio and video plugins as part of the
11174``COMMERCIAL_AUDIO_PLUGINS`` and ``COMMERCIAL_VIDEO_PLUGINS`` statements
Andrew Geissler9aee5002022-03-30 16:27:02 +000011175(along with the enabling :term:`LICENSE_FLAGS_ACCEPTED`) includes the
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011176plugins or components into built images, thus adding support for media
11177formats or components.
11178
11179Maintaining Open Source License Compliance During Your Product's Lifecycle
11180--------------------------------------------------------------------------
11181
11182One of the concerns for a development organization using open source
11183software is how to maintain compliance with various open source
11184licensing during the lifecycle of the product. While this section does
11185not provide legal advice or comprehensively cover all scenarios, it does
11186present methods that you can use to assist you in meeting the compliance
11187requirements during a software release.
11188
11189With hundreds of different open source licenses that the Yocto Project
11190tracks, it is difficult to know the requirements of each and every
11191license. However, the requirements of the major FLOSS licenses can begin
William A. Kennington IIIac69b482021-06-02 12:28:27 -070011192to be covered by assuming that there are three main areas of concern:
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011193
11194- Source code must be provided.
11195
11196- License text for the software must be provided.
11197
11198- Compilation scripts and modifications to the source code must be
11199 provided.
11200
11201There are other requirements beyond the scope of these three and the
11202methods described in this section (e.g. the mechanism through which
11203source code is distributed).
11204
11205As different organizations have different methods of complying with open
11206source licensing, this section is not meant to imply that there is only
11207one single way to meet your compliance obligations, but rather to
11208describe one method of achieving compliance. The remainder of this
11209section describes methods supported to meet the previously mentioned
11210three requirements. Once you take steps to meet these requirements, and
11211prior to releasing images, sources, and the build system, you should
11212audit all artifacts to ensure completeness.
11213
11214.. note::
11215
11216 The Yocto Project generates a license manifest during image creation
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011217 that is located in ``${DEPLOY_DIR}/licenses/``\ `image_name`\ ``-``\ `datestamp`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011218 to assist with any audits.
11219
11220Providing the Source Code
11221~~~~~~~~~~~~~~~~~~~~~~~~~
11222
11223Compliance activities should begin before you generate the final image.
11224The first thing you should look at is the requirement that tops the list
Andrew Geissler615f2f12022-07-15 14:00:58 -050011225for most compliance groups --- providing the source. The Yocto Project has
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011226a few ways of meeting this requirement.
11227
11228One of the easiest ways to meet this requirement is to provide the
11229entire :term:`DL_DIR` used by the
11230build. This method, however, has a few issues. The most obvious is the
11231size of the directory since it includes all sources used in the build
11232and not just the source used in the released image. It will include
11233toolchain source, and other artifacts, which you would not generally
11234release. However, the more serious issue for most companies is
11235accidental release of proprietary software. The Yocto Project provides
11236an :ref:`archiver <ref-classes-archiver>` class to
11237help avoid some of these concerns.
11238
Andrew Geissler595f6302022-01-24 19:11:47 +000011239Before you employ :term:`DL_DIR` or the :ref:`archiver <ref-classes-archiver>` class, you need to
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011240decide how you choose to provide source. The source ``archiver`` class
11241can generate tarballs and SRPMs and can create them with various levels
11242of compliance in mind.
11243
11244One way of doing this (but certainly not the only way) is to release
11245just the source as a tarball. You can do this by adding the following to
Patrick Williams2390b1b2022-11-03 13:47:49 -050011246the ``local.conf`` file found in the :term:`Build Directory`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011247
11248 INHERIT += "archiver"
11249 ARCHIVER_MODE[src] = "original"
11250
11251During the creation of your
11252image, the source from all recipes that deploy packages to the image is
11253placed within subdirectories of ``DEPLOY_DIR/sources`` based on the
11254:term:`LICENSE` for each recipe.
11255Releasing the entire directory enables you to comply with requirements
11256concerning providing the unmodified source. It is important to note that
11257the size of the directory can get large.
11258
11259A way to help mitigate the size issue is to only release tarballs for
11260licenses that require the release of source. Let us assume you are only
11261concerned with GPL code as identified by running the following script:
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011262
11263.. code-block:: shell
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011264
11265 # Script to archive a subset of packages matching specific license(s)
11266 # Source and license files are copied into sub folders of package folder
11267 # Must be run from build folder
11268 #!/bin/bash
11269 src_release_dir="source-release"
11270 mkdir -p $src_release_dir
11271 for a in tmp/deploy/sources/*; do
11272 for d in $a/*; do
11273 # Get package name from path
11274 p=`basename $d`
11275 p=${p%-*}
11276 p=${p%-*}
11277 # Only archive GPL packages (update *GPL* regex for your license check)
11278 numfiles=`ls tmp/deploy/licenses/$p/*GPL* 2> /dev/null | wc -l`
Patrick Williams213cb262021-08-07 19:21:33 -050011279 if [ $numfiles -ge 1 ]; then
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011280 echo Archiving $p
11281 mkdir -p $src_release_dir/$p/source
11282 cp $d/* $src_release_dir/$p/source 2> /dev/null
11283 mkdir -p $src_release_dir/$p/license
11284 cp tmp/deploy/licenses/$p/* $src_release_dir/$p/license 2> /dev/null
11285 fi
11286 done
11287 done
11288
11289At this point, you
11290could create a tarball from the ``gpl_source_release`` directory and
11291provide that to the end user. This method would be a step toward
11292achieving compliance with section 3a of GPLv2 and with section 6 of
11293GPLv3.
11294
11295Providing License Text
11296~~~~~~~~~~~~~~~~~~~~~~
11297
11298One requirement that is often overlooked is inclusion of license text.
11299This requirement also needs to be dealt with prior to generating the
11300final image. Some licenses require the license text to accompany the
11301binary. You can achieve this by adding the following to your
Andrew Geisslerc926e172021-05-07 16:11:35 -050011302``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011303
11304 COPY_LIC_MANIFEST = "1"
11305 COPY_LIC_DIRS = "1"
11306 LICENSE_CREATE_PACKAGE = "1"
11307
11308Adding these statements to the
11309configuration file ensures that the licenses collected during package
11310generation are included on your image.
11311
11312.. note::
11313
11314 Setting all three variables to "1" results in the image having two
11315 copies of the same license file. One copy resides in
11316 ``/usr/share/common-licenses`` and the other resides in
11317 ``/usr/share/license``.
11318
11319 The reason for this behavior is because
11320 :term:`COPY_LIC_DIRS` and
11321 :term:`COPY_LIC_MANIFEST`
11322 add a copy of the license when the image is built but do not offer a
11323 path for adding licenses for newly installed packages to an image.
11324 :term:`LICENSE_CREATE_PACKAGE`
11325 adds a separate package and an upgrade path for adding licenses to an
11326 image.
11327
11328As the source ``archiver`` class has already archived the original
11329unmodified source that contains the license files, you would have
11330already met the requirements for inclusion of the license information
11331with source as defined by the GPL and other open source licenses.
11332
11333Providing Compilation Scripts and Source Code Modifications
11334~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11335
11336At this point, we have addressed all we need to prior to generating the
11337image. The next two requirements are addressed during the final
11338packaging of the release.
11339
11340By releasing the version of the OpenEmbedded build system and the layers
11341used during the build, you will be providing both compilation scripts
11342and the source code modifications in one step.
11343
Andrew Geissler09209ee2020-12-13 08:44:15 -060011344If the deployment team has a :ref:`overview-manual/concepts:bsp layer`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011345and a distro layer, and those
11346those layers are used to patch, compile, package, or modify (in any way)
11347any open source software included in your released images, you might be
11348required to release those layers under section 3 of GPLv2 or section 1
11349of GPLv3. One way of doing that is with a clean checkout of the version
11350of the Yocto Project and layers used during your build. Here is an
11351example:
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011352
11353.. code-block:: shell
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011354
11355 # We built using the dunfell branch of the poky repo
11356 $ git clone -b dunfell git://git.yoctoproject.org/poky
11357 $ cd poky
11358 # We built using the release_branch for our layers
11359 $ git clone -b release_branch git://git.mycompany.com/meta-my-bsp-layer
11360 $ git clone -b release_branch git://git.mycompany.com/meta-my-software-layer
11361 # clean up the .git repos
11362 $ find . -name ".git" -type d -exec rm -rf {} \;
11363
Andrew Geissler87f5cff2022-09-30 13:13:31 -050011364One thing a development organization might want to consider for end-user
11365convenience is to modify
11366``meta-poky/conf/templates/default/bblayers.conf.sample`` to ensure that when
11367the end user utilizes the released build system to build an image, the
11368development organization's layers are included in the ``bblayers.conf`` file
11369automatically::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011370
11371 # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
11372 # changes incompatibly
11373 POKY_BBLAYERS_CONF_VERSION = "2"
11374
11375 BBPATH = "${TOPDIR}"
11376 BBFILES ?= ""
11377
11378 BBLAYERS ?= " \
11379 ##OEROOT##/meta \
11380 ##OEROOT##/meta-poky \
11381 ##OEROOT##/meta-yocto-bsp \
11382 ##OEROOT##/meta-mylayer \
11383 "
11384
11385Creating and
11386providing an archive of the :term:`Metadata`
11387layers (recipes, configuration files, and so forth) enables you to meet
11388your requirements to include the scripts to control compilation as well
11389as any modifications to the original source.
11390
Andrew Geisslereff27472021-10-29 15:35:00 -050011391Compliance Limitations with Executables Built from Static Libraries
11392~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011393
Andrew Geisslereff27472021-10-29 15:35:00 -050011394When package A is added to an image via the :term:`RDEPENDS` or :term:`RRECOMMENDS`
11395mechanisms as well as explicitly included in the image recipe with
11396:term:`IMAGE_INSTALL`, and depends on a static linked library recipe B
11397(``DEPENDS += "B"``), package B will neither appear in the generated license
11398manifest nor in the generated source tarballs. This occurs as the
11399:ref:`license <ref-classes-license>` and :ref:`archiver <ref-classes-archiver>`
11400classes assume that only packages included via :term:`RDEPENDS` or :term:`RRECOMMENDS`
11401end up in the image.
11402
11403As a result, potential obligations regarding license compliance for package B
11404may not be met.
11405
11406The Yocto Project doesn't enable static libraries by default, in part because
11407of this issue. Before a solution to this limitation is found, you need to
11408keep in mind that if your root filesystem is built from static libraries,
11409you will need to manually ensure that your deliveries are compliant
11410with the licenses of these libraries.
11411
11412Copying Non Standard Licenses
11413-----------------------------
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011414
11415Some packages, such as the linux-firmware package, have many licenses
11416that are not in any way common. You can avoid adding a lot of these
11417types of common license files, which are only applicable to a specific
11418package, by using the
11419:term:`NO_GENERIC_LICENSE`
11420variable. Using this variable also avoids QA errors when you use a
11421non-common, non-CLOSED license in a recipe.
11422
William A. Kennington IIIac69b482021-06-02 12:28:27 -070011423Here is an example that uses the ``LICENSE.Abilis.txt`` file as
Andrew Geisslerc926e172021-05-07 16:11:35 -050011424the license from the fetched source::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011425
11426 NO_GENERIC_LICENSE[Firmware-Abilis] = "LICENSE.Abilis.txt"
11427
Patrick Williams213cb262021-08-07 19:21:33 -050011428Checking for Vulnerabilities
11429============================
11430
Patrick Williams2390b1b2022-11-03 13:47:49 -050011431Vulnerabilities in Poky and OE-Core
11432-----------------------------------
Patrick Williams213cb262021-08-07 19:21:33 -050011433
11434The Yocto Project has an infrastructure to track and address unfixed
11435known security vulnerabilities, as tracked by the public
Patrick Williams7784c422022-11-17 07:29:11 -060011436:wikipedia:`Common Vulnerabilities and Exposures (CVE) <Common_Vulnerabilities_and_Exposures>`
Patrick Williams213cb262021-08-07 19:21:33 -050011437database.
11438
Andrew Geissler615f2f12022-07-15 14:00:58 -050011439The Yocto Project maintains a `list of known vulnerabilities
11440<https://autobuilder.yocto.io/pub/non-release/patchmetrics/>`__
11441for packages in Poky and OE-Core, tracking the evolution of the number of
11442unpatched CVEs and the status of patches. Such information is available for
11443the current development version and for each supported release.
11444
Patrick Williams2390b1b2022-11-03 13:47:49 -050011445Security is a process, not a product, and thus at any time, a number of security
11446issues may be impacting Poky and OE-Core. It is up to the maintainers, users,
11447contributors and anyone interested in the issues to investigate and possibly fix them by
11448updating software components to newer versions or by applying patches to address them.
11449It is recommended to work with Poky and OE-Core upstream maintainers and submit
11450patches to fix them, see ":ref:`dev-manual/common-tasks:submitting a change to the yocto project`" for details.
11451
11452Vulnerability check at build time
11453---------------------------------
11454
11455To enable a check for CVE security vulnerabilities using :ref:`cve-check <ref-classes-cve-check>` in the specific image
11456or target you are building, add the following setting to your configuration::
Patrick Williams213cb262021-08-07 19:21:33 -050011457
11458 INHERIT += "cve-check"
11459
Patrick Williams2390b1b2022-11-03 13:47:49 -050011460The CVE database contains some old incomplete entries which have been
11461deemed not to impact Poky or OE-Core. These CVE entries can be excluded from the
11462check using build configuration::
11463
11464 include conf/distro/include/cve-extra-exclusions.inc
11465
11466With this CVE check enabled, BitBake build will try to map each compiled software component
11467recipe name and version information to the CVE database and generate recipe and
11468image specific reports. These reports will contain:
11469
11470- metadata about the software component like names and versions
11471
11472- metadata about the CVE issue such as description and NVD link
11473
11474- for each software component, a list of CVEs which are possibly impacting this version
11475
11476- status of each CVE: ``Patched``, ``Unpatched`` or ``Ignored``
11477
11478The status ``Patched`` means that a patch file to address the security issue has been
11479applied. ``Unpatched`` status means that no patches to address the issue have been
11480applied and that the issue needs to be investigated. ``Ignored`` means that after
11481analysis, it has been deemed to ignore the issue as it for example affects
11482the software component on a different operating system platform.
11483
Patrick Williams7784c422022-11-17 07:29:11 -060011484After a build with CVE check enabled, reports for each compiled source recipe will be
Patrick Williams2390b1b2022-11-03 13:47:49 -050011485found in ``build/tmp/deploy/cve``.
11486
11487For example the CVE check report for the ``flex-native`` recipe looks like::
11488
11489 $ cat poky/build/tmp/deploy/cve/flex-native
11490 LAYER: meta
11491 PACKAGE NAME: flex-native
11492 PACKAGE VERSION: 2.6.4
11493 CVE: CVE-2016-6354
11494 CVE STATUS: Patched
11495 CVE SUMMARY: Heap-based buffer overflow in the yy_get_next_buffer function in Flex before 2.6.1 might allow context-dependent attackers to cause a denial of service or possibly execute arbitrary code via vectors involving num_to_read.
11496 CVSS v2 BASE SCORE: 7.5
11497 CVSS v3 BASE SCORE: 9.8
11498 VECTOR: NETWORK
11499 MORE INFORMATION: https://nvd.nist.gov/vuln/detail/CVE-2016-6354
11500
11501 LAYER: meta
11502 PACKAGE NAME: flex-native
11503 PACKAGE VERSION: 2.6.4
11504 CVE: CVE-2019-6293
11505 CVE STATUS: Ignored
11506 CVE SUMMARY: An issue was discovered in the function mark_beginning_as_normal in nfa.c in flex 2.6.4. There is a stack exhaustion problem caused by the mark_beginning_as_normal function making recursive calls to itself in certain scenarios involving lots of '*' characters. Remote attackers could leverage this vulnerability to cause a denial-of-service.
11507 CVSS v2 BASE SCORE: 4.3
11508 CVSS v3 BASE SCORE: 5.5
11509 VECTOR: NETWORK
11510 MORE INFORMATION: https://nvd.nist.gov/vuln/detail/CVE-2019-6293
11511
11512For images, a summary of all recipes included in the image and their CVEs is also
11513generated in textual and JSON formats. These ``.cve`` and ``.json`` reports can be found
11514in the ``tmp/deploy/images`` directory for each compiled image.
11515
11516At build time CVE check will also throw warnings about ``Unpatched`` CVEs::
Patrick Williams213cb262021-08-07 19:21:33 -050011517
11518 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
11519 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
11520
11521It is also possible to check the CVE status of individual packages as follows::
11522
11523 bitbake -c cve_check flex libarchive
11524
Patrick Williams2390b1b2022-11-03 13:47:49 -050011525Fixing CVE product name and version mappings
11526--------------------------------------------
Patrick Williams213cb262021-08-07 19:21:33 -050011527
Patrick Williams2390b1b2022-11-03 13:47:49 -050011528By default, :ref:`cve-check <ref-classes-cve-check>` uses the recipe name :term:`BPN` as CVE
11529product name when querying the CVE database. If this mapping contains false positives, e.g.
11530some reported CVEs are not for the software component in question, or false negatives like
11531some CVEs are not found to impact the recipe when they should, then the problems can be
11532in the recipe name to CVE product mapping. These mapping issues can be fixed by setting
Patrick Williams7784c422022-11-17 07:29:11 -060011533the :term:`CVE_PRODUCT` variable inside the recipe. This defines the name of the software component in the
Patrick Williams2390b1b2022-11-03 13:47:49 -050011534upstream `NIST CVE database <https://nvd.nist.gov/>`__.
Patrick Williams213cb262021-08-07 19:21:33 -050011535
Patrick Williams2390b1b2022-11-03 13:47:49 -050011536The variable supports using vendor and product names like this::
Patrick Williams213cb262021-08-07 19:21:33 -050011537
Patrick Williams2390b1b2022-11-03 13:47:49 -050011538 CVE_PRODUCT = "flex_project:flex"
Patrick Williams213cb262021-08-07 19:21:33 -050011539
Patrick Williams7784c422022-11-17 07:29:11 -060011540In this example the vendor name used in the CVE database is ``flex_project`` and the
Patrick Williams2390b1b2022-11-03 13:47:49 -050011541product is ``flex``. With this setting the ``flex`` recipe only maps to this specific
11542product and not products from other vendors with same name ``flex``.
Patrick Williams0ca19cc2021-08-16 14:03:13 -050011543
Patrick Williams7784c422022-11-17 07:29:11 -060011544Similarly, when the recipe version :term:`PV` is not compatible with software versions used by
Patrick Williams2390b1b2022-11-03 13:47:49 -050011545the upstream software component releases and the CVE database, these can be fixed using
Patrick Williams7784c422022-11-17 07:29:11 -060011546the :term:`CVE_VERSION` variable.
Patrick Williams2390b1b2022-11-03 13:47:49 -050011547
Patrick Williams7784c422022-11-17 07:29:11 -060011548Note that if the CVE entries in the NVD database contain bugs or have missing or incomplete
Patrick Williams2390b1b2022-11-03 13:47:49 -050011549information, it is recommended to fix the information there directly instead of working
Patrick Williams7784c422022-11-17 07:29:11 -060011550around the issues possibly for a long time in Poky and OE-Core side recipes. Feedback to
11551NVD about CVE entries can be provided through the `NVD contact form <https://nvd.nist.gov/info/contact-form>`__.
Patrick Williams2390b1b2022-11-03 13:47:49 -050011552
11553Fixing vulnerabilities in recipes
11554---------------------------------
11555
11556If a CVE security issue impacts a software component, it can be fixed by updating to a newer
11557version of the software component or by applying a patch. For Poky and OE-Core master branches, updating
Patrick Williams7784c422022-11-17 07:29:11 -060011558to a newer software component release with fixes is the best option, but patches can be applied
Patrick Williams2390b1b2022-11-03 13:47:49 -050011559if releases are not yet available.
11560
11561For stable branches, it is preferred to apply patches for the issues. For some software
Patrick Williams7784c422022-11-17 07:29:11 -060011562components minor version updates can also be applied if they are backwards compatible.
Patrick Williams2390b1b2022-11-03 13:47:49 -050011563
11564Here is an example of fixing CVE security issues with patch files,
Patrick Williams0ca19cc2021-08-16 14:03:13 -050011565an example from the :oe_layerindex:`ffmpeg recipe</layerindex/recipe/47350>`::
11566
11567 SRC_URI = "https://www.ffmpeg.org/releases/${BP}.tar.xz \
11568 file://0001-libavutil-include-assembly-with-full-path-from-sourc.patch \
11569 file://fix-CVE-2020-20446.patch \
11570 file://fix-CVE-2020-20453.patch \
11571 file://fix-CVE-2020-22015.patch \
11572 file://fix-CVE-2020-22021.patch \
11573 file://fix-CVE-2020-22033-CVE-2020-22019.patch \
11574 file://fix-CVE-2021-33815.patch \
11575
Patrick Williams7784c422022-11-17 07:29:11 -060011576A good practice is to include the CVE identifier in both the patch file name
11577and inside the patch file commit message using the format::
Patrick Williams0ca19cc2021-08-16 14:03:13 -050011578
Patrick Williams2390b1b2022-11-03 13:47:49 -050011579 CVE: CVE-2020-22033
Patrick Williams0ca19cc2021-08-16 14:03:13 -050011580
Patrick Williams2390b1b2022-11-03 13:47:49 -050011581CVE checker will then capture this information and change the CVE status to ``Patched``
11582in the generated reports.
Patrick Williams0ca19cc2021-08-16 14:03:13 -050011583
Patrick Williams2390b1b2022-11-03 13:47:49 -050011584If analysis shows that the CVE issue does not impact the recipe due to configuration, platform,
Patrick Williams7784c422022-11-17 07:29:11 -060011585version or other reasons, the CVE can be marked as ``Ignored`` using the :term:`CVE_CHECK_IGNORE` variable.
Patrick Williams2390b1b2022-11-03 13:47:49 -050011586As mentioned previously, if data in the CVE database is wrong, it is recommend to fix those
11587issues in the CVE database directly.
Patrick Williams0ca19cc2021-08-16 14:03:13 -050011588
Patrick Williams2390b1b2022-11-03 13:47:49 -050011589Recipes can be completely skipped by CVE check by including the recipe name in
11590the :term:`CVE_CHECK_SKIP_RECIPE` variable.
Patrick Williams0ca19cc2021-08-16 14:03:13 -050011591
11592Implementation details
11593----------------------
11594
11595Here's what the :ref:`cve-check <ref-classes-cve-check>` class does to
11596find unpatched CVE IDs.
11597
11598First the code goes through each patch file provided by a recipe. If a valid CVE ID
11599is found in the name of the file, the corresponding CVE is considered as patched.
11600Don't forget that if multiple CVE IDs are found in the filename, only the last
11601one is considered. Then, the code looks for ``CVE: CVE-ID`` lines in the patch
11602file. The found CVE IDs are also considered as patched.
11603
11604Then, the code looks up all the CVE IDs in the NIST database for all the
11605products defined in :term:`CVE_PRODUCT`. Then, for each found CVE:
11606
Patrick Williams2390b1b2022-11-03 13:47:49 -050011607- If the package name (:term:`PN`) is part of
11608 :term:`CVE_CHECK_SKIP_RECIPE`, it is considered as ``Patched``.
Patrick Williams0ca19cc2021-08-16 14:03:13 -050011609
Patrick Williams2390b1b2022-11-03 13:47:49 -050011610- If the CVE ID is part of :term:`CVE_CHECK_IGNORE`, it is
11611 set as ``Ignored``.
Patrick Williams0ca19cc2021-08-16 14:03:13 -050011612
Patrick Williams2390b1b2022-11-03 13:47:49 -050011613- If the CVE ID is part of the patched CVE for the recipe, it is
11614 already considered as ``Patched``.
Patrick Williams0ca19cc2021-08-16 14:03:13 -050011615
Patrick Williams2390b1b2022-11-03 13:47:49 -050011616- Otherwise, the code checks whether the recipe version (:term:`PV`)
Patrick Williams0ca19cc2021-08-16 14:03:13 -050011617 is within the range of versions impacted by the CVE. If so, the CVE
Patrick Williams2390b1b2022-11-03 13:47:49 -050011618 is considered as ``Unpatched``.
Patrick Williams0ca19cc2021-08-16 14:03:13 -050011619
Patrick Williams213cb262021-08-07 19:21:33 -050011620The CVE database is stored in :term:`DL_DIR` and can be inspected using
11621``sqlite3`` command as follows::
11622
11623 sqlite3 downloads/CVE_CHECK/nvdcve_1.1.db .dump | grep CVE-2021-37462
11624
Patrick Williams2390b1b2022-11-03 13:47:49 -050011625When analyzing CVEs, it is recommended to:
11626
11627- study the latest information in `CVE database <https://nvd.nist.gov/vuln/search>`__.
11628
11629- check how upstream developers of the software component addressed the issue, e.g.
11630 what patch was applied, which upstream release contains the fix.
11631
11632- check what other Linux distributions like `Debian <https://security-tracker.debian.org/tracker/>`__
11633 did to analyze and address the issue.
11634
11635- follow security notices from other Linux distributions.
11636
11637- follow public `open source security mailing lists <https://oss-security.openwall.org/wiki/mailing-lists>`__ for
11638 discussions and advance notifications of CVE bugs and software releases with fixes.
11639
Patrick Williams7784c422022-11-17 07:29:11 -060011640Creating a Software Bill of Materials
11641=====================================
11642
11643Once you are able to build an image for your project, once the licenses for
11644each software component are all identified (see
11645":ref:`dev-manual/common-tasks:working with licenses`") and once vulnerability
11646fixes are applied (see ":ref:`dev-manual/common-tasks:checking
11647for vulnerabilities`"), the OpenEmbedded build system can generate
11648a description of all the components you used, their licenses, their dependencies,
11649the changes that were applied and the known vulnerabilities that were fixed.
11650
11651This description is generated in the form of a *Software Bill of Materials*
11652(:term:`SBOM`), using the :term:`SPDX` standard.
11653
11654When you release software, this is the most standard way to provide information
11655about the Software Supply Chain of your software image and SDK. The
11656:term:`SBOM` tooling is often used to ensure open source license compliance by
11657providing the license texts used in the product which legal departments and end
11658users can read in standardized format.
11659
11660:term:`SBOM` information is also critical to performing vulnerability exposure
11661assessments, as all the components used in the Software Supply Chain are listed.
11662
11663The OpenEmbedded build system doesn't generate such information by default.
11664To make this happen, you must inherit the
11665:ref:`create-spdx <ref-classes-create-spdx>` class from a configuration file::
11666
11667 INHERIT += "create-spdx"
11668
11669You then get :term:`SPDX` output in JSON format as an
11670``IMAGE-MACHINE.spdx.json`` file in ``tmp/deploy/images/MACHINE/`` inside the
11671:term:`Build Directory`.
11672
11673This is a toplevel file accompanied by an ``IMAGE-MACHINE.spdx.index.json``
11674containing an index of JSON :term:`SPDX` files for individual recipes, together
11675with an ``IMAGE-MACHINE.spdx.tar.zst`` compressed archive containing all such
11676files.
11677
11678The :ref:`create-spdx <ref-classes-create-spdx>` class offers options to include
11679more information in the output :term:`SPDX` data, such as making the generated
11680files more human readable (:term:`SPDX_PRETTY`), adding compressed archives of
11681the files in the generated target packages (:term:`SPDX_ARCHIVE_PACKAGED`),
11682adding a description of the source files handled by the target recipes
11683(:term:`SPDX_INCLUDE_SOURCES`) and adding archives of these source files
11684themselves (:term:`SPDX_ARCHIVE_SOURCES`).
11685
11686Though the toplevel :term:`SPDX` output is available in
11687``tmp/deploy/images/MACHINE/`` inside the :term:`Build Directory`, ancillary
11688generated files are available in ``tmp/deploy/spdx/MACHINE`` too, such as:
11689
11690- The individual :term:`SPDX` JSON files in the ``IMAGE-MACHINE.spdx.tar.zst``
11691 archive.
11692
11693- Compressed archives of the files in the generated target packages,
11694 in ``packages/packagename.tar.zst`` (when :term:`SPDX_ARCHIVE_PACKAGED`
11695 is set).
11696
11697- Compressed archives of the source files used to build the host tools
11698 and the target packages in ``recipes/recipe-packagename.tar.zst``
11699 (when :term:`SPDX_ARCHIVE_SOURCES` is set). Those are needed to fulfill
11700 "source code access" license requirements.
11701
11702See the `tools page <https://spdx.dev/resources/tools/>`__ on the :term:`SPDX`
11703project website for a list of tools to consume and transform the :term:`SPDX`
11704data generated by the OpenEmbedded build system.
11705
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011706Using the Error Reporting Tool
11707==============================
11708
11709The error reporting tool allows you to submit errors encountered during
11710builds to a central database. Outside of the build environment, you can
11711use a web interface to browse errors, view statistics, and query for
11712errors. The tool works using a client-server system where the client
11713portion is integrated with the installed Yocto Project
11714:term:`Source Directory` (e.g. ``poky``).
11715The server receives the information collected and saves it in a
11716database.
11717
William A. Kennington IIIac69b482021-06-02 12:28:27 -070011718There is a live instance of the error reporting server at
11719https://errors.yoctoproject.org.
11720When you want to get help with build failures, you can submit all of the
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011721information on the failure easily and then point to the URL in your bug
11722report or send an email to the mailing list.
11723
11724.. note::
11725
11726 If you send error reports to this server, the reports become publicly
11727 visible.
11728
11729Enabling and Using the Tool
11730---------------------------
11731
11732By default, the error reporting tool is disabled. You can enable it by
Patrick Williams2390b1b2022-11-03 13:47:49 -050011733inheriting the :ref:`report-error <ref-classes-report-error>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011734class by adding the following statement to the end of your
Patrick Williams2390b1b2022-11-03 13:47:49 -050011735``local.conf`` file in your :term:`Build Directory`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011736
11737 INHERIT += "report-error"
11738
11739By default, the error reporting feature stores information in
11740``${``\ :term:`LOG_DIR`\ ``}/error-report``.
11741However, you can specify a directory to use by adding the following to
Andrew Geisslerc926e172021-05-07 16:11:35 -050011742your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011743
11744 ERR_REPORT_DIR = "path"
11745
11746Enabling error
11747reporting causes the build process to collect the errors and store them
11748in a file as previously described. When the build system encounters an
11749error, it includes a command as part of the console output. You can run
11750the command to send the error file to the server. For example, the
Andrew Geisslerc926e172021-05-07 16:11:35 -050011751following command sends the errors to an upstream server::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011752
11753 $ send-error-report /home/brandusa/project/poky/build/tmp/log/error-report/error_report_201403141617.txt
11754
11755In the previous example, the errors are sent to a public database
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011756available at https://errors.yoctoproject.org, which is used by the
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011757entire community. If you specify a particular server, you can send the
11758errors to a different database. Use the following command for more
Andrew Geisslerc926e172021-05-07 16:11:35 -050011759information on available options::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011760
11761 $ send-error-report --help
11762
11763When sending the error file, you are prompted to review the data being
11764sent as well as to provide a name and optional email address. Once you
11765satisfy these prompts, the command returns a link from the server that
11766corresponds to your entry in the database. For example, here is a
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011767typical link: https://errors.yoctoproject.org/Errors/Details/9522/
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011768
11769Following the link takes you to a web interface where you can browse,
11770query the errors, and view statistics.
11771
11772Disabling the Tool
11773------------------
11774
11775To disable the error reporting feature, simply remove or comment out the
11776following statement from the end of your ``local.conf`` file in your
11777:term:`Build Directory`.
11778::
11779
11780 INHERIT += "report-error"
11781
11782Setting Up Your Own Error Reporting Server
11783------------------------------------------
11784
11785If you want to set up your own error reporting server, you can obtain
Andrew Geissler09209ee2020-12-13 08:44:15 -060011786the code from the Git repository at :yocto_git:`/error-report-web/`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011787Instructions on how to set it up are in the README document.
11788
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011789Using Wayland and Weston
11790========================
11791
Patrick Williams7784c422022-11-17 07:29:11 -060011792:wikipedia:`Wayland <Wayland_(display_server_protocol)>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011793is a computer display server protocol that provides a method for
11794compositing window managers to communicate directly with applications
11795and video hardware and expects them to communicate with input hardware
11796using other libraries. Using Wayland with supporting targets can result
11797in better control over graphics frame rendering than an application
11798might otherwise achieve.
11799
11800The Yocto Project provides the Wayland protocol libraries and the
Patrick Williams7784c422022-11-17 07:29:11 -060011801reference :wikipedia:`Weston <Wayland_(display_server_protocol)#Weston>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011802compositor as part of its release. You can find the integrated packages
11803in the ``meta`` layer of the :term:`Source Directory`.
11804Specifically, you
11805can find the recipes that build both Wayland and Weston at
11806``meta/recipes-graphics/wayland``.
11807
Patrick Williams7784c422022-11-17 07:29:11 -060011808You can build both the Wayland and Weston packages for use only with targets
11809that accept the :wikipedia:`Mesa 3D and Direct Rendering Infrastructure
11810<Mesa_(computer_graphics)>`, which is also known as Mesa DRI. This implies that
11811you cannot build and use the packages if your target uses, for example, the
11812Intel Embedded Media and Graphics Driver (Intel EMGD) that overrides Mesa DRI.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011813
11814.. note::
11815
11816 Due to lack of EGL support, Weston 1.0.3 will not run directly on the
11817 emulated QEMU hardware. However, this version of Weston will run
11818 under X emulation without issues.
11819
11820This section describes what you need to do to implement Wayland and use
11821the Weston compositor when building an image for a supporting target.
11822
11823Enabling Wayland in an Image
11824----------------------------
11825
11826To enable Wayland, you need to enable it to be built and enable it to be
11827included (installed) in the image.
11828
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011829Building Wayland
11830~~~~~~~~~~~~~~~~
11831
11832To cause Mesa to build the ``wayland-egl`` platform and Weston to build
11833Wayland with Kernel Mode Setting
11834(`KMS <https://wiki.archlinux.org/index.php/Kernel_Mode_Setting>`__)
11835support, include the "wayland" flag in the
11836:term:`DISTRO_FEATURES`
Andrew Geisslerc926e172021-05-07 16:11:35 -050011837statement in your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011838
Patrick Williams0ca19cc2021-08-16 14:03:13 -050011839 DISTRO_FEATURES:append = " wayland"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011840
11841.. note::
11842
11843 If X11 has been enabled elsewhere, Weston will build Wayland with X11
11844 support
11845
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011846Installing Wayland and Weston
11847~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11848
11849To install the Wayland feature into an image, you must include the
11850following
11851:term:`CORE_IMAGE_EXTRA_INSTALL`
Andrew Geisslerc926e172021-05-07 16:11:35 -050011852statement in your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011853
11854 CORE_IMAGE_EXTRA_INSTALL += "wayland weston"
11855
11856Running Weston
11857--------------
11858
11859To run Weston inside X11, enabling it as described earlier and building
11860a Sato image is sufficient. If you are running your image under Sato, a
11861Weston Launcher appears in the "Utility" category.
11862
11863Alternatively, you can run Weston through the command-line interpretor
11864(CLI), which is better suited for development work. To run Weston under
11865the CLI, you need to do the following after your image is built:
11866
Andrew Geisslerc926e172021-05-07 16:11:35 -0500118671. Run these commands to export ``XDG_RUNTIME_DIR``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011868
11869 mkdir -p /tmp/$USER-weston
11870 chmod 0700 /tmp/$USER-weston
11871 export XDG_RUNTIME_DIR=/tmp/$USER-weston
11872
Andrew Geisslerc926e172021-05-07 16:11:35 -0500118732. Launch Weston in the shell::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011874
11875 weston