diff options
Diffstat (limited to 'documentation/dev-manual/common-tasks.rst')
| -rw-r--r-- | documentation/dev-manual/common-tasks.rst | 11582 |
1 files changed, 11582 insertions, 0 deletions
diff --git a/documentation/dev-manual/common-tasks.rst b/documentation/dev-manual/common-tasks.rst new file mode 100644 index 0000000000..c627491f39 --- /dev/null +++ b/documentation/dev-manual/common-tasks.rst | |||
| @@ -0,0 +1,11582 @@ | |||
| 1 | .. SPDX-License-Identifier: CC-BY-SA-2.0-UK | ||
| 2 | |||
| 3 | ************ | ||
| 4 | Common Tasks | ||
| 5 | ************ | ||
| 6 | |||
| 7 | This chapter describes fundamental procedures such as creating layers, | ||
| 8 | adding new software packages, extending or customizing images, porting | ||
| 9 | work to new hardware (adding a new machine), and so forth. You will find | ||
| 10 | that the procedures documented here occur often in the development cycle | ||
| 11 | using the Yocto Project. | ||
| 12 | |||
| 13 | Understanding and Creating Layers | ||
| 14 | ================================= | ||
| 15 | |||
| 16 | The OpenEmbedded build system supports organizing | ||
| 17 | :term:`Metadata` into multiple layers. | ||
| 18 | Layers allow you to isolate different types of customizations from each | ||
| 19 | other. For introductory information on the Yocto Project Layer Model, | ||
| 20 | see the | ||
| 21 | ":ref:`overview-manual/overview-manual-yp-intro:the yocto project layer model`" | ||
| 22 | section in the Yocto Project Overview and Concepts Manual. | ||
| 23 | |||
| 24 | Creating Your Own Layer | ||
| 25 | ----------------------- | ||
| 26 | |||
| 27 | It is very easy to create your own layers to use with the OpenEmbedded | ||
| 28 | build system. The Yocto Project ships with tools that speed up creating | ||
| 29 | layers. This section describes the steps you perform by hand to create | ||
| 30 | layers so that you can better understand them. For information about the | ||
| 31 | layer-creation tools, see the | ||
| 32 | ":ref:`bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script`" | ||
| 33 | section in the Yocto Project Board Support Package (BSP) Developer's | ||
| 34 | Guide and the ":ref:`dev-manual/common-tasks:creating a general layer using the \`\`bitbake-layers\`\` script`" | ||
| 35 | section further down in this manual. | ||
| 36 | |||
| 37 | Follow these general steps to create your layer without using tools: | ||
| 38 | |||
| 39 | 1. *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 | ||
| 42 | Index <https://layers.openembedded.org/layerindex/layers/>`__ for a | ||
| 43 | 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 | |||
| 47 | 2. *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 | |||
| 72 | 3. *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 </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 | |||
| 87 | # We have recipes-* directories, add to BBFILES | ||
| 88 | 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 </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 | |||
| 143 | 4. *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 | ||
| 153 | Yocto Project, see the ":ref:`bsp-guide/bsp:example filesystem layout`" | ||
| 154 | section in the Yocto Project Board Support Package (BSP) Developer's Guide. | ||
| 155 | |||
| 156 | 5. *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 | Following Best Practices When Creating Layers | ||
| 164 | --------------------------------------------- | ||
| 165 | |||
| 166 | To create layers that are easier to maintain and that will not impact | ||
| 167 | builds for other machines, you should consider the information in the | ||
| 168 | following list: | ||
| 169 | |||
| 170 | - *Avoid "Overlaying" Entire Recipes from Other Layers in Your | ||
| 171 | Configuration:* In other words, do not copy an entire recipe into | ||
| 172 | your layer and then modify it. Rather, use an append file | ||
| 173 | (``.bbappend``) to override only those parts of the original recipe | ||
| 174 | you need to modify. | ||
| 175 | |||
| 176 | - *Avoid Duplicating Include Files:* Use append files (``.bbappend``) | ||
| 177 | for each recipe that uses an include file. Or, if you are introducing | ||
| 178 | a new recipe that requires the included file, use the path relative | ||
| 179 | to the original layer directory to refer to the file. For example, | ||
| 180 | use ``require recipes-core/``\ `package`\ ``/``\ `file`\ ``.inc`` instead | ||
| 181 | of ``require`` `file`\ ``.inc``. If you're finding you have to overlay | ||
| 182 | the include file, it could indicate a deficiency in the include file | ||
| 183 | in the layer to which it originally belongs. If this is the case, you | ||
| 184 | should try to address that deficiency instead of overlaying the | ||
| 185 | include file. For example, you could address this by getting the | ||
| 186 | maintainer of the include file to add a variable or variables to make | ||
| 187 | it easy to override the parts needing to be overridden. | ||
| 188 | |||
| 189 | - *Structure Your Layers:* Proper use of overrides within append files | ||
| 190 | and placement of machine-specific files within your layer can ensure | ||
| 191 | that a build is not using the wrong Metadata and negatively impacting | ||
| 192 | a build for a different machine. Following are some examples: | ||
| 193 | |||
| 194 | - *Modify Variables to Support a Different Machine:* Suppose you | ||
| 195 | have a layer named ``meta-one`` that adds support for building | ||
| 196 | machine "one". To do so, you use an append file named | ||
| 197 | ``base-files.bbappend`` and create a dependency on "foo" by | ||
| 198 | altering the :term:`DEPENDS` | ||
| 199 | variable: | ||
| 200 | :: | ||
| 201 | |||
| 202 | DEPENDS = "foo" | ||
| 203 | |||
| 204 | The dependency is created during any | ||
| 205 | build that includes the layer ``meta-one``. However, you might not | ||
| 206 | want this dependency for all machines. For example, suppose you | ||
| 207 | are building for machine "two" but your ``bblayers.conf`` file has | ||
| 208 | the ``meta-one`` layer included. During the build, the | ||
| 209 | ``base-files`` for machine "two" will also have the dependency on | ||
| 210 | ``foo``. | ||
| 211 | |||
| 212 | To make sure your changes apply only when building machine "one", | ||
| 213 | use a machine override with the ``DEPENDS`` statement: | ||
| 214 | :: | ||
| 215 | |||
| 216 | DEPENDS_one = "foo" | ||
| 217 | |||
| 218 | You should follow the same strategy when using ``_append`` | ||
| 219 | and ``_prepend`` operations: | ||
| 220 | :: | ||
| 221 | |||
| 222 | DEPENDS_append_one = " foo" | ||
| 223 | DEPENDS_prepend_one = "foo " | ||
| 224 | |||
| 225 | As an actual example, here's a | ||
| 226 | snippet from the generic kernel include file ``linux-yocto.inc``, | ||
| 227 | wherein the kernel compile and link options are adjusted in the | ||
| 228 | case of a subset of the supported architectures: | ||
| 229 | :: | ||
| 230 | |||
| 231 | DEPENDS_append_aarch64 = " libgcc" | ||
| 232 | KERNEL_CC_append_aarch64 = " ${TOOLCHAIN_OPTIONS}" | ||
| 233 | KERNEL_LD_append_aarch64 = " ${TOOLCHAIN_OPTIONS}" | ||
| 234 | |||
| 235 | DEPENDS_append_nios2 = " libgcc" | ||
| 236 | KERNEL_CC_append_nios2 = " ${TOOLCHAIN_OPTIONS}" | ||
| 237 | KERNEL_LD_append_nios2 = " ${TOOLCHAIN_OPTIONS}" | ||
| 238 | |||
| 239 | DEPENDS_append_arc = " libgcc" | ||
| 240 | KERNEL_CC_append_arc = " ${TOOLCHAIN_OPTIONS}" | ||
| 241 | KERNEL_LD_append_arc = " ${TOOLCHAIN_OPTIONS}" | ||
| 242 | |||
| 243 | KERNEL_FEATURES_append_qemuall=" features/debug/printk.scc" | ||
| 244 | |||
| 245 | .. note:: | ||
| 246 | |||
| 247 | Avoiding "+=" and "=+" and using machine-specific ``_append`` | ||
| 248 | and ``_prepend`` operations is recommended as well. | ||
| 249 | |||
| 250 | - *Place Machine-Specific Files in Machine-Specific Locations:* When | ||
| 251 | you have a base recipe, such as ``base-files.bb``, that contains a | ||
| 252 | :term:`SRC_URI` statement to a | ||
| 253 | file, you can use an append file to cause the build to use your | ||
| 254 | own version of the file. For example, an append file in your layer | ||
| 255 | at ``meta-one/recipes-core/base-files/base-files.bbappend`` could | ||
| 256 | extend :term:`FILESPATH` using :term:`FILESEXTRAPATHS` as follows: | ||
| 257 | :: | ||
| 258 | |||
| 259 | FILESEXTRAPATHS_prepend := "${THISDIR}/${BPN}:" | ||
| 260 | |||
| 261 | The build for machine "one" will pick up your machine-specific file as | ||
| 262 | long as you have the file in | ||
| 263 | ``meta-one/recipes-core/base-files/base-files/``. However, if you | ||
| 264 | are building for a different machine and the ``bblayers.conf`` | ||
| 265 | file includes the ``meta-one`` layer and the location of your | ||
| 266 | machine-specific file is the first location where that file is | ||
| 267 | found according to ``FILESPATH``, builds for all machines will | ||
| 268 | also use that machine-specific file. | ||
| 269 | |||
| 270 | You can make sure that a machine-specific file is used for a | ||
| 271 | particular machine by putting the file in a subdirectory specific | ||
| 272 | to the machine. For example, rather than placing the file in | ||
| 273 | ``meta-one/recipes-core/base-files/base-files/`` as shown above, | ||
| 274 | put it in ``meta-one/recipes-core/base-files/base-files/one/``. | ||
| 275 | Not only does this make sure the file is used only when building | ||
| 276 | for machine "one", but the build process locates the file more | ||
| 277 | quickly. | ||
| 278 | |||
| 279 | In summary, you need to place all files referenced from | ||
| 280 | ``SRC_URI`` in a machine-specific subdirectory within the layer in | ||
| 281 | order to restrict those files to machine-specific builds. | ||
| 282 | |||
| 283 | - *Perform Steps to Apply for Yocto Project Compatibility:* If you want | ||
| 284 | permission to use the Yocto Project Compatibility logo with your | ||
| 285 | layer or application that uses your layer, perform the steps to apply | ||
| 286 | for compatibility. See the "`Making Sure Your Layer is Compatible | ||
| 287 | With Yocto | ||
| 288 | Project <#making-sure-your-layer-is-compatible-with-yocto-project>`__" | ||
| 289 | section for more information. | ||
| 290 | |||
| 291 | - *Follow the Layer Naming Convention:* Store custom layers in a Git | ||
| 292 | repository that use the ``meta-layer_name`` format. | ||
| 293 | |||
| 294 | - *Group Your Layers Locally:* Clone your repository alongside other | ||
| 295 | cloned ``meta`` directories from the :term:`Source Directory`. | ||
| 296 | |||
| 297 | Making Sure Your Layer is Compatible With Yocto Project | ||
| 298 | ------------------------------------------------------- | ||
| 299 | |||
| 300 | When you create a layer used with the Yocto Project, it is advantageous | ||
| 301 | to make sure that the layer interacts well with existing Yocto Project | ||
| 302 | layers (i.e. the layer is compatible with the Yocto Project). Ensuring | ||
| 303 | compatibility makes the layer easy to be consumed by others in the Yocto | ||
| 304 | Project community and could allow you permission to use the Yocto | ||
| 305 | Project Compatible Logo. | ||
| 306 | |||
| 307 | .. note:: | ||
| 308 | |||
| 309 | Only Yocto Project member organizations are permitted to use the | ||
| 310 | Yocto Project Compatible Logo. The logo is not available for general | ||
| 311 | use. For information on how to become a Yocto Project member | ||
| 312 | organization, see the :yocto_home:`Yocto Project Website <>`. | ||
| 313 | |||
| 314 | The Yocto Project Compatibility Program consists of a layer application | ||
| 315 | process that requests permission to use the Yocto Project Compatibility | ||
| 316 | Logo for your layer and application. The process consists of two parts: | ||
| 317 | |||
| 318 | 1. Successfully passing a script (``yocto-check-layer``) that when run | ||
| 319 | against your layer, tests it against constraints based on experiences | ||
| 320 | of how layers have worked in the real world and where pitfalls have | ||
| 321 | been found. Getting a "PASS" result from the script is required for | ||
| 322 | successful compatibility registration. | ||
| 323 | |||
| 324 | 2. Completion of an application acceptance form, which you can find at | ||
| 325 | https://www.yoctoproject.org/webform/yocto-project-compatible-registration. | ||
| 326 | |||
| 327 | To be granted permission to use the logo, you need to satisfy the | ||
| 328 | following: | ||
| 329 | |||
| 330 | - Be able to check the box indicating that you got a "PASS" when | ||
| 331 | running the script against your layer. | ||
| 332 | |||
| 333 | - Answer "Yes" to the questions on the form or have an acceptable | ||
| 334 | explanation for any questions answered "No". | ||
| 335 | |||
| 336 | - Be a Yocto Project Member Organization. | ||
| 337 | |||
| 338 | The remainder of this section presents information on the registration | ||
| 339 | form and on the ``yocto-check-layer`` script. | ||
| 340 | |||
| 341 | Yocto Project Compatible Program Application | ||
| 342 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 343 | |||
| 344 | Use the form to apply for your layer's approval. Upon successful | ||
| 345 | application, you can use the Yocto Project Compatibility Logo with your | ||
| 346 | layer and the application that uses your layer. | ||
| 347 | |||
| 348 | To access the form, use this link: | ||
| 349 | https://www.yoctoproject.org/webform/yocto-project-compatible-registration. | ||
| 350 | Follow the instructions on the form to complete your application. | ||
| 351 | |||
| 352 | The application consists of the following sections: | ||
| 353 | |||
| 354 | - *Contact Information:* Provide your contact information as the fields | ||
| 355 | require. Along with your information, provide the released versions | ||
| 356 | of the Yocto Project for which your layer is compatible. | ||
| 357 | |||
| 358 | - *Acceptance Criteria:* Provide "Yes" or "No" answers for each of the | ||
| 359 | items in the checklist. Space exists at the bottom of the form for | ||
| 360 | any explanations for items for which you answered "No". | ||
| 361 | |||
| 362 | - *Recommendations:* Provide answers for the questions regarding Linux | ||
| 363 | kernel use and build success. | ||
| 364 | |||
| 365 | ``yocto-check-layer`` Script | ||
| 366 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 367 | |||
| 368 | The ``yocto-check-layer`` script provides you a way to assess how | ||
| 369 | compatible your layer is with the Yocto Project. You should run this | ||
| 370 | script prior to using the form to apply for compatibility as described | ||
| 371 | in the previous section. You need to achieve a "PASS" result in order to | ||
| 372 | have your application form successfully processed. | ||
| 373 | |||
| 374 | The script divides tests into three areas: COMMON, BSP, and DISTRO. For | ||
| 375 | example, given a distribution layer (DISTRO), the layer must pass both | ||
| 376 | the COMMON and DISTRO related tests. Furthermore, if your layer is a BSP | ||
| 377 | layer, the layer must pass the COMMON and BSP set of tests. | ||
| 378 | |||
| 379 | To execute the script, enter the following commands from your build | ||
| 380 | directory: | ||
| 381 | :: | ||
| 382 | |||
| 383 | $ source oe-init-build-env | ||
| 384 | $ yocto-check-layer your_layer_directory | ||
| 385 | |||
| 386 | Be sure to provide the actual directory for your | ||
| 387 | layer as part of the command. | ||
| 388 | |||
| 389 | Entering the command causes the script to determine the type of layer | ||
| 390 | and then to execute a set of specific tests against the layer. The | ||
| 391 | following list overviews the test: | ||
| 392 | |||
| 393 | - ``common.test_readme``: Tests if a ``README`` file exists in the | ||
| 394 | layer and the file is not empty. | ||
| 395 | |||
| 396 | - ``common.test_parse``: Tests to make sure that BitBake can parse the | ||
| 397 | files without error (i.e. ``bitbake -p``). | ||
| 398 | |||
| 399 | - ``common.test_show_environment``: Tests that the global or per-recipe | ||
| 400 | environment is in order without errors (i.e. ``bitbake -e``). | ||
| 401 | |||
| 402 | - ``common.test_world``: Verifies that ``bitbake world`` works. | ||
| 403 | |||
| 404 | - ``common.test_signatures``: Tests to be sure that BSP and DISTRO | ||
| 405 | layers do not come with recipes that change signatures. | ||
| 406 | |||
| 407 | - ``common.test_layerseries_compat``: Verifies layer compatibility is | ||
| 408 | set properly. | ||
| 409 | |||
| 410 | - ``bsp.test_bsp_defines_machines``: Tests if a BSP layer has machine | ||
| 411 | configurations. | ||
| 412 | |||
| 413 | - ``bsp.test_bsp_no_set_machine``: Tests to ensure a BSP layer does not | ||
| 414 | set the machine when the layer is added. | ||
| 415 | |||
| 416 | - ``bsp.test_machine_world``: Verifies that ``bitbake world`` works | ||
| 417 | regardless of which machine is selected. | ||
| 418 | |||
| 419 | - ``bsp.test_machine_signatures``: Verifies that building for a | ||
| 420 | particular machine affects only the signature of tasks specific to | ||
| 421 | that machine. | ||
| 422 | |||
| 423 | - ``distro.test_distro_defines_distros``: Tests if a DISTRO layer has | ||
| 424 | distro configurations. | ||
| 425 | |||
| 426 | - ``distro.test_distro_no_set_distros``: Tests to ensure a DISTRO layer | ||
| 427 | does not set the distribution when the layer is added. | ||
| 428 | |||
| 429 | Enabling Your Layer | ||
| 430 | ------------------- | ||
| 431 | |||
| 432 | Before the OpenEmbedded build system can use your new layer, you need to | ||
| 433 | enable it. To enable your layer, simply add your layer's path to the | ||
| 434 | ``BBLAYERS`` variable in your ``conf/bblayers.conf`` file, which is | ||
| 435 | found in the :term:`Build Directory`. | ||
| 436 | The following example shows how to enable a layer named | ||
| 437 | ``meta-mylayer``: | ||
| 438 | :: | ||
| 439 | |||
| 440 | # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf | ||
| 441 | # changes incompatibly | ||
| 442 | POKY_BBLAYERS_CONF_VERSION = "2" | ||
| 443 | BBPATH = "${TOPDIR}" | ||
| 444 | BBFILES ?= "" | ||
| 445 | BBLAYERS ?= " \ | ||
| 446 | /home/user/poky/meta \ | ||
| 447 | /home/user/poky/meta-poky \ | ||
| 448 | /home/user/poky/meta-yocto-bsp \ | ||
| 449 | /home/user/poky/meta-mylayer \ | ||
| 450 | " | ||
| 451 | |||
| 452 | BitBake parses each ``conf/layer.conf`` file from the top down as | ||
| 453 | specified in the ``BBLAYERS`` variable within the ``conf/bblayers.conf`` | ||
| 454 | file. During the processing of each ``conf/layer.conf`` file, BitBake | ||
| 455 | adds the recipes, classes and configurations contained within the | ||
| 456 | particular layer to the source directory. | ||
| 457 | |||
| 458 | Using .bbappend Files in Your Layer | ||
| 459 | ----------------------------------- | ||
| 460 | |||
| 461 | A recipe that appends Metadata to another recipe is called a BitBake | ||
| 462 | append file. A BitBake append file uses the ``.bbappend`` file type | ||
| 463 | suffix, while the corresponding recipe to which Metadata is being | ||
| 464 | appended uses the ``.bb`` file type suffix. | ||
| 465 | |||
| 466 | You can use a ``.bbappend`` file in your layer to make additions or | ||
| 467 | changes to the content of another layer's recipe without having to copy | ||
| 468 | the other layer's recipe into your layer. Your ``.bbappend`` file | ||
| 469 | resides in your layer, while the main ``.bb`` recipe file to which you | ||
| 470 | are appending Metadata resides in a different layer. | ||
| 471 | |||
| 472 | Being able to append information to an existing recipe not only avoids | ||
| 473 | duplication, but also automatically applies recipe changes from a | ||
| 474 | different layer into your layer. If you were copying recipes, you would | ||
| 475 | have to manually merge changes as they occur. | ||
| 476 | |||
| 477 | When you create an append file, you must use the same root name as the | ||
| 478 | corresponding recipe file. For example, the append file | ||
| 479 | ``someapp_3.1.bbappend`` must apply to ``someapp_3.1.bb``. This | ||
| 480 | means the original recipe and append file names are version | ||
| 481 | number-specific. If the corresponding recipe is renamed to update to a | ||
| 482 | newer version, you must also rename and possibly update the | ||
| 483 | corresponding ``.bbappend`` as well. During the build process, BitBake | ||
| 484 | displays an error on starting if it detects a ``.bbappend`` file that | ||
| 485 | does not have a corresponding recipe with a matching name. See the | ||
| 486 | :term:`BB_DANGLINGAPPENDS_WARNONLY` | ||
| 487 | variable for information on how to handle this error. | ||
| 488 | |||
| 489 | As an example, consider the main formfactor recipe and a corresponding | ||
| 490 | formfactor append file both from the :term:`Source Directory`. | ||
| 491 | Here is the main | ||
| 492 | formfactor recipe, which is named ``formfactor_0.0.bb`` and located in | ||
| 493 | the "meta" layer at ``meta/recipes-bsp/formfactor``: | ||
| 494 | :: | ||
| 495 | |||
| 496 | SUMMARY = "Device formfactor information" | ||
| 497 | DESCRIPTION = "A formfactor configuration file provides information about the \ | ||
| 498 | target hardware for which the image is being built and information that the \ | ||
| 499 | build system cannot obtain from other sources such as the kernel." | ||
| 500 | SECTION = "base" | ||
| 501 | LICENSE = "MIT" | ||
| 502 | LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" | ||
| 503 | PR = "r45" | ||
| 504 | |||
| 505 | SRC_URI = "file://config file://machconfig" | ||
| 506 | S = "${WORKDIR}" | ||
| 507 | |||
| 508 | PACKAGE_ARCH = "${MACHINE_ARCH}" | ||
| 509 | INHIBIT_DEFAULT_DEPS = "1" | ||
| 510 | |||
| 511 | do_install() { | ||
| 512 | # Install file only if it has contents | ||
| 513 | install -d ${D}${sysconfdir}/formfactor/ | ||
| 514 | install -m 0644 ${S}/config ${D}${sysconfdir}/formfactor/ | ||
| 515 | if [ -s "${S}/machconfig" ]; then | ||
| 516 | install -m 0644 ${S}/machconfig ${D}${sysconfdir}/formfactor/ | ||
| 517 | fi | ||
| 518 | } | ||
| 519 | |||
| 520 | In the main recipe, note the :term:`SRC_URI` | ||
| 521 | variable, which tells the OpenEmbedded build system where to find files | ||
| 522 | during the build. | ||
| 523 | |||
| 524 | Following is the append file, which is named ``formfactor_0.0.bbappend`` | ||
| 525 | and is from the Raspberry Pi BSP Layer named ``meta-raspberrypi``. The | ||
| 526 | file is in the layer at ``recipes-bsp/formfactor``: | ||
| 527 | :: | ||
| 528 | |||
| 529 | FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" | ||
| 530 | |||
| 531 | By default, the build system uses the | ||
| 532 | :term:`FILESPATH` variable to | ||
| 533 | locate files. This append file extends the locations by setting the | ||
| 534 | :term:`FILESEXTRAPATHS` | ||
| 535 | variable. Setting this variable in the ``.bbappend`` file is the most | ||
| 536 | reliable and recommended method for adding directories to the search | ||
| 537 | path used by the build system to find files. | ||
| 538 | |||
| 539 | The statement in this example extends the directories to include | ||
| 540 | ``${``\ :term:`THISDIR`\ ``}/${``\ :term:`PN`\ ``}``, | ||
| 541 | which resolves to a directory named ``formfactor`` in the same directory | ||
| 542 | in which the append file resides (i.e. | ||
| 543 | ``meta-raspberrypi/recipes-bsp/formfactor``. This implies that you must | ||
| 544 | have the supporting directory structure set up that will contain any | ||
| 545 | files or patches you will be including from the layer. | ||
| 546 | |||
| 547 | Using the immediate expansion assignment operator ``:=`` is important | ||
| 548 | because of the reference to ``THISDIR``. The trailing colon character is | ||
| 549 | important as it ensures that items in the list remain colon-separated. | ||
| 550 | |||
| 551 | .. note:: | ||
| 552 | |||
| 553 | BitBake automatically defines the ``THISDIR`` variable. You should | ||
| 554 | never set this variable yourself. Using "_prepend" as part of the | ||
| 555 | ``FILESEXTRAPATHS`` ensures your path will be searched prior to other | ||
| 556 | paths in the final list. | ||
| 557 | |||
| 558 | Also, not all append files add extra files. Many append files simply | ||
| 559 | exist to add build options (e.g. ``systemd``). For these cases, your | ||
| 560 | append file would not even use the ``FILESEXTRAPATHS`` statement. | ||
| 561 | |||
| 562 | Prioritizing Your Layer | ||
| 563 | ----------------------- | ||
| 564 | |||
| 565 | Each layer is assigned a priority value. Priority values control which | ||
| 566 | layer takes precedence if there are recipe files with the same name in | ||
| 567 | multiple layers. For these cases, the recipe file from the layer with a | ||
| 568 | higher priority number takes precedence. Priority values also affect the | ||
| 569 | order in which multiple ``.bbappend`` files for the same recipe are | ||
| 570 | applied. You can either specify the priority manually, or allow the | ||
| 571 | build system to calculate it based on the layer's dependencies. | ||
| 572 | |||
| 573 | To specify the layer's priority manually, use the | ||
| 574 | :term:`BBFILE_PRIORITY` | ||
| 575 | variable and append the layer's root name: | ||
| 576 | :: | ||
| 577 | |||
| 578 | BBFILE_PRIORITY_mylayer = "1" | ||
| 579 | |||
| 580 | .. note:: | ||
| 581 | |||
| 582 | It is possible for a recipe with a lower version number | ||
| 583 | :term:`PV` in a layer that has a higher | ||
| 584 | priority to take precedence. | ||
| 585 | |||
| 586 | Also, the layer priority does not currently affect the precedence | ||
| 587 | order of ``.conf`` or ``.bbclass`` files. Future versions of BitBake | ||
| 588 | might address this. | ||
| 589 | |||
| 590 | Managing Layers | ||
| 591 | --------------- | ||
| 592 | |||
| 593 | You can use the BitBake layer management tool ``bitbake-layers`` to | ||
| 594 | provide a view into the structure of recipes across a multi-layer | ||
| 595 | project. Being able to generate output that reports on configured layers | ||
| 596 | with their paths and priorities and on ``.bbappend`` files and their | ||
| 597 | applicable recipes can help to reveal potential problems. | ||
| 598 | |||
| 599 | For help on the BitBake layer management tool, use the following | ||
| 600 | command: | ||
| 601 | :: | ||
| 602 | |||
| 603 | $ bitbake-layers --help | ||
| 604 | NOTE: Starting bitbake server... | ||
| 605 | usage: bitbake-layers [-d] [-q] [-F] [--color COLOR] [-h] <subcommand> ... | ||
| 606 | |||
| 607 | BitBake layers utility | ||
| 608 | |||
| 609 | optional arguments: | ||
| 610 | -d, --debug Enable debug output | ||
| 611 | -q, --quiet Print only errors | ||
| 612 | -F, --force Force add without recipe parse verification | ||
| 613 | --color COLOR Colorize output (where COLOR is auto, always, never) | ||
| 614 | -h, --help show this help message and exit | ||
| 615 | |||
| 616 | subcommands: | ||
| 617 | <subcommand> | ||
| 618 | layerindex-fetch Fetches a layer from a layer index along with its | ||
| 619 | dependent layers, and adds them to conf/bblayers.conf. | ||
| 620 | layerindex-show-depends | ||
| 621 | Find layer dependencies from layer index. | ||
| 622 | add-layer Add one or more layers to bblayers.conf. | ||
| 623 | remove-layer Remove one or more layers from bblayers.conf. | ||
| 624 | flatten flatten layer configuration into a separate output | ||
| 625 | directory. | ||
| 626 | show-layers show current configured layers. | ||
| 627 | show-overlayed list overlayed recipes (where the same recipe exists | ||
| 628 | in another layer) | ||
| 629 | show-recipes list available recipes, showing the layer they are | ||
| 630 | provided by | ||
| 631 | show-appends list bbappend files and recipe files they apply to | ||
| 632 | show-cross-depends Show dependencies between recipes that cross layer | ||
| 633 | boundaries. | ||
| 634 | create-layer Create a basic layer | ||
| 635 | |||
| 636 | Use bitbake-layers <subcommand> --help to get help on a specific command | ||
| 637 | |||
| 638 | The following list describes the available commands: | ||
| 639 | |||
| 640 | - ``help:`` Displays general help or help on a specified command. | ||
| 641 | |||
| 642 | - ``show-layers:`` Shows the current configured layers. | ||
| 643 | |||
| 644 | - ``show-overlayed:`` Lists overlayed recipes. A recipe is overlayed | ||
| 645 | when a recipe with the same name exists in another layer that has a | ||
| 646 | higher layer priority. | ||
| 647 | |||
| 648 | - ``show-recipes:`` Lists available recipes and the layers that | ||
| 649 | provide them. | ||
| 650 | |||
| 651 | - ``show-appends:`` Lists ``.bbappend`` files and the recipe files to | ||
| 652 | which they apply. | ||
| 653 | |||
| 654 | - ``show-cross-depends:`` Lists dependency relationships between | ||
| 655 | recipes that cross layer boundaries. | ||
| 656 | |||
| 657 | - ``add-layer:`` Adds a layer to ``bblayers.conf``. | ||
| 658 | |||
| 659 | - ``remove-layer:`` Removes a layer from ``bblayers.conf`` | ||
| 660 | |||
| 661 | - ``flatten:`` Flattens the layer configuration into a separate | ||
| 662 | output directory. Flattening your layer configuration builds a | ||
| 663 | "flattened" directory that contains the contents of all layers, with | ||
| 664 | any overlayed recipes removed and any ``.bbappend`` files appended to | ||
| 665 | the corresponding recipes. You might have to perform some manual | ||
| 666 | cleanup of the flattened layer as follows: | ||
| 667 | |||
| 668 | - Non-recipe files (such as patches) are overwritten. The flatten | ||
| 669 | command shows a warning for these files. | ||
| 670 | |||
| 671 | - Anything beyond the normal layer setup has been added to the | ||
| 672 | ``layer.conf`` file. Only the lowest priority layer's | ||
| 673 | ``layer.conf`` is used. | ||
| 674 | |||
| 675 | - Overridden and appended items from ``.bbappend`` files need to be | ||
| 676 | cleaned up. The contents of each ``.bbappend`` end up in the | ||
| 677 | flattened recipe. However, if there are appended or changed | ||
| 678 | variable values, you need to tidy these up yourself. Consider the | ||
| 679 | following example. Here, the ``bitbake-layers`` command adds the | ||
| 680 | line ``#### bbappended ...`` so that you know where the following | ||
| 681 | lines originate: | ||
| 682 | :: | ||
| 683 | |||
| 684 | ... | ||
| 685 | DESCRIPTION = "A useful utility" | ||
| 686 | ... | ||
| 687 | EXTRA_OECONF = "--enable-something" | ||
| 688 | ... | ||
| 689 | |||
| 690 | #### bbappended from meta-anotherlayer #### | ||
| 691 | |||
| 692 | DESCRIPTION = "Customized utility" | ||
| 693 | EXTRA_OECONF += "--enable-somethingelse" | ||
| 694 | |||
| 695 | |||
| 696 | Ideally, you would tidy up these utilities as follows: | ||
| 697 | :: | ||
| 698 | |||
| 699 | ... | ||
| 700 | DESCRIPTION = "Customized utility" | ||
| 701 | ... | ||
| 702 | EXTRA_OECONF = "--enable-something --enable-somethingelse" | ||
| 703 | ... | ||
| 704 | |||
| 705 | - ``layerindex-fetch``: Fetches a layer from a layer index, along | ||
| 706 | with its dependent layers, and adds the layers to the | ||
| 707 | ``conf/bblayers.conf`` file. | ||
| 708 | |||
| 709 | - ``layerindex-show-depends``: Finds layer dependencies from the | ||
| 710 | layer index. | ||
| 711 | |||
| 712 | - ``create-layer``: Creates a basic layer. | ||
| 713 | |||
| 714 | Creating a General Layer Using the ``bitbake-layers`` Script | ||
| 715 | ------------------------------------------------------------ | ||
| 716 | |||
| 717 | The ``bitbake-layers`` script with the ``create-layer`` subcommand | ||
| 718 | simplifies creating a new general layer. | ||
| 719 | |||
| 720 | .. note:: | ||
| 721 | |||
| 722 | - For information on BSP layers, see the ":ref:`bsp-guide/bsp:bsp layers`" | ||
| 723 | section in the Yocto | ||
| 724 | Project Board Specific (BSP) Developer's Guide. | ||
| 725 | |||
| 726 | - In order to use a layer with the OpenEmbedded build system, you | ||
| 727 | need to add the layer to your ``bblayers.conf`` configuration | ||
| 728 | file. See the ":ref:`dev-manual/common-tasks:adding a layer using the \`\`bitbake-layers\`\` script`" | ||
| 729 | section for more information. | ||
| 730 | |||
| 731 | The default mode of the script's operation with this subcommand is to | ||
| 732 | create a layer with the following: | ||
| 733 | |||
| 734 | - A layer priority of 6. | ||
| 735 | |||
| 736 | - A ``conf`` subdirectory that contains a ``layer.conf`` file. | ||
| 737 | |||
| 738 | - A ``recipes-example`` subdirectory that contains a further | ||
| 739 | subdirectory named ``example``, which contains an ``example.bb`` | ||
| 740 | recipe file. | ||
| 741 | |||
| 742 | - A ``COPYING.MIT``, which is the license statement for the layer. The | ||
| 743 | script assumes you want to use the MIT license, which is typical for | ||
| 744 | most layers, for the contents of the layer itself. | ||
| 745 | |||
| 746 | - A ``README`` file, which is a file describing the contents of your | ||
| 747 | new layer. | ||
| 748 | |||
| 749 | In its simplest form, you can use the following command form to create a | ||
| 750 | layer. The command creates a layer whose name corresponds to | ||
| 751 | "your_layer_name" in the current directory: | ||
| 752 | :: | ||
| 753 | |||
| 754 | $ bitbake-layers create-layer your_layer_name | ||
| 755 | |||
| 756 | As an example, the following command creates a layer named ``meta-scottrif`` | ||
| 757 | in your home directory: | ||
| 758 | :: | ||
| 759 | |||
| 760 | $ cd /usr/home | ||
| 761 | $ bitbake-layers create-layer meta-scottrif | ||
| 762 | NOTE: Starting bitbake server... | ||
| 763 | Add your new layer with 'bitbake-layers add-layer meta-scottrif' | ||
| 764 | |||
| 765 | If you want to set the priority of the layer to other than the default | ||
| 766 | value of "6", you can either use the ``--priority`` option or you | ||
| 767 | can edit the | ||
| 768 | :term:`BBFILE_PRIORITY` value | ||
| 769 | in the ``conf/layer.conf`` after the script creates it. Furthermore, if | ||
| 770 | you want to give the example recipe file some name other than the | ||
| 771 | default, you can use the ``--example-recipe-name`` option. | ||
| 772 | |||
| 773 | The easiest way to see how the ``bitbake-layers create-layer`` command | ||
| 774 | works is to experiment with the script. You can also read the usage | ||
| 775 | information by entering the following: | ||
| 776 | :: | ||
| 777 | |||
| 778 | $ bitbake-layers create-layer --help | ||
| 779 | NOTE: Starting bitbake server... | ||
| 780 | usage: bitbake-layers create-layer [-h] [--priority PRIORITY] | ||
| 781 | [--example-recipe-name EXAMPLERECIPE] | ||
| 782 | layerdir | ||
| 783 | |||
| 784 | Create a basic layer | ||
| 785 | |||
| 786 | positional arguments: | ||
| 787 | layerdir Layer directory to create | ||
| 788 | |||
| 789 | optional arguments: | ||
| 790 | -h, --help show this help message and exit | ||
| 791 | --priority PRIORITY, -p PRIORITY | ||
| 792 | Layer directory to create | ||
| 793 | --example-recipe-name EXAMPLERECIPE, -e EXAMPLERECIPE | ||
| 794 | Filename of the example recipe | ||
| 795 | |||
| 796 | Adding a Layer Using the ``bitbake-layers`` Script | ||
| 797 | -------------------------------------------------- | ||
| 798 | |||
| 799 | Once you create your general layer, you must add it to your | ||
| 800 | ``bblayers.conf`` file. Adding the layer to this configuration file | ||
| 801 | makes the OpenEmbedded build system aware of your layer so that it can | ||
| 802 | search it for metadata. | ||
| 803 | |||
| 804 | Add your layer by using the ``bitbake-layers add-layer`` command: | ||
| 805 | :: | ||
| 806 | |||
| 807 | $ bitbake-layers add-layer your_layer_name | ||
| 808 | |||
| 809 | Here is an example that adds a | ||
| 810 | layer named ``meta-scottrif`` to the configuration file. Following the | ||
| 811 | command that adds the layer is another ``bitbake-layers`` command that | ||
| 812 | shows the layers that are in your ``bblayers.conf`` file: | ||
| 813 | :: | ||
| 814 | |||
| 815 | $ bitbake-layers add-layer meta-scottrif | ||
| 816 | NOTE: Starting bitbake server... | ||
| 817 | Parsing recipes: 100% |##########################################################| Time: 0:00:49 | ||
| 818 | Parsing of 1441 .bb files complete (0 cached, 1441 parsed). 2055 targets, 56 skipped, 0 masked, 0 errors. | ||
| 819 | $ bitbake-layers show-layers | ||
| 820 | NOTE: Starting bitbake server... | ||
| 821 | layer path priority | ||
| 822 | ========================================================================== | ||
| 823 | meta /home/scottrif/poky/meta 5 | ||
| 824 | meta-poky /home/scottrif/poky/meta-poky 5 | ||
| 825 | meta-yocto-bsp /home/scottrif/poky/meta-yocto-bsp 5 | ||
| 826 | workspace /home/scottrif/poky/build/workspace 99 | ||
| 827 | meta-scottrif /home/scottrif/poky/build/meta-scottrif 6 | ||
| 828 | |||
| 829 | |||
| 830 | Adding the layer to this file | ||
| 831 | enables the build system to locate the layer during the build. | ||
| 832 | |||
| 833 | .. note:: | ||
| 834 | |||
| 835 | During a build, the OpenEmbedded build system looks in the layers | ||
| 836 | from the top of the list down to the bottom in that order. | ||
| 837 | |||
| 838 | Customizing Images | ||
| 839 | ================== | ||
| 840 | |||
| 841 | You can customize images to satisfy particular requirements. This | ||
| 842 | section describes several methods and provides guidelines for each. | ||
| 843 | |||
| 844 | Customizing Images Using ``local.conf`` | ||
| 845 | --------------------------------------- | ||
| 846 | |||
| 847 | Probably the easiest way to customize an image is to add a package by | ||
| 848 | way of the ``local.conf`` configuration file. Because it is limited to | ||
| 849 | local use, this method generally only allows you to add packages and is | ||
| 850 | not as flexible as creating your own customized image. When you add | ||
| 851 | packages using local variables this way, you need to realize that these | ||
| 852 | variable changes are in effect for every build and consequently affect | ||
| 853 | all images, which might not be what you require. | ||
| 854 | |||
| 855 | To add a package to your image using the local configuration file, use | ||
| 856 | the ``IMAGE_INSTALL`` variable with the ``_append`` operator: | ||
| 857 | :: | ||
| 858 | |||
| 859 | IMAGE_INSTALL_append = " strace" | ||
| 860 | |||
| 861 | Use of the syntax is important - | ||
| 862 | specifically, the space between the quote and the package name, which is | ||
| 863 | ``strace`` in this example. This space is required since the ``_append`` | ||
| 864 | operator does not add the space. | ||
| 865 | |||
| 866 | Furthermore, you must use ``_append`` instead of the ``+=`` operator if | ||
| 867 | you want to avoid ordering issues. The reason for this is because doing | ||
| 868 | so unconditionally appends to the variable and avoids ordering problems | ||
| 869 | due to the variable being set in image recipes and ``.bbclass`` files | ||
| 870 | with operators like ``?=``. Using ``_append`` ensures the operation | ||
| 871 | takes effect. | ||
| 872 | |||
| 873 | As shown in its simplest use, ``IMAGE_INSTALL_append`` affects all | ||
| 874 | images. It is possible to extend the syntax so that the variable applies | ||
| 875 | to a specific image only. Here is an example: | ||
| 876 | :: | ||
| 877 | |||
| 878 | IMAGE_INSTALL_append_pn-core-image-minimal = " strace" | ||
| 879 | |||
| 880 | This example adds ``strace`` to the ``core-image-minimal`` image only. | ||
| 881 | |||
| 882 | You can add packages using a similar approach through the | ||
| 883 | ``CORE_IMAGE_EXTRA_INSTALL`` variable. If you use this variable, only | ||
| 884 | ``core-image-*`` images are affected. | ||
| 885 | |||
| 886 | Customizing Images Using Custom ``IMAGE_FEATURES`` and ``EXTRA_IMAGE_FEATURES`` | ||
| 887 | ------------------------------------------------------------------------------- | ||
| 888 | |||
| 889 | Another method for customizing your image is to enable or disable | ||
| 890 | high-level image features by using the | ||
| 891 | :term:`IMAGE_FEATURES` and | ||
| 892 | :term:`EXTRA_IMAGE_FEATURES` | ||
| 893 | variables. Although the functions for both variables are nearly | ||
| 894 | equivalent, best practices dictate using ``IMAGE_FEATURES`` from within | ||
| 895 | a recipe and using ``EXTRA_IMAGE_FEATURES`` from within your | ||
| 896 | ``local.conf`` file, which is found in the | ||
| 897 | :term:`Build Directory`. | ||
| 898 | |||
| 899 | To understand how these features work, the best reference is | ||
| 900 | ``meta/classes/core-image.bbclass``. This class lists out the available | ||
| 901 | ``IMAGE_FEATURES`` of which most map to package groups while some, such | ||
| 902 | as ``debug-tweaks`` and ``read-only-rootfs``, resolve as general | ||
| 903 | configuration settings. | ||
| 904 | |||
| 905 | In summary, the file looks at the contents of the ``IMAGE_FEATURES`` | ||
| 906 | variable and then maps or configures the feature accordingly. Based on | ||
| 907 | this information, the build system automatically adds the appropriate | ||
| 908 | packages or configurations to the | ||
| 909 | :term:`IMAGE_INSTALL` variable. | ||
| 910 | Effectively, you are enabling extra features by extending the class or | ||
| 911 | creating a custom class for use with specialized image ``.bb`` files. | ||
| 912 | |||
| 913 | Use the ``EXTRA_IMAGE_FEATURES`` variable from within your local | ||
| 914 | configuration file. Using a separate area from which to enable features | ||
| 915 | with this variable helps you avoid overwriting the features in the image | ||
| 916 | recipe that are enabled with ``IMAGE_FEATURES``. The value of | ||
| 917 | ``EXTRA_IMAGE_FEATURES`` is added to ``IMAGE_FEATURES`` within | ||
| 918 | ``meta/conf/bitbake.conf``. | ||
| 919 | |||
| 920 | To illustrate how you can use these variables to modify your image, | ||
| 921 | consider an example that selects the SSH server. The Yocto Project ships | ||
| 922 | with two SSH servers you can use with your images: Dropbear and OpenSSH. | ||
| 923 | Dropbear is a minimal SSH server appropriate for resource-constrained | ||
| 924 | environments, while OpenSSH is a well-known standard SSH server | ||
| 925 | implementation. By default, the ``core-image-sato`` image is configured | ||
| 926 | to use Dropbear. The ``core-image-full-cmdline`` and ``core-image-lsb`` | ||
| 927 | images both include OpenSSH. The ``core-image-minimal`` image does not | ||
| 928 | contain an SSH server. | ||
| 929 | |||
| 930 | You can customize your image and change these defaults. Edit the | ||
| 931 | ``IMAGE_FEATURES`` variable in your recipe or use the | ||
| 932 | ``EXTRA_IMAGE_FEATURES`` in your ``local.conf`` file so that it | ||
| 933 | configures the image you are working with to include | ||
| 934 | ``ssh-server-dropbear`` or ``ssh-server-openssh``. | ||
| 935 | |||
| 936 | .. note:: | ||
| 937 | |||
| 938 | See the ":ref:`ref-manual/ref-features:image features`" section in the Yocto | ||
| 939 | Project Reference Manual for a complete list of image features that ship | ||
| 940 | with the Yocto Project. | ||
| 941 | |||
| 942 | Customizing Images Using Custom .bb Files | ||
| 943 | ----------------------------------------- | ||
| 944 | |||
| 945 | You can also customize an image by creating a custom recipe that defines | ||
| 946 | additional software as part of the image. The following example shows | ||
| 947 | the form for the two lines you need: | ||
| 948 | :: | ||
| 949 | |||
| 950 | IMAGE_INSTALL = "packagegroup-core-x11-base package1 package2" | ||
| 951 | inherit core-image | ||
| 952 | |||
| 953 | Defining the software using a custom recipe gives you total control over | ||
| 954 | the contents of the image. It is important to use the correct names of | ||
| 955 | packages in the ``IMAGE_INSTALL`` variable. You must use the | ||
| 956 | OpenEmbedded notation and not the Debian notation for the names (e.g. | ||
| 957 | ``glibc-dev`` instead of ``libc6-dev``). | ||
| 958 | |||
| 959 | The other method for creating a custom image is to base it on an | ||
| 960 | existing image. For example, if you want to create an image based on | ||
| 961 | ``core-image-sato`` but add the additional package ``strace`` to the | ||
| 962 | image, copy the ``meta/recipes-sato/images/core-image-sato.bb`` to a new | ||
| 963 | ``.bb`` and add the following line to the end of the copy: | ||
| 964 | :: | ||
| 965 | |||
| 966 | IMAGE_INSTALL += "strace" | ||
| 967 | |||
| 968 | Customizing Images Using Custom Package Groups | ||
| 969 | ---------------------------------------------- | ||
| 970 | |||
| 971 | For complex custom images, the best approach for customizing an image is | ||
| 972 | to create a custom package group recipe that is used to build the image | ||
| 973 | or images. A good example of a package group recipe is | ||
| 974 | ``meta/recipes-core/packagegroups/packagegroup-base.bb``. | ||
| 975 | |||
| 976 | If you examine that recipe, you see that the ``PACKAGES`` variable lists | ||
| 977 | the package group packages to produce. The ``inherit packagegroup`` | ||
| 978 | statement sets appropriate default values and automatically adds | ||
| 979 | ``-dev``, ``-dbg``, and ``-ptest`` complementary packages for each | ||
| 980 | package specified in the ``PACKAGES`` statement. | ||
| 981 | |||
| 982 | .. note:: | ||
| 983 | |||
| 984 | The ``inherit packagegroup`` line should be located near the top of the | ||
| 985 | recipe, certainly before the ``PACKAGES`` statement. | ||
| 986 | |||
| 987 | For each package you specify in ``PACKAGES``, you can use ``RDEPENDS`` | ||
| 988 | and ``RRECOMMENDS`` entries to provide a list of packages the parent | ||
| 989 | task package should contain. You can see examples of these further down | ||
| 990 | in the ``packagegroup-base.bb`` recipe. | ||
| 991 | |||
| 992 | Here is a short, fabricated example showing the same basic pieces for a | ||
| 993 | hypothetical packagegroup defined in ``packagegroup-custom.bb``, where | ||
| 994 | the variable ``PN`` is the standard way to abbreviate the reference to | ||
| 995 | the full packagegroup name ``packagegroup-custom``: | ||
| 996 | :: | ||
| 997 | |||
| 998 | DESCRIPTION = "My Custom Package Groups" | ||
| 999 | |||
| 1000 | inherit packagegroup | ||
| 1001 | |||
| 1002 | PACKAGES = "\ | ||
| 1003 | ${PN}-apps \ | ||
| 1004 | ${PN}-tools \ | ||
| 1005 | " | ||
| 1006 | |||
| 1007 | RDEPENDS_${PN}-apps = "\ | ||
| 1008 | dropbear \ | ||
| 1009 | portmap \ | ||
| 1010 | psplash" | ||
| 1011 | |||
| 1012 | RDEPENDS_${PN}-tools = "\ | ||
| 1013 | oprofile \ | ||
| 1014 | oprofileui-server \ | ||
| 1015 | lttng-tools" | ||
| 1016 | |||
| 1017 | RRECOMMENDS_${PN}-tools = "\ | ||
| 1018 | kernel-module-oprofile" | ||
| 1019 | |||
| 1020 | In the previous example, two package group packages are created with | ||
| 1021 | their dependencies and their recommended package dependencies listed: | ||
| 1022 | ``packagegroup-custom-apps``, and ``packagegroup-custom-tools``. To | ||
| 1023 | build an image using these package group packages, you need to add | ||
| 1024 | ``packagegroup-custom-apps`` and/or ``packagegroup-custom-tools`` to | ||
| 1025 | ``IMAGE_INSTALL``. For other forms of image dependencies see the other | ||
| 1026 | areas of this section. | ||
| 1027 | |||
| 1028 | Customizing an Image Hostname | ||
| 1029 | ----------------------------- | ||
| 1030 | |||
| 1031 | By default, the configured hostname (i.e. ``/etc/hostname``) in an image | ||
| 1032 | is the same as the machine name. For example, if | ||
| 1033 | :term:`MACHINE` equals "qemux86", the | ||
| 1034 | configured hostname written to ``/etc/hostname`` is "qemux86". | ||
| 1035 | |||
| 1036 | You can customize this name by altering the value of the "hostname" | ||
| 1037 | variable in the ``base-files`` recipe using either an append file or a | ||
| 1038 | configuration file. Use the following in an append file: | ||
| 1039 | :: | ||
| 1040 | |||
| 1041 | hostname = "myhostname" | ||
| 1042 | |||
| 1043 | Use the following in a configuration file: | ||
| 1044 | :: | ||
| 1045 | |||
| 1046 | hostname_pn-base-files = "myhostname" | ||
| 1047 | |||
| 1048 | Changing the default value of the variable "hostname" can be useful in | ||
| 1049 | certain situations. For example, suppose you need to do extensive | ||
| 1050 | testing on an image and you would like to easily identify the image | ||
| 1051 | under test from existing images with typical default hostnames. In this | ||
| 1052 | situation, you could change the default hostname to "testme", which | ||
| 1053 | results in all the images using the name "testme". Once testing is | ||
| 1054 | complete and you do not need to rebuild the image for test any longer, | ||
| 1055 | you can easily reset the default hostname. | ||
| 1056 | |||
| 1057 | Another point of interest is that if you unset the variable, the image | ||
| 1058 | will have no default hostname in the filesystem. Here is an example that | ||
| 1059 | unsets the variable in a configuration file: | ||
| 1060 | :: | ||
| 1061 | |||
| 1062 | hostname_pn-base-files = "" | ||
| 1063 | |||
| 1064 | Having no default hostname in the filesystem is suitable for | ||
| 1065 | environments that use dynamic hostnames such as virtual machines. | ||
| 1066 | |||
| 1067 | Writing a New Recipe | ||
| 1068 | ==================== | ||
| 1069 | |||
| 1070 | Recipes (``.bb`` files) are fundamental components in the Yocto Project | ||
| 1071 | environment. Each software component built by the OpenEmbedded build | ||
| 1072 | system requires a recipe to define the component. This section describes | ||
| 1073 | how to create, write, and test a new recipe. | ||
| 1074 | |||
| 1075 | .. note:: | ||
| 1076 | |||
| 1077 | For information on variables that are useful for recipes and for | ||
| 1078 | information about recipe naming issues, see the | ||
| 1079 | ":ref:`ref-manual/ref-varlocality:recipes`" section of the Yocto Project | ||
| 1080 | Reference Manual. | ||
| 1081 | |||
| 1082 | Overview | ||
| 1083 | -------- | ||
| 1084 | |||
| 1085 | The following figure shows the basic process for creating a new recipe. | ||
| 1086 | The remainder of the section provides details for the steps. | ||
| 1087 | |||
| 1088 | .. image:: figures/recipe-workflow.png | ||
| 1089 | :align: center | ||
| 1090 | |||
| 1091 | Locate or Automatically Create a Base Recipe | ||
| 1092 | -------------------------------------------- | ||
| 1093 | |||
| 1094 | You can always write a recipe from scratch. However, three choices exist | ||
| 1095 | that can help you quickly get a start on a new recipe: | ||
| 1096 | |||
| 1097 | - ``devtool add``: A command that assists in creating a recipe and an | ||
| 1098 | environment conducive to development. | ||
| 1099 | |||
| 1100 | - ``recipetool create``: A command provided by the Yocto Project that | ||
| 1101 | automates creation of a base recipe based on the source files. | ||
| 1102 | |||
| 1103 | - *Existing Recipes:* Location and modification of an existing recipe | ||
| 1104 | that is similar in function to the recipe you need. | ||
| 1105 | |||
| 1106 | .. note:: | ||
| 1107 | |||
| 1108 | For information on recipe syntax, see the | ||
| 1109 | ":ref:`dev-manual/common-tasks:recipe syntax`" section. | ||
| 1110 | |||
| 1111 | Creating the Base Recipe Using ``devtool add`` | ||
| 1112 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 1113 | |||
| 1114 | The ``devtool add`` command uses the same logic for auto-creating the | ||
| 1115 | recipe as ``recipetool create``, which is listed below. Additionally, | ||
| 1116 | however, ``devtool add`` sets up an environment that makes it easy for | ||
| 1117 | you to patch the source and to make changes to the recipe as is often | ||
| 1118 | necessary when adding a recipe to build a new piece of software to be | ||
| 1119 | included in a build. | ||
| 1120 | |||
| 1121 | You can find a complete description of the ``devtool add`` command in | ||
| 1122 | the ":ref:`sdk-manual/sdk-extensible:a closer look at \`\`devtool add\`\``" section | ||
| 1123 | in the Yocto Project Application Development and the Extensible Software | ||
| 1124 | Development Kit (eSDK) manual. | ||
| 1125 | |||
| 1126 | Creating the Base Recipe Using ``recipetool create`` | ||
| 1127 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 1128 | |||
| 1129 | ``recipetool create`` automates creation of a base recipe given a set of | ||
| 1130 | source code files. As long as you can extract or point to the source | ||
| 1131 | files, the tool will construct a recipe and automatically configure all | ||
| 1132 | pre-build information into the recipe. For example, suppose you have an | ||
| 1133 | application that builds using Autotools. Creating the base recipe using | ||
| 1134 | ``recipetool`` results in a recipe that has the pre-build dependencies, | ||
| 1135 | license requirements, and checksums configured. | ||
| 1136 | |||
| 1137 | To run the tool, you just need to be in your | ||
| 1138 | :term:`Build Directory` and have sourced the | ||
| 1139 | build environment setup script (i.e. | ||
| 1140 | :ref:`structure-core-script`). | ||
| 1141 | To get help on the tool, use the following command: | ||
| 1142 | :: | ||
| 1143 | |||
| 1144 | $ recipetool -h | ||
| 1145 | NOTE: Starting bitbake server... | ||
| 1146 | usage: recipetool [-d] [-q] [--color COLOR] [-h] <subcommand> ... | ||
| 1147 | |||
| 1148 | OpenEmbedded recipe tool | ||
| 1149 | |||
| 1150 | options: | ||
| 1151 | -d, --debug Enable debug output | ||
| 1152 | -q, --quiet Print only errors | ||
| 1153 | --color COLOR Colorize output (where COLOR is auto, always, never) | ||
| 1154 | -h, --help show this help message and exit | ||
| 1155 | |||
| 1156 | subcommands: | ||
| 1157 | create Create a new recipe | ||
| 1158 | newappend Create a bbappend for the specified target in the specified | ||
| 1159 | layer | ||
| 1160 | setvar Set a variable within a recipe | ||
| 1161 | appendfile Create/update a bbappend to replace a target file | ||
| 1162 | appendsrcfiles Create/update a bbappend to add or replace source files | ||
| 1163 | appendsrcfile Create/update a bbappend to add or replace a source file | ||
| 1164 | Use recipetool <subcommand> --help to get help on a specific command | ||
| 1165 | |||
| 1166 | Running ``recipetool create -o OUTFILE`` creates the base recipe and | ||
| 1167 | locates it properly in the layer that contains your source files. | ||
| 1168 | Following are some syntax examples: | ||
| 1169 | |||
| 1170 | - Use this syntax to generate a recipe based on source. Once generated, | ||
| 1171 | the recipe resides in the existing source code layer: | ||
| 1172 | :: | ||
| 1173 | |||
| 1174 | recipetool create -o OUTFILE source | ||
| 1175 | |||
| 1176 | - Use this syntax to generate a recipe using code that | ||
| 1177 | you extract from source. The extracted code is placed in its own layer | ||
| 1178 | defined by ``EXTERNALSRC``. | ||
| 1179 | :: | ||
| 1180 | |||
| 1181 | recipetool create -o OUTFILE -x EXTERNALSRC source | ||
| 1182 | |||
| 1183 | - Use this syntax to generate a recipe based on source. The options | ||
| 1184 | direct ``recipetool`` to generate debugging information. Once generated, | ||
| 1185 | the recipe resides in the existing source code layer: | ||
| 1186 | :: | ||
| 1187 | |||
| 1188 | recipetool create -d -o OUTFILE source | ||
| 1189 | |||
| 1190 | Locating and Using a Similar Recipe | ||
| 1191 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 1192 | |||
| 1193 | Before writing a recipe from scratch, it is often useful to discover | ||
| 1194 | whether someone else has already written one that meets (or comes close | ||
| 1195 | to meeting) your needs. The Yocto Project and OpenEmbedded communities | ||
| 1196 | maintain many recipes that might be candidates for what you are doing. | ||
| 1197 | You can find a good central index of these recipes in the `OpenEmbedded | ||
| 1198 | Layer Index <https://layers.openembedded.org>`__. | ||
| 1199 | |||
| 1200 | Working from an existing recipe or a skeleton recipe is the best way to | ||
| 1201 | get started. Here are some points on both methods: | ||
| 1202 | |||
| 1203 | - *Locate and modify a recipe that is close to what you want to do:* | ||
| 1204 | This method works when you are familiar with the current recipe | ||
| 1205 | space. The method does not work so well for those new to the Yocto | ||
| 1206 | Project or writing recipes. | ||
| 1207 | |||
| 1208 | Some risks associated with this method are using a recipe that has | ||
| 1209 | areas totally unrelated to what you are trying to accomplish with | ||
| 1210 | your recipe, not recognizing areas of the recipe that you might have | ||
| 1211 | to add from scratch, and so forth. All these risks stem from | ||
| 1212 | unfamiliarity with the existing recipe space. | ||
| 1213 | |||
| 1214 | - *Use and modify the following skeleton recipe:* If for some reason | ||
| 1215 | you do not want to use ``recipetool`` and you cannot find an existing | ||
| 1216 | recipe that is close to meeting your needs, you can use the following | ||
| 1217 | structure to provide the fundamental areas of a new recipe. | ||
| 1218 | :: | ||
| 1219 | |||
| 1220 | DESCRIPTION = "" | ||
| 1221 | HOMEPAGE = "" | ||
| 1222 | LICENSE = "" | ||
| 1223 | SECTION = "" | ||
| 1224 | DEPENDS = "" | ||
| 1225 | LIC_FILES_CHKSUM = "" | ||
| 1226 | |||
| 1227 | SRC_URI = "" | ||
| 1228 | |||
| 1229 | Storing and Naming the Recipe | ||
| 1230 | ----------------------------- | ||
| 1231 | |||
| 1232 | Once you have your base recipe, you should put it in your own layer and | ||
| 1233 | name it appropriately. Locating it correctly ensures that the | ||
| 1234 | OpenEmbedded build system can find it when you use BitBake to process | ||
| 1235 | the recipe. | ||
| 1236 | |||
| 1237 | - *Storing Your Recipe:* The OpenEmbedded build system locates your | ||
| 1238 | recipe through the layer's ``conf/layer.conf`` file and the | ||
| 1239 | :term:`BBFILES` variable. This | ||
| 1240 | variable sets up a path from which the build system can locate | ||
| 1241 | recipes. Here is the typical use: | ||
| 1242 | :: | ||
| 1243 | |||
| 1244 | BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \ | ||
| 1245 | ${LAYERDIR}/recipes-*/*/*.bbappend" | ||
| 1246 | |||
| 1247 | Consequently, you need to be sure you locate your new recipe inside | ||
| 1248 | your layer such that it can be found. | ||
| 1249 | |||
| 1250 | You can find more information on how layers are structured in the | ||
| 1251 | "`Understanding and Creating | ||
| 1252 | Layers <#understanding-and-creating-layers>`__" section. | ||
| 1253 | |||
| 1254 | - *Naming Your Recipe:* When you name your recipe, you need to follow | ||
| 1255 | this naming convention: | ||
| 1256 | :: | ||
| 1257 | |||
| 1258 | basename_version.bb | ||
| 1259 | |||
| 1260 | Use lower-cased characters and do not include the reserved suffixes | ||
| 1261 | ``-native``, ``-cross``, ``-initial``, or ``-dev`` casually (i.e. do not use | ||
| 1262 | them as part of your recipe name unless the string applies). Here are some | ||
| 1263 | examples: | ||
| 1264 | |||
| 1265 | .. code-block:: none | ||
| 1266 | |||
| 1267 | cups_1.7.0.bb | ||
| 1268 | gawk_4.0.2.bb | ||
| 1269 | irssi_0.8.16-rc1.bb | ||
| 1270 | |||
| 1271 | Running a Build on the Recipe | ||
| 1272 | ----------------------------- | ||
| 1273 | |||
| 1274 | Creating a new recipe is usually an iterative process that requires | ||
| 1275 | using BitBake to process the recipe multiple times in order to | ||
| 1276 | progressively discover and add information to the recipe file. | ||
| 1277 | |||
| 1278 | Assuming you have sourced the build environment setup script (i.e. | ||
| 1279 | :ref:`structure-core-script`) and you are in | ||
| 1280 | the :term:`Build Directory`, use | ||
| 1281 | BitBake to process your recipe. All you need to provide is the | ||
| 1282 | ``basename`` of the recipe as described in the previous section: | ||
| 1283 | :: | ||
| 1284 | |||
| 1285 | $ bitbake basename | ||
| 1286 | |||
| 1287 | During the build, the OpenEmbedded build system creates a temporary work | ||
| 1288 | directory for each recipe | ||
| 1289 | (``${``\ :term:`WORKDIR`\ ``}``) | ||
| 1290 | where it keeps extracted source files, log files, intermediate | ||
| 1291 | compilation and packaging files, and so forth. | ||
| 1292 | |||
| 1293 | The path to the per-recipe temporary work directory depends on the | ||
| 1294 | context in which it is being built. The quickest way to find this path | ||
| 1295 | is to have BitBake return it by running the following: | ||
| 1296 | :: | ||
| 1297 | |||
| 1298 | $ bitbake -e basename | grep ^WORKDIR= | ||
| 1299 | |||
| 1300 | As an example, assume a Source Directory | ||
| 1301 | top-level folder named ``poky``, a default Build Directory at | ||
| 1302 | ``poky/build``, and a ``qemux86-poky-linux`` machine target system. | ||
| 1303 | Furthermore, suppose your recipe is named ``foo_1.3.0.bb``. In this | ||
| 1304 | case, the work directory the build system uses to build the package | ||
| 1305 | would be as follows: | ||
| 1306 | :: | ||
| 1307 | |||
| 1308 | poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0 | ||
| 1309 | |||
| 1310 | Inside this directory you can find sub-directories such as ``image``, | ||
| 1311 | ``packages-split``, and ``temp``. After the build, you can examine these | ||
| 1312 | to determine how well the build went. | ||
| 1313 | |||
| 1314 | .. note:: | ||
| 1315 | |||
| 1316 | You can find log files for each task in the recipe's ``temp`` | ||
| 1317 | directory (e.g. ``poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0/temp``). | ||
| 1318 | Log files are named ``log.taskname`` (e.g. ``log.do_configure``, | ||
| 1319 | ``log.do_fetch``, and ``log.do_compile``). | ||
| 1320 | |||
| 1321 | You can find more information about the build process in | ||
| 1322 | ":doc:`/overview-manual/overview-manual-development-environment`" | ||
| 1323 | chapter of the Yocto Project Overview and Concepts Manual. | ||
| 1324 | |||
| 1325 | Fetching Code | ||
| 1326 | ------------- | ||
| 1327 | |||
| 1328 | The first thing your recipe must do is specify how to fetch the source | ||
| 1329 | files. Fetching is controlled mainly through the | ||
| 1330 | :term:`SRC_URI` variable. Your recipe | ||
| 1331 | must have a ``SRC_URI`` variable that points to where the source is | ||
| 1332 | located. For a graphical representation of source locations, see the | ||
| 1333 | ":ref:`overview-manual/overview-manual-concepts:sources`" section in | ||
| 1334 | the Yocto Project Overview and Concepts Manual. | ||
| 1335 | |||
| 1336 | The :ref:`ref-tasks-fetch` task uses | ||
| 1337 | the prefix of each entry in the ``SRC_URI`` variable value to determine | ||
| 1338 | which :ref:`fetcher <bitbake:bitbake-user-manual/bitbake-user-manual-fetching:fetchers>` to use to get your | ||
| 1339 | source files. It is the ``SRC_URI`` variable that triggers the fetcher. | ||
| 1340 | The :ref:`ref-tasks-patch` task uses | ||
| 1341 | the variable after source is fetched to apply patches. The OpenEmbedded | ||
| 1342 | build system uses | ||
| 1343 | :term:`FILESOVERRIDES` for | ||
| 1344 | scanning directory locations for local files in ``SRC_URI``. | ||
| 1345 | |||
| 1346 | The ``SRC_URI`` variable in your recipe must define each unique location | ||
| 1347 | for your source files. It is good practice to not hard-code version | ||
| 1348 | numbers in a URL used in ``SRC_URI``. Rather than hard-code these | ||
| 1349 | values, use ``${``\ :term:`PV`\ ``}``, | ||
| 1350 | which causes the fetch process to use the version specified in the | ||
| 1351 | recipe filename. Specifying the version in this manner means that | ||
| 1352 | upgrading the recipe to a future version is as simple as renaming the | ||
| 1353 | recipe to match the new version. | ||
| 1354 | |||
| 1355 | Here is a simple example from the | ||
| 1356 | ``meta/recipes-devtools/strace/strace_5.5.bb`` recipe where the source | ||
| 1357 | comes from a single tarball. Notice the use of the | ||
| 1358 | :term:`PV` variable: | ||
| 1359 | :: | ||
| 1360 | |||
| 1361 | SRC_URI = "https://strace.io/files/${PV}/strace-${PV}.tar.xz \ | ||
| 1362 | |||
| 1363 | Files mentioned in ``SRC_URI`` whose names end in a typical archive | ||
| 1364 | extension (e.g. ``.tar``, ``.tar.gz``, ``.tar.bz2``, ``.zip``, and so | ||
| 1365 | forth), are automatically extracted during the | ||
| 1366 | :ref:`ref-tasks-unpack` task. For | ||
| 1367 | another example that specifies these types of files, see the | ||
| 1368 | "`Autotooled Package <#new-recipe-autotooled-package>`__" section. | ||
| 1369 | |||
| 1370 | Another way of specifying source is from an SCM. For Git repositories, | ||
| 1371 | you must specify :term:`SRCREV` and | ||
| 1372 | you should specify :term:`PV` to include | ||
| 1373 | the revision with :term:`SRCPV`. Here | ||
| 1374 | is an example from the recipe | ||
| 1375 | ``meta/recipes-kernel/blktrace/blktrace_git.bb``: | ||
| 1376 | :: | ||
| 1377 | |||
| 1378 | SRCREV = "d6918c8832793b4205ed3bfede78c2f915c23385" | ||
| 1379 | |||
| 1380 | PR = "r6" | ||
| 1381 | PV = "1.0.5+git${SRCPV}" | ||
| 1382 | |||
| 1383 | SRC_URI = "git://git.kernel.dk/blktrace.git \ | ||
| 1384 | file://ldflags.patch" | ||
| 1385 | |||
| 1386 | If your ``SRC_URI`` statement includes URLs pointing to individual files | ||
| 1387 | fetched from a remote server other than a version control system, | ||
| 1388 | BitBake attempts to verify the files against checksums defined in your | ||
| 1389 | recipe to ensure they have not been tampered with or otherwise modified | ||
| 1390 | since the recipe was written. Two checksums are used: | ||
| 1391 | ``SRC_URI[md5sum]`` and ``SRC_URI[sha256sum]``. | ||
| 1392 | |||
| 1393 | If your ``SRC_URI`` variable points to more than a single URL (excluding | ||
| 1394 | SCM URLs), you need to provide the ``md5`` and ``sha256`` checksums for | ||
| 1395 | each URL. For these cases, you provide a name for each URL as part of | ||
| 1396 | the ``SRC_URI`` and then reference that name in the subsequent checksum | ||
| 1397 | statements. Here is an example combining lines from the files | ||
| 1398 | ``git.inc`` and ``git_2.24.1.bb``: | ||
| 1399 | :: | ||
| 1400 | |||
| 1401 | SRC_URI = "${KERNELORG_MIRROR}/software/scm/git/git-${PV}.tar.gz;name=tarball \ | ||
| 1402 | ${KERNELORG_MIRROR}/software/scm/git/git-manpages-${PV}.tar.gz;name=manpages" | ||
| 1403 | |||
| 1404 | SRC_URI[tarball.md5sum] = "166bde96adbbc11c8843d4f8f4f9811b" | ||
| 1405 | SRC_URI[tarball.sha256sum] = "ad5334956301c86841eb1e5b1bb20884a6bad89a10a6762c958220c7cf64da02" | ||
| 1406 | SRC_URI[manpages.md5sum] = "31c2272a8979022497ba3d4202df145d" | ||
| 1407 | SRC_URI[manpages.sha256sum] = "9a7ae3a093bea39770eb96ca3e5b40bff7af0b9f6123f089d7821d0e5b8e1230" | ||
| 1408 | |||
| 1409 | Proper values for ``md5`` and ``sha256`` checksums might be available | ||
| 1410 | with other signatures on the download page for the upstream source (e.g. | ||
| 1411 | ``md5``, ``sha1``, ``sha256``, ``GPG``, and so forth). Because the | ||
| 1412 | OpenEmbedded build system only deals with ``sha256sum`` and ``md5sum``, | ||
| 1413 | you should verify all the signatures you find by hand. | ||
| 1414 | |||
| 1415 | If no ``SRC_URI`` checksums are specified when you attempt to build the | ||
| 1416 | recipe, or you provide an incorrect checksum, the build will produce an | ||
| 1417 | error for each missing or incorrect checksum. As part of the error | ||
| 1418 | message, the build system provides the checksum string corresponding to | ||
| 1419 | the fetched file. Once you have the correct checksums, you can copy and | ||
| 1420 | paste them into your recipe and then run the build again to continue. | ||
| 1421 | |||
| 1422 | .. note:: | ||
| 1423 | |||
| 1424 | As mentioned, if the upstream source provides signatures for | ||
| 1425 | verifying the downloaded source code, you should verify those | ||
| 1426 | manually before setting the checksum values in the recipe and | ||
| 1427 | continuing with the build. | ||
| 1428 | |||
| 1429 | This final example is a bit more complicated and is from the | ||
| 1430 | ``meta/recipes-sato/rxvt-unicode/rxvt-unicode_9.20.bb`` recipe. The | ||
| 1431 | example's ``SRC_URI`` statement identifies multiple files as the source | ||
| 1432 | files for the recipe: a tarball, a patch file, a desktop file, and an | ||
| 1433 | icon. | ||
| 1434 | :: | ||
| 1435 | |||
| 1436 | SRC_URI = "http://dist.schmorp.de/rxvt-unicode/Attic/rxvt-unicode-${PV}.tar.bz2 \ | ||
| 1437 | file://xwc.patch \ | ||
| 1438 | file://rxvt.desktop \ | ||
| 1439 | file://rxvt.png" | ||
| 1440 | |||
| 1441 | When you specify local files using the ``file://`` URI protocol, the | ||
| 1442 | build system fetches files from the local machine. The path is relative | ||
| 1443 | to the :term:`FILESPATH` variable | ||
| 1444 | and searches specific directories in a certain order: | ||
| 1445 | ``${``\ :term:`BP`\ ``}``, | ||
| 1446 | ``${``\ :term:`BPN`\ ``}``, and | ||
| 1447 | ``files``. The directories are assumed to be subdirectories of the | ||
| 1448 | directory in which the recipe or append file resides. For another | ||
| 1449 | example that specifies these types of files, see the "`Single .c File | ||
| 1450 | Package (Hello | ||
| 1451 | World!) <#new-recipe-single-c-file-package-hello-world>`__" section. | ||
| 1452 | |||
| 1453 | The previous example also specifies a patch file. Patch files are files | ||
| 1454 | whose names usually end in ``.patch`` or ``.diff`` but can end with | ||
| 1455 | compressed suffixes such as ``diff.gz`` and ``patch.bz2``, for example. | ||
| 1456 | The build system automatically applies patches as described in the | ||
| 1457 | "`Patching Code <#new-recipe-patching-code>`__" section. | ||
| 1458 | |||
| 1459 | Unpacking Code | ||
| 1460 | -------------- | ||
| 1461 | |||
| 1462 | During the build, the | ||
| 1463 | :ref:`ref-tasks-unpack` task unpacks | ||
| 1464 | the source with ``${``\ :term:`S`\ ``}`` | ||
| 1465 | pointing to where it is unpacked. | ||
| 1466 | |||
| 1467 | If you are fetching your source files from an upstream source archived | ||
| 1468 | tarball and the tarball's internal structure matches the common | ||
| 1469 | convention of a top-level subdirectory named | ||
| 1470 | ``${``\ :term:`BPN`\ ``}-${``\ :term:`PV`\ ``}``, | ||
| 1471 | then you do not need to set ``S``. However, if ``SRC_URI`` specifies to | ||
| 1472 | fetch source from an archive that does not use this convention, or from | ||
| 1473 | an SCM like Git or Subversion, your recipe needs to define ``S``. | ||
| 1474 | |||
| 1475 | If processing your recipe using BitBake successfully unpacks the source | ||
| 1476 | files, you need to be sure that the directory pointed to by ``${S}`` | ||
| 1477 | matches the structure of the source. | ||
| 1478 | |||
| 1479 | Patching Code | ||
| 1480 | ------------- | ||
| 1481 | |||
| 1482 | Sometimes it is necessary to patch code after it has been fetched. Any | ||
| 1483 | files mentioned in ``SRC_URI`` whose names end in ``.patch`` or | ||
| 1484 | ``.diff`` or compressed versions of these suffixes (e.g. ``diff.gz`` are | ||
| 1485 | treated as patches. The | ||
| 1486 | :ref:`ref-tasks-patch` task | ||
| 1487 | automatically applies these patches. | ||
| 1488 | |||
| 1489 | The build system should be able to apply patches with the "-p1" option | ||
| 1490 | (i.e. one directory level in the path will be stripped off). If your | ||
| 1491 | patch needs to have more directory levels stripped off, specify the | ||
| 1492 | number of levels using the "striplevel" option in the ``SRC_URI`` entry | ||
| 1493 | for the patch. Alternatively, if your patch needs to be applied in a | ||
| 1494 | specific subdirectory that is not specified in the patch file, use the | ||
| 1495 | "patchdir" option in the entry. | ||
| 1496 | |||
| 1497 | As with all local files referenced in | ||
| 1498 | :term:`SRC_URI` using ``file://``, | ||
| 1499 | you should place patch files in a directory next to the recipe either | ||
| 1500 | named the same as the base name of the recipe | ||
| 1501 | (:term:`BP` and | ||
| 1502 | :term:`BPN`) or "files". | ||
| 1503 | |||
| 1504 | Licensing | ||
| 1505 | --------- | ||
| 1506 | |||
| 1507 | Your recipe needs to have both the | ||
| 1508 | :term:`LICENSE` and | ||
| 1509 | :term:`LIC_FILES_CHKSUM` | ||
| 1510 | variables: | ||
| 1511 | |||
| 1512 | - ``LICENSE``: This variable specifies the license for the software. | ||
| 1513 | If you do not know the license under which the software you are | ||
| 1514 | building is distributed, you should go to the source code and look | ||
| 1515 | for that information. Typical files containing this information | ||
| 1516 | include ``COPYING``, ``LICENSE``, and ``README`` files. You could | ||
| 1517 | also find the information near the top of a source file. For example, | ||
| 1518 | given a piece of software licensed under the GNU General Public | ||
| 1519 | License version 2, you would set ``LICENSE`` as follows: | ||
| 1520 | :: | ||
| 1521 | |||
| 1522 | LICENSE = "GPLv2" | ||
| 1523 | |||
| 1524 | The licenses you specify within ``LICENSE`` can have any name as long | ||
| 1525 | as you do not use spaces, since spaces are used as separators between | ||
| 1526 | license names. For standard licenses, use the names of the files in | ||
| 1527 | ``meta/files/common-licenses/`` or the ``SPDXLICENSEMAP`` flag names | ||
| 1528 | defined in ``meta/conf/licenses.conf``. | ||
| 1529 | |||
| 1530 | - ``LIC_FILES_CHKSUM``: The OpenEmbedded build system uses this | ||
| 1531 | variable to make sure the license text has not changed. If it has, | ||
| 1532 | the build produces an error and it affords you the chance to figure | ||
| 1533 | it out and correct the problem. | ||
| 1534 | |||
| 1535 | You need to specify all applicable licensing files for the software. | ||
| 1536 | At the end of the configuration step, the build process will compare | ||
| 1537 | the checksums of the files to be sure the text has not changed. Any | ||
| 1538 | differences result in an error with the message containing the | ||
| 1539 | current checksum. For more explanation and examples of how to set the | ||
| 1540 | ``LIC_FILES_CHKSUM`` variable, see the | ||
| 1541 | ":ref:`dev-manual/common-tasks:tracking license changes`" section. | ||
| 1542 | |||
| 1543 | To determine the correct checksum string, you can list the | ||
| 1544 | appropriate files in the ``LIC_FILES_CHKSUM`` variable with incorrect | ||
| 1545 | md5 strings, attempt to build the software, and then note the | ||
| 1546 | resulting error messages that will report the correct md5 strings. | ||
| 1547 | See the "`Fetching Code <#new-recipe-fetching-code>`__" section for | ||
| 1548 | additional information. | ||
| 1549 | |||
| 1550 | Here is an example that assumes the software has a ``COPYING`` file: | ||
| 1551 | :: | ||
| 1552 | |||
| 1553 | LIC_FILES_CHKSUM = "file://COPYING;md5=xxx" | ||
| 1554 | |||
| 1555 | When you try to build the | ||
| 1556 | software, the build system will produce an error and give you the | ||
| 1557 | correct string that you can substitute into the recipe file for a | ||
| 1558 | subsequent build. | ||
| 1559 | |||
| 1560 | Dependencies | ||
| 1561 | ------------ | ||
| 1562 | |||
| 1563 | Most software packages have a short list of other packages that they | ||
| 1564 | require, which are called dependencies. These dependencies fall into two | ||
| 1565 | main categories: build-time dependencies, which are required when the | ||
| 1566 | software is built; and runtime dependencies, which are required to be | ||
| 1567 | installed on the target in order for the software to run. | ||
| 1568 | |||
| 1569 | Within a recipe, you specify build-time dependencies using the | ||
| 1570 | :term:`DEPENDS` variable. Although | ||
| 1571 | nuances exist, items specified in ``DEPENDS`` should be names of other | ||
| 1572 | recipes. It is important that you specify all build-time dependencies | ||
| 1573 | explicitly. | ||
| 1574 | |||
| 1575 | Another consideration is that configure scripts might automatically | ||
| 1576 | check for optional dependencies and enable corresponding functionality | ||
| 1577 | if those dependencies are found. If you wish to make a recipe that is | ||
| 1578 | more generally useful (e.g. publish the recipe in a layer for others to | ||
| 1579 | use), instead of hard-disabling the functionality, you can use the | ||
| 1580 | :term:`PACKAGECONFIG` variable to allow functionality and the | ||
| 1581 | corresponding dependencies to be enabled and disabled easily by other | ||
| 1582 | users of the recipe. | ||
| 1583 | |||
| 1584 | Similar to build-time dependencies, you specify runtime dependencies | ||
| 1585 | through a variable - | ||
| 1586 | :term:`RDEPENDS`, which is | ||
| 1587 | package-specific. All variables that are package-specific need to have | ||
| 1588 | the name of the package added to the end as an override. Since the main | ||
| 1589 | package for a recipe has the same name as the recipe, and the recipe's | ||
| 1590 | name can be found through the | ||
| 1591 | ``${``\ :term:`PN`\ ``}`` variable, then | ||
| 1592 | you specify the dependencies for the main package by setting | ||
| 1593 | ``RDEPENDS_${PN}``. If the package were named ``${PN}-tools``, then you | ||
| 1594 | would set ``RDEPENDS_${PN}-tools``, and so forth. | ||
| 1595 | |||
| 1596 | Some runtime dependencies will be set automatically at packaging time. | ||
| 1597 | These dependencies include any shared library dependencies (i.e. if a | ||
| 1598 | package "example" contains "libexample" and another package "mypackage" | ||
| 1599 | contains a binary that links to "libexample" then the OpenEmbedded build | ||
| 1600 | system will automatically add a runtime dependency to "mypackage" on | ||
| 1601 | "example"). See the | ||
| 1602 | ":ref:`overview-manual/overview-manual-concepts:automatically added runtime dependencies`" | ||
| 1603 | section in the Yocto Project Overview and Concepts Manual for further | ||
| 1604 | details. | ||
| 1605 | |||
| 1606 | Configuring the Recipe | ||
| 1607 | ---------------------- | ||
| 1608 | |||
| 1609 | Most software provides some means of setting build-time configuration | ||
| 1610 | options before compilation. Typically, setting these options is | ||
| 1611 | accomplished by running a configure script with options, or by modifying | ||
| 1612 | a build configuration file. | ||
| 1613 | |||
| 1614 | .. note:: | ||
| 1615 | |||
| 1616 | As of Yocto Project Release 1.7, some of the core recipes that | ||
| 1617 | package binary configuration scripts now disable the scripts due to | ||
| 1618 | the scripts previously requiring error-prone path substitution. The | ||
| 1619 | OpenEmbedded build system uses ``pkg-config`` now, which is much more | ||
| 1620 | robust. You can find a list of the ``*-config`` scripts that are disabled | ||
| 1621 | in the ":ref:`migration-1.7-binary-configuration-scripts-disabled`" section | ||
| 1622 | in the Yocto Project Reference Manual. | ||
| 1623 | |||
| 1624 | A major part of build-time configuration is about checking for | ||
| 1625 | build-time dependencies and possibly enabling optional functionality as | ||
| 1626 | a result. You need to specify any build-time dependencies for the | ||
| 1627 | software you are building in your recipe's | ||
| 1628 | :term:`DEPENDS` value, in terms of | ||
| 1629 | other recipes that satisfy those dependencies. You can often find | ||
| 1630 | build-time or runtime dependencies described in the software's | ||
| 1631 | documentation. | ||
| 1632 | |||
| 1633 | The following list provides configuration items of note based on how | ||
| 1634 | your software is built: | ||
| 1635 | |||
| 1636 | - *Autotools:* If your source files have a ``configure.ac`` file, then | ||
| 1637 | your software is built using Autotools. If this is the case, you just | ||
| 1638 | need to worry about modifying the configuration. | ||
| 1639 | |||
| 1640 | When using Autotools, your recipe needs to inherit the | ||
| 1641 | :ref:`autotools <ref-classes-autotools>` class | ||
| 1642 | and your recipe does not have to contain a | ||
| 1643 | :ref:`ref-tasks-configure` task. | ||
| 1644 | However, you might still want to make some adjustments. For example, | ||
| 1645 | you can set | ||
| 1646 | :term:`EXTRA_OECONF` or | ||
| 1647 | :term:`PACKAGECONFIG_CONFARGS` | ||
| 1648 | to pass any needed configure options that are specific to the recipe. | ||
| 1649 | |||
| 1650 | - *CMake:* If your source files have a ``CMakeLists.txt`` file, then | ||
| 1651 | your software is built using CMake. If this is the case, you just | ||
| 1652 | need to worry about modifying the configuration. | ||
| 1653 | |||
| 1654 | When you use CMake, your recipe needs to inherit the | ||
| 1655 | :ref:`cmake <ref-classes-cmake>` class and your | ||
| 1656 | recipe does not have to contain a | ||
| 1657 | :ref:`ref-tasks-configure` task. | ||
| 1658 | You can make some adjustments by setting | ||
| 1659 | :term:`EXTRA_OECMAKE` to | ||
| 1660 | pass any needed configure options that are specific to the recipe. | ||
| 1661 | |||
| 1662 | .. note:: | ||
| 1663 | |||
| 1664 | If you need to install one or more custom CMake toolchain files | ||
| 1665 | that are supplied by the application you are building, install the | ||
| 1666 | files to ``${D}${datadir}/cmake/Modules`` during ``do_install``. | ||
| 1667 | |||
| 1668 | - *Other:* If your source files do not have a ``configure.ac`` or | ||
| 1669 | ``CMakeLists.txt`` file, then your software is built using some | ||
| 1670 | method other than Autotools or CMake. If this is the case, you | ||
| 1671 | normally need to provide a | ||
| 1672 | :ref:`ref-tasks-configure` task | ||
| 1673 | in your recipe unless, of course, there is nothing to configure. | ||
| 1674 | |||
| 1675 | Even if your software is not being built by Autotools or CMake, you | ||
| 1676 | still might not need to deal with any configuration issues. You need | ||
| 1677 | to determine if configuration is even a required step. You might need | ||
| 1678 | to modify a Makefile or some configuration file used for the build to | ||
| 1679 | specify necessary build options. Or, perhaps you might need to run a | ||
| 1680 | provided, custom configure script with the appropriate options. | ||
| 1681 | |||
| 1682 | For the case involving a custom configure script, you would run | ||
| 1683 | ``./configure --help`` and look for the options you need to set. | ||
| 1684 | |||
| 1685 | Once configuration succeeds, it is always good practice to look at the | ||
| 1686 | ``log.do_configure`` file to ensure that the appropriate options have | ||
| 1687 | been enabled and no additional build-time dependencies need to be added | ||
| 1688 | to ``DEPENDS``. For example, if the configure script reports that it | ||
| 1689 | found something not mentioned in ``DEPENDS``, or that it did not find | ||
| 1690 | something that it needed for some desired optional functionality, then | ||
| 1691 | you would need to add those to ``DEPENDS``. Looking at the log might | ||
| 1692 | also reveal items being checked for, enabled, or both that you do not | ||
| 1693 | want, or items not being found that are in ``DEPENDS``, in which case | ||
| 1694 | you would need to look at passing extra options to the configure script | ||
| 1695 | as needed. For reference information on configure options specific to | ||
| 1696 | the software you are building, you can consult the output of the | ||
| 1697 | ``./configure --help`` command within ``${S}`` or consult the software's | ||
| 1698 | upstream documentation. | ||
| 1699 | |||
| 1700 | Using Headers to Interface with Devices | ||
| 1701 | --------------------------------------- | ||
| 1702 | |||
| 1703 | If your recipe builds an application that needs to communicate with some | ||
| 1704 | device or needs an API into a custom kernel, you will need to provide | ||
| 1705 | appropriate header files. Under no circumstances should you ever modify | ||
| 1706 | the existing | ||
| 1707 | ``meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc`` file. | ||
| 1708 | These headers are used to build ``libc`` and must not be compromised | ||
| 1709 | with custom or machine-specific header information. If you customize | ||
| 1710 | ``libc`` through modified headers all other applications that use | ||
| 1711 | ``libc`` thus become affected. | ||
| 1712 | |||
| 1713 | .. note:: | ||
| 1714 | |||
| 1715 | Never copy and customize the ``libc`` header file (i.e. | ||
| 1716 | ``meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc``). | ||
| 1717 | |||
| 1718 | The correct way to interface to a device or custom kernel is to use a | ||
| 1719 | separate package that provides the additional headers for the driver or | ||
| 1720 | other unique interfaces. When doing so, your application also becomes | ||
| 1721 | responsible for creating a dependency on that specific provider. | ||
| 1722 | |||
| 1723 | Consider the following: | ||
| 1724 | |||
| 1725 | - Never modify ``linux-libc-headers.inc``. Consider that file to be | ||
| 1726 | part of the ``libc`` system, and not something you use to access the | ||
| 1727 | kernel directly. You should access ``libc`` through specific ``libc`` | ||
| 1728 | calls. | ||
| 1729 | |||
| 1730 | - Applications that must talk directly to devices should either provide | ||
| 1731 | necessary headers themselves, or establish a dependency on a special | ||
| 1732 | headers package that is specific to that driver. | ||
| 1733 | |||
| 1734 | For example, suppose you want to modify an existing header that adds I/O | ||
| 1735 | control or network support. If the modifications are used by a small | ||
| 1736 | number programs, providing a unique version of a header is easy and has | ||
| 1737 | little impact. When doing so, bear in mind the guidelines in the | ||
| 1738 | previous list. | ||
| 1739 | |||
| 1740 | .. note:: | ||
| 1741 | |||
| 1742 | If for some reason your changes need to modify the behavior of the ``libc``, | ||
| 1743 | and subsequently all other applications on the system, use a ``.bbappend`` | ||
| 1744 | to modify the ``linux-kernel-headers.inc`` file. However, take care to not | ||
| 1745 | make the changes machine specific. | ||
| 1746 | |||
| 1747 | Consider a case where your kernel is older and you need an older | ||
| 1748 | ``libc`` ABI. The headers installed by your recipe should still be a | ||
| 1749 | standard mainline kernel, not your own custom one. | ||
| 1750 | |||
| 1751 | When you use custom kernel headers you need to get them from | ||
| 1752 | :term:`STAGING_KERNEL_DIR`, | ||
| 1753 | which is the directory with kernel headers that are required to build | ||
| 1754 | out-of-tree modules. Your recipe will also need the following: | ||
| 1755 | :: | ||
| 1756 | |||
| 1757 | do_configure[depends] += "virtual/kernel:do_shared_workdir" | ||
| 1758 | |||
| 1759 | Compilation | ||
| 1760 | ----------- | ||
| 1761 | |||
| 1762 | During a build, the ``do_compile`` task happens after source is fetched, | ||
| 1763 | unpacked, and configured. If the recipe passes through ``do_compile`` | ||
| 1764 | successfully, nothing needs to be done. | ||
| 1765 | |||
| 1766 | However, if the compile step fails, you need to diagnose the failure. | ||
| 1767 | Here are some common issues that cause failures. | ||
| 1768 | |||
| 1769 | .. note:: | ||
| 1770 | |||
| 1771 | For cases where improper paths are detected for configuration files | ||
| 1772 | or for when libraries/headers cannot be found, be sure you are using | ||
| 1773 | the more robust ``pkg-config``. See the note in section | ||
| 1774 | ":ref:`dev-manual/common-tasks:Configuring the Recipe`" for additional information. | ||
| 1775 | |||
| 1776 | - *Parallel build failures:* These failures manifest themselves as | ||
| 1777 | intermittent errors, or errors reporting that a file or directory | ||
| 1778 | that should be created by some other part of the build process could | ||
| 1779 | not be found. This type of failure can occur even if, upon | ||
| 1780 | inspection, the file or directory does exist after the build has | ||
| 1781 | failed, because that part of the build process happened in the wrong | ||
| 1782 | order. | ||
| 1783 | |||
| 1784 | To fix the problem, you need to either satisfy the missing dependency | ||
| 1785 | in the Makefile or whatever script produced the Makefile, or (as a | ||
| 1786 | workaround) set :term:`PARALLEL_MAKE` to an empty string: | ||
| 1787 | :: | ||
| 1788 | |||
| 1789 | PARALLEL_MAKE = "" | ||
| 1790 | |||
| 1791 | For information on parallel Makefile issues, see the "`Debugging | ||
| 1792 | Parallel Make Races <#debugging-parallel-make-races>`__" section. | ||
| 1793 | |||
| 1794 | - *Improper host path usage:* This failure applies to recipes building | ||
| 1795 | for the target or ``nativesdk`` only. The failure occurs when the | ||
| 1796 | compilation process uses improper headers, libraries, or other files | ||
| 1797 | from the host system when cross-compiling for the target. | ||
| 1798 | |||
| 1799 | To fix the problem, examine the ``log.do_compile`` file to identify | ||
| 1800 | the host paths being used (e.g. ``/usr/include``, ``/usr/lib``, and | ||
| 1801 | so forth) and then either add configure options, apply a patch, or do | ||
| 1802 | both. | ||
| 1803 | |||
| 1804 | - *Failure to find required libraries/headers:* If a build-time | ||
| 1805 | dependency is missing because it has not been declared in | ||
| 1806 | :term:`DEPENDS`, or because the | ||
| 1807 | dependency exists but the path used by the build process to find the | ||
| 1808 | file is incorrect and the configure step did not detect it, the | ||
| 1809 | compilation process could fail. For either of these failures, the | ||
| 1810 | compilation process notes that files could not be found. In these | ||
| 1811 | cases, you need to go back and add additional options to the | ||
| 1812 | configure script as well as possibly add additional build-time | ||
| 1813 | dependencies to ``DEPENDS``. | ||
| 1814 | |||
| 1815 | Occasionally, it is necessary to apply a patch to the source to | ||
| 1816 | ensure the correct paths are used. If you need to specify paths to | ||
| 1817 | find files staged into the sysroot from other recipes, use the | ||
| 1818 | variables that the OpenEmbedded build system provides (e.g. | ||
| 1819 | ``STAGING_BINDIR``, ``STAGING_INCDIR``, ``STAGING_DATADIR``, and so | ||
| 1820 | forth). | ||
| 1821 | |||
| 1822 | Installing | ||
| 1823 | ---------- | ||
| 1824 | |||
| 1825 | During ``do_install``, the task copies the built files along with their | ||
| 1826 | hierarchy to locations that would mirror their locations on the target | ||
| 1827 | device. The installation process copies files from the | ||
| 1828 | ``${``\ :term:`S`\ ``}``, | ||
| 1829 | ``${``\ :term:`B`\ ``}``, and | ||
| 1830 | ``${``\ :term:`WORKDIR`\ ``}`` | ||
| 1831 | directories to the ``${``\ :term:`D`\ ``}`` | ||
| 1832 | directory to create the structure as it should appear on the target | ||
| 1833 | system. | ||
| 1834 | |||
| 1835 | How your software is built affects what you must do to be sure your | ||
| 1836 | software is installed correctly. The following list describes what you | ||
| 1837 | must do for installation depending on the type of build system used by | ||
| 1838 | the software being built: | ||
| 1839 | |||
| 1840 | - *Autotools and CMake:* If the software your recipe is building uses | ||
| 1841 | Autotools or CMake, the OpenEmbedded build system understands how to | ||
| 1842 | install the software. Consequently, you do not have to have a | ||
| 1843 | ``do_install`` task as part of your recipe. You just need to make | ||
| 1844 | sure the install portion of the build completes with no issues. | ||
| 1845 | However, if you wish to install additional files not already being | ||
| 1846 | installed by ``make install``, you should do this using a | ||
| 1847 | ``do_install_append`` function using the install command as described | ||
| 1848 | in the "Manual" bulleted item later in this list. | ||
| 1849 | |||
| 1850 | - *Other (using* ``make install``\ *)*: You need to define a ``do_install`` | ||
| 1851 | function in your recipe. The function should call | ||
| 1852 | ``oe_runmake install`` and will likely need to pass in the | ||
| 1853 | destination directory as well. How you pass that path is dependent on | ||
| 1854 | how the ``Makefile`` being run is written (e.g. ``DESTDIR=${D}``, | ||
| 1855 | ``PREFIX=${D}``, ``INSTALLROOT=${D}``, and so forth). | ||
| 1856 | |||
| 1857 | For an example recipe using ``make install``, see the | ||
| 1858 | "`Makefile-Based Package <#new-recipe-makefile-based-package>`__" | ||
| 1859 | section. | ||
| 1860 | |||
| 1861 | - *Manual:* You need to define a ``do_install`` function in your | ||
| 1862 | recipe. The function must first use ``install -d`` to create the | ||
| 1863 | directories under | ||
| 1864 | ``${``\ :term:`D`\ ``}``. Once the | ||
| 1865 | directories exist, your function can use ``install`` to manually | ||
| 1866 | install the built software into the directories. | ||
| 1867 | |||
| 1868 | You can find more information on ``install`` at | ||
| 1869 | https://www.gnu.org/software/coreutils/manual/html_node/install-invocation.html. | ||
| 1870 | |||
| 1871 | For the scenarios that do not use Autotools or CMake, you need to track | ||
| 1872 | the installation and diagnose and fix any issues until everything | ||
| 1873 | installs correctly. You need to look in the default location of | ||
| 1874 | ``${D}``, which is ``${WORKDIR}/image``, to be sure your files have been | ||
| 1875 | installed correctly. | ||
| 1876 | |||
| 1877 | .. note:: | ||
| 1878 | |||
| 1879 | - During the installation process, you might need to modify some of | ||
| 1880 | the installed files to suit the target layout. For example, you | ||
| 1881 | might need to replace hard-coded paths in an initscript with | ||
| 1882 | values of variables provided by the build system, such as | ||
| 1883 | replacing ``/usr/bin/`` with ``${bindir}``. If you do perform such | ||
| 1884 | modifications during ``do_install``, be sure to modify the | ||
| 1885 | destination file after copying rather than before copying. | ||
| 1886 | Modifying after copying ensures that the build system can | ||
| 1887 | re-execute ``do_install`` if needed. | ||
| 1888 | |||
| 1889 | - ``oe_runmake install``, which can be run directly or can be run | ||
| 1890 | indirectly by the | ||
| 1891 | :ref:`autotools <ref-classes-autotools>` and | ||
| 1892 | :ref:`cmake <ref-classes-cmake>` classes, | ||
| 1893 | runs ``make install`` in parallel. Sometimes, a Makefile can have | ||
| 1894 | missing dependencies between targets that can result in race | ||
| 1895 | conditions. If you experience intermittent failures during | ||
| 1896 | ``do_install``, you might be able to work around them by disabling | ||
| 1897 | parallel Makefile installs by adding the following to the recipe: | ||
| 1898 | :: | ||
| 1899 | |||
| 1900 | PARALLEL_MAKEINST = "" | ||
| 1901 | |||
| 1902 | See :term:`PARALLEL_MAKEINST` for additional information. | ||
| 1903 | |||
| 1904 | - If you need to install one or more custom CMake toolchain files | ||
| 1905 | that are supplied by the application you are building, install the | ||
| 1906 | files to ``${D}${datadir}/cmake/Modules`` during | ||
| 1907 | :ref:`ref-tasks-install`. | ||
| 1908 | |||
| 1909 | Enabling System Services | ||
| 1910 | ------------------------ | ||
| 1911 | |||
| 1912 | If you want to install a service, which is a process that usually starts | ||
| 1913 | on boot and runs in the background, then you must include some | ||
| 1914 | additional definitions in your recipe. | ||
| 1915 | |||
| 1916 | If you are adding services and the service initialization script or the | ||
| 1917 | service file itself is not installed, you must provide for that | ||
| 1918 | installation in your recipe using a ``do_install_append`` function. If | ||
| 1919 | your recipe already has a ``do_install`` function, update the function | ||
| 1920 | near its end rather than adding an additional ``do_install_append`` | ||
| 1921 | function. | ||
| 1922 | |||
| 1923 | When you create the installation for your services, you need to | ||
| 1924 | accomplish what is normally done by ``make install``. In other words, | ||
| 1925 | make sure your installation arranges the output similar to how it is | ||
| 1926 | arranged on the target system. | ||
| 1927 | |||
| 1928 | The OpenEmbedded build system provides support for starting services two | ||
| 1929 | different ways: | ||
| 1930 | |||
| 1931 | - *SysVinit:* SysVinit is a system and service manager that manages the | ||
| 1932 | init system used to control the very basic functions of your system. | ||
| 1933 | The init program is the first program started by the Linux kernel | ||
| 1934 | when the system boots. Init then controls the startup, running and | ||
| 1935 | shutdown of all other programs. | ||
| 1936 | |||
| 1937 | To enable a service using SysVinit, your recipe needs to inherit the | ||
| 1938 | :ref:`update-rc.d <ref-classes-update-rc.d>` | ||
| 1939 | class. The class helps facilitate safely installing the package on | ||
| 1940 | the target. | ||
| 1941 | |||
| 1942 | You will need to set the | ||
| 1943 | :term:`INITSCRIPT_PACKAGES`, | ||
| 1944 | :term:`INITSCRIPT_NAME`, | ||
| 1945 | and | ||
| 1946 | :term:`INITSCRIPT_PARAMS` | ||
| 1947 | variables within your recipe. | ||
| 1948 | |||
| 1949 | - *systemd:* System Management Daemon (systemd) was designed to replace | ||
| 1950 | SysVinit and to provide enhanced management of services. For more | ||
| 1951 | information on systemd, see the systemd homepage at | ||
| 1952 | https://freedesktop.org/wiki/Software/systemd/. | ||
| 1953 | |||
| 1954 | To enable a service using systemd, your recipe needs to inherit the | ||
| 1955 | :ref:`systemd <ref-classes-systemd>` class. See | ||
| 1956 | the ``systemd.bbclass`` file located in your :term:`Source Directory` | ||
| 1957 | section for | ||
| 1958 | more information. | ||
| 1959 | |||
| 1960 | Packaging | ||
| 1961 | --------- | ||
| 1962 | |||
| 1963 | Successful packaging is a combination of automated processes performed | ||
| 1964 | by the OpenEmbedded build system and some specific steps you need to | ||
| 1965 | take. The following list describes the process: | ||
| 1966 | |||
| 1967 | - *Splitting Files*: The ``do_package`` task splits the files produced | ||
| 1968 | by the recipe into logical components. Even software that produces a | ||
| 1969 | single binary might still have debug symbols, documentation, and | ||
| 1970 | other logical components that should be split out. The ``do_package`` | ||
| 1971 | task ensures that files are split up and packaged correctly. | ||
| 1972 | |||
| 1973 | - *Running QA Checks*: The | ||
| 1974 | :ref:`insane <ref-classes-insane>` class adds a | ||
| 1975 | step to the package generation process so that output quality | ||
| 1976 | assurance checks are generated by the OpenEmbedded build system. This | ||
| 1977 | step performs a range of checks to be sure the build's output is free | ||
| 1978 | of common problems that show up during runtime. For information on | ||
| 1979 | these checks, see the | ||
| 1980 | :ref:`insane <ref-classes-insane>` class and | ||
| 1981 | the ":ref:`ref-manual/ref-qa-checks:qa error and warning messages`" | ||
| 1982 | chapter in the Yocto Project Reference Manual. | ||
| 1983 | |||
| 1984 | - *Hand-Checking Your Packages*: After you build your software, you | ||
| 1985 | need to be sure your packages are correct. Examine the | ||
| 1986 | ``${``\ :term:`WORKDIR`\ ``}/packages-split`` | ||
| 1987 | directory and make sure files are where you expect them to be. If you | ||
| 1988 | discover problems, you can set | ||
| 1989 | :term:`PACKAGES`, | ||
| 1990 | :term:`FILES`, | ||
| 1991 | ``do_install(_append)``, and so forth as needed. | ||
| 1992 | |||
| 1993 | - *Splitting an Application into Multiple Packages*: If you need to | ||
| 1994 | split an application into several packages, see the "`Splitting an | ||
| 1995 | Application into Multiple | ||
| 1996 | Packages <#splitting-an-application-into-multiple-packages>`__" | ||
| 1997 | section for an example. | ||
| 1998 | |||
| 1999 | - *Installing a Post-Installation Script*: For an example showing how | ||
| 2000 | to install a post-installation script, see the "`Post-Installation | ||
| 2001 | Scripts <#new-recipe-post-installation-scripts>`__" section. | ||
| 2002 | |||
| 2003 | - *Marking Package Architecture*: Depending on what your recipe is | ||
| 2004 | building and how it is configured, it might be important to mark the | ||
| 2005 | packages produced as being specific to a particular machine, or to | ||
| 2006 | mark them as not being specific to a particular machine or | ||
| 2007 | architecture at all. | ||
| 2008 | |||
| 2009 | By default, packages apply to any machine with the same architecture | ||
| 2010 | as the target machine. When a recipe produces packages that are | ||
| 2011 | machine-specific (e.g. the | ||
| 2012 | :term:`MACHINE` value is passed | ||
| 2013 | into the configure script or a patch is applied only for a particular | ||
| 2014 | machine), you should mark them as such by adding the following to the | ||
| 2015 | recipe: | ||
| 2016 | :: | ||
| 2017 | |||
| 2018 | PACKAGE_ARCH = "${MACHINE_ARCH}" | ||
| 2019 | |||
| 2020 | On the other hand, if the recipe produces packages that do not | ||
| 2021 | contain anything specific to the target machine or architecture at | ||
| 2022 | all (e.g. recipes that simply package script files or configuration | ||
| 2023 | files), you should use the | ||
| 2024 | :ref:`allarch <ref-classes-allarch>` class to | ||
| 2025 | do this for you by adding this to your recipe: | ||
| 2026 | :: | ||
| 2027 | |||
| 2028 | inherit allarch | ||
| 2029 | |||
| 2030 | Ensuring that the package architecture is correct is not critical | ||
| 2031 | while you are doing the first few builds of your recipe. However, it | ||
| 2032 | is important in order to ensure that your recipe rebuilds (or does | ||
| 2033 | not rebuild) appropriately in response to changes in configuration, | ||
| 2034 | and to ensure that you get the appropriate packages installed on the | ||
| 2035 | target machine, particularly if you run separate builds for more than | ||
| 2036 | one target machine. | ||
| 2037 | |||
| 2038 | Sharing Files Between Recipes | ||
| 2039 | ----------------------------- | ||
| 2040 | |||
| 2041 | Recipes often need to use files provided by other recipes on the build | ||
| 2042 | host. For example, an application linking to a common library needs | ||
| 2043 | access to the library itself and its associated headers. The way this | ||
| 2044 | access is accomplished is by populating a sysroot with files. Each | ||
| 2045 | recipe has two sysroots in its work directory, one for target files | ||
| 2046 | (``recipe-sysroot``) and one for files that are native to the build host | ||
| 2047 | (``recipe-sysroot-native``). | ||
| 2048 | |||
| 2049 | .. note:: | ||
| 2050 | |||
| 2051 | You could find the term "staging" used within the Yocto project | ||
| 2052 | regarding files populating sysroots (e.g. the :term:`STAGING_DIR` | ||
| 2053 | variable). | ||
| 2054 | |||
| 2055 | Recipes should never populate the sysroot directly (i.e. write files | ||
| 2056 | into sysroot). Instead, files should be installed into standard | ||
| 2057 | locations during the | ||
| 2058 | :ref:`ref-tasks-install` task within | ||
| 2059 | the ``${``\ :term:`D`\ ``}`` directory. The | ||
| 2060 | reason for this limitation is that almost all files that populate the | ||
| 2061 | sysroot are cataloged in manifests in order to ensure the files can be | ||
| 2062 | removed later when a recipe is either modified or removed. Thus, the | ||
| 2063 | sysroot is able to remain free from stale files. | ||
| 2064 | |||
| 2065 | A subset of the files installed by the | ||
| 2066 | :ref:`ref-tasks-install` task are | ||
| 2067 | used by the | ||
| 2068 | :ref:`ref-tasks-populate_sysroot` | ||
| 2069 | task as defined by the the | ||
| 2070 | :term:`SYSROOT_DIRS` variable to | ||
| 2071 | automatically populate the sysroot. It is possible to modify the list of | ||
| 2072 | directories that populate the sysroot. The following example shows how | ||
| 2073 | you could add the ``/opt`` directory to the list of directories within a | ||
| 2074 | recipe: | ||
| 2075 | :: | ||
| 2076 | |||
| 2077 | SYSROOT_DIRS += "/opt" | ||
| 2078 | |||
| 2079 | For a more complete description of the | ||
| 2080 | :ref:`ref-tasks-populate_sysroot` | ||
| 2081 | task and its associated functions, see the | ||
| 2082 | :ref:`staging <ref-classes-staging>` class. | ||
| 2083 | |||
| 2084 | Using Virtual Providers | ||
| 2085 | ----------------------- | ||
| 2086 | |||
| 2087 | Prior to a build, if you know that several different recipes provide the | ||
| 2088 | same functionality, you can use a virtual provider (i.e. ``virtual/*``) | ||
| 2089 | as a placeholder for the actual provider. The actual provider is | ||
| 2090 | determined at build-time. | ||
| 2091 | |||
| 2092 | A common scenario where a virtual provider is used would be for the | ||
| 2093 | kernel recipe. Suppose you have three kernel recipes whose | ||
| 2094 | :term:`PN` values map to ``kernel-big``, | ||
| 2095 | ``kernel-mid``, and ``kernel-small``. Furthermore, each of these recipes | ||
| 2096 | in some way uses a :term:`PROVIDES` | ||
| 2097 | statement that essentially identifies itself as being able to provide | ||
| 2098 | ``virtual/kernel``. Here is one way through the | ||
| 2099 | :ref:`kernel <ref-classes-kernel>` class: | ||
| 2100 | :: | ||
| 2101 | |||
| 2102 | PROVIDES += "${@ "virtual/kernel" if (d.getVar("KERNEL_PACKAGE_NAME") == "kernel") else "" }" | ||
| 2103 | |||
| 2104 | Any recipe that inherits the ``kernel`` class is | ||
| 2105 | going to utilize a ``PROVIDES`` statement that identifies that recipe as | ||
| 2106 | being able to provide the ``virtual/kernel`` item. | ||
| 2107 | |||
| 2108 | Now comes the time to actually build an image and you need a kernel | ||
| 2109 | recipe, but which one? You can configure your build to call out the | ||
| 2110 | kernel recipe you want by using the :term:`PREFERRED_PROVIDER` variable. As | ||
| 2111 | an example, consider the :yocto_git:`x86-base.inc | ||
| 2112 | </poky/tree/meta/conf/machine/include/x86-base.inc>` include file, which is a | ||
| 2113 | machine (i.e. :term:`MACHINE`) configuration file. This include file is the | ||
| 2114 | reason all x86-based machines use the ``linux-yocto`` kernel. Here are the | ||
| 2115 | relevant lines from the include file: | ||
| 2116 | :: | ||
| 2117 | |||
| 2118 | PREFERRED_PROVIDER_virtual/kernel ??= "linux-yocto" | ||
| 2119 | PREFERRED_VERSION_linux-yocto ??= "4.15%" | ||
| 2120 | |||
| 2121 | When you use a virtual provider, you do not have to "hard code" a recipe | ||
| 2122 | name as a build dependency. You can use the | ||
| 2123 | :term:`DEPENDS` variable to state the | ||
| 2124 | build is dependent on ``virtual/kernel`` for example: | ||
| 2125 | :: | ||
| 2126 | |||
| 2127 | DEPENDS = "virtual/kernel" | ||
| 2128 | |||
| 2129 | During the build, the OpenEmbedded build system picks | ||
| 2130 | the correct recipe needed for the ``virtual/kernel`` dependency based on | ||
| 2131 | the ``PREFERRED_PROVIDER`` variable. If you want to use the small kernel | ||
| 2132 | mentioned at the beginning of this section, configure your build as | ||
| 2133 | follows: | ||
| 2134 | :: | ||
| 2135 | |||
| 2136 | PREFERRED_PROVIDER_virtual/kernel ??= "kernel-small" | ||
| 2137 | |||
| 2138 | .. note:: | ||
| 2139 | |||
| 2140 | Any recipe that ``PROVIDES`` a ``virtual/*`` item that is ultimately not | ||
| 2141 | selected through ``PREFERRED_PROVIDER`` does not get built. Preventing these | ||
| 2142 | recipes from building is usually the desired behavior since this mechanism's | ||
| 2143 | purpose is to select between mutually exclusive alternative providers. | ||
| 2144 | |||
| 2145 | The following lists specific examples of virtual providers: | ||
| 2146 | |||
| 2147 | - ``virtual/kernel``: Provides the name of the kernel recipe to use | ||
| 2148 | when building a kernel image. | ||
| 2149 | |||
| 2150 | - ``virtual/bootloader``: Provides the name of the bootloader to use | ||
| 2151 | when building an image. | ||
| 2152 | |||
| 2153 | - ``virtual/libgbm``: Provides ``gbm.pc``. | ||
| 2154 | |||
| 2155 | - ``virtual/egl``: Provides ``egl.pc`` and possibly ``wayland-egl.pc``. | ||
| 2156 | |||
| 2157 | - ``virtual/libgl``: Provides ``gl.pc`` (i.e. libGL). | ||
| 2158 | |||
| 2159 | - ``virtual/libgles1``: Provides ``glesv1_cm.pc`` (i.e. libGLESv1_CM). | ||
| 2160 | |||
| 2161 | - ``virtual/libgles2``: Provides ``glesv2.pc`` (i.e. libGLESv2). | ||
| 2162 | |||
| 2163 | .. note:: | ||
| 2164 | |||
| 2165 | Virtual providers only apply to build time dependencies specified with | ||
| 2166 | :term:`PROVIDES` and :term:`DEPENDS`. They do not apply to runtime | ||
| 2167 | dependencies specified with :term:`RPROVIDES` and :term:`RDEPENDS`. | ||
| 2168 | |||
| 2169 | Properly Versioning Pre-Release Recipes | ||
| 2170 | --------------------------------------- | ||
| 2171 | |||
| 2172 | Sometimes the name of a recipe can lead to versioning problems when the | ||
| 2173 | recipe is upgraded to a final release. For example, consider the | ||
| 2174 | ``irssi_0.8.16-rc1.bb`` recipe file in the list of example recipes in | ||
| 2175 | the "`Storing and Naming the | ||
| 2176 | Recipe <#new-recipe-storing-and-naming-the-recipe>`__" section. This | ||
| 2177 | recipe is at a release candidate stage (i.e. "rc1"). When the recipe is | ||
| 2178 | released, the recipe filename becomes ``irssi_0.8.16.bb``. The version | ||
| 2179 | change from ``0.8.16-rc1`` to ``0.8.16`` is seen as a decrease by the | ||
| 2180 | build system and package managers, so the resulting packages will not | ||
| 2181 | correctly trigger an upgrade. | ||
| 2182 | |||
| 2183 | In order to ensure the versions compare properly, the recommended | ||
| 2184 | convention is to set :term:`PV` within the | ||
| 2185 | recipe to "previous_version+current_version". You can use an additional | ||
| 2186 | variable so that you can use the current version elsewhere. Here is an | ||
| 2187 | example: | ||
| 2188 | :: | ||
| 2189 | |||
| 2190 | REALPV = "0.8.16-rc1" | ||
| 2191 | PV = "0.8.15+${REALPV}" | ||
| 2192 | |||
| 2193 | Post-Installation Scripts | ||
| 2194 | ------------------------- | ||
| 2195 | |||
| 2196 | Post-installation scripts run immediately after installing a package on | ||
| 2197 | the target or during image creation when a package is included in an | ||
| 2198 | image. To add a post-installation script to a package, add a | ||
| 2199 | ``pkg_postinst_``\ `PACKAGENAME`\ ``()`` function to the recipe file | ||
| 2200 | (``.bb``) and replace `PACKAGENAME` with the name of the package you want | ||
| 2201 | to attach to the ``postinst`` script. To apply the post-installation | ||
| 2202 | script to the main package for the recipe, which is usually what is | ||
| 2203 | required, specify | ||
| 2204 | ``${``\ :term:`PN`\ ``}`` in place of | ||
| 2205 | PACKAGENAME. | ||
| 2206 | |||
| 2207 | A post-installation function has the following structure: | ||
| 2208 | :: | ||
| 2209 | |||
| 2210 | pkg_postinst_PACKAGENAME() { | ||
| 2211 | # Commands to carry out | ||
| 2212 | } | ||
| 2213 | |||
| 2214 | The script defined in the post-installation function is called when the | ||
| 2215 | root filesystem is created. If the script succeeds, the package is | ||
| 2216 | marked as installed. | ||
| 2217 | |||
| 2218 | .. note:: | ||
| 2219 | |||
| 2220 | Any RPM post-installation script that runs on the target should | ||
| 2221 | return a 0 exit code. RPM does not allow non-zero exit codes for | ||
| 2222 | these scripts, and the RPM package manager will cause the package to | ||
| 2223 | fail installation on the target. | ||
| 2224 | |||
| 2225 | Sometimes it is necessary for the execution of a post-installation | ||
| 2226 | script to be delayed until the first boot. For example, the script might | ||
| 2227 | need to be executed on the device itself. To delay script execution | ||
| 2228 | until boot time, you must explicitly mark post installs to defer to the | ||
| 2229 | target. You can use ``pkg_postinst_ontarget()`` or call | ||
| 2230 | ``postinst_intercept delay_to_first_boot`` from ``pkg_postinst()``. Any | ||
| 2231 | failure of a ``pkg_postinst()`` script (including exit 1) triggers an | ||
| 2232 | error during the | ||
| 2233 | :ref:`ref-tasks-rootfs` task. | ||
| 2234 | |||
| 2235 | If you have recipes that use ``pkg_postinst`` function and they require | ||
| 2236 | the use of non-standard native tools that have dependencies during | ||
| 2237 | rootfs construction, you need to use the | ||
| 2238 | :term:`PACKAGE_WRITE_DEPS` | ||
| 2239 | variable in your recipe to list these tools. If you do not use this | ||
| 2240 | variable, the tools might be missing and execution of the | ||
| 2241 | post-installation script is deferred until first boot. Deferring the | ||
| 2242 | script to first boot is undesirable and for read-only rootfs impossible. | ||
| 2243 | |||
| 2244 | .. note:: | ||
| 2245 | |||
| 2246 | Equivalent support for pre-install, pre-uninstall, and post-uninstall | ||
| 2247 | scripts exist by way of ``pkg_preinst``, ``pkg_prerm``, and ``pkg_postrm``, | ||
| 2248 | respectively. These scrips work in exactly the same way as does | ||
| 2249 | ``pkg_postinst`` with the exception that they run at different times. Also, | ||
| 2250 | because of when they run, they are not applicable to being run at image | ||
| 2251 | creation time like ``pkg_postinst``. | ||
| 2252 | |||
| 2253 | Testing | ||
| 2254 | ------- | ||
| 2255 | |||
| 2256 | The final step for completing your recipe is to be sure that the | ||
| 2257 | software you built runs correctly. To accomplish runtime testing, add | ||
| 2258 | the build's output packages to your image and test them on the target. | ||
| 2259 | |||
| 2260 | For information on how to customize your image by adding specific | ||
| 2261 | packages, see the "`Customizing | ||
| 2262 | Images <#usingpoky-extend-customimage>`__" section. | ||
| 2263 | |||
| 2264 | Examples | ||
| 2265 | -------- | ||
| 2266 | |||
| 2267 | To help summarize how to write a recipe, this section provides some | ||
| 2268 | examples given various scenarios: | ||
| 2269 | |||
| 2270 | - Recipes that use local files | ||
| 2271 | |||
| 2272 | - Using an Autotooled package | ||
| 2273 | |||
| 2274 | - Using a Makefile-based package | ||
| 2275 | |||
| 2276 | - Splitting an application into multiple packages | ||
| 2277 | |||
| 2278 | - Adding binaries to an image | ||
| 2279 | |||
| 2280 | Single .c File Package (Hello World!) | ||
| 2281 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 2282 | |||
| 2283 | Building an application from a single file that is stored locally (e.g. | ||
| 2284 | under ``files``) requires a recipe that has the file listed in the | ||
| 2285 | ``SRC_URI`` variable. Additionally, you need to manually write the | ||
| 2286 | ``do_compile`` and ``do_install`` tasks. The ``S`` variable defines the | ||
| 2287 | directory containing the source code, which is set to | ||
| 2288 | :term:`WORKDIR` in this case - the | ||
| 2289 | directory BitBake uses for the build. | ||
| 2290 | :: | ||
| 2291 | |||
| 2292 | SUMMARY = "Simple helloworld application" | ||
| 2293 | SECTION = "examples" | ||
| 2294 | LICENSE = "MIT" | ||
| 2295 | LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" | ||
| 2296 | |||
| 2297 | SRC_URI = "file://helloworld.c" | ||
| 2298 | |||
| 2299 | S = "${WORKDIR}" | ||
| 2300 | |||
| 2301 | do_compile() { | ||
| 2302 | ${CC} helloworld.c -o helloworld | ||
| 2303 | } | ||
| 2304 | |||
| 2305 | do_install() { | ||
| 2306 | install -d ${D}${bindir} | ||
| 2307 | install -m 0755 helloworld ${D}${bindir} | ||
| 2308 | } | ||
| 2309 | |||
| 2310 | By default, the ``helloworld``, ``helloworld-dbg``, and | ||
| 2311 | ``helloworld-dev`` packages are built. For information on how to | ||
| 2312 | customize the packaging process, see the "`Splitting an Application into | ||
| 2313 | Multiple Packages <#splitting-an-application-into-multiple-packages>`__" | ||
| 2314 | section. | ||
| 2315 | |||
| 2316 | Autotooled Package | ||
| 2317 | ~~~~~~~~~~~~~~~~~~ | ||
| 2318 | |||
| 2319 | Applications that use Autotools such as ``autoconf`` and ``automake`` | ||
| 2320 | require a recipe that has a source archive listed in ``SRC_URI`` and | ||
| 2321 | also inherit the | ||
| 2322 | :ref:`autotools <ref-classes-autotools>` class, | ||
| 2323 | which contains the definitions of all the steps needed to build an | ||
| 2324 | Autotool-based application. The result of the build is automatically | ||
| 2325 | packaged. And, if the application uses NLS for localization, packages | ||
| 2326 | with local information are generated (one package per language). | ||
| 2327 | Following is one example: (``hello_2.3.bb``) | ||
| 2328 | :: | ||
| 2329 | |||
| 2330 | SUMMARY = "GNU Helloworld application" | ||
| 2331 | SECTION = "examples" | ||
| 2332 | LICENSE = "GPLv2+" | ||
| 2333 | LIC_FILES_CHKSUM = "file://COPYING;md5=751419260aa954499f7abaabaa882bbe" | ||
| 2334 | |||
| 2335 | SRC_URI = "${GNU_MIRROR}/hello/hello-${PV}.tar.gz" | ||
| 2336 | |||
| 2337 | inherit autotools gettext | ||
| 2338 | |||
| 2339 | The variable ``LIC_FILES_CHKSUM`` is used to track source license | ||
| 2340 | changes as described in the | ||
| 2341 | ":ref:`dev-manual/common-tasks:tracking license changes`" section in | ||
| 2342 | the Yocto Project Overview and Concepts Manual. You can quickly create | ||
| 2343 | Autotool-based recipes in a manner similar to the previous example. | ||
| 2344 | |||
| 2345 | Makefile-Based Package | ||
| 2346 | ~~~~~~~~~~~~~~~~~~~~~~ | ||
| 2347 | |||
| 2348 | Applications that use GNU ``make`` also require a recipe that has the | ||
| 2349 | source archive listed in ``SRC_URI``. You do not need to add a | ||
| 2350 | ``do_compile`` step since by default BitBake starts the ``make`` command | ||
| 2351 | to compile the application. If you need additional ``make`` options, you | ||
| 2352 | should store them in the | ||
| 2353 | :term:`EXTRA_OEMAKE` or | ||
| 2354 | :term:`PACKAGECONFIG_CONFARGS` | ||
| 2355 | variables. BitBake passes these options into the GNU ``make`` | ||
| 2356 | invocation. Note that a ``do_install`` task is still required. | ||
| 2357 | Otherwise, BitBake runs an empty ``do_install`` task by default. | ||
| 2358 | |||
| 2359 | Some applications might require extra parameters to be passed to the | ||
| 2360 | compiler. For example, the application might need an additional header | ||
| 2361 | path. You can accomplish this by adding to the ``CFLAGS`` variable. The | ||
| 2362 | following example shows this: | ||
| 2363 | :: | ||
| 2364 | |||
| 2365 | CFLAGS_prepend = "-I ${S}/include " | ||
| 2366 | |||
| 2367 | In the following example, ``mtd-utils`` is a makefile-based package: | ||
| 2368 | :: | ||
| 2369 | |||
| 2370 | SUMMARY = "Tools for managing memory technology devices" | ||
| 2371 | SECTION = "base" | ||
| 2372 | DEPENDS = "zlib lzo e2fsprogs util-linux" | ||
| 2373 | HOMEPAGE = "http://www.linux-mtd.infradead.org/" | ||
| 2374 | LICENSE = "GPLv2+" | ||
| 2375 | LIC_FILES_CHKSUM = "file://COPYING;md5=0636e73ff0215e8d672dc4c32c317bb3 \ | ||
| 2376 | file://include/common.h;beginline=1;endline=17;md5=ba05b07912a44ea2bf81ce409380049c" | ||
| 2377 | |||
| 2378 | # Use the latest version at 26 Oct, 2013 | ||
| 2379 | SRCREV = "9f107132a6a073cce37434ca9cda6917dd8d866b" | ||
| 2380 | SRC_URI = "git://git.infradead.org/mtd-utils.git \ | ||
| 2381 | file://add-exclusion-to-mkfs-jffs2-git-2.patch \ | ||
| 2382 | " | ||
| 2383 | |||
| 2384 | PV = "1.5.1+git${SRCPV}" | ||
| 2385 | |||
| 2386 | S = "${WORKDIR}/git" | ||
| 2387 | |||
| 2388 | EXTRA_OEMAKE = "'CC=${CC}' 'RANLIB=${RANLIB}' 'AR=${AR}' 'CFLAGS=${CFLAGS} -I${S}/include -DWITHOUT_XATTR' 'BUILDDIR=${S}'" | ||
| 2389 | |||
| 2390 | do_install () { | ||
| 2391 | oe_runmake install DESTDIR=${D} SBINDIR=${sbindir} MANDIR=${mandir} INCLUDEDIR=${includedir} | ||
| 2392 | } | ||
| 2393 | |||
| 2394 | PACKAGES =+ "mtd-utils-jffs2 mtd-utils-ubifs mtd-utils-misc" | ||
| 2395 | |||
| 2396 | FILES_mtd-utils-jffs2 = "${sbindir}/mkfs.jffs2 ${sbindir}/jffs2dump ${sbindir}/jffs2reader ${sbindir}/sumtool" | ||
| 2397 | FILES_mtd-utils-ubifs = "${sbindir}/mkfs.ubifs ${sbindir}/ubi*" | ||
| 2398 | FILES_mtd-utils-misc = "${sbindir}/nftl* ${sbindir}/ftl* ${sbindir}/rfd* ${sbindir}/doc* ${sbindir}/serve_image ${sbindir}/recv_image" | ||
| 2399 | |||
| 2400 | PARALLEL_MAKE = "" | ||
| 2401 | |||
| 2402 | BBCLASSEXTEND = "native" | ||
| 2403 | |||
| 2404 | Splitting an Application into Multiple Packages | ||
| 2405 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 2406 | |||
| 2407 | You can use the variables ``PACKAGES`` and ``FILES`` to split an | ||
| 2408 | application into multiple packages. | ||
| 2409 | |||
| 2410 | Following is an example that uses the ``libxpm`` recipe. By default, | ||
| 2411 | this recipe generates a single package that contains the library along | ||
| 2412 | with a few binaries. You can modify the recipe to split the binaries | ||
| 2413 | into separate packages: | ||
| 2414 | :: | ||
| 2415 | |||
| 2416 | require xorg-lib-common.inc | ||
| 2417 | |||
| 2418 | SUMMARY = "Xpm: X Pixmap extension library" | ||
| 2419 | LICENSE = "BSD" | ||
| 2420 | LIC_FILES_CHKSUM = "file://COPYING;md5=51f4270b012ecd4ab1a164f5f4ed6cf7" | ||
| 2421 | DEPENDS += "libxext libsm libxt" | ||
| 2422 | PE = "1" | ||
| 2423 | |||
| 2424 | XORG_PN = "libXpm" | ||
| 2425 | |||
| 2426 | PACKAGES =+ "sxpm cxpm" | ||
| 2427 | FILES_cxpm = "${bindir}/cxpm" | ||
| 2428 | FILES_sxpm = "${bindir}/sxpm" | ||
| 2429 | |||
| 2430 | In the previous example, we want to ship the ``sxpm`` and ``cxpm`` | ||
| 2431 | binaries in separate packages. Since ``bindir`` would be packaged into | ||
| 2432 | the main ``PN`` package by default, we prepend the ``PACKAGES`` variable | ||
| 2433 | so additional package names are added to the start of list. This results | ||
| 2434 | in the extra ``FILES_*`` variables then containing information that | ||
| 2435 | define which files and directories go into which packages. Files | ||
| 2436 | included by earlier packages are skipped by latter packages. Thus, the | ||
| 2437 | main ``PN`` package does not include the above listed files. | ||
| 2438 | |||
| 2439 | Packaging Externally Produced Binaries | ||
| 2440 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 2441 | |||
| 2442 | Sometimes, you need to add pre-compiled binaries to an image. For | ||
| 2443 | example, suppose that binaries for proprietary code exist, which are | ||
| 2444 | created by a particular division of a company. Your part of the company | ||
| 2445 | needs to use those binaries as part of an image that you are building | ||
| 2446 | using the OpenEmbedded build system. Since you only have the binaries | ||
| 2447 | and not the source code, you cannot use a typical recipe that expects to | ||
| 2448 | fetch the source specified in | ||
| 2449 | :term:`SRC_URI` and then compile it. | ||
| 2450 | |||
| 2451 | One method is to package the binaries and then install them as part of | ||
| 2452 | the image. Generally, it is not a good idea to package binaries since, | ||
| 2453 | among other things, it can hinder the ability to reproduce builds and | ||
| 2454 | could lead to compatibility problems with ABI in the future. However, | ||
| 2455 | sometimes you have no choice. | ||
| 2456 | |||
| 2457 | The easiest solution is to create a recipe that uses the | ||
| 2458 | :ref:`bin_package <ref-classes-bin-package>` class | ||
| 2459 | and to be sure that you are using default locations for build artifacts. | ||
| 2460 | In most cases, the ``bin_package`` class handles "skipping" the | ||
| 2461 | configure and compile steps as well as sets things up to grab packages | ||
| 2462 | from the appropriate area. In particular, this class sets ``noexec`` on | ||
| 2463 | both the :ref:`ref-tasks-configure` | ||
| 2464 | and :ref:`ref-tasks-compile` tasks, | ||
| 2465 | sets ``FILES_${PN}`` to "/" so that it picks up all files, and sets up a | ||
| 2466 | :ref:`ref-tasks-install` task, which | ||
| 2467 | effectively copies all files from ``${S}`` to ``${D}``. The | ||
| 2468 | ``bin_package`` class works well when the files extracted into ``${S}`` | ||
| 2469 | are already laid out in the way they should be laid out on the target. | ||
| 2470 | For more information on these variables, see the | ||
| 2471 | :term:`FILES`, | ||
| 2472 | :term:`PN`, | ||
| 2473 | :term:`S`, and | ||
| 2474 | :term:`D` variables in the Yocto Project | ||
| 2475 | Reference Manual's variable glossary. | ||
| 2476 | |||
| 2477 | .. note:: | ||
| 2478 | |||
| 2479 | - Using :term:`DEPENDS` is a good | ||
| 2480 | idea even for components distributed in binary form, and is often | ||
| 2481 | necessary for shared libraries. For a shared library, listing the | ||
| 2482 | library dependencies in ``DEPENDS`` makes sure that the libraries | ||
| 2483 | are available in the staging sysroot when other recipes link | ||
| 2484 | against the library, which might be necessary for successful | ||
| 2485 | linking. | ||
| 2486 | |||
| 2487 | - Using ``DEPENDS`` also allows runtime dependencies between | ||
| 2488 | packages to be added automatically. See the | ||
| 2489 | ":ref:`overview-manual/overview-manual-concepts:automatically added runtime dependencies`" | ||
| 2490 | section in the Yocto Project Overview and Concepts Manual for more | ||
| 2491 | information. | ||
| 2492 | |||
| 2493 | If you cannot use the ``bin_package`` class, you need to be sure you are | ||
| 2494 | doing the following: | ||
| 2495 | |||
| 2496 | - Create a recipe where the | ||
| 2497 | :ref:`ref-tasks-configure` and | ||
| 2498 | :ref:`ref-tasks-compile` tasks do | ||
| 2499 | nothing: It is usually sufficient to just not define these tasks in | ||
| 2500 | the recipe, because the default implementations do nothing unless a | ||
| 2501 | Makefile is found in | ||
| 2502 | ``${``\ :term:`S`\ ``}``. | ||
| 2503 | |||
| 2504 | If ``${S}`` might contain a Makefile, or if you inherit some class | ||
| 2505 | that replaces ``do_configure`` and ``do_compile`` with custom | ||
| 2506 | versions, then you can use the | ||
| 2507 | ``[``\ :ref:`noexec <bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ``]`` | ||
| 2508 | flag to turn the tasks into no-ops, as follows: | ||
| 2509 | :: | ||
| 2510 | |||
| 2511 | do_configure[noexec] = "1" | ||
| 2512 | do_compile[noexec] = "1" | ||
| 2513 | |||
| 2514 | Unlike | ||
| 2515 | :ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:deleting a task`, | ||
| 2516 | using the flag preserves the dependency chain from the | ||
| 2517 | :ref:`ref-tasks-fetch`, | ||
| 2518 | :ref:`ref-tasks-unpack`, and | ||
| 2519 | :ref:`ref-tasks-patch` tasks to the | ||
| 2520 | :ref:`ref-tasks-install` task. | ||
| 2521 | |||
| 2522 | - Make sure your ``do_install`` task installs the binaries | ||
| 2523 | appropriately. | ||
| 2524 | |||
| 2525 | - Ensure that you set up :term:`FILES` | ||
| 2526 | (usually | ||
| 2527 | ``FILES_${``\ :term:`PN`\ ``}``) to | ||
| 2528 | point to the files you have installed, which of course depends on | ||
| 2529 | where you have installed them and whether those files are in | ||
| 2530 | different locations than the defaults. | ||
| 2531 | |||
| 2532 | .. note:: | ||
| 2533 | |||
| 2534 | If image prelinking is enabled (e.g. "image-prelink" is in :term:`USER_CLASSES` | ||
| 2535 | which it is by default), prelink will change the binaries in the generated images | ||
| 2536 | and this often catches people out. Remove that class to ensure binaries are | ||
| 2537 | preserved exactly if that is necessary. | ||
| 2538 | |||
| 2539 | Following Recipe Style Guidelines | ||
| 2540 | --------------------------------- | ||
| 2541 | |||
| 2542 | When writing recipes, it is good to conform to existing style | ||
| 2543 | guidelines. The :oe_home:`OpenEmbedded Styleguide </wiki/Styleguide>` wiki page | ||
| 2544 | provides rough guidelines for preferred recipe style. | ||
| 2545 | |||
| 2546 | It is common for existing recipes to deviate a bit from this style. | ||
| 2547 | However, aiming for at least a consistent style is a good idea. Some | ||
| 2548 | practices, such as omitting spaces around ``=`` operators in assignments | ||
| 2549 | or ordering recipe components in an erratic way, are widely seen as poor | ||
| 2550 | style. | ||
| 2551 | |||
| 2552 | Recipe Syntax | ||
| 2553 | ------------- | ||
| 2554 | |||
| 2555 | Understanding recipe file syntax is important for writing recipes. The | ||
| 2556 | following list overviews the basic items that make up a BitBake recipe | ||
| 2557 | file. For more complete BitBake syntax descriptions, see the | ||
| 2558 | ":doc:`bitbake-user-manual/bitbake-user-manual-metadata`" | ||
| 2559 | chapter of the BitBake User Manual. | ||
| 2560 | |||
| 2561 | - *Variable Assignments and Manipulations:* Variable assignments allow | ||
| 2562 | a value to be assigned to a variable. The assignment can be static | ||
| 2563 | text or might include the contents of other variables. In addition to | ||
| 2564 | the assignment, appending and prepending operations are also | ||
| 2565 | supported. | ||
| 2566 | |||
| 2567 | The following example shows some of the ways you can use variables in | ||
| 2568 | recipes: | ||
| 2569 | :: | ||
| 2570 | |||
| 2571 | S = "${WORKDIR}/postfix-${PV}" | ||
| 2572 | CFLAGS += "-DNO_ASM" | ||
| 2573 | SRC_URI_append = " file://fixup.patch" | ||
| 2574 | |||
| 2575 | - *Functions:* Functions provide a series of actions to be performed. | ||
| 2576 | You usually use functions to override the default implementation of a | ||
| 2577 | task function or to complement a default function (i.e. append or | ||
| 2578 | prepend to an existing function). Standard functions use ``sh`` shell | ||
| 2579 | syntax, although access to OpenEmbedded variables and internal | ||
| 2580 | methods are also available. | ||
| 2581 | |||
| 2582 | The following is an example function from the ``sed`` recipe: | ||
| 2583 | :: | ||
| 2584 | |||
| 2585 | do_install () { | ||
| 2586 | autotools_do_install | ||
| 2587 | install -d ${D}${base_bindir} | ||
| 2588 | mv ${D}${bindir}/sed ${D}${base_bindir}/sed | ||
| 2589 | rmdir ${D}${bindir}/ | ||
| 2590 | } | ||
| 2591 | |||
| 2592 | It is | ||
| 2593 | also possible to implement new functions that are called between | ||
| 2594 | existing tasks as long as the new functions are not replacing or | ||
| 2595 | complementing the default functions. You can implement functions in | ||
| 2596 | Python instead of shell. Both of these options are not seen in the | ||
| 2597 | majority of recipes. | ||
| 2598 | |||
| 2599 | - *Keywords:* BitBake recipes use only a few keywords. You use keywords | ||
| 2600 | to include common functions (``inherit``), load parts of a recipe | ||
| 2601 | from other files (``include`` and ``require``) and export variables | ||
| 2602 | to the environment (``export``). | ||
| 2603 | |||
| 2604 | The following example shows the use of some of these keywords: | ||
| 2605 | :: | ||
| 2606 | |||
| 2607 | export POSTCONF = "${STAGING_BINDIR}/postconf" | ||
| 2608 | inherit autoconf | ||
| 2609 | require otherfile.inc | ||
| 2610 | |||
| 2611 | - *Comments (#):* Any lines that begin with the hash character (``#``) | ||
| 2612 | are treated as comment lines and are ignored: | ||
| 2613 | :: | ||
| 2614 | |||
| 2615 | # This is a comment | ||
| 2616 | |||
| 2617 | This next list summarizes the most important and most commonly used | ||
| 2618 | parts of the recipe syntax. For more information on these parts of the | ||
| 2619 | syntax, you can reference the | ||
| 2620 | :doc:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata` chapter | ||
| 2621 | in the BitBake User Manual. | ||
| 2622 | |||
| 2623 | - *Line Continuation (\\):* Use the backward slash (``\``) character to | ||
| 2624 | split a statement over multiple lines. Place the slash character at | ||
| 2625 | the end of the line that is to be continued on the next line: | ||
| 2626 | :: | ||
| 2627 | |||
| 2628 | VAR = "A really long \ | ||
| 2629 | line" | ||
| 2630 | |||
| 2631 | .. note:: | ||
| 2632 | |||
| 2633 | You cannot have any characters including spaces or tabs after the | ||
| 2634 | slash character. | ||
| 2635 | |||
| 2636 | - *Using Variables (${VARNAME}):* Use the ``${VARNAME}`` syntax to | ||
| 2637 | access the contents of a variable: | ||
| 2638 | :: | ||
| 2639 | |||
| 2640 | SRC_URI = "${SOURCEFORGE_MIRROR}/libpng/zlib-${PV}.tar.gz" | ||
| 2641 | |||
| 2642 | .. note:: | ||
| 2643 | |||
| 2644 | It is important to understand that the value of a variable | ||
| 2645 | expressed in this form does not get substituted automatically. The | ||
| 2646 | expansion of these expressions happens on-demand later (e.g. | ||
| 2647 | usually when a function that makes reference to the variable | ||
| 2648 | executes). This behavior ensures that the values are most | ||
| 2649 | appropriate for the context in which they are finally used. On the | ||
| 2650 | rare occasion that you do need the variable expression to be | ||
| 2651 | expanded immediately, you can use the | ||
| 2652 | := | ||
| 2653 | operator instead of | ||
| 2654 | = | ||
| 2655 | when you make the assignment, but this is not generally needed. | ||
| 2656 | |||
| 2657 | - *Quote All Assignments ("value"):* Use double quotes around values in | ||
| 2658 | all variable assignments (e.g. ``"value"``). Following is an example: | ||
| 2659 | :: | ||
| 2660 | |||
| 2661 | VAR1 = "${OTHERVAR}" | ||
| 2662 | VAR2 = "The version is ${PV}" | ||
| 2663 | |||
| 2664 | - *Conditional Assignment (?=):* Conditional assignment is used to | ||
| 2665 | assign a value to a variable, but only when the variable is currently | ||
| 2666 | unset. Use the question mark followed by the equal sign (``?=``) to | ||
| 2667 | make a "soft" assignment used for conditional assignment. Typically, | ||
| 2668 | "soft" assignments are used in the ``local.conf`` file for variables | ||
| 2669 | that are allowed to come through from the external environment. | ||
| 2670 | |||
| 2671 | Here is an example where ``VAR1`` is set to "New value" if it is | ||
| 2672 | currently empty. However, if ``VAR1`` has already been set, it | ||
| 2673 | remains unchanged: | ||
| 2674 | :: | ||
| 2675 | |||
| 2676 | VAR1 ?= "New value" | ||
| 2677 | |||
| 2678 | In this next example, ``VAR1`` is left with the value "Original value": | ||
| 2679 | :: | ||
| 2680 | |||
| 2681 | VAR1 = "Original value" | ||
| 2682 | VAR1 ?= "New value" | ||
| 2683 | |||
| 2684 | - *Appending (+=):* Use the plus character followed by the equals sign | ||
| 2685 | (``+=``) to append values to existing variables. | ||
| 2686 | |||
| 2687 | .. note:: | ||
| 2688 | |||
| 2689 | This operator adds a space between the existing content of the | ||
| 2690 | variable and the new content. | ||
| 2691 | |||
| 2692 | Here is an example: | ||
| 2693 | :: | ||
| 2694 | |||
| 2695 | SRC_URI += "file://fix-makefile.patch" | ||
| 2696 | |||
| 2697 | - *Prepending (=+):* Use the equals sign followed by the plus character | ||
| 2698 | (``=+``) to prepend values to existing variables. | ||
| 2699 | |||
| 2700 | .. note:: | ||
| 2701 | |||
| 2702 | This operator adds a space between the new content and the | ||
| 2703 | existing content of the variable. | ||
| 2704 | |||
| 2705 | Here is an example: | ||
| 2706 | :: | ||
| 2707 | |||
| 2708 | VAR =+ "Starts" | ||
| 2709 | |||
| 2710 | - *Appending (_append):* Use the ``_append`` operator to append values | ||
| 2711 | to existing variables. This operator does not add any additional | ||
| 2712 | space. Also, the operator is applied after all the ``+=``, and ``=+`` | ||
| 2713 | operators have been applied and after all ``=`` assignments have | ||
| 2714 | occurred. | ||
| 2715 | |||
| 2716 | The following example shows the space being explicitly added to the | ||
| 2717 | start to ensure the appended value is not merged with the existing | ||
| 2718 | value: | ||
| 2719 | :: | ||
| 2720 | |||
| 2721 | SRC_URI_append = " file://fix-makefile.patch" | ||
| 2722 | |||
| 2723 | You can also use | ||
| 2724 | the ``_append`` operator with overrides, which results in the actions | ||
| 2725 | only being performed for the specified target or machine: | ||
| 2726 | :: | ||
| 2727 | |||
| 2728 | SRC_URI_append_sh4 = " file://fix-makefile.patch" | ||
| 2729 | |||
| 2730 | - *Prepending (_prepend):* Use the ``_prepend`` operator to prepend | ||
| 2731 | values to existing variables. This operator does not add any | ||
| 2732 | additional space. Also, the operator is applied after all the ``+=``, | ||
| 2733 | and ``=+`` operators have been applied and after all ``=`` | ||
| 2734 | assignments have occurred. | ||
| 2735 | |||
| 2736 | The following example shows the space being explicitly added to the | ||
| 2737 | end to ensure the prepended value is not merged with the existing | ||
| 2738 | value: | ||
| 2739 | :: | ||
| 2740 | |||
| 2741 | CFLAGS_prepend = "-I${S}/myincludes " | ||
| 2742 | |||
| 2743 | You can also use the | ||
| 2744 | ``_prepend`` operator with overrides, which results in the actions | ||
| 2745 | only being performed for the specified target or machine: | ||
| 2746 | :: | ||
| 2747 | |||
| 2748 | CFLAGS_prepend_sh4 = "-I${S}/myincludes " | ||
| 2749 | |||
| 2750 | - *Overrides:* You can use overrides to set a value conditionally, | ||
| 2751 | typically based on how the recipe is being built. For example, to set | ||
| 2752 | the :term:`KBRANCH` variable's | ||
| 2753 | value to "standard/base" for any target | ||
| 2754 | :term:`MACHINE`, except for | ||
| 2755 | qemuarm where it should be set to "standard/arm-versatile-926ejs", | ||
| 2756 | you would do the following: | ||
| 2757 | :: | ||
| 2758 | |||
| 2759 | KBRANCH = "standard/base" | ||
| 2760 | KBRANCH_qemuarm = "standard/arm-versatile-926ejs" | ||
| 2761 | |||
| 2762 | Overrides are also used to separate | ||
| 2763 | alternate values of a variable in other situations. For example, when | ||
| 2764 | setting variables such as | ||
| 2765 | :term:`FILES` and | ||
| 2766 | :term:`RDEPENDS` that are | ||
| 2767 | specific to individual packages produced by a recipe, you should | ||
| 2768 | always use an override that specifies the name of the package. | ||
| 2769 | |||
| 2770 | - *Indentation:* Use spaces for indentation rather than tabs. For | ||
| 2771 | shell functions, both currently work. However, it is a policy | ||
| 2772 | decision of the Yocto Project to use tabs in shell functions. Realize | ||
| 2773 | that some layers have a policy to use spaces for all indentation. | ||
| 2774 | |||
| 2775 | - *Using Python for Complex Operations:* For more advanced processing, | ||
| 2776 | it is possible to use Python code during variable assignments (e.g. | ||
| 2777 | search and replacement on a variable). | ||
| 2778 | |||
| 2779 | You indicate Python code using the ``${@python_code}`` syntax for the | ||
| 2780 | variable assignment: | ||
| 2781 | :: | ||
| 2782 | |||
| 2783 | SRC_URI = "ftp://ftp.info-zip.org/pub/infozip/src/zip${@d.getVar('PV',1).replace('.', '')}.tgz | ||
| 2784 | |||
| 2785 | - *Shell Function Syntax:* Write shell functions as if you were writing | ||
| 2786 | a shell script when you describe a list of actions to take. You | ||
| 2787 | should ensure that your script works with a generic ``sh`` and that | ||
| 2788 | it does not require any ``bash`` or other shell-specific | ||
| 2789 | functionality. The same considerations apply to various system | ||
| 2790 | utilities (e.g. ``sed``, ``grep``, ``awk``, and so forth) that you | ||
| 2791 | might wish to use. If in doubt, you should check with multiple | ||
| 2792 | implementations - including those from BusyBox. | ||
| 2793 | |||
| 2794 | Adding a New Machine | ||
| 2795 | ==================== | ||
| 2796 | |||
| 2797 | Adding a new machine to the Yocto Project is a straightforward process. | ||
| 2798 | This section describes how to add machines that are similar to those | ||
| 2799 | that the Yocto Project already supports. | ||
| 2800 | |||
| 2801 | .. note:: | ||
| 2802 | |||
| 2803 | Although well within the capabilities of the Yocto Project, adding a | ||
| 2804 | totally new architecture might require changes to ``gcc``/``glibc`` | ||
| 2805 | and to the site information, which is beyond the scope of this | ||
| 2806 | manual. | ||
| 2807 | |||
| 2808 | For a complete example that shows how to add a new machine, see the | ||
| 2809 | ":ref:`bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script`" | ||
| 2810 | section in the Yocto Project Board Support Package (BSP) Developer's | ||
| 2811 | Guide. | ||
| 2812 | |||
| 2813 | Adding the Machine Configuration File | ||
| 2814 | ------------------------------------- | ||
| 2815 | |||
| 2816 | To add a new machine, you need to add a new machine configuration file | ||
| 2817 | to the layer's ``conf/machine`` directory. This configuration file | ||
| 2818 | provides details about the device you are adding. | ||
| 2819 | |||
| 2820 | The OpenEmbedded build system uses the root name of the machine | ||
| 2821 | configuration file to reference the new machine. For example, given a | ||
| 2822 | machine configuration file named ``crownbay.conf``, the build system | ||
| 2823 | recognizes the machine as "crownbay". | ||
| 2824 | |||
| 2825 | The most important variables you must set in your machine configuration | ||
| 2826 | file or include from a lower-level configuration file are as follows: | ||
| 2827 | |||
| 2828 | - ``TARGET_ARCH`` (e.g. "arm") | ||
| 2829 | |||
| 2830 | - ``PREFERRED_PROVIDER_virtual/kernel`` | ||
| 2831 | |||
| 2832 | - ``MACHINE_FEATURES`` (e.g. "apm screen wifi") | ||
| 2833 | |||
| 2834 | You might also need these variables: | ||
| 2835 | |||
| 2836 | - ``SERIAL_CONSOLES`` (e.g. "115200;ttyS0 115200;ttyS1") | ||
| 2837 | |||
| 2838 | - ``KERNEL_IMAGETYPE`` (e.g. "zImage") | ||
| 2839 | |||
| 2840 | - ``IMAGE_FSTYPES`` (e.g. "tar.gz jffs2") | ||
| 2841 | |||
| 2842 | You can find full details on these variables in the reference section. | ||
| 2843 | You can leverage existing machine ``.conf`` files from | ||
| 2844 | ``meta-yocto-bsp/conf/machine/``. | ||
| 2845 | |||
| 2846 | Adding a Kernel for the Machine | ||
| 2847 | ------------------------------- | ||
| 2848 | |||
| 2849 | The OpenEmbedded build system needs to be able to build a kernel for the | ||
| 2850 | machine. You need to either create a new kernel recipe for this machine, | ||
| 2851 | or extend an existing kernel recipe. You can find several kernel recipe | ||
| 2852 | examples in the Source Directory at ``meta/recipes-kernel/linux`` that | ||
| 2853 | you can use as references. | ||
| 2854 | |||
| 2855 | If you are creating a new kernel recipe, normal recipe-writing rules | ||
| 2856 | apply for setting up a ``SRC_URI``. Thus, you need to specify any | ||
| 2857 | necessary patches and set ``S`` to point at the source code. You need to | ||
| 2858 | create a ``do_configure`` task that configures the unpacked kernel with | ||
| 2859 | a ``defconfig`` file. You can do this by using a ``make defconfig`` | ||
| 2860 | command or, more commonly, by copying in a suitable ``defconfig`` file | ||
| 2861 | and then running ``make oldconfig``. By making use of ``inherit kernel`` | ||
| 2862 | and potentially some of the ``linux-*.inc`` files, most other | ||
| 2863 | functionality is centralized and the defaults of the class normally work | ||
| 2864 | well. | ||
| 2865 | |||
| 2866 | If you are extending an existing kernel recipe, it is usually a matter | ||
| 2867 | of adding a suitable ``defconfig`` file. The file needs to be added into | ||
| 2868 | a location similar to ``defconfig`` files used for other machines in a | ||
| 2869 | given kernel recipe. A possible way to do this is by listing the file in | ||
| 2870 | the ``SRC_URI`` and adding the machine to the expression in | ||
| 2871 | ``COMPATIBLE_MACHINE``: | ||
| 2872 | :: | ||
| 2873 | |||
| 2874 | COMPATIBLE_MACHINE = '(qemux86|qemumips)' | ||
| 2875 | |||
| 2876 | For more information on ``defconfig`` files, see the | ||
| 2877 | ":ref:`kernel-dev/kernel-dev-common:changing the configuration`" | ||
| 2878 | section in the Yocto Project Linux Kernel Development Manual. | ||
| 2879 | |||
| 2880 | Adding a Formfactor Configuration File | ||
| 2881 | -------------------------------------- | ||
| 2882 | |||
| 2883 | A formfactor configuration file provides information about the target | ||
| 2884 | hardware for which the image is being built and information that the | ||
| 2885 | build system cannot obtain from other sources such as the kernel. Some | ||
| 2886 | examples of information contained in a formfactor configuration file | ||
| 2887 | include framebuffer orientation, whether or not the system has a | ||
| 2888 | keyboard, the positioning of the keyboard in relation to the screen, and | ||
| 2889 | the screen resolution. | ||
| 2890 | |||
| 2891 | The build system uses reasonable defaults in most cases. However, if | ||
| 2892 | customization is necessary, you need to create a ``machconfig`` file in | ||
| 2893 | the ``meta/recipes-bsp/formfactor/files`` directory. This directory | ||
| 2894 | contains directories for specific machines such as ``qemuarm`` and | ||
| 2895 | ``qemux86``. For information about the settings available and the | ||
| 2896 | defaults, see the ``meta/recipes-bsp/formfactor/files/config`` file | ||
| 2897 | found in the same area. | ||
| 2898 | |||
| 2899 | Following is an example for "qemuarm" machine: | ||
| 2900 | :: | ||
| 2901 | |||
| 2902 | HAVE_TOUCHSCREEN=1 | ||
| 2903 | HAVE_KEYBOARD=1 | ||
| 2904 | DISPLAY_CAN_ROTATE=0 | ||
| 2905 | DISPLAY_ORIENTATION=0 | ||
| 2906 | #DISPLAY_WIDTH_PIXELS=640 | ||
| 2907 | #DISPLAY_HEIGHT_PIXELS=480 | ||
| 2908 | #DISPLAY_BPP=16 | ||
| 2909 | DISPLAY_DPI=150 | ||
| 2910 | DISPLAY_SUBPIXEL_ORDER=vrgb | ||
| 2911 | |||
| 2912 | Upgrading Recipes | ||
| 2913 | ================= | ||
| 2914 | |||
| 2915 | Over time, upstream developers publish new versions for software built | ||
| 2916 | by layer recipes. It is recommended to keep recipes up-to-date with | ||
| 2917 | upstream version releases. | ||
| 2918 | |||
| 2919 | While several methods exist that allow you upgrade a recipe, you might | ||
| 2920 | consider checking on the upgrade status of a recipe first. You can do so | ||
| 2921 | using the ``devtool check-upgrade-status`` command. See the | ||
| 2922 | ":ref:`devtool-checking-on-the-upgrade-status-of-a-recipe`" | ||
| 2923 | section in the Yocto Project Reference Manual for more information. | ||
| 2924 | |||
| 2925 | The remainder of this section describes three ways you can upgrade a | ||
| 2926 | recipe. You can use the Automated Upgrade Helper (AUH) to set up | ||
| 2927 | automatic version upgrades. Alternatively, you can use | ||
| 2928 | ``devtool upgrade`` to set up semi-automatic version upgrades. Finally, | ||
| 2929 | you can manually upgrade a recipe by editing the recipe itself. | ||
| 2930 | |||
| 2931 | Using the Auto Upgrade Helper (AUH) | ||
| 2932 | ----------------------------------- | ||
| 2933 | |||
| 2934 | The AUH utility works in conjunction with the OpenEmbedded build system | ||
| 2935 | in order to automatically generate upgrades for recipes based on new | ||
| 2936 | versions being published upstream. Use AUH when you want to create a | ||
| 2937 | service that performs the upgrades automatically and optionally sends | ||
| 2938 | you an email with the results. | ||
| 2939 | |||
| 2940 | AUH allows you to update several recipes with a single use. You can also | ||
| 2941 | optionally perform build and integration tests using images with the | ||
| 2942 | results saved to your hard drive and emails of results optionally sent | ||
| 2943 | to recipe maintainers. Finally, AUH creates Git commits with appropriate | ||
| 2944 | commit messages in the layer's tree for the changes made to recipes. | ||
| 2945 | |||
| 2946 | .. note:: | ||
| 2947 | |||
| 2948 | Conditions do exist when you should not use AUH to upgrade recipes | ||
| 2949 | and you should instead use either ``devtool upgrade`` or upgrade your | ||
| 2950 | recipes manually: | ||
| 2951 | |||
| 2952 | - When AUH cannot complete the upgrade sequence. This situation | ||
| 2953 | usually results because custom patches carried by the recipe | ||
| 2954 | cannot be automatically rebased to the new version. In this case, | ||
| 2955 | ``devtool upgrade`` allows you to manually resolve conflicts. | ||
| 2956 | |||
| 2957 | - When for any reason you want fuller control over the upgrade | ||
| 2958 | process. For example, when you want special arrangements for | ||
| 2959 | testing. | ||
| 2960 | |||
| 2961 | The following steps describe how to set up the AUH utility: | ||
| 2962 | |||
| 2963 | 1. *Be Sure the Development Host is Set Up:* You need to be sure that | ||
| 2964 | your development host is set up to use the Yocto Project. For | ||
| 2965 | information on how to set up your host, see the | ||
| 2966 | ":ref:`dev-manual/start:Preparing the Build Host`" section. | ||
| 2967 | |||
| 2968 | 2. *Make Sure Git is Configured:* The AUH utility requires Git to be | ||
| 2969 | configured because AUH uses Git to save upgrades. Thus, you must have | ||
| 2970 | Git user and email configured. The following command shows your | ||
| 2971 | configurations: | ||
| 2972 | :: | ||
| 2973 | |||
| 2974 | $ git config --list | ||
| 2975 | |||
| 2976 | If you do not have the user and | ||
| 2977 | email configured, you can use the following commands to do so: | ||
| 2978 | :: | ||
| 2979 | |||
| 2980 | $ git config --global user.name some_name | ||
| 2981 | $ git config --global user.email username@domain.com | ||
| 2982 | |||
| 2983 | 3. *Clone the AUH Repository:* To use AUH, you must clone the repository | ||
| 2984 | onto your development host. The following command uses Git to create | ||
| 2985 | a local copy of the repository on your system: | ||
| 2986 | :: | ||
| 2987 | |||
| 2988 | $ git clone git://git.yoctoproject.org/auto-upgrade-helper | ||
| 2989 | Cloning into 'auto-upgrade-helper'... remote: Counting objects: 768, done. | ||
| 2990 | remote: Compressing objects: 100% (300/300), done. | ||
| 2991 | remote: Total 768 (delta 499), reused 703 (delta 434) | ||
| 2992 | Receiving objects: 100% (768/768), 191.47 KiB | 98.00 KiB/s, done. | ||
| 2993 | Resolving deltas: 100% (499/499), done. | ||
| 2994 | Checking connectivity... done. | ||
| 2995 | |||
| 2996 | AUH is not part of the :term:`OpenEmbedded-Core (OE-Core)` or | ||
| 2997 | :term:`Poky` repositories. | ||
| 2998 | |||
| 2999 | 4. *Create a Dedicated Build Directory:* Run the | ||
| 3000 | :ref:`structure-core-script` | ||
| 3001 | script to create a fresh build directory that you use exclusively for | ||
| 3002 | running the AUH utility: | ||
| 3003 | :: | ||
| 3004 | |||
| 3005 | $ cd ~/poky | ||
| 3006 | $ source oe-init-build-env your_AUH_build_directory | ||
| 3007 | |||
| 3008 | Re-using an existing build directory and its configurations is not | ||
| 3009 | recommended as existing settings could cause AUH to fail or behave | ||
| 3010 | undesirably. | ||
| 3011 | |||
| 3012 | 5. *Make Configurations in Your Local Configuration File:* Several | ||
| 3013 | settings need to exist in the ``local.conf`` file in the build | ||
| 3014 | directory you just created for AUH. Make these following | ||
| 3015 | configurations: | ||
| 3016 | |||
| 3017 | - If you want to enable :ref:`Build | ||
| 3018 | History <dev-manual/common-tasks:maintaining build output quality>`, | ||
| 3019 | which is optional, you need the following lines in the | ||
| 3020 | ``conf/local.conf`` file: | ||
| 3021 | :: | ||
| 3022 | |||
| 3023 | INHERIT =+ "buildhistory" | ||
| 3024 | BUILDHISTORY_COMMIT = "1" | ||
| 3025 | |||
| 3026 | With this configuration and a successful | ||
| 3027 | upgrade, a build history "diff" file appears in the | ||
| 3028 | ``upgrade-helper/work/recipe/buildhistory-diff.txt`` file found in | ||
| 3029 | your build directory. | ||
| 3030 | |||
| 3031 | - If you want to enable testing through the | ||
| 3032 | :ref:`testimage <ref-classes-testimage*>` | ||
| 3033 | class, which is optional, you need to have the following set in | ||
| 3034 | your ``conf/local.conf`` file: | ||
| 3035 | :: | ||
| 3036 | |||
| 3037 | INHERIT += "testimage" | ||
| 3038 | |||
| 3039 | .. note:: | ||
| 3040 | |||
| 3041 | If your distro does not enable by default ptest, which Poky | ||
| 3042 | does, you need the following in your ``local.conf`` file: | ||
| 3043 | :: | ||
| 3044 | |||
| 3045 | DISTRO_FEATURES_append = " ptest" | ||
| 3046 | |||
| 3047 | |||
| 3048 | 6. *Optionally Start a vncserver:* If you are running in a server | ||
| 3049 | without an X11 session, you need to start a vncserver: | ||
| 3050 | :: | ||
| 3051 | |||
| 3052 | $ vncserver :1 | ||
| 3053 | $ export DISPLAY=:1 | ||
| 3054 | |||
| 3055 | 7. *Create and Edit an AUH Configuration File:* You need to have the | ||
| 3056 | ``upgrade-helper/upgrade-helper.conf`` configuration file in your | ||
| 3057 | build directory. You can find a sample configuration file in the | ||
| 3058 | :yocto_git:`AUH source repository </auto-upgrade-helper/tree/>`. | ||
| 3059 | |||
| 3060 | Read through the sample file and make configurations as needed. For | ||
| 3061 | example, if you enabled build history in your ``local.conf`` as | ||
| 3062 | described earlier, you must enable it in ``upgrade-helper.conf``. | ||
| 3063 | |||
| 3064 | Also, if you are using the default ``maintainers.inc`` file supplied | ||
| 3065 | with Poky and located in ``meta-yocto`` and you do not set a | ||
| 3066 | "maintainers_whitelist" or "global_maintainer_override" in the | ||
| 3067 | ``upgrade-helper.conf`` configuration, and you specify "-e all" on | ||
| 3068 | the AUH command-line, the utility automatically sends out emails to | ||
| 3069 | all the default maintainers. Please avoid this. | ||
| 3070 | |||
| 3071 | This next set of examples describes how to use the AUH: | ||
| 3072 | |||
| 3073 | - *Upgrading a Specific Recipe:* To upgrade a specific recipe, use the | ||
| 3074 | following form: | ||
| 3075 | :: | ||
| 3076 | |||
| 3077 | $ upgrade-helper.py recipe_name | ||
| 3078 | |||
| 3079 | For example, this command upgrades the ``xmodmap`` recipe: | ||
| 3080 | :: | ||
| 3081 | |||
| 3082 | $ upgrade-helper.py xmodmap | ||
| 3083 | |||
| 3084 | - *Upgrading a Specific Recipe to a Particular Version:* To upgrade a | ||
| 3085 | specific recipe to a particular version, use the following form: | ||
| 3086 | :: | ||
| 3087 | |||
| 3088 | $ upgrade-helper.py recipe_name -t version | ||
| 3089 | |||
| 3090 | For example, this command upgrades the ``xmodmap`` recipe to version 1.2.3: | ||
| 3091 | :: | ||
| 3092 | |||
| 3093 | $ upgrade-helper.py xmodmap -t 1.2.3 | ||
| 3094 | |||
| 3095 | - *Upgrading all Recipes to the Latest Versions and Suppressing Email | ||
| 3096 | Notifications:* To upgrade all recipes to their most recent versions | ||
| 3097 | and suppress the email notifications, use the following command: | ||
| 3098 | :: | ||
| 3099 | |||
| 3100 | $ upgrade-helper.py all | ||
| 3101 | |||
| 3102 | - *Upgrading all Recipes to the Latest Versions and Send Email | ||
| 3103 | Notifications:* To upgrade all recipes to their most recent versions | ||
| 3104 | and send email messages to maintainers for each attempted recipe as | ||
| 3105 | well as a status email, use the following command: | ||
| 3106 | :: | ||
| 3107 | |||
| 3108 | $ upgrade-helper.py -e all | ||
| 3109 | |||
| 3110 | Once you have run the AUH utility, you can find the results in the AUH | ||
| 3111 | build directory: | ||
| 3112 | :: | ||
| 3113 | |||
| 3114 | ${BUILDDIR}/upgrade-helper/timestamp | ||
| 3115 | |||
| 3116 | The AUH utility | ||
| 3117 | also creates recipe update commits from successful upgrade attempts in | ||
| 3118 | the layer tree. | ||
| 3119 | |||
| 3120 | You can easily set up to run the AUH utility on a regular basis by using | ||
| 3121 | a cron job. See the | ||
| 3122 | :yocto_git:`weeklyjob.sh </auto-upgrade-helper/tree/weeklyjob.sh>` | ||
| 3123 | file distributed with the utility for an example. | ||
| 3124 | |||
| 3125 | Using ``devtool upgrade`` | ||
| 3126 | ------------------------- | ||
| 3127 | |||
| 3128 | As mentioned earlier, an alternative method for upgrading recipes to | ||
| 3129 | newer versions is to use | ||
| 3130 | :doc:`devtool upgrade </ref-manual/ref-devtool-reference>`. | ||
| 3131 | You can read about ``devtool upgrade`` in general in the | ||
| 3132 | ":ref:`sdk-manual/sdk-extensible:use \`\`devtool upgrade\`\` to create a version of the recipe that supports a newer version of the software`" | ||
| 3133 | section in the Yocto Project Application Development and the Extensible | ||
| 3134 | Software Development Kit (eSDK) Manual. | ||
| 3135 | |||
| 3136 | To see all the command-line options available with ``devtool upgrade``, | ||
| 3137 | use the following help command: | ||
| 3138 | :: | ||
| 3139 | |||
| 3140 | $ devtool upgrade -h | ||
| 3141 | |||
| 3142 | If you want to find out what version a recipe is currently at upstream | ||
| 3143 | without any attempt to upgrade your local version of the recipe, you can | ||
| 3144 | use the following command: | ||
| 3145 | :: | ||
| 3146 | |||
| 3147 | $ devtool latest-version recipe_name | ||
| 3148 | |||
| 3149 | As mentioned in the previous section describing AUH, ``devtool upgrade`` | ||
| 3150 | works in a less-automated manner than AUH. Specifically, | ||
| 3151 | ``devtool upgrade`` only works on a single recipe that you name on the | ||
| 3152 | command line, cannot perform build and integration testing using images, | ||
| 3153 | and does not automatically generate commits for changes in the source | ||
| 3154 | tree. Despite all these "limitations", ``devtool upgrade`` updates the | ||
| 3155 | recipe file to the new upstream version and attempts to rebase custom | ||
| 3156 | patches contained by the recipe as needed. | ||
| 3157 | |||
| 3158 | .. note:: | ||
| 3159 | |||
| 3160 | AUH uses much of ``devtool upgrade`` behind the scenes making AUH somewhat | ||
| 3161 | of a "wrapper" application for ``devtool upgrade``. | ||
| 3162 | |||
| 3163 | A typical scenario involves having used Git to clone an upstream | ||
| 3164 | repository that you use during build operations. Because you have built the | ||
| 3165 | recipe in the past, the layer is likely added to your | ||
| 3166 | configuration already. If for some reason, the layer is not added, you | ||
| 3167 | could add it easily using the | ||
| 3168 | ":ref:`bitbake-layers <bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script>`" | ||
| 3169 | script. For example, suppose you use the ``nano.bb`` recipe from the | ||
| 3170 | ``meta-oe`` layer in the ``meta-openembedded`` repository. For this | ||
| 3171 | example, assume that the layer has been cloned into following area: | ||
| 3172 | :: | ||
| 3173 | |||
| 3174 | /home/scottrif/meta-openembedded | ||
| 3175 | |||
| 3176 | The following command from your | ||
| 3177 | :term:`Build Directory` adds the layer to | ||
| 3178 | your build configuration (i.e. ``${BUILDDIR}/conf/bblayers.conf``): | ||
| 3179 | :: | ||
| 3180 | |||
| 3181 | $ bitbake-layers add-layer /home/scottrif/meta-openembedded/meta-oe | ||
| 3182 | NOTE: Starting bitbake server... | ||
| 3183 | Parsing recipes: 100% |##########################################| Time: 0:00:55 | ||
| 3184 | Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors. | ||
| 3185 | Removing 12 recipes from the x86_64 sysroot: 100% |##############| Time: 0:00:00 | ||
| 3186 | Removing 1 recipes from the x86_64_i586 sysroot: 100% |##########| Time: 0:00:00 | ||
| 3187 | Removing 5 recipes from the i586 sysroot: 100% |#################| Time: 0:00:00 | ||
| 3188 | Removing 5 recipes from the qemux86 sysroot: 100% |##############| Time: 0:00:00 | ||
| 3189 | |||
| 3190 | For this example, assume that the ``nano.bb`` recipe that | ||
| 3191 | is upstream has a 2.9.3 version number. However, the version in the | ||
| 3192 | local repository is 2.7.4. The following command from your build | ||
| 3193 | directory automatically upgrades the recipe for you: | ||
| 3194 | |||
| 3195 | .. note:: | ||
| 3196 | |||
| 3197 | Using the ``-V`` option is not necessary. Omitting the version number causes | ||
| 3198 | ``devtool upgrade`` to upgrade the recipe to the most recent version. | ||
| 3199 | |||
| 3200 | :: | ||
| 3201 | |||
| 3202 | $ devtool upgrade nano -V 2.9.3 | ||
| 3203 | NOTE: Starting bitbake server... | ||
| 3204 | NOTE: Creating workspace layer in /home/scottrif/poky/build/workspace | ||
| 3205 | Parsing recipes: 100% |##########################################| Time: 0:00:46 | ||
| 3206 | Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors. | ||
| 3207 | NOTE: Extracting current version source... | ||
| 3208 | NOTE: Resolving any missing task queue dependencies | ||
| 3209 | . | ||
| 3210 | . | ||
| 3211 | . | ||
| 3212 | NOTE: Executing SetScene Tasks | ||
| 3213 | NOTE: Executing RunQueue Tasks | ||
| 3214 | NOTE: Tasks Summary: Attempted 74 tasks of which 72 didn't need to be rerun and all succeeded. | ||
| 3215 | Adding changed files: 100% |#####################################| Time: 0:00:00 | ||
| 3216 | NOTE: Upgraded source extracted to /home/scottrif/poky/build/workspace/sources/nano | ||
| 3217 | NOTE: New recipe is /home/scottrif/poky/build/workspace/recipes/nano/nano_2.9.3.bb | ||
| 3218 | |||
| 3219 | Continuing with this example, you can use ``devtool build`` to build the | ||
| 3220 | newly upgraded recipe: | ||
| 3221 | :: | ||
| 3222 | |||
| 3223 | $ devtool build nano | ||
| 3224 | NOTE: Starting bitbake server... | ||
| 3225 | Loading cache: 100% |################################################################################################| Time: 0:00:01 | ||
| 3226 | Loaded 2040 entries from dependency cache. | ||
| 3227 | Parsing recipes: 100% |##############################################################################################| Time: 0:00:00 | ||
| 3228 | Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors. | ||
| 3229 | NOTE: Resolving any missing task queue dependencies | ||
| 3230 | . | ||
| 3231 | . | ||
| 3232 | . | ||
| 3233 | NOTE: Executing SetScene Tasks | ||
| 3234 | NOTE: Executing RunQueue Tasks | ||
| 3235 | NOTE: nano: compiling from external source tree /home/scottrif/poky/build/workspace/sources/nano | ||
| 3236 | NOTE: Tasks Summary: Attempted 520 tasks of which 304 didn't need to be rerun and all succeeded. | ||
| 3237 | |||
| 3238 | Within the ``devtool upgrade`` workflow, opportunity | ||
| 3239 | exists to deploy and test your rebuilt software. For this example, | ||
| 3240 | however, running ``devtool finish`` cleans up the workspace once the | ||
| 3241 | source in your workspace is clean. This usually means using Git to stage | ||
| 3242 | and submit commits for the changes generated by the upgrade process. | ||
| 3243 | |||
| 3244 | Once the tree is clean, you can clean things up in this example with the | ||
| 3245 | following command from the ``${BUILDDIR}/workspace/sources/nano`` | ||
| 3246 | directory: | ||
| 3247 | :: | ||
| 3248 | |||
| 3249 | $ devtool finish nano meta-oe | ||
| 3250 | NOTE: Starting bitbake server... | ||
| 3251 | Loading cache: 100% |################################################################################################| Time: 0:00:00 | ||
| 3252 | Loaded 2040 entries from dependency cache. | ||
| 3253 | Parsing recipes: 100% |##############################################################################################| Time: 0:00:01 | ||
| 3254 | Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors. | ||
| 3255 | NOTE: Adding new patch 0001-nano.bb-Stuff-I-changed-when-upgrading-nano.bb.patch | ||
| 3256 | NOTE: Updating recipe nano_2.9.3.bb | ||
| 3257 | NOTE: Removing file /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano/nano_2.7.4.bb | ||
| 3258 | NOTE: Moving recipe file to /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano | ||
| 3259 | NOTE: Leaving source tree /home/scottrif/poky/build/workspace/sources/nano as-is; if you no longer need it then please delete it manually | ||
| 3260 | |||
| 3261 | |||
| 3262 | Using the ``devtool finish`` command cleans up the workspace and creates a patch | ||
| 3263 | file based on your commits. The tool puts all patch files back into the | ||
| 3264 | source directory in a sub-directory named ``nano`` in this case. | ||
| 3265 | |||
| 3266 | Manually Upgrading a Recipe | ||
| 3267 | --------------------------- | ||
| 3268 | |||
| 3269 | If for some reason you choose not to upgrade recipes using | ||
| 3270 | :ref:`dev-manual/common-tasks:Using the Auto Upgrade Helper (AUH)` or | ||
| 3271 | by :ref:`dev-manual/common-tasks:Using \`\`devtool upgrade\`\``, | ||
| 3272 | you can manually edit the recipe files to upgrade the versions. | ||
| 3273 | |||
| 3274 | .. note:: | ||
| 3275 | |||
| 3276 | Manually updating multiple recipes scales poorly and involves many | ||
| 3277 | steps. The recommendation to upgrade recipe versions is through AUH | ||
| 3278 | or ``devtool upgrade``, both of which automate some steps and provide | ||
| 3279 | guidance for others needed for the manual process. | ||
| 3280 | |||
| 3281 | To manually upgrade recipe versions, follow these general steps: | ||
| 3282 | |||
| 3283 | 1. *Change the Version:* Rename the recipe such that the version (i.e. | ||
| 3284 | the :term:`PV` part of the recipe name) | ||
| 3285 | changes appropriately. If the version is not part of the recipe name, | ||
| 3286 | change the value as it is set for ``PV`` within the recipe itself. | ||
| 3287 | |||
| 3288 | 2. *Update* ``SRCREV`` *if Needed*: If the source code your recipe builds | ||
| 3289 | is fetched from Git or some other version control system, update | ||
| 3290 | :term:`SRCREV` to point to the | ||
| 3291 | commit hash that matches the new version. | ||
| 3292 | |||
| 3293 | 3. *Build the Software:* Try to build the recipe using BitBake. Typical | ||
| 3294 | build failures include the following: | ||
| 3295 | |||
| 3296 | - License statements were updated for the new version. For this | ||
| 3297 | case, you need to review any changes to the license and update the | ||
| 3298 | values of :term:`LICENSE` and | ||
| 3299 | :term:`LIC_FILES_CHKSUM` | ||
| 3300 | as needed. | ||
| 3301 | |||
| 3302 | .. note:: | ||
| 3303 | |||
| 3304 | License changes are often inconsequential. For example, the | ||
| 3305 | license text's copyright year might have changed. | ||
| 3306 | |||
| 3307 | - Custom patches carried by the older version of the recipe might | ||
| 3308 | fail to apply to the new version. For these cases, you need to | ||
| 3309 | review the failures. Patches might not be necessary for the new | ||
| 3310 | version of the software if the upgraded version has fixed those | ||
| 3311 | issues. If a patch is necessary and failing, you need to rebase it | ||
| 3312 | into the new version. | ||
| 3313 | |||
| 3314 | 4. *Optionally Attempt to Build for Several Architectures:* Once you | ||
| 3315 | successfully build the new software for a given architecture, you | ||
| 3316 | could test the build for other architectures by changing the | ||
| 3317 | :term:`MACHINE` variable and | ||
| 3318 | rebuilding the software. This optional step is especially important | ||
| 3319 | if the recipe is to be released publicly. | ||
| 3320 | |||
| 3321 | 5. *Check the Upstream Change Log or Release Notes:* Checking both these | ||
| 3322 | reveals if new features exist that could break | ||
| 3323 | backwards-compatibility. If so, you need to take steps to mitigate or | ||
| 3324 | eliminate that situation. | ||
| 3325 | |||
| 3326 | 6. *Optionally Create a Bootable Image and Test:* If you want, you can | ||
| 3327 | test the new software by booting it onto actual hardware. | ||
| 3328 | |||
| 3329 | 7. *Create a Commit with the Change in the Layer Repository:* After all | ||
| 3330 | builds work and any testing is successful, you can create commits for | ||
| 3331 | any changes in the layer holding your upgraded recipe. | ||
| 3332 | |||
| 3333 | Finding Temporary Source Code | ||
| 3334 | ============================= | ||
| 3335 | |||
| 3336 | You might find it helpful during development to modify the temporary | ||
| 3337 | source code used by recipes to build packages. For example, suppose you | ||
| 3338 | are developing a patch and you need to experiment a bit to figure out | ||
| 3339 | your solution. After you have initially built the package, you can | ||
| 3340 | iteratively tweak the source code, which is located in the | ||
| 3341 | :term:`Build Directory`, and then you can | ||
| 3342 | force a re-compile and quickly test your altered code. Once you settle | ||
| 3343 | on a solution, you can then preserve your changes in the form of | ||
| 3344 | patches. | ||
| 3345 | |||
| 3346 | During a build, the unpacked temporary source code used by recipes to | ||
| 3347 | build packages is available in the Build Directory as defined by the | ||
| 3348 | :term:`S` variable. Below is the default | ||
| 3349 | value for the ``S`` variable as defined in the | ||
| 3350 | ``meta/conf/bitbake.conf`` configuration file in the | ||
| 3351 | :term:`Source Directory`: | ||
| 3352 | :: | ||
| 3353 | |||
| 3354 | S = "${WORKDIR}/${BP}" | ||
| 3355 | |||
| 3356 | You should be aware that many recipes override the | ||
| 3357 | ``S`` variable. For example, recipes that fetch their source from Git | ||
| 3358 | usually set ``S`` to ``${WORKDIR}/git``. | ||
| 3359 | |||
| 3360 | .. note:: | ||
| 3361 | |||
| 3362 | The :term:`BP` represents the base recipe name, which consists of the name | ||
| 3363 | and version: | ||
| 3364 | :: | ||
| 3365 | |||
| 3366 | BP = "${BPN}-${PV}" | ||
| 3367 | |||
| 3368 | |||
| 3369 | The path to the work directory for the recipe | ||
| 3370 | (:term:`WORKDIR`) is defined as | ||
| 3371 | follows: | ||
| 3372 | :: | ||
| 3373 | |||
| 3374 | ${TMPDIR}/work/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR} | ||
| 3375 | |||
| 3376 | The actual directory depends on several things: | ||
| 3377 | |||
| 3378 | - :term:`TMPDIR`: The top-level build | ||
| 3379 | output directory. | ||
| 3380 | |||
| 3381 | - :term:`MULTIMACH_TARGET_SYS`: | ||
| 3382 | The target system identifier. | ||
| 3383 | |||
| 3384 | - :term:`PN`: The recipe name. | ||
| 3385 | |||
| 3386 | - :term:`EXTENDPE`: The epoch - (if | ||
| 3387 | :term:`PE` is not specified, which is | ||
| 3388 | usually the case for most recipes, then ``EXTENDPE`` is blank). | ||
| 3389 | |||
| 3390 | - :term:`PV`: The recipe version. | ||
| 3391 | |||
| 3392 | - :term:`PR`: The recipe revision. | ||
| 3393 | |||
| 3394 | As an example, assume a Source Directory top-level folder named | ||
| 3395 | ``poky``, a default Build Directory at ``poky/build``, and a | ||
| 3396 | ``qemux86-poky-linux`` machine target system. Furthermore, suppose your | ||
| 3397 | recipe is named ``foo_1.3.0.bb``. In this case, the work directory the | ||
| 3398 | build system uses to build the package would be as follows: | ||
| 3399 | :: | ||
| 3400 | |||
| 3401 | poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0 | ||
| 3402 | |||
| 3403 | Using Quilt in Your Workflow | ||
| 3404 | ============================ | ||
| 3405 | |||
| 3406 | `Quilt <https://savannah.nongnu.org/projects/quilt>`__ is a powerful tool | ||
| 3407 | that allows you to capture source code changes without having a clean | ||
| 3408 | source tree. This section outlines the typical workflow you can use to | ||
| 3409 | modify source code, test changes, and then preserve the changes in the | ||
| 3410 | form of a patch all using Quilt. | ||
| 3411 | |||
| 3412 | .. note:: | ||
| 3413 | |||
| 3414 | With regard to preserving changes to source files, if you clean a | ||
| 3415 | recipe or have ``rm_work`` enabled, the | ||
| 3416 | :ref:`devtool workflow <sdk-manual/sdk-extensible:using \`\`devtool\`\` in your sdk workflow>` | ||
| 3417 | as described in the Yocto Project Application Development and the | ||
| 3418 | Extensible Software Development Kit (eSDK) manual is a safer | ||
| 3419 | development flow than the flow that uses Quilt. | ||
| 3420 | |||
| 3421 | Follow these general steps: | ||
| 3422 | |||
| 3423 | 1. *Find the Source Code:* Temporary source code used by the | ||
| 3424 | OpenEmbedded build system is kept in the | ||
| 3425 | :term:`Build Directory`. See the | ||
| 3426 | "`Finding Temporary Source | ||
| 3427 | Code <#finding-the-temporary-source-code>`__" section to learn how to | ||
| 3428 | locate the directory that has the temporary source code for a | ||
| 3429 | particular package. | ||
| 3430 | |||
| 3431 | 2. *Change Your Working Directory:* You need to be in the directory that | ||
| 3432 | has the temporary source code. That directory is defined by the | ||
| 3433 | :term:`S` variable. | ||
| 3434 | |||
| 3435 | 3. *Create a New Patch:* Before modifying source code, you need to | ||
| 3436 | create a new patch. To create a new patch file, use ``quilt new`` as | ||
| 3437 | below: | ||
| 3438 | :: | ||
| 3439 | |||
| 3440 | $ quilt new my_changes.patch | ||
| 3441 | |||
| 3442 | 4. *Notify Quilt and Add Files:* After creating the patch, you need to | ||
| 3443 | notify Quilt about the files you plan to edit. You notify Quilt by | ||
| 3444 | adding the files to the patch you just created: | ||
| 3445 | :: | ||
| 3446 | |||
| 3447 | $ quilt add file1.c file2.c file3.c | ||
| 3448 | |||
| 3449 | 5. *Edit the Files:* Make your changes in the source code to the files | ||
| 3450 | you added to the patch. | ||
| 3451 | |||
| 3452 | 6. *Test Your Changes:* Once you have modified the source code, the | ||
| 3453 | easiest way to test your changes is by calling the ``do_compile`` | ||
| 3454 | task as shown in the following example: | ||
| 3455 | :: | ||
| 3456 | |||
| 3457 | $ bitbake -c compile -f package | ||
| 3458 | |||
| 3459 | The ``-f`` or ``--force`` option forces the specified task to | ||
| 3460 | execute. If you find problems with your code, you can just keep | ||
| 3461 | editing and re-testing iteratively until things work as expected. | ||
| 3462 | |||
| 3463 | .. note:: | ||
| 3464 | |||
| 3465 | All the modifications you make to the temporary source code disappear | ||
| 3466 | once you run the ``do_clean`` or ``do_cleanall`` tasks using BitBake | ||
| 3467 | (i.e. ``bitbake -c clean package`` and ``bitbake -c cleanall package``). | ||
| 3468 | Modifications will also disappear if you use the ``rm_work`` feature as | ||
| 3469 | described in the | ||
| 3470 | ":ref:`dev-manual/common-tasks:conserving disk space during builds`" | ||
| 3471 | section. | ||
| 3472 | |||
| 3473 | 7. *Generate the Patch:* Once your changes work as expected, you need to | ||
| 3474 | use Quilt to generate the final patch that contains all your | ||
| 3475 | modifications. | ||
| 3476 | :: | ||
| 3477 | |||
| 3478 | $ quilt refresh | ||
| 3479 | |||
| 3480 | At this point, the | ||
| 3481 | ``my_changes.patch`` file has all your edits made to the ``file1.c``, | ||
| 3482 | ``file2.c``, and ``file3.c`` files. | ||
| 3483 | |||
| 3484 | You can find the resulting patch file in the ``patches/`` | ||
| 3485 | subdirectory of the source (``S``) directory. | ||
| 3486 | |||
| 3487 | 8. *Copy the Patch File:* For simplicity, copy the patch file into a | ||
| 3488 | directory named ``files``, which you can create in the same directory | ||
| 3489 | that holds the recipe (``.bb``) file or the append (``.bbappend``) | ||
| 3490 | file. Placing the patch here guarantees that the OpenEmbedded build | ||
| 3491 | system will find the patch. Next, add the patch into the ``SRC_URI`` | ||
| 3492 | of the recipe. Here is an example: | ||
| 3493 | :: | ||
| 3494 | |||
| 3495 | SRC_URI += "file://my_changes.patch" | ||
| 3496 | |||
| 3497 | Using a Development Shell | ||
| 3498 | ========================= | ||
| 3499 | |||
| 3500 | When debugging certain commands or even when just editing packages, | ||
| 3501 | ``devshell`` can be a useful tool. When you invoke ``devshell``, all | ||
| 3502 | tasks up to and including | ||
| 3503 | :ref:`ref-tasks-patch` are run for the | ||
| 3504 | specified target. Then, a new terminal is opened and you are placed in | ||
| 3505 | ``${``\ :term:`S`\ ``}``, the source | ||
| 3506 | directory. In the new terminal, all the OpenEmbedded build-related | ||
| 3507 | environment variables are still defined so you can use commands such as | ||
| 3508 | ``configure`` and ``make``. The commands execute just as if the | ||
| 3509 | OpenEmbedded build system were executing them. Consequently, working | ||
| 3510 | this way can be helpful when debugging a build or preparing software to | ||
| 3511 | be used with the OpenEmbedded build system. | ||
| 3512 | |||
| 3513 | Following is an example that uses ``devshell`` on a target named | ||
| 3514 | ``matchbox-desktop``: | ||
| 3515 | :: | ||
| 3516 | |||
| 3517 | $ bitbake matchbox-desktop -c devshell | ||
| 3518 | |||
| 3519 | This command spawns a terminal with a shell prompt within the | ||
| 3520 | OpenEmbedded build environment. The | ||
| 3521 | :term:`OE_TERMINAL` variable | ||
| 3522 | controls what type of shell is opened. | ||
| 3523 | |||
| 3524 | For spawned terminals, the following occurs: | ||
| 3525 | |||
| 3526 | - The ``PATH`` variable includes the cross-toolchain. | ||
| 3527 | |||
| 3528 | - The ``pkgconfig`` variables find the correct ``.pc`` files. | ||
| 3529 | |||
| 3530 | - The ``configure`` command finds the Yocto Project site files as well | ||
| 3531 | as any other necessary files. | ||
| 3532 | |||
| 3533 | Within this environment, you can run configure or compile commands as if | ||
| 3534 | they were being run by the OpenEmbedded build system itself. As noted | ||
| 3535 | earlier, the working directory also automatically changes to the Source | ||
| 3536 | Directory (:term:`S`). | ||
| 3537 | |||
| 3538 | To manually run a specific task using ``devshell``, run the | ||
| 3539 | corresponding ``run.*`` script in the | ||
| 3540 | ``${``\ :term:`WORKDIR`\ ``}/temp`` | ||
| 3541 | directory (e.g., ``run.do_configure.``\ `pid`). If a task's script does | ||
| 3542 | not exist, which would be the case if the task was skipped by way of the | ||
| 3543 | sstate cache, you can create the task by first running it outside of the | ||
| 3544 | ``devshell``: | ||
| 3545 | :: | ||
| 3546 | |||
| 3547 | $ bitbake -c task | ||
| 3548 | |||
| 3549 | .. note:: | ||
| 3550 | |||
| 3551 | - Execution of a task's ``run.*`` script and BitBake's execution of | ||
| 3552 | a task are identical. In other words, running the script re-runs | ||
| 3553 | the task just as it would be run using the ``bitbake -c`` command. | ||
| 3554 | |||
| 3555 | - Any ``run.*`` file that does not have a ``.pid`` extension is a | ||
| 3556 | symbolic link (symlink) to the most recent version of that file. | ||
| 3557 | |||
| 3558 | Remember, that the ``devshell`` is a mechanism that allows you to get | ||
| 3559 | into the BitBake task execution environment. And as such, all commands | ||
| 3560 | must be called just as BitBake would call them. That means you need to | ||
| 3561 | provide the appropriate options for cross-compilation and so forth as | ||
| 3562 | applicable. | ||
| 3563 | |||
| 3564 | When you are finished using ``devshell``, exit the shell or close the | ||
| 3565 | terminal window. | ||
| 3566 | |||
| 3567 | .. note:: | ||
| 3568 | |||
| 3569 | - It is worth remembering that when using ``devshell`` you need to | ||
| 3570 | use the full compiler name such as ``arm-poky-linux-gnueabi-gcc`` | ||
| 3571 | instead of just using ``gcc``. The same applies to other | ||
| 3572 | applications such as ``binutils``, ``libtool`` and so forth. | ||
| 3573 | BitBake sets up environment variables such as ``CC`` to assist | ||
| 3574 | applications, such as ``make`` to find the correct tools. | ||
| 3575 | |||
| 3576 | - It is also worth noting that ``devshell`` still works over X11 | ||
| 3577 | forwarding and similar situations. | ||
| 3578 | |||
| 3579 | Using a Development Python Shell | ||
| 3580 | ================================ | ||
| 3581 | |||
| 3582 | Similar to working within a development shell as described in the | ||
| 3583 | previous section, you can also spawn and work within an interactive | ||
| 3584 | Python development shell. When debugging certain commands or even when | ||
| 3585 | just editing packages, ``devpyshell`` can be a useful tool. When you | ||
| 3586 | invoke ``devpyshell``, all tasks up to and including | ||
| 3587 | :ref:`ref-tasks-patch` are run for the | ||
| 3588 | specified target. Then a new terminal is opened. Additionally, key | ||
| 3589 | Python objects and code are available in the same way they are to | ||
| 3590 | BitBake tasks, in particular, the data store 'd'. So, commands such as | ||
| 3591 | the following are useful when exploring the data store and running | ||
| 3592 | functions: | ||
| 3593 | :: | ||
| 3594 | |||
| 3595 | pydevshell> d.getVar("STAGING_DIR") | ||
| 3596 | '/media/build1/poky/build/tmp/sysroots' | ||
| 3597 | pydevshell> d.getVar("STAGING_DIR") | ||
| 3598 | '${TMPDIR}/sysroots' | ||
| 3599 | pydevshell> d.setVar("FOO", "bar") | ||
| 3600 | pydevshell> d.getVar("FOO") | ||
| 3601 | 'bar' | ||
| 3602 | pydevshell> d.delVar("FOO") | ||
| 3603 | pydevshell> d.getVar("FOO") | ||
| 3604 | pydevshell> bb.build.exec_func("do_unpack", d) | ||
| 3605 | pydevshell> | ||
| 3606 | |||
| 3607 | The commands execute just as if the OpenEmbedded build | ||
| 3608 | system were executing them. Consequently, working this way can be | ||
| 3609 | helpful when debugging a build or preparing software to be used with the | ||
| 3610 | OpenEmbedded build system. | ||
| 3611 | |||
| 3612 | Following is an example that uses ``devpyshell`` on a target named | ||
| 3613 | ``matchbox-desktop``: | ||
| 3614 | :: | ||
| 3615 | |||
| 3616 | $ bitbake matchbox-desktop -c devpyshell | ||
| 3617 | |||
| 3618 | This command spawns a terminal and places you in an interactive Python | ||
| 3619 | interpreter within the OpenEmbedded build environment. The | ||
| 3620 | :term:`OE_TERMINAL` variable | ||
| 3621 | controls what type of shell is opened. | ||
| 3622 | |||
| 3623 | When you are finished using ``devpyshell``, you can exit the shell | ||
| 3624 | either by using Ctrl+d or closing the terminal window. | ||
| 3625 | |||
| 3626 | Building | ||
| 3627 | ======== | ||
| 3628 | |||
| 3629 | This section describes various build procedures. For example, the steps | ||
| 3630 | needed for a simple build, a target that uses multiple configurations, | ||
| 3631 | building an image for more than one machine, and so forth. | ||
| 3632 | |||
| 3633 | Building a Simple Image | ||
| 3634 | ----------------------- | ||
| 3635 | |||
| 3636 | In the development environment, you need to build an image whenever you | ||
| 3637 | change hardware support, add or change system libraries, or add or | ||
| 3638 | change services that have dependencies. Several methods exist that allow | ||
| 3639 | you to build an image within the Yocto Project. This section presents | ||
| 3640 | the basic steps you need to build a simple image using BitBake from a | ||
| 3641 | build host running Linux. | ||
| 3642 | |||
| 3643 | .. note:: | ||
| 3644 | |||
| 3645 | - For information on how to build an image using | ||
| 3646 | :term:`Toaster`, see the | ||
| 3647 | :doc:`/toaster-manual/index`. | ||
| 3648 | |||
| 3649 | - For information on how to use ``devtool`` to build images, see the | ||
| 3650 | ":ref:`sdk-manual/sdk-extensible:using \`\`devtool\`\` in your sdk workflow`" | ||
| 3651 | section in the Yocto Project Application Development and the | ||
| 3652 | Extensible Software Development Kit (eSDK) manual. | ||
| 3653 | |||
| 3654 | - For a quick example on how to build an image using the | ||
| 3655 | OpenEmbedded build system, see the | ||
| 3656 | :doc:`/brief-yoctoprojectqs/index` document. | ||
| 3657 | |||
| 3658 | The build process creates an entire Linux distribution from source and | ||
| 3659 | places it in your :term:`Build Directory` under | ||
| 3660 | ``tmp/deploy/images``. For detailed information on the build process | ||
| 3661 | using BitBake, see the ":ref:`overview-manual/overview-manual-concepts:images`" section in the | ||
| 3662 | Yocto Project Overview and Concepts Manual. | ||
| 3663 | |||
| 3664 | The following figure and list overviews the build process: | ||
| 3665 | |||
| 3666 | .. image:: figures/bitbake-build-flow.png | ||
| 3667 | :align: center | ||
| 3668 | |||
| 3669 | 1. *Set up Your Host Development System to Support Development Using the | ||
| 3670 | Yocto Project*: See the ":doc:`start`" section for options on how to get a | ||
| 3671 | build host ready to use the Yocto Project. | ||
| 3672 | |||
| 3673 | 2. *Initialize the Build Environment:* Initialize the build environment | ||
| 3674 | by sourcing the build environment script (i.e. | ||
| 3675 | :ref:`structure-core-script`): | ||
| 3676 | :: | ||
| 3677 | |||
| 3678 | $ source oe-init-build-env [build_dir] | ||
| 3679 | |||
| 3680 | When you use the initialization script, the OpenEmbedded build system | ||
| 3681 | uses ``build`` as the default :term:`Build Directory` in your current work | ||
| 3682 | directory. You can use a `build_dir` argument with the script to | ||
| 3683 | specify a different build directory. | ||
| 3684 | |||
| 3685 | .. note:: | ||
| 3686 | |||
| 3687 | A common practice is to use a different Build Directory for | ||
| 3688 | different targets. For example, ``~/build/x86`` for a ``qemux86`` | ||
| 3689 | target, and ``~/build/arm`` for a ``qemuarm`` target. | ||
| 3690 | |||
| 3691 | 3. *Make Sure Your* ``local.conf`` *File is Correct*: Ensure the | ||
| 3692 | ``conf/local.conf`` configuration file, which is found in the Build | ||
| 3693 | Directory, is set up how you want it. This file defines many aspects | ||
| 3694 | of the build environment including the target machine architecture | ||
| 3695 | through the ``MACHINE`` variable, the packaging format used during | ||
| 3696 | the build | ||
| 3697 | (:term:`PACKAGE_CLASSES`), | ||
| 3698 | and a centralized tarball download directory through the | ||
| 3699 | :term:`DL_DIR` variable. | ||
| 3700 | |||
| 3701 | 4. *Build the Image:* Build the image using the ``bitbake`` command: | ||
| 3702 | :: | ||
| 3703 | |||
| 3704 | $ bitbake target | ||
| 3705 | |||
| 3706 | .. note:: | ||
| 3707 | |||
| 3708 | For information on BitBake, see the :doc:`bitbake:index`. | ||
| 3709 | |||
| 3710 | The target is the name of the recipe you want to build. Common | ||
| 3711 | targets are the images in ``meta/recipes-core/images``, | ||
| 3712 | ``meta/recipes-sato/images``, and so forth all found in the | ||
| 3713 | :term:`Source Directory`. Or, the target | ||
| 3714 | can be the name of a recipe for a specific piece of software such as | ||
| 3715 | BusyBox. For more details about the images the OpenEmbedded build | ||
| 3716 | system supports, see the | ||
| 3717 | ":ref:`ref-manual/ref-images:Images`" chapter in the Yocto | ||
| 3718 | Project Reference Manual. | ||
| 3719 | |||
| 3720 | As an example, the following command builds the | ||
| 3721 | ``core-image-minimal`` image: | ||
| 3722 | :: | ||
| 3723 | |||
| 3724 | $ bitbake core-image-minimal | ||
| 3725 | |||
| 3726 | Once an | ||
| 3727 | image has been built, it often needs to be installed. The images and | ||
| 3728 | kernels built by the OpenEmbedded build system are placed in the | ||
| 3729 | Build Directory in ``tmp/deploy/images``. For information on how to | ||
| 3730 | run pre-built images such as ``qemux86`` and ``qemuarm``, see the | ||
| 3731 | :doc:`/sdk-manual/index` manual. For | ||
| 3732 | information about how to install these images, see the documentation | ||
| 3733 | for your particular board or machine. | ||
| 3734 | |||
| 3735 | Building Images for Multiple Targets Using Multiple Configurations | ||
| 3736 | ------------------------------------------------------------------ | ||
| 3737 | |||
| 3738 | You can use a single ``bitbake`` command to build multiple images or | ||
| 3739 | packages for different targets where each image or package requires a | ||
| 3740 | different configuration (multiple configuration builds). The builds, in | ||
| 3741 | this scenario, are sometimes referred to as "multiconfigs", and this | ||
| 3742 | section uses that term throughout. | ||
| 3743 | |||
| 3744 | This section describes how to set up for multiple configuration builds | ||
| 3745 | and how to account for cross-build dependencies between the | ||
| 3746 | multiconfigs. | ||
| 3747 | |||
| 3748 | Setting Up and Running a Multiple Configuration Build | ||
| 3749 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 3750 | |||
| 3751 | To accomplish a multiple configuration build, you must define each | ||
| 3752 | target's configuration separately using a parallel configuration file in | ||
| 3753 | the :term:`Build Directory`, and you | ||
| 3754 | must follow a required file hierarchy. Additionally, you must enable the | ||
| 3755 | multiple configuration builds in your ``local.conf`` file. | ||
| 3756 | |||
| 3757 | Follow these steps to set up and execute multiple configuration builds: | ||
| 3758 | |||
| 3759 | - *Create Separate Configuration Files*: You need to create a single | ||
| 3760 | configuration file for each build target (each multiconfig). | ||
| 3761 | Minimally, each configuration file must define the machine and the | ||
| 3762 | temporary directory BitBake uses for the build. Suggested practice | ||
| 3763 | dictates that you do not overlap the temporary directories used | ||
| 3764 | during the builds. However, it is possible that you can share the | ||
| 3765 | temporary directory | ||
| 3766 | (:term:`TMPDIR`). For example, | ||
| 3767 | consider a scenario with two different multiconfigs for the same | ||
| 3768 | :term:`MACHINE`: "qemux86" built | ||
| 3769 | for two distributions such as "poky" and "poky-lsb". In this case, | ||
| 3770 | you might want to use the same ``TMPDIR``. | ||
| 3771 | |||
| 3772 | Here is an example showing the minimal statements needed in a | ||
| 3773 | configuration file for a "qemux86" target whose temporary build | ||
| 3774 | directory is ``tmpmultix86``: | ||
| 3775 | :: | ||
| 3776 | |||
| 3777 | MACHINE = "qemux86" | ||
| 3778 | TMPDIR = "${TOPDIR}/tmpmultix86" | ||
| 3779 | |||
| 3780 | The location for these multiconfig configuration files is specific. | ||
| 3781 | They must reside in the current build directory in a sub-directory of | ||
| 3782 | ``conf`` named ``multiconfig``. Following is an example that defines | ||
| 3783 | two configuration files for the "x86" and "arm" multiconfigs: | ||
| 3784 | |||
| 3785 | .. image:: figures/multiconfig_files.png | ||
| 3786 | :align: center | ||
| 3787 | |||
| 3788 | The reason for this required file hierarchy is because the ``BBPATH`` | ||
| 3789 | variable is not constructed until the layers are parsed. | ||
| 3790 | Consequently, using the configuration file as a pre-configuration | ||
| 3791 | file is not possible unless it is located in the current working | ||
| 3792 | directory. | ||
| 3793 | |||
| 3794 | - *Add the BitBake Multi-configuration Variable to the Local | ||
| 3795 | Configuration File*: Use the | ||
| 3796 | :term:`BBMULTICONFIG` | ||
| 3797 | variable in your ``conf/local.conf`` configuration file to specify | ||
| 3798 | each multiconfig. Continuing with the example from the previous | ||
| 3799 | figure, the ``BBMULTICONFIG`` variable needs to enable two | ||
| 3800 | multiconfigs: "x86" and "arm" by specifying each configuration file: | ||
| 3801 | :: | ||
| 3802 | |||
| 3803 | BBMULTICONFIG = "x86 arm" | ||
| 3804 | |||
| 3805 | .. note:: | ||
| 3806 | |||
| 3807 | A "default" configuration already exists by definition. This | ||
| 3808 | configuration is named: "" (i.e. empty string) and is defined by | ||
| 3809 | the variables coming from your ``local.conf`` | ||
| 3810 | file. Consequently, the previous example actually adds two | ||
| 3811 | additional configurations to your build: "arm" and "x86" along | ||
| 3812 | with "". | ||
| 3813 | |||
| 3814 | - *Launch BitBake*: Use the following BitBake command form to launch | ||
| 3815 | the multiple configuration build: | ||
| 3816 | :: | ||
| 3817 | |||
| 3818 | $ bitbake [mc:multiconfigname:]target [[[mc:multiconfigname:]target] ... ] | ||
| 3819 | |||
| 3820 | For the example in this section, the following command applies: | ||
| 3821 | :: | ||
| 3822 | |||
| 3823 | $ bitbake mc:x86:core-image-minimal mc:arm:core-image-sato mc::core-image-base | ||
| 3824 | |||
| 3825 | The previous BitBake command builds a ``core-image-minimal`` image | ||
| 3826 | that is configured through the ``x86.conf`` configuration file, a | ||
| 3827 | ``core-image-sato`` image that is configured through the ``arm.conf`` | ||
| 3828 | configuration file and a ``core-image-base`` that is configured | ||
| 3829 | through your ``local.conf`` configuration file. | ||
| 3830 | |||
| 3831 | .. note:: | ||
| 3832 | |||
| 3833 | Support for multiple configuration builds in the Yocto Project &DISTRO; | ||
| 3834 | (&DISTRO_NAME;) Release does not include Shared State (sstate) | ||
| 3835 | optimizations. Consequently, if a build uses the same object twice | ||
| 3836 | in, for example, two different ``TMPDIR`` | ||
| 3837 | directories, the build either loads from an existing sstate cache for | ||
| 3838 | that build at the start or builds the object fresh. | ||
| 3839 | |||
| 3840 | Enabling Multiple Configuration Build Dependencies | ||
| 3841 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 3842 | |||
| 3843 | Sometimes dependencies can exist between targets (multiconfigs) in a | ||
| 3844 | multiple configuration build. For example, suppose that in order to | ||
| 3845 | build a ``core-image-sato`` image for an "x86" multiconfig, the root | ||
| 3846 | filesystem of an "arm" multiconfig must exist. This dependency is | ||
| 3847 | essentially that the | ||
| 3848 | :ref:`ref-tasks-image` task in the | ||
| 3849 | ``core-image-sato`` recipe depends on the completion of the | ||
| 3850 | :ref:`ref-tasks-rootfs` task of the | ||
| 3851 | ``core-image-minimal`` recipe. | ||
| 3852 | |||
| 3853 | To enable dependencies in a multiple configuration build, you must | ||
| 3854 | declare the dependencies in the recipe using the following statement | ||
| 3855 | form: | ||
| 3856 | :: | ||
| 3857 | |||
| 3858 | task_or_package[mcdepends] = "mc:from_multiconfig:to_multiconfig:recipe_name:task_on_which_to_depend" | ||
| 3859 | |||
| 3860 | To better show how to use this statement, consider the example scenario | ||
| 3861 | from the first paragraph of this section. The following statement needs | ||
| 3862 | to be added to the recipe that builds the ``core-image-sato`` image: | ||
| 3863 | :: | ||
| 3864 | |||
| 3865 | do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_rootfs" | ||
| 3866 | |||
| 3867 | In this example, the `from_multiconfig` is "x86". The `to_multiconfig` is "arm". The | ||
| 3868 | task on which the ``do_image`` task in the recipe depends is the | ||
| 3869 | ``do_rootfs`` task from the ``core-image-minimal`` recipe associated | ||
| 3870 | with the "arm" multiconfig. | ||
| 3871 | |||
| 3872 | Once you set up this dependency, you can build the "x86" multiconfig | ||
| 3873 | using a BitBake command as follows: | ||
| 3874 | :: | ||
| 3875 | |||
| 3876 | $ bitbake mc:x86:core-image-sato | ||
| 3877 | |||
| 3878 | This command executes all the tasks needed to create the | ||
| 3879 | ``core-image-sato`` image for the "x86" multiconfig. Because of the | ||
| 3880 | dependency, BitBake also executes through the ``do_rootfs`` task for the | ||
| 3881 | "arm" multiconfig build. | ||
| 3882 | |||
| 3883 | Having a recipe depend on the root filesystem of another build might not | ||
| 3884 | seem that useful. Consider this change to the statement in the | ||
| 3885 | ``core-image-sato`` recipe: | ||
| 3886 | :: | ||
| 3887 | |||
| 3888 | do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_image" | ||
| 3889 | |||
| 3890 | In this case, BitBake must | ||
| 3891 | create the ``core-image-minimal`` image for the "arm" build since the | ||
| 3892 | "x86" build depends on it. | ||
| 3893 | |||
| 3894 | Because "x86" and "arm" are enabled for multiple configuration builds | ||
| 3895 | and have separate configuration files, BitBake places the artifacts for | ||
| 3896 | each build in the respective temporary build directories (i.e. | ||
| 3897 | :term:`TMPDIR`). | ||
| 3898 | |||
| 3899 | Building an Initial RAM Filesystem (initramfs) Image | ||
| 3900 | ---------------------------------------------------- | ||
| 3901 | |||
| 3902 | An initial RAM filesystem (initramfs) image provides a temporary root | ||
| 3903 | filesystem used for early system initialization (e.g. loading of modules | ||
| 3904 | needed to locate and mount the "real" root filesystem). | ||
| 3905 | |||
| 3906 | .. note:: | ||
| 3907 | |||
| 3908 | The initramfs image is the successor of initial RAM disk (initrd). It | ||
| 3909 | is a "copy in and out" (cpio) archive of the initial filesystem that | ||
| 3910 | gets loaded into memory during the Linux startup process. Because | ||
| 3911 | Linux uses the contents of the archive during initialization, the | ||
| 3912 | initramfs image needs to contain all of the device drivers and tools | ||
| 3913 | needed to mount the final root filesystem. | ||
| 3914 | |||
| 3915 | Follow these steps to create an initramfs image: | ||
| 3916 | |||
| 3917 | 1. *Create the initramfs Image Recipe:* You can reference the | ||
| 3918 | ``core-image-minimal-initramfs.bb`` recipe found in the | ||
| 3919 | ``meta/recipes-core`` directory of the :term:`Source Directory` | ||
| 3920 | as an example | ||
| 3921 | from which to work. | ||
| 3922 | |||
| 3923 | 2. *Decide if You Need to Bundle the initramfs Image Into the Kernel | ||
| 3924 | Image:* If you want the initramfs image that is built to be bundled | ||
| 3925 | in with the kernel image, set the | ||
| 3926 | :term:`INITRAMFS_IMAGE_BUNDLE` | ||
| 3927 | variable to "1" in your ``local.conf`` configuration file and set the | ||
| 3928 | :term:`INITRAMFS_IMAGE` | ||
| 3929 | variable in the recipe that builds the kernel image. | ||
| 3930 | |||
| 3931 | .. note:: | ||
| 3932 | |||
| 3933 | It is recommended that you do bundle the initramfs image with the | ||
| 3934 | kernel image to avoid circular dependencies between the kernel | ||
| 3935 | recipe and the initramfs recipe should the initramfs image include | ||
| 3936 | kernel modules. | ||
| 3937 | |||
| 3938 | Setting the ``INITRAMFS_IMAGE_BUNDLE`` flag causes the initramfs | ||
| 3939 | image to be unpacked into the ``${B}/usr/`` directory. The unpacked | ||
| 3940 | initramfs image is then passed to the kernel's ``Makefile`` using the | ||
| 3941 | :term:`CONFIG_INITRAMFS_SOURCE` | ||
| 3942 | variable, allowing the initramfs image to be built into the kernel | ||
| 3943 | normally. | ||
| 3944 | |||
| 3945 | .. note:: | ||
| 3946 | |||
| 3947 | If you choose to not bundle the initramfs image with the kernel | ||
| 3948 | image, you are essentially using an | ||
| 3949 | `Initial RAM Disk (initrd) <https://en.wikipedia.org/wiki/Initrd>`__. | ||
| 3950 | Creating an initrd is handled primarily through the :term:`INITRD_IMAGE`, | ||
| 3951 | ``INITRD_LIVE``, and ``INITRD_IMAGE_LIVE`` variables. For more | ||
| 3952 | information, see the :ref:`ref-classes-image-live` file. | ||
| 3953 | |||
| 3954 | 3. *Optionally Add Items to the initramfs Image Through the initramfs | ||
| 3955 | Image Recipe:* If you add items to the initramfs image by way of its | ||
| 3956 | recipe, you should use | ||
| 3957 | :term:`PACKAGE_INSTALL` | ||
| 3958 | rather than | ||
| 3959 | :term:`IMAGE_INSTALL`. | ||
| 3960 | ``PACKAGE_INSTALL`` gives more direct control of what is added to the | ||
| 3961 | image as compared to the defaults you might not necessarily want that | ||
| 3962 | are set by the :ref:`image <ref-classes-image>` | ||
| 3963 | or :ref:`core-image <ref-classes-core-image>` | ||
| 3964 | classes. | ||
| 3965 | |||
| 3966 | 4. *Build the Kernel Image and the initramfs Image:* Build your kernel | ||
| 3967 | image using BitBake. Because the initramfs image recipe is a | ||
| 3968 | dependency of the kernel image, the initramfs image is built as well | ||
| 3969 | and bundled with the kernel image if you used the | ||
| 3970 | :term:`INITRAMFS_IMAGE_BUNDLE` | ||
| 3971 | variable described earlier. | ||
| 3972 | |||
| 3973 | Building a Tiny System | ||
| 3974 | ---------------------- | ||
| 3975 | |||
| 3976 | Very small distributions have some significant advantages such as | ||
| 3977 | requiring less on-die or in-package memory (cheaper), better performance | ||
| 3978 | through efficient cache usage, lower power requirements due to less | ||
| 3979 | memory, faster boot times, and reduced development overhead. Some | ||
| 3980 | real-world examples where a very small distribution gives you distinct | ||
| 3981 | advantages are digital cameras, medical devices, and small headless | ||
| 3982 | systems. | ||
| 3983 | |||
| 3984 | This section presents information that shows you how you can trim your | ||
| 3985 | distribution to even smaller sizes than the ``poky-tiny`` distribution, | ||
| 3986 | which is around 5 Mbytes, that can be built out-of-the-box using the | ||
| 3987 | Yocto Project. | ||
| 3988 | |||
| 3989 | Tiny System Overview | ||
| 3990 | ~~~~~~~~~~~~~~~~~~~~ | ||
| 3991 | |||
| 3992 | The following list presents the overall steps you need to consider and | ||
| 3993 | perform to create distributions with smaller root filesystems, achieve | ||
| 3994 | faster boot times, maintain your critical functionality, and avoid | ||
| 3995 | initial RAM disks: | ||
| 3996 | |||
| 3997 | - `Determine your goals and guiding | ||
| 3998 | principles. <#goals-and-guiding-principles>`__ | ||
| 3999 | |||
| 4000 | - `Understand what contributes to your image | ||
| 4001 | size. <#understand-what-gives-your-image-size>`__ | ||
| 4002 | |||
| 4003 | - `Reduce the size of the root | ||
| 4004 | filesystem. <#trim-the-root-filesystem>`__ | ||
| 4005 | |||
| 4006 | - `Reduce the size of the kernel. <#trim-the-kernel>`__ | ||
| 4007 | |||
| 4008 | - `Eliminate packaging | ||
| 4009 | requirements. <#remove-package-management-requirements>`__ | ||
| 4010 | |||
| 4011 | - `Look for other ways to minimize | ||
| 4012 | size. <#look-for-other-ways-to-minimize-size>`__ | ||
| 4013 | |||
| 4014 | - `Iterate on the process. <#iterate-on-the-process>`__ | ||
| 4015 | |||
| 4016 | Goals and Guiding Principles | ||
| 4017 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 4018 | |||
| 4019 | Before you can reach your destination, you need to know where you are | ||
| 4020 | going. Here is an example list that you can use as a guide when creating | ||
| 4021 | very small distributions: | ||
| 4022 | |||
| 4023 | - Determine how much space you need (e.g. a kernel that is 1 Mbyte or | ||
| 4024 | less and a root filesystem that is 3 Mbytes or less). | ||
| 4025 | |||
| 4026 | - Find the areas that are currently taking 90% of the space and | ||
| 4027 | concentrate on reducing those areas. | ||
| 4028 | |||
| 4029 | - Do not create any difficult "hacks" to achieve your goals. | ||
| 4030 | |||
| 4031 | - Leverage the device-specific options. | ||
| 4032 | |||
| 4033 | - Work in a separate layer so that you keep changes isolated. For | ||
| 4034 | information on how to create layers, see the "`Understanding and | ||
| 4035 | Creating Layers <#understanding-and-creating-layers>`__" section. | ||
| 4036 | |||
| 4037 | Understand What Contributes to Your Image Size | ||
| 4038 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 4039 | |||
| 4040 | It is easiest to have something to start with when creating your own | ||
| 4041 | distribution. You can use the Yocto Project out-of-the-box to create the | ||
| 4042 | ``poky-tiny`` distribution. Ultimately, you will want to make changes in | ||
| 4043 | your own distribution that are likely modeled after ``poky-tiny``. | ||
| 4044 | |||
| 4045 | .. note:: | ||
| 4046 | |||
| 4047 | To use ``poky-tiny`` in your build, set the ``DISTRO`` variable in your | ||
| 4048 | ``local.conf`` file to "poky-tiny" as described in the | ||
| 4049 | ":ref:`dev-manual/common-tasks:creating your own distribution`" | ||
| 4050 | section. | ||
| 4051 | |||
| 4052 | Understanding some memory concepts will help you reduce the system size. | ||
| 4053 | Memory consists of static, dynamic, and temporary memory. Static memory | ||
| 4054 | is the TEXT (code), DATA (initialized data in the code), and BSS | ||
| 4055 | (uninitialized data) sections. Dynamic memory represents memory that is | ||
| 4056 | allocated at runtime: stacks, hash tables, and so forth. Temporary | ||
| 4057 | memory is recovered after the boot process. This memory consists of | ||
| 4058 | memory used for decompressing the kernel and for the ``__init__`` | ||
| 4059 | functions. | ||
| 4060 | |||
| 4061 | To help you see where you currently are with kernel and root filesystem | ||
| 4062 | sizes, you can use two tools found in the :term:`Source Directory` | ||
| 4063 | in the | ||
| 4064 | ``scripts/tiny/`` directory: | ||
| 4065 | |||
| 4066 | - ``ksize.py``: Reports component sizes for the kernel build objects. | ||
| 4067 | |||
| 4068 | - ``dirsize.py``: Reports component sizes for the root filesystem. | ||
| 4069 | |||
| 4070 | This next tool and command help you organize configuration fragments and | ||
| 4071 | view file dependencies in a human-readable form: | ||
| 4072 | |||
| 4073 | - ``merge_config.sh``: Helps you manage configuration files and | ||
| 4074 | fragments within the kernel. With this tool, you can merge individual | ||
| 4075 | configuration fragments together. The tool allows you to make | ||
| 4076 | overrides and warns you of any missing configuration options. The | ||
| 4077 | tool is ideal for allowing you to iterate on configurations, create | ||
| 4078 | minimal configurations, and create configuration files for different | ||
| 4079 | machines without having to duplicate your process. | ||
| 4080 | |||
| 4081 | The ``merge_config.sh`` script is part of the Linux Yocto kernel Git | ||
| 4082 | repositories (i.e. ``linux-yocto-3.14``, ``linux-yocto-3.10``, | ||
| 4083 | ``linux-yocto-3.8``, and so forth) in the ``scripts/kconfig`` | ||
| 4084 | directory. | ||
| 4085 | |||
| 4086 | For more information on configuration fragments, see the | ||
| 4087 | ":ref:`kernel-dev/kernel-dev-common:creating configuration fragments`" | ||
| 4088 | section in the Yocto Project Linux Kernel Development Manual. | ||
| 4089 | |||
| 4090 | - ``bitbake -u taskexp -g bitbake_target``: Using the BitBake command | ||
| 4091 | with these options brings up a Dependency Explorer from which you can | ||
| 4092 | view file dependencies. Understanding these dependencies allows you | ||
| 4093 | to make informed decisions when cutting out various pieces of the | ||
| 4094 | kernel and root filesystem. | ||
| 4095 | |||
| 4096 | Trim the Root Filesystem | ||
| 4097 | ~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 4098 | |||
| 4099 | The root filesystem is made up of packages for booting, libraries, and | ||
| 4100 | applications. To change things, you can configure how the packaging | ||
| 4101 | happens, which changes the way you build them. You can also modify the | ||
| 4102 | filesystem itself or select a different filesystem. | ||
| 4103 | |||
| 4104 | First, find out what is hogging your root filesystem by running the | ||
| 4105 | ``dirsize.py`` script from your root directory: | ||
| 4106 | :: | ||
| 4107 | |||
| 4108 | $ cd root-directory-of-image | ||
| 4109 | $ dirsize.py 100000 > dirsize-100k.log | ||
| 4110 | $ cat dirsize-100k.log | ||
| 4111 | |||
| 4112 | You can apply a filter to the script to ignore files | ||
| 4113 | under a certain size. The previous example filters out any files below | ||
| 4114 | 100 Kbytes. The sizes reported by the tool are uncompressed, and thus | ||
| 4115 | will be smaller by a relatively constant factor in a compressed root | ||
| 4116 | filesystem. When you examine your log file, you can focus on areas of | ||
| 4117 | the root filesystem that take up large amounts of memory. | ||
| 4118 | |||
| 4119 | You need to be sure that what you eliminate does not cripple the | ||
| 4120 | functionality you need. One way to see how packages relate to each other | ||
| 4121 | is by using the Dependency Explorer UI with the BitBake command: | ||
| 4122 | :: | ||
| 4123 | |||
| 4124 | $ cd image-directory | ||
| 4125 | $ bitbake -u taskexp -g image | ||
| 4126 | |||
| 4127 | Use the interface to | ||
| 4128 | select potential packages you wish to eliminate and see their dependency | ||
| 4129 | relationships. | ||
| 4130 | |||
| 4131 | When deciding how to reduce the size, get rid of packages that result in | ||
| 4132 | minimal impact on the feature set. For example, you might not need a VGA | ||
| 4133 | display. Or, you might be able to get by with ``devtmpfs`` and ``mdev`` | ||
| 4134 | instead of ``udev``. | ||
| 4135 | |||
| 4136 | Use your ``local.conf`` file to make changes. For example, to eliminate | ||
| 4137 | ``udev`` and ``glib``, set the following in the local configuration | ||
| 4138 | file: | ||
| 4139 | :: | ||
| 4140 | |||
| 4141 | VIRTUAL-RUNTIME_dev_manager = "" | ||
| 4142 | |||
| 4143 | Finally, you should consider exactly the type of root filesystem you | ||
| 4144 | need to meet your needs while also reducing its size. For example, | ||
| 4145 | consider ``cramfs``, ``squashfs``, ``ubifs``, ``ext2``, or an | ||
| 4146 | ``initramfs`` using ``initramfs``. Be aware that ``ext3`` requires a 1 | ||
| 4147 | Mbyte journal. If you are okay with running read-only, you do not need | ||
| 4148 | this journal. | ||
| 4149 | |||
| 4150 | .. note:: | ||
| 4151 | |||
| 4152 | After each round of elimination, you need to rebuild your system and | ||
| 4153 | then use the tools to see the effects of your reductions. | ||
| 4154 | |||
| 4155 | Trim the Kernel | ||
| 4156 | ~~~~~~~~~~~~~~~ | ||
| 4157 | |||
| 4158 | The kernel is built by including policies for hardware-independent | ||
| 4159 | aspects. What subsystems do you enable? For what architecture are you | ||
| 4160 | building? Which drivers do you build by default? | ||
| 4161 | |||
| 4162 | .. note:: | ||
| 4163 | |||
| 4164 | You can modify the kernel source if you want to help with boot time. | ||
| 4165 | |||
| 4166 | Run the ``ksize.py`` script from the top-level Linux build directory to | ||
| 4167 | get an idea of what is making up the kernel: | ||
| 4168 | :: | ||
| 4169 | |||
| 4170 | $ cd top-level-linux-build-directory | ||
| 4171 | $ ksize.py > ksize.log | ||
| 4172 | $ cat ksize.log | ||
| 4173 | |||
| 4174 | When you examine the log, you will see how much space is taken up with | ||
| 4175 | the built-in ``.o`` files for drivers, networking, core kernel files, | ||
| 4176 | filesystem, sound, and so forth. The sizes reported by the tool are | ||
| 4177 | uncompressed, and thus will be smaller by a relatively constant factor | ||
| 4178 | in a compressed kernel image. Look to reduce the areas that are large | ||
| 4179 | and taking up around the "90% rule." | ||
| 4180 | |||
| 4181 | To examine, or drill down, into any particular area, use the ``-d`` | ||
| 4182 | option with the script: | ||
| 4183 | :: | ||
| 4184 | |||
| 4185 | $ ksize.py -d > ksize.log | ||
| 4186 | |||
| 4187 | Using this option | ||
| 4188 | breaks out the individual file information for each area of the kernel | ||
| 4189 | (e.g. drivers, networking, and so forth). | ||
| 4190 | |||
| 4191 | Use your log file to see what you can eliminate from the kernel based on | ||
| 4192 | features you can let go. For example, if you are not going to need | ||
| 4193 | sound, you do not need any drivers that support sound. | ||
| 4194 | |||
| 4195 | After figuring out what to eliminate, you need to reconfigure the kernel | ||
| 4196 | to reflect those changes during the next build. You could run | ||
| 4197 | ``menuconfig`` and make all your changes at once. However, that makes it | ||
| 4198 | difficult to see the effects of your individual eliminations and also | ||
| 4199 | makes it difficult to replicate the changes for perhaps another target | ||
| 4200 | device. A better method is to start with no configurations using | ||
| 4201 | ``allnoconfig``, create configuration fragments for individual changes, | ||
| 4202 | and then manage the fragments into a single configuration file using | ||
| 4203 | ``merge_config.sh``. The tool makes it easy for you to iterate using the | ||
| 4204 | configuration change and build cycle. | ||
| 4205 | |||
| 4206 | Each time you make configuration changes, you need to rebuild the kernel | ||
| 4207 | and check to see what impact your changes had on the overall size. | ||
| 4208 | |||
| 4209 | Remove Package Management Requirements | ||
| 4210 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 4211 | |||
| 4212 | Packaging requirements add size to the image. One way to reduce the size | ||
| 4213 | of the image is to remove all the packaging requirements from the image. | ||
| 4214 | This reduction includes both removing the package manager and its unique | ||
| 4215 | dependencies as well as removing the package management data itself. | ||
| 4216 | |||
| 4217 | To eliminate all the packaging requirements for an image, be sure that | ||
| 4218 | "package-management" is not part of your | ||
| 4219 | :term:`IMAGE_FEATURES` | ||
| 4220 | statement for the image. When you remove this feature, you are removing | ||
| 4221 | the package manager as well as its dependencies from the root | ||
| 4222 | filesystem. | ||
| 4223 | |||
| 4224 | Look for Other Ways to Minimize Size | ||
| 4225 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 4226 | |||
| 4227 | Depending on your particular circumstances, other areas that you can | ||
| 4228 | trim likely exist. The key to finding these areas is through tools and | ||
| 4229 | methods described here combined with experimentation and iteration. Here | ||
| 4230 | are a couple of areas to experiment with: | ||
| 4231 | |||
| 4232 | - ``glibc``: In general, follow this process: | ||
| 4233 | |||
| 4234 | 1. Remove ``glibc`` features from | ||
| 4235 | :term:`DISTRO_FEATURES` | ||
| 4236 | that you think you do not need. | ||
| 4237 | |||
| 4238 | 2. Build your distribution. | ||
| 4239 | |||
| 4240 | 3. If the build fails due to missing symbols in a package, determine | ||
| 4241 | if you can reconfigure the package to not need those features. For | ||
| 4242 | example, change the configuration to not support wide character | ||
| 4243 | support as is done for ``ncurses``. Or, if support for those | ||
| 4244 | characters is needed, determine what ``glibc`` features provide | ||
| 4245 | the support and restore the configuration. | ||
| 4246 | |||
| 4247 | 4. Rebuild and repeat the process. | ||
| 4248 | |||
| 4249 | - ``busybox``: For BusyBox, use a process similar as described for | ||
| 4250 | ``glibc``. A difference is you will need to boot the resulting system | ||
| 4251 | to see if you are able to do everything you expect from the running | ||
| 4252 | system. You need to be sure to integrate configuration fragments into | ||
| 4253 | Busybox because BusyBox handles its own core features and then allows | ||
| 4254 | you to add configuration fragments on top. | ||
| 4255 | |||
| 4256 | Iterate on the Process | ||
| 4257 | ~~~~~~~~~~~~~~~~~~~~~~ | ||
| 4258 | |||
| 4259 | If you have not reached your goals on system size, you need to iterate | ||
| 4260 | on the process. The process is the same. Use the tools and see just what | ||
| 4261 | is taking up 90% of the root filesystem and the kernel. Decide what you | ||
| 4262 | can eliminate without limiting your device beyond what you need. | ||
| 4263 | |||
| 4264 | Depending on your system, a good place to look might be Busybox, which | ||
| 4265 | provides a stripped down version of Unix tools in a single, executable | ||
| 4266 | file. You might be able to drop virtual terminal services or perhaps | ||
| 4267 | ipv6. | ||
| 4268 | |||
| 4269 | Building Images for More than One Machine | ||
| 4270 | ----------------------------------------- | ||
| 4271 | |||
| 4272 | A common scenario developers face is creating images for several | ||
| 4273 | different machines that use the same software environment. In this | ||
| 4274 | situation, it is tempting to set the tunings and optimization flags for | ||
| 4275 | each build specifically for the targeted hardware (i.e. "maxing out" the | ||
| 4276 | tunings). Doing so can considerably add to build times and package feed | ||
| 4277 | maintenance collectively for the machines. For example, selecting tunes | ||
| 4278 | that are extremely specific to a CPU core used in a system might enable | ||
| 4279 | some micro optimizations in GCC for that particular system but would | ||
| 4280 | otherwise not gain you much of a performance difference across the other | ||
| 4281 | systems as compared to using a more general tuning across all the builds | ||
| 4282 | (e.g. setting :term:`DEFAULTTUNE` | ||
| 4283 | specifically for each machine's build). Rather than "max out" each | ||
| 4284 | build's tunings, you can take steps that cause the OpenEmbedded build | ||
| 4285 | system to reuse software across the various machines where it makes | ||
| 4286 | sense. | ||
| 4287 | |||
| 4288 | If build speed and package feed maintenance are considerations, you | ||
| 4289 | should consider the points in this section that can help you optimize | ||
| 4290 | your tunings to best consider build times and package feed maintenance. | ||
| 4291 | |||
| 4292 | - *Share the Build Directory:* If at all possible, share the | ||
| 4293 | :term:`TMPDIR` across builds. The | ||
| 4294 | Yocto Project supports switching between different | ||
| 4295 | :term:`MACHINE` values in the same | ||
| 4296 | ``TMPDIR``. This practice is well supported and regularly used by | ||
| 4297 | developers when building for multiple machines. When you use the same | ||
| 4298 | ``TMPDIR`` for multiple machine builds, the OpenEmbedded build system | ||
| 4299 | can reuse the existing native and often cross-recipes for multiple | ||
| 4300 | machines. Thus, build time decreases. | ||
| 4301 | |||
| 4302 | .. note:: | ||
| 4303 | |||
| 4304 | If :term:`DISTRO` settings change or fundamental configuration settings | ||
| 4305 | such as the filesystem layout, you need to work with a clean ``TMPDIR``. | ||
| 4306 | Sharing ``TMPDIR`` under these circumstances might work but since it is | ||
| 4307 | not guaranteed, you should use a clean ``TMPDIR``. | ||
| 4308 | |||
| 4309 | - *Enable the Appropriate Package Architecture:* By default, the | ||
| 4310 | OpenEmbedded build system enables three levels of package | ||
| 4311 | architectures: "all", "tune" or "package", and "machine". Any given | ||
| 4312 | recipe usually selects one of these package architectures (types) for | ||
| 4313 | its output. Depending for what a given recipe creates packages, | ||
| 4314 | making sure you enable the appropriate package architecture can | ||
| 4315 | directly impact the build time. | ||
| 4316 | |||
| 4317 | A recipe that just generates scripts can enable "all" architecture | ||
| 4318 | because there are no binaries to build. To specifically enable "all" | ||
| 4319 | architecture, be sure your recipe inherits the | ||
| 4320 | :ref:`allarch <ref-classes-allarch>` class. | ||
| 4321 | This class is useful for "all" architectures because it configures | ||
| 4322 | many variables so packages can be used across multiple architectures. | ||
| 4323 | |||
| 4324 | If your recipe needs to generate packages that are machine-specific | ||
| 4325 | or when one of the build or runtime dependencies is already | ||
| 4326 | machine-architecture dependent, which makes your recipe also | ||
| 4327 | machine-architecture dependent, make sure your recipe enables the | ||
| 4328 | "machine" package architecture through the | ||
| 4329 | :term:`MACHINE_ARCH` | ||
| 4330 | variable: | ||
| 4331 | :: | ||
| 4332 | |||
| 4333 | PACKAGE_ARCH = "${MACHINE_ARCH}" | ||
| 4334 | |||
| 4335 | When you do not | ||
| 4336 | specifically enable a package architecture through the | ||
| 4337 | :term:`PACKAGE_ARCH`, The | ||
| 4338 | OpenEmbedded build system defaults to the | ||
| 4339 | :term:`TUNE_PKGARCH` setting: | ||
| 4340 | :: | ||
| 4341 | |||
| 4342 | PACKAGE_ARCH = "${TUNE_PKGARCH}" | ||
| 4343 | |||
| 4344 | - *Choose a Generic Tuning File if Possible:* Some tunes are more | ||
| 4345 | generic and can run on multiple targets (e.g. an ``armv5`` set of | ||
| 4346 | packages could run on ``armv6`` and ``armv7`` processors in most | ||
| 4347 | cases). Similarly, ``i486`` binaries could work on ``i586`` and | ||
| 4348 | higher processors. You should realize, however, that advances on | ||
| 4349 | newer processor versions would not be used. | ||
| 4350 | |||
| 4351 | If you select the same tune for several different machines, the | ||
| 4352 | OpenEmbedded build system reuses software previously built, thus | ||
| 4353 | speeding up the overall build time. Realize that even though a new | ||
| 4354 | sysroot for each machine is generated, the software is not recompiled | ||
| 4355 | and only one package feed exists. | ||
| 4356 | |||
| 4357 | - *Manage Granular Level Packaging:* Sometimes cases exist where | ||
| 4358 | injecting another level of package architecture beyond the three | ||
| 4359 | higher levels noted earlier can be useful. For example, consider how | ||
| 4360 | NXP (formerly Freescale) allows for the easy reuse of binary packages | ||
| 4361 | in their layer | ||
| 4362 | :yocto_git:`meta-freescale </meta-freescale/>`. | ||
| 4363 | In this example, the | ||
| 4364 | :yocto_git:`fsl-dynamic-packagearch </meta-freescale/tree/classes/fsl-dynamic-packagearch.bbclass>` | ||
| 4365 | class shares GPU packages for i.MX53 boards because all boards share | ||
| 4366 | the AMD GPU. The i.MX6-based boards can do the same because all | ||
| 4367 | boards share the Vivante GPU. This class inspects the BitBake | ||
| 4368 | datastore to identify if the package provides or depends on one of | ||
| 4369 | the sub-architecture values. If so, the class sets the | ||
| 4370 | :term:`PACKAGE_ARCH` value | ||
| 4371 | based on the ``MACHINE_SUBARCH`` value. If the package does not | ||
| 4372 | provide or depend on one of the sub-architecture values but it | ||
| 4373 | matches a value in the machine-specific filter, it sets | ||
| 4374 | :term:`MACHINE_ARCH`. This | ||
| 4375 | behavior reduces the number of packages built and saves build time by | ||
| 4376 | reusing binaries. | ||
| 4377 | |||
| 4378 | - *Use Tools to Debug Issues:* Sometimes you can run into situations | ||
| 4379 | where software is being rebuilt when you think it should not be. For | ||
| 4380 | example, the OpenEmbedded build system might not be using shared | ||
| 4381 | state between machines when you think it should be. These types of | ||
| 4382 | situations are usually due to references to machine-specific | ||
| 4383 | variables such as :term:`MACHINE`, | ||
| 4384 | :term:`SERIAL_CONSOLES`, | ||
| 4385 | :term:`XSERVER`, | ||
| 4386 | :term:`MACHINE_FEATURES`, | ||
| 4387 | and so forth in code that is supposed to only be tune-specific or | ||
| 4388 | when the recipe depends | ||
| 4389 | (:term:`DEPENDS`, | ||
| 4390 | :term:`RDEPENDS`, | ||
| 4391 | :term:`RRECOMMENDS`, | ||
| 4392 | :term:`RSUGGESTS`, and so forth) | ||
| 4393 | on some other recipe that already has | ||
| 4394 | :term:`PACKAGE_ARCH` defined | ||
| 4395 | as "${MACHINE_ARCH}". | ||
| 4396 | |||
| 4397 | .. note:: | ||
| 4398 | |||
| 4399 | Patches to fix any issues identified are most welcome as these | ||
| 4400 | issues occasionally do occur. | ||
| 4401 | |||
| 4402 | For such cases, you can use some tools to help you sort out the | ||
| 4403 | situation: | ||
| 4404 | |||
| 4405 | - ``state-diff-machines.sh``*:* You can find this tool in the | ||
| 4406 | ``scripts`` directory of the Source Repositories. See the comments | ||
| 4407 | in the script for information on how to use the tool. | ||
| 4408 | |||
| 4409 | - *BitBake's "-S printdiff" Option:* Using this option causes | ||
| 4410 | BitBake to try to establish the closest signature match it can | ||
| 4411 | (e.g. in the shared state cache) and then run ``bitbake-diffsigs`` | ||
| 4412 | over the matches to determine the stamps and delta where these two | ||
| 4413 | stamp trees diverge. | ||
| 4414 | |||
| 4415 | Building Software from an External Source | ||
| 4416 | ----------------------------------------- | ||
| 4417 | |||
| 4418 | By default, the OpenEmbedded build system uses the | ||
| 4419 | :term:`Build Directory` when building source | ||
| 4420 | code. The build process involves fetching the source files, unpacking | ||
| 4421 | them, and then patching them if necessary before the build takes place. | ||
| 4422 | |||
| 4423 | Situations exist where you might want to build software from source | ||
| 4424 | files that are external to and thus outside of the OpenEmbedded build | ||
| 4425 | system. For example, suppose you have a project that includes a new BSP | ||
| 4426 | with a heavily customized kernel. And, you want to minimize exposing the | ||
| 4427 | build system to the development team so that they can focus on their | ||
| 4428 | project and maintain everyone's workflow as much as possible. In this | ||
| 4429 | case, you want a kernel source directory on the development machine | ||
| 4430 | where the development occurs. You want the recipe's | ||
| 4431 | :term:`SRC_URI` variable to point to | ||
| 4432 | the external directory and use it as is, not copy it. | ||
| 4433 | |||
| 4434 | To build from software that comes from an external source, all you need | ||
| 4435 | to do is inherit the | ||
| 4436 | :ref:`externalsrc <ref-classes-externalsrc>` class | ||
| 4437 | and then set the | ||
| 4438 | :term:`EXTERNALSRC` variable to | ||
| 4439 | point to your external source code. Here are the statements to put in | ||
| 4440 | your ``local.conf`` file: | ||
| 4441 | :: | ||
| 4442 | |||
| 4443 | INHERIT += "externalsrc" | ||
| 4444 | EXTERNALSRC_pn-myrecipe = "path-to-your-source-tree" | ||
| 4445 | |||
| 4446 | This next example shows how to accomplish the same thing by setting | ||
| 4447 | ``EXTERNALSRC`` in the recipe itself or in the recipe's append file: | ||
| 4448 | :: | ||
| 4449 | |||
| 4450 | EXTERNALSRC = "path" | ||
| 4451 | EXTERNALSRC_BUILD = "path" | ||
| 4452 | |||
| 4453 | .. note:: | ||
| 4454 | |||
| 4455 | In order for these settings to take effect, you must globally or | ||
| 4456 | locally inherit the :ref:`externalsrc <ref-classes-externalsrc>` | ||
| 4457 | class. | ||
| 4458 | |||
| 4459 | By default, ``externalsrc.bbclass`` builds the source code in a | ||
| 4460 | directory separate from the external source directory as specified by | ||
| 4461 | :term:`EXTERNALSRC`. If you need | ||
| 4462 | to have the source built in the same directory in which it resides, or | ||
| 4463 | some other nominated directory, you can set | ||
| 4464 | :term:`EXTERNALSRC_BUILD` | ||
| 4465 | to point to that directory: | ||
| 4466 | :: | ||
| 4467 | |||
| 4468 | EXTERNALSRC_BUILD_pn-myrecipe = "path-to-your-source-tree" | ||
| 4469 | |||
| 4470 | Replicating a Build Offline | ||
| 4471 | --------------------------- | ||
| 4472 | |||
| 4473 | It can be useful to take a "snapshot" of upstream sources used in a | ||
| 4474 | build and then use that "snapshot" later to replicate the build offline. | ||
| 4475 | To do so, you need to first prepare and populate your downloads | ||
| 4476 | directory your "snapshot" of files. Once your downloads directory is | ||
| 4477 | ready, you can use it at any time and from any machine to replicate your | ||
| 4478 | build. | ||
| 4479 | |||
| 4480 | Follow these steps to populate your Downloads directory: | ||
| 4481 | |||
| 4482 | 1. *Create a Clean Downloads Directory:* Start with an empty downloads | ||
| 4483 | directory (:term:`DL_DIR`). You | ||
| 4484 | start with an empty downloads directory by either removing the files | ||
| 4485 | in the existing directory or by setting ``DL_DIR`` to point to either | ||
| 4486 | an empty location or one that does not yet exist. | ||
| 4487 | |||
| 4488 | 2. *Generate Tarballs of the Source Git Repositories:* Edit your | ||
| 4489 | ``local.conf`` configuration file as follows: | ||
| 4490 | :: | ||
| 4491 | |||
| 4492 | DL_DIR = "/home/your-download-dir/" | ||
| 4493 | BB_GENERATE_MIRROR_TARBALLS = "1" | ||
| 4494 | |||
| 4495 | During | ||
| 4496 | the fetch process in the next step, BitBake gathers the source files | ||
| 4497 | and creates tarballs in the directory pointed to by ``DL_DIR``. See | ||
| 4498 | the | ||
| 4499 | :term:`BB_GENERATE_MIRROR_TARBALLS` | ||
| 4500 | variable for more information. | ||
| 4501 | |||
| 4502 | 3. *Populate Your Downloads Directory Without Building:* Use BitBake to | ||
| 4503 | fetch your sources but inhibit the build: | ||
| 4504 | :: | ||
| 4505 | |||
| 4506 | $ bitbake target --runonly=fetch | ||
| 4507 | |||
| 4508 | The downloads directory (i.e. ``${DL_DIR}``) now has | ||
| 4509 | a "snapshot" of the source files in the form of tarballs, which can | ||
| 4510 | be used for the build. | ||
| 4511 | |||
| 4512 | 4. *Optionally Remove Any Git or other SCM Subdirectories From the | ||
| 4513 | Downloads Directory:* If you want, you can clean up your downloads | ||
| 4514 | directory by removing any Git or other Source Control Management | ||
| 4515 | (SCM) subdirectories such as ``${DL_DIR}/git2/*``. The tarballs | ||
| 4516 | already contain these subdirectories. | ||
| 4517 | |||
| 4518 | Once your downloads directory has everything it needs regarding source | ||
| 4519 | files, you can create your "own-mirror" and build your target. | ||
| 4520 | Understand that you can use the files to build the target offline from | ||
| 4521 | any machine and at any time. | ||
| 4522 | |||
| 4523 | Follow these steps to build your target using the files in the downloads | ||
| 4524 | directory: | ||
| 4525 | |||
| 4526 | 1. *Using Local Files Only:* Inside your ``local.conf`` file, add the | ||
| 4527 | :term:`SOURCE_MIRROR_URL` | ||
| 4528 | variable, inherit the | ||
| 4529 | :ref:`own-mirrors <ref-classes-own-mirrors>` | ||
| 4530 | class, and use the | ||
| 4531 | :term:`bitbake:BB_NO_NETWORK` | ||
| 4532 | variable to your ``local.conf``. | ||
| 4533 | :: | ||
| 4534 | |||
| 4535 | SOURCE_MIRROR_URL ?= "file:///home/your-download-dir/" | ||
| 4536 | INHERIT += "own-mirrors" | ||
| 4537 | BB_NO_NETWORK = "1" | ||
| 4538 | |||
| 4539 | The ``SOURCE_MIRROR_URL`` and ``own-mirror`` | ||
| 4540 | class set up the system to use the downloads directory as your "own | ||
| 4541 | mirror". Using the ``BB_NO_NETWORK`` variable makes sure that | ||
| 4542 | BitBake's fetching process in step 3 stays local, which means files | ||
| 4543 | from your "own-mirror" are used. | ||
| 4544 | |||
| 4545 | 2. *Start With a Clean Build:* You can start with a clean build by | ||
| 4546 | removing the | ||
| 4547 | ``${``\ :term:`TMPDIR`\ ``}`` | ||
| 4548 | directory or using a new :term:`Build Directory`. | ||
| 4549 | |||
| 4550 | 3. *Build Your Target:* Use BitBake to build your target: | ||
| 4551 | :: | ||
| 4552 | |||
| 4553 | $ bitbake target | ||
| 4554 | |||
| 4555 | The build completes using the known local "snapshot" of source | ||
| 4556 | files from your mirror. The resulting tarballs for your "snapshot" of | ||
| 4557 | source files are in the downloads directory. | ||
| 4558 | |||
| 4559 | .. note:: | ||
| 4560 | |||
| 4561 | The offline build does not work if recipes attempt to find the | ||
| 4562 | latest version of software by setting | ||
| 4563 | :term:`SRCREV` to | ||
| 4564 | ``${``\ :term:`AUTOREV`\ ``}``: | ||
| 4565 | :: | ||
| 4566 | |||
| 4567 | SRCREV = "${AUTOREV}" | ||
| 4568 | |||
| 4569 | When a recipe sets ``SRCREV`` to | ||
| 4570 | ``${AUTOREV}``, the build system accesses the network in an | ||
| 4571 | attempt to determine the latest version of software from the SCM. | ||
| 4572 | Typically, recipes that use ``AUTOREV`` are custom or modified | ||
| 4573 | recipes. Recipes that reside in public repositories usually do not | ||
| 4574 | use ``AUTOREV``. | ||
| 4575 | |||
| 4576 | If you do have recipes that use ``AUTOREV``, you can take steps to | ||
| 4577 | still use the recipes in an offline build. Do the following: | ||
| 4578 | |||
| 4579 | 1. Use a configuration generated by enabling `build | ||
| 4580 | history <#maintaining-build-output-quality>`__. | ||
| 4581 | |||
| 4582 | 2. Use the ``buildhistory-collect-srcrevs`` command to collect the | ||
| 4583 | stored ``SRCREV`` values from the build's history. For more | ||
| 4584 | information on collecting these values, see the "`Build History | ||
| 4585 | Package Information <#build-history-package-information>`__" | ||
| 4586 | section. | ||
| 4587 | |||
| 4588 | 3. Once you have the correct source revisions, you can modify | ||
| 4589 | those recipes to to set ``SRCREV`` to specific versions of the | ||
| 4590 | software. | ||
| 4591 | |||
| 4592 | Speeding Up a Build | ||
| 4593 | =================== | ||
| 4594 | |||
| 4595 | Build time can be an issue. By default, the build system uses simple | ||
| 4596 | controls to try and maximize build efficiency. In general, the default | ||
| 4597 | settings for all the following variables result in the most efficient | ||
| 4598 | build times when dealing with single socket systems (i.e. a single CPU). | ||
| 4599 | If you have multiple CPUs, you might try increasing the default values | ||
| 4600 | to gain more speed. See the descriptions in the glossary for each | ||
| 4601 | variable for more information: | ||
| 4602 | |||
| 4603 | - :term:`BB_NUMBER_THREADS`: | ||
| 4604 | The maximum number of threads BitBake simultaneously executes. | ||
| 4605 | |||
| 4606 | - :term:`bitbake:BB_NUMBER_PARSE_THREADS`: | ||
| 4607 | The number of threads BitBake uses during parsing. | ||
| 4608 | |||
| 4609 | - :term:`PARALLEL_MAKE`: Extra | ||
| 4610 | options passed to the ``make`` command during the | ||
| 4611 | :ref:`ref-tasks-compile` task in | ||
| 4612 | order to specify parallel compilation on the local build host. | ||
| 4613 | |||
| 4614 | - :term:`PARALLEL_MAKEINST`: | ||
| 4615 | Extra options passed to the ``make`` command during the | ||
| 4616 | :ref:`ref-tasks-install` task in | ||
| 4617 | order to specify parallel installation on the local build host. | ||
| 4618 | |||
| 4619 | As mentioned, these variables all scale to the number of processor cores | ||
| 4620 | available on the build system. For single socket systems, this | ||
| 4621 | auto-scaling ensures that the build system fundamentally takes advantage | ||
| 4622 | of potential parallel operations during the build based on the build | ||
| 4623 | machine's capabilities. | ||
| 4624 | |||
| 4625 | Following are additional factors that can affect build speed: | ||
| 4626 | |||
| 4627 | - File system type: The file system type that the build is being | ||
| 4628 | performed on can also influence performance. Using ``ext4`` is | ||
| 4629 | recommended as compared to ``ext2`` and ``ext3`` due to ``ext4`` | ||
| 4630 | improved features such as extents. | ||
| 4631 | |||
| 4632 | - Disabling the updating of access time using ``noatime``: The | ||
| 4633 | ``noatime`` mount option prevents the build system from updating file | ||
| 4634 | and directory access times. | ||
| 4635 | |||
| 4636 | - Setting a longer commit: Using the "commit=" mount option increases | ||
| 4637 | the interval in seconds between disk cache writes. Changing this | ||
| 4638 | interval from the five second default to something longer increases | ||
| 4639 | the risk of data loss but decreases the need to write to the disk, | ||
| 4640 | thus increasing the build performance. | ||
| 4641 | |||
| 4642 | - Choosing the packaging backend: Of the available packaging backends, | ||
| 4643 | IPK is the fastest. Additionally, selecting a singular packaging | ||
| 4644 | backend also helps. | ||
| 4645 | |||
| 4646 | - Using ``tmpfs`` for :term:`TMPDIR` | ||
| 4647 | as a temporary file system: While this can help speed up the build, | ||
| 4648 | the benefits are limited due to the compiler using ``-pipe``. The | ||
| 4649 | build system goes to some lengths to avoid ``sync()`` calls into the | ||
| 4650 | file system on the principle that if there was a significant failure, | ||
| 4651 | the :term:`Build Directory` | ||
| 4652 | contents could easily be rebuilt. | ||
| 4653 | |||
| 4654 | - Inheriting the | ||
| 4655 | :ref:`rm_work <ref-classes-rm-work>` class: | ||
| 4656 | Inheriting this class has shown to speed up builds due to | ||
| 4657 | significantly lower amounts of data stored in the data cache as well | ||
| 4658 | as on disk. Inheriting this class also makes cleanup of | ||
| 4659 | :term:`TMPDIR` faster, at the | ||
| 4660 | expense of being easily able to dive into the source code. File | ||
| 4661 | system maintainers have recommended that the fastest way to clean up | ||
| 4662 | large numbers of files is to reformat partitions rather than delete | ||
| 4663 | files due to the linear nature of partitions. This, of course, | ||
| 4664 | assumes you structure the disk partitions and file systems in a way | ||
| 4665 | that this is practical. | ||
| 4666 | |||
| 4667 | Aside from the previous list, you should keep some trade offs in mind | ||
| 4668 | that can help you speed up the build: | ||
| 4669 | |||
| 4670 | - Remove items from | ||
| 4671 | :term:`DISTRO_FEATURES` | ||
| 4672 | that you might not need. | ||
| 4673 | |||
| 4674 | - Exclude debug symbols and other debug information: If you do not need | ||
| 4675 | these symbols and other debug information, disabling the ``*-dbg`` | ||
| 4676 | package generation can speed up the build. You can disable this | ||
| 4677 | generation by setting the | ||
| 4678 | :term:`INHIBIT_PACKAGE_DEBUG_SPLIT` | ||
| 4679 | variable to "1". | ||
| 4680 | |||
| 4681 | - Disable static library generation for recipes derived from | ||
| 4682 | ``autoconf`` or ``libtool``: Following is an example showing how to | ||
| 4683 | disable static libraries and still provide an override to handle | ||
| 4684 | exceptions: | ||
| 4685 | :: | ||
| 4686 | |||
| 4687 | STATICLIBCONF = "--disable-static" | ||
| 4688 | STATICLIBCONF_sqlite3-native = "" | ||
| 4689 | EXTRA_OECONF += "${STATICLIBCONF}" | ||
| 4690 | |||
| 4691 | .. note:: | ||
| 4692 | |||
| 4693 | - Some recipes need static libraries in order to work correctly | ||
| 4694 | (e.g. ``pseudo-native`` needs ``sqlite3-native``). Overrides, | ||
| 4695 | as in the previous example, account for these kinds of | ||
| 4696 | exceptions. | ||
| 4697 | |||
| 4698 | - Some packages have packaging code that assumes the presence of | ||
| 4699 | the static libraries. If so, you might need to exclude them as | ||
| 4700 | well. | ||
| 4701 | |||
| 4702 | Working With Libraries | ||
| 4703 | ====================== | ||
| 4704 | |||
| 4705 | Libraries are an integral part of your system. This section describes | ||
| 4706 | some common practices you might find helpful when working with libraries | ||
| 4707 | to build your system: | ||
| 4708 | |||
| 4709 | - `How to include static library | ||
| 4710 | files <#including-static-library-files>`__ | ||
| 4711 | |||
| 4712 | - `How to use the Multilib feature to combine multiple versions of | ||
| 4713 | library files into a single | ||
| 4714 | image <#combining-multiple-versions-library-files-into-one-image>`__ | ||
| 4715 | |||
| 4716 | - `How to install multiple versions of the same library in parallel on | ||
| 4717 | the same | ||
| 4718 | system <#installing-multiple-versions-of-the-same-library>`__ | ||
| 4719 | |||
| 4720 | Including Static Library Files | ||
| 4721 | ------------------------------ | ||
| 4722 | |||
| 4723 | If you are building a library and the library offers static linking, you | ||
| 4724 | can control which static library files (``*.a`` files) get included in | ||
| 4725 | the built library. | ||
| 4726 | |||
| 4727 | The :term:`PACKAGES` and | ||
| 4728 | :term:`FILES_* <FILES>` variables in the | ||
| 4729 | ``meta/conf/bitbake.conf`` configuration file define how files installed | ||
| 4730 | by the ``do_install`` task are packaged. By default, the ``PACKAGES`` | ||
| 4731 | variable includes ``${PN}-staticdev``, which represents all static | ||
| 4732 | library files. | ||
| 4733 | |||
| 4734 | .. note:: | ||
| 4735 | |||
| 4736 | Some previously released versions of the Yocto Project defined the | ||
| 4737 | static library files through ``${PN}-dev``. | ||
| 4738 | |||
| 4739 | Following is part of the BitBake configuration file, where you can see | ||
| 4740 | how the static library files are defined: | ||
| 4741 | :: | ||
| 4742 | |||
| 4743 | PACKAGE_BEFORE_PN ?= "" | ||
| 4744 | PACKAGES = "${PN}-dbg ${PN}-staticdev ${PN}-dev ${PN}-doc ${PN}-locale ${PACKAGE_BEFORE_PN} ${PN}" | ||
| 4745 | PACKAGES_DYNAMIC = "^${PN}-locale-.*" | ||
| 4746 | FILES = "" | ||
| 4747 | |||
| 4748 | FILES_${PN} = "${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*${SOLIBS} \ | ||
| 4749 | ${sysconfdir} ${sharedstatedir} ${localstatedir} \ | ||
| 4750 | ${base_bindir}/* ${base_sbindir}/* \ | ||
| 4751 | ${base_libdir}/*${SOLIBS} \ | ||
| 4752 | ${base_prefix}/lib/udev/rules.d ${prefix}/lib/udev/rules.d \ | ||
| 4753 | ${datadir}/${BPN} ${libdir}/${BPN}/* \ | ||
| 4754 | ${datadir}/pixmaps ${datadir}/applications \ | ||
| 4755 | ${datadir}/idl ${datadir}/omf ${datadir}/sounds \ | ||
| 4756 | ${libdir}/bonobo/servers" | ||
| 4757 | |||
| 4758 | FILES_${PN}-bin = "${bindir}/* ${sbindir}/*" | ||
| 4759 | |||
| 4760 | FILES_${PN}-doc = "${docdir} ${mandir} ${infodir} ${datadir}/gtk-doc \ | ||
| 4761 | ${datadir}/gnome/help" | ||
| 4762 | SECTION_${PN}-doc = "doc" | ||
| 4763 | |||
| 4764 | FILES_SOLIBSDEV ?= "${base_libdir}/lib*${SOLIBSDEV} ${libdir}/lib*${SOLIBSDEV}" | ||
| 4765 | FILES_${PN}-dev = "${includedir} ${FILES_SOLIBSDEV} ${libdir}/*.la \ | ||
| 4766 | ${libdir}/*.o ${libdir}/pkgconfig ${datadir}/pkgconfig \ | ||
| 4767 | ${datadir}/aclocal ${base_libdir}/*.o \ | ||
| 4768 | ${libdir}/${BPN}/*.la ${base_libdir}/*.la" | ||
| 4769 | SECTION_${PN}-dev = "devel" | ||
| 4770 | ALLOW_EMPTY_${PN}-dev = "1" | ||
| 4771 | RDEPENDS_${PN}-dev = "${PN} (= ${EXTENDPKGV})" | ||
| 4772 | |||
| 4773 | FILES_${PN}-staticdev = "${libdir}/*.a ${base_libdir}/*.a ${libdir}/${BPN}/*.a" | ||
| 4774 | SECTION_${PN}-staticdev = "devel" | ||
| 4775 | RDEPENDS_${PN}-staticdev = "${PN}-dev (= ${EXTENDPKGV})" | ||
| 4776 | |||
| 4777 | Combining Multiple Versions of Library Files into One Image | ||
| 4778 | ----------------------------------------------------------- | ||
| 4779 | |||
| 4780 | The build system offers the ability to build libraries with different | ||
| 4781 | target optimizations or architecture formats and combine these together | ||
| 4782 | into one system image. You can link different binaries in the image | ||
| 4783 | against the different libraries as needed for specific use cases. This | ||
| 4784 | feature is called "Multilib". | ||
| 4785 | |||
| 4786 | An example would be where you have most of a system compiled in 32-bit | ||
| 4787 | mode using 32-bit libraries, but you have something large, like a | ||
| 4788 | database engine, that needs to be a 64-bit application and uses 64-bit | ||
| 4789 | libraries. Multilib allows you to get the best of both 32-bit and 64-bit | ||
| 4790 | libraries. | ||
| 4791 | |||
| 4792 | While the Multilib feature is most commonly used for 32 and 64-bit | ||
| 4793 | differences, the approach the build system uses facilitates different | ||
| 4794 | target optimizations. You could compile some binaries to use one set of | ||
| 4795 | libraries and other binaries to use a different set of libraries. The | ||
| 4796 | libraries could differ in architecture, compiler options, or other | ||
| 4797 | optimizations. | ||
| 4798 | |||
| 4799 | Several examples exist in the ``meta-skeleton`` layer found in the | ||
| 4800 | :term:`Source Directory`: | ||
| 4801 | |||
| 4802 | - ``conf/multilib-example.conf`` configuration file | ||
| 4803 | |||
| 4804 | - ``conf/multilib-example2.conf`` configuration file | ||
| 4805 | |||
| 4806 | - ``recipes-multilib/images/core-image-multilib-example.bb`` recipe | ||
| 4807 | |||
| 4808 | Preparing to Use Multilib | ||
| 4809 | ~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 4810 | |||
| 4811 | User-specific requirements drive the Multilib feature. Consequently, | ||
| 4812 | there is no one "out-of-the-box" configuration that likely exists to | ||
| 4813 | meet your needs. | ||
| 4814 | |||
| 4815 | In order to enable Multilib, you first need to ensure your recipe is | ||
| 4816 | extended to support multiple libraries. Many standard recipes are | ||
| 4817 | already extended and support multiple libraries. You can check in the | ||
| 4818 | ``meta/conf/multilib.conf`` configuration file in the | ||
| 4819 | :term:`Source Directory` to see how this is | ||
| 4820 | done using the | ||
| 4821 | :term:`BBCLASSEXTEND` variable. | ||
| 4822 | Eventually, all recipes will be covered and this list will not be | ||
| 4823 | needed. | ||
| 4824 | |||
| 4825 | For the most part, the Multilib class extension works automatically to | ||
| 4826 | extend the package name from ``${PN}`` to ``${MLPREFIX}${PN}``, where | ||
| 4827 | ``MLPREFIX`` is the particular multilib (e.g. "lib32-" or "lib64-"). | ||
| 4828 | Standard variables such as | ||
| 4829 | :term:`DEPENDS`, | ||
| 4830 | :term:`RDEPENDS`, | ||
| 4831 | :term:`RPROVIDES`, | ||
| 4832 | :term:`RRECOMMENDS`, | ||
| 4833 | :term:`PACKAGES`, and | ||
| 4834 | :term:`PACKAGES_DYNAMIC` are | ||
| 4835 | automatically extended by the system. If you are extending any manual | ||
| 4836 | code in the recipe, you can use the ``${MLPREFIX}`` variable to ensure | ||
| 4837 | those names are extended correctly. This automatic extension code | ||
| 4838 | resides in ``multilib.bbclass``. | ||
| 4839 | |||
| 4840 | Using Multilib | ||
| 4841 | ~~~~~~~~~~~~~~ | ||
| 4842 | |||
| 4843 | After you have set up the recipes, you need to define the actual | ||
| 4844 | combination of multiple libraries you want to build. You accomplish this | ||
| 4845 | through your ``local.conf`` configuration file in the | ||
| 4846 | :term:`Build Directory`. An example | ||
| 4847 | configuration would be as follows: | ||
| 4848 | :: | ||
| 4849 | |||
| 4850 | MACHINE = "qemux86-64" | ||
| 4851 | require conf/multilib.conf | ||
| 4852 | MULTILIBS = "multilib:lib32" | ||
| 4853 | DEFAULTTUNE_virtclass-multilib-lib32 = "x86" | ||
| 4854 | IMAGE_INSTALL_append = "lib32-glib-2.0" | ||
| 4855 | |||
| 4856 | This example enables an additional library named | ||
| 4857 | ``lib32`` alongside the normal target packages. When combining these | ||
| 4858 | "lib32" alternatives, the example uses "x86" for tuning. For information | ||
| 4859 | on this particular tuning, see | ||
| 4860 | ``meta/conf/machine/include/ia32/arch-ia32.inc``. | ||
| 4861 | |||
| 4862 | The example then includes ``lib32-glib-2.0`` in all the images, which | ||
| 4863 | illustrates one method of including a multiple library dependency. You | ||
| 4864 | can use a normal image build to include this dependency, for example: | ||
| 4865 | :: | ||
| 4866 | |||
| 4867 | $ bitbake core-image-sato | ||
| 4868 | |||
| 4869 | You can also build Multilib packages | ||
| 4870 | specifically with a command like this: | ||
| 4871 | :: | ||
| 4872 | |||
| 4873 | $ bitbake lib32-glib-2.0 | ||
| 4874 | |||
| 4875 | Additional Implementation Details | ||
| 4876 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 4877 | |||
| 4878 | Generic implementation details as well as details that are specific to | ||
| 4879 | package management systems exist. Following are implementation details | ||
| 4880 | that exist regardless of the package management system: | ||
| 4881 | |||
| 4882 | - The typical convention used for the class extension code as used by | ||
| 4883 | Multilib assumes that all package names specified in | ||
| 4884 | :term:`PACKAGES` that contain | ||
| 4885 | ``${PN}`` have ``${PN}`` at the start of the name. When that | ||
| 4886 | convention is not followed and ``${PN}`` appears at the middle or the | ||
| 4887 | end of a name, problems occur. | ||
| 4888 | |||
| 4889 | - The :term:`TARGET_VENDOR` | ||
| 4890 | value under Multilib will be extended to "-vendormlmultilib" (e.g. | ||
| 4891 | "-pokymllib32" for a "lib32" Multilib with Poky). The reason for this | ||
| 4892 | slightly unwieldy contraction is that any "-" characters in the | ||
| 4893 | vendor string presently break Autoconf's ``config.sub``, and other | ||
| 4894 | separators are problematic for different reasons. | ||
| 4895 | |||
| 4896 | For the RPM Package Management System, the following implementation | ||
| 4897 | details exist: | ||
| 4898 | |||
| 4899 | - A unique architecture is defined for the Multilib packages, along | ||
| 4900 | with creating a unique deploy folder under ``tmp/deploy/rpm`` in the | ||
| 4901 | :term:`Build Directory`. For | ||
| 4902 | example, consider ``lib32`` in a ``qemux86-64`` image. The possible | ||
| 4903 | architectures in the system are "all", "qemux86_64", | ||
| 4904 | "lib32_qemux86_64", and "lib32_x86". | ||
| 4905 | |||
| 4906 | - The ``${MLPREFIX}`` variable is stripped from ``${PN}`` during RPM | ||
| 4907 | packaging. The naming for a normal RPM package and a Multilib RPM | ||
| 4908 | package in a ``qemux86-64`` system resolves to something similar to | ||
| 4909 | ``bash-4.1-r2.x86_64.rpm`` and ``bash-4.1.r2.lib32_x86.rpm``, | ||
| 4910 | respectively. | ||
| 4911 | |||
| 4912 | - When installing a Multilib image, the RPM backend first installs the | ||
| 4913 | base image and then installs the Multilib libraries. | ||
| 4914 | |||
| 4915 | - The build system relies on RPM to resolve the identical files in the | ||
| 4916 | two (or more) Multilib packages. | ||
| 4917 | |||
| 4918 | For the IPK Package Management System, the following implementation | ||
| 4919 | details exist: | ||
| 4920 | |||
| 4921 | - The ``${MLPREFIX}`` is not stripped from ``${PN}`` during IPK | ||
| 4922 | packaging. The naming for a normal RPM package and a Multilib IPK | ||
| 4923 | package in a ``qemux86-64`` system resolves to something like | ||
| 4924 | ``bash_4.1-r2.x86_64.ipk`` and ``lib32-bash_4.1-rw_x86.ipk``, | ||
| 4925 | respectively. | ||
| 4926 | |||
| 4927 | - The IPK deploy folder is not modified with ``${MLPREFIX}`` because | ||
| 4928 | packages with and without the Multilib feature can exist in the same | ||
| 4929 | folder due to the ``${PN}`` differences. | ||
| 4930 | |||
| 4931 | - IPK defines a sanity check for Multilib installation using certain | ||
| 4932 | rules for file comparison, overridden, etc. | ||
| 4933 | |||
| 4934 | Installing Multiple Versions of the Same Library | ||
| 4935 | ------------------------------------------------ | ||
| 4936 | |||
| 4937 | Situations can exist where you need to install and use multiple versions | ||
| 4938 | of the same library on the same system at the same time. These | ||
| 4939 | situations almost always exist when a library API changes and you have | ||
| 4940 | multiple pieces of software that depend on the separate versions of the | ||
| 4941 | library. To accommodate these situations, you can install multiple | ||
| 4942 | versions of the same library in parallel on the same system. | ||
| 4943 | |||
| 4944 | The process is straightforward as long as the libraries use proper | ||
| 4945 | versioning. With properly versioned libraries, all you need to do to | ||
| 4946 | individually specify the libraries is create separate, appropriately | ||
| 4947 | named recipes where the :term:`PN` part of | ||
| 4948 | the name includes a portion that differentiates each library version | ||
| 4949 | (e.g. the major part of the version number). Thus, instead of having a | ||
| 4950 | single recipe that loads one version of a library (e.g. ``clutter``), | ||
| 4951 | you provide multiple recipes that result in different versions of the | ||
| 4952 | libraries you want. As an example, the following two recipes would allow | ||
| 4953 | the two separate versions of the ``clutter`` library to co-exist on the | ||
| 4954 | same system: | ||
| 4955 | |||
| 4956 | .. code-block:: none | ||
| 4957 | |||
| 4958 | clutter-1.6_1.6.20.bb | ||
| 4959 | clutter-1.8_1.8.4.bb | ||
| 4960 | |||
| 4961 | Additionally, if | ||
| 4962 | you have other recipes that depend on a given library, you need to use | ||
| 4963 | the :term:`DEPENDS` variable to | ||
| 4964 | create the dependency. Continuing with the same example, if you want to | ||
| 4965 | have a recipe depend on the 1.8 version of the ``clutter`` library, use | ||
| 4966 | the following in your recipe: | ||
| 4967 | :: | ||
| 4968 | |||
| 4969 | DEPENDS = "clutter-1.8" | ||
| 4970 | |||
| 4971 | Using x32 psABI | ||
| 4972 | =============== | ||
| 4973 | |||
| 4974 | x32 processor-specific Application Binary Interface (`x32 | ||
| 4975 | psABI <https://software.intel.com/en-us/node/628948>`__) is a native | ||
| 4976 | 32-bit processor-specific ABI for Intel 64 (x86-64) architectures. An | ||
| 4977 | ABI defines the calling conventions between functions in a processing | ||
| 4978 | environment. The interface determines what registers are used and what | ||
| 4979 | the sizes are for various C data types. | ||
| 4980 | |||
| 4981 | Some processing environments prefer using 32-bit applications even when | ||
| 4982 | running on Intel 64-bit platforms. Consider the i386 psABI, which is a | ||
| 4983 | very old 32-bit ABI for Intel 64-bit platforms. The i386 psABI does not | ||
| 4984 | provide efficient use and access of the Intel 64-bit processor | ||
| 4985 | resources, leaving the system underutilized. Now consider the x86_64 | ||
| 4986 | psABI. This ABI is newer and uses 64-bits for data sizes and program | ||
| 4987 | pointers. The extra bits increase the footprint size of the programs, | ||
| 4988 | libraries, and also increases the memory and file system size | ||
| 4989 | requirements. Executing under the x32 psABI enables user programs to | ||
| 4990 | utilize CPU and system resources more efficiently while keeping the | ||
| 4991 | memory footprint of the applications low. Extra bits are used for | ||
| 4992 | registers but not for addressing mechanisms. | ||
| 4993 | |||
| 4994 | The Yocto Project supports the final specifications of x32 psABI as | ||
| 4995 | follows: | ||
| 4996 | |||
| 4997 | - You can create packages and images in x32 psABI format on x86_64 | ||
| 4998 | architecture targets. | ||
| 4999 | |||
| 5000 | - You can successfully build recipes with the x32 toolchain. | ||
| 5001 | |||
| 5002 | - You can create and boot ``core-image-minimal`` and | ||
| 5003 | ``core-image-sato`` images. | ||
| 5004 | |||
| 5005 | - RPM Package Manager (RPM) support exists for x32 binaries. | ||
| 5006 | |||
| 5007 | - Support for large images exists. | ||
| 5008 | |||
| 5009 | To use the x32 psABI, you need to edit your ``conf/local.conf`` | ||
| 5010 | configuration file as follows: | ||
| 5011 | :: | ||
| 5012 | |||
| 5013 | MACHINE = "qemux86-64" | ||
| 5014 | DEFAULTTUNE = "x86-64-x32" | ||
| 5015 | baselib = "${@d.getVar('BASE_LIB_tune-' + (d.getVar('DEFAULTTUNE') \ | ||
| 5016 | or 'INVALID')) or 'lib'}" | ||
| 5017 | |||
| 5018 | Once you have set | ||
| 5019 | up your configuration file, use BitBake to build an image that supports | ||
| 5020 | the x32 psABI. Here is an example: | ||
| 5021 | :: | ||
| 5022 | |||
| 5023 | $ bitbake core-image-sato | ||
| 5024 | |||
| 5025 | Enabling GObject Introspection Support | ||
| 5026 | ====================================== | ||
| 5027 | |||
| 5028 | `GObject | ||
| 5029 | introspection <https://wiki.gnome.org/Projects/GObjectIntrospection>`__ | ||
| 5030 | is the standard mechanism for accessing GObject-based software from | ||
| 5031 | runtime environments. GObject is a feature of the GLib library that | ||
| 5032 | provides an object framework for the GNOME desktop and related software. | ||
| 5033 | GObject Introspection adds information to GObject that allows objects | ||
| 5034 | created within it to be represented across different programming | ||
| 5035 | languages. If you want to construct GStreamer pipelines using Python, or | ||
| 5036 | control UPnP infrastructure using Javascript and GUPnP, GObject | ||
| 5037 | introspection is the only way to do it. | ||
| 5038 | |||
| 5039 | This section describes the Yocto Project support for generating and | ||
| 5040 | packaging GObject introspection data. GObject introspection data is a | ||
| 5041 | description of the API provided by libraries built on top of GLib | ||
| 5042 | framework, and, in particular, that framework's GObject mechanism. | ||
| 5043 | GObject Introspection Repository (GIR) files go to ``-dev`` packages, | ||
| 5044 | ``typelib`` files go to main packages as they are packaged together with | ||
| 5045 | libraries that are introspected. | ||
| 5046 | |||
| 5047 | The data is generated when building such a library, by linking the | ||
| 5048 | library with a small executable binary that asks the library to describe | ||
| 5049 | itself, and then executing the binary and processing its output. | ||
| 5050 | |||
| 5051 | Generating this data in a cross-compilation environment is difficult | ||
| 5052 | because the library is produced for the target architecture, but its | ||
| 5053 | code needs to be executed on the build host. This problem is solved with | ||
| 5054 | the OpenEmbedded build system by running the code through QEMU, which | ||
| 5055 | allows precisely that. Unfortunately, QEMU does not always work | ||
| 5056 | perfectly as mentioned in the "`Known Issues <#known-issues>`__" | ||
| 5057 | section. | ||
| 5058 | |||
| 5059 | Enabling the Generation of Introspection Data | ||
| 5060 | --------------------------------------------- | ||
| 5061 | |||
| 5062 | Enabling the generation of introspection data (GIR files) in your | ||
| 5063 | library package involves the following: | ||
| 5064 | |||
| 5065 | 1. Inherit the | ||
| 5066 | :ref:`gobject-introspection <ref-classes-gobject-introspection>` | ||
| 5067 | class. | ||
| 5068 | |||
| 5069 | 2. Make sure introspection is not disabled anywhere in the recipe or | ||
| 5070 | from anything the recipe includes. Also, make sure that | ||
| 5071 | "gobject-introspection-data" is not in | ||
| 5072 | :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED` | ||
| 5073 | and that "qemu-usermode" is not in | ||
| 5074 | :term:`MACHINE_FEATURES_BACKFILL_CONSIDERED`. | ||
| 5075 | If either of these conditions exist, nothing will happen. | ||
| 5076 | |||
| 5077 | 3. Try to build the recipe. If you encounter build errors that look like | ||
| 5078 | something is unable to find ``.so`` libraries, check where these | ||
| 5079 | libraries are located in the source tree and add the following to the | ||
| 5080 | recipe: | ||
| 5081 | :: | ||
| 5082 | |||
| 5083 | GIR_EXTRA_LIBS_PATH = "${B}/something/.libs" | ||
| 5084 | |||
| 5085 | .. note:: | ||
| 5086 | |||
| 5087 | See recipes in the ``oe-core`` repository that use that | ||
| 5088 | ``GIR_EXTRA_LIBS_PATH`` variable as an example. | ||
| 5089 | |||
| 5090 | 4. Look for any other errors, which probably mean that introspection | ||
| 5091 | support in a package is not entirely standard, and thus breaks down | ||
| 5092 | in a cross-compilation environment. For such cases, custom-made fixes | ||
| 5093 | are needed. A good place to ask and receive help in these cases is | ||
| 5094 | the :ref:`Yocto Project mailing | ||
| 5095 | lists <resources-mailinglist>`. | ||
| 5096 | |||
| 5097 | .. note:: | ||
| 5098 | |||
| 5099 | Using a library that no longer builds against the latest Yocto | ||
| 5100 | Project release and prints introspection related errors is a good | ||
| 5101 | candidate for the previous procedure. | ||
| 5102 | |||
| 5103 | Disabling the Generation of Introspection Data | ||
| 5104 | ---------------------------------------------- | ||
| 5105 | |||
| 5106 | You might find that you do not want to generate introspection data. Or, | ||
| 5107 | perhaps QEMU does not work on your build host and target architecture | ||
| 5108 | combination. If so, you can use either of the following methods to | ||
| 5109 | disable GIR file generations: | ||
| 5110 | |||
| 5111 | - Add the following to your distro configuration: | ||
| 5112 | :: | ||
| 5113 | |||
| 5114 | DISTRO_FEATURES_BACKFILL_CONSIDERED = "gobject-introspection-data" | ||
| 5115 | |||
| 5116 | Adding this statement disables generating introspection data using | ||
| 5117 | QEMU but will still enable building introspection tools and libraries | ||
| 5118 | (i.e. building them does not require the use of QEMU). | ||
| 5119 | |||
| 5120 | - Add the following to your machine configuration: | ||
| 5121 | :: | ||
| 5122 | |||
| 5123 | MACHINE_FEATURES_BACKFILL_CONSIDERED = "qemu-usermode" | ||
| 5124 | |||
| 5125 | Adding this statement disables the use of QEMU when building packages for your | ||
| 5126 | machine. Currently, this feature is used only by introspection | ||
| 5127 | recipes and has the same effect as the previously described option. | ||
| 5128 | |||
| 5129 | .. note:: | ||
| 5130 | |||
| 5131 | Future releases of the Yocto Project might have other features | ||
| 5132 | affected by this option. | ||
| 5133 | |||
| 5134 | If you disable introspection data, you can still obtain it through other | ||
| 5135 | means such as copying the data from a suitable sysroot, or by generating | ||
| 5136 | it on the target hardware. The OpenEmbedded build system does not | ||
| 5137 | currently provide specific support for these techniques. | ||
| 5138 | |||
| 5139 | Testing that Introspection Works in an Image | ||
| 5140 | -------------------------------------------- | ||
| 5141 | |||
| 5142 | Use the following procedure to test if generating introspection data is | ||
| 5143 | working in an image: | ||
| 5144 | |||
| 5145 | 1. Make sure that "gobject-introspection-data" is not in | ||
| 5146 | :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED` | ||
| 5147 | and that "qemu-usermode" is not in | ||
| 5148 | :term:`MACHINE_FEATURES_BACKFILL_CONSIDERED`. | ||
| 5149 | |||
| 5150 | 2. Build ``core-image-sato``. | ||
| 5151 | |||
| 5152 | 3. Launch a Terminal and then start Python in the terminal. | ||
| 5153 | |||
| 5154 | 4. Enter the following in the terminal: | ||
| 5155 | :: | ||
| 5156 | |||
| 5157 | >>> from gi.repository import GLib | ||
| 5158 | >>> GLib.get_host_name() | ||
| 5159 | |||
| 5160 | 5. For something a little more advanced, enter the following see: | ||
| 5161 | https://python-gtk-3-tutorial.readthedocs.io/en/latest/introduction.html | ||
| 5162 | |||
| 5163 | Known Issues | ||
| 5164 | ------------ | ||
| 5165 | |||
| 5166 | The following know issues exist for GObject Introspection Support: | ||
| 5167 | |||
| 5168 | - ``qemu-ppc64`` immediately crashes. Consequently, you cannot build | ||
| 5169 | introspection data on that architecture. | ||
| 5170 | |||
| 5171 | - x32 is not supported by QEMU. Consequently, introspection data is | ||
| 5172 | disabled. | ||
| 5173 | |||
| 5174 | - musl causes transient GLib binaries to crash on assertion failures. | ||
| 5175 | Consequently, generating introspection data is disabled. | ||
| 5176 | |||
| 5177 | - Because QEMU is not able to run the binaries correctly, introspection | ||
| 5178 | is disabled for some specific packages under specific architectures | ||
| 5179 | (e.g. ``gcr``, ``libsecret``, and ``webkit``). | ||
| 5180 | |||
| 5181 | - QEMU usermode might not work properly when running 64-bit binaries | ||
| 5182 | under 32-bit host machines. In particular, "qemumips64" is known to | ||
| 5183 | not work under i686. | ||
| 5184 | |||
| 5185 | Optionally Using an External Toolchain | ||
| 5186 | ====================================== | ||
| 5187 | |||
| 5188 | You might want to use an external toolchain as part of your development. | ||
| 5189 | If this is the case, the fundamental steps you need to accomplish are as | ||
| 5190 | follows: | ||
| 5191 | |||
| 5192 | - Understand where the installed toolchain resides. For cases where you | ||
| 5193 | need to build the external toolchain, you would need to take separate | ||
| 5194 | steps to build and install the toolchain. | ||
| 5195 | |||
| 5196 | - Make sure you add the layer that contains the toolchain to your | ||
| 5197 | ``bblayers.conf`` file through the | ||
| 5198 | :term:`BBLAYERS` variable. | ||
| 5199 | |||
| 5200 | - Set the ``EXTERNAL_TOOLCHAIN`` variable in your ``local.conf`` file | ||
| 5201 | to the location in which you installed the toolchain. | ||
| 5202 | |||
| 5203 | A good example of an external toolchain used with the Yocto Project is | ||
| 5204 | Mentor Graphics Sourcery G++ Toolchain. You can see information on how | ||
| 5205 | to use that particular layer in the ``README`` file at | ||
| 5206 | https://github.com/MentorEmbedded/meta-sourcery/. You can find | ||
| 5207 | further information by reading about the | ||
| 5208 | :term:`TCMODE` variable in the Yocto | ||
| 5209 | Project Reference Manual's variable glossary. | ||
| 5210 | |||
| 5211 | Creating Partitioned Images Using Wic | ||
| 5212 | ===================================== | ||
| 5213 | |||
| 5214 | Creating an image for a particular hardware target using the | ||
| 5215 | OpenEmbedded build system does not necessarily mean you can boot that | ||
| 5216 | image as is on your device. Physical devices accept and boot images in | ||
| 5217 | various ways depending on the specifics of the device. Usually, | ||
| 5218 | information about the hardware can tell you what image format the device | ||
| 5219 | requires. Should your device require multiple partitions on an SD card, | ||
| 5220 | flash, or an HDD, you can use the OpenEmbedded Image Creator, Wic, to | ||
| 5221 | create the properly partitioned image. | ||
| 5222 | |||
| 5223 | The ``wic`` command generates partitioned images from existing | ||
| 5224 | OpenEmbedded build artifacts. Image generation is driven by partitioning | ||
| 5225 | commands contained in an Openembedded kickstart file (``.wks``) | ||
| 5226 | specified either directly on the command line or as one of a selection | ||
| 5227 | of canned kickstart files as shown with the ``wic list images`` command | ||
| 5228 | in the "`Using an Existing Kickstart | ||
| 5229 | File <#using-a-provided-kickstart-file>`__" section. When you apply the | ||
| 5230 | command to a given set of build artifacts, the result is an image or set | ||
| 5231 | of images that can be directly written onto media and used on a | ||
| 5232 | particular system. | ||
| 5233 | |||
| 5234 | .. note:: | ||
| 5235 | |||
| 5236 | For a kickstart file reference, see the | ||
| 5237 | ":ref:`ref-manual/ref-kickstart:openembedded kickstart (\`\`.wks\`\`) reference`" | ||
| 5238 | Chapter in the Yocto Project Reference Manual. | ||
| 5239 | |||
| 5240 | The ``wic`` command and the infrastructure it is based on is by | ||
| 5241 | definition incomplete. The purpose of the command is to allow the | ||
| 5242 | generation of customized images, and as such, was designed to be | ||
| 5243 | completely extensible through a plugin interface. See the "`Using the | ||
| 5244 | Wic PlugIn Interface <#wic-using-the-wic-plugin-interface>`__" section | ||
| 5245 | for information on these plugins. | ||
| 5246 | |||
| 5247 | This section provides some background information on Wic, describes what | ||
| 5248 | you need to have in place to run the tool, provides instruction on how | ||
| 5249 | to use the Wic utility, provides information on using the Wic plugins | ||
| 5250 | interface, and provides several examples that show how to use Wic. | ||
| 5251 | |||
| 5252 | Background | ||
| 5253 | ---------- | ||
| 5254 | |||
| 5255 | This section provides some background on the Wic utility. While none of | ||
| 5256 | this information is required to use Wic, you might find it interesting. | ||
| 5257 | |||
| 5258 | - The name "Wic" is derived from OpenEmbedded Image Creator (oeic). The | ||
| 5259 | "oe" diphthong in "oeic" was promoted to the letter "w", because | ||
| 5260 | "oeic" is both difficult to remember and to pronounce. | ||
| 5261 | |||
| 5262 | - Wic is loosely based on the Meego Image Creator (``mic``) framework. | ||
| 5263 | The Wic implementation has been heavily modified to make direct use | ||
| 5264 | of OpenEmbedded build artifacts instead of package installation and | ||
| 5265 | configuration, which are already incorporated within the OpenEmbedded | ||
| 5266 | artifacts. | ||
| 5267 | |||
| 5268 | - Wic is a completely independent standalone utility that initially | ||
| 5269 | provides easier-to-use and more flexible replacements for an existing | ||
| 5270 | functionality in OE-Core's | ||
| 5271 | :ref:`image-live <ref-classes-image-live>` | ||
| 5272 | class. The difference between Wic and those examples is that with Wic | ||
| 5273 | the functionality of those scripts is implemented by a | ||
| 5274 | general-purpose partitioning language, which is based on Redhat | ||
| 5275 | kickstart syntax. | ||
| 5276 | |||
| 5277 | Requirements | ||
| 5278 | ------------ | ||
| 5279 | |||
| 5280 | In order to use the Wic utility with the OpenEmbedded Build system, your | ||
| 5281 | system needs to meet the following requirements: | ||
| 5282 | |||
| 5283 | - The Linux distribution on your development host must support the | ||
| 5284 | Yocto Project. See the ":ref:`detailed-supported-distros`" | ||
| 5285 | section in the Yocto Project Reference Manual for the list of | ||
| 5286 | distributions that support the Yocto Project. | ||
| 5287 | |||
| 5288 | - The standard system utilities, such as ``cp``, must be installed on | ||
| 5289 | your development host system. | ||
| 5290 | |||
| 5291 | - You must have sourced the build environment setup script (i.e. | ||
| 5292 | :ref:`structure-core-script`) found in the | ||
| 5293 | :term:`Build Directory`. | ||
| 5294 | |||
| 5295 | - You need to have the build artifacts already available, which | ||
| 5296 | typically means that you must have already created an image using the | ||
| 5297 | Openembedded build system (e.g. ``core-image-minimal``). While it | ||
| 5298 | might seem redundant to generate an image in order to create an image | ||
| 5299 | using Wic, the current version of Wic requires the artifacts in the | ||
| 5300 | form generated by the OpenEmbedded build system. | ||
| 5301 | |||
| 5302 | - You must build several native tools, which are built to run on the | ||
| 5303 | build system: | ||
| 5304 | :: | ||
| 5305 | |||
| 5306 | $ bitbake parted-native dosfstools-native mtools-native | ||
| 5307 | |||
| 5308 | - Include "wic" as part of the | ||
| 5309 | :term:`IMAGE_FSTYPES` | ||
| 5310 | variable. | ||
| 5311 | |||
| 5312 | - Include the name of the :ref:`wic kickstart file <openembedded-kickstart-wks-reference>` | ||
| 5313 | as part of the :term:`WKS_FILE` variable | ||
| 5314 | |||
| 5315 | Getting Help | ||
| 5316 | ------------ | ||
| 5317 | |||
| 5318 | You can get general help for the ``wic`` command by entering the ``wic`` | ||
| 5319 | command by itself or by entering the command with a help argument as | ||
| 5320 | follows: | ||
| 5321 | :: | ||
| 5322 | |||
| 5323 | $ wic -h | ||
| 5324 | $ wic --help | ||
| 5325 | $ wic help | ||
| 5326 | |||
| 5327 | Currently, Wic supports seven commands: ``cp``, ``create``, ``help``, | ||
| 5328 | ``list``, ``ls``, ``rm``, and ``write``. You can get help for all these | ||
| 5329 | commands except "help" by using the following form: | ||
| 5330 | :: | ||
| 5331 | |||
| 5332 | $ wic help command | ||
| 5333 | |||
| 5334 | For example, the following command returns help for the ``write`` | ||
| 5335 | command: | ||
| 5336 | :: | ||
| 5337 | |||
| 5338 | $ wic help write | ||
| 5339 | |||
| 5340 | Wic supports help for three topics: ``overview``, ``plugins``, and | ||
| 5341 | ``kickstart``. You can get help for any topic using the following form: | ||
| 5342 | :: | ||
| 5343 | |||
| 5344 | $ wic help topic | ||
| 5345 | |||
| 5346 | For example, the following returns overview help for Wic: | ||
| 5347 | :: | ||
| 5348 | |||
| 5349 | $ wic help overview | ||
| 5350 | |||
| 5351 | One additional level of help exists for Wic. You can get help on | ||
| 5352 | individual images through the ``list`` command. You can use the ``list`` | ||
| 5353 | command to return the available Wic images as follows: | ||
| 5354 | :: | ||
| 5355 | |||
| 5356 | $ wic list images | ||
| 5357 | genericx86 Create an EFI disk image for genericx86* | ||
| 5358 | beaglebone-yocto Create SD card image for Beaglebone | ||
| 5359 | edgerouter Create SD card image for Edgerouter | ||
| 5360 | qemux86-directdisk Create a qemu machine 'pcbios' direct disk image | ||
| 5361 | directdisk-gpt Create a 'pcbios' direct disk image | ||
| 5362 | mkefidisk Create an EFI disk image | ||
| 5363 | directdisk Create a 'pcbios' direct disk image | ||
| 5364 | systemd-bootdisk Create an EFI disk image with systemd-boot | ||
| 5365 | mkhybridiso Create a hybrid ISO image | ||
| 5366 | sdimage-bootpart Create SD card image with a boot partition | ||
| 5367 | directdisk-multi-rootfs Create multi rootfs image using rootfs plugin | ||
| 5368 | directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config | ||
| 5369 | |||
| 5370 | Once you know the list of available | ||
| 5371 | Wic images, you can use ``help`` with the command to get help on a | ||
| 5372 | particular image. For example, the following command returns help on the | ||
| 5373 | "beaglebone-yocto" image: | ||
| 5374 | :: | ||
| 5375 | |||
| 5376 | $ wic list beaglebone-yocto help | ||
| 5377 | |||
| 5378 | Creates a partitioned SD card image for Beaglebone. | ||
| 5379 | Boot files are located in the first vfat partition. | ||
| 5380 | |||
| 5381 | Operational Modes | ||
| 5382 | ----------------- | ||
| 5383 | |||
| 5384 | You can use Wic in two different modes, depending on how much control | ||
| 5385 | you need for specifying the Openembedded build artifacts that are used | ||
| 5386 | for creating the image: Raw and Cooked: | ||
| 5387 | |||
| 5388 | - *Raw Mode:* You explicitly specify build artifacts through Wic | ||
| 5389 | command-line arguments. | ||
| 5390 | |||
| 5391 | - *Cooked Mode:* The current | ||
| 5392 | :term:`MACHINE` setting and image | ||
| 5393 | name are used to automatically locate and provide the build | ||
| 5394 | artifacts. You just supply a kickstart file and the name of the image | ||
| 5395 | from which to use artifacts. | ||
| 5396 | |||
| 5397 | Regardless of the mode you use, you need to have the build artifacts | ||
| 5398 | ready and available. | ||
| 5399 | |||
| 5400 | Raw Mode | ||
| 5401 | ~~~~~~~~ | ||
| 5402 | |||
| 5403 | Running Wic in raw mode allows you to specify all the partitions through | ||
| 5404 | the ``wic`` command line. The primary use for raw mode is if you have | ||
| 5405 | built your kernel outside of the Yocto Project | ||
| 5406 | :term:`Build Directory`. In other words, you | ||
| 5407 | can point to arbitrary kernel, root filesystem locations, and so forth. | ||
| 5408 | Contrast this behavior with cooked mode where Wic looks in the Build | ||
| 5409 | Directory (e.g. ``tmp/deploy/images/``\ machine). | ||
| 5410 | |||
| 5411 | The general form of the ``wic`` command in raw mode is: | ||
| 5412 | :: | ||
| 5413 | |||
| 5414 | $ wic create wks_file options ... | ||
| 5415 | |||
| 5416 | Where: | ||
| 5417 | |||
| 5418 | wks_file: | ||
| 5419 | An OpenEmbedded kickstart file. You can provide | ||
| 5420 | your own custom file or use a file from a set of | ||
| 5421 | existing files as described by further options. | ||
| 5422 | |||
| 5423 | optional arguments: | ||
| 5424 | -h, --help show this help message and exit | ||
| 5425 | -o OUTDIR, --outdir OUTDIR | ||
| 5426 | name of directory to create image in | ||
| 5427 | -e IMAGE_NAME, --image-name IMAGE_NAME | ||
| 5428 | name of the image to use the artifacts from e.g. core- | ||
| 5429 | image-sato | ||
| 5430 | -r ROOTFS_DIR, --rootfs-dir ROOTFS_DIR | ||
| 5431 | path to the /rootfs dir to use as the .wks rootfs | ||
| 5432 | source | ||
| 5433 | -b BOOTIMG_DIR, --bootimg-dir BOOTIMG_DIR | ||
| 5434 | path to the dir containing the boot artifacts (e.g. | ||
| 5435 | /EFI or /syslinux dirs) to use as the .wks bootimg | ||
| 5436 | source | ||
| 5437 | -k KERNEL_DIR, --kernel-dir KERNEL_DIR | ||
| 5438 | path to the dir containing the kernel to use in the | ||
| 5439 | .wks bootimg | ||
| 5440 | -n NATIVE_SYSROOT, --native-sysroot NATIVE_SYSROOT | ||
| 5441 | path to the native sysroot containing the tools to use | ||
| 5442 | to build the image | ||
| 5443 | -s, --skip-build-check | ||
| 5444 | skip the build check | ||
| 5445 | -f, --build-rootfs build rootfs | ||
| 5446 | -c {gzip,bzip2,xz}, --compress-with {gzip,bzip2,xz} | ||
| 5447 | compress image with specified compressor | ||
| 5448 | -m, --bmap generate .bmap | ||
| 5449 | --no-fstab-update Do not change fstab file. | ||
| 5450 | -v VARS_DIR, --vars VARS_DIR | ||
| 5451 | directory with <image>.env files that store bitbake | ||
| 5452 | variables | ||
| 5453 | -D, --debug output debug information | ||
| 5454 | |||
| 5455 | .. note:: | ||
| 5456 | |||
| 5457 | You do not need root privileges to run Wic. In fact, you should not | ||
| 5458 | run as root when using the utility. | ||
| 5459 | |||
| 5460 | Cooked Mode | ||
| 5461 | ~~~~~~~~~~~ | ||
| 5462 | |||
| 5463 | Running Wic in cooked mode leverages off artifacts in the Build | ||
| 5464 | Directory. In other words, you do not have to specify kernel or root | ||
| 5465 | filesystem locations as part of the command. All you need to provide is | ||
| 5466 | a kickstart file and the name of the image from which to use artifacts | ||
| 5467 | by using the "-e" option. Wic looks in the Build Directory (e.g. | ||
| 5468 | ``tmp/deploy/images/``\ machine) for artifacts. | ||
| 5469 | |||
| 5470 | The general form of the ``wic`` command using Cooked Mode is as follows: | ||
| 5471 | :: | ||
| 5472 | |||
| 5473 | $ wic create wks_file -e IMAGE_NAME | ||
| 5474 | |||
| 5475 | Where: | ||
| 5476 | |||
| 5477 | wks_file: | ||
| 5478 | An OpenEmbedded kickstart file. You can provide | ||
| 5479 | your own custom file or use a file from a set of | ||
| 5480 | existing files provided with the Yocto Project | ||
| 5481 | release. | ||
| 5482 | |||
| 5483 | required argument: | ||
| 5484 | -e IMAGE_NAME, --image-name IMAGE_NAME | ||
| 5485 | name of the image to use the artifacts from e.g. core- | ||
| 5486 | image-sato | ||
| 5487 | |||
| 5488 | Using an Existing Kickstart File | ||
| 5489 | -------------------------------- | ||
| 5490 | |||
| 5491 | If you do not want to create your own kickstart file, you can use an | ||
| 5492 | existing file provided by the Wic installation. As shipped, kickstart | ||
| 5493 | files can be found in the :ref:`overview-manual/overview-manual-development-environment:yocto project source repositories` in the | ||
| 5494 | following two locations: | ||
| 5495 | :: | ||
| 5496 | |||
| 5497 | poky/meta-yocto-bsp/wic | ||
| 5498 | poky/scripts/lib/wic/canned-wks | ||
| 5499 | |||
| 5500 | Use the following command to list the available kickstart files: | ||
| 5501 | :: | ||
| 5502 | |||
| 5503 | $ wic list images | ||
| 5504 | genericx86 Create an EFI disk image for genericx86* | ||
| 5505 | beaglebone-yocto Create SD card image for Beaglebone | ||
| 5506 | edgerouter Create SD card image for Edgerouter | ||
| 5507 | qemux86-directdisk Create a qemu machine 'pcbios' direct disk image | ||
| 5508 | directdisk-gpt Create a 'pcbios' direct disk image | ||
| 5509 | mkefidisk Create an EFI disk image | ||
| 5510 | directdisk Create a 'pcbios' direct disk image | ||
| 5511 | systemd-bootdisk Create an EFI disk image with systemd-boot | ||
| 5512 | mkhybridiso Create a hybrid ISO image | ||
| 5513 | sdimage-bootpart Create SD card image with a boot partition | ||
| 5514 | directdisk-multi-rootfs Create multi rootfs image using rootfs plugin | ||
| 5515 | directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config | ||
| 5516 | |||
| 5517 | When you use an existing file, you | ||
| 5518 | do not have to use the ``.wks`` extension. Here is an example in Raw | ||
| 5519 | Mode that uses the ``directdisk`` file: | ||
| 5520 | :: | ||
| 5521 | |||
| 5522 | $ wic create directdisk -r rootfs_dir -b bootimg_dir \ | ||
| 5523 | -k kernel_dir -n native_sysroot | ||
| 5524 | |||
| 5525 | Here are the actual partition language commands used in the | ||
| 5526 | ``genericx86.wks`` file to generate an image: | ||
| 5527 | :: | ||
| 5528 | |||
| 5529 | # short-description: Create an EFI disk image for genericx86* | ||
| 5530 | # long-description: Creates a partitioned EFI disk image for genericx86* machines | ||
| 5531 | part /boot --source bootimg-efi --sourceparams="loader=grub-efi" --ondisk sda --label msdos --active --align 1024 | ||
| 5532 | part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid | ||
| 5533 | part swap --ondisk sda --size 44 --label swap1 --fstype=swap | ||
| 5534 | |||
| 5535 | bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=ttyS0,115200 console=tty0" | ||
| 5536 | |||
| 5537 | Using the Wic Plugin Interface | ||
| 5538 | ------------------------------ | ||
| 5539 | |||
| 5540 | You can extend and specialize Wic functionality by using Wic plugins. | ||
| 5541 | This section explains the Wic plugin interface. | ||
| 5542 | |||
| 5543 | .. note:: | ||
| 5544 | |||
| 5545 | Wic plugins consist of "source" and "imager" plugins. Imager plugins | ||
| 5546 | are beyond the scope of this section. | ||
| 5547 | |||
| 5548 | Source plugins provide a mechanism to customize partition content during | ||
| 5549 | the Wic image generation process. You can use source plugins to map | ||
| 5550 | values that you specify using ``--source`` commands in kickstart files | ||
| 5551 | (i.e. ``*.wks``) to a plugin implementation used to populate a given | ||
| 5552 | partition. | ||
| 5553 | |||
| 5554 | .. note:: | ||
| 5555 | |||
| 5556 | If you use plugins that have build-time dependencies (e.g. native | ||
| 5557 | tools, bootloaders, and so forth) when building a Wic image, you need | ||
| 5558 | to specify those dependencies using the :term:`WKS_FILE_DEPENDS` | ||
| 5559 | variable. | ||
| 5560 | |||
| 5561 | Source plugins are subclasses defined in plugin files. As shipped, the | ||
| 5562 | Yocto Project provides several plugin files. You can see the source | ||
| 5563 | plugin files that ship with the Yocto Project | ||
| 5564 | :yocto_git:`here </poky/tree/scripts/lib/wic/plugins/source>`. | ||
| 5565 | Each of these plugin files contains source plugins that are designed to | ||
| 5566 | populate a specific Wic image partition. | ||
| 5567 | |||
| 5568 | Source plugins are subclasses of the ``SourcePlugin`` class, which is | ||
| 5569 | defined in the ``poky/scripts/lib/wic/pluginbase.py`` file. For example, | ||
| 5570 | the ``BootimgEFIPlugin`` source plugin found in the ``bootimg-efi.py`` | ||
| 5571 | file is a subclass of the ``SourcePlugin`` class, which is found in the | ||
| 5572 | ``pluginbase.py`` file. | ||
| 5573 | |||
| 5574 | You can also implement source plugins in a layer outside of the Source | ||
| 5575 | Repositories (external layer). To do so, be sure that your plugin files | ||
| 5576 | are located in a directory whose path is | ||
| 5577 | ``scripts/lib/wic/plugins/source/`` within your external layer. When the | ||
| 5578 | plugin files are located there, the source plugins they contain are made | ||
| 5579 | available to Wic. | ||
| 5580 | |||
| 5581 | When the Wic implementation needs to invoke a partition-specific | ||
| 5582 | implementation, it looks for the plugin with the same name as the | ||
| 5583 | ``--source`` parameter used in the kickstart file given to that | ||
| 5584 | partition. For example, if the partition is set up using the following | ||
| 5585 | command in a kickstart file: | ||
| 5586 | :: | ||
| 5587 | |||
| 5588 | part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024 | ||
| 5589 | |||
| 5590 | The methods defined as class | ||
| 5591 | members of the matching source plugin (i.e. ``bootimg-pcbios``) in the | ||
| 5592 | ``bootimg-pcbios.py`` plugin file are used. | ||
| 5593 | |||
| 5594 | To be more concrete, here is the corresponding plugin definition from | ||
| 5595 | the ``bootimg-pcbios.py`` file for the previous command along with an | ||
| 5596 | example method called by the Wic implementation when it needs to prepare | ||
| 5597 | a partition using an implementation-specific function: | ||
| 5598 | :: | ||
| 5599 | |||
| 5600 | . | ||
| 5601 | . | ||
| 5602 | . | ||
| 5603 | class BootimgPcbiosPlugin(SourcePlugin): | ||
| 5604 | """ | ||
| 5605 | Create MBR boot partition and install syslinux on it. | ||
| 5606 | """ | ||
| 5607 | |||
| 5608 | name = 'bootimg-pcbios' | ||
| 5609 | . | ||
| 5610 | . | ||
| 5611 | . | ||
| 5612 | @classmethod | ||
| 5613 | def do_prepare_partition(cls, part, source_params, creator, cr_workdir, | ||
| 5614 | oe_builddir, bootimg_dir, kernel_dir, | ||
| 5615 | rootfs_dir, native_sysroot): | ||
| 5616 | """ | ||
| 5617 | Called to do the actual content population for a partition i.e. it | ||
| 5618 | 'prepares' the partition to be incorporated into the image. | ||
| 5619 | In this case, prepare content for legacy bios boot partition. | ||
| 5620 | """ | ||
| 5621 | . | ||
| 5622 | . | ||
| 5623 | . | ||
| 5624 | |||
| 5625 | If a | ||
| 5626 | subclass (plugin) itself does not implement a particular function, Wic | ||
| 5627 | locates and uses the default version in the superclass. It is for this | ||
| 5628 | reason that all source plugins are derived from the ``SourcePlugin`` | ||
| 5629 | class. | ||
| 5630 | |||
| 5631 | The ``SourcePlugin`` class defined in the ``pluginbase.py`` file defines | ||
| 5632 | a set of methods that source plugins can implement or override. Any | ||
| 5633 | plugins (subclass of ``SourcePlugin``) that do not implement a | ||
| 5634 | particular method inherit the implementation of the method from the | ||
| 5635 | ``SourcePlugin`` class. For more information, see the ``SourcePlugin`` | ||
| 5636 | class in the ``pluginbase.py`` file for details: | ||
| 5637 | |||
| 5638 | The following list describes the methods implemented in the | ||
| 5639 | ``SourcePlugin`` class: | ||
| 5640 | |||
| 5641 | - ``do_prepare_partition()``: Called to populate a partition with | ||
| 5642 | actual content. In other words, the method prepares the final | ||
| 5643 | partition image that is incorporated into the disk image. | ||
| 5644 | |||
| 5645 | - ``do_configure_partition()``: Called before | ||
| 5646 | ``do_prepare_partition()`` to create custom configuration files for a | ||
| 5647 | partition (e.g. syslinux or grub configuration files). | ||
| 5648 | |||
| 5649 | - ``do_install_disk()``: Called after all partitions have been | ||
| 5650 | prepared and assembled into a disk image. This method provides a hook | ||
| 5651 | to allow finalization of a disk image (e.g. writing an MBR). | ||
| 5652 | |||
| 5653 | - ``do_stage_partition()``: Special content-staging hook called | ||
| 5654 | before ``do_prepare_partition()``. This method is normally empty. | ||
| 5655 | |||
| 5656 | Typically, a partition just uses the passed-in parameters (e.g. the | ||
| 5657 | unmodified value of ``bootimg_dir``). However, in some cases, things | ||
| 5658 | might need to be more tailored. As an example, certain files might | ||
| 5659 | additionally need to be taken from ``bootimg_dir + /boot``. This hook | ||
| 5660 | allows those files to be staged in a customized fashion. | ||
| 5661 | |||
| 5662 | .. note:: | ||
| 5663 | |||
| 5664 | ``get_bitbake_var()`` allows you to access non-standard variables that | ||
| 5665 | you might want to use for this behavior. | ||
| 5666 | |||
| 5667 | You can extend the source plugin mechanism. To add more hooks, create | ||
| 5668 | more source plugin methods within ``SourcePlugin`` and the corresponding | ||
| 5669 | derived subclasses. The code that calls the plugin methods uses the | ||
| 5670 | ``plugin.get_source_plugin_methods()`` function to find the method or | ||
| 5671 | methods needed by the call. Retrieval of those methods is accomplished | ||
| 5672 | by filling up a dict with keys that contain the method names of | ||
| 5673 | interest. On success, these will be filled in with the actual methods. | ||
| 5674 | See the Wic implementation for examples and details. | ||
| 5675 | |||
| 5676 | Wic Examples | ||
| 5677 | ------------ | ||
| 5678 | |||
| 5679 | This section provides several examples that show how to use the Wic | ||
| 5680 | utility. All the examples assume the list of requirements in the | ||
| 5681 | "`Requirements <#wic-requirements>`__" section have been met. The | ||
| 5682 | examples assume the previously generated image is | ||
| 5683 | ``core-image-minimal``. | ||
| 5684 | |||
| 5685 | Generate an Image using an Existing Kickstart File | ||
| 5686 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 5687 | |||
| 5688 | This example runs in Cooked Mode and uses the ``mkefidisk`` kickstart | ||
| 5689 | file: | ||
| 5690 | :: | ||
| 5691 | |||
| 5692 | $ wic create mkefidisk -e core-image-minimal | ||
| 5693 | INFO: Building wic-tools... | ||
| 5694 | . | ||
| 5695 | . | ||
| 5696 | . | ||
| 5697 | INFO: The new image(s) can be found here: | ||
| 5698 | ./mkefidisk-201804191017-sda.direct | ||
| 5699 | |||
| 5700 | The following build artifacts were used to create the image(s): | ||
| 5701 | ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs | ||
| 5702 | BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share | ||
| 5703 | KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86 | ||
| 5704 | NATIVE_SYSROOT: /home/stephano/build/master/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native | ||
| 5705 | |||
| 5706 | INFO: The image(s) were created using OE kickstart file: | ||
| 5707 | /home/stephano/build/master/openembedded-core/scripts/lib/wic/canned-wks/mkefidisk.wks | ||
| 5708 | |||
| 5709 | The previous example shows the easiest way to create an image by running | ||
| 5710 | in cooked mode and supplying a kickstart file and the "-e" option to | ||
| 5711 | point to the existing build artifacts. Your ``local.conf`` file needs to | ||
| 5712 | have the :term:`MACHINE` variable set | ||
| 5713 | to the machine you are using, which is "qemux86" in this example. | ||
| 5714 | |||
| 5715 | Once the image builds, the output provides image location, artifact use, | ||
| 5716 | and kickstart file information. | ||
| 5717 | |||
| 5718 | .. note:: | ||
| 5719 | |||
| 5720 | You should always verify the details provided in the output to make | ||
| 5721 | sure that the image was indeed created exactly as expected. | ||
| 5722 | |||
| 5723 | Continuing with the example, you can now write the image from the Build | ||
| 5724 | Directory onto a USB stick, or whatever media for which you built your | ||
| 5725 | image, and boot from the media. You can write the image by using | ||
| 5726 | ``bmaptool`` or ``dd``: | ||
| 5727 | :: | ||
| 5728 | |||
| 5729 | $ oe-run-native bmaptool copy mkefidisk-201804191017-sda.direct /dev/sdX | ||
| 5730 | |||
| 5731 | or :: | ||
| 5732 | |||
| 5733 | $ sudo dd if=mkefidisk-201804191017-sda.direct of=/dev/sdX | ||
| 5734 | |||
| 5735 | .. note:: | ||
| 5736 | |||
| 5737 | For more information on how to use the ``bmaptool`` | ||
| 5738 | to flash a device with an image, see the | ||
| 5739 | ":ref:`dev-manual/common-tasks:flashing images using \`\`bmaptool\`\``" | ||
| 5740 | section. | ||
| 5741 | |||
| 5742 | Using a Modified Kickstart File | ||
| 5743 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 5744 | |||
| 5745 | Because partitioned image creation is driven by the kickstart file, it | ||
| 5746 | is easy to affect image creation by changing the parameters in the file. | ||
| 5747 | This next example demonstrates that through modification of the | ||
| 5748 | ``directdisk-gpt`` kickstart file. | ||
| 5749 | |||
| 5750 | As mentioned earlier, you can use the command ``wic list images`` to | ||
| 5751 | show the list of existing kickstart files. The directory in which the | ||
| 5752 | ``directdisk-gpt.wks`` file resides is | ||
| 5753 | ``scripts/lib/image/canned-wks/``, which is located in the | ||
| 5754 | :term:`Source Directory` (e.g. ``poky``). | ||
| 5755 | Because available files reside in this directory, you can create and add | ||
| 5756 | your own custom files to the directory. Subsequent use of the | ||
| 5757 | ``wic list images`` command would then include your kickstart files. | ||
| 5758 | |||
| 5759 | In this example, the existing ``directdisk-gpt`` file already does most | ||
| 5760 | of what is needed. However, for the hardware in this example, the image | ||
| 5761 | will need to boot from ``sdb`` instead of ``sda``, which is what the | ||
| 5762 | ``directdisk-gpt`` kickstart file uses. | ||
| 5763 | |||
| 5764 | The example begins by making a copy of the ``directdisk-gpt.wks`` file | ||
| 5765 | in the ``scripts/lib/image/canned-wks`` directory and then by changing | ||
| 5766 | the lines that specify the target disk from which to boot. | ||
| 5767 | :: | ||
| 5768 | |||
| 5769 | $ cp /home/stephano/poky/scripts/lib/wic/canned-wks/directdisk-gpt.wks \ | ||
| 5770 | /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks | ||
| 5771 | |||
| 5772 | Next, the example modifies the ``directdisksdb-gpt.wks`` file and | ||
| 5773 | changes all instances of "``--ondisk sda``" to "``--ondisk sdb``". The | ||
| 5774 | example changes the following two lines and leaves the remaining lines | ||
| 5775 | untouched: | ||
| 5776 | :: | ||
| 5777 | |||
| 5778 | part /boot --source bootimg-pcbios --ondisk sdb --label boot --active --align 1024 | ||
| 5779 | part / --source rootfs --ondisk sdb --fstype=ext4 --label platform --align 1024 --use-uuid | ||
| 5780 | |||
| 5781 | Once the lines are changed, the | ||
| 5782 | example generates the ``directdisksdb-gpt`` image. The command points | ||
| 5783 | the process at the ``core-image-minimal`` artifacts for the Next Unit of | ||
| 5784 | Computing (nuc) :term:`MACHINE` the | ||
| 5785 | ``local.conf``. | ||
| 5786 | :: | ||
| 5787 | |||
| 5788 | $ wic create directdisksdb-gpt -e core-image-minimal | ||
| 5789 | INFO: Building wic-tools... | ||
| 5790 | . | ||
| 5791 | . | ||
| 5792 | . | ||
| 5793 | Initialising tasks: 100% |#######################################| Time: 0:00:01 | ||
| 5794 | NOTE: Executing SetScene Tasks | ||
| 5795 | NOTE: Executing RunQueue Tasks | ||
| 5796 | NOTE: Tasks Summary: Attempted 1161 tasks of which 1157 didn't need to be rerun and all succeeded. | ||
| 5797 | INFO: Creating image(s)... | ||
| 5798 | |||
| 5799 | INFO: The new image(s) can be found here: | ||
| 5800 | ./directdisksdb-gpt-201710090938-sdb.direct | ||
| 5801 | |||
| 5802 | The following build artifacts were used to create the image(s): | ||
| 5803 | ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs | ||
| 5804 | BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share | ||
| 5805 | KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86 | ||
| 5806 | NATIVE_SYSROOT: /home/stephano/build/master/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native | ||
| 5807 | |||
| 5808 | INFO: The image(s) were created using OE kickstart file: | ||
| 5809 | /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks | ||
| 5810 | |||
| 5811 | Continuing with the example, you can now directly ``dd`` the image to a | ||
| 5812 | USB stick, or whatever media for which you built your image, and boot | ||
| 5813 | the resulting media: | ||
| 5814 | :: | ||
| 5815 | |||
| 5816 | $ sudo dd if=directdisksdb-gpt-201710090938-sdb.direct of=/dev/sdb | ||
| 5817 | 140966+0 records in | ||
| 5818 | 140966+0 records out | ||
| 5819 | 72174592 bytes (72 MB, 69 MiB) copied, 78.0282 s, 925 kB/s | ||
| 5820 | $ sudo eject /dev/sdb | ||
| 5821 | |||
| 5822 | Using a Modified Kickstart File and Running in Raw Mode | ||
| 5823 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 5824 | |||
| 5825 | This next example manually specifies each build artifact (runs in Raw | ||
| 5826 | Mode) and uses a modified kickstart file. The example also uses the | ||
| 5827 | ``-o`` option to cause Wic to create the output somewhere other than the | ||
| 5828 | default output directory, which is the current directory: | ||
| 5829 | :: | ||
| 5830 | |||
| 5831 | $ wic create /home/stephano/my_yocto/test.wks -o /home/stephano/testwic \ | ||
| 5832 | --rootfs-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/rootfs \ | ||
| 5833 | --bootimg-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share \ | ||
| 5834 | --kernel-dir /home/stephano/build/master/build/tmp/deploy/images/qemux86 \ | ||
| 5835 | --native-sysroot /home/stephano/build/master/build/tmp/work/i586-poky-linux/wic-tools/1.0-r0/recipe-sysroot-native | ||
| 5836 | |||
| 5837 | INFO: Creating image(s)... | ||
| 5838 | |||
| 5839 | INFO: The new image(s) can be found here: | ||
| 5840 | /home/stephano/testwic/test-201710091445-sdb.direct | ||
| 5841 | |||
| 5842 | The following build artifacts were used to create the image(s): | ||
| 5843 | ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs | ||
| 5844 | BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share | ||
| 5845 | KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86 | ||
| 5846 | NATIVE_SYSROOT: /home/stephano/build/master/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native | ||
| 5847 | |||
| 5848 | INFO: The image(s) were created using OE kickstart file: | ||
| 5849 | /home/stephano/my_yocto/test.wks | ||
| 5850 | |||
| 5851 | For this example, | ||
| 5852 | :term:`MACHINE` did not have to be | ||
| 5853 | specified in the ``local.conf`` file since the artifact is manually | ||
| 5854 | specified. | ||
| 5855 | |||
| 5856 | Using Wic to Manipulate an Image | ||
| 5857 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 5858 | |||
| 5859 | Wic image manipulation allows you to shorten turnaround time during | ||
| 5860 | image development. For example, you can use Wic to delete the kernel | ||
| 5861 | partition of a Wic image and then insert a newly built kernel. This | ||
| 5862 | saves you time from having to rebuild the entire image each time you | ||
| 5863 | modify the kernel. | ||
| 5864 | |||
| 5865 | .. note:: | ||
| 5866 | |||
| 5867 | In order to use Wic to manipulate a Wic image as in this example, | ||
| 5868 | your development machine must have the ``mtools`` package installed. | ||
| 5869 | |||
| 5870 | The following example examines the contents of the Wic image, deletes | ||
| 5871 | the existing kernel, and then inserts a new kernel: | ||
| 5872 | |||
| 5873 | 1. *List the Partitions:* Use the ``wic ls`` command to list all the | ||
| 5874 | partitions in the Wic image: | ||
| 5875 | :: | ||
| 5876 | |||
| 5877 | $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic | ||
| 5878 | Num Start End Size Fstype | ||
| 5879 | 1 1048576 25041919 23993344 fat16 | ||
| 5880 | 2 25165824 72157183 46991360 ext4 | ||
| 5881 | |||
| 5882 | The previous output shows two partitions in the | ||
| 5883 | ``core-image-minimal-qemux86.wic`` image. | ||
| 5884 | |||
| 5885 | 2. *Examine a Particular Partition:* Use the ``wic ls`` command again | ||
| 5886 | but in a different form to examine a particular partition. | ||
| 5887 | |||
| 5888 | .. note:: | ||
| 5889 | |||
| 5890 | You can get command usage on any Wic command using the following | ||
| 5891 | form: | ||
| 5892 | :: | ||
| 5893 | |||
| 5894 | $ wic help command | ||
| 5895 | |||
| 5896 | |||
| 5897 | For example, the following command shows you the various ways to | ||
| 5898 | use the | ||
| 5899 | wic ls | ||
| 5900 | command: | ||
| 5901 | :: | ||
| 5902 | |||
| 5903 | $ wic help ls | ||
| 5904 | |||
| 5905 | |||
| 5906 | The following command shows what is in Partition one: | ||
| 5907 | :: | ||
| 5908 | |||
| 5909 | $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1 | ||
| 5910 | Volume in drive : is boot | ||
| 5911 | Volume Serial Number is E894-1809 | ||
| 5912 | Directory for ::/ | ||
| 5913 | |||
| 5914 | libcom32 c32 186500 2017-10-09 16:06 | ||
| 5915 | libutil c32 24148 2017-10-09 16:06 | ||
| 5916 | syslinux cfg 220 2017-10-09 16:06 | ||
| 5917 | vesamenu c32 27104 2017-10-09 16:06 | ||
| 5918 | vmlinuz 6904608 2017-10-09 16:06 | ||
| 5919 | 5 files 7 142 580 bytes | ||
| 5920 | 16 582 656 bytes free | ||
| 5921 | |||
| 5922 | The previous output shows five files, with the | ||
| 5923 | ``vmlinuz`` being the kernel. | ||
| 5924 | |||
| 5925 | .. note:: | ||
| 5926 | |||
| 5927 | If you see the following error, you need to update or create a | ||
| 5928 | ``~/.mtoolsrc`` file and be sure to have the line "mtools_skip_check=1" | ||
| 5929 | in the file. Then, run the Wic command again: | ||
| 5930 | :: | ||
| 5931 | |||
| 5932 | ERROR: _exec_cmd: /usr/bin/mdir -i /tmp/wic-parttfokuwra ::/ returned '1' instead of 0 | ||
| 5933 | output: Total number of sectors (47824) not a multiple of sectors per track (32)! | ||
| 5934 | Add mtools_skip_check=1 to your .mtoolsrc file to skip this test | ||
| 5935 | |||
| 5936 | |||
| 5937 | 3. *Remove the Old Kernel:* Use the ``wic rm`` command to remove the | ||
| 5938 | ``vmlinuz`` file (kernel): | ||
| 5939 | :: | ||
| 5940 | |||
| 5941 | $ wic rm tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz | ||
| 5942 | |||
| 5943 | 4. *Add In the New Kernel:* Use the ``wic cp`` command to add the | ||
| 5944 | updated kernel to the Wic image. Depending on how you built your | ||
| 5945 | kernel, it could be in different places. If you used ``devtool`` and | ||
| 5946 | an SDK to build your kernel, it resides in the ``tmp/work`` directory | ||
| 5947 | of the extensible SDK. If you used ``make`` to build the kernel, the | ||
| 5948 | kernel will be in the ``workspace/sources`` area. | ||
| 5949 | |||
| 5950 | The following example assumes ``devtool`` was used to build the | ||
| 5951 | kernel: | ||
| 5952 | :: | ||
| 5953 | |||
| 5954 | 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 \ | ||
| 5955 | ~/poky/build/tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz | ||
| 5956 | |||
| 5957 | Once the new kernel is added back into the image, you can use the | ||
| 5958 | ``dd`` command or :ref:`bmaptool | ||
| 5959 | <dev-manual/common-tasks:flashing images using \`\`bmaptool\`\`>` | ||
| 5960 | to flash your wic image onto an SD card or USB stick and test your | ||
| 5961 | target. | ||
| 5962 | |||
| 5963 | .. note:: | ||
| 5964 | |||
| 5965 | Using ``bmaptool`` is generally 10 to 20 times faster than using ``dd``. | ||
| 5966 | |||
| 5967 | Flashing Images Using ``bmaptool`` | ||
| 5968 | ================================== | ||
| 5969 | |||
| 5970 | A fast and easy way to flash an image to a bootable device is to use | ||
| 5971 | Bmaptool, which is integrated into the OpenEmbedded build system. | ||
| 5972 | Bmaptool is a generic tool that creates a file's block map (bmap) and | ||
| 5973 | then uses that map to copy the file. As compared to traditional tools | ||
| 5974 | such as dd or cp, Bmaptool can copy (or flash) large files like raw | ||
| 5975 | system image files much faster. | ||
| 5976 | |||
| 5977 | .. note:: | ||
| 5978 | |||
| 5979 | - If you are using Ubuntu or Debian distributions, you can install | ||
| 5980 | the ``bmap-tools`` package using the following command and then | ||
| 5981 | use the tool without specifying ``PATH`` even from the root | ||
| 5982 | account: | ||
| 5983 | :: | ||
| 5984 | |||
| 5985 | $ sudo apt-get install bmap-tools | ||
| 5986 | |||
| 5987 | - If you are unable to install the ``bmap-tools`` package, you will | ||
| 5988 | need to build Bmaptool before using it. Use the following command: | ||
| 5989 | :: | ||
| 5990 | |||
| 5991 | $ bitbake bmap-tools-native | ||
| 5992 | |||
| 5993 | Following, is an example that shows how to flash a Wic image. Realize | ||
| 5994 | that while this example uses a Wic image, you can use Bmaptool to flash | ||
| 5995 | any type of image. Use these steps to flash an image using Bmaptool: | ||
| 5996 | |||
| 5997 | 1. *Update your local.conf File:* You need to have the following set | ||
| 5998 | in your ``local.conf`` file before building your image: | ||
| 5999 | :: | ||
| 6000 | |||
| 6001 | IMAGE_FSTYPES += "wic wic.bmap" | ||
| 6002 | |||
| 6003 | 2. *Get Your Image:* Either have your image ready (pre-built with the | ||
| 6004 | :term:`IMAGE_FSTYPES` | ||
| 6005 | setting previously mentioned) or take the step to build the image: | ||
| 6006 | :: | ||
| 6007 | |||
| 6008 | $ bitbake image | ||
| 6009 | |||
| 6010 | 3. *Flash the Device:* Flash the device with the image by using Bmaptool | ||
| 6011 | depending on your particular setup. The following commands assume the | ||
| 6012 | image resides in the Build Directory's ``deploy/images/`` area: | ||
| 6013 | |||
| 6014 | - If you have write access to the media, use this command form: | ||
| 6015 | :: | ||
| 6016 | |||
| 6017 | $ oe-run-native bmap-tools-native bmaptool copy build-directory/tmp/deploy/images/machine/image.wic /dev/sdX | ||
| 6018 | |||
| 6019 | - If you do not have write access to the media, set your permissions | ||
| 6020 | first and then use the same command form: | ||
| 6021 | :: | ||
| 6022 | |||
| 6023 | $ sudo chmod 666 /dev/sdX | ||
| 6024 | $ oe-run-native bmap-tools-native bmaptool copy build-directory/tmp/deploy/images/machine/image.wic /dev/sdX | ||
| 6025 | |||
| 6026 | For help on the ``bmaptool`` command, use the following command: | ||
| 6027 | :: | ||
| 6028 | |||
| 6029 | $ bmaptool --help | ||
| 6030 | |||
| 6031 | Making Images More Secure | ||
| 6032 | ========================= | ||
| 6033 | |||
| 6034 | Security is of increasing concern for embedded devices. Consider the | ||
| 6035 | issues and problems discussed in just this sampling of work found across | ||
| 6036 | the Internet: | ||
| 6037 | |||
| 6038 | - *"*\ `Security Risks of Embedded | ||
| 6039 | Systems <https://www.schneier.com/blog/archives/2014/01/security_risks_9.html>`__\ *"* | ||
| 6040 | by Bruce Schneier | ||
| 6041 | |||
| 6042 | - *"*\ `Internet Census | ||
| 6043 | 2012 <http://census2012.sourceforge.net/paper.html>`__\ *"* by Carna | ||
| 6044 | Botnet | ||
| 6045 | |||
| 6046 | - *"*\ `Security Issues for Embedded | ||
| 6047 | Devices <http://elinux.org/images/6/6f/Security-issues.pdf>`__\ *"* | ||
| 6048 | by Jake Edge | ||
| 6049 | |||
| 6050 | When securing your image is of concern, there are steps, tools, and | ||
| 6051 | variables that you can consider to help you reach the security goals you | ||
| 6052 | need for your particular device. Not all situations are identical when | ||
| 6053 | it comes to making an image secure. Consequently, this section provides | ||
| 6054 | some guidance and suggestions for consideration when you want to make | ||
| 6055 | your image more secure. | ||
| 6056 | |||
| 6057 | .. note:: | ||
| 6058 | |||
| 6059 | Because the security requirements and risks are different for every | ||
| 6060 | type of device, this section cannot provide a complete reference on | ||
| 6061 | securing your custom OS. It is strongly recommended that you also | ||
| 6062 | consult other sources of information on embedded Linux system | ||
| 6063 | hardening and on security. | ||
| 6064 | |||
| 6065 | General Considerations | ||
| 6066 | ---------------------- | ||
| 6067 | |||
| 6068 | General considerations exist that help you create more secure images. | ||
| 6069 | You should consider the following suggestions to help make your device | ||
| 6070 | more secure: | ||
| 6071 | |||
| 6072 | - Scan additional code you are adding to the system (e.g. application | ||
| 6073 | code) by using static analysis tools. Look for buffer overflows and | ||
| 6074 | other potential security problems. | ||
| 6075 | |||
| 6076 | - Pay particular attention to the security for any web-based | ||
| 6077 | administration interface. | ||
| 6078 | |||
| 6079 | Web interfaces typically need to perform administrative functions and | ||
| 6080 | tend to need to run with elevated privileges. Thus, the consequences | ||
| 6081 | resulting from the interface's security becoming compromised can be | ||
| 6082 | serious. Look for common web vulnerabilities such as | ||
| 6083 | cross-site-scripting (XSS), unvalidated inputs, and so forth. | ||
| 6084 | |||
| 6085 | As with system passwords, the default credentials for accessing a | ||
| 6086 | web-based interface should not be the same across all devices. This | ||
| 6087 | is particularly true if the interface is enabled by default as it can | ||
| 6088 | be assumed that many end-users will not change the credentials. | ||
| 6089 | |||
| 6090 | - Ensure you can update the software on the device to mitigate | ||
| 6091 | vulnerabilities discovered in the future. This consideration | ||
| 6092 | especially applies when your device is network-enabled. | ||
| 6093 | |||
| 6094 | - Ensure you remove or disable debugging functionality before producing | ||
| 6095 | the final image. For information on how to do this, see the | ||
| 6096 | "`Considerations Specific to the OpenEmbedded Build | ||
| 6097 | System <#considerations-specific-to-the-openembedded-build-system>`__" | ||
| 6098 | section. | ||
| 6099 | |||
| 6100 | - Ensure you have no network services listening that are not needed. | ||
| 6101 | |||
| 6102 | - Remove any software from the image that is not needed. | ||
| 6103 | |||
| 6104 | - Enable hardware support for secure boot functionality when your | ||
| 6105 | device supports this functionality. | ||
| 6106 | |||
| 6107 | Security Flags | ||
| 6108 | -------------- | ||
| 6109 | |||
| 6110 | The Yocto Project has security flags that you can enable that help make | ||
| 6111 | your build output more secure. The security flags are in the | ||
| 6112 | ``meta/conf/distro/include/security_flags.inc`` file in your | ||
| 6113 | :term:`Source Directory` (e.g. ``poky``). | ||
| 6114 | |||
| 6115 | .. note:: | ||
| 6116 | |||
| 6117 | Depending on the recipe, certain security flags are enabled and | ||
| 6118 | disabled by default. | ||
| 6119 | |||
| 6120 | Use the following line in your ``local.conf`` file or in your custom | ||
| 6121 | distribution configuration file to enable the security compiler and | ||
| 6122 | linker flags for your build: | ||
| 6123 | :: | ||
| 6124 | |||
| 6125 | require conf/distro/include/security_flags.inc | ||
| 6126 | |||
| 6127 | Considerations Specific to the OpenEmbedded Build System | ||
| 6128 | -------------------------------------------------------- | ||
| 6129 | |||
| 6130 | You can take some steps that are specific to the OpenEmbedded build | ||
| 6131 | system to make your images more secure: | ||
| 6132 | |||
| 6133 | - Ensure "debug-tweaks" is not one of your selected | ||
| 6134 | :term:`IMAGE_FEATURES`. | ||
| 6135 | When creating a new project, the default is to provide you with an | ||
| 6136 | initial ``local.conf`` file that enables this feature using the | ||
| 6137 | :term:`EXTRA_IMAGE_FEATURES` | ||
| 6138 | variable with the line: | ||
| 6139 | :: | ||
| 6140 | |||
| 6141 | EXTRA_IMAGE_FEATURES = "debug-tweaks" | ||
| 6142 | |||
| 6143 | To disable that feature, simply comment out that line in your | ||
| 6144 | ``local.conf`` file, or make sure ``IMAGE_FEATURES`` does not contain | ||
| 6145 | "debug-tweaks" before producing your final image. Among other things, | ||
| 6146 | leaving this in place sets the root password as blank, which makes | ||
| 6147 | logging in for debugging or inspection easy during development but | ||
| 6148 | also means anyone can easily log in during production. | ||
| 6149 | |||
| 6150 | - It is possible to set a root password for the image and also to set | ||
| 6151 | passwords for any extra users you might add (e.g. administrative or | ||
| 6152 | service type users). When you set up passwords for multiple images or | ||
| 6153 | users, you should not duplicate passwords. | ||
| 6154 | |||
| 6155 | To set up passwords, use the | ||
| 6156 | :ref:`extrausers <ref-classes-extrausers>` | ||
| 6157 | class, which is the preferred method. For an example on how to set up | ||
| 6158 | both root and user passwords, see the | ||
| 6159 | ":ref:`extrausers.bbclass <ref-classes-extrausers>`" | ||
| 6160 | section. | ||
| 6161 | |||
| 6162 | .. note:: | ||
| 6163 | |||
| 6164 | When adding extra user accounts or setting a root password, be | ||
| 6165 | cautious about setting the same password on every device. If you | ||
| 6166 | do this, and the password you have set is exposed, then every | ||
| 6167 | device is now potentially compromised. If you need this access but | ||
| 6168 | want to ensure security, consider setting a different, random | ||
| 6169 | password for each device. Typically, you do this as a separate | ||
| 6170 | step after you deploy the image onto the device. | ||
| 6171 | |||
| 6172 | - Consider enabling a Mandatory Access Control (MAC) framework such as | ||
| 6173 | SMACK or SELinux and tuning it appropriately for your device's usage. | ||
| 6174 | You can find more information in the | ||
| 6175 | :yocto_git:`meta-selinux </meta-selinux/>` layer. | ||
| 6176 | |||
| 6177 | Tools for Hardening Your Image | ||
| 6178 | ------------------------------ | ||
| 6179 | |||
| 6180 | The Yocto Project provides tools for making your image more secure. You | ||
| 6181 | can find these tools in the ``meta-security`` layer of the | ||
| 6182 | :yocto_git:`Yocto Project Source Repositories <>`. | ||
| 6183 | |||
| 6184 | Creating Your Own Distribution | ||
| 6185 | ============================== | ||
| 6186 | |||
| 6187 | When you build an image using the Yocto Project and do not alter any | ||
| 6188 | distribution :term:`Metadata`, you are | ||
| 6189 | creating a Poky distribution. If you wish to gain more control over | ||
| 6190 | package alternative selections, compile-time options, and other | ||
| 6191 | low-level configurations, you can create your own distribution. | ||
| 6192 | |||
| 6193 | To create your own distribution, the basic steps consist of creating | ||
| 6194 | your own distribution layer, creating your own distribution | ||
| 6195 | configuration file, and then adding any needed code and Metadata to the | ||
| 6196 | layer. The following steps provide some more detail: | ||
| 6197 | |||
| 6198 | - *Create a layer for your new distro:* Create your distribution layer | ||
| 6199 | so that you can keep your Metadata and code for the distribution | ||
| 6200 | separate. It is strongly recommended that you create and use your own | ||
| 6201 | layer for configuration and code. Using your own layer as compared to | ||
| 6202 | just placing configurations in a ``local.conf`` configuration file | ||
| 6203 | makes it easier to reproduce the same build configuration when using | ||
| 6204 | multiple build machines. See the | ||
| 6205 | ":ref:`dev-manual/common-tasks:creating a general layer using the \`\`bitbake-layers\`\` script`" | ||
| 6206 | section for information on how to quickly set up a layer. | ||
| 6207 | |||
| 6208 | - *Create the distribution configuration file:* The distribution | ||
| 6209 | configuration file needs to be created in the ``conf/distro`` | ||
| 6210 | directory of your layer. You need to name it using your distribution | ||
| 6211 | name (e.g. ``mydistro.conf``). | ||
| 6212 | |||
| 6213 | .. note:: | ||
| 6214 | |||
| 6215 | The :term:`DISTRO` variable in your ``local.conf`` file determines the | ||
| 6216 | name of your distribution. | ||
| 6217 | |||
| 6218 | You can split out parts of your configuration file into include files | ||
| 6219 | and then "require" them from within your distribution configuration | ||
| 6220 | file. Be sure to place the include files in the | ||
| 6221 | ``conf/distro/include`` directory of your layer. A common example | ||
| 6222 | usage of include files would be to separate out the selection of | ||
| 6223 | desired version and revisions for individual recipes. | ||
| 6224 | |||
| 6225 | Your configuration file needs to set the following required | ||
| 6226 | variables: | ||
| 6227 | |||
| 6228 | - :term:`DISTRO_NAME` | ||
| 6229 | |||
| 6230 | - :term:`DISTRO_VERSION` | ||
| 6231 | |||
| 6232 | These following variables are optional and you typically set them | ||
| 6233 | from the distribution configuration file: | ||
| 6234 | |||
| 6235 | - :term:`DISTRO_FEATURES` | ||
| 6236 | |||
| 6237 | - :term:`DISTRO_EXTRA_RDEPENDS` | ||
| 6238 | |||
| 6239 | - :term:`DISTRO_EXTRA_RRECOMMENDS` | ||
| 6240 | |||
| 6241 | - :term:`TCLIBC` | ||
| 6242 | |||
| 6243 | .. tip:: | ||
| 6244 | |||
| 6245 | If you want to base your distribution configuration file on the | ||
| 6246 | very basic configuration from OE-Core, you can use | ||
| 6247 | ``conf/distro/defaultsetup.conf`` as a reference and just include | ||
| 6248 | variables that differ as compared to ``defaultsetup.conf``. | ||
| 6249 | Alternatively, you can create a distribution configuration file | ||
| 6250 | from scratch using the ``defaultsetup.conf`` file or configuration files | ||
| 6251 | from other distributions such as Poky or Angstrom as references. | ||
| 6252 | |||
| 6253 | - *Provide miscellaneous variables:* Be sure to define any other | ||
| 6254 | variables for which you want to create a default or enforce as part | ||
| 6255 | of the distribution configuration. You can include nearly any | ||
| 6256 | variable from the ``local.conf`` file. The variables you use are not | ||
| 6257 | limited to the list in the previous bulleted item. | ||
| 6258 | |||
| 6259 | - *Point to Your distribution configuration file:* In your | ||
| 6260 | ``local.conf`` file in the :term:`Build Directory`, | ||
| 6261 | set your | ||
| 6262 | :term:`DISTRO` variable to point to | ||
| 6263 | your distribution's configuration file. For example, if your | ||
| 6264 | distribution's configuration file is named ``mydistro.conf``, then | ||
| 6265 | you point to it as follows: | ||
| 6266 | :: | ||
| 6267 | |||
| 6268 | DISTRO = "mydistro" | ||
| 6269 | |||
| 6270 | - *Add more to the layer if necessary:* Use your layer to hold other | ||
| 6271 | information needed for the distribution: | ||
| 6272 | |||
| 6273 | - Add recipes for installing distro-specific configuration files | ||
| 6274 | that are not already installed by another recipe. If you have | ||
| 6275 | distro-specific configuration files that are included by an | ||
| 6276 | existing recipe, you should add an append file (``.bbappend``) for | ||
| 6277 | those. For general information and recommendations on how to add | ||
| 6278 | recipes to your layer, see the "`Creating Your Own | ||
| 6279 | Layer <#creating-your-own-layer>`__" and "`Following Best | ||
| 6280 | Practices When Creating | ||
| 6281 | Layers <#best-practices-to-follow-when-creating-layers>`__" | ||
| 6282 | sections. | ||
| 6283 | |||
| 6284 | - Add any image recipes that are specific to your distribution. | ||
| 6285 | |||
| 6286 | - Add a ``psplash`` append file for a branded splash screen. For | ||
| 6287 | information on append files, see the "`Using .bbappend Files in | ||
| 6288 | Your Layer <#using-bbappend-files>`__" section. | ||
| 6289 | |||
| 6290 | - Add any other append files to make custom changes that are | ||
| 6291 | specific to individual recipes. | ||
| 6292 | |||
| 6293 | Creating a Custom Template Configuration Directory | ||
| 6294 | ================================================== | ||
| 6295 | |||
| 6296 | If you are producing your own customized version of the build system for | ||
| 6297 | use by other users, you might want to customize the message shown by the | ||
| 6298 | setup script or you might want to change the template configuration | ||
| 6299 | files (i.e. ``local.conf`` and ``bblayers.conf``) that are created in a | ||
| 6300 | new build directory. | ||
| 6301 | |||
| 6302 | The OpenEmbedded build system uses the environment variable | ||
| 6303 | ``TEMPLATECONF`` to locate the directory from which it gathers | ||
| 6304 | configuration information that ultimately ends up in the | ||
| 6305 | :term:`Build Directory` ``conf`` directory. | ||
| 6306 | By default, ``TEMPLATECONF`` is set as follows in the ``poky`` | ||
| 6307 | repository: | ||
| 6308 | :: | ||
| 6309 | |||
| 6310 | TEMPLATECONF=${TEMPLATECONF:-meta-poky/conf} | ||
| 6311 | |||
| 6312 | This is the | ||
| 6313 | directory used by the build system to find templates from which to build | ||
| 6314 | some key configuration files. If you look at this directory, you will | ||
| 6315 | see the ``bblayers.conf.sample``, ``local.conf.sample``, and | ||
| 6316 | ``conf-notes.txt`` files. The build system uses these files to form the | ||
| 6317 | respective ``bblayers.conf`` file, ``local.conf`` file, and display the | ||
| 6318 | list of BitBake targets when running the setup script. | ||
| 6319 | |||
| 6320 | To override these default configuration files with configurations you | ||
| 6321 | want used within every new Build Directory, simply set the | ||
| 6322 | ``TEMPLATECONF`` variable to your directory. The ``TEMPLATECONF`` | ||
| 6323 | variable is set in the ``.templateconf`` file, which is in the top-level | ||
| 6324 | :term:`Source Directory` folder | ||
| 6325 | (e.g. ``poky``). Edit the ``.templateconf`` so that it can locate your | ||
| 6326 | directory. | ||
| 6327 | |||
| 6328 | Best practices dictate that you should keep your template configuration | ||
| 6329 | directory in your custom distribution layer. For example, suppose you | ||
| 6330 | have a layer named ``meta-mylayer`` located in your home directory and | ||
| 6331 | you want your template configuration directory named ``myconf``. | ||
| 6332 | Changing the ``.templateconf`` as follows causes the OpenEmbedded build | ||
| 6333 | system to look in your directory and base its configuration files on the | ||
| 6334 | ``*.sample`` configuration files it finds. The final configuration files | ||
| 6335 | (i.e. ``local.conf`` and ``bblayers.conf`` ultimately still end up in | ||
| 6336 | your Build Directory, but they are based on your ``*.sample`` files. | ||
| 6337 | :: | ||
| 6338 | |||
| 6339 | TEMPLATECONF=${TEMPLATECONF:-meta-mylayer/myconf} | ||
| 6340 | |||
| 6341 | Aside from the ``*.sample`` configuration files, the ``conf-notes.txt`` | ||
| 6342 | also resides in the default ``meta-poky/conf`` directory. The script | ||
| 6343 | that sets up the build environment (i.e. | ||
| 6344 | :ref:`structure-core-script`) uses this file to | ||
| 6345 | display BitBake targets as part of the script output. Customizing this | ||
| 6346 | ``conf-notes.txt`` file is a good way to make sure your list of custom | ||
| 6347 | targets appears as part of the script's output. | ||
| 6348 | |||
| 6349 | Here is the default list of targets displayed as a result of running | ||
| 6350 | either of the setup scripts: | ||
| 6351 | :: | ||
| 6352 | |||
| 6353 | You can now run 'bitbake <target>' | ||
| 6354 | |||
| 6355 | Common targets are: | ||
| 6356 | core-image-minimal | ||
| 6357 | core-image-sato | ||
| 6358 | meta-toolchain | ||
| 6359 | meta-ide-support | ||
| 6360 | |||
| 6361 | Changing the listed common targets is as easy as editing your version of | ||
| 6362 | ``conf-notes.txt`` in your custom template configuration directory and | ||
| 6363 | making sure you have ``TEMPLATECONF`` set to your directory. | ||
| 6364 | |||
| 6365 | Conserving Disk Space During Builds | ||
| 6366 | =================================== | ||
| 6367 | |||
| 6368 | To help conserve disk space during builds, you can add the following | ||
| 6369 | statement to your project's ``local.conf`` configuration file found in | ||
| 6370 | the :term:`Build Directory`: | ||
| 6371 | :: | ||
| 6372 | |||
| 6373 | INHERIT += "rm_work" | ||
| 6374 | |||
| 6375 | Adding this statement deletes the work directory used for | ||
| 6376 | building a recipe once the recipe is built. For more information on | ||
| 6377 | "rm_work", see the | ||
| 6378 | :ref:`rm_work <ref-classes-rm-work>` class in the | ||
| 6379 | Yocto Project Reference Manual. | ||
| 6380 | |||
| 6381 | Working with Packages | ||
| 6382 | ===================== | ||
| 6383 | |||
| 6384 | This section describes a few tasks that involve packages: | ||
| 6385 | |||
| 6386 | - `Excluding packages from an | ||
| 6387 | image <#excluding-packages-from-an-image>`__ | ||
| 6388 | |||
| 6389 | - `Incrementing a binary package | ||
| 6390 | version <#incrementing-a-binary-package-version>`__ | ||
| 6391 | |||
| 6392 | - `Handling optional module | ||
| 6393 | packaging <#handling-optional-module-packaging>`__ | ||
| 6394 | |||
| 6395 | - `Using runtime package | ||
| 6396 | management <#using-runtime-package-management>`__ | ||
| 6397 | |||
| 6398 | - `Generating and using signed | ||
| 6399 | packages <#generating-and-using-signed-packages>`__ | ||
| 6400 | |||
| 6401 | - `Setting up and running package test | ||
| 6402 | (ptest) <#testing-packages-with-ptest>`__ | ||
| 6403 | |||
| 6404 | - `Creating node package manager (NPM) | ||
| 6405 | packages <#creating-node-package-manager-npm-packages>`__ | ||
| 6406 | |||
| 6407 | - `Adding custom metadata to | ||
| 6408 | packages <#adding-custom-metadata-to-packages>`__ | ||
| 6409 | |||
| 6410 | Excluding Packages from an Image | ||
| 6411 | -------------------------------- | ||
| 6412 | |||
| 6413 | You might find it necessary to prevent specific packages from being | ||
| 6414 | installed into an image. If so, you can use several variables to direct | ||
| 6415 | the build system to essentially ignore installing recommended packages | ||
| 6416 | or to not install a package at all. | ||
| 6417 | |||
| 6418 | The following list introduces variables you can use to prevent packages | ||
| 6419 | from being installed into your image. Each of these variables only works | ||
| 6420 | with IPK and RPM package types. Support for Debian packages does not | ||
| 6421 | exist. Also, you can use these variables from your ``local.conf`` file | ||
| 6422 | or attach them to a specific image recipe by using a recipe name | ||
| 6423 | override. For more detail on the variables, see the descriptions in the | ||
| 6424 | Yocto Project Reference Manual's glossary chapter. | ||
| 6425 | |||
| 6426 | - :term:`BAD_RECOMMENDATIONS`: | ||
| 6427 | Use this variable to specify "recommended-only" packages that you do | ||
| 6428 | not want installed. | ||
| 6429 | |||
| 6430 | - :term:`NO_RECOMMENDATIONS`: | ||
| 6431 | Use this variable to prevent all "recommended-only" packages from | ||
| 6432 | being installed. | ||
| 6433 | |||
| 6434 | - :term:`PACKAGE_EXCLUDE`: | ||
| 6435 | Use this variable to prevent specific packages from being installed | ||
| 6436 | regardless of whether they are "recommended-only" or not. You need to | ||
| 6437 | realize that the build process could fail with an error when you | ||
| 6438 | prevent the installation of a package whose presence is required by | ||
| 6439 | an installed package. | ||
| 6440 | |||
| 6441 | Incrementing a Package Version | ||
| 6442 | ------------------------------ | ||
| 6443 | |||
| 6444 | This section provides some background on how binary package versioning | ||
| 6445 | is accomplished and presents some of the services, variables, and | ||
| 6446 | terminology involved. | ||
| 6447 | |||
| 6448 | In order to understand binary package versioning, you need to consider | ||
| 6449 | the following: | ||
| 6450 | |||
| 6451 | - Binary Package: The binary package that is eventually built and | ||
| 6452 | installed into an image. | ||
| 6453 | |||
| 6454 | - Binary Package Version: The binary package version is composed of two | ||
| 6455 | components - a version and a revision. | ||
| 6456 | |||
| 6457 | .. note:: | ||
| 6458 | |||
| 6459 | Technically, a third component, the "epoch" (i.e. :term:`PE`) is involved | ||
| 6460 | but this discussion for the most part ignores ``PE``. | ||
| 6461 | |||
| 6462 | The version and revision are taken from the | ||
| 6463 | :term:`PV` and | ||
| 6464 | :term:`PR` variables, respectively. | ||
| 6465 | |||
| 6466 | - ``PV``: The recipe version. ``PV`` represents the version of the | ||
| 6467 | software being packaged. Do not confuse ``PV`` with the binary | ||
| 6468 | package version. | ||
| 6469 | |||
| 6470 | - ``PR``: The recipe revision. | ||
| 6471 | |||
| 6472 | - :term:`SRCPV`: The OpenEmbedded | ||
| 6473 | build system uses this string to help define the value of ``PV`` when | ||
| 6474 | the source code revision needs to be included in it. | ||
| 6475 | |||
| 6476 | - :yocto_wiki:`PR Service </PR_Service>`: A | ||
| 6477 | network-based service that helps automate keeping package feeds | ||
| 6478 | compatible with existing package manager applications such as RPM, | ||
| 6479 | APT, and OPKG. | ||
| 6480 | |||
| 6481 | Whenever the binary package content changes, the binary package version | ||
| 6482 | must change. Changing the binary package version is accomplished by | ||
| 6483 | changing or "bumping" the ``PR`` and/or ``PV`` values. Increasing these | ||
| 6484 | values occurs one of two ways: | ||
| 6485 | |||
| 6486 | - Automatically using a Package Revision Service (PR Service). | ||
| 6487 | |||
| 6488 | - Manually incrementing the ``PR`` and/or ``PV`` variables. | ||
| 6489 | |||
| 6490 | Given a primary challenge of any build system and its users is how to | ||
| 6491 | maintain a package feed that is compatible with existing package manager | ||
| 6492 | applications such as RPM, APT, and OPKG, using an automated system is | ||
| 6493 | much preferred over a manual system. In either system, the main | ||
| 6494 | requirement is that binary package version numbering increases in a | ||
| 6495 | linear fashion and that a number of version components exist that | ||
| 6496 | support that linear progression. For information on how to ensure | ||
| 6497 | package revisioning remains linear, see the "`Automatically Incrementing | ||
| 6498 | a Binary Package Revision | ||
| 6499 | Number <#automatically-incrementing-a-binary-package-revision-number>`__" | ||
| 6500 | section. | ||
| 6501 | |||
| 6502 | The following three sections provide related information on the PR | ||
| 6503 | Service, the manual method for "bumping" ``PR`` and/or ``PV``, and on | ||
| 6504 | how to ensure binary package revisioning remains linear. | ||
| 6505 | |||
| 6506 | Working With a PR Service | ||
| 6507 | ~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 6508 | |||
| 6509 | As mentioned, attempting to maintain revision numbers in the | ||
| 6510 | :term:`Metadata` is error prone, inaccurate, | ||
| 6511 | and causes problems for people submitting recipes. Conversely, the PR | ||
| 6512 | Service automatically generates increasing numbers, particularly the | ||
| 6513 | revision field, which removes the human element. | ||
| 6514 | |||
| 6515 | .. note:: | ||
| 6516 | |||
| 6517 | For additional information on using a PR Service, you can see the | ||
| 6518 | :yocto_wiki:`PR Service </PR_Service>` wiki page. | ||
| 6519 | |||
| 6520 | The Yocto Project uses variables in order of decreasing priority to | ||
| 6521 | facilitate revision numbering (i.e. | ||
| 6522 | :term:`PE`, | ||
| 6523 | :term:`PV`, and | ||
| 6524 | :term:`PR` for epoch, version, and | ||
| 6525 | revision, respectively). The values are highly dependent on the policies | ||
| 6526 | and procedures of a given distribution and package feed. | ||
| 6527 | |||
| 6528 | Because the OpenEmbedded build system uses | ||
| 6529 | ":ref:`signatures <overview-manual/overview-manual-concepts:checksums (signatures)>`", which are | ||
| 6530 | unique to a given build, the build system knows when to rebuild | ||
| 6531 | packages. All the inputs into a given task are represented by a | ||
| 6532 | signature, which can trigger a rebuild when different. Thus, the build | ||
| 6533 | system itself does not rely on the ``PR``, ``PV``, and ``PE`` numbers to | ||
| 6534 | trigger a rebuild. The signatures, however, can be used to generate | ||
| 6535 | these values. | ||
| 6536 | |||
| 6537 | The PR Service works with both ``OEBasic`` and ``OEBasicHash`` | ||
| 6538 | generators. The value of ``PR`` bumps when the checksum changes and the | ||
| 6539 | different generator mechanisms change signatures under different | ||
| 6540 | circumstances. | ||
| 6541 | |||
| 6542 | As implemented, the build system includes values from the PR Service | ||
| 6543 | into the ``PR`` field as an addition using the form "``.x``" so ``r0`` | ||
| 6544 | becomes ``r0.1``, ``r0.2`` and so forth. This scheme allows existing | ||
| 6545 | ``PR`` values to be used for whatever reasons, which include manual | ||
| 6546 | ``PR`` bumps, should it be necessary. | ||
| 6547 | |||
| 6548 | By default, the PR Service is not enabled or running. Thus, the packages | ||
| 6549 | generated are just "self consistent". The build system adds and removes | ||
| 6550 | packages and there are no guarantees about upgrade paths but images will | ||
| 6551 | be consistent and correct with the latest changes. | ||
| 6552 | |||
| 6553 | The simplest form for a PR Service is for it to exist for a single host | ||
| 6554 | development system that builds the package feed (building system). For | ||
| 6555 | this scenario, you can enable a local PR Service by setting | ||
| 6556 | :term:`PRSERV_HOST` in your | ||
| 6557 | ``local.conf`` file in the :term:`Build Directory`: | ||
| 6558 | :: | ||
| 6559 | |||
| 6560 | PRSERV_HOST = "localhost:0" | ||
| 6561 | |||
| 6562 | Once the service is started, packages will automatically | ||
| 6563 | get increasing ``PR`` values and BitBake takes care of starting and | ||
| 6564 | stopping the server. | ||
| 6565 | |||
| 6566 | If you have a more complex setup where multiple host development systems | ||
| 6567 | work against a common, shared package feed, you have a single PR Service | ||
| 6568 | running and it is connected to each building system. For this scenario, | ||
| 6569 | you need to start the PR Service using the ``bitbake-prserv`` command: | ||
| 6570 | :: | ||
| 6571 | |||
| 6572 | bitbake-prserv --host ip --port port --start | ||
| 6573 | |||
| 6574 | In addition to | ||
| 6575 | hand-starting the service, you need to update the ``local.conf`` file of | ||
| 6576 | each building system as described earlier so each system points to the | ||
| 6577 | server and port. | ||
| 6578 | |||
| 6579 | It is also recommended you use build history, which adds some sanity | ||
| 6580 | checks to binary package versions, in conjunction with the server that | ||
| 6581 | is running the PR Service. To enable build history, add the following to | ||
| 6582 | each building system's ``local.conf`` file: | ||
| 6583 | :: | ||
| 6584 | |||
| 6585 | # It is recommended to activate "buildhistory" for testing the PR service | ||
| 6586 | INHERIT += "buildhistory" | ||
| 6587 | BUILDHISTORY_COMMIT = "1" | ||
| 6588 | |||
| 6589 | For information on build | ||
| 6590 | history, see the "`Maintaining Build Output | ||
| 6591 | Quality <#maintaining-build-output-quality>`__" section. | ||
| 6592 | |||
| 6593 | .. note:: | ||
| 6594 | |||
| 6595 | The OpenEmbedded build system does not maintain ``PR`` information as | ||
| 6596 | part of the shared state (sstate) packages. If you maintain an sstate | ||
| 6597 | feed, its expected that either all your building systems that | ||
| 6598 | contribute to the sstate feed use a shared PR Service, or you do not | ||
| 6599 | run a PR Service on any of your building systems. Having some systems | ||
| 6600 | use a PR Service while others do not leads to obvious problems. | ||
| 6601 | |||
| 6602 | For more information on shared state, see the | ||
| 6603 | ":ref:`overview-manual/overview-manual-concepts:shared state cache`" | ||
| 6604 | section in the Yocto Project Overview and Concepts Manual. | ||
| 6605 | |||
| 6606 | Manually Bumping PR | ||
| 6607 | ~~~~~~~~~~~~~~~~~~~ | ||
| 6608 | |||
| 6609 | The alternative to setting up a PR Service is to manually "bump" the | ||
| 6610 | :term:`PR` variable. | ||
| 6611 | |||
| 6612 | If a committed change results in changing the package output, then the | ||
| 6613 | value of the PR variable needs to be increased (or "bumped") as part of | ||
| 6614 | that commit. For new recipes you should add the ``PR`` variable and set | ||
| 6615 | its initial value equal to "r0", which is the default. Even though the | ||
| 6616 | default value is "r0", the practice of adding it to a new recipe makes | ||
| 6617 | it harder to forget to bump the variable when you make changes to the | ||
| 6618 | recipe in future. | ||
| 6619 | |||
| 6620 | If you are sharing a common ``.inc`` file with multiple recipes, you can | ||
| 6621 | also use the ``INC_PR`` variable to ensure that the recipes sharing the | ||
| 6622 | ``.inc`` file are rebuilt when the ``.inc`` file itself is changed. The | ||
| 6623 | ``.inc`` file must set ``INC_PR`` (initially to "r0"), and all recipes | ||
| 6624 | referring to it should set ``PR`` to "${INC_PR}.0" initially, | ||
| 6625 | incrementing the last number when the recipe is changed. If the ``.inc`` | ||
| 6626 | file is changed then its ``INC_PR`` should be incremented. | ||
| 6627 | |||
| 6628 | When upgrading the version of a binary package, assuming the ``PV`` | ||
| 6629 | changes, the ``PR`` variable should be reset to "r0" (or "${INC_PR}.0" | ||
| 6630 | if you are using ``INC_PR``). | ||
| 6631 | |||
| 6632 | Usually, version increases occur only to binary packages. However, if | ||
| 6633 | for some reason ``PV`` changes but does not increase, you can increase | ||
| 6634 | the ``PE`` variable (Package Epoch). The ``PE`` variable defaults to | ||
| 6635 | "0". | ||
| 6636 | |||
| 6637 | Binary package version numbering strives to follow the `Debian Version | ||
| 6638 | Field Policy | ||
| 6639 | Guidelines <https://www.debian.org/doc/debian-policy/ch-controlfields.html>`__. | ||
| 6640 | These guidelines define how versions are compared and what "increasing" | ||
| 6641 | a version means. | ||
| 6642 | |||
| 6643 | Automatically Incrementing a Package Version Number | ||
| 6644 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 6645 | |||
| 6646 | When fetching a repository, BitBake uses the | ||
| 6647 | :term:`SRCREV` variable to determine | ||
| 6648 | the specific source code revision from which to build. You set the | ||
| 6649 | ``SRCREV`` variable to | ||
| 6650 | :term:`AUTOREV` to cause the | ||
| 6651 | OpenEmbedded build system to automatically use the latest revision of | ||
| 6652 | the software: | ||
| 6653 | :: | ||
| 6654 | |||
| 6655 | SRCREV = "${AUTOREV}" | ||
| 6656 | |||
| 6657 | Furthermore, you need to reference ``SRCPV`` in ``PV`` in order to | ||
| 6658 | automatically update the version whenever the revision of the source | ||
| 6659 | code changes. Here is an example: | ||
| 6660 | :: | ||
| 6661 | |||
| 6662 | PV = "1.0+git${SRCPV}" | ||
| 6663 | |||
| 6664 | The OpenEmbedded build system substitutes ``SRCPV`` with the following: | ||
| 6665 | |||
| 6666 | .. code-block:: none | ||
| 6667 | |||
| 6668 | AUTOINC+source_code_revision | ||
| 6669 | |||
| 6670 | The build system replaces the ``AUTOINC`` | ||
| 6671 | with a number. The number used depends on the state of the PR Service: | ||
| 6672 | |||
| 6673 | - If PR Service is enabled, the build system increments the number, | ||
| 6674 | which is similar to the behavior of | ||
| 6675 | :term:`PR`. This behavior results in | ||
| 6676 | linearly increasing package versions, which is desirable. Here is an | ||
| 6677 | example: | ||
| 6678 | |||
| 6679 | .. code-block:: none | ||
| 6680 | |||
| 6681 | hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk | ||
| 6682 | hello-world-git_0.0+git1+dd2f5c3565-r0.0_armv7a-neon.ipk | ||
| 6683 | |||
| 6684 | - If PR Service is not enabled, the build system replaces the | ||
| 6685 | ``AUTOINC`` placeholder with zero (i.e. "0"). This results in | ||
| 6686 | changing the package version since the source revision is included. | ||
| 6687 | However, package versions are not increased linearly. Here is an | ||
| 6688 | example: | ||
| 6689 | |||
| 6690 | .. code-block:: none | ||
| 6691 | |||
| 6692 | hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk | ||
| 6693 | hello-world-git_0.0+git0+dd2f5c3565-r0.0_armv7a-neon.ipk | ||
| 6694 | |||
| 6695 | In summary, the OpenEmbedded build system does not track the history of | ||
| 6696 | binary package versions for this purpose. ``AUTOINC``, in this case, is | ||
| 6697 | comparable to ``PR``. If PR server is not enabled, ``AUTOINC`` in the | ||
| 6698 | package version is simply replaced by "0". If PR server is enabled, the | ||
| 6699 | build system keeps track of the package versions and bumps the number | ||
| 6700 | when the package revision changes. | ||
| 6701 | |||
| 6702 | Handling Optional Module Packaging | ||
| 6703 | ---------------------------------- | ||
| 6704 | |||
| 6705 | Many pieces of software split functionality into optional modules (or | ||
| 6706 | plugins) and the plugins that are built might depend on configuration | ||
| 6707 | options. To avoid having to duplicate the logic that determines what | ||
| 6708 | modules are available in your recipe or to avoid having to package each | ||
| 6709 | module by hand, the OpenEmbedded build system provides functionality to | ||
| 6710 | handle module packaging dynamically. | ||
| 6711 | |||
| 6712 | To handle optional module packaging, you need to do two things: | ||
| 6713 | |||
| 6714 | - Ensure the module packaging is actually done. | ||
| 6715 | |||
| 6716 | - Ensure that any dependencies on optional modules from other recipes | ||
| 6717 | are satisfied by your recipe. | ||
| 6718 | |||
| 6719 | Making Sure the Packaging is Done | ||
| 6720 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 6721 | |||
| 6722 | To ensure the module packaging actually gets done, you use the | ||
| 6723 | ``do_split_packages`` function within the ``populate_packages`` Python | ||
| 6724 | function in your recipe. The ``do_split_packages`` function searches for | ||
| 6725 | a pattern of files or directories under a specified path and creates a | ||
| 6726 | package for each one it finds by appending to the | ||
| 6727 | :term:`PACKAGES` variable and | ||
| 6728 | setting the appropriate values for ``FILES_packagename``, | ||
| 6729 | ``RDEPENDS_packagename``, ``DESCRIPTION_packagename``, and so forth. | ||
| 6730 | Here is an example from the ``lighttpd`` recipe: | ||
| 6731 | :: | ||
| 6732 | |||
| 6733 | python populate_packages_prepend () { | ||
| 6734 | lighttpd_libdir = d.expand('${libdir}') | ||
| 6735 | do_split_packages(d, lighttpd_libdir, '^mod_(.*).so$', | ||
| 6736 | 'lighttpd-module-%s', 'Lighttpd module for %s', | ||
| 6737 | extra_depends='') | ||
| 6738 | } | ||
| 6739 | |||
| 6740 | The previous example specifies a number of things in the call to | ||
| 6741 | ``do_split_packages``. | ||
| 6742 | |||
| 6743 | - A directory within the files installed by your recipe through | ||
| 6744 | ``do_install`` in which to search. | ||
| 6745 | |||
| 6746 | - A regular expression used to match module files in that directory. In | ||
| 6747 | the example, note the parentheses () that mark the part of the | ||
| 6748 | expression from which the module name should be derived. | ||
| 6749 | |||
| 6750 | - A pattern to use for the package names. | ||
| 6751 | |||
| 6752 | - A description for each package. | ||
| 6753 | |||
| 6754 | - An empty string for ``extra_depends``, which disables the default | ||
| 6755 | dependency on the main ``lighttpd`` package. Thus, if a file in | ||
| 6756 | ``${libdir}`` called ``mod_alias.so`` is found, a package called | ||
| 6757 | ``lighttpd-module-alias`` is created for it and the | ||
| 6758 | :term:`DESCRIPTION` is set to | ||
| 6759 | "Lighttpd module for alias". | ||
| 6760 | |||
| 6761 | Often, packaging modules is as simple as the previous example. However, | ||
| 6762 | more advanced options exist that you can use within | ||
| 6763 | ``do_split_packages`` to modify its behavior. And, if you need to, you | ||
| 6764 | can add more logic by specifying a hook function that is called for each | ||
| 6765 | package. It is also perfectly acceptable to call ``do_split_packages`` | ||
| 6766 | multiple times if you have more than one set of modules to package. | ||
| 6767 | |||
| 6768 | For more examples that show how to use ``do_split_packages``, see the | ||
| 6769 | ``connman.inc`` file in the ``meta/recipes-connectivity/connman/`` | ||
| 6770 | directory of the ``poky`` :ref:`source repository <overview-manual/overview-manual-development-environment:yocto project source repositories>`. You can | ||
| 6771 | also find examples in ``meta/classes/kernel.bbclass``. | ||
| 6772 | |||
| 6773 | Following is a reference that shows ``do_split_packages`` mandatory and | ||
| 6774 | optional arguments: | ||
| 6775 | :: | ||
| 6776 | |||
| 6777 | Mandatory arguments | ||
| 6778 | |||
| 6779 | root | ||
| 6780 | The path in which to search | ||
| 6781 | file_regex | ||
| 6782 | Regular expression to match searched files. | ||
| 6783 | Use parentheses () to mark the part of this | ||
| 6784 | expression that should be used to derive the | ||
| 6785 | module name (to be substituted where %s is | ||
| 6786 | used in other function arguments as noted below) | ||
| 6787 | output_pattern | ||
| 6788 | Pattern to use for the package names. Must | ||
| 6789 | include %s. | ||
| 6790 | description | ||
| 6791 | Description to set for each package. Must | ||
| 6792 | include %s. | ||
| 6793 | |||
| 6794 | Optional arguments | ||
| 6795 | |||
| 6796 | postinst | ||
| 6797 | Postinstall script to use for all packages | ||
| 6798 | (as a string) | ||
| 6799 | recursive | ||
| 6800 | True to perform a recursive search - default | ||
| 6801 | False | ||
| 6802 | hook | ||
| 6803 | A hook function to be called for every match. | ||
| 6804 | The function will be called with the following | ||
| 6805 | arguments (in the order listed): | ||
| 6806 | |||
| 6807 | f | ||
| 6808 | Full path to the file/directory match | ||
| 6809 | pkg | ||
| 6810 | The package name | ||
| 6811 | file_regex | ||
| 6812 | As above | ||
| 6813 | output_pattern | ||
| 6814 | As above | ||
| 6815 | modulename | ||
| 6816 | The module name derived using file_regex | ||
| 6817 | extra_depends | ||
| 6818 | Extra runtime dependencies (RDEPENDS) to be | ||
| 6819 | set for all packages. The default value of None | ||
| 6820 | causes a dependency on the main package | ||
| 6821 | (${PN}) - if you do not want this, pass empty | ||
| 6822 | string '' for this parameter. | ||
| 6823 | aux_files_pattern | ||
| 6824 | Extra item(s) to be added to FILES for each | ||
| 6825 | package. Can be a single string item or a list | ||
| 6826 | of strings for multiple items. Must include %s. | ||
| 6827 | postrm | ||
| 6828 | postrm script to use for all packages (as a | ||
| 6829 | string) | ||
| 6830 | allow_dirs | ||
| 6831 | True to allow directories to be matched - | ||
| 6832 | default False | ||
| 6833 | prepend | ||
| 6834 | If True, prepend created packages to PACKAGES | ||
| 6835 | instead of the default False which appends them | ||
| 6836 | match_path | ||
| 6837 | match file_regex on the whole relative path to | ||
| 6838 | the root rather than just the file name | ||
| 6839 | aux_files_pattern_verbatim | ||
| 6840 | Extra item(s) to be added to FILES for each | ||
| 6841 | package, using the actual derived module name | ||
| 6842 | rather than converting it to something legal | ||
| 6843 | for a package name. Can be a single string item | ||
| 6844 | or a list of strings for multiple items. Must | ||
| 6845 | include %s. | ||
| 6846 | allow_links | ||
| 6847 | True to allow symlinks to be matched - default | ||
| 6848 | False | ||
| 6849 | summary | ||
| 6850 | Summary to set for each package. Must include %s; | ||
| 6851 | defaults to description if not set. | ||
| 6852 | |||
| 6853 | |||
| 6854 | |||
| 6855 | Satisfying Dependencies | ||
| 6856 | ~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 6857 | |||
| 6858 | The second part for handling optional module packaging is to ensure that | ||
| 6859 | any dependencies on optional modules from other recipes are satisfied by | ||
| 6860 | your recipe. You can be sure these dependencies are satisfied by using | ||
| 6861 | the :term:`PACKAGES_DYNAMIC` | ||
| 6862 | variable. Here is an example that continues with the ``lighttpd`` recipe | ||
| 6863 | shown earlier: | ||
| 6864 | :: | ||
| 6865 | |||
| 6866 | PACKAGES_DYNAMIC = "lighttpd-module-.*" | ||
| 6867 | |||
| 6868 | The name | ||
| 6869 | specified in the regular expression can of course be anything. In this | ||
| 6870 | example, it is ``lighttpd-module-`` and is specified as the prefix to | ||
| 6871 | ensure that any :term:`RDEPENDS` and | ||
| 6872 | :term:`RRECOMMENDS` on a package | ||
| 6873 | name starting with the prefix are satisfied during build time. If you | ||
| 6874 | are using ``do_split_packages`` as described in the previous section, | ||
| 6875 | the value you put in ``PACKAGES_DYNAMIC`` should correspond to the name | ||
| 6876 | pattern specified in the call to ``do_split_packages``. | ||
| 6877 | |||
| 6878 | Using Runtime Package Management | ||
| 6879 | -------------------------------- | ||
| 6880 | |||
| 6881 | During a build, BitBake always transforms a recipe into one or more | ||
| 6882 | packages. For example, BitBake takes the ``bash`` recipe and produces a | ||
| 6883 | number of packages (e.g. ``bash``, ``bash-bashbug``, | ||
| 6884 | ``bash-completion``, ``bash-completion-dbg``, ``bash-completion-dev``, | ||
| 6885 | ``bash-completion-extra``, ``bash-dbg``, and so forth). Not all | ||
| 6886 | generated packages are included in an image. | ||
| 6887 | |||
| 6888 | In several situations, you might need to update, add, remove, or query | ||
| 6889 | the packages on a target device at runtime (i.e. without having to | ||
| 6890 | generate a new image). Examples of such situations include: | ||
| 6891 | |||
| 6892 | - You want to provide in-the-field updates to deployed devices (e.g. | ||
| 6893 | security updates). | ||
| 6894 | |||
| 6895 | - You want to have a fast turn-around development cycle for one or more | ||
| 6896 | applications that run on your device. | ||
| 6897 | |||
| 6898 | - You want to temporarily install the "debug" packages of various | ||
| 6899 | applications on your device so that debugging can be greatly improved | ||
| 6900 | by allowing access to symbols and source debugging. | ||
| 6901 | |||
| 6902 | - You want to deploy a more minimal package selection of your device | ||
| 6903 | but allow in-the-field updates to add a larger selection for | ||
| 6904 | customization. | ||
| 6905 | |||
| 6906 | In all these situations, you have something similar to a more | ||
| 6907 | traditional Linux distribution in that in-field devices are able to | ||
| 6908 | receive pre-compiled packages from a server for installation or update. | ||
| 6909 | Being able to install these packages on a running, in-field device is | ||
| 6910 | what is termed "runtime package management". | ||
| 6911 | |||
| 6912 | In order to use runtime package management, you need a host or server | ||
| 6913 | machine that serves up the pre-compiled packages plus the required | ||
| 6914 | metadata. You also need package manipulation tools on the target. The | ||
| 6915 | build machine is a likely candidate to act as the server. However, that | ||
| 6916 | machine does not necessarily have to be the package server. The build | ||
| 6917 | machine could push its artifacts to another machine that acts as the | ||
| 6918 | server (e.g. Internet-facing). In fact, doing so is advantageous for a | ||
| 6919 | production environment as getting the packages away from the development | ||
| 6920 | system's build directory prevents accidental overwrites. | ||
| 6921 | |||
| 6922 | A simple build that targets just one device produces more than one | ||
| 6923 | package database. In other words, the packages produced by a build are | ||
| 6924 | separated out into a couple of different package groupings based on | ||
| 6925 | criteria such as the target's CPU architecture, the target board, or the | ||
| 6926 | C library used on the target. For example, a build targeting the | ||
| 6927 | ``qemux86`` device produces the following three package databases: | ||
| 6928 | ``noarch``, ``i586``, and ``qemux86``. If you wanted your ``qemux86`` | ||
| 6929 | device to be aware of all the packages that were available to it, you | ||
| 6930 | would need to point it to each of these databases individually. In a | ||
| 6931 | similar way, a traditional Linux distribution usually is configured to | ||
| 6932 | be aware of a number of software repositories from which it retrieves | ||
| 6933 | packages. | ||
| 6934 | |||
| 6935 | Using runtime package management is completely optional and not required | ||
| 6936 | for a successful build or deployment in any way. But if you want to make | ||
| 6937 | use of runtime package management, you need to do a couple things above | ||
| 6938 | and beyond the basics. The remainder of this section describes what you | ||
| 6939 | need to do. | ||
| 6940 | |||
| 6941 | Build Considerations | ||
| 6942 | ~~~~~~~~~~~~~~~~~~~~ | ||
| 6943 | |||
| 6944 | This section describes build considerations of which you need to be | ||
| 6945 | aware in order to provide support for runtime package management. | ||
| 6946 | |||
| 6947 | When BitBake generates packages, it needs to know what format or formats | ||
| 6948 | to use. In your configuration, you use the | ||
| 6949 | :term:`PACKAGE_CLASSES` | ||
| 6950 | variable to specify the format: | ||
| 6951 | |||
| 6952 | 1. Open the ``local.conf`` file inside your | ||
| 6953 | :term:`Build Directory` (e.g. | ||
| 6954 | ``~/poky/build/conf/local.conf``). | ||
| 6955 | |||
| 6956 | 2. Select the desired package format as follows: | ||
| 6957 | :: | ||
| 6958 | |||
| 6959 | PACKAGE_CLASSES ?= "package_packageformat" | ||
| 6960 | |||
| 6961 | where packageformat can be "ipk", "rpm", | ||
| 6962 | "deb", or "tar" which are the supported package formats. | ||
| 6963 | |||
| 6964 | .. note:: | ||
| 6965 | |||
| 6966 | Because the Yocto Project supports four different package formats, | ||
| 6967 | you can set the variable with more than one argument. However, the | ||
| 6968 | OpenEmbedded build system only uses the first argument when | ||
| 6969 | creating an image or Software Development Kit (SDK). | ||
| 6970 | |||
| 6971 | If you would like your image to start off with a basic package database | ||
| 6972 | containing the packages in your current build as well as to have the | ||
| 6973 | relevant tools available on the target for runtime package management, | ||
| 6974 | you can include "package-management" in the | ||
| 6975 | :term:`IMAGE_FEATURES` | ||
| 6976 | variable. Including "package-management" in this configuration variable | ||
| 6977 | ensures that when the image is assembled for your target, the image | ||
| 6978 | includes the currently-known package databases as well as the | ||
| 6979 | target-specific tools required for runtime package management to be | ||
| 6980 | performed on the target. However, this is not strictly necessary. You | ||
| 6981 | could start your image off without any databases but only include the | ||
| 6982 | required on-target package tool(s). As an example, you could include | ||
| 6983 | "opkg" in your | ||
| 6984 | :term:`IMAGE_INSTALL` variable | ||
| 6985 | if you are using the IPK package format. You can then initialize your | ||
| 6986 | target's package database(s) later once your image is up and running. | ||
| 6987 | |||
| 6988 | Whenever you perform any sort of build step that can potentially | ||
| 6989 | generate a package or modify existing package, it is always a good idea | ||
| 6990 | to re-generate the package index after the build by using the following | ||
| 6991 | command: | ||
| 6992 | :: | ||
| 6993 | |||
| 6994 | $ bitbake package-index | ||
| 6995 | |||
| 6996 | It might be tempting to build the | ||
| 6997 | package and the package index at the same time with a command such as | ||
| 6998 | the following: | ||
| 6999 | :: | ||
| 7000 | |||
| 7001 | $ bitbake some-package package-index | ||
| 7002 | |||
| 7003 | Do not do this as | ||
| 7004 | BitBake does not schedule the package index for after the completion of | ||
| 7005 | the package you are building. Consequently, you cannot be sure of the | ||
| 7006 | package index including information for the package you just built. | ||
| 7007 | Thus, be sure to run the package update step separately after building | ||
| 7008 | any packages. | ||
| 7009 | |||
| 7010 | You can use the | ||
| 7011 | :term:`PACKAGE_FEED_ARCHS`, | ||
| 7012 | :term:`PACKAGE_FEED_BASE_PATHS`, | ||
| 7013 | and | ||
| 7014 | :term:`PACKAGE_FEED_URIS` | ||
| 7015 | variables to pre-configure target images to use a package feed. If you | ||
| 7016 | do not define these variables, then manual steps as described in the | ||
| 7017 | subsequent sections are necessary to configure the target. You should | ||
| 7018 | set these variables before building the image in order to produce a | ||
| 7019 | correctly configured image. | ||
| 7020 | |||
| 7021 | When your build is complete, your packages reside in the | ||
| 7022 | ``${TMPDIR}/deploy/packageformat`` directory. For example, if | ||
| 7023 | ``${``\ :term:`TMPDIR`\ ``}`` is | ||
| 7024 | ``tmp`` and your selected package type is RPM, then your RPM packages | ||
| 7025 | are available in ``tmp/deploy/rpm``. | ||
| 7026 | |||
| 7027 | Host or Server Machine Setup | ||
| 7028 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 7029 | |||
| 7030 | Although other protocols are possible, a server using HTTP typically | ||
| 7031 | serves packages. If you want to use HTTP, then set up and configure a | ||
| 7032 | web server such as Apache 2, lighttpd, or Python web server on the | ||
| 7033 | machine serving the packages. | ||
| 7034 | |||
| 7035 | To keep things simple, this section describes how to set up a | ||
| 7036 | Python web server to share package feeds from the developer's | ||
| 7037 | machine. Although this server might not be the best for a production | ||
| 7038 | environment, the setup is simple and straight forward. Should you want | ||
| 7039 | to use a different server more suited for production (e.g. Apache 2, | ||
| 7040 | Lighttpd, or Nginx), take the appropriate steps to do so. | ||
| 7041 | |||
| 7042 | From within the build directory where you have built an image based on | ||
| 7043 | your packaging choice (i.e. the | ||
| 7044 | :term:`PACKAGE_CLASSES` | ||
| 7045 | setting), simply start the server. The following example assumes a build | ||
| 7046 | directory of ``~/poky/build/tmp/deploy/rpm`` and a ``PACKAGE_CLASSES`` | ||
| 7047 | setting of "package_rpm": | ||
| 7048 | :: | ||
| 7049 | |||
| 7050 | $ cd ~/poky/build/tmp/deploy/rpm | ||
| 7051 | $ python3 -m http.server | ||
| 7052 | |||
| 7053 | Target Setup | ||
| 7054 | ~~~~~~~~~~~~ | ||
| 7055 | |||
| 7056 | Setting up the target differs depending on the package management | ||
| 7057 | system. This section provides information for RPM, IPK, and DEB. | ||
| 7058 | |||
| 7059 | Using RPM | ||
| 7060 | ^^^^^^^^^ | ||
| 7061 | |||
| 7062 | The `Dandified Packaging | ||
| 7063 | Tool <https://en.wikipedia.org/wiki/DNF_(software)>`__ (DNF) performs | ||
| 7064 | runtime package management of RPM packages. In order to use DNF for | ||
| 7065 | runtime package management, you must perform an initial setup on the | ||
| 7066 | target machine for cases where the ``PACKAGE_FEED_*`` variables were not | ||
| 7067 | set as part of the image that is running on the target. This means if | ||
| 7068 | you built your image and did not not use these variables as part of the | ||
| 7069 | build and your image is now running on the target, you need to perform | ||
| 7070 | the steps in this section if you want to use runtime package management. | ||
| 7071 | |||
| 7072 | .. note:: | ||
| 7073 | |||
| 7074 | For information on the ``PACKAGE_FEED_*`` variables, see | ||
| 7075 | :term:`PACKAGE_FEED_ARCHS`, :term:`PACKAGE_FEED_BASE_PATHS`, and | ||
| 7076 | :term:`PACKAGE_FEED_URIS` in the Yocto Project Reference Manual variables | ||
| 7077 | glossary. | ||
| 7078 | |||
| 7079 | On the target, you must inform DNF that package databases are available. | ||
| 7080 | You do this by creating a file named | ||
| 7081 | ``/etc/yum.repos.d/oe-packages.repo`` and defining the ``oe-packages``. | ||
| 7082 | |||
| 7083 | As an example, assume the target is able to use the following package | ||
| 7084 | databases: ``all``, ``i586``, and ``qemux86`` from a server named | ||
| 7085 | ``my.server``. The specifics for setting up the web server are up to | ||
| 7086 | you. The critical requirement is that the URIs in the target repository | ||
| 7087 | configuration point to the correct remote location for the feeds. | ||
| 7088 | |||
| 7089 | .. note:: | ||
| 7090 | |||
| 7091 | For development purposes, you can point the web server to the build | ||
| 7092 | system's ``deploy`` directory. However, for production use, it is better to | ||
| 7093 | copy the package directories to a location outside of the build area and use | ||
| 7094 | that location. Doing so avoids situations where the build system | ||
| 7095 | overwrites or changes the ``deploy`` directory. | ||
| 7096 | |||
| 7097 | When telling DNF where to look for the package databases, you must | ||
| 7098 | declare individual locations per architecture or a single location used | ||
| 7099 | for all architectures. You cannot do both: | ||
| 7100 | |||
| 7101 | - *Create an Explicit List of Architectures:* Define individual base | ||
| 7102 | URLs to identify where each package database is located: | ||
| 7103 | |||
| 7104 | .. code-block:: none | ||
| 7105 | |||
| 7106 | [oe-packages] | ||
| 7107 | baseurl=http://my.server/rpm/i586 http://my.server/rpm/qemux86 http://my.server/rpm/all | ||
| 7108 | |||
| 7109 | This example | ||
| 7110 | informs DNF about individual package databases for all three | ||
| 7111 | architectures. | ||
| 7112 | |||
| 7113 | - *Create a Single (Full) Package Index:* Define a single base URL that | ||
| 7114 | identifies where a full package database is located: | ||
| 7115 | :: | ||
| 7116 | |||
| 7117 | [oe-packages] | ||
| 7118 | baseurl=http://my.server/rpm | ||
| 7119 | |||
| 7120 | This example informs DNF about a single | ||
| 7121 | package database that contains all the package index information for | ||
| 7122 | all supported architectures. | ||
| 7123 | |||
| 7124 | Once you have informed DNF where to find the package databases, you need | ||
| 7125 | to fetch them: | ||
| 7126 | |||
| 7127 | .. code-block:: none | ||
| 7128 | |||
| 7129 | # dnf makecache | ||
| 7130 | |||
| 7131 | DNF is now able to find, install, and | ||
| 7132 | upgrade packages from the specified repository or repositories. | ||
| 7133 | |||
| 7134 | .. note:: | ||
| 7135 | |||
| 7136 | See the `DNF documentation <https://dnf.readthedocs.io/en/latest/>`__ for | ||
| 7137 | additional information. | ||
| 7138 | |||
| 7139 | Using IPK | ||
| 7140 | ^^^^^^^^^ | ||
| 7141 | |||
| 7142 | The ``opkg`` application performs runtime package management of IPK | ||
| 7143 | packages. You must perform an initial setup for ``opkg`` on the target | ||
| 7144 | machine if the | ||
| 7145 | :term:`PACKAGE_FEED_ARCHS`, | ||
| 7146 | :term:`PACKAGE_FEED_BASE_PATHS`, | ||
| 7147 | and | ||
| 7148 | :term:`PACKAGE_FEED_URIS` | ||
| 7149 | variables have not been set or the target image was built before the | ||
| 7150 | variables were set. | ||
| 7151 | |||
| 7152 | The ``opkg`` application uses configuration files to find available | ||
| 7153 | package databases. Thus, you need to create a configuration file inside | ||
| 7154 | the ``/etc/opkg/`` direction, which informs ``opkg`` of any repository | ||
| 7155 | you want to use. | ||
| 7156 | |||
| 7157 | As an example, suppose you are serving packages from a ``ipk/`` | ||
| 7158 | directory containing the ``i586``, ``all``, and ``qemux86`` databases | ||
| 7159 | through an HTTP server named ``my.server``. On the target, create a | ||
| 7160 | configuration file (e.g. ``my_repo.conf``) inside the ``/etc/opkg/`` | ||
| 7161 | directory containing the following: | ||
| 7162 | |||
| 7163 | .. code-block:: none | ||
| 7164 | |||
| 7165 | src/gz all http://my.server/ipk/all | ||
| 7166 | src/gz i586 http://my.server/ipk/i586 | ||
| 7167 | src/gz qemux86 http://my.server/ipk/qemux86 | ||
| 7168 | |||
| 7169 | Next, instruct ``opkg`` to fetch the | ||
| 7170 | repository information: | ||
| 7171 | |||
| 7172 | .. code-block:: none | ||
| 7173 | |||
| 7174 | # opkg update | ||
| 7175 | |||
| 7176 | The ``opkg`` application is now able to find, install, and upgrade packages | ||
| 7177 | from the specified repository. | ||
| 7178 | |||
| 7179 | Using DEB | ||
| 7180 | ^^^^^^^^^ | ||
| 7181 | |||
| 7182 | The ``apt`` application performs runtime package management of DEB | ||
| 7183 | packages. This application uses a source list file to find available | ||
| 7184 | package databases. You must perform an initial setup for ``apt`` on the | ||
| 7185 | target machine if the | ||
| 7186 | :term:`PACKAGE_FEED_ARCHS`, | ||
| 7187 | :term:`PACKAGE_FEED_BASE_PATHS`, | ||
| 7188 | and | ||
| 7189 | :term:`PACKAGE_FEED_URIS` | ||
| 7190 | variables have not been set or the target image was built before the | ||
| 7191 | variables were set. | ||
| 7192 | |||
| 7193 | To inform ``apt`` of the repository you want to use, you might create a | ||
| 7194 | list file (e.g. ``my_repo.list``) inside the | ||
| 7195 | ``/etc/apt/sources.list.d/`` directory. As an example, suppose you are | ||
| 7196 | serving packages from a ``deb/`` directory containing the ``i586``, | ||
| 7197 | ``all``, and ``qemux86`` databases through an HTTP server named | ||
| 7198 | ``my.server``. The list file should contain: | ||
| 7199 | |||
| 7200 | .. code-block:: none | ||
| 7201 | |||
| 7202 | deb http://my.server/deb/all ./ | ||
| 7203 | deb http://my.server/deb/i586 ./ | ||
| 7204 | deb http://my.server/deb/qemux86 ./ | ||
| 7205 | |||
| 7206 | Next, instruct the ``apt`` application | ||
| 7207 | to fetch the repository information: | ||
| 7208 | |||
| 7209 | .. code-block:: none | ||
| 7210 | |||
| 7211 | # apt-get update | ||
| 7212 | |||
| 7213 | After this step, | ||
| 7214 | ``apt`` is able to find, install, and upgrade packages from the | ||
| 7215 | specified repository. | ||
| 7216 | |||
| 7217 | Generating and Using Signed Packages | ||
| 7218 | ------------------------------------ | ||
| 7219 | |||
| 7220 | In order to add security to RPM packages used during a build, you can | ||
| 7221 | take steps to securely sign them. Once a signature is verified, the | ||
| 7222 | OpenEmbedded build system can use the package in the build. If security | ||
| 7223 | fails for a signed package, the build system aborts the build. | ||
| 7224 | |||
| 7225 | This section describes how to sign RPM packages during a build and how | ||
| 7226 | to use signed package feeds (repositories) when doing a build. | ||
| 7227 | |||
| 7228 | Signing RPM Packages | ||
| 7229 | ~~~~~~~~~~~~~~~~~~~~ | ||
| 7230 | |||
| 7231 | To enable signing RPM packages, you must set up the following | ||
| 7232 | configurations in either your ``local.config`` or ``distro.config`` | ||
| 7233 | file: | ||
| 7234 | :: | ||
| 7235 | |||
| 7236 | # Inherit sign_rpm.bbclass to enable signing functionality | ||
| 7237 | INHERIT += " sign_rpm" | ||
| 7238 | # Define the GPG key that will be used for signing. | ||
| 7239 | RPM_GPG_NAME = "key_name" | ||
| 7240 | # Provide passphrase for the key | ||
| 7241 | RPM_GPG_PASSPHRASE = "passphrase" | ||
| 7242 | |||
| 7243 | .. note:: | ||
| 7244 | |||
| 7245 | Be sure to supply appropriate values for both `key_name` and | ||
| 7246 | `passphrase`. | ||
| 7247 | |||
| 7248 | Aside from the ``RPM_GPG_NAME`` and ``RPM_GPG_PASSPHRASE`` variables in | ||
| 7249 | the previous example, two optional variables related to signing exist: | ||
| 7250 | |||
| 7251 | - *GPG_BIN:* Specifies a ``gpg`` binary/wrapper that is executed | ||
| 7252 | when the package is signed. | ||
| 7253 | |||
| 7254 | - *GPG_PATH:* Specifies the ``gpg`` home directory used when the | ||
| 7255 | package is signed. | ||
| 7256 | |||
| 7257 | Processing Package Feeds | ||
| 7258 | ~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 7259 | |||
| 7260 | In addition to being able to sign RPM packages, you can also enable | ||
| 7261 | signed package feeds for IPK and RPM packages. | ||
| 7262 | |||
| 7263 | The steps you need to take to enable signed package feed use are similar | ||
| 7264 | to the steps used to sign RPM packages. You must define the following in | ||
| 7265 | your ``local.config`` or ``distro.config`` file: | ||
| 7266 | :: | ||
| 7267 | |||
| 7268 | INHERIT += "sign_package_feed" | ||
| 7269 | PACKAGE_FEED_GPG_NAME = "key_name" | ||
| 7270 | PACKAGE_FEED_GPG_PASSPHRASE_FILE = "path_to_file_containing_passphrase" | ||
| 7271 | |||
| 7272 | For signed package feeds, the passphrase must exist in a separate file, | ||
| 7273 | which is pointed to by the ``PACKAGE_FEED_GPG_PASSPHRASE_FILE`` | ||
| 7274 | variable. Regarding security, keeping a plain text passphrase out of the | ||
| 7275 | configuration is more secure. | ||
| 7276 | |||
| 7277 | Aside from the ``PACKAGE_FEED_GPG_NAME`` and | ||
| 7278 | ``PACKAGE_FEED_GPG_PASSPHRASE_FILE`` variables, three optional variables | ||
| 7279 | related to signed package feeds exist: | ||
| 7280 | |||
| 7281 | - *GPG_BIN* Specifies a ``gpg`` binary/wrapper that is executed | ||
| 7282 | when the package is signed. | ||
| 7283 | |||
| 7284 | - *GPG_PATH:* Specifies the ``gpg`` home directory used when the | ||
| 7285 | package is signed. | ||
| 7286 | |||
| 7287 | - *PACKAGE_FEED_GPG_SIGNATURE_TYPE:* Specifies the type of ``gpg`` | ||
| 7288 | signature. This variable applies only to RPM and IPK package feeds. | ||
| 7289 | Allowable values for the ``PACKAGE_FEED_GPG_SIGNATURE_TYPE`` are | ||
| 7290 | "ASC", which is the default and specifies ascii armored, and "BIN", | ||
| 7291 | which specifies binary. | ||
| 7292 | |||
| 7293 | Testing Packages With ptest | ||
| 7294 | --------------------------- | ||
| 7295 | |||
| 7296 | A Package Test (ptest) runs tests against packages built by the | ||
| 7297 | OpenEmbedded build system on the target machine. A ptest contains at | ||
| 7298 | least two items: the actual test, and a shell script (``run-ptest``) | ||
| 7299 | that starts the test. The shell script that starts the test must not | ||
| 7300 | contain the actual test - the script only starts the test. On the other | ||
| 7301 | hand, the test can be anything from a simple shell script that runs a | ||
| 7302 | binary and checks the output to an elaborate system of test binaries and | ||
| 7303 | data files. | ||
| 7304 | |||
| 7305 | The test generates output in the format used by Automake: | ||
| 7306 | :: | ||
| 7307 | |||
| 7308 | result: testname | ||
| 7309 | |||
| 7310 | where the result can be ``PASS``, ``FAIL``, or ``SKIP``, and | ||
| 7311 | the testname can be any identifying string. | ||
| 7312 | |||
| 7313 | For a list of Yocto Project recipes that are already enabled with ptest, | ||
| 7314 | see the :yocto_wiki:`Ptest </Ptest>` wiki page. | ||
| 7315 | |||
| 7316 | .. note:: | ||
| 7317 | |||
| 7318 | A recipe is "ptest-enabled" if it inherits the | ||
| 7319 | :ref:`ptest <ref-classes-ptest>` class. | ||
| 7320 | |||
| 7321 | Adding ptest to Your Build | ||
| 7322 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 7323 | |||
| 7324 | To add package testing to your build, add the | ||
| 7325 | :term:`DISTRO_FEATURES` and | ||
| 7326 | :term:`EXTRA_IMAGE_FEATURES` | ||
| 7327 | variables to your ``local.conf`` file, which is found in the | ||
| 7328 | :term:`Build Directory`: | ||
| 7329 | :: | ||
| 7330 | |||
| 7331 | DISTRO_FEATURES_append = " ptest" | ||
| 7332 | EXTRA_IMAGE_FEATURES += "ptest-pkgs" | ||
| 7333 | |||
| 7334 | Once your build is complete, the ptest files are installed into the | ||
| 7335 | ``/usr/lib/package/ptest`` directory within the image, where ``package`` | ||
| 7336 | is the name of the package. | ||
| 7337 | |||
| 7338 | Running ptest | ||
| 7339 | ~~~~~~~~~~~~~ | ||
| 7340 | |||
| 7341 | The ``ptest-runner`` package installs a shell script that loops through | ||
| 7342 | all installed ptest test suites and runs them in sequence. Consequently, | ||
| 7343 | you might want to add this package to your image. | ||
| 7344 | |||
| 7345 | Getting Your Package Ready | ||
| 7346 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 7347 | |||
| 7348 | In order to enable a recipe to run installed ptests on target hardware, | ||
| 7349 | you need to prepare the recipes that build the packages you want to | ||
| 7350 | test. Here is what you have to do for each recipe: | ||
| 7351 | |||
| 7352 | - *Be sure the recipe inherits | ||
| 7353 | the* :ref:`ptest <ref-classes-ptest>` *class:* | ||
| 7354 | Include the following line in each recipe: | ||
| 7355 | :: | ||
| 7356 | |||
| 7357 | inherit ptest | ||
| 7358 | |||
| 7359 | - *Create run-ptest:* This script starts your test. Locate the | ||
| 7360 | script where you will refer to it using | ||
| 7361 | :term:`SRC_URI`. Here is an | ||
| 7362 | example that starts a test for ``dbus``: | ||
| 7363 | :: | ||
| 7364 | |||
| 7365 | #!/bin/sh | ||
| 7366 | cd test | ||
| 7367 | make -k runtest-TESTS | ||
| 7368 | |||
| 7369 | - *Ensure dependencies are met:* If the test adds build or runtime | ||
| 7370 | dependencies that normally do not exist for the package (such as | ||
| 7371 | requiring "make" to run the test suite), use the | ||
| 7372 | :term:`DEPENDS` and | ||
| 7373 | :term:`RDEPENDS` variables in | ||
| 7374 | your recipe in order for the package to meet the dependencies. Here | ||
| 7375 | is an example where the package has a runtime dependency on "make": | ||
| 7376 | :: | ||
| 7377 | |||
| 7378 | RDEPENDS_${PN}-ptest += "make" | ||
| 7379 | |||
| 7380 | - *Add a function to build the test suite:* Not many packages support | ||
| 7381 | cross-compilation of their test suites. Consequently, you usually | ||
| 7382 | need to add a cross-compilation function to the package. | ||
| 7383 | |||
| 7384 | Many packages based on Automake compile and run the test suite by | ||
| 7385 | using a single command such as ``make check``. However, the host | ||
| 7386 | ``make check`` builds and runs on the same computer, while | ||
| 7387 | cross-compiling requires that the package is built on the host but | ||
| 7388 | executed for the target architecture (though often, as in the case | ||
| 7389 | for ptest, the execution occurs on the host). The built version of | ||
| 7390 | Automake that ships with the Yocto Project includes a patch that | ||
| 7391 | separates building and execution. Consequently, packages that use the | ||
| 7392 | unaltered, patched version of ``make check`` automatically | ||
| 7393 | cross-compiles. | ||
| 7394 | |||
| 7395 | Regardless, you still must add a ``do_compile_ptest`` function to | ||
| 7396 | build the test suite. Add a function similar to the following to your | ||
| 7397 | recipe: | ||
| 7398 | :: | ||
| 7399 | |||
| 7400 | do_compile_ptest() { | ||
| 7401 | oe_runmake buildtest-TESTS | ||
| 7402 | } | ||
| 7403 | |||
| 7404 | - *Ensure special configurations are set:* If the package requires | ||
| 7405 | special configurations prior to compiling the test code, you must | ||
| 7406 | insert a ``do_configure_ptest`` function into the recipe. | ||
| 7407 | |||
| 7408 | - *Install the test suite:* The ``ptest`` class automatically copies | ||
| 7409 | the file ``run-ptest`` to the target and then runs make | ||
| 7410 | ``install-ptest`` to run the tests. If this is not enough, you need | ||
| 7411 | to create a ``do_install_ptest`` function and make sure it gets | ||
| 7412 | called after the "make install-ptest" completes. | ||
| 7413 | |||
| 7414 | Creating Node Package Manager (NPM) Packages | ||
| 7415 | -------------------------------------------- | ||
| 7416 | |||
| 7417 | `NPM <https://en.wikipedia.org/wiki/Npm_(software)>`__ is a package | ||
| 7418 | manager for the JavaScript programming language. The Yocto Project | ||
| 7419 | supports the NPM :ref:`fetcher <bitbake:bitbake-user-manual/bitbake-user-manual-fetching:fetchers>`. You can | ||
| 7420 | use this fetcher in combination with | ||
| 7421 | :doc:`devtool </ref-manual/ref-devtool-reference>` to create | ||
| 7422 | recipes that produce NPM packages. | ||
| 7423 | |||
| 7424 | Two workflows exist that allow you to create NPM packages using | ||
| 7425 | ``devtool``: the NPM registry modules method and the NPM project code | ||
| 7426 | method. | ||
| 7427 | |||
| 7428 | .. note:: | ||
| 7429 | |||
| 7430 | While it is possible to create NPM recipes manually, using | ||
| 7431 | ``devtool`` is far simpler. | ||
| 7432 | |||
| 7433 | Additionally, some requirements and caveats exist. | ||
| 7434 | |||
| 7435 | Requirements and Caveats | ||
| 7436 | ~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 7437 | |||
| 7438 | You need to be aware of the following before using ``devtool`` to create | ||
| 7439 | NPM packages: | ||
| 7440 | |||
| 7441 | - Of the two methods that you can use ``devtool`` to create NPM | ||
| 7442 | packages, the registry approach is slightly simpler. However, you | ||
| 7443 | might consider the project approach because you do not have to | ||
| 7444 | publish your module in the NPM registry | ||
| 7445 | (`npm-registry <https://docs.npmjs.com/misc/registry>`_), which | ||
| 7446 | is NPM's public registry. | ||
| 7447 | |||
| 7448 | - Be familiar with | ||
| 7449 | :doc:`devtool </ref-manual/ref-devtool-reference>`. | ||
| 7450 | |||
| 7451 | - The NPM host tools need the native ``nodejs-npm`` package, which is | ||
| 7452 | part of the OpenEmbedded environment. You need to get the package by | ||
| 7453 | cloning the https://github.com/openembedded/meta-openembedded | ||
| 7454 | repository out of GitHub. Be sure to add the path to your local copy | ||
| 7455 | to your ``bblayers.conf`` file. | ||
| 7456 | |||
| 7457 | - ``devtool`` cannot detect native libraries in module dependencies. | ||
| 7458 | Consequently, you must manually add packages to your recipe. | ||
| 7459 | |||
| 7460 | - While deploying NPM packages, ``devtool`` cannot determine which | ||
| 7461 | dependent packages are missing on the target (e.g. the node runtime | ||
| 7462 | ``nodejs``). Consequently, you need to find out what files are | ||
| 7463 | missing and be sure they are on the target. | ||
| 7464 | |||
| 7465 | - Although you might not need NPM to run your node package, it is | ||
| 7466 | useful to have NPM on your target. The NPM package name is | ||
| 7467 | ``nodejs-npm``. | ||
| 7468 | |||
| 7469 | Using the Registry Modules Method | ||
| 7470 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 7471 | |||
| 7472 | This section presents an example that uses the ``cute-files`` module, | ||
| 7473 | which is a file browser web application. | ||
| 7474 | |||
| 7475 | .. note:: | ||
| 7476 | |||
| 7477 | You must know the ``cute-files`` module version. | ||
| 7478 | |||
| 7479 | The first thing you need to do is use ``devtool`` and the NPM fetcher to | ||
| 7480 | create the recipe: | ||
| 7481 | :: | ||
| 7482 | |||
| 7483 | $ devtool add "npm://registry.npmjs.org;package=cute-files;version=1.0.2" | ||
| 7484 | |||
| 7485 | The | ||
| 7486 | ``devtool add`` command runs ``recipetool create`` and uses the same | ||
| 7487 | fetch URI to download each dependency and capture license details where | ||
| 7488 | possible. The result is a generated recipe. | ||
| 7489 | |||
| 7490 | The recipe file is fairly simple and contains every license that | ||
| 7491 | ``recipetool`` finds and includes the licenses in the recipe's | ||
| 7492 | :term:`LIC_FILES_CHKSUM` | ||
| 7493 | variables. You need to examine the variables and look for those with | ||
| 7494 | "unknown" in the :term:`LICENSE` | ||
| 7495 | field. You need to track down the license information for "unknown" | ||
| 7496 | modules and manually add the information to the recipe. | ||
| 7497 | |||
| 7498 | ``recipetool`` creates a "shrinkwrap" file for your recipe. Shrinkwrap | ||
| 7499 | files capture the version of all dependent modules. Many packages do not | ||
| 7500 | provide shrinkwrap files. ``recipetool`` create a shrinkwrap file as it | ||
| 7501 | runs. | ||
| 7502 | |||
| 7503 | .. note:: | ||
| 7504 | |||
| 7505 | A package is created for each sub-module. This policy is the only | ||
| 7506 | practical way to have the licenses for all of the dependencies | ||
| 7507 | represented in the license manifest of the image. | ||
| 7508 | |||
| 7509 | The ``devtool edit-recipe`` command lets you take a look at the recipe: | ||
| 7510 | :: | ||
| 7511 | |||
| 7512 | $ devtool edit-recipe cute-files | ||
| 7513 | SUMMARY = "Turn any folder on your computer into a cute file browser, available on the local network." | ||
| 7514 | LICENSE = "MIT & ISC & Unknown" | ||
| 7515 | LIC_FILES_CHKSUM = "file://LICENSE;md5=71d98c0a1db42956787b1909c74a86ca \ | ||
| 7516 | file://node_modules/toidentifier/LICENSE;md5=1a261071a044d02eb6f2bb47f51a3502 \ | ||
| 7517 | file://node_modules/debug/LICENSE;md5=ddd815a475e7338b0be7a14d8ee35a99 \ | ||
| 7518 | ... | ||
| 7519 | SRC_URI = " \ | ||
| 7520 | npm://registry.npmjs.org/;package=cute-files;version=${PV} \ | ||
| 7521 | npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \ | ||
| 7522 | " | ||
| 7523 | S = "${WORKDIR}/npm" | ||
| 7524 | inherit npm LICENSE_${PN} = "MIT" | ||
| 7525 | LICENSE_${PN}-accepts = "MIT" | ||
| 7526 | LICENSE_${PN}-array-flatten = "MIT" | ||
| 7527 | ... | ||
| 7528 | LICENSE_${PN}-vary = "MIT" | ||
| 7529 | |||
| 7530 | Three key points exist in the previous example: | ||
| 7531 | |||
| 7532 | - :term:`SRC_URI` uses the NPM | ||
| 7533 | scheme so that the NPM fetcher is used. | ||
| 7534 | |||
| 7535 | - ``recipetool`` collects all the license information. If a | ||
| 7536 | sub-module's license is unavailable, the sub-module's name appears in | ||
| 7537 | the comments. | ||
| 7538 | |||
| 7539 | - The ``inherit npm`` statement causes the | ||
| 7540 | :ref:`npm <ref-classes-npm>` class to package | ||
| 7541 | up all the modules. | ||
| 7542 | |||
| 7543 | You can run the following command to build the ``cute-files`` package: | ||
| 7544 | :: | ||
| 7545 | |||
| 7546 | $ devtool build cute-files | ||
| 7547 | |||
| 7548 | Remember that ``nodejs`` must be installed on | ||
| 7549 | the target before your package. | ||
| 7550 | |||
| 7551 | Assuming 192.168.7.2 for the target's IP address, use the following | ||
| 7552 | command to deploy your package: | ||
| 7553 | :: | ||
| 7554 | |||
| 7555 | $ devtool deploy-target -s cute-files root@192.168.7.2 | ||
| 7556 | |||
| 7557 | Once the package is installed on the target, you can | ||
| 7558 | test the application: | ||
| 7559 | |||
| 7560 | .. note:: | ||
| 7561 | |||
| 7562 | Because of a known issue, you cannot simply run ``cute-files`` as you would | ||
| 7563 | if you had run ``npm install``. | ||
| 7564 | |||
| 7565 | :: | ||
| 7566 | |||
| 7567 | $ cd /usr/lib/node_modules/cute-files | ||
| 7568 | $ node cute-files.js | ||
| 7569 | |||
| 7570 | On a browser, | ||
| 7571 | go to ``http://192.168.7.2:3000`` and you see the following: | ||
| 7572 | |||
| 7573 | .. image:: figures/cute-files-npm-example.png | ||
| 7574 | :align: center | ||
| 7575 | |||
| 7576 | You can find the recipe in ``workspace/recipes/cute-files``. You can use | ||
| 7577 | the recipe in any layer you choose. | ||
| 7578 | |||
| 7579 | Using the NPM Projects Code Method | ||
| 7580 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 7581 | |||
| 7582 | Although it is useful to package modules already in the NPM registry, | ||
| 7583 | adding ``node.js`` projects under development is a more common developer | ||
| 7584 | use case. | ||
| 7585 | |||
| 7586 | This section covers the NPM projects code method, which is very similar | ||
| 7587 | to the "registry" approach described in the previous section. In the NPM | ||
| 7588 | projects method, you provide ``devtool`` with an URL that points to the | ||
| 7589 | source files. | ||
| 7590 | |||
| 7591 | Replicating the same example, (i.e. ``cute-files``) use the following | ||
| 7592 | command: | ||
| 7593 | :: | ||
| 7594 | |||
| 7595 | $ devtool add https://github.com/martinaglv/cute-files.git | ||
| 7596 | |||
| 7597 | The | ||
| 7598 | recipe this command generates is very similar to the recipe created in | ||
| 7599 | the previous section. However, the ``SRC_URI`` looks like the following: | ||
| 7600 | :: | ||
| 7601 | |||
| 7602 | SRC_URI = " \ | ||
| 7603 | git://github.com/martinaglv/cute-files.git;protocol=https \ | ||
| 7604 | npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \ | ||
| 7605 | " | ||
| 7606 | |||
| 7607 | In this example, | ||
| 7608 | the main module is taken from the Git repository and dependencies are | ||
| 7609 | taken from the NPM registry. Other than those differences, the recipe is | ||
| 7610 | basically the same between the two methods. You can build and deploy the | ||
| 7611 | package exactly as described in the previous section that uses the | ||
| 7612 | registry modules method. | ||
| 7613 | |||
| 7614 | Adding custom metadata to packages | ||
| 7615 | ---------------------------------- | ||
| 7616 | |||
| 7617 | The variable | ||
| 7618 | :term:`PACKAGE_ADD_METADATA` | ||
| 7619 | can be used to add additional metadata to packages. This is reflected in | ||
| 7620 | the package control/spec file. To take the ipk format for example, the | ||
| 7621 | CONTROL file stored inside would contain the additional metadata as | ||
| 7622 | additional lines. | ||
| 7623 | |||
| 7624 | The variable can be used in multiple ways, including using suffixes to | ||
| 7625 | set it for a specific package type and/or package. Note that the order | ||
| 7626 | of precedence is the same as this list: | ||
| 7627 | |||
| 7628 | - ``PACKAGE_ADD_METADATA_<PKGTYPE>_<PN>`` | ||
| 7629 | |||
| 7630 | - ``PACKAGE_ADD_METADATA_<PKGTYPE>`` | ||
| 7631 | |||
| 7632 | - ``PACKAGE_ADD_METADATA_<PN>`` | ||
| 7633 | |||
| 7634 | - ``PACKAGE_ADD_METADATA`` | ||
| 7635 | |||
| 7636 | `<PKGTYPE>` is a parameter and expected to be a distinct name of specific | ||
| 7637 | package type: | ||
| 7638 | |||
| 7639 | - IPK for .ipk packages | ||
| 7640 | |||
| 7641 | - DEB for .deb packages | ||
| 7642 | |||
| 7643 | - RPM for .rpm packages | ||
| 7644 | |||
| 7645 | `<PN>` is a parameter and expected to be a package name. | ||
| 7646 | |||
| 7647 | The variable can contain multiple [one-line] metadata fields separated | ||
| 7648 | by the literal sequence '\\n'. The separator can be redefined using the | ||
| 7649 | variable flag ``separator``. | ||
| 7650 | |||
| 7651 | The following is an example that adds two custom fields for ipk | ||
| 7652 | packages: | ||
| 7653 | :: | ||
| 7654 | |||
| 7655 | PACKAGE_ADD_METADATA_IPK = "Vendor: CustomIpk\nGroup:Applications/Spreadsheets" | ||
| 7656 | |||
| 7657 | Efficiently Fetching Source Files During a Build | ||
| 7658 | ================================================ | ||
| 7659 | |||
| 7660 | The OpenEmbedded build system works with source files located through | ||
| 7661 | the :term:`SRC_URI` variable. When | ||
| 7662 | you build something using BitBake, a big part of the operation is | ||
| 7663 | locating and downloading all the source tarballs. For images, | ||
| 7664 | downloading all the source for various packages can take a significant | ||
| 7665 | amount of time. | ||
| 7666 | |||
| 7667 | This section shows you how you can use mirrors to speed up fetching | ||
| 7668 | source files and how you can pre-fetch files all of which leads to more | ||
| 7669 | efficient use of resources and time. | ||
| 7670 | |||
| 7671 | Setting up Effective Mirrors | ||
| 7672 | ---------------------------- | ||
| 7673 | |||
| 7674 | A good deal that goes into a Yocto Project build is simply downloading | ||
| 7675 | all of the source tarballs. Maybe you have been working with another | ||
| 7676 | build system (OpenEmbedded or Angstrom) for which you have built up a | ||
| 7677 | sizable directory of source tarballs. Or, perhaps someone else has such | ||
| 7678 | a directory for which you have read access. If so, you can save time by | ||
| 7679 | adding statements to your configuration file so that the build process | ||
| 7680 | checks local directories first for existing tarballs before checking the | ||
| 7681 | Internet. | ||
| 7682 | |||
| 7683 | Here is an efficient way to set it up in your ``local.conf`` file: | ||
| 7684 | :: | ||
| 7685 | |||
| 7686 | SOURCE_MIRROR_URL ?= "file:///home/you/your-download-dir/" | ||
| 7687 | INHERIT += "own-mirrors" | ||
| 7688 | BB_GENERATE_MIRROR_TARBALLS = "1" | ||
| 7689 | # BB_NO_NETWORK = "1" | ||
| 7690 | |||
| 7691 | In the previous example, the | ||
| 7692 | :term:`BB_GENERATE_MIRROR_TARBALLS` | ||
| 7693 | variable causes the OpenEmbedded build system to generate tarballs of | ||
| 7694 | the Git repositories and store them in the | ||
| 7695 | :term:`DL_DIR` directory. Due to | ||
| 7696 | performance reasons, generating and storing these tarballs is not the | ||
| 7697 | build system's default behavior. | ||
| 7698 | |||
| 7699 | You can also use the | ||
| 7700 | :term:`PREMIRRORS` variable. For | ||
| 7701 | an example, see the variable's glossary entry in the Yocto Project | ||
| 7702 | Reference Manual. | ||
| 7703 | |||
| 7704 | Getting Source Files and Suppressing the Build | ||
| 7705 | ---------------------------------------------- | ||
| 7706 | |||
| 7707 | Another technique you can use to ready yourself for a successive string | ||
| 7708 | of build operations, is to pre-fetch all the source files without | ||
| 7709 | actually starting a build. This technique lets you work through any | ||
| 7710 | download issues and ultimately gathers all the source files into your | ||
| 7711 | download directory :ref:`structure-build-downloads`, | ||
| 7712 | which is located with :term:`DL_DIR`. | ||
| 7713 | |||
| 7714 | Use the following BitBake command form to fetch all the necessary | ||
| 7715 | sources without starting the build: | ||
| 7716 | :: | ||
| 7717 | |||
| 7718 | $ bitbake target --runall=fetch | ||
| 7719 | |||
| 7720 | This | ||
| 7721 | variation of the BitBake command guarantees that you have all the | ||
| 7722 | sources for that BitBake target should you disconnect from the Internet | ||
| 7723 | and want to do the build later offline. | ||
| 7724 | |||
| 7725 | Selecting an Initialization Manager | ||
| 7726 | =================================== | ||
| 7727 | |||
| 7728 | By default, the Yocto Project uses SysVinit as the initialization | ||
| 7729 | manager. However, support also exists for systemd, which is a full | ||
| 7730 | replacement for init with parallel starting of services, reduced shell | ||
| 7731 | overhead and other features that are used by many distributions. | ||
| 7732 | |||
| 7733 | Within the system, SysVinit treats system components as services. These | ||
| 7734 | services are maintained as shell scripts stored in the ``/etc/init.d/`` | ||
| 7735 | directory. Services organize into different run levels. This | ||
| 7736 | organization is maintained by putting links to the services in the | ||
| 7737 | ``/etc/rcN.d/`` directories, where `N/` is one of the following options: | ||
| 7738 | "S", "0", "1", "2", "3", "4", "5", or "6". | ||
| 7739 | |||
| 7740 | .. note:: | ||
| 7741 | |||
| 7742 | Each runlevel has a dependency on the previous runlevel. This | ||
| 7743 | dependency allows the services to work properly. | ||
| 7744 | |||
| 7745 | In comparison, systemd treats components as units. Using units is a | ||
| 7746 | broader concept as compared to using a service. A unit includes several | ||
| 7747 | different types of entities. Service is one of the types of entities. | ||
| 7748 | The runlevel concept in SysVinit corresponds to the concept of a target | ||
| 7749 | in systemd, where target is also a type of supported unit. | ||
| 7750 | |||
| 7751 | In a SysVinit-based system, services load sequentially (i.e. one by one) | ||
| 7752 | during init and parallelization is not supported. With systemd, services | ||
| 7753 | start in parallel. Needless to say, the method can have an impact on | ||
| 7754 | system startup performance. | ||
| 7755 | |||
| 7756 | If you want to use SysVinit, you do not have to do anything. But, if you | ||
| 7757 | want to use systemd, you must take some steps as described in the | ||
| 7758 | following sections. | ||
| 7759 | |||
| 7760 | Using systemd Exclusively | ||
| 7761 | ------------------------- | ||
| 7762 | |||
| 7763 | Set these variables in your distribution configuration file as follows: | ||
| 7764 | :: | ||
| 7765 | |||
| 7766 | DISTRO_FEATURES_append = " systemd" | ||
| 7767 | VIRTUAL-RUNTIME_init_manager = "systemd" | ||
| 7768 | |||
| 7769 | You can also prevent the SysVinit distribution feature from | ||
| 7770 | being automatically enabled as follows: | ||
| 7771 | :: | ||
| 7772 | |||
| 7773 | DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit" | ||
| 7774 | |||
| 7775 | Doing so removes any | ||
| 7776 | redundant SysVinit scripts. | ||
| 7777 | |||
| 7778 | To remove initscripts from your image altogether, set this variable | ||
| 7779 | also: | ||
| 7780 | :: | ||
| 7781 | |||
| 7782 | VIRTUAL-RUNTIME_initscripts = "" | ||
| 7783 | |||
| 7784 | For information on the backfill variable, see | ||
| 7785 | :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`. | ||
| 7786 | |||
| 7787 | Using systemd for the Main Image and Using SysVinit for the Rescue Image | ||
| 7788 | ------------------------------------------------------------------------ | ||
| 7789 | |||
| 7790 | Set these variables in your distribution configuration file as follows: | ||
| 7791 | :: | ||
| 7792 | |||
| 7793 | DISTRO_FEATURES_append = " systemd" | ||
| 7794 | VIRTUAL-RUNTIME_init_manager = "systemd" | ||
| 7795 | |||
| 7796 | Doing so causes your main image to use the | ||
| 7797 | ``packagegroup-core-boot.bb`` recipe and systemd. The rescue/minimal | ||
| 7798 | image cannot use this package group. However, it can install SysVinit | ||
| 7799 | and the appropriate packages will have support for both systemd and | ||
| 7800 | SysVinit. | ||
| 7801 | |||
| 7802 | Selecting a Device Manager | ||
| 7803 | ========================== | ||
| 7804 | |||
| 7805 | The Yocto Project provides multiple ways to manage the device manager | ||
| 7806 | (``/dev``): | ||
| 7807 | |||
| 7808 | - Persistent and Pre-Populated\ ``/dev``: For this case, the ``/dev`` | ||
| 7809 | directory is persistent and the required device nodes are created | ||
| 7810 | during the build. | ||
| 7811 | |||
| 7812 | - Use ``devtmpfs`` with a Device Manager: For this case, the ``/dev`` | ||
| 7813 | directory is provided by the kernel as an in-memory file system and | ||
| 7814 | is automatically populated by the kernel at runtime. Additional | ||
| 7815 | configuration of device nodes is done in user space by a device | ||
| 7816 | manager like ``udev`` or ``busybox-mdev``. | ||
| 7817 | |||
| 7818 | Using Persistent and Pre-Populated\ ``/dev`` | ||
| 7819 | -------------------------------------------- | ||
| 7820 | |||
| 7821 | To use the static method for device population, you need to set the | ||
| 7822 | :term:`USE_DEVFS` variable to "0" | ||
| 7823 | as follows: | ||
| 7824 | :: | ||
| 7825 | |||
| 7826 | USE_DEVFS = "0" | ||
| 7827 | |||
| 7828 | The content of the resulting ``/dev`` directory is defined in a Device | ||
| 7829 | Table file. The | ||
| 7830 | :term:`IMAGE_DEVICE_TABLES` | ||
| 7831 | variable defines the Device Table to use and should be set in the | ||
| 7832 | machine or distro configuration file. Alternatively, you can set this | ||
| 7833 | variable in your ``local.conf`` configuration file. | ||
| 7834 | |||
| 7835 | If you do not define the ``IMAGE_DEVICE_TABLES`` variable, the default | ||
| 7836 | ``device_table-minimal.txt`` is used: | ||
| 7837 | :: | ||
| 7838 | |||
| 7839 | IMAGE_DEVICE_TABLES = "device_table-mymachine.txt" | ||
| 7840 | |||
| 7841 | The population is handled by the ``makedevs`` utility during image | ||
| 7842 | creation: | ||
| 7843 | |||
| 7844 | Using ``devtmpfs`` and a Device Manager | ||
| 7845 | --------------------------------------- | ||
| 7846 | |||
| 7847 | To use the dynamic method for device population, you need to use (or be | ||
| 7848 | sure to set) the :term:`USE_DEVFS` | ||
| 7849 | variable to "1", which is the default: | ||
| 7850 | :: | ||
| 7851 | |||
| 7852 | USE_DEVFS = "1" | ||
| 7853 | |||
| 7854 | With this | ||
| 7855 | setting, the resulting ``/dev`` directory is populated by the kernel | ||
| 7856 | using ``devtmpfs``. Make sure the corresponding kernel configuration | ||
| 7857 | variable ``CONFIG_DEVTMPFS`` is set when building you build a Linux | ||
| 7858 | kernel. | ||
| 7859 | |||
| 7860 | All devices created by ``devtmpfs`` will be owned by ``root`` and have | ||
| 7861 | permissions ``0600``. | ||
| 7862 | |||
| 7863 | To have more control over the device nodes, you can use a device manager | ||
| 7864 | like ``udev`` or ``busybox-mdev``. You choose the device manager by | ||
| 7865 | defining the ``VIRTUAL-RUNTIME_dev_manager`` variable in your machine or | ||
| 7866 | distro configuration file. Alternatively, you can set this variable in | ||
| 7867 | your ``local.conf`` configuration file: | ||
| 7868 | :: | ||
| 7869 | |||
| 7870 | VIRTUAL-RUNTIME_dev_manager = "udev" | ||
| 7871 | |||
| 7872 | # Some alternative values | ||
| 7873 | # VIRTUAL-RUNTIME_dev_manager = "busybox-mdev" | ||
| 7874 | # VIRTUAL-RUNTIME_dev_manager = "systemd" | ||
| 7875 | |||
| 7876 | Using an External SCM | ||
| 7877 | ===================== | ||
| 7878 | |||
| 7879 | If you're working on a recipe that pulls from an external Source Code | ||
| 7880 | Manager (SCM), it is possible to have the OpenEmbedded build system | ||
| 7881 | notice new recipe changes added to the SCM and then build the resulting | ||
| 7882 | packages that depend on the new recipes by using the latest versions. | ||
| 7883 | This only works for SCMs from which it is possible to get a sensible | ||
| 7884 | revision number for changes. Currently, you can do this with Apache | ||
| 7885 | Subversion (SVN), Git, and Bazaar (BZR) repositories. | ||
| 7886 | |||
| 7887 | To enable this behavior, the :term:`PV` of | ||
| 7888 | the recipe needs to reference | ||
| 7889 | :term:`SRCPV`. Here is an example: | ||
| 7890 | :: | ||
| 7891 | |||
| 7892 | PV = "1.2.3+git${SRCPV}" | ||
| 7893 | |||
| 7894 | Then, you can add the following to your | ||
| 7895 | ``local.conf``: | ||
| 7896 | :: | ||
| 7897 | |||
| 7898 | SRCREV_pn-PN = "${AUTOREV}" | ||
| 7899 | |||
| 7900 | :term:`PN` is the name of the recipe for | ||
| 7901 | which you want to enable automatic source revision updating. | ||
| 7902 | |||
| 7903 | If you do not want to update your local configuration file, you can add | ||
| 7904 | the following directly to the recipe to finish enabling the feature: | ||
| 7905 | :: | ||
| 7906 | |||
| 7907 | SRCREV = "${AUTOREV}" | ||
| 7908 | |||
| 7909 | The Yocto Project provides a distribution named ``poky-bleeding``, whose | ||
| 7910 | configuration file contains the line: | ||
| 7911 | :: | ||
| 7912 | |||
| 7913 | require conf/distro/include/poky-floating-revisions.inc | ||
| 7914 | |||
| 7915 | This line pulls in the | ||
| 7916 | listed include file that contains numerous lines of exactly that form: | ||
| 7917 | :: | ||
| 7918 | |||
| 7919 | #SRCREV_pn-opkg-native ?= "${AUTOREV}" | ||
| 7920 | #SRCREV_pn-opkg-sdk ?= "${AUTOREV}" | ||
| 7921 | #SRCREV_pn-opkg ?= "${AUTOREV}" | ||
| 7922 | #SRCREV_pn-opkg-utils-native ?= "${AUTOREV}" | ||
| 7923 | #SRCREV_pn-opkg-utils ?= "${AUTOREV}" | ||
| 7924 | SRCREV_pn-gconf-dbus ?= "${AUTOREV}" | ||
| 7925 | SRCREV_pn-matchbox-common ?= "${AUTOREV}" | ||
| 7926 | SRCREV_pn-matchbox-config-gtk ?= "${AUTOREV}" | ||
| 7927 | SRCREV_pn-matchbox-desktop ?= "${AUTOREV}" | ||
| 7928 | SRCREV_pn-matchbox-keyboard ?= "${AUTOREV}" | ||
| 7929 | SRCREV_pn-matchbox-panel-2 ?= "${AUTOREV}" | ||
| 7930 | SRCREV_pn-matchbox-themes-extra ?= "${AUTOREV}" | ||
| 7931 | SRCREV_pn-matchbox-terminal ?= "${AUTOREV}" | ||
| 7932 | SRCREV_pn-matchbox-wm ?= "${AUTOREV}" | ||
| 7933 | SRCREV_pn-settings-daemon ?= "${AUTOREV}" | ||
| 7934 | SRCREV_pn-screenshot ?= "${AUTOREV}" | ||
| 7935 | . . . | ||
| 7936 | |||
| 7937 | These lines allow you to | ||
| 7938 | experiment with building a distribution that tracks the latest | ||
| 7939 | development source for numerous packages. | ||
| 7940 | |||
| 7941 | .. note:: | ||
| 7942 | |||
| 7943 | The ``poky-bleeding`` distribution is not tested on a regular basis. Keep | ||
| 7944 | this in mind if you use it. | ||
| 7945 | |||
| 7946 | Creating a Read-Only Root Filesystem | ||
| 7947 | ==================================== | ||
| 7948 | |||
| 7949 | Suppose, for security reasons, you need to disable your target device's | ||
| 7950 | root filesystem's write permissions (i.e. you need a read-only root | ||
| 7951 | filesystem). Or, perhaps you are running the device's operating system | ||
| 7952 | from a read-only storage device. For either case, you can customize your | ||
| 7953 | image for that behavior. | ||
| 7954 | |||
| 7955 | .. note:: | ||
| 7956 | |||
| 7957 | Supporting a read-only root filesystem requires that the system and | ||
| 7958 | applications do not try to write to the root filesystem. You must | ||
| 7959 | configure all parts of the target system to write elsewhere, or to | ||
| 7960 | gracefully fail in the event of attempting to write to the root | ||
| 7961 | filesystem. | ||
| 7962 | |||
| 7963 | Creating the Root Filesystem | ||
| 7964 | ---------------------------- | ||
| 7965 | |||
| 7966 | To create the read-only root filesystem, simply add the | ||
| 7967 | "read-only-rootfs" feature to your image, normally in one of two ways. | ||
| 7968 | The first way is to add the "read-only-rootfs" image feature in the | ||
| 7969 | image's recipe file via the ``IMAGE_FEATURES`` variable: | ||
| 7970 | :: | ||
| 7971 | |||
| 7972 | IMAGE_FEATURES += "read-only-rootfs" | ||
| 7973 | |||
| 7974 | As an alternative, you can add the same feature | ||
| 7975 | from within your build directory's ``local.conf`` file with the | ||
| 7976 | associated ``EXTRA_IMAGE_FEATURES`` variable, as in: | ||
| 7977 | :: | ||
| 7978 | |||
| 7979 | EXTRA_IMAGE_FEATURES = "read-only-rootfs" | ||
| 7980 | |||
| 7981 | For more information on how to use these variables, see the | ||
| 7982 | ":ref:`dev-manual/common-tasks:Customizing Images Using Custom \`\`IMAGE_FEATURES\`\` and \`\`EXTRA_IMAGE_FEATURES\`\``" | ||
| 7983 | section. For information on the variables, see | ||
| 7984 | :term:`IMAGE_FEATURES` and | ||
| 7985 | :term:`EXTRA_IMAGE_FEATURES`. | ||
| 7986 | |||
| 7987 | Post-Installation Scripts and Read-Only Root Filesystem | ||
| 7988 | ------------------------------------------------------- | ||
| 7989 | |||
| 7990 | It is very important that you make sure all post-Installation | ||
| 7991 | (``pkg_postinst``) scripts for packages that are installed into the | ||
| 7992 | image can be run at the time when the root filesystem is created during | ||
| 7993 | the build on the host system. These scripts cannot attempt to run during | ||
| 7994 | first-boot on the target device. With the "read-only-rootfs" feature | ||
| 7995 | enabled, the build system checks during root filesystem creation to make | ||
| 7996 | sure all post-installation scripts succeed. If any of these scripts | ||
| 7997 | still need to be run after the root filesystem is created, the build | ||
| 7998 | immediately fails. These build-time checks ensure that the build fails | ||
| 7999 | rather than the target device fails later during its initial boot | ||
| 8000 | operation. | ||
| 8001 | |||
| 8002 | Most of the common post-installation scripts generated by the build | ||
| 8003 | system for the out-of-the-box Yocto Project are engineered so that they | ||
| 8004 | can run during root filesystem creation (e.g. post-installation scripts | ||
| 8005 | for caching fonts). However, if you create and add custom scripts, you | ||
| 8006 | need to be sure they can be run during this file system creation. | ||
| 8007 | |||
| 8008 | Here are some common problems that prevent post-installation scripts | ||
| 8009 | from running during root filesystem creation: | ||
| 8010 | |||
| 8011 | - *Not using $D in front of absolute paths:* The build system defines | ||
| 8012 | ``$``\ :term:`D` when the root | ||
| 8013 | filesystem is created. Furthermore, ``$D`` is blank when the script | ||
| 8014 | is run on the target device. This implies two purposes for ``$D``: | ||
| 8015 | ensuring paths are valid in both the host and target environments, | ||
| 8016 | and checking to determine which environment is being used as a method | ||
| 8017 | for taking appropriate actions. | ||
| 8018 | |||
| 8019 | - *Attempting to run processes that are specific to or dependent on the | ||
| 8020 | target architecture:* You can work around these attempts by using | ||
| 8021 | native tools, which run on the host system, to accomplish the same | ||
| 8022 | tasks, or by alternatively running the processes under QEMU, which | ||
| 8023 | has the ``qemu_run_binary`` function. For more information, see the | ||
| 8024 | :ref:`qemu <ref-classes-qemu>` class. | ||
| 8025 | |||
| 8026 | Areas With Write Access | ||
| 8027 | ----------------------- | ||
| 8028 | |||
| 8029 | With the "read-only-rootfs" feature enabled, any attempt by the target | ||
| 8030 | to write to the root filesystem at runtime fails. Consequently, you must | ||
| 8031 | make sure that you configure processes and applications that attempt | ||
| 8032 | these types of writes do so to directories with write access (e.g. | ||
| 8033 | ``/tmp`` or ``/var/run``). | ||
| 8034 | |||
| 8035 | Maintaining Build Output Quality | ||
| 8036 | ================================ | ||
| 8037 | |||
| 8038 | Many factors can influence the quality of a build. For example, if you | ||
| 8039 | upgrade a recipe to use a new version of an upstream software package or | ||
| 8040 | you experiment with some new configuration options, subtle changes can | ||
| 8041 | occur that you might not detect until later. Consider the case where | ||
| 8042 | your recipe is using a newer version of an upstream package. In this | ||
| 8043 | case, a new version of a piece of software might introduce an optional | ||
| 8044 | dependency on another library, which is auto-detected. If that library | ||
| 8045 | has already been built when the software is building, the software will | ||
| 8046 | link to the built library and that library will be pulled into your | ||
| 8047 | image along with the new software even if you did not want the library. | ||
| 8048 | |||
| 8049 | The :ref:`buildhistory <ref-classes-buildhistory>` | ||
| 8050 | class exists to help you maintain the quality of your build output. You | ||
| 8051 | can use the class to highlight unexpected and possibly unwanted changes | ||
| 8052 | in the build output. When you enable build history, it records | ||
| 8053 | information about the contents of each package and image and then | ||
| 8054 | commits that information to a local Git repository where you can examine | ||
| 8055 | the information. | ||
| 8056 | |||
| 8057 | The remainder of this section describes the following: | ||
| 8058 | |||
| 8059 | - :ref:`How you can enable and disable build history <dev-manual/common-tasks:enabling and disabling build history>` | ||
| 8060 | |||
| 8061 | - :ref:`How to understand what the build history contains <dev-manual/common-tasks:understanding what the build history contains>` | ||
| 8062 | |||
| 8063 | - :ref:`How to limit the information used for build history <dev-manual/common-tasks:using build history to gather image information only>` | ||
| 8064 | |||
| 8065 | - :ref:`How to examine the build history from both a command-line and web interface <dev-manual/common-tasks:examining build history information>` | ||
| 8066 | |||
| 8067 | Enabling and Disabling Build History | ||
| 8068 | ------------------------------------ | ||
| 8069 | |||
| 8070 | Build history is disabled by default. To enable it, add the following | ||
| 8071 | ``INHERIT`` statement and set the | ||
| 8072 | :term:`BUILDHISTORY_COMMIT` | ||
| 8073 | variable to "1" at the end of your ``conf/local.conf`` file found in the | ||
| 8074 | :term:`Build Directory`: | ||
| 8075 | :: | ||
| 8076 | |||
| 8077 | INHERIT += "buildhistory" | ||
| 8078 | BUILDHISTORY_COMMIT = "1" | ||
| 8079 | |||
| 8080 | Enabling build history as | ||
| 8081 | previously described causes the OpenEmbedded build system to collect | ||
| 8082 | build output information and commit it as a single commit to a local | ||
| 8083 | :ref:`overview-manual/overview-manual-development-environment:git` repository. | ||
| 8084 | |||
| 8085 | .. note:: | ||
| 8086 | |||
| 8087 | Enabling build history increases your build times slightly, | ||
| 8088 | particularly for images, and increases the amount of disk space used | ||
| 8089 | during the build. | ||
| 8090 | |||
| 8091 | You can disable build history by removing the previous statements from | ||
| 8092 | your ``conf/local.conf`` file. | ||
| 8093 | |||
| 8094 | Understanding What the Build History Contains | ||
| 8095 | --------------------------------------------- | ||
| 8096 | |||
| 8097 | Build history information is kept in | ||
| 8098 | ``${``\ :term:`TOPDIR`\ ``}/buildhistory`` | ||
| 8099 | in the Build Directory as defined by the | ||
| 8100 | :term:`BUILDHISTORY_DIR` | ||
| 8101 | variable. The following is an example abbreviated listing: | ||
| 8102 | |||
| 8103 | .. image:: figures/buildhistory.png | ||
| 8104 | :align: center | ||
| 8105 | |||
| 8106 | At the top level, a ``metadata-revs`` file exists that lists the | ||
| 8107 | revisions of the repositories for the enabled layers when the build was | ||
| 8108 | produced. The rest of the data splits into separate ``packages``, | ||
| 8109 | ``images`` and ``sdk`` directories, the contents of which are described | ||
| 8110 | as follows. | ||
| 8111 | |||
| 8112 | Build History Package Information | ||
| 8113 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 8114 | |||
| 8115 | The history for each package contains a text file that has name-value | ||
| 8116 | pairs with information about the package. For example, | ||
| 8117 | ``buildhistory/packages/i586-poky-linux/busybox/busybox/latest`` | ||
| 8118 | contains the following: | ||
| 8119 | |||
| 8120 | .. code-block:: none | ||
| 8121 | |||
| 8122 | PV = 1.22.1 | ||
| 8123 | PR = r32 | ||
| 8124 | RPROVIDES = | ||
| 8125 | RDEPENDS = glibc (>= 2.20) update-alternatives-opkg | ||
| 8126 | RRECOMMENDS = busybox-syslog busybox-udhcpc update-rc.d | ||
| 8127 | PKGSIZE = 540168 | ||
| 8128 | FILES = /usr/bin/* /usr/sbin/* /usr/lib/busybox/* /usr/lib/lib*.so.* \ | ||
| 8129 | /etc /com /var /bin/* /sbin/* /lib/*.so.* /lib/udev/rules.d \ | ||
| 8130 | /usr/lib/udev/rules.d /usr/share/busybox /usr/lib/busybox/* \ | ||
| 8131 | /usr/share/pixmaps /usr/share/applications /usr/share/idl \ | ||
| 8132 | /usr/share/omf /usr/share/sounds /usr/lib/bonobo/servers | ||
| 8133 | FILELIST = /bin/busybox /bin/busybox.nosuid /bin/busybox.suid /bin/sh \ | ||
| 8134 | /etc/busybox.links.nosuid /etc/busybox.links.suid | ||
| 8135 | |||
| 8136 | Most of these | ||
| 8137 | name-value pairs correspond to variables used to produce the package. | ||
| 8138 | The exceptions are ``FILELIST``, which is the actual list of files in | ||
| 8139 | the package, and ``PKGSIZE``, which is the total size of files in the | ||
| 8140 | package in bytes. | ||
| 8141 | |||
| 8142 | A file also exists that corresponds to the recipe from which the package | ||
| 8143 | came (e.g. ``buildhistory/packages/i586-poky-linux/busybox/latest``): | ||
| 8144 | |||
| 8145 | .. code-block:: none | ||
| 8146 | |||
| 8147 | PV = 1.22.1 | ||
| 8148 | PR = r32 | ||
| 8149 | DEPENDS = initscripts kern-tools-native update-rc.d-native \ | ||
| 8150 | virtual/i586-poky-linux-compilerlibs virtual/i586-poky-linux-gcc \ | ||
| 8151 | virtual/libc virtual/update-alternatives | ||
| 8152 | PACKAGES = busybox-ptest busybox-httpd busybox-udhcpd busybox-udhcpc \ | ||
| 8153 | busybox-syslog busybox-mdev busybox-hwclock busybox-dbg \ | ||
| 8154 | busybox-staticdev busybox-dev busybox-doc busybox-locale busybox | ||
| 8155 | |||
| 8156 | Finally, for those recipes fetched from a version control system (e.g., | ||
| 8157 | Git), a file exists that lists source revisions that are specified in | ||
| 8158 | the recipe and lists the actual revisions used during the build. Listed | ||
| 8159 | and actual revisions might differ when | ||
| 8160 | :term:`SRCREV` is set to | ||
| 8161 | ${:term:`AUTOREV`}. Here is an | ||
| 8162 | example assuming | ||
| 8163 | ``buildhistory/packages/qemux86-poky-linux/linux-yocto/latest_srcrev``): | ||
| 8164 | :: | ||
| 8165 | |||
| 8166 | # SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1" | ||
| 8167 | SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1" | ||
| 8168 | # SRCREV_meta = "a227f20eff056e511d504b2e490f3774ab260d6f" | ||
| 8169 | SRCREV_meta ="a227f20eff056e511d504b2e490f3774ab260d6f" | ||
| 8170 | |||
| 8171 | You can use the | ||
| 8172 | ``buildhistory-collect-srcrevs`` command with the ``-a`` option to | ||
| 8173 | collect the stored ``SRCREV`` values from build history and report them | ||
| 8174 | in a format suitable for use in global configuration (e.g., | ||
| 8175 | ``local.conf`` or a distro include file) to override floating | ||
| 8176 | ``AUTOREV`` values to a fixed set of revisions. Here is some example | ||
| 8177 | output from this command: | ||
| 8178 | :: | ||
| 8179 | |||
| 8180 | $ buildhistory-collect-srcrevs -a | ||
| 8181 | # i586-poky-linux | ||
| 8182 | SRCREV_pn-glibc = "b8079dd0d360648e4e8de48656c5c38972621072" | ||
| 8183 | SRCREV_pn-glibc-initial = "b8079dd0d360648e4e8de48656c5c38972621072" | ||
| 8184 | SRCREV_pn-opkg-utils = "53274f087565fd45d8452c5367997ba6a682a37a" | ||
| 8185 | SRCREV_pn-kmod = "fd56638aed3fe147015bfa10ed4a5f7491303cb4" | ||
| 8186 | # x86_64-linux | ||
| 8187 | SRCREV_pn-gtk-doc-stub-native = "1dea266593edb766d6d898c79451ef193eb17cfa" | ||
| 8188 | SRCREV_pn-dtc-native = "65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf" | ||
| 8189 | SRCREV_pn-update-rc.d-native = "eca680ddf28d024954895f59a241a622dd575c11" | ||
| 8190 | SRCREV_glibc_pn-cross-localedef-native = "b8079dd0d360648e4e8de48656c5c38972621072" | ||
| 8191 | SRCREV_localedef_pn-cross-localedef-native = "c833367348d39dad7ba018990bfdaffaec8e9ed3" | ||
| 8192 | SRCREV_pn-prelink-native = "faa069deec99bf61418d0bab831c83d7c1b797ca" | ||
| 8193 | SRCREV_pn-opkg-utils-native = "53274f087565fd45d8452c5367997ba6a682a37a" | ||
| 8194 | SRCREV_pn-kern-tools-native = "23345b8846fe4bd167efdf1bd8a1224b2ba9a5ff" | ||
| 8195 | SRCREV_pn-kmod-native = "fd56638aed3fe147015bfa10ed4a5f7491303cb4" | ||
| 8196 | # qemux86-poky-linux | ||
| 8197 | SRCREV_machine_pn-linux-yocto = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1" | ||
| 8198 | SRCREV_meta_pn-linux-yocto = "a227f20eff056e511d504b2e490f3774ab260d6f" | ||
| 8199 | # all-poky-linux | ||
| 8200 | SRCREV_pn-update-rc.d = "eca680ddf28d024954895f59a241a622dd575c11" | ||
| 8201 | |||
| 8202 | .. note:: | ||
| 8203 | |||
| 8204 | Here are some notes on using the ``buildhistory-collect-srcrevs`` command: | ||
| 8205 | |||
| 8206 | - By default, only values where the ``SRCREV`` was not hardcoded | ||
| 8207 | (usually when ``AUTOREV`` is used) are reported. Use the ``-a`` | ||
| 8208 | option to see all ``SRCREV`` values. | ||
| 8209 | |||
| 8210 | - The output statements might not have any effect if overrides are | ||
| 8211 | applied elsewhere in the build system configuration. Use the | ||
| 8212 | ``-f`` option to add the ``forcevariable`` override to each output | ||
| 8213 | line if you need to work around this restriction. | ||
| 8214 | |||
| 8215 | - The script does apply special handling when building for multiple | ||
| 8216 | machines. However, the script does place a comment before each set | ||
| 8217 | of values that specifies which triplet to which they belong as | ||
| 8218 | previously shown (e.g., ``i586-poky-linux``). | ||
| 8219 | |||
| 8220 | Build History Image Information | ||
| 8221 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 8222 | |||
| 8223 | The files produced for each image are as follows: | ||
| 8224 | |||
| 8225 | - ``image-files:`` A directory containing selected files from the root | ||
| 8226 | filesystem. The files are defined by | ||
| 8227 | :term:`BUILDHISTORY_IMAGE_FILES`. | ||
| 8228 | |||
| 8229 | - ``build-id.txt:`` Human-readable information about the build | ||
| 8230 | configuration and metadata source revisions. This file contains the | ||
| 8231 | full build header as printed by BitBake. | ||
| 8232 | |||
| 8233 | - ``*.dot:`` Dependency graphs for the image that are compatible with | ||
| 8234 | ``graphviz``. | ||
| 8235 | |||
| 8236 | - ``files-in-image.txt:`` A list of files in the image with | ||
| 8237 | permissions, owner, group, size, and symlink information. | ||
| 8238 | |||
| 8239 | - ``image-info.txt:`` A text file containing name-value pairs with | ||
| 8240 | information about the image. See the following listing example for | ||
| 8241 | more information. | ||
| 8242 | |||
| 8243 | - ``installed-package-names.txt:`` A list of installed packages by name | ||
| 8244 | only. | ||
| 8245 | |||
| 8246 | - ``installed-package-sizes.txt:`` A list of installed packages ordered | ||
| 8247 | by size. | ||
| 8248 | |||
| 8249 | - ``installed-packages.txt:`` A list of installed packages with full | ||
| 8250 | package filenames. | ||
| 8251 | |||
| 8252 | .. note:: | ||
| 8253 | |||
| 8254 | Installed package information is able to be gathered and produced | ||
| 8255 | even if package management is disabled for the final image. | ||
| 8256 | |||
| 8257 | Here is an example of ``image-info.txt``: | ||
| 8258 | |||
| 8259 | .. code-block:: none | ||
| 8260 | |||
| 8261 | DISTRO = poky | ||
| 8262 | DISTRO_VERSION = 1.7 | ||
| 8263 | USER_CLASSES = buildstats image-mklibs image-prelink | ||
| 8264 | IMAGE_CLASSES = image_types | ||
| 8265 | IMAGE_FEATURES = debug-tweaks | ||
| 8266 | IMAGE_LINGUAS = | ||
| 8267 | IMAGE_INSTALL = packagegroup-core-boot run-postinsts | ||
| 8268 | BAD_RECOMMENDATIONS = | ||
| 8269 | NO_RECOMMENDATIONS = | ||
| 8270 | PACKAGE_EXCLUDE = | ||
| 8271 | ROOTFS_POSTPROCESS_COMMAND = write_package_manifest; license_create_manifest; \ | ||
| 8272 | write_image_manifest ; buildhistory_list_installed_image ; \ | ||
| 8273 | buildhistory_get_image_installed ; ssh_allow_empty_password; \ | ||
| 8274 | postinst_enable_logging; rootfs_update_timestamp ; ssh_disable_dns_lookup ; | ||
| 8275 | IMAGE_POSTPROCESS_COMMAND = buildhistory_get_imageinfo ; | ||
| 8276 | IMAGESIZE = 6900 | ||
| 8277 | |||
| 8278 | Other than ``IMAGESIZE``, | ||
| 8279 | which is the total size of the files in the image in Kbytes, the | ||
| 8280 | name-value pairs are variables that may have influenced the content of | ||
| 8281 | the image. This information is often useful when you are trying to | ||
| 8282 | determine why a change in the package or file listings has occurred. | ||
| 8283 | |||
| 8284 | Using Build History to Gather Image Information Only | ||
| 8285 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 8286 | |||
| 8287 | As you can see, build history produces image information, including | ||
| 8288 | dependency graphs, so you can see why something was pulled into the | ||
| 8289 | image. If you are just interested in this information and not interested | ||
| 8290 | in collecting specific package or SDK information, you can enable | ||
| 8291 | writing only image information without any history by adding the | ||
| 8292 | following to your ``conf/local.conf`` file found in the | ||
| 8293 | :term:`Build Directory`: | ||
| 8294 | :: | ||
| 8295 | |||
| 8296 | INHERIT += "buildhistory" | ||
| 8297 | BUILDHISTORY_COMMIT = "0" | ||
| 8298 | BUILDHISTORY_FEATURES = "image" | ||
| 8299 | |||
| 8300 | Here, you set the | ||
| 8301 | :term:`BUILDHISTORY_FEATURES` | ||
| 8302 | variable to use the image feature only. | ||
| 8303 | |||
| 8304 | Build History SDK Information | ||
| 8305 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 8306 | |||
| 8307 | Build history collects similar information on the contents of SDKs (e.g. | ||
| 8308 | ``bitbake -c populate_sdk imagename``) as compared to information it | ||
| 8309 | collects for images. Furthermore, this information differs depending on | ||
| 8310 | whether an extensible or standard SDK is being produced. | ||
| 8311 | |||
| 8312 | The following list shows the files produced for SDKs: | ||
| 8313 | |||
| 8314 | - ``files-in-sdk.txt:`` A list of files in the SDK with permissions, | ||
| 8315 | owner, group, size, and symlink information. This list includes both | ||
| 8316 | the host and target parts of the SDK. | ||
| 8317 | |||
| 8318 | - ``sdk-info.txt:`` A text file containing name-value pairs with | ||
| 8319 | information about the SDK. See the following listing example for more | ||
| 8320 | information. | ||
| 8321 | |||
| 8322 | - ``sstate-task-sizes.txt:`` A text file containing name-value pairs | ||
| 8323 | with information about task group sizes (e.g. ``do_populate_sysroot`` | ||
| 8324 | tasks have a total size). The ``sstate-task-sizes.txt`` file exists | ||
| 8325 | only when an extensible SDK is created. | ||
| 8326 | |||
| 8327 | - ``sstate-package-sizes.txt:`` A text file containing name-value pairs | ||
| 8328 | with information for the shared-state packages and sizes in the SDK. | ||
| 8329 | The ``sstate-package-sizes.txt`` file exists only when an extensible | ||
| 8330 | SDK is created. | ||
| 8331 | |||
| 8332 | - ``sdk-files:`` A folder that contains copies of the files mentioned | ||
| 8333 | in ``BUILDHISTORY_SDK_FILES`` if the files are present in the output. | ||
| 8334 | Additionally, the default value of ``BUILDHISTORY_SDK_FILES`` is | ||
| 8335 | specific to the extensible SDK although you can set it differently if | ||
| 8336 | you would like to pull in specific files from the standard SDK. | ||
| 8337 | |||
| 8338 | The default files are ``conf/local.conf``, ``conf/bblayers.conf``, | ||
| 8339 | ``conf/auto.conf``, ``conf/locked-sigs.inc``, and | ||
| 8340 | ``conf/devtool.conf``. Thus, for an extensible SDK, these files get | ||
| 8341 | copied into the ``sdk-files`` directory. | ||
| 8342 | |||
| 8343 | - The following information appears under each of the ``host`` and | ||
| 8344 | ``target`` directories for the portions of the SDK that run on the | ||
| 8345 | host and on the target, respectively: | ||
| 8346 | |||
| 8347 | .. note:: | ||
| 8348 | |||
| 8349 | The following files for the most part are empty when producing an | ||
| 8350 | extensible SDK because this type of SDK is not constructed from | ||
| 8351 | packages as is the standard SDK. | ||
| 8352 | |||
| 8353 | - ``depends.dot:`` Dependency graph for the SDK that is compatible | ||
| 8354 | with ``graphviz``. | ||
| 8355 | |||
| 8356 | - ``installed-package-names.txt:`` A list of installed packages by | ||
| 8357 | name only. | ||
| 8358 | |||
| 8359 | - ``installed-package-sizes.txt:`` A list of installed packages | ||
| 8360 | ordered by size. | ||
| 8361 | |||
| 8362 | - ``installed-packages.txt:`` A list of installed packages with full | ||
| 8363 | package filenames. | ||
| 8364 | |||
| 8365 | Here is an example of ``sdk-info.txt``: | ||
| 8366 | |||
| 8367 | .. code-block:: none | ||
| 8368 | |||
| 8369 | DISTRO = poky | ||
| 8370 | DISTRO_VERSION = 1.3+snapshot-20130327 | ||
| 8371 | SDK_NAME = poky-glibc-i686-arm | ||
| 8372 | SDK_VERSION = 1.3+snapshot | ||
| 8373 | SDKMACHINE = | ||
| 8374 | SDKIMAGE_FEATURES = dev-pkgs dbg-pkgs | ||
| 8375 | BAD_RECOMMENDATIONS = | ||
| 8376 | SDKSIZE = 352712 | ||
| 8377 | |||
| 8378 | Other than ``SDKSIZE``, which is | ||
| 8379 | the total size of the files in the SDK in Kbytes, the name-value pairs | ||
| 8380 | are variables that might have influenced the content of the SDK. This | ||
| 8381 | information is often useful when you are trying to determine why a | ||
| 8382 | change in the package or file listings has occurred. | ||
| 8383 | |||
| 8384 | Examining Build History Information | ||
| 8385 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 8386 | |||
| 8387 | You can examine build history output from the command line or from a web | ||
| 8388 | interface. | ||
| 8389 | |||
| 8390 | To see any changes that have occurred (assuming you have | ||
| 8391 | :term:`BUILDHISTORY_COMMIT` = "1"), | ||
| 8392 | you can simply use any Git command that allows you to view the history | ||
| 8393 | of a repository. Here is one method: | ||
| 8394 | :: | ||
| 8395 | |||
| 8396 | $ git log -p | ||
| 8397 | |||
| 8398 | You need to realize, | ||
| 8399 | however, that this method does show changes that are not significant | ||
| 8400 | (e.g. a package's size changing by a few bytes). | ||
| 8401 | |||
| 8402 | A command-line tool called ``buildhistory-diff`` does exist, though, | ||
| 8403 | that queries the Git repository and prints just the differences that | ||
| 8404 | might be significant in human-readable form. Here is an example: | ||
| 8405 | :: | ||
| 8406 | |||
| 8407 | $ ~/poky/poky/scripts/buildhistory-diff . HEAD^ | ||
| 8408 | Changes to images/qemux86_64/glibc/core-image-minimal (files-in-image.txt): | ||
| 8409 | /etc/anotherpkg.conf was added | ||
| 8410 | /sbin/anotherpkg was added | ||
| 8411 | * (installed-package-names.txt): | ||
| 8412 | * anotherpkg was added | ||
| 8413 | Changes to images/qemux86_64/glibc/core-image-minimal (installed-package-names.txt): | ||
| 8414 | anotherpkg was added | ||
| 8415 | packages/qemux86_64-poky-linux/v86d: PACKAGES: added "v86d-extras" | ||
| 8416 | * PR changed from "r0" to "r1" | ||
| 8417 | * PV changed from "0.1.10" to "0.1.12" | ||
| 8418 | packages/qemux86_64-poky-linux/v86d/v86d: PKGSIZE changed from 110579 to 144381 (+30%) | ||
| 8419 | * PR changed from "r0" to "r1" | ||
| 8420 | * PV changed from "0.1.10" to "0.1.12" | ||
| 8421 | |||
| 8422 | .. note:: | ||
| 8423 | |||
| 8424 | The ``buildhistory-diff`` tool requires the ``GitPython`` | ||
| 8425 | package. Be sure to install it using Pip3 as follows: | ||
| 8426 | :: | ||
| 8427 | |||
| 8428 | $ pip3 install GitPython --user | ||
| 8429 | |||
| 8430 | |||
| 8431 | Alternatively, you can install ``python3-git`` using the appropriate | ||
| 8432 | distribution package manager (e.g. ``apt-get``, ``dnf``, or ``zipper``). | ||
| 8433 | |||
| 8434 | To see changes to the build history using a web interface, follow the | ||
| 8435 | instruction in the ``README`` file | ||
| 8436 | :yocto_git:`here </buildhistory-web/>`. | ||
| 8437 | |||
| 8438 | Here is a sample screenshot of the interface: | ||
| 8439 | |||
| 8440 | .. image:: figures/buildhistory-web.png | ||
| 8441 | :align: center | ||
| 8442 | |||
| 8443 | Performing Automated Runtime Testing | ||
| 8444 | ==================================== | ||
| 8445 | |||
| 8446 | The OpenEmbedded build system makes available a series of automated | ||
| 8447 | tests for images to verify runtime functionality. You can run these | ||
| 8448 | tests on either QEMU or actual target hardware. Tests are written in | ||
| 8449 | Python making use of the ``unittest`` module, and the majority of them | ||
| 8450 | run commands on the target system over SSH. This section describes how | ||
| 8451 | you set up the environment to use these tests, run available tests, and | ||
| 8452 | write and add your own tests. | ||
| 8453 | |||
| 8454 | For information on the test and QA infrastructure available within the | ||
| 8455 | Yocto Project, see the ":ref:`ref-manual/ref-release-process:testing and quality assurance`" | ||
| 8456 | section in the Yocto Project Reference Manual. | ||
| 8457 | |||
| 8458 | Enabling Tests | ||
| 8459 | -------------- | ||
| 8460 | |||
| 8461 | Depending on whether you are planning to run tests using QEMU or on the | ||
| 8462 | hardware, you have to take different steps to enable the tests. See the | ||
| 8463 | following subsections for information on how to enable both types of | ||
| 8464 | tests. | ||
| 8465 | |||
| 8466 | Enabling Runtime Tests on QEMU | ||
| 8467 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 8468 | |||
| 8469 | In order to run tests, you need to do the following: | ||
| 8470 | |||
| 8471 | - *Set up to avoid interaction with sudo for networking:* To | ||
| 8472 | accomplish this, you must do one of the following: | ||
| 8473 | |||
| 8474 | - Add ``NOPASSWD`` for your user in ``/etc/sudoers`` either for all | ||
| 8475 | commands or just for ``runqemu-ifup``. You must provide the full | ||
| 8476 | path as that can change if you are using multiple clones of the | ||
| 8477 | source repository. | ||
| 8478 | |||
| 8479 | .. note:: | ||
| 8480 | |||
| 8481 | On some distributions, you also need to comment out "Defaults | ||
| 8482 | requiretty" in ``/etc/sudoers``. | ||
| 8483 | |||
| 8484 | - Manually configure a tap interface for your system. | ||
| 8485 | |||
| 8486 | - Run as root the script in ``scripts/runqemu-gen-tapdevs``, which | ||
| 8487 | should generate a list of tap devices. This is the option | ||
| 8488 | typically chosen for Autobuilder-type environments. | ||
| 8489 | |||
| 8490 | .. note:: | ||
| 8491 | |||
| 8492 | - Be sure to use an absolute path when calling this script | ||
| 8493 | with sudo. | ||
| 8494 | |||
| 8495 | - The package recipe ``qemu-helper-native`` is required to run | ||
| 8496 | this script. Build the package using the following command: | ||
| 8497 | :: | ||
| 8498 | |||
| 8499 | $ bitbake qemu-helper-native | ||
| 8500 | |||
| 8501 | - *Set the DISPLAY variable:* You need to set this variable so that | ||
| 8502 | you have an X server available (e.g. start ``vncserver`` for a | ||
| 8503 | headless machine). | ||
| 8504 | |||
| 8505 | - *Be sure your host's firewall accepts incoming connections from | ||
| 8506 | 192.168.7.0/24:* Some of the tests (in particular DNF tests) start an | ||
| 8507 | HTTP server on a random high number port, which is used to serve | ||
| 8508 | files to the target. The DNF module serves | ||
| 8509 | ``${WORKDIR}/oe-rootfs-repo`` so it can run DNF channel commands. | ||
| 8510 | That means your host's firewall must accept incoming connections from | ||
| 8511 | 192.168.7.0/24, which is the default IP range used for tap devices by | ||
| 8512 | ``runqemu``. | ||
| 8513 | |||
| 8514 | - *Be sure your host has the correct packages installed:* Depending | ||
| 8515 | your host's distribution, you need to have the following packages | ||
| 8516 | installed: | ||
| 8517 | |||
| 8518 | - Ubuntu and Debian: ``sysstat`` and ``iproute2`` | ||
| 8519 | |||
| 8520 | - OpenSUSE: ``sysstat`` and ``iproute2`` | ||
| 8521 | |||
| 8522 | - Fedora: ``sysstat`` and ``iproute`` | ||
| 8523 | |||
| 8524 | - CentOS: ``sysstat`` and ``iproute`` | ||
| 8525 | |||
| 8526 | Once you start running the tests, the following happens: | ||
| 8527 | |||
| 8528 | 1. A copy of the root filesystem is written to ``${WORKDIR}/testimage``. | ||
| 8529 | |||
| 8530 | 2. The image is booted under QEMU using the standard ``runqemu`` script. | ||
| 8531 | |||
| 8532 | 3. A default timeout of 500 seconds occurs to allow for the boot process | ||
| 8533 | to reach the login prompt. You can change the timeout period by | ||
| 8534 | setting | ||
| 8535 | :term:`TEST_QEMUBOOT_TIMEOUT` | ||
| 8536 | in the ``local.conf`` file. | ||
| 8537 | |||
| 8538 | 4. Once the boot process is reached and the login prompt appears, the | ||
| 8539 | tests run. The full boot log is written to | ||
| 8540 | ``${WORKDIR}/testimage/qemu_boot_log``. | ||
| 8541 | |||
| 8542 | 5. Each test module loads in the order found in ``TEST_SUITES``. You can | ||
| 8543 | find the full output of the commands run over SSH in | ||
| 8544 | ``${WORKDIR}/testimgage/ssh_target_log``. | ||
| 8545 | |||
| 8546 | 6. If no failures occur, the task running the tests ends successfully. | ||
| 8547 | You can find the output from the ``unittest`` in the task log at | ||
| 8548 | ``${WORKDIR}/temp/log.do_testimage``. | ||
| 8549 | |||
| 8550 | Enabling Runtime Tests on Hardware | ||
| 8551 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 8552 | |||
| 8553 | The OpenEmbedded build system can run tests on real hardware, and for | ||
| 8554 | certain devices it can also deploy the image to be tested onto the | ||
| 8555 | device beforehand. | ||
| 8556 | |||
| 8557 | For automated deployment, a "master image" is installed onto the | ||
| 8558 | hardware once as part of setup. Then, each time tests are to be run, the | ||
| 8559 | following occurs: | ||
| 8560 | |||
| 8561 | 1. The master image is booted into and used to write the image to be | ||
| 8562 | tested to a second partition. | ||
| 8563 | |||
| 8564 | 2. The device is then rebooted using an external script that you need to | ||
| 8565 | provide. | ||
| 8566 | |||
| 8567 | 3. The device boots into the image to be tested. | ||
| 8568 | |||
| 8569 | When running tests (independent of whether the image has been deployed | ||
| 8570 | automatically or not), the device is expected to be connected to a | ||
| 8571 | network on a pre-determined IP address. You can either use static IP | ||
| 8572 | addresses written into the image, or set the image to use DHCP and have | ||
| 8573 | your DHCP server on the test network assign a known IP address based on | ||
| 8574 | the MAC address of the device. | ||
| 8575 | |||
| 8576 | In order to run tests on hardware, you need to set ``TEST_TARGET`` to an | ||
| 8577 | appropriate value. For QEMU, you do not have to change anything, the | ||
| 8578 | default value is "qemu". For running tests on hardware, the following | ||
| 8579 | options exist: | ||
| 8580 | |||
| 8581 | - *"simpleremote":* Choose "simpleremote" if you are going to run tests | ||
| 8582 | on a target system that is already running the image to be tested and | ||
| 8583 | is available on the network. You can use "simpleremote" in | ||
| 8584 | conjunction with either real hardware or an image running within a | ||
| 8585 | separately started QEMU or any other virtual machine manager. | ||
| 8586 | |||
| 8587 | - *"SystemdbootTarget":* Choose "SystemdbootTarget" if your hardware is | ||
| 8588 | an EFI-based machine with ``systemd-boot`` as bootloader and | ||
| 8589 | ``core-image-testmaster`` (or something similar) is installed. Also, | ||
| 8590 | your hardware under test must be in a DHCP-enabled network that gives | ||
| 8591 | it the same IP address for each reboot. | ||
| 8592 | |||
| 8593 | If you choose "SystemdbootTarget", there are additional requirements | ||
| 8594 | and considerations. See the "`Selecting | ||
| 8595 | SystemdbootTarget <#selecting-systemdboottarget>`__" section, which | ||
| 8596 | follows, for more information. | ||
| 8597 | |||
| 8598 | - *"BeagleBoneTarget":* Choose "BeagleBoneTarget" if you are deploying | ||
| 8599 | images and running tests on the BeagleBone "Black" or original | ||
| 8600 | "White" hardware. For information on how to use these tests, see the | ||
| 8601 | comments at the top of the BeagleBoneTarget | ||
| 8602 | ``meta-yocto-bsp/lib/oeqa/controllers/beaglebonetarget.py`` file. | ||
| 8603 | |||
| 8604 | - *"EdgeRouterTarget":* Choose "EdgeRouterTarget" if you are deploying | ||
| 8605 | images and running tests on the Ubiquiti Networks EdgeRouter Lite. | ||
| 8606 | For information on how to use these tests, see the comments at the | ||
| 8607 | top of the EdgeRouterTarget | ||
| 8608 | ``meta-yocto-bsp/lib/oeqa/controllers/edgeroutertarget.py`` file. | ||
| 8609 | |||
| 8610 | - *"GrubTarget":* Choose "GrubTarget" if you are deploying images and running | ||
| 8611 | tests on any generic PC that boots using GRUB. For information on how | ||
| 8612 | to use these tests, see the comments at the top of the GrubTarget | ||
| 8613 | ``meta-yocto-bsp/lib/oeqa/controllers/grubtarget.py`` file. | ||
| 8614 | |||
| 8615 | - *"your-target":* Create your own custom target if you want to run | ||
| 8616 | tests when you are deploying images and running tests on a custom | ||
| 8617 | machine within your BSP layer. To do this, you need to add a Python | ||
| 8618 | unit that defines the target class under ``lib/oeqa/controllers/`` | ||
| 8619 | within your layer. You must also provide an empty ``__init__.py``. | ||
| 8620 | For examples, see files in ``meta-yocto-bsp/lib/oeqa/controllers/``. | ||
| 8621 | |||
| 8622 | Selecting SystemdbootTarget | ||
| 8623 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 8624 | |||
| 8625 | If you did not set ``TEST_TARGET`` to "SystemdbootTarget", then you do | ||
| 8626 | not need any information in this section. You can skip down to the | ||
| 8627 | "`Running Tests <#qemu-image-running-tests>`__" section. | ||
| 8628 | |||
| 8629 | If you did set ``TEST_TARGET`` to "SystemdbootTarget", you also need to | ||
| 8630 | perform a one-time setup of your master image by doing the following: | ||
| 8631 | |||
| 8632 | 1. *Set EFI_PROVIDER:* Be sure that ``EFI_PROVIDER`` is as follows: | ||
| 8633 | :: | ||
| 8634 | |||
| 8635 | EFI_PROVIDER = "systemd-boot" | ||
| 8636 | |||
| 8637 | 2. *Build the master image:* Build the ``core-image-testmaster`` image. | ||
| 8638 | The ``core-image-testmaster`` recipe is provided as an example for a | ||
| 8639 | "master" image and you can customize the image recipe as you would | ||
| 8640 | any other recipe. | ||
| 8641 | |||
| 8642 | Here are the image recipe requirements: | ||
| 8643 | |||
| 8644 | - Inherits ``core-image`` so that kernel modules are installed. | ||
| 8645 | |||
| 8646 | - Installs normal linux utilities not busybox ones (e.g. ``bash``, | ||
| 8647 | ``coreutils``, ``tar``, ``gzip``, and ``kmod``). | ||
| 8648 | |||
| 8649 | - Uses a custom Initial RAM Disk (initramfs) image with a custom | ||
| 8650 | installer. A normal image that you can install usually creates a | ||
| 8651 | single rootfs partition. This image uses another installer that | ||
| 8652 | creates a specific partition layout. Not all Board Support | ||
| 8653 | Packages (BSPs) can use an installer. For such cases, you need to | ||
| 8654 | manually create the following partition layout on the target: | ||
| 8655 | |||
| 8656 | - First partition mounted under ``/boot``, labeled "boot". | ||
| 8657 | |||
| 8658 | - The main rootfs partition where this image gets installed, | ||
| 8659 | which is mounted under ``/``. | ||
| 8660 | |||
| 8661 | - Another partition labeled "testrootfs" where test images get | ||
| 8662 | deployed. | ||
| 8663 | |||
| 8664 | 3. *Install image:* Install the image that you just built on the target | ||
| 8665 | system. | ||
| 8666 | |||
| 8667 | The final thing you need to do when setting ``TEST_TARGET`` to | ||
| 8668 | "SystemdbootTarget" is to set up the test image: | ||
| 8669 | |||
| 8670 | 1. *Set up your local.conf file:* Make sure you have the following | ||
| 8671 | statements in your ``local.conf`` file: | ||
| 8672 | :: | ||
| 8673 | |||
| 8674 | IMAGE_FSTYPES += "tar.gz" | ||
| 8675 | INHERIT += "testimage" | ||
| 8676 | TEST_TARGET = "SystemdbootTarget" | ||
| 8677 | TEST_TARGET_IP = "192.168.2.3" | ||
| 8678 | |||
| 8679 | 2. *Build your test image:* Use BitBake to build the image: | ||
| 8680 | :: | ||
| 8681 | |||
| 8682 | $ bitbake core-image-sato | ||
| 8683 | |||
| 8684 | Power Control | ||
| 8685 | ~~~~~~~~~~~~~ | ||
| 8686 | |||
| 8687 | For most hardware targets other than "simpleremote", you can control | ||
| 8688 | power: | ||
| 8689 | |||
| 8690 | - You can use ``TEST_POWERCONTROL_CMD`` together with | ||
| 8691 | ``TEST_POWERCONTROL_EXTRA_ARGS`` as a command that runs on the host | ||
| 8692 | and does power cycling. The test code passes one argument to that | ||
| 8693 | command: off, on or cycle (off then on). Here is an example that | ||
| 8694 | could appear in your ``local.conf`` file: | ||
| 8695 | :: | ||
| 8696 | |||
| 8697 | TEST_POWERCONTROL_CMD = "powercontrol.exp test 10.11.12.1 nuc1" | ||
| 8698 | |||
| 8699 | In this example, the expect | ||
| 8700 | script does the following: | ||
| 8701 | |||
| 8702 | .. code-block:: shell | ||
| 8703 | |||
| 8704 | ssh test@10.11.12.1 "pyctl nuc1 arg" | ||
| 8705 | |||
| 8706 | It then runs a Python script that controls power for a label called | ||
| 8707 | ``nuc1``. | ||
| 8708 | |||
| 8709 | .. note:: | ||
| 8710 | |||
| 8711 | You need to customize ``TEST_POWERCONTROL_CMD`` and | ||
| 8712 | ``TEST_POWERCONTROL_EXTRA_ARGS`` for your own setup. The one requirement | ||
| 8713 | is that it accepts "on", "off", and "cycle" as the last argument. | ||
| 8714 | |||
| 8715 | - When no command is defined, it connects to the device over SSH and | ||
| 8716 | uses the classic reboot command to reboot the device. Classic reboot | ||
| 8717 | is fine as long as the machine actually reboots (i.e. the SSH test | ||
| 8718 | has not failed). It is useful for scenarios where you have a simple | ||
| 8719 | setup, typically with a single board, and where some manual | ||
| 8720 | interaction is okay from time to time. | ||
| 8721 | |||
| 8722 | If you have no hardware to automatically perform power control but still | ||
| 8723 | wish to experiment with automated hardware testing, you can use the | ||
| 8724 | ``dialog-power-control`` script that shows a dialog prompting you to perform | ||
| 8725 | the required power action. This script requires either KDialog or Zenity | ||
| 8726 | to be installed. To use this script, set the | ||
| 8727 | :term:`TEST_POWERCONTROL_CMD` | ||
| 8728 | variable as follows: | ||
| 8729 | :: | ||
| 8730 | |||
| 8731 | TEST_POWERCONTROL_CMD = "${COREBASE}/scripts/contrib/dialog-power-control" | ||
| 8732 | |||
| 8733 | Serial Console Connection | ||
| 8734 | ~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 8735 | |||
| 8736 | For test target classes requiring a serial console to interact with the | ||
| 8737 | bootloader (e.g. BeagleBoneTarget, EdgeRouterTarget, and GrubTarget), | ||
| 8738 | you need to specify a command to use to connect to the serial console of | ||
| 8739 | the target machine by using the | ||
| 8740 | :term:`TEST_SERIALCONTROL_CMD` | ||
| 8741 | variable and optionally the | ||
| 8742 | :term:`TEST_SERIALCONTROL_EXTRA_ARGS` | ||
| 8743 | variable. | ||
| 8744 | |||
| 8745 | These cases could be a serial terminal program if the machine is | ||
| 8746 | connected to a local serial port, or a ``telnet`` or ``ssh`` command | ||
| 8747 | connecting to a remote console server. Regardless of the case, the | ||
| 8748 | command simply needs to connect to the serial console and forward that | ||
| 8749 | connection to standard input and output as any normal terminal program | ||
| 8750 | does. For example, to use the picocom terminal program on serial device | ||
| 8751 | ``/dev/ttyUSB0`` at 115200bps, you would set the variable as follows: | ||
| 8752 | :: | ||
| 8753 | |||
| 8754 | TEST_SERIALCONTROL_CMD = "picocom /dev/ttyUSB0 -b 115200" | ||
| 8755 | |||
| 8756 | For local | ||
| 8757 | devices where the serial port device disappears when the device reboots, | ||
| 8758 | an additional "serdevtry" wrapper script is provided. To use this | ||
| 8759 | wrapper, simply prefix the terminal command with | ||
| 8760 | ``${COREBASE}/scripts/contrib/serdevtry``: | ||
| 8761 | :: | ||
| 8762 | |||
| 8763 | TEST_SERIALCONTROL_CMD = "${COREBASE}/scripts/contrib/serdevtry picocom -b 115200 /dev/ttyUSB0" | ||
| 8764 | |||
| 8765 | Running Tests | ||
| 8766 | ------------- | ||
| 8767 | |||
| 8768 | You can start the tests automatically or manually: | ||
| 8769 | |||
| 8770 | - *Automatically running tests:* To run the tests automatically after | ||
| 8771 | the OpenEmbedded build system successfully creates an image, first | ||
| 8772 | set the | ||
| 8773 | :term:`TESTIMAGE_AUTO` | ||
| 8774 | variable to "1" in your ``local.conf`` file in the | ||
| 8775 | :term:`Build Directory`: | ||
| 8776 | :: | ||
| 8777 | |||
| 8778 | TESTIMAGE_AUTO = "1" | ||
| 8779 | |||
| 8780 | Next, build your image. If the image successfully builds, the | ||
| 8781 | tests run: | ||
| 8782 | :: | ||
| 8783 | |||
| 8784 | bitbake core-image-sato | ||
| 8785 | |||
| 8786 | - *Manually running tests:* To manually run the tests, first globally | ||
| 8787 | inherit the | ||
| 8788 | :ref:`testimage <ref-classes-testimage*>` class | ||
| 8789 | by editing your ``local.conf`` file: | ||
| 8790 | :: | ||
| 8791 | |||
| 8792 | INHERIT += "testimage" | ||
| 8793 | |||
| 8794 | Next, use BitBake to run the tests: | ||
| 8795 | :: | ||
| 8796 | |||
| 8797 | bitbake -c testimage image | ||
| 8798 | |||
| 8799 | All test files reside in ``meta/lib/oeqa/runtime`` in the | ||
| 8800 | :term:`Source Directory`. A test name maps | ||
| 8801 | directly to a Python module. Each test module may contain a number of | ||
| 8802 | individual tests. Tests are usually grouped together by the area tested | ||
| 8803 | (e.g tests for systemd reside in ``meta/lib/oeqa/runtime/systemd.py``). | ||
| 8804 | |||
| 8805 | You can add tests to any layer provided you place them in the proper | ||
| 8806 | area and you extend :term:`BBPATH` in | ||
| 8807 | the ``local.conf`` file as normal. Be sure that tests reside in | ||
| 8808 | ``layer/lib/oeqa/runtime``. | ||
| 8809 | |||
| 8810 | .. note:: | ||
| 8811 | |||
| 8812 | Be sure that module names do not collide with module names used in | ||
| 8813 | the default set of test modules in ``meta/lib/oeqa/runtime``. | ||
| 8814 | |||
| 8815 | You can change the set of tests run by appending or overriding | ||
| 8816 | :term:`TEST_SUITES` variable in | ||
| 8817 | ``local.conf``. Each name in ``TEST_SUITES`` represents a required test | ||
| 8818 | for the image. Test modules named within ``TEST_SUITES`` cannot be | ||
| 8819 | skipped even if a test is not suitable for an image (e.g. running the | ||
| 8820 | RPM tests on an image without ``rpm``). Appending "auto" to | ||
| 8821 | ``TEST_SUITES`` causes the build system to try to run all tests that are | ||
| 8822 | suitable for the image (i.e. each test module may elect to skip itself). | ||
| 8823 | |||
| 8824 | The order you list tests in ``TEST_SUITES`` is important and influences | ||
| 8825 | test dependencies. Consequently, tests that depend on other tests should | ||
| 8826 | be added after the test on which they depend. For example, since the | ||
| 8827 | ``ssh`` test depends on the ``ping`` test, "ssh" needs to come after | ||
| 8828 | "ping" in the list. The test class provides no re-ordering or dependency | ||
| 8829 | handling. | ||
| 8830 | |||
| 8831 | .. note:: | ||
| 8832 | |||
| 8833 | Each module can have multiple classes with multiple test methods. | ||
| 8834 | And, Python ``unittest`` rules apply. | ||
| 8835 | |||
| 8836 | Here are some things to keep in mind when running tests: | ||
| 8837 | |||
| 8838 | - The default tests for the image are defined as: | ||
| 8839 | :: | ||
| 8840 | |||
| 8841 | DEFAULT_TEST_SUITES_pn-image = "ping ssh df connman syslog xorg scp vnc date rpm dnf dmesg" | ||
| 8842 | |||
| 8843 | - Add your own test to the list of the by using the following: | ||
| 8844 | :: | ||
| 8845 | |||
| 8846 | TEST_SUITES_append = " mytest" | ||
| 8847 | |||
| 8848 | - Run a specific list of tests as follows: | ||
| 8849 | :: | ||
| 8850 | |||
| 8851 | TEST_SUITES = "test1 test2 test3" | ||
| 8852 | |||
| 8853 | Remember, order is important. Be sure to place a test that is | ||
| 8854 | dependent on another test later in the order. | ||
| 8855 | |||
| 8856 | Exporting Tests | ||
| 8857 | --------------- | ||
| 8858 | |||
| 8859 | You can export tests so that they can run independently of the build | ||
| 8860 | system. Exporting tests is required if you want to be able to hand the | ||
| 8861 | test execution off to a scheduler. You can only export tests that are | ||
| 8862 | defined in :term:`TEST_SUITES`. | ||
| 8863 | |||
| 8864 | If your image is already built, make sure the following are set in your | ||
| 8865 | ``local.conf`` file: | ||
| 8866 | :: | ||
| 8867 | |||
| 8868 | INHERIT += "testexport" | ||
| 8869 | TEST_TARGET_IP = "IP-address-for-the-test-target" | ||
| 8870 | TEST_SERVER_IP = "IP-address-for-the-test-server" | ||
| 8871 | |||
| 8872 | You can then export the tests with the | ||
| 8873 | following BitBake command form: | ||
| 8874 | :: | ||
| 8875 | |||
| 8876 | $ bitbake image -c testexport | ||
| 8877 | |||
| 8878 | Exporting the tests places them in the | ||
| 8879 | :term:`Build Directory` in | ||
| 8880 | ``tmp/testexport/``\ image, which is controlled by the | ||
| 8881 | ``TEST_EXPORT_DIR`` variable. | ||
| 8882 | |||
| 8883 | You can now run the tests outside of the build environment: | ||
| 8884 | :: | ||
| 8885 | |||
| 8886 | $ cd tmp/testexport/image | ||
| 8887 | $ ./runexported.py testdata.json | ||
| 8888 | |||
| 8889 | Here is a complete example that shows IP addresses and uses the | ||
| 8890 | ``core-image-sato`` image: | ||
| 8891 | :: | ||
| 8892 | |||
| 8893 | INHERIT += "testexport" | ||
| 8894 | TEST_TARGET_IP = "192.168.7.2" | ||
| 8895 | TEST_SERVER_IP = "192.168.7.1" | ||
| 8896 | |||
| 8897 | Use BitBake to export the tests: | ||
| 8898 | :: | ||
| 8899 | |||
| 8900 | $ bitbake core-image-sato -c testexport | ||
| 8901 | |||
| 8902 | Run the tests outside of | ||
| 8903 | the build environment using the following: | ||
| 8904 | :: | ||
| 8905 | |||
| 8906 | $ cd tmp/testexport/core-image-sato | ||
| 8907 | $ ./runexported.py testdata.json | ||
| 8908 | |||
| 8909 | Writing New Tests | ||
| 8910 | ----------------- | ||
| 8911 | |||
| 8912 | As mentioned previously, all new test files need to be in the proper | ||
| 8913 | place for the build system to find them. New tests for additional | ||
| 8914 | functionality outside of the core should be added to the layer that adds | ||
| 8915 | the functionality, in ``layer/lib/oeqa/runtime`` (as long as | ||
| 8916 | :term:`BBPATH` is extended in the | ||
| 8917 | layer's ``layer.conf`` file as normal). Just remember the following: | ||
| 8918 | |||
| 8919 | - Filenames need to map directly to test (module) names. | ||
| 8920 | |||
| 8921 | - Do not use module names that collide with existing core tests. | ||
| 8922 | |||
| 8923 | - Minimally, an empty ``__init__.py`` file must exist in the runtime | ||
| 8924 | directory. | ||
| 8925 | |||
| 8926 | To create a new test, start by copying an existing module (e.g. | ||
| 8927 | ``syslog.py`` or ``gcc.py`` are good ones to use). Test modules can use | ||
| 8928 | code from ``meta/lib/oeqa/utils``, which are helper classes. | ||
| 8929 | |||
| 8930 | .. note:: | ||
| 8931 | |||
| 8932 | Structure shell commands such that you rely on them and they return a | ||
| 8933 | single code for success. Be aware that sometimes you will need to | ||
| 8934 | parse the output. See the ``df.py`` and ``date.py`` modules for examples. | ||
| 8935 | |||
| 8936 | You will notice that all test classes inherit ``oeRuntimeTest``, which | ||
| 8937 | is found in ``meta/lib/oetest.py``. This base class offers some helper | ||
| 8938 | attributes, which are described in the following sections: | ||
| 8939 | |||
| 8940 | Class Methods | ||
| 8941 | ~~~~~~~~~~~~~ | ||
| 8942 | |||
| 8943 | Class methods are as follows: | ||
| 8944 | |||
| 8945 | - *hasPackage(pkg):* Returns "True" if ``pkg`` is in the installed | ||
| 8946 | package list of the image, which is based on the manifest file that | ||
| 8947 | is generated during the ``do_rootfs`` task. | ||
| 8948 | |||
| 8949 | - *hasFeature(feature):* Returns "True" if the feature is in | ||
| 8950 | :term:`IMAGE_FEATURES` or | ||
| 8951 | :term:`DISTRO_FEATURES`. | ||
| 8952 | |||
| 8953 | Class Attributes | ||
| 8954 | ~~~~~~~~~~~~~~~~ | ||
| 8955 | |||
| 8956 | Class attributes are as follows: | ||
| 8957 | |||
| 8958 | - *pscmd:* Equals "ps -ef" if ``procps`` is installed in the image. | ||
| 8959 | Otherwise, ``pscmd`` equals "ps" (busybox). | ||
| 8960 | |||
| 8961 | - *tc:* The called test context, which gives access to the | ||
| 8962 | following attributes: | ||
| 8963 | |||
| 8964 | - *d:* The BitBake datastore, which allows you to use stuff such | ||
| 8965 | as ``oeRuntimeTest.tc.d.getVar("VIRTUAL-RUNTIME_init_manager")``. | ||
| 8966 | |||
| 8967 | - *testslist and testsrequired:* Used internally. The tests | ||
| 8968 | do not need these. | ||
| 8969 | |||
| 8970 | - *filesdir:* The absolute path to | ||
| 8971 | ``meta/lib/oeqa/runtime/files``, which contains helper files for | ||
| 8972 | tests meant for copying on the target such as small files written | ||
| 8973 | in C for compilation. | ||
| 8974 | |||
| 8975 | - *target:* The target controller object used to deploy and | ||
| 8976 | start an image on a particular target (e.g. Qemu, SimpleRemote, | ||
| 8977 | and SystemdbootTarget). Tests usually use the following: | ||
| 8978 | |||
| 8979 | - *ip:* The target's IP address. | ||
| 8980 | |||
| 8981 | - *server_ip:* The host's IP address, which is usually used | ||
| 8982 | by the DNF test suite. | ||
| 8983 | |||
| 8984 | - *run(cmd, timeout=None):* The single, most used method. | ||
| 8985 | This command is a wrapper for: ``ssh root@host "cmd"``. The | ||
| 8986 | command returns a tuple: (status, output), which are what their | ||
| 8987 | names imply - the return code of "cmd" and whatever output it | ||
| 8988 | produces. The optional timeout argument represents the number | ||
| 8989 | of seconds the test should wait for "cmd" to return. If the | ||
| 8990 | argument is "None", the test uses the default instance's | ||
| 8991 | timeout period, which is 300 seconds. If the argument is "0", | ||
| 8992 | the test runs until the command returns. | ||
| 8993 | |||
| 8994 | - *copy_to(localpath, remotepath):* | ||
| 8995 | ``scp localpath root@ip:remotepath``. | ||
| 8996 | |||
| 8997 | - *copy_from(remotepath, localpath):* | ||
| 8998 | ``scp root@host:remotepath localpath``. | ||
| 8999 | |||
| 9000 | Instance Attributes | ||
| 9001 | ~~~~~~~~~~~~~~~~~~~ | ||
| 9002 | |||
| 9003 | A single instance attribute exists, which is ``target``. The ``target`` | ||
| 9004 | instance attribute is identical to the class attribute of the same name, | ||
| 9005 | which is described in the previous section. This attribute exists as | ||
| 9006 | both an instance and class attribute so tests can use | ||
| 9007 | ``self.target.run(cmd)`` in instance methods instead of | ||
| 9008 | ``oeRuntimeTest.tc.target.run(cmd)``. | ||
| 9009 | |||
| 9010 | Installing Packages in the DUT Without the Package Manager | ||
| 9011 | ---------------------------------------------------------- | ||
| 9012 | |||
| 9013 | When a test requires a package built by BitBake, it is possible to | ||
| 9014 | install that package. Installing the package does not require a package | ||
| 9015 | manager be installed in the device under test (DUT). It does, however, | ||
| 9016 | require an SSH connection and the target must be using the | ||
| 9017 | ``sshcontrol`` class. | ||
| 9018 | |||
| 9019 | .. note:: | ||
| 9020 | |||
| 9021 | This method uses ``scp`` to copy files from the host to the target, which | ||
| 9022 | causes permissions and special attributes to be lost. | ||
| 9023 | |||
| 9024 | A JSON file is used to define the packages needed by a test. This file | ||
| 9025 | must be in the same path as the file used to define the tests. | ||
| 9026 | Furthermore, the filename must map directly to the test module name with | ||
| 9027 | a ``.json`` extension. | ||
| 9028 | |||
| 9029 | The JSON file must include an object with the test name as keys of an | ||
| 9030 | object or an array. This object (or array of objects) uses the following | ||
| 9031 | data: | ||
| 9032 | |||
| 9033 | - "pkg" - A mandatory string that is the name of the package to be | ||
| 9034 | installed. | ||
| 9035 | |||
| 9036 | - "rm" - An optional boolean, which defaults to "false", that specifies | ||
| 9037 | to remove the package after the test. | ||
| 9038 | |||
| 9039 | - "extract" - An optional boolean, which defaults to "false", that | ||
| 9040 | specifies if the package must be extracted from the package format. | ||
| 9041 | When set to "true", the package is not automatically installed into | ||
| 9042 | the DUT. | ||
| 9043 | |||
| 9044 | Following is an example JSON file that handles test "foo" installing | ||
| 9045 | package "bar" and test "foobar" installing packages "foo" and "bar". | ||
| 9046 | Once the test is complete, the packages are removed from the DUT. | ||
| 9047 | :: | ||
| 9048 | |||
| 9049 | { | ||
| 9050 | "foo": { | ||
| 9051 | "pkg": "bar" | ||
| 9052 | }, | ||
| 9053 | "foobar": [ | ||
| 9054 | { | ||
| 9055 | "pkg": "foo", | ||
| 9056 | "rm": true | ||
| 9057 | }, | ||
| 9058 | { | ||
| 9059 | "pkg": "bar", | ||
| 9060 | "rm": true | ||
| 9061 | } | ||
| 9062 | ] | ||
| 9063 | } | ||
| 9064 | |||
| 9065 | Debugging Tools and Techniques | ||
| 9066 | ============================== | ||
| 9067 | |||
| 9068 | The exact method for debugging build failures depends on the nature of | ||
| 9069 | the problem and on the system's area from which the bug originates. | ||
| 9070 | Standard debugging practices such as comparison against the last known | ||
| 9071 | working version with examination of the changes and the re-application | ||
| 9072 | of steps to identify the one causing the problem are valid for the Yocto | ||
| 9073 | Project just as they are for any other system. Even though it is | ||
| 9074 | impossible to detail every possible potential failure, this section | ||
| 9075 | provides some general tips to aid in debugging given a variety of | ||
| 9076 | situations. | ||
| 9077 | |||
| 9078 | .. note:: | ||
| 9079 | |||
| 9080 | A useful feature for debugging is the error reporting tool. | ||
| 9081 | Configuring the Yocto Project to use this tool causes the | ||
| 9082 | OpenEmbedded build system to produce error reporting commands as part | ||
| 9083 | of the console output. You can enter the commands after the build | ||
| 9084 | completes to log error information into a common database, that can | ||
| 9085 | help you figure out what might be going wrong. For information on how | ||
| 9086 | to enable and use this feature, see the | ||
| 9087 | ":ref:`dev-manual/common-tasks:using the error reporting tool`" | ||
| 9088 | section. | ||
| 9089 | |||
| 9090 | The following list shows the debugging topics in the remainder of this | ||
| 9091 | section: | ||
| 9092 | |||
| 9093 | - "`Viewing Logs from Failed | ||
| 9094 | Tasks <#dev-debugging-viewing-logs-from-failed-tasks>`__" describes | ||
| 9095 | how to find and view logs from tasks that failed during the build | ||
| 9096 | process. | ||
| 9097 | |||
| 9098 | - "`Viewing Variable | ||
| 9099 | Values <#dev-debugging-viewing-variable-values>`__" describes how to | ||
| 9100 | use the BitBake ``-e`` option to examine variable values after a | ||
| 9101 | recipe has been parsed. | ||
| 9102 | |||
| 9103 | - ":ref:`dev-manual/common-tasks:viewing package information with \`\`oe-pkgdata-util\`\``" | ||
| 9104 | describes how to use the ``oe-pkgdata-util`` utility to query | ||
| 9105 | :term:`PKGDATA_DIR` and | ||
| 9106 | display package-related information for built packages. | ||
| 9107 | |||
| 9108 | - "`Viewing Dependencies Between Recipes and | ||
| 9109 | Tasks <#dev-viewing-dependencies-between-recipes-and-tasks>`__" | ||
| 9110 | describes how to use the BitBake ``-g`` option to display recipe | ||
| 9111 | dependency information used during the build. | ||
| 9112 | |||
| 9113 | - "`Viewing Task Variable | ||
| 9114 | Dependencies <#dev-viewing-task-variable-dependencies>`__" describes | ||
| 9115 | how to use the ``bitbake-dumpsig`` command in conjunction with key | ||
| 9116 | subdirectories in the | ||
| 9117 | :term:`Build Directory` to determine | ||
| 9118 | variable dependencies. | ||
| 9119 | |||
| 9120 | - "`Running Specific Tasks <#dev-debugging-taskrunning>`__" describes | ||
| 9121 | how to use several BitBake options (e.g. ``-c``, ``-C``, and ``-f``) | ||
| 9122 | to run specific tasks in the build chain. It can be useful to run | ||
| 9123 | tasks "out-of-order" when trying isolate build issues. | ||
| 9124 | |||
| 9125 | - "`General BitBake Problems <#dev-debugging-bitbake>`__" describes how | ||
| 9126 | to use BitBake's ``-D`` debug output option to reveal more about what | ||
| 9127 | BitBake is doing during the build. | ||
| 9128 | |||
| 9129 | - "`Building with No Dependencies <#dev-debugging-buildfile>`__" | ||
| 9130 | describes how to use the BitBake ``-b`` option to build a recipe | ||
| 9131 | while ignoring dependencies. | ||
| 9132 | |||
| 9133 | - "`Recipe Logging Mechanisms <#recipe-logging-mechanisms>`__" | ||
| 9134 | describes how to use the many recipe logging functions to produce | ||
| 9135 | debugging output and report errors and warnings. | ||
| 9136 | |||
| 9137 | - "`Debugging Parallel Make Races <#debugging-parallel-make-races>`__" | ||
| 9138 | describes how to debug situations where the build consists of several | ||
| 9139 | parts that are run simultaneously and when the output or result of | ||
| 9140 | one part is not ready for use with a different part of the build that | ||
| 9141 | depends on that output. | ||
| 9142 | |||
| 9143 | - "`Debugging With the GNU Project Debugger (GDB) | ||
| 9144 | Remotely <#platdev-gdb-remotedebug>`__" describes how to use GDB to | ||
| 9145 | allow you to examine running programs, which can help you fix | ||
| 9146 | problems. | ||
| 9147 | |||
| 9148 | - "`Debugging with the GNU Project Debugger (GDB) on the | ||
| 9149 | Target <#debugging-with-the-gnu-project-debugger-gdb-on-the-target>`__" | ||
| 9150 | describes how to use GDB directly on target hardware for debugging. | ||
| 9151 | |||
| 9152 | - "`Other Debugging Tips <#dev-other-debugging-others>`__" describes | ||
| 9153 | miscellaneous debugging tips that can be useful. | ||
| 9154 | |||
| 9155 | Viewing Logs from Failed Tasks | ||
| 9156 | ------------------------------ | ||
| 9157 | |||
| 9158 | You can find the log for a task in the file | ||
| 9159 | ``${``\ :term:`WORKDIR`\ ``}/temp/log.do_``\ `taskname`. | ||
| 9160 | For example, the log for the | ||
| 9161 | :ref:`ref-tasks-compile` task of the | ||
| 9162 | QEMU minimal image for the x86 machine (``qemux86``) might be in | ||
| 9163 | ``tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/temp/log.do_compile``. | ||
| 9164 | To see the commands :term:`BitBake` ran | ||
| 9165 | to generate a log, look at the corresponding ``run.do_``\ `taskname` file | ||
| 9166 | in the same directory. | ||
| 9167 | |||
| 9168 | ``log.do_``\ `taskname` and ``run.do_``\ `taskname` are actually symbolic | ||
| 9169 | links to ``log.do_``\ `taskname`\ ``.``\ `pid` and | ||
| 9170 | ``log.run_``\ `taskname`\ ``.``\ `pid`, where `pid` is the PID the task had | ||
| 9171 | when it ran. The symlinks always point to the files corresponding to the | ||
| 9172 | most recent run. | ||
| 9173 | |||
| 9174 | Viewing Variable Values | ||
| 9175 | ----------------------- | ||
| 9176 | |||
| 9177 | Sometimes you need to know the value of a variable as a result of | ||
| 9178 | BitBake's parsing step. This could be because some unexpected behavior | ||
| 9179 | occurred in your project. Perhaps an attempt to :ref:`modify a variable | ||
| 9180 | <bitbake:bitbake-user-manual/bitbake-user-manual-metadata:modifying existing | ||
| 9181 | variables>` did not work out as expected. | ||
| 9182 | |||
| 9183 | BitBake's ``-e`` option is used to display variable values after | ||
| 9184 | parsing. The following command displays the variable values after the | ||
| 9185 | configuration files (i.e. ``local.conf``, ``bblayers.conf``, | ||
| 9186 | ``bitbake.conf`` and so forth) have been parsed: | ||
| 9187 | :: | ||
| 9188 | |||
| 9189 | $ bitbake -e | ||
| 9190 | |||
| 9191 | The following command displays variable values after a specific recipe has | ||
| 9192 | been parsed. The variables include those from the configuration as well: | ||
| 9193 | :: | ||
| 9194 | |||
| 9195 | $ bitbake -e recipename | ||
| 9196 | |||
| 9197 | .. note:: | ||
| 9198 | |||
| 9199 | Each recipe has its own private set of variables (datastore). | ||
| 9200 | Internally, after parsing the configuration, a copy of the resulting | ||
| 9201 | datastore is made prior to parsing each recipe. This copying implies | ||
| 9202 | that variables set in one recipe will not be visible to other | ||
| 9203 | recipes. | ||
| 9204 | |||
| 9205 | Likewise, each task within a recipe gets a private datastore based on | ||
| 9206 | the recipe datastore, which means that variables set within one task | ||
| 9207 | will not be visible to other tasks. | ||
| 9208 | |||
| 9209 | In the output of ``bitbake -e``, each variable is preceded by a | ||
| 9210 | description of how the variable got its value, including temporary | ||
| 9211 | values that were later overridden. This description also includes | ||
| 9212 | variable flags (varflags) set on the variable. The output can be very | ||
| 9213 | helpful during debugging. | ||
| 9214 | |||
| 9215 | Variables that are exported to the environment are preceded by | ||
| 9216 | ``export`` in the output of ``bitbake -e``. See the following example: | ||
| 9217 | :: | ||
| 9218 | |||
| 9219 | export CC="i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/ulf/poky/build/tmp/sysroots/qemux86" | ||
| 9220 | |||
| 9221 | In addition to variable values, the output of the ``bitbake -e`` and | ||
| 9222 | ``bitbake -e`` recipe commands includes the following information: | ||
| 9223 | |||
| 9224 | - The output starts with a tree listing all configuration files and | ||
| 9225 | classes included globally, recursively listing the files they include | ||
| 9226 | or inherit in turn. Much of the behavior of the OpenEmbedded build | ||
| 9227 | system (including the behavior of the :ref:`ref-manual/ref-tasks:normal recipe build tasks`) is | ||
| 9228 | implemented in the | ||
| 9229 | :ref:`base <ref-classes-base>` class and the | ||
| 9230 | classes it inherits, rather than being built into BitBake itself. | ||
| 9231 | |||
| 9232 | - After the variable values, all functions appear in the output. For | ||
| 9233 | shell functions, variables referenced within the function body are | ||
| 9234 | expanded. If a function has been modified using overrides or using | ||
| 9235 | override-style operators like ``_append`` and ``_prepend``, then the | ||
| 9236 | final assembled function body appears in the output. | ||
| 9237 | |||
| 9238 | Viewing Package Information with ``oe-pkgdata-util`` | ||
| 9239 | ---------------------------------------------------- | ||
| 9240 | |||
| 9241 | You can use the ``oe-pkgdata-util`` command-line utility to query | ||
| 9242 | :term:`PKGDATA_DIR` and display | ||
| 9243 | various package-related information. When you use the utility, you must | ||
| 9244 | use it to view information on packages that have already been built. | ||
| 9245 | |||
| 9246 | Following are a few of the available ``oe-pkgdata-util`` subcommands. | ||
| 9247 | |||
| 9248 | .. note:: | ||
| 9249 | |||
| 9250 | You can use the standard \* and ? globbing wildcards as part of | ||
| 9251 | package names and paths. | ||
| 9252 | |||
| 9253 | - ``oe-pkgdata-util list-pkgs [pattern]``: Lists all packages | ||
| 9254 | that have been built, optionally limiting the match to packages that | ||
| 9255 | match pattern. | ||
| 9256 | |||
| 9257 | - ``oe-pkgdata-util list-pkg-files package ...``: Lists the | ||
| 9258 | files and directories contained in the given packages. | ||
| 9259 | |||
| 9260 | .. note:: | ||
| 9261 | |||
| 9262 | A different way to view the contents of a package is to look at | ||
| 9263 | the | ||
| 9264 | ``${``\ :term:`WORKDIR`\ ``}/packages-split`` | ||
| 9265 | directory of the recipe that generates the package. This directory | ||
| 9266 | is created by the | ||
| 9267 | :ref:`ref-tasks-package` task | ||
| 9268 | and has one subdirectory for each package the recipe generates, | ||
| 9269 | which contains the files stored in that package. | ||
| 9270 | |||
| 9271 | If you want to inspect the ``${WORKDIR}/packages-split`` | ||
| 9272 | directory, make sure that | ||
| 9273 | :ref:`rm_work <ref-classes-rm-work>` is not | ||
| 9274 | enabled when you build the recipe. | ||
| 9275 | |||
| 9276 | - ``oe-pkgdata-util find-path path ...``: Lists the names of | ||
| 9277 | the packages that contain the given paths. For example, the following | ||
| 9278 | tells us that ``/usr/share/man/man1/make.1`` is contained in the | ||
| 9279 | ``make-doc`` package: | ||
| 9280 | :: | ||
| 9281 | |||
| 9282 | $ oe-pkgdata-util find-path /usr/share/man/man1/make.1 | ||
| 9283 | make-doc: /usr/share/man/man1/make.1 | ||
| 9284 | |||
| 9285 | - ``oe-pkgdata-util lookup-recipe package ...``: Lists the name | ||
| 9286 | of the recipes that produce the given packages. | ||
| 9287 | |||
| 9288 | For more information on the ``oe-pkgdata-util`` command, use the help | ||
| 9289 | facility: | ||
| 9290 | :: | ||
| 9291 | |||
| 9292 | $ oe-pkgdata-util --help | ||
| 9293 | $ oe-pkgdata-util subcommand --help | ||
| 9294 | |||
| 9295 | Viewing Dependencies Between Recipes and Tasks | ||
| 9296 | ---------------------------------------------- | ||
| 9297 | |||
| 9298 | Sometimes it can be hard to see why BitBake wants to build other recipes | ||
| 9299 | before the one you have specified. Dependency information can help you | ||
| 9300 | understand why a recipe is built. | ||
| 9301 | |||
| 9302 | To generate dependency information for a recipe, run the following | ||
| 9303 | command: | ||
| 9304 | :: | ||
| 9305 | |||
| 9306 | $ bitbake -g recipename | ||
| 9307 | |||
| 9308 | This command writes the following files in the current directory: | ||
| 9309 | |||
| 9310 | - ``pn-buildlist``: A list of recipes/targets involved in building | ||
| 9311 | `recipename`. "Involved" here means that at least one task from the | ||
| 9312 | recipe needs to run when building `recipename` from scratch. Targets | ||
| 9313 | that are in | ||
| 9314 | :term:`ASSUME_PROVIDED` | ||
| 9315 | are not listed. | ||
| 9316 | |||
| 9317 | - ``task-depends.dot``: A graph showing dependencies between tasks. | ||
| 9318 | |||
| 9319 | The graphs are in | ||
| 9320 | `DOT <https://en.wikipedia.org/wiki/DOT_%28graph_description_language%29>`__ | ||
| 9321 | format and can be converted to images (e.g. using the ``dot`` tool from | ||
| 9322 | `Graphviz <https://www.graphviz.org/>`__). | ||
| 9323 | |||
| 9324 | .. note:: | ||
| 9325 | |||
| 9326 | - DOT files use a plain text format. The graphs generated using the | ||
| 9327 | ``bitbake -g`` command are often so large as to be difficult to | ||
| 9328 | read without special pruning (e.g. with Bitbake's ``-I`` option) | ||
| 9329 | and processing. Despite the form and size of the graphs, the | ||
| 9330 | corresponding ``.dot`` files can still be possible to read and | ||
| 9331 | provide useful information. | ||
| 9332 | |||
| 9333 | As an example, the ``task-depends.dot`` file contains lines such | ||
| 9334 | as the following: | ||
| 9335 | :: | ||
| 9336 | |||
| 9337 | "libxslt.do_configure" -> "libxml2.do_populate_sysroot" | ||
| 9338 | |||
| 9339 | The above example line reveals that the | ||
| 9340 | :ref:`ref-tasks-configure` | ||
| 9341 | task in ``libxslt`` depends on the | ||
| 9342 | :ref:`ref-tasks-populate_sysroot` | ||
| 9343 | task in ``libxml2``, which is a normal | ||
| 9344 | :term:`DEPENDS` dependency | ||
| 9345 | between the two recipes. | ||
| 9346 | |||
| 9347 | - For an example of how ``.dot`` files can be processed, see the | ||
| 9348 | ``scripts/contrib/graph-tool`` Python script, which finds and | ||
| 9349 | displays paths between graph nodes. | ||
| 9350 | |||
| 9351 | You can use a different method to view dependency information by using | ||
| 9352 | the following command: | ||
| 9353 | :: | ||
| 9354 | |||
| 9355 | $ bitbake -g -u taskexp recipename | ||
| 9356 | |||
| 9357 | This command | ||
| 9358 | displays a GUI window from which you can view build-time and runtime | ||
| 9359 | dependencies for the recipes involved in building recipename. | ||
| 9360 | |||
| 9361 | Viewing Task Variable Dependencies | ||
| 9362 | ---------------------------------- | ||
| 9363 | |||
| 9364 | As mentioned in the | ||
| 9365 | ":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-execution:checksums (signatures)`" section of the BitBake | ||
| 9366 | User Manual, BitBake tries to automatically determine what variables a | ||
| 9367 | task depends on so that it can rerun the task if any values of the | ||
| 9368 | variables change. This determination is usually reliable. However, if | ||
| 9369 | you do things like construct variable names at runtime, then you might | ||
| 9370 | have to manually declare dependencies on those variables using | ||
| 9371 | ``vardeps`` as described in the | ||
| 9372 | ":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags`" section of the BitBake | ||
| 9373 | User Manual. | ||
| 9374 | |||
| 9375 | If you are unsure whether a variable dependency is being picked up | ||
| 9376 | automatically for a given task, you can list the variable dependencies | ||
| 9377 | BitBake has determined by doing the following: | ||
| 9378 | |||
| 9379 | 1. Build the recipe containing the task: | ||
| 9380 | :: | ||
| 9381 | |||
| 9382 | $ bitbake recipename | ||
| 9383 | |||
| 9384 | 2. Inside the :term:`STAMPS_DIR` | ||
| 9385 | directory, find the signature data (``sigdata``) file that | ||
| 9386 | corresponds to the task. The ``sigdata`` files contain a pickled | ||
| 9387 | Python database of all the metadata that went into creating the input | ||
| 9388 | checksum for the task. As an example, for the | ||
| 9389 | :ref:`ref-tasks-fetch` task of the | ||
| 9390 | ``db`` recipe, the ``sigdata`` file might be found in the following | ||
| 9391 | location: | ||
| 9392 | :: | ||
| 9393 | |||
| 9394 | ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1 | ||
| 9395 | |||
| 9396 | For tasks that are accelerated through the shared state | ||
| 9397 | (:ref:`sstate <overview-manual/overview-manual-concepts:shared state cache>`) cache, an | ||
| 9398 | additional ``siginfo`` file is written into | ||
| 9399 | :term:`SSTATE_DIR` along with | ||
| 9400 | the cached task output. The ``siginfo`` files contain exactly the | ||
| 9401 | same information as ``sigdata`` files. | ||
| 9402 | |||
| 9403 | 3. Run ``bitbake-dumpsig`` on the ``sigdata`` or ``siginfo`` file. Here | ||
| 9404 | is an example: | ||
| 9405 | :: | ||
| 9406 | |||
| 9407 | $ bitbake-dumpsig ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1 | ||
| 9408 | |||
| 9409 | In the output of the above command, you will find a line like the | ||
| 9410 | following, which lists all the (inferred) variable dependencies for | ||
| 9411 | the task. This list also includes indirect dependencies from | ||
| 9412 | variables depending on other variables, recursively. | ||
| 9413 | :: | ||
| 9414 | |||
| 9415 | Task dependencies: ['PV', 'SRCREV', 'SRC_URI', 'SRC_URI[md5sum]', 'SRC_URI[sha256sum]', 'base_do_fetch'] | ||
| 9416 | |||
| 9417 | .. note:: | ||
| 9418 | |||
| 9419 | Functions (e.g. ``base_do_fetch``) also count as variable dependencies. | ||
| 9420 | These functions in turn depend on the variables they reference. | ||
| 9421 | |||
| 9422 | The output of ``bitbake-dumpsig`` also includes the value each | ||
| 9423 | variable had, a list of dependencies for each variable, and | ||
| 9424 | :term:`bitbake:BB_HASHBASE_WHITELIST` | ||
| 9425 | information. | ||
| 9426 | |||
| 9427 | There is also a ``bitbake-diffsigs`` command for comparing two | ||
| 9428 | ``siginfo`` or ``sigdata`` files. This command can be helpful when | ||
| 9429 | trying to figure out what changed between two versions of a task. If you | ||
| 9430 | call ``bitbake-diffsigs`` with just one file, the command behaves like | ||
| 9431 | ``bitbake-dumpsig``. | ||
| 9432 | |||
| 9433 | You can also use BitBake to dump out the signature construction | ||
| 9434 | information without executing tasks by using either of the following | ||
| 9435 | BitBake command-line options: | ||
| 9436 | :: | ||
| 9437 | |||
| 9438 | ‐‐dump-signatures=SIGNATURE_HANDLER | ||
| 9439 | -S SIGNATURE_HANDLER | ||
| 9440 | |||
| 9441 | |||
| 9442 | .. note:: | ||
| 9443 | |||
| 9444 | Two common values for `SIGNATURE_HANDLER` are "none" and "printdiff", which | ||
| 9445 | dump only the signature or compare the dumped signature with the cached one, | ||
| 9446 | respectively. | ||
| 9447 | |||
| 9448 | Using BitBake with either of these options causes BitBake to dump out | ||
| 9449 | ``sigdata`` files in the ``stamps`` directory for every task it would | ||
| 9450 | have executed instead of building the specified target package. | ||
| 9451 | |||
| 9452 | Viewing Metadata Used to Create the Input Signature of a Shared State Task | ||
| 9453 | -------------------------------------------------------------------------- | ||
| 9454 | |||
| 9455 | Seeing what metadata went into creating the input signature of a shared | ||
| 9456 | state (sstate) task can be a useful debugging aid. This information is | ||
| 9457 | available in signature information (``siginfo``) files in | ||
| 9458 | :term:`SSTATE_DIR`. For | ||
| 9459 | information on how to view and interpret information in ``siginfo`` | ||
| 9460 | files, see the "`Viewing Task Variable | ||
| 9461 | Dependencies <#dev-viewing-task-variable-dependencies>`__" section. | ||
| 9462 | |||
| 9463 | For conceptual information on shared state, see the | ||
| 9464 | ":ref:`overview-manual/overview-manual-concepts:shared state`" | ||
| 9465 | section in the Yocto Project Overview and Concepts Manual. | ||
| 9466 | |||
| 9467 | Invalidating Shared State to Force a Task to Run | ||
| 9468 | ------------------------------------------------ | ||
| 9469 | |||
| 9470 | The OpenEmbedded build system uses | ||
| 9471 | :ref:`checksums <overview-manual/overview-manual-concepts:checksums (signatures)>` and | ||
| 9472 | :ref:`overview-manual/overview-manual-concepts:shared state` cache to avoid unnecessarily | ||
| 9473 | rebuilding tasks. Collectively, this scheme is known as "shared state | ||
| 9474 | code". | ||
| 9475 | |||
| 9476 | As with all schemes, this one has some drawbacks. It is possible that | ||
| 9477 | you could make implicit changes to your code that the checksum | ||
| 9478 | calculations do not take into account. These implicit changes affect a | ||
| 9479 | task's output but do not trigger the shared state code into rebuilding a | ||
| 9480 | recipe. Consider an example during which a tool changes its output. | ||
| 9481 | Assume that the output of ``rpmdeps`` changes. The result of the change | ||
| 9482 | should be that all the ``package`` and ``package_write_rpm`` shared | ||
| 9483 | state cache items become invalid. However, because the change to the | ||
| 9484 | output is external to the code and therefore implicit, the associated | ||
| 9485 | shared state cache items do not become invalidated. In this case, the | ||
| 9486 | build process uses the cached items rather than running the task again. | ||
| 9487 | Obviously, these types of implicit changes can cause problems. | ||
| 9488 | |||
| 9489 | To avoid these problems during the build, you need to understand the | ||
| 9490 | effects of any changes you make. Realize that changes you make directly | ||
| 9491 | to a function are automatically factored into the checksum calculation. | ||
| 9492 | Thus, these explicit changes invalidate the associated area of shared | ||
| 9493 | state cache. However, you need to be aware of any implicit changes that | ||
| 9494 | are not obvious changes to the code and could affect the output of a | ||
| 9495 | given task. | ||
| 9496 | |||
| 9497 | When you identify an implicit change, you can easily take steps to | ||
| 9498 | invalidate the cache and force the tasks to run. The steps you can take | ||
| 9499 | are as simple as changing a function's comments in the source code. For | ||
| 9500 | example, to invalidate package shared state files, change the comment | ||
| 9501 | statements of | ||
| 9502 | :ref:`ref-tasks-package` or the | ||
| 9503 | comments of one of the functions it calls. Even though the change is | ||
| 9504 | purely cosmetic, it causes the checksum to be recalculated and forces | ||
| 9505 | the build system to run the task again. | ||
| 9506 | |||
| 9507 | .. note:: | ||
| 9508 | |||
| 9509 | For an example of a commit that makes a cosmetic change to invalidate | ||
| 9510 | shared state, see this | ||
| 9511 | :yocto_git:`commit </poky/commit/meta/classes/package.bbclass?id=737f8bbb4f27b4837047cb9b4fbfe01dfde36d54>`. | ||
| 9512 | |||
| 9513 | Running Specific Tasks | ||
| 9514 | ---------------------- | ||
| 9515 | |||
| 9516 | Any given recipe consists of a set of tasks. The standard BitBake | ||
| 9517 | behavior in most cases is: ``do_fetch``, ``do_unpack``, ``do_patch``, | ||
| 9518 | ``do_configure``, ``do_compile``, ``do_install``, ``do_package``, | ||
| 9519 | ``do_package_write_*``, and ``do_build``. The default task is | ||
| 9520 | ``do_build`` and any tasks on which it depends build first. Some tasks, | ||
| 9521 | such as ``do_devshell``, are not part of the default build chain. If you | ||
| 9522 | wish to run a task that is not part of the default build chain, you can | ||
| 9523 | use the ``-c`` option in BitBake. Here is an example: | ||
| 9524 | :: | ||
| 9525 | |||
| 9526 | $ bitbake matchbox-desktop -c devshell | ||
| 9527 | |||
| 9528 | The ``-c`` option respects task dependencies, which means that all other | ||
| 9529 | tasks (including tasks from other recipes) that the specified task | ||
| 9530 | depends on will be run before the task. Even when you manually specify a | ||
| 9531 | task to run with ``-c``, BitBake will only run the task if it considers | ||
| 9532 | it "out of date". See the | ||
| 9533 | ":ref:`overview-manual/overview-manual-concepts:stamp files and the rerunning of tasks`" | ||
| 9534 | section in the Yocto Project Overview and Concepts Manual for how | ||
| 9535 | BitBake determines whether a task is "out of date". | ||
| 9536 | |||
| 9537 | If you want to force an up-to-date task to be rerun (e.g. because you | ||
| 9538 | made manual modifications to the recipe's | ||
| 9539 | :term:`WORKDIR` that you want to try | ||
| 9540 | out), then you can use the ``-f`` option. | ||
| 9541 | |||
| 9542 | .. note:: | ||
| 9543 | |||
| 9544 | The reason ``-f`` is never required when running the | ||
| 9545 | :ref:`ref-tasks-devshell` task is because the | ||
| 9546 | [\ :ref:`nostamp <bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ] | ||
| 9547 | variable flag is already set for the task. | ||
| 9548 | |||
| 9549 | The following example shows one way you can use the ``-f`` option: | ||
| 9550 | :: | ||
| 9551 | |||
| 9552 | $ bitbake matchbox-desktop | ||
| 9553 | . | ||
| 9554 | . | ||
| 9555 | make some changes to the source code in the work directory | ||
| 9556 | . | ||
| 9557 | . | ||
| 9558 | $ bitbake matchbox-desktop -c compile -f | ||
| 9559 | $ bitbake matchbox-desktop | ||
| 9560 | |||
| 9561 | This sequence first builds and then recompiles ``matchbox-desktop``. The | ||
| 9562 | last command reruns all tasks (basically the packaging tasks) after the | ||
| 9563 | compile. BitBake recognizes that the ``do_compile`` task was rerun and | ||
| 9564 | therefore understands that the other tasks also need to be run again. | ||
| 9565 | |||
| 9566 | Another, shorter way to rerun a task and all | ||
| 9567 | :ref:`ref-manual/ref-tasks:normal recipe build tasks` | ||
| 9568 | that depend on it is to use the ``-C`` option. | ||
| 9569 | |||
| 9570 | .. note:: | ||
| 9571 | |||
| 9572 | This option is upper-cased and is separate from the ``-c`` | ||
| 9573 | option, which is lower-cased. | ||
| 9574 | |||
| 9575 | Using this option invalidates the given task and then runs the | ||
| 9576 | :ref:`ref-tasks-build` task, which is | ||
| 9577 | the default task if no task is given, and the tasks on which it depends. | ||
| 9578 | You could replace the final two commands in the previous example with | ||
| 9579 | the following single command: | ||
| 9580 | :: | ||
| 9581 | |||
| 9582 | $ bitbake matchbox-desktop -C compile | ||
| 9583 | |||
| 9584 | Internally, the ``-f`` and ``-C`` options work by tainting (modifying) | ||
| 9585 | the input checksum of the specified task. This tainting indirectly | ||
| 9586 | causes the task and its dependent tasks to be rerun through the normal | ||
| 9587 | task dependency mechanisms. | ||
| 9588 | |||
| 9589 | .. note:: | ||
| 9590 | |||
| 9591 | BitBake explicitly keeps track of which tasks have been tainted in | ||
| 9592 | this fashion, and will print warnings such as the following for | ||
| 9593 | builds involving such tasks: | ||
| 9594 | |||
| 9595 | .. code-block:: none | ||
| 9596 | |||
| 9597 | WARNING: /home/ulf/poky/meta/recipes-sato/matchbox-desktop/matchbox-desktop_2.1.bb.do_compile is tainted from a forced run | ||
| 9598 | |||
| 9599 | |||
| 9600 | The purpose of the warning is to let you know that the work directory | ||
| 9601 | and build output might not be in the clean state they would be in for | ||
| 9602 | a "normal" build, depending on what actions you took. To get rid of | ||
| 9603 | such warnings, you can remove the work directory and rebuild the | ||
| 9604 | recipe, as follows: | ||
| 9605 | :: | ||
| 9606 | |||
| 9607 | $ bitbake matchbox-desktop -c clean | ||
| 9608 | $ bitbake matchbox-desktop | ||
| 9609 | |||
| 9610 | |||
| 9611 | You can view a list of tasks in a given package by running the | ||
| 9612 | ``do_listtasks`` task as follows: | ||
| 9613 | :: | ||
| 9614 | |||
| 9615 | $ bitbake matchbox-desktop -c listtasks | ||
| 9616 | |||
| 9617 | The results appear as output to the console and are also in | ||
| 9618 | the file ``${WORKDIR}/temp/log.do_listtasks``. | ||
| 9619 | |||
| 9620 | General BitBake Problems | ||
| 9621 | ------------------------ | ||
| 9622 | |||
| 9623 | You can see debug output from BitBake by using the ``-D`` option. The | ||
| 9624 | debug output gives more information about what BitBake is doing and the | ||
| 9625 | reason behind it. Each ``-D`` option you use increases the logging | ||
| 9626 | level. The most common usage is ``-DDD``. | ||
| 9627 | |||
| 9628 | The output from ``bitbake -DDD -v targetname`` can reveal why BitBake | ||
| 9629 | chose a certain version of a package or why BitBake picked a certain | ||
| 9630 | provider. This command could also help you in a situation where you | ||
| 9631 | think BitBake did something unexpected. | ||
| 9632 | |||
| 9633 | Building with No Dependencies | ||
| 9634 | ----------------------------- | ||
| 9635 | |||
| 9636 | To build a specific recipe (``.bb`` file), you can use the following | ||
| 9637 | command form: | ||
| 9638 | :: | ||
| 9639 | |||
| 9640 | $ bitbake -b somepath/somerecipe.bb | ||
| 9641 | |||
| 9642 | This command form does | ||
| 9643 | not check for dependencies. Consequently, you should use it only when | ||
| 9644 | you know existing dependencies have been met. | ||
| 9645 | |||
| 9646 | .. note:: | ||
| 9647 | |||
| 9648 | You can also specify fragments of the filename. In this case, BitBake | ||
| 9649 | checks for a unique match. | ||
| 9650 | |||
| 9651 | Recipe Logging Mechanisms | ||
| 9652 | ------------------------- | ||
| 9653 | |||
| 9654 | The Yocto Project provides several logging functions for producing | ||
| 9655 | debugging output and reporting errors and warnings. For Python | ||
| 9656 | functions, the following logging functions exist. All of these functions | ||
| 9657 | log to ``${T}/log.do_``\ `task`, and can also log to standard output | ||
| 9658 | (stdout) with the right settings: | ||
| 9659 | |||
| 9660 | - ``bb.plain(msg)``: Writes msg as is to the log while also | ||
| 9661 | logging to stdout. | ||
| 9662 | |||
| 9663 | - ``bb.note(msg)``: Writes "NOTE: msg" to the log. Also logs to | ||
| 9664 | stdout if BitBake is called with "-v". | ||
| 9665 | |||
| 9666 | - ``bb.debug(level, msg)``: Writes "DEBUG: msg" to the | ||
| 9667 | log. Also logs to stdout if the log level is greater than or equal to | ||
| 9668 | level. See the ":ref:`-D <bitbake:bitbake-user-manual/bitbake-user-manual-intro:usage and syntax>`" option | ||
| 9669 | in the BitBake User Manual for more information. | ||
| 9670 | |||
| 9671 | - ``bb.warn(msg)``: Writes "WARNING: msg" to the log while also | ||
| 9672 | logging to stdout. | ||
| 9673 | |||
| 9674 | - ``bb.error(msg)``: Writes "ERROR: msg" to the log while also | ||
| 9675 | logging to standard out (stdout). | ||
| 9676 | |||
| 9677 | .. note:: | ||
| 9678 | |||
| 9679 | Calling this function does not cause the task to fail. | ||
| 9680 | |||
| 9681 | - ``bb.fatal(``\ msg\ ``)``: This logging function is similar to | ||
| 9682 | ``bb.error(``\ msg\ ``)`` but also causes the calling task to fail. | ||
| 9683 | |||
| 9684 | .. note:: | ||
| 9685 | |||
| 9686 | ``bb.fatal()`` raises an exception, which means you do not need to put a | ||
| 9687 | "return" statement after the function. | ||
| 9688 | |||
| 9689 | The same logging functions are also available in shell functions, under | ||
| 9690 | the names ``bbplain``, ``bbnote``, ``bbdebug``, ``bbwarn``, ``bberror``, | ||
| 9691 | and ``bbfatal``. The | ||
| 9692 | :ref:`logging <ref-classes-logging>` class | ||
| 9693 | implements these functions. See that class in the ``meta/classes`` | ||
| 9694 | folder of the :term:`Source Directory` for information. | ||
| 9695 | |||
| 9696 | Logging With Python | ||
| 9697 | ~~~~~~~~~~~~~~~~~~~ | ||
| 9698 | |||
| 9699 | When creating recipes using Python and inserting code that handles build | ||
| 9700 | logs, keep in mind the goal is to have informative logs while keeping | ||
| 9701 | the console as "silent" as possible. Also, if you want status messages | ||
| 9702 | in the log, use the "debug" loglevel. | ||
| 9703 | |||
| 9704 | Following is an example written in Python. The code handles logging for | ||
| 9705 | a function that determines the number of tasks needed to be run. See the | ||
| 9706 | ":ref:`ref-tasks-listtasks`" | ||
| 9707 | section for additional information: | ||
| 9708 | :: | ||
| 9709 | |||
| 9710 | python do_listtasks() { | ||
| 9711 | bb.debug(2, "Starting to figure out the task list") | ||
| 9712 | if noteworthy_condition: | ||
| 9713 | bb.note("There are 47 tasks to run") | ||
| 9714 | bb.debug(2, "Got to point xyz") | ||
| 9715 | if warning_trigger: | ||
| 9716 | bb.warn("Detected warning_trigger, this might be a problem later.") | ||
| 9717 | if recoverable_error: | ||
| 9718 | bb.error("Hit recoverable_error, you really need to fix this!") | ||
| 9719 | if fatal_error: | ||
| 9720 | bb.fatal("fatal_error detected, unable to print the task list") | ||
| 9721 | bb.plain("The tasks present are abc") | ||
| 9722 | bb.debug(2, "Finished figuring out the tasklist") | ||
| 9723 | } | ||
| 9724 | |||
| 9725 | Logging With Bash | ||
| 9726 | ~~~~~~~~~~~~~~~~~ | ||
| 9727 | |||
| 9728 | When creating recipes using Bash and inserting code that handles build | ||
| 9729 | logs, you have the same goals - informative with minimal console output. | ||
| 9730 | The syntax you use for recipes written in Bash is similar to that of | ||
| 9731 | recipes written in Python described in the previous section. | ||
| 9732 | |||
| 9733 | Following is an example written in Bash. The code logs the progress of | ||
| 9734 | the ``do_my_function`` function. | ||
| 9735 | :: | ||
| 9736 | |||
| 9737 | do_my_function() { | ||
| 9738 | bbdebug 2 "Running do_my_function" | ||
| 9739 | if [ exceptional_condition ]; then | ||
| 9740 | bbnote "Hit exceptional_condition" | ||
| 9741 | fi | ||
| 9742 | bbdebug 2 "Got to point xyz" | ||
| 9743 | if [ warning_trigger ]; then | ||
| 9744 | bbwarn "Detected warning_trigger, this might cause a problem later." | ||
| 9745 | fi | ||
| 9746 | if [ recoverable_error ]; then | ||
| 9747 | bberror "Hit recoverable_error, correcting" | ||
| 9748 | fi | ||
| 9749 | if [ fatal_error ]; then | ||
| 9750 | bbfatal "fatal_error detected" | ||
| 9751 | fi | ||
| 9752 | bbdebug 2 "Completed do_my_function" | ||
| 9753 | } | ||
| 9754 | |||
| 9755 | |||
| 9756 | Debugging Parallel Make Races | ||
| 9757 | ----------------------------- | ||
| 9758 | |||
| 9759 | A parallel ``make`` race occurs when the build consists of several parts | ||
| 9760 | that are run simultaneously and a situation occurs when the output or | ||
| 9761 | result of one part is not ready for use with a different part of the | ||
| 9762 | build that depends on that output. Parallel make races are annoying and | ||
| 9763 | can sometimes be difficult to reproduce and fix. However, some simple | ||
| 9764 | tips and tricks exist that can help you debug and fix them. This section | ||
| 9765 | presents a real-world example of an error encountered on the Yocto | ||
| 9766 | Project autobuilder and the process used to fix it. | ||
| 9767 | |||
| 9768 | .. note:: | ||
| 9769 | |||
| 9770 | If you cannot properly fix a ``make`` race condition, you can work around it | ||
| 9771 | by clearing either the :term:`PARALLEL_MAKE` or :term:`PARALLEL_MAKEINST` | ||
| 9772 | variables. | ||
| 9773 | |||
| 9774 | The Failure | ||
| 9775 | ~~~~~~~~~~~ | ||
| 9776 | |||
| 9777 | For this example, assume that you are building an image that depends on | ||
| 9778 | the "neard" package. And, during the build, BitBake runs into problems | ||
| 9779 | and creates the following output. | ||
| 9780 | |||
| 9781 | .. note:: | ||
| 9782 | |||
| 9783 | This example log file has longer lines artificially broken to make | ||
| 9784 | the listing easier to read. | ||
| 9785 | |||
| 9786 | If you examine the output or the log file, you see the failure during | ||
| 9787 | ``make``: | ||
| 9788 | |||
| 9789 | .. code-block:: none | ||
| 9790 | |||
| 9791 | | DEBUG: SITE files ['endian-little', 'bit-32', 'ix86-common', 'common-linux', 'common-glibc', 'i586-linux', 'common'] | ||
| 9792 | | DEBUG: Executing shell function do_compile | ||
| 9793 | | NOTE: make -j 16 | ||
| 9794 | | make --no-print-directory all-am | ||
| 9795 | | /bin/mkdir -p include/near | ||
| 9796 | | /bin/mkdir -p include/near | ||
| 9797 | | /bin/mkdir -p include/near | ||
| 9798 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ | ||
| 9799 | 0.14-r0/neard-0.14/include/types.h include/near/types.h | ||
| 9800 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ | ||
| 9801 | 0.14-r0/neard-0.14/include/log.h include/near/log.h | ||
| 9802 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ | ||
| 9803 | 0.14-r0/neard-0.14/include/plugin.h include/near/plugin.h | ||
| 9804 | | /bin/mkdir -p include/near | ||
| 9805 | | /bin/mkdir -p include/near | ||
| 9806 | | /bin/mkdir -p include/near | ||
| 9807 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ | ||
| 9808 | 0.14-r0/neard-0.14/include/tag.h include/near/tag.h | ||
| 9809 | | /bin/mkdir -p include/near | ||
| 9810 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ | ||
| 9811 | 0.14-r0/neard-0.14/include/adapter.h include/near/adapter.h | ||
| 9812 | | /bin/mkdir -p include/near | ||
| 9813 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ | ||
| 9814 | 0.14-r0/neard-0.14/include/ndef.h include/near/ndef.h | ||
| 9815 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ | ||
| 9816 | 0.14-r0/neard-0.14/include/tlv.h include/near/tlv.h | ||
| 9817 | | /bin/mkdir -p include/near | ||
| 9818 | | /bin/mkdir -p include/near | ||
| 9819 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ | ||
| 9820 | 0.14-r0/neard-0.14/include/setting.h include/near/setting.h | ||
| 9821 | | /bin/mkdir -p include/near | ||
| 9822 | | /bin/mkdir -p include/near | ||
| 9823 | | /bin/mkdir -p include/near | ||
| 9824 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ | ||
| 9825 | 0.14-r0/neard-0.14/include/device.h include/near/device.h | ||
| 9826 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ | ||
| 9827 | 0.14-r0/neard-0.14/include/nfc_copy.h include/near/nfc_copy.h | ||
| 9828 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ | ||
| 9829 | 0.14-r0/neard-0.14/include/snep.h include/near/snep.h | ||
| 9830 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ | ||
| 9831 | 0.14-r0/neard-0.14/include/version.h include/near/version.h | ||
| 9832 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ | ||
| 9833 | 0.14-r0/neard-0.14/include/dbus.h include/near/dbus.h | ||
| 9834 | | ./src/genbuiltin nfctype1 nfctype2 nfctype3 nfctype4 p2p > src/builtin.h | ||
| 9835 | | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/ | ||
| 9836 | build/build/tmp/sysroots/qemux86 -DHAVE_CONFIG_H -I. -I./include -I./src -I./gdbus -I/home/pokybuild/ | ||
| 9837 | yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/glib-2.0 | ||
| 9838 | -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/ | ||
| 9839 | lib/glib-2.0/include -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/ | ||
| 9840 | tmp/sysroots/qemux86/usr/include/dbus-1.0 -I/home/pokybuild/yocto-autobuilder/yocto-slave/ | ||
| 9841 | nightly-x86/build/build/tmp/sysroots/qemux86/usr/lib/dbus-1.0/include -I/home/pokybuild/yocto-autobuilder/ | ||
| 9842 | yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/libnl3 | ||
| 9843 | -DNEAR_PLUGIN_BUILTIN -DPLUGINDIR=\""/usr/lib/near/plugins"\" | ||
| 9844 | -DCONFIGDIR=\""/etc/neard\"" -O2 -pipe -g -feliminate-unused-debug-types -c | ||
| 9845 | -o tools/snep-send.o tools/snep-send.c | ||
| 9846 | | In file included from tools/snep-send.c:16:0: | ||
| 9847 | | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory | ||
| 9848 | | #include <near/dbus.h> | ||
| 9849 | | ^ | ||
| 9850 | | compilation terminated. | ||
| 9851 | | make[1]: *** [tools/snep-send.o] Error 1 | ||
| 9852 | | make[1]: *** Waiting for unfinished jobs.... | ||
| 9853 | | make: *** [all] Error 2 | ||
| 9854 | | ERROR: oe_runmake failed | ||
| 9855 | |||
| 9856 | Reproducing the Error | ||
| 9857 | ~~~~~~~~~~~~~~~~~~~~~ | ||
| 9858 | |||
| 9859 | Because race conditions are intermittent, they do not manifest | ||
| 9860 | themselves every time you do the build. In fact, most times the build | ||
| 9861 | will complete without problems even though the potential race condition | ||
| 9862 | exists. Thus, once the error surfaces, you need a way to reproduce it. | ||
| 9863 | |||
| 9864 | In this example, compiling the "neard" package is causing the problem. | ||
| 9865 | So the first thing to do is build "neard" locally. Before you start the | ||
| 9866 | build, set the | ||
| 9867 | :term:`PARALLEL_MAKE` variable | ||
| 9868 | in your ``local.conf`` file to a high number (e.g. "-j 20"). Using a | ||
| 9869 | high value for ``PARALLEL_MAKE`` increases the chances of the race | ||
| 9870 | condition showing up: | ||
| 9871 | :: | ||
| 9872 | |||
| 9873 | $ bitbake neard | ||
| 9874 | |||
| 9875 | Once the local build for "neard" completes, start a ``devshell`` build: | ||
| 9876 | :: | ||
| 9877 | |||
| 9878 | $ bitbake neard -c devshell | ||
| 9879 | |||
| 9880 | For information on how to use a | ||
| 9881 | ``devshell``, see the "`Using a Development | ||
| 9882 | Shell <#platdev-appdev-devshell>`__" section. | ||
| 9883 | |||
| 9884 | In the ``devshell``, do the following: | ||
| 9885 | :: | ||
| 9886 | |||
| 9887 | $ make clean | ||
| 9888 | $ make tools/snep-send.o | ||
| 9889 | |||
| 9890 | The ``devshell`` commands cause the failure to clearly | ||
| 9891 | be visible. In this case, a missing dependency exists for the "neard" | ||
| 9892 | Makefile target. Here is some abbreviated, sample output with the | ||
| 9893 | missing dependency clearly visible at the end: | ||
| 9894 | :: | ||
| 9895 | |||
| 9896 | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/scott-lenovo/...... | ||
| 9897 | . | ||
| 9898 | . | ||
| 9899 | . | ||
| 9900 | tools/snep-send.c | ||
| 9901 | In file included from tools/snep-send.c:16:0: | ||
| 9902 | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory | ||
| 9903 | #include <near/dbus.h> | ||
| 9904 | ^ | ||
| 9905 | compilation terminated. | ||
| 9906 | make: *** [tools/snep-send.o] Error 1 | ||
| 9907 | $ | ||
| 9908 | |||
| 9909 | |||
| 9910 | Creating a Patch for the Fix | ||
| 9911 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 9912 | |||
| 9913 | Because there is a missing dependency for the Makefile target, you need | ||
| 9914 | to patch the ``Makefile.am`` file, which is generated from | ||
| 9915 | ``Makefile.in``. You can use Quilt to create the patch: | ||
| 9916 | :: | ||
| 9917 | |||
| 9918 | $ quilt new parallelmake.patch | ||
| 9919 | Patch patches/parallelmake.patch is now on top | ||
| 9920 | $ quilt add Makefile.am | ||
| 9921 | File Makefile.am added to patch patches/parallelmake.patch | ||
| 9922 | |||
| 9923 | For more information on using Quilt, see the | ||
| 9924 | "`Using Quilt in Your Workflow <#using-a-quilt-workflow>`__" section. | ||
| 9925 | |||
| 9926 | At this point you need to make the edits to ``Makefile.am`` to add the | ||
| 9927 | missing dependency. For our example, you have to add the following line | ||
| 9928 | to the file: | ||
| 9929 | :: | ||
| 9930 | |||
| 9931 | tools/snep-send.$(OBJEXT): include/near/dbus.h | ||
| 9932 | |||
| 9933 | Once you have edited the file, use the ``refresh`` command to create the | ||
| 9934 | patch: | ||
| 9935 | :: | ||
| 9936 | |||
| 9937 | $ quilt refresh | ||
| 9938 | Refreshed patch patches/parallelmake.patch | ||
| 9939 | |||
| 9940 | Once | ||
| 9941 | the patch file exists, you need to add it back to the originating recipe | ||
| 9942 | folder. Here is an example assuming a top-level | ||
| 9943 | :term:`Source Directory` named ``poky``: | ||
| 9944 | :: | ||
| 9945 | |||
| 9946 | $ cp patches/parallelmake.patch poky/meta/recipes-connectivity/neard/neard | ||
| 9947 | |||
| 9948 | The final thing you need to do to implement the fix in the build is to | ||
| 9949 | update the "neard" recipe (i.e. ``neard-0.14.bb``) so that the | ||
| 9950 | :term:`SRC_URI` statement includes | ||
| 9951 | the patch file. The recipe file is in the folder above the patch. Here | ||
| 9952 | is what the edited ``SRC_URI`` statement would look like: | ||
| 9953 | :: | ||
| 9954 | |||
| 9955 | SRC_URI = "${KERNELORG_MIRROR}/linux/network/nfc/${BPN}-${PV}.tar.xz \ | ||
| 9956 | file://neard.in \ | ||
| 9957 | file://neard.service.in \ | ||
| 9958 | file://parallelmake.patch \ | ||
| 9959 | " | ||
| 9960 | |||
| 9961 | With the patch complete and moved to the correct folder and the | ||
| 9962 | ``SRC_URI`` statement updated, you can exit the ``devshell``: | ||
| 9963 | :: | ||
| 9964 | |||
| 9965 | $ exit | ||
| 9966 | |||
| 9967 | Testing the Build | ||
| 9968 | ~~~~~~~~~~~~~~~~~ | ||
| 9969 | |||
| 9970 | With everything in place, you can get back to trying the build again | ||
| 9971 | locally: | ||
| 9972 | :: | ||
| 9973 | |||
| 9974 | $ bitbake neard | ||
| 9975 | |||
| 9976 | This build should succeed. | ||
| 9977 | |||
| 9978 | Now you can open up a ``devshell`` again and repeat the clean and make | ||
| 9979 | operations as follows: | ||
| 9980 | :: | ||
| 9981 | |||
| 9982 | $ bitbake neard -c devshell | ||
| 9983 | $ make clean | ||
| 9984 | $ make tools/snep-send.o | ||
| 9985 | |||
| 9986 | The build should work without issue. | ||
| 9987 | |||
| 9988 | As with all solved problems, if they originated upstream, you need to | ||
| 9989 | submit the fix for the recipe in OE-Core and upstream so that the | ||
| 9990 | problem is taken care of at its source. See the "`Submitting a Change to | ||
| 9991 | the Yocto Project <#how-to-submit-a-change>`__" section for more | ||
| 9992 | information. | ||
| 9993 | |||
| 9994 | Debugging With the GNU Project Debugger (GDB) Remotely | ||
| 9995 | ------------------------------------------------------ | ||
| 9996 | |||
| 9997 | GDB allows you to examine running programs, which in turn helps you to | ||
| 9998 | understand and fix problems. It also allows you to perform post-mortem | ||
| 9999 | style analysis of program crashes. GDB is available as a package within | ||
| 10000 | the Yocto Project and is installed in SDK images by default. See the | ||
| 10001 | ":ref:`ref-manual/ref-images:Images`" chapter in the Yocto | ||
| 10002 | Project Reference Manual for a description of these images. You can find | ||
| 10003 | information on GDB at https://sourceware.org/gdb/. | ||
| 10004 | |||
| 10005 | .. note:: | ||
| 10006 | |||
| 10007 | For best results, install debug (``-dbg``) packages for the applications you | ||
| 10008 | are going to debug. Doing so makes extra debug symbols available that give | ||
| 10009 | you more meaningful output. | ||
| 10010 | |||
| 10011 | Sometimes, due to memory or disk space constraints, it is not possible | ||
| 10012 | to use GDB directly on the remote target to debug applications. These | ||
| 10013 | constraints arise because GDB needs to load the debugging information | ||
| 10014 | and the binaries of the process being debugged. Additionally, GDB needs | ||
| 10015 | to perform many computations to locate information such as function | ||
| 10016 | names, variable names and values, stack traces and so forth - even | ||
| 10017 | before starting the debugging process. These extra computations place | ||
| 10018 | more load on the target system and can alter the characteristics of the | ||
| 10019 | program being debugged. | ||
| 10020 | |||
| 10021 | To help get past the previously mentioned constraints, you can use | ||
| 10022 | gdbserver, which runs on the remote target and does not load any | ||
| 10023 | debugging information from the debugged process. Instead, a GDB instance | ||
| 10024 | processes the debugging information that is run on a remote computer - | ||
| 10025 | the host GDB. The host GDB then sends control commands to gdbserver to | ||
| 10026 | make it stop or start the debugged program, as well as read or write | ||
| 10027 | memory regions of that debugged program. All the debugging information | ||
| 10028 | loaded and processed as well as all the heavy debugging is done by the | ||
| 10029 | host GDB. Offloading these processes gives the gdbserver running on the | ||
| 10030 | target a chance to remain small and fast. | ||
| 10031 | |||
| 10032 | Because the host GDB is responsible for loading the debugging | ||
| 10033 | information and for doing the necessary processing to make actual | ||
| 10034 | debugging happen, you have to make sure the host can access the | ||
| 10035 | unstripped binaries complete with their debugging information and also | ||
| 10036 | be sure the target is compiled with no optimizations. The host GDB must | ||
| 10037 | also have local access to all the libraries used by the debugged | ||
| 10038 | program. Because gdbserver does not need any local debugging | ||
| 10039 | information, the binaries on the remote target can remain stripped. | ||
| 10040 | However, the binaries must also be compiled without optimization so they | ||
| 10041 | match the host's binaries. | ||
| 10042 | |||
| 10043 | To remain consistent with GDB documentation and terminology, the binary | ||
| 10044 | being debugged on the remote target machine is referred to as the | ||
| 10045 | "inferior" binary. For documentation on GDB see the `GDB | ||
| 10046 | site <https://sourceware.org/gdb/documentation/>`__. | ||
| 10047 | |||
| 10048 | The following steps show you how to debug using the GNU project | ||
| 10049 | debugger. | ||
| 10050 | |||
| 10051 | 1. *Configure your build system to construct the companion debug | ||
| 10052 | filesystem:* | ||
| 10053 | |||
| 10054 | In your ``local.conf`` file, set the following: | ||
| 10055 | :: | ||
| 10056 | |||
| 10057 | IMAGE_GEN_DEBUGFS = "1" | ||
| 10058 | IMAGE_FSTYPES_DEBUGFS = "tar.bz2" | ||
| 10059 | |||
| 10060 | These options cause the | ||
| 10061 | OpenEmbedded build system to generate a special companion filesystem | ||
| 10062 | fragment, which contains the matching source and debug symbols to | ||
| 10063 | your deployable filesystem. The build system does this by looking at | ||
| 10064 | what is in the deployed filesystem, and pulling the corresponding | ||
| 10065 | ``-dbg`` packages. | ||
| 10066 | |||
| 10067 | The companion debug filesystem is not a complete filesystem, but only | ||
| 10068 | contains the debug fragments. This filesystem must be combined with | ||
| 10069 | the full filesystem for debugging. Subsequent steps in this procedure | ||
| 10070 | show how to combine the partial filesystem with the full filesystem. | ||
| 10071 | |||
| 10072 | 2. *Configure the system to include gdbserver in the target filesystem:* | ||
| 10073 | |||
| 10074 | Make the following addition in either your ``local.conf`` file or in | ||
| 10075 | an image recipe: | ||
| 10076 | :: | ||
| 10077 | |||
| 10078 | IMAGE_INSTALL_append = " gdbserver" | ||
| 10079 | |||
| 10080 | The change makes | ||
| 10081 | sure the ``gdbserver`` package is included. | ||
| 10082 | |||
| 10083 | 3. *Build the environment:* | ||
| 10084 | |||
| 10085 | Use the following command to construct the image and the companion | ||
| 10086 | Debug Filesystem: | ||
| 10087 | :: | ||
| 10088 | |||
| 10089 | $ bitbake image | ||
| 10090 | |||
| 10091 | Build the cross GDB component and | ||
| 10092 | make it available for debugging. Build the SDK that matches the | ||
| 10093 | image. Building the SDK is best for a production build that can be | ||
| 10094 | used later for debugging, especially during long term maintenance: | ||
| 10095 | :: | ||
| 10096 | |||
| 10097 | $ bitbake -c populate_sdk image | ||
| 10098 | |||
| 10099 | Alternatively, you can build the minimal toolchain components that | ||
| 10100 | match the target. Doing so creates a smaller than typical SDK and | ||
| 10101 | only contains a minimal set of components with which to build simple | ||
| 10102 | test applications, as well as run the debugger: | ||
| 10103 | :: | ||
| 10104 | |||
| 10105 | $ bitbake meta-toolchain | ||
| 10106 | |||
| 10107 | A final method is to build Gdb itself within the build system: | ||
| 10108 | :: | ||
| 10109 | |||
| 10110 | $ bitbake gdb-cross-<architecture> | ||
| 10111 | |||
| 10112 | Doing so produces a temporary copy of | ||
| 10113 | ``cross-gdb`` you can use for debugging during development. While | ||
| 10114 | this is the quickest approach, the two previous methods in this step | ||
| 10115 | are better when considering long-term maintenance strategies. | ||
| 10116 | |||
| 10117 | .. note:: | ||
| 10118 | |||
| 10119 | If you run ``bitbake gdb-cross``, the OpenEmbedded build system suggests | ||
| 10120 | the actual image (e.g. ``gdb-cross-i586``). The suggestion is usually the | ||
| 10121 | actual name you want to use. | ||
| 10122 | |||
| 10123 | 4. *Set up the* ``debugfs``\ *:* | ||
| 10124 | |||
| 10125 | Run the following commands to set up the ``debugfs``: | ||
| 10126 | :: | ||
| 10127 | |||
| 10128 | $ mkdir debugfs | ||
| 10129 | $ cd debugfs | ||
| 10130 | $ tar xvfj build-dir/tmp-glibc/deploy/images/machine/image.rootfs.tar.bz2 | ||
| 10131 | $ tar xvfj build-dir/tmp-glibc/deploy/images/machine/image-dbg.rootfs.tar.bz2 | ||
| 10132 | |||
| 10133 | 5. *Set up GDB:* | ||
| 10134 | |||
| 10135 | Install the SDK (if you built one) and then source the correct | ||
| 10136 | environment file. Sourcing the environment file puts the SDK in your | ||
| 10137 | ``PATH`` environment variable. | ||
| 10138 | |||
| 10139 | If you are using the build system, Gdb is located in | ||
| 10140 | `build-dir`\ ``/tmp/sysroots/``\ `host`\ ``/usr/bin/``\ `architecture`\ ``/``\ `architecture`\ ``-gdb`` | ||
| 10141 | |||
| 10142 | 6. *Boot the target:* | ||
| 10143 | |||
| 10144 | For information on how to run QEMU, see the `QEMU | ||
| 10145 | Documentation <https://wiki.qemu.org/Documentation/GettingStartedDevelopers>`__. | ||
| 10146 | |||
| 10147 | .. note:: | ||
| 10148 | |||
| 10149 | Be sure to verify that your host can access the target via TCP. | ||
| 10150 | |||
| 10151 | 7. *Debug a program:* | ||
| 10152 | |||
| 10153 | Debugging a program involves running gdbserver on the target and then | ||
| 10154 | running Gdb on the host. The example in this step debugs ``gzip``: | ||
| 10155 | |||
| 10156 | .. code-block:: shell | ||
| 10157 | |||
| 10158 | root@qemux86:~# gdbserver localhost:1234 /bin/gzip —help | ||
| 10159 | |||
| 10160 | For | ||
| 10161 | additional gdbserver options, see the `GDB Server | ||
| 10162 | Documentation <https://www.gnu.org/software/gdb/documentation/>`__. | ||
| 10163 | |||
| 10164 | After running gdbserver on the target, you need to run Gdb on the | ||
| 10165 | host and configure it and connect to the target. Use these commands: | ||
| 10166 | :: | ||
| 10167 | |||
| 10168 | $ cd directory-holding-the-debugfs-directory | ||
| 10169 | $ arch-gdb | ||
| 10170 | (gdb) set sysroot debugfs | ||
| 10171 | (gdb) set substitute-path /usr/src/debug debugfs/usr/src/debug | ||
| 10172 | (gdb) target remote IP-of-target:1234 | ||
| 10173 | |||
| 10174 | At this | ||
| 10175 | point, everything should automatically load (i.e. matching binaries, | ||
| 10176 | symbols and headers). | ||
| 10177 | |||
| 10178 | .. note:: | ||
| 10179 | |||
| 10180 | The Gdb ``set`` commands in the previous example can be placed into the | ||
| 10181 | users ``~/.gdbinit`` file. Upon starting, Gdb automatically runs whatever | ||
| 10182 | commands are in that file. | ||
| 10183 | |||
| 10184 | 8. *Deploying without a full image rebuild:* | ||
| 10185 | |||
| 10186 | In many cases, during development you want a quick method to deploy a | ||
| 10187 | new binary to the target and debug it, without waiting for a full | ||
| 10188 | image build. | ||
| 10189 | |||
| 10190 | One approach to solving this situation is to just build the component | ||
| 10191 | you want to debug. Once you have built the component, copy the | ||
| 10192 | executable directly to both the target and the host ``debugfs``. | ||
| 10193 | |||
| 10194 | If the binary is processed through the debug splitting in | ||
| 10195 | OpenEmbedded, you should also copy the debug items (i.e. ``.debug`` | ||
| 10196 | contents and corresponding ``/usr/src/debug`` files) from the work | ||
| 10197 | directory. Here is an example: | ||
| 10198 | :: | ||
| 10199 | |||
| 10200 | $ bitbake bash | ||
| 10201 | $ bitbake -c devshell bash | ||
| 10202 | $ cd .. | ||
| 10203 | $ scp packages-split/bash/bin/bash target:/bin/bash | ||
| 10204 | $ cp -a packages-split/bash-dbg/\* path/debugfs | ||
| 10205 | |||
| 10206 | Debugging with the GNU Project Debugger (GDB) on the Target | ||
| 10207 | ----------------------------------------------------------- | ||
| 10208 | |||
| 10209 | The previous section addressed using GDB remotely for debugging | ||
| 10210 | purposes, which is the most usual case due to the inherent hardware | ||
| 10211 | limitations on many embedded devices. However, debugging in the target | ||
| 10212 | hardware itself is also possible with more powerful devices. This | ||
| 10213 | section describes what you need to do in order to support using GDB to | ||
| 10214 | debug on the target hardware. | ||
| 10215 | |||
| 10216 | To support this kind of debugging, you need do the following: | ||
| 10217 | |||
| 10218 | - Ensure that GDB is on the target. You can do this by adding "gdb" to | ||
| 10219 | :term:`IMAGE_INSTALL`: | ||
| 10220 | :: | ||
| 10221 | |||
| 10222 | IMAGE_INSTALL_append = " gdb" | ||
| 10223 | |||
| 10224 | Alternatively, you can add "tools-debug" to :term:`IMAGE_FEATURES`: | ||
| 10225 | :: | ||
| 10226 | |||
| 10227 | IMAGE_FEATURES_append = " tools-debug" | ||
| 10228 | |||
| 10229 | - Ensure that debug symbols are present. You can make sure these | ||
| 10230 | symbols are present by installing ``-dbg``: | ||
| 10231 | :: | ||
| 10232 | |||
| 10233 | IMAGE_INSTALL_append = "packagename-dbg" | ||
| 10234 | |||
| 10235 | Alternatively, you can do the following to include | ||
| 10236 | all the debug symbols: | ||
| 10237 | :: | ||
| 10238 | |||
| 10239 | IMAGE_FEATURES_append = " dbg-pkgs" | ||
| 10240 | |||
| 10241 | .. note:: | ||
| 10242 | |||
| 10243 | To improve the debug information accuracy, you can reduce the level | ||
| 10244 | of optimization used by the compiler. For example, when adding the | ||
| 10245 | following line to your ``local.conf`` file, you will reduce optimization | ||
| 10246 | from :term:`FULL_OPTIMIZATION` of "-O2" to :term:`DEBUG_OPTIMIZATION` | ||
| 10247 | of "-O -fno-omit-frame-pointer": | ||
| 10248 | :: | ||
| 10249 | |||
| 10250 | DEBUG_BUILD = "1" | ||
| 10251 | |||
| 10252 | Consider that this will reduce the application's performance and is | ||
| 10253 | recommended only for debugging purposes. | ||
| 10254 | |||
| 10255 | Other Debugging Tips | ||
| 10256 | -------------------- | ||
| 10257 | |||
| 10258 | Here are some other tips that you might find useful: | ||
| 10259 | |||
| 10260 | - When adding new packages, it is worth watching for undesirable items | ||
| 10261 | making their way into compiler command lines. For example, you do not | ||
| 10262 | want references to local system files like ``/usr/lib/`` or | ||
| 10263 | ``/usr/include/``. | ||
| 10264 | |||
| 10265 | - If you want to remove the ``psplash`` boot splashscreen, add | ||
| 10266 | ``psplash=false`` to the kernel command line. Doing so prevents | ||
| 10267 | ``psplash`` from loading and thus allows you to see the console. It | ||
| 10268 | is also possible to switch out of the splashscreen by switching the | ||
| 10269 | virtual console (e.g. Fn+Left or Fn+Right on a Zaurus). | ||
| 10270 | |||
| 10271 | - Removing :term:`TMPDIR` (usually | ||
| 10272 | ``tmp/``, within the | ||
| 10273 | :term:`Build Directory`) can often fix | ||
| 10274 | temporary build issues. Removing ``TMPDIR`` is usually a relatively | ||
| 10275 | cheap operation, because task output will be cached in | ||
| 10276 | :term:`SSTATE_DIR` (usually | ||
| 10277 | ``sstate-cache/``, which is also in the Build Directory). | ||
| 10278 | |||
| 10279 | .. note:: | ||
| 10280 | |||
| 10281 | Removing ``TMPDIR`` might be a workaround rather than a fix. | ||
| 10282 | Consequently, trying to determine the underlying cause of an issue before | ||
| 10283 | removing the directory is a good idea. | ||
| 10284 | |||
| 10285 | - Understanding how a feature is used in practice within existing | ||
| 10286 | recipes can be very helpful. It is recommended that you configure | ||
| 10287 | some method that allows you to quickly search through files. | ||
| 10288 | |||
| 10289 | Using GNU Grep, you can use the following shell function to | ||
| 10290 | recursively search through common recipe-related files, skipping | ||
| 10291 | binary files, ``.git`` directories, and the Build Directory (assuming | ||
| 10292 | its name starts with "build"): | ||
| 10293 | :: | ||
| 10294 | |||
| 10295 | g() { | ||
| 10296 | grep -Ir \ | ||
| 10297 | --exclude-dir=.git \ | ||
| 10298 | --exclude-dir='build*' \ | ||
| 10299 | --include='*.bb*' \ | ||
| 10300 | --include='*.inc*' \ | ||
| 10301 | --include='*.conf*' \ | ||
| 10302 | --include='*.py*' \ | ||
| 10303 | "$@" | ||
| 10304 | } | ||
| 10305 | |||
| 10306 | Following are some usage examples: | ||
| 10307 | :: | ||
| 10308 | |||
| 10309 | $ g FOO # Search recursively for "FOO" | ||
| 10310 | $ g -i foo # Search recursively for "foo", ignoring case | ||
| 10311 | $ g -w FOO # Search recursively for "FOO" as a word, ignoring e.g. "FOOBAR" | ||
| 10312 | |||
| 10313 | If figuring | ||
| 10314 | out how some feature works requires a lot of searching, it might | ||
| 10315 | indicate that the documentation should be extended or improved. In | ||
| 10316 | such cases, consider filing a documentation bug using the Yocto | ||
| 10317 | Project implementation of | ||
| 10318 | :yocto_bugs:`Bugzilla <>`. For information on | ||
| 10319 | how to submit a bug against the Yocto Project, see the Yocto Project | ||
| 10320 | Bugzilla :yocto_wiki:`wiki page </Bugzilla_Configuration_and_Bug_Tracking>` | ||
| 10321 | and the "`Submitting a Defect Against the Yocto | ||
| 10322 | Project <#submitting-a-defect-against-the-yocto-project>`__" section. | ||
| 10323 | |||
| 10324 | .. note:: | ||
| 10325 | |||
| 10326 | The manuals might not be the right place to document variables | ||
| 10327 | that are purely internal and have a limited scope (e.g. internal | ||
| 10328 | variables used to implement a single ``.bbclass`` file). | ||
| 10329 | |||
| 10330 | Making Changes to the Yocto Project | ||
| 10331 | =================================== | ||
| 10332 | |||
| 10333 | Because the Yocto Project is an open-source, community-based project, | ||
| 10334 | you can effect changes to the project. This section presents procedures | ||
| 10335 | that show you how to submit a defect against the project and how to | ||
| 10336 | submit a change. | ||
| 10337 | |||
| 10338 | Submitting a Defect Against the Yocto Project | ||
| 10339 | --------------------------------------------- | ||
| 10340 | |||
| 10341 | Use the Yocto Project implementation of | ||
| 10342 | `Bugzilla <https://www.bugzilla.org/about/>`__ to submit a defect (bug) | ||
| 10343 | against the Yocto Project. For additional information on this | ||
| 10344 | implementation of Bugzilla see the ":ref:`Yocto Project | ||
| 10345 | Bugzilla <resources-bugtracker>`" section in the | ||
| 10346 | Yocto Project Reference Manual. For more detail on any of the following | ||
| 10347 | steps, see the Yocto Project | ||
| 10348 | :yocto_wiki:`Bugzilla wiki page </Bugzilla_Configuration_and_Bug_Tracking>`. | ||
| 10349 | |||
| 10350 | Use the following general steps to submit a bug: | ||
| 10351 | |||
| 10352 | 1. Open the Yocto Project implementation of :yocto_bugs:`Bugzilla <>`. | ||
| 10353 | |||
| 10354 | 2. Click "File a Bug" to enter a new bug. | ||
| 10355 | |||
| 10356 | 3. Choose the appropriate "Classification", "Product", and "Component" | ||
| 10357 | for which the bug was found. Bugs for the Yocto Project fall into | ||
| 10358 | one of several classifications, which in turn break down into | ||
| 10359 | several products and components. For example, for a bug against the | ||
| 10360 | ``meta-intel`` layer, you would choose "Build System, Metadata & | ||
| 10361 | Runtime", "BSPs", and "bsps-meta-intel", respectively. | ||
| 10362 | |||
| 10363 | 4. Choose the "Version" of the Yocto Project for which you found the | ||
| 10364 | bug (e.g. &DISTRO;). | ||
| 10365 | |||
| 10366 | 5. Determine and select the "Severity" of the bug. The severity | ||
| 10367 | indicates how the bug impacted your work. | ||
| 10368 | |||
| 10369 | 6. Choose the "Hardware" that the bug impacts. | ||
| 10370 | |||
| 10371 | 7. Choose the "Architecture" that the bug impacts. | ||
| 10372 | |||
| 10373 | 8. Choose a "Documentation change" item for the bug. Fixing a bug might | ||
| 10374 | or might not affect the Yocto Project documentation. If you are | ||
| 10375 | unsure of the impact to the documentation, select "Don't Know". | ||
| 10376 | |||
| 10377 | 9. Provide a brief "Summary" of the bug. Try to limit your summary to | ||
| 10378 | just a line or two and be sure to capture the essence of the bug. | ||
| 10379 | |||
| 10380 | 10. Provide a detailed "Description" of the bug. You should provide as | ||
| 10381 | much detail as you can about the context, behavior, output, and so | ||
| 10382 | forth that surrounds the bug. You can even attach supporting files | ||
| 10383 | for output from logs by using the "Add an attachment" button. | ||
| 10384 | |||
| 10385 | 11. Click the "Submit Bug" button submit the bug. A new Bugzilla number | ||
| 10386 | is assigned to the bug and the defect is logged in the bug tracking | ||
| 10387 | system. | ||
| 10388 | |||
| 10389 | Once you file a bug, the bug is processed by the Yocto Project Bug | ||
| 10390 | Triage Team and further details concerning the bug are assigned (e.g. | ||
| 10391 | priority and owner). You are the "Submitter" of the bug and any further | ||
| 10392 | categorization, progress, or comments on the bug result in Bugzilla | ||
| 10393 | sending you an automated email concerning the particular change or | ||
| 10394 | progress to the bug. | ||
| 10395 | |||
| 10396 | Submitting a Change to the Yocto Project | ||
| 10397 | ---------------------------------------- | ||
| 10398 | |||
| 10399 | Contributions to the Yocto Project and OpenEmbedded are very welcome. | ||
| 10400 | Because the system is extremely configurable and flexible, we recognize | ||
| 10401 | that developers will want to extend, configure or optimize it for their | ||
| 10402 | specific uses. | ||
| 10403 | |||
| 10404 | The Yocto Project uses a mailing list and a patch-based workflow that is | ||
| 10405 | similar to the Linux kernel but contains important differences. In | ||
| 10406 | general, a mailing list exists through which you can submit patches. You | ||
| 10407 | should send patches to the appropriate mailing list so that they can be | ||
| 10408 | reviewed and merged by the appropriate maintainer. The specific mailing | ||
| 10409 | list you need to use depends on the location of the code you are | ||
| 10410 | changing. Each component (e.g. layer) should have a ``README`` file that | ||
| 10411 | indicates where to send the changes and which process to follow. | ||
| 10412 | |||
| 10413 | You can send the patch to the mailing list using whichever approach you | ||
| 10414 | feel comfortable with to generate the patch. Once sent, the patch is | ||
| 10415 | usually reviewed by the community at large. If somebody has concerns | ||
| 10416 | with the patch, they will usually voice their concern over the mailing | ||
| 10417 | list. If a patch does not receive any negative reviews, the maintainer | ||
| 10418 | of the affected layer typically takes the patch, tests it, and then | ||
| 10419 | based on successful testing, merges the patch. | ||
| 10420 | |||
| 10421 | The "poky" repository, which is the Yocto Project's reference build | ||
| 10422 | environment, is a hybrid repository that contains several individual | ||
| 10423 | pieces (e.g. BitBake, Metadata, documentation, and so forth) built using | ||
| 10424 | the combo-layer tool. The upstream location used for submitting changes | ||
| 10425 | varies by component: | ||
| 10426 | |||
| 10427 | - *Core Metadata:* Send your patch to the | ||
| 10428 | :oe_lists:`openembedded-core </g/openembedded-core>` | ||
| 10429 | mailing list. For example, a change to anything under the ``meta`` or | ||
| 10430 | ``scripts`` directories should be sent to this mailing list. | ||
| 10431 | |||
| 10432 | - *BitBake:* For changes to BitBake (i.e. anything under the | ||
| 10433 | ``bitbake`` directory), send your patch to the | ||
| 10434 | :oe_lists:`bitbake-devel </g/bitbake-devel>` | ||
| 10435 | mailing list. | ||
| 10436 | |||
| 10437 | - *"meta-\*" trees:* These trees contain Metadata. Use the | ||
| 10438 | :yocto_lists:`poky </g/poky>` mailing list. | ||
| 10439 | |||
| 10440 | - *Documentation*: For changes to the Yocto Project documentation, use the | ||
| 10441 | :yocto_lists:`docs </g/docs>` mailing list. | ||
| 10442 | |||
| 10443 | For changes to other layers hosted in the Yocto Project source | ||
| 10444 | repositories (i.e. ``yoctoproject.org``) and tools use the | ||
| 10445 | :yocto_lists:`Yocto Project </g/yocto/>` general mailing list. | ||
| 10446 | |||
| 10447 | .. note:: | ||
| 10448 | |||
| 10449 | Sometimes a layer's documentation specifies to use a particular | ||
| 10450 | mailing list. If so, use that list. | ||
| 10451 | |||
| 10452 | For additional recipes that do not fit into the core Metadata, you | ||
| 10453 | should determine which layer the recipe should go into and submit the | ||
| 10454 | change in the manner recommended by the documentation (e.g. the | ||
| 10455 | ``README`` file) supplied with the layer. If in doubt, please ask on the | ||
| 10456 | Yocto general mailing list or on the openembedded-devel mailing list. | ||
| 10457 | |||
| 10458 | You can also push a change upstream and request a maintainer to pull the | ||
| 10459 | change into the component's upstream repository. You do this by pushing | ||
| 10460 | to a contribution repository that is upstream. See the | ||
| 10461 | ":ref:`overview-manual/overview-manual-development-environment:git workflows and the yocto project`" | ||
| 10462 | section in the Yocto Project Overview and Concepts Manual for additional | ||
| 10463 | concepts on working in the Yocto Project development environment. | ||
| 10464 | |||
| 10465 | Maintainers commonly use ``-next`` branches to test submissions prior to | ||
| 10466 | merging patches. Thus, you can get an idea of the status of a patch based on | ||
| 10467 | whether the patch has been merged into one of these branches. The commonly | ||
| 10468 | used testing branches for OpenEmbedded-Core are as follows: | ||
| 10469 | |||
| 10470 | - *openembedded-core "master-next" branch:* This branch is part of the | ||
| 10471 | :oe_git:`openembedded-core </openembedded-core/>` repository and contains | ||
| 10472 | proposed changes to the core metadata. | ||
| 10473 | |||
| 10474 | - *poky "master-next" branch:* This branch is part of the | ||
| 10475 | :yocto_git:`poky </poky/>` repository and combines proposed | ||
| 10476 | changes to bitbake, the core metadata and the poky distro. | ||
| 10477 | |||
| 10478 | Similarly, stable branches maintained by the project may have corresponding | ||
| 10479 | ``-next`` branches which collect proposed changes. For example, | ||
| 10480 | ``&DISTRO_NAME_NO_CAP;-next`` and ``&DISTRO_NAME_NO_CAP_MINUS_ONE;-next`` | ||
| 10481 | branches in both the "openembdedded-core" and "poky" repositories. | ||
| 10482 | |||
| 10483 | Other layers may have similar testing branches but there is no formal | ||
| 10484 | requirement or standard for these so please check the documentation for the | ||
| 10485 | layers you are contributing to. | ||
| 10486 | |||
| 10487 | The following sections provide procedures for submitting a change. | ||
| 10488 | |||
| 10489 | Preparing Changes for Submission | ||
| 10490 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 10491 | |||
| 10492 | 1. *Make Your Changes Locally:* Make your changes in your local Git | ||
| 10493 | repository. You should make small, controlled, isolated changes. | ||
| 10494 | Keeping changes small and isolated aids review, makes | ||
| 10495 | merging/rebasing easier and keeps the change history clean should | ||
| 10496 | anyone need to refer to it in future. | ||
| 10497 | |||
| 10498 | 2. *Stage Your Changes:* Stage your changes by using the ``git add`` | ||
| 10499 | command on each file you changed. | ||
| 10500 | |||
| 10501 | 3. *Commit Your Changes:* Commit the change by using the ``git commit`` | ||
| 10502 | command. Make sure your commit information follows standards by | ||
| 10503 | following these accepted conventions: | ||
| 10504 | |||
| 10505 | - Be sure to include a "Signed-off-by:" line in the same style as | ||
| 10506 | required by the Linux kernel. Adding this line signifies that you, | ||
| 10507 | the submitter, have agreed to the Developer's Certificate of | ||
| 10508 | Origin 1.1 as follows: | ||
| 10509 | |||
| 10510 | .. code-block:: none | ||
| 10511 | |||
| 10512 | Developer's Certificate of Origin 1.1 | ||
| 10513 | |||
| 10514 | By making a contribution to this project, I certify that: | ||
| 10515 | |||
| 10516 | (a) The contribution was created in whole or in part by me and I | ||
| 10517 | have the right to submit it under the open source license | ||
| 10518 | indicated in the file; or | ||
| 10519 | |||
| 10520 | (b) The contribution is based upon previous work that, to the best | ||
| 10521 | of my knowledge, is covered under an appropriate open source | ||
| 10522 | license and I have the right under that license to submit that | ||
| 10523 | work with modifications, whether created in whole or in part | ||
| 10524 | by me, under the same open source license (unless I am | ||
| 10525 | permitted to submit under a different license), as indicated | ||
| 10526 | in the file; or | ||
| 10527 | |||
| 10528 | (c) The contribution was provided directly to me by some other | ||
| 10529 | person who certified (a), (b) or (c) and I have not modified | ||
| 10530 | it. | ||
| 10531 | |||
| 10532 | (d) I understand and agree that this project and the contribution | ||
| 10533 | are public and that a record of the contribution (including all | ||
| 10534 | personal information I submit with it, including my sign-off) is | ||
| 10535 | maintained indefinitely and may be redistributed consistent with | ||
| 10536 | this project or the open source license(s) involved. | ||
| 10537 | |||
| 10538 | - Provide a single-line summary of the change and, if more | ||
| 10539 | explanation is needed, provide more detail in the body of the | ||
| 10540 | commit. This summary is typically viewable in the "shortlist" of | ||
| 10541 | changes. Thus, providing something short and descriptive that | ||
| 10542 | gives the reader a summary of the change is useful when viewing a | ||
| 10543 | list of many commits. You should prefix this short description | ||
| 10544 | with the recipe name (if changing a recipe), or else with the | ||
| 10545 | short form path to the file being changed. | ||
| 10546 | |||
| 10547 | - For the body of the commit message, provide detailed information | ||
| 10548 | that describes what you changed, why you made the change, and the | ||
| 10549 | approach you used. It might also be helpful if you mention how you | ||
| 10550 | tested the change. Provide as much detail as you can in the body | ||
| 10551 | of the commit message. | ||
| 10552 | |||
| 10553 | .. note:: | ||
| 10554 | |||
| 10555 | You do not need to provide a more detailed explanation of a | ||
| 10556 | change if the change is minor to the point of the single line | ||
| 10557 | summary providing all the information. | ||
| 10558 | |||
| 10559 | - If the change addresses a specific bug or issue that is associated | ||
| 10560 | with a bug-tracking ID, include a reference to that ID in your | ||
| 10561 | detailed description. For example, the Yocto Project uses a | ||
| 10562 | specific convention for bug references - any commit that addresses | ||
| 10563 | a specific bug should use the following form for the detailed | ||
| 10564 | description. Be sure to use the actual bug-tracking ID from | ||
| 10565 | Bugzilla for bug-id: | ||
| 10566 | :: | ||
| 10567 | |||
| 10568 | Fixes [YOCTO #bug-id] | ||
| 10569 | |||
| 10570 | detailed description of change | ||
| 10571 | |||
| 10572 | Using Email to Submit a Patch | ||
| 10573 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 10574 | |||
| 10575 | Depending on the components changed, you need to submit the email to a | ||
| 10576 | specific mailing list. For some guidance on which mailing list to use, | ||
| 10577 | see the `list <#figuring-out-the-mailing-list-to-use>`__ at the | ||
| 10578 | beginning of this section. For a description of all the available | ||
| 10579 | mailing lists, see the ":ref:`Mailing Lists <resources-mailinglist>`" section in the | ||
| 10580 | Yocto Project Reference Manual. | ||
| 10581 | |||
| 10582 | Here is the general procedure on how to submit a patch through email | ||
| 10583 | without using the scripts once the steps in | ||
| 10584 | :ref:`dev-manual/common-tasks:preparing changes for submission` have been followed: | ||
| 10585 | |||
| 10586 | 1. *Format the Commit:* Format the commit into an email message. To | ||
| 10587 | format commits, use the ``git format-patch`` command. When you | ||
| 10588 | provide the command, you must include a revision list or a number of | ||
| 10589 | patches as part of the command. For example, either of these two | ||
| 10590 | commands takes your most recent single commit and formats it as an | ||
| 10591 | email message in the current directory: | ||
| 10592 | :: | ||
| 10593 | |||
| 10594 | $ git format-patch -1 | ||
| 10595 | |||
| 10596 | or :: | ||
| 10597 | |||
| 10598 | $ git format-patch HEAD~ | ||
| 10599 | |||
| 10600 | After the command is run, the current directory contains a numbered | ||
| 10601 | ``.patch`` file for the commit. | ||
| 10602 | |||
| 10603 | If you provide several commits as part of the command, the | ||
| 10604 | ``git format-patch`` command produces a series of numbered files in | ||
| 10605 | the current directory – one for each commit. If you have more than | ||
| 10606 | one patch, you should also use the ``--cover`` option with the | ||
| 10607 | command, which generates a cover letter as the first "patch" in the | ||
| 10608 | series. You can then edit the cover letter to provide a description | ||
| 10609 | for the series of patches. For information on the | ||
| 10610 | ``git format-patch`` command, see ``GIT_FORMAT_PATCH(1)`` displayed | ||
| 10611 | using the ``man git-format-patch`` command. | ||
| 10612 | |||
| 10613 | .. note:: | ||
| 10614 | |||
| 10615 | If you are or will be a frequent contributor to the Yocto Project | ||
| 10616 | or to OpenEmbedded, you might consider requesting a contrib area | ||
| 10617 | and the necessary associated rights. | ||
| 10618 | |||
| 10619 | 2. *Send the patches via email:* Send the patches to the recipients and | ||
| 10620 | relevant mailing lists by using the ``git send-email`` command. | ||
| 10621 | |||
| 10622 | .. note:: | ||
| 10623 | |||
| 10624 | In order to use ``git send-email``, you must have the proper Git packages | ||
| 10625 | installed on your host. | ||
| 10626 | For Ubuntu, Debian, and Fedora the package is ``git-email``. | ||
| 10627 | |||
| 10628 | The ``git send-email`` command sends email by using a local or remote | ||
| 10629 | Mail Transport Agent (MTA) such as ``msmtp``, ``sendmail``, or | ||
| 10630 | through a direct ``smtp`` configuration in your Git ``~/.gitconfig`` | ||
| 10631 | file. If you are submitting patches through email only, it is very | ||
| 10632 | important that you submit them without any whitespace or HTML | ||
| 10633 | formatting that either you or your mailer introduces. The maintainer | ||
| 10634 | that receives your patches needs to be able to save and apply them | ||
| 10635 | directly from your emails. A good way to verify that what you are | ||
| 10636 | sending will be applicable by the maintainer is to do a dry run and | ||
| 10637 | send them to yourself and then save and apply them as the maintainer | ||
| 10638 | would. | ||
| 10639 | |||
| 10640 | The ``git send-email`` command is the preferred method for sending | ||
| 10641 | your patches using email since there is no risk of compromising | ||
| 10642 | whitespace in the body of the message, which can occur when you use | ||
| 10643 | your own mail client. The command also has several options that let | ||
| 10644 | you specify recipients and perform further editing of the email | ||
| 10645 | message. For information on how to use the ``git send-email`` | ||
| 10646 | command, see ``GIT-SEND-EMAIL(1)`` displayed using the | ||
| 10647 | ``man git-send-email`` command. | ||
| 10648 | |||
| 10649 | The Yocto Project uses a `Patchwork instance <https://patchwork.openembedded.org/>`__ | ||
| 10650 | to track the status of patches submitted to the various mailing lists and to | ||
| 10651 | support automated patch testing. Each submitted patch is checked for common | ||
| 10652 | mistakes and deviations from the expected patch format and submitters are | ||
| 10653 | notified by patchtest if such mistakes are found. This process helps to | ||
| 10654 | reduce the burden of patch review on maintainers. | ||
| 10655 | |||
| 10656 | .. note:: | ||
| 10657 | |||
| 10658 | This system is imperfect and changes can sometimes get lost in the flow. | ||
| 10659 | Asking about the status of a patch or change is reasonable if the change | ||
| 10660 | has been idle for a while with no feedback. | ||
| 10661 | |||
| 10662 | Using Scripts to Push a Change Upstream and Request a Pull | ||
| 10663 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 10664 | |||
| 10665 | For larger patch series it is preferable to send a pull request which not | ||
| 10666 | only includes the patch but also a pointer to a branch that can be pulled | ||
| 10667 | from. This involves making a local branch for your changes, pushing this | ||
| 10668 | branch to an accessible repository and then using the ``create-pull-request`` | ||
| 10669 | and ``send-pull-request`` scripts from openembedded-core to create and send a | ||
| 10670 | patch series with a link to the branch for review. | ||
| 10671 | |||
| 10672 | Follow this procedure to push a change to an upstream "contrib" Git | ||
| 10673 | repository once the steps in :ref:`dev-manual/common-tasks:preparing changes for submission` have | ||
| 10674 | been followed: | ||
| 10675 | |||
| 10676 | .. note:: | ||
| 10677 | |||
| 10678 | You can find general Git information on how to push a change upstream | ||
| 10679 | in the | ||
| 10680 | `Git Community Book <https://git-scm.com/book/en/v2/Distributed-Git-Distributed-Workflows>`__. | ||
| 10681 | |||
| 10682 | 1. *Push Your Commits to a "Contrib" Upstream:* If you have arranged for | ||
| 10683 | permissions to push to an upstream contrib repository, push the | ||
| 10684 | change to that repository: | ||
| 10685 | :: | ||
| 10686 | |||
| 10687 | $ git push upstream_remote_repo local_branch_name | ||
| 10688 | |||
| 10689 | For example, suppose you have permissions to push | ||
| 10690 | into the upstream ``meta-intel-contrib`` repository and you are | ||
| 10691 | working in a local branch named `your_name`\ ``/README``. The following | ||
| 10692 | command pushes your local commits to the ``meta-intel-contrib`` | ||
| 10693 | upstream repository and puts the commit in a branch named | ||
| 10694 | `your_name`\ ``/README``: | ||
| 10695 | :: | ||
| 10696 | |||
| 10697 | $ git push meta-intel-contrib your_name/README | ||
| 10698 | |||
| 10699 | 2. *Determine Who to Notify:* Determine the maintainer or the mailing | ||
| 10700 | list that you need to notify for the change. | ||
| 10701 | |||
| 10702 | Before submitting any change, you need to be sure who the maintainer | ||
| 10703 | is or what mailing list that you need to notify. Use either these | ||
| 10704 | methods to find out: | ||
| 10705 | |||
| 10706 | - *Maintenance File:* Examine the ``maintainers.inc`` file, which is | ||
| 10707 | located in the :term:`Source Directory` at | ||
| 10708 | ``meta/conf/distro/include``, to see who is responsible for code. | ||
| 10709 | |||
| 10710 | - *Search by File:* Using :ref:`overview-manual/overview-manual-development-environment:git`, you can | ||
| 10711 | enter the following command to bring up a short list of all | ||
| 10712 | commits against a specific file: | ||
| 10713 | :: | ||
| 10714 | |||
| 10715 | git shortlog -- filename | ||
| 10716 | |||
| 10717 | Just provide the name of the file for which you are interested. The | ||
| 10718 | information returned is not ordered by history but does include a | ||
| 10719 | list of everyone who has committed grouped by name. From the list, | ||
| 10720 | you can see who is responsible for the bulk of the changes against | ||
| 10721 | the file. | ||
| 10722 | |||
| 10723 | - *Examine the List of Mailing Lists:* For a list of the Yocto | ||
| 10724 | Project and related mailing lists, see the ":ref:`Mailing | ||
| 10725 | lists <resources-mailinglist>`" section in | ||
| 10726 | the Yocto Project Reference Manual. | ||
| 10727 | |||
| 10728 | 3. *Make a Pull Request:* Notify the maintainer or the mailing list that | ||
| 10729 | you have pushed a change by making a pull request. | ||
| 10730 | |||
| 10731 | The Yocto Project provides two scripts that conveniently let you | ||
| 10732 | generate and send pull requests to the Yocto Project. These scripts | ||
| 10733 | are ``create-pull-request`` and ``send-pull-request``. You can find | ||
| 10734 | these scripts in the ``scripts`` directory within the | ||
| 10735 | :term:`Source Directory` (e.g. | ||
| 10736 | ``~/poky/scripts``). | ||
| 10737 | |||
| 10738 | Using these scripts correctly formats the requests without | ||
| 10739 | introducing any whitespace or HTML formatting. The maintainer that | ||
| 10740 | receives your patches either directly or through the mailing list | ||
| 10741 | needs to be able to save and apply them directly from your emails. | ||
| 10742 | Using these scripts is the preferred method for sending patches. | ||
| 10743 | |||
| 10744 | First, create the pull request. For example, the following command | ||
| 10745 | runs the script, specifies the upstream repository in the contrib | ||
| 10746 | directory into which you pushed the change, and provides a subject | ||
| 10747 | line in the created patch files: | ||
| 10748 | :: | ||
| 10749 | |||
| 10750 | $ ~/poky/scripts/create-pull-request -u meta-intel-contrib -s "Updated Manual Section Reference in README" | ||
| 10751 | |||
| 10752 | Running this script forms ``*.patch`` files in a folder named | ||
| 10753 | ``pull-``\ `PID` in the current directory. One of the patch files is a | ||
| 10754 | cover letter. | ||
| 10755 | |||
| 10756 | Before running the ``send-pull-request`` script, you must edit the | ||
| 10757 | cover letter patch to insert information about your change. After | ||
| 10758 | editing the cover letter, send the pull request. For example, the | ||
| 10759 | following command runs the script and specifies the patch directory | ||
| 10760 | and email address. In this example, the email address is a mailing | ||
| 10761 | list: | ||
| 10762 | :: | ||
| 10763 | |||
| 10764 | $ ~/poky/scripts/send-pull-request -p ~/meta-intel/pull-10565 -t meta-intel@yoctoproject.org | ||
| 10765 | |||
| 10766 | You need to follow the prompts as the script is interactive. | ||
| 10767 | |||
| 10768 | .. note:: | ||
| 10769 | |||
| 10770 | For help on using these scripts, simply provide the ``-h`` | ||
| 10771 | argument as follows: | ||
| 10772 | :: | ||
| 10773 | |||
| 10774 | $ poky/scripts/create-pull-request -h | ||
| 10775 | $ poky/scripts/send-pull-request -h | ||
| 10776 | |||
| 10777 | Responding to Patch Review | ||
| 10778 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 10779 | |||
| 10780 | You may get feedback on your submitted patches from other community members | ||
| 10781 | or from the automated patchtest service. If issues are identified in your | ||
| 10782 | patch then it is usually necessary to address these before the patch will be | ||
| 10783 | accepted into the project. In this case you should amend the patch according | ||
| 10784 | to the feedback and submit an updated version to the relevant mailing list, | ||
| 10785 | copying in the reviewers who provided feedback to the previous version of the | ||
| 10786 | patch. | ||
| 10787 | |||
| 10788 | The patch should be amended using ``git commit --amend`` or perhaps ``git | ||
| 10789 | rebase`` for more expert git users. You should also modify the ``[PATCH]`` | ||
| 10790 | tag in the email subject line when sending the revised patch to mark the new | ||
| 10791 | iteration as ``[PATCH v2]``, ``[PATCH v3]``, etc as appropriate. This can be | ||
| 10792 | done by passing the ``-v`` argument to ``git format-patch`` with a version | ||
| 10793 | number. | ||
| 10794 | |||
| 10795 | Lastly please ensure that you also test your revised changes. In particular | ||
| 10796 | please don't just edit the patch file written out by ``git format-patch`` and | ||
| 10797 | resend it. | ||
| 10798 | |||
| 10799 | Submitting Changes to Stable Release Branches | ||
| 10800 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 10801 | |||
| 10802 | The process for proposing changes to a Yocto Project stable branch differs | ||
| 10803 | from the steps described above. Changes to a stable branch must address | ||
| 10804 | identified bugs or CVEs and should be made carefully in order to avoid the | ||
| 10805 | risk of introducing new bugs or breaking backwards compatibility. Typically | ||
| 10806 | bug fixes must already be accepted into the master branch before they can be | ||
| 10807 | backported to a stable branch unless the bug in question does not affect the | ||
| 10808 | master branch or the fix on the master branch is unsuitable for backporting. | ||
| 10809 | |||
| 10810 | The list of stable branches along with the status and maintainer for each | ||
| 10811 | branch can be obtained from the | ||
| 10812 | :yocto_wiki:`Releases wiki page </Releases>`. | ||
| 10813 | |||
| 10814 | .. note:: | ||
| 10815 | |||
| 10816 | Changes will not typically be accepted for branches which are marked as | ||
| 10817 | End-Of-Life (EOL). | ||
| 10818 | |||
| 10819 | With this in mind, the steps to submit a change for a stable branch are as | ||
| 10820 | follows: | ||
| 10821 | |||
| 10822 | 1. *Identify the bug or CVE to be fixed:* This information should be | ||
| 10823 | collected so that it can be included in your submission. | ||
| 10824 | |||
| 10825 | 2. *Check if the fix is already present in the master branch:* This will | ||
| 10826 | result in the most straightforward path into the stable branch for the | ||
| 10827 | fix. | ||
| 10828 | |||
| 10829 | a. *If the fix is present in the master branch - Submit a backport request | ||
| 10830 | by email:* You should send an email to the relevant stable branch | ||
| 10831 | maintainer and the mailing list with details of the bug or CVE to be | ||
| 10832 | fixed, the commit hash on the master branch that fixes the issue and | ||
| 10833 | the stable branches which you would like this fix to be backported to. | ||
| 10834 | |||
| 10835 | b. *If the fix is not present in the master branch - Submit the fix to the | ||
| 10836 | master branch first:* This will ensure that the fix passes through the | ||
| 10837 | project's usual patch review and test processes before being accepted. | ||
| 10838 | It will also ensure that bugs are not left unresolved in the master | ||
| 10839 | branch itself. Once the fix is accepted in the master branch a backport | ||
| 10840 | request can be submitted as above. | ||
| 10841 | |||
| 10842 | c. *If the fix is unsuitable for the master branch - Submit a patch | ||
| 10843 | directly for the stable branch:* This method should be considered as a | ||
| 10844 | last resort. It is typically necessary when the master branch is using | ||
| 10845 | a newer version of the software which includes an upstream fix for the | ||
| 10846 | issue or when the issue has been fixed on the master branch in a way | ||
| 10847 | that introduces backwards incompatible changes. In this case follow the | ||
| 10848 | steps in :ref:`dev-manual/common-tasks:preparing changes for submission` and | ||
| 10849 | :ref:`dev-manual/common-tasks:using email to submit a patch` but modify the subject header of your patch | ||
| 10850 | email to include the name of the stable branch which you are | ||
| 10851 | targetting. This can be done using the ``--subject-prefix`` argument to | ||
| 10852 | ``git format-patch``, for example to submit a patch to the dunfell | ||
| 10853 | branch use | ||
| 10854 | ``git format-patch --subject-prefix='&DISTRO_NAME_NO_CAP_MINUS_ONE;][PATCH' ...``. | ||
| 10855 | |||
| 10856 | Working With Licenses | ||
| 10857 | ===================== | ||
| 10858 | |||
| 10859 | As mentioned in the ":ref:`overview-manual/overview-manual-development-environment:licensing`" | ||
| 10860 | section in the Yocto Project Overview and Concepts Manual, open source | ||
| 10861 | projects are open to the public and they consequently have different | ||
| 10862 | licensing structures in place. This section describes the mechanism by | ||
| 10863 | which the :term:`OpenEmbedded Build System` | ||
| 10864 | tracks changes to | ||
| 10865 | licensing text and covers how to maintain open source license compliance | ||
| 10866 | during your project's lifecycle. The section also describes how to | ||
| 10867 | enable commercially licensed recipes, which by default are disabled. | ||
| 10868 | |||
| 10869 | Tracking License Changes | ||
| 10870 | ------------------------ | ||
| 10871 | |||
| 10872 | The license of an upstream project might change in the future. In order | ||
| 10873 | to prevent these changes going unnoticed, the | ||
| 10874 | :term:`LIC_FILES_CHKSUM` | ||
| 10875 | variable tracks changes to the license text. The checksums are validated | ||
| 10876 | at the end of the configure step, and if the checksums do not match, the | ||
| 10877 | build will fail. | ||
| 10878 | |||
| 10879 | Specifying the ``LIC_FILES_CHKSUM`` Variable | ||
| 10880 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 10881 | |||
| 10882 | The ``LIC_FILES_CHKSUM`` variable contains checksums of the license text | ||
| 10883 | in the source code for the recipe. Following is an example of how to | ||
| 10884 | specify ``LIC_FILES_CHKSUM``: | ||
| 10885 | :: | ||
| 10886 | |||
| 10887 | LIC_FILES_CHKSUM = "file://COPYING;md5=xxxx \ | ||
| 10888 | file://licfile1.txt;beginline=5;endline=29;md5=yyyy \ | ||
| 10889 | file://licfile2.txt;endline=50;md5=zzzz \ | ||
| 10890 | ..." | ||
| 10891 | |||
| 10892 | .. note:: | ||
| 10893 | |||
| 10894 | - When using "beginline" and "endline", realize that line numbering | ||
| 10895 | begins with one and not zero. Also, the included lines are | ||
| 10896 | inclusive (i.e. lines five through and including 29 in the | ||
| 10897 | previous example for ``licfile1.txt``). | ||
| 10898 | |||
| 10899 | - When a license check fails, the selected license text is included | ||
| 10900 | as part of the QA message. Using this output, you can determine | ||
| 10901 | the exact start and finish for the needed license text. | ||
| 10902 | |||
| 10903 | The build system uses the :term:`S` | ||
| 10904 | variable as the default directory when searching files listed in | ||
| 10905 | ``LIC_FILES_CHKSUM``. The previous example employs the default | ||
| 10906 | directory. | ||
| 10907 | |||
| 10908 | Consider this next example: | ||
| 10909 | :: | ||
| 10910 | |||
| 10911 | LIC_FILES_CHKSUM = "file://src/ls.c;beginline=5;endline=16;\ | ||
| 10912 | md5=bb14ed3c4cda583abc85401304b5cd4e" | ||
| 10913 | LIC_FILES_CHKSUM = "file://${WORKDIR}/license.html;md5=5c94767cedb5d6987c902ac850ded2c6" | ||
| 10914 | |||
| 10915 | The first line locates a file in ``${S}/src/ls.c`` and isolates lines | ||
| 10916 | five through 16 as license text. The second line refers to a file in | ||
| 10917 | :term:`WORKDIR`. | ||
| 10918 | |||
| 10919 | Note that ``LIC_FILES_CHKSUM`` variable is mandatory for all recipes, | ||
| 10920 | unless the ``LICENSE`` variable is set to "CLOSED". | ||
| 10921 | |||
| 10922 | Explanation of Syntax | ||
| 10923 | ~~~~~~~~~~~~~~~~~~~~~ | ||
| 10924 | |||
| 10925 | As mentioned in the previous section, the ``LIC_FILES_CHKSUM`` variable | ||
| 10926 | lists all the important files that contain the license text for the | ||
| 10927 | source code. It is possible to specify a checksum for an entire file, or | ||
| 10928 | a specific section of a file (specified by beginning and ending line | ||
| 10929 | numbers with the "beginline" and "endline" parameters, respectively). | ||
| 10930 | The latter is useful for source files with a license notice header, | ||
| 10931 | README documents, and so forth. If you do not use the "beginline" | ||
| 10932 | parameter, then it is assumed that the text begins on the first line of | ||
| 10933 | the file. Similarly, if you do not use the "endline" parameter, it is | ||
| 10934 | assumed that the license text ends with the last line of the file. | ||
| 10935 | |||
| 10936 | The "md5" parameter stores the md5 checksum of the license text. If the | ||
| 10937 | license text changes in any way as compared to this parameter then a | ||
| 10938 | mismatch occurs. This mismatch triggers a build failure and notifies the | ||
| 10939 | developer. Notification allows the developer to review and address the | ||
| 10940 | license text changes. Also note that if a mismatch occurs during the | ||
| 10941 | build, the correct md5 checksum is placed in the build log and can be | ||
| 10942 | easily copied to the recipe. | ||
| 10943 | |||
| 10944 | There is no limit to how many files you can specify using the | ||
| 10945 | ``LIC_FILES_CHKSUM`` variable. Generally, however, every project | ||
| 10946 | requires a few specifications for license tracking. Many projects have a | ||
| 10947 | "COPYING" file that stores the license information for all the source | ||
| 10948 | code files. This practice allows you to just track the "COPYING" file as | ||
| 10949 | long as it is kept up to date. | ||
| 10950 | |||
| 10951 | .. note:: | ||
| 10952 | |||
| 10953 | - If you specify an empty or invalid "md5" parameter, | ||
| 10954 | :term:`BitBake` returns an md5 | ||
| 10955 | mis-match error and displays the correct "md5" parameter value | ||
| 10956 | during the build. The correct parameter is also captured in the | ||
| 10957 | build log. | ||
| 10958 | |||
| 10959 | - If the whole file contains only license text, you do not need to | ||
| 10960 | use the "beginline" and "endline" parameters. | ||
| 10961 | |||
| 10962 | Enabling Commercially Licensed Recipes | ||
| 10963 | -------------------------------------- | ||
| 10964 | |||
| 10965 | By default, the OpenEmbedded build system disables components that have | ||
| 10966 | commercial or other special licensing requirements. Such requirements | ||
| 10967 | are defined on a recipe-by-recipe basis through the | ||
| 10968 | :term:`LICENSE_FLAGS` variable | ||
| 10969 | definition in the affected recipe. For instance, the | ||
| 10970 | ``poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly`` recipe | ||
| 10971 | contains the following statement: | ||
| 10972 | :: | ||
| 10973 | |||
| 10974 | LICENSE_FLAGS = "commercial" | ||
| 10975 | |||
| 10976 | Here is a | ||
| 10977 | slightly more complicated example that contains both an explicit recipe | ||
| 10978 | name and version (after variable expansion): | ||
| 10979 | :: | ||
| 10980 | |||
| 10981 | LICENSE_FLAGS = "license_${PN}_${PV}" | ||
| 10982 | |||
| 10983 | In order for a component restricted by a | ||
| 10984 | ``LICENSE_FLAGS`` definition to be enabled and included in an image, it | ||
| 10985 | needs to have a matching entry in the global | ||
| 10986 | :term:`LICENSE_FLAGS_WHITELIST` | ||
| 10987 | variable, which is a variable typically defined in your ``local.conf`` | ||
| 10988 | file. For example, to enable the | ||
| 10989 | ``poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly`` package, you | ||
| 10990 | could add either the string "commercial_gst-plugins-ugly" or the more | ||
| 10991 | general string "commercial" to ``LICENSE_FLAGS_WHITELIST``. See the | ||
| 10992 | "`License Flag Matching <#license-flag-matching>`__" section for a full | ||
| 10993 | explanation of how ``LICENSE_FLAGS`` matching works. Here is the | ||
| 10994 | example: | ||
| 10995 | :: | ||
| 10996 | |||
| 10997 | LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly" | ||
| 10998 | |||
| 10999 | Likewise, to additionally enable the package built from the recipe | ||
| 11000 | containing ``LICENSE_FLAGS = "license_${PN}_${PV}"``, and assuming that | ||
| 11001 | the actual recipe name was ``emgd_1.10.bb``, the following string would | ||
| 11002 | enable that package as well as the original ``gst-plugins-ugly`` | ||
| 11003 | package: | ||
| 11004 | :: | ||
| 11005 | |||
| 11006 | LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly license_emgd_1.10" | ||
| 11007 | |||
| 11008 | As a convenience, you do not need to specify the | ||
| 11009 | complete license string in the whitelist for every package. You can use | ||
| 11010 | an abbreviated form, which consists of just the first portion or | ||
| 11011 | portions of the license string before the initial underscore character | ||
| 11012 | or characters. A partial string will match any license that contains the | ||
| 11013 | given string as the first portion of its license. For example, the | ||
| 11014 | following whitelist string will also match both of the packages | ||
| 11015 | previously mentioned as well as any other packages that have licenses | ||
| 11016 | starting with "commercial" or "license". | ||
| 11017 | :: | ||
| 11018 | |||
| 11019 | LICENSE_FLAGS_WHITELIST = "commercial license" | ||
| 11020 | |||
| 11021 | License Flag Matching | ||
| 11022 | ~~~~~~~~~~~~~~~~~~~~~ | ||
| 11023 | |||
| 11024 | License flag matching allows you to control what recipes the | ||
| 11025 | OpenEmbedded build system includes in the build. Fundamentally, the | ||
| 11026 | build system attempts to match ``LICENSE_FLAGS`` strings found in | ||
| 11027 | recipes against ``LICENSE_FLAGS_WHITELIST`` strings found in the | ||
| 11028 | whitelist. A match causes the build system to include a recipe in the | ||
| 11029 | build, while failure to find a match causes the build system to exclude | ||
| 11030 | a recipe. | ||
| 11031 | |||
| 11032 | In general, license flag matching is simple. However, understanding some | ||
| 11033 | concepts will help you correctly and effectively use matching. | ||
| 11034 | |||
| 11035 | Before a flag defined by a particular recipe is tested against the | ||
| 11036 | contents of the whitelist, the expanded string ``_${PN}`` is appended to | ||
| 11037 | the flag. This expansion makes each ``LICENSE_FLAGS`` value | ||
| 11038 | recipe-specific. After expansion, the string is then matched against the | ||
| 11039 | whitelist. Thus, specifying ``LICENSE_FLAGS = "commercial"`` in recipe | ||
| 11040 | "foo", for example, results in the string ``"commercial_foo"``. And, to | ||
| 11041 | create a match, that string must appear in the whitelist. | ||
| 11042 | |||
| 11043 | Judicious use of the ``LICENSE_FLAGS`` strings and the contents of the | ||
| 11044 | ``LICENSE_FLAGS_WHITELIST`` variable allows you a lot of flexibility for | ||
| 11045 | including or excluding recipes based on licensing. For example, you can | ||
| 11046 | broaden the matching capabilities by using license flags string subsets | ||
| 11047 | in the whitelist. | ||
| 11048 | |||
| 11049 | .. note:: | ||
| 11050 | |||
| 11051 | When using a string subset, be sure to use the part of the expanded | ||
| 11052 | string that precedes the appended underscore character (e.g. | ||
| 11053 | ``usethispart_1.3``, ``usethispart_1.4``, and so forth). | ||
| 11054 | |||
| 11055 | For example, simply specifying the string "commercial" in the whitelist | ||
| 11056 | matches any expanded ``LICENSE_FLAGS`` definition that starts with the | ||
| 11057 | string "commercial" such as "commercial_foo" and "commercial_bar", which | ||
| 11058 | are the strings the build system automatically generates for | ||
| 11059 | hypothetical recipes named "foo" and "bar" assuming those recipes simply | ||
| 11060 | specify the following: | ||
| 11061 | :: | ||
| 11062 | |||
| 11063 | LICENSE_FLAGS = "commercial" | ||
| 11064 | |||
| 11065 | Thus, you can choose | ||
| 11066 | to exhaustively enumerate each license flag in the whitelist and allow | ||
| 11067 | only specific recipes into the image, or you can use a string subset | ||
| 11068 | that causes a broader range of matches to allow a range of recipes into | ||
| 11069 | the image. | ||
| 11070 | |||
| 11071 | This scheme works even if the ``LICENSE_FLAGS`` string already has | ||
| 11072 | ``_${PN}`` appended. For example, the build system turns the license | ||
| 11073 | flag "commercial_1.2_foo" into "commercial_1.2_foo_foo" and would match | ||
| 11074 | both the general "commercial" and the specific "commercial_1.2_foo" | ||
| 11075 | strings found in the whitelist, as expected. | ||
| 11076 | |||
| 11077 | Here are some other scenarios: | ||
| 11078 | |||
| 11079 | - You can specify a versioned string in the recipe such as | ||
| 11080 | "commercial_foo_1.2" in a "foo" recipe. The build system expands this | ||
| 11081 | string to "commercial_foo_1.2_foo". Combine this license flag with a | ||
| 11082 | whitelist that has the string "commercial" and you match the flag | ||
| 11083 | along with any other flag that starts with the string "commercial". | ||
| 11084 | |||
| 11085 | - Under the same circumstances, you can use "commercial_foo" in the | ||
| 11086 | whitelist and the build system not only matches "commercial_foo_1.2" | ||
| 11087 | but also matches any license flag with the string "commercial_foo", | ||
| 11088 | regardless of the version. | ||
| 11089 | |||
| 11090 | - You can be very specific and use both the package and version parts | ||
| 11091 | in the whitelist (e.g. "commercial_foo_1.2") to specifically match a | ||
| 11092 | versioned recipe. | ||
| 11093 | |||
| 11094 | Other Variables Related to Commercial Licenses | ||
| 11095 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 11096 | |||
| 11097 | Other helpful variables related to commercial license handling exist and | ||
| 11098 | are defined in the | ||
| 11099 | ``poky/meta/conf/distro/include/default-distrovars.inc`` file: | ||
| 11100 | :: | ||
| 11101 | |||
| 11102 | COMMERCIAL_AUDIO_PLUGINS ?= "" | ||
| 11103 | COMMERCIAL_VIDEO_PLUGINS ?= "" | ||
| 11104 | |||
| 11105 | If you | ||
| 11106 | want to enable these components, you can do so by making sure you have | ||
| 11107 | statements similar to the following in your ``local.conf`` configuration | ||
| 11108 | file: | ||
| 11109 | :: | ||
| 11110 | |||
| 11111 | COMMERCIAL_AUDIO_PLUGINS = "gst-plugins-ugly-mad \ | ||
| 11112 | gst-plugins-ugly-mpegaudioparse" | ||
| 11113 | COMMERCIAL_VIDEO_PLUGINS = "gst-plugins-ugly-mpeg2dec \ | ||
| 11114 | gst-plugins-ugly-mpegstream gst-plugins-bad-mpegvideoparse" | ||
| 11115 | LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly commercial_gst-plugins-bad commercial_qmmp" | ||
| 11116 | |||
| 11117 | |||
| 11118 | Of course, you could also create a matching whitelist for those | ||
| 11119 | components using the more general "commercial" in the whitelist, but | ||
| 11120 | that would also enable all the other packages with ``LICENSE_FLAGS`` | ||
| 11121 | containing "commercial", which you may or may not want: | ||
| 11122 | :: | ||
| 11123 | |||
| 11124 | LICENSE_FLAGS_WHITELIST = "commercial" | ||
| 11125 | |||
| 11126 | Specifying audio and video plugins as part of the | ||
| 11127 | ``COMMERCIAL_AUDIO_PLUGINS`` and ``COMMERCIAL_VIDEO_PLUGINS`` statements | ||
| 11128 | (along with the enabling ``LICENSE_FLAGS_WHITELIST``) includes the | ||
| 11129 | plugins or components into built images, thus adding support for media | ||
| 11130 | formats or components. | ||
| 11131 | |||
| 11132 | Maintaining Open Source License Compliance During Your Product's Lifecycle | ||
| 11133 | -------------------------------------------------------------------------- | ||
| 11134 | |||
| 11135 | One of the concerns for a development organization using open source | ||
| 11136 | software is how to maintain compliance with various open source | ||
| 11137 | licensing during the lifecycle of the product. While this section does | ||
| 11138 | not provide legal advice or comprehensively cover all scenarios, it does | ||
| 11139 | present methods that you can use to assist you in meeting the compliance | ||
| 11140 | requirements during a software release. | ||
| 11141 | |||
| 11142 | With hundreds of different open source licenses that the Yocto Project | ||
| 11143 | tracks, it is difficult to know the requirements of each and every | ||
| 11144 | license. However, the requirements of the major FLOSS licenses can begin | ||
| 11145 | to be covered by assuming that three main areas of concern exist: | ||
| 11146 | |||
| 11147 | - Source code must be provided. | ||
| 11148 | |||
| 11149 | - License text for the software must be provided. | ||
| 11150 | |||
| 11151 | - Compilation scripts and modifications to the source code must be | ||
| 11152 | provided. | ||
| 11153 | |||
| 11154 | - spdx files can be provided. | ||
| 11155 | |||
| 11156 | There are other requirements beyond the scope of these three and the | ||
| 11157 | methods described in this section (e.g. the mechanism through which | ||
| 11158 | source code is distributed). | ||
| 11159 | |||
| 11160 | As different organizations have different methods of complying with open | ||
| 11161 | source licensing, this section is not meant to imply that there is only | ||
| 11162 | one single way to meet your compliance obligations, but rather to | ||
| 11163 | describe one method of achieving compliance. The remainder of this | ||
| 11164 | section describes methods supported to meet the previously mentioned | ||
| 11165 | three requirements. Once you take steps to meet these requirements, and | ||
| 11166 | prior to releasing images, sources, and the build system, you should | ||
| 11167 | audit all artifacts to ensure completeness. | ||
| 11168 | |||
| 11169 | .. note:: | ||
| 11170 | |||
| 11171 | The Yocto Project generates a license manifest during image creation | ||
| 11172 | that is located in ``${DEPLOY_DIR}/licenses/``\ `image_name`\ ``-``\ `datestamp` | ||
| 11173 | to assist with any audits. | ||
| 11174 | |||
| 11175 | Providing the Source Code | ||
| 11176 | ~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 11177 | |||
| 11178 | Compliance activities should begin before you generate the final image. | ||
| 11179 | The first thing you should look at is the requirement that tops the list | ||
| 11180 | for most compliance groups - providing the source. The Yocto Project has | ||
| 11181 | a few ways of meeting this requirement. | ||
| 11182 | |||
| 11183 | One of the easiest ways to meet this requirement is to provide the | ||
| 11184 | entire :term:`DL_DIR` used by the | ||
| 11185 | build. This method, however, has a few issues. The most obvious is the | ||
| 11186 | size of the directory since it includes all sources used in the build | ||
| 11187 | and not just the source used in the released image. It will include | ||
| 11188 | toolchain source, and other artifacts, which you would not generally | ||
| 11189 | release. However, the more serious issue for most companies is | ||
| 11190 | accidental release of proprietary software. The Yocto Project provides | ||
| 11191 | an :ref:`archiver <ref-classes-archiver>` class to | ||
| 11192 | help avoid some of these concerns. | ||
| 11193 | |||
| 11194 | Before you employ ``DL_DIR`` or the ``archiver`` class, you need to | ||
| 11195 | decide how you choose to provide source. The source ``archiver`` class | ||
| 11196 | can generate tarballs and SRPMs and can create them with various levels | ||
| 11197 | of compliance in mind. | ||
| 11198 | |||
| 11199 | One way of doing this (but certainly not the only way) is to release | ||
| 11200 | just the source as a tarball. You can do this by adding the following to | ||
| 11201 | the ``local.conf`` file found in the | ||
| 11202 | :term:`Build Directory`: | ||
| 11203 | :: | ||
| 11204 | |||
| 11205 | INHERIT += "archiver" | ||
| 11206 | ARCHIVER_MODE[src] = "original" | ||
| 11207 | |||
| 11208 | During the creation of your | ||
| 11209 | image, the source from all recipes that deploy packages to the image is | ||
| 11210 | placed within subdirectories of ``DEPLOY_DIR/sources`` based on the | ||
| 11211 | :term:`LICENSE` for each recipe. | ||
| 11212 | Releasing the entire directory enables you to comply with requirements | ||
| 11213 | concerning providing the unmodified source. It is important to note that | ||
| 11214 | the size of the directory can get large. | ||
| 11215 | |||
| 11216 | A way to help mitigate the size issue is to only release tarballs for | ||
| 11217 | licenses that require the release of source. Let us assume you are only | ||
| 11218 | concerned with GPL code as identified by running the following script: | ||
| 11219 | |||
| 11220 | .. code-block:: shell | ||
| 11221 | |||
| 11222 | # Script to archive a subset of packages matching specific license(s) | ||
| 11223 | # Source and license files are copied into sub folders of package folder | ||
| 11224 | # Must be run from build folder | ||
| 11225 | #!/bin/bash | ||
| 11226 | src_release_dir="source-release" | ||
| 11227 | mkdir -p $src_release_dir | ||
| 11228 | for a in tmp/deploy/sources/*; do | ||
| 11229 | for d in $a/*; do | ||
| 11230 | # Get package name from path | ||
| 11231 | p=`basename $d` | ||
| 11232 | p=${p%-*} | ||
| 11233 | p=${p%-*} | ||
| 11234 | # Only archive GPL packages (update *GPL* regex for your license check) | ||
| 11235 | numfiles=`ls tmp/deploy/licenses/$p/*GPL* 2> /dev/null | wc -l` | ||
| 11236 | if [ $numfiles -gt 1 ]; then | ||
| 11237 | echo Archiving $p | ||
| 11238 | mkdir -p $src_release_dir/$p/source | ||
| 11239 | cp $d/* $src_release_dir/$p/source 2> /dev/null | ||
| 11240 | mkdir -p $src_release_dir/$p/license | ||
| 11241 | cp tmp/deploy/licenses/$p/* $src_release_dir/$p/license 2> /dev/null | ||
| 11242 | fi | ||
| 11243 | done | ||
| 11244 | done | ||
| 11245 | |||
| 11246 | At this point, you | ||
| 11247 | could create a tarball from the ``gpl_source_release`` directory and | ||
| 11248 | provide that to the end user. This method would be a step toward | ||
| 11249 | achieving compliance with section 3a of GPLv2 and with section 6 of | ||
| 11250 | GPLv3. | ||
| 11251 | |||
| 11252 | Providing License Text | ||
| 11253 | ~~~~~~~~~~~~~~~~~~~~~~ | ||
| 11254 | |||
| 11255 | One requirement that is often overlooked is inclusion of license text. | ||
| 11256 | This requirement also needs to be dealt with prior to generating the | ||
| 11257 | final image. Some licenses require the license text to accompany the | ||
| 11258 | binary. You can achieve this by adding the following to your | ||
| 11259 | ``local.conf`` file: | ||
| 11260 | :: | ||
| 11261 | |||
| 11262 | COPY_LIC_MANIFEST = "1" | ||
| 11263 | COPY_LIC_DIRS = "1" | ||
| 11264 | LICENSE_CREATE_PACKAGE = "1" | ||
| 11265 | |||
| 11266 | Adding these statements to the | ||
| 11267 | configuration file ensures that the licenses collected during package | ||
| 11268 | generation are included on your image. | ||
| 11269 | |||
| 11270 | .. note:: | ||
| 11271 | |||
| 11272 | Setting all three variables to "1" results in the image having two | ||
| 11273 | copies of the same license file. One copy resides in | ||
| 11274 | ``/usr/share/common-licenses`` and the other resides in | ||
| 11275 | ``/usr/share/license``. | ||
| 11276 | |||
| 11277 | The reason for this behavior is because | ||
| 11278 | :term:`COPY_LIC_DIRS` and | ||
| 11279 | :term:`COPY_LIC_MANIFEST` | ||
| 11280 | add a copy of the license when the image is built but do not offer a | ||
| 11281 | path for adding licenses for newly installed packages to an image. | ||
| 11282 | :term:`LICENSE_CREATE_PACKAGE` | ||
| 11283 | adds a separate package and an upgrade path for adding licenses to an | ||
| 11284 | image. | ||
| 11285 | |||
| 11286 | As the source ``archiver`` class has already archived the original | ||
| 11287 | unmodified source that contains the license files, you would have | ||
| 11288 | already met the requirements for inclusion of the license information | ||
| 11289 | with source as defined by the GPL and other open source licenses. | ||
| 11290 | |||
| 11291 | Providing Compilation Scripts and Source Code Modifications | ||
| 11292 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 11293 | |||
| 11294 | At this point, we have addressed all we need to prior to generating the | ||
| 11295 | image. The next two requirements are addressed during the final | ||
| 11296 | packaging of the release. | ||
| 11297 | |||
| 11298 | By releasing the version of the OpenEmbedded build system and the layers | ||
| 11299 | used during the build, you will be providing both compilation scripts | ||
| 11300 | and the source code modifications in one step. | ||
| 11301 | |||
| 11302 | If the deployment team has a :ref:`overview-manual/overview-manual-concepts:bsp layer` | ||
| 11303 | and a distro layer, and those | ||
| 11304 | those layers are used to patch, compile, package, or modify (in any way) | ||
| 11305 | any open source software included in your released images, you might be | ||
| 11306 | required to release those layers under section 3 of GPLv2 or section 1 | ||
| 11307 | of GPLv3. One way of doing that is with a clean checkout of the version | ||
| 11308 | of the Yocto Project and layers used during your build. Here is an | ||
| 11309 | example: | ||
| 11310 | |||
| 11311 | .. code-block:: shell | ||
| 11312 | |||
| 11313 | # We built using the dunfell branch of the poky repo | ||
| 11314 | $ git clone -b dunfell git://git.yoctoproject.org/poky | ||
| 11315 | $ cd poky | ||
| 11316 | # We built using the release_branch for our layers | ||
| 11317 | $ git clone -b release_branch git://git.mycompany.com/meta-my-bsp-layer | ||
| 11318 | $ git clone -b release_branch git://git.mycompany.com/meta-my-software-layer | ||
| 11319 | # clean up the .git repos | ||
| 11320 | $ find . -name ".git" -type d -exec rm -rf {} \; | ||
| 11321 | |||
| 11322 | One | ||
| 11323 | thing a development organization might want to consider for end-user | ||
| 11324 | convenience is to modify ``meta-poky/conf/bblayers.conf.sample`` to | ||
| 11325 | ensure that when the end user utilizes the released build system to | ||
| 11326 | build an image, the development organization's layers are included in | ||
| 11327 | the ``bblayers.conf`` file automatically: | ||
| 11328 | :: | ||
| 11329 | |||
| 11330 | # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf | ||
| 11331 | # changes incompatibly | ||
| 11332 | POKY_BBLAYERS_CONF_VERSION = "2" | ||
| 11333 | |||
| 11334 | BBPATH = "${TOPDIR}" | ||
| 11335 | BBFILES ?= "" | ||
| 11336 | |||
| 11337 | BBLAYERS ?= " \ | ||
| 11338 | ##OEROOT##/meta \ | ||
| 11339 | ##OEROOT##/meta-poky \ | ||
| 11340 | ##OEROOT##/meta-yocto-bsp \ | ||
| 11341 | ##OEROOT##/meta-mylayer \ | ||
| 11342 | " | ||
| 11343 | |||
| 11344 | Creating and | ||
| 11345 | providing an archive of the :term:`Metadata` | ||
| 11346 | layers (recipes, configuration files, and so forth) enables you to meet | ||
| 11347 | your requirements to include the scripts to control compilation as well | ||
| 11348 | as any modifications to the original source. | ||
| 11349 | |||
| 11350 | Providing spdx files | ||
| 11351 | ~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 11352 | |||
| 11353 | The spdx module has been integrated to a layer named meta-spdxscanner. | ||
| 11354 | meta-spdxscanner provides several kinds of scanner. If you want to enable | ||
| 11355 | this function, you have to follow the following steps: | ||
| 11356 | |||
| 11357 | 1. Add meta-spdxscanner layer into ``bblayers.conf``. | ||
| 11358 | |||
| 11359 | 2. Refer to the README in meta-spdxscanner to setup the environment (e.g, | ||
| 11360 | setup a fossology server) needed for the scanner. | ||
| 11361 | |||
| 11362 | 3. Meta-spdxscanner provides several methods within the bbclass to create spdx files. | ||
| 11363 | Please choose one that you want to use and enable the spdx task. You have to | ||
| 11364 | add some config options in ``local.conf`` file in your :term:`Build | ||
| 11365 | Directory`. The following is an example showing how to generate spdx files | ||
| 11366 | during bitbake using the fossology-python.bbclass:: | ||
| 11367 | |||
| 11368 | # Select fossology-python.bbclass. | ||
| 11369 | INHERIT += "fossology-python" | ||
| 11370 | # For fossology-python.bbclass, TOKEN is necessary, so, after setup a | ||
| 11371 | # Fossology server, you have to create a token. | ||
| 11372 | TOKEN = "eyJ0eXAiO..." | ||
| 11373 | # The fossology server is necessary for fossology-python.bbclass. | ||
| 11374 | FOSSOLOGY_SERVER = "http://xx.xx.xx.xx:8081/repo" | ||
| 11375 | # If you want to upload the source code to a special folder: | ||
| 11376 | FOLDER_NAME = "xxxx" //Optional | ||
| 11377 | # If you don't want to put spdx files in tmp/deploy/spdx, you can enable: | ||
| 11378 | SPDX_DEPLOY_DIR = "${DEPLOY_DIR}" //Optional | ||
| 11379 | |||
| 11380 | For more usage information refer to :yocto_git:`the meta-spdxscanner repository | ||
| 11381 | </meta-spdxscanner/>`. | ||
| 11382 | |||
| 11383 | |||
| 11384 | Copying Licenses that Do Not Exist | ||
| 11385 | ---------------------------------- | ||
| 11386 | |||
| 11387 | Some packages, such as the linux-firmware package, have many licenses | ||
| 11388 | that are not in any way common. You can avoid adding a lot of these | ||
| 11389 | types of common license files, which are only applicable to a specific | ||
| 11390 | package, by using the | ||
| 11391 | :term:`NO_GENERIC_LICENSE` | ||
| 11392 | variable. Using this variable also avoids QA errors when you use a | ||
| 11393 | non-common, non-CLOSED license in a recipe. | ||
| 11394 | |||
| 11395 | The following is an example that uses the ``LICENSE.Abilis.txt`` file as | ||
| 11396 | the license from the fetched source: | ||
| 11397 | :: | ||
| 11398 | |||
| 11399 | NO_GENERIC_LICENSE[Firmware-Abilis] = "LICENSE.Abilis.txt" | ||
| 11400 | |||
| 11401 | Using the Error Reporting Tool | ||
| 11402 | ============================== | ||
| 11403 | |||
| 11404 | The error reporting tool allows you to submit errors encountered during | ||
| 11405 | builds to a central database. Outside of the build environment, you can | ||
| 11406 | use a web interface to browse errors, view statistics, and query for | ||
| 11407 | errors. The tool works using a client-server system where the client | ||
| 11408 | portion is integrated with the installed Yocto Project | ||
| 11409 | :term:`Source Directory` (e.g. ``poky``). | ||
| 11410 | The server receives the information collected and saves it in a | ||
| 11411 | database. | ||
| 11412 | |||
| 11413 | A live instance of the error reporting server exists at | ||
| 11414 | https://errors.yoctoproject.org. This server exists so that when | ||
| 11415 | you want to get help with build failures, you can submit all of the | ||
| 11416 | information on the failure easily and then point to the URL in your bug | ||
| 11417 | report or send an email to the mailing list. | ||
| 11418 | |||
| 11419 | .. note:: | ||
| 11420 | |||
| 11421 | If you send error reports to this server, the reports become publicly | ||
| 11422 | visible. | ||
| 11423 | |||
| 11424 | Enabling and Using the Tool | ||
| 11425 | --------------------------- | ||
| 11426 | |||
| 11427 | By default, the error reporting tool is disabled. You can enable it by | ||
| 11428 | inheriting the | ||
| 11429 | :ref:`report-error <ref-classes-report-error>` | ||
| 11430 | class by adding the following statement to the end of your | ||
| 11431 | ``local.conf`` file in your | ||
| 11432 | :term:`Build Directory`. | ||
| 11433 | :: | ||
| 11434 | |||
| 11435 | INHERIT += "report-error" | ||
| 11436 | |||
| 11437 | By default, the error reporting feature stores information in | ||
| 11438 | ``${``\ :term:`LOG_DIR`\ ``}/error-report``. | ||
| 11439 | However, you can specify a directory to use by adding the following to | ||
| 11440 | your ``local.conf`` file: | ||
| 11441 | :: | ||
| 11442 | |||
| 11443 | ERR_REPORT_DIR = "path" | ||
| 11444 | |||
| 11445 | Enabling error | ||
| 11446 | reporting causes the build process to collect the errors and store them | ||
| 11447 | in a file as previously described. When the build system encounters an | ||
| 11448 | error, it includes a command as part of the console output. You can run | ||
| 11449 | the command to send the error file to the server. For example, the | ||
| 11450 | following command sends the errors to an upstream server: | ||
| 11451 | :: | ||
| 11452 | |||
| 11453 | $ send-error-report /home/brandusa/project/poky/build/tmp/log/error-report/error_report_201403141617.txt | ||
| 11454 | |||
| 11455 | In the previous example, the errors are sent to a public database | ||
| 11456 | available at https://errors.yoctoproject.org, which is used by the | ||
| 11457 | entire community. If you specify a particular server, you can send the | ||
| 11458 | errors to a different database. Use the following command for more | ||
| 11459 | information on available options: | ||
| 11460 | :: | ||
| 11461 | |||
| 11462 | $ send-error-report --help | ||
| 11463 | |||
| 11464 | When sending the error file, you are prompted to review the data being | ||
| 11465 | sent as well as to provide a name and optional email address. Once you | ||
| 11466 | satisfy these prompts, the command returns a link from the server that | ||
| 11467 | corresponds to your entry in the database. For example, here is a | ||
| 11468 | typical link: https://errors.yoctoproject.org/Errors/Details/9522/ | ||
| 11469 | |||
| 11470 | Following the link takes you to a web interface where you can browse, | ||
| 11471 | query the errors, and view statistics. | ||
| 11472 | |||
| 11473 | Disabling the Tool | ||
| 11474 | ------------------ | ||
| 11475 | |||
| 11476 | To disable the error reporting feature, simply remove or comment out the | ||
| 11477 | following statement from the end of your ``local.conf`` file in your | ||
| 11478 | :term:`Build Directory`. | ||
| 11479 | :: | ||
| 11480 | |||
| 11481 | INHERIT += "report-error" | ||
| 11482 | |||
| 11483 | Setting Up Your Own Error Reporting Server | ||
| 11484 | ------------------------------------------ | ||
| 11485 | |||
| 11486 | If you want to set up your own error reporting server, you can obtain | ||
| 11487 | the code from the Git repository at :yocto_git:`/error-report-web/`. | ||
| 11488 | Instructions on how to set it up are in the README document. | ||
| 11489 | |||
| 11490 | Using Wayland and Weston | ||
| 11491 | ======================== | ||
| 11492 | |||
| 11493 | `Wayland <https://en.wikipedia.org/wiki/Wayland_(display_server_protocol)>`__ | ||
| 11494 | is a computer display server protocol that provides a method for | ||
| 11495 | compositing window managers to communicate directly with applications | ||
| 11496 | and video hardware and expects them to communicate with input hardware | ||
| 11497 | using other libraries. Using Wayland with supporting targets can result | ||
| 11498 | in better control over graphics frame rendering than an application | ||
| 11499 | might otherwise achieve. | ||
| 11500 | |||
| 11501 | The Yocto Project provides the Wayland protocol libraries and the | ||
| 11502 | reference | ||
| 11503 | `Weston <https://en.wikipedia.org/wiki/Wayland_(display_server_protocol)#Weston>`__ | ||
| 11504 | compositor as part of its release. You can find the integrated packages | ||
| 11505 | in the ``meta`` layer of the :term:`Source Directory`. | ||
| 11506 | Specifically, you | ||
| 11507 | can find the recipes that build both Wayland and Weston at | ||
| 11508 | ``meta/recipes-graphics/wayland``. | ||
| 11509 | |||
| 11510 | You can build both the Wayland and Weston packages for use only with | ||
| 11511 | targets that accept the `Mesa 3D and Direct Rendering | ||
| 11512 | Infrastructure <https://en.wikipedia.org/wiki/Mesa_(computer_graphics)>`__, | ||
| 11513 | which is also known as Mesa DRI. This implies that you cannot build and | ||
| 11514 | use the packages if your target uses, for example, the Intel Embedded | ||
| 11515 | Media and Graphics Driver (Intel EMGD) that overrides Mesa DRI. | ||
| 11516 | |||
| 11517 | .. note:: | ||
| 11518 | |||
| 11519 | Due to lack of EGL support, Weston 1.0.3 will not run directly on the | ||
| 11520 | emulated QEMU hardware. However, this version of Weston will run | ||
| 11521 | under X emulation without issues. | ||
| 11522 | |||
| 11523 | This section describes what you need to do to implement Wayland and use | ||
| 11524 | the Weston compositor when building an image for a supporting target. | ||
| 11525 | |||
| 11526 | Enabling Wayland in an Image | ||
| 11527 | ---------------------------- | ||
| 11528 | |||
| 11529 | To enable Wayland, you need to enable it to be built and enable it to be | ||
| 11530 | included (installed) in the image. | ||
| 11531 | |||
| 11532 | Building Wayland | ||
| 11533 | ~~~~~~~~~~~~~~~~ | ||
| 11534 | |||
| 11535 | To cause Mesa to build the ``wayland-egl`` platform and Weston to build | ||
| 11536 | Wayland with Kernel Mode Setting | ||
| 11537 | (`KMS <https://wiki.archlinux.org/index.php/Kernel_Mode_Setting>`__) | ||
| 11538 | support, include the "wayland" flag in the | ||
| 11539 | :term:`DISTRO_FEATURES` | ||
| 11540 | statement in your ``local.conf`` file: | ||
| 11541 | :: | ||
| 11542 | |||
| 11543 | DISTRO_FEATURES_append = " wayland" | ||
| 11544 | |||
| 11545 | .. note:: | ||
| 11546 | |||
| 11547 | If X11 has been enabled elsewhere, Weston will build Wayland with X11 | ||
| 11548 | support | ||
| 11549 | |||
| 11550 | Installing Wayland and Weston | ||
| 11551 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 11552 | |||
| 11553 | To install the Wayland feature into an image, you must include the | ||
| 11554 | following | ||
| 11555 | :term:`CORE_IMAGE_EXTRA_INSTALL` | ||
| 11556 | statement in your ``local.conf`` file: | ||
| 11557 | :: | ||
| 11558 | |||
| 11559 | CORE_IMAGE_EXTRA_INSTALL += "wayland weston" | ||
| 11560 | |||
| 11561 | Running Weston | ||
| 11562 | -------------- | ||
| 11563 | |||
| 11564 | To run Weston inside X11, enabling it as described earlier and building | ||
| 11565 | a Sato image is sufficient. If you are running your image under Sato, a | ||
| 11566 | Weston Launcher appears in the "Utility" category. | ||
| 11567 | |||
| 11568 | Alternatively, you can run Weston through the command-line interpretor | ||
| 11569 | (CLI), which is better suited for development work. To run Weston under | ||
| 11570 | the CLI, you need to do the following after your image is built: | ||
| 11571 | |||
| 11572 | 1. Run these commands to export ``XDG_RUNTIME_DIR``: | ||
| 11573 | :: | ||
| 11574 | |||
| 11575 | mkdir -p /tmp/$USER-weston | ||
| 11576 | chmod 0700 /tmp/$USER-weston | ||
| 11577 | export XDG_RUNTIME_DIR=/tmp/$USER-weston | ||
| 11578 | |||
| 11579 | 2. Launch Weston in the shell: | ||
| 11580 | :: | ||
| 11581 | |||
| 11582 | weston | ||
