blob: 683f5557ecba1672907e2087dcca4438fe4fea86 [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
21":ref:`overview-manual/overview-manual-yp-intro:the yocto project layer model`"
22section in the Yocto Project Overview and Concepts Manual.
23
24Creating Your Own Layer
25-----------------------
26
27It is very easy to create your own layers to use with the OpenEmbedded
28build system. The Yocto Project ships with tools that speed up creating
29layers. This section describes the steps you perform by hand to create
30layers so that you can better understand them. For information about the
31layer-creation tools, see the
32":ref:`bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script`"
33section in the Yocto Project Board Support Package (BSP) Developer's
34Guide and the ":ref:`dev-manual/dev-manual-common-tasks:creating a general layer using the \`\`bitbake-layers\`\` script`"
35section further down in this manual.
36
37Follow these general steps to create your layer without using tools:
38
391. *Check Existing Layers:* Before creating a new layer, you should be
40 sure someone has not already created a layer containing the Metadata
41 you need. You can see the `OpenEmbedded Metadata
Andrew Geissler4c19ea12020-10-27 13:52:24 -050042 Index <https://layers.openembedded.org/layerindex/layers/>`__ for a
Andrew Geisslerc9f78652020-09-18 14:11:35 -050043 list of layers from the OpenEmbedded community that can be used in
44 the Yocto Project. You could find a layer that is identical or close
45 to what you need.
46
472. *Create a Directory:* Create the directory for your layer. When you
48 create the layer, be sure to create the directory in an area not
49 associated with the Yocto Project :term:`Source Directory`
50 (e.g. the cloned ``poky`` repository).
51
52 While not strictly required, prepend the name of the directory with
53 the string "meta-". For example:
54 ::
55
56 meta-mylayer
57 meta-GUI_xyz
58 meta-mymachine
59
60 With rare exceptions, a layer's name follows this form:
61 ::
62
63 meta-root_name
64
65 Following this layer naming convention can save
66 you trouble later when tools, components, or variables "assume" your
67 layer name begins with "meta-". A notable example is in configuration
68 files as shown in the following step where layer names without the
69 "meta-" string are appended to several variables used in the
70 configuration.
71
723. *Create a Layer Configuration File:* Inside your new layer folder,
73 you need to create a ``conf/layer.conf`` file. It is easiest to take
74 an existing layer configuration file and copy that to your layer's
75 ``conf`` directory and then modify the file as needed.
76
77 The ``meta-yocto-bsp/conf/layer.conf`` file in the Yocto Project
78 :yocto_git:`Source Repositories </cgit/cgit.cgi/poky/tree/meta-yocto-bsp/conf>`
79 demonstrates the required syntax. For your layer, you need to replace
80 "yoctobsp" with a unique identifier for your layer (e.g. "machinexyz"
81 for a layer named "meta-machinexyz"):
82 ::
83
84 # We have a conf and classes directory, add to BBPATH
85 BBPATH .= ":${LAYERDIR}"
86
Andrew Geissler4c19ea12020-10-27 13:52:24 -050087 # We have recipes-* directories, add to BBFILES
Andrew Geisslerc9f78652020-09-18 14:11:35 -050088 BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
89 ${LAYERDIR}/recipes-*/*/*.bbappend"
90
91 BBFILE_COLLECTIONS += "yoctobsp"
92 BBFILE_PATTERN_yoctobsp = "^${LAYERDIR}/"
93 BBFILE_PRIORITY_yoctobsp = "5"
94 LAYERVERSION_yoctobsp = "4"
95 LAYERSERIES_COMPAT_yoctobsp = "dunfell"
96
97 Following is an explanation of the layer configuration file:
98
99 - :term:`BBPATH`: Adds the layer's
100 root directory to BitBake's search path. Through the use of the
101 ``BBPATH`` variable, BitBake locates class files (``.bbclass``),
102 configuration files, and files that are included with ``include``
103 and ``require`` statements. For these cases, BitBake uses the
104 first file that matches the name found in ``BBPATH``. This is
105 similar to the way the ``PATH`` variable is used for binaries. It
106 is recommended, therefore, that you use unique class and
107 configuration filenames in your custom layer.
108
109 - :term:`BBFILES`: Defines the
110 location for all recipes in the layer.
111
112 - :term:`BBFILE_COLLECTIONS`:
113 Establishes the current layer through a unique identifier that is
114 used throughout the OpenEmbedded build system to refer to the
115 layer. In this example, the identifier "yoctobsp" is the
116 representation for the container layer named "meta-yocto-bsp".
117
118 - :term:`BBFILE_PATTERN`:
119 Expands immediately during parsing to provide the directory of the
120 layer.
121
122 - :term:`BBFILE_PRIORITY`:
123 Establishes a priority to use for recipes in the layer when the
124 OpenEmbedded build finds recipes of the same name in different
125 layers.
126
127 - :term:`LAYERVERSION`:
128 Establishes a version number for the layer. You can use this
129 version number to specify this exact version of the layer as a
130 dependency when using the
131 :term:`LAYERDEPENDS`
132 variable.
133
134 - :term:`LAYERDEPENDS`:
135 Lists all layers on which this layer depends (if any).
136
137 - :term:`LAYERSERIES_COMPAT`:
138 Lists the :yocto_wiki:`Yocto Project </wiki/Releases>`
139 releases for which the current version is compatible. This
140 variable is a good way to indicate if your particular layer is
141 current.
142
1434. *Add Content:* Depending on the type of layer, add the content. If
144 the layer adds support for a machine, add the machine configuration
145 in a ``conf/machine/`` file within the layer. If the layer adds
146 distro policy, add the distro configuration in a ``conf/distro/``
147 file within the layer. If the layer introduces new recipes, put the
148 recipes you need in ``recipes-*`` subdirectories within the layer.
149
150 .. note::
151
152 For an explanation of layer hierarchy that is compliant with the
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500153 Yocto Project, see the ":ref:`bsp-guide/bsp:example filesystem layout`"
154 section in the Yocto Project Board Support Package (BSP) Developer's Guide.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500155
1565. *Optionally Test for Compatibility:* If you want permission to use
157 the Yocto Project Compatibility logo with your layer or application
158 that uses your layer, perform the steps to apply for compatibility.
159 See the "`Making Sure Your Layer is Compatible With Yocto
160 Project <#making-sure-your-layer-is-compatible-with-yocto-project>`__"
161 section for more information.
162
163.. _best-practices-to-follow-when-creating-layers:
164
165Following Best Practices When Creating Layers
166---------------------------------------------
167
168To create layers that are easier to maintain and that will not impact
169builds for other machines, you should consider the information in the
170following list:
171
172- *Avoid "Overlaying" Entire Recipes from Other Layers in Your
173 Configuration:* In other words, do not copy an entire recipe into
174 your layer and then modify it. Rather, use an append file
175 (``.bbappend``) to override only those parts of the original recipe
176 you need to modify.
177
178- *Avoid Duplicating Include Files:* Use append files (``.bbappend``)
179 for each recipe that uses an include file. Or, if you are introducing
180 a new recipe that requires the included file, use the path relative
181 to the original layer directory to refer to the file. For example,
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500182 use ``require recipes-core/``\ `package`\ ``/``\ `file`\ ``.inc`` instead
183 of ``require`` `file`\ ``.inc``. If you're finding you have to overlay
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500184 the include file, it could indicate a deficiency in the include file
185 in the layer to which it originally belongs. If this is the case, you
186 should try to address that deficiency instead of overlaying the
187 include file. For example, you could address this by getting the
188 maintainer of the include file to add a variable or variables to make
189 it easy to override the parts needing to be overridden.
190
191- *Structure Your Layers:* Proper use of overrides within append files
192 and placement of machine-specific files within your layer can ensure
193 that a build is not using the wrong Metadata and negatively impacting
194 a build for a different machine. Following are some examples:
195
196 - *Modify Variables to Support a Different Machine:* Suppose you
197 have a layer named ``meta-one`` that adds support for building
198 machine "one". To do so, you use an append file named
199 ``base-files.bbappend`` and create a dependency on "foo" by
200 altering the :term:`DEPENDS`
201 variable:
202 ::
203
204 DEPENDS = "foo"
205
206 The dependency is created during any
207 build that includes the layer ``meta-one``. However, you might not
208 want this dependency for all machines. For example, suppose you
209 are building for machine "two" but your ``bblayers.conf`` file has
210 the ``meta-one`` layer included. During the build, the
211 ``base-files`` for machine "two" will also have the dependency on
212 ``foo``.
213
214 To make sure your changes apply only when building machine "one",
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500215 use a machine override with the ``DEPENDS`` statement:
216 ::
217
218 DEPENDS_one = "foo"
219
220 You should follow the same strategy when using ``_append``
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500221 and ``_prepend`` operations:
222 ::
223
224 DEPENDS_append_one = " foo"
225 DEPENDS_prepend_one = "foo "
226
227 As an actual example, here's a
228 snippet from the generic kernel include file ``linux-yocto.inc``,
229 wherein the kernel compile and link options are adjusted in the
230 case of a subset of the supported architectures:
231 ::
232
233 DEPENDS_append_aarch64 = " libgcc"
234 KERNEL_CC_append_aarch64 = " ${TOOLCHAIN_OPTIONS}"
235 KERNEL_LD_append_aarch64 = " ${TOOLCHAIN_OPTIONS}"
236
237 DEPENDS_append_nios2 = " libgcc"
238 KERNEL_CC_append_nios2 = " ${TOOLCHAIN_OPTIONS}"
239 KERNEL_LD_append_nios2 = " ${TOOLCHAIN_OPTIONS}"
240
241 DEPENDS_append_arc = " libgcc"
242 KERNEL_CC_append_arc = " ${TOOLCHAIN_OPTIONS}"
243 KERNEL_LD_append_arc = " ${TOOLCHAIN_OPTIONS}"
244
245 KERNEL_FEATURES_append_qemuall=" features/debug/printk.scc"
246
247 .. note::
248
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500249 Avoiding "+=" and "=+" and using machine-specific ``_append``
250 and ``_prepend`` operations is recommended as well.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500251
252 - *Place Machine-Specific Files in Machine-Specific Locations:* When
253 you have a base recipe, such as ``base-files.bb``, that contains a
254 :term:`SRC_URI` statement to a
255 file, you can use an append file to cause the build to use your
256 own version of the file. For example, an append file in your layer
257 at ``meta-one/recipes-core/base-files/base-files.bbappend`` could
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500258 extend :term:`FILESPATH` using :term:`FILESEXTRAPATHS` as follows:
259 ::
260
261 FILESEXTRAPATHS_prepend := "${THISDIR}/${BPN}:"
262
263 The build for machine "one" will pick up your machine-specific file as
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500264 long as you have the file in
265 ``meta-one/recipes-core/base-files/base-files/``. However, if you
266 are building for a different machine and the ``bblayers.conf``
267 file includes the ``meta-one`` layer and the location of your
268 machine-specific file is the first location where that file is
269 found according to ``FILESPATH``, builds for all machines will
270 also use that machine-specific file.
271
272 You can make sure that a machine-specific file is used for a
273 particular machine by putting the file in a subdirectory specific
274 to the machine. For example, rather than placing the file in
275 ``meta-one/recipes-core/base-files/base-files/`` as shown above,
276 put it in ``meta-one/recipes-core/base-files/base-files/one/``.
277 Not only does this make sure the file is used only when building
278 for machine "one", but the build process locates the file more
279 quickly.
280
281 In summary, you need to place all files referenced from
282 ``SRC_URI`` in a machine-specific subdirectory within the layer in
283 order to restrict those files to machine-specific builds.
284
285- *Perform Steps to Apply for Yocto Project Compatibility:* If you want
286 permission to use the Yocto Project Compatibility logo with your
287 layer or application that uses your layer, perform the steps to apply
288 for compatibility. See the "`Making Sure Your Layer is Compatible
289 With Yocto
290 Project <#making-sure-your-layer-is-compatible-with-yocto-project>`__"
291 section for more information.
292
293- *Follow the Layer Naming Convention:* Store custom layers in a Git
294 repository that use the ``meta-layer_name`` format.
295
296- *Group Your Layers Locally:* Clone your repository alongside other
297 cloned ``meta`` directories from the :term:`Source Directory`.
298
299Making Sure Your Layer is Compatible With Yocto Project
300-------------------------------------------------------
301
302When you create a layer used with the Yocto Project, it is advantageous
303to make sure that the layer interacts well with existing Yocto Project
304layers (i.e. the layer is compatible with the Yocto Project). Ensuring
305compatibility makes the layer easy to be consumed by others in the Yocto
306Project community and could allow you permission to use the Yocto
307Project Compatible Logo.
308
309.. note::
310
311 Only Yocto Project member organizations are permitted to use the
312 Yocto Project Compatible Logo. The logo is not available for general
313 use. For information on how to become a Yocto Project member
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500314 organization, see the :yocto_home:`Yocto Project Website <>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500315
316The Yocto Project Compatibility Program consists of a layer application
317process that requests permission to use the Yocto Project Compatibility
318Logo for your layer and application. The process consists of two parts:
319
3201. Successfully passing a script (``yocto-check-layer``) that when run
321 against your layer, tests it against constraints based on experiences
322 of how layers have worked in the real world and where pitfalls have
323 been found. Getting a "PASS" result from the script is required for
324 successful compatibility registration.
325
3262. Completion of an application acceptance form, which you can find at
327 https://www.yoctoproject.org/webform/yocto-project-compatible-registration.
328
329To be granted permission to use the logo, you need to satisfy the
330following:
331
332- Be able to check the box indicating that you got a "PASS" when
333 running the script against your layer.
334
335- Answer "Yes" to the questions on the form or have an acceptable
336 explanation for any questions answered "No".
337
338- Be a Yocto Project Member Organization.
339
340The remainder of this section presents information on the registration
341form and on the ``yocto-check-layer`` script.
342
343Yocto Project Compatible Program Application
344~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
345
346Use the form to apply for your layer's approval. Upon successful
347application, you can use the Yocto Project Compatibility Logo with your
348layer and the application that uses your layer.
349
350To access the form, use this link:
351https://www.yoctoproject.org/webform/yocto-project-compatible-registration.
352Follow the instructions on the form to complete your application.
353
354The application consists of the following sections:
355
356- *Contact Information:* Provide your contact information as the fields
357 require. Along with your information, provide the released versions
358 of the Yocto Project for which your layer is compatible.
359
360- *Acceptance Criteria:* Provide "Yes" or "No" answers for each of the
361 items in the checklist. Space exists at the bottom of the form for
362 any explanations for items for which you answered "No".
363
364- *Recommendations:* Provide answers for the questions regarding Linux
365 kernel use and build success.
366
367``yocto-check-layer`` Script
368~~~~~~~~~~~~~~~~~~~~~~~~~~~~
369
370The ``yocto-check-layer`` script provides you a way to assess how
371compatible your layer is with the Yocto Project. You should run this
372script prior to using the form to apply for compatibility as described
373in the previous section. You need to achieve a "PASS" result in order to
374have your application form successfully processed.
375
376The script divides tests into three areas: COMMON, BSP, and DISTRO. For
377example, given a distribution layer (DISTRO), the layer must pass both
378the COMMON and DISTRO related tests. Furthermore, if your layer is a BSP
379layer, the layer must pass the COMMON and BSP set of tests.
380
381To execute the script, enter the following commands from your build
382directory:
383::
384
385 $ source oe-init-build-env
386 $ yocto-check-layer your_layer_directory
387
388Be sure to provide the actual directory for your
389layer as part of the command.
390
391Entering the command causes the script to determine the type of layer
392and then to execute a set of specific tests against the layer. The
393following list overviews the test:
394
395- ``common.test_readme``: Tests if a ``README`` file exists in the
396 layer and the file is not empty.
397
398- ``common.test_parse``: Tests to make sure that BitBake can parse the
399 files without error (i.e. ``bitbake -p``).
400
401- ``common.test_show_environment``: Tests that the global or per-recipe
402 environment is in order without errors (i.e. ``bitbake -e``).
403
404- ``common.test_world``: Verifies that ``bitbake world`` works.
405
406- ``common.test_signatures``: Tests to be sure that BSP and DISTRO
407 layers do not come with recipes that change signatures.
408
409- ``common.test_layerseries_compat``: Verifies layer compatibility is
410 set properly.
411
412- ``bsp.test_bsp_defines_machines``: Tests if a BSP layer has machine
413 configurations.
414
415- ``bsp.test_bsp_no_set_machine``: Tests to ensure a BSP layer does not
416 set the machine when the layer is added.
417
418- ``bsp.test_machine_world``: Verifies that ``bitbake world`` works
419 regardless of which machine is selected.
420
421- ``bsp.test_machine_signatures``: Verifies that building for a
422 particular machine affects only the signature of tasks specific to
423 that machine.
424
425- ``distro.test_distro_defines_distros``: Tests if a DISTRO layer has
426 distro configurations.
427
428- ``distro.test_distro_no_set_distros``: Tests to ensure a DISTRO layer
429 does not set the distribution when the layer is added.
430
431Enabling Your Layer
432-------------------
433
434Before the OpenEmbedded build system can use your new layer, you need to
435enable it. To enable your layer, simply add your layer's path to the
436``BBLAYERS`` variable in your ``conf/bblayers.conf`` file, which is
437found in the :term:`Build Directory`.
438The following example shows how to enable a layer named
439``meta-mylayer``:
440::
441
442 # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
443 # changes incompatibly
444 POKY_BBLAYERS_CONF_VERSION = "2"
445 BBPATH = "${TOPDIR}"
446 BBFILES ?= ""
447 BBLAYERS ?= " \
448 /home/user/poky/meta \
449 /home/user/poky/meta-poky \
450 /home/user/poky/meta-yocto-bsp \
451 /home/user/poky/meta-mylayer \
452 "
453
454BitBake parses each ``conf/layer.conf`` file from the top down as
455specified in the ``BBLAYERS`` variable within the ``conf/bblayers.conf``
456file. During the processing of each ``conf/layer.conf`` file, BitBake
457adds the recipes, classes and configurations contained within the
458particular layer to the source directory.
459
460.. _using-bbappend-files:
461
462Using .bbappend Files in Your Layer
463-----------------------------------
464
465A recipe that appends Metadata to another recipe is called a BitBake
466append file. A BitBake append file uses the ``.bbappend`` file type
467suffix, while the corresponding recipe to which Metadata is being
468appended uses the ``.bb`` file type suffix.
469
470You can use a ``.bbappend`` file in your layer to make additions or
471changes to the content of another layer's recipe without having to copy
472the other layer's recipe into your layer. Your ``.bbappend`` file
473resides in your layer, while the main ``.bb`` recipe file to which you
474are appending Metadata resides in a different layer.
475
476Being able to append information to an existing recipe not only avoids
477duplication, but also automatically applies recipe changes from a
478different layer into your layer. If you were copying recipes, you would
479have to manually merge changes as they occur.
480
481When you create an append file, you must use the same root name as the
482corresponding recipe file. For example, the append file
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500483``someapp_3.1.bbappend`` must apply to ``someapp_3.1.bb``. This
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500484means the original recipe and append file names are version
485number-specific. If the corresponding recipe is renamed to update to a
486newer version, you must also rename and possibly update the
487corresponding ``.bbappend`` as well. During the build process, BitBake
488displays an error on starting if it detects a ``.bbappend`` file that
489does not have a corresponding recipe with a matching name. See the
490:term:`BB_DANGLINGAPPENDS_WARNONLY`
491variable for information on how to handle this error.
492
493As an example, consider the main formfactor recipe and a corresponding
494formfactor append file both from the :term:`Source Directory`.
495Here is the main
496formfactor recipe, which is named ``formfactor_0.0.bb`` and located in
497the "meta" layer at ``meta/recipes-bsp/formfactor``:
498::
499
500 SUMMARY = "Device formfactor information"
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500501 DESCRIPTION = "A formfactor configuration file provides information about the \
502 target hardware for which the image is being built and information that the \
503 build system cannot obtain from other sources such as the kernel."
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500504 SECTION = "base"
505 LICENSE = "MIT"
506 LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
507 PR = "r45"
508
509 SRC_URI = "file://config file://machconfig"
510 S = "${WORKDIR}"
511
512 PACKAGE_ARCH = "${MACHINE_ARCH}"
513 INHIBIT_DEFAULT_DEPS = "1"
514
515 do_install() {
516 # Install file only if it has contents
517 install -d ${D}${sysconfdir}/formfactor/
518 install -m 0644 ${S}/config ${D}${sysconfdir}/formfactor/
519 if [ -s "${S}/machconfig" ]; then
520 install -m 0644 ${S}/machconfig ${D}${sysconfdir}/formfactor/
521 fi
522 }
523
524In the main recipe, note the :term:`SRC_URI`
525variable, which tells the OpenEmbedded build system where to find files
526during the build.
527
528Following is the append file, which is named ``formfactor_0.0.bbappend``
529and is from the Raspberry Pi BSP Layer named ``meta-raspberrypi``. The
530file is in the layer at ``recipes-bsp/formfactor``:
531::
532
533 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
534
535By default, the build system uses the
536:term:`FILESPATH` variable to
537locate files. This append file extends the locations by setting the
538:term:`FILESEXTRAPATHS`
539variable. Setting this variable in the ``.bbappend`` file is the most
540reliable and recommended method for adding directories to the search
541path used by the build system to find files.
542
543The statement in this example extends the directories to include
544``${``\ :term:`THISDIR`\ ``}/${``\ :term:`PN`\ ``}``,
545which resolves to a directory named ``formfactor`` in the same directory
546in which the append file resides (i.e.
547``meta-raspberrypi/recipes-bsp/formfactor``. This implies that you must
548have the supporting directory structure set up that will contain any
549files or patches you will be including from the layer.
550
551Using the immediate expansion assignment operator ``:=`` is important
552because of the reference to ``THISDIR``. The trailing colon character is
553important as it ensures that items in the list remain colon-separated.
554
555.. note::
556
557 BitBake automatically defines the ``THISDIR`` variable. You should
558 never set this variable yourself. Using "_prepend" as part of the
559 ``FILESEXTRAPATHS`` ensures your path will be searched prior to other
560 paths in the final list.
561
562 Also, not all append files add extra files. Many append files simply
563 exist to add build options (e.g. ``systemd``). For these cases, your
564 append file would not even use the ``FILESEXTRAPATHS`` statement.
565
566Prioritizing Your Layer
567-----------------------
568
569Each layer is assigned a priority value. Priority values control which
570layer takes precedence if there are recipe files with the same name in
571multiple layers. For these cases, the recipe file from the layer with a
572higher priority number takes precedence. Priority values also affect the
573order in which multiple ``.bbappend`` files for the same recipe are
574applied. You can either specify the priority manually, or allow the
575build system to calculate it based on the layer's dependencies.
576
577To specify the layer's priority manually, use the
578:term:`BBFILE_PRIORITY`
579variable and append the layer's root name:
580::
581
582 BBFILE_PRIORITY_mylayer = "1"
583
584.. note::
585
586 It is possible for a recipe with a lower version number
587 :term:`PV` in a layer that has a higher
588 priority to take precedence.
589
590 Also, the layer priority does not currently affect the precedence
591 order of ``.conf`` or ``.bbclass`` files. Future versions of BitBake
592 might address this.
593
594Managing Layers
595---------------
596
597You can use the BitBake layer management tool ``bitbake-layers`` to
598provide a view into the structure of recipes across a multi-layer
599project. Being able to generate output that reports on configured layers
600with their paths and priorities and on ``.bbappend`` files and their
601applicable recipes can help to reveal potential problems.
602
603For help on the BitBake layer management tool, use the following
604command:
605::
606
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500607 $ bitbake-layers --help
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500608 NOTE: Starting bitbake server...
609 usage: bitbake-layers [-d] [-q] [-F] [--color COLOR] [-h] <subcommand> ...
610
611 BitBake layers utility
612
613 optional arguments:
614 -d, --debug Enable debug output
615 -q, --quiet Print only errors
616 -F, --force Force add without recipe parse verification
617 --color COLOR Colorize output (where COLOR is auto, always, never)
618 -h, --help show this help message and exit
619
620 subcommands:
621 <subcommand>
622 layerindex-fetch Fetches a layer from a layer index along with its
623 dependent layers, and adds them to conf/bblayers.conf.
624 layerindex-show-depends
625 Find layer dependencies from layer index.
626 add-layer Add one or more layers to bblayers.conf.
627 remove-layer Remove one or more layers from bblayers.conf.
628 flatten flatten layer configuration into a separate output
629 directory.
630 show-layers show current configured layers.
631 show-overlayed list overlayed recipes (where the same recipe exists
632 in another layer)
633 show-recipes list available recipes, showing the layer they are
634 provided by
635 show-appends list bbappend files and recipe files they apply to
636 show-cross-depends Show dependencies between recipes that cross layer
637 boundaries.
638 create-layer Create a basic layer
639
640 Use bitbake-layers <subcommand> --help to get help on a specific command
641
642The following list describes the available commands:
643
644- ``help:`` Displays general help or help on a specified command.
645
646- ``show-layers:`` Shows the current configured layers.
647
648- ``show-overlayed:`` Lists overlayed recipes. A recipe is overlayed
649 when a recipe with the same name exists in another layer that has a
650 higher layer priority.
651
652- ``show-recipes:`` Lists available recipes and the layers that
653 provide them.
654
655- ``show-appends:`` Lists ``.bbappend`` files and the recipe files to
656 which they apply.
657
658- ``show-cross-depends:`` Lists dependency relationships between
659 recipes that cross layer boundaries.
660
661- ``add-layer:`` Adds a layer to ``bblayers.conf``.
662
663- ``remove-layer:`` Removes a layer from ``bblayers.conf``
664
665- ``flatten:`` Flattens the layer configuration into a separate
666 output directory. Flattening your layer configuration builds a
667 "flattened" directory that contains the contents of all layers, with
668 any overlayed recipes removed and any ``.bbappend`` files appended to
669 the corresponding recipes. You might have to perform some manual
670 cleanup of the flattened layer as follows:
671
672 - Non-recipe files (such as patches) are overwritten. The flatten
673 command shows a warning for these files.
674
675 - Anything beyond the normal layer setup has been added to the
676 ``layer.conf`` file. Only the lowest priority layer's
677 ``layer.conf`` is used.
678
679 - Overridden and appended items from ``.bbappend`` files need to be
680 cleaned up. The contents of each ``.bbappend`` end up in the
681 flattened recipe. However, if there are appended or changed
682 variable values, you need to tidy these up yourself. Consider the
683 following example. Here, the ``bitbake-layers`` command adds the
684 line ``#### bbappended ...`` so that you know where the following
685 lines originate:
686 ::
687
688 ...
689 DESCRIPTION = "A useful utility"
690 ...
691 EXTRA_OECONF = "--enable-something"
692 ...
693
694 #### bbappended from meta-anotherlayer ####
695
696 DESCRIPTION = "Customized utility"
697 EXTRA_OECONF += "--enable-somethingelse"
698
699
700 Ideally, you would tidy up these utilities as follows:
701 ::
702
703 ...
704 DESCRIPTION = "Customized utility"
705 ...
706 EXTRA_OECONF = "--enable-something --enable-somethingelse"
707 ...
708
709- ``layerindex-fetch``: Fetches a layer from a layer index, along
710 with its dependent layers, and adds the layers to the
711 ``conf/bblayers.conf`` file.
712
713- ``layerindex-show-depends``: Finds layer dependencies from the
714 layer index.
715
716- ``create-layer``: Creates a basic layer.
717
718Creating a General Layer Using the ``bitbake-layers`` Script
719------------------------------------------------------------
720
721The ``bitbake-layers`` script with the ``create-layer`` subcommand
722simplifies creating a new general layer.
723
724.. note::
725
726 - For information on BSP layers, see the ":ref:`bsp-guide/bsp:bsp layers`"
727 section in the Yocto
728 Project Board Specific (BSP) Developer's Guide.
729
730 - In order to use a layer with the OpenEmbedded build system, you
731 need to add the layer to your ``bblayers.conf`` configuration
732 file. See the ":ref:`dev-manual/dev-manual-common-tasks:adding a layer using the \`\`bitbake-layers\`\` script`"
733 section for more information.
734
735The default mode of the script's operation with this subcommand is to
736create a layer with the following:
737
738- A layer priority of 6.
739
740- A ``conf`` subdirectory that contains a ``layer.conf`` file.
741
742- A ``recipes-example`` subdirectory that contains a further
743 subdirectory named ``example``, which contains an ``example.bb``
744 recipe file.
745
746- A ``COPYING.MIT``, which is the license statement for the layer. The
747 script assumes you want to use the MIT license, which is typical for
748 most layers, for the contents of the layer itself.
749
750- A ``README`` file, which is a file describing the contents of your
751 new layer.
752
753In its simplest form, you can use the following command form to create a
754layer. The command creates a layer whose name corresponds to
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500755"your_layer_name" in the current directory:
756::
757
758 $ bitbake-layers create-layer your_layer_name
759
760As an example, the following command creates a layer named ``meta-scottrif``
761in your home directory:
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500762::
763
764 $ cd /usr/home
765 $ bitbake-layers create-layer meta-scottrif
766 NOTE: Starting bitbake server...
767 Add your new layer with 'bitbake-layers add-layer meta-scottrif'
768
769If you want to set the priority of the layer to other than the default
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500770value of "6", you can either use the ``--priority`` option or you
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500771can edit the
772:term:`BBFILE_PRIORITY` value
773in the ``conf/layer.conf`` after the script creates it. Furthermore, if
774you want to give the example recipe file some name other than the
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500775default, you can use the ``--example-recipe-name`` option.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500776
777The easiest way to see how the ``bitbake-layers create-layer`` command
778works is to experiment with the script. You can also read the usage
779information by entering the following:
780::
781
782 $ bitbake-layers create-layer --help
783 NOTE: Starting bitbake server...
784 usage: bitbake-layers create-layer [-h] [--priority PRIORITY]
785 [--example-recipe-name EXAMPLERECIPE]
786 layerdir
787
788 Create a basic layer
789
790 positional arguments:
791 layerdir Layer directory to create
792
793 optional arguments:
794 -h, --help show this help message and exit
795 --priority PRIORITY, -p PRIORITY
796 Layer directory to create
797 --example-recipe-name EXAMPLERECIPE, -e EXAMPLERECIPE
798 Filename of the example recipe
799
800Adding a Layer Using the ``bitbake-layers`` Script
801--------------------------------------------------
802
803Once you create your general layer, you must add it to your
804``bblayers.conf`` file. Adding the layer to this configuration file
805makes the OpenEmbedded build system aware of your layer so that it can
806search it for metadata.
807
808Add your layer by using the ``bitbake-layers add-layer`` command:
809::
810
811 $ bitbake-layers add-layer your_layer_name
812
813Here is an example that adds a
814layer named ``meta-scottrif`` to the configuration file. Following the
815command that adds the layer is another ``bitbake-layers`` command that
816shows the layers that are in your ``bblayers.conf`` file:
817::
818
819 $ bitbake-layers add-layer meta-scottrif
820 NOTE: Starting bitbake server...
821 Parsing recipes: 100% |##########################################################| Time: 0:00:49
822 Parsing of 1441 .bb files complete (0 cached, 1441 parsed). 2055 targets, 56 skipped, 0 masked, 0 errors.
823 $ bitbake-layers show-layers
824 NOTE: Starting bitbake server...
825 layer path priority
826 ==========================================================================
827 meta /home/scottrif/poky/meta 5
828 meta-poky /home/scottrif/poky/meta-poky 5
829 meta-yocto-bsp /home/scottrif/poky/meta-yocto-bsp 5
830 workspace /home/scottrif/poky/build/workspace 99
831 meta-scottrif /home/scottrif/poky/build/meta-scottrif 6
832
833
834Adding the layer to this file
835enables the build system to locate the layer during the build.
836
837.. note::
838
839 During a build, the OpenEmbedded build system looks in the layers
840 from the top of the list down to the bottom in that order.
841
842.. _usingpoky-extend-customimage:
843
844Customizing Images
845==================
846
847You can customize images to satisfy particular requirements. This
848section describes several methods and provides guidelines for each.
849
850.. _usingpoky-extend-customimage-localconf:
851
852Customizing Images Using ``local.conf``
853---------------------------------------
854
855Probably the easiest way to customize an image is to add a package by
856way of the ``local.conf`` configuration file. Because it is limited to
857local use, this method generally only allows you to add packages and is
858not as flexible as creating your own customized image. When you add
859packages using local variables this way, you need to realize that these
860variable changes are in effect for every build and consequently affect
861all images, which might not be what you require.
862
863To add a package to your image using the local configuration file, use
864the ``IMAGE_INSTALL`` variable with the ``_append`` operator:
865::
866
867 IMAGE_INSTALL_append = " strace"
868
869Use of the syntax is important -
870specifically, the space between the quote and the package name, which is
871``strace`` in this example. This space is required since the ``_append``
872operator does not add the space.
873
874Furthermore, you must use ``_append`` instead of the ``+=`` operator if
875you want to avoid ordering issues. The reason for this is because doing
876so unconditionally appends to the variable and avoids ordering problems
877due to the variable being set in image recipes and ``.bbclass`` files
878with operators like ``?=``. Using ``_append`` ensures the operation
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500879takes effect.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500880
881As shown in its simplest use, ``IMAGE_INSTALL_append`` affects all
882images. It is possible to extend the syntax so that the variable applies
883to a specific image only. Here is an example:
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500884::
885
886 IMAGE_INSTALL_append_pn-core-image-minimal = " strace"
887
888This example adds ``strace`` to the ``core-image-minimal`` image only.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500889
890You can add packages using a similar approach through the
891``CORE_IMAGE_EXTRA_INSTALL`` variable. If you use this variable, only
892``core-image-*`` images are affected.
893
894.. _usingpoky-extend-customimage-imagefeatures:
895
896Customizing Images Using Custom ``IMAGE_FEATURES`` and ``EXTRA_IMAGE_FEATURES``
897-------------------------------------------------------------------------------
898
899Another method for customizing your image is to enable or disable
900high-level image features by using the
901:term:`IMAGE_FEATURES` and
902:term:`EXTRA_IMAGE_FEATURES`
903variables. Although the functions for both variables are nearly
904equivalent, best practices dictate using ``IMAGE_FEATURES`` from within
905a recipe and using ``EXTRA_IMAGE_FEATURES`` from within your
906``local.conf`` file, which is found in the
907:term:`Build Directory`.
908
909To understand how these features work, the best reference is
910``meta/classes/core-image.bbclass``. This class lists out the available
911``IMAGE_FEATURES`` of which most map to package groups while some, such
912as ``debug-tweaks`` and ``read-only-rootfs``, resolve as general
913configuration settings.
914
915In summary, the file looks at the contents of the ``IMAGE_FEATURES``
916variable and then maps or configures the feature accordingly. Based on
917this information, the build system automatically adds the appropriate
918packages or configurations to the
919:term:`IMAGE_INSTALL` variable.
920Effectively, you are enabling extra features by extending the class or
921creating a custom class for use with specialized image ``.bb`` files.
922
923Use the ``EXTRA_IMAGE_FEATURES`` variable from within your local
924configuration file. Using a separate area from which to enable features
925with this variable helps you avoid overwriting the features in the image
926recipe that are enabled with ``IMAGE_FEATURES``. The value of
927``EXTRA_IMAGE_FEATURES`` is added to ``IMAGE_FEATURES`` within
928``meta/conf/bitbake.conf``.
929
930To illustrate how you can use these variables to modify your image,
931consider an example that selects the SSH server. The Yocto Project ships
932with two SSH servers you can use with your images: Dropbear and OpenSSH.
933Dropbear is a minimal SSH server appropriate for resource-constrained
934environments, while OpenSSH is a well-known standard SSH server
935implementation. By default, the ``core-image-sato`` image is configured
936to use Dropbear. The ``core-image-full-cmdline`` and ``core-image-lsb``
937images both include OpenSSH. The ``core-image-minimal`` image does not
938contain an SSH server.
939
940You can customize your image and change these defaults. Edit the
941``IMAGE_FEATURES`` variable in your recipe or use the
942``EXTRA_IMAGE_FEATURES`` in your ``local.conf`` file so that it
943configures the image you are working with to include
944``ssh-server-dropbear`` or ``ssh-server-openssh``.
945
946.. note::
947
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500948 See the ":ref:`ref-manual/ref-features:image features`" section in the Yocto
949 Project Reference Manual for a complete list of image features that ship
950 with the Yocto Project.
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500951
952.. _usingpoky-extend-customimage-custombb:
953
954Customizing Images Using Custom .bb Files
955-----------------------------------------
956
957You can also customize an image by creating a custom recipe that defines
958additional software as part of the image. The following example shows
959the form for the two lines you need:
960::
961
962 IMAGE_INSTALL = "packagegroup-core-x11-base package1 package2"
963 inherit core-image
964
965Defining the software using a custom recipe gives you total control over
966the contents of the image. It is important to use the correct names of
967packages in the ``IMAGE_INSTALL`` variable. You must use the
968OpenEmbedded notation and not the Debian notation for the names (e.g.
969``glibc-dev`` instead of ``libc6-dev``).
970
971The other method for creating a custom image is to base it on an
972existing image. For example, if you want to create an image based on
973``core-image-sato`` but add the additional package ``strace`` to the
974image, copy the ``meta/recipes-sato/images/core-image-sato.bb`` to a new
975``.bb`` and add the following line to the end of the copy:
976::
977
978 IMAGE_INSTALL += "strace"
979
980.. _usingpoky-extend-customimage-customtasks:
981
982Customizing Images Using Custom Package Groups
983----------------------------------------------
984
985For complex custom images, the best approach for customizing an image is
986to create a custom package group recipe that is used to build the image
987or images. A good example of a package group recipe is
988``meta/recipes-core/packagegroups/packagegroup-base.bb``.
989
990If you examine that recipe, you see that the ``PACKAGES`` variable lists
991the package group packages to produce. The ``inherit packagegroup``
992statement sets appropriate default values and automatically adds
993``-dev``, ``-dbg``, and ``-ptest`` complementary packages for each
994package specified in the ``PACKAGES`` statement.
995
996.. note::
997
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500998 The ``inherit packagegroup`` line should be located near the top of the
999 recipe, certainly before the ``PACKAGES`` statement.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001000
1001For each package you specify in ``PACKAGES``, you can use ``RDEPENDS``
1002and ``RRECOMMENDS`` entries to provide a list of packages the parent
1003task package should contain. You can see examples of these further down
1004in the ``packagegroup-base.bb`` recipe.
1005
1006Here is a short, fabricated example showing the same basic pieces for a
1007hypothetical packagegroup defined in ``packagegroup-custom.bb``, where
1008the variable ``PN`` is the standard way to abbreviate the reference to
1009the full packagegroup name ``packagegroup-custom``:
1010::
1011
1012 DESCRIPTION = "My Custom Package Groups"
1013
1014 inherit packagegroup
1015
1016 PACKAGES = "\
1017 ${PN}-apps \
1018 ${PN}-tools \
1019 "
1020
1021 RDEPENDS_${PN}-apps = "\
1022 dropbear \
1023 portmap \
1024 psplash"
1025
1026 RDEPENDS_${PN}-tools = "\
1027 oprofile \
1028 oprofileui-server \
1029 lttng-tools"
1030
1031 RRECOMMENDS_${PN}-tools = "\
1032 kernel-module-oprofile"
1033
1034In the previous example, two package group packages are created with
1035their dependencies and their recommended package dependencies listed:
1036``packagegroup-custom-apps``, and ``packagegroup-custom-tools``. To
1037build an image using these package group packages, you need to add
1038``packagegroup-custom-apps`` and/or ``packagegroup-custom-tools`` to
1039``IMAGE_INSTALL``. For other forms of image dependencies see the other
1040areas of this section.
1041
1042.. _usingpoky-extend-customimage-image-name:
1043
1044Customizing an Image Hostname
1045-----------------------------
1046
1047By default, the configured hostname (i.e. ``/etc/hostname``) in an image
1048is the same as the machine name. For example, if
1049:term:`MACHINE` equals "qemux86", the
1050configured hostname written to ``/etc/hostname`` is "qemux86".
1051
1052You can customize this name by altering the value of the "hostname"
1053variable in the ``base-files`` recipe using either an append file or a
1054configuration file. Use the following in an append file:
1055::
1056
1057 hostname = "myhostname"
1058
1059Use the following in a configuration file:
1060::
1061
1062 hostname_pn-base-files = "myhostname"
1063
1064Changing the default value of the variable "hostname" can be useful in
1065certain situations. For example, suppose you need to do extensive
1066testing on an image and you would like to easily identify the image
1067under test from existing images with typical default hostnames. In this
1068situation, you could change the default hostname to "testme", which
1069results in all the images using the name "testme". Once testing is
1070complete and you do not need to rebuild the image for test any longer,
1071you can easily reset the default hostname.
1072
1073Another point of interest is that if you unset the variable, the image
1074will have no default hostname in the filesystem. Here is an example that
1075unsets the variable in a configuration file:
1076::
1077
1078 hostname_pn-base-files = ""
1079
1080Having no default hostname in the filesystem is suitable for
1081environments that use dynamic hostnames such as virtual machines.
1082
1083.. _new-recipe-writing-a-new-recipe:
1084
1085Writing a New Recipe
1086====================
1087
1088Recipes (``.bb`` files) are fundamental components in the Yocto Project
1089environment. Each software component built by the OpenEmbedded build
1090system requires a recipe to define the component. This section describes
1091how to create, write, and test a new recipe.
1092
1093.. note::
1094
1095 For information on variables that are useful for recipes and for
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001096 information about recipe naming issues, see the
1097 ":ref:`ref-manual/ref-varlocality:recipes`" section of the Yocto Project
1098 Reference Manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001099
1100.. _new-recipe-overview:
1101
1102Overview
1103--------
1104
1105The following figure shows the basic process for creating a new recipe.
1106The remainder of the section provides details for the steps.
1107
1108.. image:: figures/recipe-workflow.png
1109 :align: center
1110
1111.. _new-recipe-locate-or-automatically-create-a-base-recipe:
1112
1113Locate or Automatically Create a Base Recipe
1114--------------------------------------------
1115
1116You can always write a recipe from scratch. However, three choices exist
1117that can help you quickly get a start on a new recipe:
1118
1119- ``devtool add``: A command that assists in creating a recipe and an
1120 environment conducive to development.
1121
1122- ``recipetool create``: A command provided by the Yocto Project that
1123 automates creation of a base recipe based on the source files.
1124
1125- *Existing Recipes:* Location and modification of an existing recipe
1126 that is similar in function to the recipe you need.
1127
1128.. note::
1129
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001130 For information on recipe syntax, see the
1131 ":ref:`dev-manual/dev-manual-common-tasks:recipe syntax`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001132
1133.. _new-recipe-creating-the-base-recipe-using-devtool:
1134
1135Creating the Base Recipe Using ``devtool add``
1136~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1137
1138The ``devtool add`` command uses the same logic for auto-creating the
1139recipe as ``recipetool create``, which is listed below. Additionally,
1140however, ``devtool add`` sets up an environment that makes it easy for
1141you to patch the source and to make changes to the recipe as is often
1142necessary when adding a recipe to build a new piece of software to be
1143included in a build.
1144
1145You can find a complete description of the ``devtool add`` command in
Andrew Geissler6ce62a22020-11-30 19:58:47 -06001146the ":ref:`sdk-manual/sdk-extensible:a closer look at \`\`devtool add\`\``" section
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001147in the Yocto Project Application Development and the Extensible Software
1148Development Kit (eSDK) manual.
1149
1150.. _new-recipe-creating-the-base-recipe-using-recipetool:
1151
1152Creating the Base Recipe Using ``recipetool create``
1153~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1154
1155``recipetool create`` automates creation of a base recipe given a set of
1156source code files. As long as you can extract or point to the source
1157files, the tool will construct a recipe and automatically configure all
1158pre-build information into the recipe. For example, suppose you have an
1159application that builds using Autotools. Creating the base recipe using
1160``recipetool`` results in a recipe that has the pre-build dependencies,
1161license requirements, and checksums configured.
1162
1163To run the tool, you just need to be in your
1164:term:`Build Directory` and have sourced the
1165build environment setup script (i.e.
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001166:ref:`structure-core-script`).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001167To get help on the tool, use the following command:
1168::
1169
1170 $ recipetool -h
1171 NOTE: Starting bitbake server...
1172 usage: recipetool [-d] [-q] [--color COLOR] [-h] <subcommand> ...
1173
1174 OpenEmbedded recipe tool
1175
1176 options:
1177 -d, --debug Enable debug output
1178 -q, --quiet Print only errors
1179 --color COLOR Colorize output (where COLOR is auto, always, never)
1180 -h, --help show this help message and exit
1181
1182 subcommands:
1183 create Create a new recipe
1184 newappend Create a bbappend for the specified target in the specified
1185 layer
1186 setvar Set a variable within a recipe
1187 appendfile Create/update a bbappend to replace a target file
1188 appendsrcfiles Create/update a bbappend to add or replace source files
1189 appendsrcfile Create/update a bbappend to add or replace a source file
1190 Use recipetool <subcommand> --help to get help on a specific command
1191
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001192Running ``recipetool create -o OUTFILE`` creates the base recipe and
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001193locates it properly in the layer that contains your source files.
1194Following are some syntax examples:
1195
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001196 - Use this syntax to generate a recipe based on source. Once generated,
1197 the recipe resides in the existing source code layer:
1198 ::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001199
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001200 recipetool create -o OUTFILE source
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001201
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001202 - Use this syntax to generate a recipe using code that
1203 you extract from source. The extracted code is placed in its own layer
1204 defined by ``EXTERNALSRC``.
1205 ::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001206
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001207 recipetool create -o OUTFILE -x EXTERNALSRC source
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001208
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001209 - Use this syntax to generate a recipe based on source. The options
1210 direct ``recipetool`` to generate debugging information. Once generated,
1211 the recipe resides in the existing source code layer:
1212 ::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001213
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001214 recipetool create -d -o OUTFILE source
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001215
1216.. _new-recipe-locating-and-using-a-similar-recipe:
1217
1218Locating and Using a Similar Recipe
1219~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1220
1221Before writing a recipe from scratch, it is often useful to discover
1222whether someone else has already written one that meets (or comes close
1223to meeting) your needs. The Yocto Project and OpenEmbedded communities
1224maintain many recipes that might be candidates for what you are doing.
1225You can find a good central index of these recipes in the `OpenEmbedded
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001226Layer Index <https://layers.openembedded.org>`__.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001227
1228Working from an existing recipe or a skeleton recipe is the best way to
1229get started. Here are some points on both methods:
1230
1231- *Locate and modify a recipe that is close to what you want to do:*
1232 This method works when you are familiar with the current recipe
1233 space. The method does not work so well for those new to the Yocto
1234 Project or writing recipes.
1235
1236 Some risks associated with this method are using a recipe that has
1237 areas totally unrelated to what you are trying to accomplish with
1238 your recipe, not recognizing areas of the recipe that you might have
1239 to add from scratch, and so forth. All these risks stem from
1240 unfamiliarity with the existing recipe space.
1241
1242- *Use and modify the following skeleton recipe:* If for some reason
1243 you do not want to use ``recipetool`` and you cannot find an existing
1244 recipe that is close to meeting your needs, you can use the following
1245 structure to provide the fundamental areas of a new recipe.
1246 ::
1247
1248 DESCRIPTION = ""
1249 HOMEPAGE = ""
1250 LICENSE = ""
1251 SECTION = ""
1252 DEPENDS = ""
1253 LIC_FILES_CHKSUM = ""
1254
1255 SRC_URI = ""
1256
1257.. _new-recipe-storing-and-naming-the-recipe:
1258
1259Storing and Naming the Recipe
1260-----------------------------
1261
1262Once you have your base recipe, you should put it in your own layer and
1263name it appropriately. Locating it correctly ensures that the
1264OpenEmbedded build system can find it when you use BitBake to process
1265the recipe.
1266
1267- *Storing Your Recipe:* The OpenEmbedded build system locates your
1268 recipe through the layer's ``conf/layer.conf`` file and the
1269 :term:`BBFILES` variable. This
1270 variable sets up a path from which the build system can locate
1271 recipes. Here is the typical use:
1272 ::
1273
1274 BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
1275 ${LAYERDIR}/recipes-*/*/*.bbappend"
1276
1277 Consequently, you need to be sure you locate your new recipe inside
1278 your layer such that it can be found.
1279
1280 You can find more information on how layers are structured in the
1281 "`Understanding and Creating
1282 Layers <#understanding-and-creating-layers>`__" section.
1283
1284- *Naming Your Recipe:* When you name your recipe, you need to follow
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001285 this naming convention:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001286 ::
1287
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001288 basename_version.bb
1289
1290 Use lower-cased characters and do not include the reserved suffixes
1291 ``-native``, ``-cross``, ``-initial``, or ``-dev`` casually (i.e. do not use
1292 them as part of your recipe name unless the string applies). Here are some
1293 examples:
1294
1295 .. code-block:: none
1296
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001297 cups_1.7.0.bb
1298 gawk_4.0.2.bb
1299 irssi_0.8.16-rc1.bb
1300
1301.. _new-recipe-running-a-build-on-the-recipe:
1302
1303Running a Build on the Recipe
1304-----------------------------
1305
1306Creating a new recipe is usually an iterative process that requires
1307using BitBake to process the recipe multiple times in order to
1308progressively discover and add information to the recipe file.
1309
1310Assuming you have sourced the build environment setup script (i.e.
1311:ref:`structure-core-script`) and you are in
1312the :term:`Build Directory`, use
1313BitBake to process your recipe. All you need to provide is the
1314``basename`` of the recipe as described in the previous section:
1315::
1316
1317 $ bitbake basename
1318
1319During the build, the OpenEmbedded build system creates a temporary work
1320directory for each recipe
1321(``${``\ :term:`WORKDIR`\ ``}``)
1322where it keeps extracted source files, log files, intermediate
1323compilation and packaging files, and so forth.
1324
1325The path to the per-recipe temporary work directory depends on the
1326context in which it is being built. The quickest way to find this path
1327is to have BitBake return it by running the following:
1328::
1329
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001330 $ bitbake -e basename | grep ^WORKDIR=
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001331
1332As an example, assume a Source Directory
1333top-level folder named ``poky``, a default Build Directory at
1334``poky/build``, and a ``qemux86-poky-linux`` machine target system.
1335Furthermore, suppose your recipe is named ``foo_1.3.0.bb``. In this
1336case, the work directory the build system uses to build the package
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001337would be as follows:
1338::
1339
1340 poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
1341
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001342Inside this directory you can find sub-directories such as ``image``,
1343``packages-split``, and ``temp``. After the build, you can examine these
1344to determine how well the build went.
1345
1346.. note::
1347
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001348 You can find log files for each task in the recipe's ``temp``
1349 directory (e.g. ``poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0/temp``).
1350 Log files are named ``log.taskname`` (e.g. ``log.do_configure``,
1351 ``log.do_fetch``, and ``log.do_compile``).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001352
1353You can find more information about the build process in
1354":doc:`../overview-manual/overview-manual-development-environment`"
1355chapter of the Yocto Project Overview and Concepts Manual.
1356
1357.. _new-recipe-fetching-code:
1358
1359Fetching Code
1360-------------
1361
1362The first thing your recipe must do is specify how to fetch the source
1363files. Fetching is controlled mainly through the
1364:term:`SRC_URI` variable. Your recipe
1365must have a ``SRC_URI`` variable that points to where the source is
1366located. For a graphical representation of source locations, see the
1367":ref:`sources-dev-environment`" section in
1368the Yocto Project Overview and Concepts Manual.
1369
1370The :ref:`ref-tasks-fetch` task uses
1371the prefix of each entry in the ``SRC_URI`` variable value to determine
1372which :ref:`fetcher <bitbake:bb-fetchers>` to use to get your
1373source files. It is the ``SRC_URI`` variable that triggers the fetcher.
1374The :ref:`ref-tasks-patch` task uses
1375the variable after source is fetched to apply patches. The OpenEmbedded
1376build system uses
1377:term:`FILESOVERRIDES` for
1378scanning directory locations for local files in ``SRC_URI``.
1379
1380The ``SRC_URI`` variable in your recipe must define each unique location
1381for your source files. It is good practice to not hard-code version
1382numbers in a URL used in ``SRC_URI``. Rather than hard-code these
1383values, use ``${``\ :term:`PV`\ ``}``,
1384which causes the fetch process to use the version specified in the
1385recipe filename. Specifying the version in this manner means that
1386upgrading the recipe to a future version is as simple as renaming the
1387recipe to match the new version.
1388
1389Here is a simple example from the
1390``meta/recipes-devtools/strace/strace_5.5.bb`` recipe where the source
1391comes from a single tarball. Notice the use of the
1392:term:`PV` variable:
1393::
1394
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001395 SRC_URI = "https://strace.io/files/${PV}/strace-${PV}.tar.xz \
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001396
1397Files mentioned in ``SRC_URI`` whose names end in a typical archive
1398extension (e.g. ``.tar``, ``.tar.gz``, ``.tar.bz2``, ``.zip``, and so
1399forth), are automatically extracted during the
1400:ref:`ref-tasks-unpack` task. For
1401another example that specifies these types of files, see the
1402"`Autotooled Package <#new-recipe-autotooled-package>`__" section.
1403
1404Another way of specifying source is from an SCM. For Git repositories,
1405you must specify :term:`SRCREV` and
1406you should specify :term:`PV` to include
1407the revision with :term:`SRCPV`. Here
1408is an example from the recipe
1409``meta/recipes-kernel/blktrace/blktrace_git.bb``:
1410::
1411
1412 SRCREV = "d6918c8832793b4205ed3bfede78c2f915c23385"
1413
1414 PR = "r6"
1415 PV = "1.0.5+git${SRCPV}"
1416
1417 SRC_URI = "git://git.kernel.dk/blktrace.git \
1418 file://ldflags.patch"
1419
1420If your ``SRC_URI`` statement includes URLs pointing to individual files
1421fetched from a remote server other than a version control system,
1422BitBake attempts to verify the files against checksums defined in your
1423recipe to ensure they have not been tampered with or otherwise modified
1424since the recipe was written. Two checksums are used:
1425``SRC_URI[md5sum]`` and ``SRC_URI[sha256sum]``.
1426
1427If your ``SRC_URI`` variable points to more than a single URL (excluding
1428SCM URLs), you need to provide the ``md5`` and ``sha256`` checksums for
1429each URL. For these cases, you provide a name for each URL as part of
1430the ``SRC_URI`` and then reference that name in the subsequent checksum
1431statements. Here is an example combining lines from the files
1432``git.inc`` and ``git_2.24.1.bb``:
1433::
1434
1435 SRC_URI = "${KERNELORG_MIRROR}/software/scm/git/git-${PV}.tar.gz;name=tarball \
1436 ${KERNELORG_MIRROR}/software/scm/git/git-manpages-${PV}.tar.gz;name=manpages"
1437
1438 SRC_URI[tarball.md5sum] = "166bde96adbbc11c8843d4f8f4f9811b"
1439 SRC_URI[tarball.sha256sum] = "ad5334956301c86841eb1e5b1bb20884a6bad89a10a6762c958220c7cf64da02"
1440 SRC_URI[manpages.md5sum] = "31c2272a8979022497ba3d4202df145d"
1441 SRC_URI[manpages.sha256sum] = "9a7ae3a093bea39770eb96ca3e5b40bff7af0b9f6123f089d7821d0e5b8e1230"
1442
1443Proper values for ``md5`` and ``sha256`` checksums might be available
1444with other signatures on the download page for the upstream source (e.g.
1445``md5``, ``sha1``, ``sha256``, ``GPG``, and so forth). Because the
1446OpenEmbedded build system only deals with ``sha256sum`` and ``md5sum``,
1447you should verify all the signatures you find by hand.
1448
1449If no ``SRC_URI`` checksums are specified when you attempt to build the
1450recipe, or you provide an incorrect checksum, the build will produce an
1451error for each missing or incorrect checksum. As part of the error
1452message, the build system provides the checksum string corresponding to
1453the fetched file. Once you have the correct checksums, you can copy and
1454paste them into your recipe and then run the build again to continue.
1455
1456.. note::
1457
1458 As mentioned, if the upstream source provides signatures for
1459 verifying the downloaded source code, you should verify those
1460 manually before setting the checksum values in the recipe and
1461 continuing with the build.
1462
1463This final example is a bit more complicated and is from the
1464``meta/recipes-sato/rxvt-unicode/rxvt-unicode_9.20.bb`` recipe. The
1465example's ``SRC_URI`` statement identifies multiple files as the source
1466files for the recipe: a tarball, a patch file, a desktop file, and an
1467icon.
1468::
1469
1470 SRC_URI = "http://dist.schmorp.de/rxvt-unicode/Attic/rxvt-unicode-${PV}.tar.bz2 \
1471 file://xwc.patch \
1472 file://rxvt.desktop \
1473 file://rxvt.png"
1474
1475When you specify local files using the ``file://`` URI protocol, the
1476build system fetches files from the local machine. The path is relative
1477to the :term:`FILESPATH` variable
1478and searches specific directories in a certain order:
1479``${``\ :term:`BP`\ ``}``,
1480``${``\ :term:`BPN`\ ``}``, and
1481``files``. The directories are assumed to be subdirectories of the
1482directory in which the recipe or append file resides. For another
1483example that specifies these types of files, see the "`Single .c File
1484Package (Hello
1485World!) <#new-recipe-single-c-file-package-hello-world>`__" section.
1486
1487The previous example also specifies a patch file. Patch files are files
1488whose names usually end in ``.patch`` or ``.diff`` but can end with
1489compressed suffixes such as ``diff.gz`` and ``patch.bz2``, for example.
1490The build system automatically applies patches as described in the
1491"`Patching Code <#new-recipe-patching-code>`__" section.
1492
1493.. _new-recipe-unpacking-code:
1494
1495Unpacking Code
1496--------------
1497
1498During the build, the
1499:ref:`ref-tasks-unpack` task unpacks
1500the source with ``${``\ :term:`S`\ ``}``
1501pointing to where it is unpacked.
1502
1503If you are fetching your source files from an upstream source archived
1504tarball and the tarball's internal structure matches the common
1505convention of a top-level subdirectory named
1506``${``\ :term:`BPN`\ ``}-${``\ :term:`PV`\ ``}``,
1507then you do not need to set ``S``. However, if ``SRC_URI`` specifies to
1508fetch source from an archive that does not use this convention, or from
1509an SCM like Git or Subversion, your recipe needs to define ``S``.
1510
1511If processing your recipe using BitBake successfully unpacks the source
1512files, you need to be sure that the directory pointed to by ``${S}``
1513matches the structure of the source.
1514
1515.. _new-recipe-patching-code:
1516
1517Patching Code
1518-------------
1519
1520Sometimes it is necessary to patch code after it has been fetched. Any
1521files mentioned in ``SRC_URI`` whose names end in ``.patch`` or
1522``.diff`` or compressed versions of these suffixes (e.g. ``diff.gz`` are
1523treated as patches. The
1524:ref:`ref-tasks-patch` task
1525automatically applies these patches.
1526
1527The build system should be able to apply patches with the "-p1" option
1528(i.e. one directory level in the path will be stripped off). If your
1529patch needs to have more directory levels stripped off, specify the
1530number of levels using the "striplevel" option in the ``SRC_URI`` entry
1531for the patch. Alternatively, if your patch needs to be applied in a
1532specific subdirectory that is not specified in the patch file, use the
1533"patchdir" option in the entry.
1534
1535As with all local files referenced in
1536:term:`SRC_URI` using ``file://``,
1537you should place patch files in a directory next to the recipe either
1538named the same as the base name of the recipe
1539(:term:`BP` and
1540:term:`BPN`) or "files".
1541
1542.. _new-recipe-licensing:
1543
1544Licensing
1545---------
1546
1547Your recipe needs to have both the
1548:term:`LICENSE` and
1549:term:`LIC_FILES_CHKSUM`
1550variables:
1551
1552- ``LICENSE``: This variable specifies the license for the software.
1553 If you do not know the license under which the software you are
1554 building is distributed, you should go to the source code and look
1555 for that information. Typical files containing this information
1556 include ``COPYING``, ``LICENSE``, and ``README`` files. You could
1557 also find the information near the top of a source file. For example,
1558 given a piece of software licensed under the GNU General Public
1559 License version 2, you would set ``LICENSE`` as follows:
1560 ::
1561
1562 LICENSE = "GPLv2"
1563
1564 The licenses you specify within ``LICENSE`` can have any name as long
1565 as you do not use spaces, since spaces are used as separators between
1566 license names. For standard licenses, use the names of the files in
1567 ``meta/files/common-licenses/`` or the ``SPDXLICENSEMAP`` flag names
1568 defined in ``meta/conf/licenses.conf``.
1569
1570- ``LIC_FILES_CHKSUM``: The OpenEmbedded build system uses this
1571 variable to make sure the license text has not changed. If it has,
1572 the build produces an error and it affords you the chance to figure
1573 it out and correct the problem.
1574
1575 You need to specify all applicable licensing files for the software.
1576 At the end of the configuration step, the build process will compare
1577 the checksums of the files to be sure the text has not changed. Any
1578 differences result in an error with the message containing the
1579 current checksum. For more explanation and examples of how to set the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001580 ``LIC_FILES_CHKSUM`` variable, see the
1581 ":ref:`dev-manual/dev-manual-common-tasks:tracking license changes`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001582
1583 To determine the correct checksum string, you can list the
1584 appropriate files in the ``LIC_FILES_CHKSUM`` variable with incorrect
1585 md5 strings, attempt to build the software, and then note the
1586 resulting error messages that will report the correct md5 strings.
1587 See the "`Fetching Code <#new-recipe-fetching-code>`__" section for
1588 additional information.
1589
1590 Here is an example that assumes the software has a ``COPYING`` file:
1591 ::
1592
1593 LIC_FILES_CHKSUM = "file://COPYING;md5=xxx"
1594
1595 When you try to build the
1596 software, the build system will produce an error and give you the
1597 correct string that you can substitute into the recipe file for a
1598 subsequent build.
1599
1600.. _new-dependencies:
1601
1602Dependencies
1603------------
1604
1605Most software packages have a short list of other packages that they
1606require, which are called dependencies. These dependencies fall into two
1607main categories: build-time dependencies, which are required when the
1608software is built; and runtime dependencies, which are required to be
1609installed on the target in order for the software to run.
1610
1611Within a recipe, you specify build-time dependencies using the
1612:term:`DEPENDS` variable. Although
1613nuances exist, items specified in ``DEPENDS`` should be names of other
1614recipes. It is important that you specify all build-time dependencies
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001615explicitly.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001616
1617Another consideration is that configure scripts might automatically
1618check for optional dependencies and enable corresponding functionality
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001619if those dependencies are found. If you wish to make a recipe that is
1620more generally useful (e.g. publish the recipe in a layer for others to
1621use), instead of hard-disabling the functionality, you can use the
1622:term:`PACKAGECONFIG` variable to allow functionality and the
1623corresponding dependencies to be enabled and disabled easily by other
1624users of the recipe.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001625
1626Similar to build-time dependencies, you specify runtime dependencies
1627through a variable -
1628:term:`RDEPENDS`, which is
1629package-specific. All variables that are package-specific need to have
1630the name of the package added to the end as an override. Since the main
1631package for a recipe has the same name as the recipe, and the recipe's
1632name can be found through the
1633``${``\ :term:`PN`\ ``}`` variable, then
1634you specify the dependencies for the main package by setting
1635``RDEPENDS_${PN}``. If the package were named ``${PN}-tools``, then you
1636would set ``RDEPENDS_${PN}-tools``, and so forth.
1637
1638Some runtime dependencies will be set automatically at packaging time.
1639These dependencies include any shared library dependencies (i.e. if a
1640package "example" contains "libexample" and another package "mypackage"
1641contains a binary that links to "libexample" then the OpenEmbedded build
1642system will automatically add a runtime dependency to "mypackage" on
1643"example"). See the
1644":ref:`overview-manual/overview-manual-concepts:automatically added runtime dependencies`"
1645section in the Yocto Project Overview and Concepts Manual for further
1646details.
1647
1648.. _new-recipe-configuring-the-recipe:
1649
1650Configuring the Recipe
1651----------------------
1652
1653Most software provides some means of setting build-time configuration
1654options before compilation. Typically, setting these options is
1655accomplished by running a configure script with options, or by modifying
1656a build configuration file.
1657
1658.. note::
1659
1660 As of Yocto Project Release 1.7, some of the core recipes that
1661 package binary configuration scripts now disable the scripts due to
1662 the scripts previously requiring error-prone path substitution. The
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001663 OpenEmbedded build system uses ``pkg-config`` now, which is much more
1664 robust. You can find a list of the ``*-config`` scripts that are disabled
1665 in the ":ref:`migration-1.7-binary-configuration-scripts-disabled`" section
1666 in the Yocto Project Reference Manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001667
1668A major part of build-time configuration is about checking for
1669build-time dependencies and possibly enabling optional functionality as
1670a result. You need to specify any build-time dependencies for the
1671software you are building in your recipe's
1672:term:`DEPENDS` value, in terms of
1673other recipes that satisfy those dependencies. You can often find
1674build-time or runtime dependencies described in the software's
1675documentation.
1676
1677The following list provides configuration items of note based on how
1678your software is built:
1679
1680- *Autotools:* If your source files have a ``configure.ac`` file, then
1681 your software is built using Autotools. If this is the case, you just
1682 need to worry about modifying the configuration.
1683
1684 When using Autotools, your recipe needs to inherit the
1685 :ref:`autotools <ref-classes-autotools>` class
1686 and your recipe does not have to contain a
1687 :ref:`ref-tasks-configure` task.
1688 However, you might still want to make some adjustments. For example,
1689 you can set
1690 :term:`EXTRA_OECONF` or
1691 :term:`PACKAGECONFIG_CONFARGS`
1692 to pass any needed configure options that are specific to the recipe.
1693
1694- *CMake:* If your source files have a ``CMakeLists.txt`` file, then
1695 your software is built using CMake. If this is the case, you just
1696 need to worry about modifying the configuration.
1697
1698 When you use CMake, your recipe needs to inherit the
1699 :ref:`cmake <ref-classes-cmake>` class and your
1700 recipe does not have to contain a
1701 :ref:`ref-tasks-configure` task.
1702 You can make some adjustments by setting
1703 :term:`EXTRA_OECMAKE` to
1704 pass any needed configure options that are specific to the recipe.
1705
1706 .. note::
1707
1708 If you need to install one or more custom CMake toolchain files
1709 that are supplied by the application you are building, install the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001710 files to ``${D}${datadir}/cmake/Modules`` during ``do_install``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001711
1712- *Other:* If your source files do not have a ``configure.ac`` or
1713 ``CMakeLists.txt`` file, then your software is built using some
1714 method other than Autotools or CMake. If this is the case, you
1715 normally need to provide a
1716 :ref:`ref-tasks-configure` task
1717 in your recipe unless, of course, there is nothing to configure.
1718
1719 Even if your software is not being built by Autotools or CMake, you
1720 still might not need to deal with any configuration issues. You need
1721 to determine if configuration is even a required step. You might need
1722 to modify a Makefile or some configuration file used for the build to
1723 specify necessary build options. Or, perhaps you might need to run a
1724 provided, custom configure script with the appropriate options.
1725
1726 For the case involving a custom configure script, you would run
1727 ``./configure --help`` and look for the options you need to set.
1728
1729Once configuration succeeds, it is always good practice to look at the
1730``log.do_configure`` file to ensure that the appropriate options have
1731been enabled and no additional build-time dependencies need to be added
1732to ``DEPENDS``. For example, if the configure script reports that it
1733found something not mentioned in ``DEPENDS``, or that it did not find
1734something that it needed for some desired optional functionality, then
1735you would need to add those to ``DEPENDS``. Looking at the log might
1736also reveal items being checked for, enabled, or both that you do not
1737want, or items not being found that are in ``DEPENDS``, in which case
1738you would need to look at passing extra options to the configure script
1739as needed. For reference information on configure options specific to
1740the software you are building, you can consult the output of the
1741``./configure --help`` command within ``${S}`` or consult the software's
1742upstream documentation.
1743
1744.. _new-recipe-using-headers-to-interface-with-devices:
1745
1746Using Headers to Interface with Devices
1747---------------------------------------
1748
1749If your recipe builds an application that needs to communicate with some
1750device or needs an API into a custom kernel, you will need to provide
1751appropriate header files. Under no circumstances should you ever modify
1752the existing
1753``meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc`` file.
1754These headers are used to build ``libc`` and must not be compromised
1755with custom or machine-specific header information. If you customize
1756``libc`` through modified headers all other applications that use
1757``libc`` thus become affected.
1758
1759.. note::
1760
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001761 Never copy and customize the ``libc`` header file (i.e.
1762 ``meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc``).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001763
1764The correct way to interface to a device or custom kernel is to use a
1765separate package that provides the additional headers for the driver or
1766other unique interfaces. When doing so, your application also becomes
1767responsible for creating a dependency on that specific provider.
1768
1769Consider the following:
1770
1771- Never modify ``linux-libc-headers.inc``. Consider that file to be
1772 part of the ``libc`` system, and not something you use to access the
1773 kernel directly. You should access ``libc`` through specific ``libc``
1774 calls.
1775
1776- Applications that must talk directly to devices should either provide
1777 necessary headers themselves, or establish a dependency on a special
1778 headers package that is specific to that driver.
1779
1780For example, suppose you want to modify an existing header that adds I/O
1781control or network support. If the modifications are used by a small
1782number programs, providing a unique version of a header is easy and has
1783little impact. When doing so, bear in mind the guidelines in the
1784previous list.
1785
1786.. note::
1787
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001788 If for some reason your changes need to modify the behavior of the ``libc``,
1789 and subsequently all other applications on the system, use a ``.bbappend``
1790 to modify the ``linux-kernel-headers.inc`` file. However, take care to not
1791 make the changes machine specific.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001792
1793Consider a case where your kernel is older and you need an older
1794``libc`` ABI. The headers installed by your recipe should still be a
1795standard mainline kernel, not your own custom one.
1796
1797When you use custom kernel headers you need to get them from
1798:term:`STAGING_KERNEL_DIR`,
1799which is the directory with kernel headers that are required to build
1800out-of-tree modules. Your recipe will also need the following:
1801::
1802
1803 do_configure[depends] += "virtual/kernel:do_shared_workdir"
1804
1805.. _new-recipe-compilation:
1806
1807Compilation
1808-----------
1809
1810During a build, the ``do_compile`` task happens after source is fetched,
1811unpacked, and configured. If the recipe passes through ``do_compile``
1812successfully, nothing needs to be done.
1813
1814However, if the compile step fails, you need to diagnose the failure.
1815Here are some common issues that cause failures.
1816
1817.. note::
1818
1819 For cases where improper paths are detected for configuration files
1820 or for when libraries/headers cannot be found, be sure you are using
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001821 the more robust ``pkg-config``. See the note in section
Andrew Geissler6ce62a22020-11-30 19:58:47 -06001822 ":ref:`dev-manual/dev-manual-common-tasks:Configuring the Recipe`" for additional information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001823
1824- *Parallel build failures:* These failures manifest themselves as
1825 intermittent errors, or errors reporting that a file or directory
1826 that should be created by some other part of the build process could
1827 not be found. This type of failure can occur even if, upon
1828 inspection, the file or directory does exist after the build has
1829 failed, because that part of the build process happened in the wrong
1830 order.
1831
1832 To fix the problem, you need to either satisfy the missing dependency
1833 in the Makefile or whatever script produced the Makefile, or (as a
1834 workaround) set :term:`PARALLEL_MAKE` to an empty string:
1835 ::
1836
1837 PARALLEL_MAKE = ""
1838
1839 For information on parallel Makefile issues, see the "`Debugging
1840 Parallel Make Races <#debugging-parallel-make-races>`__" section.
1841
1842- *Improper host path usage:* This failure applies to recipes building
1843 for the target or ``nativesdk`` only. The failure occurs when the
1844 compilation process uses improper headers, libraries, or other files
1845 from the host system when cross-compiling for the target.
1846
1847 To fix the problem, examine the ``log.do_compile`` file to identify
1848 the host paths being used (e.g. ``/usr/include``, ``/usr/lib``, and
1849 so forth) and then either add configure options, apply a patch, or do
1850 both.
1851
1852- *Failure to find required libraries/headers:* If a build-time
1853 dependency is missing because it has not been declared in
1854 :term:`DEPENDS`, or because the
1855 dependency exists but the path used by the build process to find the
1856 file is incorrect and the configure step did not detect it, the
1857 compilation process could fail. For either of these failures, the
1858 compilation process notes that files could not be found. In these
1859 cases, you need to go back and add additional options to the
1860 configure script as well as possibly add additional build-time
1861 dependencies to ``DEPENDS``.
1862
1863 Occasionally, it is necessary to apply a patch to the source to
1864 ensure the correct paths are used. If you need to specify paths to
1865 find files staged into the sysroot from other recipes, use the
1866 variables that the OpenEmbedded build system provides (e.g.
1867 ``STAGING_BINDIR``, ``STAGING_INCDIR``, ``STAGING_DATADIR``, and so
1868 forth).
1869
1870.. _new-recipe-installing:
1871
1872Installing
1873----------
1874
1875During ``do_install``, the task copies the built files along with their
1876hierarchy to locations that would mirror their locations on the target
1877device. The installation process copies files from the
1878``${``\ :term:`S`\ ``}``,
1879``${``\ :term:`B`\ ``}``, and
1880``${``\ :term:`WORKDIR`\ ``}``
1881directories to the ``${``\ :term:`D`\ ``}``
1882directory to create the structure as it should appear on the target
1883system.
1884
1885How your software is built affects what you must do to be sure your
1886software is installed correctly. The following list describes what you
1887must do for installation depending on the type of build system used by
1888the software being built:
1889
1890- *Autotools and CMake:* If the software your recipe is building uses
1891 Autotools or CMake, the OpenEmbedded build system understands how to
1892 install the software. Consequently, you do not have to have a
1893 ``do_install`` task as part of your recipe. You just need to make
1894 sure the install portion of the build completes with no issues.
1895 However, if you wish to install additional files not already being
1896 installed by ``make install``, you should do this using a
1897 ``do_install_append`` function using the install command as described
1898 in the "Manual" bulleted item later in this list.
1899
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001900- *Other (using* ``make install``\ *)*: You need to define a ``do_install``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001901 function in your recipe. The function should call
1902 ``oe_runmake install`` and will likely need to pass in the
1903 destination directory as well. How you pass that path is dependent on
1904 how the ``Makefile`` being run is written (e.g. ``DESTDIR=${D}``,
1905 ``PREFIX=${D}``, ``INSTALLROOT=${D}``, and so forth).
1906
1907 For an example recipe using ``make install``, see the
1908 "`Makefile-Based Package <#new-recipe-makefile-based-package>`__"
1909 section.
1910
1911- *Manual:* You need to define a ``do_install`` function in your
1912 recipe. The function must first use ``install -d`` to create the
1913 directories under
1914 ``${``\ :term:`D`\ ``}``. Once the
1915 directories exist, your function can use ``install`` to manually
1916 install the built software into the directories.
1917
1918 You can find more information on ``install`` at
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001919 https://www.gnu.org/software/coreutils/manual/html_node/install-invocation.html.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001920
1921For the scenarios that do not use Autotools or CMake, you need to track
1922the installation and diagnose and fix any issues until everything
1923installs correctly. You need to look in the default location of
1924``${D}``, which is ``${WORKDIR}/image``, to be sure your files have been
1925installed correctly.
1926
1927.. note::
1928
1929 - During the installation process, you might need to modify some of
1930 the installed files to suit the target layout. For example, you
1931 might need to replace hard-coded paths in an initscript with
1932 values of variables provided by the build system, such as
1933 replacing ``/usr/bin/`` with ``${bindir}``. If you do perform such
1934 modifications during ``do_install``, be sure to modify the
1935 destination file after copying rather than before copying.
1936 Modifying after copying ensures that the build system can
1937 re-execute ``do_install`` if needed.
1938
1939 - ``oe_runmake install``, which can be run directly or can be run
1940 indirectly by the
1941 :ref:`autotools <ref-classes-autotools>` and
1942 :ref:`cmake <ref-classes-cmake>` classes,
1943 runs ``make install`` in parallel. Sometimes, a Makefile can have
1944 missing dependencies between targets that can result in race
1945 conditions. If you experience intermittent failures during
1946 ``do_install``, you might be able to work around them by disabling
1947 parallel Makefile installs by adding the following to the recipe:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001948 ::
1949
1950 PARALLEL_MAKEINST = ""
1951
1952 See :term:`PARALLEL_MAKEINST` for additional information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001953
1954 - If you need to install one or more custom CMake toolchain files
1955 that are supplied by the application you are building, install the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05001956 files to ``${D}${datadir}/cmake/Modules`` during
Andrew Geisslerc9f78652020-09-18 14:11:35 -05001957 :ref:`ref-tasks-install`.
1958
1959.. _new-recipe-enabling-system-services:
1960
1961Enabling System Services
1962------------------------
1963
1964If you want to install a service, which is a process that usually starts
1965on boot and runs in the background, then you must include some
1966additional definitions in your recipe.
1967
1968If you are adding services and the service initialization script or the
1969service file itself is not installed, you must provide for that
1970installation in your recipe using a ``do_install_append`` function. If
1971your recipe already has a ``do_install`` function, update the function
1972near its end rather than adding an additional ``do_install_append``
1973function.
1974
1975When you create the installation for your services, you need to
1976accomplish what is normally done by ``make install``. In other words,
1977make sure your installation arranges the output similar to how it is
1978arranged on the target system.
1979
1980The OpenEmbedded build system provides support for starting services two
1981different ways:
1982
1983- *SysVinit:* SysVinit is a system and service manager that manages the
1984 init system used to control the very basic functions of your system.
1985 The init program is the first program started by the Linux kernel
1986 when the system boots. Init then controls the startup, running and
1987 shutdown of all other programs.
1988
1989 To enable a service using SysVinit, your recipe needs to inherit the
1990 :ref:`update-rc.d <ref-classes-update-rc.d>`
1991 class. The class helps facilitate safely installing the package on
1992 the target.
1993
1994 You will need to set the
1995 :term:`INITSCRIPT_PACKAGES`,
1996 :term:`INITSCRIPT_NAME`,
1997 and
1998 :term:`INITSCRIPT_PARAMS`
1999 variables within your recipe.
2000
2001- *systemd:* System Management Daemon (systemd) was designed to replace
2002 SysVinit and to provide enhanced management of services. For more
2003 information on systemd, see the systemd homepage at
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002004 https://freedesktop.org/wiki/Software/systemd/.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002005
2006 To enable a service using systemd, your recipe needs to inherit the
2007 :ref:`systemd <ref-classes-systemd>` class. See
2008 the ``systemd.bbclass`` file located in your :term:`Source Directory`
2009 section for
2010 more information.
2011
2012.. _new-recipe-packaging:
2013
2014Packaging
2015---------
2016
2017Successful packaging is a combination of automated processes performed
2018by the OpenEmbedded build system and some specific steps you need to
2019take. The following list describes the process:
2020
2021- *Splitting Files*: The ``do_package`` task splits the files produced
2022 by the recipe into logical components. Even software that produces a
2023 single binary might still have debug symbols, documentation, and
2024 other logical components that should be split out. The ``do_package``
2025 task ensures that files are split up and packaged correctly.
2026
2027- *Running QA Checks*: The
2028 :ref:`insane <ref-classes-insane>` class adds a
2029 step to the package generation process so that output quality
2030 assurance checks are generated by the OpenEmbedded build system. This
2031 step performs a range of checks to be sure the build's output is free
2032 of common problems that show up during runtime. For information on
2033 these checks, see the
2034 :ref:`insane <ref-classes-insane>` class and
2035 the ":ref:`ref-manual/ref-qa-checks:qa error and warning messages`"
2036 chapter in the Yocto Project Reference Manual.
2037
2038- *Hand-Checking Your Packages*: After you build your software, you
2039 need to be sure your packages are correct. Examine the
2040 ``${``\ :term:`WORKDIR`\ ``}/packages-split``
2041 directory and make sure files are where you expect them to be. If you
2042 discover problems, you can set
2043 :term:`PACKAGES`,
2044 :term:`FILES`,
2045 ``do_install(_append)``, and so forth as needed.
2046
2047- *Splitting an Application into Multiple Packages*: If you need to
2048 split an application into several packages, see the "`Splitting an
2049 Application into Multiple
2050 Packages <#splitting-an-application-into-multiple-packages>`__"
2051 section for an example.
2052
2053- *Installing a Post-Installation Script*: For an example showing how
2054 to install a post-installation script, see the "`Post-Installation
2055 Scripts <#new-recipe-post-installation-scripts>`__" section.
2056
2057- *Marking Package Architecture*: Depending on what your recipe is
2058 building and how it is configured, it might be important to mark the
2059 packages produced as being specific to a particular machine, or to
2060 mark them as not being specific to a particular machine or
2061 architecture at all.
2062
2063 By default, packages apply to any machine with the same architecture
2064 as the target machine. When a recipe produces packages that are
2065 machine-specific (e.g. the
2066 :term:`MACHINE` value is passed
2067 into the configure script or a patch is applied only for a particular
2068 machine), you should mark them as such by adding the following to the
2069 recipe:
2070 ::
2071
2072 PACKAGE_ARCH = "${MACHINE_ARCH}"
2073
2074 On the other hand, if the recipe produces packages that do not
2075 contain anything specific to the target machine or architecture at
2076 all (e.g. recipes that simply package script files or configuration
2077 files), you should use the
2078 :ref:`allarch <ref-classes-allarch>` class to
2079 do this for you by adding this to your recipe:
2080 ::
2081
2082 inherit allarch
2083
2084 Ensuring that the package architecture is correct is not critical
2085 while you are doing the first few builds of your recipe. However, it
2086 is important in order to ensure that your recipe rebuilds (or does
2087 not rebuild) appropriately in response to changes in configuration,
2088 and to ensure that you get the appropriate packages installed on the
2089 target machine, particularly if you run separate builds for more than
2090 one target machine.
2091
2092.. _new-sharing-files-between-recipes:
2093
2094Sharing Files Between Recipes
2095-----------------------------
2096
2097Recipes often need to use files provided by other recipes on the build
2098host. For example, an application linking to a common library needs
2099access to the library itself and its associated headers. The way this
2100access is accomplished is by populating a sysroot with files. Each
2101recipe has two sysroots in its work directory, one for target files
2102(``recipe-sysroot``) and one for files that are native to the build host
2103(``recipe-sysroot-native``).
2104
2105.. note::
2106
2107 You could find the term "staging" used within the Yocto project
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002108 regarding files populating sysroots (e.g. the :term:`STAGING_DIR`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002109 variable).
2110
2111Recipes should never populate the sysroot directly (i.e. write files
2112into sysroot). Instead, files should be installed into standard
2113locations during the
2114:ref:`ref-tasks-install` task within
2115the ``${``\ :term:`D`\ ``}`` directory. The
2116reason for this limitation is that almost all files that populate the
2117sysroot are cataloged in manifests in order to ensure the files can be
2118removed later when a recipe is either modified or removed. Thus, the
2119sysroot is able to remain free from stale files.
2120
2121A subset of the files installed by the
2122:ref:`ref-tasks-install` task are
2123used by the
2124:ref:`ref-tasks-populate_sysroot`
2125task as defined by the the
2126:term:`SYSROOT_DIRS` variable to
2127automatically populate the sysroot. It is possible to modify the list of
2128directories that populate the sysroot. The following example shows how
2129you could add the ``/opt`` directory to the list of directories within a
2130recipe:
2131::
2132
2133 SYSROOT_DIRS += "/opt"
2134
2135For a more complete description of the
2136:ref:`ref-tasks-populate_sysroot`
2137task and its associated functions, see the
2138:ref:`staging <ref-classes-staging>` class.
2139
2140.. _metadata-virtual-providers:
2141
2142Using Virtual Providers
2143-----------------------
2144
2145Prior to a build, if you know that several different recipes provide the
2146same functionality, you can use a virtual provider (i.e. ``virtual/*``)
2147as a placeholder for the actual provider. The actual provider is
2148determined at build-time.
2149
2150A common scenario where a virtual provider is used would be for the
2151kernel recipe. Suppose you have three kernel recipes whose
2152:term:`PN` values map to ``kernel-big``,
2153``kernel-mid``, and ``kernel-small``. Furthermore, each of these recipes
2154in some way uses a :term:`PROVIDES`
2155statement that essentially identifies itself as being able to provide
2156``virtual/kernel``. Here is one way through the
2157:ref:`kernel <ref-classes-kernel>` class:
2158::
2159
2160 PROVIDES += "${@ "virtual/kernel" if (d.getVar("KERNEL_PACKAGE_NAME") == "kernel") else "" }"
2161
2162Any recipe that inherits the ``kernel`` class is
2163going to utilize a ``PROVIDES`` statement that identifies that recipe as
2164being able to provide the ``virtual/kernel`` item.
2165
2166Now comes the time to actually build an image and you need a kernel
2167recipe, but which one? You can configure your build to call out the
2168kernel recipe you want by using the
2169:term:`PREFERRED_PROVIDER`
2170variable. As an example, consider the
2171`x86-base.inc <https://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/meta/conf/machine/include/x86-base.inc>`_
2172include file, which is a machine (i.e.
2173:term:`MACHINE`) configuration file.
2174This include file is the reason all x86-based machines use the
2175``linux-yocto`` kernel. Here are the relevant lines from the include
2176file:
2177::
2178
2179 PREFERRED_PROVIDER_virtual/kernel ??= "linux-yocto"
2180 PREFERRED_VERSION_linux-yocto ??= "4.15%"
2181
2182When you use a virtual provider, you do not have to "hard code" a recipe
2183name as a build dependency. You can use the
2184:term:`DEPENDS` variable to state the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002185build is dependent on ``virtual/kernel`` for example:
2186::
2187
2188 DEPENDS = "virtual/kernel"
2189
2190During the build, the OpenEmbedded build system picks
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002191the correct recipe needed for the ``virtual/kernel`` dependency based on
2192the ``PREFERRED_PROVIDER`` variable. If you want to use the small kernel
2193mentioned at the beginning of this section, configure your build as
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002194follows:
2195::
2196
2197 PREFERRED_PROVIDER_virtual/kernel ??= "kernel-small"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002198
2199.. note::
2200
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002201 Any recipe that ``PROVIDES`` a ``virtual/*`` item that is ultimately not
2202 selected through ``PREFERRED_PROVIDER`` does not get built. Preventing these
2203 recipes from building is usually the desired behavior since this mechanism's
2204 purpose is to select between mutually exclusive alternative providers.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002205
2206The following lists specific examples of virtual providers:
2207
2208- ``virtual/kernel``: Provides the name of the kernel recipe to use
2209 when building a kernel image.
2210
2211- ``virtual/bootloader``: Provides the name of the bootloader to use
2212 when building an image.
2213
2214- ``virtual/libgbm``: Provides ``gbm.pc``.
2215
2216- ``virtual/egl``: Provides ``egl.pc`` and possibly ``wayland-egl.pc``.
2217
2218- ``virtual/libgl``: Provides ``gl.pc`` (i.e. libGL).
2219
2220- ``virtual/libgles1``: Provides ``glesv1_cm.pc`` (i.e. libGLESv1_CM).
2221
2222- ``virtual/libgles2``: Provides ``glesv2.pc`` (i.e. libGLESv2).
2223
2224.. note::
2225
2226 Virtual providers only apply to build time dependencies specified with
2227 :term:`PROVIDES` and :term:`DEPENDS`. They do not apply to runtime
2228 dependencies specified with :term:`RPROVIDES` and :term:`RDEPENDS`.
2229
2230Properly Versioning Pre-Release Recipes
2231---------------------------------------
2232
2233Sometimes the name of a recipe can lead to versioning problems when the
2234recipe is upgraded to a final release. For example, consider the
2235``irssi_0.8.16-rc1.bb`` recipe file in the list of example recipes in
2236the "`Storing and Naming the
2237Recipe <#new-recipe-storing-and-naming-the-recipe>`__" section. This
2238recipe is at a release candidate stage (i.e. "rc1"). When the recipe is
2239released, the recipe filename becomes ``irssi_0.8.16.bb``. The version
2240change from ``0.8.16-rc1`` to ``0.8.16`` is seen as a decrease by the
2241build system and package managers, so the resulting packages will not
2242correctly trigger an upgrade.
2243
2244In order to ensure the versions compare properly, the recommended
2245convention is to set :term:`PV` within the
2246recipe to "previous_version+current_version". You can use an additional
2247variable so that you can use the current version elsewhere. Here is an
2248example:
2249::
2250
2251 REALPV = "0.8.16-rc1"
2252 PV = "0.8.15+${REALPV}"
2253
2254.. _new-recipe-post-installation-scripts:
2255
2256Post-Installation Scripts
2257-------------------------
2258
2259Post-installation scripts run immediately after installing a package on
2260the target or during image creation when a package is included in an
2261image. To add a post-installation script to a package, add a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002262``pkg_postinst_``\ `PACKAGENAME`\ ``()`` function to the recipe file
2263(``.bb``) and replace `PACKAGENAME` with the name of the package you want
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002264to attach to the ``postinst`` script. To apply the post-installation
2265script to the main package for the recipe, which is usually what is
2266required, specify
2267``${``\ :term:`PN`\ ``}`` in place of
2268PACKAGENAME.
2269
2270A post-installation function has the following structure:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002271::
2272
2273 pkg_postinst_PACKAGENAME() {
2274 # Commands to carry out
2275 }
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002276
2277The script defined in the post-installation function is called when the
2278root filesystem is created. If the script succeeds, the package is
2279marked as installed.
2280
2281.. note::
2282
2283 Any RPM post-installation script that runs on the target should
2284 return a 0 exit code. RPM does not allow non-zero exit codes for
2285 these scripts, and the RPM package manager will cause the package to
2286 fail installation on the target.
2287
2288Sometimes it is necessary for the execution of a post-installation
2289script to be delayed until the first boot. For example, the script might
2290need to be executed on the device itself. To delay script execution
2291until boot time, you must explicitly mark post installs to defer to the
2292target. You can use ``pkg_postinst_ontarget()`` or call
2293``postinst_intercept delay_to_first_boot`` from ``pkg_postinst()``. Any
2294failure of a ``pkg_postinst()`` script (including exit 1) triggers an
2295error during the
2296:ref:`ref-tasks-rootfs` task.
2297
2298If you have recipes that use ``pkg_postinst`` function and they require
2299the use of non-standard native tools that have dependencies during
2300rootfs construction, you need to use the
2301:term:`PACKAGE_WRITE_DEPS`
2302variable in your recipe to list these tools. If you do not use this
2303variable, the tools might be missing and execution of the
2304post-installation script is deferred until first boot. Deferring the
2305script to first boot is undesirable and for read-only rootfs impossible.
2306
2307.. note::
2308
2309 Equivalent support for pre-install, pre-uninstall, and post-uninstall
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002310 scripts exist by way of ``pkg_preinst``, ``pkg_prerm``, and ``pkg_postrm``,
2311 respectively. These scrips work in exactly the same way as does
2312 ``pkg_postinst`` with the exception that they run at different times. Also,
2313 because of when they run, they are not applicable to being run at image
2314 creation time like ``pkg_postinst``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002315
2316.. _new-recipe-testing:
2317
2318Testing
2319-------
2320
2321The final step for completing your recipe is to be sure that the
2322software you built runs correctly. To accomplish runtime testing, add
2323the build's output packages to your image and test them on the target.
2324
2325For information on how to customize your image by adding specific
2326packages, see the "`Customizing
2327Images <#usingpoky-extend-customimage>`__" section.
2328
2329.. _new-recipe-testing-examples:
2330
2331Examples
2332--------
2333
2334To help summarize how to write a recipe, this section provides some
2335examples given various scenarios:
2336
2337- Recipes that use local files
2338
2339- Using an Autotooled package
2340
2341- Using a Makefile-based package
2342
2343- Splitting an application into multiple packages
2344
2345- Adding binaries to an image
2346
2347.. _new-recipe-single-c-file-package-hello-world:
2348
2349Single .c File Package (Hello World!)
2350~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2351
2352Building an application from a single file that is stored locally (e.g.
2353under ``files``) requires a recipe that has the file listed in the
2354``SRC_URI`` variable. Additionally, you need to manually write the
2355``do_compile`` and ``do_install`` tasks. The ``S`` variable defines the
2356directory containing the source code, which is set to
2357:term:`WORKDIR` in this case - the
2358directory BitBake uses for the build.
2359::
2360
2361 SUMMARY = "Simple helloworld application"
2362 SECTION = "examples"
2363 LICENSE = "MIT"
2364 LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
2365
2366 SRC_URI = "file://helloworld.c"
2367
2368 S = "${WORKDIR}"
2369
2370 do_compile() {
2371 ${CC} helloworld.c -o helloworld
2372 }
2373
2374 do_install() {
2375 install -d ${D}${bindir}
2376 install -m 0755 helloworld ${D}${bindir}
2377 }
2378
2379By default, the ``helloworld``, ``helloworld-dbg``, and
2380``helloworld-dev`` packages are built. For information on how to
2381customize the packaging process, see the "`Splitting an Application into
2382Multiple Packages <#splitting-an-application-into-multiple-packages>`__"
2383section.
2384
2385.. _new-recipe-autotooled-package:
2386
2387Autotooled Package
2388~~~~~~~~~~~~~~~~~~
2389
2390Applications that use Autotools such as ``autoconf`` and ``automake``
2391require a recipe that has a source archive listed in ``SRC_URI`` and
2392also inherit the
2393:ref:`autotools <ref-classes-autotools>` class,
2394which contains the definitions of all the steps needed to build an
2395Autotool-based application. The result of the build is automatically
2396packaged. And, if the application uses NLS for localization, packages
2397with local information are generated (one package per language).
2398Following is one example: (``hello_2.3.bb``)
2399::
2400
2401 SUMMARY = "GNU Helloworld application"
2402 SECTION = "examples"
2403 LICENSE = "GPLv2+"
2404 LIC_FILES_CHKSUM = "file://COPYING;md5=751419260aa954499f7abaabaa882bbe"
2405
2406 SRC_URI = "${GNU_MIRROR}/hello/hello-${PV}.tar.gz"
2407
2408 inherit autotools gettext
2409
2410The variable ``LIC_FILES_CHKSUM`` is used to track source license
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002411changes as described in the
2412":ref:`dev-manual/dev-manual-common-tasks:tracking license changes`" section in
2413the Yocto Project Overview and Concepts Manual. You can quickly create
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002414Autotool-based recipes in a manner similar to the previous example.
2415
2416.. _new-recipe-makefile-based-package:
2417
2418Makefile-Based Package
2419~~~~~~~~~~~~~~~~~~~~~~
2420
2421Applications that use GNU ``make`` also require a recipe that has the
2422source archive listed in ``SRC_URI``. You do not need to add a
2423``do_compile`` step since by default BitBake starts the ``make`` command
2424to compile the application. If you need additional ``make`` options, you
2425should store them in the
2426:term:`EXTRA_OEMAKE` or
2427:term:`PACKAGECONFIG_CONFARGS`
2428variables. BitBake passes these options into the GNU ``make``
2429invocation. Note that a ``do_install`` task is still required.
2430Otherwise, BitBake runs an empty ``do_install`` task by default.
2431
2432Some applications might require extra parameters to be passed to the
2433compiler. For example, the application might need an additional header
2434path. You can accomplish this by adding to the ``CFLAGS`` variable. The
2435following example shows this:
2436::
2437
2438 CFLAGS_prepend = "-I ${S}/include "
2439
2440In the following example, ``mtd-utils`` is a makefile-based package:
2441::
2442
2443 SUMMARY = "Tools for managing memory technology devices"
2444 SECTION = "base"
2445 DEPENDS = "zlib lzo e2fsprogs util-linux"
2446 HOMEPAGE = "http://www.linux-mtd.infradead.org/"
2447 LICENSE = "GPLv2+"
2448 LIC_FILES_CHKSUM = "file://COPYING;md5=0636e73ff0215e8d672dc4c32c317bb3 \
2449 file://include/common.h;beginline=1;endline=17;md5=ba05b07912a44ea2bf81ce409380049c"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002450
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002451 # Use the latest version at 26 Oct, 2013
2452 SRCREV = "9f107132a6a073cce37434ca9cda6917dd8d866b"
2453 SRC_URI = "git://git.infradead.org/mtd-utils.git \
2454 file://add-exclusion-to-mkfs-jffs2-git-2.patch \
2455 "
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002456
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002457 PV = "1.5.1+git${SRCPV}"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002458
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002459 S = "${WORKDIR}/git"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002460
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002461 EXTRA_OEMAKE = "'CC=${CC}' 'RANLIB=${RANLIB}' 'AR=${AR}' 'CFLAGS=${CFLAGS} -I${S}/include -DWITHOUT_XATTR' 'BUILDDIR=${S}'"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002462
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002463 do_install () {
2464 oe_runmake install DESTDIR=${D} SBINDIR=${sbindir} MANDIR=${mandir} INCLUDEDIR=${includedir}
2465 }
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002466
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002467 PACKAGES =+ "mtd-utils-jffs2 mtd-utils-ubifs mtd-utils-misc"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002468
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002469 FILES_mtd-utils-jffs2 = "${sbindir}/mkfs.jffs2 ${sbindir}/jffs2dump ${sbindir}/jffs2reader ${sbindir}/sumtool"
2470 FILES_mtd-utils-ubifs = "${sbindir}/mkfs.ubifs ${sbindir}/ubi*"
2471 FILES_mtd-utils-misc = "${sbindir}/nftl* ${sbindir}/ftl* ${sbindir}/rfd* ${sbindir}/doc* ${sbindir}/serve_image ${sbindir}/recv_image"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002472
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002473 PARALLEL_MAKE = ""
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002474
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002475 BBCLASSEXTEND = "native"
2476
2477Splitting an Application into Multiple Packages
2478~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2479
2480You can use the variables ``PACKAGES`` and ``FILES`` to split an
2481application into multiple packages.
2482
2483Following is an example that uses the ``libxpm`` recipe. By default,
2484this recipe generates a single package that contains the library along
2485with a few binaries. You can modify the recipe to split the binaries
2486into separate packages:
2487::
2488
2489 require xorg-lib-common.inc
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002490
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002491 SUMMARY = "Xpm: X Pixmap extension library"
2492 LICENSE = "BSD"
2493 LIC_FILES_CHKSUM = "file://COPYING;md5=51f4270b012ecd4ab1a164f5f4ed6cf7"
2494 DEPENDS += "libxext libsm libxt"
2495 PE = "1"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002496
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002497 XORG_PN = "libXpm"
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002498
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002499 PACKAGES =+ "sxpm cxpm"
2500 FILES_cxpm = "${bindir}/cxpm"
2501 FILES_sxpm = "${bindir}/sxpm"
2502
2503In the previous example, we want to ship the ``sxpm`` and ``cxpm``
2504binaries in separate packages. Since ``bindir`` would be packaged into
2505the main ``PN`` package by default, we prepend the ``PACKAGES`` variable
2506so additional package names are added to the start of list. This results
2507in the extra ``FILES_*`` variables then containing information that
2508define which files and directories go into which packages. Files
2509included by earlier packages are skipped by latter packages. Thus, the
2510main ``PN`` package does not include the above listed files.
2511
2512Packaging Externally Produced Binaries
2513~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2514
2515Sometimes, you need to add pre-compiled binaries to an image. For
2516example, suppose that binaries for proprietary code exist, which are
2517created by a particular division of a company. Your part of the company
2518needs to use those binaries as part of an image that you are building
2519using the OpenEmbedded build system. Since you only have the binaries
2520and not the source code, you cannot use a typical recipe that expects to
2521fetch the source specified in
2522:term:`SRC_URI` and then compile it.
2523
2524One method is to package the binaries and then install them as part of
2525the image. Generally, it is not a good idea to package binaries since,
2526among other things, it can hinder the ability to reproduce builds and
2527could lead to compatibility problems with ABI in the future. However,
2528sometimes you have no choice.
2529
2530The easiest solution is to create a recipe that uses the
2531:ref:`bin_package <ref-classes-bin-package>` class
2532and to be sure that you are using default locations for build artifacts.
2533In most cases, the ``bin_package`` class handles "skipping" the
2534configure and compile steps as well as sets things up to grab packages
2535from the appropriate area. In particular, this class sets ``noexec`` on
2536both the :ref:`ref-tasks-configure`
2537and :ref:`ref-tasks-compile` tasks,
2538sets ``FILES_${PN}`` to "/" so that it picks up all files, and sets up a
2539:ref:`ref-tasks-install` task, which
2540effectively copies all files from ``${S}`` to ``${D}``. The
2541``bin_package`` class works well when the files extracted into ``${S}``
2542are already laid out in the way they should be laid out on the target.
2543For more information on these variables, see the
2544:term:`FILES`,
2545:term:`PN`,
2546:term:`S`, and
2547:term:`D` variables in the Yocto Project
2548Reference Manual's variable glossary.
2549
2550.. note::
2551
2552 - Using :term:`DEPENDS` is a good
2553 idea even for components distributed in binary form, and is often
2554 necessary for shared libraries. For a shared library, listing the
2555 library dependencies in ``DEPENDS`` makes sure that the libraries
2556 are available in the staging sysroot when other recipes link
2557 against the library, which might be necessary for successful
2558 linking.
2559
2560 - Using ``DEPENDS`` also allows runtime dependencies between
2561 packages to be added automatically. See the
2562 ":ref:`overview-manual/overview-manual-concepts:automatically added runtime dependencies`"
2563 section in the Yocto Project Overview and Concepts Manual for more
2564 information.
2565
2566If you cannot use the ``bin_package`` class, you need to be sure you are
2567doing the following:
2568
2569- Create a recipe where the
2570 :ref:`ref-tasks-configure` and
2571 :ref:`ref-tasks-compile` tasks do
2572 nothing: It is usually sufficient to just not define these tasks in
2573 the recipe, because the default implementations do nothing unless a
2574 Makefile is found in
2575 ``${``\ :term:`S`\ ``}``.
2576
2577 If ``${S}`` might contain a Makefile, or if you inherit some class
2578 that replaces ``do_configure`` and ``do_compile`` with custom
2579 versions, then you can use the
2580 ``[``\ :ref:`noexec <bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ``]``
2581 flag to turn the tasks into no-ops, as follows:
2582 ::
2583
2584 do_configure[noexec] = "1"
2585 do_compile[noexec] = "1"
2586
2587 Unlike
2588 :ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:deleting a task`,
2589 using the flag preserves the dependency chain from the
2590 :ref:`ref-tasks-fetch`,
2591 :ref:`ref-tasks-unpack`, and
2592 :ref:`ref-tasks-patch` tasks to the
2593 :ref:`ref-tasks-install` task.
2594
2595- Make sure your ``do_install`` task installs the binaries
2596 appropriately.
2597
2598- Ensure that you set up :term:`FILES`
2599 (usually
2600 ``FILES_${``\ :term:`PN`\ ``}``) to
2601 point to the files you have installed, which of course depends on
2602 where you have installed them and whether those files are in
2603 different locations than the defaults.
2604
Andrew Geissler6ce62a22020-11-30 19:58:47 -06002605.. note::
2606
2607 If image prelinking is enabled (e.g. "image-prelink" is in :term:`USER_CLASSES`
2608 which it is by default), prelink will change the binaries in the generated images
2609 and this often catches people out. Remove that class to ensure binaries are
2610 preserved exactly if that is necessary.
2611
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002612Following Recipe Style Guidelines
2613---------------------------------
2614
2615When writing recipes, it is good to conform to existing style
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002616guidelines. The :oe_home:`OpenEmbedded Styleguide </wiki/Styleguide>` wiki page
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002617provides rough guidelines for preferred recipe style.
2618
2619It is common for existing recipes to deviate a bit from this style.
2620However, aiming for at least a consistent style is a good idea. Some
2621practices, such as omitting spaces around ``=`` operators in assignments
2622or ordering recipe components in an erratic way, are widely seen as poor
2623style.
2624
2625Recipe Syntax
2626-------------
2627
2628Understanding recipe file syntax is important for writing recipes. The
2629following list overviews the basic items that make up a BitBake recipe
2630file. For more complete BitBake syntax descriptions, see the
2631":doc:`bitbake-user-manual/bitbake-user-manual-metadata`"
2632chapter of the BitBake User Manual.
2633
2634- *Variable Assignments and Manipulations:* Variable assignments allow
2635 a value to be assigned to a variable. The assignment can be static
2636 text or might include the contents of other variables. In addition to
2637 the assignment, appending and prepending operations are also
2638 supported.
2639
2640 The following example shows some of the ways you can use variables in
2641 recipes:
2642 ::
2643
2644 S = "${WORKDIR}/postfix-${PV}"
2645 CFLAGS += "-DNO_ASM"
2646 SRC_URI_append = " file://fixup.patch"
2647
2648- *Functions:* Functions provide a series of actions to be performed.
2649 You usually use functions to override the default implementation of a
2650 task function or to complement a default function (i.e. append or
2651 prepend to an existing function). Standard functions use ``sh`` shell
2652 syntax, although access to OpenEmbedded variables and internal
2653 methods are also available.
2654
2655 The following is an example function from the ``sed`` recipe:
2656 ::
2657
2658 do_install () {
2659 autotools_do_install
2660 install -d ${D}${base_bindir}
2661 mv ${D}${bindir}/sed ${D}${base_bindir}/sed
2662 rmdir ${D}${bindir}/
2663 }
2664
2665 It is
2666 also possible to implement new functions that are called between
2667 existing tasks as long as the new functions are not replacing or
2668 complementing the default functions. You can implement functions in
2669 Python instead of shell. Both of these options are not seen in the
2670 majority of recipes.
2671
2672- *Keywords:* BitBake recipes use only a few keywords. You use keywords
2673 to include common functions (``inherit``), load parts of a recipe
2674 from other files (``include`` and ``require``) and export variables
2675 to the environment (``export``).
2676
2677 The following example shows the use of some of these keywords:
2678 ::
2679
2680 export POSTCONF = "${STAGING_BINDIR}/postconf"
2681 inherit autoconf
2682 require otherfile.inc
2683
2684- *Comments (#):* Any lines that begin with the hash character (``#``)
2685 are treated as comment lines and are ignored:
2686 ::
2687
2688 # This is a comment
2689
2690This next list summarizes the most important and most commonly used
2691parts of the recipe syntax. For more information on these parts of the
2692syntax, you can reference the
2693:doc:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata` chapter
2694in the BitBake User Manual.
2695
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002696- *Line Continuation (\\):* Use the backward slash (``\``) character to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002697 split a statement over multiple lines. Place the slash character at
2698 the end of the line that is to be continued on the next line:
2699 ::
2700
2701 VAR = "A really long \
2702 line"
2703
2704 .. note::
2705
2706 You cannot have any characters including spaces or tabs after the
2707 slash character.
2708
2709- *Using Variables (${VARNAME}):* Use the ``${VARNAME}`` syntax to
2710 access the contents of a variable:
2711 ::
2712
2713 SRC_URI = "${SOURCEFORGE_MIRROR}/libpng/zlib-${PV}.tar.gz"
2714
2715 .. note::
2716
2717 It is important to understand that the value of a variable
2718 expressed in this form does not get substituted automatically. The
2719 expansion of these expressions happens on-demand later (e.g.
2720 usually when a function that makes reference to the variable
2721 executes). This behavior ensures that the values are most
2722 appropriate for the context in which they are finally used. On the
2723 rare occasion that you do need the variable expression to be
2724 expanded immediately, you can use the
2725 :=
2726 operator instead of
2727 =
2728 when you make the assignment, but this is not generally needed.
2729
2730- *Quote All Assignments ("value"):* Use double quotes around values in
2731 all variable assignments (e.g. ``"value"``). Following is an example:
2732 ::
2733
2734 VAR1 = "${OTHERVAR}"
2735 VAR2 = "The version is ${PV}"
2736
2737- *Conditional Assignment (?=):* Conditional assignment is used to
2738 assign a value to a variable, but only when the variable is currently
2739 unset. Use the question mark followed by the equal sign (``?=``) to
2740 make a "soft" assignment used for conditional assignment. Typically,
2741 "soft" assignments are used in the ``local.conf`` file for variables
2742 that are allowed to come through from the external environment.
2743
2744 Here is an example where ``VAR1`` is set to "New value" if it is
2745 currently empty. However, if ``VAR1`` has already been set, it
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002746 remains unchanged:
2747 ::
2748
2749 VAR1 ?= "New value"
2750
2751 In this next example, ``VAR1`` is left with the value "Original value":
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002752 ::
2753
2754 VAR1 = "Original value"
2755 VAR1 ?= "New value"
2756
2757- *Appending (+=):* Use the plus character followed by the equals sign
2758 (``+=``) to append values to existing variables.
2759
2760 .. note::
2761
2762 This operator adds a space between the existing content of the
2763 variable and the new content.
2764
2765 Here is an example:
2766 ::
2767
2768 SRC_URI += "file://fix-makefile.patch"
2769
2770- *Prepending (=+):* Use the equals sign followed by the plus character
2771 (``=+``) to prepend values to existing variables.
2772
2773 .. note::
2774
2775 This operator adds a space between the new content and the
2776 existing content of the variable.
2777
2778 Here is an example:
2779 ::
2780
2781 VAR =+ "Starts"
2782
2783- *Appending (_append):* Use the ``_append`` operator to append values
2784 to existing variables. This operator does not add any additional
2785 space. Also, the operator is applied after all the ``+=``, and ``=+``
2786 operators have been applied and after all ``=`` assignments have
2787 occurred.
2788
2789 The following example shows the space being explicitly added to the
2790 start to ensure the appended value is not merged with the existing
2791 value:
2792 ::
2793
2794 SRC_URI_append = " file://fix-makefile.patch"
2795
2796 You can also use
2797 the ``_append`` operator with overrides, which results in the actions
2798 only being performed for the specified target or machine:
2799 ::
2800
2801 SRC_URI_append_sh4 = " file://fix-makefile.patch"
2802
2803- *Prepending (_prepend):* Use the ``_prepend`` operator to prepend
2804 values to existing variables. This operator does not add any
2805 additional space. Also, the operator is applied after all the ``+=``,
2806 and ``=+`` operators have been applied and after all ``=``
2807 assignments have occurred.
2808
2809 The following example shows the space being explicitly added to the
2810 end to ensure the prepended value is not merged with the existing
2811 value:
2812 ::
2813
2814 CFLAGS_prepend = "-I${S}/myincludes "
2815
2816 You can also use the
2817 ``_prepend`` operator with overrides, which results in the actions
2818 only being performed for the specified target or machine:
2819 ::
2820
2821 CFLAGS_prepend_sh4 = "-I${S}/myincludes "
2822
2823- *Overrides:* You can use overrides to set a value conditionally,
2824 typically based on how the recipe is being built. For example, to set
2825 the :term:`KBRANCH` variable's
2826 value to "standard/base" for any target
2827 :term:`MACHINE`, except for
2828 qemuarm where it should be set to "standard/arm-versatile-926ejs",
2829 you would do the following:
2830 ::
2831
2832 KBRANCH = "standard/base"
2833 KBRANCH_qemuarm = "standard/arm-versatile-926ejs"
2834
2835 Overrides are also used to separate
2836 alternate values of a variable in other situations. For example, when
2837 setting variables such as
2838 :term:`FILES` and
2839 :term:`RDEPENDS` that are
2840 specific to individual packages produced by a recipe, you should
2841 always use an override that specifies the name of the package.
2842
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002843- *Indentation:* Use spaces for indentation rather than tabs. For
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002844 shell functions, both currently work. However, it is a policy
2845 decision of the Yocto Project to use tabs in shell functions. Realize
2846 that some layers have a policy to use spaces for all indentation.
2847
2848- *Using Python for Complex Operations:* For more advanced processing,
2849 it is possible to use Python code during variable assignments (e.g.
2850 search and replacement on a variable).
2851
2852 You indicate Python code using the ``${@python_code}`` syntax for the
2853 variable assignment:
2854 ::
2855
2856 SRC_URI = "ftp://ftp.info-zip.org/pub/infozip/src/zip${@d.getVar('PV',1).replace('.', '')}.tgz
2857
2858- *Shell Function Syntax:* Write shell functions as if you were writing
2859 a shell script when you describe a list of actions to take. You
2860 should ensure that your script works with a generic ``sh`` and that
2861 it does not require any ``bash`` or other shell-specific
2862 functionality. The same considerations apply to various system
2863 utilities (e.g. ``sed``, ``grep``, ``awk``, and so forth) that you
2864 might wish to use. If in doubt, you should check with multiple
2865 implementations - including those from BusyBox.
2866
2867.. _platdev-newmachine:
2868
2869Adding a New Machine
2870====================
2871
2872Adding a new machine to the Yocto Project is a straightforward process.
2873This section describes how to add machines that are similar to those
2874that the Yocto Project already supports.
2875
2876.. note::
2877
2878 Although well within the capabilities of the Yocto Project, adding a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05002879 totally new architecture might require changes to ``gcc``/``glibc``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05002880 and to the site information, which is beyond the scope of this
2881 manual.
2882
2883For a complete example that shows how to add a new machine, see the
2884":ref:`bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script`"
2885section in the Yocto Project Board Support Package (BSP) Developer's
2886Guide.
2887
2888.. _platdev-newmachine-conffile:
2889
2890Adding the Machine Configuration File
2891-------------------------------------
2892
2893To add a new machine, you need to add a new machine configuration file
2894to the layer's ``conf/machine`` directory. This configuration file
2895provides details about the device you are adding.
2896
2897The OpenEmbedded build system uses the root name of the machine
2898configuration file to reference the new machine. For example, given a
2899machine configuration file named ``crownbay.conf``, the build system
2900recognizes the machine as "crownbay".
2901
2902The most important variables you must set in your machine configuration
2903file or include from a lower-level configuration file are as follows:
2904
2905- ``TARGET_ARCH`` (e.g. "arm")
2906
2907- ``PREFERRED_PROVIDER_virtual/kernel``
2908
2909- ``MACHINE_FEATURES`` (e.g. "apm screen wifi")
2910
2911You might also need these variables:
2912
2913- ``SERIAL_CONSOLES`` (e.g. "115200;ttyS0 115200;ttyS1")
2914
2915- ``KERNEL_IMAGETYPE`` (e.g. "zImage")
2916
2917- ``IMAGE_FSTYPES`` (e.g. "tar.gz jffs2")
2918
2919You can find full details on these variables in the reference section.
2920You can leverage existing machine ``.conf`` files from
2921``meta-yocto-bsp/conf/machine/``.
2922
2923.. _platdev-newmachine-kernel:
2924
2925Adding a Kernel for the Machine
2926-------------------------------
2927
2928The OpenEmbedded build system needs to be able to build a kernel for the
2929machine. You need to either create a new kernel recipe for this machine,
2930or extend an existing kernel recipe. You can find several kernel recipe
2931examples in the Source Directory at ``meta/recipes-kernel/linux`` that
2932you can use as references.
2933
2934If you are creating a new kernel recipe, normal recipe-writing rules
2935apply for setting up a ``SRC_URI``. Thus, you need to specify any
2936necessary patches and set ``S`` to point at the source code. You need to
2937create a ``do_configure`` task that configures the unpacked kernel with
2938a ``defconfig`` file. You can do this by using a ``make defconfig``
2939command or, more commonly, by copying in a suitable ``defconfig`` file
2940and then running ``make oldconfig``. By making use of ``inherit kernel``
2941and potentially some of the ``linux-*.inc`` files, most other
2942functionality is centralized and the defaults of the class normally work
2943well.
2944
2945If you are extending an existing kernel recipe, it is usually a matter
2946of adding a suitable ``defconfig`` file. The file needs to be added into
2947a location similar to ``defconfig`` files used for other machines in a
2948given kernel recipe. A possible way to do this is by listing the file in
2949the ``SRC_URI`` and adding the machine to the expression in
2950``COMPATIBLE_MACHINE``:
2951::
2952
2953 COMPATIBLE_MACHINE = '(qemux86|qemumips)'
2954
2955For more information on ``defconfig`` files, see the
2956":ref:`kernel-dev/kernel-dev-common:changing the configuration`"
2957section in the Yocto Project Linux Kernel Development Manual.
2958
2959.. _platdev-newmachine-formfactor:
2960
2961Adding a Formfactor Configuration File
2962--------------------------------------
2963
2964A formfactor configuration file provides information about the target
2965hardware for which the image is being built and information that the
2966build system cannot obtain from other sources such as the kernel. Some
2967examples of information contained in a formfactor configuration file
2968include framebuffer orientation, whether or not the system has a
2969keyboard, the positioning of the keyboard in relation to the screen, and
2970the screen resolution.
2971
2972The build system uses reasonable defaults in most cases. However, if
2973customization is necessary, you need to create a ``machconfig`` file in
2974the ``meta/recipes-bsp/formfactor/files`` directory. This directory
2975contains directories for specific machines such as ``qemuarm`` and
2976``qemux86``. For information about the settings available and the
2977defaults, see the ``meta/recipes-bsp/formfactor/files/config`` file
2978found in the same area.
2979
2980Following is an example for "qemuarm" machine:
2981::
2982
2983 HAVE_TOUCHSCREEN=1
2984 HAVE_KEYBOARD=1
2985 DISPLAY_CAN_ROTATE=0
2986 DISPLAY_ORIENTATION=0
2987 #DISPLAY_WIDTH_PIXELS=640
2988 #DISPLAY_HEIGHT_PIXELS=480
2989 #DISPLAY_BPP=16
2990 DISPLAY_DPI=150
2991 DISPLAY_SUBPIXEL_ORDER=vrgb
2992
2993.. _gs-upgrading-recipes:
2994
2995Upgrading Recipes
2996=================
2997
2998Over time, upstream developers publish new versions for software built
2999by layer recipes. It is recommended to keep recipes up-to-date with
3000upstream version releases.
3001
3002While several methods exist that allow you upgrade a recipe, you might
3003consider checking on the upgrade status of a recipe first. You can do so
3004using the ``devtool check-upgrade-status`` command. See the
3005":ref:`devtool-checking-on-the-upgrade-status-of-a-recipe`"
3006section in the Yocto Project Reference Manual for more information.
3007
3008The remainder of this section describes three ways you can upgrade a
3009recipe. You can use the Automated Upgrade Helper (AUH) to set up
3010automatic version upgrades. Alternatively, you can use
3011``devtool upgrade`` to set up semi-automatic version upgrades. Finally,
3012you can manually upgrade a recipe by editing the recipe itself.
3013
3014.. _gs-using-the-auto-upgrade-helper:
3015
3016Using the Auto Upgrade Helper (AUH)
3017-----------------------------------
3018
3019The AUH utility works in conjunction with the OpenEmbedded build system
3020in order to automatically generate upgrades for recipes based on new
3021versions being published upstream. Use AUH when you want to create a
3022service that performs the upgrades automatically and optionally sends
3023you an email with the results.
3024
3025AUH allows you to update several recipes with a single use. You can also
3026optionally perform build and integration tests using images with the
3027results saved to your hard drive and emails of results optionally sent
3028to recipe maintainers. Finally, AUH creates Git commits with appropriate
3029commit messages in the layer's tree for the changes made to recipes.
3030
3031.. note::
3032
3033 Conditions do exist when you should not use AUH to upgrade recipes
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003034 and you should instead use either ``devtool upgrade`` or upgrade your
3035 recipes manually:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003036
3037 - When AUH cannot complete the upgrade sequence. This situation
3038 usually results because custom patches carried by the recipe
3039 cannot be automatically rebased to the new version. In this case,
3040 ``devtool upgrade`` allows you to manually resolve conflicts.
3041
3042 - When for any reason you want fuller control over the upgrade
3043 process. For example, when you want special arrangements for
3044 testing.
3045
3046The following steps describe how to set up the AUH utility:
3047
30481. *Be Sure the Development Host is Set Up:* You need to be sure that
3049 your development host is set up to use the Yocto Project. For
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003050 information on how to set up your host, see the
Andrew Geissler6ce62a22020-11-30 19:58:47 -06003051 ":ref:`dev-manual/dev-manual-start:Preparing the Build Host`" section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003052
30532. *Make Sure Git is Configured:* The AUH utility requires Git to be
3054 configured because AUH uses Git to save upgrades. Thus, you must have
3055 Git user and email configured. The following command shows your
3056 configurations:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003057 ::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003058
3059 $ git config --list
3060
3061 If you do not have the user and
3062 email configured, you can use the following commands to do so:
3063 ::
3064
3065 $ git config --global user.name some_name
3066 $ git config --global user.email username@domain.com
3067
30683. *Clone the AUH Repository:* To use AUH, you must clone the repository
3069 onto your development host. The following command uses Git to create
3070 a local copy of the repository on your system:
3071 ::
3072
3073 $ git clone git://git.yoctoproject.org/auto-upgrade-helper
3074 Cloning into 'auto-upgrade-helper'... remote: Counting objects: 768, done.
3075 remote: Compressing objects: 100% (300/300), done.
3076 remote: Total 768 (delta 499), reused 703 (delta 434)
3077 Receiving objects: 100% (768/768), 191.47 KiB | 98.00 KiB/s, done.
3078 Resolving deltas: 100% (499/499), done.
3079 Checking connectivity... done.
3080
3081 AUH is not part of the :term:`OpenEmbedded-Core (OE-Core)` or
3082 :term:`Poky` repositories.
3083
30844. *Create a Dedicated Build Directory:* Run the
3085 :ref:`structure-core-script`
3086 script to create a fresh build directory that you use exclusively for
3087 running the AUH utility:
3088 ::
3089
3090 $ cd ~/poky
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003091 $ source oe-init-build-env your_AUH_build_directory
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003092
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003093 Re-using an existing build directory and its configurations is not
3094 recommended as existing settings could cause AUH to fail or behave
3095 undesirably.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003096
30975. *Make Configurations in Your Local Configuration File:* Several
3098 settings need to exist in the ``local.conf`` file in the build
3099 directory you just created for AUH. Make these following
3100 configurations:
3101
3102 - If you want to enable :ref:`Build
3103 History <dev-manual/dev-manual-common-tasks:maintaining build output quality>`,
3104 which is optional, you need the following lines in the
3105 ``conf/local.conf`` file:
3106 ::
3107
3108 INHERIT =+ "buildhistory"
3109 BUILDHISTORY_COMMIT = "1"
3110
3111 With this configuration and a successful
3112 upgrade, a build history "diff" file appears in the
3113 ``upgrade-helper/work/recipe/buildhistory-diff.txt`` file found in
3114 your build directory.
3115
3116 - If you want to enable testing through the
3117 :ref:`testimage <ref-classes-testimage*>`
3118 class, which is optional, you need to have the following set in
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003119 your ``conf/local.conf`` file:
3120 ::
3121
3122 INHERIT += "testimage"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003123
3124 .. note::
3125
3126 If your distro does not enable by default ptest, which Poky
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003127 does, you need the following in your ``local.conf`` file:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003128 ::
3129
3130 DISTRO_FEATURES_append = " ptest"
3131
3132
31336. *Optionally Start a vncserver:* If you are running in a server
3134 without an X11 session, you need to start a vncserver:
3135 ::
3136
3137 $ vncserver :1
3138 $ export DISPLAY=:1
3139
31407. *Create and Edit an AUH Configuration File:* You need to have the
3141 ``upgrade-helper/upgrade-helper.conf`` configuration file in your
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003142 build directory. You can find a sample configuration file in the
3143 :yocto_git:`AUH source repository </cgit/cgit.cgi/auto-upgrade-helper/tree/>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003144
3145 Read through the sample file and make configurations as needed. For
3146 example, if you enabled build history in your ``local.conf`` as
3147 described earlier, you must enable it in ``upgrade-helper.conf``.
3148
3149 Also, if you are using the default ``maintainers.inc`` file supplied
3150 with Poky and located in ``meta-yocto`` and you do not set a
3151 "maintainers_whitelist" or "global_maintainer_override" in the
3152 ``upgrade-helper.conf`` configuration, and you specify "-e all" on
3153 the AUH command-line, the utility automatically sends out emails to
3154 all the default maintainers. Please avoid this.
3155
3156This next set of examples describes how to use the AUH:
3157
3158- *Upgrading a Specific Recipe:* To upgrade a specific recipe, use the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003159 following form:
3160 ::
3161
3162 $ upgrade-helper.py recipe_name
3163
3164 For example, this command upgrades the ``xmodmap`` recipe:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003165 ::
3166
3167 $ upgrade-helper.py xmodmap
3168
3169- *Upgrading a Specific Recipe to a Particular Version:* To upgrade a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003170 specific recipe to a particular version, use the following form:
3171 ::
3172
3173 $ upgrade-helper.py recipe_name -t version
3174
3175 For example, this command upgrades the ``xmodmap`` recipe to version 1.2.3:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003176 ::
3177
3178 $ upgrade-helper.py xmodmap -t 1.2.3
3179
3180- *Upgrading all Recipes to the Latest Versions and Suppressing Email
3181 Notifications:* To upgrade all recipes to their most recent versions
3182 and suppress the email notifications, use the following command:
3183 ::
3184
3185 $ upgrade-helper.py all
3186
3187- *Upgrading all Recipes to the Latest Versions and Send Email
3188 Notifications:* To upgrade all recipes to their most recent versions
3189 and send email messages to maintainers for each attempted recipe as
3190 well as a status email, use the following command:
3191 ::
3192
3193 $ upgrade-helper.py -e all
3194
3195Once you have run the AUH utility, you can find the results in the AUH
3196build directory:
3197::
3198
3199 ${BUILDDIR}/upgrade-helper/timestamp
3200
3201The AUH utility
3202also creates recipe update commits from successful upgrade attempts in
3203the layer tree.
3204
3205You can easily set up to run the AUH utility on a regular basis by using
3206a cron job. See the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003207:yocto_git:`weeklyjob.sh </cgit/cgit.cgi/auto-upgrade-helper/tree/weeklyjob.sh>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003208file distributed with the utility for an example.
3209
3210.. _gs-using-devtool-upgrade:
3211
3212Using ``devtool upgrade``
3213-------------------------
3214
3215As mentioned earlier, an alternative method for upgrading recipes to
3216newer versions is to use
3217:doc:`devtool upgrade <../ref-manual/ref-devtool-reference>`.
3218You can read about ``devtool upgrade`` in general in the
Andrew Geissler6ce62a22020-11-30 19:58:47 -06003219":ref:`sdk-manual/sdk-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 -05003220section in the Yocto Project Application Development and the Extensible
3221Software Development Kit (eSDK) Manual.
3222
3223To see all the command-line options available with ``devtool upgrade``,
3224use the following help command:
3225::
3226
3227 $ devtool upgrade -h
3228
3229If you want to find out what version a recipe is currently at upstream
3230without any attempt to upgrade your local version of the recipe, you can
3231use the following command:
3232::
3233
3234 $ devtool latest-version recipe_name
3235
3236As mentioned in the previous section describing AUH, ``devtool upgrade``
3237works in a less-automated manner than AUH. Specifically,
3238``devtool upgrade`` only works on a single recipe that you name on the
3239command line, cannot perform build and integration testing using images,
3240and does not automatically generate commits for changes in the source
3241tree. Despite all these "limitations", ``devtool upgrade`` updates the
3242recipe file to the new upstream version and attempts to rebase custom
3243patches contained by the recipe as needed.
3244
3245.. note::
3246
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003247 AUH uses much of ``devtool upgrade`` behind the scenes making AUH somewhat
3248 of a "wrapper" application for ``devtool upgrade``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003249
3250A typical scenario involves having used Git to clone an upstream
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003251repository that you use during build operations. Because you have built the
3252recipe in the past, the layer is likely added to your
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003253configuration already. If for some reason, the layer is not added, you
3254could add it easily using the
3255":ref:`bitbake-layers <bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script>`"
3256script. For example, suppose you use the ``nano.bb`` recipe from the
3257``meta-oe`` layer in the ``meta-openembedded`` repository. For this
3258example, assume that the layer has been cloned into following area:
3259::
3260
3261 /home/scottrif/meta-openembedded
3262
3263The following command from your
3264:term:`Build Directory` adds the layer to
3265your build configuration (i.e. ``${BUILDDIR}/conf/bblayers.conf``):
3266::
3267
3268 $ bitbake-layers add-layer /home/scottrif/meta-openembedded/meta-oe
3269 NOTE: Starting bitbake server...
3270 Parsing recipes: 100% |##########################################| Time: 0:00:55
3271 Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
3272 Removing 12 recipes from the x86_64 sysroot: 100% |##############| Time: 0:00:00
3273 Removing 1 recipes from the x86_64_i586 sysroot: 100% |##########| Time: 0:00:00
3274 Removing 5 recipes from the i586 sysroot: 100% |#################| Time: 0:00:00
3275 Removing 5 recipes from the qemux86 sysroot: 100% |##############| Time: 0:00:00
3276
3277For this example, assume that the ``nano.bb`` recipe that
3278is upstream has a 2.9.3 version number. However, the version in the
3279local repository is 2.7.4. The following command from your build
3280directory automatically upgrades the recipe for you:
3281
3282.. note::
3283
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003284 Using the ``-V`` option is not necessary. Omitting the version number causes
3285 ``devtool upgrade`` to upgrade the recipe to the most recent version.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003286
3287::
3288
3289 $ devtool upgrade nano -V 2.9.3
3290 NOTE: Starting bitbake server...
3291 NOTE: Creating workspace layer in /home/scottrif/poky/build/workspace
3292 Parsing recipes: 100% |##########################################| Time: 0:00:46
3293 Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors.
3294 NOTE: Extracting current version source...
3295 NOTE: Resolving any missing task queue dependencies
3296 .
3297 .
3298 .
3299 NOTE: Executing SetScene Tasks
3300 NOTE: Executing RunQueue Tasks
3301 NOTE: Tasks Summary: Attempted 74 tasks of which 72 didn't need to be rerun and all succeeded.
3302 Adding changed files: 100% |#####################################| Time: 0:00:00
3303 NOTE: Upgraded source extracted to /home/scottrif/poky/build/workspace/sources/nano
3304 NOTE: New recipe is /home/scottrif/poky/build/workspace/recipes/nano/nano_2.9.3.bb
3305
3306Continuing with this example, you can use ``devtool build`` to build the
3307newly upgraded recipe:
3308::
3309
3310 $ devtool build nano
3311 NOTE: Starting bitbake server...
3312 Loading cache: 100% |################################################################################################| Time: 0:00:01
3313 Loaded 2040 entries from dependency cache.
3314 Parsing recipes: 100% |##############################################################################################| Time: 0:00:00
3315 Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
3316 NOTE: Resolving any missing task queue dependencies
3317 .
3318 .
3319 .
3320 NOTE: Executing SetScene Tasks
3321 NOTE: Executing RunQueue Tasks
3322 NOTE: nano: compiling from external source tree /home/scottrif/poky/build/workspace/sources/nano
3323 NOTE: Tasks Summary: Attempted 520 tasks of which 304 didn't need to be rerun and all succeeded.
3324
3325Within the ``devtool upgrade`` workflow, opportunity
3326exists to deploy and test your rebuilt software. For this example,
3327however, running ``devtool finish`` cleans up the workspace once the
3328source in your workspace is clean. This usually means using Git to stage
3329and submit commits for the changes generated by the upgrade process.
3330
3331Once the tree is clean, you can clean things up in this example with the
3332following command from the ``${BUILDDIR}/workspace/sources/nano``
3333directory:
3334::
3335
3336 $ devtool finish nano meta-oe
3337 NOTE: Starting bitbake server...
3338 Loading cache: 100% |################################################################################################| Time: 0:00:00
3339 Loaded 2040 entries from dependency cache.
3340 Parsing recipes: 100% |##############################################################################################| Time: 0:00:01
3341 Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors.
3342 NOTE: Adding new patch 0001-nano.bb-Stuff-I-changed-when-upgrading-nano.bb.patch
3343 NOTE: Updating recipe nano_2.9.3.bb
3344 NOTE: Removing file /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano/nano_2.7.4.bb
3345 NOTE: Moving recipe file to /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano
3346 NOTE: Leaving source tree /home/scottrif/poky/build/workspace/sources/nano as-is; if you no longer need it then please delete it manually
3347
3348
3349Using the ``devtool finish`` command cleans up the workspace and creates a patch
3350file based on your commits. The tool puts all patch files back into the
3351source directory in a sub-directory named ``nano`` in this case.
3352
3353.. _dev-manually-upgrading-a-recipe:
3354
3355Manually Upgrading a Recipe
3356---------------------------
3357
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003358If for some reason you choose not to upgrade recipes using
Andrew Geissler6ce62a22020-11-30 19:58:47 -06003359:ref:`dev-manual/dev-manual-common-tasks:Using the Auto Upgrade Helper (AUH)` or
3360by :ref:`dev-manual/dev-manual-common-tasks:Using \`\`devtool upgrade\`\``,
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003361you can manually edit the recipe files to upgrade the versions.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003362
3363.. note::
3364
3365 Manually updating multiple recipes scales poorly and involves many
3366 steps. The recommendation to upgrade recipe versions is through AUH
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003367 or ``devtool upgrade``, both of which automate some steps and provide
3368 guidance for others needed for the manual process.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003369
3370To manually upgrade recipe versions, follow these general steps:
3371
33721. *Change the Version:* Rename the recipe such that the version (i.e.
3373 the :term:`PV` part of the recipe name)
3374 changes appropriately. If the version is not part of the recipe name,
3375 change the value as it is set for ``PV`` within the recipe itself.
3376
Andrew Geissler4c19ea12020-10-27 13:52:24 -050033772. *Update* ``SRCREV`` *if Needed*: If the source code your recipe builds
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003378 is fetched from Git or some other version control system, update
3379 :term:`SRCREV` to point to the
3380 commit hash that matches the new version.
3381
33823. *Build the Software:* Try to build the recipe using BitBake. Typical
3383 build failures include the following:
3384
3385 - License statements were updated for the new version. For this
3386 case, you need to review any changes to the license and update the
3387 values of :term:`LICENSE` and
3388 :term:`LIC_FILES_CHKSUM`
3389 as needed.
3390
3391 .. note::
3392
3393 License changes are often inconsequential. For example, the
3394 license text's copyright year might have changed.
3395
3396 - Custom patches carried by the older version of the recipe might
3397 fail to apply to the new version. For these cases, you need to
3398 review the failures. Patches might not be necessary for the new
3399 version of the software if the upgraded version has fixed those
3400 issues. If a patch is necessary and failing, you need to rebase it
3401 into the new version.
3402
34034. *Optionally Attempt to Build for Several Architectures:* Once you
3404 successfully build the new software for a given architecture, you
3405 could test the build for other architectures by changing the
3406 :term:`MACHINE` variable and
3407 rebuilding the software. This optional step is especially important
3408 if the recipe is to be released publicly.
3409
34105. *Check the Upstream Change Log or Release Notes:* Checking both these
3411 reveals if new features exist that could break
3412 backwards-compatibility. If so, you need to take steps to mitigate or
3413 eliminate that situation.
3414
34156. *Optionally Create a Bootable Image and Test:* If you want, you can
3416 test the new software by booting it onto actual hardware.
3417
34187. *Create a Commit with the Change in the Layer Repository:* After all
3419 builds work and any testing is successful, you can create commits for
3420 any changes in the layer holding your upgraded recipe.
3421
3422.. _finding-the-temporary-source-code:
3423
3424Finding Temporary Source Code
3425=============================
3426
3427You might find it helpful during development to modify the temporary
3428source code used by recipes to build packages. For example, suppose you
3429are developing a patch and you need to experiment a bit to figure out
3430your solution. After you have initially built the package, you can
3431iteratively tweak the source code, which is located in the
3432:term:`Build Directory`, and then you can
3433force a re-compile and quickly test your altered code. Once you settle
3434on a solution, you can then preserve your changes in the form of
3435patches.
3436
3437During a build, the unpacked temporary source code used by recipes to
3438build packages is available in the Build Directory as defined by the
3439:term:`S` variable. Below is the default
3440value for the ``S`` variable as defined in the
3441``meta/conf/bitbake.conf`` configuration file in the
3442:term:`Source Directory`:
3443::
3444
3445 S = "${WORKDIR}/${BP}"
3446
3447You should be aware that many recipes override the
3448``S`` variable. For example, recipes that fetch their source from Git
3449usually set ``S`` to ``${WORKDIR}/git``.
3450
3451.. note::
3452
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003453 The :term:`BP` represents the base recipe name, which consists of the name
3454 and version:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003455 ::
3456
3457 BP = "${BPN}-${PV}"
3458
3459
3460The path to the work directory for the recipe
3461(:term:`WORKDIR`) is defined as
3462follows:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003463::
3464
3465 ${TMPDIR}/work/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR}
3466
3467The actual directory depends on several things:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003468
3469- :term:`TMPDIR`: The top-level build
3470 output directory.
3471
3472- :term:`MULTIMACH_TARGET_SYS`:
3473 The target system identifier.
3474
3475- :term:`PN`: The recipe name.
3476
3477- :term:`EXTENDPE`: The epoch - (if
3478 :term:`PE` is not specified, which is
3479 usually the case for most recipes, then ``EXTENDPE`` is blank).
3480
3481- :term:`PV`: The recipe version.
3482
3483- :term:`PR`: The recipe revision.
3484
3485As an example, assume a Source Directory top-level folder named
3486``poky``, a default Build Directory at ``poky/build``, and a
3487``qemux86-poky-linux`` machine target system. Furthermore, suppose your
3488recipe is named ``foo_1.3.0.bb``. In this case, the work directory the
3489build system uses to build the package would be as follows:
3490::
3491
3492 poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0
3493
3494.. _using-a-quilt-workflow:
3495
3496Using Quilt in Your Workflow
3497============================
3498
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003499`Quilt <https://savannah.nongnu.org/projects/quilt>`__ is a powerful tool
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003500that allows you to capture source code changes without having a clean
3501source tree. This section outlines the typical workflow you can use to
3502modify source code, test changes, and then preserve the changes in the
3503form of a patch all using Quilt.
3504
3505.. note::
3506
3507 With regard to preserving changes to source files, if you clean a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003508 recipe or have ``rm_work`` enabled, the
3509 :ref:`devtool workflow <sdk-manual/sdk-extensible:using \`\`devtool\`\` in your sdk workflow>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003510 as described in the Yocto Project Application Development and the
3511 Extensible Software Development Kit (eSDK) manual is a safer
3512 development flow than the flow that uses Quilt.
3513
3514Follow these general steps:
3515
35161. *Find the Source Code:* Temporary source code used by the
3517 OpenEmbedded build system is kept in the
3518 :term:`Build Directory`. See the
3519 "`Finding Temporary Source
3520 Code <#finding-the-temporary-source-code>`__" section to learn how to
3521 locate the directory that has the temporary source code for a
3522 particular package.
3523
35242. *Change Your Working Directory:* You need to be in the directory that
3525 has the temporary source code. That directory is defined by the
3526 :term:`S` variable.
3527
35283. *Create a New Patch:* Before modifying source code, you need to
3529 create a new patch. To create a new patch file, use ``quilt new`` as
3530 below:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003531 ::
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003532
3533 $ quilt new my_changes.patch
3534
35354. *Notify Quilt and Add Files:* After creating the patch, you need to
3536 notify Quilt about the files you plan to edit. You notify Quilt by
3537 adding the files to the patch you just created:
3538 ::
3539
3540 $ quilt add file1.c file2.c file3.c
3541
35425. *Edit the Files:* Make your changes in the source code to the files
3543 you added to the patch.
3544
35456. *Test Your Changes:* Once you have modified the source code, the
3546 easiest way to test your changes is by calling the ``do_compile``
3547 task as shown in the following example:
3548 ::
3549
3550 $ bitbake -c compile -f package
3551
3552 The ``-f`` or ``--force`` option forces the specified task to
3553 execute. If you find problems with your code, you can just keep
3554 editing and re-testing iteratively until things work as expected.
3555
3556 .. note::
3557
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003558 All the modifications you make to the temporary source code disappear
3559 once you run the ``do_clean`` or ``do_cleanall`` tasks using BitBake
3560 (i.e. ``bitbake -c clean package`` and ``bitbake -c cleanall package``).
3561 Modifications will also disappear if you use the ``rm_work`` feature as
3562 described in the
3563 ":ref:`dev-manual/dev-manual-common-tasks:conserving disk space during builds`"
3564 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003565
35667. *Generate the Patch:* Once your changes work as expected, you need to
3567 use Quilt to generate the final patch that contains all your
3568 modifications.
3569 ::
3570
3571 $ quilt refresh
3572
3573 At this point, the
3574 ``my_changes.patch`` file has all your edits made to the ``file1.c``,
3575 ``file2.c``, and ``file3.c`` files.
3576
3577 You can find the resulting patch file in the ``patches/``
3578 subdirectory of the source (``S``) directory.
3579
35808. *Copy the Patch File:* For simplicity, copy the patch file into a
3581 directory named ``files``, which you can create in the same directory
3582 that holds the recipe (``.bb``) file or the append (``.bbappend``)
3583 file. Placing the patch here guarantees that the OpenEmbedded build
3584 system will find the patch. Next, add the patch into the ``SRC_URI``
3585 of the recipe. Here is an example:
3586 ::
3587
3588 SRC_URI += "file://my_changes.patch"
3589
3590.. _platdev-appdev-devshell:
3591
3592Using a Development Shell
3593=========================
3594
3595When debugging certain commands or even when just editing packages,
3596``devshell`` can be a useful tool. When you invoke ``devshell``, all
3597tasks up to and including
3598:ref:`ref-tasks-patch` are run for the
3599specified target. Then, a new terminal is opened and you are placed in
3600``${``\ :term:`S`\ ``}``, the source
3601directory. In the new terminal, all the OpenEmbedded build-related
3602environment variables are still defined so you can use commands such as
3603``configure`` and ``make``. The commands execute just as if the
3604OpenEmbedded build system were executing them. Consequently, working
3605this way can be helpful when debugging a build or preparing software to
3606be used with the OpenEmbedded build system.
3607
3608Following is an example that uses ``devshell`` on a target named
3609``matchbox-desktop``:
3610::
3611
3612 $ bitbake matchbox-desktop -c devshell
3613
3614This command spawns a terminal with a shell prompt within the
3615OpenEmbedded build environment. The
3616:term:`OE_TERMINAL` variable
3617controls what type of shell is opened.
3618
3619For spawned terminals, the following occurs:
3620
3621- The ``PATH`` variable includes the cross-toolchain.
3622
3623- The ``pkgconfig`` variables find the correct ``.pc`` files.
3624
3625- The ``configure`` command finds the Yocto Project site files as well
3626 as any other necessary files.
3627
3628Within this environment, you can run configure or compile commands as if
3629they were being run by the OpenEmbedded build system itself. As noted
3630earlier, the working directory also automatically changes to the Source
3631Directory (:term:`S`).
3632
3633To manually run a specific task using ``devshell``, run the
3634corresponding ``run.*`` script in the
3635``${``\ :term:`WORKDIR`\ ``}/temp``
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003636directory (e.g., ``run.do_configure.``\ `pid`). If a task's script does
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003637not exist, which would be the case if the task was skipped by way of the
3638sstate cache, you can create the task by first running it outside of the
3639``devshell``:
3640::
3641
3642 $ bitbake -c task
3643
3644.. note::
3645
3646 - Execution of a task's ``run.*`` script and BitBake's execution of
3647 a task are identical. In other words, running the script re-runs
3648 the task just as it would be run using the ``bitbake -c`` command.
3649
3650 - Any ``run.*`` file that does not have a ``.pid`` extension is a
3651 symbolic link (symlink) to the most recent version of that file.
3652
3653Remember, that the ``devshell`` is a mechanism that allows you to get
3654into the BitBake task execution environment. And as such, all commands
3655must be called just as BitBake would call them. That means you need to
3656provide the appropriate options for cross-compilation and so forth as
3657applicable.
3658
3659When you are finished using ``devshell``, exit the shell or close the
3660terminal window.
3661
3662.. note::
3663
3664 - It is worth remembering that when using ``devshell`` you need to
3665 use the full compiler name such as ``arm-poky-linux-gnueabi-gcc``
3666 instead of just using ``gcc``. The same applies to other
3667 applications such as ``binutils``, ``libtool`` and so forth.
3668 BitBake sets up environment variables such as ``CC`` to assist
3669 applications, such as ``make`` to find the correct tools.
3670
3671 - It is also worth noting that ``devshell`` still works over X11
3672 forwarding and similar situations.
3673
3674.. _platdev-appdev-devpyshell:
3675
3676Using a Development Python Shell
3677================================
3678
3679Similar to working within a development shell as described in the
3680previous section, you can also spawn and work within an interactive
3681Python development shell. When debugging certain commands or even when
3682just editing packages, ``devpyshell`` can be a useful tool. When you
3683invoke ``devpyshell``, all tasks up to and including
3684:ref:`ref-tasks-patch` are run for the
3685specified target. Then a new terminal is opened. Additionally, key
3686Python objects and code are available in the same way they are to
3687BitBake tasks, in particular, the data store 'd'. So, commands such as
3688the following are useful when exploring the data store and running
3689functions:
3690::
3691
3692 pydevshell> d.getVar("STAGING_DIR")
3693 '/media/build1/poky/build/tmp/sysroots'
3694 pydevshell> d.getVar("STAGING_DIR")
3695 '${TMPDIR}/sysroots'
3696 pydevshell> d.setVar("FOO", "bar")
3697 pydevshell> d.getVar("FOO")
3698 'bar'
3699 pydevshell> d.delVar("FOO")
3700 pydevshell> d.getVar("FOO")
3701 pydevshell> bb.build.exec_func("do_unpack", d)
3702 pydevshell>
3703
3704The commands execute just as if the OpenEmbedded build
3705system were executing them. Consequently, working this way can be
3706helpful when debugging a build or preparing software to be used with the
3707OpenEmbedded build system.
3708
3709Following is an example that uses ``devpyshell`` on a target named
3710``matchbox-desktop``:
3711::
3712
3713 $ bitbake matchbox-desktop -c devpyshell
3714
3715This command spawns a terminal and places you in an interactive Python
3716interpreter within the OpenEmbedded build environment. The
3717:term:`OE_TERMINAL` variable
3718controls what type of shell is opened.
3719
3720When you are finished using ``devpyshell``, you can exit the shell
3721either by using Ctrl+d or closing the terminal window.
3722
3723.. _dev-building:
3724
3725Building
3726========
3727
3728This section describes various build procedures. For example, the steps
3729needed for a simple build, a target that uses multiple configurations,
3730building an image for more than one machine, and so forth.
3731
3732.. _dev-building-a-simple-image:
3733
3734Building a Simple Image
3735-----------------------
3736
3737In the development environment, you need to build an image whenever you
3738change hardware support, add or change system libraries, or add or
3739change services that have dependencies. Several methods exist that allow
3740you to build an image within the Yocto Project. This section presents
3741the basic steps you need to build a simple image using BitBake from a
3742build host running Linux.
3743
3744.. note::
3745
3746 - For information on how to build an image using
3747 :term:`Toaster`, see the
3748 :doc:`../toaster-manual/toaster-manual`.
3749
3750 - For information on how to use ``devtool`` to build images, see the
3751 ":ref:`sdk-manual/sdk-extensible:using \`\`devtool\`\` in your sdk workflow`"
3752 section in the Yocto Project Application Development and the
3753 Extensible Software Development Kit (eSDK) manual.
3754
3755 - For a quick example on how to build an image using the
3756 OpenEmbedded build system, see the
3757 :doc:`../brief-yoctoprojectqs/brief-yoctoprojectqs` document.
3758
3759The build process creates an entire Linux distribution from source and
3760places it in your :term:`Build Directory` under
3761``tmp/deploy/images``. For detailed information on the build process
3762using BitBake, see the ":ref:`images-dev-environment`" section in the
3763Yocto Project Overview and Concepts Manual.
3764
3765The following figure and list overviews the build process:
3766
3767.. image:: figures/bitbake-build-flow.png
3768 :align: center
3769
37701. *Set up Your Host Development System to Support Development Using the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003771 Yocto Project*: See the ":doc:`dev-manual-start`" section for options on how to get a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003772 build host ready to use the Yocto Project.
3773
37742. *Initialize the Build Environment:* Initialize the build environment
3775 by sourcing the build environment script (i.e.
3776 :ref:`structure-core-script`):
3777 ::
3778
3779 $ source oe-init-build-env [build_dir]
3780
3781 When you use the initialization script, the OpenEmbedded build system
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003782 uses ``build`` as the default :term:`Build Directory` in your current work
3783 directory. You can use a `build_dir` argument with the script to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003784 specify a different build directory.
3785
3786 .. note::
3787
3788 A common practice is to use a different Build Directory for
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003789 different targets. For example, ``~/build/x86`` for a ``qemux86``
3790 target, and ``~/build/arm`` for a ``qemuarm`` target.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003791
Andrew Geissler4c19ea12020-10-27 13:52:24 -050037923. *Make Sure Your* ``local.conf`` *File is Correct*: Ensure the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003793 ``conf/local.conf`` configuration file, which is found in the Build
3794 Directory, is set up how you want it. This file defines many aspects
3795 of the build environment including the target machine architecture
3796 through the ``MACHINE`` variable, the packaging format used during
3797 the build
3798 (:term:`PACKAGE_CLASSES`),
3799 and a centralized tarball download directory through the
3800 :term:`DL_DIR` variable.
3801
38024. *Build the Image:* Build the image using the ``bitbake`` command:
3803 ::
3804
3805 $ bitbake target
3806
3807 .. note::
3808
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003809 For information on BitBake, see the :doc:`bitbake:index`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003810
3811 The target is the name of the recipe you want to build. Common
3812 targets are the images in ``meta/recipes-core/images``,
3813 ``meta/recipes-sato/images``, and so forth all found in the
3814 :term:`Source Directory`. Or, the target
3815 can be the name of a recipe for a specific piece of software such as
3816 BusyBox. For more details about the images the OpenEmbedded build
3817 system supports, see the
3818 ":ref:`ref-manual/ref-images:Images`" chapter in the Yocto
3819 Project Reference Manual.
3820
3821 As an example, the following command builds the
3822 ``core-image-minimal`` image:
3823 ::
3824
3825 $ bitbake core-image-minimal
3826
3827 Once an
3828 image has been built, it often needs to be installed. The images and
3829 kernels built by the OpenEmbedded build system are placed in the
3830 Build Directory in ``tmp/deploy/images``. For information on how to
3831 run pre-built images such as ``qemux86`` and ``qemuarm``, see the
3832 :doc:`../sdk-manual/sdk-manual` manual. For
3833 information about how to install these images, see the documentation
3834 for your particular board or machine.
3835
3836.. _dev-building-images-for-multiple-targets-using-multiple-configurations:
3837
3838Building Images for Multiple Targets Using Multiple Configurations
3839------------------------------------------------------------------
3840
3841You can use a single ``bitbake`` command to build multiple images or
3842packages for different targets where each image or package requires a
3843different configuration (multiple configuration builds). The builds, in
3844this scenario, are sometimes referred to as "multiconfigs", and this
3845section uses that term throughout.
3846
3847This section describes how to set up for multiple configuration builds
3848and how to account for cross-build dependencies between the
3849multiconfigs.
3850
3851.. _dev-setting-up-and-running-a-multiple-configuration-build:
3852
3853Setting Up and Running a Multiple Configuration Build
3854~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3855
3856To accomplish a multiple configuration build, you must define each
3857target's configuration separately using a parallel configuration file in
3858the :term:`Build Directory`, and you
3859must follow a required file hierarchy. Additionally, you must enable the
3860multiple configuration builds in your ``local.conf`` file.
3861
3862Follow these steps to set up and execute multiple configuration builds:
3863
3864- *Create Separate Configuration Files*: You need to create a single
3865 configuration file for each build target (each multiconfig).
3866 Minimally, each configuration file must define the machine and the
3867 temporary directory BitBake uses for the build. Suggested practice
3868 dictates that you do not overlap the temporary directories used
3869 during the builds. However, it is possible that you can share the
3870 temporary directory
3871 (:term:`TMPDIR`). For example,
3872 consider a scenario with two different multiconfigs for the same
3873 :term:`MACHINE`: "qemux86" built
3874 for two distributions such as "poky" and "poky-lsb". In this case,
3875 you might want to use the same ``TMPDIR``.
3876
3877 Here is an example showing the minimal statements needed in a
3878 configuration file for a "qemux86" target whose temporary build
3879 directory is ``tmpmultix86``:
3880 ::
3881
3882 MACHINE = "qemux86"
3883 TMPDIR = "${TOPDIR}/tmpmultix86"
3884
3885 The location for these multiconfig configuration files is specific.
3886 They must reside in the current build directory in a sub-directory of
3887 ``conf`` named ``multiconfig``. Following is an example that defines
3888 two configuration files for the "x86" and "arm" multiconfigs:
3889
3890 .. image:: figures/multiconfig_files.png
3891 :align: center
3892
3893 The reason for this required file hierarchy is because the ``BBPATH``
3894 variable is not constructed until the layers are parsed.
3895 Consequently, using the configuration file as a pre-configuration
3896 file is not possible unless it is located in the current working
3897 directory.
3898
3899- *Add the BitBake Multi-configuration Variable to the Local
3900 Configuration File*: Use the
3901 :term:`BBMULTICONFIG`
3902 variable in your ``conf/local.conf`` configuration file to specify
3903 each multiconfig. Continuing with the example from the previous
3904 figure, the ``BBMULTICONFIG`` variable needs to enable two
3905 multiconfigs: "x86" and "arm" by specifying each configuration file:
3906 ::
3907
3908 BBMULTICONFIG = "x86 arm"
3909
3910 .. note::
3911
3912 A "default" configuration already exists by definition. This
3913 configuration is named: "" (i.e. empty string) and is defined by
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003914 the variables coming from your ``local.conf``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003915 file. Consequently, the previous example actually adds two
3916 additional configurations to your build: "arm" and "x86" along
3917 with "".
3918
3919- *Launch BitBake*: Use the following BitBake command form to launch
3920 the multiple configuration build:
3921 ::
3922
3923 $ bitbake [mc:multiconfigname:]target [[[mc:multiconfigname:]target] ... ]
3924
3925 For the example in this section, the following command applies:
3926 ::
3927
3928 $ bitbake mc:x86:core-image-minimal mc:arm:core-image-sato mc::core-image-base
3929
3930 The previous BitBake command builds a ``core-image-minimal`` image
3931 that is configured through the ``x86.conf`` configuration file, a
3932 ``core-image-sato`` image that is configured through the ``arm.conf``
3933 configuration file and a ``core-image-base`` that is configured
3934 through your ``local.conf`` configuration file.
3935
3936.. note::
3937
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003938 Support for multiple configuration builds in the Yocto Project &DISTRO;
3939 (&DISTRO_NAME;) Release does not include Shared State (sstate)
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003940 optimizations. Consequently, if a build uses the same object twice
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003941 in, for example, two different ``TMPDIR``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003942 directories, the build either loads from an existing sstate cache for
3943 that build at the start or builds the object fresh.
3944
3945.. _dev-enabling-multiple-configuration-build-dependencies:
3946
3947Enabling Multiple Configuration Build Dependencies
3948~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3949
3950Sometimes dependencies can exist between targets (multiconfigs) in a
3951multiple configuration build. For example, suppose that in order to
3952build a ``core-image-sato`` image for an "x86" multiconfig, the root
3953filesystem of an "arm" multiconfig must exist. This dependency is
3954essentially that the
3955:ref:`ref-tasks-image` task in the
3956``core-image-sato`` recipe depends on the completion of the
3957:ref:`ref-tasks-rootfs` task of the
3958``core-image-minimal`` recipe.
3959
3960To enable dependencies in a multiple configuration build, you must
3961declare the dependencies in the recipe using the following statement
3962form:
3963::
3964
3965 task_or_package[mcdepends] = "mc:from_multiconfig:to_multiconfig:recipe_name:task_on_which_to_depend"
3966
3967To better show how to use this statement, consider the example scenario
3968from the first paragraph of this section. The following statement needs
3969to be added to the recipe that builds the ``core-image-sato`` image:
3970::
3971
3972 do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_rootfs"
3973
Andrew Geissler4c19ea12020-10-27 13:52:24 -05003974In this example, the `from_multiconfig` is "x86". The `to_multiconfig` is "arm". The
Andrew Geisslerc9f78652020-09-18 14:11:35 -05003975task on which the ``do_image`` task in the recipe depends is the
3976``do_rootfs`` task from the ``core-image-minimal`` recipe associated
3977with the "arm" multiconfig.
3978
3979Once you set up this dependency, you can build the "x86" multiconfig
3980using a BitBake command as follows:
3981::
3982
3983 $ bitbake mc:x86:core-image-sato
3984
3985This command executes all the tasks needed to create the
3986``core-image-sato`` image for the "x86" multiconfig. Because of the
3987dependency, BitBake also executes through the ``do_rootfs`` task for the
3988"arm" multiconfig build.
3989
3990Having a recipe depend on the root filesystem of another build might not
3991seem that useful. Consider this change to the statement in the
3992``core-image-sato`` recipe:
3993::
3994
3995 do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_image"
3996
3997In this case, BitBake must
3998create the ``core-image-minimal`` image for the "arm" build since the
3999"x86" build depends on it.
4000
4001Because "x86" and "arm" are enabled for multiple configuration builds
4002and have separate configuration files, BitBake places the artifacts for
4003each build in the respective temporary build directories (i.e.
4004:term:`TMPDIR`).
4005
4006.. _building-an-initramfs-image:
4007
4008Building an Initial RAM Filesystem (initramfs) Image
4009----------------------------------------------------
4010
4011An initial RAM filesystem (initramfs) image provides a temporary root
4012filesystem used for early system initialization (e.g. loading of modules
4013needed to locate and mount the "real" root filesystem).
4014
4015.. note::
4016
4017 The initramfs image is the successor of initial RAM disk (initrd). It
4018 is a "copy in and out" (cpio) archive of the initial filesystem that
4019 gets loaded into memory during the Linux startup process. Because
4020 Linux uses the contents of the archive during initialization, the
4021 initramfs image needs to contain all of the device drivers and tools
4022 needed to mount the final root filesystem.
4023
4024Follow these steps to create an initramfs image:
4025
40261. *Create the initramfs Image Recipe:* You can reference the
4027 ``core-image-minimal-initramfs.bb`` recipe found in the
4028 ``meta/recipes-core`` directory of the :term:`Source Directory`
4029 as an example
4030 from which to work.
4031
40322. *Decide if You Need to Bundle the initramfs Image Into the Kernel
4033 Image:* If you want the initramfs image that is built to be bundled
4034 in with the kernel image, set the
4035 :term:`INITRAMFS_IMAGE_BUNDLE`
4036 variable to "1" in your ``local.conf`` configuration file and set the
4037 :term:`INITRAMFS_IMAGE`
4038 variable in the recipe that builds the kernel image.
4039
4040 .. note::
4041
4042 It is recommended that you do bundle the initramfs image with the
4043 kernel image to avoid circular dependencies between the kernel
4044 recipe and the initramfs recipe should the initramfs image include
4045 kernel modules.
4046
4047 Setting the ``INITRAMFS_IMAGE_BUNDLE`` flag causes the initramfs
4048 image to be unpacked into the ``${B}/usr/`` directory. The unpacked
4049 initramfs image is then passed to the kernel's ``Makefile`` using the
4050 :term:`CONFIG_INITRAMFS_SOURCE`
4051 variable, allowing the initramfs image to be built into the kernel
4052 normally.
4053
4054 .. note::
4055
4056 If you choose to not bundle the initramfs image with the kernel
4057 image, you are essentially using an
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004058 `Initial RAM Disk (initrd) <https://en.wikipedia.org/wiki/Initrd>`__.
4059 Creating an initrd is handled primarily through the :term:`INITRD_IMAGE`,
4060 ``INITRD_LIVE``, and ``INITRD_IMAGE_LIVE`` variables. For more
4061 information, see the :ref:`ref-classes-image-live` file.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004062
40633. *Optionally Add Items to the initramfs Image Through the initramfs
4064 Image Recipe:* If you add items to the initramfs image by way of its
4065 recipe, you should use
4066 :term:`PACKAGE_INSTALL`
4067 rather than
4068 :term:`IMAGE_INSTALL`.
4069 ``PACKAGE_INSTALL`` gives more direct control of what is added to the
4070 image as compared to the defaults you might not necessarily want that
4071 are set by the :ref:`image <ref-classes-image>`
4072 or :ref:`core-image <ref-classes-core-image>`
4073 classes.
4074
40754. *Build the Kernel Image and the initramfs Image:* Build your kernel
4076 image using BitBake. Because the initramfs image recipe is a
4077 dependency of the kernel image, the initramfs image is built as well
4078 and bundled with the kernel image if you used the
4079 :term:`INITRAMFS_IMAGE_BUNDLE`
4080 variable described earlier.
4081
4082Building a Tiny System
4083----------------------
4084
4085Very small distributions have some significant advantages such as
4086requiring less on-die or in-package memory (cheaper), better performance
4087through efficient cache usage, lower power requirements due to less
4088memory, faster boot times, and reduced development overhead. Some
4089real-world examples where a very small distribution gives you distinct
4090advantages are digital cameras, medical devices, and small headless
4091systems.
4092
4093This section presents information that shows you how you can trim your
4094distribution to even smaller sizes than the ``poky-tiny`` distribution,
4095which is around 5 Mbytes, that can be built out-of-the-box using the
4096Yocto Project.
4097
4098.. _tiny-system-overview:
4099
4100Tiny System Overview
4101~~~~~~~~~~~~~~~~~~~~
4102
4103The following list presents the overall steps you need to consider and
4104perform to create distributions with smaller root filesystems, achieve
4105faster boot times, maintain your critical functionality, and avoid
4106initial RAM disks:
4107
4108- `Determine your goals and guiding
4109 principles. <#goals-and-guiding-principles>`__
4110
4111- `Understand what contributes to your image
4112 size. <#understand-what-gives-your-image-size>`__
4113
4114- `Reduce the size of the root
4115 filesystem. <#trim-the-root-filesystem>`__
4116
4117- `Reduce the size of the kernel. <#trim-the-kernel>`__
4118
4119- `Eliminate packaging
4120 requirements. <#remove-package-management-requirements>`__
4121
4122- `Look for other ways to minimize
4123 size. <#look-for-other-ways-to-minimize-size>`__
4124
4125- `Iterate on the process. <#iterate-on-the-process>`__
4126
4127Goals and Guiding Principles
4128~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4129
4130Before you can reach your destination, you need to know where you are
4131going. Here is an example list that you can use as a guide when creating
4132very small distributions:
4133
4134- Determine how much space you need (e.g. a kernel that is 1 Mbyte or
4135 less and a root filesystem that is 3 Mbytes or less).
4136
4137- Find the areas that are currently taking 90% of the space and
4138 concentrate on reducing those areas.
4139
4140- Do not create any difficult "hacks" to achieve your goals.
4141
4142- Leverage the device-specific options.
4143
4144- Work in a separate layer so that you keep changes isolated. For
4145 information on how to create layers, see the "`Understanding and
4146 Creating Layers <#understanding-and-creating-layers>`__" section.
4147
4148.. _understand-what-gives-your-image-size:
4149
4150Understand What Contributes to Your Image Size
4151~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4152
4153It is easiest to have something to start with when creating your own
4154distribution. You can use the Yocto Project out-of-the-box to create the
4155``poky-tiny`` distribution. Ultimately, you will want to make changes in
4156your own distribution that are likely modeled after ``poky-tiny``.
4157
4158.. note::
4159
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004160 To use ``poky-tiny`` in your build, set the ``DISTRO`` variable in your
4161 ``local.conf`` file to "poky-tiny" as described in the
4162 ":ref:`dev-manual/dev-manual-common-tasks:creating your own distribution`"
4163 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004164
4165Understanding some memory concepts will help you reduce the system size.
4166Memory consists of static, dynamic, and temporary memory. Static memory
4167is the TEXT (code), DATA (initialized data in the code), and BSS
4168(uninitialized data) sections. Dynamic memory represents memory that is
4169allocated at runtime: stacks, hash tables, and so forth. Temporary
4170memory is recovered after the boot process. This memory consists of
4171memory used for decompressing the kernel and for the ``__init__``
4172functions.
4173
4174To help you see where you currently are with kernel and root filesystem
4175sizes, you can use two tools found in the :term:`Source Directory`
4176in the
4177``scripts/tiny/`` directory:
4178
4179- ``ksize.py``: Reports component sizes for the kernel build objects.
4180
4181- ``dirsize.py``: Reports component sizes for the root filesystem.
4182
4183This next tool and command help you organize configuration fragments and
4184view file dependencies in a human-readable form:
4185
4186- ``merge_config.sh``: Helps you manage configuration files and
4187 fragments within the kernel. With this tool, you can merge individual
4188 configuration fragments together. The tool allows you to make
4189 overrides and warns you of any missing configuration options. The
4190 tool is ideal for allowing you to iterate on configurations, create
4191 minimal configurations, and create configuration files for different
4192 machines without having to duplicate your process.
4193
4194 The ``merge_config.sh`` script is part of the Linux Yocto kernel Git
4195 repositories (i.e. ``linux-yocto-3.14``, ``linux-yocto-3.10``,
4196 ``linux-yocto-3.8``, and so forth) in the ``scripts/kconfig``
4197 directory.
4198
4199 For more information on configuration fragments, see the
Andrew Geissler6ce62a22020-11-30 19:58:47 -06004200 ":ref:`kernel-dev/kernel-dev-common:creating configuration fragments`"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004201 section in the Yocto Project Linux Kernel Development Manual.
4202
4203- ``bitbake -u taskexp -g bitbake_target``: Using the BitBake command
4204 with these options brings up a Dependency Explorer from which you can
4205 view file dependencies. Understanding these dependencies allows you
4206 to make informed decisions when cutting out various pieces of the
4207 kernel and root filesystem.
4208
4209Trim the Root Filesystem
4210~~~~~~~~~~~~~~~~~~~~~~~~
4211
4212The root filesystem is made up of packages for booting, libraries, and
4213applications. To change things, you can configure how the packaging
4214happens, which changes the way you build them. You can also modify the
4215filesystem itself or select a different filesystem.
4216
4217First, find out what is hogging your root filesystem by running the
4218``dirsize.py`` script from your root directory:
4219::
4220
4221 $ cd root-directory-of-image
4222 $ dirsize.py 100000 > dirsize-100k.log
4223 $ cat dirsize-100k.log
4224
4225You can apply a filter to the script to ignore files
4226under a certain size. The previous example filters out any files below
4227100 Kbytes. The sizes reported by the tool are uncompressed, and thus
4228will be smaller by a relatively constant factor in a compressed root
4229filesystem. When you examine your log file, you can focus on areas of
4230the root filesystem that take up large amounts of memory.
4231
4232You need to be sure that what you eliminate does not cripple the
4233functionality you need. One way to see how packages relate to each other
4234is by using the Dependency Explorer UI with the BitBake command:
4235::
4236
4237 $ cd image-directory
4238 $ bitbake -u taskexp -g image
4239
4240Use the interface to
4241select potential packages you wish to eliminate and see their dependency
4242relationships.
4243
4244When deciding how to reduce the size, get rid of packages that result in
4245minimal impact on the feature set. For example, you might not need a VGA
4246display. Or, you might be able to get by with ``devtmpfs`` and ``mdev``
4247instead of ``udev``.
4248
4249Use your ``local.conf`` file to make changes. For example, to eliminate
4250``udev`` and ``glib``, set the following in the local configuration
4251file:
4252::
4253
4254 VIRTUAL-RUNTIME_dev_manager = ""
4255
4256Finally, you should consider exactly the type of root filesystem you
4257need to meet your needs while also reducing its size. For example,
4258consider ``cramfs``, ``squashfs``, ``ubifs``, ``ext2``, or an
4259``initramfs`` using ``initramfs``. Be aware that ``ext3`` requires a 1
4260Mbyte journal. If you are okay with running read-only, you do not need
4261this journal.
4262
4263.. note::
4264
4265 After each round of elimination, you need to rebuild your system and
4266 then use the tools to see the effects of your reductions.
4267
4268Trim the Kernel
4269~~~~~~~~~~~~~~~
4270
4271The kernel is built by including policies for hardware-independent
4272aspects. What subsystems do you enable? For what architecture are you
4273building? Which drivers do you build by default?
4274
4275.. note::
4276
4277 You can modify the kernel source if you want to help with boot time.
4278
4279Run the ``ksize.py`` script from the top-level Linux build directory to
4280get an idea of what is making up the kernel:
4281::
4282
4283 $ cd top-level-linux-build-directory
4284 $ ksize.py > ksize.log
4285 $ cat ksize.log
4286
4287When you examine the log, you will see how much space is taken up with
4288the built-in ``.o`` files for drivers, networking, core kernel files,
4289filesystem, sound, and so forth. The sizes reported by the tool are
4290uncompressed, and thus will be smaller by a relatively constant factor
4291in a compressed kernel image. Look to reduce the areas that are large
4292and taking up around the "90% rule."
4293
4294To examine, or drill down, into any particular area, use the ``-d``
4295option with the script:
4296::
4297
4298 $ ksize.py -d > ksize.log
4299
4300Using this option
4301breaks out the individual file information for each area of the kernel
4302(e.g. drivers, networking, and so forth).
4303
4304Use your log file to see what you can eliminate from the kernel based on
4305features you can let go. For example, if you are not going to need
4306sound, you do not need any drivers that support sound.
4307
4308After figuring out what to eliminate, you need to reconfigure the kernel
4309to reflect those changes during the next build. You could run
4310``menuconfig`` and make all your changes at once. However, that makes it
4311difficult to see the effects of your individual eliminations and also
4312makes it difficult to replicate the changes for perhaps another target
4313device. A better method is to start with no configurations using
4314``allnoconfig``, create configuration fragments for individual changes,
4315and then manage the fragments into a single configuration file using
4316``merge_config.sh``. The tool makes it easy for you to iterate using the
4317configuration change and build cycle.
4318
4319Each time you make configuration changes, you need to rebuild the kernel
4320and check to see what impact your changes had on the overall size.
4321
4322Remove Package Management Requirements
4323~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4324
4325Packaging requirements add size to the image. One way to reduce the size
4326of the image is to remove all the packaging requirements from the image.
4327This reduction includes both removing the package manager and its unique
4328dependencies as well as removing the package management data itself.
4329
4330To eliminate all the packaging requirements for an image, be sure that
4331"package-management" is not part of your
4332:term:`IMAGE_FEATURES`
4333statement for the image. When you remove this feature, you are removing
4334the package manager as well as its dependencies from the root
4335filesystem.
4336
4337Look for Other Ways to Minimize Size
4338~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4339
4340Depending on your particular circumstances, other areas that you can
4341trim likely exist. The key to finding these areas is through tools and
4342methods described here combined with experimentation and iteration. Here
4343are a couple of areas to experiment with:
4344
4345- ``glibc``: In general, follow this process:
4346
4347 1. Remove ``glibc`` features from
4348 :term:`DISTRO_FEATURES`
4349 that you think you do not need.
4350
4351 2. Build your distribution.
4352
4353 3. If the build fails due to missing symbols in a package, determine
4354 if you can reconfigure the package to not need those features. For
4355 example, change the configuration to not support wide character
4356 support as is done for ``ncurses``. Or, if support for those
4357 characters is needed, determine what ``glibc`` features provide
4358 the support and restore the configuration.
4359
4360 4. Rebuild and repeat the process.
4361
4362- ``busybox``: For BusyBox, use a process similar as described for
4363 ``glibc``. A difference is you will need to boot the resulting system
4364 to see if you are able to do everything you expect from the running
4365 system. You need to be sure to integrate configuration fragments into
4366 Busybox because BusyBox handles its own core features and then allows
4367 you to add configuration fragments on top.
4368
4369Iterate on the Process
4370~~~~~~~~~~~~~~~~~~~~~~
4371
4372If you have not reached your goals on system size, you need to iterate
4373on the process. The process is the same. Use the tools and see just what
4374is taking up 90% of the root filesystem and the kernel. Decide what you
4375can eliminate without limiting your device beyond what you need.
4376
4377Depending on your system, a good place to look might be Busybox, which
4378provides a stripped down version of Unix tools in a single, executable
4379file. You might be able to drop virtual terminal services or perhaps
4380ipv6.
4381
4382Building Images for More than One Machine
4383-----------------------------------------
4384
4385A common scenario developers face is creating images for several
4386different machines that use the same software environment. In this
4387situation, it is tempting to set the tunings and optimization flags for
4388each build specifically for the targeted hardware (i.e. "maxing out" the
4389tunings). Doing so can considerably add to build times and package feed
4390maintenance collectively for the machines. For example, selecting tunes
4391that are extremely specific to a CPU core used in a system might enable
4392some micro optimizations in GCC for that particular system but would
4393otherwise not gain you much of a performance difference across the other
4394systems as compared to using a more general tuning across all the builds
4395(e.g. setting :term:`DEFAULTTUNE`
4396specifically for each machine's build). Rather than "max out" each
4397build's tunings, you can take steps that cause the OpenEmbedded build
4398system to reuse software across the various machines where it makes
4399sense.
4400
4401If build speed and package feed maintenance are considerations, you
4402should consider the points in this section that can help you optimize
4403your tunings to best consider build times and package feed maintenance.
4404
4405- *Share the Build Directory:* If at all possible, share the
4406 :term:`TMPDIR` across builds. The
4407 Yocto Project supports switching between different
4408 :term:`MACHINE` values in the same
4409 ``TMPDIR``. This practice is well supported and regularly used by
4410 developers when building for multiple machines. When you use the same
4411 ``TMPDIR`` for multiple machine builds, the OpenEmbedded build system
4412 can reuse the existing native and often cross-recipes for multiple
4413 machines. Thus, build time decreases.
4414
4415 .. note::
4416
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004417 If :term:`DISTRO` settings change or fundamental configuration settings
4418 such as the filesystem layout, you need to work with a clean ``TMPDIR``.
4419 Sharing ``TMPDIR`` under these circumstances might work but since it is
4420 not guaranteed, you should use a clean ``TMPDIR``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004421
4422- *Enable the Appropriate Package Architecture:* By default, the
4423 OpenEmbedded build system enables three levels of package
4424 architectures: "all", "tune" or "package", and "machine". Any given
4425 recipe usually selects one of these package architectures (types) for
4426 its output. Depending for what a given recipe creates packages,
4427 making sure you enable the appropriate package architecture can
4428 directly impact the build time.
4429
4430 A recipe that just generates scripts can enable "all" architecture
4431 because there are no binaries to build. To specifically enable "all"
4432 architecture, be sure your recipe inherits the
4433 :ref:`allarch <ref-classes-allarch>` class.
4434 This class is useful for "all" architectures because it configures
4435 many variables so packages can be used across multiple architectures.
4436
4437 If your recipe needs to generate packages that are machine-specific
4438 or when one of the build or runtime dependencies is already
4439 machine-architecture dependent, which makes your recipe also
4440 machine-architecture dependent, make sure your recipe enables the
4441 "machine" package architecture through the
4442 :term:`MACHINE_ARCH`
4443 variable:
4444 ::
4445
4446 PACKAGE_ARCH = "${MACHINE_ARCH}"
4447
4448 When you do not
4449 specifically enable a package architecture through the
4450 :term:`PACKAGE_ARCH`, The
4451 OpenEmbedded build system defaults to the
4452 :term:`TUNE_PKGARCH` setting:
4453 ::
4454
4455 PACKAGE_ARCH = "${TUNE_PKGARCH}"
4456
4457- *Choose a Generic Tuning File if Possible:* Some tunes are more
4458 generic and can run on multiple targets (e.g. an ``armv5`` set of
4459 packages could run on ``armv6`` and ``armv7`` processors in most
4460 cases). Similarly, ``i486`` binaries could work on ``i586`` and
4461 higher processors. You should realize, however, that advances on
4462 newer processor versions would not be used.
4463
4464 If you select the same tune for several different machines, the
4465 OpenEmbedded build system reuses software previously built, thus
4466 speeding up the overall build time. Realize that even though a new
4467 sysroot for each machine is generated, the software is not recompiled
4468 and only one package feed exists.
4469
4470- *Manage Granular Level Packaging:* Sometimes cases exist where
4471 injecting another level of package architecture beyond the three
4472 higher levels noted earlier can be useful. For example, consider how
4473 NXP (formerly Freescale) allows for the easy reuse of binary packages
4474 in their layer
4475 :yocto_git:`meta-freescale </cgit/cgit.cgi/meta-freescale/>`.
4476 In this example, the
4477 :yocto_git:`fsl-dynamic-packagearch </cgit/cgit.cgi/meta-freescale/tree/classes/fsl-dynamic-packagearch.bbclass>`
4478 class shares GPU packages for i.MX53 boards because all boards share
4479 the AMD GPU. The i.MX6-based boards can do the same because all
4480 boards share the Vivante GPU. This class inspects the BitBake
4481 datastore to identify if the package provides or depends on one of
4482 the sub-architecture values. If so, the class sets the
4483 :term:`PACKAGE_ARCH` value
4484 based on the ``MACHINE_SUBARCH`` value. If the package does not
4485 provide or depend on one of the sub-architecture values but it
4486 matches a value in the machine-specific filter, it sets
4487 :term:`MACHINE_ARCH`. This
4488 behavior reduces the number of packages built and saves build time by
4489 reusing binaries.
4490
4491- *Use Tools to Debug Issues:* Sometimes you can run into situations
4492 where software is being rebuilt when you think it should not be. For
4493 example, the OpenEmbedded build system might not be using shared
4494 state between machines when you think it should be. These types of
4495 situations are usually due to references to machine-specific
4496 variables such as :term:`MACHINE`,
4497 :term:`SERIAL_CONSOLES`,
4498 :term:`XSERVER`,
4499 :term:`MACHINE_FEATURES`,
4500 and so forth in code that is supposed to only be tune-specific or
4501 when the recipe depends
4502 (:term:`DEPENDS`,
4503 :term:`RDEPENDS`,
4504 :term:`RRECOMMENDS`,
4505 :term:`RSUGGESTS`, and so forth)
4506 on some other recipe that already has
4507 :term:`PACKAGE_ARCH` defined
4508 as "${MACHINE_ARCH}".
4509
4510 .. note::
4511
4512 Patches to fix any issues identified are most welcome as these
4513 issues occasionally do occur.
4514
4515 For such cases, you can use some tools to help you sort out the
4516 situation:
4517
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004518 - ``state-diff-machines.sh``*:* You can find this tool in the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004519 ``scripts`` directory of the Source Repositories. See the comments
4520 in the script for information on how to use the tool.
4521
4522 - *BitBake's "-S printdiff" Option:* Using this option causes
4523 BitBake to try to establish the closest signature match it can
4524 (e.g. in the shared state cache) and then run ``bitbake-diffsigs``
4525 over the matches to determine the stamps and delta where these two
4526 stamp trees diverge.
4527
4528Building Software from an External Source
4529-----------------------------------------
4530
4531By default, the OpenEmbedded build system uses the
4532:term:`Build Directory` when building source
4533code. The build process involves fetching the source files, unpacking
4534them, and then patching them if necessary before the build takes place.
4535
4536Situations exist where you might want to build software from source
4537files that are external to and thus outside of the OpenEmbedded build
4538system. For example, suppose you have a project that includes a new BSP
4539with a heavily customized kernel. And, you want to minimize exposing the
4540build system to the development team so that they can focus on their
4541project and maintain everyone's workflow as much as possible. In this
4542case, you want a kernel source directory on the development machine
4543where the development occurs. You want the recipe's
4544:term:`SRC_URI` variable to point to
4545the external directory and use it as is, not copy it.
4546
4547To build from software that comes from an external source, all you need
4548to do is inherit the
4549:ref:`externalsrc <ref-classes-externalsrc>` class
4550and then set the
4551:term:`EXTERNALSRC` variable to
4552point to your external source code. Here are the statements to put in
4553your ``local.conf`` file:
4554::
4555
4556 INHERIT += "externalsrc"
4557 EXTERNALSRC_pn-myrecipe = "path-to-your-source-tree"
4558
4559This next example shows how to accomplish the same thing by setting
4560``EXTERNALSRC`` in the recipe itself or in the recipe's append file:
4561::
4562
4563 EXTERNALSRC = "path"
4564 EXTERNALSRC_BUILD = "path"
4565
4566.. note::
4567
4568 In order for these settings to take effect, you must globally or
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004569 locally inherit the :ref:`externalsrc <ref-classes-externalsrc>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004570 class.
4571
4572By default, ``externalsrc.bbclass`` builds the source code in a
4573directory separate from the external source directory as specified by
4574:term:`EXTERNALSRC`. If you need
4575to have the source built in the same directory in which it resides, or
4576some other nominated directory, you can set
4577:term:`EXTERNALSRC_BUILD`
4578to point to that directory:
4579::
4580
4581 EXTERNALSRC_BUILD_pn-myrecipe = "path-to-your-source-tree"
4582
4583Replicating a Build Offline
4584---------------------------
4585
4586It can be useful to take a "snapshot" of upstream sources used in a
4587build and then use that "snapshot" later to replicate the build offline.
4588To do so, you need to first prepare and populate your downloads
4589directory your "snapshot" of files. Once your downloads directory is
4590ready, you can use it at any time and from any machine to replicate your
4591build.
4592
4593Follow these steps to populate your Downloads directory:
4594
45951. *Create a Clean Downloads Directory:* Start with an empty downloads
4596 directory (:term:`DL_DIR`). You
4597 start with an empty downloads directory by either removing the files
4598 in the existing directory or by setting ``DL_DIR`` to point to either
4599 an empty location or one that does not yet exist.
4600
46012. *Generate Tarballs of the Source Git Repositories:* Edit your
4602 ``local.conf`` configuration file as follows:
4603 ::
4604
4605 DL_DIR = "/home/your-download-dir/"
4606 BB_GENERATE_MIRROR_TARBALLS = "1"
4607
4608 During
4609 the fetch process in the next step, BitBake gathers the source files
4610 and creates tarballs in the directory pointed to by ``DL_DIR``. See
4611 the
4612 :term:`BB_GENERATE_MIRROR_TARBALLS`
4613 variable for more information.
4614
46153. *Populate Your Downloads Directory Without Building:* Use BitBake to
4616 fetch your sources but inhibit the build:
4617 ::
4618
4619 $ bitbake target --runonly=fetch
4620
4621 The downloads directory (i.e. ``${DL_DIR}``) now has
4622 a "snapshot" of the source files in the form of tarballs, which can
4623 be used for the build.
4624
46254. *Optionally Remove Any Git or other SCM Subdirectories From the
4626 Downloads Directory:* If you want, you can clean up your downloads
4627 directory by removing any Git or other Source Control Management
4628 (SCM) subdirectories such as ``${DL_DIR}/git2/*``. The tarballs
4629 already contain these subdirectories.
4630
4631Once your downloads directory has everything it needs regarding source
4632files, you can create your "own-mirror" and build your target.
4633Understand that you can use the files to build the target offline from
4634any machine and at any time.
4635
4636Follow these steps to build your target using the files in the downloads
4637directory:
4638
46391. *Using Local Files Only:* Inside your ``local.conf`` file, add the
4640 :term:`SOURCE_MIRROR_URL`
4641 variable, inherit the
4642 :ref:`own-mirrors <ref-classes-own-mirrors>`
4643 class, and use the
4644 :term:`bitbake:BB_NO_NETWORK`
4645 variable to your ``local.conf``.
4646 ::
4647
4648 SOURCE_MIRROR_URL ?= "file:///home/your-download-dir/"
4649 INHERIT += "own-mirrors"
4650 BB_NO_NETWORK = "1"
4651
4652 The ``SOURCE_MIRROR_URL`` and ``own-mirror``
4653 class set up the system to use the downloads directory as your "own
4654 mirror". Using the ``BB_NO_NETWORK`` variable makes sure that
4655 BitBake's fetching process in step 3 stays local, which means files
4656 from your "own-mirror" are used.
4657
46582. *Start With a Clean Build:* You can start with a clean build by
4659 removing the
4660 ``${``\ :term:`TMPDIR`\ ``}``
4661 directory or using a new :term:`Build Directory`.
4662
46633. *Build Your Target:* Use BitBake to build your target:
4664 ::
4665
4666 $ bitbake target
4667
4668 The build completes using the known local "snapshot" of source
4669 files from your mirror. The resulting tarballs for your "snapshot" of
4670 source files are in the downloads directory.
4671
4672 .. note::
4673
4674 The offline build does not work if recipes attempt to find the
4675 latest version of software by setting
4676 :term:`SRCREV` to
4677 ``${``\ :term:`AUTOREV`\ ``}``:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004678 ::
4679
4680 SRCREV = "${AUTOREV}"
4681
4682 When a recipe sets ``SRCREV`` to
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004683 ``${AUTOREV}``, the build system accesses the network in an
4684 attempt to determine the latest version of software from the SCM.
4685 Typically, recipes that use ``AUTOREV`` are custom or modified
4686 recipes. Recipes that reside in public repositories usually do not
4687 use ``AUTOREV``.
4688
4689 If you do have recipes that use ``AUTOREV``, you can take steps to
4690 still use the recipes in an offline build. Do the following:
4691
4692 1. Use a configuration generated by enabling `build
4693 history <#maintaining-build-output-quality>`__.
4694
4695 2. Use the ``buildhistory-collect-srcrevs`` command to collect the
4696 stored ``SRCREV`` values from the build's history. For more
4697 information on collecting these values, see the "`Build History
4698 Package Information <#build-history-package-information>`__"
4699 section.
4700
4701 3. Once you have the correct source revisions, you can modify
4702 those recipes to to set ``SRCREV`` to specific versions of the
4703 software.
4704
4705Speeding Up a Build
4706===================
4707
4708Build time can be an issue. By default, the build system uses simple
4709controls to try and maximize build efficiency. In general, the default
4710settings for all the following variables result in the most efficient
4711build times when dealing with single socket systems (i.e. a single CPU).
4712If you have multiple CPUs, you might try increasing the default values
4713to gain more speed. See the descriptions in the glossary for each
4714variable for more information:
4715
4716- :term:`BB_NUMBER_THREADS`:
4717 The maximum number of threads BitBake simultaneously executes.
4718
4719- :term:`bitbake:BB_NUMBER_PARSE_THREADS`:
4720 The number of threads BitBake uses during parsing.
4721
4722- :term:`PARALLEL_MAKE`: Extra
4723 options passed to the ``make`` command during the
4724 :ref:`ref-tasks-compile` task in
4725 order to specify parallel compilation on the local build host.
4726
4727- :term:`PARALLEL_MAKEINST`:
4728 Extra options passed to the ``make`` command during the
4729 :ref:`ref-tasks-install` task in
4730 order to specify parallel installation on the local build host.
4731
4732As mentioned, these variables all scale to the number of processor cores
4733available on the build system. For single socket systems, this
4734auto-scaling ensures that the build system fundamentally takes advantage
4735of potential parallel operations during the build based on the build
4736machine's capabilities.
4737
4738Following are additional factors that can affect build speed:
4739
4740- File system type: The file system type that the build is being
4741 performed on can also influence performance. Using ``ext4`` is
4742 recommended as compared to ``ext2`` and ``ext3`` due to ``ext4``
4743 improved features such as extents.
4744
4745- Disabling the updating of access time using ``noatime``: The
4746 ``noatime`` mount option prevents the build system from updating file
4747 and directory access times.
4748
4749- Setting a longer commit: Using the "commit=" mount option increases
4750 the interval in seconds between disk cache writes. Changing this
4751 interval from the five second default to something longer increases
4752 the risk of data loss but decreases the need to write to the disk,
4753 thus increasing the build performance.
4754
4755- Choosing the packaging backend: Of the available packaging backends,
4756 IPK is the fastest. Additionally, selecting a singular packaging
4757 backend also helps.
4758
4759- Using ``tmpfs`` for :term:`TMPDIR`
4760 as a temporary file system: While this can help speed up the build,
4761 the benefits are limited due to the compiler using ``-pipe``. The
4762 build system goes to some lengths to avoid ``sync()`` calls into the
4763 file system on the principle that if there was a significant failure,
4764 the :term:`Build Directory`
4765 contents could easily be rebuilt.
4766
4767- Inheriting the
4768 :ref:`rm_work <ref-classes-rm-work>` class:
4769 Inheriting this class has shown to speed up builds due to
4770 significantly lower amounts of data stored in the data cache as well
4771 as on disk. Inheriting this class also makes cleanup of
4772 :term:`TMPDIR` faster, at the
4773 expense of being easily able to dive into the source code. File
4774 system maintainers have recommended that the fastest way to clean up
4775 large numbers of files is to reformat partitions rather than delete
4776 files due to the linear nature of partitions. This, of course,
4777 assumes you structure the disk partitions and file systems in a way
4778 that this is practical.
4779
4780Aside from the previous list, you should keep some trade offs in mind
4781that can help you speed up the build:
4782
4783- Remove items from
4784 :term:`DISTRO_FEATURES`
4785 that you might not need.
4786
4787- Exclude debug symbols and other debug information: If you do not need
4788 these symbols and other debug information, disabling the ``*-dbg``
4789 package generation can speed up the build. You can disable this
4790 generation by setting the
4791 :term:`INHIBIT_PACKAGE_DEBUG_SPLIT`
4792 variable to "1".
4793
4794- Disable static library generation for recipes derived from
4795 ``autoconf`` or ``libtool``: Following is an example showing how to
4796 disable static libraries and still provide an override to handle
4797 exceptions:
4798 ::
4799
4800 STATICLIBCONF = "--disable-static"
4801 STATICLIBCONF_sqlite3-native = ""
4802 EXTRA_OECONF += "${STATICLIBCONF}"
4803
4804 .. note::
4805
4806 - Some recipes need static libraries in order to work correctly
4807 (e.g. ``pseudo-native`` needs ``sqlite3-native``). Overrides,
4808 as in the previous example, account for these kinds of
4809 exceptions.
4810
4811 - Some packages have packaging code that assumes the presence of
4812 the static libraries. If so, you might need to exclude them as
4813 well.
4814
4815.. _platdev-working-with-libraries:
4816
4817Working With Libraries
4818======================
4819
4820Libraries are an integral part of your system. This section describes
4821some common practices you might find helpful when working with libraries
4822to build your system:
4823
4824- `How to include static library
4825 files <#including-static-library-files>`__
4826
4827- `How to use the Multilib feature to combine multiple versions of
4828 library files into a single
4829 image <#combining-multiple-versions-library-files-into-one-image>`__
4830
4831- `How to install multiple versions of the same library in parallel on
4832 the same
4833 system <#installing-multiple-versions-of-the-same-library>`__
4834
4835Including Static Library Files
4836------------------------------
4837
4838If you are building a library and the library offers static linking, you
4839can control which static library files (``*.a`` files) get included in
4840the built library.
4841
4842The :term:`PACKAGES` and
4843:term:`FILES_* <FILES>` variables in the
4844``meta/conf/bitbake.conf`` configuration file define how files installed
4845by the ``do_install`` task are packaged. By default, the ``PACKAGES``
4846variable includes ``${PN}-staticdev``, which represents all static
4847library files.
4848
4849.. note::
4850
4851 Some previously released versions of the Yocto Project defined the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004852 static library files through ``${PN}-dev``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004853
4854Following is part of the BitBake configuration file, where you can see
4855how the static library files are defined:
4856::
4857
4858 PACKAGE_BEFORE_PN ?= ""
4859 PACKAGES = "${PN}-dbg ${PN}-staticdev ${PN}-dev ${PN}-doc ${PN}-locale ${PACKAGE_BEFORE_PN} ${PN}"
4860 PACKAGES_DYNAMIC = "^${PN}-locale-.*"
4861 FILES = ""
4862
4863 FILES_${PN} = "${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*${SOLIBS} \
4864 ${sysconfdir} ${sharedstatedir} ${localstatedir} \
4865 ${base_bindir}/* ${base_sbindir}/* \
4866 ${base_libdir}/*${SOLIBS} \
4867 ${base_prefix}/lib/udev/rules.d ${prefix}/lib/udev/rules.d \
4868 ${datadir}/${BPN} ${libdir}/${BPN}/* \
4869 ${datadir}/pixmaps ${datadir}/applications \
4870 ${datadir}/idl ${datadir}/omf ${datadir}/sounds \
4871 ${libdir}/bonobo/servers"
4872
4873 FILES_${PN}-bin = "${bindir}/* ${sbindir}/*"
4874
4875 FILES_${PN}-doc = "${docdir} ${mandir} ${infodir} ${datadir}/gtk-doc \
4876 ${datadir}/gnome/help"
4877 SECTION_${PN}-doc = "doc"
4878
4879 FILES_SOLIBSDEV ?= "${base_libdir}/lib*${SOLIBSDEV} ${libdir}/lib*${SOLIBSDEV}"
4880 FILES_${PN}-dev = "${includedir} ${FILES_SOLIBSDEV} ${libdir}/*.la \
4881 ${libdir}/*.o ${libdir}/pkgconfig ${datadir}/pkgconfig \
4882 ${datadir}/aclocal ${base_libdir}/*.o \
4883 ${libdir}/${BPN}/*.la ${base_libdir}/*.la"
4884 SECTION_${PN}-dev = "devel"
4885 ALLOW_EMPTY_${PN}-dev = "1"
4886 RDEPENDS_${PN}-dev = "${PN} (= ${EXTENDPKGV})"
4887
4888 FILES_${PN}-staticdev = "${libdir}/*.a ${base_libdir}/*.a ${libdir}/${BPN}/*.a"
4889 SECTION_${PN}-staticdev = "devel"
4890 RDEPENDS_${PN}-staticdev = "${PN}-dev (= ${EXTENDPKGV})"
4891
4892.. _combining-multiple-versions-library-files-into-one-image:
4893
4894Combining Multiple Versions of Library Files into One Image
4895-----------------------------------------------------------
4896
4897The build system offers the ability to build libraries with different
4898target optimizations or architecture formats and combine these together
4899into one system image. You can link different binaries in the image
4900against the different libraries as needed for specific use cases. This
Andrew Geissler4c19ea12020-10-27 13:52:24 -05004901feature is called "Multilib".
Andrew Geisslerc9f78652020-09-18 14:11:35 -05004902
4903An example would be where you have most of a system compiled in 32-bit
4904mode using 32-bit libraries, but you have something large, like a
4905database engine, that needs to be a 64-bit application and uses 64-bit
4906libraries. Multilib allows you to get the best of both 32-bit and 64-bit
4907libraries.
4908
4909While the Multilib feature is most commonly used for 32 and 64-bit
4910differences, the approach the build system uses facilitates different
4911target optimizations. You could compile some binaries to use one set of
4912libraries and other binaries to use a different set of libraries. The
4913libraries could differ in architecture, compiler options, or other
4914optimizations.
4915
4916Several examples exist in the ``meta-skeleton`` layer found in the
4917:term:`Source Directory`:
4918
4919- ``conf/multilib-example.conf`` configuration file
4920
4921- ``conf/multilib-example2.conf`` configuration file
4922
4923- ``recipes-multilib/images/core-image-multilib-example.bb`` recipe
4924
4925Preparing to Use Multilib
4926~~~~~~~~~~~~~~~~~~~~~~~~~
4927
4928User-specific requirements drive the Multilib feature. Consequently,
4929there is no one "out-of-the-box" configuration that likely exists to
4930meet your needs.
4931
4932In order to enable Multilib, you first need to ensure your recipe is
4933extended to support multiple libraries. Many standard recipes are
4934already extended and support multiple libraries. You can check in the
4935``meta/conf/multilib.conf`` configuration file in the
4936:term:`Source Directory` to see how this is
4937done using the
4938:term:`BBCLASSEXTEND` variable.
4939Eventually, all recipes will be covered and this list will not be
4940needed.
4941
4942For the most part, the Multilib class extension works automatically to
4943extend the package name from ``${PN}`` to ``${MLPREFIX}${PN}``, where
4944``MLPREFIX`` is the particular multilib (e.g. "lib32-" or "lib64-").
4945Standard variables such as
4946:term:`DEPENDS`,
4947:term:`RDEPENDS`,
4948:term:`RPROVIDES`,
4949:term:`RRECOMMENDS`,
4950:term:`PACKAGES`, and
4951:term:`PACKAGES_DYNAMIC` are
4952automatically extended by the system. If you are extending any manual
4953code in the recipe, you can use the ``${MLPREFIX}`` variable to ensure
4954those names are extended correctly. This automatic extension code
4955resides in ``multilib.bbclass``.
4956
4957Using Multilib
4958~~~~~~~~~~~~~~
4959
4960After you have set up the recipes, you need to define the actual
4961combination of multiple libraries you want to build. You accomplish this
4962through your ``local.conf`` configuration file in the
4963:term:`Build Directory`. An example
4964configuration would be as follows:
4965::
4966
4967 MACHINE = "qemux86-64"
4968 require conf/multilib.conf
4969 MULTILIBS = "multilib:lib32"
4970 DEFAULTTUNE_virtclass-multilib-lib32 = "x86"
4971 IMAGE_INSTALL_append = "lib32-glib-2.0"
4972
4973This example enables an additional library named
4974``lib32`` alongside the normal target packages. When combining these
4975"lib32" alternatives, the example uses "x86" for tuning. For information
4976on this particular tuning, see
4977``meta/conf/machine/include/ia32/arch-ia32.inc``.
4978
4979The example then includes ``lib32-glib-2.0`` in all the images, which
4980illustrates one method of including a multiple library dependency. You
4981can use a normal image build to include this dependency, for example:
4982::
4983
4984 $ bitbake core-image-sato
4985
4986You can also build Multilib packages
4987specifically with a command like this:
4988::
4989
4990 $ bitbake lib32-glib-2.0
4991
4992Additional Implementation Details
4993~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4994
4995Generic implementation details as well as details that are specific to
4996package management systems exist. Following are implementation details
4997that exist regardless of the package management system:
4998
4999- The typical convention used for the class extension code as used by
5000 Multilib assumes that all package names specified in
5001 :term:`PACKAGES` that contain
5002 ``${PN}`` have ``${PN}`` at the start of the name. When that
5003 convention is not followed and ``${PN}`` appears at the middle or the
5004 end of a name, problems occur.
5005
5006- The :term:`TARGET_VENDOR`
5007 value under Multilib will be extended to "-vendormlmultilib" (e.g.
5008 "-pokymllib32" for a "lib32" Multilib with Poky). The reason for this
5009 slightly unwieldy contraction is that any "-" characters in the
5010 vendor string presently break Autoconf's ``config.sub``, and other
5011 separators are problematic for different reasons.
5012
5013For the RPM Package Management System, the following implementation
5014details exist:
5015
5016- A unique architecture is defined for the Multilib packages, along
5017 with creating a unique deploy folder under ``tmp/deploy/rpm`` in the
5018 :term:`Build Directory`. For
5019 example, consider ``lib32`` in a ``qemux86-64`` image. The possible
5020 architectures in the system are "all", "qemux86_64",
5021 "lib32_qemux86_64", and "lib32_x86".
5022
5023- The ``${MLPREFIX}`` variable is stripped from ``${PN}`` during RPM
5024 packaging. The naming for a normal RPM package and a Multilib RPM
5025 package in a ``qemux86-64`` system resolves to something similar to
5026 ``bash-4.1-r2.x86_64.rpm`` and ``bash-4.1.r2.lib32_x86.rpm``,
5027 respectively.
5028
5029- When installing a Multilib image, the RPM backend first installs the
5030 base image and then installs the Multilib libraries.
5031
5032- The build system relies on RPM to resolve the identical files in the
5033 two (or more) Multilib packages.
5034
5035For the IPK Package Management System, the following implementation
5036details exist:
5037
5038- The ``${MLPREFIX}`` is not stripped from ``${PN}`` during IPK
5039 packaging. The naming for a normal RPM package and a Multilib IPK
5040 package in a ``qemux86-64`` system resolves to something like
5041 ``bash_4.1-r2.x86_64.ipk`` and ``lib32-bash_4.1-rw_x86.ipk``,
5042 respectively.
5043
5044- The IPK deploy folder is not modified with ``${MLPREFIX}`` because
5045 packages with and without the Multilib feature can exist in the same
5046 folder due to the ``${PN}`` differences.
5047
5048- IPK defines a sanity check for Multilib installation using certain
5049 rules for file comparison, overridden, etc.
5050
5051Installing Multiple Versions of the Same Library
5052------------------------------------------------
5053
5054Situations can exist where you need to install and use multiple versions
5055of the same library on the same system at the same time. These
5056situations almost always exist when a library API changes and you have
5057multiple pieces of software that depend on the separate versions of the
5058library. To accommodate these situations, you can install multiple
5059versions of the same library in parallel on the same system.
5060
5061The process is straightforward as long as the libraries use proper
5062versioning. With properly versioned libraries, all you need to do to
5063individually specify the libraries is create separate, appropriately
5064named recipes where the :term:`PN` part of
5065the name includes a portion that differentiates each library version
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005066(e.g. the major part of the version number). Thus, instead of having a
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005067single recipe that loads one version of a library (e.g. ``clutter``),
5068you provide multiple recipes that result in different versions of the
5069libraries you want. As an example, the following two recipes would allow
5070the two separate versions of the ``clutter`` library to co-exist on the
5071same system:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005072
5073.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005074
5075 clutter-1.6_1.6.20.bb
5076 clutter-1.8_1.8.4.bb
5077
5078Additionally, if
5079you have other recipes that depend on a given library, you need to use
5080the :term:`DEPENDS` variable to
5081create the dependency. Continuing with the same example, if you want to
5082have a recipe depend on the 1.8 version of the ``clutter`` library, use
5083the following in your recipe:
5084::
5085
5086 DEPENDS = "clutter-1.8"
5087
5088Using x32 psABI
5089===============
5090
5091x32 processor-specific Application Binary Interface (`x32
5092psABI <https://software.intel.com/en-us/node/628948>`__) is a native
509332-bit processor-specific ABI for Intel 64 (x86-64) architectures. An
5094ABI defines the calling conventions between functions in a processing
5095environment. The interface determines what registers are used and what
5096the sizes are for various C data types.
5097
5098Some processing environments prefer using 32-bit applications even when
5099running on Intel 64-bit platforms. Consider the i386 psABI, which is a
5100very old 32-bit ABI for Intel 64-bit platforms. The i386 psABI does not
5101provide efficient use and access of the Intel 64-bit processor
5102resources, leaving the system underutilized. Now consider the x86_64
5103psABI. This ABI is newer and uses 64-bits for data sizes and program
5104pointers. The extra bits increase the footprint size of the programs,
5105libraries, and also increases the memory and file system size
5106requirements. Executing under the x32 psABI enables user programs to
5107utilize CPU and system resources more efficiently while keeping the
5108memory footprint of the applications low. Extra bits are used for
5109registers but not for addressing mechanisms.
5110
5111The Yocto Project supports the final specifications of x32 psABI as
5112follows:
5113
5114- You can create packages and images in x32 psABI format on x86_64
5115 architecture targets.
5116
5117- You can successfully build recipes with the x32 toolchain.
5118
5119- You can create and boot ``core-image-minimal`` and
5120 ``core-image-sato`` images.
5121
5122- RPM Package Manager (RPM) support exists for x32 binaries.
5123
5124- Support for large images exists.
5125
5126To use the x32 psABI, you need to edit your ``conf/local.conf``
5127configuration file as follows:
5128::
5129
5130 MACHINE = "qemux86-64"
5131 DEFAULTTUNE = "x86-64-x32"
5132 baselib = "${@d.getVar('BASE_LIB_tune-' + (d.getVar('DEFAULTTUNE') \
5133 or 'INVALID')) or 'lib'}"
5134
5135Once you have set
5136up your configuration file, use BitBake to build an image that supports
5137the x32 psABI. Here is an example:
5138::
5139
5140 $ bitbake core-image-sato
5141
5142Enabling GObject Introspection Support
5143======================================
5144
5145`GObject
5146introspection <https://wiki.gnome.org/Projects/GObjectIntrospection>`__
5147is the standard mechanism for accessing GObject-based software from
5148runtime environments. GObject is a feature of the GLib library that
5149provides an object framework for the GNOME desktop and related software.
5150GObject Introspection adds information to GObject that allows objects
5151created within it to be represented across different programming
5152languages. If you want to construct GStreamer pipelines using Python, or
5153control UPnP infrastructure using Javascript and GUPnP, GObject
5154introspection is the only way to do it.
5155
5156This section describes the Yocto Project support for generating and
5157packaging GObject introspection data. GObject introspection data is a
5158description of the API provided by libraries built on top of GLib
5159framework, and, in particular, that framework's GObject mechanism.
5160GObject Introspection Repository (GIR) files go to ``-dev`` packages,
5161``typelib`` files go to main packages as they are packaged together with
5162libraries that are introspected.
5163
5164The data is generated when building such a library, by linking the
5165library with a small executable binary that asks the library to describe
5166itself, and then executing the binary and processing its output.
5167
5168Generating this data in a cross-compilation environment is difficult
5169because the library is produced for the target architecture, but its
5170code needs to be executed on the build host. This problem is solved with
5171the OpenEmbedded build system by running the code through QEMU, which
5172allows precisely that. Unfortunately, QEMU does not always work
5173perfectly as mentioned in the "`Known Issues <#known-issues>`__"
5174section.
5175
5176Enabling the Generation of Introspection Data
5177---------------------------------------------
5178
5179Enabling the generation of introspection data (GIR files) in your
5180library package involves the following:
5181
51821. Inherit the
5183 :ref:`gobject-introspection <ref-classes-gobject-introspection>`
5184 class.
5185
51862. Make sure introspection is not disabled anywhere in the recipe or
5187 from anything the recipe includes. Also, make sure that
5188 "gobject-introspection-data" is not in
5189 :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`
5190 and that "qemu-usermode" is not in
5191 :term:`MACHINE_FEATURES_BACKFILL_CONSIDERED`.
5192 If either of these conditions exist, nothing will happen.
5193
51943. Try to build the recipe. If you encounter build errors that look like
5195 something is unable to find ``.so`` libraries, check where these
5196 libraries are located in the source tree and add the following to the
5197 recipe:
5198 ::
5199
5200 GIR_EXTRA_LIBS_PATH = "${B}/something/.libs"
5201
5202 .. note::
5203
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005204 See recipes in the ``oe-core`` repository that use that
5205 ``GIR_EXTRA_LIBS_PATH`` variable as an example.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005206
52074. Look for any other errors, which probably mean that introspection
5208 support in a package is not entirely standard, and thus breaks down
5209 in a cross-compilation environment. For such cases, custom-made fixes
5210 are needed. A good place to ask and receive help in these cases is
5211 the :ref:`Yocto Project mailing
5212 lists <resources-mailinglist>`.
5213
5214.. note::
5215
5216 Using a library that no longer builds against the latest Yocto
5217 Project release and prints introspection related errors is a good
5218 candidate for the previous procedure.
5219
5220Disabling the Generation of Introspection Data
5221----------------------------------------------
5222
5223You might find that you do not want to generate introspection data. Or,
5224perhaps QEMU does not work on your build host and target architecture
5225combination. If so, you can use either of the following methods to
5226disable GIR file generations:
5227
5228- Add the following to your distro configuration:
5229 ::
5230
5231 DISTRO_FEATURES_BACKFILL_CONSIDERED = "gobject-introspection-data"
5232
5233 Adding this statement disables generating introspection data using
5234 QEMU but will still enable building introspection tools and libraries
5235 (i.e. building them does not require the use of QEMU).
5236
5237- Add the following to your machine configuration:
5238 ::
5239
5240 MACHINE_FEATURES_BACKFILL_CONSIDERED = "qemu-usermode"
5241
5242 Adding this statement disables the use of QEMU when building packages for your
5243 machine. Currently, this feature is used only by introspection
5244 recipes and has the same effect as the previously described option.
5245
5246 .. note::
5247
5248 Future releases of the Yocto Project might have other features
5249 affected by this option.
5250
5251If you disable introspection data, you can still obtain it through other
5252means such as copying the data from a suitable sysroot, or by generating
5253it on the target hardware. The OpenEmbedded build system does not
5254currently provide specific support for these techniques.
5255
5256Testing that Introspection Works in an Image
5257--------------------------------------------
5258
5259Use the following procedure to test if generating introspection data is
5260working in an image:
5261
52621. Make sure that "gobject-introspection-data" is not in
5263 :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`
5264 and that "qemu-usermode" is not in
5265 :term:`MACHINE_FEATURES_BACKFILL_CONSIDERED`.
5266
52672. Build ``core-image-sato``.
5268
52693. Launch a Terminal and then start Python in the terminal.
5270
52714. Enter the following in the terminal:
5272 ::
5273
5274 >>> from gi.repository import GLib
5275 >>> GLib.get_host_name()
5276
52775. For something a little more advanced, enter the following see:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005278 https://python-gtk-3-tutorial.readthedocs.io/en/latest/introduction.html
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005279
5280Known Issues
5281------------
5282
5283The following know issues exist for GObject Introspection Support:
5284
5285- ``qemu-ppc64`` immediately crashes. Consequently, you cannot build
5286 introspection data on that architecture.
5287
5288- x32 is not supported by QEMU. Consequently, introspection data is
5289 disabled.
5290
5291- musl causes transient GLib binaries to crash on assertion failures.
5292 Consequently, generating introspection data is disabled.
5293
5294- Because QEMU is not able to run the binaries correctly, introspection
5295 is disabled for some specific packages under specific architectures
5296 (e.g. ``gcr``, ``libsecret``, and ``webkit``).
5297
5298- QEMU usermode might not work properly when running 64-bit binaries
5299 under 32-bit host machines. In particular, "qemumips64" is known to
5300 not work under i686.
5301
5302.. _dev-optionally-using-an-external-toolchain:
5303
5304Optionally Using an External Toolchain
5305======================================
5306
5307You might want to use an external toolchain as part of your development.
5308If this is the case, the fundamental steps you need to accomplish are as
5309follows:
5310
5311- Understand where the installed toolchain resides. For cases where you
5312 need to build the external toolchain, you would need to take separate
5313 steps to build and install the toolchain.
5314
5315- Make sure you add the layer that contains the toolchain to your
5316 ``bblayers.conf`` file through the
5317 :term:`BBLAYERS` variable.
5318
5319- Set the ``EXTERNAL_TOOLCHAIN`` variable in your ``local.conf`` file
5320 to the location in which you installed the toolchain.
5321
5322A good example of an external toolchain used with the Yocto Project is
5323Mentor Graphics Sourcery G++ Toolchain. You can see information on how
5324to use that particular layer in the ``README`` file at
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005325https://github.com/MentorEmbedded/meta-sourcery/. You can find
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005326further information by reading about the
5327:term:`TCMODE` variable in the Yocto
5328Project Reference Manual's variable glossary.
5329
5330Creating Partitioned Images Using Wic
5331=====================================
5332
5333Creating an image for a particular hardware target using the
5334OpenEmbedded build system does not necessarily mean you can boot that
5335image as is on your device. Physical devices accept and boot images in
5336various ways depending on the specifics of the device. Usually,
5337information about the hardware can tell you what image format the device
5338requires. Should your device require multiple partitions on an SD card,
5339flash, or an HDD, you can use the OpenEmbedded Image Creator, Wic, to
5340create the properly partitioned image.
5341
5342The ``wic`` command generates partitioned images from existing
5343OpenEmbedded build artifacts. Image generation is driven by partitioning
5344commands contained in an Openembedded kickstart file (``.wks``)
5345specified either directly on the command line or as one of a selection
5346of canned kickstart files as shown with the ``wic list images`` command
5347in the "`Using an Existing Kickstart
5348File <#using-a-provided-kickstart-file>`__" section. When you apply the
5349command to a given set of build artifacts, the result is an image or set
5350of images that can be directly written onto media and used on a
5351particular system.
5352
5353.. note::
5354
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005355 For a kickstart file reference, see the
5356 ":ref:`ref-manual/ref-kickstart:openembedded kickstart (\`\`.wks\`\`) reference`"
5357 Chapter in the Yocto Project Reference Manual.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005358
5359The ``wic`` command and the infrastructure it is based on is by
5360definition incomplete. The purpose of the command is to allow the
5361generation of customized images, and as such, was designed to be
5362completely extensible through a plugin interface. See the "`Using the
5363Wic PlugIn Interface <#wic-using-the-wic-plugin-interface>`__" section
5364for information on these plugins.
5365
5366This section provides some background information on Wic, describes what
5367you need to have in place to run the tool, provides instruction on how
5368to use the Wic utility, provides information on using the Wic plugins
5369interface, and provides several examples that show how to use Wic.
5370
5371.. _wic-background:
5372
5373Background
5374----------
5375
5376This section provides some background on the Wic utility. While none of
5377this information is required to use Wic, you might find it interesting.
5378
5379- The name "Wic" is derived from OpenEmbedded Image Creator (oeic). The
5380 "oe" diphthong in "oeic" was promoted to the letter "w", because
5381 "oeic" is both difficult to remember and to pronounce.
5382
5383- Wic is loosely based on the Meego Image Creator (``mic``) framework.
5384 The Wic implementation has been heavily modified to make direct use
5385 of OpenEmbedded build artifacts instead of package installation and
5386 configuration, which are already incorporated within the OpenEmbedded
5387 artifacts.
5388
5389- Wic is a completely independent standalone utility that initially
5390 provides easier-to-use and more flexible replacements for an existing
5391 functionality in OE-Core's
5392 :ref:`image-live <ref-classes-image-live>`
5393 class. The difference between Wic and those examples is that with Wic
5394 the functionality of those scripts is implemented by a
5395 general-purpose partitioning language, which is based on Redhat
5396 kickstart syntax.
5397
5398.. _wic-requirements:
5399
5400Requirements
5401------------
5402
5403In order to use the Wic utility with the OpenEmbedded Build system, your
5404system needs to meet the following requirements:
5405
5406- The Linux distribution on your development host must support the
5407 Yocto Project. See the ":ref:`detailed-supported-distros`"
5408 section in the Yocto Project Reference Manual for the list of
5409 distributions that support the Yocto Project.
5410
5411- The standard system utilities, such as ``cp``, must be installed on
5412 your development host system.
5413
5414- You must have sourced the build environment setup script (i.e.
5415 :ref:`structure-core-script`) found in the
5416 :term:`Build Directory`.
5417
5418- You need to have the build artifacts already available, which
5419 typically means that you must have already created an image using the
5420 Openembedded build system (e.g. ``core-image-minimal``). While it
5421 might seem redundant to generate an image in order to create an image
5422 using Wic, the current version of Wic requires the artifacts in the
5423 form generated by the OpenEmbedded build system.
5424
5425- You must build several native tools, which are built to run on the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005426 build system:
5427 ::
5428
5429 $ bitbake parted-native dosfstools-native mtools-native
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005430
5431- Include "wic" as part of the
5432 :term:`IMAGE_FSTYPES`
5433 variable.
5434
5435- Include the name of the :ref:`wic kickstart file <openembedded-kickstart-wks-reference>`
5436 as part of the :term:`WKS_FILE` variable
5437
5438.. _wic-getting-help:
5439
5440Getting Help
5441------------
5442
5443You can get general help for the ``wic`` command by entering the ``wic``
5444command by itself or by entering the command with a help argument as
5445follows:
5446::
5447
5448 $ wic -h
5449 $ wic --help
5450 $ wic help
5451
5452Currently, Wic supports seven commands: ``cp``, ``create``, ``help``,
5453``list``, ``ls``, ``rm``, and ``write``. You can get help for all these
5454commands except "help" by using the following form:
5455::
5456
5457 $ wic help command
5458
5459For example, the following command returns help for the ``write``
5460command:
5461::
5462
5463 $ wic help write
5464
5465Wic supports help for three topics: ``overview``, ``plugins``, and
5466``kickstart``. You can get help for any topic using the following form:
5467::
5468
5469 $ wic help topic
5470
5471For example, the following returns overview help for Wic:
5472::
5473
5474 $ wic help overview
5475
5476One additional level of help exists for Wic. You can get help on
5477individual images through the ``list`` command. You can use the ``list``
5478command to return the available Wic images as follows:
5479::
5480
5481 $ wic list images
5482 genericx86 Create an EFI disk image for genericx86*
5483 beaglebone-yocto Create SD card image for Beaglebone
5484 edgerouter Create SD card image for Edgerouter
5485 qemux86-directdisk Create a qemu machine 'pcbios' direct disk image
5486 directdisk-gpt Create a 'pcbios' direct disk image
5487 mkefidisk Create an EFI disk image
5488 directdisk Create a 'pcbios' direct disk image
5489 systemd-bootdisk Create an EFI disk image with systemd-boot
5490 mkhybridiso Create a hybrid ISO image
5491 sdimage-bootpart Create SD card image with a boot partition
5492 directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
5493 directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
5494
5495Once you know the list of available
5496Wic images, you can use ``help`` with the command to get help on a
5497particular image. For example, the following command returns help on the
5498"beaglebone-yocto" image:
5499::
5500
5501 $ wic list beaglebone-yocto help
5502
5503 Creates a partitioned SD card image for Beaglebone.
5504 Boot files are located in the first vfat partition.
5505
5506Operational Modes
5507-----------------
5508
5509You can use Wic in two different modes, depending on how much control
5510you need for specifying the Openembedded build artifacts that are used
5511for creating the image: Raw and Cooked:
5512
5513- *Raw Mode:* You explicitly specify build artifacts through Wic
5514 command-line arguments.
5515
5516- *Cooked Mode:* The current
5517 :term:`MACHINE` setting and image
5518 name are used to automatically locate and provide the build
5519 artifacts. You just supply a kickstart file and the name of the image
5520 from which to use artifacts.
5521
5522Regardless of the mode you use, you need to have the build artifacts
5523ready and available.
5524
5525Raw Mode
5526~~~~~~~~
5527
5528Running Wic in raw mode allows you to specify all the partitions through
5529the ``wic`` command line. The primary use for raw mode is if you have
5530built your kernel outside of the Yocto Project
5531:term:`Build Directory`. In other words, you
5532can point to arbitrary kernel, root filesystem locations, and so forth.
5533Contrast this behavior with cooked mode where Wic looks in the Build
5534Directory (e.g. ``tmp/deploy/images/``\ machine).
5535
5536The general form of the ``wic`` command in raw mode is:
5537::
5538
5539 $ wic create wks_file options ...
5540
5541 Where:
5542
5543 wks_file:
5544 An OpenEmbedded kickstart file. You can provide
5545 your own custom file or use a file from a set of
5546 existing files as described by further options.
5547
5548 optional arguments:
5549 -h, --help show this help message and exit
5550 -o OUTDIR, --outdir OUTDIR
5551 name of directory to create image in
5552 -e IMAGE_NAME, --image-name IMAGE_NAME
5553 name of the image to use the artifacts from e.g. core-
5554 image-sato
5555 -r ROOTFS_DIR, --rootfs-dir ROOTFS_DIR
5556 path to the /rootfs dir to use as the .wks rootfs
5557 source
5558 -b BOOTIMG_DIR, --bootimg-dir BOOTIMG_DIR
5559 path to the dir containing the boot artifacts (e.g.
5560 /EFI or /syslinux dirs) to use as the .wks bootimg
5561 source
5562 -k KERNEL_DIR, --kernel-dir KERNEL_DIR
5563 path to the dir containing the kernel to use in the
5564 .wks bootimg
5565 -n NATIVE_SYSROOT, --native-sysroot NATIVE_SYSROOT
5566 path to the native sysroot containing the tools to use
5567 to build the image
5568 -s, --skip-build-check
5569 skip the build check
5570 -f, --build-rootfs build rootfs
5571 -c {gzip,bzip2,xz}, --compress-with {gzip,bzip2,xz}
5572 compress image with specified compressor
5573 -m, --bmap generate .bmap
5574 --no-fstab-update Do not change fstab file.
5575 -v VARS_DIR, --vars VARS_DIR
5576 directory with <image>.env files that store bitbake
5577 variables
5578 -D, --debug output debug information
5579
5580.. note::
5581
5582 You do not need root privileges to run Wic. In fact, you should not
5583 run as root when using the utility.
5584
5585Cooked Mode
5586~~~~~~~~~~~
5587
5588Running Wic in cooked mode leverages off artifacts in the Build
5589Directory. In other words, you do not have to specify kernel or root
5590filesystem locations as part of the command. All you need to provide is
5591a kickstart file and the name of the image from which to use artifacts
5592by using the "-e" option. Wic looks in the Build Directory (e.g.
5593``tmp/deploy/images/``\ machine) for artifacts.
5594
5595The general form of the ``wic`` command using Cooked Mode is as follows:
5596::
5597
5598 $ wic create wks_file -e IMAGE_NAME
5599
5600 Where:
5601
5602 wks_file:
5603 An OpenEmbedded kickstart file. You can provide
5604 your own custom file or use a file from a set of
5605 existing files provided with the Yocto Project
5606 release.
5607
5608 required argument:
5609 -e IMAGE_NAME, --image-name IMAGE_NAME
5610 name of the image to use the artifacts from e.g. core-
5611 image-sato
5612
5613.. _using-a-provided-kickstart-file:
5614
5615Using an Existing Kickstart File
5616--------------------------------
5617
5618If you do not want to create your own kickstart file, you can use an
5619existing file provided by the Wic installation. As shipped, kickstart
5620files can be found in the :ref:`overview-manual/overview-manual-development-environment:yocto project source repositories` in the
5621following two locations:
5622::
5623
5624 poky/meta-yocto-bsp/wic
5625 poky/scripts/lib/wic/canned-wks
5626
5627Use the following command to list the available kickstart files:
5628::
5629
5630 $ wic list images
5631 genericx86 Create an EFI disk image for genericx86*
5632 beaglebone-yocto Create SD card image for Beaglebone
5633 edgerouter Create SD card image for Edgerouter
5634 qemux86-directdisk Create a qemu machine 'pcbios' direct disk image
5635 directdisk-gpt Create a 'pcbios' direct disk image
5636 mkefidisk Create an EFI disk image
5637 directdisk Create a 'pcbios' direct disk image
5638 systemd-bootdisk Create an EFI disk image with systemd-boot
5639 mkhybridiso Create a hybrid ISO image
5640 sdimage-bootpart Create SD card image with a boot partition
5641 directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
5642 directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
5643
5644When you use an existing file, you
5645do not have to use the ``.wks`` extension. Here is an example in Raw
5646Mode that uses the ``directdisk`` file:
5647::
5648
5649 $ wic create directdisk -r rootfs_dir -b bootimg_dir \
5650 -k kernel_dir -n native_sysroot
5651
5652Here are the actual partition language commands used in the
5653``genericx86.wks`` file to generate an image:
5654::
5655
5656 # short-description: Create an EFI disk image for genericx86*
5657 # long-description: Creates a partitioned EFI disk image for genericx86* machines
5658 part /boot --source bootimg-efi --sourceparams="loader=grub-efi" --ondisk sda --label msdos --active --align 1024
5659 part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid
5660 part swap --ondisk sda --size 44 --label swap1 --fstype=swap
5661
5662 bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=ttyS0,115200 console=tty0"
5663
5664.. _wic-using-the-wic-plugin-interface:
5665
5666Using the Wic Plugin Interface
5667------------------------------
5668
5669You can extend and specialize Wic functionality by using Wic plugins.
5670This section explains the Wic plugin interface.
5671
5672.. note::
5673
5674 Wic plugins consist of "source" and "imager" plugins. Imager plugins
5675 are beyond the scope of this section.
5676
5677Source plugins provide a mechanism to customize partition content during
5678the Wic image generation process. You can use source plugins to map
5679values that you specify using ``--source`` commands in kickstart files
5680(i.e. ``*.wks``) to a plugin implementation used to populate a given
5681partition.
5682
5683.. note::
5684
5685 If you use plugins that have build-time dependencies (e.g. native
5686 tools, bootloaders, and so forth) when building a Wic image, you need
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005687 to specify those dependencies using the :term:`WKS_FILE_DEPENDS`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005688 variable.
5689
5690Source plugins are subclasses defined in plugin files. As shipped, the
5691Yocto Project provides several plugin files. You can see the source
5692plugin files that ship with the Yocto Project
5693:yocto_git:`here </cgit/cgit.cgi/poky/tree/scripts/lib/wic/plugins/source>`.
5694Each of these plugin files contains source plugins that are designed to
5695populate a specific Wic image partition.
5696
5697Source plugins are subclasses of the ``SourcePlugin`` class, which is
5698defined in the ``poky/scripts/lib/wic/pluginbase.py`` file. For example,
5699the ``BootimgEFIPlugin`` source plugin found in the ``bootimg-efi.py``
5700file is a subclass of the ``SourcePlugin`` class, which is found in the
5701``pluginbase.py`` file.
5702
5703You can also implement source plugins in a layer outside of the Source
5704Repositories (external layer). To do so, be sure that your plugin files
5705are located in a directory whose path is
5706``scripts/lib/wic/plugins/source/`` within your external layer. When the
5707plugin files are located there, the source plugins they contain are made
5708available to Wic.
5709
5710When the Wic implementation needs to invoke a partition-specific
5711implementation, it looks for the plugin with the same name as the
5712``--source`` parameter used in the kickstart file given to that
5713partition. For example, if the partition is set up using the following
5714command in a kickstart file:
5715::
5716
5717 part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024
5718
5719The methods defined as class
5720members of the matching source plugin (i.e. ``bootimg-pcbios``) in the
5721``bootimg-pcbios.py`` plugin file are used.
5722
5723To be more concrete, here is the corresponding plugin definition from
5724the ``bootimg-pcbios.py`` file for the previous command along with an
5725example method called by the Wic implementation when it needs to prepare
5726a partition using an implementation-specific function:
5727::
5728
5729 .
5730 .
5731 .
5732 class BootimgPcbiosPlugin(SourcePlugin):
5733 """
5734 Create MBR boot partition and install syslinux on it.
5735 """
5736
5737 name = 'bootimg-pcbios'
5738 .
5739 .
5740 .
5741 @classmethod
5742 def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
5743 oe_builddir, bootimg_dir, kernel_dir,
5744 rootfs_dir, native_sysroot):
5745 """
5746 Called to do the actual content population for a partition i.e. it
5747 'prepares' the partition to be incorporated into the image.
5748 In this case, prepare content for legacy bios boot partition.
5749 """
5750 .
5751 .
5752 .
5753
5754If a
5755subclass (plugin) itself does not implement a particular function, Wic
5756locates and uses the default version in the superclass. It is for this
5757reason that all source plugins are derived from the ``SourcePlugin``
5758class.
5759
5760The ``SourcePlugin`` class defined in the ``pluginbase.py`` file defines
5761a set of methods that source plugins can implement or override. Any
5762plugins (subclass of ``SourcePlugin``) that do not implement a
5763particular method inherit the implementation of the method from the
5764``SourcePlugin`` class. For more information, see the ``SourcePlugin``
5765class in the ``pluginbase.py`` file for details:
5766
5767The following list describes the methods implemented in the
5768``SourcePlugin`` class:
5769
5770- ``do_prepare_partition()``: Called to populate a partition with
5771 actual content. In other words, the method prepares the final
5772 partition image that is incorporated into the disk image.
5773
5774- ``do_configure_partition()``: Called before
5775 ``do_prepare_partition()`` to create custom configuration files for a
5776 partition (e.g. syslinux or grub configuration files).
5777
5778- ``do_install_disk()``: Called after all partitions have been
5779 prepared and assembled into a disk image. This method provides a hook
5780 to allow finalization of a disk image (e.g. writing an MBR).
5781
5782- ``do_stage_partition()``: Special content-staging hook called
5783 before ``do_prepare_partition()``. This method is normally empty.
5784
5785 Typically, a partition just uses the passed-in parameters (e.g. the
5786 unmodified value of ``bootimg_dir``). However, in some cases, things
5787 might need to be more tailored. As an example, certain files might
5788 additionally need to be taken from ``bootimg_dir + /boot``. This hook
5789 allows those files to be staged in a customized fashion.
5790
5791 .. note::
5792
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005793 ``get_bitbake_var()`` allows you to access non-standard variables that
5794 you might want to use for this behavior.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005795
5796You can extend the source plugin mechanism. To add more hooks, create
5797more source plugin methods within ``SourcePlugin`` and the corresponding
5798derived subclasses. The code that calls the plugin methods uses the
5799``plugin.get_source_plugin_methods()`` function to find the method or
5800methods needed by the call. Retrieval of those methods is accomplished
5801by filling up a dict with keys that contain the method names of
5802interest. On success, these will be filled in with the actual methods.
5803See the Wic implementation for examples and details.
5804
5805.. _wic-usage-examples:
5806
5807Wic Examples
5808------------
5809
5810This section provides several examples that show how to use the Wic
5811utility. All the examples assume the list of requirements in the
5812"`Requirements <#wic-requirements>`__" section have been met. The
5813examples assume the previously generated image is
5814``core-image-minimal``.
5815
5816.. _generate-an-image-using-a-provided-kickstart-file:
5817
5818Generate an Image using an Existing Kickstart File
5819~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5820
5821This example runs in Cooked Mode and uses the ``mkefidisk`` kickstart
5822file:
5823::
5824
5825 $ wic create mkefidisk -e core-image-minimal
5826 INFO: Building wic-tools...
5827 .
5828 .
5829 .
5830 INFO: The new image(s) can be found here:
5831 ./mkefidisk-201804191017-sda.direct
5832
5833 The following build artifacts were used to create the image(s):
5834 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
5835 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
5836 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
5837 NATIVE_SYSROOT: /home/stephano/build/master/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
5838
5839 INFO: The image(s) were created using OE kickstart file:
5840 /home/stephano/build/master/openembedded-core/scripts/lib/wic/canned-wks/mkefidisk.wks
5841
5842The previous example shows the easiest way to create an image by running
5843in cooked mode and supplying a kickstart file and the "-e" option to
5844point to the existing build artifacts. Your ``local.conf`` file needs to
5845have the :term:`MACHINE` variable set
5846to the machine you are using, which is "qemux86" in this example.
5847
5848Once the image builds, the output provides image location, artifact use,
5849and kickstart file information.
5850
5851.. note::
5852
5853 You should always verify the details provided in the output to make
5854 sure that the image was indeed created exactly as expected.
5855
5856Continuing with the example, you can now write the image from the Build
5857Directory onto a USB stick, or whatever media for which you built your
5858image, and boot from the media. You can write the image by using
5859``bmaptool`` or ``dd``:
5860::
5861
5862 $ oe-run-native bmaptool copy mkefidisk-201804191017-sda.direct /dev/sdX
5863
5864or ::
5865
5866 $ sudo dd if=mkefidisk-201804191017-sda.direct of=/dev/sdX
5867
5868.. note::
5869
Andrew Geissler4c19ea12020-10-27 13:52:24 -05005870 For more information on how to use the ``bmaptool``
5871 to flash a device with an image, see the
5872 ":ref:`dev-manual/dev-manual-common-tasks:flashing images using \`\`bmaptool\`\``"
5873 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05005874
5875Using a Modified Kickstart File
5876~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5877
5878Because partitioned image creation is driven by the kickstart file, it
5879is easy to affect image creation by changing the parameters in the file.
5880This next example demonstrates that through modification of the
5881``directdisk-gpt`` kickstart file.
5882
5883As mentioned earlier, you can use the command ``wic list images`` to
5884show the list of existing kickstart files. The directory in which the
5885``directdisk-gpt.wks`` file resides is
5886``scripts/lib/image/canned-wks/``, which is located in the
5887:term:`Source Directory` (e.g. ``poky``).
5888Because available files reside in this directory, you can create and add
5889your own custom files to the directory. Subsequent use of the
5890``wic list images`` command would then include your kickstart files.
5891
5892In this example, the existing ``directdisk-gpt`` file already does most
5893of what is needed. However, for the hardware in this example, the image
5894will need to boot from ``sdb`` instead of ``sda``, which is what the
5895``directdisk-gpt`` kickstart file uses.
5896
5897The example begins by making a copy of the ``directdisk-gpt.wks`` file
5898in the ``scripts/lib/image/canned-wks`` directory and then by changing
5899the lines that specify the target disk from which to boot.
5900::
5901
5902 $ cp /home/stephano/poky/scripts/lib/wic/canned-wks/directdisk-gpt.wks \
5903 /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
5904
5905Next, the example modifies the ``directdisksdb-gpt.wks`` file and
5906changes all instances of "``--ondisk sda``" to "``--ondisk sdb``". The
5907example changes the following two lines and leaves the remaining lines
5908untouched:
5909::
5910
5911 part /boot --source bootimg-pcbios --ondisk sdb --label boot --active --align 1024
5912 part / --source rootfs --ondisk sdb --fstype=ext4 --label platform --align 1024 --use-uuid
5913
5914Once the lines are changed, the
5915example generates the ``directdisksdb-gpt`` image. The command points
5916the process at the ``core-image-minimal`` artifacts for the Next Unit of
5917Computing (nuc) :term:`MACHINE` the
5918``local.conf``.
5919::
5920
5921 $ wic create directdisksdb-gpt -e core-image-minimal
5922 INFO: Building wic-tools...
5923 .
5924 .
5925 .
5926 Initialising tasks: 100% |#######################################| Time: 0:00:01
5927 NOTE: Executing SetScene Tasks
5928 NOTE: Executing RunQueue Tasks
5929 NOTE: Tasks Summary: Attempted 1161 tasks of which 1157 didn't need to be rerun and all succeeded.
5930 INFO: Creating image(s)...
5931
5932 INFO: The new image(s) can be found here:
5933 ./directdisksdb-gpt-201710090938-sdb.direct
5934
5935 The following build artifacts were used to create the image(s):
5936 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
5937 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
5938 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
5939 NATIVE_SYSROOT: /home/stephano/build/master/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
5940
5941 INFO: The image(s) were created using OE kickstart file:
5942 /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
5943
5944Continuing with the example, you can now directly ``dd`` the image to a
5945USB stick, or whatever media for which you built your image, and boot
5946the resulting media:
5947::
5948
5949 $ sudo dd if=directdisksdb-gpt-201710090938-sdb.direct of=/dev/sdb
5950 140966+0 records in
5951 140966+0 records out
5952 72174592 bytes (72 MB, 69 MiB) copied, 78.0282 s, 925 kB/s
5953 $ sudo eject /dev/sdb
5954
5955Using a Modified Kickstart File and Running in Raw Mode
5956~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5957
5958This next example manually specifies each build artifact (runs in Raw
5959Mode) and uses a modified kickstart file. The example also uses the
5960``-o`` option to cause Wic to create the output somewhere other than the
5961default output directory, which is the current directory:
5962::
5963
5964 $ wic create /home/stephano/my_yocto/test.wks -o /home/stephano/testwic \
5965 --rootfs-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/rootfs \
5966 --bootimg-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share \
5967 --kernel-dir /home/stephano/build/master/build/tmp/deploy/images/qemux86 \
5968 --native-sysroot /home/stephano/build/master/build/tmp/work/i586-poky-linux/wic-tools/1.0-r0/recipe-sysroot-native
5969
5970 INFO: Creating image(s)...
5971
5972 INFO: The new image(s) can be found here:
5973 /home/stephano/testwic/test-201710091445-sdb.direct
5974
5975 The following build artifacts were used to create the image(s):
5976 ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
5977 BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
5978 KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86
5979 NATIVE_SYSROOT: /home/stephano/build/master/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
5980
5981 INFO: The image(s) were created using OE kickstart file:
5982 /home/stephano/my_yocto/test.wks
5983
5984For this example,
5985:term:`MACHINE` did not have to be
5986specified in the ``local.conf`` file since the artifact is manually
5987specified.
5988
5989Using Wic to Manipulate an Image
5990~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5991
5992Wic image manipulation allows you to shorten turnaround time during
5993image development. For example, you can use Wic to delete the kernel
5994partition of a Wic image and then insert a newly built kernel. This
5995saves you time from having to rebuild the entire image each time you
5996modify the kernel.
5997
5998.. note::
5999
6000 In order to use Wic to manipulate a Wic image as in this example,
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006001 your development machine must have the ``mtools`` package installed.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006002
6003The following example examines the contents of the Wic image, deletes
6004the existing kernel, and then inserts a new kernel:
6005
60061. *List the Partitions:* Use the ``wic ls`` command to list all the
6007 partitions in the Wic image:
6008 ::
6009
6010 $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic
6011 Num Start End Size Fstype
6012 1 1048576 25041919 23993344 fat16
6013 2 25165824 72157183 46991360 ext4
6014
6015 The previous output shows two partitions in the
6016 ``core-image-minimal-qemux86.wic`` image.
6017
60182. *Examine a Particular Partition:* Use the ``wic ls`` command again
6019 but in a different form to examine a particular partition.
6020
6021 .. note::
6022
6023 You can get command usage on any Wic command using the following
6024 form:
6025 ::
6026
6027 $ wic help command
6028
6029
6030 For example, the following command shows you the various ways to
6031 use the
6032 wic ls
6033 command:
6034 ::
6035
6036 $ wic help ls
6037
6038
6039 The following command shows what is in Partition one:
6040 ::
6041
6042 $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1
6043 Volume in drive : is boot
6044 Volume Serial Number is E894-1809
6045 Directory for ::/
6046
6047 libcom32 c32 186500 2017-10-09 16:06
6048 libutil c32 24148 2017-10-09 16:06
6049 syslinux cfg 220 2017-10-09 16:06
6050 vesamenu c32 27104 2017-10-09 16:06
6051 vmlinuz 6904608 2017-10-09 16:06
6052 5 files 7 142 580 bytes
6053 16 582 656 bytes free
6054
6055 The previous output shows five files, with the
6056 ``vmlinuz`` being the kernel.
6057
6058 .. note::
6059
6060 If you see the following error, you need to update or create a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006061 ``~/.mtoolsrc`` file and be sure to have the line "mtools_skip_check=1"
6062 in the file. Then, run the Wic command again:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006063 ::
6064
6065 ERROR: _exec_cmd: /usr/bin/mdir -i /tmp/wic-parttfokuwra ::/ returned '1' instead of 0
6066 output: Total number of sectors (47824) not a multiple of sectors per track (32)!
6067 Add mtools_skip_check=1 to your .mtoolsrc file to skip this test
6068
6069
60703. *Remove the Old Kernel:* Use the ``wic rm`` command to remove the
6071 ``vmlinuz`` file (kernel):
6072 ::
6073
6074 $ wic rm tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
6075
60764. *Add In the New Kernel:* Use the ``wic cp`` command to add the
6077 updated kernel to the Wic image. Depending on how you built your
6078 kernel, it could be in different places. If you used ``devtool`` and
6079 an SDK to build your kernel, it resides in the ``tmp/work`` directory
6080 of the extensible SDK. If you used ``make`` to build the kernel, the
6081 kernel will be in the ``workspace/sources`` area.
6082
6083 The following example assumes ``devtool`` was used to build the
6084 kernel:
6085 ::
6086
6087 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 \
6088 ~/poky/build/tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
6089
6090 Once the new kernel is added back into the image, you can use the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006091 ``dd`` command or :ref:`bmaptool
6092 <dev-manual/dev-manual-common-tasks:flashing images using \`\`bmaptool\`\`>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006093 to flash your wic image onto an SD card or USB stick and test your
6094 target.
6095
6096 .. note::
6097
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006098 Using ``bmaptool`` is generally 10 to 20 times faster than using ``dd``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006099
6100Flashing Images Using ``bmaptool``
6101==================================
6102
6103A fast and easy way to flash an image to a bootable device is to use
6104Bmaptool, which is integrated into the OpenEmbedded build system.
6105Bmaptool is a generic tool that creates a file's block map (bmap) and
6106then uses that map to copy the file. As compared to traditional tools
6107such as dd or cp, Bmaptool can copy (or flash) large files like raw
6108system image files much faster.
6109
6110.. note::
6111
6112 - If you are using Ubuntu or Debian distributions, you can install
6113 the ``bmap-tools`` package using the following command and then
6114 use the tool without specifying ``PATH`` even from the root
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006115 account:
6116 ::
6117
6118 $ sudo apt-get install bmap-tools
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006119
6120 - If you are unable to install the ``bmap-tools`` package, you will
6121 need to build Bmaptool before using it. Use the following command:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006122 ::
6123
6124 $ bitbake bmap-tools-native
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006125
6126Following, is an example that shows how to flash a Wic image. Realize
6127that while this example uses a Wic image, you can use Bmaptool to flash
6128any type of image. Use these steps to flash an image using Bmaptool:
6129
61301. *Update your local.conf File:* You need to have the following set
6131 in your ``local.conf`` file before building your image:
6132 ::
6133
6134 IMAGE_FSTYPES += "wic wic.bmap"
6135
61362. *Get Your Image:* Either have your image ready (pre-built with the
6137 :term:`IMAGE_FSTYPES`
6138 setting previously mentioned) or take the step to build the image:
6139 ::
6140
6141 $ bitbake image
6142
61433. *Flash the Device:* Flash the device with the image by using Bmaptool
6144 depending on your particular setup. The following commands assume the
6145 image resides in the Build Directory's ``deploy/images/`` area:
6146
6147 - If you have write access to the media, use this command form:
6148 ::
6149
6150 $ oe-run-native bmap-tools-native bmaptool copy build-directory/tmp/deploy/images/machine/image.wic /dev/sdX
6151
6152 - If you do not have write access to the media, set your permissions
6153 first and then use the same command form:
6154 ::
6155
6156 $ sudo chmod 666 /dev/sdX
6157 $ oe-run-native bmap-tools-native bmaptool copy build-directory/tmp/deploy/images/machine/image.wic /dev/sdX
6158
6159For help on the ``bmaptool`` command, use the following command:
6160::
6161
6162 $ bmaptool --help
6163
6164Making Images More Secure
6165=========================
6166
6167Security is of increasing concern for embedded devices. Consider the
6168issues and problems discussed in just this sampling of work found across
6169the Internet:
6170
6171- *"*\ `Security Risks of Embedded
6172 Systems <https://www.schneier.com/blog/archives/2014/01/security_risks_9.html>`__\ *"*
6173 by Bruce Schneier
6174
6175- *"*\ `Internet Census
6176 2012 <http://census2012.sourceforge.net/paper.html>`__\ *"* by Carna
6177 Botnet
6178
6179- *"*\ `Security Issues for Embedded
6180 Devices <http://elinux.org/images/6/6f/Security-issues.pdf>`__\ *"*
6181 by Jake Edge
6182
6183When securing your image is of concern, there are steps, tools, and
6184variables that you can consider to help you reach the security goals you
6185need for your particular device. Not all situations are identical when
6186it comes to making an image secure. Consequently, this section provides
6187some guidance and suggestions for consideration when you want to make
6188your image more secure.
6189
6190.. note::
6191
6192 Because the security requirements and risks are different for every
6193 type of device, this section cannot provide a complete reference on
6194 securing your custom OS. It is strongly recommended that you also
6195 consult other sources of information on embedded Linux system
6196 hardening and on security.
6197
6198General Considerations
6199----------------------
6200
6201General considerations exist that help you create more secure images.
6202You should consider the following suggestions to help make your device
6203more secure:
6204
6205- Scan additional code you are adding to the system (e.g. application
6206 code) by using static analysis tools. Look for buffer overflows and
6207 other potential security problems.
6208
6209- Pay particular attention to the security for any web-based
6210 administration interface.
6211
6212 Web interfaces typically need to perform administrative functions and
6213 tend to need to run with elevated privileges. Thus, the consequences
6214 resulting from the interface's security becoming compromised can be
6215 serious. Look for common web vulnerabilities such as
6216 cross-site-scripting (XSS), unvalidated inputs, and so forth.
6217
6218 As with system passwords, the default credentials for accessing a
6219 web-based interface should not be the same across all devices. This
6220 is particularly true if the interface is enabled by default as it can
6221 be assumed that many end-users will not change the credentials.
6222
6223- Ensure you can update the software on the device to mitigate
6224 vulnerabilities discovered in the future. This consideration
6225 especially applies when your device is network-enabled.
6226
6227- Ensure you remove or disable debugging functionality before producing
6228 the final image. For information on how to do this, see the
6229 "`Considerations Specific to the OpenEmbedded Build
6230 System <#considerations-specific-to-the-openembedded-build-system>`__"
6231 section.
6232
6233- Ensure you have no network services listening that are not needed.
6234
6235- Remove any software from the image that is not needed.
6236
6237- Enable hardware support for secure boot functionality when your
6238 device supports this functionality.
6239
6240Security Flags
6241--------------
6242
6243The Yocto Project has security flags that you can enable that help make
6244your build output more secure. The security flags are in the
6245``meta/conf/distro/include/security_flags.inc`` file in your
6246:term:`Source Directory` (e.g. ``poky``).
6247
6248.. note::
6249
6250 Depending on the recipe, certain security flags are enabled and
6251 disabled by default.
6252
6253Use the following line in your ``local.conf`` file or in your custom
6254distribution configuration file to enable the security compiler and
6255linker flags for your build:
6256::
6257
6258 require conf/distro/include/security_flags.inc
6259
6260Considerations Specific to the OpenEmbedded Build System
6261--------------------------------------------------------
6262
6263You can take some steps that are specific to the OpenEmbedded build
6264system to make your images more secure:
6265
6266- Ensure "debug-tweaks" is not one of your selected
6267 :term:`IMAGE_FEATURES`.
6268 When creating a new project, the default is to provide you with an
6269 initial ``local.conf`` file that enables this feature using the
6270 :term:`EXTRA_IMAGE_FEATURES`
6271 variable with the line:
6272 ::
6273
6274 EXTRA_IMAGE_FEATURES = "debug-tweaks"
6275
6276 To disable that feature, simply comment out that line in your
6277 ``local.conf`` file, or make sure ``IMAGE_FEATURES`` does not contain
6278 "debug-tweaks" before producing your final image. Among other things,
6279 leaving this in place sets the root password as blank, which makes
6280 logging in for debugging or inspection easy during development but
6281 also means anyone can easily log in during production.
6282
6283- It is possible to set a root password for the image and also to set
6284 passwords for any extra users you might add (e.g. administrative or
6285 service type users). When you set up passwords for multiple images or
6286 users, you should not duplicate passwords.
6287
6288 To set up passwords, use the
6289 :ref:`extrausers <ref-classes-extrausers>`
6290 class, which is the preferred method. For an example on how to set up
6291 both root and user passwords, see the
6292 ":ref:`extrausers.bbclass <ref-classes-extrausers>`"
6293 section.
6294
6295 .. note::
6296
6297 When adding extra user accounts or setting a root password, be
6298 cautious about setting the same password on every device. If you
6299 do this, and the password you have set is exposed, then every
6300 device is now potentially compromised. If you need this access but
6301 want to ensure security, consider setting a different, random
6302 password for each device. Typically, you do this as a separate
6303 step after you deploy the image onto the device.
6304
6305- Consider enabling a Mandatory Access Control (MAC) framework such as
6306 SMACK or SELinux and tuning it appropriately for your device's usage.
6307 You can find more information in the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006308 :yocto_git:`meta-selinux </cgit/cgit.cgi/meta-selinux/>` layer.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006309
6310Tools for Hardening Your Image
6311------------------------------
6312
6313The Yocto Project provides tools for making your image more secure. You
6314can find these tools in the ``meta-security`` layer of the
6315:yocto_git:`Yocto Project Source Repositories <>`.
6316
6317Creating Your Own Distribution
6318==============================
6319
6320When you build an image using the Yocto Project and do not alter any
6321distribution :term:`Metadata`, you are
6322creating a Poky distribution. If you wish to gain more control over
6323package alternative selections, compile-time options, and other
6324low-level configurations, you can create your own distribution.
6325
6326To create your own distribution, the basic steps consist of creating
6327your own distribution layer, creating your own distribution
6328configuration file, and then adding any needed code and Metadata to the
6329layer. The following steps provide some more detail:
6330
6331- *Create a layer for your new distro:* Create your distribution layer
6332 so that you can keep your Metadata and code for the distribution
6333 separate. It is strongly recommended that you create and use your own
6334 layer for configuration and code. Using your own layer as compared to
6335 just placing configurations in a ``local.conf`` configuration file
6336 makes it easier to reproduce the same build configuration when using
6337 multiple build machines. See the
6338 ":ref:`dev-manual/dev-manual-common-tasks:creating a general layer using the \`\`bitbake-layers\`\` script`"
6339 section for information on how to quickly set up a layer.
6340
6341- *Create the distribution configuration file:* The distribution
6342 configuration file needs to be created in the ``conf/distro``
6343 directory of your layer. You need to name it using your distribution
6344 name (e.g. ``mydistro.conf``).
6345
6346 .. note::
6347
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006348 The :term:`DISTRO` variable in your ``local.conf`` file determines the
6349 name of your distribution.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006350
6351 You can split out parts of your configuration file into include files
6352 and then "require" them from within your distribution configuration
6353 file. Be sure to place the include files in the
6354 ``conf/distro/include`` directory of your layer. A common example
6355 usage of include files would be to separate out the selection of
6356 desired version and revisions for individual recipes.
6357
6358 Your configuration file needs to set the following required
6359 variables:
6360
6361 - :term:`DISTRO_NAME`
6362
6363 - :term:`DISTRO_VERSION`
6364
6365 These following variables are optional and you typically set them
6366 from the distribution configuration file:
6367
6368 - :term:`DISTRO_FEATURES`
6369
6370 - :term:`DISTRO_EXTRA_RDEPENDS`
6371
6372 - :term:`DISTRO_EXTRA_RRECOMMENDS`
6373
6374 - :term:`TCLIBC`
6375
6376 .. tip::
6377
6378 If you want to base your distribution configuration file on the
6379 very basic configuration from OE-Core, you can use
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006380 ``conf/distro/defaultsetup.conf`` as a reference and just include
6381 variables that differ as compared to ``defaultsetup.conf``.
6382 Alternatively, you can create a distribution configuration file
6383 from scratch using the ``defaultsetup.conf`` file or configuration files
6384 from other distributions such as Poky or Angstrom as references.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006385
6386- *Provide miscellaneous variables:* Be sure to define any other
6387 variables for which you want to create a default or enforce as part
6388 of the distribution configuration. You can include nearly any
6389 variable from the ``local.conf`` file. The variables you use are not
6390 limited to the list in the previous bulleted item.
6391
6392- *Point to Your distribution configuration file:* In your
6393 ``local.conf`` file in the :term:`Build Directory`,
6394 set your
6395 :term:`DISTRO` variable to point to
6396 your distribution's configuration file. For example, if your
6397 distribution's configuration file is named ``mydistro.conf``, then
6398 you point to it as follows:
6399 ::
6400
6401 DISTRO = "mydistro"
6402
6403- *Add more to the layer if necessary:* Use your layer to hold other
6404 information needed for the distribution:
6405
6406 - Add recipes for installing distro-specific configuration files
6407 that are not already installed by another recipe. If you have
6408 distro-specific configuration files that are included by an
6409 existing recipe, you should add an append file (``.bbappend``) for
6410 those. For general information and recommendations on how to add
6411 recipes to your layer, see the "`Creating Your Own
6412 Layer <#creating-your-own-layer>`__" and "`Following Best
6413 Practices When Creating
6414 Layers <#best-practices-to-follow-when-creating-layers>`__"
6415 sections.
6416
6417 - Add any image recipes that are specific to your distribution.
6418
6419 - Add a ``psplash`` append file for a branded splash screen. For
6420 information on append files, see the "`Using .bbappend Files in
6421 Your Layer <#using-bbappend-files>`__" section.
6422
6423 - Add any other append files to make custom changes that are
6424 specific to individual recipes.
6425
6426Creating a Custom Template Configuration Directory
6427==================================================
6428
6429If you are producing your own customized version of the build system for
6430use by other users, you might want to customize the message shown by the
6431setup script or you might want to change the template configuration
6432files (i.e. ``local.conf`` and ``bblayers.conf``) that are created in a
6433new build directory.
6434
6435The OpenEmbedded build system uses the environment variable
6436``TEMPLATECONF`` to locate the directory from which it gathers
6437configuration information that ultimately ends up in the
6438:term:`Build Directory` ``conf`` directory.
6439By default, ``TEMPLATECONF`` is set as follows in the ``poky``
6440repository:
6441::
6442
6443 TEMPLATECONF=${TEMPLATECONF:-meta-poky/conf}
6444
6445This is the
6446directory used by the build system to find templates from which to build
6447some key configuration files. If you look at this directory, you will
6448see the ``bblayers.conf.sample``, ``local.conf.sample``, and
6449``conf-notes.txt`` files. The build system uses these files to form the
6450respective ``bblayers.conf`` file, ``local.conf`` file, and display the
6451list of BitBake targets when running the setup script.
6452
6453To override these default configuration files with configurations you
6454want used within every new Build Directory, simply set the
6455``TEMPLATECONF`` variable to your directory. The ``TEMPLATECONF``
6456variable is set in the ``.templateconf`` file, which is in the top-level
6457:term:`Source Directory` folder
6458(e.g. ``poky``). Edit the ``.templateconf`` so that it can locate your
6459directory.
6460
6461Best practices dictate that you should keep your template configuration
6462directory in your custom distribution layer. For example, suppose you
6463have a layer named ``meta-mylayer`` located in your home directory and
6464you want your template configuration directory named ``myconf``.
6465Changing the ``.templateconf`` as follows causes the OpenEmbedded build
6466system to look in your directory and base its configuration files on the
6467``*.sample`` configuration files it finds. The final configuration files
6468(i.e. ``local.conf`` and ``bblayers.conf`` ultimately still end up in
6469your Build Directory, but they are based on your ``*.sample`` files.
6470::
6471
6472 TEMPLATECONF=${TEMPLATECONF:-meta-mylayer/myconf}
6473
6474Aside from the ``*.sample`` configuration files, the ``conf-notes.txt``
6475also resides in the default ``meta-poky/conf`` directory. The script
6476that sets up the build environment (i.e.
6477:ref:`structure-core-script`) uses this file to
6478display BitBake targets as part of the script output. Customizing this
6479``conf-notes.txt`` file is a good way to make sure your list of custom
6480targets appears as part of the script's output.
6481
6482Here is the default list of targets displayed as a result of running
6483either of the setup scripts:
6484::
6485
6486 You can now run 'bitbake <target>'
6487
6488 Common targets are:
6489 core-image-minimal
6490 core-image-sato
6491 meta-toolchain
6492 meta-ide-support
6493
6494Changing the listed common targets is as easy as editing your version of
6495``conf-notes.txt`` in your custom template configuration directory and
6496making sure you have ``TEMPLATECONF`` set to your directory.
6497
6498.. _dev-saving-memory-during-a-build:
6499
6500Conserving Disk Space During Builds
6501===================================
6502
6503To help conserve disk space during builds, you can add the following
6504statement to your project's ``local.conf`` configuration file found in
6505the :term:`Build Directory`:
6506::
6507
6508 INHERIT += "rm_work"
6509
6510Adding this statement deletes the work directory used for
6511building a recipe once the recipe is built. For more information on
6512"rm_work", see the
6513:ref:`rm_work <ref-classes-rm-work>` class in the
6514Yocto Project Reference Manual.
6515
6516Working with Packages
6517=====================
6518
6519This section describes a few tasks that involve packages:
6520
6521- `Excluding packages from an
6522 image <#excluding-packages-from-an-image>`__
6523
6524- `Incrementing a binary package
6525 version <#incrementing-a-binary-package-version>`__
6526
6527- `Handling optional module
6528 packaging <#handling-optional-module-packaging>`__
6529
6530- `Using runtime package
6531 management <#using-runtime-package-management>`__
6532
6533- `Generating and using signed
6534 packages <#generating-and-using-signed-packages>`__
6535
6536- `Setting up and running package test
6537 (ptest) <#testing-packages-with-ptest>`__
6538
6539- `Creating node package manager (NPM)
6540 packages <#creating-node-package-manager-npm-packages>`__
6541
6542- `Adding custom metadata to
6543 packages <#adding-custom-metadata-to-packages>`__
6544
6545Excluding Packages from an Image
6546--------------------------------
6547
6548You might find it necessary to prevent specific packages from being
6549installed into an image. If so, you can use several variables to direct
6550the build system to essentially ignore installing recommended packages
6551or to not install a package at all.
6552
6553The following list introduces variables you can use to prevent packages
6554from being installed into your image. Each of these variables only works
6555with IPK and RPM package types. Support for Debian packages does not
6556exist. Also, you can use these variables from your ``local.conf`` file
6557or attach them to a specific image recipe by using a recipe name
6558override. For more detail on the variables, see the descriptions in the
6559Yocto Project Reference Manual's glossary chapter.
6560
6561- :term:`BAD_RECOMMENDATIONS`:
6562 Use this variable to specify "recommended-only" packages that you do
6563 not want installed.
6564
6565- :term:`NO_RECOMMENDATIONS`:
6566 Use this variable to prevent all "recommended-only" packages from
6567 being installed.
6568
6569- :term:`PACKAGE_EXCLUDE`:
6570 Use this variable to prevent specific packages from being installed
6571 regardless of whether they are "recommended-only" or not. You need to
6572 realize that the build process could fail with an error when you
6573 prevent the installation of a package whose presence is required by
6574 an installed package.
6575
6576.. _incrementing-a-binary-package-version:
6577
6578Incrementing a Package Version
6579------------------------------
6580
6581This section provides some background on how binary package versioning
6582is accomplished and presents some of the services, variables, and
6583terminology involved.
6584
6585In order to understand binary package versioning, you need to consider
6586the following:
6587
6588- Binary Package: The binary package that is eventually built and
6589 installed into an image.
6590
6591- Binary Package Version: The binary package version is composed of two
6592 components - a version and a revision.
6593
6594 .. note::
6595
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006596 Technically, a third component, the "epoch" (i.e. :term:`PE`) is involved
6597 but this discussion for the most part ignores ``PE``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006598
6599 The version and revision are taken from the
6600 :term:`PV` and
6601 :term:`PR` variables, respectively.
6602
6603- ``PV``: The recipe version. ``PV`` represents the version of the
6604 software being packaged. Do not confuse ``PV`` with the binary
6605 package version.
6606
6607- ``PR``: The recipe revision.
6608
6609- :term:`SRCPV`: The OpenEmbedded
6610 build system uses this string to help define the value of ``PV`` when
6611 the source code revision needs to be included in it.
6612
6613- :yocto_wiki:`PR Service </wiki/PR_Service>`: A
6614 network-based service that helps automate keeping package feeds
6615 compatible with existing package manager applications such as RPM,
6616 APT, and OPKG.
6617
6618Whenever the binary package content changes, the binary package version
6619must change. Changing the binary package version is accomplished by
6620changing or "bumping" the ``PR`` and/or ``PV`` values. Increasing these
6621values occurs one of two ways:
6622
6623- Automatically using a Package Revision Service (PR Service).
6624
6625- Manually incrementing the ``PR`` and/or ``PV`` variables.
6626
6627Given a primary challenge of any build system and its users is how to
6628maintain a package feed that is compatible with existing package manager
6629applications such as RPM, APT, and OPKG, using an automated system is
6630much preferred over a manual system. In either system, the main
6631requirement is that binary package version numbering increases in a
6632linear fashion and that a number of version components exist that
6633support that linear progression. For information on how to ensure
6634package revisioning remains linear, see the "`Automatically Incrementing
6635a Binary Package Revision
6636Number <#automatically-incrementing-a-binary-package-revision-number>`__"
6637section.
6638
6639The following three sections provide related information on the PR
6640Service, the manual method for "bumping" ``PR`` and/or ``PV``, and on
6641how to ensure binary package revisioning remains linear.
6642
6643Working With a PR Service
6644~~~~~~~~~~~~~~~~~~~~~~~~~
6645
6646As mentioned, attempting to maintain revision numbers in the
6647:term:`Metadata` is error prone, inaccurate,
6648and causes problems for people submitting recipes. Conversely, the PR
6649Service automatically generates increasing numbers, particularly the
6650revision field, which removes the human element.
6651
6652.. note::
6653
6654 For additional information on using a PR Service, you can see the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006655 :yocto_wiki:`PR Service </wiki/PR_Service>` wiki page.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006656
6657The Yocto Project uses variables in order of decreasing priority to
6658facilitate revision numbering (i.e.
6659:term:`PE`,
6660:term:`PV`, and
6661:term:`PR` for epoch, version, and
6662revision, respectively). The values are highly dependent on the policies
6663and procedures of a given distribution and package feed.
6664
6665Because the OpenEmbedded build system uses
6666":ref:`signatures <overview-checksums>`", which are
6667unique to a given build, the build system knows when to rebuild
6668packages. All the inputs into a given task are represented by a
6669signature, which can trigger a rebuild when different. Thus, the build
6670system itself does not rely on the ``PR``, ``PV``, and ``PE`` numbers to
6671trigger a rebuild. The signatures, however, can be used to generate
6672these values.
6673
6674The PR Service works with both ``OEBasic`` and ``OEBasicHash``
6675generators. The value of ``PR`` bumps when the checksum changes and the
6676different generator mechanisms change signatures under different
6677circumstances.
6678
6679As implemented, the build system includes values from the PR Service
6680into the ``PR`` field as an addition using the form "``.x``" so ``r0``
6681becomes ``r0.1``, ``r0.2`` and so forth. This scheme allows existing
6682``PR`` values to be used for whatever reasons, which include manual
6683``PR`` bumps, should it be necessary.
6684
6685By default, the PR Service is not enabled or running. Thus, the packages
6686generated are just "self consistent". The build system adds and removes
6687packages and there are no guarantees about upgrade paths but images will
6688be consistent and correct with the latest changes.
6689
6690The simplest form for a PR Service is for it to exist for a single host
6691development system that builds the package feed (building system). For
6692this scenario, you can enable a local PR Service by setting
6693:term:`PRSERV_HOST` in your
6694``local.conf`` file in the :term:`Build Directory`:
6695::
6696
6697 PRSERV_HOST = "localhost:0"
6698
6699Once the service is started, packages will automatically
6700get increasing ``PR`` values and BitBake takes care of starting and
6701stopping the server.
6702
6703If you have a more complex setup where multiple host development systems
6704work against a common, shared package feed, you have a single PR Service
6705running and it is connected to each building system. For this scenario,
6706you need to start the PR Service using the ``bitbake-prserv`` command:
6707::
6708
6709 bitbake-prserv --host ip --port port --start
6710
6711In addition to
6712hand-starting the service, you need to update the ``local.conf`` file of
6713each building system as described earlier so each system points to the
6714server and port.
6715
6716It is also recommended you use build history, which adds some sanity
6717checks to binary package versions, in conjunction with the server that
6718is running the PR Service. To enable build history, add the following to
6719each building system's ``local.conf`` file:
6720::
6721
6722 # It is recommended to activate "buildhistory" for testing the PR service
6723 INHERIT += "buildhistory"
6724 BUILDHISTORY_COMMIT = "1"
6725
6726For information on build
6727history, see the "`Maintaining Build Output
6728Quality <#maintaining-build-output-quality>`__" section.
6729
6730.. note::
6731
6732 The OpenEmbedded build system does not maintain ``PR`` information as
6733 part of the shared state (sstate) packages. If you maintain an sstate
6734 feed, its expected that either all your building systems that
6735 contribute to the sstate feed use a shared PR Service, or you do not
6736 run a PR Service on any of your building systems. Having some systems
6737 use a PR Service while others do not leads to obvious problems.
6738
6739 For more information on shared state, see the
6740 ":ref:`overview-manual/overview-manual-concepts:shared state cache`"
6741 section in the Yocto Project Overview and Concepts Manual.
6742
6743Manually Bumping PR
6744~~~~~~~~~~~~~~~~~~~
6745
6746The alternative to setting up a PR Service is to manually "bump" the
6747:term:`PR` variable.
6748
6749If a committed change results in changing the package output, then the
6750value of the PR variable needs to be increased (or "bumped") as part of
6751that commit. For new recipes you should add the ``PR`` variable and set
6752its initial value equal to "r0", which is the default. Even though the
6753default value is "r0", the practice of adding it to a new recipe makes
6754it harder to forget to bump the variable when you make changes to the
6755recipe in future.
6756
6757If you are sharing a common ``.inc`` file with multiple recipes, you can
6758also use the ``INC_PR`` variable to ensure that the recipes sharing the
6759``.inc`` file are rebuilt when the ``.inc`` file itself is changed. The
6760``.inc`` file must set ``INC_PR`` (initially to "r0"), and all recipes
6761referring to it should set ``PR`` to "${INC_PR}.0" initially,
6762incrementing the last number when the recipe is changed. If the ``.inc``
6763file is changed then its ``INC_PR`` should be incremented.
6764
6765When upgrading the version of a binary package, assuming the ``PV``
6766changes, the ``PR`` variable should be reset to "r0" (or "${INC_PR}.0"
6767if you are using ``INC_PR``).
6768
6769Usually, version increases occur only to binary packages. However, if
6770for some reason ``PV`` changes but does not increase, you can increase
6771the ``PE`` variable (Package Epoch). The ``PE`` variable defaults to
6772"0".
6773
6774Binary package version numbering strives to follow the `Debian Version
6775Field Policy
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006776Guidelines <https://www.debian.org/doc/debian-policy/ch-controlfields.html>`__.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006777These guidelines define how versions are compared and what "increasing"
6778a version means.
6779
6780.. _automatically-incrementing-a-binary-package-revision-number:
6781
6782Automatically Incrementing a Package Version Number
6783~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6784
6785When fetching a repository, BitBake uses the
6786:term:`SRCREV` variable to determine
6787the specific source code revision from which to build. You set the
6788``SRCREV`` variable to
6789:term:`AUTOREV` to cause the
6790OpenEmbedded build system to automatically use the latest revision of
6791the software:
6792::
6793
6794 SRCREV = "${AUTOREV}"
6795
6796Furthermore, you need to reference ``SRCPV`` in ``PV`` in order to
6797automatically update the version whenever the revision of the source
6798code changes. Here is an example:
6799::
6800
6801 PV = "1.0+git${SRCPV}"
6802
6803The OpenEmbedded build system substitutes ``SRCPV`` with the following:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006804
6805.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006806
6807 AUTOINC+source_code_revision
6808
6809The build system replaces the ``AUTOINC``
6810with a number. The number used depends on the state of the PR Service:
6811
6812- If PR Service is enabled, the build system increments the number,
6813 which is similar to the behavior of
6814 :term:`PR`. This behavior results in
6815 linearly increasing package versions, which is desirable. Here is an
6816 example:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006817
6818 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006819
6820 hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
6821 hello-world-git_0.0+git1+dd2f5c3565-r0.0_armv7a-neon.ipk
6822
6823- If PR Service is not enabled, the build system replaces the
6824 ``AUTOINC`` placeholder with zero (i.e. "0"). This results in
6825 changing the package version since the source revision is included.
6826 However, package versions are not increased linearly. Here is an
6827 example:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006828
6829 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006830
6831 hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk
6832 hello-world-git_0.0+git0+dd2f5c3565-r0.0_armv7a-neon.ipk
6833
6834In summary, the OpenEmbedded build system does not track the history of
6835binary package versions for this purpose. ``AUTOINC``, in this case, is
6836comparable to ``PR``. If PR server is not enabled, ``AUTOINC`` in the
6837package version is simply replaced by "0". If PR server is enabled, the
6838build system keeps track of the package versions and bumps the number
6839when the package revision changes.
6840
6841Handling Optional Module Packaging
6842----------------------------------
6843
6844Many pieces of software split functionality into optional modules (or
6845plugins) and the plugins that are built might depend on configuration
6846options. To avoid having to duplicate the logic that determines what
6847modules are available in your recipe or to avoid having to package each
6848module by hand, the OpenEmbedded build system provides functionality to
6849handle module packaging dynamically.
6850
6851To handle optional module packaging, you need to do two things:
6852
6853- Ensure the module packaging is actually done.
6854
6855- Ensure that any dependencies on optional modules from other recipes
6856 are satisfied by your recipe.
6857
6858Making Sure the Packaging is Done
6859~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6860
6861To ensure the module packaging actually gets done, you use the
6862``do_split_packages`` function within the ``populate_packages`` Python
6863function in your recipe. The ``do_split_packages`` function searches for
6864a pattern of files or directories under a specified path and creates a
6865package for each one it finds by appending to the
6866:term:`PACKAGES` variable and
6867setting the appropriate values for ``FILES_packagename``,
6868``RDEPENDS_packagename``, ``DESCRIPTION_packagename``, and so forth.
6869Here is an example from the ``lighttpd`` recipe:
6870::
6871
6872 python populate_packages_prepend () {
6873 lighttpd_libdir = d.expand('${libdir}')
6874 do_split_packages(d, lighttpd_libdir, '^mod_(.*).so$',
6875 'lighttpd-module-%s', 'Lighttpd module for %s',
6876 extra_depends='')
6877 }
6878
6879The previous example specifies a number of things in the call to
6880``do_split_packages``.
6881
6882- A directory within the files installed by your recipe through
6883 ``do_install`` in which to search.
6884
6885- A regular expression used to match module files in that directory. In
6886 the example, note the parentheses () that mark the part of the
6887 expression from which the module name should be derived.
6888
6889- A pattern to use for the package names.
6890
6891- A description for each package.
6892
6893- An empty string for ``extra_depends``, which disables the default
6894 dependency on the main ``lighttpd`` package. Thus, if a file in
6895 ``${libdir}`` called ``mod_alias.so`` is found, a package called
6896 ``lighttpd-module-alias`` is created for it and the
6897 :term:`DESCRIPTION` is set to
6898 "Lighttpd module for alias".
6899
6900Often, packaging modules is as simple as the previous example. However,
6901more advanced options exist that you can use within
6902``do_split_packages`` to modify its behavior. And, if you need to, you
6903can add more logic by specifying a hook function that is called for each
6904package. It is also perfectly acceptable to call ``do_split_packages``
6905multiple times if you have more than one set of modules to package.
6906
6907For more examples that show how to use ``do_split_packages``, see the
6908``connman.inc`` file in the ``meta/recipes-connectivity/connman/``
6909directory of the ``poky`` :ref:`source repository <yocto-project-repositories>`. You can
6910also find examples in ``meta/classes/kernel.bbclass``.
6911
6912Following is a reference that shows ``do_split_packages`` mandatory and
6913optional arguments:
6914::
6915
6916 Mandatory arguments
6917
6918 root
6919 The path in which to search
6920 file_regex
6921 Regular expression to match searched files.
6922 Use parentheses () to mark the part of this
6923 expression that should be used to derive the
6924 module name (to be substituted where %s is
6925 used in other function arguments as noted below)
6926 output_pattern
6927 Pattern to use for the package names. Must
6928 include %s.
6929 description
6930 Description to set for each package. Must
6931 include %s.
6932
6933 Optional arguments
6934
6935 postinst
6936 Postinstall script to use for all packages
6937 (as a string)
6938 recursive
6939 True to perform a recursive search - default
6940 False
6941 hook
6942 A hook function to be called for every match.
6943 The function will be called with the following
6944 arguments (in the order listed):
6945
6946 f
6947 Full path to the file/directory match
6948 pkg
6949 The package name
6950 file_regex
6951 As above
6952 output_pattern
6953 As above
6954 modulename
6955 The module name derived using file_regex
Andrew Geissler4c19ea12020-10-27 13:52:24 -05006956 extra_depends
Andrew Geisslerc9f78652020-09-18 14:11:35 -05006957 Extra runtime dependencies (RDEPENDS) to be
6958 set for all packages. The default value of None
6959 causes a dependency on the main package
6960 (${PN}) - if you do not want this, pass empty
6961 string '' for this parameter.
6962 aux_files_pattern
6963 Extra item(s) to be added to FILES for each
6964 package. Can be a single string item or a list
6965 of strings for multiple items. Must include %s.
6966 postrm
6967 postrm script to use for all packages (as a
6968 string)
6969 allow_dirs
6970 True to allow directories to be matched -
6971 default False
6972 prepend
6973 If True, prepend created packages to PACKAGES
6974 instead of the default False which appends them
6975 match_path
6976 match file_regex on the whole relative path to
6977 the root rather than just the file name
6978 aux_files_pattern_verbatim
6979 Extra item(s) to be added to FILES for each
6980 package, using the actual derived module name
6981 rather than converting it to something legal
6982 for a package name. Can be a single string item
6983 or a list of strings for multiple items. Must
6984 include %s.
6985 allow_links
6986 True to allow symlinks to be matched - default
6987 False
6988 summary
6989 Summary to set for each package. Must include %s;
6990 defaults to description if not set.
6991
6992
6993
6994Satisfying Dependencies
6995~~~~~~~~~~~~~~~~~~~~~~~
6996
6997The second part for handling optional module packaging is to ensure that
6998any dependencies on optional modules from other recipes are satisfied by
6999your recipe. You can be sure these dependencies are satisfied by using
7000the :term:`PACKAGES_DYNAMIC`
7001variable. Here is an example that continues with the ``lighttpd`` recipe
7002shown earlier:
7003::
7004
7005 PACKAGES_DYNAMIC = "lighttpd-module-.*"
7006
7007The name
7008specified in the regular expression can of course be anything. In this
7009example, it is ``lighttpd-module-`` and is specified as the prefix to
7010ensure that any :term:`RDEPENDS` and
7011:term:`RRECOMMENDS` on a package
7012name starting with the prefix are satisfied during build time. If you
7013are using ``do_split_packages`` as described in the previous section,
7014the value you put in ``PACKAGES_DYNAMIC`` should correspond to the name
7015pattern specified in the call to ``do_split_packages``.
7016
7017Using Runtime Package Management
7018--------------------------------
7019
7020During a build, BitBake always transforms a recipe into one or more
7021packages. For example, BitBake takes the ``bash`` recipe and produces a
7022number of packages (e.g. ``bash``, ``bash-bashbug``,
7023``bash-completion``, ``bash-completion-dbg``, ``bash-completion-dev``,
7024``bash-completion-extra``, ``bash-dbg``, and so forth). Not all
7025generated packages are included in an image.
7026
7027In several situations, you might need to update, add, remove, or query
7028the packages on a target device at runtime (i.e. without having to
7029generate a new image). Examples of such situations include:
7030
7031- You want to provide in-the-field updates to deployed devices (e.g.
7032 security updates).
7033
7034- You want to have a fast turn-around development cycle for one or more
7035 applications that run on your device.
7036
7037- You want to temporarily install the "debug" packages of various
7038 applications on your device so that debugging can be greatly improved
7039 by allowing access to symbols and source debugging.
7040
7041- You want to deploy a more minimal package selection of your device
7042 but allow in-the-field updates to add a larger selection for
7043 customization.
7044
7045In all these situations, you have something similar to a more
7046traditional Linux distribution in that in-field devices are able to
7047receive pre-compiled packages from a server for installation or update.
7048Being able to install these packages on a running, in-field device is
7049what is termed "runtime package management".
7050
7051In order to use runtime package management, you need a host or server
7052machine that serves up the pre-compiled packages plus the required
7053metadata. You also need package manipulation tools on the target. The
7054build machine is a likely candidate to act as the server. However, that
7055machine does not necessarily have to be the package server. The build
7056machine could push its artifacts to another machine that acts as the
7057server (e.g. Internet-facing). In fact, doing so is advantageous for a
7058production environment as getting the packages away from the development
7059system's build directory prevents accidental overwrites.
7060
7061A simple build that targets just one device produces more than one
7062package database. In other words, the packages produced by a build are
7063separated out into a couple of different package groupings based on
7064criteria such as the target's CPU architecture, the target board, or the
7065C library used on the target. For example, a build targeting the
7066``qemux86`` device produces the following three package databases:
7067``noarch``, ``i586``, and ``qemux86``. If you wanted your ``qemux86``
7068device to be aware of all the packages that were available to it, you
7069would need to point it to each of these databases individually. In a
7070similar way, a traditional Linux distribution usually is configured to
7071be aware of a number of software repositories from which it retrieves
7072packages.
7073
7074Using runtime package management is completely optional and not required
7075for a successful build or deployment in any way. But if you want to make
7076use of runtime package management, you need to do a couple things above
7077and beyond the basics. The remainder of this section describes what you
7078need to do.
7079
7080.. _runtime-package-management-build:
7081
7082Build Considerations
7083~~~~~~~~~~~~~~~~~~~~
7084
7085This section describes build considerations of which you need to be
7086aware in order to provide support for runtime package management.
7087
7088When BitBake generates packages, it needs to know what format or formats
7089to use. In your configuration, you use the
7090:term:`PACKAGE_CLASSES`
7091variable to specify the format:
7092
70931. Open the ``local.conf`` file inside your
7094 :term:`Build Directory` (e.g.
7095 ``~/poky/build/conf/local.conf``).
7096
70972. Select the desired package format as follows:
7098 ::
7099
7100 PACKAGE_CLASSES ?= "package_packageformat"
7101
7102 where packageformat can be "ipk", "rpm",
7103 "deb", or "tar" which are the supported package formats.
7104
7105 .. note::
7106
7107 Because the Yocto Project supports four different package formats,
7108 you can set the variable with more than one argument. However, the
7109 OpenEmbedded build system only uses the first argument when
7110 creating an image or Software Development Kit (SDK).
7111
7112If you would like your image to start off with a basic package database
7113containing the packages in your current build as well as to have the
7114relevant tools available on the target for runtime package management,
7115you can include "package-management" in the
7116:term:`IMAGE_FEATURES`
7117variable. Including "package-management" in this configuration variable
7118ensures that when the image is assembled for your target, the image
7119includes the currently-known package databases as well as the
7120target-specific tools required for runtime package management to be
7121performed on the target. However, this is not strictly necessary. You
7122could start your image off without any databases but only include the
7123required on-target package tool(s). As an example, you could include
7124"opkg" in your
7125:term:`IMAGE_INSTALL` variable
7126if you are using the IPK package format. You can then initialize your
7127target's package database(s) later once your image is up and running.
7128
7129Whenever you perform any sort of build step that can potentially
7130generate a package or modify existing package, it is always a good idea
7131to re-generate the package index after the build by using the following
7132command:
7133::
7134
7135 $ bitbake package-index
7136
7137It might be tempting to build the
7138package and the package index at the same time with a command such as
7139the following:
7140::
7141
7142 $ bitbake some-package package-index
7143
7144Do not do this as
7145BitBake does not schedule the package index for after the completion of
7146the package you are building. Consequently, you cannot be sure of the
7147package index including information for the package you just built.
7148Thus, be sure to run the package update step separately after building
7149any packages.
7150
7151You can use the
7152:term:`PACKAGE_FEED_ARCHS`,
7153:term:`PACKAGE_FEED_BASE_PATHS`,
7154and
7155:term:`PACKAGE_FEED_URIS`
7156variables to pre-configure target images to use a package feed. If you
7157do not define these variables, then manual steps as described in the
7158subsequent sections are necessary to configure the target. You should
7159set these variables before building the image in order to produce a
7160correctly configured image.
7161
7162When your build is complete, your packages reside in the
7163``${TMPDIR}/deploy/packageformat`` directory. For example, if
7164``${``\ :term:`TMPDIR`\ ``}`` is
7165``tmp`` and your selected package type is RPM, then your RPM packages
7166are available in ``tmp/deploy/rpm``.
7167
7168.. _runtime-package-management-server:
7169
7170Host or Server Machine Setup
7171~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7172
7173Although other protocols are possible, a server using HTTP typically
7174serves packages. If you want to use HTTP, then set up and configure a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007175web server such as Apache 2, lighttpd, or Python web server on the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007176machine serving the packages.
7177
7178To keep things simple, this section describes how to set up a
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007179Python web server to share package feeds from the developer's
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007180machine. Although this server might not be the best for a production
7181environment, the setup is simple and straight forward. Should you want
7182to use a different server more suited for production (e.g. Apache 2,
7183Lighttpd, or Nginx), take the appropriate steps to do so.
7184
7185From within the build directory where you have built an image based on
7186your packaging choice (i.e. the
7187:term:`PACKAGE_CLASSES`
7188setting), simply start the server. The following example assumes a build
7189directory of ``~/poky/build/tmp/deploy/rpm`` and a ``PACKAGE_CLASSES``
7190setting of "package_rpm":
7191::
7192
7193 $ cd ~/poky/build/tmp/deploy/rpm
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007194 $ python3 -m http.server
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007195
7196.. _runtime-package-management-target:
7197
7198Target Setup
7199~~~~~~~~~~~~
7200
7201Setting up the target differs depending on the package management
7202system. This section provides information for RPM, IPK, and DEB.
7203
7204.. _runtime-package-management-target-rpm:
7205
7206Using RPM
7207^^^^^^^^^
7208
7209The `Dandified Packaging
7210Tool <https://en.wikipedia.org/wiki/DNF_(software)>`__ (DNF) performs
7211runtime package management of RPM packages. In order to use DNF for
7212runtime package management, you must perform an initial setup on the
7213target machine for cases where the ``PACKAGE_FEED_*`` variables were not
7214set as part of the image that is running on the target. This means if
7215you built your image and did not not use these variables as part of the
7216build and your image is now running on the target, you need to perform
7217the steps in this section if you want to use runtime package management.
7218
7219.. note::
7220
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007221 For information on the ``PACKAGE_FEED_*`` variables, see
7222 :term:`PACKAGE_FEED_ARCHS`, :term:`PACKAGE_FEED_BASE_PATHS`, and
7223 :term:`PACKAGE_FEED_URIS` in the Yocto Project Reference Manual variables
7224 glossary.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007225
7226On the target, you must inform DNF that package databases are available.
7227You do this by creating a file named
7228``/etc/yum.repos.d/oe-packages.repo`` and defining the ``oe-packages``.
7229
7230As an example, assume the target is able to use the following package
7231databases: ``all``, ``i586``, and ``qemux86`` from a server named
7232``my.server``. The specifics for setting up the web server are up to
7233you. The critical requirement is that the URIs in the target repository
7234configuration point to the correct remote location for the feeds.
7235
7236.. note::
7237
7238 For development purposes, you can point the web server to the build
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007239 system's ``deploy`` directory. However, for production use, it is better to
7240 copy the package directories to a location outside of the build area and use
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007241 that location. Doing so avoids situations where the build system
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007242 overwrites or changes the ``deploy`` directory.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007243
7244When telling DNF where to look for the package databases, you must
7245declare individual locations per architecture or a single location used
7246for all architectures. You cannot do both:
7247
7248- *Create an Explicit List of Architectures:* Define individual base
7249 URLs to identify where each package database is located:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007250
7251 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007252
7253 [oe-packages]
7254 baseurl=http://my.server/rpm/i586 http://my.server/rpm/qemux86 http://my.server/rpm/all
7255
7256 This example
7257 informs DNF about individual package databases for all three
7258 architectures.
7259
7260- *Create a Single (Full) Package Index:* Define a single base URL that
7261 identifies where a full package database is located:
7262 ::
7263
7264 [oe-packages]
7265 baseurl=http://my.server/rpm
7266
7267 This example informs DNF about a single
7268 package database that contains all the package index information for
7269 all supported architectures.
7270
7271Once you have informed DNF where to find the package databases, you need
7272to fetch them:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007273
7274.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007275
7276 # dnf makecache
7277
7278DNF is now able to find, install, and
7279upgrade packages from the specified repository or repositories.
7280
7281.. note::
7282
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007283 See the `DNF documentation <https://dnf.readthedocs.io/en/latest/>`__ for
7284 additional information.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007285
7286.. _runtime-package-management-target-ipk:
7287
7288Using IPK
7289^^^^^^^^^
7290
7291The ``opkg`` application performs runtime package management of IPK
7292packages. You must perform an initial setup for ``opkg`` on the target
7293machine if the
7294:term:`PACKAGE_FEED_ARCHS`,
7295:term:`PACKAGE_FEED_BASE_PATHS`,
7296and
7297:term:`PACKAGE_FEED_URIS`
7298variables have not been set or the target image was built before the
7299variables were set.
7300
7301The ``opkg`` application uses configuration files to find available
7302package databases. Thus, you need to create a configuration file inside
7303the ``/etc/opkg/`` direction, which informs ``opkg`` of any repository
7304you want to use.
7305
7306As an example, suppose you are serving packages from a ``ipk/``
7307directory containing the ``i586``, ``all``, and ``qemux86`` databases
7308through an HTTP server named ``my.server``. On the target, create a
7309configuration file (e.g. ``my_repo.conf``) inside the ``/etc/opkg/``
7310directory containing the following:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007311
7312.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007313
7314 src/gz all http://my.server/ipk/all
7315 src/gz i586 http://my.server/ipk/i586
7316 src/gz qemux86 http://my.server/ipk/qemux86
7317
7318Next, instruct ``opkg`` to fetch the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007319repository information:
7320
7321.. code-block:: none
7322
7323 # opkg update
7324
7325The ``opkg`` application is now able to find, install, and upgrade packages
7326from the specified repository.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007327
7328.. _runtime-package-management-target-deb:
7329
7330Using DEB
7331^^^^^^^^^
7332
7333The ``apt`` application performs runtime package management of DEB
7334packages. This application uses a source list file to find available
7335package databases. You must perform an initial setup for ``apt`` on the
7336target machine if the
7337:term:`PACKAGE_FEED_ARCHS`,
7338:term:`PACKAGE_FEED_BASE_PATHS`,
7339and
7340:term:`PACKAGE_FEED_URIS`
7341variables have not been set or the target image was built before the
7342variables were set.
7343
7344To inform ``apt`` of the repository you want to use, you might create a
7345list file (e.g. ``my_repo.list``) inside the
7346``/etc/apt/sources.list.d/`` directory. As an example, suppose you are
7347serving packages from a ``deb/`` directory containing the ``i586``,
7348``all``, and ``qemux86`` databases through an HTTP server named
7349``my.server``. The list file should contain:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007350
7351.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007352
7353 deb http://my.server/deb/all ./
7354 deb http://my.server/deb/i586 ./
7355 deb http://my.server/deb/qemux86 ./
7356
7357Next, instruct the ``apt`` application
7358to fetch the repository information:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007359
7360.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007361
7362 # apt-get update
7363
7364After this step,
7365``apt`` is able to find, install, and upgrade packages from the
7366specified repository.
7367
7368Generating and Using Signed Packages
7369------------------------------------
7370
7371In order to add security to RPM packages used during a build, you can
7372take steps to securely sign them. Once a signature is verified, the
7373OpenEmbedded build system can use the package in the build. If security
7374fails for a signed package, the build system aborts the build.
7375
7376This section describes how to sign RPM packages during a build and how
7377to use signed package feeds (repositories) when doing a build.
7378
7379Signing RPM Packages
7380~~~~~~~~~~~~~~~~~~~~
7381
7382To enable signing RPM packages, you must set up the following
7383configurations in either your ``local.config`` or ``distro.config``
7384file:
7385::
7386
7387 # Inherit sign_rpm.bbclass to enable signing functionality
7388 INHERIT += " sign_rpm"
7389 # Define the GPG key that will be used for signing.
7390 RPM_GPG_NAME = "key_name"
7391 # Provide passphrase for the key
7392 RPM_GPG_PASSPHRASE = "passphrase"
7393
7394.. note::
7395
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007396 Be sure to supply appropriate values for both `key_name` and
7397 `passphrase`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007398
7399Aside from the ``RPM_GPG_NAME`` and ``RPM_GPG_PASSPHRASE`` variables in
7400the previous example, two optional variables related to signing exist:
7401
7402- *GPG_BIN:* Specifies a ``gpg`` binary/wrapper that is executed
7403 when the package is signed.
7404
7405- *GPG_PATH:* Specifies the ``gpg`` home directory used when the
7406 package is signed.
7407
7408Processing Package Feeds
7409~~~~~~~~~~~~~~~~~~~~~~~~
7410
7411In addition to being able to sign RPM packages, you can also enable
7412signed package feeds for IPK and RPM packages.
7413
7414The steps you need to take to enable signed package feed use are similar
7415to the steps used to sign RPM packages. You must define the following in
7416your ``local.config`` or ``distro.config`` file:
7417::
7418
7419 INHERIT += "sign_package_feed"
7420 PACKAGE_FEED_GPG_NAME = "key_name"
7421 PACKAGE_FEED_GPG_PASSPHRASE_FILE = "path_to_file_containing_passphrase"
7422
7423For signed package feeds, the passphrase must exist in a separate file,
7424which is pointed to by the ``PACKAGE_FEED_GPG_PASSPHRASE_FILE``
7425variable. Regarding security, keeping a plain text passphrase out of the
7426configuration is more secure.
7427
7428Aside from the ``PACKAGE_FEED_GPG_NAME`` and
7429``PACKAGE_FEED_GPG_PASSPHRASE_FILE`` variables, three optional variables
7430related to signed package feeds exist:
7431
7432- *GPG_BIN* Specifies a ``gpg`` binary/wrapper that is executed
7433 when the package is signed.
7434
7435- *GPG_PATH:* Specifies the ``gpg`` home directory used when the
7436 package is signed.
7437
7438- *PACKAGE_FEED_GPG_SIGNATURE_TYPE:* Specifies the type of ``gpg``
7439 signature. This variable applies only to RPM and IPK package feeds.
7440 Allowable values for the ``PACKAGE_FEED_GPG_SIGNATURE_TYPE`` are
7441 "ASC", which is the default and specifies ascii armored, and "BIN",
7442 which specifies binary.
7443
7444Testing Packages With ptest
7445---------------------------
7446
7447A Package Test (ptest) runs tests against packages built by the
7448OpenEmbedded build system on the target machine. A ptest contains at
7449least two items: the actual test, and a shell script (``run-ptest``)
7450that starts the test. The shell script that starts the test must not
7451contain the actual test - the script only starts the test. On the other
7452hand, the test can be anything from a simple shell script that runs a
7453binary and checks the output to an elaborate system of test binaries and
7454data files.
7455
7456The test generates output in the format used by Automake:
7457::
7458
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,
7465see the :yocto_wiki:`Ptest </wiki/Ptest>` wiki page.
7466
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
7479:term:`Build Directory`:
7480::
7481
7482 DISTRO_FEATURES_append = " ptest"
7483 EXTRA_IMAGE_FEATURES += "ptest-pkgs"
7484
7485Once your build is complete, the ptest files are installed into the
7486``/usr/lib/package/ptest`` directory within the image, where ``package``
7487is the name of the package.
7488
7489Running ptest
7490~~~~~~~~~~~~~
7491
7492The ``ptest-runner`` package installs a shell script that loops through
7493all installed ptest test suites and runs them in sequence. Consequently,
7494you might want to add this package to your image.
7495
7496Getting Your Package Ready
7497~~~~~~~~~~~~~~~~~~~~~~~~~~
7498
7499In order to enable a recipe to run installed ptests on target hardware,
7500you need to prepare the recipes that build the packages you want to
7501test. Here is what you have to do for each recipe:
7502
7503- *Be sure the recipe inherits
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007504 the* :ref:`ptest <ref-classes-ptest>` *class:*
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007505 Include the following line in each recipe:
7506 ::
7507
7508 inherit ptest
7509
7510- *Create run-ptest:* This script starts your test. Locate the
7511 script where you will refer to it using
7512 :term:`SRC_URI`. Here is an
7513 example that starts a test for ``dbus``:
7514 ::
7515
7516 #!/bin/sh
7517 cd test
7518 make -k runtest-TESTS
7519
7520- *Ensure dependencies are met:* If the test adds build or runtime
7521 dependencies that normally do not exist for the package (such as
7522 requiring "make" to run the test suite), use the
7523 :term:`DEPENDS` and
7524 :term:`RDEPENDS` variables in
7525 your recipe in order for the package to meet the dependencies. Here
7526 is an example where the package has a runtime dependency on "make":
7527 ::
7528
7529 RDEPENDS_${PN}-ptest += "make"
7530
7531- *Add a function to build the test suite:* Not many packages support
7532 cross-compilation of their test suites. Consequently, you usually
7533 need to add a cross-compilation function to the package.
7534
7535 Many packages based on Automake compile and run the test suite by
7536 using a single command such as ``make check``. However, the host
7537 ``make check`` builds and runs on the same computer, while
7538 cross-compiling requires that the package is built on the host but
7539 executed for the target architecture (though often, as in the case
7540 for ptest, the execution occurs on the host). The built version of
7541 Automake that ships with the Yocto Project includes a patch that
7542 separates building and execution. Consequently, packages that use the
7543 unaltered, patched version of ``make check`` automatically
7544 cross-compiles.
7545
7546 Regardless, you still must add a ``do_compile_ptest`` function to
7547 build the test suite. Add a function similar to the following to your
7548 recipe:
7549 ::
7550
7551 do_compile_ptest() {
7552 oe_runmake buildtest-TESTS
7553 }
7554
7555- *Ensure special configurations are set:* If the package requires
7556 special configurations prior to compiling the test code, you must
7557 insert a ``do_configure_ptest`` function into the recipe.
7558
7559- *Install the test suite:* The ``ptest`` class automatically copies
7560 the file ``run-ptest`` to the target and then runs make
7561 ``install-ptest`` to run the tests. If this is not enough, you need
7562 to create a ``do_install_ptest`` function and make sure it gets
7563 called after the "make install-ptest" completes.
7564
7565Creating Node Package Manager (NPM) Packages
7566--------------------------------------------
7567
7568`NPM <https://en.wikipedia.org/wiki/Npm_(software)>`__ is a package
7569manager for the JavaScript programming language. The Yocto Project
7570supports the NPM :ref:`fetcher <bitbake:bb-fetchers>`. You can
7571use this fetcher in combination with
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007572:doc:`devtool <../ref-manual/ref-devtool-reference>` to create
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007573recipes that produce NPM packages.
7574
7575Two workflows exist that allow you to create NPM packages using
7576``devtool``: the NPM registry modules method and the NPM project code
7577method.
7578
7579.. note::
7580
7581 While it is possible to create NPM recipes manually, using
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007582 ``devtool`` is far simpler.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007583
7584Additionally, some requirements and caveats exist.
7585
7586.. _npm-package-creation-requirements:
7587
7588Requirements and Caveats
7589~~~~~~~~~~~~~~~~~~~~~~~~
7590
7591You need to be aware of the following before using ``devtool`` to create
7592NPM packages:
7593
7594- Of the two methods that you can use ``devtool`` to create NPM
7595 packages, the registry approach is slightly simpler. However, you
7596 might consider the project approach because you do not have to
7597 publish your module in the NPM registry
7598 (`npm-registry <https://docs.npmjs.com/misc/registry>`_), which
7599 is NPM's public registry.
7600
7601- Be familiar with
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007602 :doc:`devtool <../ref-manual/ref-devtool-reference>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007603
7604- The NPM host tools need the native ``nodejs-npm`` package, which is
7605 part of the OpenEmbedded environment. You need to get the package by
7606 cloning the https://github.com/openembedded/meta-openembedded
7607 repository out of GitHub. Be sure to add the path to your local copy
7608 to your ``bblayers.conf`` file.
7609
7610- ``devtool`` cannot detect native libraries in module dependencies.
7611 Consequently, you must manually add packages to your recipe.
7612
7613- While deploying NPM packages, ``devtool`` cannot determine which
7614 dependent packages are missing on the target (e.g. the node runtime
7615 ``nodejs``). Consequently, you need to find out what files are
7616 missing and be sure they are on the target.
7617
7618- Although you might not need NPM to run your node package, it is
7619 useful to have NPM on your target. The NPM package name is
7620 ``nodejs-npm``.
7621
7622.. _npm-using-the-registry-modules-method:
7623
7624Using the Registry Modules Method
7625~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7626
7627This section presents an example that uses the ``cute-files`` module,
7628which is a file browser web application.
7629
7630.. note::
7631
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007632 You must know the ``cute-files`` module version.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007633
7634The first thing you need to do is use ``devtool`` and the NPM fetcher to
7635create the recipe:
7636::
7637
7638 $ devtool add "npm://registry.npmjs.org;package=cute-files;version=1.0.2"
7639
7640The
7641``devtool add`` command runs ``recipetool create`` and uses the same
7642fetch URI to download each dependency and capture license details where
7643possible. The result is a generated recipe.
7644
7645The recipe file is fairly simple and contains every license that
7646``recipetool`` finds and includes the licenses in the recipe's
7647:term:`LIC_FILES_CHKSUM`
7648variables. You need to examine the variables and look for those with
7649"unknown" in the :term:`LICENSE`
7650field. You need to track down the license information for "unknown"
7651modules and manually add the information to the recipe.
7652
7653``recipetool`` creates a "shrinkwrap" file for your recipe. Shrinkwrap
7654files capture the version of all dependent modules. Many packages do not
7655provide shrinkwrap files. ``recipetool`` create a shrinkwrap file as it
7656runs.
7657
7658.. note::
7659
7660 A package is created for each sub-module. This policy is the only
7661 practical way to have the licenses for all of the dependencies
7662 represented in the license manifest of the image.
7663
7664The ``devtool edit-recipe`` command lets you take a look at the recipe:
7665::
7666
7667 $ devtool edit-recipe cute-files
7668 SUMMARY = "Turn any folder on your computer into a cute file browser, available on the local network."
7669 LICENSE = "MIT & ISC & Unknown"
7670 LIC_FILES_CHKSUM = "file://LICENSE;md5=71d98c0a1db42956787b1909c74a86ca \
7671 file://node_modules/toidentifier/LICENSE;md5=1a261071a044d02eb6f2bb47f51a3502 \
7672 file://node_modules/debug/LICENSE;md5=ddd815a475e7338b0be7a14d8ee35a99 \
7673 ...
7674 SRC_URI = " \
7675 npm://registry.npmjs.org/;package=cute-files;version=${PV} \
7676 npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \
7677 "
7678 S = "${WORKDIR}/npm"
7679 inherit npm LICENSE_${PN} = "MIT"
7680 LICENSE_${PN}-accepts = "MIT"
7681 LICENSE_${PN}-array-flatten = "MIT"
7682 ...
7683 LICENSE_${PN}-vary = "MIT"
7684
7685Three key points exist in the previous example:
7686
7687- :term:`SRC_URI` uses the NPM
7688 scheme so that the NPM fetcher is used.
7689
7690- ``recipetool`` collects all the license information. If a
7691 sub-module's license is unavailable, the sub-module's name appears in
7692 the comments.
7693
7694- The ``inherit npm`` statement causes the
7695 :ref:`npm <ref-classes-npm>` class to package
7696 up all the modules.
7697
7698You can run the following command to build the ``cute-files`` package:
7699::
7700
7701 $ devtool build cute-files
7702
7703Remember that ``nodejs`` must be installed on
7704the target before your package.
7705
7706Assuming 192.168.7.2 for the target's IP address, use the following
7707command to deploy your package:
7708::
7709
7710 $ devtool deploy-target -s cute-files root@192.168.7.2
7711
7712Once the package is installed on the target, you can
7713test the application:
7714
7715.. note::
7716
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007717 Because of a known issue, you cannot simply run ``cute-files`` as you would
7718 if you had run ``npm install``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007719
7720::
7721
7722 $ cd /usr/lib/node_modules/cute-files
7723 $ node cute-files.js
7724
7725On a browser,
7726go to ``http://192.168.7.2:3000`` and you see the following:
7727
7728.. image:: figures/cute-files-npm-example.png
7729 :align: center
7730
7731You can find the recipe in ``workspace/recipes/cute-files``. You can use
7732the recipe in any layer you choose.
7733
7734.. _npm-using-the-npm-projects-method:
7735
7736Using the NPM Projects Code Method
7737~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7738
7739Although it is useful to package modules already in the NPM registry,
7740adding ``node.js`` projects under development is a more common developer
7741use case.
7742
7743This section covers the NPM projects code method, which is very similar
7744to the "registry" approach described in the previous section. In the NPM
7745projects method, you provide ``devtool`` with an URL that points to the
7746source files.
7747
7748Replicating the same example, (i.e. ``cute-files``) use the following
7749command:
7750::
7751
7752 $ devtool add https://github.com/martinaglv/cute-files.git
7753
7754The
7755recipe this command generates is very similar to the recipe created in
7756the previous section. However, the ``SRC_URI`` looks like the following:
7757::
7758
7759 SRC_URI = " \
7760 git://github.com/martinaglv/cute-files.git;protocol=https \
7761 npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \
7762 "
7763
7764In this example,
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007765the main module is taken from the Git repository and dependencies are
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007766taken from the NPM registry. Other than those differences, the recipe is
7767basically the same between the two methods. You can build and deploy the
7768package exactly as described in the previous section that uses the
7769registry modules method.
7770
7771Adding custom metadata to packages
7772----------------------------------
7773
7774The variable
7775:term:`PACKAGE_ADD_METADATA`
7776can be used to add additional metadata to packages. This is reflected in
7777the package control/spec file. To take the ipk format for example, the
7778CONTROL file stored inside would contain the additional metadata as
7779additional lines.
7780
7781The variable can be used in multiple ways, including using suffixes to
7782set it for a specific package type and/or package. Note that the order
7783of precedence is the same as this list:
7784
7785- ``PACKAGE_ADD_METADATA_<PKGTYPE>_<PN>``
7786
7787- ``PACKAGE_ADD_METADATA_<PKGTYPE>``
7788
7789- ``PACKAGE_ADD_METADATA_<PN>``
7790
7791- ``PACKAGE_ADD_METADATA``
7792
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007793`<PKGTYPE>` is a parameter and expected to be a distinct name of specific
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007794package type:
7795
7796- IPK for .ipk packages
7797
7798- DEB for .deb packages
7799
7800- RPM for .rpm packages
7801
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007802`<PN>` is a parameter and expected to be a package name.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007803
7804The variable can contain multiple [one-line] metadata fields separated
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007805by the literal sequence '\\n'. The separator can be redefined using the
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007806variable flag ``separator``.
7807
7808The following is an example that adds two custom fields for ipk
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007809packages:
7810::
7811
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
7833build system (OpenEmbedded or Angstrom) for which you have built up a
7834sizable 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
7840Here is an efficient way to set it up in your ``local.conf`` file:
7841::
7842
7843 SOURCE_MIRROR_URL ?= "file:///home/you/your-download-dir/"
7844 INHERIT += "own-mirrors"
7845 BB_GENERATE_MIRROR_TARBALLS = "1"
7846 # BB_NO_NETWORK = "1"
7847
7848In the previous example, the
7849:term:`BB_GENERATE_MIRROR_TARBALLS`
7850variable causes the OpenEmbedded build system to generate tarballs of
7851the Git repositories and store them in the
7852:term:`DL_DIR` directory. Due to
7853performance reasons, generating and storing these tarballs is not the
7854build system's default behavior.
7855
7856You can also use the
7857:term:`PREMIRRORS` variable. For
7858an example, see the variable's glossary entry in the Yocto Project
7859Reference Manual.
7860
7861Getting Source Files and Suppressing the Build
7862----------------------------------------------
7863
7864Another technique you can use to ready yourself for a successive string
7865of build operations, is to pre-fetch all the source files without
7866actually starting a build. This technique lets you work through any
7867download issues and ultimately gathers all the source files into your
7868download directory :ref:`structure-build-downloads`,
7869which is located with :term:`DL_DIR`.
7870
7871Use the following BitBake command form to fetch all the necessary
7872sources without starting the build:
7873::
7874
7875 $ bitbake target --runall=fetch
7876
7877This
7878variation of the BitBake command guarantees that you have all the
7879sources for that BitBake target should you disconnect from the Internet
7880and want to do the build later offline.
7881
7882Selecting an Initialization Manager
7883===================================
7884
7885By default, the Yocto Project uses SysVinit as the initialization
7886manager. However, support also exists for systemd, which is a full
7887replacement for init with parallel starting of services, reduced shell
7888overhead and other features that are used by many distributions.
7889
7890Within the system, SysVinit treats system components as services. These
7891services are maintained as shell scripts stored in the ``/etc/init.d/``
7892directory. Services organize into different run levels. This
7893organization is maintained by putting links to the services in the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007894``/etc/rcN.d/`` directories, where `N/` is one of the following options:
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007895"S", "0", "1", "2", "3", "4", "5", or "6".
7896
7897.. note::
7898
7899 Each runlevel has a dependency on the previous runlevel. This
7900 dependency allows the services to work properly.
7901
7902In comparison, systemd treats components as units. Using units is a
7903broader concept as compared to using a service. A unit includes several
7904different types of entities. Service is one of the types of entities.
7905The runlevel concept in SysVinit corresponds to the concept of a target
7906in systemd, where target is also a type of supported unit.
7907
7908In a SysVinit-based system, services load sequentially (i.e. one by one)
Andrew Geissler4c19ea12020-10-27 13:52:24 -05007909during init and parallelization is not supported. With systemd, services
Andrew Geisslerc9f78652020-09-18 14:11:35 -05007910start in parallel. Needless to say, the method can have an impact on
7911system startup performance.
7912
7913If you want to use SysVinit, you do not have to do anything. But, if you
7914want to use systemd, you must take some steps as described in the
7915following sections.
7916
7917Using systemd Exclusively
7918-------------------------
7919
7920Set these variables in your distribution configuration file as follows:
7921::
7922
7923 DISTRO_FEATURES_append = " systemd"
7924 VIRTUAL-RUNTIME_init_manager = "systemd"
7925
7926You can also prevent the SysVinit distribution feature from
7927being automatically enabled as follows:
7928::
7929
7930 DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
7931
7932Doing so removes any
7933redundant SysVinit scripts.
7934
7935To remove initscripts from your image altogether, set this variable
7936also:
7937::
7938
7939 VIRTUAL-RUNTIME_initscripts = ""
7940
7941For information on the backfill variable, see
7942:term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`.
7943
7944Using systemd for the Main Image and Using SysVinit for the Rescue Image
7945------------------------------------------------------------------------
7946
7947Set these variables in your distribution configuration file as follows:
7948::
7949
7950 DISTRO_FEATURES_append = " systemd"
7951 VIRTUAL-RUNTIME_init_manager = "systemd"
7952
7953Doing so causes your main image to use the
7954``packagegroup-core-boot.bb`` recipe and systemd. The rescue/minimal
7955image cannot use this package group. However, it can install SysVinit
7956and the appropriate packages will have support for both systemd and
7957SysVinit.
7958
7959.. _selecting-dev-manager:
7960
7961Selecting a Device Manager
7962==========================
7963
7964The Yocto Project provides multiple ways to manage the device manager
7965(``/dev``):
7966
7967- Persistent and Pre-Populated\ ``/dev``: For this case, the ``/dev``
7968 directory is persistent and the required device nodes are created
7969 during the build.
7970
7971- Use ``devtmpfs`` with a Device Manager: For this case, the ``/dev``
7972 directory is provided by the kernel as an in-memory file system and
7973 is automatically populated by the kernel at runtime. Additional
7974 configuration of device nodes is done in user space by a device
7975 manager like ``udev`` or ``busybox-mdev``.
7976
7977.. _static-dev-management:
7978
7979Using Persistent and Pre-Populated\ ``/dev``
7980--------------------------------------------
7981
7982To use the static method for device population, you need to set the
7983:term:`USE_DEVFS` variable to "0"
7984as follows:
7985::
7986
7987 USE_DEVFS = "0"
7988
7989The content of the resulting ``/dev`` directory is defined in a Device
7990Table file. The
7991:term:`IMAGE_DEVICE_TABLES`
7992variable defines the Device Table to use and should be set in the
7993machine or distro configuration file. Alternatively, you can set this
7994variable in your ``local.conf`` configuration file.
7995
7996If you do not define the ``IMAGE_DEVICE_TABLES`` variable, the default
7997``device_table-minimal.txt`` is used:
7998::
7999
8000 IMAGE_DEVICE_TABLES = "device_table-mymachine.txt"
8001
8002The population is handled by the ``makedevs`` utility during image
8003creation:
8004
8005.. _devtmpfs-dev-management:
8006
8007Using ``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`
8012variable to "1", which is the default:
8013::
8014
8015 USE_DEVFS = "1"
8016
8017With this
8018setting, the resulting ``/dev`` directory is populated by the kernel
8019using ``devtmpfs``. Make sure the corresponding kernel configuration
8020variable ``CONFIG_DEVTMPFS`` is set when building you build a Linux
8021kernel.
8022
8023All devices created by ``devtmpfs`` will be owned by ``root`` and have
8024permissions ``0600``.
8025
8026To have more control over the device nodes, you can use a device manager
8027like ``udev`` or ``busybox-mdev``. You choose the device manager by
8028defining the ``VIRTUAL-RUNTIME_dev_manager`` variable in your machine or
8029distro configuration file. Alternatively, you can set this variable in
8030your ``local.conf`` configuration file:
8031::
8032
8033 VIRTUAL-RUNTIME_dev_manager = "udev"
8034
8035 # Some alternative values
8036 # VIRTUAL-RUNTIME_dev_manager = "busybox-mdev"
8037 # VIRTUAL-RUNTIME_dev_manager = "systemd"
8038
8039.. _platdev-appdev-srcrev:
8040
8041Using an External SCM
8042=====================
8043
8044If you're working on a recipe that pulls from an external Source Code
8045Manager (SCM), it is possible to have the OpenEmbedded build system
8046notice new recipe changes added to the SCM and then build the resulting
8047packages that depend on the new recipes by using the latest versions.
8048This only works for SCMs from which it is possible to get a sensible
8049revision number for changes. Currently, you can do this with Apache
8050Subversion (SVN), Git, and Bazaar (BZR) repositories.
8051
8052To enable this behavior, the :term:`PV` of
8053the recipe needs to reference
8054:term:`SRCPV`. Here is an example:
8055::
8056
8057 PV = "1.2.3+git${SRCPV}"
8058
8059Then, you can add the following to your
8060``local.conf``:
8061::
8062
8063 SRCREV_pn-PN = "${AUTOREV}"
8064
8065:term:`PN` is the name of the recipe for
8066which you want to enable automatic source revision updating.
8067
8068If you do not want to update your local configuration file, you can add
8069the following directly to the recipe to finish enabling the feature:
8070::
8071
8072 SRCREV = "${AUTOREV}"
8073
8074The Yocto Project provides a distribution named ``poky-bleeding``, whose
8075configuration file contains the line:
8076::
8077
8078 require conf/distro/include/poky-floating-revisions.inc
8079
8080This line pulls in the
8081listed include file that contains numerous lines of exactly that form:
8082::
8083
8084 #SRCREV_pn-opkg-native ?= "${AUTOREV}"
8085 #SRCREV_pn-opkg-sdk ?= "${AUTOREV}"
8086 #SRCREV_pn-opkg ?= "${AUTOREV}"
8087 #SRCREV_pn-opkg-utils-native ?= "${AUTOREV}"
8088 #SRCREV_pn-opkg-utils ?= "${AUTOREV}"
8089 SRCREV_pn-gconf-dbus ?= "${AUTOREV}"
8090 SRCREV_pn-matchbox-common ?= "${AUTOREV}"
8091 SRCREV_pn-matchbox-config-gtk ?= "${AUTOREV}"
8092 SRCREV_pn-matchbox-desktop ?= "${AUTOREV}"
8093 SRCREV_pn-matchbox-keyboard ?= "${AUTOREV}"
8094 SRCREV_pn-matchbox-panel-2 ?= "${AUTOREV}"
8095 SRCREV_pn-matchbox-themes-extra ?= "${AUTOREV}"
8096 SRCREV_pn-matchbox-terminal ?= "${AUTOREV}"
8097 SRCREV_pn-matchbox-wm ?= "${AUTOREV}"
8098 SRCREV_pn-settings-daemon ?= "${AUTOREV}"
8099 SRCREV_pn-screenshot ?= "${AUTOREV}"
8100 . . .
8101
8102These lines allow you to
8103experiment with building a distribution that tracks the latest
8104development source for numerous packages.
8105
8106.. note::
8107
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008108 The ``poky-bleeding`` distribution is not tested on a regular basis. Keep
8109 this in mind if you use it.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008110
8111Creating a Read-Only Root Filesystem
8112====================================
8113
8114Suppose, for security reasons, you need to disable your target device's
8115root filesystem's write permissions (i.e. you need a read-only root
8116filesystem). Or, perhaps you are running the device's operating system
8117from a read-only storage device. For either case, you can customize your
8118image for that behavior.
8119
8120.. note::
8121
8122 Supporting a read-only root filesystem requires that the system and
8123 applications do not try to write to the root filesystem. You must
8124 configure all parts of the target system to write elsewhere, or to
8125 gracefully fail in the event of attempting to write to the root
8126 filesystem.
8127
8128Creating the Root Filesystem
8129----------------------------
8130
8131To create the read-only root filesystem, simply add the
8132"read-only-rootfs" feature to your image, normally in one of two ways.
8133The first way is to add the "read-only-rootfs" image feature in the
8134image's recipe file via the ``IMAGE_FEATURES`` variable:
8135::
8136
8137 IMAGE_FEATURES += "read-only-rootfs"
8138
8139As an alternative, you can add the same feature
8140from within your build directory's ``local.conf`` file with the
8141associated ``EXTRA_IMAGE_FEATURES`` variable, as in:
8142::
8143
8144 EXTRA_IMAGE_FEATURES = "read-only-rootfs"
8145
8146For more information on how to use these variables, see the
Andrew Geissler6ce62a22020-11-30 19:58:47 -06008147":ref:`dev-manual/dev-manual-common-tasks:Customizing Images Using Custom \`\`IMAGE_FEATURES\`\` and \`\`EXTRA_IMAGE_FEATURES\`\``"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008148section. For information on the variables, see
8149:term:`IMAGE_FEATURES` and
8150:term:`EXTRA_IMAGE_FEATURES`.
8151
8152Post-Installation Scripts and Read-Only Root Filesystem
8153-------------------------------------------------------
8154
8155It is very important that you make sure all post-Installation
8156(``pkg_postinst``) scripts for packages that are installed into the
8157image can be run at the time when the root filesystem is created during
8158the build on the host system. These scripts cannot attempt to run during
8159first-boot on the target device. With the "read-only-rootfs" feature
8160enabled, the build system checks during root filesystem creation to make
8161sure all post-installation scripts succeed. If any of these scripts
8162still need to be run after the root filesystem is created, the build
8163immediately fails. These build-time checks ensure that the build fails
8164rather than the target device fails later during its initial boot
8165operation.
8166
8167Most of the common post-installation scripts generated by the build
8168system for the out-of-the-box Yocto Project are engineered so that they
8169can run during root filesystem creation (e.g. post-installation scripts
8170for caching fonts). However, if you create and add custom scripts, you
8171need to be sure they can be run during this file system creation.
8172
8173Here are some common problems that prevent post-installation scripts
8174from running during root filesystem creation:
8175
8176- *Not using $D in front of absolute paths:* The build system defines
8177 ``$``\ :term:`D` when the root
8178 filesystem is created. Furthermore, ``$D`` is blank when the script
8179 is run on the target device. This implies two purposes for ``$D``:
8180 ensuring paths are valid in both the host and target environments,
8181 and checking to determine which environment is being used as a method
8182 for taking appropriate actions.
8183
8184- *Attempting to run processes that are specific to or dependent on the
8185 target architecture:* You can work around these attempts by using
8186 native tools, which run on the host system, to accomplish the same
8187 tasks, or by alternatively running the processes under QEMU, which
8188 has the ``qemu_run_binary`` function. For more information, see the
8189 :ref:`qemu <ref-classes-qemu>` class.
8190
8191Areas With Write Access
8192-----------------------
8193
8194With the "read-only-rootfs" feature enabled, any attempt by the target
8195to write to the root filesystem at runtime fails. Consequently, you must
8196make sure that you configure processes and applications that attempt
8197these types of writes do so to directories with write access (e.g.
8198``/tmp`` or ``/var/run``).
8199
8200Maintaining Build Output Quality
8201================================
8202
8203Many factors can influence the quality of a build. For example, if you
8204upgrade a recipe to use a new version of an upstream software package or
8205you experiment with some new configuration options, subtle changes can
8206occur that you might not detect until later. Consider the case where
8207your recipe is using a newer version of an upstream package. In this
8208case, a new version of a piece of software might introduce an optional
8209dependency on another library, which is auto-detected. If that library
8210has already been built when the software is building, the software will
8211link to the built library and that library will be pulled into your
8212image along with the new software even if you did not want the library.
8213
8214The :ref:`buildhistory <ref-classes-buildhistory>`
8215class exists to help you maintain the quality of your build output. You
8216can use the class to highlight unexpected and possibly unwanted changes
8217in the build output. When you enable build history, it records
8218information about the contents of each package and image and then
8219commits that information to a local Git repository where you can examine
8220the information.
8221
8222The remainder of this section describes the following:
8223
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008224- :ref:`How you can enable and disable build history <dev-manual/dev-manual-common-tasks:enabling and disabling build history>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008225
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008226- :ref:`How to understand what the build history contains <dev-manual/dev-manual-common-tasks:understanding what the build history contains>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008227
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008228- :ref:`How to limit the information used for build history <dev-manual/dev-manual-common-tasks:using build history to gather image information only>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008229
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008230- :ref:`How to examine the build history from both a command-line and web interface <dev-manual/dev-manual-common-tasks:examining build history information>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008231
8232Enabling and Disabling Build History
8233------------------------------------
8234
8235Build history is disabled by default. To enable it, add the following
8236``INHERIT`` statement and set the
8237:term:`BUILDHISTORY_COMMIT`
8238variable to "1" at the end of your ``conf/local.conf`` file found in the
8239:term:`Build Directory`:
8240::
8241
8242 INHERIT += "buildhistory"
8243 BUILDHISTORY_COMMIT = "1"
8244
8245Enabling build history as
8246previously described causes the OpenEmbedded build system to collect
8247build output information and commit it as a single commit to a local
8248:ref:`overview-manual/overview-manual-development-environment:git` repository.
8249
8250.. note::
8251
8252 Enabling build history increases your build times slightly,
8253 particularly for images, and increases the amount of disk space used
8254 during the build.
8255
8256You can disable build history by removing the previous statements from
8257your ``conf/local.conf`` file.
8258
8259Understanding What the Build History Contains
8260---------------------------------------------
8261
8262Build history information is kept in
8263``${``\ :term:`TOPDIR`\ ``}/buildhistory``
8264in the Build Directory as defined by the
8265:term:`BUILDHISTORY_DIR`
8266variable. The following is an example abbreviated listing:
8267
8268.. image:: figures/buildhistory.png
8269 :align: center
8270
8271At the top level, a ``metadata-revs`` file exists that lists the
8272revisions of the repositories for the enabled layers when the build was
8273produced. The rest of the data splits into separate ``packages``,
8274``images`` and ``sdk`` directories, the contents of which are described
8275as follows.
8276
8277Build History Package Information
8278~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8279
8280The history for each package contains a text file that has name-value
8281pairs with information about the package. For example,
8282``buildhistory/packages/i586-poky-linux/busybox/busybox/latest``
8283contains the following:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008284
8285.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008286
8287 PV = 1.22.1
8288 PR = r32
8289 RPROVIDES =
8290 RDEPENDS = glibc (>= 2.20) update-alternatives-opkg
8291 RRECOMMENDS = busybox-syslog busybox-udhcpc update-rc.d
8292 PKGSIZE = 540168
8293 FILES = /usr/bin/* /usr/sbin/* /usr/lib/busybox/* /usr/lib/lib*.so.* \
8294 /etc /com /var /bin/* /sbin/* /lib/*.so.* /lib/udev/rules.d \
8295 /usr/lib/udev/rules.d /usr/share/busybox /usr/lib/busybox/* \
8296 /usr/share/pixmaps /usr/share/applications /usr/share/idl \
8297 /usr/share/omf /usr/share/sounds /usr/lib/bonobo/servers
8298 FILELIST = /bin/busybox /bin/busybox.nosuid /bin/busybox.suid /bin/sh \
8299 /etc/busybox.links.nosuid /etc/busybox.links.suid
8300
8301Most of these
8302name-value pairs correspond to variables used to produce the package.
8303The exceptions are ``FILELIST``, which is the actual list of files in
8304the package, and ``PKGSIZE``, which is the total size of files in the
8305package in bytes.
8306
8307A file also exists that corresponds to the recipe from which the package
8308came (e.g. ``buildhistory/packages/i586-poky-linux/busybox/latest``):
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008309
8310.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008311
8312 PV = 1.22.1
8313 PR = r32
8314 DEPENDS = initscripts kern-tools-native update-rc.d-native \
8315 virtual/i586-poky-linux-compilerlibs virtual/i586-poky-linux-gcc \
8316 virtual/libc virtual/update-alternatives
8317 PACKAGES = busybox-ptest busybox-httpd busybox-udhcpd busybox-udhcpc \
8318 busybox-syslog busybox-mdev busybox-hwclock busybox-dbg \
8319 busybox-staticdev busybox-dev busybox-doc busybox-locale busybox
8320
8321Finally, for those recipes fetched from a version control system (e.g.,
8322Git), a file exists that lists source revisions that are specified in
8323the recipe and lists the actual revisions used during the build. Listed
8324and actual revisions might differ when
8325:term:`SRCREV` is set to
8326${:term:`AUTOREV`}. Here is an
8327example assuming
8328``buildhistory/packages/qemux86-poky-linux/linux-yocto/latest_srcrev``):
8329::
8330
8331 # SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
8332 SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
8333 # SRCREV_meta = "a227f20eff056e511d504b2e490f3774ab260d6f"
8334 SRCREV_meta ="a227f20eff056e511d504b2e490f3774ab260d6f"
8335
8336You can use the
8337``buildhistory-collect-srcrevs`` command with the ``-a`` option to
8338collect the stored ``SRCREV`` values from build history and report them
8339in a format suitable for use in global configuration (e.g.,
8340``local.conf`` or a distro include file) to override floating
8341``AUTOREV`` values to a fixed set of revisions. Here is some example
8342output from this command:
8343::
8344
8345 $ buildhistory-collect-srcrevs -a
8346 # i586-poky-linux
8347 SRCREV_pn-glibc = "b8079dd0d360648e4e8de48656c5c38972621072"
8348 SRCREV_pn-glibc-initial = "b8079dd0d360648e4e8de48656c5c38972621072"
8349 SRCREV_pn-opkg-utils = "53274f087565fd45d8452c5367997ba6a682a37a"
8350 SRCREV_pn-kmod = "fd56638aed3fe147015bfa10ed4a5f7491303cb4"
8351 # x86_64-linux
8352 SRCREV_pn-gtk-doc-stub-native = "1dea266593edb766d6d898c79451ef193eb17cfa"
8353 SRCREV_pn-dtc-native = "65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf"
8354 SRCREV_pn-update-rc.d-native = "eca680ddf28d024954895f59a241a622dd575c11"
8355 SRCREV_glibc_pn-cross-localedef-native = "b8079dd0d360648e4e8de48656c5c38972621072"
8356 SRCREV_localedef_pn-cross-localedef-native = "c833367348d39dad7ba018990bfdaffaec8e9ed3"
8357 SRCREV_pn-prelink-native = "faa069deec99bf61418d0bab831c83d7c1b797ca"
8358 SRCREV_pn-opkg-utils-native = "53274f087565fd45d8452c5367997ba6a682a37a"
8359 SRCREV_pn-kern-tools-native = "23345b8846fe4bd167efdf1bd8a1224b2ba9a5ff"
8360 SRCREV_pn-kmod-native = "fd56638aed3fe147015bfa10ed4a5f7491303cb4"
8361 # qemux86-poky-linux
8362 SRCREV_machine_pn-linux-yocto = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1"
8363 SRCREV_meta_pn-linux-yocto = "a227f20eff056e511d504b2e490f3774ab260d6f"
8364 # all-poky-linux
8365 SRCREV_pn-update-rc.d = "eca680ddf28d024954895f59a241a622dd575c11"
8366
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
8371 - By default, only values where the ``SRCREV`` was not hardcoded
8372 (usually when ``AUTOREV`` is used) are reported. Use the ``-a``
8373 option to see all ``SRCREV`` values.
8374
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
8427 DISTRO_VERSION = 1.7
8428 USER_CLASSES = buildstats image-mklibs image-prelink
8429 IMAGE_CLASSES = image_types
8430 IMAGE_FEATURES = debug-tweaks
8431 IMAGE_LINGUAS =
8432 IMAGE_INSTALL = packagegroup-core-boot run-postinsts
8433 BAD_RECOMMENDATIONS =
8434 NO_RECOMMENDATIONS =
8435 PACKAGE_EXCLUDE =
8436 ROOTFS_POSTPROCESS_COMMAND = write_package_manifest; license_create_manifest; \
8437 write_image_manifest ; buildhistory_list_installed_image ; \
8438 buildhistory_get_image_installed ; ssh_allow_empty_password; \
8439 postinst_enable_logging; rootfs_update_timestamp ; ssh_disable_dns_lookup ;
8440 IMAGE_POSTPROCESS_COMMAND = buildhistory_get_imageinfo ;
8441 IMAGESIZE = 6900
8442
8443Other than ``IMAGESIZE``,
8444which is the total size of the files in the image in Kbytes, the
8445name-value pairs are variables that may have influenced the content of
8446the image. This information is often useful when you are trying to
8447determine why a change in the package or file listings has occurred.
8448
8449Using Build History to Gather Image Information Only
8450~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8451
8452As you can see, build history produces image information, including
8453dependency graphs, so you can see why something was pulled into the
8454image. If you are just interested in this information and not interested
8455in collecting specific package or SDK information, you can enable
8456writing only image information without any history by adding the
8457following to your ``conf/local.conf`` file found in the
8458:term:`Build Directory`:
8459::
8460
8461 INHERIT += "buildhistory"
8462 BUILDHISTORY_COMMIT = "0"
8463 BUILDHISTORY_FEATURES = "image"
8464
8465Here, you set the
8466:term:`BUILDHISTORY_FEATURES`
8467variable to use the image feature only.
8468
8469Build History SDK Information
8470~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8471
8472Build history collects similar information on the contents of SDKs (e.g.
8473``bitbake -c populate_sdk imagename``) as compared to information it
8474collects for images. Furthermore, this information differs depending on
8475whether an extensible or standard SDK is being produced.
8476
8477The following list shows the files produced for SDKs:
8478
8479- ``files-in-sdk.txt:`` A list of files in the SDK with permissions,
8480 owner, group, size, and symlink information. This list includes both
8481 the host and target parts of the SDK.
8482
8483- ``sdk-info.txt:`` A text file containing name-value pairs with
8484 information about the SDK. See the following listing example for more
8485 information.
8486
8487- ``sstate-task-sizes.txt:`` A text file containing name-value pairs
8488 with information about task group sizes (e.g. ``do_populate_sysroot``
8489 tasks have a total size). The ``sstate-task-sizes.txt`` file exists
8490 only when an extensible SDK is created.
8491
8492- ``sstate-package-sizes.txt:`` A text file containing name-value pairs
8493 with information for the shared-state packages and sizes in the SDK.
8494 The ``sstate-package-sizes.txt`` file exists only when an extensible
8495 SDK is created.
8496
8497- ``sdk-files:`` A folder that contains copies of the files mentioned
8498 in ``BUILDHISTORY_SDK_FILES`` if the files are present in the output.
8499 Additionally, the default value of ``BUILDHISTORY_SDK_FILES`` is
8500 specific to the extensible SDK although you can set it differently if
8501 you would like to pull in specific files from the standard SDK.
8502
8503 The default files are ``conf/local.conf``, ``conf/bblayers.conf``,
8504 ``conf/auto.conf``, ``conf/locked-sigs.inc``, and
8505 ``conf/devtool.conf``. Thus, for an extensible SDK, these files get
8506 copied into the ``sdk-files`` directory.
8507
8508- The following information appears under each of the ``host`` and
8509 ``target`` directories for the portions of the SDK that run on the
8510 host and on the target, respectively:
8511
8512 .. note::
8513
8514 The following files for the most part are empty when producing an
8515 extensible SDK because this type of SDK is not constructed from
8516 packages as is the standard SDK.
8517
8518 - ``depends.dot:`` Dependency graph for the SDK that is compatible
8519 with ``graphviz``.
8520
8521 - ``installed-package-names.txt:`` A list of installed packages by
8522 name only.
8523
8524 - ``installed-package-sizes.txt:`` A list of installed packages
8525 ordered by size.
8526
8527 - ``installed-packages.txt:`` A list of installed packages with full
8528 package filenames.
8529
8530Here is an example of ``sdk-info.txt``:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008531
8532.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008533
8534 DISTRO = poky
8535 DISTRO_VERSION = 1.3+snapshot-20130327
8536 SDK_NAME = poky-glibc-i686-arm
8537 SDK_VERSION = 1.3+snapshot
8538 SDKMACHINE =
8539 SDKIMAGE_FEATURES = dev-pkgs dbg-pkgs
8540 BAD_RECOMMENDATIONS =
8541 SDKSIZE = 352712
8542
8543Other than ``SDKSIZE``, which is
8544the total size of the files in the SDK in Kbytes, the name-value pairs
8545are variables that might have influenced the content of the SDK. This
8546information is often useful when you are trying to determine why a
8547change in the package or file listings has occurred.
8548
8549Examining Build History Information
8550~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8551
8552You can examine build history output from the command line or from a web
8553interface.
8554
8555To see any changes that have occurred (assuming you have
8556:term:`BUILDHISTORY_COMMIT` = "1"),
8557you can simply use any Git command that allows you to view the history
8558of a repository. Here is one method:
8559::
8560
8561 $ git log -p
8562
8563You need to realize,
8564however, that this method does show changes that are not significant
8565(e.g. a package's size changing by a few bytes).
8566
8567A command-line tool called ``buildhistory-diff`` does exist, though,
8568that queries the Git repository and prints just the differences that
8569might be significant in human-readable form. Here is an example:
8570::
8571
8572 $ ~/poky/poky/scripts/buildhistory-diff . HEAD^
8573 Changes to images/qemux86_64/glibc/core-image-minimal (files-in-image.txt):
8574 /etc/anotherpkg.conf was added
8575 /sbin/anotherpkg was added
8576 * (installed-package-names.txt):
8577 * anotherpkg was added
8578 Changes to images/qemux86_64/glibc/core-image-minimal (installed-package-names.txt):
8579 anotherpkg was added
8580 packages/qemux86_64-poky-linux/v86d: PACKAGES: added "v86d-extras"
8581 * PR changed from "r0" to "r1"
8582 * PV changed from "0.1.10" to "0.1.12"
8583 packages/qemux86_64-poky-linux/v86d/v86d: PKGSIZE changed from 110579 to 144381 (+30%)
8584 * PR changed from "r0" to "r1"
8585 * PV changed from "0.1.10" to "0.1.12"
8586
8587.. note::
8588
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008589 The ``buildhistory-diff`` tool requires the ``GitPython``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008590 package. Be sure to install it using Pip3 as follows:
8591 ::
8592
8593 $ pip3 install GitPython --user
8594
8595
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008596 Alternatively, you can install ``python3-git`` using the appropriate
8597 distribution package manager (e.g. ``apt-get``, ``dnf``, or ``zipper``).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008598
8599To see changes to the build history using a web interface, follow the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008600instruction in the ``README`` file
8601:yocto_git:`here </cgit/cgit.cgi/buildhistory-web/>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008602
8603Here is a sample screenshot of the interface:
8604
8605.. image:: figures/buildhistory-web.png
8606 :align: center
8607
8608Performing Automated Runtime Testing
8609====================================
8610
8611The OpenEmbedded build system makes available a series of automated
8612tests for images to verify runtime functionality. You can run these
8613tests on either QEMU or actual target hardware. Tests are written in
8614Python making use of the ``unittest`` module, and the majority of them
8615run commands on the target system over SSH. This section describes how
8616you set up the environment to use these tests, run available tests, and
8617write and add your own tests.
8618
8619For information on the test and QA infrastructure available within the
8620Yocto Project, see the ":ref:`ref-manual/ref-release-process:testing and quality assurance`"
8621section in the Yocto Project Reference Manual.
8622
8623Enabling Tests
8624--------------
8625
8626Depending on whether you are planning to run tests using QEMU or on the
8627hardware, you have to take different steps to enable the tests. See the
8628following subsections for information on how to enable both types of
8629tests.
8630
8631.. _qemu-image-enabling-tests:
8632
8633Enabling Runtime Tests on QEMU
8634~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8635
8636In order to run tests, you need to do the following:
8637
8638- *Set up to avoid interaction with sudo for networking:* To
8639 accomplish this, you must do one of the following:
8640
8641 - Add ``NOPASSWD`` for your user in ``/etc/sudoers`` either for all
8642 commands or just for ``runqemu-ifup``. You must provide the full
8643 path as that can change if you are using multiple clones of the
8644 source repository.
8645
8646 .. note::
8647
8648 On some distributions, you also need to comment out "Defaults
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008649 requiretty" in ``/etc/sudoers``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008650
8651 - Manually configure a tap interface for your system.
8652
8653 - Run as root the script in ``scripts/runqemu-gen-tapdevs``, which
8654 should generate a list of tap devices. This is the option
8655 typically chosen for Autobuilder-type environments.
8656
8657 .. note::
8658
8659 - Be sure to use an absolute path when calling this script
8660 with sudo.
8661
8662 - The package recipe ``qemu-helper-native`` is required to run
8663 this script. Build the package using the following command:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008664 ::
8665
8666 $ bitbake qemu-helper-native
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008667
8668- *Set the DISPLAY variable:* You need to set this variable so that
8669 you have an X server available (e.g. start ``vncserver`` for a
8670 headless machine).
8671
8672- *Be sure your host's firewall accepts incoming connections from
8673 192.168.7.0/24:* Some of the tests (in particular DNF tests) start an
8674 HTTP server on a random high number port, which is used to serve
8675 files to the target. The DNF module serves
8676 ``${WORKDIR}/oe-rootfs-repo`` so it can run DNF channel commands.
8677 That means your host's firewall must accept incoming connections from
8678 192.168.7.0/24, which is the default IP range used for tap devices by
8679 ``runqemu``.
8680
8681- *Be sure your host has the correct packages installed:* Depending
8682 your host's distribution, you need to have the following packages
8683 installed:
8684
8685 - Ubuntu and Debian: ``sysstat`` and ``iproute2``
8686
8687 - OpenSUSE: ``sysstat`` and ``iproute2``
8688
8689 - Fedora: ``sysstat`` and ``iproute``
8690
8691 - CentOS: ``sysstat`` and ``iproute``
8692
8693Once you start running the tests, the following happens:
8694
86951. A copy of the root filesystem is written to ``${WORKDIR}/testimage``.
8696
86972. The image is booted under QEMU using the standard ``runqemu`` script.
8698
86993. A default timeout of 500 seconds occurs to allow for the boot process
8700 to reach the login prompt. You can change the timeout period by
8701 setting
8702 :term:`TEST_QEMUBOOT_TIMEOUT`
8703 in the ``local.conf`` file.
8704
87054. Once the boot process is reached and the login prompt appears, the
8706 tests run. The full boot log is written to
8707 ``${WORKDIR}/testimage/qemu_boot_log``.
8708
87095. Each test module loads in the order found in ``TEST_SUITES``. You can
8710 find the full output of the commands run over SSH in
8711 ``${WORKDIR}/testimgage/ssh_target_log``.
8712
87136. If no failures occur, the task running the tests ends successfully.
8714 You can find the output from the ``unittest`` in the task log at
8715 ``${WORKDIR}/temp/log.do_testimage``.
8716
8717.. _hardware-image-enabling-tests:
8718
8719Enabling Runtime Tests on Hardware
8720~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8721
8722The OpenEmbedded build system can run tests on real hardware, and for
8723certain devices it can also deploy the image to be tested onto the
8724device beforehand.
8725
8726For automated deployment, a "master image" is installed onto the
8727hardware once as part of setup. Then, each time tests are to be run, the
8728following occurs:
8729
87301. The master image is booted into and used to write the image to be
8731 tested to a second partition.
8732
87332. The device is then rebooted using an external script that you need to
8734 provide.
8735
87363. The device boots into the image to be tested.
8737
8738When running tests (independent of whether the image has been deployed
8739automatically or not), the device is expected to be connected to a
8740network on a pre-determined IP address. You can either use static IP
8741addresses written into the image, or set the image to use DHCP and have
8742your DHCP server on the test network assign a known IP address based on
8743the MAC address of the device.
8744
8745In order to run tests on hardware, you need to set ``TEST_TARGET`` to an
8746appropriate value. For QEMU, you do not have to change anything, the
8747default value is "qemu". For running tests on hardware, the following
8748options exist:
8749
8750- *"simpleremote":* Choose "simpleremote" if you are going to run tests
8751 on a target system that is already running the image to be tested and
8752 is available on the network. You can use "simpleremote" in
8753 conjunction with either real hardware or an image running within a
8754 separately started QEMU or any other virtual machine manager.
8755
8756- *"SystemdbootTarget":* Choose "SystemdbootTarget" if your hardware is
8757 an EFI-based machine with ``systemd-boot`` as bootloader and
8758 ``core-image-testmaster`` (or something similar) is installed. Also,
8759 your hardware under test must be in a DHCP-enabled network that gives
8760 it the same IP address for each reboot.
8761
8762 If you choose "SystemdbootTarget", there are additional requirements
8763 and considerations. See the "`Selecting
8764 SystemdbootTarget <#selecting-systemdboottarget>`__" section, which
8765 follows, for more information.
8766
8767- *"BeagleBoneTarget":* Choose "BeagleBoneTarget" if you are deploying
8768 images and running tests on the BeagleBone "Black" or original
8769 "White" hardware. For information on how to use these tests, see the
8770 comments at the top of the BeagleBoneTarget
8771 ``meta-yocto-bsp/lib/oeqa/controllers/beaglebonetarget.py`` file.
8772
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008773- *"EdgeRouterTarget":* Choose "EdgeRouterTarget" if you are deploying
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008774 images and running tests on the Ubiquiti Networks EdgeRouter Lite.
8775 For information on how to use these tests, see the comments at the
8776 top of the EdgeRouterTarget
8777 ``meta-yocto-bsp/lib/oeqa/controllers/edgeroutertarget.py`` file.
8778
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008779- *"GrubTarget":* Choose "GrubTarget" if you are deploying images and running
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008780 tests on any generic PC that boots using GRUB. For information on how
8781 to use these tests, see the comments at the top of the GrubTarget
8782 ``meta-yocto-bsp/lib/oeqa/controllers/grubtarget.py`` file.
8783
8784- *"your-target":* Create your own custom target if you want to run
8785 tests when you are deploying images and running tests on a custom
8786 machine within your BSP layer. To do this, you need to add a Python
8787 unit that defines the target class under ``lib/oeqa/controllers/``
8788 within your layer. You must also provide an empty ``__init__.py``.
8789 For examples, see files in ``meta-yocto-bsp/lib/oeqa/controllers/``.
8790
8791Selecting SystemdbootTarget
8792~~~~~~~~~~~~~~~~~~~~~~~~~~~
8793
8794If you did not set ``TEST_TARGET`` to "SystemdbootTarget", then you do
8795not need any information in this section. You can skip down to the
8796"`Running Tests <#qemu-image-running-tests>`__" section.
8797
8798If you did set ``TEST_TARGET`` to "SystemdbootTarget", you also need to
8799perform a one-time setup of your master image by doing the following:
8800
88011. *Set EFI_PROVIDER:* Be sure that ``EFI_PROVIDER`` is as follows:
8802 ::
8803
8804 EFI_PROVIDER = "systemd-boot"
8805
88062. *Build the master image:* Build the ``core-image-testmaster`` image.
8807 The ``core-image-testmaster`` recipe is provided as an example for a
8808 "master" image and you can customize the image recipe as you would
8809 any other recipe.
8810
8811 Here are the image recipe requirements:
8812
8813 - Inherits ``core-image`` so that kernel modules are installed.
8814
8815 - Installs normal linux utilities not busybox ones (e.g. ``bash``,
8816 ``coreutils``, ``tar``, ``gzip``, and ``kmod``).
8817
8818 - Uses a custom Initial RAM Disk (initramfs) image with a custom
8819 installer. A normal image that you can install usually creates a
8820 single rootfs partition. This image uses another installer that
8821 creates a specific partition layout. Not all Board Support
8822 Packages (BSPs) can use an installer. For such cases, you need to
8823 manually create the following partition layout on the target:
8824
8825 - First partition mounted under ``/boot``, labeled "boot".
8826
8827 - The main rootfs partition where this image gets installed,
8828 which is mounted under ``/``.
8829
8830 - Another partition labeled "testrootfs" where test images get
8831 deployed.
8832
88333. *Install image:* Install the image that you just built on the target
8834 system.
8835
8836The final thing you need to do when setting ``TEST_TARGET`` to
8837"SystemdbootTarget" is to set up the test image:
8838
88391. *Set up your local.conf file:* Make sure you have the following
8840 statements in your ``local.conf`` file:
8841 ::
8842
8843 IMAGE_FSTYPES += "tar.gz"
8844 INHERIT += "testimage"
8845 TEST_TARGET = "SystemdbootTarget"
8846 TEST_TARGET_IP = "192.168.2.3"
8847
88482. *Build your test image:* Use BitBake to build the image:
8849 ::
8850
8851 $ bitbake core-image-sato
8852
8853Power Control
8854~~~~~~~~~~~~~
8855
8856For most hardware targets other than "simpleremote", you can control
8857power:
8858
8859- You can use ``TEST_POWERCONTROL_CMD`` together with
8860 ``TEST_POWERCONTROL_EXTRA_ARGS`` as a command that runs on the host
8861 and does power cycling. The test code passes one argument to that
8862 command: off, on or cycle (off then on). Here is an example that
8863 could appear in your ``local.conf`` file:
8864 ::
8865
8866 TEST_POWERCONTROL_CMD = "powercontrol.exp test 10.11.12.1 nuc1"
8867
8868 In this example, the expect
8869 script does the following:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008870
8871 .. code-block:: shell
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008872
8873 ssh test@10.11.12.1 "pyctl nuc1 arg"
8874
8875 It then runs a Python script that controls power for a label called
8876 ``nuc1``.
8877
8878 .. note::
8879
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008880 You need to customize ``TEST_POWERCONTROL_CMD`` and
8881 ``TEST_POWERCONTROL_EXTRA_ARGS`` for your own setup. The one requirement
8882 is that it accepts "on", "off", and "cycle" as the last argument.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008883
8884- When no command is defined, it connects to the device over SSH and
8885 uses the classic reboot command to reboot the device. Classic reboot
8886 is fine as long as the machine actually reboots (i.e. the SSH test
8887 has not failed). It is useful for scenarios where you have a simple
8888 setup, typically with a single board, and where some manual
8889 interaction is okay from time to time.
8890
8891If you have no hardware to automatically perform power control but still
8892wish to experiment with automated hardware testing, you can use the
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008893``dialog-power-control`` script that shows a dialog prompting you to perform
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008894the required power action. This script requires either KDialog or Zenity
8895to be installed. To use this script, set the
8896:term:`TEST_POWERCONTROL_CMD`
8897variable as follows:
8898::
8899
8900 TEST_POWERCONTROL_CMD = "${COREBASE}/scripts/contrib/dialog-power-control"
8901
8902Serial Console Connection
8903~~~~~~~~~~~~~~~~~~~~~~~~~
8904
8905For test target classes requiring a serial console to interact with the
8906bootloader (e.g. BeagleBoneTarget, EdgeRouterTarget, and GrubTarget),
8907you need to specify a command to use to connect to the serial console of
8908the target machine by using the
8909:term:`TEST_SERIALCONTROL_CMD`
8910variable and optionally the
8911:term:`TEST_SERIALCONTROL_EXTRA_ARGS`
8912variable.
8913
8914These cases could be a serial terminal program if the machine is
8915connected to a local serial port, or a ``telnet`` or ``ssh`` command
8916connecting to a remote console server. Regardless of the case, the
8917command simply needs to connect to the serial console and forward that
8918connection to standard input and output as any normal terminal program
8919does. For example, to use the picocom terminal program on serial device
8920``/dev/ttyUSB0`` at 115200bps, you would set the variable as follows:
8921::
8922
8923 TEST_SERIALCONTROL_CMD = "picocom /dev/ttyUSB0 -b 115200"
8924
8925For local
8926devices where the serial port device disappears when the device reboots,
8927an additional "serdevtry" wrapper script is provided. To use this
8928wrapper, simply prefix the terminal command with
8929``${COREBASE}/scripts/contrib/serdevtry``:
8930::
8931
8932 TEST_SERIALCONTROL_CMD = "${COREBASE}/scripts/contrib/serdevtry picocom -b 115200 /dev/ttyUSB0"
8933
8934.. _qemu-image-running-tests:
8935
8936Running Tests
8937-------------
8938
8939You can start the tests automatically or manually:
8940
8941- *Automatically running tests:* To run the tests automatically after
8942 the OpenEmbedded build system successfully creates an image, first
8943 set the
8944 :term:`TESTIMAGE_AUTO`
8945 variable to "1" in your ``local.conf`` file in the
8946 :term:`Build Directory`:
8947 ::
8948
8949 TESTIMAGE_AUTO = "1"
8950
8951 Next, build your image. If the image successfully builds, the
8952 tests run:
8953 ::
8954
8955 bitbake core-image-sato
8956
8957- *Manually running tests:* To manually run the tests, first globally
8958 inherit the
8959 :ref:`testimage <ref-classes-testimage*>` class
8960 by editing your ``local.conf`` file:
8961 ::
8962
8963 INHERIT += "testimage"
8964
8965 Next, use BitBake to run the tests:
8966 ::
8967
8968 bitbake -c testimage image
8969
8970All test files reside in ``meta/lib/oeqa/runtime`` in the
8971:term:`Source Directory`. A test name maps
8972directly to a Python module. Each test module may contain a number of
8973individual tests. Tests are usually grouped together by the area tested
8974(e.g tests for systemd reside in ``meta/lib/oeqa/runtime/systemd.py``).
8975
8976You can add tests to any layer provided you place them in the proper
8977area and you extend :term:`BBPATH` in
8978the ``local.conf`` file as normal. Be sure that tests reside in
8979``layer/lib/oeqa/runtime``.
8980
8981.. note::
8982
8983 Be sure that module names do not collide with module names used in
Andrew Geissler4c19ea12020-10-27 13:52:24 -05008984 the default set of test modules in ``meta/lib/oeqa/runtime``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05008985
8986You can change the set of tests run by appending or overriding
8987:term:`TEST_SUITES` variable in
8988``local.conf``. Each name in ``TEST_SUITES`` represents a required test
8989for the image. Test modules named within ``TEST_SUITES`` cannot be
8990skipped even if a test is not suitable for an image (e.g. running the
8991RPM tests on an image without ``rpm``). Appending "auto" to
8992``TEST_SUITES`` causes the build system to try to run all tests that are
8993suitable for the image (i.e. each test module may elect to skip itself).
8994
8995The order you list tests in ``TEST_SUITES`` is important and influences
8996test dependencies. Consequently, tests that depend on other tests should
8997be added after the test on which they depend. For example, since the
8998``ssh`` test depends on the ``ping`` test, "ssh" needs to come after
8999"ping" in the list. The test class provides no re-ordering or dependency
9000handling.
9001
9002.. note::
9003
9004 Each module can have multiple classes with multiple test methods.
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009005 And, Python ``unittest`` rules apply.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009006
9007Here are some things to keep in mind when running tests:
9008
9009- The default tests for the image are defined as:
9010 ::
9011
9012 DEFAULT_TEST_SUITES_pn-image = "ping ssh df connman syslog xorg scp vnc date rpm dnf dmesg"
9013
9014- Add your own test to the list of the by using the following:
9015 ::
9016
9017 TEST_SUITES_append = " mytest"
9018
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009019- Run a specific list of tests as follows:
9020 ::
9021
9022 TEST_SUITES = "test1 test2 test3"
9023
9024 Remember, order is important. Be sure to place a test that is
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009025 dependent on another test later in the order.
9026
9027Exporting Tests
9028---------------
9029
9030You can export tests so that they can run independently of the build
9031system. Exporting tests is required if you want to be able to hand the
9032test execution off to a scheduler. You can only export tests that are
9033defined in :term:`TEST_SUITES`.
9034
9035If your image is already built, make sure the following are set in your
9036``local.conf`` file:
9037::
9038
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009039 INHERIT += "testexport"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009040 TEST_TARGET_IP = "IP-address-for-the-test-target"
9041 TEST_SERVER_IP = "IP-address-for-the-test-server"
9042
9043You can then export the tests with the
9044following BitBake command form:
9045::
9046
9047 $ bitbake image -c testexport
9048
9049Exporting the tests places them in the
9050:term:`Build Directory` in
9051``tmp/testexport/``\ image, which is controlled by the
9052``TEST_EXPORT_DIR`` variable.
9053
9054You can now run the tests outside of the build environment:
9055::
9056
9057 $ cd tmp/testexport/image
9058 $ ./runexported.py testdata.json
9059
9060Here is a complete example that shows IP addresses and uses the
9061``core-image-sato`` image:
9062::
9063
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009064 INHERIT += "testexport"
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009065 TEST_TARGET_IP = "192.168.7.2"
9066 TEST_SERVER_IP = "192.168.7.1"
9067
9068Use BitBake to export the tests:
9069::
9070
9071 $ bitbake core-image-sato -c testexport
9072
9073Run the tests outside of
9074the build environment using the following:
9075::
9076
9077 $ cd tmp/testexport/core-image-sato
9078 $ ./runexported.py testdata.json
9079
9080.. _qemu-image-writing-new-tests:
9081
9082Writing New Tests
9083-----------------
9084
9085As mentioned previously, all new test files need to be in the proper
9086place for the build system to find them. New tests for additional
9087functionality outside of the core should be added to the layer that adds
9088the functionality, in ``layer/lib/oeqa/runtime`` (as long as
9089:term:`BBPATH` is extended in the
9090layer's ``layer.conf`` file as normal). Just remember the following:
9091
9092- Filenames need to map directly to test (module) names.
9093
9094- Do not use module names that collide with existing core tests.
9095
9096- Minimally, an empty ``__init__.py`` file must exist in the runtime
9097 directory.
9098
9099To create a new test, start by copying an existing module (e.g.
9100``syslog.py`` or ``gcc.py`` are good ones to use). Test modules can use
9101code from ``meta/lib/oeqa/utils``, which are helper classes.
9102
9103.. note::
9104
9105 Structure shell commands such that you rely on them and they return a
9106 single code for success. Be aware that sometimes you will need to
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009107 parse the output. See the ``df.py`` and ``date.py`` modules for examples.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009108
9109You will notice that all test classes inherit ``oeRuntimeTest``, which
9110is found in ``meta/lib/oetest.py``. This base class offers some helper
9111attributes, which are described in the following sections:
9112
9113.. _qemu-image-writing-tests-class-methods:
9114
9115Class Methods
9116~~~~~~~~~~~~~
9117
9118Class methods are as follows:
9119
9120- *hasPackage(pkg):* Returns "True" if ``pkg`` is in the installed
9121 package list of the image, which is based on the manifest file that
9122 is generated during the ``do_rootfs`` task.
9123
9124- *hasFeature(feature):* Returns "True" if the feature is in
9125 :term:`IMAGE_FEATURES` or
9126 :term:`DISTRO_FEATURES`.
9127
9128.. _qemu-image-writing-tests-class-attributes:
9129
9130Class Attributes
9131~~~~~~~~~~~~~~~~
9132
9133Class attributes are as follows:
9134
9135- *pscmd:* Equals "ps -ef" if ``procps`` is installed in the image.
9136 Otherwise, ``pscmd`` equals "ps" (busybox).
9137
9138- *tc:* The called test context, which gives access to the
9139 following attributes:
9140
9141 - *d:* The BitBake datastore, which allows you to use stuff such
9142 as ``oeRuntimeTest.tc.d.getVar("VIRTUAL-RUNTIME_init_manager")``.
9143
9144 - *testslist and testsrequired:* Used internally. The tests
9145 do not need these.
9146
9147 - *filesdir:* The absolute path to
9148 ``meta/lib/oeqa/runtime/files``, which contains helper files for
9149 tests meant for copying on the target such as small files written
9150 in C for compilation.
9151
9152 - *target:* The target controller object used to deploy and
9153 start an image on a particular target (e.g. Qemu, SimpleRemote,
9154 and SystemdbootTarget). Tests usually use the following:
9155
9156 - *ip:* The target's IP address.
9157
9158 - *server_ip:* The host's IP address, which is usually used
9159 by the DNF test suite.
9160
9161 - *run(cmd, timeout=None):* The single, most used method.
9162 This command is a wrapper for: ``ssh root@host "cmd"``. The
9163 command returns a tuple: (status, output), which are what their
9164 names imply - the return code of "cmd" and whatever output it
9165 produces. The optional timeout argument represents the number
9166 of seconds the test should wait for "cmd" to return. If the
9167 argument is "None", the test uses the default instance's
9168 timeout period, which is 300 seconds. If the argument is "0",
9169 the test runs until the command returns.
9170
9171 - *copy_to(localpath, remotepath):*
9172 ``scp localpath root@ip:remotepath``.
9173
9174 - *copy_from(remotepath, localpath):*
9175 ``scp root@host:remotepath localpath``.
9176
9177.. _qemu-image-writing-tests-instance-attributes:
9178
9179Instance Attributes
9180~~~~~~~~~~~~~~~~~~~
9181
9182A single instance attribute exists, which is ``target``. The ``target``
9183instance attribute is identical to the class attribute of the same name,
9184which is described in the previous section. This attribute exists as
9185both an instance and class attribute so tests can use
9186``self.target.run(cmd)`` in instance methods instead of
9187``oeRuntimeTest.tc.target.run(cmd)``.
9188
9189Installing Packages in the DUT Without the Package Manager
9190----------------------------------------------------------
9191
9192When a test requires a package built by BitBake, it is possible to
9193install that package. Installing the package does not require a package
9194manager be installed in the device under test (DUT). It does, however,
9195require an SSH connection and the target must be using the
9196``sshcontrol`` class.
9197
9198.. note::
9199
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009200 This method uses ``scp`` to copy files from the host to the target, which
9201 causes permissions and special attributes to be lost.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009202
9203A JSON file is used to define the packages needed by a test. This file
9204must be in the same path as the file used to define the tests.
9205Furthermore, the filename must map directly to the test module name with
9206a ``.json`` extension.
9207
9208The JSON file must include an object with the test name as keys of an
9209object or an array. This object (or array of objects) uses the following
9210data:
9211
9212- "pkg" - A mandatory string that is the name of the package to be
9213 installed.
9214
9215- "rm" - An optional boolean, which defaults to "false", that specifies
9216 to remove the package after the test.
9217
9218- "extract" - An optional boolean, which defaults to "false", that
9219 specifies if the package must be extracted from the package format.
9220 When set to "true", the package is not automatically installed into
9221 the DUT.
9222
9223Following is an example JSON file that handles test "foo" installing
9224package "bar" and test "foobar" installing packages "foo" and "bar".
9225Once the test is complete, the packages are removed from the DUT.
9226::
9227
9228 {
9229 "foo": {
9230 "pkg": "bar"
9231 },
9232 "foobar": [
9233 {
9234 "pkg": "foo",
9235 "rm": true
9236 },
9237 {
9238 "pkg": "bar",
9239 "rm": true
9240 }
9241 ]
9242 }
9243
9244.. _usingpoky-debugging-tools-and-techniques:
9245
9246Debugging Tools and Techniques
9247==============================
9248
9249The exact method for debugging build failures depends on the nature of
9250the problem and on the system's area from which the bug originates.
9251Standard debugging practices such as comparison against the last known
9252working version with examination of the changes and the re-application
9253of steps to identify the one causing the problem are valid for the Yocto
9254Project just as they are for any other system. Even though it is
9255impossible to detail every possible potential failure, this section
9256provides some general tips to aid in debugging given a variety of
9257situations.
9258
9259.. note::
9260
9261 A useful feature for debugging is the error reporting tool.
9262 Configuring the Yocto Project to use this tool causes the
9263 OpenEmbedded build system to produce error reporting commands as part
9264 of the console output. You can enter the commands after the build
9265 completes to log error information into a common database, that can
9266 help you figure out what might be going wrong. For information on how
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009267 to enable and use this feature, see the
9268 ":ref:`dev-manual/dev-manual-common-tasks:using the error reporting tool`"
9269 section.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009270
9271The following list shows the debugging topics in the remainder of this
9272section:
9273
9274- "`Viewing Logs from Failed
9275 Tasks <#dev-debugging-viewing-logs-from-failed-tasks>`__" describes
9276 how to find and view logs from tasks that failed during the build
9277 process.
9278
9279- "`Viewing Variable
9280 Values <#dev-debugging-viewing-variable-values>`__" describes how to
9281 use the BitBake ``-e`` option to examine variable values after a
9282 recipe has been parsed.
9283
9284- ":ref:`dev-manual/dev-manual-common-tasks:viewing package information with \`\`oe-pkgdata-util\`\``"
9285 describes how to use the ``oe-pkgdata-util`` utility to query
9286 :term:`PKGDATA_DIR` and
9287 display package-related information for built packages.
9288
9289- "`Viewing Dependencies Between Recipes and
9290 Tasks <#dev-viewing-dependencies-between-recipes-and-tasks>`__"
9291 describes how to use the BitBake ``-g`` option to display recipe
9292 dependency information used during the build.
9293
9294- "`Viewing Task Variable
9295 Dependencies <#dev-viewing-task-variable-dependencies>`__" describes
9296 how to use the ``bitbake-dumpsig`` command in conjunction with key
9297 subdirectories in the
9298 :term:`Build Directory` to determine
9299 variable dependencies.
9300
9301- "`Running Specific Tasks <#dev-debugging-taskrunning>`__" describes
9302 how to use several BitBake options (e.g. ``-c``, ``-C``, and ``-f``)
9303 to run specific tasks in the build chain. It can be useful to run
9304 tasks "out-of-order" when trying isolate build issues.
9305
9306- "`General BitBake Problems <#dev-debugging-bitbake>`__" describes how
9307 to use BitBake's ``-D`` debug output option to reveal more about what
9308 BitBake is doing during the build.
9309
9310- "`Building with No Dependencies <#dev-debugging-buildfile>`__"
9311 describes how to use the BitBake ``-b`` option to build a recipe
9312 while ignoring dependencies.
9313
9314- "`Recipe Logging Mechanisms <#recipe-logging-mechanisms>`__"
9315 describes how to use the many recipe logging functions to produce
9316 debugging output and report errors and warnings.
9317
9318- "`Debugging Parallel Make Races <#debugging-parallel-make-races>`__"
9319 describes how to debug situations where the build consists of several
9320 parts that are run simultaneously and when the output or result of
9321 one part is not ready for use with a different part of the build that
9322 depends on that output.
9323
9324- "`Debugging With the GNU Project Debugger (GDB)
9325 Remotely <#platdev-gdb-remotedebug>`__" describes how to use GDB to
9326 allow you to examine running programs, which can help you fix
9327 problems.
9328
9329- "`Debugging with the GNU Project Debugger (GDB) on the
9330 Target <#debugging-with-the-gnu-project-debugger-gdb-on-the-target>`__"
9331 describes how to use GDB directly on target hardware for debugging.
9332
9333- "`Other Debugging Tips <#dev-other-debugging-others>`__" describes
9334 miscellaneous debugging tips that can be useful.
9335
9336.. _dev-debugging-viewing-logs-from-failed-tasks:
9337
9338Viewing Logs from Failed Tasks
9339------------------------------
9340
9341You can find the log for a task in the file
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009342``${``\ :term:`WORKDIR`\ ``}/temp/log.do_``\ `taskname`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009343For example, the log for the
9344:ref:`ref-tasks-compile` task of the
9345QEMU minimal image for the x86 machine (``qemux86``) might be in
9346``tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/temp/log.do_compile``.
9347To see the commands :term:`BitBake` ran
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009348to generate a log, look at the corresponding ``run.do_``\ `taskname` file
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009349in the same directory.
9350
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009351``log.do_``\ `taskname` and ``run.do_``\ `taskname` are actually symbolic
9352links to ``log.do_``\ `taskname`\ ``.``\ `pid` and
9353``log.run_``\ `taskname`\ ``.``\ `pid`, where `pid` is the PID the task had
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009354when it ran. The symlinks always point to the files corresponding to the
9355most recent run.
9356
9357.. _dev-debugging-viewing-variable-values:
9358
9359Viewing Variable Values
9360-----------------------
9361
9362Sometimes you need to know the value of a variable as a result of
9363BitBake's parsing step. This could be because some unexpected behavior
9364occurred in your project. Perhaps an attempt to :ref:`modify a variable
9365<bitbake:bitbake-user-manual/bitbake-user-manual-metadata:modifying existing
9366variables>` did not work out as expected.
9367
9368BitBake's ``-e`` option is used to display variable values after
9369parsing. The following command displays the variable values after the
9370configuration files (i.e. ``local.conf``, ``bblayers.conf``,
9371``bitbake.conf`` and so forth) have been parsed:
9372::
9373
9374 $ bitbake -e
9375
9376The following command displays variable values after a specific recipe has
9377been parsed. The variables include those from the configuration as well:
9378::
9379
9380 $ bitbake -e recipename
9381
9382.. note::
9383
9384 Each recipe has its own private set of variables (datastore).
9385 Internally, after parsing the configuration, a copy of the resulting
9386 datastore is made prior to parsing each recipe. This copying implies
9387 that variables set in one recipe will not be visible to other
9388 recipes.
9389
9390 Likewise, each task within a recipe gets a private datastore based on
9391 the recipe datastore, which means that variables set within one task
9392 will not be visible to other tasks.
9393
9394In the output of ``bitbake -e``, each variable is preceded by a
9395description of how the variable got its value, including temporary
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009396values that were later overridden. This description also includes
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009397variable flags (varflags) set on the variable. The output can be very
9398helpful during debugging.
9399
9400Variables that are exported to the environment are preceded by
9401``export`` in the output of ``bitbake -e``. See the following example:
9402::
9403
9404 export CC="i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/ulf/poky/build/tmp/sysroots/qemux86"
9405
9406In addition to variable values, the output of the ``bitbake -e`` and
9407``bitbake -e`` recipe commands includes the following information:
9408
9409- The output starts with a tree listing all configuration files and
9410 classes included globally, recursively listing the files they include
9411 or inherit in turn. Much of the behavior of the OpenEmbedded build
9412 system (including the behavior of the :ref:`ref-manual/ref-tasks:normal recipe build tasks`) is
9413 implemented in the
9414 :ref:`base <ref-classes-base>` class and the
9415 classes it inherits, rather than being built into BitBake itself.
9416
9417- After the variable values, all functions appear in the output. For
9418 shell functions, variables referenced within the function body are
9419 expanded. If a function has been modified using overrides or using
9420 override-style operators like ``_append`` and ``_prepend``, then the
9421 final assembled function body appears in the output.
9422
9423Viewing Package Information with ``oe-pkgdata-util``
9424----------------------------------------------------
9425
9426You can use the ``oe-pkgdata-util`` command-line utility to query
9427:term:`PKGDATA_DIR` and display
9428various package-related information. When you use the utility, you must
9429use it to view information on packages that have already been built.
9430
9431Following are a few of the available ``oe-pkgdata-util`` subcommands.
9432
9433.. note::
9434
9435 You can use the standard \* and ? globbing wildcards as part of
9436 package names and paths.
9437
9438- ``oe-pkgdata-util list-pkgs [pattern]``: Lists all packages
9439 that have been built, optionally limiting the match to packages that
9440 match pattern.
9441
9442- ``oe-pkgdata-util list-pkg-files package ...``: Lists the
9443 files and directories contained in the given packages.
9444
9445 .. note::
9446
9447 A different way to view the contents of a package is to look at
9448 the
9449 ``${``\ :term:`WORKDIR`\ ``}/packages-split``
9450 directory of the recipe that generates the package. This directory
9451 is created by the
9452 :ref:`ref-tasks-package` task
9453 and has one subdirectory for each package the recipe generates,
9454 which contains the files stored in that package.
9455
9456 If you want to inspect the ``${WORKDIR}/packages-split``
9457 directory, make sure that
9458 :ref:`rm_work <ref-classes-rm-work>` is not
9459 enabled when you build the recipe.
9460
9461- ``oe-pkgdata-util find-path path ...``: Lists the names of
9462 the packages that contain the given paths. For example, the following
9463 tells us that ``/usr/share/man/man1/make.1`` is contained in the
9464 ``make-doc`` package:
9465 ::
9466
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009467 $ oe-pkgdata-util find-path /usr/share/man/man1/make.1
9468 make-doc: /usr/share/man/man1/make.1
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009469
9470- ``oe-pkgdata-util lookup-recipe package ...``: Lists the name
9471 of the recipes that produce the given packages.
9472
9473For more information on the ``oe-pkgdata-util`` command, use the help
9474facility:
9475::
9476
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009477 $ oe-pkgdata-util --help
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009478 $ oe-pkgdata-util subcommand --help
9479
9480.. _dev-viewing-dependencies-between-recipes-and-tasks:
9481
9482Viewing Dependencies Between Recipes and Tasks
9483----------------------------------------------
9484
9485Sometimes it can be hard to see why BitBake wants to build other recipes
9486before the one you have specified. Dependency information can help you
9487understand why a recipe is built.
9488
9489To generate dependency information for a recipe, run the following
9490command:
9491::
9492
9493 $ bitbake -g recipename
9494
9495This command writes the following files in the current directory:
9496
9497- ``pn-buildlist``: A list of recipes/targets involved in building
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009498 `recipename`. "Involved" here means that at least one task from the
9499 recipe needs to run when building `recipename` from scratch. Targets
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009500 that are in
9501 :term:`ASSUME_PROVIDED`
9502 are not listed.
9503
9504- ``task-depends.dot``: A graph showing dependencies between tasks.
9505
9506The graphs are in
9507`DOT <https://en.wikipedia.org/wiki/DOT_%28graph_description_language%29>`__
9508format and can be converted to images (e.g. using the ``dot`` tool from
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009509`Graphviz <https://www.graphviz.org/>`__).
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009510
9511.. note::
9512
9513 - DOT files use a plain text format. The graphs generated using the
9514 ``bitbake -g`` command are often so large as to be difficult to
9515 read without special pruning (e.g. with Bitbake's ``-I`` option)
9516 and processing. Despite the form and size of the graphs, the
9517 corresponding ``.dot`` files can still be possible to read and
9518 provide useful information.
9519
9520 As an example, the ``task-depends.dot`` file contains lines such
9521 as the following:
9522 ::
9523
9524 "libxslt.do_configure" -> "libxml2.do_populate_sysroot"
9525
9526 The above example line reveals that the
9527 :ref:`ref-tasks-configure`
9528 task in ``libxslt`` depends on the
9529 :ref:`ref-tasks-populate_sysroot`
9530 task in ``libxml2``, which is a normal
9531 :term:`DEPENDS` dependency
9532 between the two recipes.
9533
9534 - For an example of how ``.dot`` files can be processed, see the
9535 ``scripts/contrib/graph-tool`` Python script, which finds and
9536 displays paths between graph nodes.
9537
9538You can use a different method to view dependency information by using
9539the following command:
9540::
9541
9542 $ bitbake -g -u taskexp recipename
9543
9544This command
9545displays a GUI window from which you can view build-time and runtime
9546dependencies for the recipes involved in building recipename.
9547
9548.. _dev-viewing-task-variable-dependencies:
9549
9550Viewing Task Variable Dependencies
9551----------------------------------
9552
9553As mentioned in the
9554":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-execution:checksums (signatures)`" section of the BitBake
9555User Manual, BitBake tries to automatically determine what variables a
9556task depends on so that it can rerun the task if any values of the
9557variables change. This determination is usually reliable. However, if
9558you do things like construct variable names at runtime, then you might
9559have to manually declare dependencies on those variables using
9560``vardeps`` as described in the
9561":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags`" section of the BitBake
9562User Manual.
9563
9564If you are unsure whether a variable dependency is being picked up
9565automatically for a given task, you can list the variable dependencies
9566BitBake has determined by doing the following:
9567
95681. Build the recipe containing the task:
9569::
9570
9571 $ bitbake recipename
9572
95732. Inside the :term:`STAMPS_DIR`
9574 directory, find the signature data (``sigdata``) file that
9575 corresponds to the task. The ``sigdata`` files contain a pickled
9576 Python database of all the metadata that went into creating the input
9577 checksum for the task. As an example, for the
9578 :ref:`ref-tasks-fetch` task of the
9579 ``db`` recipe, the ``sigdata`` file might be found in the following
9580 location:
9581 ::
9582
9583 ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
9584
9585 For tasks that are accelerated through the shared state
9586 (:ref:`sstate <overview-manual/overview-manual-concepts:shared state cache>`) cache, an
9587 additional ``siginfo`` file is written into
9588 :term:`SSTATE_DIR` along with
9589 the cached task output. The ``siginfo`` files contain exactly the
9590 same information as ``sigdata`` files.
9591
95923. Run ``bitbake-dumpsig`` on the ``sigdata`` or ``siginfo`` file. Here
9593 is an example:
9594 ::
9595
9596 $ bitbake-dumpsig ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
9597
9598 In the output of the above command, you will find a line like the
9599 following, which lists all the (inferred) variable dependencies for
9600 the task. This list also includes indirect dependencies from
9601 variables depending on other variables, recursively.
9602 ::
9603
9604 Task dependencies: ['PV', 'SRCREV', 'SRC_URI', 'SRC_URI[md5sum]', 'SRC_URI[sha256sum]', 'base_do_fetch']
9605
9606 .. note::
9607
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009608 Functions (e.g. ``base_do_fetch``) also count as variable dependencies.
9609 These functions in turn depend on the variables they reference.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009610
9611 The output of ``bitbake-dumpsig`` also includes the value each
9612 variable had, a list of dependencies for each variable, and
9613 :term:`bitbake:BB_HASHBASE_WHITELIST`
9614 information.
9615
9616There is also a ``bitbake-diffsigs`` command for comparing two
9617``siginfo`` or ``sigdata`` files. This command can be helpful when
9618trying to figure out what changed between two versions of a task. If you
9619call ``bitbake-diffsigs`` with just one file, the command behaves like
9620``bitbake-dumpsig``.
9621
9622You can also use BitBake to dump out the signature construction
9623information without executing tasks by using either of the following
9624BitBake command-line options:
9625::
9626
9627 ‐‐dump-signatures=SIGNATURE_HANDLER
9628 -S SIGNATURE_HANDLER
9629
9630
9631.. note::
9632
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009633 Two common values for `SIGNATURE_HANDLER` are "none" and "printdiff", which
9634 dump only the signature or compare the dumped signature with the cached one,
9635 respectively.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009636
9637Using BitBake with either of these options causes BitBake to dump out
9638``sigdata`` files in the ``stamps`` directory for every task it would
9639have executed instead of building the specified target package.
9640
9641.. _dev-viewing-metadata-used-to-create-the-input-signature-of-a-shared-state-task:
9642
9643Viewing Metadata Used to Create the Input Signature of a Shared State Task
9644--------------------------------------------------------------------------
9645
9646Seeing what metadata went into creating the input signature of a shared
9647state (sstate) task can be a useful debugging aid. This information is
9648available in signature information (``siginfo``) files in
9649:term:`SSTATE_DIR`. For
9650information on how to view and interpret information in ``siginfo``
9651files, see the "`Viewing Task Variable
9652Dependencies <#dev-viewing-task-variable-dependencies>`__" section.
9653
9654For conceptual information on shared state, see the
9655":ref:`overview-manual/overview-manual-concepts:shared state`"
9656section in the Yocto Project Overview and Concepts Manual.
9657
9658.. _dev-invalidating-shared-state-to-force-a-task-to-run:
9659
9660Invalidating Shared State to Force a Task to Run
9661------------------------------------------------
9662
9663The OpenEmbedded build system uses
9664:ref:`checksums <overview-checksums>` and
9665:ref:`overview-manual/overview-manual-concepts:shared state` cache to avoid unnecessarily
9666rebuilding tasks. Collectively, this scheme is known as "shared state
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009667code".
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009668
9669As with all schemes, this one has some drawbacks. It is possible that
9670you could make implicit changes to your code that the checksum
9671calculations do not take into account. These implicit changes affect a
9672task's output but do not trigger the shared state code into rebuilding a
9673recipe. Consider an example during which a tool changes its output.
9674Assume that the output of ``rpmdeps`` changes. The result of the change
9675should be that all the ``package`` and ``package_write_rpm`` shared
9676state cache items become invalid. However, because the change to the
9677output is external to the code and therefore implicit, the associated
9678shared state cache items do not become invalidated. In this case, the
9679build process uses the cached items rather than running the task again.
9680Obviously, these types of implicit changes can cause problems.
9681
9682To avoid these problems during the build, you need to understand the
9683effects of any changes you make. Realize that changes you make directly
9684to a function are automatically factored into the checksum calculation.
9685Thus, these explicit changes invalidate the associated area of shared
9686state cache. However, you need to be aware of any implicit changes that
9687are not obvious changes to the code and could affect the output of a
9688given task.
9689
9690When you identify an implicit change, you can easily take steps to
9691invalidate the cache and force the tasks to run. The steps you can take
9692are as simple as changing a function's comments in the source code. For
9693example, to invalidate package shared state files, change the comment
9694statements of
9695:ref:`ref-tasks-package` or the
9696comments of one of the functions it calls. Even though the change is
9697purely cosmetic, it causes the checksum to be recalculated and forces
9698the build system to run the task again.
9699
9700.. note::
9701
9702 For an example of a commit that makes a cosmetic change to invalidate
9703 shared state, see this
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009704 :yocto_git:`commit </cgit.cgi/poky/commit/meta/classes/package.bbclass?id=737f8bbb4f27b4837047cb9b4fbfe01dfde36d54>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009705
9706.. _dev-debugging-taskrunning:
9707
9708Running Specific Tasks
9709----------------------
9710
9711Any given recipe consists of a set of tasks. The standard BitBake
9712behavior in most cases is: ``do_fetch``, ``do_unpack``, ``do_patch``,
9713``do_configure``, ``do_compile``, ``do_install``, ``do_package``,
9714``do_package_write_*``, and ``do_build``. The default task is
9715``do_build`` and any tasks on which it depends build first. Some tasks,
9716such as ``do_devshell``, are not part of the default build chain. If you
9717wish to run a task that is not part of the default build chain, you can
9718use the ``-c`` option in BitBake. Here is an example:
9719::
9720
9721 $ bitbake matchbox-desktop -c devshell
9722
9723The ``-c`` option respects task dependencies, which means that all other
9724tasks (including tasks from other recipes) that the specified task
9725depends on will be run before the task. Even when you manually specify a
9726task to run with ``-c``, BitBake will only run the task if it considers
9727it "out of date". See the
9728":ref:`overview-manual/overview-manual-concepts:stamp files and the rerunning of tasks`"
9729section in the Yocto Project Overview and Concepts Manual for how
9730BitBake determines whether a task is "out of date".
9731
9732If you want to force an up-to-date task to be rerun (e.g. because you
9733made manual modifications to the recipe's
9734:term:`WORKDIR` that you want to try
9735out), then you can use the ``-f`` option.
9736
9737.. note::
9738
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009739 The reason ``-f`` is never required when running the
9740 :ref:`ref-tasks-devshell` task is because the
9741 [\ :ref:`nostamp <bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ]
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009742 variable flag is already set for the task.
9743
9744The following example shows one way you can use the ``-f`` option:
9745::
9746
9747 $ bitbake matchbox-desktop
9748 .
9749 .
9750 make some changes to the source code in the work directory
9751 .
9752 .
9753 $ bitbake matchbox-desktop -c compile -f
9754 $ bitbake matchbox-desktop
9755
9756This sequence first builds and then recompiles ``matchbox-desktop``. The
9757last command reruns all tasks (basically the packaging tasks) after the
9758compile. BitBake recognizes that the ``do_compile`` task was rerun and
9759therefore understands that the other tasks also need to be run again.
9760
9761Another, shorter way to rerun a task and all
9762:ref:`ref-manual/ref-tasks:normal recipe build tasks`
9763that depend on it is to use the ``-C`` option.
9764
9765.. note::
9766
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009767 This option is upper-cased and is separate from the ``-c``
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009768 option, which is lower-cased.
9769
9770Using this option invalidates the given task and then runs the
9771:ref:`ref-tasks-build` task, which is
9772the default task if no task is given, and the tasks on which it depends.
9773You could replace the final two commands in the previous example with
9774the following single command:
9775::
9776
9777 $ bitbake matchbox-desktop -C compile
9778
9779Internally, the ``-f`` and ``-C`` options work by tainting (modifying)
9780the input checksum of the specified task. This tainting indirectly
9781causes the task and its dependent tasks to be rerun through the normal
9782task dependency mechanisms.
9783
9784.. note::
9785
9786 BitBake explicitly keeps track of which tasks have been tainted in
9787 this fashion, and will print warnings such as the following for
9788 builds involving such tasks:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009789
9790 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009791
9792 WARNING: /home/ulf/poky/meta/recipes-sato/matchbox-desktop/matchbox-desktop_2.1.bb.do_compile is tainted from a forced run
9793
9794
9795 The purpose of the warning is to let you know that the work directory
9796 and build output might not be in the clean state they would be in for
9797 a "normal" build, depending on what actions you took. To get rid of
9798 such warnings, you can remove the work directory and rebuild the
9799 recipe, as follows:
9800 ::
9801
9802 $ bitbake matchbox-desktop -c clean
9803 $ bitbake matchbox-desktop
9804
9805
9806You can view a list of tasks in a given package by running the
9807``do_listtasks`` task as follows:
9808::
9809
9810 $ bitbake matchbox-desktop -c listtasks
9811
9812The results appear as output to the console and are also in
9813the file ``${WORKDIR}/temp/log.do_listtasks``.
9814
9815.. _dev-debugging-bitbake:
9816
9817General BitBake Problems
9818------------------------
9819
9820You can see debug output from BitBake by using the ``-D`` option. The
9821debug output gives more information about what BitBake is doing and the
9822reason behind it. Each ``-D`` option you use increases the logging
9823level. The most common usage is ``-DDD``.
9824
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009825The output from ``bitbake -DDD -v targetname`` can reveal why BitBake
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009826chose a certain version of a package or why BitBake picked a certain
9827provider. This command could also help you in a situation where you
9828think BitBake did something unexpected.
9829
9830.. _dev-debugging-buildfile:
9831
9832Building with No Dependencies
9833-----------------------------
9834
9835To build a specific recipe (``.bb`` file), you can use the following
9836command form:
9837::
9838
9839 $ bitbake -b somepath/somerecipe.bb
9840
9841This command form does
9842not check for dependencies. Consequently, you should use it only when
9843you know existing dependencies have been met.
9844
9845.. note::
9846
9847 You can also specify fragments of the filename. In this case, BitBake
9848 checks for a unique match.
9849
9850Recipe Logging Mechanisms
9851-------------------------
9852
9853The Yocto Project provides several logging functions for producing
9854debugging output and reporting errors and warnings. For Python
9855functions, the following logging functions exist. All of these functions
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009856log to ``${T}/log.do_``\ `task`, and can also log to standard output
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009857(stdout) with the right settings:
9858
9859- ``bb.plain(msg)``: Writes msg as is to the log while also
9860 logging to stdout.
9861
9862- ``bb.note(msg)``: Writes "NOTE: msg" to the log. Also logs to
9863 stdout if BitBake is called with "-v".
9864
9865- ``bb.debug(level, msg)``: Writes "DEBUG: msg" to the
9866 log. Also logs to stdout if the log level is greater than or equal to
9867 level. See the ":ref:`-D <bitbake:bitbake-user-manual/bitbake-user-manual-intro:usage and syntax>`" option
9868 in the BitBake User Manual for more information.
9869
9870- ``bb.warn(msg)``: Writes "WARNING: msg" to the log while also
9871 logging to stdout.
9872
9873- ``bb.error(msg)``: Writes "ERROR: msg" to the log while also
9874 logging to standard out (stdout).
9875
9876 .. note::
9877
9878 Calling this function does not cause the task to fail.
9879
9880- ``bb.fatal(``\ msg\ ``)``: This logging function is similar to
9881 ``bb.error(``\ msg\ ``)`` but also causes the calling task to fail.
9882
9883 .. note::
9884
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009885 ``bb.fatal()`` raises an exception, which means you do not need to put a
9886 "return" statement after the function.
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009887
9888The same logging functions are also available in shell functions, under
9889the names ``bbplain``, ``bbnote``, ``bbdebug``, ``bbwarn``, ``bberror``,
9890and ``bbfatal``. The
9891:ref:`logging <ref-classes-logging>` class
9892implements these functions. See that class in the ``meta/classes``
9893folder of the :term:`Source Directory` for information.
9894
9895Logging With Python
9896~~~~~~~~~~~~~~~~~~~
9897
9898When creating recipes using Python and inserting code that handles build
9899logs, keep in mind the goal is to have informative logs while keeping
9900the console as "silent" as possible. Also, if you want status messages
9901in the log, use the "debug" loglevel.
9902
9903Following is an example written in Python. The code handles logging for
9904a function that determines the number of tasks needed to be run. See the
9905":ref:`ref-tasks-listtasks`"
9906section for additional information:
9907::
9908
9909 python do_listtasks() {
9910 bb.debug(2, "Starting to figure out the task list")
9911 if noteworthy_condition:
9912 bb.note("There are 47 tasks to run")
9913 bb.debug(2, "Got to point xyz")
9914 if warning_trigger:
9915 bb.warn("Detected warning_trigger, this might be a problem later.")
9916 if recoverable_error:
9917 bb.error("Hit recoverable_error, you really need to fix this!")
9918 if fatal_error:
9919 bb.fatal("fatal_error detected, unable to print the task list")
9920 bb.plain("The tasks present are abc")
9921 bb.debug(2, "Finished figuring out the tasklist")
9922 }
9923
9924Logging With Bash
9925~~~~~~~~~~~~~~~~~
9926
9927When creating recipes using Bash and inserting code that handles build
9928logs, you have the same goals - informative with minimal console output.
9929The syntax you use for recipes written in Bash is similar to that of
9930recipes written in Python described in the previous section.
9931
9932Following is an example written in Bash. The code logs the progress of
9933the ``do_my_function`` function.
9934::
9935
9936 do_my_function() {
9937 bbdebug 2 "Running do_my_function"
9938 if [ exceptional_condition ]; then
9939 bbnote "Hit exceptional_condition"
9940 fi
9941 bbdebug 2 "Got to point xyz"
9942 if [ warning_trigger ]; then
9943 bbwarn "Detected warning_trigger, this might cause a problem later."
9944 fi
9945 if [ recoverable_error ]; then
9946 bberror "Hit recoverable_error, correcting"
9947 fi
9948 if [ fatal_error ]; then
9949 bbfatal "fatal_error detected"
9950 fi
9951 bbdebug 2 "Completed do_my_function"
9952 }
9953
9954
9955Debugging Parallel Make Races
9956-----------------------------
9957
9958A parallel ``make`` race occurs when the build consists of several parts
9959that are run simultaneously and a situation occurs when the output or
9960result of one part is not ready for use with a different part of the
9961build that depends on that output. Parallel make races are annoying and
9962can sometimes be difficult to reproduce and fix. However, some simple
9963tips and tricks exist that can help you debug and fix them. This section
9964presents a real-world example of an error encountered on the Yocto
9965Project autobuilder and the process used to fix it.
9966
9967.. note::
9968
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009969 If you cannot properly fix a ``make`` race condition, you can work around it
9970 by clearing either the :term:`PARALLEL_MAKE` or :term:`PARALLEL_MAKEINST`
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009971 variables.
9972
9973The Failure
9974~~~~~~~~~~~
9975
9976For this example, assume that you are building an image that depends on
9977the "neard" package. And, during the build, BitBake runs into problems
9978and creates the following output.
9979
9980.. note::
9981
9982 This example log file has longer lines artificially broken to make
9983 the listing easier to read.
9984
9985If you examine the output or the log file, you see the failure during
9986``make``:
Andrew Geissler4c19ea12020-10-27 13:52:24 -05009987
9988.. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -05009989
9990 | DEBUG: SITE files ['endian-little', 'bit-32', 'ix86-common', 'common-linux', 'common-glibc', 'i586-linux', 'common']
9991 | DEBUG: Executing shell function do_compile
9992 | NOTE: make -j 16
9993 | make --no-print-directory all-am
9994 | /bin/mkdir -p include/near
9995 | /bin/mkdir -p include/near
9996 | /bin/mkdir -p include/near
9997 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
9998 0.14-r0/neard-0.14/include/types.h include/near/types.h
9999 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
10000 0.14-r0/neard-0.14/include/log.h include/near/log.h
10001 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
10002 0.14-r0/neard-0.14/include/plugin.h include/near/plugin.h
10003 | /bin/mkdir -p include/near
10004 | /bin/mkdir -p include/near
10005 | /bin/mkdir -p include/near
10006 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
10007 0.14-r0/neard-0.14/include/tag.h include/near/tag.h
10008 | /bin/mkdir -p include/near
10009 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
10010 0.14-r0/neard-0.14/include/adapter.h include/near/adapter.h
10011 | /bin/mkdir -p include/near
10012 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
10013 0.14-r0/neard-0.14/include/ndef.h include/near/ndef.h
10014 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
10015 0.14-r0/neard-0.14/include/tlv.h include/near/tlv.h
10016 | /bin/mkdir -p include/near
10017 | /bin/mkdir -p include/near
10018 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
10019 0.14-r0/neard-0.14/include/setting.h include/near/setting.h
10020 | /bin/mkdir -p include/near
10021 | /bin/mkdir -p include/near
10022 | /bin/mkdir -p include/near
10023 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
10024 0.14-r0/neard-0.14/include/device.h include/near/device.h
10025 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
10026 0.14-r0/neard-0.14/include/nfc_copy.h include/near/nfc_copy.h
10027 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
10028 0.14-r0/neard-0.14/include/snep.h include/near/snep.h
10029 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
10030 0.14-r0/neard-0.14/include/version.h include/near/version.h
10031 | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
10032 0.14-r0/neard-0.14/include/dbus.h include/near/dbus.h
10033 | ./src/genbuiltin nfctype1 nfctype2 nfctype3 nfctype4 p2p > src/builtin.h
10034 | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/
10035 build/build/tmp/sysroots/qemux86 -DHAVE_CONFIG_H -I. -I./include -I./src -I./gdbus -I/home/pokybuild/
10036 yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/glib-2.0
10037 -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/
10038 lib/glib-2.0/include -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/
10039 tmp/sysroots/qemux86/usr/include/dbus-1.0 -I/home/pokybuild/yocto-autobuilder/yocto-slave/
10040 nightly-x86/build/build/tmp/sysroots/qemux86/usr/lib/dbus-1.0/include -I/home/pokybuild/yocto-autobuilder/
10041 yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/libnl3
10042 -DNEAR_PLUGIN_BUILTIN -DPLUGINDIR=\""/usr/lib/near/plugins"\"
10043 -DCONFIGDIR=\""/etc/neard\"" -O2 -pipe -g -feliminate-unused-debug-types -c
10044 -o tools/snep-send.o tools/snep-send.c
10045 | In file included from tools/snep-send.c:16:0:
10046 | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
10047 | #include <near/dbus.h>
10048 | ^
10049 | compilation terminated.
10050 | make[1]: *** [tools/snep-send.o] Error 1
10051 | make[1]: *** Waiting for unfinished jobs....
10052 | make: *** [all] Error 2
10053 | ERROR: oe_runmake failed
10054
10055Reproducing the Error
10056~~~~~~~~~~~~~~~~~~~~~
10057
10058Because race conditions are intermittent, they do not manifest
10059themselves every time you do the build. In fact, most times the build
10060will complete without problems even though the potential race condition
10061exists. Thus, once the error surfaces, you need a way to reproduce it.
10062
10063In this example, compiling the "neard" package is causing the problem.
10064So the first thing to do is build "neard" locally. Before you start the
10065build, set the
10066:term:`PARALLEL_MAKE` variable
10067in your ``local.conf`` file to a high number (e.g. "-j 20"). Using a
10068high value for ``PARALLEL_MAKE`` increases the chances of the race
10069condition showing up:
10070::
10071
10072 $ bitbake neard
10073
10074Once the local build for "neard" completes, start a ``devshell`` build:
10075::
10076
10077 $ bitbake neard -c devshell
10078
10079For information on how to use a
10080``devshell``, see the "`Using a Development
10081Shell <#platdev-appdev-devshell>`__" section.
10082
10083In the ``devshell``, do the following:
10084::
10085
10086 $ make clean
10087 $ make tools/snep-send.o
10088
10089The ``devshell`` commands cause the failure to clearly
10090be visible. In this case, a missing dependency exists for the "neard"
10091Makefile target. Here is some abbreviated, sample output with the
10092missing dependency clearly visible at the end:
10093::
10094
10095 i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/scott-lenovo/......
10096 .
10097 .
10098 .
10099 tools/snep-send.c
10100 In file included from tools/snep-send.c:16:0:
10101 tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
10102 #include <near/dbus.h>
10103 ^
10104 compilation terminated.
10105 make: *** [tools/snep-send.o] Error 1
10106 $
10107
10108
10109Creating a Patch for the Fix
10110~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10111
10112Because there is a missing dependency for the Makefile target, you need
10113to patch the ``Makefile.am`` file, which is generated from
10114``Makefile.in``. You can use Quilt to create the patch:
10115::
10116
10117 $ quilt new parallelmake.patch
10118 Patch patches/parallelmake.patch is now on top
10119 $ quilt add Makefile.am
10120 File Makefile.am added to patch patches/parallelmake.patch
10121
10122For more information on using Quilt, see the
10123"`Using Quilt in Your Workflow <#using-a-quilt-workflow>`__" section.
10124
10125At this point you need to make the edits to ``Makefile.am`` to add the
10126missing dependency. For our example, you have to add the following line
10127to the file:
10128::
10129
10130 tools/snep-send.$(OBJEXT): include/near/dbus.h
10131
10132Once you have edited the file, use the ``refresh`` command to create the
10133patch:
10134::
10135
10136 $ quilt refresh
10137 Refreshed patch patches/parallelmake.patch
10138
10139Once
10140the patch file exists, you need to add it back to the originating recipe
10141folder. Here is an example assuming a top-level
10142:term:`Source Directory` named ``poky``:
10143::
10144
10145 $ cp patches/parallelmake.patch poky/meta/recipes-connectivity/neard/neard
10146
10147The final thing you need to do to implement the fix in the build is to
10148update the "neard" recipe (i.e. ``neard-0.14.bb``) so that the
10149:term:`SRC_URI` statement includes
10150the patch file. The recipe file is in the folder above the patch. Here
10151is what the edited ``SRC_URI`` statement would look like:
10152::
10153
10154 SRC_URI = "${KERNELORG_MIRROR}/linux/network/nfc/${BPN}-${PV}.tar.xz \
10155 file://neard.in \
10156 file://neard.service.in \
10157 file://parallelmake.patch \
10158 "
10159
10160With the patch complete and moved to the correct folder and the
10161``SRC_URI`` statement updated, you can exit the ``devshell``:
10162::
10163
10164 $ exit
10165
10166Testing the Build
10167~~~~~~~~~~~~~~~~~
10168
10169With everything in place, you can get back to trying the build again
10170locally:
10171::
10172
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010173 $ bitbake neard
10174
10175This build should succeed.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010176
10177Now you can open up a ``devshell`` again and repeat the clean and make
10178operations as follows:
10179::
10180
10181 $ bitbake neard -c devshell
10182 $ make clean
10183 $ make tools/snep-send.o
10184
10185The build should work without issue.
10186
10187As with all solved problems, if they originated upstream, you need to
10188submit the fix for the recipe in OE-Core and upstream so that the
10189problem is taken care of at its source. See the "`Submitting a Change to
10190the Yocto Project <#how-to-submit-a-change>`__" section for more
10191information.
10192
10193.. _platdev-gdb-remotedebug:
10194
10195Debugging With the GNU Project Debugger (GDB) Remotely
10196------------------------------------------------------
10197
10198GDB allows you to examine running programs, which in turn helps you to
10199understand and fix problems. It also allows you to perform post-mortem
10200style analysis of program crashes. GDB is available as a package within
10201the Yocto Project and is installed in SDK images by default. See the
10202":ref:`ref-manual/ref-images:Images`" chapter in the Yocto
10203Project Reference Manual for a description of these images. You can find
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010204information on GDB at https://sourceware.org/gdb/.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010205
10206.. note::
10207
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010208 For best results, install debug (``-dbg``) packages for the applications you
10209 are going to debug. Doing so makes extra debug symbols available that give
10210 you more meaningful output.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010211
10212Sometimes, due to memory or disk space constraints, it is not possible
10213to use GDB directly on the remote target to debug applications. These
10214constraints arise because GDB needs to load the debugging information
10215and the binaries of the process being debugged. Additionally, GDB needs
10216to perform many computations to locate information such as function
10217names, variable names and values, stack traces and so forth - even
10218before starting the debugging process. These extra computations place
10219more load on the target system and can alter the characteristics of the
10220program being debugged.
10221
10222To help get past the previously mentioned constraints, you can use
10223gdbserver, which runs on the remote target and does not load any
10224debugging information from the debugged process. Instead, a GDB instance
10225processes the debugging information that is run on a remote computer -
10226the host GDB. The host GDB then sends control commands to gdbserver to
10227make it stop or start the debugged program, as well as read or write
10228memory regions of that debugged program. All the debugging information
10229loaded and processed as well as all the heavy debugging is done by the
10230host GDB. Offloading these processes gives the gdbserver running on the
10231target a chance to remain small and fast.
10232
10233Because the host GDB is responsible for loading the debugging
10234information and for doing the necessary processing to make actual
10235debugging happen, you have to make sure the host can access the
10236unstripped binaries complete with their debugging information and also
10237be sure the target is compiled with no optimizations. The host GDB must
10238also have local access to all the libraries used by the debugged
10239program. Because gdbserver does not need any local debugging
10240information, the binaries on the remote target can remain stripped.
10241However, the binaries must also be compiled without optimization so they
10242match the host's binaries.
10243
10244To remain consistent with GDB documentation and terminology, the binary
10245being debugged on the remote target machine is referred to as the
10246"inferior" binary. For documentation on GDB see the `GDB
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010247site <https://sourceware.org/gdb/documentation/>`__.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010248
10249The following steps show you how to debug using the GNU project
10250debugger.
10251
102521. *Configure your build system to construct the companion debug
10253 filesystem:*
10254
10255 In your ``local.conf`` file, set the following:
10256 ::
10257
10258 IMAGE_GEN_DEBUGFS = "1"
10259 IMAGE_FSTYPES_DEBUGFS = "tar.bz2"
10260
10261 These options cause the
10262 OpenEmbedded build system to generate a special companion filesystem
10263 fragment, which contains the matching source and debug symbols to
10264 your deployable filesystem. The build system does this by looking at
10265 what is in the deployed filesystem, and pulling the corresponding
10266 ``-dbg`` packages.
10267
10268 The companion debug filesystem is not a complete filesystem, but only
10269 contains the debug fragments. This filesystem must be combined with
10270 the full filesystem for debugging. Subsequent steps in this procedure
10271 show how to combine the partial filesystem with the full filesystem.
10272
102732. *Configure the system to include gdbserver in the target filesystem:*
10274
10275 Make the following addition in either your ``local.conf`` file or in
10276 an image recipe:
10277 ::
10278
10279 IMAGE_INSTALL_append = " gdbserver"
10280
10281 The change makes
10282 sure the ``gdbserver`` package is included.
10283
102843. *Build the environment:*
10285
10286 Use the following command to construct the image and the companion
10287 Debug Filesystem:
10288 ::
10289
10290 $ bitbake image
10291
10292 Build the cross GDB component and
10293 make it available for debugging. Build the SDK that matches the
10294 image. Building the SDK is best for a production build that can be
10295 used later for debugging, especially during long term maintenance:
10296 ::
10297
10298 $ bitbake -c populate_sdk image
10299
10300 Alternatively, you can build the minimal toolchain components that
10301 match the target. Doing so creates a smaller than typical SDK and
10302 only contains a minimal set of components with which to build simple
10303 test applications, as well as run the debugger:
10304 ::
10305
10306 $ bitbake meta-toolchain
10307
10308 A final method is to build Gdb itself within the build system:
10309 ::
10310
10311 $ bitbake gdb-cross-<architecture>
10312
10313 Doing so produces a temporary copy of
10314 ``cross-gdb`` you can use for debugging during development. While
10315 this is the quickest approach, the two previous methods in this step
10316 are better when considering long-term maintenance strategies.
10317
10318 .. note::
10319
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010320 If you run ``bitbake gdb-cross``, the OpenEmbedded build system suggests
10321 the actual image (e.g. ``gdb-cross-i586``). The suggestion is usually the
10322 actual name you want to use.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010323
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500103244. *Set up the* ``debugfs``\ *:*
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010325
10326 Run the following commands to set up the ``debugfs``:
10327 ::
10328
10329 $ mkdir debugfs
10330 $ cd debugfs
10331 $ tar xvfj build-dir/tmp-glibc/deploy/images/machine/image.rootfs.tar.bz2
10332 $ tar xvfj build-dir/tmp-glibc/deploy/images/machine/image-dbg.rootfs.tar.bz2
10333
Andrew Geissler4c19ea12020-10-27 13:52:24 -0500103345. *Set up GDB:*
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010335
10336 Install the SDK (if you built one) and then source the correct
10337 environment file. Sourcing the environment file puts the SDK in your
10338 ``PATH`` environment variable.
10339
10340 If you are using the build system, Gdb is located in
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010341 `build-dir`\ ``/tmp/sysroots/``\ `host`\ ``/usr/bin/``\ `architecture`\ ``/``\ `architecture`\ ``-gdb``
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010342
103436. *Boot the target:*
10344
10345 For information on how to run QEMU, see the `QEMU
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010346 Documentation <https://wiki.qemu.org/Documentation/GettingStartedDevelopers>`__.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010347
10348 .. note::
10349
10350 Be sure to verify that your host can access the target via TCP.
10351
103527. *Debug a program:*
10353
10354 Debugging a program involves running gdbserver on the target and then
10355 running Gdb on the host. The example in this step debugs ``gzip``:
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010356
10357 .. code-block:: shell
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010358
10359 root@qemux86:~# gdbserver localhost:1234 /bin/gzip —help
10360
10361 For
10362 additional gdbserver options, see the `GDB Server
10363 Documentation <https://www.gnu.org/software/gdb/documentation/>`__.
10364
10365 After running gdbserver on the target, you need to run Gdb on the
10366 host and configure it and connect to the target. Use these commands:
10367 ::
10368
10369 $ cd directory-holding-the-debugfs-directory
10370 $ arch-gdb
10371 (gdb) set sysroot debugfs
10372 (gdb) set substitute-path /usr/src/debug debugfs/usr/src/debug
10373 (gdb) target remote IP-of-target:1234
10374
10375 At this
10376 point, everything should automatically load (i.e. matching binaries,
10377 symbols and headers).
10378
10379 .. note::
10380
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010381 The Gdb ``set`` commands in the previous example can be placed into the
10382 users ``~/.gdbinit`` file. Upon starting, Gdb automatically runs whatever
10383 commands are in that file.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010384
103858. *Deploying without a full image rebuild:*
10386
10387 In many cases, during development you want a quick method to deploy a
10388 new binary to the target and debug it, without waiting for a full
10389 image build.
10390
10391 One approach to solving this situation is to just build the component
10392 you want to debug. Once you have built the component, copy the
10393 executable directly to both the target and the host ``debugfs``.
10394
10395 If the binary is processed through the debug splitting in
10396 OpenEmbedded, you should also copy the debug items (i.e. ``.debug``
10397 contents and corresponding ``/usr/src/debug`` files) from the work
10398 directory. Here is an example:
10399 ::
10400
10401 $ bitbake bash
10402 $ bitbake -c devshell bash
10403 $ cd ..
10404 $ scp packages-split/bash/bin/bash target:/bin/bash
10405 $ cp -a packages-split/bash-dbg/\* path/debugfs
10406
10407Debugging with the GNU Project Debugger (GDB) on the Target
10408-----------------------------------------------------------
10409
10410The previous section addressed using GDB remotely for debugging
10411purposes, which is the most usual case due to the inherent hardware
10412limitations on many embedded devices. However, debugging in the target
10413hardware itself is also possible with more powerful devices. This
10414section describes what you need to do in order to support using GDB to
10415debug on the target hardware.
10416
10417To support this kind of debugging, you need do the following:
10418
10419- Ensure that GDB is on the target. You can do this by adding "gdb" to
10420 :term:`IMAGE_INSTALL`:
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010421 ::
10422
10423 IMAGE_INSTALL_append = " gdb"
10424
10425 Alternatively, you can add "tools-debug" to :term:`IMAGE_FEATURES`:
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010426 ::
10427
10428 IMAGE_FEATURES_append = " tools-debug"
10429
10430- Ensure that debug symbols are present. You can make sure these
10431 symbols are present by installing ``-dbg``:
10432 ::
10433
10434 IMAGE_INSTALL_append = "packagename-dbg"
10435
10436 Alternatively, you can do the following to include
10437 all the debug symbols:
10438 ::
10439
10440 IMAGE_FEATURES_append = " dbg-pkgs"
10441
10442.. note::
10443
10444 To improve the debug information accuracy, you can reduce the level
10445 of optimization used by the compiler. For example, when adding the
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010446 following line to your ``local.conf`` file, you will reduce optimization
10447 from :term:`FULL_OPTIMIZATION` of "-O2" to :term:`DEBUG_OPTIMIZATION`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010448 of "-O -fno-omit-frame-pointer":
10449 ::
10450
10451 DEBUG_BUILD = "1"
10452
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010453 Consider that this will reduce the application's performance and is
10454 recommended only for debugging purposes.
10455
10456.. _dev-other-debugging-others:
10457
10458Other Debugging Tips
10459--------------------
10460
10461Here are some other tips that you might find useful:
10462
10463- When adding new packages, it is worth watching for undesirable items
10464 making their way into compiler command lines. For example, you do not
10465 want references to local system files like ``/usr/lib/`` or
10466 ``/usr/include/``.
10467
10468- If you want to remove the ``psplash`` boot splashscreen, add
10469 ``psplash=false`` to the kernel command line. Doing so prevents
10470 ``psplash`` from loading and thus allows you to see the console. It
10471 is also possible to switch out of the splashscreen by switching the
10472 virtual console (e.g. Fn+Left or Fn+Right on a Zaurus).
10473
10474- Removing :term:`TMPDIR` (usually
10475 ``tmp/``, within the
10476 :term:`Build Directory`) can often fix
10477 temporary build issues. Removing ``TMPDIR`` is usually a relatively
10478 cheap operation, because task output will be cached in
10479 :term:`SSTATE_DIR` (usually
10480 ``sstate-cache/``, which is also in the Build Directory).
10481
10482 .. note::
10483
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010484 Removing ``TMPDIR`` might be a workaround rather than a fix.
10485 Consequently, trying to determine the underlying cause of an issue before
10486 removing the directory is a good idea.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010487
10488- Understanding how a feature is used in practice within existing
10489 recipes can be very helpful. It is recommended that you configure
10490 some method that allows you to quickly search through files.
10491
10492 Using GNU Grep, you can use the following shell function to
10493 recursively search through common recipe-related files, skipping
10494 binary files, ``.git`` directories, and the Build Directory (assuming
10495 its name starts with "build"):
10496 ::
10497
10498 g() {
10499 grep -Ir \
10500 --exclude-dir=.git \
10501 --exclude-dir='build*' \
10502 --include='*.bb*' \
10503 --include='*.inc*' \
10504 --include='*.conf*' \
10505 --include='*.py*' \
10506 "$@"
10507 }
10508
10509 Following are some usage examples:
10510 ::
10511
10512 $ g FOO # Search recursively for "FOO"
10513 $ g -i foo # Search recursively for "foo", ignoring case
10514 $ g -w FOO # Search recursively for "FOO" as a word, ignoring e.g. "FOOBAR"
10515
10516 If figuring
10517 out how some feature works requires a lot of searching, it might
10518 indicate that the documentation should be extended or improved. In
10519 such cases, consider filing a documentation bug using the Yocto
10520 Project implementation of
10521 :yocto_bugs:`Bugzilla <>`. For information on
10522 how to submit a bug against the Yocto Project, see the Yocto Project
10523 Bugzilla :yocto_wiki:`wiki page </wiki/Bugzilla_Configuration_and_Bug_Tracking>`
10524 and the "`Submitting a Defect Against the Yocto
10525 Project <#submitting-a-defect-against-the-yocto-project>`__" section.
10526
10527 .. note::
10528
10529 The manuals might not be the right place to document variables
10530 that are purely internal and have a limited scope (e.g. internal
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010531 variables used to implement a single ``.bbclass`` file).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010532
10533Making Changes to the Yocto Project
10534===================================
10535
10536Because the Yocto Project is an open-source, community-based project,
10537you can effect changes to the project. This section presents procedures
10538that show you how to submit a defect against the project and how to
10539submit a change.
10540
10541Submitting a Defect Against the Yocto Project
10542---------------------------------------------
10543
10544Use the Yocto Project implementation of
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010545`Bugzilla <https://www.bugzilla.org/about/>`__ to submit a defect (bug)
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010546against the Yocto Project. For additional information on this
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010547implementation of Bugzilla see the ":ref:`Yocto Project
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010548Bugzilla <resources-bugtracker>`" section in the
10549Yocto Project Reference Manual. For more detail on any of the following
10550steps, see the Yocto Project
10551:yocto_wiki:`Bugzilla wiki page </wiki/Bugzilla_Configuration_and_Bug_Tracking>`.
10552
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010553Use the following general steps to submit a bug:
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010554
105551. Open the Yocto Project implementation of :yocto_bugs:`Bugzilla <>`.
10556
105572. Click "File a Bug" to enter a new bug.
10558
105593. Choose the appropriate "Classification", "Product", and "Component"
10560 for which the bug was found. Bugs for the Yocto Project fall into
10561 one of several classifications, which in turn break down into
10562 several products and components. For example, for a bug against the
10563 ``meta-intel`` layer, you would choose "Build System, Metadata &
10564 Runtime", "BSPs", and "bsps-meta-intel", respectively.
10565
105664. Choose the "Version" of the Yocto Project for which you found the
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010567 bug (e.g. &DISTRO;).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010568
105695. Determine and select the "Severity" of the bug. The severity
10570 indicates how the bug impacted your work.
10571
105726. Choose the "Hardware" that the bug impacts.
10573
105747. Choose the "Architecture" that the bug impacts.
10575
105768. Choose a "Documentation change" item for the bug. Fixing a bug might
10577 or might not affect the Yocto Project documentation. If you are
10578 unsure of the impact to the documentation, select "Don't Know".
10579
105809. Provide a brief "Summary" of the bug. Try to limit your summary to
10581 just a line or two and be sure to capture the essence of the bug.
10582
1058310. Provide a detailed "Description" of the bug. You should provide as
10584 much detail as you can about the context, behavior, output, and so
10585 forth that surrounds the bug. You can even attach supporting files
10586 for output from logs by using the "Add an attachment" button.
10587
1058811. Click the "Submit Bug" button submit the bug. A new Bugzilla number
10589 is assigned to the bug and the defect is logged in the bug tracking
10590 system.
10591
10592Once you file a bug, the bug is processed by the Yocto Project Bug
10593Triage Team and further details concerning the bug are assigned (e.g.
10594priority and owner). You are the "Submitter" of the bug and any further
10595categorization, progress, or comments on the bug result in Bugzilla
10596sending you an automated email concerning the particular change or
10597progress to the bug.
10598
10599.. _how-to-submit-a-change:
10600
10601Submitting a Change to the Yocto Project
10602----------------------------------------
10603
10604Contributions to the Yocto Project and OpenEmbedded are very welcome.
10605Because the system is extremely configurable and flexible, we recognize
10606that developers will want to extend, configure or optimize it for their
10607specific uses.
10608
10609The Yocto Project uses a mailing list and a patch-based workflow that is
10610similar to the Linux kernel but contains important differences. In
10611general, a mailing list exists through which you can submit patches. You
10612should send patches to the appropriate mailing list so that they can be
10613reviewed and merged by the appropriate maintainer. The specific mailing
10614list you need to use depends on the location of the code you are
10615changing. Each component (e.g. layer) should have a ``README`` file that
10616indicates where to send the changes and which process to follow.
10617
10618You can send the patch to the mailing list using whichever approach you
10619feel comfortable with to generate the patch. Once sent, the patch is
10620usually reviewed by the community at large. If somebody has concerns
10621with the patch, they will usually voice their concern over the mailing
10622list. If a patch does not receive any negative reviews, the maintainer
10623of the affected layer typically takes the patch, tests it, and then
10624based on successful testing, merges the patch.
10625
10626The "poky" repository, which is the Yocto Project's reference build
10627environment, is a hybrid repository that contains several individual
10628pieces (e.g. BitBake, Metadata, documentation, and so forth) built using
10629the combo-layer tool. The upstream location used for submitting changes
10630varies by component:
10631
10632- *Core Metadata:* Send your patch to the
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010633 :oe_lists:`openembedded-core </g/openembedded-core>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010634 mailing list. For example, a change to anything under the ``meta`` or
10635 ``scripts`` directories should be sent to this mailing list.
10636
10637- *BitBake:* For changes to BitBake (i.e. anything under the
10638 ``bitbake`` directory), send your patch to the
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010639 :oe_lists:`bitbake-devel </g/bitbake-devel>`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010640 mailing list.
10641
Andrew Geisslerc3d88e42020-10-02 09:45:00 -050010642- *"meta-\*" trees:* These trees contain Metadata. Use the
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010643 :yocto_lists:`poky </g/poky>` mailing list.
Andrew Geisslerc3d88e42020-10-02 09:45:00 -050010644
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010645- *Documentation*: For changes to the Yocto Project documentation, use the
10646 :yocto_lists:`docs </g/docs>` mailing list.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010647
10648For changes to other layers hosted in the Yocto Project source
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010649repositories (i.e. ``yoctoproject.org``) and tools use the
10650:yocto_lists:`Yocto Project </g/yocto/>` general mailing list.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010651
10652.. note::
10653
10654 Sometimes a layer's documentation specifies to use a particular
10655 mailing list. If so, use that list.
10656
10657For additional recipes that do not fit into the core Metadata, you
10658should determine which layer the recipe should go into and submit the
10659change in the manner recommended by the documentation (e.g. the
10660``README`` file) supplied with the layer. If in doubt, please ask on the
10661Yocto general mailing list or on the openembedded-devel mailing list.
10662
10663You can also push a change upstream and request a maintainer to pull the
10664change into the component's upstream repository. You do this by pushing
10665to a contribution repository that is upstream. See the ":ref:`gs-git-workflows-and-the-yocto-project`"
10666section in the Yocto Project Overview and Concepts Manual for additional
10667concepts on working in the Yocto Project development environment.
10668
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010669Maintainers commonly use ``-next`` branches to test submissions prior to
10670merging patches. Thus, you can get an idea of the status of a patch based on
10671whether the patch has been merged into one of these branches. The commonly
10672used testing branches for OpenEmbedded-Core are as follows:
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010673
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010674- *openembedded-core "master-next" branch:* This branch is part of the
10675 :oe_git:`openembedded-core </openembedded-core/>` repository and contains
10676 proposed changes to the core metadata.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010677
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010678- *poky "master-next" branch:* This branch is part of the
10679 :yocto_git:`poky </cgit/cgit.cgi/poky/>` repository and combines proposed
10680 changes to bitbake, the core metadata and the poky distro.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010681
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010682Similarly, stable branches maintained by the project may have corresponding
10683``-next`` branches which collect proposed changes. For example,
10684``&DISTRO_NAME_NO_CAP;-next`` and ``&DISTRO_NAME_NO_CAP_MINUS_ONE;-next``
10685branches in both the "openembdedded-core" and "poky" repositories.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010686
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010687Other layers may have similar testing branches but there is no formal
10688requirement or standard for these so please check the documentation for the
10689layers you are contributing to.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010690
10691The following sections provide procedures for submitting a change.
10692
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010693.. _preparing-changes-for-submissions:
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010694
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010695Preparing Changes for Submission
10696~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010697
106981. *Make Your Changes Locally:* Make your changes in your local Git
10699 repository. You should make small, controlled, isolated changes.
10700 Keeping changes small and isolated aids review, makes
10701 merging/rebasing easier and keeps the change history clean should
10702 anyone need to refer to it in future.
10703
107042. *Stage Your Changes:* Stage your changes by using the ``git add``
10705 command on each file you changed.
10706
107073. *Commit Your Changes:* Commit the change by using the ``git commit``
10708 command. Make sure your commit information follows standards by
10709 following these accepted conventions:
10710
10711 - Be sure to include a "Signed-off-by:" line in the same style as
10712 required by the Linux kernel. Adding this line signifies that you,
10713 the submitter, have agreed to the Developer's Certificate of
10714 Origin 1.1 as follows:
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010715
10716 .. code-block:: none
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010717
10718 Developer's Certificate of Origin 1.1
10719
10720 By making a contribution to this project, I certify that:
10721
10722 (a) The contribution was created in whole or in part by me and I
10723 have the right to submit it under the open source license
10724 indicated in the file; or
10725
10726 (b) The contribution is based upon previous work that, to the best
10727 of my knowledge, is covered under an appropriate open source
10728 license and I have the right under that license to submit that
10729 work with modifications, whether created in whole or in part
10730 by me, under the same open source license (unless I am
10731 permitted to submit under a different license), as indicated
10732 in the file; or
10733
10734 (c) The contribution was provided directly to me by some other
10735 person who certified (a), (b) or (c) and I have not modified
10736 it.
10737
10738 (d) I understand and agree that this project and the contribution
10739 are public and that a record of the contribution (including all
10740 personal information I submit with it, including my sign-off) is
10741 maintained indefinitely and may be redistributed consistent with
10742 this project or the open source license(s) involved.
10743
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010744 - Provide a single-line summary of the change and, if more
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010745 explanation is needed, provide more detail in the body of the
10746 commit. This summary is typically viewable in the "shortlist" of
10747 changes. Thus, providing something short and descriptive that
10748 gives the reader a summary of the change is useful when viewing a
10749 list of many commits. You should prefix this short description
10750 with the recipe name (if changing a recipe), or else with the
10751 short form path to the file being changed.
10752
10753 - For the body of the commit message, provide detailed information
10754 that describes what you changed, why you made the change, and the
10755 approach you used. It might also be helpful if you mention how you
10756 tested the change. Provide as much detail as you can in the body
10757 of the commit message.
10758
10759 .. note::
10760
10761 You do not need to provide a more detailed explanation of a
10762 change if the change is minor to the point of the single line
10763 summary providing all the information.
10764
10765 - If the change addresses a specific bug or issue that is associated
10766 with a bug-tracking ID, include a reference to that ID in your
10767 detailed description. For example, the Yocto Project uses a
10768 specific convention for bug references - any commit that addresses
10769 a specific bug should use the following form for the detailed
10770 description. Be sure to use the actual bug-tracking ID from
10771 Bugzilla for bug-id:
10772 ::
10773
10774 Fixes [YOCTO #bug-id]
10775
10776 detailed description of change
10777
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010778.. _submitting-a-patch:
10779
10780Using Email to Submit a Patch
10781~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10782
10783Depending on the components changed, you need to submit the email to a
10784specific mailing list. For some guidance on which mailing list to use,
10785see the `list <#figuring-out-the-mailing-list-to-use>`__ at the
10786beginning of this section. For a description of all the available
10787mailing lists, see the ":ref:`Mailing Lists <resources-mailinglist>`" section in the
10788Yocto Project Reference Manual.
10789
10790Here is the general procedure on how to submit a patch through email
10791without using the scripts once the steps in
10792:ref:`preparing-changes-for-submissions` have been followed:
10793
107941. *Format the Commit:* Format the commit into an email message. To
10795 format commits, use the ``git format-patch`` command. When you
10796 provide the command, you must include a revision list or a number of
10797 patches as part of the command. For example, either of these two
10798 commands takes your most recent single commit and formats it as an
10799 email message in the current directory:
10800 ::
10801
10802 $ git format-patch -1
10803
10804 or ::
10805
10806 $ git format-patch HEAD~
10807
10808 After the command is run, the current directory contains a numbered
10809 ``.patch`` file for the commit.
10810
10811 If you provide several commits as part of the command, the
10812 ``git format-patch`` command produces a series of numbered files in
10813 the current directory – one for each commit. If you have more than
10814 one patch, you should also use the ``--cover`` option with the
10815 command, which generates a cover letter as the first "patch" in the
10816 series. You can then edit the cover letter to provide a description
10817 for the series of patches. For information on the
10818 ``git format-patch`` command, see ``GIT_FORMAT_PATCH(1)`` displayed
10819 using the ``man git-format-patch`` command.
10820
10821 .. note::
10822
10823 If you are or will be a frequent contributor to the Yocto Project
10824 or to OpenEmbedded, you might consider requesting a contrib area
10825 and the necessary associated rights.
10826
108272. *Send the patches via email:* Send the patches to the recipients and
10828 relevant mailing lists by using the ``git send-email`` command.
10829
10830 .. note::
10831
10832 In order to use ``git send-email``, you must have the proper Git packages
10833 installed on your host.
10834 For Ubuntu, Debian, and Fedora the package is ``git-email``.
10835
10836 The ``git send-email`` command sends email by using a local or remote
10837 Mail Transport Agent (MTA) such as ``msmtp``, ``sendmail``, or
10838 through a direct ``smtp`` configuration in your Git ``~/.gitconfig``
10839 file. If you are submitting patches through email only, it is very
10840 important that you submit them without any whitespace or HTML
10841 formatting that either you or your mailer introduces. The maintainer
10842 that receives your patches needs to be able to save and apply them
10843 directly from your emails. A good way to verify that what you are
10844 sending will be applicable by the maintainer is to do a dry run and
10845 send them to yourself and then save and apply them as the maintainer
10846 would.
10847
10848 The ``git send-email`` command is the preferred method for sending
10849 your patches using email since there is no risk of compromising
10850 whitespace in the body of the message, which can occur when you use
10851 your own mail client. The command also has several options that let
10852 you specify recipients and perform further editing of the email
10853 message. For information on how to use the ``git send-email``
10854 command, see ``GIT-SEND-EMAIL(1)`` displayed using the
10855 ``man git-send-email`` command.
10856
10857The Yocto Project uses a `Patchwork instance <https://patchwork.openembedded.org/>`__
10858to track the status of patches submitted to the various mailing lists and to
10859support automated patch testing. Each submitted patch is checked for common
10860mistakes and deviations from the expected patch format and submitters are
10861notified by patchtest if such mistakes are found. This process helps to
10862reduce the burden of patch review on maintainers.
10863
10864.. note::
10865
10866 This system is imperfect and changes can sometimes get lost in the flow.
10867 Asking about the status of a patch or change is reasonable if the change
10868 has been idle for a while with no feedback.
10869
10870.. _pushing-a-change-upstream:
10871
10872Using Scripts to Push a Change Upstream and Request a Pull
10873~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10874
10875For larger patch series it is preferable to send a pull request which not
10876only includes the patch but also a pointer to a branch that can be pulled
10877from. This involves making a local branch for your changes, pushing this
10878branch to an accessible repository and then using the ``create-pull-request``
10879and ``send-pull-request`` scripts from openembedded-core to create and send a
10880patch series with a link to the branch for review.
10881
10882Follow this procedure to push a change to an upstream "contrib" Git
10883repository once the steps in :ref:`preparing-changes-for-submissions` have
10884been followed:
10885
10886.. note::
10887
10888 You can find general Git information on how to push a change upstream
10889 in the
10890 `Git Community Book <https://git-scm.com/book/en/v2/Distributed-Git-Distributed-Workflows>`__.
10891
108921. *Push Your Commits to a "Contrib" Upstream:* If you have arranged for
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010893 permissions to push to an upstream contrib repository, push the
10894 change to that repository:
10895 ::
10896
10897 $ git push upstream_remote_repo local_branch_name
10898
10899 For example, suppose you have permissions to push
10900 into the upstream ``meta-intel-contrib`` repository and you are
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010901 working in a local branch named `your_name`\ ``/README``. The following
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010902 command pushes your local commits to the ``meta-intel-contrib``
10903 upstream repository and puts the commit in a branch named
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010904 `your_name`\ ``/README``:
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010905 ::
10906
10907 $ git push meta-intel-contrib your_name/README
10908
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600109092. *Determine Who to Notify:* Determine the maintainer or the mailing
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010910 list that you need to notify for the change.
10911
10912 Before submitting any change, you need to be sure who the maintainer
10913 is or what mailing list that you need to notify. Use either these
10914 methods to find out:
10915
10916 - *Maintenance File:* Examine the ``maintainers.inc`` file, which is
10917 located in the :term:`Source Directory` at
10918 ``meta/conf/distro/include``, to see who is responsible for code.
10919
10920 - *Search by File:* Using :ref:`overview-manual/overview-manual-development-environment:git`, you can
10921 enter the following command to bring up a short list of all
10922 commits against a specific file:
10923 ::
10924
10925 git shortlog -- filename
10926
10927 Just provide the name of the file for which you are interested. The
10928 information returned is not ordered by history but does include a
10929 list of everyone who has committed grouped by name. From the list,
10930 you can see who is responsible for the bulk of the changes against
10931 the file.
10932
10933 - *Examine the List of Mailing Lists:* For a list of the Yocto
10934 Project and related mailing lists, see the ":ref:`Mailing
10935 lists <resources-mailinglist>`" section in
10936 the Yocto Project Reference Manual.
10937
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600109383. *Make a Pull Request:* Notify the maintainer or the mailing list that
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010939 you have pushed a change by making a pull request.
10940
10941 The Yocto Project provides two scripts that conveniently let you
10942 generate and send pull requests to the Yocto Project. These scripts
10943 are ``create-pull-request`` and ``send-pull-request``. You can find
10944 these scripts in the ``scripts`` directory within the
10945 :term:`Source Directory` (e.g.
10946 ``~/poky/scripts``).
10947
10948 Using these scripts correctly formats the requests without
10949 introducing any whitespace or HTML formatting. The maintainer that
10950 receives your patches either directly or through the mailing list
10951 needs to be able to save and apply them directly from your emails.
10952 Using these scripts is the preferred method for sending patches.
10953
10954 First, create the pull request. For example, the following command
10955 runs the script, specifies the upstream repository in the contrib
10956 directory into which you pushed the change, and provides a subject
10957 line in the created patch files:
10958 ::
10959
10960 $ ~/poky/scripts/create-pull-request -u meta-intel-contrib -s "Updated Manual Section Reference in README"
10961
10962 Running this script forms ``*.patch`` files in a folder named
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010963 ``pull-``\ `PID` in the current directory. One of the patch files is a
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010964 cover letter.
10965
10966 Before running the ``send-pull-request`` script, you must edit the
10967 cover letter patch to insert information about your change. After
10968 editing the cover letter, send the pull request. For example, the
10969 following command runs the script and specifies the patch directory
10970 and email address. In this example, the email address is a mailing
10971 list:
10972 ::
10973
10974 $ ~/poky/scripts/send-pull-request -p ~/meta-intel/pull-10565 -t meta-intel@yoctoproject.org
10975
10976 You need to follow the prompts as the script is interactive.
10977
10978 .. note::
10979
Andrew Geissler4c19ea12020-10-27 13:52:24 -050010980 For help on using these scripts, simply provide the ``-h``
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010981 argument as follows:
10982 ::
10983
10984 $ poky/scripts/create-pull-request -h
10985 $ poky/scripts/send-pull-request -h
10986
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010987Responding to Patch Review
10988~~~~~~~~~~~~~~~~~~~~~~~~~~
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010989
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010990You may get feedback on your submitted patches from other community members
10991or from the automated patchtest service. If issues are identified in your
10992patch then it is usually necessary to address these before the patch will be
10993accepted into the project. In this case you should amend the patch according
10994to the feedback and submit an updated version to the relevant mailing list,
10995copying in the reviewers who provided feedback to the previous version of the
10996patch.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010997
Andrew Geissler6ce62a22020-11-30 19:58:47 -060010998The patch should be amended using ``git commit --amend`` or perhaps ``git
10999rebase`` for more expert git users. You should also modify the ``[PATCH]``
11000tag in the email subject line when sending the revised patch to mark the new
11001iteration as ``[PATCH v2]``, ``[PATCH v3]``, etc as appropriate. This can be
11002done by passing the ``-v`` argument to ``git format-patch`` with a version
11003number.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011004
Andrew Geissler6ce62a22020-11-30 19:58:47 -060011005Lastly please ensure that you also test your revised changes. In particular
11006please don't just edit the patch file written out by ``git format-patch`` and
11007resend it.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011008
Andrew Geissler6ce62a22020-11-30 19:58:47 -060011009Submitting Changes to Stable Release Branches
11010~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011011
Andrew Geissler6ce62a22020-11-30 19:58:47 -060011012The process for proposing changes to a Yocto Project stable branch differs
11013from the steps described above. Changes to a stable branch must address
11014identified bugs or CVEs and should be made carefully in order to avoid the
11015risk of introducing new bugs or breaking backwards compatibility. Typically
11016bug fixes must already be accepted into the master branch before they can be
11017backported to a stable branch unless the bug in question does not affect the
11018master branch or the fix on the master branch is unsuitable for backporting.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011019
Andrew Geissler6ce62a22020-11-30 19:58:47 -060011020The list of stable branches along with the status and maintainer for each
11021branch can be obtained from the
11022:yocto_wiki:`Releases wiki page </wiki/Releases>`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011023
Andrew Geissler6ce62a22020-11-30 19:58:47 -060011024.. note::
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011025
Andrew Geissler6ce62a22020-11-30 19:58:47 -060011026 Changes will not typically be accepted for branches which are marked as
11027 End-Of-Life (EOL).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011028
Andrew Geissler6ce62a22020-11-30 19:58:47 -060011029With this in mind, the steps to submit a change for a stable branch are as
11030follows:
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011031
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600110321. *Identify the bug or CVE to be fixed:* This information should be
11033 collected so that it can be included in your submission.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011034
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600110352. *Check if the fix is already present in the master branch:* This will
11036 result in the most straightforward path into the stable branch for the
11037 fix.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011038
Andrew Geissler6ce62a22020-11-30 19:58:47 -060011039 a. *If the fix is present in the master branch - Submit a backport request
11040 by email:* You should send an email to the relevant stable branch
11041 maintainer and the mailing list with details of the bug or CVE to be
11042 fixed, the commit hash on the master branch that fixes the issue and
11043 the stable branches which you would like this fix to be backported to.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011044
Andrew Geissler6ce62a22020-11-30 19:58:47 -060011045 b. *If the fix is not present in the master branch - Submit the fix to the
11046 master branch first:* This will ensure that the fix passes through the
11047 project's usual patch review and test processes before being accepted.
11048 It will also ensure that bugs are not left unresolved in the master
11049 branch itself. Once the fix is accepted in the master branch a backport
11050 request can be submitted as above.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011051
Andrew Geissler6ce62a22020-11-30 19:58:47 -060011052 c. *If the fix is unsuitable for the master branch - Submit a patch
11053 directly for the stable branch:* This method should be considered as a
11054 last resort. It is typically necessary when the master branch is using
11055 a newer version of the software which includes an upstream fix for the
11056 issue or when the issue has been fixed on the master branch in a way
11057 that introduces backwards incompatible changes. In this case follow the
11058 steps in :ref:`preparing-changes-for-submissions` and
11059 :ref:`submitting-a-patch` but modify the subject header of your patch
11060 email to include the name of the stable branch which you are
11061 targetting. This can be done using the ``--subject-prefix`` argument to
11062 ``git format-patch``, for example to submit a patch to the dunfell
11063 branch use
11064 ``git format-patch --subject-prefix='&DISTRO_NAME_NO_CAP_MINUS_ONE;][PATCH' ...``.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011065
11066Working With Licenses
11067=====================
11068
11069As mentioned in the ":ref:`overview-manual/overview-manual-development-environment:licensing`"
11070section in the Yocto Project Overview and Concepts Manual, open source
11071projects are open to the public and they consequently have different
11072licensing structures in place. This section describes the mechanism by
11073which the :term:`OpenEmbedded Build System`
11074tracks changes to
11075licensing text and covers how to maintain open source license compliance
11076during your project's lifecycle. The section also describes how to
11077enable commercially licensed recipes, which by default are disabled.
11078
11079.. _usingpoky-configuring-LIC_FILES_CHKSUM:
11080
11081Tracking License Changes
11082------------------------
11083
11084The license of an upstream project might change in the future. In order
11085to prevent these changes going unnoticed, the
11086:term:`LIC_FILES_CHKSUM`
11087variable tracks changes to the license text. The checksums are validated
11088at the end of the configure step, and if the checksums do not match, the
11089build will fail.
11090
11091.. _usingpoky-specifying-LIC_FILES_CHKSUM:
11092
11093Specifying the ``LIC_FILES_CHKSUM`` Variable
11094~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11095
11096The ``LIC_FILES_CHKSUM`` variable contains checksums of the license text
11097in the source code for the recipe. Following is an example of how to
11098specify ``LIC_FILES_CHKSUM``:
11099::
11100
11101 LIC_FILES_CHKSUM = "file://COPYING;md5=xxxx \
11102 file://licfile1.txt;beginline=5;endline=29;md5=yyyy \
11103 file://licfile2.txt;endline=50;md5=zzzz \
11104 ..."
11105
11106.. note::
11107
11108 - When using "beginline" and "endline", realize that line numbering
11109 begins with one and not zero. Also, the included lines are
11110 inclusive (i.e. lines five through and including 29 in the
11111 previous example for ``licfile1.txt``).
11112
11113 - When a license check fails, the selected license text is included
11114 as part of the QA message. Using this output, you can determine
11115 the exact start and finish for the needed license text.
11116
11117The build system uses the :term:`S`
11118variable as the default directory when searching files listed in
11119``LIC_FILES_CHKSUM``. The previous example employs the default
11120directory.
11121
11122Consider this next example:
11123::
11124
11125 LIC_FILES_CHKSUM = "file://src/ls.c;beginline=5;endline=16;\
11126 md5=bb14ed3c4cda583abc85401304b5cd4e"
11127 LIC_FILES_CHKSUM = "file://${WORKDIR}/license.html;md5=5c94767cedb5d6987c902ac850ded2c6"
11128
11129The first line locates a file in ``${S}/src/ls.c`` and isolates lines
11130five through 16 as license text. The second line refers to a file in
11131:term:`WORKDIR`.
11132
11133Note that ``LIC_FILES_CHKSUM`` variable is mandatory for all recipes,
11134unless the ``LICENSE`` variable is set to "CLOSED".
11135
11136.. _usingpoky-LIC_FILES_CHKSUM-explanation-of-syntax:
11137
11138Explanation of Syntax
11139~~~~~~~~~~~~~~~~~~~~~
11140
11141As mentioned in the previous section, the ``LIC_FILES_CHKSUM`` variable
11142lists all the important files that contain the license text for the
11143source code. It is possible to specify a checksum for an entire file, or
11144a specific section of a file (specified by beginning and ending line
11145numbers with the "beginline" and "endline" parameters, respectively).
11146The latter is useful for source files with a license notice header,
11147README documents, and so forth. If you do not use the "beginline"
11148parameter, then it is assumed that the text begins on the first line of
11149the file. Similarly, if you do not use the "endline" parameter, it is
11150assumed that the license text ends with the last line of the file.
11151
11152The "md5" parameter stores the md5 checksum of the license text. If the
11153license text changes in any way as compared to this parameter then a
11154mismatch occurs. This mismatch triggers a build failure and notifies the
11155developer. Notification allows the developer to review and address the
11156license text changes. Also note that if a mismatch occurs during the
11157build, the correct md5 checksum is placed in the build log and can be
11158easily copied to the recipe.
11159
11160There is no limit to how many files you can specify using the
11161``LIC_FILES_CHKSUM`` variable. Generally, however, every project
11162requires a few specifications for license tracking. Many projects have a
11163"COPYING" file that stores the license information for all the source
11164code files. This practice allows you to just track the "COPYING" file as
11165long as it is kept up to date.
11166
11167.. note::
11168
11169 - If you specify an empty or invalid "md5" parameter,
11170 :term:`BitBake` returns an md5
11171 mis-match error and displays the correct "md5" parameter value
11172 during the build. The correct parameter is also captured in the
11173 build log.
11174
11175 - If the whole file contains only license text, you do not need to
11176 use the "beginline" and "endline" parameters.
11177
11178Enabling Commercially Licensed Recipes
11179--------------------------------------
11180
11181By default, the OpenEmbedded build system disables components that have
11182commercial or other special licensing requirements. Such requirements
11183are defined on a recipe-by-recipe basis through the
11184:term:`LICENSE_FLAGS` variable
11185definition in the affected recipe. For instance, the
11186``poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly`` recipe
11187contains the following statement:
11188::
11189
11190 LICENSE_FLAGS = "commercial"
11191
11192Here is a
11193slightly more complicated example that contains both an explicit recipe
11194name and version (after variable expansion):
11195::
11196
11197 LICENSE_FLAGS = "license_${PN}_${PV}"
11198
11199In order for a component restricted by a
11200``LICENSE_FLAGS`` definition to be enabled and included in an image, it
11201needs to have a matching entry in the global
11202:term:`LICENSE_FLAGS_WHITELIST`
11203variable, which is a variable typically defined in your ``local.conf``
11204file. For example, to enable the
11205``poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly`` package, you
11206could add either the string "commercial_gst-plugins-ugly" or the more
11207general string "commercial" to ``LICENSE_FLAGS_WHITELIST``. See the
11208"`License Flag Matching <#license-flag-matching>`__" section for a full
11209explanation of how ``LICENSE_FLAGS`` matching works. Here is the
11210example:
11211::
11212
11213 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly"
11214
11215Likewise, to additionally enable the package built from the recipe
11216containing ``LICENSE_FLAGS = "license_${PN}_${PV}"``, and assuming that
11217the actual recipe name was ``emgd_1.10.bb``, the following string would
11218enable that package as well as the original ``gst-plugins-ugly``
11219package:
11220::
11221
11222 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly license_emgd_1.10"
11223
11224As a convenience, you do not need to specify the
11225complete license string in the whitelist for every package. You can use
11226an abbreviated form, which consists of just the first portion or
11227portions of the license string before the initial underscore character
11228or characters. A partial string will match any license that contains the
11229given string as the first portion of its license. For example, the
11230following whitelist string will also match both of the packages
11231previously mentioned as well as any other packages that have licenses
11232starting with "commercial" or "license".
11233::
11234
11235 LICENSE_FLAGS_WHITELIST = "commercial license"
11236
11237License Flag Matching
11238~~~~~~~~~~~~~~~~~~~~~
11239
11240License flag matching allows you to control what recipes the
11241OpenEmbedded build system includes in the build. Fundamentally, the
11242build system attempts to match ``LICENSE_FLAGS`` strings found in
11243recipes against ``LICENSE_FLAGS_WHITELIST`` strings found in the
11244whitelist. A match causes the build system to include a recipe in the
11245build, while failure to find a match causes the build system to exclude
11246a recipe.
11247
11248In general, license flag matching is simple. However, understanding some
11249concepts will help you correctly and effectively use matching.
11250
11251Before a flag defined by a particular recipe is tested against the
11252contents of the whitelist, the expanded string ``_${PN}`` is appended to
11253the flag. This expansion makes each ``LICENSE_FLAGS`` value
11254recipe-specific. After expansion, the string is then matched against the
11255whitelist. Thus, specifying ``LICENSE_FLAGS = "commercial"`` in recipe
11256"foo", for example, results in the string ``"commercial_foo"``. And, to
11257create a match, that string must appear in the whitelist.
11258
11259Judicious use of the ``LICENSE_FLAGS`` strings and the contents of the
11260``LICENSE_FLAGS_WHITELIST`` variable allows you a lot of flexibility for
11261including or excluding recipes based on licensing. For example, you can
11262broaden the matching capabilities by using license flags string subsets
11263in the whitelist.
11264
11265.. note::
11266
11267 When using a string subset, be sure to use the part of the expanded
11268 string that precedes the appended underscore character (e.g.
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011269 ``usethispart_1.3``, ``usethispart_1.4``, and so forth).
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011270
11271For example, simply specifying the string "commercial" in the whitelist
11272matches any expanded ``LICENSE_FLAGS`` definition that starts with the
11273string "commercial" such as "commercial_foo" and "commercial_bar", which
11274are the strings the build system automatically generates for
11275hypothetical recipes named "foo" and "bar" assuming those recipes simply
11276specify the following:
11277::
11278
11279 LICENSE_FLAGS = "commercial"
11280
11281Thus, you can choose
11282to exhaustively enumerate each license flag in the whitelist and allow
11283only specific recipes into the image, or you can use a string subset
11284that causes a broader range of matches to allow a range of recipes into
11285the image.
11286
11287This scheme works even if the ``LICENSE_FLAGS`` string already has
11288``_${PN}`` appended. For example, the build system turns the license
11289flag "commercial_1.2_foo" into "commercial_1.2_foo_foo" and would match
11290both the general "commercial" and the specific "commercial_1.2_foo"
11291strings found in the whitelist, as expected.
11292
11293Here are some other scenarios:
11294
11295- You can specify a versioned string in the recipe such as
11296 "commercial_foo_1.2" in a "foo" recipe. The build system expands this
11297 string to "commercial_foo_1.2_foo". Combine this license flag with a
11298 whitelist that has the string "commercial" and you match the flag
11299 along with any other flag that starts with the string "commercial".
11300
11301- Under the same circumstances, you can use "commercial_foo" in the
11302 whitelist and the build system not only matches "commercial_foo_1.2"
11303 but also matches any license flag with the string "commercial_foo",
11304 regardless of the version.
11305
11306- You can be very specific and use both the package and version parts
11307 in the whitelist (e.g. "commercial_foo_1.2") to specifically match a
11308 versioned recipe.
11309
11310Other Variables Related to Commercial Licenses
11311~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11312
11313Other helpful variables related to commercial license handling exist and
11314are defined in the
11315``poky/meta/conf/distro/include/default-distrovars.inc`` file:
11316::
11317
11318 COMMERCIAL_AUDIO_PLUGINS ?= ""
11319 COMMERCIAL_VIDEO_PLUGINS ?= ""
11320
11321If you
11322want to enable these components, you can do so by making sure you have
11323statements similar to the following in your ``local.conf`` configuration
11324file:
11325::
11326
11327 COMMERCIAL_AUDIO_PLUGINS = "gst-plugins-ugly-mad \
11328 gst-plugins-ugly-mpegaudioparse"
11329 COMMERCIAL_VIDEO_PLUGINS = "gst-plugins-ugly-mpeg2dec \
11330 gst-plugins-ugly-mpegstream gst-plugins-bad-mpegvideoparse"
11331 LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly commercial_gst-plugins-bad commercial_qmmp"
11332
11333
11334Of course, you could also create a matching whitelist for those
11335components using the more general "commercial" in the whitelist, but
11336that would also enable all the other packages with ``LICENSE_FLAGS``
11337containing "commercial", which you may or may not want:
11338::
11339
11340 LICENSE_FLAGS_WHITELIST = "commercial"
11341
11342Specifying audio and video plugins as part of the
11343``COMMERCIAL_AUDIO_PLUGINS`` and ``COMMERCIAL_VIDEO_PLUGINS`` statements
11344(along with the enabling ``LICENSE_FLAGS_WHITELIST``) includes the
11345plugins or components into built images, thus adding support for media
11346formats or components.
11347
11348Maintaining Open Source License Compliance During Your Product's Lifecycle
11349--------------------------------------------------------------------------
11350
11351One of the concerns for a development organization using open source
11352software is how to maintain compliance with various open source
11353licensing during the lifecycle of the product. While this section does
11354not provide legal advice or comprehensively cover all scenarios, it does
11355present methods that you can use to assist you in meeting the compliance
11356requirements during a software release.
11357
11358With hundreds of different open source licenses that the Yocto Project
11359tracks, it is difficult to know the requirements of each and every
11360license. However, the requirements of the major FLOSS licenses can begin
11361to be covered by assuming that three main areas of concern exist:
11362
11363- Source code must be provided.
11364
11365- License text for the software must be provided.
11366
11367- Compilation scripts and modifications to the source code must be
11368 provided.
11369
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011370- spdx files can be provided.
11371
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011372There are other requirements beyond the scope of these three and the
11373methods described in this section (e.g. the mechanism through which
11374source code is distributed).
11375
11376As different organizations have different methods of complying with open
11377source licensing, this section is not meant to imply that there is only
11378one single way to meet your compliance obligations, but rather to
11379describe one method of achieving compliance. The remainder of this
11380section describes methods supported to meet the previously mentioned
11381three requirements. Once you take steps to meet these requirements, and
11382prior to releasing images, sources, and the build system, you should
11383audit all artifacts to ensure completeness.
11384
11385.. note::
11386
11387 The Yocto Project generates a license manifest during image creation
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011388 that is located in ``${DEPLOY_DIR}/licenses/``\ `image_name`\ ``-``\ `datestamp`
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011389 to assist with any audits.
11390
11391Providing the Source Code
11392~~~~~~~~~~~~~~~~~~~~~~~~~
11393
11394Compliance activities should begin before you generate the final image.
11395The first thing you should look at is the requirement that tops the list
11396for most compliance groups - providing the source. The Yocto Project has
11397a few ways of meeting this requirement.
11398
11399One of the easiest ways to meet this requirement is to provide the
11400entire :term:`DL_DIR` used by the
11401build. This method, however, has a few issues. The most obvious is the
11402size of the directory since it includes all sources used in the build
11403and not just the source used in the released image. It will include
11404toolchain source, and other artifacts, which you would not generally
11405release. However, the more serious issue for most companies is
11406accidental release of proprietary software. The Yocto Project provides
11407an :ref:`archiver <ref-classes-archiver>` class to
11408help avoid some of these concerns.
11409
11410Before you employ ``DL_DIR`` or the ``archiver`` class, you need to
11411decide how you choose to provide source. The source ``archiver`` class
11412can generate tarballs and SRPMs and can create them with various levels
11413of compliance in mind.
11414
11415One way of doing this (but certainly not the only way) is to release
11416just the source as a tarball. You can do this by adding the following to
11417the ``local.conf`` file found in the
11418:term:`Build Directory`:
11419::
11420
11421 INHERIT += "archiver"
11422 ARCHIVER_MODE[src] = "original"
11423
11424During the creation of your
11425image, the source from all recipes that deploy packages to the image is
11426placed within subdirectories of ``DEPLOY_DIR/sources`` based on the
11427:term:`LICENSE` for each recipe.
11428Releasing the entire directory enables you to comply with requirements
11429concerning providing the unmodified source. It is important to note that
11430the size of the directory can get large.
11431
11432A way to help mitigate the size issue is to only release tarballs for
11433licenses that require the release of source. Let us assume you are only
11434concerned with GPL code as identified by running the following script:
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011435
11436.. code-block:: shell
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011437
11438 # Script to archive a subset of packages matching specific license(s)
11439 # Source and license files are copied into sub folders of package folder
11440 # Must be run from build folder
11441 #!/bin/bash
11442 src_release_dir="source-release"
11443 mkdir -p $src_release_dir
11444 for a in tmp/deploy/sources/*; do
11445 for d in $a/*; do
11446 # Get package name from path
11447 p=`basename $d`
11448 p=${p%-*}
11449 p=${p%-*}
11450 # Only archive GPL packages (update *GPL* regex for your license check)
11451 numfiles=`ls tmp/deploy/licenses/$p/*GPL* 2> /dev/null | wc -l`
11452 if [ $numfiles -gt 1 ]; then
11453 echo Archiving $p
11454 mkdir -p $src_release_dir/$p/source
11455 cp $d/* $src_release_dir/$p/source 2> /dev/null
11456 mkdir -p $src_release_dir/$p/license
11457 cp tmp/deploy/licenses/$p/* $src_release_dir/$p/license 2> /dev/null
11458 fi
11459 done
11460 done
11461
11462At this point, you
11463could create a tarball from the ``gpl_source_release`` directory and
11464provide that to the end user. This method would be a step toward
11465achieving compliance with section 3a of GPLv2 and with section 6 of
11466GPLv3.
11467
11468Providing License Text
11469~~~~~~~~~~~~~~~~~~~~~~
11470
11471One requirement that is often overlooked is inclusion of license text.
11472This requirement also needs to be dealt with prior to generating the
11473final image. Some licenses require the license text to accompany the
11474binary. You can achieve this by adding the following to your
11475``local.conf`` file:
11476::
11477
11478 COPY_LIC_MANIFEST = "1"
11479 COPY_LIC_DIRS = "1"
11480 LICENSE_CREATE_PACKAGE = "1"
11481
11482Adding these statements to the
11483configuration file ensures that the licenses collected during package
11484generation are included on your image.
11485
11486.. note::
11487
11488 Setting all three variables to "1" results in the image having two
11489 copies of the same license file. One copy resides in
11490 ``/usr/share/common-licenses`` and the other resides in
11491 ``/usr/share/license``.
11492
11493 The reason for this behavior is because
11494 :term:`COPY_LIC_DIRS` and
11495 :term:`COPY_LIC_MANIFEST`
11496 add a copy of the license when the image is built but do not offer a
11497 path for adding licenses for newly installed packages to an image.
11498 :term:`LICENSE_CREATE_PACKAGE`
11499 adds a separate package and an upgrade path for adding licenses to an
11500 image.
11501
11502As the source ``archiver`` class has already archived the original
11503unmodified source that contains the license files, you would have
11504already met the requirements for inclusion of the license information
11505with source as defined by the GPL and other open source licenses.
11506
11507Providing Compilation Scripts and Source Code Modifications
11508~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11509
11510At this point, we have addressed all we need to prior to generating the
11511image. The next two requirements are addressed during the final
11512packaging of the release.
11513
11514By releasing the version of the OpenEmbedded build system and the layers
11515used during the build, you will be providing both compilation scripts
11516and the source code modifications in one step.
11517
11518If the deployment team has a :ref:`overview-manual/overview-manual-concepts:bsp layer`
11519and a distro layer, and those
11520those layers are used to patch, compile, package, or modify (in any way)
11521any open source software included in your released images, you might be
11522required to release those layers under section 3 of GPLv2 or section 1
11523of GPLv3. One way of doing that is with a clean checkout of the version
11524of the Yocto Project and layers used during your build. Here is an
11525example:
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011526
11527.. code-block:: shell
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011528
11529 # We built using the dunfell branch of the poky repo
11530 $ git clone -b dunfell git://git.yoctoproject.org/poky
11531 $ cd poky
11532 # We built using the release_branch for our layers
11533 $ git clone -b release_branch git://git.mycompany.com/meta-my-bsp-layer
11534 $ git clone -b release_branch git://git.mycompany.com/meta-my-software-layer
11535 # clean up the .git repos
11536 $ find . -name ".git" -type d -exec rm -rf {} \;
11537
11538One
11539thing a development organization might want to consider for end-user
11540convenience is to modify ``meta-poky/conf/bblayers.conf.sample`` to
11541ensure that when the end user utilizes the released build system to
11542build an image, the development organization's layers are included in
11543the ``bblayers.conf`` file automatically:
11544::
11545
11546 # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
11547 # changes incompatibly
11548 POKY_BBLAYERS_CONF_VERSION = "2"
11549
11550 BBPATH = "${TOPDIR}"
11551 BBFILES ?= ""
11552
11553 BBLAYERS ?= " \
11554 ##OEROOT##/meta \
11555 ##OEROOT##/meta-poky \
11556 ##OEROOT##/meta-yocto-bsp \
11557 ##OEROOT##/meta-mylayer \
11558 "
11559
11560Creating and
11561providing an archive of the :term:`Metadata`
11562layers (recipes, configuration files, and so forth) enables you to meet
11563your requirements to include the scripts to control compilation as well
11564as any modifications to the original source.
11565
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011566Providing spdx files
11567~~~~~~~~~~~~~~~~~~~~~~~~~
11568
11569The spdx module has been integrated to a layer named meta-spdxscanner.
11570meta-spdxscanner provides several kinds of scanner. If you want to enable
11571this function, you have to follow the following steps:
11572
115731. Add meta-spdxscanner layer into ``bblayers.conf``.
11574
115752. Refer to the README in meta-spdxscanner to setup the environment (e.g,
11576 setup a fossology server) needed for the scanner.
11577
115783. Meta-spdxscanner provides several methods within the bbclass to create spdx files.
11579 Please choose one that you want to use and enable the spdx task. You have to
11580 add some config options in ``local.conf`` file in your :term:`Build
11581 Directory`. The following is an example showing how to generate spdx files
11582 during bitbake using the fossology-python.bbclass::
11583
11584 # Select fossology-python.bbclass.
11585 INHERIT += "fossology-python"
11586 # For fossology-python.bbclass, TOKEN is necessary, so, after setup a
11587 # Fossology server, you have to create a token.
11588 TOKEN = "eyJ0eXAiO..."
11589 # The fossology server is necessary for fossology-python.bbclass.
11590 FOSSOLOGY_SERVER = "http://xx.xx.xx.xx:8081/repo"
11591 # If you want to upload the source code to a special folder:
11592 FOLDER_NAME = "xxxx" //Optional
11593 # If you don't want to put spdx files in tmp/deploy/spdx, you can enable:
11594 SPDX_DEPLOY_DIR = "${DEPLOY_DIR}" //Optional
11595
11596For more usage information refer to :yocto_git:`the meta-spdxscanner repository
11597</cgit/cgit.cgi/meta-spdxscanner/>`.
11598
11599
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011600Copying Licenses that Do Not Exist
11601----------------------------------
11602
11603Some packages, such as the linux-firmware package, have many licenses
11604that are not in any way common. You can avoid adding a lot of these
11605types of common license files, which are only applicable to a specific
11606package, by using the
11607:term:`NO_GENERIC_LICENSE`
11608variable. Using this variable also avoids QA errors when you use a
11609non-common, non-CLOSED license in a recipe.
11610
11611The following is an example that uses the ``LICENSE.Abilis.txt`` file as
11612the license from the fetched source:
11613::
11614
11615 NO_GENERIC_LICENSE[Firmware-Abilis] = "LICENSE.Abilis.txt"
11616
11617Using the Error Reporting Tool
11618==============================
11619
11620The error reporting tool allows you to submit errors encountered during
11621builds to a central database. Outside of the build environment, you can
11622use a web interface to browse errors, view statistics, and query for
11623errors. The tool works using a client-server system where the client
11624portion is integrated with the installed Yocto Project
11625:term:`Source Directory` (e.g. ``poky``).
11626The server receives the information collected and saves it in a
11627database.
11628
11629A live instance of the error reporting server exists at
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011630https://errors.yoctoproject.org. This server exists so that when
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011631you want to get help with build failures, you can submit all of the
11632information on the failure easily and then point to the URL in your bug
11633report or send an email to the mailing list.
11634
11635.. note::
11636
11637 If you send error reports to this server, the reports become publicly
11638 visible.
11639
11640Enabling and Using the Tool
11641---------------------------
11642
11643By default, the error reporting tool is disabled. You can enable it by
11644inheriting the
11645:ref:`report-error <ref-classes-report-error>`
11646class by adding the following statement to the end of your
11647``local.conf`` file in your
11648:term:`Build Directory`.
11649::
11650
11651 INHERIT += "report-error"
11652
11653By default, the error reporting feature stores information in
11654``${``\ :term:`LOG_DIR`\ ``}/error-report``.
11655However, you can specify a directory to use by adding the following to
11656your ``local.conf`` file:
11657::
11658
11659 ERR_REPORT_DIR = "path"
11660
11661Enabling error
11662reporting causes the build process to collect the errors and store them
11663in a file as previously described. When the build system encounters an
11664error, it includes a command as part of the console output. You can run
11665the command to send the error file to the server. For example, the
11666following command sends the errors to an upstream server:
11667::
11668
11669 $ send-error-report /home/brandusa/project/poky/build/tmp/log/error-report/error_report_201403141617.txt
11670
11671In the previous example, the errors are sent to a public database
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011672available at https://errors.yoctoproject.org, which is used by the
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011673entire community. If you specify a particular server, you can send the
11674errors to a different database. Use the following command for more
11675information on available options:
11676::
11677
11678 $ send-error-report --help
11679
11680When sending the error file, you are prompted to review the data being
11681sent as well as to provide a name and optional email address. Once you
11682satisfy these prompts, the command returns a link from the server that
11683corresponds to your entry in the database. For example, here is a
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011684typical link: https://errors.yoctoproject.org/Errors/Details/9522/
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011685
11686Following the link takes you to a web interface where you can browse,
11687query the errors, and view statistics.
11688
11689Disabling the Tool
11690------------------
11691
11692To disable the error reporting feature, simply remove or comment out the
11693following statement from the end of your ``local.conf`` file in your
11694:term:`Build Directory`.
11695::
11696
11697 INHERIT += "report-error"
11698
11699Setting Up Your Own Error Reporting Server
11700------------------------------------------
11701
11702If you want to set up your own error reporting server, you can obtain
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011703the code from the Git repository at :yocto_git:`/cgit/cgit.cgi/error-report-web/`.
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011704Instructions on how to set it up are in the README document.
11705
11706.. _dev-using-wayland-and-weston:
11707
11708Using Wayland and Weston
11709========================
11710
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011711`Wayland <https://en.wikipedia.org/wiki/Wayland_(display_server_protocol)>`__
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011712is a computer display server protocol that provides a method for
11713compositing window managers to communicate directly with applications
11714and video hardware and expects them to communicate with input hardware
11715using other libraries. Using Wayland with supporting targets can result
11716in better control over graphics frame rendering than an application
11717might otherwise achieve.
11718
11719The Yocto Project provides the Wayland protocol libraries and the
11720reference
Andrew Geissler4c19ea12020-10-27 13:52:24 -050011721`Weston <https://en.wikipedia.org/wiki/Wayland_(display_server_protocol)#Weston>`__
Andrew Geisslerc9f78652020-09-18 14:11:35 -050011722compositor as part of its release. You can find the integrated packages
11723in the ``meta`` layer of the :term:`Source Directory`.
11724Specifically, you
11725can find the recipes that build both Wayland and Weston at
11726``meta/recipes-graphics/wayland``.
11727
11728You can build both the Wayland and Weston packages for use only with
11729targets that accept the `Mesa 3D and Direct Rendering
11730Infrastructure <https://en.wikipedia.org/wiki/Mesa_(computer_graphics)>`__,
11731which is also known as Mesa DRI. This implies that you cannot build and
11732use the packages if your target uses, for example, the Intel Embedded
11733Media and Graphics Driver (Intel EMGD) that overrides Mesa DRI.
11734
11735.. note::
11736
11737 Due to lack of EGL support, Weston 1.0.3 will not run directly on the
11738 emulated QEMU hardware. However, this version of Weston will run
11739 under X emulation without issues.
11740
11741This section describes what you need to do to implement Wayland and use
11742the Weston compositor when building an image for a supporting target.
11743
11744Enabling Wayland in an Image
11745----------------------------
11746
11747To enable Wayland, you need to enable it to be built and enable it to be
11748included (installed) in the image.
11749
11750.. _enable-building:
11751
11752Building Wayland
11753~~~~~~~~~~~~~~~~
11754
11755To cause Mesa to build the ``wayland-egl`` platform and Weston to build
11756Wayland with Kernel Mode Setting
11757(`KMS <https://wiki.archlinux.org/index.php/Kernel_Mode_Setting>`__)
11758support, include the "wayland" flag in the
11759:term:`DISTRO_FEATURES`
11760statement in your ``local.conf`` file:
11761::
11762
11763 DISTRO_FEATURES_append = " wayland"
11764
11765.. note::
11766
11767 If X11 has been enabled elsewhere, Weston will build Wayland with X11
11768 support
11769
11770.. _enable-installation-in-an-image:
11771
11772Installing Wayland and Weston
11773~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11774
11775To install the Wayland feature into an image, you must include the
11776following
11777:term:`CORE_IMAGE_EXTRA_INSTALL`
11778statement in your ``local.conf`` file:
11779::
11780
11781 CORE_IMAGE_EXTRA_INSTALL += "wayland weston"
11782
11783Running Weston
11784--------------
11785
11786To run Weston inside X11, enabling it as described earlier and building
11787a Sato image is sufficient. If you are running your image under Sato, a
11788Weston Launcher appears in the "Utility" category.
11789
11790Alternatively, you can run Weston through the command-line interpretor
11791(CLI), which is better suited for development work. To run Weston under
11792the CLI, you need to do the following after your image is built:
11793
117941. Run these commands to export ``XDG_RUNTIME_DIR``:
11795 ::
11796
11797 mkdir -p /tmp/$USER-weston
11798 chmod 0700 /tmp/$USER-weston
11799 export XDG_RUNTIME_DIR=/tmp/$USER-weston
11800
118012. Launch Weston in the shell:
11802 ::
11803
11804 weston