blob: 559709d6f393c6a563ea6c38e94c23c9013903bd [file] [log] [blame]
Andrew Geisslerf0343792020-11-18 10:42:21 -06001.. SPDX-License-Identifier: CC-BY-SA-2.0-UK
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002
3************
4Common Tasks
5************
6
7This chapter describes fundamental procedures such as creating layers,
8adding new software packages, extending or customizing images, porting
9work to new hardware (adding a new machine), and so forth. You will find
10that the procedures documented here occur often in the development cycle
11using the Yocto Project.
12
13Understanding and Creating Layers
14=================================
15
16The OpenEmbedded build system supports organizing
17:term:`Metadata` into multiple layers.
18Layers allow you to isolate different types of customizations from each
19other. For introductory information on the Yocto Project Layer Model,
20see the
Andrew Geissler09209ee2020-12-13 08:44:15 -060021":ref:`overview-manual/yp-intro:the yocto project layer model`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050022section in the Yocto Project Overview and Concepts Manual.
23
24Creating Your Own Layer
25-----------------------
26
Andrew Geissler595f6302022-01-24 19:11:47 +000027.. note::
28
29 It is very easy to create your own layers to use with the OpenEmbedded
30 build system, as the Yocto Project ships with tools that speed up creating
31 layers. This section describes the steps you perform by hand to create
32 layers so that you can better understand them. For information about the
33 layer-creation tools, see the
34 ":ref:`bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script`"
35 section in the Yocto Project Board Support Package (BSP) Developer's
36 Guide and the ":ref:`dev-manual/common-tasks:creating a general layer using the \`\`bitbake-layers\`\` script`"
37 section further down in this manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050038
39Follow these general steps to create your layer without using tools:
40
411. *Check Existing Layers:* Before creating a new layer, you should be
42 sure someone has not already created a layer containing the Metadata
Andrew Geisslerd1e89492021-02-12 15:35:20 -060043 you need. You can see the :oe_layerindex:`OpenEmbedded Metadata Index <>`
44 for a list of layers from the OpenEmbedded community that can be used in
Andrew Geisslerc9f78652020-09-18 14:11:35 -050045 the Yocto Project. You could find a layer that is identical or close
46 to what you need.
47
482. *Create a Directory:* Create the directory for your layer. When you
49 create the layer, be sure to create the directory in an area not
50 associated with the Yocto Project :term:`Source Directory`
51 (e.g. the cloned ``poky`` repository).
52
53 While not strictly required, prepend the name of the directory with
Andrew Geisslerc926e172021-05-07 16:11:35 -050054 the string "meta-". For example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050055
56 meta-mylayer
57 meta-GUI_xyz
58 meta-mymachine
59
Andrew Geisslerc926e172021-05-07 16:11:35 -050060 With rare exceptions, a layer's name follows this form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050061
62 meta-root_name
63
64 Following this layer naming convention can save
65 you trouble later when tools, components, or variables "assume" your
66 layer name begins with "meta-". A notable example is in configuration
67 files as shown in the following step where layer names without the
68 "meta-" string are appended to several variables used in the
69 configuration.
70
713. *Create a Layer Configuration File:* Inside your new layer folder,
72 you need to create a ``conf/layer.conf`` file. It is easiest to take
73 an existing layer configuration file and copy that to your layer's
74 ``conf`` directory and then modify the file as needed.
75
76 The ``meta-yocto-bsp/conf/layer.conf`` file in the Yocto Project
Andrew Geissler09209ee2020-12-13 08:44:15 -060077 :yocto_git:`Source Repositories </poky/tree/meta-yocto-bsp/conf>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050078 demonstrates the required syntax. For your layer, you need to replace
79 "yoctobsp" with a unique identifier for your layer (e.g. "machinexyz"
Andrew Geisslerc926e172021-05-07 16:11:35 -050080 for a layer named "meta-machinexyz")::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050081
82 # We have a conf and classes directory, add to BBPATH
83 BBPATH .= ":${LAYERDIR}"
84
Andrew Geissler4c19ea12020-10-27 13:52:24 -050085 # We have recipes-* directories, add to BBFILES
Andrew Geisslerc9f78652020-09-18 14:11:35 -050086 BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
87 ${LAYERDIR}/recipes-*/*/*.bbappend"
88
89 BBFILE_COLLECTIONS += "yoctobsp"
90 BBFILE_PATTERN_yoctobsp = "^${LAYERDIR}/"
91 BBFILE_PRIORITY_yoctobsp = "5"
92 LAYERVERSION_yoctobsp = "4"
93 LAYERSERIES_COMPAT_yoctobsp = "dunfell"
94
95 Following is an explanation of the layer configuration file:
96
97 - :term:`BBPATH`: Adds the layer's
98 root directory to BitBake's search path. Through the use of the
Andrew Geissler09036742021-06-25 14:25:14 -050099 :term:`BBPATH` variable, BitBake locates class files (``.bbclass``),
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500100 configuration files, and files that are included with ``include``
101 and ``require`` statements. For these cases, BitBake uses the
Andrew Geissler09036742021-06-25 14:25:14 -0500102 first file that matches the name found in :term:`BBPATH`. This is
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500103 similar to the way the ``PATH`` variable is used for binaries. It
104 is recommended, therefore, that you use unique class and
105 configuration filenames in your custom layer.
106
107 - :term:`BBFILES`: Defines the
108 location for all recipes in the layer.
109
110 - :term:`BBFILE_COLLECTIONS`:
111 Establishes the current layer through a unique identifier that is
112 used throughout the OpenEmbedded build system to refer to the
113 layer. In this example, the identifier "yoctobsp" is the
114 representation for the container layer named "meta-yocto-bsp".
115
116 - :term:`BBFILE_PATTERN`:
117 Expands immediately during parsing to provide the directory of the
118 layer.
119
120 - :term:`BBFILE_PRIORITY`:
121 Establishes a priority to use for recipes in the layer when the
122 OpenEmbedded build finds recipes of the same name in different
123 layers.
124
125 - :term:`LAYERVERSION`:
126 Establishes a version number for the layer. You can use this
127 version number to specify this exact version of the layer as a
128 dependency when using the
129 :term:`LAYERDEPENDS`
130 variable.
131
132 - :term:`LAYERDEPENDS`:
133 Lists all layers on which this layer depends (if any).
134
135 - :term:`LAYERSERIES_COMPAT`:
Andrew Geissler09209ee2020-12-13 08:44:15 -0600136 Lists the :yocto_wiki:`Yocto Project </Releases>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500137 releases for which the current version is compatible. This
138 variable is a good way to indicate if your particular layer is
139 current.
140
1414. *Add Content:* Depending on the type of layer, add the content. If
142 the layer adds support for a machine, add the machine configuration
143 in a ``conf/machine/`` file within the layer. If the layer adds
144 distro policy, add the distro configuration in a ``conf/distro/``
145 file within the layer. If the layer introduces new recipes, put the
146 recipes you need in ``recipes-*`` subdirectories within the layer.
147
148 .. note::
149
150 For an explanation of layer hierarchy that is compliant with the
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500151 Yocto Project, see the ":ref:`bsp-guide/bsp:example filesystem layout`"
152 section in the Yocto Project Board Support Package (BSP) Developer's Guide.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500153
1545. *Optionally Test for Compatibility:* If you want permission to use
155 the Yocto Project Compatibility logo with your layer or application
156 that uses your layer, perform the steps to apply for compatibility.
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500157 See the
158 ":ref:`dev-manual/common-tasks:making sure your layer is compatible with yocto project`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500159 section for more information.
160
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500161Following Best Practices When Creating Layers
162---------------------------------------------
163
164To create layers that are easier to maintain and that will not impact
165builds for other machines, you should consider the information in the
166following list:
167
168- *Avoid "Overlaying" Entire Recipes from Other Layers in Your
169 Configuration:* In other words, do not copy an entire recipe into
170 your layer and then modify it. Rather, use an append file
171 (``.bbappend``) to override only those parts of the original recipe
172 you need to modify.
173
174- *Avoid Duplicating Include Files:* Use append files (``.bbappend``)
175 for each recipe that uses an include file. Or, if you are introducing
176 a new recipe that requires the included file, use the path relative
177 to the original layer directory to refer to the file. For example,
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500178 use ``require recipes-core/``\ `package`\ ``/``\ `file`\ ``.inc`` instead
179 of ``require`` `file`\ ``.inc``. If you're finding you have to overlay
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500180 the include file, it could indicate a deficiency in the include file
181 in the layer to which it originally belongs. If this is the case, you
182 should try to address that deficiency instead of overlaying the
183 include file. For example, you could address this by getting the
184 maintainer of the include file to add a variable or variables to make
185 it easy to override the parts needing to be overridden.
186
187- *Structure Your Layers:* Proper use of overrides within append files
188 and placement of machine-specific files within your layer can ensure
189 that a build is not using the wrong Metadata and negatively impacting
190 a build for a different machine. Following are some examples:
191
192 - *Modify Variables to Support a Different Machine:* Suppose you
193 have a layer named ``meta-one`` that adds support for building
194 machine "one". To do so, you use an append file named
195 ``base-files.bbappend`` and create a dependency on "foo" by
196 altering the :term:`DEPENDS`
Andrew Geisslerc926e172021-05-07 16:11:35 -0500197 variable::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500198
199 DEPENDS = "foo"
200
201 The dependency is created during any
202 build that includes the layer ``meta-one``. However, you might not
203 want this dependency for all machines. For example, suppose you
204 are building for machine "two" but your ``bblayers.conf`` file has
205 the ``meta-one`` layer included. During the build, the
206 ``base-files`` for machine "two" will also have the dependency on
207 ``foo``.
208
209 To make sure your changes apply only when building machine "one",
Andrew Geissler09036742021-06-25 14:25:14 -0500210 use a machine override with the :term:`DEPENDS` statement::
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500211
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500212 DEPENDS:one = "foo"
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500213
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500214 You should follow the same strategy when using ``:append``
215 and ``:prepend`` operations::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500216
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500217 DEPENDS:append:one = " foo"
218 DEPENDS:prepend:one = "foo "
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500219
220 As an actual example, here's a
221 snippet from the generic kernel include file ``linux-yocto.inc``,
222 wherein the kernel compile and link options are adjusted in the
Andrew Geisslerc926e172021-05-07 16:11:35 -0500223 case of a subset of the supported architectures::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500224
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500225 DEPENDS:append:aarch64 = " libgcc"
226 KERNEL_CC:append:aarch64 = " ${TOOLCHAIN_OPTIONS}"
227 KERNEL_LD:append:aarch64 = " ${TOOLCHAIN_OPTIONS}"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500228
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500229 DEPENDS:append:nios2 = " libgcc"
230 KERNEL_CC:append:nios2 = " ${TOOLCHAIN_OPTIONS}"
231 KERNEL_LD:append:nios2 = " ${TOOLCHAIN_OPTIONS}"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500232
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500233 DEPENDS:append:arc = " libgcc"
234 KERNEL_CC:append:arc = " ${TOOLCHAIN_OPTIONS}"
235 KERNEL_LD:append:arc = " ${TOOLCHAIN_OPTIONS}"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500236
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500237 KERNEL_FEATURES:append:qemuall=" features/debug/printk.scc"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500238
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500239 - *Place Machine-Specific Files in Machine-Specific Locations:* When
240 you have a base recipe, such as ``base-files.bb``, that contains a
241 :term:`SRC_URI` statement to a
242 file, you can use an append file to cause the build to use your
243 own version of the file. For example, an append file in your layer
244 at ``meta-one/recipes-core/base-files/base-files.bbappend`` could
Andrew Geisslerc926e172021-05-07 16:11:35 -0500245 extend :term:`FILESPATH` using :term:`FILESEXTRAPATHS` as follows::
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500246
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500247 FILESEXTRAPATHS:prepend := "${THISDIR}/${BPN}:"
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500248
249 The build for machine "one" will pick up your machine-specific file as
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500250 long as you have the file in
251 ``meta-one/recipes-core/base-files/base-files/``. However, if you
252 are building for a different machine and the ``bblayers.conf``
253 file includes the ``meta-one`` layer and the location of your
254 machine-specific file is the first location where that file is
Andrew Geissler09036742021-06-25 14:25:14 -0500255 found according to :term:`FILESPATH`, builds for all machines will
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500256 also use that machine-specific file.
257
258 You can make sure that a machine-specific file is used for a
259 particular machine by putting the file in a subdirectory specific
260 to the machine. For example, rather than placing the file in
261 ``meta-one/recipes-core/base-files/base-files/`` as shown above,
262 put it in ``meta-one/recipes-core/base-files/base-files/one/``.
263 Not only does this make sure the file is used only when building
264 for machine "one", but the build process locates the file more
265 quickly.
266
267 In summary, you need to place all files referenced from
Andrew Geissler5f350902021-07-23 13:09:54 -0400268 :term:`SRC_URI` in a machine-specific subdirectory within the layer in
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500269 order to restrict those files to machine-specific builds.
270
271- *Perform Steps to Apply for Yocto Project Compatibility:* If you want
272 permission to use the Yocto Project Compatibility logo with your
273 layer or application that uses your layer, perform the steps to apply
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500274 for compatibility. See the
275 ":ref:`dev-manual/common-tasks:making sure your layer is compatible with yocto project`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500276 section for more information.
277
278- *Follow the Layer Naming Convention:* Store custom layers in a Git
279 repository that use the ``meta-layer_name`` format.
280
281- *Group Your Layers Locally:* Clone your repository alongside other
282 cloned ``meta`` directories from the :term:`Source Directory`.
283
284Making Sure Your Layer is Compatible With Yocto Project
285-------------------------------------------------------
286
287When you create a layer used with the Yocto Project, it is advantageous
288to make sure that the layer interacts well with existing Yocto Project
289layers (i.e. the layer is compatible with the Yocto Project). Ensuring
290compatibility makes the layer easy to be consumed by others in the Yocto
291Project community and could allow you permission to use the Yocto
292Project Compatible Logo.
293
294.. note::
295
296 Only Yocto Project member organizations are permitted to use the
297 Yocto Project Compatible Logo. The logo is not available for general
298 use. For information on how to become a Yocto Project member
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500299 organization, see the :yocto_home:`Yocto Project Website <>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500300
301The Yocto Project Compatibility Program consists of a layer application
302process that requests permission to use the Yocto Project Compatibility
303Logo for your layer and application. The process consists of two parts:
304
3051. Successfully passing a script (``yocto-check-layer``) that when run
306 against your layer, tests it against constraints based on experiences
307 of how layers have worked in the real world and where pitfalls have
308 been found. Getting a "PASS" result from the script is required for
309 successful compatibility registration.
310
3112. Completion of an application acceptance form, which you can find at
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600312 :yocto_home:`/webform/yocto-project-compatible-registration`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500313
314To be granted permission to use the logo, you need to satisfy the
315following:
316
317- Be able to check the box indicating that you got a "PASS" when
318 running the script against your layer.
319
320- Answer "Yes" to the questions on the form or have an acceptable
321 explanation for any questions answered "No".
322
323- Be a Yocto Project Member Organization.
324
325The remainder of this section presents information on the registration
326form and on the ``yocto-check-layer`` script.
327
328Yocto Project Compatible Program Application
329~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
330
331Use the form to apply for your layer's approval. Upon successful
332application, you can use the Yocto Project Compatibility Logo with your
333layer and the application that uses your layer.
334
335To access the form, use this link:
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600336:yocto_home:`/webform/yocto-project-compatible-registration`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500337Follow the instructions on the form to complete your application.
338
339The application consists of the following sections:
340
341- *Contact Information:* Provide your contact information as the fields
342 require. Along with your information, provide the released versions
343 of the Yocto Project for which your layer is compatible.
344
345- *Acceptance Criteria:* Provide "Yes" or "No" answers for each of the
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700346 items in the checklist. There is space at the bottom of the form for
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500347 any explanations for items for which you answered "No".
348
349- *Recommendations:* Provide answers for the questions regarding Linux
350 kernel use and build success.
351
352``yocto-check-layer`` Script
353~~~~~~~~~~~~~~~~~~~~~~~~~~~~
354
355The ``yocto-check-layer`` script provides you a way to assess how
356compatible your layer is with the Yocto Project. You should run this
357script prior to using the form to apply for compatibility as described
358in the previous section. You need to achieve a "PASS" result in order to
359have your application form successfully processed.
360
361The script divides tests into three areas: COMMON, BSP, and DISTRO. For
362example, given a distribution layer (DISTRO), the layer must pass both
363the COMMON and DISTRO related tests. Furthermore, if your layer is a BSP
364layer, the layer must pass the COMMON and BSP set of tests.
365
366To execute the script, enter the following commands from your build
Andrew Geisslerc926e172021-05-07 16:11:35 -0500367directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500368
369 $ source oe-init-build-env
370 $ yocto-check-layer your_layer_directory
371
372Be sure to provide the actual directory for your
373layer as part of the command.
374
375Entering the command causes the script to determine the type of layer
376and then to execute a set of specific tests against the layer. The
377following list overviews the test:
378
379- ``common.test_readme``: Tests if a ``README`` file exists in the
380 layer and the file is not empty.
381
382- ``common.test_parse``: Tests to make sure that BitBake can parse the
383 files without error (i.e. ``bitbake -p``).
384
385- ``common.test_show_environment``: Tests that the global or per-recipe
386 environment is in order without errors (i.e. ``bitbake -e``).
387
388- ``common.test_world``: Verifies that ``bitbake world`` works.
389
390- ``common.test_signatures``: Tests to be sure that BSP and DISTRO
391 layers do not come with recipes that change signatures.
392
393- ``common.test_layerseries_compat``: Verifies layer compatibility is
394 set properly.
395
396- ``bsp.test_bsp_defines_machines``: Tests if a BSP layer has machine
397 configurations.
398
399- ``bsp.test_bsp_no_set_machine``: Tests to ensure a BSP layer does not
400 set the machine when the layer is added.
401
402- ``bsp.test_machine_world``: Verifies that ``bitbake world`` works
403 regardless of which machine is selected.
404
405- ``bsp.test_machine_signatures``: Verifies that building for a
406 particular machine affects only the signature of tasks specific to
407 that machine.
408
409- ``distro.test_distro_defines_distros``: Tests if a DISTRO layer has
410 distro configurations.
411
412- ``distro.test_distro_no_set_distros``: Tests to ensure a DISTRO layer
413 does not set the distribution when the layer is added.
414
415Enabling Your Layer
416-------------------
417
418Before the OpenEmbedded build system can use your new layer, you need to
419enable it. To enable your layer, simply add your layer's path to the
Andrew Geissler09036742021-06-25 14:25:14 -0500420:term:`BBLAYERS` variable in your ``conf/bblayers.conf`` file, which is
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500421found in the :term:`Build Directory`.
Andrew Geissler5199d832021-09-24 16:47:35 -0500422The following example shows how to enable your new
423``meta-mylayer`` layer (note how your new layer exists outside of
424the official ``poky`` repository which you would have checked out earlier)::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500425
426 # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
427 # changes incompatibly
428 POKY_BBLAYERS_CONF_VERSION = "2"
429 BBPATH = "${TOPDIR}"
430 BBFILES ?= ""
431 BBLAYERS ?= " \
432 /home/user/poky/meta \
433 /home/user/poky/meta-poky \
434 /home/user/poky/meta-yocto-bsp \
Andrew Geissler5199d832021-09-24 16:47:35 -0500435 /home/user/mystuff/meta-mylayer \
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500436 "
437
438BitBake parses each ``conf/layer.conf`` file from the top down as
Andrew Geissler09036742021-06-25 14:25:14 -0500439specified in the :term:`BBLAYERS` variable within the ``conf/bblayers.conf``
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500440file. During the processing of each ``conf/layer.conf`` file, BitBake
441adds the recipes, classes and configurations contained within the
442particular layer to the source directory.
443
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500444Appending Other Layers Metadata With Your Layer
445-----------------------------------------------
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500446
447A recipe that appends Metadata to another recipe is called a BitBake
448append file. A BitBake append file uses the ``.bbappend`` file type
449suffix, while the corresponding recipe to which Metadata is being
450appended uses the ``.bb`` file type suffix.
451
452You can use a ``.bbappend`` file in your layer to make additions or
453changes to the content of another layer's recipe without having to copy
454the other layer's recipe into your layer. Your ``.bbappend`` file
455resides in your layer, while the main ``.bb`` recipe file to which you
456are appending Metadata resides in a different layer.
457
458Being able to append information to an existing recipe not only avoids
459duplication, but also automatically applies recipe changes from a
460different layer into your layer. If you were copying recipes, you would
461have to manually merge changes as they occur.
462
463When you create an append file, you must use the same root name as the
464corresponding recipe file. For example, the append file
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500465``someapp_3.1.bbappend`` must apply to ``someapp_3.1.bb``. This
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500466means the original recipe and append filenames are version
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500467number-specific. If the corresponding recipe is renamed to update to a
468newer version, you must also rename and possibly update the
469corresponding ``.bbappend`` as well. During the build process, BitBake
470displays an error on starting if it detects a ``.bbappend`` file that
471does not have a corresponding recipe with a matching name. See the
472:term:`BB_DANGLINGAPPENDS_WARNONLY`
473variable for information on how to handle this error.
474
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500475Overlaying a File Using Your Layer
476~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
477
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500478As an example, consider the main formfactor recipe and a corresponding
479formfactor append file both from the :term:`Source Directory`.
480Here is the main
481formfactor recipe, which is named ``formfactor_0.0.bb`` and located in
Andrew Geisslerc926e172021-05-07 16:11:35 -0500482the "meta" layer at ``meta/recipes-bsp/formfactor``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500483
484 SUMMARY = "Device formfactor information"
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500485 DESCRIPTION = "A formfactor configuration file provides information about the \
486 target hardware for which the image is being built and information that the \
487 build system cannot obtain from other sources such as the kernel."
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500488 SECTION = "base"
489 LICENSE = "MIT"
490 LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
491 PR = "r45"
492
493 SRC_URI = "file://config file://machconfig"
494 S = "${WORKDIR}"
495
496 PACKAGE_ARCH = "${MACHINE_ARCH}"
497 INHIBIT_DEFAULT_DEPS = "1"
498
499 do_install() {
500 # Install file only if it has contents
501 install -d ${D}${sysconfdir}/formfactor/
502 install -m 0644 ${S}/config ${D}${sysconfdir}/formfactor/
503 if [ -s "${S}/machconfig" ]; then
504 install -m 0644 ${S}/machconfig ${D}${sysconfdir}/formfactor/
505 fi
506 }
507
508In the main recipe, note the :term:`SRC_URI`
509variable, which tells the OpenEmbedded build system where to find files
510during the build.
511
512Following is the append file, which is named ``formfactor_0.0.bbappend``
513and is from the Raspberry Pi BSP Layer named ``meta-raspberrypi``. The
Andrew Geisslerc926e172021-05-07 16:11:35 -0500514file is in the layer at ``recipes-bsp/formfactor``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500515
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500516 FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500517
518By default, the build system uses the
519:term:`FILESPATH` variable to
520locate files. This append file extends the locations by setting the
521:term:`FILESEXTRAPATHS`
522variable. Setting this variable in the ``.bbappend`` file is the most
523reliable and recommended method for adding directories to the search
524path used by the build system to find files.
525
526The statement in this example extends the directories to include
527``${``\ :term:`THISDIR`\ ``}/${``\ :term:`PN`\ ``}``,
528which resolves to a directory named ``formfactor`` in the same directory
529in which the append file resides (i.e.
530``meta-raspberrypi/recipes-bsp/formfactor``. This implies that you must
531have the supporting directory structure set up that will contain any
532files or patches you will be including from the layer.
533
534Using the immediate expansion assignment operator ``:=`` is important
Andrew Geissler09036742021-06-25 14:25:14 -0500535because of the reference to :term:`THISDIR`. The trailing colon character is
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500536important as it ensures that items in the list remain colon-separated.
537
538.. note::
539
Andrew Geissler09036742021-06-25 14:25:14 -0500540 BitBake automatically defines the :term:`THISDIR` variable. You should
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500541 never set this variable yourself. Using ":prepend" as part of the
Andrew Geissler09036742021-06-25 14:25:14 -0500542 :term:`FILESEXTRAPATHS` ensures your path will be searched prior to other
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500543 paths in the final list.
544
545 Also, not all append files add extra files. Many append files simply
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700546 allow to add build options (e.g. ``systemd``). For these cases, your
Andrew Geissler09036742021-06-25 14:25:14 -0500547 append file would not even use the :term:`FILESEXTRAPATHS` statement.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500548
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500549The end result of this ``.bbappend`` file is that on a Raspberry Pi, where
550``rpi`` will exist in the list of :term:`OVERRIDES`, the file
551``meta-raspberrypi/recipes-bsp/formfactor/formfactor/rpi/machconfig`` will be
552used during :ref:`ref-tasks-fetch` and the test for a non-zero file size in
553:ref:`ref-tasks-install` will return true, and the file will be installed.
554
Andrew Geissler5199d832021-09-24 16:47:35 -0500555Installing Additional Files Using Your Layer
556~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
557
558As another example, consider the main ``xserver-xf86-config`` recipe and a
559corresponding ``xserver-xf86-config`` append file both from the :term:`Source
560Directory`. Here is the main ``xserver-xf86-config`` recipe, which is named
561``xserver-xf86-config_0.1.bb`` and located in the "meta" layer at
562``meta/recipes-graphics/xorg-xserver``::
563
564 SUMMARY = "X.Org X server configuration file"
565 HOMEPAGE = "http://www.x.org"
566 SECTION = "x11/base"
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
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500972``local.conf`` file, which is found in the
973:term:`Build Directory`.
974
975To understand how these features work, the best reference is
Andrew Geissler595f6302022-01-24 19:11:47 +0000976:ref:`meta/classes/image.bbclass <ref-classes-image>`.
977This class lists out the available
Andrew Geissler09036742021-06-25 14:25:14 -0500978:term:`IMAGE_FEATURES` of which most map to package groups while some, such
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500979as ``debug-tweaks`` and ``read-only-rootfs``, resolve as general
980configuration settings.
981
Andrew Geissler09036742021-06-25 14:25:14 -0500982In summary, the file looks at the contents of the :term:`IMAGE_FEATURES`
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500983variable and then maps or configures the feature accordingly. Based on
984this information, the build system automatically adds the appropriate
985packages or configurations to the
986:term:`IMAGE_INSTALL` variable.
987Effectively, you are enabling extra features by extending the class or
988creating a custom class for use with specialized image ``.bb`` files.
989
Andrew Geissler09036742021-06-25 14:25:14 -0500990Use the :term:`EXTRA_IMAGE_FEATURES` variable from within your local
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500991configuration file. Using a separate area from which to enable features
992with this variable helps you avoid overwriting the features in the image
Andrew Geissler09036742021-06-25 14:25:14 -0500993recipe that are enabled with :term:`IMAGE_FEATURES`. The value of
994:term:`EXTRA_IMAGE_FEATURES` is added to :term:`IMAGE_FEATURES` within
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500995``meta/conf/bitbake.conf``.
996
997To illustrate how you can use these variables to modify your image,
998consider an example that selects the SSH server. The Yocto Project ships
999with two SSH servers you can use with your images: Dropbear and OpenSSH.
1000Dropbear is a minimal SSH server appropriate for resource-constrained
1001environments, while OpenSSH is a well-known standard SSH server
1002implementation. By default, the ``core-image-sato`` image is configured
1003to use Dropbear. The ``core-image-full-cmdline`` and ``core-image-lsb``
1004images both include OpenSSH. The ``core-image-minimal`` image does not
1005contain an SSH server.
1006
1007You can customize your image and change these defaults. Edit the
Andrew Geissler09036742021-06-25 14:25:14 -05001008:term:`IMAGE_FEATURES` variable in your recipe or use the
1009:term:`EXTRA_IMAGE_FEATURES` in your ``local.conf`` file so that it
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001010configures the image you are working with to include
1011``ssh-server-dropbear`` or ``ssh-server-openssh``.
1012
1013.. note::
1014
Andrew Geissler09209ee2020-12-13 08:44:15 -06001015 See the ":ref:`ref-manual/features:image features`" section in the Yocto
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001016 Project Reference Manual for a complete list of image features that ship
1017 with the Yocto Project.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001018
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001019Customizing Images Using Custom .bb Files
1020-----------------------------------------
1021
1022You can also customize an image by creating a custom recipe that defines
1023additional software as part of the image. The following example shows
Andrew Geisslerc926e172021-05-07 16:11:35 -05001024the form for the two lines you need::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001025
1026 IMAGE_INSTALL = "packagegroup-core-x11-base package1 package2"
1027 inherit core-image
1028
1029Defining the software using a custom recipe gives you total control over
1030the contents of the image. It is important to use the correct names of
Andrew Geissler09036742021-06-25 14:25:14 -05001031packages in the :term:`IMAGE_INSTALL` variable. You must use the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001032OpenEmbedded notation and not the Debian notation for the names (e.g.
1033``glibc-dev`` instead of ``libc6-dev``).
1034
1035The other method for creating a custom image is to base it on an
1036existing image. For example, if you want to create an image based on
1037``core-image-sato`` but add the additional package ``strace`` to the
1038image, copy the ``meta/recipes-sato/images/core-image-sato.bb`` to a new
Andrew Geisslerc926e172021-05-07 16:11:35 -05001039``.bb`` and add the following line to the end of the copy::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001040
1041 IMAGE_INSTALL += "strace"
1042
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001043Customizing Images Using Custom Package Groups
1044----------------------------------------------
1045
1046For complex custom images, the best approach for customizing an image is
1047to create a custom package group recipe that is used to build the image
1048or images. A good example of a package group recipe is
1049``meta/recipes-core/packagegroups/packagegroup-base.bb``.
1050
Andrew Geissler09036742021-06-25 14:25:14 -05001051If you examine that recipe, you see that the :term:`PACKAGES` variable lists
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001052the package group packages to produce. The ``inherit packagegroup``
1053statement sets appropriate default values and automatically adds
1054``-dev``, ``-dbg``, and ``-ptest`` complementary packages for each
Andrew Geissler09036742021-06-25 14:25:14 -05001055package specified in the :term:`PACKAGES` statement.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001056
1057.. note::
1058
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001059 The ``inherit packagegroup`` line should be located near the top of the
Andrew Geissler09036742021-06-25 14:25:14 -05001060 recipe, certainly before the :term:`PACKAGES` statement.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001061
Andrew Geissler09036742021-06-25 14:25:14 -05001062For each package you specify in :term:`PACKAGES`, you can use :term:`RDEPENDS`
1063and :term:`RRECOMMENDS` entries to provide a list of packages the parent
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001064task package should contain. You can see examples of these further down
1065in the ``packagegroup-base.bb`` recipe.
1066
1067Here is a short, fabricated example showing the same basic pieces for a
1068hypothetical packagegroup defined in ``packagegroup-custom.bb``, where
Andrew Geissler09036742021-06-25 14:25:14 -05001069the variable :term:`PN` is the standard way to abbreviate the reference to
Andrew Geisslerc926e172021-05-07 16:11:35 -05001070the full packagegroup name ``packagegroup-custom``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001071
1072 DESCRIPTION = "My Custom Package Groups"
1073
1074 inherit packagegroup
1075
1076 PACKAGES = "\
1077 ${PN}-apps \
1078 ${PN}-tools \
1079 "
1080
Patrick Williams0ca19cc2021-08-16 14:03:13 -05001081 RDEPENDS:${PN}-apps = "\
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001082 dropbear \
1083 portmap \
1084 psplash"
1085
Patrick Williams0ca19cc2021-08-16 14:03:13 -05001086 RDEPENDS:${PN}-tools = "\
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001087 oprofile \
1088 oprofileui-server \
1089 lttng-tools"
1090
Patrick Williams0ca19cc2021-08-16 14:03:13 -05001091 RRECOMMENDS:${PN}-tools = "\
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001092 kernel-module-oprofile"
1093
1094In the previous example, two package group packages are created with
1095their dependencies and their recommended package dependencies listed:
1096``packagegroup-custom-apps``, and ``packagegroup-custom-tools``. To
1097build an image using these package group packages, you need to add
1098``packagegroup-custom-apps`` and/or ``packagegroup-custom-tools`` to
Andrew Geissler09036742021-06-25 14:25:14 -05001099:term:`IMAGE_INSTALL`. For other forms of image dependencies see the other
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001100areas of this section.
1101
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001102Customizing an Image Hostname
1103-----------------------------
1104
1105By default, the configured hostname (i.e. ``/etc/hostname``) in an image
1106is the same as the machine name. For example, if
1107:term:`MACHINE` equals "qemux86", the
1108configured hostname written to ``/etc/hostname`` is "qemux86".
1109
1110You can customize this name by altering the value of the "hostname"
1111variable in the ``base-files`` recipe using either an append file or a
Andrew Geisslerc926e172021-05-07 16:11:35 -05001112configuration file. Use the following in an append file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001113
1114 hostname = "myhostname"
1115
Andrew Geisslerc926e172021-05-07 16:11:35 -05001116Use the following in a configuration file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001117
Patrick Williams0ca19cc2021-08-16 14:03:13 -05001118 hostname:pn-base-files = "myhostname"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001119
1120Changing the default value of the variable "hostname" can be useful in
1121certain situations. For example, suppose you need to do extensive
1122testing on an image and you would like to easily identify the image
1123under test from existing images with typical default hostnames. In this
1124situation, you could change the default hostname to "testme", which
1125results in all the images using the name "testme". Once testing is
1126complete and you do not need to rebuild the image for test any longer,
1127you can easily reset the default hostname.
1128
1129Another point of interest is that if you unset the variable, the image
1130will have no default hostname in the filesystem. Here is an example that
Andrew Geisslerc926e172021-05-07 16:11:35 -05001131unsets the variable in a configuration file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001132
Patrick Williams0ca19cc2021-08-16 14:03:13 -05001133 hostname:pn-base-files = ""
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001134
1135Having no default hostname in the filesystem is suitable for
1136environments that use dynamic hostnames such as virtual machines.
1137
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001138Writing a New Recipe
1139====================
1140
1141Recipes (``.bb`` files) are fundamental components in the Yocto Project
1142environment. Each software component built by the OpenEmbedded build
1143system requires a recipe to define the component. This section describes
1144how to create, write, and test a new recipe.
1145
1146.. note::
1147
1148 For information on variables that are useful for recipes and for
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001149 information about recipe naming issues, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001150 ":ref:`ref-manual/varlocality:recipes`" section of the Yocto Project
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001151 Reference Manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001152
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001153Overview
1154--------
1155
1156The following figure shows the basic process for creating a new recipe.
1157The remainder of the section provides details for the steps.
1158
1159.. image:: figures/recipe-workflow.png
1160 :align: center
Andrew Geisslerd5838332022-05-27 11:33:10 -05001161 :width: 50%
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001162
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001163Locate or Automatically Create a Base Recipe
1164--------------------------------------------
1165
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001166You can always write a recipe from scratch. However, there are three choices
1167that can help you quickly get started with a new recipe:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001168
1169- ``devtool add``: A command that assists in creating a recipe and an
1170 environment conducive to development.
1171
1172- ``recipetool create``: A command provided by the Yocto Project that
1173 automates creation of a base recipe based on the source files.
1174
1175- *Existing Recipes:* Location and modification of an existing recipe
1176 that is similar in function to the recipe you need.
1177
1178.. note::
1179
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001180 For information on recipe syntax, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001181 ":ref:`dev-manual/common-tasks:recipe syntax`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001182
1183Creating the Base Recipe Using ``devtool add``
1184~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1185
1186The ``devtool add`` command uses the same logic for auto-creating the
1187recipe as ``recipetool create``, which is listed below. Additionally,
1188however, ``devtool add`` sets up an environment that makes it easy for
1189you to patch the source and to make changes to the recipe as is often
1190necessary when adding a recipe to build a new piece of software to be
1191included in a build.
1192
1193You can find a complete description of the ``devtool add`` command in
Andrew Geissler09209ee2020-12-13 08:44:15 -06001194the ":ref:`sdk-manual/extensible:a closer look at \`\`devtool add\`\``" section
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001195in the Yocto Project Application Development and the Extensible Software
1196Development Kit (eSDK) manual.
1197
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001198Creating the Base Recipe Using ``recipetool create``
1199~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1200
1201``recipetool create`` automates creation of a base recipe given a set of
1202source code files. As long as you can extract or point to the source
1203files, the tool will construct a recipe and automatically configure all
1204pre-build information into the recipe. For example, suppose you have an
1205application that builds using Autotools. Creating the base recipe using
1206``recipetool`` results in a recipe that has the pre-build dependencies,
1207license requirements, and checksums configured.
1208
1209To run the tool, you just need to be in your
1210:term:`Build Directory` and have sourced the
1211build environment setup script (i.e.
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001212:ref:`structure-core-script`).
Andrew Geisslerc926e172021-05-07 16:11:35 -05001213To get help on the tool, use the following command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001214
1215 $ recipetool -h
1216 NOTE: Starting bitbake server...
1217 usage: recipetool [-d] [-q] [--color COLOR] [-h] <subcommand> ...
1218
1219 OpenEmbedded recipe tool
1220
1221 options:
1222 -d, --debug Enable debug output
1223 -q, --quiet Print only errors
1224 --color COLOR Colorize output (where COLOR is auto, always, never)
1225 -h, --help show this help message and exit
1226
1227 subcommands:
1228 create Create a new recipe
1229 newappend Create a bbappend for the specified target in the specified
1230 layer
1231 setvar Set a variable within a recipe
1232 appendfile Create/update a bbappend to replace a target file
1233 appendsrcfiles Create/update a bbappend to add or replace source files
1234 appendsrcfile Create/update a bbappend to add or replace a source file
1235 Use recipetool <subcommand> --help to get help on a specific command
1236
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001237Running ``recipetool create -o OUTFILE`` creates the base recipe and
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001238locates it properly in the layer that contains your source files.
1239Following are some syntax examples:
1240
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001241 - Use this syntax to generate a recipe based on source. Once generated,
Andrew Geisslerc926e172021-05-07 16:11:35 -05001242 the recipe resides in the existing source code layer::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001243
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001244 recipetool create -o OUTFILE source
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001245
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001246 - Use this syntax to generate a recipe using code that
1247 you extract from source. The extracted code is placed in its own layer
Andrew Geissler09036742021-06-25 14:25:14 -05001248 defined by :term:`EXTERNALSRC`.
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001249 ::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001250
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001251 recipetool create -o OUTFILE -x EXTERNALSRC source
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001252
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001253 - Use this syntax to generate a recipe based on source. The options
1254 direct ``recipetool`` to generate debugging information. Once generated,
Andrew Geisslerc926e172021-05-07 16:11:35 -05001255 the recipe resides in the existing source code layer::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001256
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001257 recipetool create -d -o OUTFILE source
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001258
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001259Locating and Using a Similar Recipe
1260~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1261
1262Before writing a recipe from scratch, it is often useful to discover
1263whether someone else has already written one that meets (or comes close
1264to meeting) your needs. The Yocto Project and OpenEmbedded communities
1265maintain many recipes that might be candidates for what you are doing.
Andrew Geisslerd1e89492021-02-12 15:35:20 -06001266You can find a good central index of these recipes in the
1267:oe_layerindex:`OpenEmbedded Layer Index <>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001268
1269Working from an existing recipe or a skeleton recipe is the best way to
1270get started. Here are some points on both methods:
1271
1272- *Locate and modify a recipe that is close to what you want to do:*
1273 This method works when you are familiar with the current recipe
1274 space. The method does not work so well for those new to the Yocto
1275 Project or writing recipes.
1276
1277 Some risks associated with this method are using a recipe that has
1278 areas totally unrelated to what you are trying to accomplish with
1279 your recipe, not recognizing areas of the recipe that you might have
1280 to add from scratch, and so forth. All these risks stem from
1281 unfamiliarity with the existing recipe space.
1282
1283- *Use and modify the following skeleton recipe:* If for some reason
1284 you do not want to use ``recipetool`` and you cannot find an existing
1285 recipe that is close to meeting your needs, you can use the following
1286 structure to provide the fundamental areas of a new recipe.
1287 ::
1288
1289 DESCRIPTION = ""
1290 HOMEPAGE = ""
1291 LICENSE = ""
1292 SECTION = ""
1293 DEPENDS = ""
1294 LIC_FILES_CHKSUM = ""
1295
1296 SRC_URI = ""
1297
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001298Storing and Naming the Recipe
1299-----------------------------
1300
1301Once you have your base recipe, you should put it in your own layer and
1302name it appropriately. Locating it correctly ensures that the
1303OpenEmbedded build system can find it when you use BitBake to process
1304the recipe.
1305
1306- *Storing Your Recipe:* The OpenEmbedded build system locates your
1307 recipe through the layer's ``conf/layer.conf`` file and the
1308 :term:`BBFILES` variable. This
1309 variable sets up a path from which the build system can locate
Andrew Geisslerc926e172021-05-07 16:11:35 -05001310 recipes. Here is the typical use::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001311
1312 BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
1313 ${LAYERDIR}/recipes-*/*/*.bbappend"
1314
1315 Consequently, you need to be sure you locate your new recipe inside
1316 your layer such that it can be found.
1317
1318 You can find more information on how layers are structured in the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001319 ":ref:`dev-manual/common-tasks:understanding and creating layers`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001320
1321- *Naming Your Recipe:* When you name your recipe, you need to follow
Andrew Geisslerc926e172021-05-07 16:11:35 -05001322 this naming convention::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001323
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001324 basename_version.bb
1325
1326 Use lower-cased characters and do not include the reserved suffixes
1327 ``-native``, ``-cross``, ``-initial``, or ``-dev`` casually (i.e. do not use
1328 them as part of your recipe name unless the string applies). Here are some
1329 examples:
1330
1331 .. code-block:: none
1332
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001333 cups_1.7.0.bb
1334 gawk_4.0.2.bb
1335 irssi_0.8.16-rc1.bb
1336
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001337Running a Build on the Recipe
1338-----------------------------
1339
1340Creating a new recipe is usually an iterative process that requires
1341using BitBake to process the recipe multiple times in order to
1342progressively discover and add information to the recipe file.
1343
1344Assuming you have sourced the build environment setup script (i.e.
1345:ref:`structure-core-script`) and you are in
1346the :term:`Build Directory`, use
1347BitBake to process your recipe. All you need to provide is the
Andrew Geisslerc926e172021-05-07 16:11:35 -05001348``basename`` of the recipe as described in the previous section::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001349
1350 $ bitbake basename
1351
1352During the build, the OpenEmbedded build system creates a temporary work
1353directory for each recipe
1354(``${``\ :term:`WORKDIR`\ ``}``)
1355where it keeps extracted source files, log files, intermediate
1356compilation and packaging files, and so forth.
1357
1358The path to the per-recipe temporary work directory depends on the
1359context in which it is being built. The quickest way to find this path
Andrew Geisslerc926e172021-05-07 16:11:35 -05001360is to have BitBake return it by running the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001361
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001362 $ bitbake -e basename | grep ^WORKDIR=
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001363
1364As an example, assume a Source Directory
1365top-level folder named ``poky``, a default Build Directory at
1366``poky/build``, and a ``qemux86-poky-linux`` machine target system.
1367Furthermore, suppose your recipe is named ``foo_1.3.0.bb``. In this
1368case, the work directory the build system uses to build the package
Andrew Geisslerc926e172021-05-07 16:11:35 -05001369would be as follows::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001370
1371 poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
1372
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001373Inside this directory you can find sub-directories such as ``image``,
1374``packages-split``, and ``temp``. After the build, you can examine these
1375to determine how well the build went.
1376
1377.. note::
1378
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001379 You can find log files for each task in the recipe's ``temp``
1380 directory (e.g. ``poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0/temp``).
1381 Log files are named ``log.taskname`` (e.g. ``log.do_configure``,
1382 ``log.do_fetch``, and ``log.do_compile``).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001383
1384You can find more information about the build process in
Andrew Geissler09209ee2020-12-13 08:44:15 -06001385":doc:`/overview-manual/development-environment`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001386chapter of the Yocto Project Overview and Concepts Manual.
1387
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001388Fetching Code
1389-------------
1390
1391The first thing your recipe must do is specify how to fetch the source
1392files. Fetching is controlled mainly through the
1393:term:`SRC_URI` variable. Your recipe
Andrew Geissler09036742021-06-25 14:25:14 -05001394must have a :term:`SRC_URI` variable that points to where the source is
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001395located. For a graphical representation of source locations, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001396":ref:`overview-manual/concepts:sources`" section in
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001397the Yocto Project Overview and Concepts Manual.
1398
1399The :ref:`ref-tasks-fetch` task uses
Andrew Geissler09036742021-06-25 14:25:14 -05001400the prefix of each entry in the :term:`SRC_URI` variable value to determine
Andrew Geissler09209ee2020-12-13 08:44:15 -06001401which :ref:`fetcher <bitbake:bitbake-user-manual/bitbake-user-manual-fetching:fetchers>` to use to get your
Andrew Geissler09036742021-06-25 14:25:14 -05001402source files. It is the :term:`SRC_URI` variable that triggers the fetcher.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001403The :ref:`ref-tasks-patch` task uses
1404the variable after source is fetched to apply patches. The OpenEmbedded
1405build system uses
1406:term:`FILESOVERRIDES` for
Andrew Geissler09036742021-06-25 14:25:14 -05001407scanning directory locations for local files in :term:`SRC_URI`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001408
Andrew Geissler09036742021-06-25 14:25:14 -05001409The :term:`SRC_URI` variable in your recipe must define each unique location
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001410for your source files. It is good practice to not hard-code version
Andrew Geissler5f350902021-07-23 13:09:54 -04001411numbers in a URL used in :term:`SRC_URI`. Rather than hard-code these
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001412values, use ``${``\ :term:`PV`\ ``}``,
1413which causes the fetch process to use the version specified in the
1414recipe filename. Specifying the version in this manner means that
1415upgrading the recipe to a future version is as simple as renaming the
1416recipe to match the new version.
1417
1418Here is a simple example from the
1419``meta/recipes-devtools/strace/strace_5.5.bb`` recipe where the source
1420comes from a single tarball. Notice the use of the
Andrew Geisslerc926e172021-05-07 16:11:35 -05001421:term:`PV` variable::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001422
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001423 SRC_URI = "https://strace.io/files/${PV}/strace-${PV}.tar.xz \
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001424
Andrew Geissler09036742021-06-25 14:25:14 -05001425Files mentioned in :term:`SRC_URI` whose names end in a typical archive
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001426extension (e.g. ``.tar``, ``.tar.gz``, ``.tar.bz2``, ``.zip``, and so
1427forth), are automatically extracted during the
1428:ref:`ref-tasks-unpack` task. For
1429another example that specifies these types of files, see the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001430":ref:`dev-manual/common-tasks:autotooled package`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001431
1432Another way of specifying source is from an SCM. For Git repositories,
Andrew Geissler9aee5002022-03-30 16:27:02 +00001433you must specify :term:`SRCREV` and you should specify :term:`PV` to include
1434the revision with :term:`SRCPV`. Here is an example from the recipe
1435``meta/recipes-core/musl/gcompat_git.bb``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001436
Andrew Geissler9aee5002022-03-30 16:27:02 +00001437 SRC_URI = "git://git.adelielinux.org/adelie/gcompat.git;protocol=https;branch=current"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001438
Andrew Geissler9aee5002022-03-30 16:27:02 +00001439 PV = "1.0.0+1.1+git${SRCPV}"
1440 SRCREV = "af5a49e489fdc04b9cf02547650d7aeaccd43793"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001441
Andrew Geissler09036742021-06-25 14:25:14 -05001442If your :term:`SRC_URI` statement includes URLs pointing to individual files
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001443fetched from a remote server other than a version control system,
1444BitBake attempts to verify the files against checksums defined in your
1445recipe to ensure they have not been tampered with or otherwise modified
1446since the recipe was written. Two checksums are used:
1447``SRC_URI[md5sum]`` and ``SRC_URI[sha256sum]``.
1448
Andrew Geissler09036742021-06-25 14:25:14 -05001449If your :term:`SRC_URI` variable points to more than a single URL (excluding
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001450SCM URLs), you need to provide the ``md5`` and ``sha256`` checksums for
1451each URL. For these cases, you provide a name for each URL as part of
Andrew Geissler09036742021-06-25 14:25:14 -05001452the :term:`SRC_URI` and then reference that name in the subsequent checksum
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001453statements. Here is an example combining lines from the files
Andrew Geisslerc926e172021-05-07 16:11:35 -05001454``git.inc`` and ``git_2.24.1.bb``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001455
1456 SRC_URI = "${KERNELORG_MIRROR}/software/scm/git/git-${PV}.tar.gz;name=tarball \
1457 ${KERNELORG_MIRROR}/software/scm/git/git-manpages-${PV}.tar.gz;name=manpages"
1458
1459 SRC_URI[tarball.md5sum] = "166bde96adbbc11c8843d4f8f4f9811b"
1460 SRC_URI[tarball.sha256sum] = "ad5334956301c86841eb1e5b1bb20884a6bad89a10a6762c958220c7cf64da02"
1461 SRC_URI[manpages.md5sum] = "31c2272a8979022497ba3d4202df145d"
1462 SRC_URI[manpages.sha256sum] = "9a7ae3a093bea39770eb96ca3e5b40bff7af0b9f6123f089d7821d0e5b8e1230"
1463
1464Proper values for ``md5`` and ``sha256`` checksums might be available
1465with other signatures on the download page for the upstream source (e.g.
1466``md5``, ``sha1``, ``sha256``, ``GPG``, and so forth). Because the
1467OpenEmbedded build system only deals with ``sha256sum`` and ``md5sum``,
1468you should verify all the signatures you find by hand.
1469
Andrew Geissler09036742021-06-25 14:25:14 -05001470If no :term:`SRC_URI` checksums are specified when you attempt to build the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001471recipe, or you provide an incorrect checksum, the build will produce an
1472error for each missing or incorrect checksum. As part of the error
1473message, the build system provides the checksum string corresponding to
1474the fetched file. Once you have the correct checksums, you can copy and
1475paste them into your recipe and then run the build again to continue.
1476
1477.. note::
1478
1479 As mentioned, if the upstream source provides signatures for
1480 verifying the downloaded source code, you should verify those
1481 manually before setting the checksum values in the recipe and
1482 continuing with the build.
1483
1484This final example is a bit more complicated and is from the
1485``meta/recipes-sato/rxvt-unicode/rxvt-unicode_9.20.bb`` recipe. The
Andrew Geissler09036742021-06-25 14:25:14 -05001486example's :term:`SRC_URI` statement identifies multiple files as the source
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001487files for the recipe: a tarball, a patch file, a desktop file, and an
1488icon.
1489::
1490
1491 SRC_URI = "http://dist.schmorp.de/rxvt-unicode/Attic/rxvt-unicode-${PV}.tar.bz2 \
1492 file://xwc.patch \
1493 file://rxvt.desktop \
1494 file://rxvt.png"
1495
1496When you specify local files using the ``file://`` URI protocol, the
1497build system fetches files from the local machine. The path is relative
1498to the :term:`FILESPATH` variable
1499and searches specific directories in a certain order:
1500``${``\ :term:`BP`\ ``}``,
1501``${``\ :term:`BPN`\ ``}``, and
1502``files``. The directories are assumed to be subdirectories of the
1503directory in which the recipe or append file resides. For another
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001504example that specifies these types of files, see the
1505":ref:`dev-manual/common-tasks:single .c file package (hello world!)`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001506
1507The previous example also specifies a patch file. Patch files are files
1508whose names usually end in ``.patch`` or ``.diff`` but can end with
1509compressed suffixes such as ``diff.gz`` and ``patch.bz2``, for example.
1510The build system automatically applies patches as described in the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001511":ref:`dev-manual/common-tasks:patching code`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001512
Andrew Geissler9aee5002022-03-30 16:27:02 +00001513Fetching Code Through Firewalls
1514~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1515
1516Some users are behind firewalls and need to fetch code through a proxy.
1517See the ":doc:`/ref-manual/faq`" chapter for advice.
1518
1519Limiting the Number of Parallel Connections
1520~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1521
1522Some users are behind firewalls or use servers where the number of parallel
1523connections is limited. In such cases, you can limit the number of fetch
1524tasks being run in parallel by adding the following to your ``local.conf``
1525file::
1526
1527 do_fetch[number_threads] = "4"
1528
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001529Unpacking Code
1530--------------
1531
1532During the build, the
1533:ref:`ref-tasks-unpack` task unpacks
1534the source with ``${``\ :term:`S`\ ``}``
1535pointing to where it is unpacked.
1536
1537If you are fetching your source files from an upstream source archived
1538tarball and the tarball's internal structure matches the common
1539convention of a top-level subdirectory named
1540``${``\ :term:`BPN`\ ``}-${``\ :term:`PV`\ ``}``,
Andrew Geissler09036742021-06-25 14:25:14 -05001541then you do not need to set :term:`S`. However, if :term:`SRC_URI` specifies to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001542fetch source from an archive that does not use this convention, or from
Andrew Geissler09036742021-06-25 14:25:14 -05001543an SCM like Git or Subversion, your recipe needs to define :term:`S`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001544
1545If processing your recipe using BitBake successfully unpacks the source
1546files, you need to be sure that the directory pointed to by ``${S}``
1547matches the structure of the source.
1548
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001549Patching Code
1550-------------
1551
1552Sometimes it is necessary to patch code after it has been fetched. Any
Andrew Geissler09036742021-06-25 14:25:14 -05001553files mentioned in :term:`SRC_URI` whose names end in ``.patch`` or
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001554``.diff`` or compressed versions of these suffixes (e.g. ``diff.gz`` are
1555treated as patches. The
1556:ref:`ref-tasks-patch` task
1557automatically applies these patches.
1558
1559The build system should be able to apply patches with the "-p1" option
1560(i.e. one directory level in the path will be stripped off). If your
1561patch needs to have more directory levels stripped off, specify the
Andrew Geissler09036742021-06-25 14:25:14 -05001562number of levels using the "striplevel" option in the :term:`SRC_URI` entry
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001563for the patch. Alternatively, if your patch needs to be applied in a
1564specific subdirectory that is not specified in the patch file, use the
1565"patchdir" option in the entry.
1566
1567As with all local files referenced in
1568:term:`SRC_URI` using ``file://``,
1569you should place patch files in a directory next to the recipe either
1570named the same as the base name of the recipe
1571(:term:`BP` and
1572:term:`BPN`) or "files".
1573
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001574Licensing
1575---------
1576
1577Your recipe needs to have both the
1578:term:`LICENSE` and
1579:term:`LIC_FILES_CHKSUM`
1580variables:
1581
Andrew Geissler09036742021-06-25 14:25:14 -05001582- :term:`LICENSE`: This variable specifies the license for the software.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001583 If you do not know the license under which the software you are
1584 building is distributed, you should go to the source code and look
1585 for that information. Typical files containing this information
Andrew Geissler09036742021-06-25 14:25:14 -05001586 include ``COPYING``, :term:`LICENSE`, and ``README`` files. You could
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001587 also find the information near the top of a source file. For example,
1588 given a piece of software licensed under the GNU General Public
Andrew Geissler09036742021-06-25 14:25:14 -05001589 License version 2, you would set :term:`LICENSE` as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001590
Andrew Geissler9aee5002022-03-30 16:27:02 +00001591 LICENSE = "GPL-2.0-only"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001592
Andrew Geissler09036742021-06-25 14:25:14 -05001593 The licenses you specify within :term:`LICENSE` can have any name as long
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001594 as you do not use spaces, since spaces are used as separators between
1595 license names. For standard licenses, use the names of the files in
Andrew Geissler09036742021-06-25 14:25:14 -05001596 ``meta/files/common-licenses/`` or the :term:`SPDXLICENSEMAP` flag names
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001597 defined in ``meta/conf/licenses.conf``.
1598
Andrew Geissler09036742021-06-25 14:25:14 -05001599- :term:`LIC_FILES_CHKSUM`: The OpenEmbedded build system uses this
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001600 variable to make sure the license text has not changed. If it has,
1601 the build produces an error and it affords you the chance to figure
1602 it out and correct the problem.
1603
1604 You need to specify all applicable licensing files for the software.
1605 At the end of the configuration step, the build process will compare
1606 the checksums of the files to be sure the text has not changed. Any
1607 differences result in an error with the message containing the
1608 current checksum. For more explanation and examples of how to set the
Andrew Geissler09036742021-06-25 14:25:14 -05001609 :term:`LIC_FILES_CHKSUM` variable, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001610 ":ref:`dev-manual/common-tasks:tracking license changes`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001611
1612 To determine the correct checksum string, you can list the
Andrew Geissler09036742021-06-25 14:25:14 -05001613 appropriate files in the :term:`LIC_FILES_CHKSUM` variable with incorrect
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001614 md5 strings, attempt to build the software, and then note the
1615 resulting error messages that will report the correct md5 strings.
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001616 See the ":ref:`dev-manual/common-tasks:fetching code`" section for
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001617 additional information.
1618
Andrew Geisslerc926e172021-05-07 16:11:35 -05001619 Here is an example that assumes the software has a ``COPYING`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001620
1621 LIC_FILES_CHKSUM = "file://COPYING;md5=xxx"
1622
1623 When you try to build the
1624 software, the build system will produce an error and give you the
1625 correct string that you can substitute into the recipe file for a
1626 subsequent build.
1627
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001628Dependencies
1629------------
1630
1631Most software packages have a short list of other packages that they
1632require, which are called dependencies. These dependencies fall into two
1633main categories: build-time dependencies, which are required when the
1634software is built; and runtime dependencies, which are required to be
1635installed on the target in order for the software to run.
1636
1637Within a recipe, you specify build-time dependencies using the
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001638:term:`DEPENDS` variable. Although there are nuances,
Andrew Geissler09036742021-06-25 14:25:14 -05001639items specified in :term:`DEPENDS` should be names of other
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001640recipes. It is important that you specify all build-time dependencies
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001641explicitly.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001642
1643Another consideration is that configure scripts might automatically
1644check for optional dependencies and enable corresponding functionality
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001645if those dependencies are found. If you wish to make a recipe that is
1646more generally useful (e.g. publish the recipe in a layer for others to
1647use), instead of hard-disabling the functionality, you can use the
1648:term:`PACKAGECONFIG` variable to allow functionality and the
1649corresponding dependencies to be enabled and disabled easily by other
1650users of the recipe.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001651
1652Similar to build-time dependencies, you specify runtime dependencies
1653through a variable -
1654:term:`RDEPENDS`, which is
1655package-specific. All variables that are package-specific need to have
1656the name of the package added to the end as an override. Since the main
1657package for a recipe has the same name as the recipe, and the recipe's
1658name can be found through the
1659``${``\ :term:`PN`\ ``}`` variable, then
1660you specify the dependencies for the main package by setting
Patrick Williams0ca19cc2021-08-16 14:03:13 -05001661``RDEPENDS:${PN}``. If the package were named ``${PN}-tools``, then you
1662would set ``RDEPENDS:${PN}-tools``, and so forth.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001663
1664Some runtime dependencies will be set automatically at packaging time.
1665These dependencies include any shared library dependencies (i.e. if a
1666package "example" contains "libexample" and another package "mypackage"
1667contains a binary that links to "libexample" then the OpenEmbedded build
1668system will automatically add a runtime dependency to "mypackage" on
1669"example"). See the
Andrew Geissler09209ee2020-12-13 08:44:15 -06001670":ref:`overview-manual/concepts:automatically added runtime dependencies`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001671section in the Yocto Project Overview and Concepts Manual for further
1672details.
1673
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001674Configuring the Recipe
1675----------------------
1676
1677Most software provides some means of setting build-time configuration
1678options before compilation. Typically, setting these options is
1679accomplished by running a configure script with options, or by modifying
1680a build configuration file.
1681
1682.. note::
1683
1684 As of Yocto Project Release 1.7, some of the core recipes that
1685 package binary configuration scripts now disable the scripts due to
1686 the scripts previously requiring error-prone path substitution. The
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001687 OpenEmbedded build system uses ``pkg-config`` now, which is much more
1688 robust. You can find a list of the ``*-config`` scripts that are disabled
1689 in the ":ref:`migration-1.7-binary-configuration-scripts-disabled`" section
1690 in the Yocto Project Reference Manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001691
1692A major part of build-time configuration is about checking for
1693build-time dependencies and possibly enabling optional functionality as
1694a result. You need to specify any build-time dependencies for the
1695software you are building in your recipe's
1696:term:`DEPENDS` value, in terms of
1697other recipes that satisfy those dependencies. You can often find
1698build-time or runtime dependencies described in the software's
1699documentation.
1700
1701The following list provides configuration items of note based on how
1702your software is built:
1703
1704- *Autotools:* If your source files have a ``configure.ac`` file, then
1705 your software is built using Autotools. If this is the case, you just
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001706 need to modify the configuration.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001707
1708 When using Autotools, your recipe needs to inherit the
1709 :ref:`autotools <ref-classes-autotools>` class
1710 and your recipe does not have to contain a
1711 :ref:`ref-tasks-configure` task.
1712 However, you might still want to make some adjustments. For example,
1713 you can set
1714 :term:`EXTRA_OECONF` or
1715 :term:`PACKAGECONFIG_CONFARGS`
1716 to pass any needed configure options that are specific to the recipe.
1717
1718- *CMake:* If your source files have a ``CMakeLists.txt`` file, then
1719 your software is built using CMake. If this is the case, you just
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001720 need to modify the configuration.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001721
1722 When you use CMake, your recipe needs to inherit the
1723 :ref:`cmake <ref-classes-cmake>` class and your
1724 recipe does not have to contain a
1725 :ref:`ref-tasks-configure` task.
1726 You can make some adjustments by setting
1727 :term:`EXTRA_OECMAKE` to
1728 pass any needed configure options that are specific to the recipe.
1729
1730 .. note::
1731
1732 If you need to install one or more custom CMake toolchain files
1733 that are supplied by the application you are building, install the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001734 files to ``${D}${datadir}/cmake/Modules`` during ``do_install``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001735
1736- *Other:* If your source files do not have a ``configure.ac`` or
1737 ``CMakeLists.txt`` file, then your software is built using some
1738 method other than Autotools or CMake. If this is the case, you
1739 normally need to provide a
1740 :ref:`ref-tasks-configure` task
1741 in your recipe unless, of course, there is nothing to configure.
1742
1743 Even if your software is not being built by Autotools or CMake, you
1744 still might not need to deal with any configuration issues. You need
1745 to determine if configuration is even a required step. You might need
1746 to modify a Makefile or some configuration file used for the build to
1747 specify necessary build options. Or, perhaps you might need to run a
1748 provided, custom configure script with the appropriate options.
1749
1750 For the case involving a custom configure script, you would run
1751 ``./configure --help`` and look for the options you need to set.
1752
1753Once configuration succeeds, it is always good practice to look at the
1754``log.do_configure`` file to ensure that the appropriate options have
1755been enabled and no additional build-time dependencies need to be added
Andrew Geissler09036742021-06-25 14:25:14 -05001756to :term:`DEPENDS`. For example, if the configure script reports that it
1757found something not mentioned in :term:`DEPENDS`, or that it did not find
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001758something that it needed for some desired optional functionality, then
Andrew Geissler09036742021-06-25 14:25:14 -05001759you would need to add those to :term:`DEPENDS`. Looking at the log might
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001760also reveal items being checked for, enabled, or both that you do not
Andrew Geissler09036742021-06-25 14:25:14 -05001761want, or items not being found that are in :term:`DEPENDS`, in which case
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001762you would need to look at passing extra options to the configure script
1763as needed. For reference information on configure options specific to
1764the software you are building, you can consult the output of the
1765``./configure --help`` command within ``${S}`` or consult the software's
1766upstream documentation.
1767
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001768Using Headers to Interface with Devices
1769---------------------------------------
1770
1771If your recipe builds an application that needs to communicate with some
1772device or needs an API into a custom kernel, you will need to provide
1773appropriate header files. Under no circumstances should you ever modify
1774the existing
1775``meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc`` file.
1776These headers are used to build ``libc`` and must not be compromised
1777with custom or machine-specific header information. If you customize
1778``libc`` through modified headers all other applications that use
1779``libc`` thus become affected.
1780
1781.. note::
1782
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001783 Never copy and customize the ``libc`` header file (i.e.
1784 ``meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc``).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001785
1786The correct way to interface to a device or custom kernel is to use a
1787separate package that provides the additional headers for the driver or
1788other unique interfaces. When doing so, your application also becomes
1789responsible for creating a dependency on that specific provider.
1790
1791Consider the following:
1792
1793- Never modify ``linux-libc-headers.inc``. Consider that file to be
1794 part of the ``libc`` system, and not something you use to access the
1795 kernel directly. You should access ``libc`` through specific ``libc``
1796 calls.
1797
1798- Applications that must talk directly to devices should either provide
1799 necessary headers themselves, or establish a dependency on a special
1800 headers package that is specific to that driver.
1801
1802For example, suppose you want to modify an existing header that adds I/O
1803control or network support. If the modifications are used by a small
1804number programs, providing a unique version of a header is easy and has
1805little impact. When doing so, bear in mind the guidelines in the
1806previous list.
1807
1808.. note::
1809
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001810 If for some reason your changes need to modify the behavior of the ``libc``,
1811 and subsequently all other applications on the system, use a ``.bbappend``
1812 to modify the ``linux-kernel-headers.inc`` file. However, take care to not
1813 make the changes machine specific.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001814
1815Consider a case where your kernel is older and you need an older
1816``libc`` ABI. The headers installed by your recipe should still be a
1817standard mainline kernel, not your own custom one.
1818
1819When you use custom kernel headers you need to get them from
1820:term:`STAGING_KERNEL_DIR`,
1821which is the directory with kernel headers that are required to build
Andrew Geisslerc926e172021-05-07 16:11:35 -05001822out-of-tree modules. Your recipe will also need the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001823
1824 do_configure[depends] += "virtual/kernel:do_shared_workdir"
1825
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001826Compilation
1827-----------
1828
1829During a build, the ``do_compile`` task happens after source is fetched,
1830unpacked, and configured. If the recipe passes through ``do_compile``
1831successfully, nothing needs to be done.
1832
1833However, if the compile step fails, you need to diagnose the failure.
1834Here are some common issues that cause failures.
1835
1836.. note::
1837
1838 For cases where improper paths are detected for configuration files
1839 or for when libraries/headers cannot be found, be sure you are using
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001840 the more robust ``pkg-config``. See the note in section
Andrew Geissler09209ee2020-12-13 08:44:15 -06001841 ":ref:`dev-manual/common-tasks:Configuring the Recipe`" for additional information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001842
1843- *Parallel build failures:* These failures manifest themselves as
1844 intermittent errors, or errors reporting that a file or directory
1845 that should be created by some other part of the build process could
1846 not be found. This type of failure can occur even if, upon
1847 inspection, the file or directory does exist after the build has
1848 failed, because that part of the build process happened in the wrong
1849 order.
1850
1851 To fix the problem, you need to either satisfy the missing dependency
1852 in the Makefile or whatever script produced the Makefile, or (as a
Andrew Geisslerc926e172021-05-07 16:11:35 -05001853 workaround) set :term:`PARALLEL_MAKE` to an empty string::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001854
1855 PARALLEL_MAKE = ""
1856
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001857 For information on parallel Makefile issues, see the
1858 ":ref:`dev-manual/common-tasks:debugging parallel make races`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001859
1860- *Improper host path usage:* This failure applies to recipes building
1861 for the target or ``nativesdk`` only. The failure occurs when the
1862 compilation process uses improper headers, libraries, or other files
1863 from the host system when cross-compiling for the target.
1864
1865 To fix the problem, examine the ``log.do_compile`` file to identify
1866 the host paths being used (e.g. ``/usr/include``, ``/usr/lib``, and
1867 so forth) and then either add configure options, apply a patch, or do
1868 both.
1869
1870- *Failure to find required libraries/headers:* If a build-time
1871 dependency is missing because it has not been declared in
1872 :term:`DEPENDS`, or because the
1873 dependency exists but the path used by the build process to find the
1874 file is incorrect and the configure step did not detect it, the
1875 compilation process could fail. For either of these failures, the
1876 compilation process notes that files could not be found. In these
1877 cases, you need to go back and add additional options to the
1878 configure script as well as possibly add additional build-time
Andrew Geissler09036742021-06-25 14:25:14 -05001879 dependencies to :term:`DEPENDS`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001880
1881 Occasionally, it is necessary to apply a patch to the source to
1882 ensure the correct paths are used. If you need to specify paths to
1883 find files staged into the sysroot from other recipes, use the
1884 variables that the OpenEmbedded build system provides (e.g.
Andrew Geissler09036742021-06-25 14:25:14 -05001885 :term:`STAGING_BINDIR`, :term:`STAGING_INCDIR`, :term:`STAGING_DATADIR`, and so
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001886 forth).
1887
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001888Installing
1889----------
1890
1891During ``do_install``, the task copies the built files along with their
1892hierarchy to locations that would mirror their locations on the target
1893device. The installation process copies files from the
1894``${``\ :term:`S`\ ``}``,
1895``${``\ :term:`B`\ ``}``, and
1896``${``\ :term:`WORKDIR`\ ``}``
1897directories to the ``${``\ :term:`D`\ ``}``
1898directory to create the structure as it should appear on the target
1899system.
1900
1901How your software is built affects what you must do to be sure your
1902software is installed correctly. The following list describes what you
1903must do for installation depending on the type of build system used by
1904the software being built:
1905
1906- *Autotools and CMake:* If the software your recipe is building uses
1907 Autotools or CMake, the OpenEmbedded build system understands how to
1908 install the software. Consequently, you do not have to have a
1909 ``do_install`` task as part of your recipe. You just need to make
1910 sure the install portion of the build completes with no issues.
1911 However, if you wish to install additional files not already being
1912 installed by ``make install``, you should do this using a
Patrick Williams0ca19cc2021-08-16 14:03:13 -05001913 ``do_install:append`` function using the install command as described
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001914 in the "Manual" bulleted item later in this list.
1915
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001916- *Other (using* ``make install``\ *)*: You need to define a ``do_install``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001917 function in your recipe. The function should call
1918 ``oe_runmake install`` and will likely need to pass in the
1919 destination directory as well. How you pass that path is dependent on
1920 how the ``Makefile`` being run is written (e.g. ``DESTDIR=${D}``,
1921 ``PREFIX=${D}``, ``INSTALLROOT=${D}``, and so forth).
1922
1923 For an example recipe using ``make install``, see the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05001924 ":ref:`dev-manual/common-tasks:makefile-based package`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001925
1926- *Manual:* You need to define a ``do_install`` function in your
1927 recipe. The function must first use ``install -d`` to create the
1928 directories under
1929 ``${``\ :term:`D`\ ``}``. Once the
1930 directories exist, your function can use ``install`` to manually
1931 install the built software into the directories.
1932
1933 You can find more information on ``install`` at
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001934 https://www.gnu.org/software/coreutils/manual/html_node/install-invocation.html.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001935
1936For the scenarios that do not use Autotools or CMake, you need to track
1937the installation and diagnose and fix any issues until everything
1938installs correctly. You need to look in the default location of
1939``${D}``, which is ``${WORKDIR}/image``, to be sure your files have been
1940installed correctly.
1941
1942.. note::
1943
1944 - During the installation process, you might need to modify some of
1945 the installed files to suit the target layout. For example, you
1946 might need to replace hard-coded paths in an initscript with
1947 values of variables provided by the build system, such as
1948 replacing ``/usr/bin/`` with ``${bindir}``. If you do perform such
1949 modifications during ``do_install``, be sure to modify the
1950 destination file after copying rather than before copying.
1951 Modifying after copying ensures that the build system can
1952 re-execute ``do_install`` if needed.
1953
1954 - ``oe_runmake install``, which can be run directly or can be run
1955 indirectly by the
1956 :ref:`autotools <ref-classes-autotools>` and
1957 :ref:`cmake <ref-classes-cmake>` classes,
1958 runs ``make install`` in parallel. Sometimes, a Makefile can have
1959 missing dependencies between targets that can result in race
1960 conditions. If you experience intermittent failures during
1961 ``do_install``, you might be able to work around them by disabling
Andrew Geisslerc926e172021-05-07 16:11:35 -05001962 parallel Makefile installs by adding the following to the recipe::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001963
1964 PARALLEL_MAKEINST = ""
1965
1966 See :term:`PARALLEL_MAKEINST` for additional information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001967
1968 - If you need to install one or more custom CMake toolchain files
1969 that are supplied by the application you are building, install the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001970 files to ``${D}${datadir}/cmake/Modules`` during
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001971 :ref:`ref-tasks-install`.
1972
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001973Enabling System Services
1974------------------------
1975
1976If you want to install a service, which is a process that usually starts
1977on boot and runs in the background, then you must include some
1978additional definitions in your recipe.
1979
1980If you are adding services and the service initialization script or the
1981service file itself is not installed, you must provide for that
Patrick Williams0ca19cc2021-08-16 14:03:13 -05001982installation in your recipe using a ``do_install:append`` function. If
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001983your recipe already has a ``do_install`` function, update the function
Patrick Williams0ca19cc2021-08-16 14:03:13 -05001984near its end rather than adding an additional ``do_install:append``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001985function.
1986
1987When you create the installation for your services, you need to
1988accomplish what is normally done by ``make install``. In other words,
1989make sure your installation arranges the output similar to how it is
1990arranged on the target system.
1991
1992The OpenEmbedded build system provides support for starting services two
1993different ways:
1994
1995- *SysVinit:* SysVinit is a system and service manager that manages the
1996 init system used to control the very basic functions of your system.
1997 The init program is the first program started by the Linux kernel
1998 when the system boots. Init then controls the startup, running and
1999 shutdown of all other programs.
2000
2001 To enable a service using SysVinit, your recipe needs to inherit the
2002 :ref:`update-rc.d <ref-classes-update-rc.d>`
2003 class. The class helps facilitate safely installing the package on
2004 the target.
2005
2006 You will need to set the
2007 :term:`INITSCRIPT_PACKAGES`,
2008 :term:`INITSCRIPT_NAME`,
2009 and
2010 :term:`INITSCRIPT_PARAMS`
2011 variables within your recipe.
2012
2013- *systemd:* System Management Daemon (systemd) was designed to replace
2014 SysVinit and to provide enhanced management of services. For more
2015 information on systemd, see the systemd homepage at
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002016 https://freedesktop.org/wiki/Software/systemd/.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002017
2018 To enable a service using systemd, your recipe needs to inherit the
2019 :ref:`systemd <ref-classes-systemd>` class. See
2020 the ``systemd.bbclass`` file located in your :term:`Source Directory`
2021 section for
2022 more information.
2023
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002024Packaging
2025---------
2026
2027Successful packaging is a combination of automated processes performed
2028by the OpenEmbedded build system and some specific steps you need to
2029take. The following list describes the process:
2030
2031- *Splitting Files*: The ``do_package`` task splits the files produced
2032 by the recipe into logical components. Even software that produces a
2033 single binary might still have debug symbols, documentation, and
2034 other logical components that should be split out. The ``do_package``
2035 task ensures that files are split up and packaged correctly.
2036
2037- *Running QA Checks*: The
2038 :ref:`insane <ref-classes-insane>` class adds a
2039 step to the package generation process so that output quality
2040 assurance checks are generated by the OpenEmbedded build system. This
2041 step performs a range of checks to be sure the build's output is free
2042 of common problems that show up during runtime. For information on
2043 these checks, see the
2044 :ref:`insane <ref-classes-insane>` class and
Andrew Geissler09209ee2020-12-13 08:44:15 -06002045 the ":ref:`ref-manual/qa-checks:qa error and warning messages`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002046 chapter in the Yocto Project Reference Manual.
2047
2048- *Hand-Checking Your Packages*: After you build your software, you
2049 need to be sure your packages are correct. Examine the
2050 ``${``\ :term:`WORKDIR`\ ``}/packages-split``
2051 directory and make sure files are where you expect them to be. If you
2052 discover problems, you can set
2053 :term:`PACKAGES`,
2054 :term:`FILES`,
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002055 ``do_install(:append)``, and so forth as needed.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002056
2057- *Splitting an Application into Multiple Packages*: If you need to
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05002058 split an application into several packages, see the
2059 ":ref:`dev-manual/common-tasks:splitting an application into multiple packages`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002060 section for an example.
2061
2062- *Installing a Post-Installation Script*: For an example showing how
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05002063 to install a post-installation script, see the
2064 ":ref:`dev-manual/common-tasks:post-installation scripts`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002065
2066- *Marking Package Architecture*: Depending on what your recipe is
2067 building and how it is configured, it might be important to mark the
2068 packages produced as being specific to a particular machine, or to
2069 mark them as not being specific to a particular machine or
2070 architecture at all.
2071
2072 By default, packages apply to any machine with the same architecture
2073 as the target machine. When a recipe produces packages that are
2074 machine-specific (e.g. the
2075 :term:`MACHINE` value is passed
2076 into the configure script or a patch is applied only for a particular
2077 machine), you should mark them as such by adding the following to the
Andrew Geisslerc926e172021-05-07 16:11:35 -05002078 recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002079
2080 PACKAGE_ARCH = "${MACHINE_ARCH}"
2081
2082 On the other hand, if the recipe produces packages that do not
2083 contain anything specific to the target machine or architecture at
2084 all (e.g. recipes that simply package script files or configuration
2085 files), you should use the
2086 :ref:`allarch <ref-classes-allarch>` class to
Andrew Geisslerc926e172021-05-07 16:11:35 -05002087 do this for you by adding this to your recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002088
2089 inherit allarch
2090
2091 Ensuring that the package architecture is correct is not critical
2092 while you are doing the first few builds of your recipe. However, it
2093 is important in order to ensure that your recipe rebuilds (or does
2094 not rebuild) appropriately in response to changes in configuration,
2095 and to ensure that you get the appropriate packages installed on the
2096 target machine, particularly if you run separate builds for more than
2097 one target machine.
2098
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002099Sharing Files Between Recipes
2100-----------------------------
2101
2102Recipes often need to use files provided by other recipes on the build
2103host. For example, an application linking to a common library needs
2104access to the library itself and its associated headers. The way this
2105access is accomplished is by populating a sysroot with files. Each
2106recipe has two sysroots in its work directory, one for target files
2107(``recipe-sysroot``) and one for files that are native to the build host
2108(``recipe-sysroot-native``).
2109
2110.. note::
2111
2112 You could find the term "staging" used within the Yocto project
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002113 regarding files populating sysroots (e.g. the :term:`STAGING_DIR`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002114 variable).
2115
2116Recipes should never populate the sysroot directly (i.e. write files
2117into sysroot). Instead, files should be installed into standard
2118locations during the
2119:ref:`ref-tasks-install` task within
2120the ``${``\ :term:`D`\ ``}`` directory. The
2121reason for this limitation is that almost all files that populate the
2122sysroot are cataloged in manifests in order to ensure the files can be
2123removed later when a recipe is either modified or removed. Thus, the
2124sysroot is able to remain free from stale files.
2125
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05002126A subset of the files installed by the :ref:`ref-tasks-install` task are
2127used by the :ref:`ref-tasks-populate_sysroot` task as defined by the the
2128:term:`SYSROOT_DIRS` variable to automatically populate the sysroot. It
2129is possible to modify the list of directories that populate the sysroot.
2130The following example shows how you could add the ``/opt`` directory to
Andrew Geisslerc926e172021-05-07 16:11:35 -05002131the list of directories within a recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002132
2133 SYSROOT_DIRS += "/opt"
2134
Andrew Geisslerd1e89492021-02-12 15:35:20 -06002135.. note::
2136
2137 The `/sysroot-only` is to be used by recipes that generate artifacts
2138 that are not included in the target filesystem, allowing them to share
Andrew Geissler09036742021-06-25 14:25:14 -05002139 these artifacts without needing to use the :term:`DEPLOY_DIR`.
Andrew Geisslerd1e89492021-02-12 15:35:20 -06002140
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05002141For a more complete description of the :ref:`ref-tasks-populate_sysroot`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002142task and its associated functions, see the
2143:ref:`staging <ref-classes-staging>` class.
2144
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002145Using Virtual Providers
2146-----------------------
2147
2148Prior to a build, if you know that several different recipes provide the
2149same functionality, you can use a virtual provider (i.e. ``virtual/*``)
2150as a placeholder for the actual provider. The actual provider is
2151determined at build-time.
2152
2153A common scenario where a virtual provider is used would be for the
2154kernel recipe. Suppose you have three kernel recipes whose
2155:term:`PN` values map to ``kernel-big``,
2156``kernel-mid``, and ``kernel-small``. Furthermore, each of these recipes
2157in some way uses a :term:`PROVIDES`
2158statement that essentially identifies itself as being able to provide
2159``virtual/kernel``. Here is one way through the
Andrew Geisslerc926e172021-05-07 16:11:35 -05002160:ref:`kernel <ref-classes-kernel>` class::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002161
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00002162 PROVIDES += "virtual/kernel"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002163
Andrew Geissler595f6302022-01-24 19:11:47 +00002164Any recipe that inherits the :ref:`kernel <ref-classes-kernel>` class is
Andrew Geissler09036742021-06-25 14:25:14 -05002165going to utilize a :term:`PROVIDES` statement that identifies that recipe as
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002166being able to provide the ``virtual/kernel`` item.
2167
2168Now comes the time to actually build an image and you need a kernel
2169recipe, but which one? You can configure your build to call out the
Andrew Geissler09209ee2020-12-13 08:44:15 -06002170kernel recipe you want by using the :term:`PREFERRED_PROVIDER` variable. As
2171an example, consider the :yocto_git:`x86-base.inc
Andrew Geisslerd159c7f2021-09-02 21:05:58 -05002172</poky/tree/meta/conf/machine/include/x86/x86-base.inc>` include file, which is a
Andrew Geissler09209ee2020-12-13 08:44:15 -06002173machine (i.e. :term:`MACHINE`) configuration file. This include file is the
2174reason all x86-based machines use the ``linux-yocto`` kernel. Here are the
Andrew Geisslerc926e172021-05-07 16:11:35 -05002175relevant lines from the include file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002176
2177 PREFERRED_PROVIDER_virtual/kernel ??= "linux-yocto"
2178 PREFERRED_VERSION_linux-yocto ??= "4.15%"
2179
2180When you use a virtual provider, you do not have to "hard code" a recipe
2181name as a build dependency. You can use the
2182:term:`DEPENDS` variable to state the
Andrew Geisslerc926e172021-05-07 16:11:35 -05002183build is dependent on ``virtual/kernel`` for example::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002184
2185 DEPENDS = "virtual/kernel"
2186
2187During the build, the OpenEmbedded build system picks
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002188the correct recipe needed for the ``virtual/kernel`` dependency based on
Andrew Geissler09036742021-06-25 14:25:14 -05002189the :term:`PREFERRED_PROVIDER` variable. If you want to use the small kernel
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002190mentioned at the beginning of this section, configure your build as
Andrew Geisslerc926e172021-05-07 16:11:35 -05002191follows::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002192
2193 PREFERRED_PROVIDER_virtual/kernel ??= "kernel-small"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002194
2195.. note::
2196
Andrew Geissler09036742021-06-25 14:25:14 -05002197 Any recipe that :term:`PROVIDES` a ``virtual/*`` item that is ultimately not
2198 selected through :term:`PREFERRED_PROVIDER` does not get built. Preventing these
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002199 recipes from building is usually the desired behavior since this mechanism's
2200 purpose is to select between mutually exclusive alternative providers.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002201
2202The following lists specific examples of virtual providers:
2203
2204- ``virtual/kernel``: Provides the name of the kernel recipe to use
2205 when building a kernel image.
2206
2207- ``virtual/bootloader``: Provides the name of the bootloader to use
2208 when building an image.
2209
2210- ``virtual/libgbm``: Provides ``gbm.pc``.
2211
2212- ``virtual/egl``: Provides ``egl.pc`` and possibly ``wayland-egl.pc``.
2213
2214- ``virtual/libgl``: Provides ``gl.pc`` (i.e. libGL).
2215
2216- ``virtual/libgles1``: Provides ``glesv1_cm.pc`` (i.e. libGLESv1_CM).
2217
2218- ``virtual/libgles2``: Provides ``glesv2.pc`` (i.e. libGLESv2).
2219
2220.. note::
2221
2222 Virtual providers only apply to build time dependencies specified with
2223 :term:`PROVIDES` and :term:`DEPENDS`. They do not apply to runtime
2224 dependencies specified with :term:`RPROVIDES` and :term:`RDEPENDS`.
2225
2226Properly Versioning Pre-Release Recipes
2227---------------------------------------
2228
2229Sometimes the name of a recipe can lead to versioning problems when the
2230recipe is upgraded to a final release. For example, consider the
2231``irssi_0.8.16-rc1.bb`` recipe file in the list of example recipes in
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05002232the ":ref:`dev-manual/common-tasks:storing and naming the recipe`" section.
2233This recipe is at a release candidate stage (i.e. "rc1"). When the recipe is
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002234released, the recipe filename becomes ``irssi_0.8.16.bb``. The version
2235change from ``0.8.16-rc1`` to ``0.8.16`` is seen as a decrease by the
2236build system and package managers, so the resulting packages will not
2237correctly trigger an upgrade.
2238
2239In order to ensure the versions compare properly, the recommended
2240convention is to set :term:`PV` within the
2241recipe to "previous_version+current_version". You can use an additional
2242variable so that you can use the current version elsewhere. Here is an
Andrew Geisslerc926e172021-05-07 16:11:35 -05002243example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002244
2245 REALPV = "0.8.16-rc1"
2246 PV = "0.8.15+${REALPV}"
2247
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002248Post-Installation Scripts
2249-------------------------
2250
2251Post-installation scripts run immediately after installing a package on
2252the target or during image creation when a package is included in an
2253image. To add a post-installation script to a package, add a
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002254``pkg_postinst:``\ `PACKAGENAME`\ ``()`` function to the recipe file
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002255(``.bb``) and replace `PACKAGENAME` with the name of the package you want
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002256to attach to the ``postinst`` script. To apply the post-installation
2257script to the main package for the recipe, which is usually what is
2258required, specify
2259``${``\ :term:`PN`\ ``}`` in place of
2260PACKAGENAME.
2261
Andrew Geisslerc926e172021-05-07 16:11:35 -05002262A post-installation function has the following structure::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002263
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002264 pkg_postinst:PACKAGENAME() {
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002265 # Commands to carry out
2266 }
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002267
2268The script defined in the post-installation function is called when the
2269root filesystem is created. If the script succeeds, the package is
2270marked as installed.
2271
2272.. note::
2273
2274 Any RPM post-installation script that runs on the target should
2275 return a 0 exit code. RPM does not allow non-zero exit codes for
2276 these scripts, and the RPM package manager will cause the package to
2277 fail installation on the target.
2278
2279Sometimes it is necessary for the execution of a post-installation
2280script to be delayed until the first boot. For example, the script might
2281need to be executed on the device itself. To delay script execution
2282until boot time, you must explicitly mark post installs to defer to the
2283target. You can use ``pkg_postinst_ontarget()`` or call
2284``postinst_intercept delay_to_first_boot`` from ``pkg_postinst()``. Any
2285failure of a ``pkg_postinst()`` script (including exit 1) triggers an
2286error during the
2287:ref:`ref-tasks-rootfs` task.
2288
2289If you have recipes that use ``pkg_postinst`` function and they require
2290the use of non-standard native tools that have dependencies during
Andrew Geissler595f6302022-01-24 19:11:47 +00002291root filesystem construction, you need to use the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002292:term:`PACKAGE_WRITE_DEPS`
2293variable in your recipe to list these tools. If you do not use this
2294variable, the tools might be missing and execution of the
2295post-installation script is deferred until first boot. Deferring the
Andrew Geissler595f6302022-01-24 19:11:47 +00002296script to the first boot is undesirable and impossible for read-only
2297root filesystems.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002298
2299.. note::
2300
William A. Kennington IIIac69b482021-06-02 12:28:27 -07002301 There is equivalent support for pre-install, pre-uninstall, and post-uninstall
2302 scripts by way of ``pkg_preinst``, ``pkg_prerm``, and ``pkg_postrm``,
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002303 respectively. These scrips work in exactly the same way as does
2304 ``pkg_postinst`` with the exception that they run at different times. Also,
2305 because of when they run, they are not applicable to being run at image
2306 creation time like ``pkg_postinst``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002307
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002308Testing
2309-------
2310
2311The final step for completing your recipe is to be sure that the
2312software you built runs correctly. To accomplish runtime testing, add
2313the build's output packages to your image and test them on the target.
2314
2315For information on how to customize your image by adding specific
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05002316packages, see ":ref:`dev-manual/common-tasks:customizing images`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002317
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002318Examples
2319--------
2320
2321To help summarize how to write a recipe, this section provides some
2322examples given various scenarios:
2323
2324- Recipes that use local files
2325
2326- Using an Autotooled package
2327
2328- Using a Makefile-based package
2329
2330- Splitting an application into multiple packages
2331
2332- Adding binaries to an image
2333
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002334Single .c File Package (Hello World!)
2335~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2336
2337Building an application from a single file that is stored locally (e.g.
2338under ``files``) requires a recipe that has the file listed in the
Andrew Geissler09036742021-06-25 14:25:14 -05002339:term:`SRC_URI` variable. Additionally, you need to manually write the
2340``do_compile`` and ``do_install`` tasks. The :term:`S` variable defines the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002341directory containing the source code, which is set to
Andrew Geissler615f2f12022-07-15 14:00:58 -05002342:term:`WORKDIR` in this case --- the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002343directory BitBake uses for the build.
2344::
2345
2346 SUMMARY = "Simple helloworld application"
2347 SECTION = "examples"
2348 LICENSE = "MIT"
2349 LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
2350
2351 SRC_URI = "file://helloworld.c"
2352
2353 S = "${WORKDIR}"
2354
2355 do_compile() {
Andrew Geisslerd1e89492021-02-12 15:35:20 -06002356 ${CC} ${LDFLAGS} helloworld.c -o helloworld
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002357 }
2358
2359 do_install() {
2360 install -d ${D}${bindir}
2361 install -m 0755 helloworld ${D}${bindir}
2362 }
2363
2364By default, the ``helloworld``, ``helloworld-dbg``, and
2365``helloworld-dev`` packages are built. For information on how to
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05002366customize the packaging process, see the
2367":ref:`dev-manual/common-tasks:splitting an application into multiple packages`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002368section.
2369
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002370Autotooled Package
2371~~~~~~~~~~~~~~~~~~
2372
2373Applications that use Autotools such as ``autoconf`` and ``automake``
Andrew Geissler09036742021-06-25 14:25:14 -05002374require a recipe that has a source archive listed in :term:`SRC_URI` and
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002375also inherit the
2376:ref:`autotools <ref-classes-autotools>` class,
2377which contains the definitions of all the steps needed to build an
2378Autotool-based application. The result of the build is automatically
2379packaged. And, if the application uses NLS for localization, packages
2380with local information are generated (one package per language).
2381Following is one example: (``hello_2.3.bb``)
2382::
2383
2384 SUMMARY = "GNU Helloworld application"
2385 SECTION = "examples"
Andrew Geissler9aee5002022-03-30 16:27:02 +00002386 LICENSE = "GPL-2.0-or-later"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002387 LIC_FILES_CHKSUM = "file://COPYING;md5=751419260aa954499f7abaabaa882bbe"
2388
2389 SRC_URI = "${GNU_MIRROR}/hello/hello-${PV}.tar.gz"
2390
2391 inherit autotools gettext
2392
Andrew Geissler09036742021-06-25 14:25:14 -05002393The variable :term:`LIC_FILES_CHKSUM` is used to track source license
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002394changes as described in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06002395":ref:`dev-manual/common-tasks:tracking license changes`" section in
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002396the Yocto Project Overview and Concepts Manual. You can quickly create
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002397Autotool-based recipes in a manner similar to the previous example.
2398
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002399Makefile-Based Package
2400~~~~~~~~~~~~~~~~~~~~~~
2401
2402Applications that use GNU ``make`` also require a recipe that has the
Andrew Geissler09036742021-06-25 14:25:14 -05002403source archive listed in :term:`SRC_URI`. You do not need to add a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002404``do_compile`` step since by default BitBake starts the ``make`` command
2405to compile the application. If you need additional ``make`` options, you
2406should store them in the
2407:term:`EXTRA_OEMAKE` or
2408:term:`PACKAGECONFIG_CONFARGS`
2409variables. BitBake passes these options into the GNU ``make``
2410invocation. Note that a ``do_install`` task is still required.
2411Otherwise, BitBake runs an empty ``do_install`` task by default.
2412
2413Some applications might require extra parameters to be passed to the
2414compiler. For example, the application might need an additional header
Andrew Geissler09036742021-06-25 14:25:14 -05002415path. You can accomplish this by adding to the :term:`CFLAGS` variable. The
Andrew Geisslerc926e172021-05-07 16:11:35 -05002416following example shows this::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002417
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002418 CFLAGS:prepend = "-I ${S}/include "
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002419
Andrew Geissler9aee5002022-03-30 16:27:02 +00002420In the following example, ``lz4`` is a makefile-based package::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002421
Andrew Geissler9aee5002022-03-30 16:27:02 +00002422 SUMMARY = "Extremely Fast Compression algorithm"
2423 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."
2424 HOMEPAGE = "https://github.com/lz4/lz4"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002425
Andrew Geissler9aee5002022-03-30 16:27:02 +00002426 LICENSE = "BSD-2-Clause | GPL-2.0-only"
2427 LIC_FILES_CHKSUM = "file://lib/LICENSE;md5=ebc2ea4814a64de7708f1571904b32cc \
2428 file://programs/COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263 \
2429 file://LICENSE;md5=d57c0d21cb917fb4e0af2454aa48b956 \
2430 "
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002431
Andrew Geissler9aee5002022-03-30 16:27:02 +00002432 PE = "1"
2433
2434 SRCREV = "d44371841a2f1728a3f36839fd4b7e872d0927d3"
2435
2436 SRC_URI = "git://github.com/lz4/lz4.git;branch=release;protocol=https \
2437 file://CVE-2021-3520.patch \
2438 "
2439 UPSTREAM_CHECK_GITTAGREGEX = "v(?P<pver>.*)"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002440
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002441 S = "${WORKDIR}/git"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002442
Andrew Geissler9aee5002022-03-30 16:27:02 +00002443 # Fixed in r118, which is larger than the current version.
2444 CVE_CHECK_IGNORE += "CVE-2014-4715"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002445
Andrew Geissler9aee5002022-03-30 16:27:02 +00002446 EXTRA_OEMAKE = "PREFIX=${prefix} CC='${CC}' CFLAGS='${CFLAGS}' DESTDIR=${D} LIBDIR=${libdir} INCLUDEDIR=${includedir} BUILD_STATIC=no"
2447
2448 do_install() {
2449 oe_runmake install
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002450 }
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002451
Andrew Geissler9aee5002022-03-30 16:27:02 +00002452 BBCLASSEXTEND = "native nativesdk"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002453
2454Splitting an Application into Multiple Packages
2455~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2456
Andrew Geissler09036742021-06-25 14:25:14 -05002457You can use the variables :term:`PACKAGES` and :term:`FILES` to split an
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002458application into multiple packages.
2459
2460Following is an example that uses the ``libxpm`` recipe. By default,
2461this recipe generates a single package that contains the library along
2462with a few binaries. You can modify the recipe to split the binaries
Andrew Geisslerc926e172021-05-07 16:11:35 -05002463into separate packages::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002464
2465 require xorg-lib-common.inc
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002466
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002467 SUMMARY = "Xpm: X Pixmap extension library"
Andrew Geissler5199d832021-09-24 16:47:35 -05002468 LICENSE = "MIT"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002469 LIC_FILES_CHKSUM = "file://COPYING;md5=51f4270b012ecd4ab1a164f5f4ed6cf7"
2470 DEPENDS += "libxext libsm libxt"
2471 PE = "1"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002472
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002473 XORG_PN = "libXpm"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002474
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002475 PACKAGES =+ "sxpm cxpm"
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002476 FILES:cxpm = "${bindir}/cxpm"
2477 FILES:sxpm = "${bindir}/sxpm"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002478
2479In the previous example, we want to ship the ``sxpm`` and ``cxpm``
2480binaries in separate packages. Since ``bindir`` would be packaged into
Andrew Geissler09036742021-06-25 14:25:14 -05002481the main :term:`PN` package by default, we prepend the :term:`PACKAGES` variable
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002482so additional package names are added to the start of list. This results
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002483in the extra ``FILES:*`` variables then containing information that
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002484define which files and directories go into which packages. Files
2485included by earlier packages are skipped by latter packages. Thus, the
Andrew Geissler09036742021-06-25 14:25:14 -05002486main :term:`PN` package does not include the above listed files.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002487
2488Packaging Externally Produced Binaries
2489~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2490
2491Sometimes, you need to add pre-compiled binaries to an image. For
William A. Kennington IIIac69b482021-06-02 12:28:27 -07002492example, suppose that there are binaries for proprietary code,
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002493created by a particular division of a company. Your part of the company
2494needs to use those binaries as part of an image that you are building
2495using the OpenEmbedded build system. Since you only have the binaries
2496and not the source code, you cannot use a typical recipe that expects to
2497fetch the source specified in
2498:term:`SRC_URI` and then compile it.
2499
2500One method is to package the binaries and then install them as part of
2501the image. Generally, it is not a good idea to package binaries since,
2502among other things, it can hinder the ability to reproduce builds and
2503could lead to compatibility problems with ABI in the future. However,
2504sometimes you have no choice.
2505
2506The easiest solution is to create a recipe that uses the
2507:ref:`bin_package <ref-classes-bin-package>` class
2508and to be sure that you are using default locations for build artifacts.
Andrew Geissler595f6302022-01-24 19:11:47 +00002509In most cases, the :ref:`bin_package <ref-classes-bin-package>` class handles "skipping" the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002510configure and compile steps as well as sets things up to grab packages
2511from the appropriate area. In particular, this class sets ``noexec`` on
2512both the :ref:`ref-tasks-configure`
2513and :ref:`ref-tasks-compile` tasks,
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002514sets ``FILES:${PN}`` to "/" so that it picks up all files, and sets up a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002515:ref:`ref-tasks-install` task, which
2516effectively copies all files from ``${S}`` to ``${D}``. The
Andrew Geissler595f6302022-01-24 19:11:47 +00002517:ref:`bin_package <ref-classes-bin-package>` class works well when the files extracted into ``${S}``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002518are already laid out in the way they should be laid out on the target.
2519For more information on these variables, see the
2520:term:`FILES`,
2521:term:`PN`,
2522:term:`S`, and
2523:term:`D` variables in the Yocto Project
2524Reference Manual's variable glossary.
2525
2526.. note::
2527
2528 - Using :term:`DEPENDS` is a good
2529 idea even for components distributed in binary form, and is often
2530 necessary for shared libraries. For a shared library, listing the
Andrew Geissler09036742021-06-25 14:25:14 -05002531 library dependencies in :term:`DEPENDS` makes sure that the libraries
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002532 are available in the staging sysroot when other recipes link
2533 against the library, which might be necessary for successful
2534 linking.
2535
Andrew Geissler09036742021-06-25 14:25:14 -05002536 - Using :term:`DEPENDS` also allows runtime dependencies between
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002537 packages to be added automatically. See the
Andrew Geissler09209ee2020-12-13 08:44:15 -06002538 ":ref:`overview-manual/concepts:automatically added runtime dependencies`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002539 section in the Yocto Project Overview and Concepts Manual for more
2540 information.
2541
Andrew Geissler595f6302022-01-24 19:11:47 +00002542If 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 -05002543doing the following:
2544
2545- Create a recipe where the
2546 :ref:`ref-tasks-configure` and
2547 :ref:`ref-tasks-compile` tasks do
2548 nothing: It is usually sufficient to just not define these tasks in
2549 the recipe, because the default implementations do nothing unless a
2550 Makefile is found in
2551 ``${``\ :term:`S`\ ``}``.
2552
2553 If ``${S}`` might contain a Makefile, or if you inherit some class
2554 that replaces ``do_configure`` and ``do_compile`` with custom
2555 versions, then you can use the
2556 ``[``\ :ref:`noexec <bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ``]``
Andrew Geisslerc926e172021-05-07 16:11:35 -05002557 flag to turn the tasks into no-ops, as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002558
2559 do_configure[noexec] = "1"
2560 do_compile[noexec] = "1"
2561
2562 Unlike
2563 :ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:deleting a task`,
2564 using the flag preserves the dependency chain from the
2565 :ref:`ref-tasks-fetch`,
2566 :ref:`ref-tasks-unpack`, and
2567 :ref:`ref-tasks-patch` tasks to the
2568 :ref:`ref-tasks-install` task.
2569
2570- Make sure your ``do_install`` task installs the binaries
2571 appropriately.
2572
2573- Ensure that you set up :term:`FILES`
2574 (usually
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002575 ``FILES:${``\ :term:`PN`\ ``}``) to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002576 point to the files you have installed, which of course depends on
2577 where you have installed them and whether those files are in
2578 different locations than the defaults.
2579
2580Following Recipe Style Guidelines
2581---------------------------------
2582
2583When writing recipes, it is good to conform to existing style
Andrew Geisslerd1e89492021-02-12 15:35:20 -06002584guidelines. The :oe_wiki:`OpenEmbedded Styleguide </Styleguide>` wiki page
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002585provides rough guidelines for preferred recipe style.
2586
2587It is common for existing recipes to deviate a bit from this style.
2588However, aiming for at least a consistent style is a good idea. Some
2589practices, such as omitting spaces around ``=`` operators in assignments
2590or ordering recipe components in an erratic way, are widely seen as poor
2591style.
2592
2593Recipe Syntax
2594-------------
2595
2596Understanding recipe file syntax is important for writing recipes. The
2597following list overviews the basic items that make up a BitBake recipe
2598file. For more complete BitBake syntax descriptions, see the
Andrew Geissler615f2f12022-07-15 14:00:58 -05002599":doc:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002600chapter of the BitBake User Manual.
2601
2602- *Variable Assignments and Manipulations:* Variable assignments allow
2603 a value to be assigned to a variable. The assignment can be static
2604 text or might include the contents of other variables. In addition to
2605 the assignment, appending and prepending operations are also
2606 supported.
2607
2608 The following example shows some of the ways you can use variables in
Andrew Geisslerc926e172021-05-07 16:11:35 -05002609 recipes::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002610
2611 S = "${WORKDIR}/postfix-${PV}"
2612 CFLAGS += "-DNO_ASM"
Andrew Geissler87f5cff2022-09-30 13:13:31 -05002613 CFLAGS:append = " --enable-important-feature"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002614
2615- *Functions:* Functions provide a series of actions to be performed.
2616 You usually use functions to override the default implementation of a
2617 task function or to complement a default function (i.e. append or
2618 prepend to an existing function). Standard functions use ``sh`` shell
2619 syntax, although access to OpenEmbedded variables and internal
2620 methods are also available.
2621
William A. Kennington IIIac69b482021-06-02 12:28:27 -07002622 Here is an example function from the ``sed`` recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002623
2624 do_install () {
2625 autotools_do_install
2626 install -d ${D}${base_bindir}
2627 mv ${D}${bindir}/sed ${D}${base_bindir}/sed
2628 rmdir ${D}${bindir}/
2629 }
2630
2631 It is
2632 also possible to implement new functions that are called between
2633 existing tasks as long as the new functions are not replacing or
2634 complementing the default functions. You can implement functions in
2635 Python instead of shell. Both of these options are not seen in the
2636 majority of recipes.
2637
2638- *Keywords:* BitBake recipes use only a few keywords. You use keywords
2639 to include common functions (``inherit``), load parts of a recipe
2640 from other files (``include`` and ``require``) and export variables
2641 to the environment (``export``).
2642
Andrew Geisslerc926e172021-05-07 16:11:35 -05002643 The following example shows the use of some of these keywords::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002644
2645 export POSTCONF = "${STAGING_BINDIR}/postconf"
2646 inherit autoconf
2647 require otherfile.inc
2648
2649- *Comments (#):* Any lines that begin with the hash character (``#``)
Andrew Geisslerc926e172021-05-07 16:11:35 -05002650 are treated as comment lines and are ignored::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002651
2652 # This is a comment
2653
2654This next list summarizes the most important and most commonly used
2655parts of the recipe syntax. For more information on these parts of the
2656syntax, you can reference the
Andrew Geissler615f2f12022-07-15 14:00:58 -05002657":doc:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata`" chapter
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002658in the BitBake User Manual.
2659
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002660- *Line Continuation (\\):* Use the backward slash (``\``) character to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002661 split a statement over multiple lines. Place the slash character at
Andrew Geisslerc926e172021-05-07 16:11:35 -05002662 the end of the line that is to be continued on the next line::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002663
2664 VAR = "A really long \
2665 line"
2666
2667 .. note::
2668
2669 You cannot have any characters including spaces or tabs after the
2670 slash character.
2671
2672- *Using Variables (${VARNAME}):* Use the ``${VARNAME}`` syntax to
Andrew Geisslerc926e172021-05-07 16:11:35 -05002673 access the contents of a variable::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002674
2675 SRC_URI = "${SOURCEFORGE_MIRROR}/libpng/zlib-${PV}.tar.gz"
2676
2677 .. note::
2678
2679 It is important to understand that the value of a variable
2680 expressed in this form does not get substituted automatically. The
2681 expansion of these expressions happens on-demand later (e.g.
2682 usually when a function that makes reference to the variable
2683 executes). This behavior ensures that the values are most
2684 appropriate for the context in which they are finally used. On the
2685 rare occasion that you do need the variable expression to be
2686 expanded immediately, you can use the
2687 :=
2688 operator instead of
2689 =
2690 when you make the assignment, but this is not generally needed.
2691
2692- *Quote All Assignments ("value"):* Use double quotes around values in
Andrew Geisslerc926e172021-05-07 16:11:35 -05002693 all variable assignments (e.g. ``"value"``). Following is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002694
2695 VAR1 = "${OTHERVAR}"
2696 VAR2 = "The version is ${PV}"
2697
2698- *Conditional Assignment (?=):* Conditional assignment is used to
2699 assign a value to a variable, but only when the variable is currently
2700 unset. Use the question mark followed by the equal sign (``?=``) to
2701 make a "soft" assignment used for conditional assignment. Typically,
2702 "soft" assignments are used in the ``local.conf`` file for variables
2703 that are allowed to come through from the external environment.
2704
2705 Here is an example where ``VAR1`` is set to "New value" if it is
2706 currently empty. However, if ``VAR1`` has already been set, it
Andrew Geisslerc926e172021-05-07 16:11:35 -05002707 remains unchanged::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002708
2709 VAR1 ?= "New value"
2710
Andrew Geisslerc926e172021-05-07 16:11:35 -05002711 In this next example, ``VAR1`` is left with the value "Original value"::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002712
2713 VAR1 = "Original value"
2714 VAR1 ?= "New value"
2715
2716- *Appending (+=):* Use the plus character followed by the equals sign
2717 (``+=``) to append values to existing variables.
2718
2719 .. note::
2720
2721 This operator adds a space between the existing content of the
2722 variable and the new content.
2723
Andrew Geisslerc926e172021-05-07 16:11:35 -05002724 Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002725
2726 SRC_URI += "file://fix-makefile.patch"
2727
2728- *Prepending (=+):* Use the equals sign followed by the plus character
2729 (``=+``) to prepend values to existing variables.
2730
2731 .. note::
2732
2733 This operator adds a space between the new content and the
2734 existing content of the variable.
2735
Andrew Geisslerc926e172021-05-07 16:11:35 -05002736 Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002737
2738 VAR =+ "Starts"
2739
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002740- *Appending (:append):* Use the ``:append`` operator to append values
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002741 to existing variables. This operator does not add any additional
2742 space. Also, the operator is applied after all the ``+=``, and ``=+``
2743 operators have been applied and after all ``=`` assignments have
Andrew Geissler87f5cff2022-09-30 13:13:31 -05002744 occurred. This means that if ``:append`` is used in a recipe, it can
2745 only be overridden by another layer using the special ``:remove``
2746 operator, which in turn will prevent further layers from adding it back.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002747
2748 The following example shows the space being explicitly added to the
2749 start to ensure the appended value is not merged with the existing
Andrew Geisslerc926e172021-05-07 16:11:35 -05002750 value::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002751
Andrew Geissler87f5cff2022-09-30 13:13:31 -05002752 CFLAGS:append = " --enable-important-feature"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002753
2754 You can also use
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002755 the ``:append`` operator with overrides, which results in the actions
Andrew Geisslerc926e172021-05-07 16:11:35 -05002756 only being performed for the specified target or machine::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002757
Andrew Geissler87f5cff2022-09-30 13:13:31 -05002758 CFLAGS:append:sh4 = " --enable-important-sh4-specific-feature"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002759
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002760- *Prepending (:prepend):* Use the ``:prepend`` operator to prepend
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002761 values to existing variables. This operator does not add any
2762 additional space. Also, the operator is applied after all the ``+=``,
2763 and ``=+`` operators have been applied and after all ``=``
2764 assignments have occurred.
2765
2766 The following example shows the space being explicitly added to the
2767 end to ensure the prepended value is not merged with the existing
Andrew Geisslerc926e172021-05-07 16:11:35 -05002768 value::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002769
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002770 CFLAGS:prepend = "-I${S}/myincludes "
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002771
2772 You can also use the
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002773 ``:prepend`` operator with overrides, which results in the actions
Andrew Geisslerc926e172021-05-07 16:11:35 -05002774 only being performed for the specified target or machine::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002775
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002776 CFLAGS:prepend:sh4 = "-I${S}/myincludes "
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002777
2778- *Overrides:* You can use overrides to set a value conditionally,
2779 typically based on how the recipe is being built. For example, to set
2780 the :term:`KBRANCH` variable's
2781 value to "standard/base" for any target
2782 :term:`MACHINE`, except for
2783 qemuarm where it should be set to "standard/arm-versatile-926ejs",
Andrew Geisslerc926e172021-05-07 16:11:35 -05002784 you would do the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002785
2786 KBRANCH = "standard/base"
Patrick Williams0ca19cc2021-08-16 14:03:13 -05002787 KBRANCH:qemuarm = "standard/arm-versatile-926ejs"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002788
2789 Overrides are also used to separate
2790 alternate values of a variable in other situations. For example, when
2791 setting variables such as
2792 :term:`FILES` and
2793 :term:`RDEPENDS` that are
2794 specific to individual packages produced by a recipe, you should
2795 always use an override that specifies the name of the package.
2796
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002797- *Indentation:* Use spaces for indentation rather than tabs. For
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002798 shell functions, both currently work. However, it is a policy
2799 decision of the Yocto Project to use tabs in shell functions. Realize
2800 that some layers have a policy to use spaces for all indentation.
2801
2802- *Using Python for Complex Operations:* For more advanced processing,
2803 it is possible to use Python code during variable assignments (e.g.
2804 search and replacement on a variable).
2805
2806 You indicate Python code using the ``${@python_code}`` syntax for the
Andrew Geisslerc926e172021-05-07 16:11:35 -05002807 variable assignment::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002808
2809 SRC_URI = "ftp://ftp.info-zip.org/pub/infozip/src/zip${@d.getVar('PV',1).replace('.', '')}.tgz
2810
2811- *Shell Function Syntax:* Write shell functions as if you were writing
2812 a shell script when you describe a list of actions to take. You
2813 should ensure that your script works with a generic ``sh`` and that
2814 it does not require any ``bash`` or other shell-specific
2815 functionality. The same considerations apply to various system
2816 utilities (e.g. ``sed``, ``grep``, ``awk``, and so forth) that you
2817 might wish to use. If in doubt, you should check with multiple
Andrew Geissler615f2f12022-07-15 14:00:58 -05002818 implementations --- including those from BusyBox.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002819
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002820Adding a New Machine
2821====================
2822
2823Adding a new machine to the Yocto Project is a straightforward process.
2824This section describes how to add machines that are similar to those
2825that the Yocto Project already supports.
2826
2827.. note::
2828
2829 Although well within the capabilities of the Yocto Project, adding a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002830 totally new architecture might require changes to ``gcc``/``glibc``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002831 and to the site information, which is beyond the scope of this
2832 manual.
2833
2834For a complete example that shows how to add a new machine, see the
2835":ref:`bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script`"
2836section in the Yocto Project Board Support Package (BSP) Developer's
2837Guide.
2838
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002839Adding the Machine Configuration File
2840-------------------------------------
2841
2842To add a new machine, you need to add a new machine configuration file
2843to the layer's ``conf/machine`` directory. This configuration file
2844provides details about the device you are adding.
2845
2846The OpenEmbedded build system uses the root name of the machine
2847configuration file to reference the new machine. For example, given a
2848machine configuration file named ``crownbay.conf``, the build system
2849recognizes the machine as "crownbay".
2850
2851The most important variables you must set in your machine configuration
2852file or include from a lower-level configuration file are as follows:
2853
Andrew Geissler5f350902021-07-23 13:09:54 -04002854- :term:`TARGET_ARCH` (e.g. "arm")
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002855
2856- ``PREFERRED_PROVIDER_virtual/kernel``
2857
Andrew Geissler09036742021-06-25 14:25:14 -05002858- :term:`MACHINE_FEATURES` (e.g. "apm screen wifi")
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002859
2860You might also need these variables:
2861
Andrew Geissler5f350902021-07-23 13:09:54 -04002862- :term:`SERIAL_CONSOLES` (e.g. "115200;ttyS0 115200;ttyS1")
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002863
Andrew Geissler5f350902021-07-23 13:09:54 -04002864- :term:`KERNEL_IMAGETYPE` (e.g. "zImage")
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002865
Andrew Geissler09036742021-06-25 14:25:14 -05002866- :term:`IMAGE_FSTYPES` (e.g. "tar.gz jffs2")
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002867
2868You can find full details on these variables in the reference section.
2869You can leverage existing machine ``.conf`` files from
2870``meta-yocto-bsp/conf/machine/``.
2871
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002872Adding a Kernel for the Machine
2873-------------------------------
2874
2875The OpenEmbedded build system needs to be able to build a kernel for the
2876machine. You need to either create a new kernel recipe for this machine,
2877or extend an existing kernel recipe. You can find several kernel recipe
2878examples in the Source Directory at ``meta/recipes-kernel/linux`` that
2879you can use as references.
2880
2881If you are creating a new kernel recipe, normal recipe-writing rules
Andrew Geissler09036742021-06-25 14:25:14 -05002882apply for setting up a :term:`SRC_URI`. Thus, you need to specify any
2883necessary patches and set :term:`S` to point at the source code. You need to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002884create a ``do_configure`` task that configures the unpacked kernel with
2885a ``defconfig`` file. You can do this by using a ``make defconfig``
2886command or, more commonly, by copying in a suitable ``defconfig`` file
2887and then running ``make oldconfig``. By making use of ``inherit kernel``
2888and potentially some of the ``linux-*.inc`` files, most other
2889functionality is centralized and the defaults of the class normally work
2890well.
2891
2892If you are extending an existing kernel recipe, it is usually a matter
2893of adding a suitable ``defconfig`` file. The file needs to be added into
2894a location similar to ``defconfig`` files used for other machines in a
2895given kernel recipe. A possible way to do this is by listing the file in
Andrew Geissler09036742021-06-25 14:25:14 -05002896the :term:`SRC_URI` and adding the machine to the expression in
2897:term:`COMPATIBLE_MACHINE`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002898
2899 COMPATIBLE_MACHINE = '(qemux86|qemumips)'
2900
2901For more information on ``defconfig`` files, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06002902":ref:`kernel-dev/common:changing the configuration`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002903section in the Yocto Project Linux Kernel Development Manual.
2904
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002905Adding a Formfactor Configuration File
2906--------------------------------------
2907
2908A formfactor configuration file provides information about the target
2909hardware for which the image is being built and information that the
2910build system cannot obtain from other sources such as the kernel. Some
2911examples of information contained in a formfactor configuration file
2912include framebuffer orientation, whether or not the system has a
2913keyboard, the positioning of the keyboard in relation to the screen, and
2914the screen resolution.
2915
2916The build system uses reasonable defaults in most cases. However, if
2917customization is necessary, you need to create a ``machconfig`` file in
2918the ``meta/recipes-bsp/formfactor/files`` directory. This directory
2919contains directories for specific machines such as ``qemuarm`` and
2920``qemux86``. For information about the settings available and the
2921defaults, see the ``meta/recipes-bsp/formfactor/files/config`` file
2922found in the same area.
2923
Andrew Geisslerc926e172021-05-07 16:11:35 -05002924Following is an example for "qemuarm" machine::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002925
2926 HAVE_TOUCHSCREEN=1
2927 HAVE_KEYBOARD=1
2928 DISPLAY_CAN_ROTATE=0
2929 DISPLAY_ORIENTATION=0
2930 #DISPLAY_WIDTH_PIXELS=640
2931 #DISPLAY_HEIGHT_PIXELS=480
2932 #DISPLAY_BPP=16
2933 DISPLAY_DPI=150
2934 DISPLAY_SUBPIXEL_ORDER=vrgb
2935
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002936Upgrading Recipes
2937=================
2938
2939Over time, upstream developers publish new versions for software built
2940by layer recipes. It is recommended to keep recipes up-to-date with
2941upstream version releases.
2942
William A. Kennington IIIac69b482021-06-02 12:28:27 -07002943While there are several methods to upgrade a recipe, you might
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002944consider checking on the upgrade status of a recipe first. You can do so
2945using the ``devtool check-upgrade-status`` command. See the
2946":ref:`devtool-checking-on-the-upgrade-status-of-a-recipe`"
2947section in the Yocto Project Reference Manual for more information.
2948
2949The remainder of this section describes three ways you can upgrade a
2950recipe. You can use the Automated Upgrade Helper (AUH) to set up
2951automatic version upgrades. Alternatively, you can use
2952``devtool upgrade`` to set up semi-automatic version upgrades. Finally,
2953you can manually upgrade a recipe by editing the recipe itself.
2954
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002955Using the Auto Upgrade Helper (AUH)
2956-----------------------------------
2957
2958The AUH utility works in conjunction with the OpenEmbedded build system
2959in order to automatically generate upgrades for recipes based on new
2960versions being published upstream. Use AUH when you want to create a
2961service that performs the upgrades automatically and optionally sends
2962you an email with the results.
2963
2964AUH allows you to update several recipes with a single use. You can also
2965optionally perform build and integration tests using images with the
2966results saved to your hard drive and emails of results optionally sent
2967to recipe maintainers. Finally, AUH creates Git commits with appropriate
2968commit messages in the layer's tree for the changes made to recipes.
2969
2970.. note::
2971
William A. Kennington IIIac69b482021-06-02 12:28:27 -07002972 In some conditions, you should not use AUH to upgrade recipes
2973 and should instead use either ``devtool upgrade`` or upgrade your
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002974 recipes manually:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002975
2976 - When AUH cannot complete the upgrade sequence. This situation
2977 usually results because custom patches carried by the recipe
2978 cannot be automatically rebased to the new version. In this case,
2979 ``devtool upgrade`` allows you to manually resolve conflicts.
2980
2981 - When for any reason you want fuller control over the upgrade
2982 process. For example, when you want special arrangements for
2983 testing.
2984
2985The following steps describe how to set up the AUH utility:
2986
29871. *Be Sure the Development Host is Set Up:* You need to be sure that
2988 your development host is set up to use the Yocto Project. For
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002989 information on how to set up your host, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06002990 ":ref:`dev-manual/start:Preparing the Build Host`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002991
29922. *Make Sure Git is Configured:* The AUH utility requires Git to be
2993 configured because AUH uses Git to save upgrades. Thus, you must have
2994 Git user and email configured. The following command shows your
Andrew Geisslerc926e172021-05-07 16:11:35 -05002995 configurations::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002996
2997 $ git config --list
2998
2999 If you do not have the user and
Andrew Geisslerc926e172021-05-07 16:11:35 -05003000 email configured, you can use the following commands to do so::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003001
3002 $ git config --global user.name some_name
3003 $ git config --global user.email username@domain.com
3004
30053. *Clone the AUH Repository:* To use AUH, you must clone the repository
3006 onto your development host. The following command uses Git to create
Andrew Geisslerc926e172021-05-07 16:11:35 -05003007 a local copy of the repository on your system::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003008
3009 $ git clone git://git.yoctoproject.org/auto-upgrade-helper
3010 Cloning into 'auto-upgrade-helper'... remote: Counting objects: 768, done.
3011 remote: Compressing objects: 100% (300/300), done.
3012 remote: Total 768 (delta 499), reused 703 (delta 434)
3013 Receiving objects: 100% (768/768), 191.47 KiB | 98.00 KiB/s, done.
3014 Resolving deltas: 100% (499/499), done.
3015 Checking connectivity... done.
3016
3017 AUH is not part of the :term:`OpenEmbedded-Core (OE-Core)` or
3018 :term:`Poky` repositories.
3019
30204. *Create a Dedicated Build Directory:* Run the
3021 :ref:`structure-core-script`
3022 script to create a fresh build directory that you use exclusively for
Andrew Geisslerc926e172021-05-07 16:11:35 -05003023 running the AUH utility::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003024
Andrew Geissler95ac1b82021-03-31 14:34:31 -05003025 $ cd poky
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003026 $ source oe-init-build-env your_AUH_build_directory
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003027
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003028 Re-using an existing build directory and its configurations is not
3029 recommended as existing settings could cause AUH to fail or behave
3030 undesirably.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003031
30325. *Make Configurations in Your Local Configuration File:* Several
William A. Kennington IIIac69b482021-06-02 12:28:27 -07003033 settings are needed in the ``local.conf`` file in the build
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003034 directory you just created for AUH. Make these following
3035 configurations:
3036
3037 - If you want to enable :ref:`Build
Andrew Geissler09209ee2020-12-13 08:44:15 -06003038 History <dev-manual/common-tasks:maintaining build output quality>`,
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003039 which is optional, you need the following lines in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05003040 ``conf/local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003041
3042 INHERIT =+ "buildhistory"
3043 BUILDHISTORY_COMMIT = "1"
3044
3045 With this configuration and a successful
3046 upgrade, a build history "diff" file appears in the
3047 ``upgrade-helper/work/recipe/buildhistory-diff.txt`` file found in
3048 your build directory.
3049
3050 - If you want to enable testing through the
3051 :ref:`testimage <ref-classes-testimage*>`
3052 class, which is optional, you need to have the following set in
Andrew Geisslerc926e172021-05-07 16:11:35 -05003053 your ``conf/local.conf`` file::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003054
3055 INHERIT += "testimage"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003056
3057 .. note::
3058
3059 If your distro does not enable by default ptest, which Poky
Andrew Geisslerc926e172021-05-07 16:11:35 -05003060 does, you need the following in your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003061
Patrick Williams0ca19cc2021-08-16 14:03:13 -05003062 DISTRO_FEATURES:append = " ptest"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003063
3064
30656. *Optionally Start a vncserver:* If you are running in a server
Andrew Geisslerc926e172021-05-07 16:11:35 -05003066 without an X11 session, you need to start a vncserver::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003067
3068 $ vncserver :1
3069 $ export DISPLAY=:1
3070
30717. *Create and Edit an AUH Configuration File:* You need to have the
3072 ``upgrade-helper/upgrade-helper.conf`` configuration file in your
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003073 build directory. You can find a sample configuration file in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003074 :yocto_git:`AUH source repository </auto-upgrade-helper/tree/>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003075
3076 Read through the sample file and make configurations as needed. For
3077 example, if you enabled build history in your ``local.conf`` as
3078 described earlier, you must enable it in ``upgrade-helper.conf``.
3079
3080 Also, if you are using the default ``maintainers.inc`` file supplied
3081 with Poky and located in ``meta-yocto`` and you do not set a
3082 "maintainers_whitelist" or "global_maintainer_override" in the
3083 ``upgrade-helper.conf`` configuration, and you specify "-e all" on
3084 the AUH command-line, the utility automatically sends out emails to
3085 all the default maintainers. Please avoid this.
3086
3087This next set of examples describes how to use the AUH:
3088
3089- *Upgrading a Specific Recipe:* To upgrade a specific recipe, use the
Andrew Geisslerc926e172021-05-07 16:11:35 -05003090 following form::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003091
3092 $ upgrade-helper.py recipe_name
3093
Andrew Geisslerc926e172021-05-07 16:11:35 -05003094 For example, this command upgrades the ``xmodmap`` recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003095
3096 $ upgrade-helper.py xmodmap
3097
3098- *Upgrading a Specific Recipe to a Particular Version:* To upgrade a
Andrew Geisslerc926e172021-05-07 16:11:35 -05003099 specific recipe to a particular version, use the following form::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003100
3101 $ upgrade-helper.py recipe_name -t version
3102
Andrew Geisslerc926e172021-05-07 16:11:35 -05003103 For example, this command upgrades the ``xmodmap`` recipe to version 1.2.3::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003104
3105 $ upgrade-helper.py xmodmap -t 1.2.3
3106
3107- *Upgrading all Recipes to the Latest Versions and Suppressing Email
3108 Notifications:* To upgrade all recipes to their most recent versions
Andrew Geisslerc926e172021-05-07 16:11:35 -05003109 and suppress the email notifications, use the following command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003110
3111 $ upgrade-helper.py all
3112
3113- *Upgrading all Recipes to the Latest Versions and Send Email
3114 Notifications:* To upgrade all recipes to their most recent versions
3115 and send email messages to maintainers for each attempted recipe as
Andrew Geisslerc926e172021-05-07 16:11:35 -05003116 well as a status email, use the following command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003117
3118 $ upgrade-helper.py -e all
3119
3120Once you have run the AUH utility, you can find the results in the AUH
Andrew Geisslerc926e172021-05-07 16:11:35 -05003121build directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003122
3123 ${BUILDDIR}/upgrade-helper/timestamp
3124
3125The AUH utility
3126also creates recipe update commits from successful upgrade attempts in
3127the layer tree.
3128
3129You can easily set up to run the AUH utility on a regular basis by using
3130a cron job. See the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003131:yocto_git:`weeklyjob.sh </auto-upgrade-helper/tree/weeklyjob.sh>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003132file distributed with the utility for an example.
3133
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003134Using ``devtool upgrade``
3135-------------------------
3136
3137As mentioned earlier, an alternative method for upgrading recipes to
3138newer versions is to use
Andrew Geissler09209ee2020-12-13 08:44:15 -06003139:doc:`devtool upgrade </ref-manual/devtool-reference>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003140You can read about ``devtool upgrade`` in general in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003141":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 -05003142section in the Yocto Project Application Development and the Extensible
3143Software Development Kit (eSDK) Manual.
3144
3145To see all the command-line options available with ``devtool upgrade``,
Andrew Geisslerc926e172021-05-07 16:11:35 -05003146use the following help command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003147
3148 $ devtool upgrade -h
3149
3150If you want to find out what version a recipe is currently at upstream
3151without any attempt to upgrade your local version of the recipe, you can
Andrew Geisslerc926e172021-05-07 16:11:35 -05003152use the following command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003153
3154 $ devtool latest-version recipe_name
3155
3156As mentioned in the previous section describing AUH, ``devtool upgrade``
3157works in a less-automated manner than AUH. Specifically,
3158``devtool upgrade`` only works on a single recipe that you name on the
3159command line, cannot perform build and integration testing using images,
3160and does not automatically generate commits for changes in the source
3161tree. Despite all these "limitations", ``devtool upgrade`` updates the
3162recipe file to the new upstream version and attempts to rebase custom
3163patches contained by the recipe as needed.
3164
3165.. note::
3166
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003167 AUH uses much of ``devtool upgrade`` behind the scenes making AUH somewhat
3168 of a "wrapper" application for ``devtool upgrade``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003169
3170A typical scenario involves having used Git to clone an upstream
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003171repository that you use during build operations. Because you have built the
3172recipe in the past, the layer is likely added to your
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003173configuration already. If for some reason, the layer is not added, you
3174could add it easily using the
3175":ref:`bitbake-layers <bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script>`"
3176script. For example, suppose you use the ``nano.bb`` recipe from the
3177``meta-oe`` layer in the ``meta-openembedded`` repository. For this
Andrew Geisslerc926e172021-05-07 16:11:35 -05003178example, assume that the layer has been cloned into following area::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003179
3180 /home/scottrif/meta-openembedded
3181
3182The following command from your
3183:term:`Build Directory` adds the layer to
Andrew Geisslerc926e172021-05-07 16:11:35 -05003184your build configuration (i.e. ``${BUILDDIR}/conf/bblayers.conf``)::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003185
3186 $ bitbake-layers add-layer /home/scottrif/meta-openembedded/meta-oe
3187 NOTE: Starting bitbake server...
3188 Parsing recipes: 100% |##########################################| Time: 0:00:55
3189 Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
3190 Removing 12 recipes from the x86_64 sysroot: 100% |##############| Time: 0:00:00
3191 Removing 1 recipes from the x86_64_i586 sysroot: 100% |##########| Time: 0:00:00
3192 Removing 5 recipes from the i586 sysroot: 100% |#################| Time: 0:00:00
3193 Removing 5 recipes from the qemux86 sysroot: 100% |##############| Time: 0:00:00
3194
3195For this example, assume that the ``nano.bb`` recipe that
3196is upstream has a 2.9.3 version number. However, the version in the
3197local repository is 2.7.4. The following command from your build
3198directory automatically upgrades the recipe for you:
3199
3200.. note::
3201
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003202 Using the ``-V`` option is not necessary. Omitting the version number causes
3203 ``devtool upgrade`` to upgrade the recipe to the most recent version.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003204
3205::
3206
3207 $ devtool upgrade nano -V 2.9.3
3208 NOTE: Starting bitbake server...
3209 NOTE: Creating workspace layer in /home/scottrif/poky/build/workspace
3210 Parsing recipes: 100% |##########################################| Time: 0:00:46
3211 Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
3212 NOTE: Extracting current version source...
3213 NOTE: Resolving any missing task queue dependencies
3214 .
3215 .
3216 .
3217 NOTE: Executing SetScene Tasks
3218 NOTE: Executing RunQueue Tasks
3219 NOTE: Tasks Summary: Attempted 74 tasks of which 72 didn't need to be rerun and all succeeded.
3220 Adding changed files: 100% |#####################################| Time: 0:00:00
3221 NOTE: Upgraded source extracted to /home/scottrif/poky/build/workspace/sources/nano
3222 NOTE: New recipe is /home/scottrif/poky/build/workspace/recipes/nano/nano_2.9.3.bb
3223
3224Continuing with this example, you can use ``devtool build`` to build the
Andrew Geisslerc926e172021-05-07 16:11:35 -05003225newly upgraded recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003226
3227 $ devtool build nano
3228 NOTE: Starting bitbake server...
3229 Loading cache: 100% |################################################################################################| Time: 0:00:01
3230 Loaded 2040 entries from dependency cache.
3231 Parsing recipes: 100% |##############################################################################################| Time: 0:00:00
3232 Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
3233 NOTE: Resolving any missing task queue dependencies
3234 .
3235 .
3236 .
3237 NOTE: Executing SetScene Tasks
3238 NOTE: Executing RunQueue Tasks
3239 NOTE: nano: compiling from external source tree /home/scottrif/poky/build/workspace/sources/nano
3240 NOTE: Tasks Summary: Attempted 520 tasks of which 304 didn't need to be rerun and all succeeded.
3241
William A. Kennington IIIac69b482021-06-02 12:28:27 -07003242Within the ``devtool upgrade`` workflow, you can
3243deploy and test your rebuilt software. For this example,
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003244however, running ``devtool finish`` cleans up the workspace once the
3245source in your workspace is clean. This usually means using Git to stage
3246and submit commits for the changes generated by the upgrade process.
3247
3248Once the tree is clean, you can clean things up in this example with the
3249following command from the ``${BUILDDIR}/workspace/sources/nano``
Andrew Geisslerc926e172021-05-07 16:11:35 -05003250directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003251
3252 $ devtool finish nano meta-oe
3253 NOTE: Starting bitbake server...
3254 Loading cache: 100% |################################################################################################| Time: 0:00:00
3255 Loaded 2040 entries from dependency cache.
3256 Parsing recipes: 100% |##############################################################################################| Time: 0:00:01
3257 Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
3258 NOTE: Adding new patch 0001-nano.bb-Stuff-I-changed-when-upgrading-nano.bb.patch
3259 NOTE: Updating recipe nano_2.9.3.bb
3260 NOTE: Removing file /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano/nano_2.7.4.bb
3261 NOTE: Moving recipe file to /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano
3262 NOTE: Leaving source tree /home/scottrif/poky/build/workspace/sources/nano as-is; if you no longer need it then please delete it manually
3263
3264
3265Using the ``devtool finish`` command cleans up the workspace and creates a patch
3266file based on your commits. The tool puts all patch files back into the
3267source directory in a sub-directory named ``nano`` in this case.
3268
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003269Manually Upgrading a Recipe
3270---------------------------
3271
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003272If for some reason you choose not to upgrade recipes using
Andrew Geissler09209ee2020-12-13 08:44:15 -06003273:ref:`dev-manual/common-tasks:Using the Auto Upgrade Helper (AUH)` or
3274by :ref:`dev-manual/common-tasks:Using \`\`devtool upgrade\`\``,
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003275you can manually edit the recipe files to upgrade the versions.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003276
3277.. note::
3278
3279 Manually updating multiple recipes scales poorly and involves many
3280 steps. The recommendation to upgrade recipe versions is through AUH
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003281 or ``devtool upgrade``, both of which automate some steps and provide
3282 guidance for others needed for the manual process.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003283
3284To manually upgrade recipe versions, follow these general steps:
3285
32861. *Change the Version:* Rename the recipe such that the version (i.e.
3287 the :term:`PV` part of the recipe name)
3288 changes appropriately. If the version is not part of the recipe name,
Andrew Geissler09036742021-06-25 14:25:14 -05003289 change the value as it is set for :term:`PV` within the recipe itself.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003290
Andrew Geissler09036742021-06-25 14:25:14 -050032912. *Update* :term:`SRCREV` *if Needed*: If the source code your recipe builds
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003292 is fetched from Git or some other version control system, update
3293 :term:`SRCREV` to point to the
3294 commit hash that matches the new version.
3295
32963. *Build the Software:* Try to build the recipe using BitBake. Typical
3297 build failures include the following:
3298
3299 - License statements were updated for the new version. For this
3300 case, you need to review any changes to the license and update the
3301 values of :term:`LICENSE` and
3302 :term:`LIC_FILES_CHKSUM`
3303 as needed.
3304
3305 .. note::
3306
3307 License changes are often inconsequential. For example, the
3308 license text's copyright year might have changed.
3309
3310 - Custom patches carried by the older version of the recipe might
3311 fail to apply to the new version. For these cases, you need to
3312 review the failures. Patches might not be necessary for the new
3313 version of the software if the upgraded version has fixed those
3314 issues. If a patch is necessary and failing, you need to rebase it
3315 into the new version.
3316
33174. *Optionally Attempt to Build for Several Architectures:* Once you
3318 successfully build the new software for a given architecture, you
3319 could test the build for other architectures by changing the
3320 :term:`MACHINE` variable and
3321 rebuilding the software. This optional step is especially important
3322 if the recipe is to be released publicly.
3323
33245. *Check the Upstream Change Log or Release Notes:* Checking both these
William A. Kennington IIIac69b482021-06-02 12:28:27 -07003325 reveals if there are new features that could break
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003326 backwards-compatibility. If so, you need to take steps to mitigate or
3327 eliminate that situation.
3328
33296. *Optionally Create a Bootable Image and Test:* If you want, you can
3330 test the new software by booting it onto actual hardware.
3331
33327. *Create a Commit with the Change in the Layer Repository:* After all
3333 builds work and any testing is successful, you can create commits for
3334 any changes in the layer holding your upgraded recipe.
3335
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003336Finding Temporary Source Code
3337=============================
3338
3339You might find it helpful during development to modify the temporary
3340source code used by recipes to build packages. For example, suppose you
3341are developing a patch and you need to experiment a bit to figure out
3342your solution. After you have initially built the package, you can
3343iteratively tweak the source code, which is located in the
3344:term:`Build Directory`, and then you can
3345force a re-compile and quickly test your altered code. Once you settle
3346on a solution, you can then preserve your changes in the form of
3347patches.
3348
3349During a build, the unpacked temporary source code used by recipes to
3350build packages is available in the Build Directory as defined by the
3351:term:`S` variable. Below is the default
Andrew Geissler09036742021-06-25 14:25:14 -05003352value for the :term:`S` variable as defined in the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003353``meta/conf/bitbake.conf`` configuration file in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05003354:term:`Source Directory`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003355
3356 S = "${WORKDIR}/${BP}"
3357
3358You should be aware that many recipes override the
Andrew Geissler09036742021-06-25 14:25:14 -05003359:term:`S` variable. For example, recipes that fetch their source from Git
3360usually set :term:`S` to ``${WORKDIR}/git``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003361
3362.. note::
3363
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003364 The :term:`BP` represents the base recipe name, which consists of the name
Andrew Geisslerc926e172021-05-07 16:11:35 -05003365 and version::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003366
3367 BP = "${BPN}-${PV}"
3368
3369
3370The path to the work directory for the recipe
3371(:term:`WORKDIR`) is defined as
Andrew Geisslerc926e172021-05-07 16:11:35 -05003372follows::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003373
3374 ${TMPDIR}/work/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR}
3375
3376The actual directory depends on several things:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003377
3378- :term:`TMPDIR`: The top-level build
3379 output directory.
3380
3381- :term:`MULTIMACH_TARGET_SYS`:
3382 The target system identifier.
3383
3384- :term:`PN`: The recipe name.
3385
Andrew Geissler615f2f12022-07-15 14:00:58 -05003386- :term:`EXTENDPE`: The epoch --- if
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003387 :term:`PE` is not specified, which is
Andrew Geissler615f2f12022-07-15 14:00:58 -05003388 usually the case for most recipes, then :term:`EXTENDPE` is blank.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003389
3390- :term:`PV`: The recipe version.
3391
3392- :term:`PR`: The recipe revision.
3393
3394As an example, assume a Source Directory top-level folder named
3395``poky``, a default Build Directory at ``poky/build``, and a
3396``qemux86-poky-linux`` machine target system. Furthermore, suppose your
3397recipe is named ``foo_1.3.0.bb``. In this case, the work directory the
Andrew Geisslerc926e172021-05-07 16:11:35 -05003398build system uses to build the package would be as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003399
3400 poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
3401
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003402Using Quilt in Your Workflow
3403============================
3404
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003405`Quilt <https://savannah.nongnu.org/projects/quilt>`__ is a powerful tool
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003406that allows you to capture source code changes without having a clean
3407source tree. This section outlines the typical workflow you can use to
3408modify source code, test changes, and then preserve the changes in the
3409form of a patch all using Quilt.
3410
3411.. note::
3412
3413 With regard to preserving changes to source files, if you clean a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003414 recipe or have ``rm_work`` enabled, the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003415 :ref:`devtool workflow <sdk-manual/extensible:using \`\`devtool\`\` in your sdk workflow>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003416 as described in the Yocto Project Application Development and the
3417 Extensible Software Development Kit (eSDK) manual is a safer
3418 development flow than the flow that uses Quilt.
3419
3420Follow these general steps:
3421
34221. *Find the Source Code:* Temporary source code used by the
3423 OpenEmbedded build system is kept in the
3424 :term:`Build Directory`. See the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05003425 ":ref:`dev-manual/common-tasks:finding temporary source code`" section to
3426 learn how to locate the directory that has the temporary source code for a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003427 particular package.
3428
34292. *Change Your Working Directory:* You need to be in the directory that
3430 has the temporary source code. That directory is defined by the
3431 :term:`S` variable.
3432
34333. *Create a New Patch:* Before modifying source code, you need to
3434 create a new patch. To create a new patch file, use ``quilt new`` as
Andrew Geisslerc926e172021-05-07 16:11:35 -05003435 below::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003436
3437 $ quilt new my_changes.patch
3438
34394. *Notify Quilt and Add Files:* After creating the patch, you need to
3440 notify Quilt about the files you plan to edit. You notify Quilt by
Andrew Geisslerc926e172021-05-07 16:11:35 -05003441 adding the files to the patch you just created::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003442
3443 $ quilt add file1.c file2.c file3.c
3444
34455. *Edit the Files:* Make your changes in the source code to the files
3446 you added to the patch.
3447
34486. *Test Your Changes:* Once you have modified the source code, the
3449 easiest way to test your changes is by calling the ``do_compile``
Andrew Geisslerc926e172021-05-07 16:11:35 -05003450 task as shown in the following example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003451
3452 $ bitbake -c compile -f package
3453
3454 The ``-f`` or ``--force`` option forces the specified task to
3455 execute. If you find problems with your code, you can just keep
3456 editing and re-testing iteratively until things work as expected.
3457
3458 .. note::
3459
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003460 All the modifications you make to the temporary source code disappear
3461 once you run the ``do_clean`` or ``do_cleanall`` tasks using BitBake
3462 (i.e. ``bitbake -c clean package`` and ``bitbake -c cleanall package``).
3463 Modifications will also disappear if you use the ``rm_work`` feature as
3464 described in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003465 ":ref:`dev-manual/common-tasks:conserving disk space during builds`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003466 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003467
34687. *Generate the Patch:* Once your changes work as expected, you need to
3469 use Quilt to generate the final patch that contains all your
3470 modifications.
3471 ::
3472
3473 $ quilt refresh
3474
3475 At this point, the
3476 ``my_changes.patch`` file has all your edits made to the ``file1.c``,
3477 ``file2.c``, and ``file3.c`` files.
3478
3479 You can find the resulting patch file in the ``patches/``
Andrew Geissler09036742021-06-25 14:25:14 -05003480 subdirectory of the source (:term:`S`) directory.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003481
34828. *Copy the Patch File:* For simplicity, copy the patch file into a
3483 directory named ``files``, which you can create in the same directory
3484 that holds the recipe (``.bb``) file or the append (``.bbappend``)
3485 file. Placing the patch here guarantees that the OpenEmbedded build
Andrew Geissler09036742021-06-25 14:25:14 -05003486 system will find the patch. Next, add the patch into the :term:`SRC_URI`
Andrew Geisslerc926e172021-05-07 16:11:35 -05003487 of the recipe. Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003488
3489 SRC_URI += "file://my_changes.patch"
3490
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003491Using a Development Shell
3492=========================
3493
3494When debugging certain commands or even when just editing packages,
3495``devshell`` can be a useful tool. When you invoke ``devshell``, all
3496tasks up to and including
3497:ref:`ref-tasks-patch` are run for the
3498specified target. Then, a new terminal is opened and you are placed in
3499``${``\ :term:`S`\ ``}``, the source
3500directory. In the new terminal, all the OpenEmbedded build-related
3501environment variables are still defined so you can use commands such as
3502``configure`` and ``make``. The commands execute just as if the
3503OpenEmbedded build system were executing them. Consequently, working
3504this way can be helpful when debugging a build or preparing software to
3505be used with the OpenEmbedded build system.
3506
3507Following is an example that uses ``devshell`` on a target named
Andrew Geisslerc926e172021-05-07 16:11:35 -05003508``matchbox-desktop``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003509
3510 $ bitbake matchbox-desktop -c devshell
3511
3512This command spawns a terminal with a shell prompt within the
3513OpenEmbedded build environment. The
3514:term:`OE_TERMINAL` variable
3515controls what type of shell is opened.
3516
3517For spawned terminals, the following occurs:
3518
3519- The ``PATH`` variable includes the cross-toolchain.
3520
3521- The ``pkgconfig`` variables find the correct ``.pc`` files.
3522
3523- The ``configure`` command finds the Yocto Project site files as well
3524 as any other necessary files.
3525
3526Within this environment, you can run configure or compile commands as if
3527they were being run by the OpenEmbedded build system itself. As noted
3528earlier, the working directory also automatically changes to the Source
3529Directory (:term:`S`).
3530
3531To manually run a specific task using ``devshell``, run the
3532corresponding ``run.*`` script in the
3533``${``\ :term:`WORKDIR`\ ``}/temp``
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003534directory (e.g., ``run.do_configure.``\ `pid`). If a task's script does
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003535not exist, which would be the case if the task was skipped by way of the
3536sstate cache, you can create the task by first running it outside of the
Andrew Geisslerc926e172021-05-07 16:11:35 -05003537``devshell``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003538
3539 $ bitbake -c task
3540
3541.. note::
3542
3543 - Execution of a task's ``run.*`` script and BitBake's execution of
3544 a task are identical. In other words, running the script re-runs
3545 the task just as it would be run using the ``bitbake -c`` command.
3546
3547 - Any ``run.*`` file that does not have a ``.pid`` extension is a
3548 symbolic link (symlink) to the most recent version of that file.
3549
3550Remember, that the ``devshell`` is a mechanism that allows you to get
3551into the BitBake task execution environment. And as such, all commands
3552must be called just as BitBake would call them. That means you need to
3553provide the appropriate options for cross-compilation and so forth as
3554applicable.
3555
3556When you are finished using ``devshell``, exit the shell or close the
3557terminal window.
3558
3559.. note::
3560
3561 - It is worth remembering that when using ``devshell`` you need to
3562 use the full compiler name such as ``arm-poky-linux-gnueabi-gcc``
3563 instead of just using ``gcc``. The same applies to other
3564 applications such as ``binutils``, ``libtool`` and so forth.
Andrew Geissler09036742021-06-25 14:25:14 -05003565 BitBake sets up environment variables such as :term:`CC` to assist
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003566 applications, such as ``make`` to find the correct tools.
3567
3568 - It is also worth noting that ``devshell`` still works over X11
3569 forwarding and similar situations.
3570
Andrew Geisslereff27472021-10-29 15:35:00 -05003571Using a Python Development Shell
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003572================================
3573
3574Similar to working within a development shell as described in the
3575previous section, you can also spawn and work within an interactive
3576Python development shell. When debugging certain commands or even when
Andrew Geisslereff27472021-10-29 15:35:00 -05003577just editing packages, ``pydevshell`` can be a useful tool. When you
3578invoke the ``pydevshell`` task, all tasks up to and including
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003579:ref:`ref-tasks-patch` are run for the
3580specified target. Then a new terminal is opened. Additionally, key
3581Python objects and code are available in the same way they are to
3582BitBake tasks, in particular, the data store 'd'. So, commands such as
3583the following are useful when exploring the data store and running
Andrew Geisslerc926e172021-05-07 16:11:35 -05003584functions::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003585
3586 pydevshell> d.getVar("STAGING_DIR")
3587 '/media/build1/poky/build/tmp/sysroots'
Andrew Geissler5199d832021-09-24 16:47:35 -05003588 pydevshell> d.getVar("STAGING_DIR", False)
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003589 '${TMPDIR}/sysroots'
3590 pydevshell> d.setVar("FOO", "bar")
3591 pydevshell> d.getVar("FOO")
3592 'bar'
3593 pydevshell> d.delVar("FOO")
3594 pydevshell> d.getVar("FOO")
3595 pydevshell> bb.build.exec_func("do_unpack", d)
3596 pydevshell>
3597
Andrew Geissler87f5cff2022-09-30 13:13:31 -05003598See the ":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:functions you can call from within python`"
3599section in the BitBake User Manual for details about available functions.
3600
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003601The commands execute just as if the OpenEmbedded build
3602system were executing them. Consequently, working this way can be
3603helpful when debugging a build or preparing software to be used with the
3604OpenEmbedded build system.
3605
Andrew Geisslereff27472021-10-29 15:35:00 -05003606Following is an example that uses ``pydevshell`` on a target named
Andrew Geisslerc926e172021-05-07 16:11:35 -05003607``matchbox-desktop``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003608
Andrew Geisslereff27472021-10-29 15:35:00 -05003609 $ bitbake matchbox-desktop -c pydevshell
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003610
3611This command spawns a terminal and places you in an interactive Python
3612interpreter within the OpenEmbedded build environment. The
3613:term:`OE_TERMINAL` variable
3614controls what type of shell is opened.
3615
Andrew Geisslereff27472021-10-29 15:35:00 -05003616When you are finished using ``pydevshell``, you can exit the shell
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003617either by using Ctrl+d or closing the terminal window.
3618
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003619Building
3620========
3621
Andrew Geissler5199d832021-09-24 16:47:35 -05003622This section describes various build procedures, such as the steps
3623needed for a simple build, building a target for multiple configurations,
3624generating an image for more than one machine, and so forth.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003625
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003626Building a Simple Image
3627-----------------------
3628
3629In the development environment, you need to build an image whenever you
3630change hardware support, add or change system libraries, or add or
William A. Kennington IIIac69b482021-06-02 12:28:27 -07003631change services that have dependencies. There are several methods that allow
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003632you to build an image within the Yocto Project. This section presents
3633the basic steps you need to build a simple image using BitBake from a
3634build host running Linux.
3635
3636.. note::
3637
3638 - For information on how to build an image using
3639 :term:`Toaster`, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003640 :doc:`/toaster-manual/index`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003641
3642 - For information on how to use ``devtool`` to build images, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003643 ":ref:`sdk-manual/extensible:using \`\`devtool\`\` in your sdk workflow`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003644 section in the Yocto Project Application Development and the
3645 Extensible Software Development Kit (eSDK) manual.
3646
3647 - For a quick example on how to build an image using the
3648 OpenEmbedded build system, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003649 :doc:`/brief-yoctoprojectqs/index` document.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003650
3651The build process creates an entire Linux distribution from source and
3652places it in your :term:`Build Directory` under
3653``tmp/deploy/images``. For detailed information on the build process
Andrew Geissler09209ee2020-12-13 08:44:15 -06003654using BitBake, see the ":ref:`overview-manual/concepts:images`" section in the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003655Yocto Project Overview and Concepts Manual.
3656
3657The following figure and list overviews the build process:
3658
3659.. image:: figures/bitbake-build-flow.png
Andrew Geisslerd5838332022-05-27 11:33:10 -05003660 :width: 100%
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003661
36621. *Set up Your Host Development System to Support Development Using the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003663 Yocto Project*: See the ":doc:`start`" section for options on how to get a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003664 build host ready to use the Yocto Project.
3665
36662. *Initialize the Build Environment:* Initialize the build environment
3667 by sourcing the build environment script (i.e.
Andrew Geisslerc926e172021-05-07 16:11:35 -05003668 :ref:`structure-core-script`)::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003669
3670 $ source oe-init-build-env [build_dir]
3671
3672 When you use the initialization script, the OpenEmbedded build system
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003673 uses ``build`` as the default :term:`Build Directory` in your current work
3674 directory. You can use a `build_dir` argument with the script to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003675 specify a different build directory.
3676
3677 .. note::
3678
3679 A common practice is to use a different Build Directory for
Andrew Geissler5199d832021-09-24 16:47:35 -05003680 different targets; for example, ``~/build/x86`` for a ``qemux86``
3681 target, and ``~/build/arm`` for a ``qemuarm`` target. In any
3682 event, it's typically cleaner to locate the build directory
3683 somewhere outside of your source directory.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003684
Andrew Geissler4c19ea12020-10-27 13:52:24 -050036853. *Make Sure Your* ``local.conf`` *File is Correct*: Ensure the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003686 ``conf/local.conf`` configuration file, which is found in the Build
3687 Directory, is set up how you want it. This file defines many aspects
3688 of the build environment including the target machine architecture
Andrew Geissler09036742021-06-25 14:25:14 -05003689 through the :term:`MACHINE` variable, the packaging format used during
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003690 the build
3691 (:term:`PACKAGE_CLASSES`),
3692 and a centralized tarball download directory through the
3693 :term:`DL_DIR` variable.
3694
Andrew Geisslerc926e172021-05-07 16:11:35 -050036954. *Build the Image:* Build the image using the ``bitbake`` command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003696
3697 $ bitbake target
3698
3699 .. note::
3700
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003701 For information on BitBake, see the :doc:`bitbake:index`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003702
3703 The target is the name of the recipe you want to build. Common
3704 targets are the images in ``meta/recipes-core/images``,
3705 ``meta/recipes-sato/images``, and so forth all found in the
Andrew Geissler5199d832021-09-24 16:47:35 -05003706 :term:`Source Directory`. Alternatively, the target
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003707 can be the name of a recipe for a specific piece of software such as
3708 BusyBox. For more details about the images the OpenEmbedded build
3709 system supports, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003710 ":ref:`ref-manual/images:Images`" chapter in the Yocto
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003711 Project Reference Manual.
3712
3713 As an example, the following command builds the
Andrew Geisslerc926e172021-05-07 16:11:35 -05003714 ``core-image-minimal`` image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003715
3716 $ bitbake core-image-minimal
3717
3718 Once an
3719 image has been built, it often needs to be installed. The images and
3720 kernels built by the OpenEmbedded build system are placed in the
3721 Build Directory in ``tmp/deploy/images``. For information on how to
3722 run pre-built images such as ``qemux86`` and ``qemuarm``, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06003723 :doc:`/sdk-manual/index` manual. For
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003724 information about how to install these images, see the documentation
3725 for your particular board or machine.
3726
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003727Building Images for Multiple Targets Using Multiple Configurations
3728------------------------------------------------------------------
3729
3730You can use a single ``bitbake`` command to build multiple images or
3731packages for different targets where each image or package requires a
3732different configuration (multiple configuration builds). The builds, in
3733this scenario, are sometimes referred to as "multiconfigs", and this
3734section uses that term throughout.
3735
3736This section describes how to set up for multiple configuration builds
3737and how to account for cross-build dependencies between the
3738multiconfigs.
3739
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003740Setting Up and Running a Multiple Configuration Build
3741~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3742
3743To accomplish a multiple configuration build, you must define each
3744target's configuration separately using a parallel configuration file in
Andrew Geissler615f2f12022-07-15 14:00:58 -05003745the :term:`Build Directory` or configuration directory within a layer, and you
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003746must follow a required file hierarchy. Additionally, you must enable the
3747multiple configuration builds in your ``local.conf`` file.
3748
3749Follow these steps to set up and execute multiple configuration builds:
3750
3751- *Create Separate Configuration Files*: You need to create a single
3752 configuration file for each build target (each multiconfig).
Andrew Geissler615f2f12022-07-15 14:00:58 -05003753 The configuration definitions are implementation dependent but often
3754 each configuration file will define the machine and the
3755 temporary directory BitBake uses for the build. Whether the same
3756 temporary directory (:term:`TMPDIR`) can be shared will depend on what is
3757 similar and what is different between the configurations. Multiple MACHINE
3758 targets can share the same (:term:`TMPDIR`) as long as the rest of the
3759 configuration is the same, multiple DISTRO settings would need separate
3760 (:term:`TMPDIR`) directories.
3761
3762 For example, consider a scenario with two different multiconfigs for the same
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003763 :term:`MACHINE`: "qemux86" built
3764 for two distributions such as "poky" and "poky-lsb". In this case,
Andrew Geissler615f2f12022-07-15 14:00:58 -05003765 you would need to use the different :term:`TMPDIR`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003766
3767 Here is an example showing the minimal statements needed in a
3768 configuration file for a "qemux86" target whose temporary build
Andrew Geisslerc926e172021-05-07 16:11:35 -05003769 directory is ``tmpmultix86``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003770
3771 MACHINE = "qemux86"
3772 TMPDIR = "${TOPDIR}/tmpmultix86"
3773
3774 The location for these multiconfig configuration files is specific.
3775 They must reside in the current build directory in a sub-directory of
Andrew Geissler615f2f12022-07-15 14:00:58 -05003776 ``conf`` named ``multiconfig`` or within a layer's ``conf`` directory
3777 under a directory named ``multiconfig``. Following is an example that defines
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003778 two configuration files for the "x86" and "arm" multiconfigs:
3779
3780 .. image:: figures/multiconfig_files.png
3781 :align: center
Andrew Geisslerd5838332022-05-27 11:33:10 -05003782 :width: 50%
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003783
Andrew Geissler615f2f12022-07-15 14:00:58 -05003784 The usual :term:`BBPATH` search path is used to locate multiconfig files in
3785 a similar way to other conf files.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003786
3787- *Add the BitBake Multi-configuration Variable to the Local
3788 Configuration File*: Use the
3789 :term:`BBMULTICONFIG`
3790 variable in your ``conf/local.conf`` configuration file to specify
3791 each multiconfig. Continuing with the example from the previous
Andrew Geissler09036742021-06-25 14:25:14 -05003792 figure, the :term:`BBMULTICONFIG` variable needs to enable two
Andrew Geisslerc926e172021-05-07 16:11:35 -05003793 multiconfigs: "x86" and "arm" by specifying each configuration file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003794
3795 BBMULTICONFIG = "x86 arm"
3796
3797 .. note::
3798
3799 A "default" configuration already exists by definition. This
3800 configuration is named: "" (i.e. empty string) and is defined by
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003801 the variables coming from your ``local.conf``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003802 file. Consequently, the previous example actually adds two
3803 additional configurations to your build: "arm" and "x86" along
3804 with "".
3805
3806- *Launch BitBake*: Use the following BitBake command form to launch
Andrew Geisslerc926e172021-05-07 16:11:35 -05003807 the multiple configuration build::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003808
3809 $ bitbake [mc:multiconfigname:]target [[[mc:multiconfigname:]target] ... ]
3810
Andrew Geisslerc926e172021-05-07 16:11:35 -05003811 For the example in this section, the following command applies::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003812
3813 $ bitbake mc:x86:core-image-minimal mc:arm:core-image-sato mc::core-image-base
3814
3815 The previous BitBake command builds a ``core-image-minimal`` image
3816 that is configured through the ``x86.conf`` configuration file, a
3817 ``core-image-sato`` image that is configured through the ``arm.conf``
3818 configuration file and a ``core-image-base`` that is configured
3819 through your ``local.conf`` configuration file.
3820
3821.. note::
3822
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003823 Support for multiple configuration builds in the Yocto Project &DISTRO;
3824 (&DISTRO_NAME;) Release does not include Shared State (sstate)
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003825 optimizations. Consequently, if a build uses the same object twice
Andrew Geissler09036742021-06-25 14:25:14 -05003826 in, for example, two different :term:`TMPDIR`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003827 directories, the build either loads from an existing sstate cache for
3828 that build at the start or builds the object fresh.
3829
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003830Enabling Multiple Configuration Build Dependencies
3831~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3832
3833Sometimes dependencies can exist between targets (multiconfigs) in a
3834multiple configuration build. For example, suppose that in order to
3835build a ``core-image-sato`` image for an "x86" multiconfig, the root
3836filesystem of an "arm" multiconfig must exist. This dependency is
3837essentially that the
3838:ref:`ref-tasks-image` task in the
3839``core-image-sato`` recipe depends on the completion of the
3840:ref:`ref-tasks-rootfs` task of the
3841``core-image-minimal`` recipe.
3842
3843To enable dependencies in a multiple configuration build, you must
3844declare the dependencies in the recipe using the following statement
Andrew Geisslerc926e172021-05-07 16:11:35 -05003845form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003846
3847 task_or_package[mcdepends] = "mc:from_multiconfig:to_multiconfig:recipe_name:task_on_which_to_depend"
3848
3849To better show how to use this statement, consider the example scenario
3850from the first paragraph of this section. The following statement needs
Andrew Geisslerc926e172021-05-07 16:11:35 -05003851to be added to the recipe that builds the ``core-image-sato`` image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003852
3853 do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_rootfs"
3854
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003855In this example, the `from_multiconfig` is "x86". The `to_multiconfig` is "arm". The
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003856task on which the ``do_image`` task in the recipe depends is the
3857``do_rootfs`` task from the ``core-image-minimal`` recipe associated
3858with the "arm" multiconfig.
3859
3860Once you set up this dependency, you can build the "x86" multiconfig
Andrew Geisslerc926e172021-05-07 16:11:35 -05003861using a BitBake command as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003862
3863 $ bitbake mc:x86:core-image-sato
3864
3865This command executes all the tasks needed to create the
3866``core-image-sato`` image for the "x86" multiconfig. Because of the
3867dependency, BitBake also executes through the ``do_rootfs`` task for the
3868"arm" multiconfig build.
3869
3870Having a recipe depend on the root filesystem of another build might not
3871seem that useful. Consider this change to the statement in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05003872``core-image-sato`` recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003873
3874 do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_image"
3875
3876In this case, BitBake must
3877create the ``core-image-minimal`` image for the "arm" build since the
3878"x86" build depends on it.
3879
3880Because "x86" and "arm" are enabled for multiple configuration builds
3881and have separate configuration files, BitBake places the artifacts for
3882each build in the respective temporary build directories (i.e.
3883:term:`TMPDIR`).
3884
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003885Building an Initial RAM Filesystem (initramfs) Image
3886----------------------------------------------------
3887
3888An initial RAM filesystem (initramfs) image provides a temporary root
3889filesystem used for early system initialization (e.g. loading of modules
3890needed to locate and mount the "real" root filesystem).
3891
3892.. note::
3893
3894 The initramfs image is the successor of initial RAM disk (initrd). It
3895 is a "copy in and out" (cpio) archive of the initial filesystem that
3896 gets loaded into memory during the Linux startup process. Because
3897 Linux uses the contents of the archive during initialization, the
3898 initramfs image needs to contain all of the device drivers and tools
3899 needed to mount the final root filesystem.
3900
3901Follow these steps to create an initramfs image:
3902
39031. *Create the initramfs Image Recipe:* You can reference the
3904 ``core-image-minimal-initramfs.bb`` recipe found in the
3905 ``meta/recipes-core`` directory of the :term:`Source Directory`
3906 as an example
3907 from which to work.
3908
39092. *Decide if You Need to Bundle the initramfs Image Into the Kernel
3910 Image:* If you want the initramfs image that is built to be bundled
3911 in with the kernel image, set the
3912 :term:`INITRAMFS_IMAGE_BUNDLE`
3913 variable to "1" in your ``local.conf`` configuration file and set the
3914 :term:`INITRAMFS_IMAGE`
3915 variable in the recipe that builds the kernel image.
3916
3917 .. note::
3918
Andrew Geissler5199d832021-09-24 16:47:35 -05003919 It is recommended that you bundle the initramfs image with the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003920 kernel image to avoid circular dependencies between the kernel
3921 recipe and the initramfs recipe should the initramfs image include
3922 kernel modules.
3923
Andrew Geissler09036742021-06-25 14:25:14 -05003924 Setting the :term:`INITRAMFS_IMAGE_BUNDLE` flag causes the initramfs
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003925 image to be unpacked into the ``${B}/usr/`` directory. The unpacked
3926 initramfs image is then passed to the kernel's ``Makefile`` using the
3927 :term:`CONFIG_INITRAMFS_SOURCE`
3928 variable, allowing the initramfs image to be built into the kernel
3929 normally.
3930
3931 .. note::
3932
Patrick Williams93c203f2021-10-06 16:15:23 -05003933 Bundling the initramfs with the kernel conflates the code in the initramfs
3934 with the GPLv2 licensed Linux kernel binary. Thus only GPLv2 compatible
3935 software may be part of a bundled initramfs.
3936
3937 .. note::
3938
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003939 If you choose to not bundle the initramfs image with the kernel
3940 image, you are essentially using an
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003941 `Initial RAM Disk (initrd) <https://en.wikipedia.org/wiki/Initrd>`__.
3942 Creating an initrd is handled primarily through the :term:`INITRD_IMAGE`,
3943 ``INITRD_LIVE``, and ``INITRD_IMAGE_LIVE`` variables. For more
3944 information, see the :ref:`ref-classes-image-live` file.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003945
39463. *Optionally Add Items to the initramfs Image Through the initramfs
3947 Image Recipe:* If you add items to the initramfs image by way of its
3948 recipe, you should use
3949 :term:`PACKAGE_INSTALL`
3950 rather than
3951 :term:`IMAGE_INSTALL`.
Andrew Geissler09036742021-06-25 14:25:14 -05003952 :term:`PACKAGE_INSTALL` gives more direct control of what is added to the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003953 image as compared to the defaults you might not necessarily want that
3954 are set by the :ref:`image <ref-classes-image>`
3955 or :ref:`core-image <ref-classes-core-image>`
3956 classes.
3957
39584. *Build the Kernel Image and the initramfs Image:* Build your kernel
3959 image using BitBake. Because the initramfs image recipe is a
3960 dependency of the kernel image, the initramfs image is built as well
3961 and bundled with the kernel image if you used the
3962 :term:`INITRAMFS_IMAGE_BUNDLE`
3963 variable described earlier.
3964
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00003965Bundling an Initramfs Image From a Separate Multiconfig
3966~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3967
3968There may be a case where we want to build an initramfs image which does not
3969inherit the same distro policy as our main image, for example, we may want
3970our main image to use ``TCLIBC="glibc"``, but to use ``TCLIBC="musl"`` in our initramfs
3971image to keep a smaller footprint. However, by performing the steps mentioned
3972above the initramfs image will inherit ``TCLIBC="glibc"`` without allowing us
3973to override it.
3974
3975To achieve this, you need to perform some additional steps:
3976
39771. *Create a multiconfig for your initramfs image:* You can perform the steps
3978 on ":ref:`dev-manual/common-tasks:building images for multiple targets using multiple configurations`" to create a separate multiconfig.
3979 For the sake of simplicity let's assume such multiconfig is called: ``initramfscfg.conf`` and
3980 contains the variables::
3981
3982 TMPDIR="${TOPDIR}/tmp-initramfscfg"
3983 TCLIBC="musl"
3984
39852. *Set additional initramfs variables on your main configuration:*
3986 Additionally, on your main configuration (``local.conf``) you need to set the
3987 variables::
3988
3989 INITRAMFS_MULTICONFIG = "initramfscfg"
3990 INITRAMFS_DEPLOY_DIR_IMAGE = "${TOPDIR}/tmp-initramfscfg/deploy/images/${MACHINE}"
3991
3992 The variables :term:`INITRAMFS_MULTICONFIG` and :term:`INITRAMFS_DEPLOY_DIR_IMAGE`
3993 are used to create a multiconfig dependency from the kernel to the :term:`INITRAMFS_IMAGE`
3994 to be built coming from the ``initramfscfg`` multiconfig, and to let the
3995 buildsystem know where the :term:`INITRAMFS_IMAGE` will be located.
3996
3997 Building a system with such configuration will build the kernel using the
3998 main configuration but the ``do_bundle_initramfs`` task will grab the
3999 selected :term:`INITRAMFS_IMAGE` from :term:`INITRAMFS_DEPLOY_DIR_IMAGE`
4000 instead, resulting in a musl based initramfs image bundled in the kernel
4001 but a glibc based main image.
4002
4003 The same is applicable to avoid inheriting :term:`DISTRO_FEATURES` on :term:`INITRAMFS_IMAGE`
4004 or to build a different :term:`DISTRO` for it such as ``poky-tiny``.
4005
4006
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004007Building a Tiny System
4008----------------------
4009
4010Very small distributions have some significant advantages such as
4011requiring less on-die or in-package memory (cheaper), better performance
4012through efficient cache usage, lower power requirements due to less
4013memory, faster boot times, and reduced development overhead. Some
4014real-world examples where a very small distribution gives you distinct
4015advantages are digital cameras, medical devices, and small headless
4016systems.
4017
4018This section presents information that shows you how you can trim your
4019distribution to even smaller sizes than the ``poky-tiny`` distribution,
4020which is around 5 Mbytes, that can be built out-of-the-box using the
4021Yocto Project.
4022
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004023Tiny System Overview
4024~~~~~~~~~~~~~~~~~~~~
4025
4026The following list presents the overall steps you need to consider and
4027perform to create distributions with smaller root filesystems, achieve
4028faster boot times, maintain your critical functionality, and avoid
4029initial RAM disks:
4030
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004031- :ref:`Determine your goals and guiding principles
4032 <dev-manual/common-tasks:goals and guiding principles>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004033
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004034- :ref:`dev-manual/common-tasks:understand what contributes to your image size`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004035
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004036- :ref:`Reduce the size of the root filesystem
4037 <dev-manual/common-tasks:trim the root filesystem>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004038
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004039- :ref:`Reduce the size of the kernel <dev-manual/common-tasks:trim the kernel>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004040
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004041- :ref:`dev-manual/common-tasks:remove package management requirements`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004042
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004043- :ref:`dev-manual/common-tasks:look for other ways to minimize size`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004044
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004045- :ref:`dev-manual/common-tasks:iterate on the process`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004046
4047Goals and Guiding Principles
4048~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4049
4050Before you can reach your destination, you need to know where you are
4051going. Here is an example list that you can use as a guide when creating
4052very small distributions:
4053
4054- Determine how much space you need (e.g. a kernel that is 1 Mbyte or
4055 less and a root filesystem that is 3 Mbytes or less).
4056
4057- Find the areas that are currently taking 90% of the space and
4058 concentrate on reducing those areas.
4059
4060- Do not create any difficult "hacks" to achieve your goals.
4061
4062- Leverage the device-specific options.
4063
4064- Work in a separate layer so that you keep changes isolated. For
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004065 information on how to create layers, see the
4066 ":ref:`dev-manual/common-tasks:understanding and creating layers`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004067
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004068Understand What Contributes to Your Image Size
4069~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4070
4071It is easiest to have something to start with when creating your own
4072distribution. You can use the Yocto Project out-of-the-box to create the
4073``poky-tiny`` distribution. Ultimately, you will want to make changes in
4074your own distribution that are likely modeled after ``poky-tiny``.
4075
4076.. note::
4077
Andrew Geissler09036742021-06-25 14:25:14 -05004078 To use ``poky-tiny`` in your build, set the :term:`DISTRO` variable in your
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004079 ``local.conf`` file to "poky-tiny" as described in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06004080 ":ref:`dev-manual/common-tasks:creating your own distribution`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004081 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004082
4083Understanding some memory concepts will help you reduce the system size.
4084Memory consists of static, dynamic, and temporary memory. Static memory
4085is the TEXT (code), DATA (initialized data in the code), and BSS
4086(uninitialized data) sections. Dynamic memory represents memory that is
4087allocated at runtime: stacks, hash tables, and so forth. Temporary
4088memory is recovered after the boot process. This memory consists of
4089memory used for decompressing the kernel and for the ``__init__``
4090functions.
4091
4092To help you see where you currently are with kernel and root filesystem
4093sizes, you can use two tools found in the :term:`Source Directory`
4094in the
4095``scripts/tiny/`` directory:
4096
4097- ``ksize.py``: Reports component sizes for the kernel build objects.
4098
4099- ``dirsize.py``: Reports component sizes for the root filesystem.
4100
4101This next tool and command help you organize configuration fragments and
4102view file dependencies in a human-readable form:
4103
4104- ``merge_config.sh``: Helps you manage configuration files and
4105 fragments within the kernel. With this tool, you can merge individual
4106 configuration fragments together. The tool allows you to make
4107 overrides and warns you of any missing configuration options. The
4108 tool is ideal for allowing you to iterate on configurations, create
4109 minimal configurations, and create configuration files for different
4110 machines without having to duplicate your process.
4111
4112 The ``merge_config.sh`` script is part of the Linux Yocto kernel Git
4113 repositories (i.e. ``linux-yocto-3.14``, ``linux-yocto-3.10``,
4114 ``linux-yocto-3.8``, and so forth) in the ``scripts/kconfig``
4115 directory.
4116
4117 For more information on configuration fragments, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06004118 ":ref:`kernel-dev/common:creating configuration fragments`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004119 section in the Yocto Project Linux Kernel Development Manual.
4120
4121- ``bitbake -u taskexp -g bitbake_target``: Using the BitBake command
4122 with these options brings up a Dependency Explorer from which you can
4123 view file dependencies. Understanding these dependencies allows you
4124 to make informed decisions when cutting out various pieces of the
4125 kernel and root filesystem.
4126
4127Trim the Root Filesystem
4128~~~~~~~~~~~~~~~~~~~~~~~~
4129
4130The root filesystem is made up of packages for booting, libraries, and
4131applications. To change things, you can configure how the packaging
4132happens, which changes the way you build them. You can also modify the
4133filesystem itself or select a different filesystem.
4134
4135First, find out what is hogging your root filesystem by running the
Andrew Geisslerc926e172021-05-07 16:11:35 -05004136``dirsize.py`` script from your root directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004137
4138 $ cd root-directory-of-image
4139 $ dirsize.py 100000 > dirsize-100k.log
4140 $ cat dirsize-100k.log
4141
4142You can apply a filter to the script to ignore files
4143under a certain size. The previous example filters out any files below
4144100 Kbytes. The sizes reported by the tool are uncompressed, and thus
4145will be smaller by a relatively constant factor in a compressed root
4146filesystem. When you examine your log file, you can focus on areas of
4147the root filesystem that take up large amounts of memory.
4148
4149You need to be sure that what you eliminate does not cripple the
4150functionality you need. One way to see how packages relate to each other
Andrew Geisslerc926e172021-05-07 16:11:35 -05004151is by using the Dependency Explorer UI with the BitBake command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004152
4153 $ cd image-directory
4154 $ bitbake -u taskexp -g image
4155
4156Use the interface to
4157select potential packages you wish to eliminate and see their dependency
4158relationships.
4159
4160When deciding how to reduce the size, get rid of packages that result in
4161minimal impact on the feature set. For example, you might not need a VGA
4162display. Or, you might be able to get by with ``devtmpfs`` and ``mdev``
4163instead of ``udev``.
4164
4165Use your ``local.conf`` file to make changes. For example, to eliminate
4166``udev`` and ``glib``, set the following in the local configuration
Andrew Geisslerc926e172021-05-07 16:11:35 -05004167file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004168
4169 VIRTUAL-RUNTIME_dev_manager = ""
4170
4171Finally, you should consider exactly the type of root filesystem you
4172need to meet your needs while also reducing its size. For example,
4173consider ``cramfs``, ``squashfs``, ``ubifs``, ``ext2``, or an
4174``initramfs`` using ``initramfs``. Be aware that ``ext3`` requires a 1
4175Mbyte journal. If you are okay with running read-only, you do not need
4176this journal.
4177
4178.. note::
4179
4180 After each round of elimination, you need to rebuild your system and
4181 then use the tools to see the effects of your reductions.
4182
4183Trim the Kernel
4184~~~~~~~~~~~~~~~
4185
4186The kernel is built by including policies for hardware-independent
4187aspects. What subsystems do you enable? For what architecture are you
4188building? Which drivers do you build by default?
4189
4190.. note::
4191
4192 You can modify the kernel source if you want to help with boot time.
4193
4194Run the ``ksize.py`` script from the top-level Linux build directory to
Andrew Geisslerc926e172021-05-07 16:11:35 -05004195get an idea of what is making up the kernel::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004196
4197 $ cd top-level-linux-build-directory
4198 $ ksize.py > ksize.log
4199 $ cat ksize.log
4200
4201When you examine the log, you will see how much space is taken up with
4202the built-in ``.o`` files for drivers, networking, core kernel files,
4203filesystem, sound, and so forth. The sizes reported by the tool are
4204uncompressed, and thus will be smaller by a relatively constant factor
4205in a compressed kernel image. Look to reduce the areas that are large
4206and taking up around the "90% rule."
4207
4208To examine, or drill down, into any particular area, use the ``-d``
Andrew Geisslerc926e172021-05-07 16:11:35 -05004209option with the script::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004210
4211 $ ksize.py -d > ksize.log
4212
4213Using this option
4214breaks out the individual file information for each area of the kernel
4215(e.g. drivers, networking, and so forth).
4216
4217Use your log file to see what you can eliminate from the kernel based on
4218features you can let go. For example, if you are not going to need
4219sound, you do not need any drivers that support sound.
4220
4221After figuring out what to eliminate, you need to reconfigure the kernel
4222to reflect those changes during the next build. You could run
4223``menuconfig`` and make all your changes at once. However, that makes it
4224difficult to see the effects of your individual eliminations and also
4225makes it difficult to replicate the changes for perhaps another target
4226device. A better method is to start with no configurations using
4227``allnoconfig``, create configuration fragments for individual changes,
4228and then manage the fragments into a single configuration file using
4229``merge_config.sh``. The tool makes it easy for you to iterate using the
4230configuration change and build cycle.
4231
4232Each time you make configuration changes, you need to rebuild the kernel
4233and check to see what impact your changes had on the overall size.
4234
4235Remove Package Management Requirements
4236~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4237
4238Packaging requirements add size to the image. One way to reduce the size
4239of the image is to remove all the packaging requirements from the image.
4240This reduction includes both removing the package manager and its unique
4241dependencies as well as removing the package management data itself.
4242
4243To eliminate all the packaging requirements for an image, be sure that
4244"package-management" is not part of your
4245:term:`IMAGE_FEATURES`
4246statement for the image. When you remove this feature, you are removing
4247the package manager as well as its dependencies from the root
4248filesystem.
4249
4250Look for Other Ways to Minimize Size
4251~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4252
4253Depending on your particular circumstances, other areas that you can
4254trim likely exist. The key to finding these areas is through tools and
4255methods described here combined with experimentation and iteration. Here
4256are a couple of areas to experiment with:
4257
4258- ``glibc``: In general, follow this process:
4259
4260 1. Remove ``glibc`` features from
4261 :term:`DISTRO_FEATURES`
4262 that you think you do not need.
4263
4264 2. Build your distribution.
4265
4266 3. If the build fails due to missing symbols in a package, determine
4267 if you can reconfigure the package to not need those features. For
4268 example, change the configuration to not support wide character
4269 support as is done for ``ncurses``. Or, if support for those
4270 characters is needed, determine what ``glibc`` features provide
4271 the support and restore the configuration.
4272
4273 4. Rebuild and repeat the process.
4274
4275- ``busybox``: For BusyBox, use a process similar as described for
4276 ``glibc``. A difference is you will need to boot the resulting system
4277 to see if you are able to do everything you expect from the running
4278 system. You need to be sure to integrate configuration fragments into
4279 Busybox because BusyBox handles its own core features and then allows
4280 you to add configuration fragments on top.
4281
4282Iterate on the Process
4283~~~~~~~~~~~~~~~~~~~~~~
4284
4285If you have not reached your goals on system size, you need to iterate
4286on the process. The process is the same. Use the tools and see just what
4287is taking up 90% of the root filesystem and the kernel. Decide what you
4288can eliminate without limiting your device beyond what you need.
4289
4290Depending on your system, a good place to look might be Busybox, which
4291provides a stripped down version of Unix tools in a single, executable
4292file. You might be able to drop virtual terminal services or perhaps
4293ipv6.
4294
4295Building Images for More than One Machine
4296-----------------------------------------
4297
4298A common scenario developers face is creating images for several
4299different machines that use the same software environment. In this
4300situation, it is tempting to set the tunings and optimization flags for
4301each build specifically for the targeted hardware (i.e. "maxing out" the
4302tunings). Doing so can considerably add to build times and package feed
4303maintenance collectively for the machines. For example, selecting tunes
4304that are extremely specific to a CPU core used in a system might enable
4305some micro optimizations in GCC for that particular system but would
4306otherwise not gain you much of a performance difference across the other
4307systems as compared to using a more general tuning across all the builds
4308(e.g. setting :term:`DEFAULTTUNE`
4309specifically for each machine's build). Rather than "max out" each
4310build's tunings, you can take steps that cause the OpenEmbedded build
4311system to reuse software across the various machines where it makes
4312sense.
4313
4314If build speed and package feed maintenance are considerations, you
4315should consider the points in this section that can help you optimize
4316your tunings to best consider build times and package feed maintenance.
4317
4318- *Share the Build Directory:* If at all possible, share the
4319 :term:`TMPDIR` across builds. The
4320 Yocto Project supports switching between different
4321 :term:`MACHINE` values in the same
Andrew Geissler09036742021-06-25 14:25:14 -05004322 :term:`TMPDIR`. This practice is well supported and regularly used by
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004323 developers when building for multiple machines. When you use the same
Andrew Geissler09036742021-06-25 14:25:14 -05004324 :term:`TMPDIR` for multiple machine builds, the OpenEmbedded build system
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004325 can reuse the existing native and often cross-recipes for multiple
4326 machines. Thus, build time decreases.
4327
4328 .. note::
4329
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004330 If :term:`DISTRO` settings change or fundamental configuration settings
Andrew Geissler09036742021-06-25 14:25:14 -05004331 such as the filesystem layout, you need to work with a clean :term:`TMPDIR`.
4332 Sharing :term:`TMPDIR` under these circumstances might work but since it is
Andrew Geissler5f350902021-07-23 13:09:54 -04004333 not guaranteed, you should use a clean :term:`TMPDIR`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004334
4335- *Enable the Appropriate Package Architecture:* By default, the
4336 OpenEmbedded build system enables three levels of package
4337 architectures: "all", "tune" or "package", and "machine". Any given
4338 recipe usually selects one of these package architectures (types) for
4339 its output. Depending for what a given recipe creates packages,
4340 making sure you enable the appropriate package architecture can
4341 directly impact the build time.
4342
4343 A recipe that just generates scripts can enable "all" architecture
4344 because there are no binaries to build. To specifically enable "all"
4345 architecture, be sure your recipe inherits the
4346 :ref:`allarch <ref-classes-allarch>` class.
4347 This class is useful for "all" architectures because it configures
4348 many variables so packages can be used across multiple architectures.
4349
4350 If your recipe needs to generate packages that are machine-specific
4351 or when one of the build or runtime dependencies is already
4352 machine-architecture dependent, which makes your recipe also
4353 machine-architecture dependent, make sure your recipe enables the
4354 "machine" package architecture through the
4355 :term:`MACHINE_ARCH`
Andrew Geisslerc926e172021-05-07 16:11:35 -05004356 variable::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004357
4358 PACKAGE_ARCH = "${MACHINE_ARCH}"
4359
4360 When you do not
4361 specifically enable a package architecture through the
4362 :term:`PACKAGE_ARCH`, The
4363 OpenEmbedded build system defaults to the
Andrew Geisslerc926e172021-05-07 16:11:35 -05004364 :term:`TUNE_PKGARCH` setting::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004365
4366 PACKAGE_ARCH = "${TUNE_PKGARCH}"
4367
4368- *Choose a Generic Tuning File if Possible:* Some tunes are more
4369 generic and can run on multiple targets (e.g. an ``armv5`` set of
4370 packages could run on ``armv6`` and ``armv7`` processors in most
4371 cases). Similarly, ``i486`` binaries could work on ``i586`` and
4372 higher processors. You should realize, however, that advances on
4373 newer processor versions would not be used.
4374
4375 If you select the same tune for several different machines, the
4376 OpenEmbedded build system reuses software previously built, thus
4377 speeding up the overall build time. Realize that even though a new
4378 sysroot for each machine is generated, the software is not recompiled
4379 and only one package feed exists.
4380
William A. Kennington IIIac69b482021-06-02 12:28:27 -07004381- *Manage Granular Level Packaging:* Sometimes there are cases where
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004382 injecting another level of package architecture beyond the three
4383 higher levels noted earlier can be useful. For example, consider how
4384 NXP (formerly Freescale) allows for the easy reuse of binary packages
4385 in their layer
Andrew Geissler09209ee2020-12-13 08:44:15 -06004386 :yocto_git:`meta-freescale </meta-freescale/>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004387 In this example, the
Andrew Geissler09209ee2020-12-13 08:44:15 -06004388 :yocto_git:`fsl-dynamic-packagearch </meta-freescale/tree/classes/fsl-dynamic-packagearch.bbclass>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004389 class shares GPU packages for i.MX53 boards because all boards share
4390 the AMD GPU. The i.MX6-based boards can do the same because all
4391 boards share the Vivante GPU. This class inspects the BitBake
4392 datastore to identify if the package provides or depends on one of
4393 the sub-architecture values. If so, the class sets the
4394 :term:`PACKAGE_ARCH` value
4395 based on the ``MACHINE_SUBARCH`` value. If the package does not
4396 provide or depend on one of the sub-architecture values but it
4397 matches a value in the machine-specific filter, it sets
4398 :term:`MACHINE_ARCH`. This
4399 behavior reduces the number of packages built and saves build time by
4400 reusing binaries.
4401
4402- *Use Tools to Debug Issues:* Sometimes you can run into situations
4403 where software is being rebuilt when you think it should not be. For
4404 example, the OpenEmbedded build system might not be using shared
4405 state between machines when you think it should be. These types of
4406 situations are usually due to references to machine-specific
4407 variables such as :term:`MACHINE`,
4408 :term:`SERIAL_CONSOLES`,
4409 :term:`XSERVER`,
4410 :term:`MACHINE_FEATURES`,
4411 and so forth in code that is supposed to only be tune-specific or
4412 when the recipe depends
4413 (:term:`DEPENDS`,
4414 :term:`RDEPENDS`,
4415 :term:`RRECOMMENDS`,
4416 :term:`RSUGGESTS`, and so forth)
4417 on some other recipe that already has
4418 :term:`PACKAGE_ARCH` defined
4419 as "${MACHINE_ARCH}".
4420
4421 .. note::
4422
4423 Patches to fix any issues identified are most welcome as these
4424 issues occasionally do occur.
4425
4426 For such cases, you can use some tools to help you sort out the
4427 situation:
4428
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004429 - ``state-diff-machines.sh``*:* You can find this tool in the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004430 ``scripts`` directory of the Source Repositories. See the comments
4431 in the script for information on how to use the tool.
4432
4433 - *BitBake's "-S printdiff" Option:* Using this option causes
4434 BitBake to try to establish the closest signature match it can
4435 (e.g. in the shared state cache) and then run ``bitbake-diffsigs``
4436 over the matches to determine the stamps and delta where these two
4437 stamp trees diverge.
4438
4439Building Software from an External Source
4440-----------------------------------------
4441
4442By default, the OpenEmbedded build system uses the
4443:term:`Build Directory` when building source
4444code. The build process involves fetching the source files, unpacking
4445them, and then patching them if necessary before the build takes place.
4446
William A. Kennington IIIac69b482021-06-02 12:28:27 -07004447There are situations where you might want to build software from source
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004448files that are external to and thus outside of the OpenEmbedded build
4449system. For example, suppose you have a project that includes a new BSP
4450with a heavily customized kernel. And, you want to minimize exposing the
4451build system to the development team so that they can focus on their
4452project and maintain everyone's workflow as much as possible. In this
4453case, you want a kernel source directory on the development machine
4454where the development occurs. You want the recipe's
4455:term:`SRC_URI` variable to point to
4456the external directory and use it as is, not copy it.
4457
4458To build from software that comes from an external source, all you need
4459to do is inherit the
4460:ref:`externalsrc <ref-classes-externalsrc>` class
4461and then set the
4462:term:`EXTERNALSRC` variable to
4463point to your external source code. Here are the statements to put in
Andrew Geisslerc926e172021-05-07 16:11:35 -05004464your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004465
4466 INHERIT += "externalsrc"
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004467 EXTERNALSRC:pn-myrecipe = "path-to-your-source-tree"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004468
4469This next example shows how to accomplish the same thing by setting
Andrew Geissler09036742021-06-25 14:25:14 -05004470:term:`EXTERNALSRC` in the recipe itself or in the recipe's append file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004471
4472 EXTERNALSRC = "path"
4473 EXTERNALSRC_BUILD = "path"
4474
4475.. note::
4476
4477 In order for these settings to take effect, you must globally or
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004478 locally inherit the :ref:`externalsrc <ref-classes-externalsrc>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004479 class.
4480
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00004481By default, :ref:`ref-classes-externalsrc` builds the source code in a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004482directory separate from the external source directory as specified by
4483:term:`EXTERNALSRC`. If you need
4484to have the source built in the same directory in which it resides, or
4485some other nominated directory, you can set
4486:term:`EXTERNALSRC_BUILD`
Andrew Geisslerc926e172021-05-07 16:11:35 -05004487to point to that directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004488
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004489 EXTERNALSRC_BUILD:pn-myrecipe = "path-to-your-source-tree"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004490
4491Replicating a Build Offline
4492---------------------------
4493
4494It can be useful to take a "snapshot" of upstream sources used in a
4495build and then use that "snapshot" later to replicate the build offline.
4496To do so, you need to first prepare and populate your downloads
4497directory your "snapshot" of files. Once your downloads directory is
4498ready, you can use it at any time and from any machine to replicate your
4499build.
4500
4501Follow these steps to populate your Downloads directory:
4502
45031. *Create a Clean Downloads Directory:* Start with an empty downloads
4504 directory (:term:`DL_DIR`). You
4505 start with an empty downloads directory by either removing the files
Andrew Geissler09036742021-06-25 14:25:14 -05004506 in the existing directory or by setting :term:`DL_DIR` to point to either
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004507 an empty location or one that does not yet exist.
4508
45092. *Generate Tarballs of the Source Git Repositories:* Edit your
Andrew Geisslerc926e172021-05-07 16:11:35 -05004510 ``local.conf`` configuration file as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004511
4512 DL_DIR = "/home/your-download-dir/"
4513 BB_GENERATE_MIRROR_TARBALLS = "1"
4514
4515 During
4516 the fetch process in the next step, BitBake gathers the source files
Andrew Geissler09036742021-06-25 14:25:14 -05004517 and creates tarballs in the directory pointed to by :term:`DL_DIR`. See
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004518 the
4519 :term:`BB_GENERATE_MIRROR_TARBALLS`
4520 variable for more information.
4521
45223. *Populate Your Downloads Directory Without Building:* Use BitBake to
Andrew Geisslerc926e172021-05-07 16:11:35 -05004523 fetch your sources but inhibit the build::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004524
4525 $ bitbake target --runonly=fetch
4526
4527 The downloads directory (i.e. ``${DL_DIR}``) now has
4528 a "snapshot" of the source files in the form of tarballs, which can
4529 be used for the build.
4530
45314. *Optionally Remove Any Git or other SCM Subdirectories From the
4532 Downloads Directory:* If you want, you can clean up your downloads
4533 directory by removing any Git or other Source Control Management
4534 (SCM) subdirectories such as ``${DL_DIR}/git2/*``. The tarballs
4535 already contain these subdirectories.
4536
4537Once your downloads directory has everything it needs regarding source
4538files, you can create your "own-mirror" and build your target.
4539Understand that you can use the files to build the target offline from
4540any machine and at any time.
4541
4542Follow these steps to build your target using the files in the downloads
4543directory:
4544
45451. *Using Local Files Only:* Inside your ``local.conf`` file, add the
Andrew Geissler595f6302022-01-24 19:11:47 +00004546 :term:`SOURCE_MIRROR_URL` variable, inherit the
4547 :ref:`own-mirrors <ref-classes-own-mirrors>` class, and use the
4548 :term:`BB_NO_NETWORK` variable to your ``local.conf``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004549 ::
4550
4551 SOURCE_MIRROR_URL ?= "file:///home/your-download-dir/"
4552 INHERIT += "own-mirrors"
4553 BB_NO_NETWORK = "1"
4554
Andrew Geissler595f6302022-01-24 19:11:47 +00004555 The :term:`SOURCE_MIRROR_URL` and :ref:`own-mirrors <ref-classes-own-mirrors>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004556 class set up the system to use the downloads directory as your "own
Andrew Geissler09036742021-06-25 14:25:14 -05004557 mirror". Using the :term:`BB_NO_NETWORK` variable makes sure that
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004558 BitBake's fetching process in step 3 stays local, which means files
4559 from your "own-mirror" are used.
4560
45612. *Start With a Clean Build:* You can start with a clean build by
4562 removing the
4563 ``${``\ :term:`TMPDIR`\ ``}``
4564 directory or using a new :term:`Build Directory`.
4565
Andrew Geisslerc926e172021-05-07 16:11:35 -050045663. *Build Your Target:* Use BitBake to build your target::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004567
4568 $ bitbake target
4569
4570 The build completes using the known local "snapshot" of source
4571 files from your mirror. The resulting tarballs for your "snapshot" of
4572 source files are in the downloads directory.
4573
4574 .. note::
4575
4576 The offline build does not work if recipes attempt to find the
4577 latest version of software by setting
4578 :term:`SRCREV` to
Andrew Geisslerc926e172021-05-07 16:11:35 -05004579 ``${``\ :term:`AUTOREV`\ ``}``::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004580
4581 SRCREV = "${AUTOREV}"
4582
Andrew Geissler09036742021-06-25 14:25:14 -05004583 When a recipe sets :term:`SRCREV` to
Andrew Geissler5199d832021-09-24 16:47:35 -05004584 ``${``\ :term:`AUTOREV`\ ``}``, the build system accesses the network in an
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004585 attempt to determine the latest version of software from the SCM.
Andrew Geissler09036742021-06-25 14:25:14 -05004586 Typically, recipes that use :term:`AUTOREV` are custom or modified
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004587 recipes. Recipes that reside in public repositories usually do not
Andrew Geissler09036742021-06-25 14:25:14 -05004588 use :term:`AUTOREV`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004589
Andrew Geissler09036742021-06-25 14:25:14 -05004590 If you do have recipes that use :term:`AUTOREV`, you can take steps to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004591 still use the recipes in an offline build. Do the following:
4592
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004593 1. Use a configuration generated by enabling :ref:`build
4594 history <dev-manual/common-tasks:maintaining build output quality>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004595
4596 2. Use the ``buildhistory-collect-srcrevs`` command to collect the
Andrew Geissler09036742021-06-25 14:25:14 -05004597 stored :term:`SRCREV` values from the build's history. For more
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004598 information on collecting these values, see the
4599 ":ref:`dev-manual/common-tasks:build history package information`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004600 section.
4601
4602 3. Once you have the correct source revisions, you can modify
Andrew Geissler09036742021-06-25 14:25:14 -05004603 those recipes to set :term:`SRCREV` to specific versions of the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004604 software.
4605
4606Speeding Up a Build
4607===================
4608
4609Build time can be an issue. By default, the build system uses simple
4610controls to try and maximize build efficiency. In general, the default
4611settings for all the following variables result in the most efficient
4612build times when dealing with single socket systems (i.e. a single CPU).
4613If you have multiple CPUs, you might try increasing the default values
4614to gain more speed. See the descriptions in the glossary for each
4615variable for more information:
4616
4617- :term:`BB_NUMBER_THREADS`:
4618 The maximum number of threads BitBake simultaneously executes.
4619
Patrick Williams213cb262021-08-07 19:21:33 -05004620- :term:`BB_NUMBER_PARSE_THREADS`:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004621 The number of threads BitBake uses during parsing.
4622
4623- :term:`PARALLEL_MAKE`: Extra
4624 options passed to the ``make`` command during the
4625 :ref:`ref-tasks-compile` task in
4626 order to specify parallel compilation on the local build host.
4627
4628- :term:`PARALLEL_MAKEINST`:
4629 Extra options passed to the ``make`` command during the
4630 :ref:`ref-tasks-install` task in
4631 order to specify parallel installation on the local build host.
4632
4633As mentioned, these variables all scale to the number of processor cores
4634available on the build system. For single socket systems, this
4635auto-scaling ensures that the build system fundamentally takes advantage
4636of potential parallel operations during the build based on the build
4637machine's capabilities.
4638
4639Following are additional factors that can affect build speed:
4640
4641- File system type: The file system type that the build is being
4642 performed on can also influence performance. Using ``ext4`` is
4643 recommended as compared to ``ext2`` and ``ext3`` due to ``ext4``
4644 improved features such as extents.
4645
4646- Disabling the updating of access time using ``noatime``: The
4647 ``noatime`` mount option prevents the build system from updating file
4648 and directory access times.
4649
4650- Setting a longer commit: Using the "commit=" mount option increases
4651 the interval in seconds between disk cache writes. Changing this
4652 interval from the five second default to something longer increases
4653 the risk of data loss but decreases the need to write to the disk,
4654 thus increasing the build performance.
4655
4656- Choosing the packaging backend: Of the available packaging backends,
4657 IPK is the fastest. Additionally, selecting a singular packaging
4658 backend also helps.
4659
4660- Using ``tmpfs`` for :term:`TMPDIR`
4661 as a temporary file system: While this can help speed up the build,
4662 the benefits are limited due to the compiler using ``-pipe``. The
4663 build system goes to some lengths to avoid ``sync()`` calls into the
4664 file system on the principle that if there was a significant failure,
4665 the :term:`Build Directory`
4666 contents could easily be rebuilt.
4667
4668- Inheriting the
4669 :ref:`rm_work <ref-classes-rm-work>` class:
4670 Inheriting this class has shown to speed up builds due to
4671 significantly lower amounts of data stored in the data cache as well
4672 as on disk. Inheriting this class also makes cleanup of
4673 :term:`TMPDIR` faster, at the
4674 expense of being easily able to dive into the source code. File
4675 system maintainers have recommended that the fastest way to clean up
4676 large numbers of files is to reformat partitions rather than delete
4677 files due to the linear nature of partitions. This, of course,
4678 assumes you structure the disk partitions and file systems in a way
4679 that this is practical.
4680
4681Aside from the previous list, you should keep some trade offs in mind
4682that can help you speed up the build:
4683
4684- Remove items from
4685 :term:`DISTRO_FEATURES`
4686 that you might not need.
4687
4688- Exclude debug symbols and other debug information: If you do not need
4689 these symbols and other debug information, disabling the ``*-dbg``
4690 package generation can speed up the build. You can disable this
4691 generation by setting the
4692 :term:`INHIBIT_PACKAGE_DEBUG_SPLIT`
4693 variable to "1".
4694
4695- Disable static library generation for recipes derived from
4696 ``autoconf`` or ``libtool``: Following is an example showing how to
4697 disable static libraries and still provide an override to handle
Andrew Geisslerc926e172021-05-07 16:11:35 -05004698 exceptions::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004699
4700 STATICLIBCONF = "--disable-static"
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004701 STATICLIBCONF:sqlite3-native = ""
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004702 EXTRA_OECONF += "${STATICLIBCONF}"
4703
4704 .. note::
4705
4706 - Some recipes need static libraries in order to work correctly
4707 (e.g. ``pseudo-native`` needs ``sqlite3-native``). Overrides,
4708 as in the previous example, account for these kinds of
4709 exceptions.
4710
4711 - Some packages have packaging code that assumes the presence of
4712 the static libraries. If so, you might need to exclude them as
4713 well.
4714
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004715Working With Libraries
4716======================
4717
4718Libraries are an integral part of your system. This section describes
4719some common practices you might find helpful when working with libraries
4720to build your system:
4721
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004722- :ref:`How to include static library files
4723 <dev-manual/common-tasks:including static library files>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004724
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004725- :ref:`How to use the Multilib feature to combine multiple versions of
4726 library files into a single image
4727 <dev-manual/common-tasks:combining multiple versions of library files into one image>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004728
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05004729- :ref:`How to install multiple versions of the same library in parallel on
4730 the same system
4731 <dev-manual/common-tasks:installing multiple versions of the same library>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004732
4733Including Static Library Files
4734------------------------------
4735
4736If you are building a library and the library offers static linking, you
4737can control which static library files (``*.a`` files) get included in
4738the built library.
4739
4740The :term:`PACKAGES` and
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004741:term:`FILES:* <FILES>` variables in the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004742``meta/conf/bitbake.conf`` configuration file define how files installed
Andrew Geissler09036742021-06-25 14:25:14 -05004743by the ``do_install`` task are packaged. By default, the :term:`PACKAGES`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004744variable includes ``${PN}-staticdev``, which represents all static
4745library files.
4746
4747.. note::
4748
4749 Some previously released versions of the Yocto Project defined the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004750 static library files through ``${PN}-dev``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004751
4752Following is part of the BitBake configuration file, where you can see
Andrew Geisslerc926e172021-05-07 16:11:35 -05004753how the static library files are defined::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004754
4755 PACKAGE_BEFORE_PN ?= ""
Andrew Geissler595f6302022-01-24 19:11:47 +00004756 PACKAGES = "${PN}-src ${PN}-dbg ${PN}-staticdev ${PN}-dev ${PN}-doc ${PN}-locale ${PACKAGE_BEFORE_PN} ${PN}"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004757 PACKAGES_DYNAMIC = "^${PN}-locale-.*"
4758 FILES = ""
4759
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004760 FILES:${PN} = "${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*${SOLIBS} \
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004761 ${sysconfdir} ${sharedstatedir} ${localstatedir} \
4762 ${base_bindir}/* ${base_sbindir}/* \
4763 ${base_libdir}/*${SOLIBS} \
Andrew Geissler595f6302022-01-24 19:11:47 +00004764 ${base_prefix}/lib/udev ${prefix}/lib/udev \
4765 ${base_libdir}/udev ${libdir}/udev \
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004766 ${datadir}/${BPN} ${libdir}/${BPN}/* \
4767 ${datadir}/pixmaps ${datadir}/applications \
4768 ${datadir}/idl ${datadir}/omf ${datadir}/sounds \
4769 ${libdir}/bonobo/servers"
4770
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004771 FILES:${PN}-bin = "${bindir}/* ${sbindir}/*"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004772
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004773 FILES:${PN}-doc = "${docdir} ${mandir} ${infodir} ${datadir}/gtk-doc \
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004774 ${datadir}/gnome/help"
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004775 SECTION:${PN}-doc = "doc"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004776
4777 FILES_SOLIBSDEV ?= "${base_libdir}/lib*${SOLIBSDEV} ${libdir}/lib*${SOLIBSDEV}"
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004778 FILES:${PN}-dev = "${includedir} ${FILES_SOLIBSDEV} ${libdir}/*.la \
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004779 ${libdir}/*.o ${libdir}/pkgconfig ${datadir}/pkgconfig \
4780 ${datadir}/aclocal ${base_libdir}/*.o \
Andrew Geissler595f6302022-01-24 19:11:47 +00004781 ${libdir}/${BPN}/*.la ${base_libdir}/*.la \
4782 ${libdir}/cmake ${datadir}/cmake"
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004783 SECTION:${PN}-dev = "devel"
4784 ALLOW_EMPTY:${PN}-dev = "1"
4785 RDEPENDS:${PN}-dev = "${PN} (= ${EXTENDPKGV})"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004786
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004787 FILES:${PN}-staticdev = "${libdir}/*.a ${base_libdir}/*.a ${libdir}/${BPN}/*.a"
4788 SECTION:${PN}-staticdev = "devel"
4789 RDEPENDS:${PN}-staticdev = "${PN}-dev (= ${EXTENDPKGV})"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004790
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004791Combining Multiple Versions of Library Files into One Image
4792-----------------------------------------------------------
4793
4794The build system offers the ability to build libraries with different
4795target optimizations or architecture formats and combine these together
4796into one system image. You can link different binaries in the image
4797against the different libraries as needed for specific use cases. This
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004798feature is called "Multilib".
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004799
4800An example would be where you have most of a system compiled in 32-bit
4801mode using 32-bit libraries, but you have something large, like a
4802database engine, that needs to be a 64-bit application and uses 64-bit
4803libraries. Multilib allows you to get the best of both 32-bit and 64-bit
4804libraries.
4805
4806While the Multilib feature is most commonly used for 32 and 64-bit
4807differences, the approach the build system uses facilitates different
4808target optimizations. You could compile some binaries to use one set of
4809libraries and other binaries to use a different set of libraries. The
4810libraries could differ in architecture, compiler options, or other
4811optimizations.
4812
William A. Kennington IIIac69b482021-06-02 12:28:27 -07004813There are several examples in the ``meta-skeleton`` layer found in the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004814:term:`Source Directory`:
4815
Andrew Geissler595f6302022-01-24 19:11:47 +00004816- :oe_git:`conf/multilib-example.conf </openembedded-core/tree/meta-skeleton/conf/multilib-example.conf>`
4817 configuration file.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004818
Andrew Geissler595f6302022-01-24 19:11:47 +00004819- :oe_git:`conf/multilib-example2.conf </openembedded-core/tree/meta-skeleton/conf/multilib-example2.conf>`
4820 configuration file.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004821
Andrew Geissler595f6302022-01-24 19:11:47 +00004822- :oe_git:`recipes-multilib/images/core-image-multilib-example.bb </openembedded-core/tree/meta-skeleton/recipes-multilib/images/core-image-multilib-example.bb>`
4823 recipe
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004824
4825Preparing to Use Multilib
4826~~~~~~~~~~~~~~~~~~~~~~~~~
4827
4828User-specific requirements drive the Multilib feature. Consequently,
William A. Kennington IIIac69b482021-06-02 12:28:27 -07004829there is no one "out-of-the-box" configuration that would
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004830meet your needs.
4831
4832In order to enable Multilib, you first need to ensure your recipe is
4833extended to support multiple libraries. Many standard recipes are
4834already extended and support multiple libraries. You can check in the
4835``meta/conf/multilib.conf`` configuration file in the
4836:term:`Source Directory` to see how this is
4837done using the
4838:term:`BBCLASSEXTEND` variable.
4839Eventually, all recipes will be covered and this list will not be
4840needed.
4841
Andrew Geissler595f6302022-01-24 19:11:47 +00004842For the most part, the :ref:`Multilib <ref-classes-multilib*>`
4843class extension works automatically to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004844extend the package name from ``${PN}`` to ``${MLPREFIX}${PN}``, where
Andrew Geissler5f350902021-07-23 13:09:54 -04004845:term:`MLPREFIX` is the particular multilib (e.g. "lib32-" or "lib64-").
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004846Standard variables such as
4847:term:`DEPENDS`,
4848:term:`RDEPENDS`,
4849:term:`RPROVIDES`,
4850:term:`RRECOMMENDS`,
4851:term:`PACKAGES`, and
4852:term:`PACKAGES_DYNAMIC` are
4853automatically extended by the system. If you are extending any manual
4854code in the recipe, you can use the ``${MLPREFIX}`` variable to ensure
Andrew Geissler595f6302022-01-24 19:11:47 +00004855those names are extended correctly.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004856
4857Using Multilib
4858~~~~~~~~~~~~~~
4859
4860After you have set up the recipes, you need to define the actual
4861combination of multiple libraries you want to build. You accomplish this
4862through your ``local.conf`` configuration file in the
4863:term:`Build Directory`. An example
Andrew Geisslerc926e172021-05-07 16:11:35 -05004864configuration would be as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004865
4866 MACHINE = "qemux86-64"
4867 require conf/multilib.conf
4868 MULTILIBS = "multilib:lib32"
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004869 DEFAULTTUNE:virtclass-multilib-lib32 = "x86"
Andrew Geisslerd5838332022-05-27 11:33:10 -05004870 IMAGE_INSTALL:append = " lib32-glib-2.0"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004871
4872This example enables an additional library named
4873``lib32`` alongside the normal target packages. When combining these
4874"lib32" alternatives, the example uses "x86" for tuning. For information
4875on this particular tuning, see
4876``meta/conf/machine/include/ia32/arch-ia32.inc``.
4877
4878The example then includes ``lib32-glib-2.0`` in all the images, which
4879illustrates one method of including a multiple library dependency. You
Andrew Geisslerc926e172021-05-07 16:11:35 -05004880can use a normal image build to include this dependency, for example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004881
4882 $ bitbake core-image-sato
4883
4884You can also build Multilib packages
Andrew Geisslerc926e172021-05-07 16:11:35 -05004885specifically with a command like this::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004886
4887 $ bitbake lib32-glib-2.0
4888
4889Additional Implementation Details
4890~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4891
William A. Kennington IIIac69b482021-06-02 12:28:27 -07004892There are generic implementation details as well as details that are specific to
4893package management systems. Following are implementation details
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004894that exist regardless of the package management system:
4895
4896- The typical convention used for the class extension code as used by
4897 Multilib assumes that all package names specified in
4898 :term:`PACKAGES` that contain
4899 ``${PN}`` have ``${PN}`` at the start of the name. When that
4900 convention is not followed and ``${PN}`` appears at the middle or the
4901 end of a name, problems occur.
4902
4903- The :term:`TARGET_VENDOR`
4904 value under Multilib will be extended to "-vendormlmultilib" (e.g.
4905 "-pokymllib32" for a "lib32" Multilib with Poky). The reason for this
4906 slightly unwieldy contraction is that any "-" characters in the
4907 vendor string presently break Autoconf's ``config.sub``, and other
4908 separators are problematic for different reasons.
4909
William A. Kennington IIIac69b482021-06-02 12:28:27 -07004910Here are the implementation details for the RPM Package Management System:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004911
4912- A unique architecture is defined for the Multilib packages, along
4913 with creating a unique deploy folder under ``tmp/deploy/rpm`` in the
4914 :term:`Build Directory`. For
4915 example, consider ``lib32`` in a ``qemux86-64`` image. The possible
4916 architectures in the system are "all", "qemux86_64",
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004917 "lib32:qemux86_64", and "lib32:x86".
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004918
4919- The ``${MLPREFIX}`` variable is stripped from ``${PN}`` during RPM
4920 packaging. The naming for a normal RPM package and a Multilib RPM
4921 package in a ``qemux86-64`` system resolves to something similar to
4922 ``bash-4.1-r2.x86_64.rpm`` and ``bash-4.1.r2.lib32_x86.rpm``,
4923 respectively.
4924
4925- When installing a Multilib image, the RPM backend first installs the
4926 base image and then installs the Multilib libraries.
4927
4928- The build system relies on RPM to resolve the identical files in the
4929 two (or more) Multilib packages.
4930
William A. Kennington IIIac69b482021-06-02 12:28:27 -07004931Here are the implementation details for the IPK Package Management System:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004932
4933- The ``${MLPREFIX}`` is not stripped from ``${PN}`` during IPK
4934 packaging. The naming for a normal RPM package and a Multilib IPK
4935 package in a ``qemux86-64`` system resolves to something like
Patrick Williams0ca19cc2021-08-16 14:03:13 -05004936 ``bash_4.1-r2.x86_64.ipk`` and ``lib32-bash_4.1-rw:x86.ipk``,
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004937 respectively.
4938
4939- The IPK deploy folder is not modified with ``${MLPREFIX}`` because
4940 packages with and without the Multilib feature can exist in the same
4941 folder due to the ``${PN}`` differences.
4942
4943- IPK defines a sanity check for Multilib installation using certain
4944 rules for file comparison, overridden, etc.
4945
4946Installing Multiple Versions of the Same Library
4947------------------------------------------------
4948
William A. Kennington IIIac69b482021-06-02 12:28:27 -07004949There are be situations where you need to install and use multiple versions
4950of the same library on the same system at the same time. This
4951almost always happens when a library API changes and you have
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004952multiple pieces of software that depend on the separate versions of the
4953library. To accommodate these situations, you can install multiple
4954versions of the same library in parallel on the same system.
4955
4956The process is straightforward as long as the libraries use proper
4957versioning. With properly versioned libraries, all you need to do to
4958individually specify the libraries is create separate, appropriately
4959named recipes where the :term:`PN` part of
4960the name includes a portion that differentiates each library version
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004961(e.g. the major part of the version number). Thus, instead of having a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004962single recipe that loads one version of a library (e.g. ``clutter``),
4963you provide multiple recipes that result in different versions of the
4964libraries you want. As an example, the following two recipes would allow
4965the two separate versions of the ``clutter`` library to co-exist on the
4966same system:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004967
4968.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004969
4970 clutter-1.6_1.6.20.bb
4971 clutter-1.8_1.8.4.bb
4972
4973Additionally, if
4974you have other recipes that depend on a given library, you need to use
4975the :term:`DEPENDS` variable to
4976create the dependency. Continuing with the same example, if you want to
4977have a recipe depend on the 1.8 version of the ``clutter`` library, use
Andrew Geisslerc926e172021-05-07 16:11:35 -05004978the following in your recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004979
4980 DEPENDS = "clutter-1.8"
4981
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00004982Working with Pre-Built Libraries
4983================================
4984
4985Introduction
4986-------------
4987
4988Some library vendors do not release source code for their software but do
4989release pre-built binaries. When shared libraries are built, they should
4990be versioned (see `this article
4991<https://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html>`__
4992for some background), but sometimes this is not done.
4993
4994To summarize, a versioned library must meet two conditions:
4995
4996#. The filename must have the version appended, for example: ``libfoo.so.1.2.3``.
4997#. The library must have the ELF tag ``SONAME`` set to the major version
4998 of the library, for example: ``libfoo.so.1``. You can check this by
4999 running ``readelf -d filename | grep SONAME``.
5000
5001This section shows how to deal with both versioned and unversioned
5002pre-built libraries.
5003
5004Versioned Libraries
5005-------------------
5006
5007In this example we work with pre-built libraries for the FT4222H USB I/O chip.
5008Libraries are built for several target architecture variants and packaged in
5009an archive as follows::
5010
5011 ├── build-arm-hisiv300
5012 │   └── libft4222.so.1.4.4.44
5013 ├── build-arm-v5-sf
5014 │   └── libft4222.so.1.4.4.44
5015 ├── build-arm-v6-hf
5016 │   └── libft4222.so.1.4.4.44
5017 ├── build-arm-v7-hf
5018 │   └── libft4222.so.1.4.4.44
5019 ├── build-arm-v8
5020 │   └── libft4222.so.1.4.4.44
5021 ├── build-i386
5022 │   └── libft4222.so.1.4.4.44
5023 ├── build-i486
5024 │   └── libft4222.so.1.4.4.44
5025 ├── build-mips-eglibc-hf
5026 │   └── libft4222.so.1.4.4.44
5027 ├── build-pentium
5028 │   └── libft4222.so.1.4.4.44
5029 ├── build-x86_64
5030 │   └── libft4222.so.1.4.4.44
5031 ├── examples
5032 │   ├── get-version.c
5033 │   ├── i2cm.c
5034 │   ├── spim.c
5035 │   └── spis.c
5036 ├── ftd2xx.h
5037 ├── install4222.sh
5038 ├── libft4222.h
5039 ├── ReadMe.txt
5040 └── WinTypes.h
5041
5042To write a recipe to use such a library in your system:
5043
5044- The vendor will probably have a proprietary licence, so set
5045 :term:`LICENSE_FLAGS` in your recipe.
5046- The vendor provides a tarball containing libraries so set :term:`SRC_URI`
5047 appropriately.
5048- Set :term:`COMPATIBLE_HOST` so that the recipe cannot be used with an
5049 unsupported architecture. In the following example, we only support the 32
5050 and 64 bit variants of the ``x86`` architecture.
5051- As the vendor provides versioned libraries, we can use ``oe_soinstall``
5052 from :ref:`ref-classes-utils` to install the shared library and create
5053 symbolic links. If the vendor does not do this, we need to follow the
5054 non-versioned library guidelines in the next section.
5055- As the vendor likely used :term:`LDFLAGS` different from those in your Yocto
5056 Project build, disable the corresponding checks by adding ``ldflags``
5057 to :term:`INSANE_SKIP`.
5058- The vendor will typically ship release builds without debugging symbols.
5059 Avoid errors by preventing the packaging task from stripping out the symbols
5060 and adding them to a separate debug package. This is done by setting the
5061 ``INHIBIT_`` flags shown below.
5062
5063The complete recipe would look like this::
5064
5065 SUMMARY = "FTDI FT4222H Library"
5066 SECTION = "libs"
5067 LICENSE_FLAGS = "ftdi"
5068 LICENSE = "CLOSED"
5069
5070 COMPATIBLE_HOST = "(i.86|x86_64).*-linux"
5071
5072 # Sources available in a .tgz file in .zip archive
5073 # at https://ftdichip.com/wp-content/uploads/2021/01/libft4222-linux-1.4.4.44.zip
5074 # Found on https://ftdichip.com/software-examples/ft4222h-software-examples/
5075 # Since dealing with this particular type of archive is out of topic here,
5076 # we use a local link.
5077 SRC_URI = "file://libft4222-linux-${PV}.tgz"
5078
5079 S = "${WORKDIR}"
5080
5081 ARCH_DIR:x86-64 = "build-x86_64"
5082 ARCH_DIR:i586 = "build-i386"
5083 ARCH_DIR:i686 = "build-i386"
5084
5085 INSANE_SKIP:${PN} = "ldflags"
5086 INHIBIT_PACKAGE_STRIP = "1"
5087 INHIBIT_SYSROOT_STRIP = "1"
5088 INHIBIT_PACKAGE_DEBUG_SPLIT = "1"
5089
5090 do_install () {
5091 install -m 0755 -d ${D}${libdir}
5092 oe_soinstall ${S}/${ARCH_DIR}/libft4222.so.${PV} ${D}${libdir}
5093 install -d ${D}${includedir}
5094 install -m 0755 ${S}/*.h ${D}${includedir}
5095 }
5096
5097If the precompiled binaries are not statically linked and have dependencies on
5098other libraries, then by adding those libraries to :term:`DEPENDS`, the linking
5099can be examined and the appropriate :term:`RDEPENDS` automatically added.
5100
5101Non-Versioned Libraries
5102-----------------------
5103
5104Some Background
5105~~~~~~~~~~~~~~~
5106
5107Libraries in Linux systems are generally versioned so that it is possible
5108to have multiple versions of the same library installed, which eases upgrades
5109and support for older software. For example, suppose that in a versioned
5110library, an actual library is called ``libfoo.so.1.2``, a symbolic link named
5111``libfoo.so.1`` points to ``libfoo.so.1.2``, and a symbolic link named
5112``libfoo.so`` points to ``libfoo.so.1.2``. Given these conditions, when you
5113link a binary against a library, you typically provide the unversioned file
5114name (i.e. ``-lfoo`` to the linker). However, the linker follows the symbolic
5115link and actually links against the versioned filename. The unversioned symbolic
5116link is only used at development time. Consequently, the library is packaged
5117along with the headers in the development package ``${PN}-dev`` along with the
5118actual library and versioned symbolic links in ``${PN}``. Because versioned
5119libraries are far more common than unversioned libraries, the default packaging
5120rules assume versioned libraries.
5121
5122Yocto Library Packaging Overview
5123~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5124
5125It follows that packaging an unversioned library requires a bit of work in the
5126recipe. By default, ``libfoo.so`` gets packaged into ``${PN}-dev``, which
5127triggers a QA warning that a non-symlink library is in a ``-dev`` package,
5128and binaries in the same recipe link to the library in ``${PN}-dev``,
5129which triggers more QA warnings. To solve this problem, you need to package the
5130unversioned library into ``${PN}`` where it belongs. The following are the abridged
5131default :term:`FILES` variables in ``bitbake.conf``::
5132
5133 SOLIBS = ".so.*"
5134 SOLIBSDEV = ".so"
5135 FILES_${PN} = "... ${libdir}/lib*${SOLIBS} ..."
5136 FILES_SOLIBSDEV ?= "... ${libdir}/lib*${SOLIBSDEV} ..."
5137 FILES_${PN}-dev = "... ${FILES_SOLIBSDEV} ..."
5138
5139:term:`SOLIBS` defines a pattern that matches real shared object libraries.
5140:term:`SOLIBSDEV` matches the development form (unversioned symlink). These two
5141variables are then used in ``FILES:${PN}`` and ``FILES:${PN}-dev``, which puts
5142the real libraries into ``${PN}`` and the unversioned symbolic link into ``${PN}-dev``.
5143To package unversioned libraries, you need to modify the variables in the recipe
5144as follows::
5145
5146 SOLIBS = ".so"
5147 FILES_SOLIBSDEV = ""
5148
5149The modifications cause the ``.so`` file to be the real library
5150and unset :term:`FILES_SOLIBSDEV` so that no libraries get packaged into
5151``${PN}-dev``. The changes are required because unless :term:`PACKAGES` is changed,
5152``${PN}-dev`` collects files before `${PN}`. ``${PN}-dev`` must not collect any of
5153the files you want in ``${PN}``.
5154
5155Finally, loadable modules, essentially unversioned libraries that are linked
5156at runtime using ``dlopen()`` instead of at build time, should generally be
5157installed in a private directory. However, if they are installed in ``${libdir}``,
5158then the modules can be treated as unversioned libraries.
5159
5160Example
5161~~~~~~~
5162
5163The example below installs an unversioned x86-64 pre-built library named
5164``libfoo.so``. The :term:`COMPATIBLE_HOST` variable limits recipes to the
5165x86-64 architecture while the :term:`INSANE_SKIP`, :term:`INHIBIT_PACKAGE_STRIP`
5166and :term:`INHIBIT_SYSROOT_STRIP` variables are all set as in the above
5167versioned library example. The "magic" is setting the :term:`SOLIBS` and
5168:term:`FILES_SOLIBSDEV` variables as explained above::
5169
5170 SUMMARY = "libfoo sample recipe"
5171 SECTION = "libs"
5172 LICENSE = "CLOSED"
5173
5174 SRC_URI = "file://libfoo.so"
5175
5176 COMPATIBLE_HOST = "x86_64.*-linux"
5177
5178 INSANE_SKIP:${PN} = "ldflags"
5179 INHIBIT_PACKAGE_STRIP = "1"
5180 INHIBIT_SYSROOT_STRIP = "1"
5181 SOLIBS = ".so"
5182 FILES_SOLIBSDEV = ""
5183
5184 do_install () {
5185 install -d ${D}${libdir}
5186 install -m 0755 ${WORKDIR}/libfoo.so ${D}${libdir}
5187 }
5188
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005189Using x32 psABI
5190===============
5191
5192x32 processor-specific Application Binary Interface (`x32
5193psABI <https://software.intel.com/en-us/node/628948>`__) is a native
519432-bit processor-specific ABI for Intel 64 (x86-64) architectures. An
5195ABI defines the calling conventions between functions in a processing
5196environment. The interface determines what registers are used and what
5197the sizes are for various C data types.
5198
5199Some processing environments prefer using 32-bit applications even when
5200running on Intel 64-bit platforms. Consider the i386 psABI, which is a
5201very old 32-bit ABI for Intel 64-bit platforms. The i386 psABI does not
5202provide efficient use and access of the Intel 64-bit processor
5203resources, leaving the system underutilized. Now consider the x86_64
5204psABI. This ABI is newer and uses 64-bits for data sizes and program
5205pointers. The extra bits increase the footprint size of the programs,
5206libraries, and also increases the memory and file system size
5207requirements. Executing under the x32 psABI enables user programs to
5208utilize CPU and system resources more efficiently while keeping the
5209memory footprint of the applications low. Extra bits are used for
5210registers but not for addressing mechanisms.
5211
5212The Yocto Project supports the final specifications of x32 psABI as
5213follows:
5214
5215- You can create packages and images in x32 psABI format on x86_64
5216 architecture targets.
5217
5218- You can successfully build recipes with the x32 toolchain.
5219
5220- You can create and boot ``core-image-minimal`` and
5221 ``core-image-sato`` images.
5222
William A. Kennington IIIac69b482021-06-02 12:28:27 -07005223- There is RPM Package Manager (RPM) support for x32 binaries.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005224
William A. Kennington IIIac69b482021-06-02 12:28:27 -07005225- There is support for large images.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005226
5227To use the x32 psABI, you need to edit your ``conf/local.conf``
Andrew Geisslerc926e172021-05-07 16:11:35 -05005228configuration file as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005229
5230 MACHINE = "qemux86-64"
5231 DEFAULTTUNE = "x86-64-x32"
Patrick Williams0ca19cc2021-08-16 14:03:13 -05005232 baselib = "${@d.getVar('BASE_LIB:tune-' + (d.getVar('DEFAULTTUNE') \
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005233 or 'INVALID')) or 'lib'}"
5234
5235Once you have set
5236up your configuration file, use BitBake to build an image that supports
Andrew Geisslerc926e172021-05-07 16:11:35 -05005237the x32 psABI. Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005238
5239 $ bitbake core-image-sato
5240
5241Enabling GObject Introspection Support
5242======================================
5243
Andrew Geissler595f6302022-01-24 19:11:47 +00005244`GObject introspection <https://gi.readthedocs.io/en/latest/>`__
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005245is the standard mechanism for accessing GObject-based software from
5246runtime environments. GObject is a feature of the GLib library that
5247provides an object framework for the GNOME desktop and related software.
5248GObject Introspection adds information to GObject that allows objects
5249created within it to be represented across different programming
5250languages. If you want to construct GStreamer pipelines using Python, or
5251control UPnP infrastructure using Javascript and GUPnP, GObject
5252introspection is the only way to do it.
5253
5254This section describes the Yocto Project support for generating and
5255packaging GObject introspection data. GObject introspection data is a
Andrew Geissler595f6302022-01-24 19:11:47 +00005256description of the API provided by libraries built on top of the GLib
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005257framework, and, in particular, that framework's GObject mechanism.
5258GObject Introspection Repository (GIR) files go to ``-dev`` packages,
5259``typelib`` files go to main packages as they are packaged together with
5260libraries that are introspected.
5261
5262The data is generated when building such a library, by linking the
5263library with a small executable binary that asks the library to describe
5264itself, and then executing the binary and processing its output.
5265
5266Generating this data in a cross-compilation environment is difficult
5267because the library is produced for the target architecture, but its
5268code needs to be executed on the build host. This problem is solved with
5269the OpenEmbedded build system by running the code through QEMU, which
5270allows precisely that. Unfortunately, QEMU does not always work
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05005271perfectly as mentioned in the ":ref:`dev-manual/common-tasks:known issues`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005272section.
5273
5274Enabling the Generation of Introspection Data
5275---------------------------------------------
5276
5277Enabling the generation of introspection data (GIR files) in your
5278library package involves the following:
5279
52801. Inherit the
5281 :ref:`gobject-introspection <ref-classes-gobject-introspection>`
5282 class.
5283
52842. Make sure introspection is not disabled anywhere in the recipe or
5285 from anything the recipe includes. Also, make sure that
5286 "gobject-introspection-data" is not in
5287 :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`
5288 and that "qemu-usermode" is not in
5289 :term:`MACHINE_FEATURES_BACKFILL_CONSIDERED`.
William A. Kennington IIIac69b482021-06-02 12:28:27 -07005290 In either of these conditions, nothing will happen.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005291
52923. Try to build the recipe. If you encounter build errors that look like
5293 something is unable to find ``.so`` libraries, check where these
5294 libraries are located in the source tree and add the following to the
Andrew Geisslerc926e172021-05-07 16:11:35 -05005295 recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005296
5297 GIR_EXTRA_LIBS_PATH = "${B}/something/.libs"
5298
5299 .. note::
5300
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005301 See recipes in the ``oe-core`` repository that use that
Andrew Geissler595f6302022-01-24 19:11:47 +00005302 :term:`GIR_EXTRA_LIBS_PATH` variable as an example.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005303
53044. Look for any other errors, which probably mean that introspection
5305 support in a package is not entirely standard, and thus breaks down
5306 in a cross-compilation environment. For such cases, custom-made fixes
5307 are needed. A good place to ask and receive help in these cases is
5308 the :ref:`Yocto Project mailing
5309 lists <resources-mailinglist>`.
5310
5311.. note::
5312
5313 Using a library that no longer builds against the latest Yocto
5314 Project release and prints introspection related errors is a good
5315 candidate for the previous procedure.
5316
5317Disabling the Generation of Introspection Data
5318----------------------------------------------
5319
5320You might find that you do not want to generate introspection data. Or,
5321perhaps QEMU does not work on your build host and target architecture
5322combination. If so, you can use either of the following methods to
5323disable GIR file generations:
5324
Andrew Geisslerc926e172021-05-07 16:11:35 -05005325- Add the following to your distro configuration::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005326
5327 DISTRO_FEATURES_BACKFILL_CONSIDERED = "gobject-introspection-data"
5328
5329 Adding this statement disables generating introspection data using
5330 QEMU but will still enable building introspection tools and libraries
5331 (i.e. building them does not require the use of QEMU).
5332
Andrew Geisslerc926e172021-05-07 16:11:35 -05005333- Add the following to your machine configuration::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005334
5335 MACHINE_FEATURES_BACKFILL_CONSIDERED = "qemu-usermode"
5336
5337 Adding this statement disables the use of QEMU when building packages for your
5338 machine. Currently, this feature is used only by introspection
5339 recipes and has the same effect as the previously described option.
5340
5341 .. note::
5342
5343 Future releases of the Yocto Project might have other features
5344 affected by this option.
5345
5346If you disable introspection data, you can still obtain it through other
5347means such as copying the data from a suitable sysroot, or by generating
5348it on the target hardware. The OpenEmbedded build system does not
5349currently provide specific support for these techniques.
5350
5351Testing that Introspection Works in an Image
5352--------------------------------------------
5353
5354Use the following procedure to test if generating introspection data is
5355working in an image:
5356
53571. Make sure that "gobject-introspection-data" is not in
5358 :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`
5359 and that "qemu-usermode" is not in
5360 :term:`MACHINE_FEATURES_BACKFILL_CONSIDERED`.
5361
53622. Build ``core-image-sato``.
5363
53643. Launch a Terminal and then start Python in the terminal.
5365
Andrew Geisslerc926e172021-05-07 16:11:35 -050053664. Enter the following in the terminal::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005367
5368 >>> from gi.repository import GLib
5369 >>> GLib.get_host_name()
5370
53715. For something a little more advanced, enter the following see:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005372 https://python-gtk-3-tutorial.readthedocs.io/en/latest/introduction.html
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005373
5374Known Issues
5375------------
5376
William A. Kennington IIIac69b482021-06-02 12:28:27 -07005377Here are know issues in GObject Introspection Support:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005378
5379- ``qemu-ppc64`` immediately crashes. Consequently, you cannot build
5380 introspection data on that architecture.
5381
5382- x32 is not supported by QEMU. Consequently, introspection data is
5383 disabled.
5384
5385- musl causes transient GLib binaries to crash on assertion failures.
5386 Consequently, generating introspection data is disabled.
5387
5388- Because QEMU is not able to run the binaries correctly, introspection
5389 is disabled for some specific packages under specific architectures
5390 (e.g. ``gcr``, ``libsecret``, and ``webkit``).
5391
5392- QEMU usermode might not work properly when running 64-bit binaries
5393 under 32-bit host machines. In particular, "qemumips64" is known to
5394 not work under i686.
5395
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005396Optionally Using an External Toolchain
5397======================================
5398
5399You might want to use an external toolchain as part of your development.
5400If this is the case, the fundamental steps you need to accomplish are as
5401follows:
5402
5403- Understand where the installed toolchain resides. For cases where you
5404 need to build the external toolchain, you would need to take separate
5405 steps to build and install the toolchain.
5406
5407- Make sure you add the layer that contains the toolchain to your
5408 ``bblayers.conf`` file through the
5409 :term:`BBLAYERS` variable.
5410
5411- Set the ``EXTERNAL_TOOLCHAIN`` variable in your ``local.conf`` file
5412 to the location in which you installed the toolchain.
5413
5414A good example of an external toolchain used with the Yocto Project is
5415Mentor Graphics Sourcery G++ Toolchain. You can see information on how
5416to use that particular layer in the ``README`` file at
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005417https://github.com/MentorEmbedded/meta-sourcery/. You can find
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005418further information by reading about the
5419:term:`TCMODE` variable in the Yocto
5420Project Reference Manual's variable glossary.
5421
5422Creating Partitioned Images Using Wic
5423=====================================
5424
5425Creating an image for a particular hardware target using the
5426OpenEmbedded build system does not necessarily mean you can boot that
5427image as is on your device. Physical devices accept and boot images in
5428various ways depending on the specifics of the device. Usually,
5429information about the hardware can tell you what image format the device
5430requires. Should your device require multiple partitions on an SD card,
5431flash, or an HDD, you can use the OpenEmbedded Image Creator, Wic, to
5432create the properly partitioned image.
5433
5434The ``wic`` command generates partitioned images from existing
5435OpenEmbedded build artifacts. Image generation is driven by partitioning
Andrew Geisslerd5838332022-05-27 11:33:10 -05005436commands contained in an OpenEmbedded kickstart file (``.wks``)
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005437specified either directly on the command line or as one of a selection
5438of canned kickstart files as shown with the ``wic list images`` command
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05005439in the
5440":ref:`dev-manual/common-tasks:generate an image using an existing kickstart file`"
5441section. When you apply the command to a given set of build artifacts, the
5442result is an image or set of images that can be directly written onto media and
5443used on a particular system.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005444
5445.. note::
5446
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005447 For a kickstart file reference, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06005448 ":ref:`ref-manual/kickstart:openembedded kickstart (\`\`.wks\`\`) reference`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005449 Chapter in the Yocto Project Reference Manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005450
5451The ``wic`` command and the infrastructure it is based on is by
5452definition incomplete. The purpose of the command is to allow the
5453generation of customized images, and as such, was designed to be
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05005454completely extensible through a plugin interface. See the
5455":ref:`dev-manual/common-tasks:using the wic plugin interface`" section
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005456for information on these plugins.
5457
5458This section provides some background information on Wic, describes what
5459you need to have in place to run the tool, provides instruction on how
5460to use the Wic utility, provides information on using the Wic plugins
5461interface, and provides several examples that show how to use Wic.
5462
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005463Background
5464----------
5465
5466This section provides some background on the Wic utility. While none of
5467this information is required to use Wic, you might find it interesting.
5468
5469- The name "Wic" is derived from OpenEmbedded Image Creator (oeic). The
5470 "oe" diphthong in "oeic" was promoted to the letter "w", because
5471 "oeic" is both difficult to remember and to pronounce.
5472
5473- Wic is loosely based on the Meego Image Creator (``mic``) framework.
5474 The Wic implementation has been heavily modified to make direct use
5475 of OpenEmbedded build artifacts instead of package installation and
5476 configuration, which are already incorporated within the OpenEmbedded
5477 artifacts.
5478
5479- Wic is a completely independent standalone utility that initially
5480 provides easier-to-use and more flexible replacements for an existing
5481 functionality in OE-Core's
5482 :ref:`image-live <ref-classes-image-live>`
5483 class. The difference between Wic and those examples is that with Wic
5484 the functionality of those scripts is implemented by a
5485 general-purpose partitioning language, which is based on Redhat
5486 kickstart syntax.
5487
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005488Requirements
5489------------
5490
5491In order to use the Wic utility with the OpenEmbedded Build system, your
5492system needs to meet the following requirements:
5493
5494- The Linux distribution on your development host must support the
5495 Yocto Project. See the ":ref:`detailed-supported-distros`"
5496 section in the Yocto Project Reference Manual for the list of
5497 distributions that support the Yocto Project.
5498
5499- The standard system utilities, such as ``cp``, must be installed on
5500 your development host system.
5501
5502- You must have sourced the build environment setup script (i.e.
5503 :ref:`structure-core-script`) found in the
5504 :term:`Build Directory`.
5505
5506- You need to have the build artifacts already available, which
5507 typically means that you must have already created an image using the
Andrew Geisslerd5838332022-05-27 11:33:10 -05005508 OpenEmbedded build system (e.g. ``core-image-minimal``). While it
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005509 might seem redundant to generate an image in order to create an image
5510 using Wic, the current version of Wic requires the artifacts in the
5511 form generated by the OpenEmbedded build system.
5512
5513- You must build several native tools, which are built to run on the
Andrew Geisslerc926e172021-05-07 16:11:35 -05005514 build system::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005515
5516 $ bitbake parted-native dosfstools-native mtools-native
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005517
5518- Include "wic" as part of the
5519 :term:`IMAGE_FSTYPES`
5520 variable.
5521
5522- Include the name of the :ref:`wic kickstart file <openembedded-kickstart-wks-reference>`
Andrew Geisslerd5838332022-05-27 11:33:10 -05005523 as part of the :term:`WKS_FILE` variable. If multiple candidate files can
5524 be provided by different layers, specify all the possible names through the
5525 :term:`WKS_FILES` variable instead.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005526
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005527Getting Help
5528------------
5529
5530You can get general help for the ``wic`` command by entering the ``wic``
5531command by itself or by entering the command with a help argument as
Andrew Geisslerc926e172021-05-07 16:11:35 -05005532follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005533
5534 $ wic -h
5535 $ wic --help
5536 $ wic help
5537
5538Currently, Wic supports seven commands: ``cp``, ``create``, ``help``,
5539``list``, ``ls``, ``rm``, and ``write``. You can get help for all these
Andrew Geisslerc926e172021-05-07 16:11:35 -05005540commands except "help" by using the following form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005541
5542 $ wic help command
5543
5544For example, the following command returns help for the ``write``
Andrew Geisslerc926e172021-05-07 16:11:35 -05005545command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005546
5547 $ wic help write
5548
5549Wic supports help for three topics: ``overview``, ``plugins``, and
Andrew Geisslerc926e172021-05-07 16:11:35 -05005550``kickstart``. You can get help for any topic using the following form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005551
5552 $ wic help topic
5553
Andrew Geisslerc926e172021-05-07 16:11:35 -05005554For example, the following returns overview help for Wic::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005555
5556 $ wic help overview
5557
William A. Kennington IIIac69b482021-06-02 12:28:27 -07005558There is one additional level of help for Wic. You can get help on
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005559individual images through the ``list`` command. You can use the ``list``
Andrew Geisslerc926e172021-05-07 16:11:35 -05005560command to return the available Wic images as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005561
5562 $ wic list images
5563 genericx86 Create an EFI disk image for genericx86*
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005564 edgerouter Create SD card image for Edgerouter
Andrew Geissler5199d832021-09-24 16:47:35 -05005565 beaglebone-yocto Create SD card image for Beaglebone
5566 qemux86-directdisk Create a qemu machine 'pcbios' direct disk image
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005567 systemd-bootdisk Create an EFI disk image with systemd-boot
5568 mkhybridiso Create a hybrid ISO image
Andrew Geissler5199d832021-09-24 16:47:35 -05005569 mkefidisk Create an EFI disk image
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005570 sdimage-bootpart Create SD card image with a boot partition
5571 directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
Andrew Geissler5199d832021-09-24 16:47:35 -05005572 directdisk Create a 'pcbios' direct disk image
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005573 directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
Andrew Geissler5199d832021-09-24 16:47:35 -05005574 qemuriscv Create qcow2 image for RISC-V QEMU machines
5575 directdisk-gpt Create a 'pcbios' direct disk image
5576 efi-bootdisk
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005577
5578Once you know the list of available
5579Wic images, you can use ``help`` with the command to get help on a
5580particular image. For example, the following command returns help on the
Andrew Geisslerc926e172021-05-07 16:11:35 -05005581"beaglebone-yocto" image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005582
5583 $ wic list beaglebone-yocto help
5584
5585 Creates a partitioned SD card image for Beaglebone.
5586 Boot files are located in the first vfat partition.
5587
5588Operational Modes
5589-----------------
5590
5591You can use Wic in two different modes, depending on how much control
Andrew Geisslerd5838332022-05-27 11:33:10 -05005592you need for specifying the OpenEmbedded build artifacts that are used
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005593for creating the image: Raw and Cooked:
5594
5595- *Raw Mode:* You explicitly specify build artifacts through Wic
5596 command-line arguments.
5597
5598- *Cooked Mode:* The current
5599 :term:`MACHINE` setting and image
5600 name are used to automatically locate and provide the build
5601 artifacts. You just supply a kickstart file and the name of the image
5602 from which to use artifacts.
5603
5604Regardless of the mode you use, you need to have the build artifacts
5605ready and available.
5606
5607Raw Mode
5608~~~~~~~~
5609
5610Running Wic in raw mode allows you to specify all the partitions through
5611the ``wic`` command line. The primary use for raw mode is if you have
5612built your kernel outside of the Yocto Project
5613:term:`Build Directory`. In other words, you
5614can point to arbitrary kernel, root filesystem locations, and so forth.
5615Contrast this behavior with cooked mode where Wic looks in the Build
5616Directory (e.g. ``tmp/deploy/images/``\ machine).
5617
Andrew Geisslerc926e172021-05-07 16:11:35 -05005618The general form of the ``wic`` command in raw mode is::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005619
5620 $ wic create wks_file options ...
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 as described by further options.
5628
5629 optional arguments:
5630 -h, --help show this help message and exit
5631 -o OUTDIR, --outdir OUTDIR
5632 name of directory to create image in
5633 -e IMAGE_NAME, --image-name IMAGE_NAME
5634 name of the image to use the artifacts from e.g. core-
5635 image-sato
5636 -r ROOTFS_DIR, --rootfs-dir ROOTFS_DIR
5637 path to the /rootfs dir to use as the .wks rootfs
5638 source
5639 -b BOOTIMG_DIR, --bootimg-dir BOOTIMG_DIR
5640 path to the dir containing the boot artifacts (e.g.
5641 /EFI or /syslinux dirs) to use as the .wks bootimg
5642 source
5643 -k KERNEL_DIR, --kernel-dir KERNEL_DIR
5644 path to the dir containing the kernel to use in the
5645 .wks bootimg
5646 -n NATIVE_SYSROOT, --native-sysroot NATIVE_SYSROOT
5647 path to the native sysroot containing the tools to use
5648 to build the image
5649 -s, --skip-build-check
5650 skip the build check
5651 -f, --build-rootfs build rootfs
5652 -c {gzip,bzip2,xz}, --compress-with {gzip,bzip2,xz}
5653 compress image with specified compressor
5654 -m, --bmap generate .bmap
5655 --no-fstab-update Do not change fstab file.
5656 -v VARS_DIR, --vars VARS_DIR
5657 directory with <image>.env files that store bitbake
5658 variables
5659 -D, --debug output debug information
5660
5661.. note::
5662
5663 You do not need root privileges to run Wic. In fact, you should not
5664 run as root when using the utility.
5665
5666Cooked Mode
5667~~~~~~~~~~~
5668
5669Running Wic in cooked mode leverages off artifacts in the Build
5670Directory. In other words, you do not have to specify kernel or root
5671filesystem locations as part of the command. All you need to provide is
5672a kickstart file and the name of the image from which to use artifacts
5673by using the "-e" option. Wic looks in the Build Directory (e.g.
5674``tmp/deploy/images/``\ machine) for artifacts.
5675
Andrew Geisslerc926e172021-05-07 16:11:35 -05005676The general form of the ``wic`` command using Cooked Mode is as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005677
5678 $ wic create wks_file -e IMAGE_NAME
5679
5680 Where:
5681
5682 wks_file:
5683 An OpenEmbedded kickstart file. You can provide
5684 your own custom file or use a file from a set of
5685 existing files provided with the Yocto Project
5686 release.
5687
5688 required argument:
5689 -e IMAGE_NAME, --image-name IMAGE_NAME
5690 name of the image to use the artifacts from e.g. core-
5691 image-sato
5692
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005693Using an Existing Kickstart File
5694--------------------------------
5695
5696If you do not want to create your own kickstart file, you can use an
5697existing file provided by the Wic installation. As shipped, kickstart
Andrew Geissler09209ee2020-12-13 08:44:15 -06005698files can be found in the :ref:`overview-manual/development-environment:yocto project source repositories` in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05005699following two locations::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005700
5701 poky/meta-yocto-bsp/wic
5702 poky/scripts/lib/wic/canned-wks
5703
Andrew Geisslerc926e172021-05-07 16:11:35 -05005704Use the following command to list the available kickstart files::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005705
5706 $ wic list images
5707 genericx86 Create an EFI disk image for genericx86*
5708 beaglebone-yocto Create SD card image for Beaglebone
5709 edgerouter Create SD card image for Edgerouter
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05005710 qemux86-directdisk Create a QEMU machine 'pcbios' direct disk image
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005711 directdisk-gpt Create a 'pcbios' direct disk image
5712 mkefidisk Create an EFI disk image
5713 directdisk Create a 'pcbios' direct disk image
5714 systemd-bootdisk Create an EFI disk image with systemd-boot
5715 mkhybridiso Create a hybrid ISO image
5716 sdimage-bootpart Create SD card image with a boot partition
5717 directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
5718 directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
5719
5720When you use an existing file, you
5721do not have to use the ``.wks`` extension. Here is an example in Raw
Andrew Geisslerc926e172021-05-07 16:11:35 -05005722Mode that uses the ``directdisk`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005723
5724 $ wic create directdisk -r rootfs_dir -b bootimg_dir \
5725 -k kernel_dir -n native_sysroot
5726
5727Here are the actual partition language commands used in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05005728``genericx86.wks`` file to generate an image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005729
5730 # short-description: Create an EFI disk image for genericx86*
5731 # long-description: Creates a partitioned EFI disk image for genericx86* machines
5732 part /boot --source bootimg-efi --sourceparams="loader=grub-efi" --ondisk sda --label msdos --active --align 1024
5733 part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid
5734 part swap --ondisk sda --size 44 --label swap1 --fstype=swap
5735
5736 bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=ttyS0,115200 console=tty0"
5737
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005738Using the Wic Plugin Interface
5739------------------------------
5740
5741You can extend and specialize Wic functionality by using Wic plugins.
5742This section explains the Wic plugin interface.
5743
5744.. note::
5745
5746 Wic plugins consist of "source" and "imager" plugins. Imager plugins
5747 are beyond the scope of this section.
5748
5749Source plugins provide a mechanism to customize partition content during
5750the Wic image generation process. You can use source plugins to map
5751values that you specify using ``--source`` commands in kickstart files
5752(i.e. ``*.wks``) to a plugin implementation used to populate a given
5753partition.
5754
5755.. note::
5756
5757 If you use plugins that have build-time dependencies (e.g. native
5758 tools, bootloaders, and so forth) when building a Wic image, you need
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005759 to specify those dependencies using the :term:`WKS_FILE_DEPENDS`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005760 variable.
5761
5762Source plugins are subclasses defined in plugin files. As shipped, the
5763Yocto Project provides several plugin files. You can see the source
5764plugin files that ship with the Yocto Project
Andrew Geissler09209ee2020-12-13 08:44:15 -06005765:yocto_git:`here </poky/tree/scripts/lib/wic/plugins/source>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005766Each of these plugin files contains source plugins that are designed to
5767populate a specific Wic image partition.
5768
5769Source plugins are subclasses of the ``SourcePlugin`` class, which is
5770defined in the ``poky/scripts/lib/wic/pluginbase.py`` file. For example,
5771the ``BootimgEFIPlugin`` source plugin found in the ``bootimg-efi.py``
5772file is a subclass of the ``SourcePlugin`` class, which is found in the
5773``pluginbase.py`` file.
5774
5775You can also implement source plugins in a layer outside of the Source
5776Repositories (external layer). To do so, be sure that your plugin files
5777are located in a directory whose path is
5778``scripts/lib/wic/plugins/source/`` within your external layer. When the
5779plugin files are located there, the source plugins they contain are made
5780available to Wic.
5781
5782When the Wic implementation needs to invoke a partition-specific
5783implementation, it looks for the plugin with the same name as the
5784``--source`` parameter used in the kickstart file given to that
5785partition. For example, if the partition is set up using the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05005786command in a kickstart file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005787
5788 part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024
5789
5790The methods defined as class
5791members of the matching source plugin (i.e. ``bootimg-pcbios``) in the
5792``bootimg-pcbios.py`` plugin file are used.
5793
5794To be more concrete, here is the corresponding plugin definition from
5795the ``bootimg-pcbios.py`` file for the previous command along with an
5796example method called by the Wic implementation when it needs to prepare
Andrew Geisslerc926e172021-05-07 16:11:35 -05005797a partition using an implementation-specific function::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005798
5799 .
5800 .
5801 .
5802 class BootimgPcbiosPlugin(SourcePlugin):
5803 """
5804 Create MBR boot partition and install syslinux on it.
5805 """
5806
5807 name = 'bootimg-pcbios'
5808 .
5809 .
5810 .
5811 @classmethod
5812 def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
5813 oe_builddir, bootimg_dir, kernel_dir,
5814 rootfs_dir, native_sysroot):
5815 """
5816 Called to do the actual content population for a partition i.e. it
5817 'prepares' the partition to be incorporated into the image.
5818 In this case, prepare content for legacy bios boot partition.
5819 """
5820 .
5821 .
5822 .
5823
5824If a
5825subclass (plugin) itself does not implement a particular function, Wic
5826locates and uses the default version in the superclass. It is for this
5827reason that all source plugins are derived from the ``SourcePlugin``
5828class.
5829
5830The ``SourcePlugin`` class defined in the ``pluginbase.py`` file defines
5831a set of methods that source plugins can implement or override. Any
5832plugins (subclass of ``SourcePlugin``) that do not implement a
5833particular method inherit the implementation of the method from the
5834``SourcePlugin`` class. For more information, see the ``SourcePlugin``
5835class in the ``pluginbase.py`` file for details:
5836
5837The following list describes the methods implemented in the
5838``SourcePlugin`` class:
5839
5840- ``do_prepare_partition()``: Called to populate a partition with
5841 actual content. In other words, the method prepares the final
5842 partition image that is incorporated into the disk image.
5843
5844- ``do_configure_partition()``: Called before
5845 ``do_prepare_partition()`` to create custom configuration files for a
5846 partition (e.g. syslinux or grub configuration files).
5847
5848- ``do_install_disk()``: Called after all partitions have been
5849 prepared and assembled into a disk image. This method provides a hook
5850 to allow finalization of a disk image (e.g. writing an MBR).
5851
5852- ``do_stage_partition()``: Special content-staging hook called
5853 before ``do_prepare_partition()``. This method is normally empty.
5854
5855 Typically, a partition just uses the passed-in parameters (e.g. the
5856 unmodified value of ``bootimg_dir``). However, in some cases, things
5857 might need to be more tailored. As an example, certain files might
5858 additionally need to be taken from ``bootimg_dir + /boot``. This hook
5859 allows those files to be staged in a customized fashion.
5860
5861 .. note::
5862
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005863 ``get_bitbake_var()`` allows you to access non-standard variables that
5864 you might want to use for this behavior.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005865
5866You can extend the source plugin mechanism. To add more hooks, create
5867more source plugin methods within ``SourcePlugin`` and the corresponding
5868derived subclasses. The code that calls the plugin methods uses the
5869``plugin.get_source_plugin_methods()`` function to find the method or
5870methods needed by the call. Retrieval of those methods is accomplished
5871by filling up a dict with keys that contain the method names of
5872interest. On success, these will be filled in with the actual methods.
5873See the Wic implementation for examples and details.
5874
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005875Wic Examples
5876------------
5877
5878This section provides several examples that show how to use the Wic
5879utility. All the examples assume the list of requirements in the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05005880":ref:`dev-manual/common-tasks:requirements`" section have been met. The
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005881examples assume the previously generated image is
5882``core-image-minimal``.
5883
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005884Generate an Image using an Existing Kickstart File
5885~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5886
5887This example runs in Cooked Mode and uses the ``mkefidisk`` kickstart
Andrew Geisslerc926e172021-05-07 16:11:35 -05005888file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005889
5890 $ wic create mkefidisk -e core-image-minimal
5891 INFO: Building wic-tools...
5892 .
5893 .
5894 .
5895 INFO: The new image(s) can be found here:
5896 ./mkefidisk-201804191017-sda.direct
5897
5898 The following build artifacts were used to create the image(s):
Andrew Geissler595f6302022-01-24 19:11:47 +00005899 ROOTFS_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
5900 BOOTIMG_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
5901 KERNEL_DIR: /home/stephano/yocto/build/tmp-glibc/deploy/images/qemux86
5902 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 -05005903
5904 INFO: The image(s) were created using OE kickstart file:
Andrew Geissler595f6302022-01-24 19:11:47 +00005905 /home/stephano/yocto/openembedded-core/scripts/lib/wic/canned-wks/mkefidisk.wks
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005906
5907The previous example shows the easiest way to create an image by running
5908in cooked mode and supplying a kickstart file and the "-e" option to
5909point to the existing build artifacts. Your ``local.conf`` file needs to
5910have the :term:`MACHINE` variable set
5911to the machine you are using, which is "qemux86" in this example.
5912
5913Once the image builds, the output provides image location, artifact use,
5914and kickstart file information.
5915
5916.. note::
5917
5918 You should always verify the details provided in the output to make
5919 sure that the image was indeed created exactly as expected.
5920
5921Continuing with the example, you can now write the image from the Build
5922Directory onto a USB stick, or whatever media for which you built your
5923image, and boot from the media. You can write the image by using
Andrew Geisslerc926e172021-05-07 16:11:35 -05005924``bmaptool`` or ``dd``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005925
Andrew Geisslerd5838332022-05-27 11:33:10 -05005926 $ oe-run-native bmap-tools-native bmaptool copy mkefidisk-201804191017-sda.direct /dev/sdX
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005927
5928or ::
5929
5930 $ sudo dd if=mkefidisk-201804191017-sda.direct of=/dev/sdX
5931
5932.. note::
5933
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005934 For more information on how to use the ``bmaptool``
5935 to flash a device with an image, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06005936 ":ref:`dev-manual/common-tasks:flashing images using \`\`bmaptool\`\``"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005937 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005938
5939Using a Modified Kickstart File
5940~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5941
5942Because partitioned image creation is driven by the kickstart file, it
5943is easy to affect image creation by changing the parameters in the file.
5944This next example demonstrates that through modification of the
5945``directdisk-gpt`` kickstart file.
5946
5947As mentioned earlier, you can use the command ``wic list images`` to
5948show the list of existing kickstart files. The directory in which the
5949``directdisk-gpt.wks`` file resides is
5950``scripts/lib/image/canned-wks/``, which is located in the
5951:term:`Source Directory` (e.g. ``poky``).
5952Because available files reside in this directory, you can create and add
5953your own custom files to the directory. Subsequent use of the
5954``wic list images`` command would then include your kickstart files.
5955
5956In this example, the existing ``directdisk-gpt`` file already does most
5957of what is needed. However, for the hardware in this example, the image
5958will need to boot from ``sdb`` instead of ``sda``, which is what the
5959``directdisk-gpt`` kickstart file uses.
5960
5961The example begins by making a copy of the ``directdisk-gpt.wks`` file
5962in the ``scripts/lib/image/canned-wks`` directory and then by changing
5963the lines that specify the target disk from which to boot.
5964::
5965
Andrew Geissler595f6302022-01-24 19:11:47 +00005966 $ cp /home/stephano/yocto/poky/scripts/lib/wic/canned-wks/directdisk-gpt.wks \
5967 /home/stephano/yocto/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005968
5969Next, the example modifies the ``directdisksdb-gpt.wks`` file and
5970changes all instances of "``--ondisk sda``" to "``--ondisk sdb``". The
5971example changes the following two lines and leaves the remaining lines
Andrew Geisslerc926e172021-05-07 16:11:35 -05005972untouched::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005973
5974 part /boot --source bootimg-pcbios --ondisk sdb --label boot --active --align 1024
5975 part / --source rootfs --ondisk sdb --fstype=ext4 --label platform --align 1024 --use-uuid
5976
5977Once the lines are changed, the
5978example generates the ``directdisksdb-gpt`` image. The command points
5979the process at the ``core-image-minimal`` artifacts for the Next Unit of
5980Computing (nuc) :term:`MACHINE` the
5981``local.conf``.
5982::
5983
5984 $ wic create directdisksdb-gpt -e core-image-minimal
5985 INFO: Building wic-tools...
5986 .
5987 .
5988 .
5989 Initialising tasks: 100% |#######################################| Time: 0:00:01
5990 NOTE: Executing SetScene Tasks
5991 NOTE: Executing RunQueue Tasks
5992 NOTE: Tasks Summary: Attempted 1161 tasks of which 1157 didn't need to be rerun and all succeeded.
5993 INFO: Creating image(s)...
5994
5995 INFO: The new image(s) can be found here:
5996 ./directdisksdb-gpt-201710090938-sdb.direct
5997
5998 The following build artifacts were used to create the image(s):
Andrew Geissler595f6302022-01-24 19:11:47 +00005999 ROOTFS_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
6000 BOOTIMG_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
6001 KERNEL_DIR: /home/stephano/yocto/build/tmp-glibc/deploy/images/qemux86
6002 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 -05006003
6004 INFO: The image(s) were created using OE kickstart file:
Andrew Geissler595f6302022-01-24 19:11:47 +00006005 /home/stephano/yocto/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006006
6007Continuing with the example, you can now directly ``dd`` the image to a
6008USB stick, or whatever media for which you built your image, and boot
Andrew Geisslerc926e172021-05-07 16:11:35 -05006009the resulting media::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006010
6011 $ sudo dd if=directdisksdb-gpt-201710090938-sdb.direct of=/dev/sdb
6012 140966+0 records in
6013 140966+0 records out
6014 72174592 bytes (72 MB, 69 MiB) copied, 78.0282 s, 925 kB/s
6015 $ sudo eject /dev/sdb
6016
6017Using a Modified Kickstart File and Running in Raw Mode
6018~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6019
6020This next example manually specifies each build artifact (runs in Raw
6021Mode) and uses a modified kickstart file. The example also uses the
6022``-o`` option to cause Wic to create the output somewhere other than the
Andrew Geisslerc926e172021-05-07 16:11:35 -05006023default output directory, which is the current directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006024
Andrew Geissler595f6302022-01-24 19:11:47 +00006025 $ wic create test.wks -o /home/stephano/testwic \
6026 --rootfs-dir /home/stephano/yocto/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/rootfs \
6027 --bootimg-dir /home/stephano/yocto/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share \
6028 --kernel-dir /home/stephano/yocto/build/tmp/deploy/images/qemux86 \
6029 --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 -05006030
6031 INFO: Creating image(s)...
6032
6033 INFO: The new image(s) can be found here:
6034 /home/stephano/testwic/test-201710091445-sdb.direct
6035
6036 The following build artifacts were used to create the image(s):
Andrew Geissler595f6302022-01-24 19:11:47 +00006037 ROOTFS_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
6038 BOOTIMG_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
6039 KERNEL_DIR: /home/stephano/yocto/build/tmp-glibc/deploy/images/qemux86
6040 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 -05006041
6042 INFO: The image(s) were created using OE kickstart file:
Andrew Geissler595f6302022-01-24 19:11:47 +00006043 test.wks
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006044
6045For this example,
6046:term:`MACHINE` did not have to be
6047specified in the ``local.conf`` file since the artifact is manually
6048specified.
6049
6050Using Wic to Manipulate an Image
6051~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6052
6053Wic image manipulation allows you to shorten turnaround time during
6054image development. For example, you can use Wic to delete the kernel
6055partition of a Wic image and then insert a newly built kernel. This
6056saves you time from having to rebuild the entire image each time you
6057modify the kernel.
6058
6059.. note::
6060
6061 In order to use Wic to manipulate a Wic image as in this example,
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006062 your development machine must have the ``mtools`` package installed.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006063
6064The following example examines the contents of the Wic image, deletes
6065the existing kernel, and then inserts a new kernel:
6066
60671. *List the Partitions:* Use the ``wic ls`` command to list all the
Andrew Geisslerc926e172021-05-07 16:11:35 -05006068 partitions in the Wic image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006069
6070 $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic
6071 Num Start End Size Fstype
6072 1 1048576 25041919 23993344 fat16
6073 2 25165824 72157183 46991360 ext4
6074
6075 The previous output shows two partitions in the
6076 ``core-image-minimal-qemux86.wic`` image.
6077
60782. *Examine a Particular Partition:* Use the ``wic ls`` command again
6079 but in a different form to examine a particular partition.
6080
6081 .. note::
6082
6083 You can get command usage on any Wic command using the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05006084 form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006085
6086 $ wic help command
6087
6088
6089 For example, the following command shows you the various ways to
6090 use the
6091 wic ls
Andrew Geisslerc926e172021-05-07 16:11:35 -05006092 command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006093
6094 $ wic help ls
6095
6096
Andrew Geisslerc926e172021-05-07 16:11:35 -05006097 The following command shows what is in partition one::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006098
6099 $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1
6100 Volume in drive : is boot
6101 Volume Serial Number is E894-1809
6102 Directory for ::/
6103
6104 libcom32 c32 186500 2017-10-09 16:06
6105 libutil c32 24148 2017-10-09 16:06
6106 syslinux cfg 220 2017-10-09 16:06
6107 vesamenu c32 27104 2017-10-09 16:06
6108 vmlinuz 6904608 2017-10-09 16:06
6109 5 files 7 142 580 bytes
6110 16 582 656 bytes free
6111
6112 The previous output shows five files, with the
6113 ``vmlinuz`` being the kernel.
6114
6115 .. note::
6116
6117 If you see the following error, you need to update or create a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006118 ``~/.mtoolsrc`` file and be sure to have the line "mtools_skip_check=1"
Andrew Geisslerc926e172021-05-07 16:11:35 -05006119 in the file. Then, run the Wic command again::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006120
6121 ERROR: _exec_cmd: /usr/bin/mdir -i /tmp/wic-parttfokuwra ::/ returned '1' instead of 0
6122 output: Total number of sectors (47824) not a multiple of sectors per track (32)!
6123 Add mtools_skip_check=1 to your .mtoolsrc file to skip this test
6124
6125
61263. *Remove the Old Kernel:* Use the ``wic rm`` command to remove the
Andrew Geisslerc926e172021-05-07 16:11:35 -05006127 ``vmlinuz`` file (kernel)::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006128
6129 $ wic rm tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
6130
61314. *Add In the New Kernel:* Use the ``wic cp`` command to add the
6132 updated kernel to the Wic image. Depending on how you built your
6133 kernel, it could be in different places. If you used ``devtool`` and
6134 an SDK to build your kernel, it resides in the ``tmp/work`` directory
6135 of the extensible SDK. If you used ``make`` to build the kernel, the
6136 kernel will be in the ``workspace/sources`` area.
6137
6138 The following example assumes ``devtool`` was used to build the
Andrew Geisslerc926e172021-05-07 16:11:35 -05006139 kernel::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006140
Andrew Geissler95ac1b82021-03-31 14:34:31 -05006141 $ 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 \
6142 poky/build/tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006143
6144 Once the new kernel is added back into the image, you can use the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006145 ``dd`` command or :ref:`bmaptool
Andrew Geissler09209ee2020-12-13 08:44:15 -06006146 <dev-manual/common-tasks:flashing images using \`\`bmaptool\`\`>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006147 to flash your wic image onto an SD card or USB stick and test your
6148 target.
6149
6150 .. note::
6151
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006152 Using ``bmaptool`` is generally 10 to 20 times faster than using ``dd``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006153
6154Flashing Images Using ``bmaptool``
6155==================================
6156
6157A fast and easy way to flash an image to a bootable device is to use
6158Bmaptool, which is integrated into the OpenEmbedded build system.
6159Bmaptool is a generic tool that creates a file's block map (bmap) and
6160then uses that map to copy the file. As compared to traditional tools
6161such as dd or cp, Bmaptool can copy (or flash) large files like raw
6162system image files much faster.
6163
6164.. note::
6165
6166 - If you are using Ubuntu or Debian distributions, you can install
6167 the ``bmap-tools`` package using the following command and then
6168 use the tool without specifying ``PATH`` even from the root
Andrew Geisslerc926e172021-05-07 16:11:35 -05006169 account::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006170
Andrew Geisslereff27472021-10-29 15:35:00 -05006171 $ sudo apt install bmap-tools
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006172
6173 - If you are unable to install the ``bmap-tools`` package, you will
Andrew Geisslerc926e172021-05-07 16:11:35 -05006174 need to build Bmaptool before using it. Use the following command::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006175
6176 $ bitbake bmap-tools-native
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006177
6178Following, is an example that shows how to flash a Wic image. Realize
6179that while this example uses a Wic image, you can use Bmaptool to flash
6180any type of image. Use these steps to flash an image using Bmaptool:
6181
61821. *Update your local.conf File:* You need to have the following set
Andrew Geisslerc926e172021-05-07 16:11:35 -05006183 in your ``local.conf`` file before building your image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006184
6185 IMAGE_FSTYPES += "wic wic.bmap"
6186
61872. *Get Your Image:* Either have your image ready (pre-built with the
6188 :term:`IMAGE_FSTYPES`
Andrew Geisslerc926e172021-05-07 16:11:35 -05006189 setting previously mentioned) or take the step to build the image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006190
6191 $ bitbake image
6192
61933. *Flash the Device:* Flash the device with the image by using Bmaptool
6194 depending on your particular setup. The following commands assume the
6195 image resides in the Build Directory's ``deploy/images/`` area:
6196
Andrew Geisslerc926e172021-05-07 16:11:35 -05006197 - If you have write access to the media, use this command form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006198
6199 $ oe-run-native bmap-tools-native bmaptool copy build-directory/tmp/deploy/images/machine/image.wic /dev/sdX
6200
6201 - If you do not have write access to the media, set your permissions
Andrew Geisslerc926e172021-05-07 16:11:35 -05006202 first and then use the same command form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006203
6204 $ sudo chmod 666 /dev/sdX
6205 $ oe-run-native bmap-tools-native bmaptool copy build-directory/tmp/deploy/images/machine/image.wic /dev/sdX
6206
Andrew Geisslerc926e172021-05-07 16:11:35 -05006207For help on the ``bmaptool`` command, use the following command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006208
6209 $ bmaptool --help
6210
6211Making Images More Secure
6212=========================
6213
6214Security is of increasing concern for embedded devices. Consider the
6215issues and problems discussed in just this sampling of work found across
6216the Internet:
6217
6218- *"*\ `Security Risks of Embedded
6219 Systems <https://www.schneier.com/blog/archives/2014/01/security_risks_9.html>`__\ *"*
6220 by Bruce Schneier
6221
6222- *"*\ `Internet Census
6223 2012 <http://census2012.sourceforge.net/paper.html>`__\ *"* by Carna
6224 Botnet
6225
6226- *"*\ `Security Issues for Embedded
Andrew Geisslerd1e89492021-02-12 15:35:20 -06006227 Devices <https://elinux.org/images/6/6f/Security-issues.pdf>`__\ *"*
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006228 by Jake Edge
6229
6230When securing your image is of concern, there are steps, tools, and
6231variables that you can consider to help you reach the security goals you
6232need for your particular device. Not all situations are identical when
6233it comes to making an image secure. Consequently, this section provides
6234some guidance and suggestions for consideration when you want to make
6235your image more secure.
6236
6237.. note::
6238
6239 Because the security requirements and risks are different for every
6240 type of device, this section cannot provide a complete reference on
6241 securing your custom OS. It is strongly recommended that you also
6242 consult other sources of information on embedded Linux system
6243 hardening and on security.
6244
6245General Considerations
6246----------------------
6247
William A. Kennington IIIac69b482021-06-02 12:28:27 -07006248There are general considerations that help you create more secure images.
6249You should consider the following suggestions to make your device
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006250more secure:
6251
6252- Scan additional code you are adding to the system (e.g. application
6253 code) by using static analysis tools. Look for buffer overflows and
6254 other potential security problems.
6255
6256- Pay particular attention to the security for any web-based
6257 administration interface.
6258
6259 Web interfaces typically need to perform administrative functions and
6260 tend to need to run with elevated privileges. Thus, the consequences
6261 resulting from the interface's security becoming compromised can be
6262 serious. Look for common web vulnerabilities such as
6263 cross-site-scripting (XSS), unvalidated inputs, and so forth.
6264
6265 As with system passwords, the default credentials for accessing a
6266 web-based interface should not be the same across all devices. This
6267 is particularly true if the interface is enabled by default as it can
6268 be assumed that many end-users will not change the credentials.
6269
6270- Ensure you can update the software on the device to mitigate
6271 vulnerabilities discovered in the future. This consideration
6272 especially applies when your device is network-enabled.
6273
6274- Ensure you remove or disable debugging functionality before producing
6275 the final image. For information on how to do this, see the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006276 ":ref:`dev-manual/common-tasks:considerations specific to the openembedded build system`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006277 section.
6278
6279- Ensure you have no network services listening that are not needed.
6280
6281- Remove any software from the image that is not needed.
6282
6283- Enable hardware support for secure boot functionality when your
6284 device supports this functionality.
6285
6286Security Flags
6287--------------
6288
6289The Yocto Project has security flags that you can enable that help make
6290your build output more secure. The security flags are in the
6291``meta/conf/distro/include/security_flags.inc`` file in your
6292:term:`Source Directory` (e.g. ``poky``).
6293
6294.. note::
6295
6296 Depending on the recipe, certain security flags are enabled and
6297 disabled by default.
6298
6299Use the following line in your ``local.conf`` file or in your custom
6300distribution configuration file to enable the security compiler and
Andrew Geisslerc926e172021-05-07 16:11:35 -05006301linker flags for your build::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006302
6303 require conf/distro/include/security_flags.inc
6304
6305Considerations Specific to the OpenEmbedded Build System
6306--------------------------------------------------------
6307
6308You can take some steps that are specific to the OpenEmbedded build
6309system to make your images more secure:
6310
6311- Ensure "debug-tweaks" is not one of your selected
6312 :term:`IMAGE_FEATURES`.
6313 When creating a new project, the default is to provide you with an
6314 initial ``local.conf`` file that enables this feature using the
6315 :term:`EXTRA_IMAGE_FEATURES`
Andrew Geisslerc926e172021-05-07 16:11:35 -05006316 variable with the line::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006317
6318 EXTRA_IMAGE_FEATURES = "debug-tweaks"
6319
6320 To disable that feature, simply comment out that line in your
Andrew Geissler09036742021-06-25 14:25:14 -05006321 ``local.conf`` file, or make sure :term:`IMAGE_FEATURES` does not contain
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006322 "debug-tweaks" before producing your final image. Among other things,
6323 leaving this in place sets the root password as blank, which makes
6324 logging in for debugging or inspection easy during development but
6325 also means anyone can easily log in during production.
6326
6327- It is possible to set a root password for the image and also to set
6328 passwords for any extra users you might add (e.g. administrative or
6329 service type users). When you set up passwords for multiple images or
6330 users, you should not duplicate passwords.
6331
6332 To set up passwords, use the
6333 :ref:`extrausers <ref-classes-extrausers>`
6334 class, which is the preferred method. For an example on how to set up
6335 both root and user passwords, see the
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00006336 ":ref:`ref-classes-extrausers`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006337
6338 .. note::
6339
6340 When adding extra user accounts or setting a root password, be
6341 cautious about setting the same password on every device. If you
6342 do this, and the password you have set is exposed, then every
6343 device is now potentially compromised. If you need this access but
6344 want to ensure security, consider setting a different, random
6345 password for each device. Typically, you do this as a separate
6346 step after you deploy the image onto the device.
6347
6348- Consider enabling a Mandatory Access Control (MAC) framework such as
6349 SMACK or SELinux and tuning it appropriately for your device's usage.
6350 You can find more information in the
Andrew Geissler09209ee2020-12-13 08:44:15 -06006351 :yocto_git:`meta-selinux </meta-selinux/>` layer.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006352
6353Tools for Hardening Your Image
6354------------------------------
6355
6356The Yocto Project provides tools for making your image more secure. You
6357can find these tools in the ``meta-security`` layer of the
6358:yocto_git:`Yocto Project Source Repositories <>`.
6359
6360Creating Your Own Distribution
6361==============================
6362
6363When you build an image using the Yocto Project and do not alter any
6364distribution :term:`Metadata`, you are
6365creating a Poky distribution. If you wish to gain more control over
6366package alternative selections, compile-time options, and other
6367low-level configurations, you can create your own distribution.
6368
6369To create your own distribution, the basic steps consist of creating
6370your own distribution layer, creating your own distribution
6371configuration file, and then adding any needed code and Metadata to the
6372layer. The following steps provide some more detail:
6373
6374- *Create a layer for your new distro:* Create your distribution layer
6375 so that you can keep your Metadata and code for the distribution
6376 separate. It is strongly recommended that you create and use your own
6377 layer for configuration and code. Using your own layer as compared to
6378 just placing configurations in a ``local.conf`` configuration file
6379 makes it easier to reproduce the same build configuration when using
6380 multiple build machines. See the
Andrew Geissler09209ee2020-12-13 08:44:15 -06006381 ":ref:`dev-manual/common-tasks:creating a general layer using the \`\`bitbake-layers\`\` script`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006382 section for information on how to quickly set up a layer.
6383
6384- *Create the distribution configuration file:* The distribution
6385 configuration file needs to be created in the ``conf/distro``
6386 directory of your layer. You need to name it using your distribution
6387 name (e.g. ``mydistro.conf``).
6388
6389 .. note::
6390
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006391 The :term:`DISTRO` variable in your ``local.conf`` file determines the
6392 name of your distribution.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006393
6394 You can split out parts of your configuration file into include files
6395 and then "require" them from within your distribution configuration
6396 file. Be sure to place the include files in the
6397 ``conf/distro/include`` directory of your layer. A common example
6398 usage of include files would be to separate out the selection of
6399 desired version and revisions for individual recipes.
6400
6401 Your configuration file needs to set the following required
6402 variables:
6403
6404 - :term:`DISTRO_NAME`
6405
6406 - :term:`DISTRO_VERSION`
6407
6408 These following variables are optional and you typically set them
6409 from the distribution configuration file:
6410
6411 - :term:`DISTRO_FEATURES`
6412
6413 - :term:`DISTRO_EXTRA_RDEPENDS`
6414
6415 - :term:`DISTRO_EXTRA_RRECOMMENDS`
6416
6417 - :term:`TCLIBC`
6418
6419 .. tip::
6420
6421 If you want to base your distribution configuration file on the
6422 very basic configuration from OE-Core, you can use
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006423 ``conf/distro/defaultsetup.conf`` as a reference and just include
6424 variables that differ as compared to ``defaultsetup.conf``.
6425 Alternatively, you can create a distribution configuration file
6426 from scratch using the ``defaultsetup.conf`` file or configuration files
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00006427 from another distribution such as Poky as a reference.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006428
6429- *Provide miscellaneous variables:* Be sure to define any other
6430 variables for which you want to create a default or enforce as part
6431 of the distribution configuration. You can include nearly any
6432 variable from the ``local.conf`` file. The variables you use are not
6433 limited to the list in the previous bulleted item.
6434
6435- *Point to Your distribution configuration file:* In your
6436 ``local.conf`` file in the :term:`Build Directory`,
6437 set your
6438 :term:`DISTRO` variable to point to
6439 your distribution's configuration file. For example, if your
6440 distribution's configuration file is named ``mydistro.conf``, then
Andrew Geisslerc926e172021-05-07 16:11:35 -05006441 you point to it as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006442
6443 DISTRO = "mydistro"
6444
6445- *Add more to the layer if necessary:* Use your layer to hold other
6446 information needed for the distribution:
6447
6448 - Add recipes for installing distro-specific configuration files
6449 that are not already installed by another recipe. If you have
6450 distro-specific configuration files that are included by an
6451 existing recipe, you should add an append file (``.bbappend``) for
6452 those. For general information and recommendations on how to add
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006453 recipes to your layer, see the
6454 ":ref:`dev-manual/common-tasks:creating your own layer`" and
6455 ":ref:`dev-manual/common-tasks:following best practices when creating layers`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006456 sections.
6457
6458 - Add any image recipes that are specific to your distribution.
6459
6460 - Add a ``psplash`` append file for a branded splash screen. For
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006461 information on append files, see the
Patrick Williams0ca19cc2021-08-16 14:03:13 -05006462 ":ref:`dev-manual/common-tasks:appending other layers metadata with your layer`"
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006463 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006464
6465 - Add any other append files to make custom changes that are
6466 specific to individual recipes.
6467
6468Creating a Custom Template Configuration Directory
6469==================================================
6470
6471If you are producing your own customized version of the build system for
Andrew Geissler87f5cff2022-09-30 13:13:31 -05006472use by other users, you might want to provide a custom build configuration
6473that includes all the necessary settings and layers (i.e. ``local.conf`` and
6474``bblayers.conf`` that are created in a new build directory) and a custom
6475message that is shown when setting up the build. This can be done by
6476creating one or more template configuration directories in your
6477custom distribution layer.
6478
6479This can be done by using ``bitbake-layers save-build-conf``::
6480
6481 $ bitbake-layers save-build-conf ../../meta-alex/ test-1
6482 NOTE: Starting bitbake server...
6483 NOTE: Configuration template placed into /srv/work/alex/meta-alex/conf/templates/test-1
6484 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
6485 You can try out the configuration with
6486 TEMPLATECONF=/srv/work/alex/meta-alex/conf/templates/test-1 . /srv/work/alex/poky/oe-init-build-env build-try-test-1
6487
6488The above command takes the config files from the currently active build directory under ``conf``,
6489replaces site-specific paths in ``bblayers.conf`` with ``##OECORE##``-relative paths, and copies
6490the config files into a specified layer under a specified template name.
6491
6492To use those saved templates as a starting point for a build, users should point
6493to one of them with :term:`TEMPLATECONF` environment variable::
6494
6495 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 -05006496
6497The OpenEmbedded build system uses the environment variable
Andrew Geisslerd5838332022-05-27 11:33:10 -05006498:term:`TEMPLATECONF` to locate the directory from which it gathers
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006499configuration information that ultimately ends up in the
6500:term:`Build Directory` ``conf`` directory.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006501
Andrew Geissler87f5cff2022-09-30 13:13:31 -05006502If :term:`TEMPLATECONF` is not set, the default value is obtained
6503from ``.templateconf`` file that is read from the same directory as
6504``oe-init-build-env`` script. For the Poky reference distribution this
6505would be::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006506
Andrew Geissler87f5cff2022-09-30 13:13:31 -05006507 TEMPLATECONF=${TEMPLATECONF:-meta-poky/conf/templates/default}
6508
6509If you look at a configuration template directory, you will
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006510see the ``bblayers.conf.sample``, ``local.conf.sample``, and
6511``conf-notes.txt`` files. The build system uses these files to form the
Andrew Geissler87f5cff2022-09-30 13:13:31 -05006512respective ``bblayers.conf`` file, ``local.conf`` file, and show
6513users a note about the build they're setting up
6514when running the ``oe-init-build-env`` setup script. These can be
6515edited further if needed to improve or change the build configurations
6516available to the users.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006517
Andrew Geissler595f6302022-01-24 19:11:47 +00006518Conserving Disk Space
6519=====================
6520
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006521Conserving Disk Space During Builds
Andrew Geissler595f6302022-01-24 19:11:47 +00006522-----------------------------------
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006523
6524To help conserve disk space during builds, you can add the following
6525statement to your project's ``local.conf`` configuration file found in
Andrew Geisslerc926e172021-05-07 16:11:35 -05006526the :term:`Build Directory`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006527
6528 INHERIT += "rm_work"
6529
6530Adding this statement deletes the work directory used for
6531building a recipe once the recipe is built. For more information on
6532"rm_work", see the
6533:ref:`rm_work <ref-classes-rm-work>` class in the
6534Yocto Project Reference Manual.
6535
Andrew Geissler595f6302022-01-24 19:11:47 +00006536Purging Duplicate Shared State Cache Files
6537-------------------------------------------
6538
6539After multiple build iterations, the Shared State (sstate) cache can contain
6540duplicate cache files for a given package, while only the most recent one
6541is likely to be reusable. The following command purges all but the
6542newest sstate cache file for each package::
6543
6544 sstate-cache-management.sh --remove-duplicated --cache-dir=build/sstate-cache
6545
6546This command will ask you to confirm the deletions it identifies.
6547
Patrick Williams92b42cb2022-09-03 06:53:57 -05006548.. note::
Andrew Geissler595f6302022-01-24 19:11:47 +00006549
6550 The duplicated sstate cache files of one package must have the same
6551 architecture, which means that sstate cache files with multiple
6552 architectures are not considered as duplicate.
6553
6554Run ``sstate-cache-management.sh`` for more details about this script.
6555
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006556Working with Packages
6557=====================
6558
6559This section describes a few tasks that involve packages:
6560
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006561- :ref:`dev-manual/common-tasks:excluding packages from an image`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006562
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006563- :ref:`dev-manual/common-tasks:incrementing a package version`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006564
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006565- :ref:`dev-manual/common-tasks:handling optional module packaging`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006566
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006567- :ref:`dev-manual/common-tasks:using runtime package management`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006568
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006569- :ref:`dev-manual/common-tasks:generating and using signed packages`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006570
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006571- :ref:`Setting up and running package test
6572 (ptest) <dev-manual/common-tasks:testing packages with ptest>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006573
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006574- :ref:`dev-manual/common-tasks:creating node package manager (npm) packages`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006575
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006576- :ref:`dev-manual/common-tasks:adding custom metadata to packages`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006577
6578Excluding Packages from an Image
6579--------------------------------
6580
6581You might find it necessary to prevent specific packages from being
6582installed into an image. If so, you can use several variables to direct
6583the build system to essentially ignore installing recommended packages
6584or to not install a package at all.
6585
6586The following list introduces variables you can use to prevent packages
6587from being installed into your image. Each of these variables only works
William A. Kennington IIIac69b482021-06-02 12:28:27 -07006588with IPK and RPM package types, not for Debian packages.
6589Also, you can use these variables from your ``local.conf`` file
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006590or attach them to a specific image recipe by using a recipe name
6591override. For more detail on the variables, see the descriptions in the
6592Yocto Project Reference Manual's glossary chapter.
6593
6594- :term:`BAD_RECOMMENDATIONS`:
6595 Use this variable to specify "recommended-only" packages that you do
6596 not want installed.
6597
6598- :term:`NO_RECOMMENDATIONS`:
6599 Use this variable to prevent all "recommended-only" packages from
6600 being installed.
6601
6602- :term:`PACKAGE_EXCLUDE`:
6603 Use this variable to prevent specific packages from being installed
6604 regardless of whether they are "recommended-only" or not. You need to
6605 realize that the build process could fail with an error when you
6606 prevent the installation of a package whose presence is required by
6607 an installed package.
6608
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006609Incrementing a Package Version
6610------------------------------
6611
6612This section provides some background on how binary package versioning
6613is accomplished and presents some of the services, variables, and
6614terminology involved.
6615
6616In order to understand binary package versioning, you need to consider
6617the following:
6618
6619- Binary Package: The binary package that is eventually built and
6620 installed into an image.
6621
6622- Binary Package Version: The binary package version is composed of two
Andrew Geissler615f2f12022-07-15 14:00:58 -05006623 components --- a version and a revision.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006624
6625 .. note::
6626
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006627 Technically, a third component, the "epoch" (i.e. :term:`PE`) is involved
Andrew Geissler09036742021-06-25 14:25:14 -05006628 but this discussion for the most part ignores :term:`PE`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006629
6630 The version and revision are taken from the
6631 :term:`PV` and
6632 :term:`PR` variables, respectively.
6633
Andrew Geissler09036742021-06-25 14:25:14 -05006634- :term:`PV`: The recipe version. :term:`PV` represents the version of the
6635 software being packaged. Do not confuse :term:`PV` with the binary
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006636 package version.
6637
Andrew Geissler5f350902021-07-23 13:09:54 -04006638- :term:`PR`: The recipe revision.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006639
6640- :term:`SRCPV`: The OpenEmbedded
Andrew Geissler09036742021-06-25 14:25:14 -05006641 build system uses this string to help define the value of :term:`PV` when
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006642 the source code revision needs to be included in it.
6643
Andrew Geissler09209ee2020-12-13 08:44:15 -06006644- :yocto_wiki:`PR Service </PR_Service>`: A
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006645 network-based service that helps automate keeping package feeds
6646 compatible with existing package manager applications such as RPM,
6647 APT, and OPKG.
6648
6649Whenever the binary package content changes, the binary package version
6650must change. Changing the binary package version is accomplished by
Andrew Geissler09036742021-06-25 14:25:14 -05006651changing or "bumping" the :term:`PR` and/or :term:`PV` values. Increasing these
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006652values occurs one of two ways:
6653
6654- Automatically using a Package Revision Service (PR Service).
6655
Andrew Geissler09036742021-06-25 14:25:14 -05006656- Manually incrementing the :term:`PR` and/or :term:`PV` variables.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006657
6658Given a primary challenge of any build system and its users is how to
6659maintain a package feed that is compatible with existing package manager
6660applications such as RPM, APT, and OPKG, using an automated system is
6661much preferred over a manual system. In either system, the main
6662requirement is that binary package version numbering increases in a
William A. Kennington IIIac69b482021-06-02 12:28:27 -07006663linear fashion and that there is a number of version components that
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006664support that linear progression. For information on how to ensure
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006665package revisioning remains linear, see the
6666":ref:`dev-manual/common-tasks:automatically incrementing a package version number`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006667section.
6668
6669The following three sections provide related information on the PR
Andrew Geissler09036742021-06-25 14:25:14 -05006670Service, the manual method for "bumping" :term:`PR` and/or :term:`PV`, and on
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006671how to ensure binary package revisioning remains linear.
6672
6673Working With a PR Service
6674~~~~~~~~~~~~~~~~~~~~~~~~~
6675
6676As mentioned, attempting to maintain revision numbers in the
6677:term:`Metadata` is error prone, inaccurate,
6678and causes problems for people submitting recipes. Conversely, the PR
6679Service automatically generates increasing numbers, particularly the
6680revision field, which removes the human element.
6681
6682.. note::
6683
6684 For additional information on using a PR Service, you can see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06006685 :yocto_wiki:`PR Service </PR_Service>` wiki page.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006686
6687The Yocto Project uses variables in order of decreasing priority to
6688facilitate revision numbering (i.e.
6689:term:`PE`,
6690:term:`PV`, and
6691:term:`PR` for epoch, version, and
6692revision, respectively). The values are highly dependent on the policies
6693and procedures of a given distribution and package feed.
6694
6695Because the OpenEmbedded build system uses
Andrew Geissler09209ee2020-12-13 08:44:15 -06006696":ref:`signatures <overview-manual/concepts:checksums (signatures)>`", which are
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006697unique to a given build, the build system knows when to rebuild
6698packages. All the inputs into a given task are represented by a
6699signature, which can trigger a rebuild when different. Thus, the build
Andrew Geissler09036742021-06-25 14:25:14 -05006700system itself does not rely on the :term:`PR`, :term:`PV`, and :term:`PE` numbers to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006701trigger a rebuild. The signatures, however, can be used to generate
6702these values.
6703
6704The PR Service works with both ``OEBasic`` and ``OEBasicHash``
Andrew Geissler09036742021-06-25 14:25:14 -05006705generators. The value of :term:`PR` bumps when the checksum changes and the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006706different generator mechanisms change signatures under different
6707circumstances.
6708
6709As implemented, the build system includes values from the PR Service
Andrew Geissler09036742021-06-25 14:25:14 -05006710into the :term:`PR` field as an addition using the form "``.x``" so ``r0``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006711becomes ``r0.1``, ``r0.2`` and so forth. This scheme allows existing
Andrew Geissler09036742021-06-25 14:25:14 -05006712:term:`PR` values to be used for whatever reasons, which include manual
6713:term:`PR` bumps, should it be necessary.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006714
6715By default, the PR Service is not enabled or running. Thus, the packages
6716generated are just "self consistent". The build system adds and removes
6717packages and there are no guarantees about upgrade paths but images will
6718be consistent and correct with the latest changes.
6719
William A. Kennington IIIac69b482021-06-02 12:28:27 -07006720The simplest form for a PR Service is for a single host
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006721development system that builds the package feed (building system). For
6722this scenario, you can enable a local PR Service by setting
6723:term:`PRSERV_HOST` in your
Andrew Geisslerc926e172021-05-07 16:11:35 -05006724``local.conf`` file in the :term:`Build Directory`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006725
6726 PRSERV_HOST = "localhost:0"
6727
6728Once the service is started, packages will automatically
Andrew Geissler09036742021-06-25 14:25:14 -05006729get increasing :term:`PR` values and BitBake takes care of starting and
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006730stopping the server.
6731
6732If you have a more complex setup where multiple host development systems
6733work against a common, shared package feed, you have a single PR Service
6734running and it is connected to each building system. For this scenario,
Andrew Geisslerc926e172021-05-07 16:11:35 -05006735you need to start the PR Service using the ``bitbake-prserv`` command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006736
6737 bitbake-prserv --host ip --port port --start
6738
6739In addition to
6740hand-starting the service, you need to update the ``local.conf`` file of
6741each building system as described earlier so each system points to the
6742server and port.
6743
6744It is also recommended you use build history, which adds some sanity
6745checks to binary package versions, in conjunction with the server that
6746is running the PR Service. To enable build history, add the following to
Andrew Geisslerc926e172021-05-07 16:11:35 -05006747each building system's ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006748
6749 # It is recommended to activate "buildhistory" for testing the PR service
6750 INHERIT += "buildhistory"
6751 BUILDHISTORY_COMMIT = "1"
6752
6753For information on build
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006754history, see the
6755":ref:`dev-manual/common-tasks:maintaining build output quality`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006756
6757.. note::
6758
Andrew Geissler09036742021-06-25 14:25:14 -05006759 The OpenEmbedded build system does not maintain :term:`PR` information as
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006760 part of the shared state (sstate) packages. If you maintain an sstate
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05006761 feed, it's expected that either all your building systems that
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006762 contribute to the sstate feed use a shared PR Service, or you do not
6763 run a PR Service on any of your building systems. Having some systems
6764 use a PR Service while others do not leads to obvious problems.
6765
6766 For more information on shared state, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06006767 ":ref:`overview-manual/concepts:shared state cache`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006768 section in the Yocto Project Overview and Concepts Manual.
6769
6770Manually Bumping PR
6771~~~~~~~~~~~~~~~~~~~
6772
6773The alternative to setting up a PR Service is to manually "bump" the
6774:term:`PR` variable.
6775
6776If a committed change results in changing the package output, then the
6777value of the PR variable needs to be increased (or "bumped") as part of
Andrew Geissler09036742021-06-25 14:25:14 -05006778that commit. For new recipes you should add the :term:`PR` variable and set
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006779its initial value equal to "r0", which is the default. Even though the
6780default value is "r0", the practice of adding it to a new recipe makes
6781it harder to forget to bump the variable when you make changes to the
6782recipe in future.
6783
6784If you are sharing a common ``.inc`` file with multiple recipes, you can
Andrew Geissler09036742021-06-25 14:25:14 -05006785also use the :term:`INC_PR` variable to ensure that the recipes sharing the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006786``.inc`` file are rebuilt when the ``.inc`` file itself is changed. The
Andrew Geissler09036742021-06-25 14:25:14 -05006787``.inc`` file must set :term:`INC_PR` (initially to "r0"), and all recipes
6788referring to it should set :term:`PR` to "${INC_PR}.0" initially,
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006789incrementing the last number when the recipe is changed. If the ``.inc``
Andrew Geissler09036742021-06-25 14:25:14 -05006790file is changed then its :term:`INC_PR` should be incremented.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006791
Andrew Geissler09036742021-06-25 14:25:14 -05006792When upgrading the version of a binary package, assuming the :term:`PV`
6793changes, the :term:`PR` variable should be reset to "r0" (or "${INC_PR}.0"
6794if you are using :term:`INC_PR`).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006795
6796Usually, version increases occur only to binary packages. However, if
Andrew Geissler09036742021-06-25 14:25:14 -05006797for some reason :term:`PV` changes but does not increase, you can increase
6798the :term:`PE` variable (Package Epoch). The :term:`PE` variable defaults to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006799"0".
6800
6801Binary package version numbering strives to follow the `Debian Version
6802Field Policy
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006803Guidelines <https://www.debian.org/doc/debian-policy/ch-controlfields.html>`__.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006804These guidelines define how versions are compared and what "increasing"
6805a version means.
6806
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006807Automatically Incrementing a Package Version Number
6808~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6809
6810When fetching a repository, BitBake uses the
6811:term:`SRCREV` variable to determine
6812the specific source code revision from which to build. You set the
Andrew Geissler09036742021-06-25 14:25:14 -05006813:term:`SRCREV` variable to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006814:term:`AUTOREV` to cause the
6815OpenEmbedded build system to automatically use the latest revision of
Andrew Geisslerc926e172021-05-07 16:11:35 -05006816the software::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006817
6818 SRCREV = "${AUTOREV}"
6819
Andrew Geissler09036742021-06-25 14:25:14 -05006820Furthermore, you need to reference :term:`SRCPV` in :term:`PV` in order to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006821automatically update the version whenever the revision of the source
Andrew Geisslerc926e172021-05-07 16:11:35 -05006822code changes. Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006823
6824 PV = "1.0+git${SRCPV}"
6825
Andrew Geissler09036742021-06-25 14:25:14 -05006826The OpenEmbedded build system substitutes :term:`SRCPV` with the following:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006827
6828.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006829
6830 AUTOINC+source_code_revision
6831
6832The build system replaces the ``AUTOINC``
6833with a number. The number used depends on the state of the PR Service:
6834
6835- If PR Service is enabled, the build system increments the number,
6836 which is similar to the behavior of
6837 :term:`PR`. This behavior results in
6838 linearly increasing package versions, which is desirable. Here is an
6839 example:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006840
6841 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006842
6843 hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
6844 hello-world-git_0.0+git1+dd2f5c3565-r0.0_armv7a-neon.ipk
6845
6846- If PR Service is not enabled, the build system replaces the
6847 ``AUTOINC`` placeholder with zero (i.e. "0"). This results in
6848 changing the package version since the source revision is included.
6849 However, package versions are not increased linearly. Here is an
6850 example:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006851
6852 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006853
6854 hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
6855 hello-world-git_0.0+git0+dd2f5c3565-r0.0_armv7a-neon.ipk
6856
6857In summary, the OpenEmbedded build system does not track the history of
6858binary package versions for this purpose. ``AUTOINC``, in this case, is
Andrew Geissler09036742021-06-25 14:25:14 -05006859comparable to :term:`PR`. If PR server is not enabled, ``AUTOINC`` in the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006860package version is simply replaced by "0". If PR server is enabled, the
6861build system keeps track of the package versions and bumps the number
6862when the package revision changes.
6863
6864Handling Optional Module Packaging
6865----------------------------------
6866
6867Many pieces of software split functionality into optional modules (or
6868plugins) and the plugins that are built might depend on configuration
6869options. To avoid having to duplicate the logic that determines what
6870modules are available in your recipe or to avoid having to package each
6871module by hand, the OpenEmbedded build system provides functionality to
6872handle module packaging dynamically.
6873
6874To handle optional module packaging, you need to do two things:
6875
6876- Ensure the module packaging is actually done.
6877
6878- Ensure that any dependencies on optional modules from other recipes
6879 are satisfied by your recipe.
6880
6881Making Sure the Packaging is Done
6882~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6883
6884To ensure the module packaging actually gets done, you use the
6885``do_split_packages`` function within the ``populate_packages`` Python
6886function in your recipe. The ``do_split_packages`` function searches for
6887a pattern of files or directories under a specified path and creates a
6888package for each one it finds by appending to the
6889:term:`PACKAGES` variable and
Patrick Williams0ca19cc2021-08-16 14:03:13 -05006890setting the appropriate values for ``FILES:packagename``,
6891``RDEPENDS:packagename``, ``DESCRIPTION:packagename``, and so forth.
Andrew Geisslerc926e172021-05-07 16:11:35 -05006892Here is an example from the ``lighttpd`` recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006893
Patrick Williams0ca19cc2021-08-16 14:03:13 -05006894 python populate_packages:prepend () {
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006895 lighttpd_libdir = d.expand('${libdir}')
6896 do_split_packages(d, lighttpd_libdir, '^mod_(.*).so$',
6897 'lighttpd-module-%s', 'Lighttpd module for %s',
6898 extra_depends='')
6899 }
6900
6901The previous example specifies a number of things in the call to
6902``do_split_packages``.
6903
6904- A directory within the files installed by your recipe through
6905 ``do_install`` in which to search.
6906
6907- A regular expression used to match module files in that directory. In
6908 the example, note the parentheses () that mark the part of the
6909 expression from which the module name should be derived.
6910
6911- A pattern to use for the package names.
6912
6913- A description for each package.
6914
6915- An empty string for ``extra_depends``, which disables the default
6916 dependency on the main ``lighttpd`` package. Thus, if a file in
6917 ``${libdir}`` called ``mod_alias.so`` is found, a package called
6918 ``lighttpd-module-alias`` is created for it and the
6919 :term:`DESCRIPTION` is set to
6920 "Lighttpd module for alias".
6921
6922Often, packaging modules is as simple as the previous example. However,
William A. Kennington IIIac69b482021-06-02 12:28:27 -07006923there are more advanced options that you can use within
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006924``do_split_packages`` to modify its behavior. And, if you need to, you
6925can add more logic by specifying a hook function that is called for each
6926package. It is also perfectly acceptable to call ``do_split_packages``
6927multiple times if you have more than one set of modules to package.
6928
6929For more examples that show how to use ``do_split_packages``, see the
6930``connman.inc`` file in the ``meta/recipes-connectivity/connman/``
Andrew Geissler09209ee2020-12-13 08:44:15 -06006931directory of the ``poky`` :ref:`source repository <overview-manual/development-environment:yocto project source repositories>`. You can
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006932also find examples in ``meta/classes/kernel.bbclass``.
6933
6934Following is a reference that shows ``do_split_packages`` mandatory and
Andrew Geisslerc926e172021-05-07 16:11:35 -05006935optional arguments::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006936
6937 Mandatory arguments
6938
6939 root
6940 The path in which to search
6941 file_regex
6942 Regular expression to match searched files.
6943 Use parentheses () to mark the part of this
6944 expression that should be used to derive the
6945 module name (to be substituted where %s is
6946 used in other function arguments as noted below)
6947 output_pattern
6948 Pattern to use for the package names. Must
6949 include %s.
6950 description
6951 Description to set for each package. Must
6952 include %s.
6953
6954 Optional arguments
6955
6956 postinst
6957 Postinstall script to use for all packages
6958 (as a string)
6959 recursive
Andrew Geissler615f2f12022-07-15 14:00:58 -05006960 True to perform a recursive search --- default
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006961 False
6962 hook
6963 A hook function to be called for every match.
6964 The function will be called with the following
6965 arguments (in the order listed):
6966
6967 f
6968 Full path to the file/directory match
6969 pkg
6970 The package name
6971 file_regex
6972 As above
6973 output_pattern
6974 As above
6975 modulename
6976 The module name derived using file_regex
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006977 extra_depends
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006978 Extra runtime dependencies (RDEPENDS) to be
6979 set for all packages. The default value of None
6980 causes a dependency on the main package
Andrew Geissler615f2f12022-07-15 14:00:58 -05006981 (${PN}) --- if you do not want this, pass empty
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006982 string '' for this parameter.
6983 aux_files_pattern
6984 Extra item(s) to be added to FILES for each
6985 package. Can be a single string item or a list
6986 of strings for multiple items. Must include %s.
6987 postrm
6988 postrm script to use for all packages (as a
6989 string)
6990 allow_dirs
6991 True to allow directories to be matched -
6992 default False
6993 prepend
6994 If True, prepend created packages to PACKAGES
6995 instead of the default False which appends them
6996 match_path
6997 match file_regex on the whole relative path to
Patrick Williams0ca19cc2021-08-16 14:03:13 -05006998 the root rather than just the filename
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006999 aux_files_pattern_verbatim
7000 Extra item(s) to be added to FILES for each
7001 package, using the actual derived module name
7002 rather than converting it to something legal
7003 for a package name. Can be a single string item
7004 or a list of strings for multiple items. Must
7005 include %s.
7006 allow_links
Andrew Geissler615f2f12022-07-15 14:00:58 -05007007 True to allow symlinks to be matched --- default
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007008 False
7009 summary
7010 Summary to set for each package. Must include %s;
7011 defaults to description if not set.
7012
7013
7014
7015Satisfying Dependencies
7016~~~~~~~~~~~~~~~~~~~~~~~
7017
7018The second part for handling optional module packaging is to ensure that
7019any dependencies on optional modules from other recipes are satisfied by
7020your recipe. You can be sure these dependencies are satisfied by using
7021the :term:`PACKAGES_DYNAMIC`
7022variable. Here is an example that continues with the ``lighttpd`` recipe
Andrew Geisslerc926e172021-05-07 16:11:35 -05007023shown earlier::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007024
7025 PACKAGES_DYNAMIC = "lighttpd-module-.*"
7026
7027The name
7028specified in the regular expression can of course be anything. In this
7029example, it is ``lighttpd-module-`` and is specified as the prefix to
7030ensure that any :term:`RDEPENDS` and
7031:term:`RRECOMMENDS` on a package
7032name starting with the prefix are satisfied during build time. If you
7033are using ``do_split_packages`` as described in the previous section,
Andrew Geissler09036742021-06-25 14:25:14 -05007034the value you put in :term:`PACKAGES_DYNAMIC` should correspond to the name
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007035pattern specified in the call to ``do_split_packages``.
7036
7037Using Runtime Package Management
7038--------------------------------
7039
7040During a build, BitBake always transforms a recipe into one or more
7041packages. For example, BitBake takes the ``bash`` recipe and produces a
7042number of packages (e.g. ``bash``, ``bash-bashbug``,
7043``bash-completion``, ``bash-completion-dbg``, ``bash-completion-dev``,
7044``bash-completion-extra``, ``bash-dbg``, and so forth). Not all
7045generated packages are included in an image.
7046
7047In several situations, you might need to update, add, remove, or query
7048the packages on a target device at runtime (i.e. without having to
7049generate a new image). Examples of such situations include:
7050
7051- You want to provide in-the-field updates to deployed devices (e.g.
7052 security updates).
7053
7054- You want to have a fast turn-around development cycle for one or more
7055 applications that run on your device.
7056
7057- You want to temporarily install the "debug" packages of various
7058 applications on your device so that debugging can be greatly improved
7059 by allowing access to symbols and source debugging.
7060
7061- You want to deploy a more minimal package selection of your device
7062 but allow in-the-field updates to add a larger selection for
7063 customization.
7064
7065In all these situations, you have something similar to a more
7066traditional Linux distribution in that in-field devices are able to
7067receive pre-compiled packages from a server for installation or update.
7068Being able to install these packages on a running, in-field device is
7069what is termed "runtime package management".
7070
7071In order to use runtime package management, you need a host or server
7072machine that serves up the pre-compiled packages plus the required
7073metadata. You also need package manipulation tools on the target. The
7074build machine is a likely candidate to act as the server. However, that
7075machine does not necessarily have to be the package server. The build
7076machine could push its artifacts to another machine that acts as the
7077server (e.g. Internet-facing). In fact, doing so is advantageous for a
7078production environment as getting the packages away from the development
7079system's build directory prevents accidental overwrites.
7080
7081A simple build that targets just one device produces more than one
7082package database. In other words, the packages produced by a build are
7083separated out into a couple of different package groupings based on
7084criteria such as the target's CPU architecture, the target board, or the
7085C library used on the target. For example, a build targeting the
7086``qemux86`` device produces the following three package databases:
7087``noarch``, ``i586``, and ``qemux86``. If you wanted your ``qemux86``
7088device to be aware of all the packages that were available to it, you
7089would need to point it to each of these databases individually. In a
7090similar way, a traditional Linux distribution usually is configured to
7091be aware of a number of software repositories from which it retrieves
7092packages.
7093
7094Using runtime package management is completely optional and not required
7095for a successful build or deployment in any way. But if you want to make
7096use of runtime package management, you need to do a couple things above
7097and beyond the basics. The remainder of this section describes what you
7098need to do.
7099
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007100Build Considerations
7101~~~~~~~~~~~~~~~~~~~~
7102
7103This section describes build considerations of which you need to be
7104aware in order to provide support for runtime package management.
7105
7106When BitBake generates packages, it needs to know what format or formats
7107to use. In your configuration, you use the
7108:term:`PACKAGE_CLASSES`
7109variable to specify the format:
7110
71111. Open the ``local.conf`` file inside your
7112 :term:`Build Directory` (e.g.
Andrew Geissler95ac1b82021-03-31 14:34:31 -05007113 ``poky/build/conf/local.conf``).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007114
Andrew Geisslerc926e172021-05-07 16:11:35 -050071152. Select the desired package format as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007116
7117 PACKAGE_CLASSES ?= "package_packageformat"
7118
7119 where packageformat can be "ipk", "rpm",
7120 "deb", or "tar" which are the supported package formats.
7121
7122 .. note::
7123
7124 Because the Yocto Project supports four different package formats,
7125 you can set the variable with more than one argument. However, the
7126 OpenEmbedded build system only uses the first argument when
7127 creating an image or Software Development Kit (SDK).
7128
7129If you would like your image to start off with a basic package database
7130containing the packages in your current build as well as to have the
7131relevant tools available on the target for runtime package management,
7132you can include "package-management" in the
7133:term:`IMAGE_FEATURES`
7134variable. Including "package-management" in this configuration variable
7135ensures that when the image is assembled for your target, the image
7136includes the currently-known package databases as well as the
7137target-specific tools required for runtime package management to be
7138performed on the target. However, this is not strictly necessary. You
7139could start your image off without any databases but only include the
7140required on-target package tool(s). As an example, you could include
7141"opkg" in your
7142:term:`IMAGE_INSTALL` variable
7143if you are using the IPK package format. You can then initialize your
7144target's package database(s) later once your image is up and running.
7145
7146Whenever you perform any sort of build step that can potentially
7147generate a package or modify existing package, it is always a good idea
7148to re-generate the package index after the build by using the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05007149command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007150
7151 $ bitbake package-index
7152
7153It might be tempting to build the
7154package and the package index at the same time with a command such as
Andrew Geisslerc926e172021-05-07 16:11:35 -05007155the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007156
7157 $ bitbake some-package package-index
7158
7159Do not do this as
7160BitBake does not schedule the package index for after the completion of
7161the package you are building. Consequently, you cannot be sure of the
7162package index including information for the package you just built.
7163Thus, be sure to run the package update step separately after building
7164any packages.
7165
7166You can use the
7167:term:`PACKAGE_FEED_ARCHS`,
7168:term:`PACKAGE_FEED_BASE_PATHS`,
7169and
7170:term:`PACKAGE_FEED_URIS`
7171variables to pre-configure target images to use a package feed. If you
7172do not define these variables, then manual steps as described in the
7173subsequent sections are necessary to configure the target. You should
7174set these variables before building the image in order to produce a
7175correctly configured image.
7176
7177When your build is complete, your packages reside in the
7178``${TMPDIR}/deploy/packageformat`` directory. For example, if
7179``${``\ :term:`TMPDIR`\ ``}`` is
7180``tmp`` and your selected package type is RPM, then your RPM packages
7181are available in ``tmp/deploy/rpm``.
7182
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007183Host or Server Machine Setup
7184~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7185
7186Although other protocols are possible, a server using HTTP typically
7187serves packages. If you want to use HTTP, then set up and configure a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007188web server such as Apache 2, lighttpd, or Python web server on the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007189machine serving the packages.
7190
7191To keep things simple, this section describes how to set up a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007192Python web server to share package feeds from the developer's
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007193machine. Although this server might not be the best for a production
7194environment, the setup is simple and straight forward. Should you want
7195to use a different server more suited for production (e.g. Apache 2,
7196Lighttpd, or Nginx), take the appropriate steps to do so.
7197
7198From within the build directory where you have built an image based on
7199your packaging choice (i.e. the
7200:term:`PACKAGE_CLASSES`
7201setting), simply start the server. The following example assumes a build
Andrew Geissler09036742021-06-25 14:25:14 -05007202directory of ``poky/build/tmp/deploy/rpm`` and a :term:`PACKAGE_CLASSES`
Andrew Geisslerc926e172021-05-07 16:11:35 -05007203setting of "package_rpm"::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007204
Andrew Geissler95ac1b82021-03-31 14:34:31 -05007205 $ cd poky/build/tmp/deploy/rpm
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007206 $ python3 -m http.server
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007207
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007208Target Setup
7209~~~~~~~~~~~~
7210
7211Setting up the target differs depending on the package management
7212system. This section provides information for RPM, IPK, and DEB.
7213
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007214Using RPM
7215^^^^^^^^^
7216
7217The `Dandified Packaging
7218Tool <https://en.wikipedia.org/wiki/DNF_(software)>`__ (DNF) performs
7219runtime package management of RPM packages. In order to use DNF for
7220runtime package management, you must perform an initial setup on the
7221target machine for cases where the ``PACKAGE_FEED_*`` variables were not
7222set as part of the image that is running on the target. This means if
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05007223you built your image and did not use these variables as part of the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007224build and your image is now running on the target, you need to perform
7225the steps in this section if you want to use runtime package management.
7226
7227.. note::
7228
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007229 For information on the ``PACKAGE_FEED_*`` variables, see
7230 :term:`PACKAGE_FEED_ARCHS`, :term:`PACKAGE_FEED_BASE_PATHS`, and
7231 :term:`PACKAGE_FEED_URIS` in the Yocto Project Reference Manual variables
7232 glossary.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007233
7234On the target, you must inform DNF that package databases are available.
7235You do this by creating a file named
7236``/etc/yum.repos.d/oe-packages.repo`` and defining the ``oe-packages``.
7237
7238As an example, assume the target is able to use the following package
7239databases: ``all``, ``i586``, and ``qemux86`` from a server named
7240``my.server``. The specifics for setting up the web server are up to
7241you. The critical requirement is that the URIs in the target repository
7242configuration point to the correct remote location for the feeds.
7243
7244.. note::
7245
7246 For development purposes, you can point the web server to the build
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007247 system's ``deploy`` directory. However, for production use, it is better to
7248 copy the package directories to a location outside of the build area and use
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007249 that location. Doing so avoids situations where the build system
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007250 overwrites or changes the ``deploy`` directory.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007251
7252When telling DNF where to look for the package databases, you must
7253declare individual locations per architecture or a single location used
7254for all architectures. You cannot do both:
7255
7256- *Create an Explicit List of Architectures:* Define individual base
7257 URLs to identify where each package database is located:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007258
7259 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007260
7261 [oe-packages]
7262 baseurl=http://my.server/rpm/i586 http://my.server/rpm/qemux86 http://my.server/rpm/all
7263
7264 This example
7265 informs DNF about individual package databases for all three
7266 architectures.
7267
7268- *Create a Single (Full) Package Index:* Define a single base URL that
Andrew Geisslerc926e172021-05-07 16:11:35 -05007269 identifies where a full package database is located::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007270
7271 [oe-packages]
7272 baseurl=http://my.server/rpm
7273
7274 This example informs DNF about a single
7275 package database that contains all the package index information for
7276 all supported architectures.
7277
7278Once you have informed DNF where to find the package databases, you need
7279to fetch them:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007280
7281.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007282
7283 # dnf makecache
7284
7285DNF is now able to find, install, and
7286upgrade packages from the specified repository or repositories.
7287
7288.. note::
7289
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007290 See the `DNF documentation <https://dnf.readthedocs.io/en/latest/>`__ for
7291 additional information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007292
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007293Using IPK
7294^^^^^^^^^
7295
7296The ``opkg`` application performs runtime package management of IPK
7297packages. You must perform an initial setup for ``opkg`` on the target
7298machine if the
7299:term:`PACKAGE_FEED_ARCHS`,
7300:term:`PACKAGE_FEED_BASE_PATHS`,
7301and
7302:term:`PACKAGE_FEED_URIS`
7303variables have not been set or the target image was built before the
7304variables were set.
7305
7306The ``opkg`` application uses configuration files to find available
7307package databases. Thus, you need to create a configuration file inside
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00007308the ``/etc/opkg/`` directory, which informs ``opkg`` of any repository
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007309you want to use.
7310
7311As an example, suppose you are serving packages from a ``ipk/``
7312directory containing the ``i586``, ``all``, and ``qemux86`` databases
7313through an HTTP server named ``my.server``. On the target, create a
7314configuration file (e.g. ``my_repo.conf``) inside the ``/etc/opkg/``
7315directory containing the following:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007316
7317.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007318
7319 src/gz all http://my.server/ipk/all
7320 src/gz i586 http://my.server/ipk/i586
7321 src/gz qemux86 http://my.server/ipk/qemux86
7322
7323Next, instruct ``opkg`` to fetch the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007324repository information:
7325
7326.. code-block:: none
7327
7328 # opkg update
7329
7330The ``opkg`` application is now able to find, install, and upgrade packages
7331from the specified repository.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007332
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007333Using DEB
7334^^^^^^^^^
7335
7336The ``apt`` application performs runtime package management of DEB
7337packages. This application uses a source list file to find available
7338package databases. You must perform an initial setup for ``apt`` on the
7339target machine if the
7340:term:`PACKAGE_FEED_ARCHS`,
7341:term:`PACKAGE_FEED_BASE_PATHS`,
7342and
7343:term:`PACKAGE_FEED_URIS`
7344variables have not been set or the target image was built before the
7345variables were set.
7346
7347To inform ``apt`` of the repository you want to use, you might create a
7348list file (e.g. ``my_repo.list``) inside the
7349``/etc/apt/sources.list.d/`` directory. As an example, suppose you are
7350serving packages from a ``deb/`` directory containing the ``i586``,
7351``all``, and ``qemux86`` databases through an HTTP server named
7352``my.server``. The list file should contain:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007353
7354.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007355
7356 deb http://my.server/deb/all ./
7357 deb http://my.server/deb/i586 ./
7358 deb http://my.server/deb/qemux86 ./
7359
7360Next, instruct the ``apt`` application
7361to fetch the repository information:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007362
7363.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007364
Andrew Geisslereff27472021-10-29 15:35:00 -05007365 $ sudo apt update
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007366
7367After this step,
7368``apt`` is able to find, install, and upgrade packages from the
7369specified repository.
7370
7371Generating and Using Signed Packages
7372------------------------------------
7373
7374In order to add security to RPM packages used during a build, you can
7375take steps to securely sign them. Once a signature is verified, the
7376OpenEmbedded build system can use the package in the build. If security
Andrew Geissler595f6302022-01-24 19:11:47 +00007377fails for a signed package, the build system stops the build.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007378
7379This section describes how to sign RPM packages during a build and how
7380to use signed package feeds (repositories) when doing a build.
7381
7382Signing RPM Packages
7383~~~~~~~~~~~~~~~~~~~~
7384
7385To enable signing RPM packages, you must set up the following
7386configurations in either your ``local.config`` or ``distro.config``
Andrew Geisslerc926e172021-05-07 16:11:35 -05007387file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007388
7389 # Inherit sign_rpm.bbclass to enable signing functionality
7390 INHERIT += " sign_rpm"
7391 # Define the GPG key that will be used for signing.
7392 RPM_GPG_NAME = "key_name"
7393 # Provide passphrase for the key
7394 RPM_GPG_PASSPHRASE = "passphrase"
7395
7396.. note::
7397
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007398 Be sure to supply appropriate values for both `key_name` and
7399 `passphrase`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007400
7401Aside from the ``RPM_GPG_NAME`` and ``RPM_GPG_PASSPHRASE`` variables in
William A. Kennington IIIac69b482021-06-02 12:28:27 -07007402the previous example, two optional variables related to signing are available:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007403
7404- *GPG_BIN:* Specifies a ``gpg`` binary/wrapper that is executed
7405 when the package is signed.
7406
7407- *GPG_PATH:* Specifies the ``gpg`` home directory used when the
7408 package is signed.
7409
7410Processing Package Feeds
7411~~~~~~~~~~~~~~~~~~~~~~~~
7412
7413In addition to being able to sign RPM packages, you can also enable
7414signed package feeds for IPK and RPM packages.
7415
7416The steps you need to take to enable signed package feed use are similar
7417to the steps used to sign RPM packages. You must define the following in
Andrew Geisslerc926e172021-05-07 16:11:35 -05007418your ``local.config`` or ``distro.config`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007419
7420 INHERIT += "sign_package_feed"
7421 PACKAGE_FEED_GPG_NAME = "key_name"
7422 PACKAGE_FEED_GPG_PASSPHRASE_FILE = "path_to_file_containing_passphrase"
7423
William A. Kennington IIIac69b482021-06-02 12:28:27 -07007424For signed package feeds, the passphrase must be specified in a separate file,
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007425which is pointed to by the ``PACKAGE_FEED_GPG_PASSPHRASE_FILE``
7426variable. Regarding security, keeping a plain text passphrase out of the
7427configuration is more secure.
7428
7429Aside from the ``PACKAGE_FEED_GPG_NAME`` and
7430``PACKAGE_FEED_GPG_PASSPHRASE_FILE`` variables, three optional variables
William A. Kennington IIIac69b482021-06-02 12:28:27 -07007431related to signed package feeds are available:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007432
7433- *GPG_BIN* Specifies a ``gpg`` binary/wrapper that is executed
7434 when the package is signed.
7435
7436- *GPG_PATH:* Specifies the ``gpg`` home directory used when the
7437 package is signed.
7438
7439- *PACKAGE_FEED_GPG_SIGNATURE_TYPE:* Specifies the type of ``gpg``
7440 signature. This variable applies only to RPM and IPK package feeds.
7441 Allowable values for the ``PACKAGE_FEED_GPG_SIGNATURE_TYPE`` are
7442 "ASC", which is the default and specifies ascii armored, and "BIN",
7443 which specifies binary.
7444
7445Testing Packages With ptest
7446---------------------------
7447
7448A Package Test (ptest) runs tests against packages built by the
7449OpenEmbedded build system on the target machine. A ptest contains at
7450least two items: the actual test, and a shell script (``run-ptest``)
7451that starts the test. The shell script that starts the test must not
Andrew Geissler615f2f12022-07-15 14:00:58 -05007452contain the actual test --- the script only starts the test. On the other
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007453hand, the test can be anything from a simple shell script that runs a
7454binary and checks the output to an elaborate system of test binaries and
7455data files.
7456
Andrew Geisslerc926e172021-05-07 16:11:35 -05007457The test generates output in the format used by Automake::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007458
7459 result: testname
7460
7461where the result can be ``PASS``, ``FAIL``, or ``SKIP``, and
7462the testname can be any identifying string.
7463
7464For a list of Yocto Project recipes that are already enabled with ptest,
Andrew Geissler09209ee2020-12-13 08:44:15 -06007465see the :yocto_wiki:`Ptest </Ptest>` wiki page.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007466
7467.. note::
7468
7469 A recipe is "ptest-enabled" if it inherits the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007470 :ref:`ptest <ref-classes-ptest>` class.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007471
7472Adding ptest to Your Build
7473~~~~~~~~~~~~~~~~~~~~~~~~~~
7474
7475To add package testing to your build, add the
7476:term:`DISTRO_FEATURES` and
7477:term:`EXTRA_IMAGE_FEATURES`
7478variables to your ``local.conf`` file, which is found in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05007479:term:`Build Directory`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007480
Patrick Williams0ca19cc2021-08-16 14:03:13 -05007481 DISTRO_FEATURES:append = " ptest"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007482 EXTRA_IMAGE_FEATURES += "ptest-pkgs"
7483
7484Once your build is complete, the ptest files are installed into the
7485``/usr/lib/package/ptest`` directory within the image, where ``package``
7486is the name of the package.
7487
7488Running ptest
7489~~~~~~~~~~~~~
7490
7491The ``ptest-runner`` package installs a shell script that loops through
7492all installed ptest test suites and runs them in sequence. Consequently,
7493you might want to add this package to your image.
7494
7495Getting Your Package Ready
7496~~~~~~~~~~~~~~~~~~~~~~~~~~
7497
7498In order to enable a recipe to run installed ptests on target hardware,
7499you need to prepare the recipes that build the packages you want to
7500test. Here is what you have to do for each recipe:
7501
7502- *Be sure the recipe inherits
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007503 the* :ref:`ptest <ref-classes-ptest>` *class:*
Andrew Geisslerc926e172021-05-07 16:11:35 -05007504 Include the following line in each recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007505
7506 inherit ptest
7507
7508- *Create run-ptest:* This script starts your test. Locate the
7509 script where you will refer to it using
7510 :term:`SRC_URI`. Here is an
Andrew Geisslerc926e172021-05-07 16:11:35 -05007511 example that starts a test for ``dbus``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007512
7513 #!/bin/sh
7514 cd test
7515 make -k runtest-TESTS
7516
7517- *Ensure dependencies are met:* If the test adds build or runtime
7518 dependencies that normally do not exist for the package (such as
7519 requiring "make" to run the test suite), use the
7520 :term:`DEPENDS` and
7521 :term:`RDEPENDS` variables in
7522 your recipe in order for the package to meet the dependencies. Here
Andrew Geisslerc926e172021-05-07 16:11:35 -05007523 is an example where the package has a runtime dependency on "make"::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007524
Patrick Williams0ca19cc2021-08-16 14:03:13 -05007525 RDEPENDS:${PN}-ptest += "make"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007526
7527- *Add a function to build the test suite:* Not many packages support
7528 cross-compilation of their test suites. Consequently, you usually
7529 need to add a cross-compilation function to the package.
7530
7531 Many packages based on Automake compile and run the test suite by
7532 using a single command such as ``make check``. However, the host
7533 ``make check`` builds and runs on the same computer, while
7534 cross-compiling requires that the package is built on the host but
7535 executed for the target architecture (though often, as in the case
7536 for ptest, the execution occurs on the host). The built version of
7537 Automake that ships with the Yocto Project includes a patch that
7538 separates building and execution. Consequently, packages that use the
7539 unaltered, patched version of ``make check`` automatically
7540 cross-compiles.
7541
7542 Regardless, you still must add a ``do_compile_ptest`` function to
7543 build the test suite. Add a function similar to the following to your
Andrew Geisslerc926e172021-05-07 16:11:35 -05007544 recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007545
7546 do_compile_ptest() {
7547 oe_runmake buildtest-TESTS
7548 }
7549
7550- *Ensure special configurations are set:* If the package requires
7551 special configurations prior to compiling the test code, you must
7552 insert a ``do_configure_ptest`` function into the recipe.
7553
7554- *Install the test suite:* The ``ptest`` class automatically copies
7555 the file ``run-ptest`` to the target and then runs make
7556 ``install-ptest`` to run the tests. If this is not enough, you need
7557 to create a ``do_install_ptest`` function and make sure it gets
7558 called after the "make install-ptest" completes.
7559
7560Creating Node Package Manager (NPM) Packages
7561--------------------------------------------
7562
7563`NPM <https://en.wikipedia.org/wiki/Npm_(software)>`__ is a package
7564manager for the JavaScript programming language. The Yocto Project
Andrew Geissler09209ee2020-12-13 08:44:15 -06007565supports the NPM :ref:`fetcher <bitbake:bitbake-user-manual/bitbake-user-manual-fetching:fetchers>`. You can
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007566use this fetcher in combination with
Andrew Geissler09209ee2020-12-13 08:44:15 -06007567:doc:`devtool </ref-manual/devtool-reference>` to create
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007568recipes that produce NPM packages.
7569
William A. Kennington IIIac69b482021-06-02 12:28:27 -07007570There are two workflows that allow you to create NPM packages using
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007571``devtool``: the NPM registry modules method and the NPM project code
7572method.
7573
7574.. note::
7575
7576 While it is possible to create NPM recipes manually, using
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007577 ``devtool`` is far simpler.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007578
7579Additionally, some requirements and caveats exist.
7580
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007581Requirements and Caveats
7582~~~~~~~~~~~~~~~~~~~~~~~~
7583
7584You need to be aware of the following before using ``devtool`` to create
7585NPM packages:
7586
7587- Of the two methods that you can use ``devtool`` to create NPM
7588 packages, the registry approach is slightly simpler. However, you
7589 might consider the project approach because you do not have to
7590 publish your module in the NPM registry
7591 (`npm-registry <https://docs.npmjs.com/misc/registry>`_), which
7592 is NPM's public registry.
7593
7594- Be familiar with
Andrew Geissler09209ee2020-12-13 08:44:15 -06007595 :doc:`devtool </ref-manual/devtool-reference>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007596
7597- The NPM host tools need the native ``nodejs-npm`` package, which is
7598 part of the OpenEmbedded environment. You need to get the package by
7599 cloning the https://github.com/openembedded/meta-openembedded
7600 repository out of GitHub. Be sure to add the path to your local copy
7601 to your ``bblayers.conf`` file.
7602
7603- ``devtool`` cannot detect native libraries in module dependencies.
7604 Consequently, you must manually add packages to your recipe.
7605
7606- While deploying NPM packages, ``devtool`` cannot determine which
7607 dependent packages are missing on the target (e.g. the node runtime
7608 ``nodejs``). Consequently, you need to find out what files are
7609 missing and be sure they are on the target.
7610
7611- Although you might not need NPM to run your node package, it is
7612 useful to have NPM on your target. The NPM package name is
7613 ``nodejs-npm``.
7614
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007615Using the Registry Modules Method
7616~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7617
7618This section presents an example that uses the ``cute-files`` module,
7619which is a file browser web application.
7620
7621.. note::
7622
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007623 You must know the ``cute-files`` module version.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007624
7625The first thing you need to do is use ``devtool`` and the NPM fetcher to
Andrew Geisslerc926e172021-05-07 16:11:35 -05007626create the recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007627
7628 $ devtool add "npm://registry.npmjs.org;package=cute-files;version=1.0.2"
7629
7630The
7631``devtool add`` command runs ``recipetool create`` and uses the same
7632fetch URI to download each dependency and capture license details where
7633possible. The result is a generated recipe.
7634
Andrew Geissler615f2f12022-07-15 14:00:58 -05007635After running for quite a long time, in particular building the
7636``nodejs-native`` package, the command should end as follows::
7637
7638 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
7639
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007640The recipe file is fairly simple and contains every license that
7641``recipetool`` finds and includes the licenses in the recipe's
7642:term:`LIC_FILES_CHKSUM`
7643variables. You need to examine the variables and look for those with
7644"unknown" in the :term:`LICENSE`
7645field. You need to track down the license information for "unknown"
7646modules and manually add the information to the recipe.
7647
7648``recipetool`` creates a "shrinkwrap" file for your recipe. Shrinkwrap
7649files capture the version of all dependent modules. Many packages do not
Andrew Geissler615f2f12022-07-15 14:00:58 -05007650provide shrinkwrap files but ``recipetool`` will create a shrinkwrap file as it
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007651runs.
7652
7653.. note::
7654
7655 A package is created for each sub-module. This policy is the only
7656 practical way to have the licenses for all of the dependencies
7657 represented in the license manifest of the image.
7658
Andrew Geisslerc926e172021-05-07 16:11:35 -05007659The ``devtool edit-recipe`` command lets you take a look at the recipe::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007660
7661 $ devtool edit-recipe cute-files
Andrew Geissler615f2f12022-07-15 14:00:58 -05007662 # Recipe created by recipetool
7663 # This is the basis of a recipe and may need further editing in order to be fully functional.
7664 # (Feel free to remove these comments when editing.)
7665
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007666 SUMMARY = "Turn any folder on your computer into a cute file browser, available on the local network."
Andrew Geissler615f2f12022-07-15 14:00:58 -05007667 # WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is
7668 # your responsibility to verify that the values are complete and correct.
7669 #
7670 # NOTE: multiple licenses have been detected; they have been separated with &
7671 # in the LICENSE value for now since it is a reasonable assumption that all
7672 # of the licenses apply. If instead there is a choice between the multiple
7673 # licenses then you should change the value to separate the licenses with |
7674 # instead of &. If there is any doubt, check the accompanying documentation
7675 # to determine which situation is applicable.
7676
7677 SUMMARY = "Turn any folder on your computer into a cute file browser, available on the local network."
7678 LICENSE = "BSD-3-Clause & ISC & MIT"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007679 LIC_FILES_CHKSUM = "file://LICENSE;md5=71d98c0a1db42956787b1909c74a86ca \
Andrew Geissler615f2f12022-07-15 14:00:58 -05007680 file://node_modules/accepts/LICENSE;md5=bf1f9ad1e2e1d507aef4883fff7103de \
7681 file://node_modules/array-flatten/LICENSE;md5=44088ba57cb871a58add36ce51b8de08 \
7682 ...
7683 file://node_modules/cookie-signature/Readme.md;md5=57ae8b42de3dd0c1f22d5f4cf191e15a"
7684
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007685 SRC_URI = " \
7686 npm://registry.npmjs.org/;package=cute-files;version=${PV} \
7687 npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \
7688 "
Andrew Geissler615f2f12022-07-15 14:00:58 -05007689
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007690 S = "${WORKDIR}/npm"
Andrew Geissler615f2f12022-07-15 14:00:58 -05007691
Patrick Williams213cb262021-08-07 19:21:33 -05007692 inherit npm
Andrew Geissler615f2f12022-07-15 14:00:58 -05007693
Patrick Williams0ca19cc2021-08-16 14:03:13 -05007694 LICENSE:${PN} = "MIT"
7695 LICENSE:${PN}-accepts = "MIT"
7696 LICENSE:${PN}-array-flatten = "MIT"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007697 ...
Patrick Williams0ca19cc2021-08-16 14:03:13 -05007698 LICENSE:${PN}-vary = "MIT"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007699
William A. Kennington IIIac69b482021-06-02 12:28:27 -07007700Here are three key points in the previous example:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007701
7702- :term:`SRC_URI` uses the NPM
7703 scheme so that the NPM fetcher is used.
7704
7705- ``recipetool`` collects all the license information. If a
7706 sub-module's license is unavailable, the sub-module's name appears in
7707 the comments.
7708
7709- The ``inherit npm`` statement causes the
7710 :ref:`npm <ref-classes-npm>` class to package
7711 up all the modules.
7712
Andrew Geisslerc926e172021-05-07 16:11:35 -05007713You can run the following command to build the ``cute-files`` package::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007714
7715 $ devtool build cute-files
7716
7717Remember that ``nodejs`` must be installed on
7718the target before your package.
7719
7720Assuming 192.168.7.2 for the target's IP address, use the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05007721command to deploy your package::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007722
7723 $ devtool deploy-target -s cute-files root@192.168.7.2
7724
7725Once the package is installed on the target, you can
Andrew Geissler615f2f12022-07-15 14:00:58 -05007726test the application to show the contents of any directory::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007727
7728 $ cd /usr/lib/node_modules/cute-files
Andrew Geissler615f2f12022-07-15 14:00:58 -05007729 $ cute-files
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007730
7731On a browser,
7732go to ``http://192.168.7.2:3000`` and you see the following:
7733
7734.. image:: figures/cute-files-npm-example.png
Andrew Geisslerd5838332022-05-27 11:33:10 -05007735 :width: 100%
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007736
7737You can find the recipe in ``workspace/recipes/cute-files``. You can use
7738the recipe in any layer you choose.
7739
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007740Using the NPM Projects Code Method
7741~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7742
7743Although it is useful to package modules already in the NPM registry,
7744adding ``node.js`` projects under development is a more common developer
7745use case.
7746
7747This section covers the NPM projects code method, which is very similar
7748to the "registry" approach described in the previous section. In the NPM
7749projects method, you provide ``devtool`` with an URL that points to the
7750source files.
7751
7752Replicating the same example, (i.e. ``cute-files``) use the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05007753command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007754
7755 $ devtool add https://github.com/martinaglv/cute-files.git
7756
Andrew Geissler615f2f12022-07-15 14:00:58 -05007757The recipe this command generates is very similar to the recipe created in
Andrew Geissler09036742021-06-25 14:25:14 -05007758the previous section. However, the :term:`SRC_URI` looks like the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007759
7760 SRC_URI = " \
Andrew Geissler615f2f12022-07-15 14:00:58 -05007761 git://github.com/martinaglv/cute-files.git;protocol=https;branch=master \
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007762 npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \
7763 "
7764
7765In this example,
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007766the main module is taken from the Git repository and dependencies are
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007767taken from the NPM registry. Other than those differences, the recipe is
7768basically the same between the two methods. You can build and deploy the
7769package exactly as described in the previous section that uses the
7770registry modules method.
7771
7772Adding custom metadata to packages
7773----------------------------------
7774
7775The variable
7776:term:`PACKAGE_ADD_METADATA`
7777can be used to add additional metadata to packages. This is reflected in
7778the package control/spec file. To take the ipk format for example, the
7779CONTROL file stored inside would contain the additional metadata as
7780additional lines.
7781
7782The variable can be used in multiple ways, including using suffixes to
7783set it for a specific package type and/or package. Note that the order
7784of precedence is the same as this list:
7785
Patrick Williams0ca19cc2021-08-16 14:03:13 -05007786- ``PACKAGE_ADD_METADATA_<PKGTYPE>:<PN>``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007787
7788- ``PACKAGE_ADD_METADATA_<PKGTYPE>``
7789
Patrick Williams0ca19cc2021-08-16 14:03:13 -05007790- ``PACKAGE_ADD_METADATA:<PN>``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007791
Andrew Geissler09036742021-06-25 14:25:14 -05007792- :term:`PACKAGE_ADD_METADATA`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007793
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007794`<PKGTYPE>` is a parameter and expected to be a distinct name of specific
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007795package type:
7796
7797- IPK for .ipk packages
7798
7799- DEB for .deb packages
7800
7801- RPM for .rpm packages
7802
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007803`<PN>` is a parameter and expected to be a package name.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007804
7805The variable can contain multiple [one-line] metadata fields separated
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007806by the literal sequence '\\n'. The separator can be redefined using the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007807variable flag ``separator``.
7808
William A. Kennington IIIac69b482021-06-02 12:28:27 -07007809Here is an example that adds two custom fields for ipk
Andrew Geisslerc926e172021-05-07 16:11:35 -05007810packages::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007811
7812 PACKAGE_ADD_METADATA_IPK = "Vendor: CustomIpk\nGroup:Applications/Spreadsheets"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007813
7814Efficiently Fetching Source Files During a Build
7815================================================
7816
7817The OpenEmbedded build system works with source files located through
7818the :term:`SRC_URI` variable. When
7819you build something using BitBake, a big part of the operation is
7820locating and downloading all the source tarballs. For images,
7821downloading all the source for various packages can take a significant
7822amount of time.
7823
7824This section shows you how you can use mirrors to speed up fetching
7825source files and how you can pre-fetch files all of which leads to more
7826efficient use of resources and time.
7827
7828Setting up Effective Mirrors
7829----------------------------
7830
7831A good deal that goes into a Yocto Project build is simply downloading
7832all of the source tarballs. Maybe you have been working with another
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00007833build system for which you have built up a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007834sizable directory of source tarballs. Or, perhaps someone else has such
7835a directory for which you have read access. If so, you can save time by
7836adding statements to your configuration file so that the build process
7837checks local directories first for existing tarballs before checking the
7838Internet.
7839
Andrew Geisslerc926e172021-05-07 16:11:35 -05007840Here is an efficient way to set it up in your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007841
7842 SOURCE_MIRROR_URL ?= "file:///home/you/your-download-dir/"
7843 INHERIT += "own-mirrors"
7844 BB_GENERATE_MIRROR_TARBALLS = "1"
7845 # BB_NO_NETWORK = "1"
7846
7847In the previous example, the
7848:term:`BB_GENERATE_MIRROR_TARBALLS`
7849variable causes the OpenEmbedded build system to generate tarballs of
7850the Git repositories and store them in the
7851:term:`DL_DIR` directory. Due to
7852performance reasons, generating and storing these tarballs is not the
7853build system's default behavior.
7854
7855You can also use the
7856:term:`PREMIRRORS` variable. For
7857an example, see the variable's glossary entry in the Yocto Project
7858Reference Manual.
7859
7860Getting Source Files and Suppressing the Build
7861----------------------------------------------
7862
7863Another technique you can use to ready yourself for a successive string
7864of build operations, is to pre-fetch all the source files without
7865actually starting a build. This technique lets you work through any
7866download issues and ultimately gathers all the source files into your
7867download directory :ref:`structure-build-downloads`,
7868which is located with :term:`DL_DIR`.
7869
7870Use the following BitBake command form to fetch all the necessary
Andrew Geisslerc926e172021-05-07 16:11:35 -05007871sources without starting the build::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007872
7873 $ bitbake target --runall=fetch
7874
7875This
7876variation of the BitBake command guarantees that you have all the
7877sources for that BitBake target should you disconnect from the Internet
7878and want to do the build later offline.
7879
7880Selecting an Initialization Manager
7881===================================
7882
7883By default, the Yocto Project uses SysVinit as the initialization
William A. Kennington IIIac69b482021-06-02 12:28:27 -07007884manager. However, there is also support for systemd, which is a full
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007885replacement for init with parallel starting of services, reduced shell
7886overhead and other features that are used by many distributions.
7887
7888Within the system, SysVinit treats system components as services. These
7889services are maintained as shell scripts stored in the ``/etc/init.d/``
7890directory. Services organize into different run levels. This
7891organization is maintained by putting links to the services in the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007892``/etc/rcN.d/`` directories, where `N/` is one of the following options:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007893"S", "0", "1", "2", "3", "4", "5", or "6".
7894
7895.. note::
7896
7897 Each runlevel has a dependency on the previous runlevel. This
7898 dependency allows the services to work properly.
7899
7900In comparison, systemd treats components as units. Using units is a
7901broader concept as compared to using a service. A unit includes several
7902different types of entities. Service is one of the types of entities.
7903The runlevel concept in SysVinit corresponds to the concept of a target
7904in systemd, where target is also a type of supported unit.
7905
7906In a SysVinit-based system, services load sequentially (i.e. one by one)
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007907during init and parallelization is not supported. With systemd, services
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007908start in parallel. Needless to say, the method can have an impact on
7909system startup performance.
7910
7911If you want to use SysVinit, you do not have to do anything. But, if you
7912want to use systemd, you must take some steps as described in the
7913following sections.
7914
7915Using systemd Exclusively
7916-------------------------
7917
Andrew Geisslerc926e172021-05-07 16:11:35 -05007918Set these variables in your distribution configuration file as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007919
Patrick Williams0ca19cc2021-08-16 14:03:13 -05007920 DISTRO_FEATURES:append = " systemd"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007921 VIRTUAL-RUNTIME_init_manager = "systemd"
7922
7923You can also prevent the SysVinit distribution feature from
Andrew Geisslerc926e172021-05-07 16:11:35 -05007924being automatically enabled as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007925
7926 DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
7927
7928Doing so removes any
7929redundant SysVinit scripts.
7930
7931To remove initscripts from your image altogether, set this variable
Andrew Geisslerc926e172021-05-07 16:11:35 -05007932also::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007933
7934 VIRTUAL-RUNTIME_initscripts = ""
7935
7936For information on the backfill variable, see
7937:term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`.
7938
7939Using systemd for the Main Image and Using SysVinit for the Rescue Image
7940------------------------------------------------------------------------
7941
Andrew Geisslerc926e172021-05-07 16:11:35 -05007942Set these variables in your distribution configuration file as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007943
Patrick Williams0ca19cc2021-08-16 14:03:13 -05007944 DISTRO_FEATURES:append = " systemd"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007945 VIRTUAL-RUNTIME_init_manager = "systemd"
7946
7947Doing so causes your main image to use the
7948``packagegroup-core-boot.bb`` recipe and systemd. The rescue/minimal
7949image cannot use this package group. However, it can install SysVinit
7950and the appropriate packages will have support for both systemd and
7951SysVinit.
7952
Andrew Geissler9aee5002022-03-30 16:27:02 +00007953Using systemd-journald without a traditional syslog daemon
7954----------------------------------------------------------
7955
7956Counter-intuitively, ``systemd-journald`` is not a syslog runtime or provider,
7957and the proper way to use systemd-journald as your sole logging mechanism is to
7958effectively disable syslog entirely by setting these variables in your distribution
7959configuration file::
7960
7961 VIRTUAL-RUNTIME_syslog = ""
7962 VIRTUAL-RUNTIME_base-utils-syslog = ""
7963
7964Doing so will prevent ``rsyslog`` / ``busybox-syslog`` from being pulled in by
7965default, leaving only ``journald``.
7966
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007967Selecting a Device Manager
7968==========================
7969
7970The Yocto Project provides multiple ways to manage the device manager
7971(``/dev``):
7972
Andrew Geissler5199d832021-09-24 16:47:35 -05007973- Persistent and Pre-Populated ``/dev``: For this case, the ``/dev``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007974 directory is persistent and the required device nodes are created
7975 during the build.
7976
7977- Use ``devtmpfs`` with a Device Manager: For this case, the ``/dev``
7978 directory is provided by the kernel as an in-memory file system and
7979 is automatically populated by the kernel at runtime. Additional
7980 configuration of device nodes is done in user space by a device
7981 manager like ``udev`` or ``busybox-mdev``.
7982
Andrew Geissler5199d832021-09-24 16:47:35 -05007983Using Persistent and Pre-Populated ``/dev``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007984--------------------------------------------
7985
7986To use the static method for device population, you need to set the
7987:term:`USE_DEVFS` variable to "0"
Andrew Geisslerc926e172021-05-07 16:11:35 -05007988as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007989
7990 USE_DEVFS = "0"
7991
7992The content of the resulting ``/dev`` directory is defined in a Device
7993Table file. The
7994:term:`IMAGE_DEVICE_TABLES`
7995variable defines the Device Table to use and should be set in the
7996machine or distro configuration file. Alternatively, you can set this
7997variable in your ``local.conf`` configuration file.
7998
Andrew Geissler09036742021-06-25 14:25:14 -05007999If you do not define the :term:`IMAGE_DEVICE_TABLES` variable, the default
Andrew Geisslerc926e172021-05-07 16:11:35 -05008000``device_table-minimal.txt`` is used::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008001
8002 IMAGE_DEVICE_TABLES = "device_table-mymachine.txt"
8003
8004The population is handled by the ``makedevs`` utility during image
8005creation:
8006
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008007Using ``devtmpfs`` and a Device Manager
8008---------------------------------------
8009
8010To use the dynamic method for device population, you need to use (or be
8011sure to set) the :term:`USE_DEVFS`
Andrew Geisslerc926e172021-05-07 16:11:35 -05008012variable to "1", which is the default::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008013
8014 USE_DEVFS = "1"
8015
8016With this
8017setting, the resulting ``/dev`` directory is populated by the kernel
8018using ``devtmpfs``. Make sure the corresponding kernel configuration
8019variable ``CONFIG_DEVTMPFS`` is set when building you build a Linux
8020kernel.
8021
8022All devices created by ``devtmpfs`` will be owned by ``root`` and have
8023permissions ``0600``.
8024
8025To have more control over the device nodes, you can use a device manager
8026like ``udev`` or ``busybox-mdev``. You choose the device manager by
8027defining the ``VIRTUAL-RUNTIME_dev_manager`` variable in your machine or
8028distro configuration file. Alternatively, you can set this variable in
Andrew Geisslerc926e172021-05-07 16:11:35 -05008029your ``local.conf`` configuration file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008030
8031 VIRTUAL-RUNTIME_dev_manager = "udev"
8032
8033 # Some alternative values
8034 # VIRTUAL-RUNTIME_dev_manager = "busybox-mdev"
8035 # VIRTUAL-RUNTIME_dev_manager = "systemd"
8036
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008037Using an External SCM
8038=====================
8039
8040If you're working on a recipe that pulls from an external Source Code
8041Manager (SCM), it is possible to have the OpenEmbedded build system
8042notice new recipe changes added to the SCM and then build the resulting
8043packages that depend on the new recipes by using the latest versions.
8044This only works for SCMs from which it is possible to get a sensible
8045revision number for changes. Currently, you can do this with Apache
8046Subversion (SVN), Git, and Bazaar (BZR) repositories.
8047
8048To enable this behavior, the :term:`PV` of
8049the recipe needs to reference
Andrew Geisslerc926e172021-05-07 16:11:35 -05008050:term:`SRCPV`. Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008051
8052 PV = "1.2.3+git${SRCPV}"
8053
8054Then, you can add the following to your
Andrew Geisslerc926e172021-05-07 16:11:35 -05008055``local.conf``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008056
Patrick Williams0ca19cc2021-08-16 14:03:13 -05008057 SRCREV:pn-PN = "${AUTOREV}"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008058
8059:term:`PN` is the name of the recipe for
8060which you want to enable automatic source revision updating.
8061
8062If you do not want to update your local configuration file, you can add
Andrew Geisslerc926e172021-05-07 16:11:35 -05008063the following directly to the recipe to finish enabling the feature::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008064
8065 SRCREV = "${AUTOREV}"
8066
8067The Yocto Project provides a distribution named ``poky-bleeding``, whose
Andrew Geisslerc926e172021-05-07 16:11:35 -05008068configuration file contains the line::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008069
8070 require conf/distro/include/poky-floating-revisions.inc
8071
8072This line pulls in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05008073listed include file that contains numerous lines of exactly that form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008074
Patrick Williams0ca19cc2021-08-16 14:03:13 -05008075 #SRCREV:pn-opkg-native ?= "${AUTOREV}"
8076 #SRCREV:pn-opkg-sdk ?= "${AUTOREV}"
8077 #SRCREV:pn-opkg ?= "${AUTOREV}"
8078 #SRCREV:pn-opkg-utils-native ?= "${AUTOREV}"
8079 #SRCREV:pn-opkg-utils ?= "${AUTOREV}"
8080 SRCREV:pn-gconf-dbus ?= "${AUTOREV}"
8081 SRCREV:pn-matchbox-common ?= "${AUTOREV}"
8082 SRCREV:pn-matchbox-config-gtk ?= "${AUTOREV}"
8083 SRCREV:pn-matchbox-desktop ?= "${AUTOREV}"
8084 SRCREV:pn-matchbox-keyboard ?= "${AUTOREV}"
8085 SRCREV:pn-matchbox-panel-2 ?= "${AUTOREV}"
8086 SRCREV:pn-matchbox-themes-extra ?= "${AUTOREV}"
8087 SRCREV:pn-matchbox-terminal ?= "${AUTOREV}"
8088 SRCREV:pn-matchbox-wm ?= "${AUTOREV}"
8089 SRCREV:pn-settings-daemon ?= "${AUTOREV}"
8090 SRCREV:pn-screenshot ?= "${AUTOREV}"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008091 . . .
8092
8093These lines allow you to
8094experiment with building a distribution that tracks the latest
8095development source for numerous packages.
8096
8097.. note::
8098
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008099 The ``poky-bleeding`` distribution is not tested on a regular basis. Keep
8100 this in mind if you use it.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008101
8102Creating a Read-Only Root Filesystem
8103====================================
8104
8105Suppose, for security reasons, you need to disable your target device's
8106root filesystem's write permissions (i.e. you need a read-only root
8107filesystem). Or, perhaps you are running the device's operating system
8108from a read-only storage device. For either case, you can customize your
8109image for that behavior.
8110
8111.. note::
8112
8113 Supporting a read-only root filesystem requires that the system and
8114 applications do not try to write to the root filesystem. You must
8115 configure all parts of the target system to write elsewhere, or to
8116 gracefully fail in the event of attempting to write to the root
8117 filesystem.
8118
8119Creating the Root Filesystem
8120----------------------------
8121
8122To create the read-only root filesystem, simply add the
8123"read-only-rootfs" feature to your image, normally in one of two ways.
8124The first way is to add the "read-only-rootfs" image feature in the
Andrew Geissler09036742021-06-25 14:25:14 -05008125image's recipe file via the :term:`IMAGE_FEATURES` variable::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008126
8127 IMAGE_FEATURES += "read-only-rootfs"
8128
8129As an alternative, you can add the same feature
8130from within your build directory's ``local.conf`` file with the
Andrew Geissler09036742021-06-25 14:25:14 -05008131associated :term:`EXTRA_IMAGE_FEATURES` variable, as in::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008132
8133 EXTRA_IMAGE_FEATURES = "read-only-rootfs"
8134
8135For more information on how to use these variables, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06008136":ref:`dev-manual/common-tasks:Customizing Images Using Custom \`\`IMAGE_FEATURES\`\` and \`\`EXTRA_IMAGE_FEATURES\`\``"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008137section. For information on the variables, see
8138:term:`IMAGE_FEATURES` and
8139:term:`EXTRA_IMAGE_FEATURES`.
8140
8141Post-Installation Scripts and Read-Only Root Filesystem
8142-------------------------------------------------------
8143
8144It is very important that you make sure all post-Installation
8145(``pkg_postinst``) scripts for packages that are installed into the
8146image can be run at the time when the root filesystem is created during
8147the build on the host system. These scripts cannot attempt to run during
Patrick Williams0ca19cc2021-08-16 14:03:13 -05008148the first boot on the target device. With the "read-only-rootfs" feature
8149enabled, the build system makes sure that all post-installation scripts
8150succeed at file system creation time. If any of these scripts
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008151still need to be run after the root filesystem is created, the build
8152immediately fails. These build-time checks ensure that the build fails
8153rather than the target device fails later during its initial boot
8154operation.
8155
8156Most of the common post-installation scripts generated by the build
8157system for the out-of-the-box Yocto Project are engineered so that they
8158can run during root filesystem creation (e.g. post-installation scripts
8159for caching fonts). However, if you create and add custom scripts, you
8160need to be sure they can be run during this file system creation.
8161
8162Here are some common problems that prevent post-installation scripts
8163from running during root filesystem creation:
8164
8165- *Not using $D in front of absolute paths:* The build system defines
8166 ``$``\ :term:`D` when the root
8167 filesystem is created. Furthermore, ``$D`` is blank when the script
8168 is run on the target device. This implies two purposes for ``$D``:
8169 ensuring paths are valid in both the host and target environments,
8170 and checking to determine which environment is being used as a method
8171 for taking appropriate actions.
8172
8173- *Attempting to run processes that are specific to or dependent on the
8174 target architecture:* You can work around these attempts by using
8175 native tools, which run on the host system, to accomplish the same
8176 tasks, or by alternatively running the processes under QEMU, which
8177 has the ``qemu_run_binary`` function. For more information, see the
8178 :ref:`qemu <ref-classes-qemu>` class.
8179
8180Areas With Write Access
8181-----------------------
8182
8183With the "read-only-rootfs" feature enabled, any attempt by the target
8184to write to the root filesystem at runtime fails. Consequently, you must
8185make sure that you configure processes and applications that attempt
8186these types of writes do so to directories with write access (e.g.
8187``/tmp`` or ``/var/run``).
8188
8189Maintaining Build Output Quality
8190================================
8191
8192Many factors can influence the quality of a build. For example, if you
8193upgrade a recipe to use a new version of an upstream software package or
8194you experiment with some new configuration options, subtle changes can
8195occur that you might not detect until later. Consider the case where
8196your recipe is using a newer version of an upstream package. In this
8197case, a new version of a piece of software might introduce an optional
8198dependency on another library, which is auto-detected. If that library
8199has already been built when the software is building, the software will
8200link to the built library and that library will be pulled into your
8201image along with the new software even if you did not want the library.
8202
8203The :ref:`buildhistory <ref-classes-buildhistory>`
William A. Kennington IIIac69b482021-06-02 12:28:27 -07008204class helps you maintain the quality of your build output. You
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008205can use the class to highlight unexpected and possibly unwanted changes
8206in the build output. When you enable build history, it records
8207information about the contents of each package and image and then
8208commits that information to a local Git repository where you can examine
8209the information.
8210
8211The remainder of this section describes the following:
8212
Andrew Geissler09209ee2020-12-13 08:44:15 -06008213- :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 -05008214
Andrew Geissler09209ee2020-12-13 08:44:15 -06008215- :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 -05008216
Andrew Geissler09209ee2020-12-13 08:44:15 -06008217- :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 -05008218
Andrew Geissler09209ee2020-12-13 08:44:15 -06008219- :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 -05008220
8221Enabling and Disabling Build History
8222------------------------------------
8223
8224Build history is disabled by default. To enable it, add the following
Andrew Geissler09036742021-06-25 14:25:14 -05008225:term:`INHERIT` statement and set the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008226:term:`BUILDHISTORY_COMMIT`
8227variable to "1" at the end of your ``conf/local.conf`` file found in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05008228:term:`Build Directory`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008229
8230 INHERIT += "buildhistory"
8231 BUILDHISTORY_COMMIT = "1"
8232
8233Enabling build history as
8234previously described causes the OpenEmbedded build system to collect
8235build output information and commit it as a single commit to a local
Andrew Geissler09209ee2020-12-13 08:44:15 -06008236:ref:`overview-manual/development-environment:git` repository.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008237
8238.. note::
8239
8240 Enabling build history increases your build times slightly,
8241 particularly for images, and increases the amount of disk space used
8242 during the build.
8243
8244You can disable build history by removing the previous statements from
8245your ``conf/local.conf`` file.
8246
8247Understanding What the Build History Contains
8248---------------------------------------------
8249
8250Build history information is kept in
8251``${``\ :term:`TOPDIR`\ ``}/buildhistory``
8252in the Build Directory as defined by the
8253:term:`BUILDHISTORY_DIR`
William A. Kennington IIIac69b482021-06-02 12:28:27 -07008254variable. Here is an example abbreviated listing:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008255
8256.. image:: figures/buildhistory.png
8257 :align: center
Andrew Geisslerd5838332022-05-27 11:33:10 -05008258 :width: 50%
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008259
William A. Kennington IIIac69b482021-06-02 12:28:27 -07008260At the top level, there is a ``metadata-revs`` file that lists the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008261revisions of the repositories for the enabled layers when the build was
8262produced. The rest of the data splits into separate ``packages``,
8263``images`` and ``sdk`` directories, the contents of which are described
8264as follows.
8265
8266Build History Package Information
8267~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8268
8269The history for each package contains a text file that has name-value
8270pairs with information about the package. For example,
8271``buildhistory/packages/i586-poky-linux/busybox/busybox/latest``
8272contains the following:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008273
8274.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008275
8276 PV = 1.22.1
8277 PR = r32
8278 RPROVIDES =
8279 RDEPENDS = glibc (>= 2.20) update-alternatives-opkg
8280 RRECOMMENDS = busybox-syslog busybox-udhcpc update-rc.d
8281 PKGSIZE = 540168
8282 FILES = /usr/bin/* /usr/sbin/* /usr/lib/busybox/* /usr/lib/lib*.so.* \
8283 /etc /com /var /bin/* /sbin/* /lib/*.so.* /lib/udev/rules.d \
8284 /usr/lib/udev/rules.d /usr/share/busybox /usr/lib/busybox/* \
8285 /usr/share/pixmaps /usr/share/applications /usr/share/idl \
8286 /usr/share/omf /usr/share/sounds /usr/lib/bonobo/servers
8287 FILELIST = /bin/busybox /bin/busybox.nosuid /bin/busybox.suid /bin/sh \
8288 /etc/busybox.links.nosuid /etc/busybox.links.suid
8289
8290Most of these
8291name-value pairs correspond to variables used to produce the package.
8292The exceptions are ``FILELIST``, which is the actual list of files in
8293the package, and ``PKGSIZE``, which is the total size of files in the
8294package in bytes.
8295
William A. Kennington IIIac69b482021-06-02 12:28:27 -07008296There is also a file that corresponds to the recipe from which the package
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008297came (e.g. ``buildhistory/packages/i586-poky-linux/busybox/latest``):
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008298
8299.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008300
8301 PV = 1.22.1
8302 PR = r32
8303 DEPENDS = initscripts kern-tools-native update-rc.d-native \
8304 virtual/i586-poky-linux-compilerlibs virtual/i586-poky-linux-gcc \
8305 virtual/libc virtual/update-alternatives
8306 PACKAGES = busybox-ptest busybox-httpd busybox-udhcpd busybox-udhcpc \
8307 busybox-syslog busybox-mdev busybox-hwclock busybox-dbg \
8308 busybox-staticdev busybox-dev busybox-doc busybox-locale busybox
8309
8310Finally, for those recipes fetched from a version control system (e.g.,
William A. Kennington IIIac69b482021-06-02 12:28:27 -07008311Git), there is a file that lists source revisions that are specified in
8312the recipe and the actual revisions used during the build. Listed
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008313and actual revisions might differ when
8314:term:`SRCREV` is set to
8315${:term:`AUTOREV`}. Here is an
8316example assuming
Andrew Geisslerc926e172021-05-07 16:11:35 -05008317``buildhistory/packages/qemux86-poky-linux/linux-yocto/latest_srcrev``)::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008318
8319 # SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
8320 SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
8321 # SRCREV_meta = "a227f20eff056e511d504b2e490f3774ab260d6f"
8322 SRCREV_meta ="a227f20eff056e511d504b2e490f3774ab260d6f"
8323
8324You can use the
8325``buildhistory-collect-srcrevs`` command with the ``-a`` option to
Andrew Geissler09036742021-06-25 14:25:14 -05008326collect the stored :term:`SRCREV` values from build history and report them
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008327in a format suitable for use in global configuration (e.g.,
8328``local.conf`` or a distro include file) to override floating
Andrew Geissler09036742021-06-25 14:25:14 -05008329:term:`AUTOREV` values to a fixed set of revisions. Here is some example
Andrew Geisslerc926e172021-05-07 16:11:35 -05008330output from this command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008331
8332 $ buildhistory-collect-srcrevs -a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008333 # all-poky-linux
Andrew Geissler9aee5002022-03-30 16:27:02 +00008334 SRCREV:pn-ca-certificates = "07de54fdcc5806bde549e1edf60738c6bccf50e8"
8335 SRCREV:pn-update-rc.d = "8636cf478d426b568c1be11dbd9346f67e03adac"
8336 # core2-64-poky-linux
8337 SRCREV:pn-binutils = "87d4632d36323091e731eb07b8aa65f90293da66"
8338 SRCREV:pn-btrfs-tools = "8ad326b2f28c044cb6ed9016d7c3285e23b673c8"
8339 SRCREV_bzip2-tests:pn-bzip2 = "f9061c030a25de5b6829e1abf373057309c734c0"
8340 SRCREV:pn-e2fsprogs = "02540dedd3ddc52c6ae8aaa8a95ce75c3f8be1c0"
8341 SRCREV:pn-file = "504206e53a89fd6eed71aeaf878aa3512418eab1"
8342 SRCREV_glibc:pn-glibc = "24962427071fa532c3c48c918e9d64d719cc8a6c"
8343 SRCREV:pn-gnome-desktop-testing = "e346cd4ed2e2102c9b195b614f3c642d23f5f6e7"
8344 SRCREV:pn-init-system-helpers = "dbd9197569c0935029acd5c9b02b84c68fd937ee"
8345 SRCREV:pn-kmod = "b6ecfc916a17eab8f93be5b09f4e4f845aabd3d1"
8346 SRCREV:pn-libnsl2 = "82245c0c58add79a8e34ab0917358217a70e5100"
8347 SRCREV:pn-libseccomp = "57357d2741a3b3d3e8425889a6b79a130e0fa2f3"
8348 SRCREV:pn-libxcrypt = "50cf2b6dd4fdf04309445f2eec8de7051d953abf"
8349 SRCREV:pn-ncurses = "51d0fd9cc3edb975f04224f29f777f8f448e8ced"
8350 SRCREV:pn-procps = "19a508ea121c0c4ac6d0224575a036de745eaaf8"
8351 SRCREV:pn-psmisc = "5fab6b7ab385080f1db725d6803136ec1841a15f"
8352 SRCREV:pn-ptest-runner = "bcb82804daa8f725b6add259dcef2067e61a75aa"
8353 SRCREV:pn-shared-mime-info = "18e558fa1c8b90b86757ade09a4ba4d6a6cf8f70"
8354 SRCREV:pn-zstd = "e47e674cd09583ff0503f0f6defd6d23d8b718d3"
8355 # qemux86_64-poky-linux
8356 SRCREV_machine:pn-linux-yocto = "20301aeb1a64164b72bc72af58802b315e025c9c"
8357 SRCREV_meta:pn-linux-yocto = "2d38a472b21ae343707c8bd64ac68a9eaca066a0"
8358 # x86_64-linux
8359 SRCREV:pn-binutils-cross-x86_64 = "87d4632d36323091e731eb07b8aa65f90293da66"
8360 SRCREV_glibc:pn-cross-localedef-native = "24962427071fa532c3c48c918e9d64d719cc8a6c"
8361 SRCREV_localedef:pn-cross-localedef-native = "794da69788cbf9bf57b59a852f9f11307663fa87"
8362 SRCREV:pn-debianutils-native = "de14223e5bffe15e374a441302c528ffc1cbed57"
8363 SRCREV:pn-libmodulemd-native = "ee80309bc766d781a144e6879419b29f444d94eb"
8364 SRCREV:pn-virglrenderer-native = "363915595e05fb252e70d6514be2f0c0b5ca312b"
8365 SRCREV:pn-zstd-native = "e47e674cd09583ff0503f0f6defd6d23d8b718d3"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008366
8367.. note::
8368
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008369 Here are some notes on using the ``buildhistory-collect-srcrevs`` command:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008370
Andrew Geissler09036742021-06-25 14:25:14 -05008371 - By default, only values where the :term:`SRCREV` was not hardcoded
Andrew Geissler5f350902021-07-23 13:09:54 -04008372 (usually when :term:`AUTOREV` is used) are reported. Use the ``-a``
8373 option to see all :term:`SRCREV` values.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008374
8375 - The output statements might not have any effect if overrides are
8376 applied elsewhere in the build system configuration. Use the
8377 ``-f`` option to add the ``forcevariable`` override to each output
8378 line if you need to work around this restriction.
8379
8380 - The script does apply special handling when building for multiple
8381 machines. However, the script does place a comment before each set
8382 of values that specifies which triplet to which they belong as
8383 previously shown (e.g., ``i586-poky-linux``).
8384
8385Build History Image Information
8386~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8387
8388The files produced for each image are as follows:
8389
8390- ``image-files:`` A directory containing selected files from the root
8391 filesystem. The files are defined by
8392 :term:`BUILDHISTORY_IMAGE_FILES`.
8393
8394- ``build-id.txt:`` Human-readable information about the build
8395 configuration and metadata source revisions. This file contains the
8396 full build header as printed by BitBake.
8397
8398- ``*.dot:`` Dependency graphs for the image that are compatible with
8399 ``graphviz``.
8400
8401- ``files-in-image.txt:`` A list of files in the image with
8402 permissions, owner, group, size, and symlink information.
8403
8404- ``image-info.txt:`` A text file containing name-value pairs with
8405 information about the image. See the following listing example for
8406 more information.
8407
8408- ``installed-package-names.txt:`` A list of installed packages by name
8409 only.
8410
8411- ``installed-package-sizes.txt:`` A list of installed packages ordered
8412 by size.
8413
8414- ``installed-packages.txt:`` A list of installed packages with full
8415 package filenames.
8416
8417.. note::
8418
8419 Installed package information is able to be gathered and produced
8420 even if package management is disabled for the final image.
8421
8422Here is an example of ``image-info.txt``:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008423
8424.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008425
8426 DISTRO = poky
Andrew Geissler9aee5002022-03-30 16:27:02 +00008427 DISTRO_VERSION = 3.4+snapshot-a0245d7be08f3d24ea1875e9f8872aa6bbff93be
8428 USER_CLASSES = buildstats
8429 IMAGE_CLASSES = qemuboot qemuboot license_image
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008430 IMAGE_FEATURES = debug-tweaks
8431 IMAGE_LINGUAS =
Andrew Geissler9aee5002022-03-30 16:27:02 +00008432 IMAGE_INSTALL = packagegroup-core-boot speex speexdsp
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008433 BAD_RECOMMENDATIONS =
8434 NO_RECOMMENDATIONS =
8435 PACKAGE_EXCLUDE =
Andrew Geissler9aee5002022-03-30 16:27:02 +00008436 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;
8437 IMAGE_POSTPROCESS_COMMAND = buildhistory_get_imageinfo ;
8438 IMAGESIZE = 9265
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008439
8440Other than ``IMAGESIZE``,
8441which is the total size of the files in the image in Kbytes, the
8442name-value pairs are variables that may have influenced the content of
8443the image. This information is often useful when you are trying to
8444determine why a change in the package or file listings has occurred.
8445
8446Using Build History to Gather Image Information Only
8447~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8448
8449As you can see, build history produces image information, including
8450dependency graphs, so you can see why something was pulled into the
8451image. If you are just interested in this information and not interested
8452in collecting specific package or SDK information, you can enable
8453writing only image information without any history by adding the
8454following to your ``conf/local.conf`` file found in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05008455:term:`Build Directory`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008456
8457 INHERIT += "buildhistory"
8458 BUILDHISTORY_COMMIT = "0"
8459 BUILDHISTORY_FEATURES = "image"
8460
8461Here, you set the
8462:term:`BUILDHISTORY_FEATURES`
8463variable to use the image feature only.
8464
8465Build History SDK Information
8466~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8467
8468Build history collects similar information on the contents of SDKs (e.g.
8469``bitbake -c populate_sdk imagename``) as compared to information it
8470collects for images. Furthermore, this information differs depending on
8471whether an extensible or standard SDK is being produced.
8472
8473The following list shows the files produced for SDKs:
8474
8475- ``files-in-sdk.txt:`` A list of files in the SDK with permissions,
8476 owner, group, size, and symlink information. This list includes both
8477 the host and target parts of the SDK.
8478
8479- ``sdk-info.txt:`` A text file containing name-value pairs with
8480 information about the SDK. See the following listing example for more
8481 information.
8482
8483- ``sstate-task-sizes.txt:`` A text file containing name-value pairs
8484 with information about task group sizes (e.g. ``do_populate_sysroot``
8485 tasks have a total size). The ``sstate-task-sizes.txt`` file exists
8486 only when an extensible SDK is created.
8487
8488- ``sstate-package-sizes.txt:`` A text file containing name-value pairs
8489 with information for the shared-state packages and sizes in the SDK.
8490 The ``sstate-package-sizes.txt`` file exists only when an extensible
8491 SDK is created.
8492
8493- ``sdk-files:`` A folder that contains copies of the files mentioned
8494 in ``BUILDHISTORY_SDK_FILES`` if the files are present in the output.
8495 Additionally, the default value of ``BUILDHISTORY_SDK_FILES`` is
8496 specific to the extensible SDK although you can set it differently if
8497 you would like to pull in specific files from the standard SDK.
8498
8499 The default files are ``conf/local.conf``, ``conf/bblayers.conf``,
8500 ``conf/auto.conf``, ``conf/locked-sigs.inc``, and
8501 ``conf/devtool.conf``. Thus, for an extensible SDK, these files get
8502 copied into the ``sdk-files`` directory.
8503
8504- The following information appears under each of the ``host`` and
8505 ``target`` directories for the portions of the SDK that run on the
8506 host and on the target, respectively:
8507
8508 .. note::
8509
8510 The following files for the most part are empty when producing an
8511 extensible SDK because this type of SDK is not constructed from
8512 packages as is the standard SDK.
8513
8514 - ``depends.dot:`` Dependency graph for the SDK that is compatible
8515 with ``graphviz``.
8516
8517 - ``installed-package-names.txt:`` A list of installed packages by
8518 name only.
8519
8520 - ``installed-package-sizes.txt:`` A list of installed packages
8521 ordered by size.
8522
8523 - ``installed-packages.txt:`` A list of installed packages with full
8524 package filenames.
8525
8526Here is an example of ``sdk-info.txt``:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008527
8528.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008529
8530 DISTRO = poky
8531 DISTRO_VERSION = 1.3+snapshot-20130327
8532 SDK_NAME = poky-glibc-i686-arm
8533 SDK_VERSION = 1.3+snapshot
8534 SDKMACHINE =
8535 SDKIMAGE_FEATURES = dev-pkgs dbg-pkgs
8536 BAD_RECOMMENDATIONS =
8537 SDKSIZE = 352712
8538
8539Other than ``SDKSIZE``, which is
8540the total size of the files in the SDK in Kbytes, the name-value pairs
8541are variables that might have influenced the content of the SDK. This
8542information is often useful when you are trying to determine why a
8543change in the package or file listings has occurred.
8544
8545Examining Build History Information
8546~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8547
8548You can examine build history output from the command line or from a web
8549interface.
8550
8551To see any changes that have occurred (assuming you have
8552:term:`BUILDHISTORY_COMMIT` = "1"),
8553you can simply use any Git command that allows you to view the history
Andrew Geisslerc926e172021-05-07 16:11:35 -05008554of a repository. Here is one method::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008555
8556 $ git log -p
8557
8558You need to realize,
8559however, that this method does show changes that are not significant
8560(e.g. a package's size changing by a few bytes).
8561
William A. Kennington IIIac69b482021-06-02 12:28:27 -07008562There is a command-line tool called ``buildhistory-diff``, though,
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008563that queries the Git repository and prints just the differences that
Andrew Geisslerc926e172021-05-07 16:11:35 -05008564might be significant in human-readable form. Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008565
Andrew Geissler95ac1b82021-03-31 14:34:31 -05008566 $ poky/poky/scripts/buildhistory-diff . HEAD^
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008567 Changes to images/qemux86_64/glibc/core-image-minimal (files-in-image.txt):
8568 /etc/anotherpkg.conf was added
8569 /sbin/anotherpkg was added
8570 * (installed-package-names.txt):
8571 * anotherpkg was added
8572 Changes to images/qemux86_64/glibc/core-image-minimal (installed-package-names.txt):
8573 anotherpkg was added
8574 packages/qemux86_64-poky-linux/v86d: PACKAGES: added "v86d-extras"
8575 * PR changed from "r0" to "r1"
8576 * PV changed from "0.1.10" to "0.1.12"
8577 packages/qemux86_64-poky-linux/v86d/v86d: PKGSIZE changed from 110579 to 144381 (+30%)
8578 * PR changed from "r0" to "r1"
8579 * PV changed from "0.1.10" to "0.1.12"
8580
8581.. note::
8582
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008583 The ``buildhistory-diff`` tool requires the ``GitPython``
Andrew Geisslerc926e172021-05-07 16:11:35 -05008584 package. Be sure to install it using Pip3 as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008585
8586 $ pip3 install GitPython --user
8587
8588
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008589 Alternatively, you can install ``python3-git`` using the appropriate
Andrew Geisslereff27472021-10-29 15:35:00 -05008590 distribution package manager (e.g. ``apt``, ``dnf``, or ``zipper``).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008591
8592To see changes to the build history using a web interface, follow the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008593instruction in the ``README`` file
Andrew Geissler09209ee2020-12-13 08:44:15 -06008594:yocto_git:`here </buildhistory-web/>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008595
8596Here is a sample screenshot of the interface:
8597
8598.. image:: figures/buildhistory-web.png
Andrew Geisslerd5838332022-05-27 11:33:10 -05008599 :width: 100%
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008600
8601Performing Automated Runtime Testing
8602====================================
8603
8604The OpenEmbedded build system makes available a series of automated
8605tests for images to verify runtime functionality. You can run these
8606tests on either QEMU or actual target hardware. Tests are written in
8607Python making use of the ``unittest`` module, and the majority of them
8608run commands on the target system over SSH. This section describes how
8609you set up the environment to use these tests, run available tests, and
8610write and add your own tests.
8611
8612For information on the test and QA infrastructure available within the
Andrew Geissler09209ee2020-12-13 08:44:15 -06008613Yocto Project, see the ":ref:`ref-manual/release-process:testing and quality assurance`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008614section in the Yocto Project Reference Manual.
8615
8616Enabling Tests
8617--------------
8618
8619Depending on whether you are planning to run tests using QEMU or on the
8620hardware, you have to take different steps to enable the tests. See the
8621following subsections for information on how to enable both types of
8622tests.
8623
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008624Enabling Runtime Tests on QEMU
8625~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8626
8627In order to run tests, you need to do the following:
8628
8629- *Set up to avoid interaction with sudo for networking:* To
8630 accomplish this, you must do one of the following:
8631
8632 - Add ``NOPASSWD`` for your user in ``/etc/sudoers`` either for all
8633 commands or just for ``runqemu-ifup``. You must provide the full
8634 path as that can change if you are using multiple clones of the
8635 source repository.
8636
8637 .. note::
8638
8639 On some distributions, you also need to comment out "Defaults
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008640 requiretty" in ``/etc/sudoers``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008641
8642 - Manually configure a tap interface for your system.
8643
8644 - Run as root the script in ``scripts/runqemu-gen-tapdevs``, which
8645 should generate a list of tap devices. This is the option
8646 typically chosen for Autobuilder-type environments.
8647
8648 .. note::
8649
8650 - Be sure to use an absolute path when calling this script
8651 with sudo.
8652
8653 - The package recipe ``qemu-helper-native`` is required to run
Andrew Geisslerc926e172021-05-07 16:11:35 -05008654 this script. Build the package using the following command::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008655
8656 $ bitbake qemu-helper-native
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008657
8658- *Set the DISPLAY variable:* You need to set this variable so that
8659 you have an X server available (e.g. start ``vncserver`` for a
8660 headless machine).
8661
8662- *Be sure your host's firewall accepts incoming connections from
8663 192.168.7.0/24:* Some of the tests (in particular DNF tests) start an
8664 HTTP server on a random high number port, which is used to serve
8665 files to the target. The DNF module serves
8666 ``${WORKDIR}/oe-rootfs-repo`` so it can run DNF channel commands.
8667 That means your host's firewall must accept incoming connections from
8668 192.168.7.0/24, which is the default IP range used for tap devices by
8669 ``runqemu``.
8670
8671- *Be sure your host has the correct packages installed:* Depending
8672 your host's distribution, you need to have the following packages
8673 installed:
8674
8675 - Ubuntu and Debian: ``sysstat`` and ``iproute2``
8676
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05008677 - openSUSE: ``sysstat`` and ``iproute2``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008678
8679 - Fedora: ``sysstat`` and ``iproute``
8680
8681 - CentOS: ``sysstat`` and ``iproute``
8682
8683Once you start running the tests, the following happens:
8684
86851. A copy of the root filesystem is written to ``${WORKDIR}/testimage``.
8686
86872. The image is booted under QEMU using the standard ``runqemu`` script.
8688
86893. A default timeout of 500 seconds occurs to allow for the boot process
8690 to reach the login prompt. You can change the timeout period by
8691 setting
8692 :term:`TEST_QEMUBOOT_TIMEOUT`
8693 in the ``local.conf`` file.
8694
86954. Once the boot process is reached and the login prompt appears, the
8696 tests run. The full boot log is written to
8697 ``${WORKDIR}/testimage/qemu_boot_log``.
8698
Andrew Geissler09036742021-06-25 14:25:14 -050086995. Each test module loads in the order found in :term:`TEST_SUITES`. You can
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008700 find the full output of the commands run over SSH in
8701 ``${WORKDIR}/testimgage/ssh_target_log``.
8702
87036. If no failures occur, the task running the tests ends successfully.
8704 You can find the output from the ``unittest`` in the task log at
8705 ``${WORKDIR}/temp/log.do_testimage``.
8706
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008707Enabling Runtime Tests on Hardware
8708~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8709
8710The OpenEmbedded build system can run tests on real hardware, and for
8711certain devices it can also deploy the image to be tested onto the
8712device beforehand.
8713
Andrew Geissler595f6302022-01-24 19:11:47 +00008714For automated deployment, a "controller image" is installed onto the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008715hardware once as part of setup. Then, each time tests are to be run, the
8716following occurs:
8717
Andrew Geissler595f6302022-01-24 19:11:47 +000087181. The controller image is booted into and used to write the image to be
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008719 tested to a second partition.
8720
87212. The device is then rebooted using an external script that you need to
8722 provide.
8723
87243. The device boots into the image to be tested.
8725
8726When running tests (independent of whether the image has been deployed
8727automatically or not), the device is expected to be connected to a
8728network on a pre-determined IP address. You can either use static IP
8729addresses written into the image, or set the image to use DHCP and have
8730your DHCP server on the test network assign a known IP address based on
8731the MAC address of the device.
8732
Andrew Geissler09036742021-06-25 14:25:14 -05008733In order to run tests on hardware, you need to set :term:`TEST_TARGET` to an
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008734appropriate value. For QEMU, you do not have to change anything, the
8735default value is "qemu". For running tests on hardware, the following
William A. Kennington IIIac69b482021-06-02 12:28:27 -07008736options are available:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008737
8738- *"simpleremote":* Choose "simpleremote" if you are going to run tests
8739 on a target system that is already running the image to be tested and
8740 is available on the network. You can use "simpleremote" in
8741 conjunction with either real hardware or an image running within a
8742 separately started QEMU or any other virtual machine manager.
8743
8744- *"SystemdbootTarget":* Choose "SystemdbootTarget" if your hardware is
8745 an EFI-based machine with ``systemd-boot`` as bootloader and
8746 ``core-image-testmaster`` (or something similar) is installed. Also,
8747 your hardware under test must be in a DHCP-enabled network that gives
8748 it the same IP address for each reboot.
8749
8750 If you choose "SystemdbootTarget", there are additional requirements
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05008751 and considerations. See the
8752 ":ref:`dev-manual/common-tasks:selecting systemdboottarget`" section, which
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008753 follows, for more information.
8754
8755- *"BeagleBoneTarget":* Choose "BeagleBoneTarget" if you are deploying
8756 images and running tests on the BeagleBone "Black" or original
8757 "White" hardware. For information on how to use these tests, see the
8758 comments at the top of the BeagleBoneTarget
8759 ``meta-yocto-bsp/lib/oeqa/controllers/beaglebonetarget.py`` file.
8760
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008761- *"EdgeRouterTarget":* Choose "EdgeRouterTarget" if you are deploying
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008762 images and running tests on the Ubiquiti Networks EdgeRouter Lite.
8763 For information on how to use these tests, see the comments at the
8764 top of the EdgeRouterTarget
8765 ``meta-yocto-bsp/lib/oeqa/controllers/edgeroutertarget.py`` file.
8766
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008767- *"GrubTarget":* Choose "GrubTarget" if you are deploying images and running
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008768 tests on any generic PC that boots using GRUB. For information on how
8769 to use these tests, see the comments at the top of the GrubTarget
8770 ``meta-yocto-bsp/lib/oeqa/controllers/grubtarget.py`` file.
8771
8772- *"your-target":* Create your own custom target if you want to run
8773 tests when you are deploying images and running tests on a custom
8774 machine within your BSP layer. To do this, you need to add a Python
8775 unit that defines the target class under ``lib/oeqa/controllers/``
8776 within your layer. You must also provide an empty ``__init__.py``.
8777 For examples, see files in ``meta-yocto-bsp/lib/oeqa/controllers/``.
8778
8779Selecting SystemdbootTarget
8780~~~~~~~~~~~~~~~~~~~~~~~~~~~
8781
Andrew Geissler09036742021-06-25 14:25:14 -05008782If you did not set :term:`TEST_TARGET` to "SystemdbootTarget", then you do
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008783not need any information in this section. You can skip down to the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05008784":ref:`dev-manual/common-tasks:running tests`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008785
Andrew Geissler09036742021-06-25 14:25:14 -05008786If you did set :term:`TEST_TARGET` to "SystemdbootTarget", you also need to
Andrew Geissler595f6302022-01-24 19:11:47 +00008787perform a one-time setup of your controller image by doing the following:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008788
Andrew Geissler09036742021-06-25 14:25:14 -050087891. *Set EFI_PROVIDER:* Be sure that :term:`EFI_PROVIDER` is as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008790
8791 EFI_PROVIDER = "systemd-boot"
8792
Andrew Geissler595f6302022-01-24 19:11:47 +000087932. *Build the controller image:* Build the ``core-image-testmaster`` image.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008794 The ``core-image-testmaster`` recipe is provided as an example for a
Andrew Geissler595f6302022-01-24 19:11:47 +00008795 "controller" image and you can customize the image recipe as you would
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008796 any other recipe.
8797
8798 Here are the image recipe requirements:
8799
8800 - Inherits ``core-image`` so that kernel modules are installed.
8801
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05008802 - Installs normal linux utilities not BusyBox ones (e.g. ``bash``,
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008803 ``coreutils``, ``tar``, ``gzip``, and ``kmod``).
8804
8805 - Uses a custom Initial RAM Disk (initramfs) image with a custom
8806 installer. A normal image that you can install usually creates a
Andrew Geissler595f6302022-01-24 19:11:47 +00008807 single root filesystem partition. This image uses another installer that
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008808 creates a specific partition layout. Not all Board Support
8809 Packages (BSPs) can use an installer. For such cases, you need to
8810 manually create the following partition layout on the target:
8811
8812 - First partition mounted under ``/boot``, labeled "boot".
8813
Andrew Geissler595f6302022-01-24 19:11:47 +00008814 - The main root filesystem partition where this image gets installed,
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008815 which is mounted under ``/``.
8816
8817 - Another partition labeled "testrootfs" where test images get
8818 deployed.
8819
88203. *Install image:* Install the image that you just built on the target
8821 system.
8822
Andrew Geissler09036742021-06-25 14:25:14 -05008823The final thing you need to do when setting :term:`TEST_TARGET` to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008824"SystemdbootTarget" is to set up the test image:
8825
88261. *Set up your local.conf file:* Make sure you have the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05008827 statements in your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008828
8829 IMAGE_FSTYPES += "tar.gz"
8830 INHERIT += "testimage"
8831 TEST_TARGET = "SystemdbootTarget"
8832 TEST_TARGET_IP = "192.168.2.3"
8833
Andrew Geisslerc926e172021-05-07 16:11:35 -050088342. *Build your test image:* Use BitBake to build the image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008835
8836 $ bitbake core-image-sato
8837
8838Power Control
8839~~~~~~~~~~~~~
8840
8841For most hardware targets other than "simpleremote", you can control
8842power:
8843
Andrew Geissler09036742021-06-25 14:25:14 -05008844- You can use :term:`TEST_POWERCONTROL_CMD` together with
8845 :term:`TEST_POWERCONTROL_EXTRA_ARGS` as a command that runs on the host
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008846 and does power cycling. The test code passes one argument to that
8847 command: off, on or cycle (off then on). Here is an example that
Andrew Geisslerc926e172021-05-07 16:11:35 -05008848 could appear in your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008849
8850 TEST_POWERCONTROL_CMD = "powercontrol.exp test 10.11.12.1 nuc1"
8851
8852 In this example, the expect
8853 script does the following:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008854
8855 .. code-block:: shell
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008856
8857 ssh test@10.11.12.1 "pyctl nuc1 arg"
8858
8859 It then runs a Python script that controls power for a label called
8860 ``nuc1``.
8861
8862 .. note::
8863
Andrew Geissler09036742021-06-25 14:25:14 -05008864 You need to customize :term:`TEST_POWERCONTROL_CMD` and
8865 :term:`TEST_POWERCONTROL_EXTRA_ARGS` for your own setup. The one requirement
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008866 is that it accepts "on", "off", and "cycle" as the last argument.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008867
8868- When no command is defined, it connects to the device over SSH and
8869 uses the classic reboot command to reboot the device. Classic reboot
8870 is fine as long as the machine actually reboots (i.e. the SSH test
8871 has not failed). It is useful for scenarios where you have a simple
8872 setup, typically with a single board, and where some manual
8873 interaction is okay from time to time.
8874
8875If you have no hardware to automatically perform power control but still
8876wish to experiment with automated hardware testing, you can use the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008877``dialog-power-control`` script that shows a dialog prompting you to perform
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008878the required power action. This script requires either KDialog or Zenity
8879to be installed. To use this script, set the
8880:term:`TEST_POWERCONTROL_CMD`
Andrew Geisslerc926e172021-05-07 16:11:35 -05008881variable as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008882
8883 TEST_POWERCONTROL_CMD = "${COREBASE}/scripts/contrib/dialog-power-control"
8884
8885Serial Console Connection
8886~~~~~~~~~~~~~~~~~~~~~~~~~
8887
8888For test target classes requiring a serial console to interact with the
8889bootloader (e.g. BeagleBoneTarget, EdgeRouterTarget, and GrubTarget),
8890you need to specify a command to use to connect to the serial console of
8891the target machine by using the
8892:term:`TEST_SERIALCONTROL_CMD`
8893variable and optionally the
8894:term:`TEST_SERIALCONTROL_EXTRA_ARGS`
8895variable.
8896
8897These cases could be a serial terminal program if the machine is
8898connected to a local serial port, or a ``telnet`` or ``ssh`` command
8899connecting to a remote console server. Regardless of the case, the
8900command simply needs to connect to the serial console and forward that
8901connection to standard input and output as any normal terminal program
8902does. For example, to use the picocom terminal program on serial device
Andrew Geisslerc926e172021-05-07 16:11:35 -05008903``/dev/ttyUSB0`` at 115200bps, you would set the variable as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008904
8905 TEST_SERIALCONTROL_CMD = "picocom /dev/ttyUSB0 -b 115200"
8906
8907For local
8908devices where the serial port device disappears when the device reboots,
8909an additional "serdevtry" wrapper script is provided. To use this
8910wrapper, simply prefix the terminal command with
Andrew Geisslerc926e172021-05-07 16:11:35 -05008911``${COREBASE}/scripts/contrib/serdevtry``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008912
8913 TEST_SERIALCONTROL_CMD = "${COREBASE}/scripts/contrib/serdevtry picocom -b 115200 /dev/ttyUSB0"
8914
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008915Running Tests
8916-------------
8917
8918You can start the tests automatically or manually:
8919
8920- *Automatically running tests:* To run the tests automatically after
8921 the OpenEmbedded build system successfully creates an image, first
8922 set the
8923 :term:`TESTIMAGE_AUTO`
8924 variable to "1" in your ``local.conf`` file in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05008925 :term:`Build Directory`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008926
8927 TESTIMAGE_AUTO = "1"
8928
8929 Next, build your image. If the image successfully builds, the
Andrew Geisslerc926e172021-05-07 16:11:35 -05008930 tests run::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008931
8932 bitbake core-image-sato
8933
8934- *Manually running tests:* To manually run the tests, first globally
8935 inherit the
8936 :ref:`testimage <ref-classes-testimage*>` class
Andrew Geisslerc926e172021-05-07 16:11:35 -05008937 by editing your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008938
8939 INHERIT += "testimage"
8940
Andrew Geisslerc926e172021-05-07 16:11:35 -05008941 Next, use BitBake to run the tests::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008942
8943 bitbake -c testimage image
8944
8945All test files reside in ``meta/lib/oeqa/runtime`` in the
8946:term:`Source Directory`. A test name maps
8947directly to a Python module. Each test module may contain a number of
8948individual tests. Tests are usually grouped together by the area tested
8949(e.g tests for systemd reside in ``meta/lib/oeqa/runtime/systemd.py``).
8950
8951You can add tests to any layer provided you place them in the proper
8952area and you extend :term:`BBPATH` in
8953the ``local.conf`` file as normal. Be sure that tests reside in
8954``layer/lib/oeqa/runtime``.
8955
8956.. note::
8957
8958 Be sure that module names do not collide with module names used in
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008959 the default set of test modules in ``meta/lib/oeqa/runtime``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008960
8961You can change the set of tests run by appending or overriding
8962:term:`TEST_SUITES` variable in
Andrew Geissler09036742021-06-25 14:25:14 -05008963``local.conf``. Each name in :term:`TEST_SUITES` represents a required test
8964for the image. Test modules named within :term:`TEST_SUITES` cannot be
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008965skipped even if a test is not suitable for an image (e.g. running the
8966RPM tests on an image without ``rpm``). Appending "auto" to
Andrew Geissler09036742021-06-25 14:25:14 -05008967:term:`TEST_SUITES` causes the build system to try to run all tests that are
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008968suitable for the image (i.e. each test module may elect to skip itself).
8969
Andrew Geissler09036742021-06-25 14:25:14 -05008970The order you list tests in :term:`TEST_SUITES` is important and influences
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008971test dependencies. Consequently, tests that depend on other tests should
8972be added after the test on which they depend. For example, since the
8973``ssh`` test depends on the ``ping`` test, "ssh" needs to come after
8974"ping" in the list. The test class provides no re-ordering or dependency
8975handling.
8976
8977.. note::
8978
8979 Each module can have multiple classes with multiple test methods.
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008980 And, Python ``unittest`` rules apply.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008981
8982Here are some things to keep in mind when running tests:
8983
Andrew Geisslerc926e172021-05-07 16:11:35 -05008984- The default tests for the image are defined as::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008985
Patrick Williams0ca19cc2021-08-16 14:03:13 -05008986 DEFAULT_TEST_SUITES:pn-image = "ping ssh df connman syslog xorg scp vnc date rpm dnf dmesg"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008987
Andrew Geisslerc926e172021-05-07 16:11:35 -05008988- Add your own test to the list of the by using the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008989
Patrick Williams0ca19cc2021-08-16 14:03:13 -05008990 TEST_SUITES:append = " mytest"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008991
Andrew Geisslerc926e172021-05-07 16:11:35 -05008992- Run a specific list of tests as follows::
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008993
8994 TEST_SUITES = "test1 test2 test3"
8995
8996 Remember, order is important. Be sure to place a test that is
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008997 dependent on another test later in the order.
8998
8999Exporting Tests
9000---------------
9001
9002You can export tests so that they can run independently of the build
9003system. Exporting tests is required if you want to be able to hand the
9004test execution off to a scheduler. You can only export tests that are
9005defined in :term:`TEST_SUITES`.
9006
9007If your image is already built, make sure the following are set in your
Andrew Geisslerc926e172021-05-07 16:11:35 -05009008``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009009
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009010 INHERIT += "testexport"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009011 TEST_TARGET_IP = "IP-address-for-the-test-target"
9012 TEST_SERVER_IP = "IP-address-for-the-test-server"
9013
9014You can then export the tests with the
Andrew Geisslerc926e172021-05-07 16:11:35 -05009015following BitBake command form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009016
9017 $ bitbake image -c testexport
9018
9019Exporting the tests places them in the
9020:term:`Build Directory` in
9021``tmp/testexport/``\ image, which is controlled by the
Andrew Geissler09036742021-06-25 14:25:14 -05009022:term:`TEST_EXPORT_DIR` variable.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009023
Andrew Geisslerc926e172021-05-07 16:11:35 -05009024You can now run the tests outside of the build environment::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009025
9026 $ cd tmp/testexport/image
9027 $ ./runexported.py testdata.json
9028
9029Here is a complete example that shows IP addresses and uses the
Andrew Geisslerc926e172021-05-07 16:11:35 -05009030``core-image-sato`` image::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009031
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009032 INHERIT += "testexport"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009033 TEST_TARGET_IP = "192.168.7.2"
9034 TEST_SERVER_IP = "192.168.7.1"
9035
Andrew Geisslerc926e172021-05-07 16:11:35 -05009036Use BitBake to export the tests::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009037
9038 $ bitbake core-image-sato -c testexport
9039
9040Run the tests outside of
Andrew Geisslerc926e172021-05-07 16:11:35 -05009041the build environment using the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009042
9043 $ cd tmp/testexport/core-image-sato
9044 $ ./runexported.py testdata.json
9045
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009046Writing New Tests
9047-----------------
9048
9049As mentioned previously, all new test files need to be in the proper
9050place for the build system to find them. New tests for additional
9051functionality outside of the core should be added to the layer that adds
9052the functionality, in ``layer/lib/oeqa/runtime`` (as long as
9053:term:`BBPATH` is extended in the
9054layer's ``layer.conf`` file as normal). Just remember the following:
9055
9056- Filenames need to map directly to test (module) names.
9057
9058- Do not use module names that collide with existing core tests.
9059
William A. Kennington IIIac69b482021-06-02 12:28:27 -07009060- Minimally, an empty ``__init__.py`` file must be present in the runtime
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009061 directory.
9062
9063To create a new test, start by copying an existing module (e.g.
9064``syslog.py`` or ``gcc.py`` are good ones to use). Test modules can use
9065code from ``meta/lib/oeqa/utils``, which are helper classes.
9066
9067.. note::
9068
9069 Structure shell commands such that you rely on them and they return a
9070 single code for success. Be aware that sometimes you will need to
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009071 parse the output. See the ``df.py`` and ``date.py`` modules for examples.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009072
9073You will notice that all test classes inherit ``oeRuntimeTest``, which
9074is found in ``meta/lib/oetest.py``. This base class offers some helper
9075attributes, which are described in the following sections:
9076
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009077Class Methods
9078~~~~~~~~~~~~~
9079
9080Class methods are as follows:
9081
9082- *hasPackage(pkg):* Returns "True" if ``pkg`` is in the installed
9083 package list of the image, which is based on the manifest file that
9084 is generated during the ``do_rootfs`` task.
9085
9086- *hasFeature(feature):* Returns "True" if the feature is in
9087 :term:`IMAGE_FEATURES` or
9088 :term:`DISTRO_FEATURES`.
9089
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009090Class Attributes
9091~~~~~~~~~~~~~~~~
9092
9093Class attributes are as follows:
9094
9095- *pscmd:* Equals "ps -ef" if ``procps`` is installed in the image.
9096 Otherwise, ``pscmd`` equals "ps" (busybox).
9097
9098- *tc:* The called test context, which gives access to the
9099 following attributes:
9100
9101 - *d:* The BitBake datastore, which allows you to use stuff such
9102 as ``oeRuntimeTest.tc.d.getVar("VIRTUAL-RUNTIME_init_manager")``.
9103
9104 - *testslist and testsrequired:* Used internally. The tests
9105 do not need these.
9106
9107 - *filesdir:* The absolute path to
9108 ``meta/lib/oeqa/runtime/files``, which contains helper files for
9109 tests meant for copying on the target such as small files written
9110 in C for compilation.
9111
9112 - *target:* The target controller object used to deploy and
9113 start an image on a particular target (e.g. Qemu, SimpleRemote,
9114 and SystemdbootTarget). Tests usually use the following:
9115
9116 - *ip:* The target's IP address.
9117
9118 - *server_ip:* The host's IP address, which is usually used
9119 by the DNF test suite.
9120
9121 - *run(cmd, timeout=None):* The single, most used method.
9122 This command is a wrapper for: ``ssh root@host "cmd"``. The
9123 command returns a tuple: (status, output), which are what their
9124 names imply - the return code of "cmd" and whatever output it
9125 produces. The optional timeout argument represents the number
9126 of seconds the test should wait for "cmd" to return. If the
9127 argument is "None", the test uses the default instance's
9128 timeout period, which is 300 seconds. If the argument is "0",
9129 the test runs until the command returns.
9130
9131 - *copy_to(localpath, remotepath):*
9132 ``scp localpath root@ip:remotepath``.
9133
9134 - *copy_from(remotepath, localpath):*
9135 ``scp root@host:remotepath localpath``.
9136
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009137Instance Attributes
9138~~~~~~~~~~~~~~~~~~~
9139
William A. Kennington IIIac69b482021-06-02 12:28:27 -07009140There is a single instance attribute, which is ``target``. The ``target``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009141instance attribute is identical to the class attribute of the same name,
9142which is described in the previous section. This attribute exists as
9143both an instance and class attribute so tests can use
9144``self.target.run(cmd)`` in instance methods instead of
9145``oeRuntimeTest.tc.target.run(cmd)``.
9146
9147Installing Packages in the DUT Without the Package Manager
9148----------------------------------------------------------
9149
9150When a test requires a package built by BitBake, it is possible to
9151install that package. Installing the package does not require a package
9152manager be installed in the device under test (DUT). It does, however,
9153require an SSH connection and the target must be using the
9154``sshcontrol`` class.
9155
9156.. note::
9157
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009158 This method uses ``scp`` to copy files from the host to the target, which
9159 causes permissions and special attributes to be lost.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009160
9161A JSON file is used to define the packages needed by a test. This file
9162must be in the same path as the file used to define the tests.
9163Furthermore, the filename must map directly to the test module name with
9164a ``.json`` extension.
9165
9166The JSON file must include an object with the test name as keys of an
9167object or an array. This object (or array of objects) uses the following
9168data:
9169
Andrew Geissler615f2f12022-07-15 14:00:58 -05009170- "pkg" --- a mandatory string that is the name of the package to be
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009171 installed.
9172
Andrew Geissler615f2f12022-07-15 14:00:58 -05009173- "rm" --- an optional boolean, which defaults to "false", that specifies
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009174 to remove the package after the test.
9175
Andrew Geissler615f2f12022-07-15 14:00:58 -05009176- "extract" --- an optional boolean, which defaults to "false", that
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009177 specifies if the package must be extracted from the package format.
9178 When set to "true", the package is not automatically installed into
9179 the DUT.
9180
9181Following is an example JSON file that handles test "foo" installing
9182package "bar" and test "foobar" installing packages "foo" and "bar".
9183Once the test is complete, the packages are removed from the DUT.
9184::
9185
9186 {
9187 "foo": {
9188 "pkg": "bar"
9189 },
9190 "foobar": [
9191 {
9192 "pkg": "foo",
9193 "rm": true
9194 },
9195 {
9196 "pkg": "bar",
9197 "rm": true
9198 }
9199 ]
9200 }
9201
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009202Debugging Tools and Techniques
9203==============================
9204
9205The exact method for debugging build failures depends on the nature of
9206the problem and on the system's area from which the bug originates.
9207Standard debugging practices such as comparison against the last known
9208working version with examination of the changes and the re-application
9209of steps to identify the one causing the problem are valid for the Yocto
9210Project just as they are for any other system. Even though it is
9211impossible to detail every possible potential failure, this section
9212provides some general tips to aid in debugging given a variety of
9213situations.
9214
9215.. note::
9216
9217 A useful feature for debugging is the error reporting tool.
9218 Configuring the Yocto Project to use this tool causes the
9219 OpenEmbedded build system to produce error reporting commands as part
9220 of the console output. You can enter the commands after the build
9221 completes to log error information into a common database, that can
9222 help you figure out what might be going wrong. For information on how
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009223 to enable and use this feature, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06009224 ":ref:`dev-manual/common-tasks:using the error reporting tool`"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009225 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009226
9227The following list shows the debugging topics in the remainder of this
9228section:
9229
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009230- ":ref:`dev-manual/common-tasks:viewing logs from failed tasks`" describes
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009231 how to find and view logs from tasks that failed during the build
9232 process.
9233
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009234- ":ref:`dev-manual/common-tasks:viewing variable values`" describes how to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009235 use the BitBake ``-e`` option to examine variable values after a
9236 recipe has been parsed.
9237
Andrew Geissler09209ee2020-12-13 08:44:15 -06009238- ":ref:`dev-manual/common-tasks:viewing package information with \`\`oe-pkgdata-util\`\``"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009239 describes how to use the ``oe-pkgdata-util`` utility to query
9240 :term:`PKGDATA_DIR` and
9241 display package-related information for built packages.
9242
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009243- ":ref:`dev-manual/common-tasks:viewing dependencies between recipes and tasks`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009244 describes how to use the BitBake ``-g`` option to display recipe
9245 dependency information used during the build.
9246
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009247- ":ref:`dev-manual/common-tasks:viewing task variable dependencies`" describes
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009248 how to use the ``bitbake-dumpsig`` command in conjunction with key
9249 subdirectories in the
9250 :term:`Build Directory` to determine
9251 variable dependencies.
9252
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009253- ":ref:`dev-manual/common-tasks:running specific tasks`" describes
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009254 how to use several BitBake options (e.g. ``-c``, ``-C``, and ``-f``)
9255 to run specific tasks in the build chain. It can be useful to run
9256 tasks "out-of-order" when trying isolate build issues.
9257
Andrew Geisslerd5838332022-05-27 11:33:10 -05009258- ":ref:`dev-manual/common-tasks:general BitBake problems`" describes how
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009259 to use BitBake's ``-D`` debug output option to reveal more about what
9260 BitBake is doing during the build.
9261
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009262- ":ref:`dev-manual/common-tasks:building with no dependencies`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009263 describes how to use the BitBake ``-b`` option to build a recipe
9264 while ignoring dependencies.
9265
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009266- ":ref:`dev-manual/common-tasks:recipe logging mechanisms`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009267 describes how to use the many recipe logging functions to produce
9268 debugging output and report errors and warnings.
9269
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009270- ":ref:`dev-manual/common-tasks:debugging parallel make races`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009271 describes how to debug situations where the build consists of several
9272 parts that are run simultaneously and when the output or result of
9273 one part is not ready for use with a different part of the build that
9274 depends on that output.
9275
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009276- ":ref:`dev-manual/common-tasks:debugging with the gnu project debugger (gdb) remotely`"
9277 describes how to use GDB to allow you to examine running programs, which can
9278 help you fix problems.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009279
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009280- ":ref:`dev-manual/common-tasks:debugging with the gnu project debugger (gdb) on the target`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009281 describes how to use GDB directly on target hardware for debugging.
9282
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009283- ":ref:`dev-manual/common-tasks:other debugging tips`" describes
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009284 miscellaneous debugging tips that can be useful.
9285
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009286Viewing Logs from Failed Tasks
9287------------------------------
9288
9289You can find the log for a task in the file
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009290``${``\ :term:`WORKDIR`\ ``}/temp/log.do_``\ `taskname`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009291For example, the log for the
9292:ref:`ref-tasks-compile` task of the
9293QEMU minimal image for the x86 machine (``qemux86``) might be in
9294``tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/temp/log.do_compile``.
9295To see the commands :term:`BitBake` ran
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009296to generate a log, look at the corresponding ``run.do_``\ `taskname` file
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009297in the same directory.
9298
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009299``log.do_``\ `taskname` and ``run.do_``\ `taskname` are actually symbolic
9300links to ``log.do_``\ `taskname`\ ``.``\ `pid` and
9301``log.run_``\ `taskname`\ ``.``\ `pid`, where `pid` is the PID the task had
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009302when it ran. The symlinks always point to the files corresponding to the
9303most recent run.
9304
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009305Viewing Variable Values
9306-----------------------
9307
9308Sometimes you need to know the value of a variable as a result of
9309BitBake's parsing step. This could be because some unexpected behavior
9310occurred in your project. Perhaps an attempt to :ref:`modify a variable
9311<bitbake:bitbake-user-manual/bitbake-user-manual-metadata:modifying existing
9312variables>` did not work out as expected.
9313
9314BitBake's ``-e`` option is used to display variable values after
9315parsing. The following command displays the variable values after the
9316configuration files (i.e. ``local.conf``, ``bblayers.conf``,
Andrew Geisslerc926e172021-05-07 16:11:35 -05009317``bitbake.conf`` and so forth) have been parsed::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009318
9319 $ bitbake -e
9320
9321The following command displays variable values after a specific recipe has
Andrew Geisslerc926e172021-05-07 16:11:35 -05009322been parsed. The variables include those from the configuration as well::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009323
9324 $ bitbake -e recipename
9325
9326.. note::
9327
9328 Each recipe has its own private set of variables (datastore).
9329 Internally, after parsing the configuration, a copy of the resulting
9330 datastore is made prior to parsing each recipe. This copying implies
9331 that variables set in one recipe will not be visible to other
9332 recipes.
9333
9334 Likewise, each task within a recipe gets a private datastore based on
9335 the recipe datastore, which means that variables set within one task
9336 will not be visible to other tasks.
9337
9338In the output of ``bitbake -e``, each variable is preceded by a
9339description of how the variable got its value, including temporary
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009340values that were later overridden. This description also includes
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009341variable flags (varflags) set on the variable. The output can be very
9342helpful during debugging.
9343
9344Variables that are exported to the environment are preceded by
Andrew Geisslerc926e172021-05-07 16:11:35 -05009345``export`` in the output of ``bitbake -e``. See the following example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009346
9347 export CC="i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/ulf/poky/build/tmp/sysroots/qemux86"
9348
9349In addition to variable values, the output of the ``bitbake -e`` and
9350``bitbake -e`` recipe commands includes the following information:
9351
9352- The output starts with a tree listing all configuration files and
9353 classes included globally, recursively listing the files they include
9354 or inherit in turn. Much of the behavior of the OpenEmbedded build
Andrew Geissler09209ee2020-12-13 08:44:15 -06009355 system (including the behavior of the :ref:`ref-manual/tasks:normal recipe build tasks`) is
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009356 implemented in the
9357 :ref:`base <ref-classes-base>` class and the
9358 classes it inherits, rather than being built into BitBake itself.
9359
9360- After the variable values, all functions appear in the output. For
9361 shell functions, variables referenced within the function body are
9362 expanded. If a function has been modified using overrides or using
Patrick Williams0ca19cc2021-08-16 14:03:13 -05009363 override-style operators like ``:append`` and ``:prepend``, then the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009364 final assembled function body appears in the output.
9365
9366Viewing Package Information with ``oe-pkgdata-util``
9367----------------------------------------------------
9368
9369You can use the ``oe-pkgdata-util`` command-line utility to query
9370:term:`PKGDATA_DIR` and display
9371various package-related information. When you use the utility, you must
9372use it to view information on packages that have already been built.
9373
9374Following are a few of the available ``oe-pkgdata-util`` subcommands.
9375
9376.. note::
9377
9378 You can use the standard \* and ? globbing wildcards as part of
9379 package names and paths.
9380
9381- ``oe-pkgdata-util list-pkgs [pattern]``: Lists all packages
9382 that have been built, optionally limiting the match to packages that
9383 match pattern.
9384
9385- ``oe-pkgdata-util list-pkg-files package ...``: Lists the
9386 files and directories contained in the given packages.
9387
9388 .. note::
9389
9390 A different way to view the contents of a package is to look at
9391 the
9392 ``${``\ :term:`WORKDIR`\ ``}/packages-split``
9393 directory of the recipe that generates the package. This directory
9394 is created by the
9395 :ref:`ref-tasks-package` task
9396 and has one subdirectory for each package the recipe generates,
9397 which contains the files stored in that package.
9398
9399 If you want to inspect the ``${WORKDIR}/packages-split``
9400 directory, make sure that
9401 :ref:`rm_work <ref-classes-rm-work>` is not
9402 enabled when you build the recipe.
9403
9404- ``oe-pkgdata-util find-path path ...``: Lists the names of
9405 the packages that contain the given paths. For example, the following
9406 tells us that ``/usr/share/man/man1/make.1`` is contained in the
Andrew Geisslerc926e172021-05-07 16:11:35 -05009407 ``make-doc`` package::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009408
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009409 $ oe-pkgdata-util find-path /usr/share/man/man1/make.1
9410 make-doc: /usr/share/man/man1/make.1
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009411
9412- ``oe-pkgdata-util lookup-recipe package ...``: Lists the name
9413 of the recipes that produce the given packages.
9414
9415For more information on the ``oe-pkgdata-util`` command, use the help
Andrew Geisslerc926e172021-05-07 16:11:35 -05009416facility::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009417
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009418 $ oe-pkgdata-util --help
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009419 $ oe-pkgdata-util subcommand --help
9420
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009421Viewing Dependencies Between Recipes and Tasks
9422----------------------------------------------
9423
9424Sometimes it can be hard to see why BitBake wants to build other recipes
9425before the one you have specified. Dependency information can help you
9426understand why a recipe is built.
9427
9428To generate dependency information for a recipe, run the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05009429command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009430
9431 $ bitbake -g recipename
9432
9433This command writes the following files in the current directory:
9434
9435- ``pn-buildlist``: A list of recipes/targets involved in building
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009436 `recipename`. "Involved" here means that at least one task from the
9437 recipe needs to run when building `recipename` from scratch. Targets
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009438 that are in
9439 :term:`ASSUME_PROVIDED`
9440 are not listed.
9441
9442- ``task-depends.dot``: A graph showing dependencies between tasks.
9443
9444The graphs are in
9445`DOT <https://en.wikipedia.org/wiki/DOT_%28graph_description_language%29>`__
9446format and can be converted to images (e.g. using the ``dot`` tool from
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009447`Graphviz <https://www.graphviz.org/>`__).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009448
9449.. note::
9450
9451 - DOT files use a plain text format. The graphs generated using the
9452 ``bitbake -g`` command are often so large as to be difficult to
Andrew Geisslerd5838332022-05-27 11:33:10 -05009453 read without special pruning (e.g. with BitBake's ``-I`` option)
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009454 and processing. Despite the form and size of the graphs, the
9455 corresponding ``.dot`` files can still be possible to read and
9456 provide useful information.
9457
9458 As an example, the ``task-depends.dot`` file contains lines such
Andrew Geisslerc926e172021-05-07 16:11:35 -05009459 as the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009460
9461 "libxslt.do_configure" -> "libxml2.do_populate_sysroot"
9462
9463 The above example line reveals that the
9464 :ref:`ref-tasks-configure`
9465 task in ``libxslt`` depends on the
9466 :ref:`ref-tasks-populate_sysroot`
9467 task in ``libxml2``, which is a normal
9468 :term:`DEPENDS` dependency
9469 between the two recipes.
9470
9471 - For an example of how ``.dot`` files can be processed, see the
9472 ``scripts/contrib/graph-tool`` Python script, which finds and
9473 displays paths between graph nodes.
9474
9475You can use a different method to view dependency information by using
Andrew Geisslerc926e172021-05-07 16:11:35 -05009476the following command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009477
9478 $ bitbake -g -u taskexp recipename
9479
9480This command
9481displays a GUI window from which you can view build-time and runtime
9482dependencies for the recipes involved in building recipename.
9483
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009484Viewing Task Variable Dependencies
9485----------------------------------
9486
9487As mentioned in the
9488":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-execution:checksums (signatures)`" section of the BitBake
9489User Manual, BitBake tries to automatically determine what variables a
9490task depends on so that it can rerun the task if any values of the
9491variables change. This determination is usually reliable. However, if
9492you do things like construct variable names at runtime, then you might
9493have to manually declare dependencies on those variables using
9494``vardeps`` as described in the
9495":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags`" section of the BitBake
9496User Manual.
9497
9498If you are unsure whether a variable dependency is being picked up
9499automatically for a given task, you can list the variable dependencies
9500BitBake has determined by doing the following:
9501
Andrew Geisslerc926e172021-05-07 16:11:35 -050095021. Build the recipe containing the task::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009503
9504 $ bitbake recipename
9505
95062. Inside the :term:`STAMPS_DIR`
9507 directory, find the signature data (``sigdata``) file that
9508 corresponds to the task. The ``sigdata`` files contain a pickled
9509 Python database of all the metadata that went into creating the input
9510 checksum for the task. As an example, for the
9511 :ref:`ref-tasks-fetch` task of the
9512 ``db`` recipe, the ``sigdata`` file might be found in the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05009513 location::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009514
9515 ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
9516
9517 For tasks that are accelerated through the shared state
Andrew Geissler09209ee2020-12-13 08:44:15 -06009518 (:ref:`sstate <overview-manual/concepts:shared state cache>`) cache, an
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009519 additional ``siginfo`` file is written into
9520 :term:`SSTATE_DIR` along with
9521 the cached task output. The ``siginfo`` files contain exactly the
9522 same information as ``sigdata`` files.
9523
95243. Run ``bitbake-dumpsig`` on the ``sigdata`` or ``siginfo`` file. Here
Andrew Geisslerc926e172021-05-07 16:11:35 -05009525 is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009526
9527 $ bitbake-dumpsig ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
9528
9529 In the output of the above command, you will find a line like the
9530 following, which lists all the (inferred) variable dependencies for
9531 the task. This list also includes indirect dependencies from
9532 variables depending on other variables, recursively.
9533 ::
9534
9535 Task dependencies: ['PV', 'SRCREV', 'SRC_URI', 'SRC_URI[md5sum]', 'SRC_URI[sha256sum]', 'base_do_fetch']
9536
9537 .. note::
9538
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009539 Functions (e.g. ``base_do_fetch``) also count as variable dependencies.
9540 These functions in turn depend on the variables they reference.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009541
9542 The output of ``bitbake-dumpsig`` also includes the value each
9543 variable had, a list of dependencies for each variable, and
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00009544 :term:`BB_BASEHASH_IGNORE_VARS`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009545 information.
9546
9547There is also a ``bitbake-diffsigs`` command for comparing two
9548``siginfo`` or ``sigdata`` files. This command can be helpful when
9549trying to figure out what changed between two versions of a task. If you
9550call ``bitbake-diffsigs`` with just one file, the command behaves like
9551``bitbake-dumpsig``.
9552
9553You can also use BitBake to dump out the signature construction
9554information without executing tasks by using either of the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05009555BitBake command-line options::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009556
9557 ‐‐dump-signatures=SIGNATURE_HANDLER
9558 -S SIGNATURE_HANDLER
9559
9560
9561.. note::
9562
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009563 Two common values for `SIGNATURE_HANDLER` are "none" and "printdiff", which
9564 dump only the signature or compare the dumped signature with the cached one,
9565 respectively.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009566
9567Using BitBake with either of these options causes BitBake to dump out
9568``sigdata`` files in the ``stamps`` directory for every task it would
9569have executed instead of building the specified target package.
9570
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009571Viewing Metadata Used to Create the Input Signature of a Shared State Task
9572--------------------------------------------------------------------------
9573
9574Seeing what metadata went into creating the input signature of a shared
9575state (sstate) task can be a useful debugging aid. This information is
9576available in signature information (``siginfo``) files in
9577:term:`SSTATE_DIR`. For
9578information on how to view and interpret information in ``siginfo``
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009579files, see the
9580":ref:`dev-manual/common-tasks:viewing task variable dependencies`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009581
9582For conceptual information on shared state, see the
Andrew Geissler09209ee2020-12-13 08:44:15 -06009583":ref:`overview-manual/concepts:shared state`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009584section in the Yocto Project Overview and Concepts Manual.
9585
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009586Invalidating Shared State to Force a Task to Run
9587------------------------------------------------
9588
9589The OpenEmbedded build system uses
Andrew Geissler09209ee2020-12-13 08:44:15 -06009590:ref:`checksums <overview-manual/concepts:checksums (signatures)>` and
9591:ref:`overview-manual/concepts:shared state` cache to avoid unnecessarily
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009592rebuilding tasks. Collectively, this scheme is known as "shared state
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009593code".
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009594
9595As with all schemes, this one has some drawbacks. It is possible that
9596you could make implicit changes to your code that the checksum
9597calculations do not take into account. These implicit changes affect a
9598task's output but do not trigger the shared state code into rebuilding a
9599recipe. Consider an example during which a tool changes its output.
9600Assume that the output of ``rpmdeps`` changes. The result of the change
9601should be that all the ``package`` and ``package_write_rpm`` shared
9602state cache items become invalid. However, because the change to the
9603output is external to the code and therefore implicit, the associated
9604shared state cache items do not become invalidated. In this case, the
9605build process uses the cached items rather than running the task again.
9606Obviously, these types of implicit changes can cause problems.
9607
9608To avoid these problems during the build, you need to understand the
9609effects of any changes you make. Realize that changes you make directly
9610to a function are automatically factored into the checksum calculation.
9611Thus, these explicit changes invalidate the associated area of shared
9612state cache. However, you need to be aware of any implicit changes that
9613are not obvious changes to the code and could affect the output of a
9614given task.
9615
9616When you identify an implicit change, you can easily take steps to
9617invalidate the cache and force the tasks to run. The steps you can take
9618are as simple as changing a function's comments in the source code. For
9619example, to invalidate package shared state files, change the comment
9620statements of
9621:ref:`ref-tasks-package` or the
9622comments of one of the functions it calls. Even though the change is
9623purely cosmetic, it causes the checksum to be recalculated and forces
9624the build system to run the task again.
9625
9626.. note::
9627
9628 For an example of a commit that makes a cosmetic change to invalidate
9629 shared state, see this
Andrew Geissler09209ee2020-12-13 08:44:15 -06009630 :yocto_git:`commit </poky/commit/meta/classes/package.bbclass?id=737f8bbb4f27b4837047cb9b4fbfe01dfde36d54>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009631
9632Running Specific Tasks
9633----------------------
9634
9635Any given recipe consists of a set of tasks. The standard BitBake
9636behavior in most cases is: ``do_fetch``, ``do_unpack``, ``do_patch``,
9637``do_configure``, ``do_compile``, ``do_install``, ``do_package``,
9638``do_package_write_*``, and ``do_build``. The default task is
9639``do_build`` and any tasks on which it depends build first. Some tasks,
9640such as ``do_devshell``, are not part of the default build chain. If you
9641wish to run a task that is not part of the default build chain, you can
Andrew Geisslerc926e172021-05-07 16:11:35 -05009642use the ``-c`` option in BitBake. Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009643
9644 $ bitbake matchbox-desktop -c devshell
9645
9646The ``-c`` option respects task dependencies, which means that all other
9647tasks (including tasks from other recipes) that the specified task
9648depends on will be run before the task. Even when you manually specify a
9649task to run with ``-c``, BitBake will only run the task if it considers
9650it "out of date". See the
Andrew Geissler09209ee2020-12-13 08:44:15 -06009651":ref:`overview-manual/concepts:stamp files and the rerunning of tasks`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009652section in the Yocto Project Overview and Concepts Manual for how
9653BitBake determines whether a task is "out of date".
9654
9655If you want to force an up-to-date task to be rerun (e.g. because you
9656made manual modifications to the recipe's
9657:term:`WORKDIR` that you want to try
9658out), then you can use the ``-f`` option.
9659
9660.. note::
9661
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009662 The reason ``-f`` is never required when running the
9663 :ref:`ref-tasks-devshell` task is because the
9664 [\ :ref:`nostamp <bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ]
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009665 variable flag is already set for the task.
9666
Andrew Geisslerc926e172021-05-07 16:11:35 -05009667The following example shows one way you can use the ``-f`` option::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009668
9669 $ bitbake matchbox-desktop
9670 .
9671 .
9672 make some changes to the source code in the work directory
9673 .
9674 .
9675 $ bitbake matchbox-desktop -c compile -f
9676 $ bitbake matchbox-desktop
9677
9678This sequence first builds and then recompiles ``matchbox-desktop``. The
9679last command reruns all tasks (basically the packaging tasks) after the
9680compile. BitBake recognizes that the ``do_compile`` task was rerun and
9681therefore understands that the other tasks also need to be run again.
9682
9683Another, shorter way to rerun a task and all
Andrew Geissler09209ee2020-12-13 08:44:15 -06009684:ref:`ref-manual/tasks:normal recipe build tasks`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009685that depend on it is to use the ``-C`` option.
9686
9687.. note::
9688
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009689 This option is upper-cased and is separate from the ``-c``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009690 option, which is lower-cased.
9691
9692Using this option invalidates the given task and then runs the
9693:ref:`ref-tasks-build` task, which is
9694the default task if no task is given, and the tasks on which it depends.
9695You could replace the final two commands in the previous example with
Andrew Geisslerc926e172021-05-07 16:11:35 -05009696the following single command::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009697
9698 $ bitbake matchbox-desktop -C compile
9699
9700Internally, the ``-f`` and ``-C`` options work by tainting (modifying)
9701the input checksum of the specified task. This tainting indirectly
9702causes the task and its dependent tasks to be rerun through the normal
9703task dependency mechanisms.
9704
9705.. note::
9706
9707 BitBake explicitly keeps track of which tasks have been tainted in
9708 this fashion, and will print warnings such as the following for
9709 builds involving such tasks:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009710
9711 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009712
9713 WARNING: /home/ulf/poky/meta/recipes-sato/matchbox-desktop/matchbox-desktop_2.1.bb.do_compile is tainted from a forced run
9714
9715
9716 The purpose of the warning is to let you know that the work directory
9717 and build output might not be in the clean state they would be in for
9718 a "normal" build, depending on what actions you took. To get rid of
9719 such warnings, you can remove the work directory and rebuild the
Andrew Geisslerc926e172021-05-07 16:11:35 -05009720 recipe, as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009721
9722 $ bitbake matchbox-desktop -c clean
9723 $ bitbake matchbox-desktop
9724
9725
9726You can view a list of tasks in a given package by running the
Andrew Geisslerc926e172021-05-07 16:11:35 -05009727``do_listtasks`` task as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009728
9729 $ bitbake matchbox-desktop -c listtasks
9730
9731The results appear as output to the console and are also in
9732the file ``${WORKDIR}/temp/log.do_listtasks``.
9733
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009734General BitBake Problems
9735------------------------
9736
9737You can see debug output from BitBake by using the ``-D`` option. The
9738debug output gives more information about what BitBake is doing and the
9739reason behind it. Each ``-D`` option you use increases the logging
9740level. The most common usage is ``-DDD``.
9741
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009742The output from ``bitbake -DDD -v targetname`` can reveal why BitBake
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009743chose a certain version of a package or why BitBake picked a certain
9744provider. This command could also help you in a situation where you
9745think BitBake did something unexpected.
9746
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009747Building with No Dependencies
9748-----------------------------
9749
9750To build a specific recipe (``.bb`` file), you can use the following
Andrew Geisslerc926e172021-05-07 16:11:35 -05009751command form::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009752
9753 $ bitbake -b somepath/somerecipe.bb
9754
9755This command form does
9756not check for dependencies. Consequently, you should use it only when
9757you know existing dependencies have been met.
9758
9759.. note::
9760
9761 You can also specify fragments of the filename. In this case, BitBake
9762 checks for a unique match.
9763
9764Recipe Logging Mechanisms
9765-------------------------
9766
9767The Yocto Project provides several logging functions for producing
9768debugging output and reporting errors and warnings. For Python
William A. Kennington IIIac69b482021-06-02 12:28:27 -07009769functions, the following logging functions are available. All of these functions
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009770log to ``${T}/log.do_``\ `task`, and can also log to standard output
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009771(stdout) with the right settings:
9772
9773- ``bb.plain(msg)``: Writes msg as is to the log while also
9774 logging to stdout.
9775
9776- ``bb.note(msg)``: Writes "NOTE: msg" to the log. Also logs to
9777 stdout if BitBake is called with "-v".
9778
9779- ``bb.debug(level, msg)``: Writes "DEBUG: msg" to the
9780 log. Also logs to stdout if the log level is greater than or equal to
Patrick Williams213cb262021-08-07 19:21:33 -05009781 level. See the ":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-intro:usage and syntax`" option
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009782 in the BitBake User Manual for more information.
9783
9784- ``bb.warn(msg)``: Writes "WARNING: msg" to the log while also
9785 logging to stdout.
9786
9787- ``bb.error(msg)``: Writes "ERROR: msg" to the log while also
9788 logging to standard out (stdout).
9789
9790 .. note::
9791
9792 Calling this function does not cause the task to fail.
9793
Andrew Geisslereff27472021-10-29 15:35:00 -05009794- ``bb.fatal(msg)``: This logging function is similar to
9795 ``bb.error(msg)`` but also causes the calling task to fail.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009796
9797 .. note::
9798
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009799 ``bb.fatal()`` raises an exception, which means you do not need to put a
9800 "return" statement after the function.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009801
9802The same logging functions are also available in shell functions, under
9803the names ``bbplain``, ``bbnote``, ``bbdebug``, ``bbwarn``, ``bberror``,
9804and ``bbfatal``. The
9805:ref:`logging <ref-classes-logging>` class
9806implements these functions. See that class in the ``meta/classes``
9807folder of the :term:`Source Directory` for information.
9808
9809Logging With Python
9810~~~~~~~~~~~~~~~~~~~
9811
9812When creating recipes using Python and inserting code that handles build
9813logs, keep in mind the goal is to have informative logs while keeping
9814the console as "silent" as possible. Also, if you want status messages
9815in the log, use the "debug" loglevel.
9816
9817Following is an example written in Python. The code handles logging for
9818a function that determines the number of tasks needed to be run. See the
9819":ref:`ref-tasks-listtasks`"
Andrew Geisslerc926e172021-05-07 16:11:35 -05009820section for additional information::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009821
9822 python do_listtasks() {
9823 bb.debug(2, "Starting to figure out the task list")
9824 if noteworthy_condition:
9825 bb.note("There are 47 tasks to run")
9826 bb.debug(2, "Got to point xyz")
9827 if warning_trigger:
9828 bb.warn("Detected warning_trigger, this might be a problem later.")
9829 if recoverable_error:
9830 bb.error("Hit recoverable_error, you really need to fix this!")
9831 if fatal_error:
9832 bb.fatal("fatal_error detected, unable to print the task list")
9833 bb.plain("The tasks present are abc")
9834 bb.debug(2, "Finished figuring out the tasklist")
9835 }
9836
9837Logging With Bash
9838~~~~~~~~~~~~~~~~~
9839
9840When creating recipes using Bash and inserting code that handles build
Andrew Geissler615f2f12022-07-15 14:00:58 -05009841logs, you have the same goals --- informative with minimal console output.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009842The syntax you use for recipes written in Bash is similar to that of
9843recipes written in Python described in the previous section.
9844
9845Following is an example written in Bash. The code logs the progress of
9846the ``do_my_function`` function.
9847::
9848
9849 do_my_function() {
9850 bbdebug 2 "Running do_my_function"
9851 if [ exceptional_condition ]; then
9852 bbnote "Hit exceptional_condition"
9853 fi
9854 bbdebug 2 "Got to point xyz"
9855 if [ warning_trigger ]; then
9856 bbwarn "Detected warning_trigger, this might cause a problem later."
9857 fi
9858 if [ recoverable_error ]; then
9859 bberror "Hit recoverable_error, correcting"
9860 fi
9861 if [ fatal_error ]; then
9862 bbfatal "fatal_error detected"
9863 fi
9864 bbdebug 2 "Completed do_my_function"
9865 }
9866
9867
9868Debugging Parallel Make Races
9869-----------------------------
9870
9871A parallel ``make`` race occurs when the build consists of several parts
9872that are run simultaneously and a situation occurs when the output or
9873result of one part is not ready for use with a different part of the
9874build that depends on that output. Parallel make races are annoying and
William A. Kennington IIIac69b482021-06-02 12:28:27 -07009875can sometimes be difficult to reproduce and fix. However, there are some simple
9876tips and tricks that can help you debug and fix them. This section
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009877presents a real-world example of an error encountered on the Yocto
9878Project autobuilder and the process used to fix it.
9879
9880.. note::
9881
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009882 If you cannot properly fix a ``make`` race condition, you can work around it
9883 by clearing either the :term:`PARALLEL_MAKE` or :term:`PARALLEL_MAKEINST`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009884 variables.
9885
9886The Failure
9887~~~~~~~~~~~
9888
9889For this example, assume that you are building an image that depends on
9890the "neard" package. And, during the build, BitBake runs into problems
9891and creates the following output.
9892
9893.. note::
9894
9895 This example log file has longer lines artificially broken to make
9896 the listing easier to read.
9897
9898If you examine the output or the log file, you see the failure during
9899``make``:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009900
9901.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009902
9903 | DEBUG: SITE files ['endian-little', 'bit-32', 'ix86-common', 'common-linux', 'common-glibc', 'i586-linux', 'common']
9904 | DEBUG: Executing shell function do_compile
9905 | NOTE: make -j 16
9906 | make --no-print-directory all-am
9907 | /bin/mkdir -p include/near
9908 | /bin/mkdir -p include/near
9909 | /bin/mkdir -p include/near
Andrew Geissler595f6302022-01-24 19:11:47 +00009910 | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009911 0.14-r0/neard-0.14/include/types.h include/near/types.h
Andrew Geissler595f6302022-01-24 19:11:47 +00009912 | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009913 0.14-r0/neard-0.14/include/log.h include/near/log.h
Andrew Geissler595f6302022-01-24 19:11:47 +00009914 | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009915 0.14-r0/neard-0.14/include/plugin.h include/near/plugin.h
9916 | /bin/mkdir -p include/near
9917 | /bin/mkdir -p include/near
9918 | /bin/mkdir -p include/near
Andrew Geissler595f6302022-01-24 19:11:47 +00009919 | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009920 0.14-r0/neard-0.14/include/tag.h include/near/tag.h
9921 | /bin/mkdir -p include/near
Andrew Geissler595f6302022-01-24 19:11:47 +00009922 | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009923 0.14-r0/neard-0.14/include/adapter.h include/near/adapter.h
9924 | /bin/mkdir -p include/near
Andrew Geissler595f6302022-01-24 19:11:47 +00009925 | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009926 0.14-r0/neard-0.14/include/ndef.h include/near/ndef.h
Andrew Geissler595f6302022-01-24 19:11:47 +00009927 | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009928 0.14-r0/neard-0.14/include/tlv.h include/near/tlv.h
9929 | /bin/mkdir -p include/near
9930 | /bin/mkdir -p include/near
Andrew Geissler595f6302022-01-24 19:11:47 +00009931 | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009932 0.14-r0/neard-0.14/include/setting.h include/near/setting.h
9933 | /bin/mkdir -p include/near
9934 | /bin/mkdir -p include/near
9935 | /bin/mkdir -p include/near
Andrew Geissler595f6302022-01-24 19:11:47 +00009936 | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009937 0.14-r0/neard-0.14/include/device.h include/near/device.h
Andrew Geissler595f6302022-01-24 19:11:47 +00009938 | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009939 0.14-r0/neard-0.14/include/nfc_copy.h include/near/nfc_copy.h
Andrew Geissler595f6302022-01-24 19:11:47 +00009940 | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009941 0.14-r0/neard-0.14/include/snep.h include/near/snep.h
Andrew Geissler595f6302022-01-24 19:11:47 +00009942 | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009943 0.14-r0/neard-0.14/include/version.h include/near/version.h
Andrew Geissler595f6302022-01-24 19:11:47 +00009944 | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009945 0.14-r0/neard-0.14/include/dbus.h include/near/dbus.h
9946 | ./src/genbuiltin nfctype1 nfctype2 nfctype3 nfctype4 p2p > src/builtin.h
Andrew Geissler595f6302022-01-24 19:11:47 +00009947 | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/pokybuild/yocto-autobuilder/nightly-x86/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009948 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 +00009949 yocto-autobuilder/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/glib-2.0
9950 -I/home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/sysroots/qemux86/usr/
9951 lib/glib-2.0/include -I/home/pokybuild/yocto-autobuilder/nightly-x86/build/build/
9952 tmp/sysroots/qemux86/usr/include/dbus-1.0 -I/home/pokybuild/yocto-autobuilder/
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009953 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 +00009954 nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/libnl3
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009955 -DNEAR_PLUGIN_BUILTIN -DPLUGINDIR=\""/usr/lib/near/plugins"\"
9956 -DCONFIGDIR=\""/etc/neard\"" -O2 -pipe -g -feliminate-unused-debug-types -c
9957 -o tools/snep-send.o tools/snep-send.c
9958 | In file included from tools/snep-send.c:16:0:
9959 | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
9960 | #include <near/dbus.h>
9961 | ^
9962 | compilation terminated.
9963 | make[1]: *** [tools/snep-send.o] Error 1
9964 | make[1]: *** Waiting for unfinished jobs....
9965 | make: *** [all] Error 2
9966 | ERROR: oe_runmake failed
9967
9968Reproducing the Error
9969~~~~~~~~~~~~~~~~~~~~~
9970
9971Because race conditions are intermittent, they do not manifest
9972themselves every time you do the build. In fact, most times the build
9973will complete without problems even though the potential race condition
9974exists. Thus, once the error surfaces, you need a way to reproduce it.
9975
9976In this example, compiling the "neard" package is causing the problem.
9977So the first thing to do is build "neard" locally. Before you start the
9978build, set the
9979:term:`PARALLEL_MAKE` variable
9980in your ``local.conf`` file to a high number (e.g. "-j 20"). Using a
Andrew Geissler09036742021-06-25 14:25:14 -05009981high value for :term:`PARALLEL_MAKE` increases the chances of the race
Andrew Geisslerc926e172021-05-07 16:11:35 -05009982condition showing up::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009983
9984 $ bitbake neard
9985
Andrew Geisslerc926e172021-05-07 16:11:35 -05009986Once the local build for "neard" completes, start a ``devshell`` build::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009987
9988 $ bitbake neard -c devshell
9989
Andrew Geissler3b8a17c2021-04-15 15:55:55 -05009990For information on how to use a ``devshell``, see the
9991":ref:`dev-manual/common-tasks:using a development shell`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009992
Andrew Geisslerc926e172021-05-07 16:11:35 -05009993In the ``devshell``, do the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009994
9995 $ make clean
9996 $ make tools/snep-send.o
9997
9998The ``devshell`` commands cause the failure to clearly
William A. Kennington IIIac69b482021-06-02 12:28:27 -07009999be visible. In this case, there is a missing dependency for the ``neard``
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010000Makefile target. Here is some abbreviated, sample output with the
Andrew Geisslerc926e172021-05-07 16:11:35 -050010001missing dependency clearly visible at the end::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010002
10003 i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/scott-lenovo/......
10004 .
10005 .
10006 .
10007 tools/snep-send.c
10008 In file included from tools/snep-send.c:16:0:
10009 tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
10010 #include <near/dbus.h>
10011 ^
10012 compilation terminated.
10013 make: *** [tools/snep-send.o] Error 1
10014 $
10015
10016
10017Creating a Patch for the Fix
10018~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10019
10020Because there is a missing dependency for the Makefile target, you need
10021to patch the ``Makefile.am`` file, which is generated from
Andrew Geisslerc926e172021-05-07 16:11:35 -050010022``Makefile.in``. You can use Quilt to create the patch::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010023
10024 $ quilt new parallelmake.patch
10025 Patch patches/parallelmake.patch is now on top
10026 $ quilt add Makefile.am
10027 File Makefile.am added to patch patches/parallelmake.patch
10028
10029For more information on using Quilt, see the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050010030":ref:`dev-manual/common-tasks:using quilt in your workflow`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010031
10032At this point you need to make the edits to ``Makefile.am`` to add the
10033missing dependency. For our example, you have to add the following line
Andrew Geisslerc926e172021-05-07 16:11:35 -050010034to the file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010035
10036 tools/snep-send.$(OBJEXT): include/near/dbus.h
10037
10038Once you have edited the file, use the ``refresh`` command to create the
Andrew Geisslerc926e172021-05-07 16:11:35 -050010039patch::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010040
10041 $ quilt refresh
10042 Refreshed patch patches/parallelmake.patch
10043
William A. Kennington IIIac69b482021-06-02 12:28:27 -070010044Once the patch file is created, you need to add it back to the originating
10045recipe folder. Here is an example assuming a top-level
Andrew Geisslerc926e172021-05-07 16:11:35 -050010046:term:`Source Directory` named ``poky``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010047
10048 $ cp patches/parallelmake.patch poky/meta/recipes-connectivity/neard/neard
10049
10050The final thing you need to do to implement the fix in the build is to
10051update the "neard" recipe (i.e. ``neard-0.14.bb``) so that the
10052:term:`SRC_URI` statement includes
10053the patch file. The recipe file is in the folder above the patch. Here
Andrew Geissler09036742021-06-25 14:25:14 -050010054is what the edited :term:`SRC_URI` statement would look like::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010055
10056 SRC_URI = "${KERNELORG_MIRROR}/linux/network/nfc/${BPN}-${PV}.tar.xz \
10057 file://neard.in \
10058 file://neard.service.in \
10059 file://parallelmake.patch \
10060 "
10061
10062With the patch complete and moved to the correct folder and the
Andrew Geissler09036742021-06-25 14:25:14 -050010063:term:`SRC_URI` statement updated, you can exit the ``devshell``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010064
10065 $ exit
10066
10067Testing the Build
10068~~~~~~~~~~~~~~~~~
10069
10070With everything in place, you can get back to trying the build again
Andrew Geisslerc926e172021-05-07 16:11:35 -050010071locally::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010072
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010073 $ bitbake neard
10074
10075This build should succeed.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010076
10077Now you can open up a ``devshell`` again and repeat the clean and make
Andrew Geisslerc926e172021-05-07 16:11:35 -050010078operations as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010079
10080 $ bitbake neard -c devshell
10081 $ make clean
10082 $ make tools/snep-send.o
10083
10084The build should work without issue.
10085
10086As with all solved problems, if they originated upstream, you need to
10087submit the fix for the recipe in OE-Core and upstream so that the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050010088problem is taken care of at its source. See the
10089":ref:`dev-manual/common-tasks:submitting a change to the yocto project`"
10090section for more information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010091
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010092Debugging With the GNU Project Debugger (GDB) Remotely
10093------------------------------------------------------
10094
10095GDB allows you to examine running programs, which in turn helps you to
10096understand and fix problems. It also allows you to perform post-mortem
10097style analysis of program crashes. GDB is available as a package within
10098the Yocto Project and is installed in SDK images by default. See the
Andrew Geissler09209ee2020-12-13 08:44:15 -060010099":ref:`ref-manual/images:Images`" chapter in the Yocto
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010100Project Reference Manual for a description of these images. You can find
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010101information on GDB at https://sourceware.org/gdb/.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010102
10103.. note::
10104
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010105 For best results, install debug (``-dbg``) packages for the applications you
10106 are going to debug. Doing so makes extra debug symbols available that give
10107 you more meaningful output.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010108
10109Sometimes, due to memory or disk space constraints, it is not possible
10110to use GDB directly on the remote target to debug applications. These
10111constraints arise because GDB needs to load the debugging information
10112and the binaries of the process being debugged. Additionally, GDB needs
10113to perform many computations to locate information such as function
Andrew Geissler615f2f12022-07-15 14:00:58 -050010114names, variable names and values, stack traces and so forth --- even
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010115before starting the debugging process. These extra computations place
10116more load on the target system and can alter the characteristics of the
10117program being debugged.
10118
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010119To help get past the previously mentioned constraints, there are two
10120methods you can use: running a debuginfod server and using gdbserver.
10121
10122Using the debuginfod server method
10123~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10124
Andrew Geisslerc926e172021-05-07 16:11:35 -050010125``debuginfod`` from ``elfutils`` is a way to distribute ``debuginfo`` files.
10126Running a ``debuginfod`` server makes debug symbols readily available,
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010127which means you don't need to download debugging information
10128and the binaries of the process being debugged. You can just fetch
10129debug symbols from the server.
10130
Andrew Geisslerc926e172021-05-07 16:11:35 -050010131To run a ``debuginfod`` server, you need to do the following:
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010132
Andrew Geisslerc926e172021-05-07 16:11:35 -050010133- Ensure that ``debuginfod`` is present in :term:`DISTRO_FEATURES`
10134 (it already is in ``OpenEmbedded-core`` defaults and ``poky`` reference distribution).
10135 If not, set in your distro config file or in ``local.conf``::
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010136
Patrick Williams0ca19cc2021-08-16 14:03:13 -050010137 DISTRO_FEATURES:append = " debuginfod"
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010138
Andrew Geisslerc926e172021-05-07 16:11:35 -050010139 This distro feature enables the server and client library in ``elfutils``,
10140 and enables ``debuginfod`` support in clients (at the moment, ``gdb`` and ``binutils``).
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010141
Andrew Geisslerc926e172021-05-07 16:11:35 -050010142- Run the following commands to launch the ``debuginfod`` server on the host::
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010143
10144 $ oe-debuginfod
10145
Andrew Geisslerc926e172021-05-07 16:11:35 -050010146- To use ``debuginfod`` on the target, you need to know the ip:port where
10147 ``debuginfod`` is listening on the host (port defaults to 8002), and export
10148 that into the shell environment, for example in ``qemu``::
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010149
Andrew Geisslerc926e172021-05-07 16:11:35 -050010150 root@qemux86-64:~# export DEBUGINFOD_URLS="http://192.168.7.1:8002/"
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010151
Andrew Geisslerc926e172021-05-07 16:11:35 -050010152- Then debug info fetching should simply work when running the target ``gdb``,
10153 ``readelf`` or ``objdump``, for example::
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010154
Andrew Geisslerc926e172021-05-07 16:11:35 -050010155 root@qemux86-64:~# gdb /bin/cat
10156 ...
10157 Reading symbols from /bin/cat...
10158 Downloading separate debug info for /bin/cat...
10159 Reading symbols from /home/root/.cache/debuginfod_client/923dc4780cfbc545850c616bffa884b6b5eaf322/debuginfo...
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010160
Andrew Geisslerc926e172021-05-07 16:11:35 -050010161- It's also possible to use ``debuginfod-find`` to just query the server::
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010162
Andrew Geisslerc926e172021-05-07 16:11:35 -050010163 root@qemux86-64:~# debuginfod-find debuginfo /bin/ls
10164 /home/root/.cache/debuginfod_client/356edc585f7f82d46f94fcb87a86a3fe2d2e60bd/debuginfo
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010165
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010166
10167Using the gdbserver method
10168~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10169
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010170gdbserver, which runs on the remote target and does not load any
10171debugging information from the debugged process. Instead, a GDB instance
10172processes the debugging information that is run on a remote computer -
10173the host GDB. The host GDB then sends control commands to gdbserver to
10174make it stop or start the debugged program, as well as read or write
10175memory regions of that debugged program. All the debugging information
10176loaded and processed as well as all the heavy debugging is done by the
10177host GDB. Offloading these processes gives the gdbserver running on the
10178target a chance to remain small and fast.
10179
10180Because the host GDB is responsible for loading the debugging
10181information and for doing the necessary processing to make actual
10182debugging happen, you have to make sure the host can access the
10183unstripped binaries complete with their debugging information and also
10184be sure the target is compiled with no optimizations. The host GDB must
10185also have local access to all the libraries used by the debugged
10186program. Because gdbserver does not need any local debugging
10187information, the binaries on the remote target can remain stripped.
10188However, the binaries must also be compiled without optimization so they
10189match the host's binaries.
10190
10191To remain consistent with GDB documentation and terminology, the binary
10192being debugged on the remote target machine is referred to as the
10193"inferior" binary. For documentation on GDB see the `GDB
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010194site <https://sourceware.org/gdb/documentation/>`__.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010195
10196The following steps show you how to debug using the GNU project
10197debugger.
10198
101991. *Configure your build system to construct the companion debug
10200 filesystem:*
10201
Andrew Geisslerc926e172021-05-07 16:11:35 -050010202 In your ``local.conf`` file, set the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010203
10204 IMAGE_GEN_DEBUGFS = "1"
10205 IMAGE_FSTYPES_DEBUGFS = "tar.bz2"
10206
10207 These options cause the
10208 OpenEmbedded build system to generate a special companion filesystem
10209 fragment, which contains the matching source and debug symbols to
10210 your deployable filesystem. The build system does this by looking at
10211 what is in the deployed filesystem, and pulling the corresponding
10212 ``-dbg`` packages.
10213
10214 The companion debug filesystem is not a complete filesystem, but only
10215 contains the debug fragments. This filesystem must be combined with
10216 the full filesystem for debugging. Subsequent steps in this procedure
10217 show how to combine the partial filesystem with the full filesystem.
10218
102192. *Configure the system to include gdbserver in the target filesystem:*
10220
Andrew Geisslerd5838332022-05-27 11:33:10 -050010221 Make the following addition in your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010222
Andrew Geisslerd5838332022-05-27 11:33:10 -050010223 EXTRA_IMAGE_FEATURES:append = " tools-debug"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010224
10225 The change makes
10226 sure the ``gdbserver`` package is included.
10227
102283. *Build the environment:*
10229
10230 Use the following command to construct the image and the companion
Andrew Geisslerc926e172021-05-07 16:11:35 -050010231 Debug Filesystem::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010232
10233 $ bitbake image
10234
10235 Build the cross GDB component and
10236 make it available for debugging. Build the SDK that matches the
10237 image. Building the SDK is best for a production build that can be
Andrew Geisslerc926e172021-05-07 16:11:35 -050010238 used later for debugging, especially during long term maintenance::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010239
10240 $ bitbake -c populate_sdk image
10241
10242 Alternatively, you can build the minimal toolchain components that
10243 match the target. Doing so creates a smaller than typical SDK and
10244 only contains a minimal set of components with which to build simple
Andrew Geisslerc926e172021-05-07 16:11:35 -050010245 test applications, as well as run the debugger::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010246
10247 $ bitbake meta-toolchain
10248
Andrew Geisslerc926e172021-05-07 16:11:35 -050010249 A final method is to build Gdb itself within the build system::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010250
10251 $ bitbake gdb-cross-<architecture>
10252
10253 Doing so produces a temporary copy of
10254 ``cross-gdb`` you can use for debugging during development. While
10255 this is the quickest approach, the two previous methods in this step
10256 are better when considering long-term maintenance strategies.
10257
10258 .. note::
10259
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010260 If you run ``bitbake gdb-cross``, the OpenEmbedded build system suggests
10261 the actual image (e.g. ``gdb-cross-i586``). The suggestion is usually the
10262 actual name you want to use.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010263
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500102644. *Set up the* ``debugfs``\ *:*
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010265
Andrew Geisslerc926e172021-05-07 16:11:35 -050010266 Run the following commands to set up the ``debugfs``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010267
10268 $ mkdir debugfs
10269 $ cd debugfs
Andrew Geisslerd5838332022-05-27 11:33:10 -050010270 $ tar xvfj build-dir/tmp/deploy/images/machine/image.rootfs.tar.bz2
10271 $ tar xvfj build-dir/tmp/deploy/images/machine/image-dbg.rootfs.tar.bz2
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010272
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500102735. *Set up GDB:*
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010274
10275 Install the SDK (if you built one) and then source the correct
10276 environment file. Sourcing the environment file puts the SDK in your
Andrew Geisslerd5838332022-05-27 11:33:10 -050010277 ``PATH`` environment variable and sets ``$GDB`` to the SDK's debugger.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010278
10279 If you are using the build system, Gdb is located in
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010280 `build-dir`\ ``/tmp/sysroots/``\ `host`\ ``/usr/bin/``\ `architecture`\ ``/``\ `architecture`\ ``-gdb``
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010281
102826. *Boot the target:*
10283
10284 For information on how to run QEMU, see the `QEMU
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010285 Documentation <https://wiki.qemu.org/Documentation/GettingStartedDevelopers>`__.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010286
10287 .. note::
10288
10289 Be sure to verify that your host can access the target via TCP.
10290
102917. *Debug a program:*
10292
10293 Debugging a program involves running gdbserver on the target and then
10294 running Gdb on the host. The example in this step debugs ``gzip``:
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010295
10296 .. code-block:: shell
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010297
10298 root@qemux86:~# gdbserver localhost:1234 /bin/gzip —help
10299
10300 For
10301 additional gdbserver options, see the `GDB Server
10302 Documentation <https://www.gnu.org/software/gdb/documentation/>`__.
10303
10304 After running gdbserver on the target, you need to run Gdb on the
Andrew Geisslerc926e172021-05-07 16:11:35 -050010305 host and configure it and connect to the target. Use these commands::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010306
10307 $ cd directory-holding-the-debugfs-directory
10308 $ arch-gdb
10309 (gdb) set sysroot debugfs
10310 (gdb) set substitute-path /usr/src/debug debugfs/usr/src/debug
10311 (gdb) target remote IP-of-target:1234
10312
10313 At this
10314 point, everything should automatically load (i.e. matching binaries,
10315 symbols and headers).
10316
10317 .. note::
10318
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010319 The Gdb ``set`` commands in the previous example can be placed into the
10320 users ``~/.gdbinit`` file. Upon starting, Gdb automatically runs whatever
10321 commands are in that file.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010322
103238. *Deploying without a full image rebuild:*
10324
10325 In many cases, during development you want a quick method to deploy a
10326 new binary to the target and debug it, without waiting for a full
10327 image build.
10328
10329 One approach to solving this situation is to just build the component
10330 you want to debug. Once you have built the component, copy the
10331 executable directly to both the target and the host ``debugfs``.
10332
10333 If the binary is processed through the debug splitting in
10334 OpenEmbedded, you should also copy the debug items (i.e. ``.debug``
10335 contents and corresponding ``/usr/src/debug`` files) from the work
Andrew Geisslerc926e172021-05-07 16:11:35 -050010336 directory. Here is an example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010337
10338 $ bitbake bash
10339 $ bitbake -c devshell bash
10340 $ cd ..
10341 $ scp packages-split/bash/bin/bash target:/bin/bash
10342 $ cp -a packages-split/bash-dbg/\* path/debugfs
10343
10344Debugging with the GNU Project Debugger (GDB) on the Target
10345-----------------------------------------------------------
10346
10347The previous section addressed using GDB remotely for debugging
10348purposes, which is the most usual case due to the inherent hardware
10349limitations on many embedded devices. However, debugging in the target
10350hardware itself is also possible with more powerful devices. This
10351section describes what you need to do in order to support using GDB to
10352debug on the target hardware.
10353
10354To support this kind of debugging, you need do the following:
10355
Andrew Geisslerd5838332022-05-27 11:33:10 -050010356- Ensure that GDB is on the target. You can do this by making
10357 the following addition to your ``local.conf`` file::
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010358
Andrew Geisslerd5838332022-05-27 11:33:10 -050010359 EXTRA_IMAGE_FEATURES:append = " tools-debug"
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010360
Andrew Geisslerd5838332022-05-27 11:33:10 -050010361- Ensure that debug symbols are present. You can do so by adding the
10362 corresponding ``-dbg`` package to :term:`IMAGE_INSTALL`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010363
Andrew Geisslerd5838332022-05-27 11:33:10 -050010364 IMAGE_INSTALL:append = " packagename-dbg"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010365
Andrew Geisslerd5838332022-05-27 11:33:10 -050010366 Alternatively, you can add the following to ``local.conf`` to include
Andrew Geisslerc926e172021-05-07 16:11:35 -050010367 all the debug symbols::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010368
Andrew Geisslerd5838332022-05-27 11:33:10 -050010369 EXTRA_IMAGE_FEATURES:append = " dbg-pkgs"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010370
10371.. note::
10372
10373 To improve the debug information accuracy, you can reduce the level
10374 of optimization used by the compiler. For example, when adding the
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010375 following line to your ``local.conf`` file, you will reduce optimization
10376 from :term:`FULL_OPTIMIZATION` of "-O2" to :term:`DEBUG_OPTIMIZATION`
Andrew Geisslerc926e172021-05-07 16:11:35 -050010377 of "-O -fno-omit-frame-pointer"::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010378
10379 DEBUG_BUILD = "1"
10380
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010381 Consider that this will reduce the application's performance and is
10382 recommended only for debugging purposes.
10383
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010384Other Debugging Tips
10385--------------------
10386
10387Here are some other tips that you might find useful:
10388
10389- When adding new packages, it is worth watching for undesirable items
10390 making their way into compiler command lines. For example, you do not
10391 want references to local system files like ``/usr/lib/`` or
10392 ``/usr/include/``.
10393
10394- If you want to remove the ``psplash`` boot splashscreen, add
10395 ``psplash=false`` to the kernel command line. Doing so prevents
10396 ``psplash`` from loading and thus allows you to see the console. It
10397 is also possible to switch out of the splashscreen by switching the
10398 virtual console (e.g. Fn+Left or Fn+Right on a Zaurus).
10399
10400- Removing :term:`TMPDIR` (usually
10401 ``tmp/``, within the
10402 :term:`Build Directory`) can often fix
Andrew Geissler09036742021-06-25 14:25:14 -050010403 temporary build issues. Removing :term:`TMPDIR` is usually a relatively
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010404 cheap operation, because task output will be cached in
10405 :term:`SSTATE_DIR` (usually
10406 ``sstate-cache/``, which is also in the Build Directory).
10407
10408 .. note::
10409
Andrew Geissler09036742021-06-25 14:25:14 -050010410 Removing :term:`TMPDIR` might be a workaround rather than a fix.
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010411 Consequently, trying to determine the underlying cause of an issue before
10412 removing the directory is a good idea.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010413
10414- Understanding how a feature is used in practice within existing
10415 recipes can be very helpful. It is recommended that you configure
10416 some method that allows you to quickly search through files.
10417
10418 Using GNU Grep, you can use the following shell function to
10419 recursively search through common recipe-related files, skipping
10420 binary files, ``.git`` directories, and the Build Directory (assuming
Andrew Geisslerc926e172021-05-07 16:11:35 -050010421 its name starts with "build")::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010422
10423 g() {
10424 grep -Ir \
10425 --exclude-dir=.git \
10426 --exclude-dir='build*' \
10427 --include='*.bb*' \
10428 --include='*.inc*' \
10429 --include='*.conf*' \
10430 --include='*.py*' \
10431 "$@"
10432 }
10433
Andrew Geisslerc926e172021-05-07 16:11:35 -050010434 Following are some usage examples::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010435
10436 $ g FOO # Search recursively for "FOO"
10437 $ g -i foo # Search recursively for "foo", ignoring case
10438 $ g -w FOO # Search recursively for "FOO" as a word, ignoring e.g. "FOOBAR"
10439
10440 If figuring
10441 out how some feature works requires a lot of searching, it might
10442 indicate that the documentation should be extended or improved. In
10443 such cases, consider filing a documentation bug using the Yocto
10444 Project implementation of
10445 :yocto_bugs:`Bugzilla <>`. For information on
10446 how to submit a bug against the Yocto Project, see the Yocto Project
Andrew Geissler09209ee2020-12-13 08:44:15 -060010447 Bugzilla :yocto_wiki:`wiki page </Bugzilla_Configuration_and_Bug_Tracking>`
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050010448 and the
10449 ":ref:`dev-manual/common-tasks:submitting a defect against the yocto project`"
10450 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010451
10452 .. note::
10453
10454 The manuals might not be the right place to document variables
10455 that are purely internal and have a limited scope (e.g. internal
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010456 variables used to implement a single ``.bbclass`` file).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010457
10458Making Changes to the Yocto Project
10459===================================
10460
10461Because the Yocto Project is an open-source, community-based project,
10462you can effect changes to the project. This section presents procedures
10463that show you how to submit a defect against the project and how to
10464submit a change.
10465
10466Submitting a Defect Against the Yocto Project
10467---------------------------------------------
10468
10469Use the Yocto Project implementation of
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010470`Bugzilla <https://www.bugzilla.org/about/>`__ to submit a defect (bug)
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010471against the Yocto Project. For additional information on this
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010472implementation of Bugzilla see the ":ref:`Yocto Project
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010473Bugzilla <resources-bugtracker>`" section in the
10474Yocto Project Reference Manual. For more detail on any of the following
10475steps, see the Yocto Project
Andrew Geissler09209ee2020-12-13 08:44:15 -060010476:yocto_wiki:`Bugzilla wiki page </Bugzilla_Configuration_and_Bug_Tracking>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010477
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010478Use the following general steps to submit a bug:
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010479
104801. Open the Yocto Project implementation of :yocto_bugs:`Bugzilla <>`.
10481
104822. Click "File a Bug" to enter a new bug.
10483
104843. Choose the appropriate "Classification", "Product", and "Component"
10485 for which the bug was found. Bugs for the Yocto Project fall into
10486 one of several classifications, which in turn break down into
10487 several products and components. For example, for a bug against the
10488 ``meta-intel`` layer, you would choose "Build System, Metadata &
10489 Runtime", "BSPs", and "bsps-meta-intel", respectively.
10490
104914. Choose the "Version" of the Yocto Project for which you found the
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010492 bug (e.g. &DISTRO;).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010493
104945. Determine and select the "Severity" of the bug. The severity
10495 indicates how the bug impacted your work.
10496
104976. Choose the "Hardware" that the bug impacts.
10498
104997. Choose the "Architecture" that the bug impacts.
10500
105018. Choose a "Documentation change" item for the bug. Fixing a bug might
10502 or might not affect the Yocto Project documentation. If you are
10503 unsure of the impact to the documentation, select "Don't Know".
10504
105059. Provide a brief "Summary" of the bug. Try to limit your summary to
10506 just a line or two and be sure to capture the essence of the bug.
10507
1050810. Provide a detailed "Description" of the bug. You should provide as
10509 much detail as you can about the context, behavior, output, and so
10510 forth that surrounds the bug. You can even attach supporting files
10511 for output from logs by using the "Add an attachment" button.
10512
1051311. Click the "Submit Bug" button submit the bug. A new Bugzilla number
10514 is assigned to the bug and the defect is logged in the bug tracking
10515 system.
10516
10517Once you file a bug, the bug is processed by the Yocto Project Bug
10518Triage Team and further details concerning the bug are assigned (e.g.
10519priority and owner). You are the "Submitter" of the bug and any further
10520categorization, progress, or comments on the bug result in Bugzilla
10521sending you an automated email concerning the particular change or
10522progress to the bug.
10523
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010524Submitting a Change to the Yocto Project
10525----------------------------------------
10526
10527Contributions to the Yocto Project and OpenEmbedded are very welcome.
10528Because the system is extremely configurable and flexible, we recognize
10529that developers will want to extend, configure or optimize it for their
10530specific uses.
10531
10532The Yocto Project uses a mailing list and a patch-based workflow that is
10533similar to the Linux kernel but contains important differences. In
William A. Kennington IIIac69b482021-06-02 12:28:27 -070010534general, there is a mailing list through which you can submit patches. You
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010535should send patches to the appropriate mailing list so that they can be
10536reviewed and merged by the appropriate maintainer. The specific mailing
10537list you need to use depends on the location of the code you are
10538changing. Each component (e.g. layer) should have a ``README`` file that
10539indicates where to send the changes and which process to follow.
10540
10541You can send the patch to the mailing list using whichever approach you
10542feel comfortable with to generate the patch. Once sent, the patch is
10543usually reviewed by the community at large. If somebody has concerns
10544with the patch, they will usually voice their concern over the mailing
10545list. If a patch does not receive any negative reviews, the maintainer
10546of the affected layer typically takes the patch, tests it, and then
10547based on successful testing, merges the patch.
10548
10549The "poky" repository, which is the Yocto Project's reference build
10550environment, is a hybrid repository that contains several individual
10551pieces (e.g. BitBake, Metadata, documentation, and so forth) built using
10552the combo-layer tool. The upstream location used for submitting changes
10553varies by component:
10554
10555- *Core Metadata:* Send your patch to the
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010556 :oe_lists:`openembedded-core </g/openembedded-core>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010557 mailing list. For example, a change to anything under the ``meta`` or
10558 ``scripts`` directories should be sent to this mailing list.
10559
10560- *BitBake:* For changes to BitBake (i.e. anything under the
10561 ``bitbake`` directory), send your patch to the
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010562 :oe_lists:`bitbake-devel </g/bitbake-devel>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010563 mailing list.
10564
Andrew Geisslerc3d88e42020-10-02 09:45:00 -050010565- *"meta-\*" trees:* These trees contain Metadata. Use the
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010566 :yocto_lists:`poky </g/poky>` mailing list.
Andrew Geisslerc3d88e42020-10-02 09:45:00 -050010567
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010568- *Documentation*: For changes to the Yocto Project documentation, use the
10569 :yocto_lists:`docs </g/docs>` mailing list.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010570
10571For changes to other layers hosted in the Yocto Project source
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010572repositories (i.e. ``yoctoproject.org``) and tools use the
10573:yocto_lists:`Yocto Project </g/yocto/>` general mailing list.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010574
10575.. note::
10576
10577 Sometimes a layer's documentation specifies to use a particular
10578 mailing list. If so, use that list.
10579
10580For additional recipes that do not fit into the core Metadata, you
10581should determine which layer the recipe should go into and submit the
10582change in the manner recommended by the documentation (e.g. the
10583``README`` file) supplied with the layer. If in doubt, please ask on the
10584Yocto general mailing list or on the openembedded-devel mailing list.
10585
10586You can also push a change upstream and request a maintainer to pull the
10587change into the component's upstream repository. You do this by pushing
Andrew Geissler09209ee2020-12-13 08:44:15 -060010588to a contribution repository that is upstream. See the
10589":ref:`overview-manual/development-environment:git workflows and the yocto project`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010590section in the Yocto Project Overview and Concepts Manual for additional
10591concepts on working in the Yocto Project development environment.
10592
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010593Maintainers commonly use ``-next`` branches to test submissions prior to
10594merging patches. Thus, you can get an idea of the status of a patch based on
10595whether the patch has been merged into one of these branches. The commonly
10596used testing branches for OpenEmbedded-Core are as follows:
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010597
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010598- *openembedded-core "master-next" branch:* This branch is part of the
10599 :oe_git:`openembedded-core </openembedded-core/>` repository and contains
10600 proposed changes to the core metadata.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010601
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010602- *poky "master-next" branch:* This branch is part of the
Andrew Geissler09209ee2020-12-13 08:44:15 -060010603 :yocto_git:`poky </poky/>` repository and combines proposed
Andrew Geisslerd5838332022-05-27 11:33:10 -050010604 changes to BitBake, the core metadata and the poky distro.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010605
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010606Similarly, stable branches maintained by the project may have corresponding
10607``-next`` branches which collect proposed changes. For example,
10608``&DISTRO_NAME_NO_CAP;-next`` and ``&DISTRO_NAME_NO_CAP_MINUS_ONE;-next``
10609branches in both the "openembdedded-core" and "poky" repositories.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010610
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010611Other layers may have similar testing branches but there is no formal
10612requirement or standard for these so please check the documentation for the
10613layers you are contributing to.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010614
10615The following sections provide procedures for submitting a change.
10616
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010617Preparing Changes for Submission
10618~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010619
106201. *Make Your Changes Locally:* Make your changes in your local Git
10621 repository. You should make small, controlled, isolated changes.
10622 Keeping changes small and isolated aids review, makes
10623 merging/rebasing easier and keeps the change history clean should
10624 anyone need to refer to it in future.
10625
106262. *Stage Your Changes:* Stage your changes by using the ``git add``
10627 command on each file you changed.
10628
106293. *Commit Your Changes:* Commit the change by using the ``git commit``
10630 command. Make sure your commit information follows standards by
10631 following these accepted conventions:
10632
10633 - Be sure to include a "Signed-off-by:" line in the same style as
Patrick Williams03907ee2022-05-01 06:28:52 -050010634 required by the Linux kernel. This can be done by using the
10635 ``git commit -s`` command. Adding this line signifies that you,
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010636 the submitter, have agreed to the Developer's Certificate of
10637 Origin 1.1 as follows:
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010638
10639 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010640
10641 Developer's Certificate of Origin 1.1
10642
10643 By making a contribution to this project, I certify that:
10644
10645 (a) The contribution was created in whole or in part by me and I
10646 have the right to submit it under the open source license
10647 indicated in the file; or
10648
10649 (b) The contribution is based upon previous work that, to the best
10650 of my knowledge, is covered under an appropriate open source
10651 license and I have the right under that license to submit that
10652 work with modifications, whether created in whole or in part
10653 by me, under the same open source license (unless I am
10654 permitted to submit under a different license), as indicated
10655 in the file; or
10656
10657 (c) The contribution was provided directly to me by some other
10658 person who certified (a), (b) or (c) and I have not modified
10659 it.
10660
10661 (d) I understand and agree that this project and the contribution
10662 are public and that a record of the contribution (including all
10663 personal information I submit with it, including my sign-off) is
10664 maintained indefinitely and may be redistributed consistent with
10665 this project or the open source license(s) involved.
10666
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010667 - Provide a single-line summary of the change and, if more
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010668 explanation is needed, provide more detail in the body of the
10669 commit. This summary is typically viewable in the "shortlist" of
10670 changes. Thus, providing something short and descriptive that
10671 gives the reader a summary of the change is useful when viewing a
10672 list of many commits. You should prefix this short description
10673 with the recipe name (if changing a recipe), or else with the
10674 short form path to the file being changed.
10675
10676 - For the body of the commit message, provide detailed information
10677 that describes what you changed, why you made the change, and the
10678 approach you used. It might also be helpful if you mention how you
10679 tested the change. Provide as much detail as you can in the body
10680 of the commit message.
10681
10682 .. note::
10683
10684 You do not need to provide a more detailed explanation of a
10685 change if the change is minor to the point of the single line
10686 summary providing all the information.
10687
10688 - If the change addresses a specific bug or issue that is associated
10689 with a bug-tracking ID, include a reference to that ID in your
10690 detailed description. For example, the Yocto Project uses a
Andrew Geissler615f2f12022-07-15 14:00:58 -050010691 specific convention for bug references --- any commit that addresses
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010692 a specific bug should use the following form for the detailed
10693 description. Be sure to use the actual bug-tracking ID from
Andrew Geisslerc926e172021-05-07 16:11:35 -050010694 Bugzilla for bug-id::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010695
10696 Fixes [YOCTO #bug-id]
10697
10698 detailed description of change
10699
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010700Using Email to Submit a Patch
10701~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10702
10703Depending on the components changed, you need to submit the email to a
10704specific mailing list. For some guidance on which mailing list to use,
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050010705see the
10706:ref:`list <dev-manual/common-tasks:submitting a change to the yocto project>`
10707at the beginning of this section. For a description of all the available
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010708mailing lists, see the ":ref:`Mailing Lists <resources-mailinglist>`" section in the
10709Yocto Project Reference Manual.
10710
10711Here is the general procedure on how to submit a patch through email
10712without using the scripts once the steps in
Andrew Geissler09209ee2020-12-13 08:44:15 -060010713:ref:`dev-manual/common-tasks:preparing changes for submission` have been followed:
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010714
107151. *Format the Commit:* Format the commit into an email message. To
10716 format commits, use the ``git format-patch`` command. When you
10717 provide the command, you must include a revision list or a number of
10718 patches as part of the command. For example, either of these two
10719 commands takes your most recent single commit and formats it as an
Andrew Geisslerc926e172021-05-07 16:11:35 -050010720 email message in the current directory::
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010721
10722 $ git format-patch -1
10723
10724 or ::
10725
10726 $ git format-patch HEAD~
10727
10728 After the command is run, the current directory contains a numbered
10729 ``.patch`` file for the commit.
10730
10731 If you provide several commits as part of the command, the
10732 ``git format-patch`` command produces a series of numbered files in
10733 the current directory – one for each commit. If you have more than
10734 one patch, you should also use the ``--cover`` option with the
10735 command, which generates a cover letter as the first "patch" in the
10736 series. You can then edit the cover letter to provide a description
10737 for the series of patches. For information on the
10738 ``git format-patch`` command, see ``GIT_FORMAT_PATCH(1)`` displayed
10739 using the ``man git-format-patch`` command.
10740
10741 .. note::
10742
10743 If you are or will be a frequent contributor to the Yocto Project
10744 or to OpenEmbedded, you might consider requesting a contrib area
10745 and the necessary associated rights.
10746
107472. *Send the patches via email:* Send the patches to the recipients and
10748 relevant mailing lists by using the ``git send-email`` command.
10749
10750 .. note::
10751
10752 In order to use ``git send-email``, you must have the proper Git packages
10753 installed on your host.
10754 For Ubuntu, Debian, and Fedora the package is ``git-email``.
10755
10756 The ``git send-email`` command sends email by using a local or remote
10757 Mail Transport Agent (MTA) such as ``msmtp``, ``sendmail``, or
10758 through a direct ``smtp`` configuration in your Git ``~/.gitconfig``
10759 file. If you are submitting patches through email only, it is very
10760 important that you submit them without any whitespace or HTML
10761 formatting that either you or your mailer introduces. The maintainer
10762 that receives your patches needs to be able to save and apply them
10763 directly from your emails. A good way to verify that what you are
10764 sending will be applicable by the maintainer is to do a dry run and
10765 send them to yourself and then save and apply them as the maintainer
10766 would.
10767
10768 The ``git send-email`` command is the preferred method for sending
10769 your patches using email since there is no risk of compromising
10770 whitespace in the body of the message, which can occur when you use
10771 your own mail client. The command also has several options that let
10772 you specify recipients and perform further editing of the email
10773 message. For information on how to use the ``git send-email``
10774 command, see ``GIT-SEND-EMAIL(1)`` displayed using the
10775 ``man git-send-email`` command.
10776
10777The Yocto Project uses a `Patchwork instance <https://patchwork.openembedded.org/>`__
10778to track the status of patches submitted to the various mailing lists and to
10779support automated patch testing. Each submitted patch is checked for common
10780mistakes and deviations from the expected patch format and submitters are
10781notified by patchtest if such mistakes are found. This process helps to
10782reduce the burden of patch review on maintainers.
10783
10784.. note::
10785
10786 This system is imperfect and changes can sometimes get lost in the flow.
10787 Asking about the status of a patch or change is reasonable if the change
10788 has been idle for a while with no feedback.
10789
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010790Using Scripts to Push a Change Upstream and Request a Pull
10791~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10792
10793For larger patch series it is preferable to send a pull request which not
10794only includes the patch but also a pointer to a branch that can be pulled
10795from. This involves making a local branch for your changes, pushing this
10796branch to an accessible repository and then using the ``create-pull-request``
10797and ``send-pull-request`` scripts from openembedded-core to create and send a
10798patch series with a link to the branch for review.
10799
10800Follow this procedure to push a change to an upstream "contrib" Git
Andrew Geissler09209ee2020-12-13 08:44:15 -060010801repository once the steps in :ref:`dev-manual/common-tasks:preparing changes for submission` have
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010802been followed:
10803
10804.. note::
10805
10806 You can find general Git information on how to push a change upstream
10807 in the
10808 `Git Community Book <https://git-scm.com/book/en/v2/Distributed-Git-Distributed-Workflows>`__.
10809
108101. *Push Your Commits to a "Contrib" Upstream:* If you have arranged for
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010811 permissions to push to an upstream contrib repository, push the
Andrew Geisslerc926e172021-05-07 16:11:35 -050010812 change to that repository::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010813
10814 $ git push upstream_remote_repo local_branch_name
10815
10816 For example, suppose you have permissions to push
10817 into the upstream ``meta-intel-contrib`` repository and you are
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010818 working in a local branch named `your_name`\ ``/README``. The following
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010819 command pushes your local commits to the ``meta-intel-contrib``
10820 upstream repository and puts the commit in a branch named
Andrew Geisslerc926e172021-05-07 16:11:35 -050010821 `your_name`\ ``/README``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010822
10823 $ git push meta-intel-contrib your_name/README
10824
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600108252. *Determine Who to Notify:* Determine the maintainer or the mailing
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010826 list that you need to notify for the change.
10827
10828 Before submitting any change, you need to be sure who the maintainer
10829 is or what mailing list that you need to notify. Use either these
10830 methods to find out:
10831
10832 - *Maintenance File:* Examine the ``maintainers.inc`` file, which is
10833 located in the :term:`Source Directory` at
10834 ``meta/conf/distro/include``, to see who is responsible for code.
10835
Andrew Geissler09209ee2020-12-13 08:44:15 -060010836 - *Search by File:* Using :ref:`overview-manual/development-environment:git`, you can
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010837 enter the following command to bring up a short list of all
Andrew Geisslerc926e172021-05-07 16:11:35 -050010838 commits against a specific file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010839
10840 git shortlog -- filename
10841
10842 Just provide the name of the file for which you are interested. The
10843 information returned is not ordered by history but does include a
10844 list of everyone who has committed grouped by name. From the list,
10845 you can see who is responsible for the bulk of the changes against
10846 the file.
10847
10848 - *Examine the List of Mailing Lists:* For a list of the Yocto
10849 Project and related mailing lists, see the ":ref:`Mailing
10850 lists <resources-mailinglist>`" section in
10851 the Yocto Project Reference Manual.
10852
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600108533. *Make a Pull Request:* Notify the maintainer or the mailing list that
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010854 you have pushed a change by making a pull request.
10855
10856 The Yocto Project provides two scripts that conveniently let you
10857 generate and send pull requests to the Yocto Project. These scripts
10858 are ``create-pull-request`` and ``send-pull-request``. You can find
10859 these scripts in the ``scripts`` directory within the
10860 :term:`Source Directory` (e.g.
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010861 ``poky/scripts``).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010862
10863 Using these scripts correctly formats the requests without
10864 introducing any whitespace or HTML formatting. The maintainer that
10865 receives your patches either directly or through the mailing list
10866 needs to be able to save and apply them directly from your emails.
10867 Using these scripts is the preferred method for sending patches.
10868
10869 First, create the pull request. For example, the following command
10870 runs the script, specifies the upstream repository in the contrib
10871 directory into which you pushed the change, and provides a subject
Andrew Geisslerc926e172021-05-07 16:11:35 -050010872 line in the created patch files::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010873
Andrew Geissler95ac1b82021-03-31 14:34:31 -050010874 $ poky/scripts/create-pull-request -u meta-intel-contrib -s "Updated Manual Section Reference in README"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010875
10876 Running this script forms ``*.patch`` files in a folder named
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010877 ``pull-``\ `PID` in the current directory. One of the patch files is a
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010878 cover letter.
10879
10880 Before running the ``send-pull-request`` script, you must edit the
10881 cover letter patch to insert information about your change. After
10882 editing the cover letter, send the pull request. For example, the
10883 following command runs the script and specifies the patch directory
10884 and email address. In this example, the email address is a mailing
Andrew Geisslerc926e172021-05-07 16:11:35 -050010885 list::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010886
Andrew Geissler5199d832021-09-24 16:47:35 -050010887 $ poky/scripts/send-pull-request -p ~/meta-intel/pull-10565 -t meta-intel@lists.yoctoproject.org
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010888
10889 You need to follow the prompts as the script is interactive.
10890
10891 .. note::
10892
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010893 For help on using these scripts, simply provide the ``-h``
Andrew Geisslerc926e172021-05-07 16:11:35 -050010894 argument as follows::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010895
10896 $ poky/scripts/create-pull-request -h
10897 $ poky/scripts/send-pull-request -h
10898
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010899Responding to Patch Review
10900~~~~~~~~~~~~~~~~~~~~~~~~~~
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010901
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010902You may get feedback on your submitted patches from other community members
10903or from the automated patchtest service. If issues are identified in your
10904patch then it is usually necessary to address these before the patch will be
10905accepted into the project. In this case you should amend the patch according
10906to the feedback and submit an updated version to the relevant mailing list,
10907copying in the reviewers who provided feedback to the previous version of the
10908patch.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010909
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010910The patch should be amended using ``git commit --amend`` or perhaps ``git
10911rebase`` for more expert git users. You should also modify the ``[PATCH]``
10912tag in the email subject line when sending the revised patch to mark the new
10913iteration as ``[PATCH v2]``, ``[PATCH v3]``, etc as appropriate. This can be
10914done by passing the ``-v`` argument to ``git format-patch`` with a version
10915number.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010916
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010917Lastly please ensure that you also test your revised changes. In particular
10918please don't just edit the patch file written out by ``git format-patch`` and
10919resend it.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010920
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010921Submitting Changes to Stable Release Branches
10922~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010923
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010924The process for proposing changes to a Yocto Project stable branch differs
10925from the steps described above. Changes to a stable branch must address
10926identified bugs or CVEs and should be made carefully in order to avoid the
10927risk of introducing new bugs or breaking backwards compatibility. Typically
10928bug fixes must already be accepted into the master branch before they can be
10929backported to a stable branch unless the bug in question does not affect the
10930master branch or the fix on the master branch is unsuitable for backporting.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010931
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010932The list of stable branches along with the status and maintainer for each
10933branch can be obtained from the
Andrew Geissler09209ee2020-12-13 08:44:15 -060010934:yocto_wiki:`Releases wiki page </Releases>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010935
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010936.. note::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010937
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010938 Changes will not typically be accepted for branches which are marked as
10939 End-Of-Life (EOL).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010940
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010941With this in mind, the steps to submit a change for a stable branch are as
10942follows:
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010943
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600109441. *Identify the bug or CVE to be fixed:* This information should be
10945 collected so that it can be included in your submission.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010946
Patrick Williams213cb262021-08-07 19:21:33 -050010947 See :ref:`dev-manual/common-tasks:checking for vulnerabilities`
10948 for details about CVE tracking.
10949
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600109502. *Check if the fix is already present in the master branch:* This will
10951 result in the most straightforward path into the stable branch for the
10952 fix.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010953
Andrew Geissler615f2f12022-07-15 14:00:58 -050010954 a. *If the fix is present in the master branch --- submit a backport request
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010955 by email:* You should send an email to the relevant stable branch
10956 maintainer and the mailing list with details of the bug or CVE to be
10957 fixed, the commit hash on the master branch that fixes the issue and
10958 the stable branches which you would like this fix to be backported to.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010959
Andrew Geissler615f2f12022-07-15 14:00:58 -050010960 b. *If the fix is not present in the master branch --- submit the fix to the
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010961 master branch first:* This will ensure that the fix passes through the
10962 project's usual patch review and test processes before being accepted.
10963 It will also ensure that bugs are not left unresolved in the master
10964 branch itself. Once the fix is accepted in the master branch a backport
10965 request can be submitted as above.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010966
Andrew Geissler615f2f12022-07-15 14:00:58 -050010967 c. *If the fix is unsuitable for the master branch --- submit a patch
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010968 directly for the stable branch:* This method should be considered as a
10969 last resort. It is typically necessary when the master branch is using
10970 a newer version of the software which includes an upstream fix for the
10971 issue or when the issue has been fixed on the master branch in a way
10972 that introduces backwards incompatible changes. In this case follow the
Andrew Geissler09209ee2020-12-13 08:44:15 -060010973 steps in :ref:`dev-manual/common-tasks:preparing changes for submission` and
10974 :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 -060010975 email to include the name of the stable branch which you are
10976 targetting. This can be done using the ``--subject-prefix`` argument to
10977 ``git format-patch``, for example to submit a patch to the dunfell
10978 branch use
10979 ``git format-patch --subject-prefix='&DISTRO_NAME_NO_CAP_MINUS_ONE;][PATCH' ...``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010980
10981Working With Licenses
10982=====================
10983
Andrew Geissler09209ee2020-12-13 08:44:15 -060010984As mentioned in the ":ref:`overview-manual/development-environment:licensing`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010985section in the Yocto Project Overview and Concepts Manual, open source
10986projects are open to the public and they consequently have different
10987licensing structures in place. This section describes the mechanism by
10988which the :term:`OpenEmbedded Build System`
10989tracks changes to
10990licensing text and covers how to maintain open source license compliance
10991during your project's lifecycle. The section also describes how to
10992enable commercially licensed recipes, which by default are disabled.
10993
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010994Tracking License Changes
10995------------------------
10996
10997The license of an upstream project might change in the future. In order
10998to prevent these changes going unnoticed, the
10999:term:`LIC_FILES_CHKSUM`
11000variable tracks changes to the license text. The checksums are validated
11001at the end of the configure step, and if the checksums do not match, the
11002build will fail.
11003
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011004Specifying the ``LIC_FILES_CHKSUM`` Variable
11005~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11006
Andrew Geissler09036742021-06-25 14:25:14 -050011007The :term:`LIC_FILES_CHKSUM` variable contains checksums of the license text
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011008in the source code for the recipe. Following is an example of how to
Andrew Geissler09036742021-06-25 14:25:14 -050011009specify :term:`LIC_FILES_CHKSUM`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011010
11011 LIC_FILES_CHKSUM = "file://COPYING;md5=xxxx \
11012 file://licfile1.txt;beginline=5;endline=29;md5=yyyy \
11013 file://licfile2.txt;endline=50;md5=zzzz \
11014 ..."
11015
11016.. note::
11017
11018 - When using "beginline" and "endline", realize that line numbering
11019 begins with one and not zero. Also, the included lines are
11020 inclusive (i.e. lines five through and including 29 in the
11021 previous example for ``licfile1.txt``).
11022
11023 - When a license check fails, the selected license text is included
11024 as part of the QA message. Using this output, you can determine
11025 the exact start and finish for the needed license text.
11026
11027The build system uses the :term:`S`
11028variable as the default directory when searching files listed in
Andrew Geissler09036742021-06-25 14:25:14 -050011029:term:`LIC_FILES_CHKSUM`. The previous example employs the default
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011030directory.
11031
Andrew Geisslerc926e172021-05-07 16:11:35 -050011032Consider this next example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011033
11034 LIC_FILES_CHKSUM = "file://src/ls.c;beginline=5;endline=16;\
11035 md5=bb14ed3c4cda583abc85401304b5cd4e"
11036 LIC_FILES_CHKSUM = "file://${WORKDIR}/license.html;md5=5c94767cedb5d6987c902ac850ded2c6"
11037
11038The first line locates a file in ``${S}/src/ls.c`` and isolates lines
11039five through 16 as license text. The second line refers to a file in
11040:term:`WORKDIR`.
11041
Andrew Geissler09036742021-06-25 14:25:14 -050011042Note that :term:`LIC_FILES_CHKSUM` variable is mandatory for all recipes,
11043unless the :term:`LICENSE` variable is set to "CLOSED".
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011044
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011045Explanation of Syntax
11046~~~~~~~~~~~~~~~~~~~~~
11047
Andrew Geissler09036742021-06-25 14:25:14 -050011048As mentioned in the previous section, the :term:`LIC_FILES_CHKSUM` variable
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011049lists all the important files that contain the license text for the
11050source code. It is possible to specify a checksum for an entire file, or
11051a specific section of a file (specified by beginning and ending line
11052numbers with the "beginline" and "endline" parameters, respectively).
11053The latter is useful for source files with a license notice header,
11054README documents, and so forth. If you do not use the "beginline"
11055parameter, then it is assumed that the text begins on the first line of
11056the file. Similarly, if you do not use the "endline" parameter, it is
11057assumed that the license text ends with the last line of the file.
11058
11059The "md5" parameter stores the md5 checksum of the license text. If the
11060license text changes in any way as compared to this parameter then a
11061mismatch occurs. This mismatch triggers a build failure and notifies the
11062developer. Notification allows the developer to review and address the
11063license text changes. Also note that if a mismatch occurs during the
11064build, the correct md5 checksum is placed in the build log and can be
11065easily copied to the recipe.
11066
11067There is no limit to how many files you can specify using the
Andrew Geissler09036742021-06-25 14:25:14 -050011068:term:`LIC_FILES_CHKSUM` variable. Generally, however, every project
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011069requires a few specifications for license tracking. Many projects have a
11070"COPYING" file that stores the license information for all the source
11071code files. This practice allows you to just track the "COPYING" file as
11072long as it is kept up to date.
11073
11074.. note::
11075
11076 - If you specify an empty or invalid "md5" parameter,
11077 :term:`BitBake` returns an md5
11078 mis-match error and displays the correct "md5" parameter value
11079 during the build. The correct parameter is also captured in the
11080 build log.
11081
11082 - If the whole file contains only license text, you do not need to
11083 use the "beginline" and "endline" parameters.
11084
11085Enabling Commercially Licensed Recipes
11086--------------------------------------
11087
11088By default, the OpenEmbedded build system disables components that have
11089commercial or other special licensing requirements. Such requirements
11090are defined on a recipe-by-recipe basis through the
11091:term:`LICENSE_FLAGS` variable
11092definition in the affected recipe. For instance, the
11093``poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly`` recipe
Andrew Geisslerc926e172021-05-07 16:11:35 -050011094contains the following statement::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011095
11096 LICENSE_FLAGS = "commercial"
11097
11098Here is a
11099slightly more complicated example that contains both an explicit recipe
Andrew Geisslerc926e172021-05-07 16:11:35 -050011100name and version (after variable expansion)::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011101
11102 LICENSE_FLAGS = "license_${PN}_${PV}"
11103
11104In order for a component restricted by a
Andrew Geissler09036742021-06-25 14:25:14 -050011105:term:`LICENSE_FLAGS` definition to be enabled and included in an image, it
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011106needs to have a matching entry in the global
Andrew Geissler9aee5002022-03-30 16:27:02 +000011107:term:`LICENSE_FLAGS_ACCEPTED`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011108variable, which is a variable typically defined in your ``local.conf``
11109file. For example, to enable the
11110``poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly`` package, you
11111could add either the string "commercial_gst-plugins-ugly" or the more
Andrew Geissler9aee5002022-03-30 16:27:02 +000011112general string "commercial" to :term:`LICENSE_FLAGS_ACCEPTED`. See the
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050011113":ref:`dev-manual/common-tasks:license flag matching`" section for a full
Andrew Geissler09036742021-06-25 14:25:14 -050011114explanation of how :term:`LICENSE_FLAGS` matching works. Here is the
Andrew Geisslerc926e172021-05-07 16:11:35 -050011115example::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011116
Andrew Geissler9aee5002022-03-30 16:27:02 +000011117 LICENSE_FLAGS_ACCEPTED = "commercial_gst-plugins-ugly"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011118
11119Likewise, to additionally enable the package built from the recipe
11120containing ``LICENSE_FLAGS = "license_${PN}_${PV}"``, and assuming that
11121the actual recipe name was ``emgd_1.10.bb``, the following string would
11122enable that package as well as the original ``gst-plugins-ugly``
Andrew Geisslerc926e172021-05-07 16:11:35 -050011123package::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011124
Andrew Geissler9aee5002022-03-30 16:27:02 +000011125 LICENSE_FLAGS_ACCEPTED = "commercial_gst-plugins-ugly license_emgd_1.10"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011126
11127As a convenience, you do not need to specify the
Andrew Geissler595f6302022-01-24 19:11:47 +000011128complete license string for every package. You can use
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011129an abbreviated form, which consists of just the first portion or
11130portions of the license string before the initial underscore character
11131or characters. A partial string will match any license that contains the
11132given string as the first portion of its license. For example, the
Andrew Geissler595f6302022-01-24 19:11:47 +000011133following value will also match both of the packages
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011134previously mentioned as well as any other packages that have licenses
11135starting with "commercial" or "license".
11136::
11137
Andrew Geissler9aee5002022-03-30 16:27:02 +000011138 LICENSE_FLAGS_ACCEPTED = "commercial license"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011139
11140License Flag Matching
11141~~~~~~~~~~~~~~~~~~~~~
11142
11143License flag matching allows you to control what recipes the
11144OpenEmbedded build system includes in the build. Fundamentally, the
Andrew Geissler09036742021-06-25 14:25:14 -050011145build system attempts to match :term:`LICENSE_FLAGS` strings found in
Andrew Geissler9aee5002022-03-30 16:27:02 +000011146recipes against strings found in :term:`LICENSE_FLAGS_ACCEPTED`.
Andrew Geissler595f6302022-01-24 19:11:47 +000011147A match causes the build system to include a recipe in the
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011148build, while failure to find a match causes the build system to exclude
11149a recipe.
11150
11151In general, license flag matching is simple. However, understanding some
11152concepts will help you correctly and effectively use matching.
11153
11154Before a flag defined by a particular recipe is tested against the
Andrew Geissler9aee5002022-03-30 16:27:02 +000011155entries of :term:`LICENSE_FLAGS_ACCEPTED`, the expanded
Andrew Geissler595f6302022-01-24 19:11:47 +000011156string ``_${PN}`` is appended to the flag. This expansion makes each
11157:term:`LICENSE_FLAGS` value recipe-specific. After expansion, the
11158string is then matched against the entries. Thus, specifying
11159``LICENSE_FLAGS = "commercial"`` in recipe "foo", for example, results
11160in the string ``"commercial_foo"``. And, to create a match, that string
Andrew Geissler9aee5002022-03-30 16:27:02 +000011161must appear among the entries of :term:`LICENSE_FLAGS_ACCEPTED`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011162
Andrew Geissler09036742021-06-25 14:25:14 -050011163Judicious use of the :term:`LICENSE_FLAGS` strings and the contents of the
Andrew Geissler9aee5002022-03-30 16:27:02 +000011164:term:`LICENSE_FLAGS_ACCEPTED` variable allows you a lot of flexibility for
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011165including or excluding recipes based on licensing. For example, you can
11166broaden the matching capabilities by using license flags string subsets
Andrew Geissler9aee5002022-03-30 16:27:02 +000011167in :term:`LICENSE_FLAGS_ACCEPTED`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011168
11169.. note::
11170
11171 When using a string subset, be sure to use the part of the expanded
11172 string that precedes the appended underscore character (e.g.
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011173 ``usethispart_1.3``, ``usethispart_1.4``, and so forth).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011174
Andrew Geissler595f6302022-01-24 19:11:47 +000011175For example, simply specifying the string "commercial" in the
Andrew Geissler9aee5002022-03-30 16:27:02 +000011176:term:`LICENSE_FLAGS_ACCEPTED` variable matches any expanded
Andrew Geissler595f6302022-01-24 19:11:47 +000011177:term:`LICENSE_FLAGS` definition that starts with the string
11178"commercial" such as "commercial_foo" and "commercial_bar", which
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011179are the strings the build system automatically generates for
11180hypothetical recipes named "foo" and "bar" assuming those recipes simply
Andrew Geisslerc926e172021-05-07 16:11:35 -050011181specify the following::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011182
11183 LICENSE_FLAGS = "commercial"
11184
Andrew Geissler595f6302022-01-24 19:11:47 +000011185Thus, you can choose to exhaustively enumerate each license flag in the
11186list and allow only specific recipes into the image, or you can use a
11187string subset that causes a broader range of matches to allow a range of
11188recipes into the image.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011189
Andrew Geissler09036742021-06-25 14:25:14 -050011190This scheme works even if the :term:`LICENSE_FLAGS` string already has
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011191``_${PN}`` appended. For example, the build system turns the license
11192flag "commercial_1.2_foo" into "commercial_1.2_foo_foo" and would match
11193both the general "commercial" and the specific "commercial_1.2_foo"
Andrew Geissler9aee5002022-03-30 16:27:02 +000011194strings found in the :term:`LICENSE_FLAGS_ACCEPTED` variable, as expected.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011195
11196Here are some other scenarios:
11197
11198- You can specify a versioned string in the recipe such as
11199 "commercial_foo_1.2" in a "foo" recipe. The build system expands this
11200 string to "commercial_foo_1.2_foo". Combine this license flag with a
Andrew Geissler9aee5002022-03-30 16:27:02 +000011201 :term:`LICENSE_FLAGS_ACCEPTED` variable that has the string
Andrew Geissler595f6302022-01-24 19:11:47 +000011202 "commercial" and you match the flag along with any other flag that
11203 starts with the string "commercial".
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011204
Andrew Geissler595f6302022-01-24 19:11:47 +000011205- Under the same circumstances, you can add "commercial_foo" in the
Andrew Geissler9aee5002022-03-30 16:27:02 +000011206 :term:`LICENSE_FLAGS_ACCEPTED` variable and the build system not only
Andrew Geissler595f6302022-01-24 19:11:47 +000011207 matches "commercial_foo_1.2" but also matches any license flag with
11208 the string "commercial_foo", regardless of the version.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011209
11210- You can be very specific and use both the package and version parts
Andrew Geissler9aee5002022-03-30 16:27:02 +000011211 in the :term:`LICENSE_FLAGS_ACCEPTED` list (e.g.
Andrew Geissler595f6302022-01-24 19:11:47 +000011212 "commercial_foo_1.2") to specifically match a versioned recipe.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011213
11214Other Variables Related to Commercial Licenses
11215~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11216
William A. Kennington IIIac69b482021-06-02 12:28:27 -070011217There are other helpful variables related to commercial license handling,
11218defined in the
Andrew Geisslerc926e172021-05-07 16:11:35 -050011219``poky/meta/conf/distro/include/default-distrovars.inc`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011220
11221 COMMERCIAL_AUDIO_PLUGINS ?= ""
11222 COMMERCIAL_VIDEO_PLUGINS ?= ""
11223
11224If you
11225want to enable these components, you can do so by making sure you have
11226statements similar to the following in your ``local.conf`` configuration
Andrew Geisslerc926e172021-05-07 16:11:35 -050011227file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011228
11229 COMMERCIAL_AUDIO_PLUGINS = "gst-plugins-ugly-mad \
11230 gst-plugins-ugly-mpegaudioparse"
11231 COMMERCIAL_VIDEO_PLUGINS = "gst-plugins-ugly-mpeg2dec \
11232 gst-plugins-ugly-mpegstream gst-plugins-bad-mpegvideoparse"
Andrew Geissler9aee5002022-03-30 16:27:02 +000011233 LICENSE_FLAGS_ACCEPTED = "commercial_gst-plugins-ugly commercial_gst-plugins-bad commercial_qmmp"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011234
11235
Andrew Geissler595f6302022-01-24 19:11:47 +000011236Of course, you could also create a matching list for those
11237components using the more general "commercial" in the
Andrew Geissler9aee5002022-03-30 16:27:02 +000011238:term:`LICENSE_FLAGS_ACCEPTED` variable, but that would also enable all
Andrew Geissler595f6302022-01-24 19:11:47 +000011239the other packages with :term:`LICENSE_FLAGS`
Andrew Geisslerc926e172021-05-07 16:11:35 -050011240containing "commercial", which you may or may not want::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011241
Andrew Geissler9aee5002022-03-30 16:27:02 +000011242 LICENSE_FLAGS_ACCEPTED = "commercial"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011243
11244Specifying audio and video plugins as part of the
11245``COMMERCIAL_AUDIO_PLUGINS`` and ``COMMERCIAL_VIDEO_PLUGINS`` statements
Andrew Geissler9aee5002022-03-30 16:27:02 +000011246(along with the enabling :term:`LICENSE_FLAGS_ACCEPTED`) includes the
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011247plugins or components into built images, thus adding support for media
11248formats or components.
11249
11250Maintaining Open Source License Compliance During Your Product's Lifecycle
11251--------------------------------------------------------------------------
11252
11253One of the concerns for a development organization using open source
11254software is how to maintain compliance with various open source
11255licensing during the lifecycle of the product. While this section does
11256not provide legal advice or comprehensively cover all scenarios, it does
11257present methods that you can use to assist you in meeting the compliance
11258requirements during a software release.
11259
11260With hundreds of different open source licenses that the Yocto Project
11261tracks, it is difficult to know the requirements of each and every
11262license. However, the requirements of the major FLOSS licenses can begin
William A. Kennington IIIac69b482021-06-02 12:28:27 -070011263to be covered by assuming that there are three main areas of concern:
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011264
11265- Source code must be provided.
11266
11267- License text for the software must be provided.
11268
11269- Compilation scripts and modifications to the source code must be
11270 provided.
11271
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011272- spdx files can be provided.
11273
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011274There are other requirements beyond the scope of these three and the
11275methods described in this section (e.g. the mechanism through which
11276source code is distributed).
11277
11278As different organizations have different methods of complying with open
11279source licensing, this section is not meant to imply that there is only
11280one single way to meet your compliance obligations, but rather to
11281describe one method of achieving compliance. The remainder of this
11282section describes methods supported to meet the previously mentioned
11283three requirements. Once you take steps to meet these requirements, and
11284prior to releasing images, sources, and the build system, you should
11285audit all artifacts to ensure completeness.
11286
11287.. note::
11288
11289 The Yocto Project generates a license manifest during image creation
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011290 that is located in ``${DEPLOY_DIR}/licenses/``\ `image_name`\ ``-``\ `datestamp`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011291 to assist with any audits.
11292
11293Providing the Source Code
11294~~~~~~~~~~~~~~~~~~~~~~~~~
11295
11296Compliance activities should begin before you generate the final image.
11297The first thing you should look at is the requirement that tops the list
Andrew Geissler615f2f12022-07-15 14:00:58 -050011298for most compliance groups --- providing the source. The Yocto Project has
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011299a few ways of meeting this requirement.
11300
11301One of the easiest ways to meet this requirement is to provide the
11302entire :term:`DL_DIR` used by the
11303build. This method, however, has a few issues. The most obvious is the
11304size of the directory since it includes all sources used in the build
11305and not just the source used in the released image. It will include
11306toolchain source, and other artifacts, which you would not generally
11307release. However, the more serious issue for most companies is
11308accidental release of proprietary software. The Yocto Project provides
11309an :ref:`archiver <ref-classes-archiver>` class to
11310help avoid some of these concerns.
11311
Andrew Geissler595f6302022-01-24 19:11:47 +000011312Before you employ :term:`DL_DIR` or the :ref:`archiver <ref-classes-archiver>` class, you need to
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011313decide how you choose to provide source. The source ``archiver`` class
11314can generate tarballs and SRPMs and can create them with various levels
11315of compliance in mind.
11316
11317One way of doing this (but certainly not the only way) is to release
11318just the source as a tarball. You can do this by adding the following to
11319the ``local.conf`` file found in the
Andrew Geisslerc926e172021-05-07 16:11:35 -050011320:term:`Build Directory`::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011321
11322 INHERIT += "archiver"
11323 ARCHIVER_MODE[src] = "original"
11324
11325During the creation of your
11326image, the source from all recipes that deploy packages to the image is
11327placed within subdirectories of ``DEPLOY_DIR/sources`` based on the
11328:term:`LICENSE` for each recipe.
11329Releasing the entire directory enables you to comply with requirements
11330concerning providing the unmodified source. It is important to note that
11331the size of the directory can get large.
11332
11333A way to help mitigate the size issue is to only release tarballs for
11334licenses that require the release of source. Let us assume you are only
11335concerned with GPL code as identified by running the following script:
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011336
11337.. code-block:: shell
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011338
11339 # Script to archive a subset of packages matching specific license(s)
11340 # Source and license files are copied into sub folders of package folder
11341 # Must be run from build folder
11342 #!/bin/bash
11343 src_release_dir="source-release"
11344 mkdir -p $src_release_dir
11345 for a in tmp/deploy/sources/*; do
11346 for d in $a/*; do
11347 # Get package name from path
11348 p=`basename $d`
11349 p=${p%-*}
11350 p=${p%-*}
11351 # Only archive GPL packages (update *GPL* regex for your license check)
11352 numfiles=`ls tmp/deploy/licenses/$p/*GPL* 2> /dev/null | wc -l`
Patrick Williams213cb262021-08-07 19:21:33 -050011353 if [ $numfiles -ge 1 ]; then
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011354 echo Archiving $p
11355 mkdir -p $src_release_dir/$p/source
11356 cp $d/* $src_release_dir/$p/source 2> /dev/null
11357 mkdir -p $src_release_dir/$p/license
11358 cp tmp/deploy/licenses/$p/* $src_release_dir/$p/license 2> /dev/null
11359 fi
11360 done
11361 done
11362
11363At this point, you
11364could create a tarball from the ``gpl_source_release`` directory and
11365provide that to the end user. This method would be a step toward
11366achieving compliance with section 3a of GPLv2 and with section 6 of
11367GPLv3.
11368
11369Providing License Text
11370~~~~~~~~~~~~~~~~~~~~~~
11371
11372One requirement that is often overlooked is inclusion of license text.
11373This requirement also needs to be dealt with prior to generating the
11374final image. Some licenses require the license text to accompany the
11375binary. You can achieve this by adding the following to your
Andrew Geisslerc926e172021-05-07 16:11:35 -050011376``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011377
11378 COPY_LIC_MANIFEST = "1"
11379 COPY_LIC_DIRS = "1"
11380 LICENSE_CREATE_PACKAGE = "1"
11381
11382Adding these statements to the
11383configuration file ensures that the licenses collected during package
11384generation are included on your image.
11385
11386.. note::
11387
11388 Setting all three variables to "1" results in the image having two
11389 copies of the same license file. One copy resides in
11390 ``/usr/share/common-licenses`` and the other resides in
11391 ``/usr/share/license``.
11392
11393 The reason for this behavior is because
11394 :term:`COPY_LIC_DIRS` and
11395 :term:`COPY_LIC_MANIFEST`
11396 add a copy of the license when the image is built but do not offer a
11397 path for adding licenses for newly installed packages to an image.
11398 :term:`LICENSE_CREATE_PACKAGE`
11399 adds a separate package and an upgrade path for adding licenses to an
11400 image.
11401
11402As the source ``archiver`` class has already archived the original
11403unmodified source that contains the license files, you would have
11404already met the requirements for inclusion of the license information
11405with source as defined by the GPL and other open source licenses.
11406
11407Providing Compilation Scripts and Source Code Modifications
11408~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11409
11410At this point, we have addressed all we need to prior to generating the
11411image. The next two requirements are addressed during the final
11412packaging of the release.
11413
11414By releasing the version of the OpenEmbedded build system and the layers
11415used during the build, you will be providing both compilation scripts
11416and the source code modifications in one step.
11417
Andrew Geissler09209ee2020-12-13 08:44:15 -060011418If the deployment team has a :ref:`overview-manual/concepts:bsp layer`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011419and a distro layer, and those
11420those layers are used to patch, compile, package, or modify (in any way)
11421any open source software included in your released images, you might be
11422required to release those layers under section 3 of GPLv2 or section 1
11423of GPLv3. One way of doing that is with a clean checkout of the version
11424of the Yocto Project and layers used during your build. Here is an
11425example:
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011426
11427.. code-block:: shell
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011428
11429 # We built using the dunfell branch of the poky repo
11430 $ git clone -b dunfell git://git.yoctoproject.org/poky
11431 $ cd poky
11432 # We built using the release_branch for our layers
11433 $ git clone -b release_branch git://git.mycompany.com/meta-my-bsp-layer
11434 $ git clone -b release_branch git://git.mycompany.com/meta-my-software-layer
11435 # clean up the .git repos
11436 $ find . -name ".git" -type d -exec rm -rf {} \;
11437
Andrew Geissler87f5cff2022-09-30 13:13:31 -050011438One thing a development organization might want to consider for end-user
11439convenience is to modify
11440``meta-poky/conf/templates/default/bblayers.conf.sample`` to ensure that when
11441the end user utilizes the released build system to build an image, the
11442development organization's layers are included in the ``bblayers.conf`` file
11443automatically::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011444
11445 # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
11446 # changes incompatibly
11447 POKY_BBLAYERS_CONF_VERSION = "2"
11448
11449 BBPATH = "${TOPDIR}"
11450 BBFILES ?= ""
11451
11452 BBLAYERS ?= " \
11453 ##OEROOT##/meta \
11454 ##OEROOT##/meta-poky \
11455 ##OEROOT##/meta-yocto-bsp \
11456 ##OEROOT##/meta-mylayer \
11457 "
11458
11459Creating and
11460providing an archive of the :term:`Metadata`
11461layers (recipes, configuration files, and so forth) enables you to meet
11462your requirements to include the scripts to control compilation as well
11463as any modifications to the original source.
11464
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011465Providing spdx files
11466~~~~~~~~~~~~~~~~~~~~~~~~~
11467
11468The spdx module has been integrated to a layer named meta-spdxscanner.
11469meta-spdxscanner provides several kinds of scanner. If you want to enable
11470this function, you have to follow the following steps:
11471
Andrew Geissler87f5cff2022-09-30 13:13:31 -0500114721. Add meta-spdxscanner layer into ``bblayers.conf``.
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011473
Andrew Geissler87f5cff2022-09-30 13:13:31 -0500114742. Refer to the README in meta-spdxscanner to setup the environment (e.g,
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011475 setup a fossology server) needed for the scanner.
11476
114773. Meta-spdxscanner provides several methods within the bbclass to create spdx files.
11478 Please choose one that you want to use and enable the spdx task. You have to
11479 add some config options in ``local.conf`` file in your :term:`Build
William A. Kennington IIIac69b482021-06-02 12:28:27 -070011480 Directory`. Here is an example showing how to generate spdx files
Andrew Geisslerd5838332022-05-27 11:33:10 -050011481 during BitBake using the fossology-python.bbclass::
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011482
11483 # Select fossology-python.bbclass.
11484 INHERIT += "fossology-python"
11485 # For fossology-python.bbclass, TOKEN is necessary, so, after setup a
11486 # Fossology server, you have to create a token.
11487 TOKEN = "eyJ0eXAiO..."
11488 # The fossology server is necessary for fossology-python.bbclass.
11489 FOSSOLOGY_SERVER = "http://xx.xx.xx.xx:8081/repo"
11490 # If you want to upload the source code to a special folder:
11491 FOLDER_NAME = "xxxx" //Optional
11492 # If you don't want to put spdx files in tmp/deploy/spdx, you can enable:
11493 SPDX_DEPLOY_DIR = "${DEPLOY_DIR}" //Optional
11494
11495For more usage information refer to :yocto_git:`the meta-spdxscanner repository
Andrew Geissler09209ee2020-12-13 08:44:15 -060011496</meta-spdxscanner/>`.
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011497
Andrew Geisslereff27472021-10-29 15:35:00 -050011498Compliance Limitations with Executables Built from Static Libraries
11499~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011500
Andrew Geisslereff27472021-10-29 15:35:00 -050011501When package A is added to an image via the :term:`RDEPENDS` or :term:`RRECOMMENDS`
11502mechanisms as well as explicitly included in the image recipe with
11503:term:`IMAGE_INSTALL`, and depends on a static linked library recipe B
11504(``DEPENDS += "B"``), package B will neither appear in the generated license
11505manifest nor in the generated source tarballs. This occurs as the
11506:ref:`license <ref-classes-license>` and :ref:`archiver <ref-classes-archiver>`
11507classes assume that only packages included via :term:`RDEPENDS` or :term:`RRECOMMENDS`
11508end up in the image.
11509
11510As a result, potential obligations regarding license compliance for package B
11511may not be met.
11512
11513The Yocto Project doesn't enable static libraries by default, in part because
11514of this issue. Before a solution to this limitation is found, you need to
11515keep in mind that if your root filesystem is built from static libraries,
11516you will need to manually ensure that your deliveries are compliant
11517with the licenses of these libraries.
11518
11519Copying Non Standard Licenses
11520-----------------------------
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011521
11522Some packages, such as the linux-firmware package, have many licenses
11523that are not in any way common. You can avoid adding a lot of these
11524types of common license files, which are only applicable to a specific
11525package, by using the
11526:term:`NO_GENERIC_LICENSE`
11527variable. Using this variable also avoids QA errors when you use a
11528non-common, non-CLOSED license in a recipe.
11529
William A. Kennington IIIac69b482021-06-02 12:28:27 -070011530Here is an example that uses the ``LICENSE.Abilis.txt`` file as
Andrew Geisslerc926e172021-05-07 16:11:35 -050011531the license from the fetched source::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011532
11533 NO_GENERIC_LICENSE[Firmware-Abilis] = "LICENSE.Abilis.txt"
11534
Patrick Williams213cb262021-08-07 19:21:33 -050011535Checking for Vulnerabilities
11536============================
11537
11538Vulnerabilities in images
11539-------------------------
11540
11541The Yocto Project has an infrastructure to track and address unfixed
11542known security vulnerabilities, as tracked by the public
11543`Common Vulnerabilities and Exposures (CVE) <https://en.wikipedia.org/wiki/Common_Vulnerabilities_and_Exposures>`__
11544database.
11545
Andrew Geissler615f2f12022-07-15 14:00:58 -050011546The Yocto Project maintains a `list of known vulnerabilities
11547<https://autobuilder.yocto.io/pub/non-release/patchmetrics/>`__
11548for packages in Poky and OE-Core, tracking the evolution of the number of
11549unpatched CVEs and the status of patches. Such information is available for
11550the current development version and for each supported release.
11551
11552To know which packages are vulnerable to known security vulnerabilities
11553in the specific image you are building, add the following setting to your
11554configuration::
Patrick Williams213cb262021-08-07 19:21:33 -050011555
11556 INHERIT += "cve-check"
11557
11558This way, at build time, BitBake will warn you about known CVEs
11559as in the example below::
11560
11561 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
11562 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
11563
11564It is also possible to check the CVE status of individual packages as follows::
11565
11566 bitbake -c cve_check flex libarchive
11567
11568Note that OpenEmbedded-Core keeps a list of known unfixed CVE issues which can
11569be ignored. You can pass this list to the check as follows::
11570
11571 bitbake -c cve_check libarchive -R conf/distro/include/cve-extra-exclusions.inc
11572
11573Enabling vulnerabily tracking in recipes
11574----------------------------------------
11575
11576The :term:`CVE_PRODUCT` variable defines the name used to match the recipe name
11577against the name in the upstream `NIST CVE database <https://nvd.nist.gov/>`__.
11578
Patrick Williams0ca19cc2021-08-16 14:03:13 -050011579Editing recipes to fix vulnerabilities
11580--------------------------------------
11581
11582To fix a given known vulnerability, you need to add a patch file to your recipe. Here's
11583an example from the :oe_layerindex:`ffmpeg recipe</layerindex/recipe/47350>`::
11584
11585 SRC_URI = "https://www.ffmpeg.org/releases/${BP}.tar.xz \
11586 file://0001-libavutil-include-assembly-with-full-path-from-sourc.patch \
11587 file://fix-CVE-2020-20446.patch \
11588 file://fix-CVE-2020-20453.patch \
11589 file://fix-CVE-2020-22015.patch \
11590 file://fix-CVE-2020-22021.patch \
11591 file://fix-CVE-2020-22033-CVE-2020-22019.patch \
11592 file://fix-CVE-2021-33815.patch \
11593
11594The :ref:`cve-check <ref-classes-cve-check>` class defines two ways of
11595supplying a patch for a given CVE. The first
11596way is to use a patch filename that matches the below pattern::
11597
11598 cve_file_name_match = re.compile(".*([Cc][Vv][Ee]\-\d{4}\-\d+)")
11599
11600As shown in the example above, multiple CVE IDs can appear in a patch filename,
11601but the :ref:`cve-check <ref-classes-cve-check>` class will only consider
11602the last CVE ID in the filename as patched.
11603
11604The second way to recognize a patched CVE ID is when a line matching the
11605below pattern is found in any patch file provided by the recipe::
11606
11607 cve_match = re.compile("CVE:( CVE\-\d{4}\-\d+)+")
11608
11609This allows a single patch file to address multiple CVE IDs at the same time.
11610
11611Of course, another way to fix vulnerabilities is to upgrade to a version
11612of the package which is not impacted, typically a more recent one.
11613The NIST database knows which versions are vulnerable and which ones
11614are not.
11615
11616Last but not least, you can choose to ignore vulnerabilities through
Andrew Geissler9aee5002022-03-30 16:27:02 +000011617the :term:`CVE_CHECK_SKIP_RECIPE` and :term:`CVE_CHECK_IGNORE`
Patrick Williams0ca19cc2021-08-16 14:03:13 -050011618variables.
11619
11620Implementation details
11621----------------------
11622
11623Here's what the :ref:`cve-check <ref-classes-cve-check>` class does to
11624find unpatched CVE IDs.
11625
11626First the code goes through each patch file provided by a recipe. If a valid CVE ID
11627is found in the name of the file, the corresponding CVE is considered as patched.
11628Don't forget that if multiple CVE IDs are found in the filename, only the last
11629one is considered. Then, the code looks for ``CVE: CVE-ID`` lines in the patch
11630file. The found CVE IDs are also considered as patched.
11631
11632Then, the code looks up all the CVE IDs in the NIST database for all the
11633products defined in :term:`CVE_PRODUCT`. Then, for each found CVE:
11634
11635 - If the package name (:term:`PN`) is part of
Andrew Geissler9aee5002022-03-30 16:27:02 +000011636 :term:`CVE_CHECK_SKIP_RECIPE`, it is considered as patched.
Patrick Williams0ca19cc2021-08-16 14:03:13 -050011637
Andrew Geissler9aee5002022-03-30 16:27:02 +000011638 - If the CVE ID is part of :term:`CVE_CHECK_IGNORE`, it is
Patrick Williams0ca19cc2021-08-16 14:03:13 -050011639 considered as patched too.
11640
11641 - If the CVE ID is part of the patched CVE for the recipe, it is
11642 already considered as patched.
11643
11644 - Otherwise, the code checks whether the recipe version (:term:`PV`)
11645 is within the range of versions impacted by the CVE. If so, the CVE
11646 is considered as unpatched.
11647
Patrick Williams213cb262021-08-07 19:21:33 -050011648The CVE database is stored in :term:`DL_DIR` and can be inspected using
11649``sqlite3`` command as follows::
11650
11651 sqlite3 downloads/CVE_CHECK/nvdcve_1.1.db .dump | grep CVE-2021-37462
11652
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011653Using the Error Reporting Tool
11654==============================
11655
11656The error reporting tool allows you to submit errors encountered during
11657builds to a central database. Outside of the build environment, you can
11658use a web interface to browse errors, view statistics, and query for
11659errors. The tool works using a client-server system where the client
11660portion is integrated with the installed Yocto Project
11661:term:`Source Directory` (e.g. ``poky``).
11662The server receives the information collected and saves it in a
11663database.
11664
William A. Kennington IIIac69b482021-06-02 12:28:27 -070011665There is a live instance of the error reporting server at
11666https://errors.yoctoproject.org.
11667When you want to get help with build failures, you can submit all of the
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011668information on the failure easily and then point to the URL in your bug
11669report or send an email to the mailing list.
11670
11671.. note::
11672
11673 If you send error reports to this server, the reports become publicly
11674 visible.
11675
11676Enabling and Using the Tool
11677---------------------------
11678
11679By default, the error reporting tool is disabled. You can enable it by
11680inheriting the
11681:ref:`report-error <ref-classes-report-error>`
11682class by adding the following statement to the end of your
11683``local.conf`` file in your
11684:term:`Build Directory`.
11685::
11686
11687 INHERIT += "report-error"
11688
11689By default, the error reporting feature stores information in
11690``${``\ :term:`LOG_DIR`\ ``}/error-report``.
11691However, you can specify a directory to use by adding the following to
Andrew Geisslerc926e172021-05-07 16:11:35 -050011692your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011693
11694 ERR_REPORT_DIR = "path"
11695
11696Enabling error
11697reporting causes the build process to collect the errors and store them
11698in a file as previously described. When the build system encounters an
11699error, it includes a command as part of the console output. You can run
11700the command to send the error file to the server. For example, the
Andrew Geisslerc926e172021-05-07 16:11:35 -050011701following command sends the errors to an upstream server::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011702
11703 $ send-error-report /home/brandusa/project/poky/build/tmp/log/error-report/error_report_201403141617.txt
11704
11705In the previous example, the errors are sent to a public database
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011706available at https://errors.yoctoproject.org, which is used by the
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011707entire community. If you specify a particular server, you can send the
11708errors to a different database. Use the following command for more
Andrew Geisslerc926e172021-05-07 16:11:35 -050011709information on available options::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011710
11711 $ send-error-report --help
11712
11713When sending the error file, you are prompted to review the data being
11714sent as well as to provide a name and optional email address. Once you
11715satisfy these prompts, the command returns a link from the server that
11716corresponds to your entry in the database. For example, here is a
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011717typical link: https://errors.yoctoproject.org/Errors/Details/9522/
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011718
11719Following the link takes you to a web interface where you can browse,
11720query the errors, and view statistics.
11721
11722Disabling the Tool
11723------------------
11724
11725To disable the error reporting feature, simply remove or comment out the
11726following statement from the end of your ``local.conf`` file in your
11727:term:`Build Directory`.
11728::
11729
11730 INHERIT += "report-error"
11731
11732Setting Up Your Own Error Reporting Server
11733------------------------------------------
11734
11735If you want to set up your own error reporting server, you can obtain
Andrew Geissler09209ee2020-12-13 08:44:15 -060011736the code from the Git repository at :yocto_git:`/error-report-web/`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011737Instructions on how to set it up are in the README document.
11738
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011739Using Wayland and Weston
11740========================
11741
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011742`Wayland <https://en.wikipedia.org/wiki/Wayland_(display_server_protocol)>`__
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011743is a computer display server protocol that provides a method for
11744compositing window managers to communicate directly with applications
11745and video hardware and expects them to communicate with input hardware
11746using other libraries. Using Wayland with supporting targets can result
11747in better control over graphics frame rendering than an application
11748might otherwise achieve.
11749
11750The Yocto Project provides the Wayland protocol libraries and the
11751reference
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011752`Weston <https://en.wikipedia.org/wiki/Wayland_(display_server_protocol)#Weston>`__
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011753compositor as part of its release. You can find the integrated packages
11754in the ``meta`` layer of the :term:`Source Directory`.
11755Specifically, you
11756can find the recipes that build both Wayland and Weston at
11757``meta/recipes-graphics/wayland``.
11758
11759You can build both the Wayland and Weston packages for use only with
11760targets that accept the `Mesa 3D and Direct Rendering
11761Infrastructure <https://en.wikipedia.org/wiki/Mesa_(computer_graphics)>`__,
11762which is also known as Mesa DRI. This implies that you cannot build and
11763use the packages if your target uses, for example, the Intel Embedded
11764Media and Graphics Driver (Intel EMGD) that overrides Mesa DRI.
11765
11766.. note::
11767
11768 Due to lack of EGL support, Weston 1.0.3 will not run directly on the
11769 emulated QEMU hardware. However, this version of Weston will run
11770 under X emulation without issues.
11771
11772This section describes what you need to do to implement Wayland and use
11773the Weston compositor when building an image for a supporting target.
11774
11775Enabling Wayland in an Image
11776----------------------------
11777
11778To enable Wayland, you need to enable it to be built and enable it to be
11779included (installed) in the image.
11780
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011781Building Wayland
11782~~~~~~~~~~~~~~~~
11783
11784To cause Mesa to build the ``wayland-egl`` platform and Weston to build
11785Wayland with Kernel Mode Setting
11786(`KMS <https://wiki.archlinux.org/index.php/Kernel_Mode_Setting>`__)
11787support, include the "wayland" flag in the
11788:term:`DISTRO_FEATURES`
Andrew Geisslerc926e172021-05-07 16:11:35 -050011789statement in your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011790
Patrick Williams0ca19cc2021-08-16 14:03:13 -050011791 DISTRO_FEATURES:append = " wayland"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011792
11793.. note::
11794
11795 If X11 has been enabled elsewhere, Weston will build Wayland with X11
11796 support
11797
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011798Installing Wayland and Weston
11799~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11800
11801To install the Wayland feature into an image, you must include the
11802following
11803:term:`CORE_IMAGE_EXTRA_INSTALL`
Andrew Geisslerc926e172021-05-07 16:11:35 -050011804statement in your ``local.conf`` file::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011805
11806 CORE_IMAGE_EXTRA_INSTALL += "wayland weston"
11807
11808Running Weston
11809--------------
11810
11811To run Weston inside X11, enabling it as described earlier and building
11812a Sato image is sufficient. If you are running your image under Sato, a
11813Weston Launcher appears in the "Utility" category.
11814
11815Alternatively, you can run Weston through the command-line interpretor
11816(CLI), which is better suited for development work. To run Weston under
11817the CLI, you need to do the following after your image is built:
11818
Andrew Geisslerc926e172021-05-07 16:11:35 -0500118191. Run these commands to export ``XDG_RUNTIME_DIR``::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011820
11821 mkdir -p /tmp/$USER-weston
11822 chmod 0700 /tmp/$USER-weston
11823 export XDG_RUNTIME_DIR=/tmp/$USER-weston
11824
Andrew Geisslerc926e172021-05-07 16:11:35 -0500118252. Launch Weston in the shell::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011826
11827 weston