Andrew Geissler | f034379 | 2020-11-18 10:42:21 -0600 | [diff] [blame] | 1 | .. SPDX-License-Identifier: CC-BY-SA-2.0-UK |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 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 |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 21 | ":ref:`overview-manual/yp-intro:the yocto project layer model`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 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 |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 34 | Guide and the ":ref:`dev-manual/common-tasks:creating a general layer using the \`\`bitbake-layers\`\` script`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 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 |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 41 | you need. You can see the :oe_layerindex:`OpenEmbedded Metadata Index <>` |
| 42 | for a list of layers from the OpenEmbedded community that can be used in |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 43 | the Yocto Project. You could find a layer that is identical or close |
| 44 | to what you need. |
| 45 | |
| 46 | 2. *Create a Directory:* Create the directory for your layer. When you |
| 47 | create the layer, be sure to create the directory in an area not |
| 48 | associated with the Yocto Project :term:`Source Directory` |
| 49 | (e.g. the cloned ``poky`` repository). |
| 50 | |
| 51 | While not strictly required, prepend the name of the directory with |
| 52 | the string "meta-". For example: |
| 53 | :: |
| 54 | |
| 55 | meta-mylayer |
| 56 | meta-GUI_xyz |
| 57 | meta-mymachine |
| 58 | |
| 59 | With rare exceptions, a layer's name follows this form: |
| 60 | :: |
| 61 | |
| 62 | meta-root_name |
| 63 | |
| 64 | Following this layer naming convention can save |
| 65 | you trouble later when tools, components, or variables "assume" your |
| 66 | layer name begins with "meta-". A notable example is in configuration |
| 67 | files as shown in the following step where layer names without the |
| 68 | "meta-" string are appended to several variables used in the |
| 69 | configuration. |
| 70 | |
| 71 | 3. *Create a Layer Configuration File:* Inside your new layer folder, |
| 72 | you need to create a ``conf/layer.conf`` file. It is easiest to take |
| 73 | an existing layer configuration file and copy that to your layer's |
| 74 | ``conf`` directory and then modify the file as needed. |
| 75 | |
| 76 | The ``meta-yocto-bsp/conf/layer.conf`` file in the Yocto Project |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 77 | :yocto_git:`Source Repositories </poky/tree/meta-yocto-bsp/conf>` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 78 | demonstrates the required syntax. For your layer, you need to replace |
| 79 | "yoctobsp" with a unique identifier for your layer (e.g. "machinexyz" |
| 80 | for a layer named "meta-machinexyz"): |
| 81 | :: |
| 82 | |
| 83 | # We have a conf and classes directory, add to BBPATH |
| 84 | BBPATH .= ":${LAYERDIR}" |
| 85 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 86 | # We have recipes-* directories, add to BBFILES |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 87 | BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \ |
| 88 | ${LAYERDIR}/recipes-*/*/*.bbappend" |
| 89 | |
| 90 | BBFILE_COLLECTIONS += "yoctobsp" |
| 91 | BBFILE_PATTERN_yoctobsp = "^${LAYERDIR}/" |
| 92 | BBFILE_PRIORITY_yoctobsp = "5" |
| 93 | LAYERVERSION_yoctobsp = "4" |
| 94 | LAYERSERIES_COMPAT_yoctobsp = "dunfell" |
| 95 | |
| 96 | Following is an explanation of the layer configuration file: |
| 97 | |
| 98 | - :term:`BBPATH`: Adds the layer's |
| 99 | root directory to BitBake's search path. Through the use of the |
| 100 | ``BBPATH`` variable, BitBake locates class files (``.bbclass``), |
| 101 | configuration files, and files that are included with ``include`` |
| 102 | and ``require`` statements. For these cases, BitBake uses the |
| 103 | first file that matches the name found in ``BBPATH``. This is |
| 104 | similar to the way the ``PATH`` variable is used for binaries. It |
| 105 | is recommended, therefore, that you use unique class and |
| 106 | configuration filenames in your custom layer. |
| 107 | |
| 108 | - :term:`BBFILES`: Defines the |
| 109 | location for all recipes in the layer. |
| 110 | |
| 111 | - :term:`BBFILE_COLLECTIONS`: |
| 112 | Establishes the current layer through a unique identifier that is |
| 113 | used throughout the OpenEmbedded build system to refer to the |
| 114 | layer. In this example, the identifier "yoctobsp" is the |
| 115 | representation for the container layer named "meta-yocto-bsp". |
| 116 | |
| 117 | - :term:`BBFILE_PATTERN`: |
| 118 | Expands immediately during parsing to provide the directory of the |
| 119 | layer. |
| 120 | |
| 121 | - :term:`BBFILE_PRIORITY`: |
| 122 | Establishes a priority to use for recipes in the layer when the |
| 123 | OpenEmbedded build finds recipes of the same name in different |
| 124 | layers. |
| 125 | |
| 126 | - :term:`LAYERVERSION`: |
| 127 | Establishes a version number for the layer. You can use this |
| 128 | version number to specify this exact version of the layer as a |
| 129 | dependency when using the |
| 130 | :term:`LAYERDEPENDS` |
| 131 | variable. |
| 132 | |
| 133 | - :term:`LAYERDEPENDS`: |
| 134 | Lists all layers on which this layer depends (if any). |
| 135 | |
| 136 | - :term:`LAYERSERIES_COMPAT`: |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 137 | Lists the :yocto_wiki:`Yocto Project </Releases>` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 138 | releases for which the current version is compatible. This |
| 139 | variable is a good way to indicate if your particular layer is |
| 140 | current. |
| 141 | |
| 142 | 4. *Add Content:* Depending on the type of layer, add the content. If |
| 143 | the layer adds support for a machine, add the machine configuration |
| 144 | in a ``conf/machine/`` file within the layer. If the layer adds |
| 145 | distro policy, add the distro configuration in a ``conf/distro/`` |
| 146 | file within the layer. If the layer introduces new recipes, put the |
| 147 | recipes you need in ``recipes-*`` subdirectories within the layer. |
| 148 | |
| 149 | .. note:: |
| 150 | |
| 151 | For an explanation of layer hierarchy that is compliant with the |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 152 | Yocto Project, see the ":ref:`bsp-guide/bsp:example filesystem layout`" |
| 153 | section in the Yocto Project Board Support Package (BSP) Developer's Guide. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 154 | |
| 155 | 5. *Optionally Test for Compatibility:* If you want permission to use |
| 156 | the Yocto Project Compatibility logo with your layer or application |
| 157 | that uses your layer, perform the steps to apply for compatibility. |
| 158 | See the "`Making Sure Your Layer is Compatible With Yocto |
| 159 | Project <#making-sure-your-layer-is-compatible-with-yocto-project>`__" |
| 160 | section for more information. |
| 161 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 162 | Following Best Practices When Creating Layers |
| 163 | --------------------------------------------- |
| 164 | |
| 165 | To create layers that are easier to maintain and that will not impact |
| 166 | builds for other machines, you should consider the information in the |
| 167 | following list: |
| 168 | |
| 169 | - *Avoid "Overlaying" Entire Recipes from Other Layers in Your |
| 170 | Configuration:* In other words, do not copy an entire recipe into |
| 171 | your layer and then modify it. Rather, use an append file |
| 172 | (``.bbappend``) to override only those parts of the original recipe |
| 173 | you need to modify. |
| 174 | |
| 175 | - *Avoid Duplicating Include Files:* Use append files (``.bbappend``) |
| 176 | for each recipe that uses an include file. Or, if you are introducing |
| 177 | a new recipe that requires the included file, use the path relative |
| 178 | to the original layer directory to refer to the file. For example, |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 179 | use ``require recipes-core/``\ `package`\ ``/``\ `file`\ ``.inc`` instead |
| 180 | of ``require`` `file`\ ``.inc``. If you're finding you have to overlay |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 181 | the include file, it could indicate a deficiency in the include file |
| 182 | in the layer to which it originally belongs. If this is the case, you |
| 183 | should try to address that deficiency instead of overlaying the |
| 184 | include file. For example, you could address this by getting the |
| 185 | maintainer of the include file to add a variable or variables to make |
| 186 | it easy to override the parts needing to be overridden. |
| 187 | |
| 188 | - *Structure Your Layers:* Proper use of overrides within append files |
| 189 | and placement of machine-specific files within your layer can ensure |
| 190 | that a build is not using the wrong Metadata and negatively impacting |
| 191 | a build for a different machine. Following are some examples: |
| 192 | |
| 193 | - *Modify Variables to Support a Different Machine:* Suppose you |
| 194 | have a layer named ``meta-one`` that adds support for building |
| 195 | machine "one". To do so, you use an append file named |
| 196 | ``base-files.bbappend`` and create a dependency on "foo" by |
| 197 | altering the :term:`DEPENDS` |
| 198 | variable: |
| 199 | :: |
| 200 | |
| 201 | DEPENDS = "foo" |
| 202 | |
| 203 | The dependency is created during any |
| 204 | build that includes the layer ``meta-one``. However, you might not |
| 205 | want this dependency for all machines. For example, suppose you |
| 206 | are building for machine "two" but your ``bblayers.conf`` file has |
| 207 | the ``meta-one`` layer included. During the build, the |
| 208 | ``base-files`` for machine "two" will also have the dependency on |
| 209 | ``foo``. |
| 210 | |
| 211 | To make sure your changes apply only when building machine "one", |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 212 | use a machine override with the ``DEPENDS`` statement: |
| 213 | :: |
| 214 | |
| 215 | DEPENDS_one = "foo" |
| 216 | |
| 217 | You should follow the same strategy when using ``_append`` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 218 | and ``_prepend`` operations: |
| 219 | :: |
| 220 | |
| 221 | DEPENDS_append_one = " foo" |
| 222 | DEPENDS_prepend_one = "foo " |
| 223 | |
| 224 | As an actual example, here's a |
| 225 | snippet from the generic kernel include file ``linux-yocto.inc``, |
| 226 | wherein the kernel compile and link options are adjusted in the |
| 227 | case of a subset of the supported architectures: |
| 228 | :: |
| 229 | |
| 230 | DEPENDS_append_aarch64 = " libgcc" |
| 231 | KERNEL_CC_append_aarch64 = " ${TOOLCHAIN_OPTIONS}" |
| 232 | KERNEL_LD_append_aarch64 = " ${TOOLCHAIN_OPTIONS}" |
| 233 | |
| 234 | DEPENDS_append_nios2 = " libgcc" |
| 235 | KERNEL_CC_append_nios2 = " ${TOOLCHAIN_OPTIONS}" |
| 236 | KERNEL_LD_append_nios2 = " ${TOOLCHAIN_OPTIONS}" |
| 237 | |
| 238 | DEPENDS_append_arc = " libgcc" |
| 239 | KERNEL_CC_append_arc = " ${TOOLCHAIN_OPTIONS}" |
| 240 | KERNEL_LD_append_arc = " ${TOOLCHAIN_OPTIONS}" |
| 241 | |
| 242 | KERNEL_FEATURES_append_qemuall=" features/debug/printk.scc" |
| 243 | |
| 244 | .. note:: |
| 245 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 246 | Avoiding "+=" and "=+" and using machine-specific ``_append`` |
| 247 | and ``_prepend`` operations is recommended as well. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 248 | |
| 249 | - *Place Machine-Specific Files in Machine-Specific Locations:* When |
| 250 | you have a base recipe, such as ``base-files.bb``, that contains a |
| 251 | :term:`SRC_URI` statement to a |
| 252 | file, you can use an append file to cause the build to use your |
| 253 | own version of the file. For example, an append file in your layer |
| 254 | at ``meta-one/recipes-core/base-files/base-files.bbappend`` could |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 255 | extend :term:`FILESPATH` using :term:`FILESEXTRAPATHS` as follows: |
| 256 | :: |
| 257 | |
| 258 | FILESEXTRAPATHS_prepend := "${THISDIR}/${BPN}:" |
| 259 | |
| 260 | The build for machine "one" will pick up your machine-specific file as |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 261 | long as you have the file in |
| 262 | ``meta-one/recipes-core/base-files/base-files/``. However, if you |
| 263 | are building for a different machine and the ``bblayers.conf`` |
| 264 | file includes the ``meta-one`` layer and the location of your |
| 265 | machine-specific file is the first location where that file is |
| 266 | found according to ``FILESPATH``, builds for all machines will |
| 267 | also use that machine-specific file. |
| 268 | |
| 269 | You can make sure that a machine-specific file is used for a |
| 270 | particular machine by putting the file in a subdirectory specific |
| 271 | to the machine. For example, rather than placing the file in |
| 272 | ``meta-one/recipes-core/base-files/base-files/`` as shown above, |
| 273 | put it in ``meta-one/recipes-core/base-files/base-files/one/``. |
| 274 | Not only does this make sure the file is used only when building |
| 275 | for machine "one", but the build process locates the file more |
| 276 | quickly. |
| 277 | |
| 278 | In summary, you need to place all files referenced from |
| 279 | ``SRC_URI`` in a machine-specific subdirectory within the layer in |
| 280 | order to restrict those files to machine-specific builds. |
| 281 | |
| 282 | - *Perform Steps to Apply for Yocto Project Compatibility:* If you want |
| 283 | permission to use the Yocto Project Compatibility logo with your |
| 284 | layer or application that uses your layer, perform the steps to apply |
| 285 | for compatibility. See the "`Making Sure Your Layer is Compatible |
| 286 | With Yocto |
| 287 | Project <#making-sure-your-layer-is-compatible-with-yocto-project>`__" |
| 288 | section for more information. |
| 289 | |
| 290 | - *Follow the Layer Naming Convention:* Store custom layers in a Git |
| 291 | repository that use the ``meta-layer_name`` format. |
| 292 | |
| 293 | - *Group Your Layers Locally:* Clone your repository alongside other |
| 294 | cloned ``meta`` directories from the :term:`Source Directory`. |
| 295 | |
| 296 | Making Sure Your Layer is Compatible With Yocto Project |
| 297 | ------------------------------------------------------- |
| 298 | |
| 299 | When you create a layer used with the Yocto Project, it is advantageous |
| 300 | to make sure that the layer interacts well with existing Yocto Project |
| 301 | layers (i.e. the layer is compatible with the Yocto Project). Ensuring |
| 302 | compatibility makes the layer easy to be consumed by others in the Yocto |
| 303 | Project community and could allow you permission to use the Yocto |
| 304 | Project Compatible Logo. |
| 305 | |
| 306 | .. note:: |
| 307 | |
| 308 | Only Yocto Project member organizations are permitted to use the |
| 309 | Yocto Project Compatible Logo. The logo is not available for general |
| 310 | use. For information on how to become a Yocto Project member |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 311 | organization, see the :yocto_home:`Yocto Project Website <>`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 312 | |
| 313 | The Yocto Project Compatibility Program consists of a layer application |
| 314 | process that requests permission to use the Yocto Project Compatibility |
| 315 | Logo for your layer and application. The process consists of two parts: |
| 316 | |
| 317 | 1. Successfully passing a script (``yocto-check-layer``) that when run |
| 318 | against your layer, tests it against constraints based on experiences |
| 319 | of how layers have worked in the real world and where pitfalls have |
| 320 | been found. Getting a "PASS" result from the script is required for |
| 321 | successful compatibility registration. |
| 322 | |
| 323 | 2. Completion of an application acceptance form, which you can find at |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 324 | :yocto_home:`/webform/yocto-project-compatible-registration`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 325 | |
| 326 | To be granted permission to use the logo, you need to satisfy the |
| 327 | following: |
| 328 | |
| 329 | - Be able to check the box indicating that you got a "PASS" when |
| 330 | running the script against your layer. |
| 331 | |
| 332 | - Answer "Yes" to the questions on the form or have an acceptable |
| 333 | explanation for any questions answered "No". |
| 334 | |
| 335 | - Be a Yocto Project Member Organization. |
| 336 | |
| 337 | The remainder of this section presents information on the registration |
| 338 | form and on the ``yocto-check-layer`` script. |
| 339 | |
| 340 | Yocto Project Compatible Program Application |
| 341 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 342 | |
| 343 | Use the form to apply for your layer's approval. Upon successful |
| 344 | application, you can use the Yocto Project Compatibility Logo with your |
| 345 | layer and the application that uses your layer. |
| 346 | |
| 347 | To access the form, use this link: |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 348 | :yocto_home:`/webform/yocto-project-compatible-registration`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 349 | Follow the instructions on the form to complete your application. |
| 350 | |
| 351 | The application consists of the following sections: |
| 352 | |
| 353 | - *Contact Information:* Provide your contact information as the fields |
| 354 | require. Along with your information, provide the released versions |
| 355 | of the Yocto Project for which your layer is compatible. |
| 356 | |
| 357 | - *Acceptance Criteria:* Provide "Yes" or "No" answers for each of the |
| 358 | items in the checklist. Space exists at the bottom of the form for |
| 359 | any explanations for items for which you answered "No". |
| 360 | |
| 361 | - *Recommendations:* Provide answers for the questions regarding Linux |
| 362 | kernel use and build success. |
| 363 | |
| 364 | ``yocto-check-layer`` Script |
| 365 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 366 | |
| 367 | The ``yocto-check-layer`` script provides you a way to assess how |
| 368 | compatible your layer is with the Yocto Project. You should run this |
| 369 | script prior to using the form to apply for compatibility as described |
| 370 | in the previous section. You need to achieve a "PASS" result in order to |
| 371 | have your application form successfully processed. |
| 372 | |
| 373 | The script divides tests into three areas: COMMON, BSP, and DISTRO. For |
| 374 | example, given a distribution layer (DISTRO), the layer must pass both |
| 375 | the COMMON and DISTRO related tests. Furthermore, if your layer is a BSP |
| 376 | layer, the layer must pass the COMMON and BSP set of tests. |
| 377 | |
| 378 | To execute the script, enter the following commands from your build |
| 379 | directory: |
| 380 | :: |
| 381 | |
| 382 | $ source oe-init-build-env |
| 383 | $ yocto-check-layer your_layer_directory |
| 384 | |
| 385 | Be sure to provide the actual directory for your |
| 386 | layer as part of the command. |
| 387 | |
| 388 | Entering the command causes the script to determine the type of layer |
| 389 | and then to execute a set of specific tests against the layer. The |
| 390 | following list overviews the test: |
| 391 | |
| 392 | - ``common.test_readme``: Tests if a ``README`` file exists in the |
| 393 | layer and the file is not empty. |
| 394 | |
| 395 | - ``common.test_parse``: Tests to make sure that BitBake can parse the |
| 396 | files without error (i.e. ``bitbake -p``). |
| 397 | |
| 398 | - ``common.test_show_environment``: Tests that the global or per-recipe |
| 399 | environment is in order without errors (i.e. ``bitbake -e``). |
| 400 | |
| 401 | - ``common.test_world``: Verifies that ``bitbake world`` works. |
| 402 | |
| 403 | - ``common.test_signatures``: Tests to be sure that BSP and DISTRO |
| 404 | layers do not come with recipes that change signatures. |
| 405 | |
| 406 | - ``common.test_layerseries_compat``: Verifies layer compatibility is |
| 407 | set properly. |
| 408 | |
| 409 | - ``bsp.test_bsp_defines_machines``: Tests if a BSP layer has machine |
| 410 | configurations. |
| 411 | |
| 412 | - ``bsp.test_bsp_no_set_machine``: Tests to ensure a BSP layer does not |
| 413 | set the machine when the layer is added. |
| 414 | |
| 415 | - ``bsp.test_machine_world``: Verifies that ``bitbake world`` works |
| 416 | regardless of which machine is selected. |
| 417 | |
| 418 | - ``bsp.test_machine_signatures``: Verifies that building for a |
| 419 | particular machine affects only the signature of tasks specific to |
| 420 | that machine. |
| 421 | |
| 422 | - ``distro.test_distro_defines_distros``: Tests if a DISTRO layer has |
| 423 | distro configurations. |
| 424 | |
| 425 | - ``distro.test_distro_no_set_distros``: Tests to ensure a DISTRO layer |
| 426 | does not set the distribution when the layer is added. |
| 427 | |
| 428 | Enabling Your Layer |
| 429 | ------------------- |
| 430 | |
| 431 | Before the OpenEmbedded build system can use your new layer, you need to |
| 432 | enable it. To enable your layer, simply add your layer's path to the |
| 433 | ``BBLAYERS`` variable in your ``conf/bblayers.conf`` file, which is |
| 434 | found in the :term:`Build Directory`. |
| 435 | The following example shows how to enable a layer named |
| 436 | ``meta-mylayer``: |
| 437 | :: |
| 438 | |
| 439 | # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf |
| 440 | # changes incompatibly |
| 441 | POKY_BBLAYERS_CONF_VERSION = "2" |
| 442 | BBPATH = "${TOPDIR}" |
| 443 | BBFILES ?= "" |
| 444 | BBLAYERS ?= " \ |
| 445 | /home/user/poky/meta \ |
| 446 | /home/user/poky/meta-poky \ |
| 447 | /home/user/poky/meta-yocto-bsp \ |
| 448 | /home/user/poky/meta-mylayer \ |
| 449 | " |
| 450 | |
| 451 | BitBake parses each ``conf/layer.conf`` file from the top down as |
| 452 | specified in the ``BBLAYERS`` variable within the ``conf/bblayers.conf`` |
| 453 | file. During the processing of each ``conf/layer.conf`` file, BitBake |
| 454 | adds the recipes, classes and configurations contained within the |
| 455 | particular layer to the source directory. |
| 456 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 457 | Using .bbappend Files in Your Layer |
| 458 | ----------------------------------- |
| 459 | |
| 460 | A recipe that appends Metadata to another recipe is called a BitBake |
| 461 | append file. A BitBake append file uses the ``.bbappend`` file type |
| 462 | suffix, while the corresponding recipe to which Metadata is being |
| 463 | appended uses the ``.bb`` file type suffix. |
| 464 | |
| 465 | You can use a ``.bbappend`` file in your layer to make additions or |
| 466 | changes to the content of another layer's recipe without having to copy |
| 467 | the other layer's recipe into your layer. Your ``.bbappend`` file |
| 468 | resides in your layer, while the main ``.bb`` recipe file to which you |
| 469 | are appending Metadata resides in a different layer. |
| 470 | |
| 471 | Being able to append information to an existing recipe not only avoids |
| 472 | duplication, but also automatically applies recipe changes from a |
| 473 | different layer into your layer. If you were copying recipes, you would |
| 474 | have to manually merge changes as they occur. |
| 475 | |
| 476 | When you create an append file, you must use the same root name as the |
| 477 | corresponding recipe file. For example, the append file |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 478 | ``someapp_3.1.bbappend`` must apply to ``someapp_3.1.bb``. This |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 479 | means the original recipe and append file names are version |
| 480 | number-specific. If the corresponding recipe is renamed to update to a |
| 481 | newer version, you must also rename and possibly update the |
| 482 | corresponding ``.bbappend`` as well. During the build process, BitBake |
| 483 | displays an error on starting if it detects a ``.bbappend`` file that |
| 484 | does not have a corresponding recipe with a matching name. See the |
| 485 | :term:`BB_DANGLINGAPPENDS_WARNONLY` |
| 486 | variable for information on how to handle this error. |
| 487 | |
| 488 | As an example, consider the main formfactor recipe and a corresponding |
| 489 | formfactor append file both from the :term:`Source Directory`. |
| 490 | Here is the main |
| 491 | formfactor recipe, which is named ``formfactor_0.0.bb`` and located in |
| 492 | the "meta" layer at ``meta/recipes-bsp/formfactor``: |
| 493 | :: |
| 494 | |
| 495 | SUMMARY = "Device formfactor information" |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 496 | DESCRIPTION = "A formfactor configuration file provides information about the \ |
| 497 | target hardware for which the image is being built and information that the \ |
| 498 | build system cannot obtain from other sources such as the kernel." |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 499 | SECTION = "base" |
| 500 | LICENSE = "MIT" |
| 501 | LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" |
| 502 | PR = "r45" |
| 503 | |
| 504 | SRC_URI = "file://config file://machconfig" |
| 505 | S = "${WORKDIR}" |
| 506 | |
| 507 | PACKAGE_ARCH = "${MACHINE_ARCH}" |
| 508 | INHIBIT_DEFAULT_DEPS = "1" |
| 509 | |
| 510 | do_install() { |
| 511 | # Install file only if it has contents |
| 512 | install -d ${D}${sysconfdir}/formfactor/ |
| 513 | install -m 0644 ${S}/config ${D}${sysconfdir}/formfactor/ |
| 514 | if [ -s "${S}/machconfig" ]; then |
| 515 | install -m 0644 ${S}/machconfig ${D}${sysconfdir}/formfactor/ |
| 516 | fi |
| 517 | } |
| 518 | |
| 519 | In the main recipe, note the :term:`SRC_URI` |
| 520 | variable, which tells the OpenEmbedded build system where to find files |
| 521 | during the build. |
| 522 | |
| 523 | Following is the append file, which is named ``formfactor_0.0.bbappend`` |
| 524 | and is from the Raspberry Pi BSP Layer named ``meta-raspberrypi``. The |
| 525 | file is in the layer at ``recipes-bsp/formfactor``: |
| 526 | :: |
| 527 | |
| 528 | FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" |
| 529 | |
| 530 | By default, the build system uses the |
| 531 | :term:`FILESPATH` variable to |
| 532 | locate files. This append file extends the locations by setting the |
| 533 | :term:`FILESEXTRAPATHS` |
| 534 | variable. Setting this variable in the ``.bbappend`` file is the most |
| 535 | reliable and recommended method for adding directories to the search |
| 536 | path used by the build system to find files. |
| 537 | |
| 538 | The statement in this example extends the directories to include |
| 539 | ``${``\ :term:`THISDIR`\ ``}/${``\ :term:`PN`\ ``}``, |
| 540 | which resolves to a directory named ``formfactor`` in the same directory |
| 541 | in which the append file resides (i.e. |
| 542 | ``meta-raspberrypi/recipes-bsp/formfactor``. This implies that you must |
| 543 | have the supporting directory structure set up that will contain any |
| 544 | files or patches you will be including from the layer. |
| 545 | |
| 546 | Using the immediate expansion assignment operator ``:=`` is important |
| 547 | because of the reference to ``THISDIR``. The trailing colon character is |
| 548 | important as it ensures that items in the list remain colon-separated. |
| 549 | |
| 550 | .. note:: |
| 551 | |
| 552 | BitBake automatically defines the ``THISDIR`` variable. You should |
| 553 | never set this variable yourself. Using "_prepend" as part of the |
| 554 | ``FILESEXTRAPATHS`` ensures your path will be searched prior to other |
| 555 | paths in the final list. |
| 556 | |
| 557 | Also, not all append files add extra files. Many append files simply |
| 558 | exist to add build options (e.g. ``systemd``). For these cases, your |
| 559 | append file would not even use the ``FILESEXTRAPATHS`` statement. |
| 560 | |
| 561 | Prioritizing Your Layer |
| 562 | ----------------------- |
| 563 | |
| 564 | Each layer is assigned a priority value. Priority values control which |
| 565 | layer takes precedence if there are recipe files with the same name in |
| 566 | multiple layers. For these cases, the recipe file from the layer with a |
| 567 | higher priority number takes precedence. Priority values also affect the |
| 568 | order in which multiple ``.bbappend`` files for the same recipe are |
| 569 | applied. You can either specify the priority manually, or allow the |
| 570 | build system to calculate it based on the layer's dependencies. |
| 571 | |
| 572 | To specify the layer's priority manually, use the |
| 573 | :term:`BBFILE_PRIORITY` |
| 574 | variable and append the layer's root name: |
| 575 | :: |
| 576 | |
| 577 | BBFILE_PRIORITY_mylayer = "1" |
| 578 | |
| 579 | .. note:: |
| 580 | |
| 581 | It is possible for a recipe with a lower version number |
| 582 | :term:`PV` in a layer that has a higher |
| 583 | priority to take precedence. |
| 584 | |
| 585 | Also, the layer priority does not currently affect the precedence |
| 586 | order of ``.conf`` or ``.bbclass`` files. Future versions of BitBake |
| 587 | might address this. |
| 588 | |
| 589 | Managing Layers |
| 590 | --------------- |
| 591 | |
| 592 | You can use the BitBake layer management tool ``bitbake-layers`` to |
| 593 | provide a view into the structure of recipes across a multi-layer |
| 594 | project. Being able to generate output that reports on configured layers |
| 595 | with their paths and priorities and on ``.bbappend`` files and their |
| 596 | applicable recipes can help to reveal potential problems. |
| 597 | |
| 598 | For help on the BitBake layer management tool, use the following |
| 599 | command: |
| 600 | :: |
| 601 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 602 | $ bitbake-layers --help |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 603 | NOTE: Starting bitbake server... |
| 604 | usage: bitbake-layers [-d] [-q] [-F] [--color COLOR] [-h] <subcommand> ... |
| 605 | |
| 606 | BitBake layers utility |
| 607 | |
| 608 | optional arguments: |
| 609 | -d, --debug Enable debug output |
| 610 | -q, --quiet Print only errors |
| 611 | -F, --force Force add without recipe parse verification |
| 612 | --color COLOR Colorize output (where COLOR is auto, always, never) |
| 613 | -h, --help show this help message and exit |
| 614 | |
| 615 | subcommands: |
| 616 | <subcommand> |
| 617 | layerindex-fetch Fetches a layer from a layer index along with its |
| 618 | dependent layers, and adds them to conf/bblayers.conf. |
| 619 | layerindex-show-depends |
| 620 | Find layer dependencies from layer index. |
| 621 | add-layer Add one or more layers to bblayers.conf. |
| 622 | remove-layer Remove one or more layers from bblayers.conf. |
| 623 | flatten flatten layer configuration into a separate output |
| 624 | directory. |
| 625 | show-layers show current configured layers. |
| 626 | show-overlayed list overlayed recipes (where the same recipe exists |
| 627 | in another layer) |
| 628 | show-recipes list available recipes, showing the layer they are |
| 629 | provided by |
| 630 | show-appends list bbappend files and recipe files they apply to |
| 631 | show-cross-depends Show dependencies between recipes that cross layer |
| 632 | boundaries. |
| 633 | create-layer Create a basic layer |
| 634 | |
| 635 | Use bitbake-layers <subcommand> --help to get help on a specific command |
| 636 | |
| 637 | The following list describes the available commands: |
| 638 | |
| 639 | - ``help:`` Displays general help or help on a specified command. |
| 640 | |
| 641 | - ``show-layers:`` Shows the current configured layers. |
| 642 | |
| 643 | - ``show-overlayed:`` Lists overlayed recipes. A recipe is overlayed |
| 644 | when a recipe with the same name exists in another layer that has a |
| 645 | higher layer priority. |
| 646 | |
| 647 | - ``show-recipes:`` Lists available recipes and the layers that |
| 648 | provide them. |
| 649 | |
| 650 | - ``show-appends:`` Lists ``.bbappend`` files and the recipe files to |
| 651 | which they apply. |
| 652 | |
| 653 | - ``show-cross-depends:`` Lists dependency relationships between |
| 654 | recipes that cross layer boundaries. |
| 655 | |
| 656 | - ``add-layer:`` Adds a layer to ``bblayers.conf``. |
| 657 | |
| 658 | - ``remove-layer:`` Removes a layer from ``bblayers.conf`` |
| 659 | |
| 660 | - ``flatten:`` Flattens the layer configuration into a separate |
| 661 | output directory. Flattening your layer configuration builds a |
| 662 | "flattened" directory that contains the contents of all layers, with |
| 663 | any overlayed recipes removed and any ``.bbappend`` files appended to |
| 664 | the corresponding recipes. You might have to perform some manual |
| 665 | cleanup of the flattened layer as follows: |
| 666 | |
| 667 | - Non-recipe files (such as patches) are overwritten. The flatten |
| 668 | command shows a warning for these files. |
| 669 | |
| 670 | - Anything beyond the normal layer setup has been added to the |
| 671 | ``layer.conf`` file. Only the lowest priority layer's |
| 672 | ``layer.conf`` is used. |
| 673 | |
| 674 | - Overridden and appended items from ``.bbappend`` files need to be |
| 675 | cleaned up. The contents of each ``.bbappend`` end up in the |
| 676 | flattened recipe. However, if there are appended or changed |
| 677 | variable values, you need to tidy these up yourself. Consider the |
| 678 | following example. Here, the ``bitbake-layers`` command adds the |
| 679 | line ``#### bbappended ...`` so that you know where the following |
| 680 | lines originate: |
| 681 | :: |
| 682 | |
| 683 | ... |
| 684 | DESCRIPTION = "A useful utility" |
| 685 | ... |
| 686 | EXTRA_OECONF = "--enable-something" |
| 687 | ... |
| 688 | |
| 689 | #### bbappended from meta-anotherlayer #### |
| 690 | |
| 691 | DESCRIPTION = "Customized utility" |
| 692 | EXTRA_OECONF += "--enable-somethingelse" |
| 693 | |
| 694 | |
| 695 | Ideally, you would tidy up these utilities as follows: |
| 696 | :: |
| 697 | |
| 698 | ... |
| 699 | DESCRIPTION = "Customized utility" |
| 700 | ... |
| 701 | EXTRA_OECONF = "--enable-something --enable-somethingelse" |
| 702 | ... |
| 703 | |
| 704 | - ``layerindex-fetch``: Fetches a layer from a layer index, along |
| 705 | with its dependent layers, and adds the layers to the |
| 706 | ``conf/bblayers.conf`` file. |
| 707 | |
| 708 | - ``layerindex-show-depends``: Finds layer dependencies from the |
| 709 | layer index. |
| 710 | |
| 711 | - ``create-layer``: Creates a basic layer. |
| 712 | |
| 713 | Creating a General Layer Using the ``bitbake-layers`` Script |
| 714 | ------------------------------------------------------------ |
| 715 | |
| 716 | The ``bitbake-layers`` script with the ``create-layer`` subcommand |
| 717 | simplifies creating a new general layer. |
| 718 | |
| 719 | .. note:: |
| 720 | |
| 721 | - For information on BSP layers, see the ":ref:`bsp-guide/bsp:bsp layers`" |
| 722 | section in the Yocto |
| 723 | Project Board Specific (BSP) Developer's Guide. |
| 724 | |
| 725 | - In order to use a layer with the OpenEmbedded build system, you |
| 726 | need to add the layer to your ``bblayers.conf`` configuration |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 727 | file. See the ":ref:`dev-manual/common-tasks:adding a layer using the \`\`bitbake-layers\`\` script`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 728 | section for more information. |
| 729 | |
| 730 | The default mode of the script's operation with this subcommand is to |
| 731 | create a layer with the following: |
| 732 | |
| 733 | - A layer priority of 6. |
| 734 | |
| 735 | - A ``conf`` subdirectory that contains a ``layer.conf`` file. |
| 736 | |
| 737 | - A ``recipes-example`` subdirectory that contains a further |
| 738 | subdirectory named ``example``, which contains an ``example.bb`` |
| 739 | recipe file. |
| 740 | |
| 741 | - A ``COPYING.MIT``, which is the license statement for the layer. The |
| 742 | script assumes you want to use the MIT license, which is typical for |
| 743 | most layers, for the contents of the layer itself. |
| 744 | |
| 745 | - A ``README`` file, which is a file describing the contents of your |
| 746 | new layer. |
| 747 | |
| 748 | In its simplest form, you can use the following command form to create a |
| 749 | layer. The command creates a layer whose name corresponds to |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 750 | "your_layer_name" in the current directory: |
| 751 | :: |
| 752 | |
| 753 | $ bitbake-layers create-layer your_layer_name |
| 754 | |
| 755 | As an example, the following command creates a layer named ``meta-scottrif`` |
| 756 | in your home directory: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 757 | :: |
| 758 | |
| 759 | $ cd /usr/home |
| 760 | $ bitbake-layers create-layer meta-scottrif |
| 761 | NOTE: Starting bitbake server... |
| 762 | Add your new layer with 'bitbake-layers add-layer meta-scottrif' |
| 763 | |
| 764 | If you want to set the priority of the layer to other than the default |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 765 | value of "6", you can either use the ``--priority`` option or you |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 766 | can edit the |
| 767 | :term:`BBFILE_PRIORITY` value |
| 768 | in the ``conf/layer.conf`` after the script creates it. Furthermore, if |
| 769 | you want to give the example recipe file some name other than the |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 770 | default, you can use the ``--example-recipe-name`` option. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 771 | |
| 772 | The easiest way to see how the ``bitbake-layers create-layer`` command |
| 773 | works is to experiment with the script. You can also read the usage |
| 774 | information by entering the following: |
| 775 | :: |
| 776 | |
| 777 | $ bitbake-layers create-layer --help |
| 778 | NOTE: Starting bitbake server... |
| 779 | usage: bitbake-layers create-layer [-h] [--priority PRIORITY] |
| 780 | [--example-recipe-name EXAMPLERECIPE] |
| 781 | layerdir |
| 782 | |
| 783 | Create a basic layer |
| 784 | |
| 785 | positional arguments: |
| 786 | layerdir Layer directory to create |
| 787 | |
| 788 | optional arguments: |
| 789 | -h, --help show this help message and exit |
| 790 | --priority PRIORITY, -p PRIORITY |
| 791 | Layer directory to create |
| 792 | --example-recipe-name EXAMPLERECIPE, -e EXAMPLERECIPE |
| 793 | Filename of the example recipe |
| 794 | |
| 795 | Adding a Layer Using the ``bitbake-layers`` Script |
| 796 | -------------------------------------------------- |
| 797 | |
| 798 | Once you create your general layer, you must add it to your |
| 799 | ``bblayers.conf`` file. Adding the layer to this configuration file |
| 800 | makes the OpenEmbedded build system aware of your layer so that it can |
| 801 | search it for metadata. |
| 802 | |
| 803 | Add your layer by using the ``bitbake-layers add-layer`` command: |
| 804 | :: |
| 805 | |
| 806 | $ bitbake-layers add-layer your_layer_name |
| 807 | |
| 808 | Here is an example that adds a |
| 809 | layer named ``meta-scottrif`` to the configuration file. Following the |
| 810 | command that adds the layer is another ``bitbake-layers`` command that |
| 811 | shows the layers that are in your ``bblayers.conf`` file: |
| 812 | :: |
| 813 | |
| 814 | $ bitbake-layers add-layer meta-scottrif |
| 815 | NOTE: Starting bitbake server... |
| 816 | Parsing recipes: 100% |##########################################################| Time: 0:00:49 |
| 817 | Parsing of 1441 .bb files complete (0 cached, 1441 parsed). 2055 targets, 56 skipped, 0 masked, 0 errors. |
| 818 | $ bitbake-layers show-layers |
| 819 | NOTE: Starting bitbake server... |
| 820 | layer path priority |
| 821 | ========================================================================== |
| 822 | meta /home/scottrif/poky/meta 5 |
| 823 | meta-poky /home/scottrif/poky/meta-poky 5 |
| 824 | meta-yocto-bsp /home/scottrif/poky/meta-yocto-bsp 5 |
| 825 | workspace /home/scottrif/poky/build/workspace 99 |
| 826 | meta-scottrif /home/scottrif/poky/build/meta-scottrif 6 |
| 827 | |
| 828 | |
| 829 | Adding the layer to this file |
| 830 | enables the build system to locate the layer during the build. |
| 831 | |
| 832 | .. note:: |
| 833 | |
| 834 | During a build, the OpenEmbedded build system looks in the layers |
| 835 | from the top of the list down to the bottom in that order. |
| 836 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 837 | Customizing Images |
| 838 | ================== |
| 839 | |
| 840 | You can customize images to satisfy particular requirements. This |
| 841 | section describes several methods and provides guidelines for each. |
| 842 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 843 | Customizing Images Using ``local.conf`` |
| 844 | --------------------------------------- |
| 845 | |
| 846 | Probably the easiest way to customize an image is to add a package by |
| 847 | way of the ``local.conf`` configuration file. Because it is limited to |
| 848 | local use, this method generally only allows you to add packages and is |
| 849 | not as flexible as creating your own customized image. When you add |
| 850 | packages using local variables this way, you need to realize that these |
| 851 | variable changes are in effect for every build and consequently affect |
| 852 | all images, which might not be what you require. |
| 853 | |
| 854 | To add a package to your image using the local configuration file, use |
| 855 | the ``IMAGE_INSTALL`` variable with the ``_append`` operator: |
| 856 | :: |
| 857 | |
| 858 | IMAGE_INSTALL_append = " strace" |
| 859 | |
| 860 | Use of the syntax is important - |
| 861 | specifically, the space between the quote and the package name, which is |
| 862 | ``strace`` in this example. This space is required since the ``_append`` |
| 863 | operator does not add the space. |
| 864 | |
| 865 | Furthermore, you must use ``_append`` instead of the ``+=`` operator if |
| 866 | you want to avoid ordering issues. The reason for this is because doing |
| 867 | so unconditionally appends to the variable and avoids ordering problems |
| 868 | due to the variable being set in image recipes and ``.bbclass`` files |
| 869 | with operators like ``?=``. Using ``_append`` ensures the operation |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 870 | takes effect. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 871 | |
| 872 | As shown in its simplest use, ``IMAGE_INSTALL_append`` affects all |
| 873 | images. It is possible to extend the syntax so that the variable applies |
| 874 | to a specific image only. Here is an example: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 875 | :: |
| 876 | |
| 877 | IMAGE_INSTALL_append_pn-core-image-minimal = " strace" |
| 878 | |
| 879 | This example adds ``strace`` to the ``core-image-minimal`` image only. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 880 | |
| 881 | You can add packages using a similar approach through the |
| 882 | ``CORE_IMAGE_EXTRA_INSTALL`` variable. If you use this variable, only |
| 883 | ``core-image-*`` images are affected. |
| 884 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 885 | Customizing Images Using Custom ``IMAGE_FEATURES`` and ``EXTRA_IMAGE_FEATURES`` |
| 886 | ------------------------------------------------------------------------------- |
| 887 | |
| 888 | Another method for customizing your image is to enable or disable |
| 889 | high-level image features by using the |
| 890 | :term:`IMAGE_FEATURES` and |
| 891 | :term:`EXTRA_IMAGE_FEATURES` |
| 892 | variables. Although the functions for both variables are nearly |
| 893 | equivalent, best practices dictate using ``IMAGE_FEATURES`` from within |
| 894 | a recipe and using ``EXTRA_IMAGE_FEATURES`` from within your |
| 895 | ``local.conf`` file, which is found in the |
| 896 | :term:`Build Directory`. |
| 897 | |
| 898 | To understand how these features work, the best reference is |
| 899 | ``meta/classes/core-image.bbclass``. This class lists out the available |
| 900 | ``IMAGE_FEATURES`` of which most map to package groups while some, such |
| 901 | as ``debug-tweaks`` and ``read-only-rootfs``, resolve as general |
| 902 | configuration settings. |
| 903 | |
| 904 | In summary, the file looks at the contents of the ``IMAGE_FEATURES`` |
| 905 | variable and then maps or configures the feature accordingly. Based on |
| 906 | this information, the build system automatically adds the appropriate |
| 907 | packages or configurations to the |
| 908 | :term:`IMAGE_INSTALL` variable. |
| 909 | Effectively, you are enabling extra features by extending the class or |
| 910 | creating a custom class for use with specialized image ``.bb`` files. |
| 911 | |
| 912 | Use the ``EXTRA_IMAGE_FEATURES`` variable from within your local |
| 913 | configuration file. Using a separate area from which to enable features |
| 914 | with this variable helps you avoid overwriting the features in the image |
| 915 | recipe that are enabled with ``IMAGE_FEATURES``. The value of |
| 916 | ``EXTRA_IMAGE_FEATURES`` is added to ``IMAGE_FEATURES`` within |
| 917 | ``meta/conf/bitbake.conf``. |
| 918 | |
| 919 | To illustrate how you can use these variables to modify your image, |
| 920 | consider an example that selects the SSH server. The Yocto Project ships |
| 921 | with two SSH servers you can use with your images: Dropbear and OpenSSH. |
| 922 | Dropbear is a minimal SSH server appropriate for resource-constrained |
| 923 | environments, while OpenSSH is a well-known standard SSH server |
| 924 | implementation. By default, the ``core-image-sato`` image is configured |
| 925 | to use Dropbear. The ``core-image-full-cmdline`` and ``core-image-lsb`` |
| 926 | images both include OpenSSH. The ``core-image-minimal`` image does not |
| 927 | contain an SSH server. |
| 928 | |
| 929 | You can customize your image and change these defaults. Edit the |
| 930 | ``IMAGE_FEATURES`` variable in your recipe or use the |
| 931 | ``EXTRA_IMAGE_FEATURES`` in your ``local.conf`` file so that it |
| 932 | configures the image you are working with to include |
| 933 | ``ssh-server-dropbear`` or ``ssh-server-openssh``. |
| 934 | |
| 935 | .. note:: |
| 936 | |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 937 | See the ":ref:`ref-manual/features:image features`" section in the Yocto |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 938 | Project Reference Manual for a complete list of image features that ship |
| 939 | with the Yocto Project. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 940 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 941 | Customizing Images Using Custom .bb Files |
| 942 | ----------------------------------------- |
| 943 | |
| 944 | You can also customize an image by creating a custom recipe that defines |
| 945 | additional software as part of the image. The following example shows |
| 946 | the form for the two lines you need: |
| 947 | :: |
| 948 | |
| 949 | IMAGE_INSTALL = "packagegroup-core-x11-base package1 package2" |
| 950 | inherit core-image |
| 951 | |
| 952 | Defining the software using a custom recipe gives you total control over |
| 953 | the contents of the image. It is important to use the correct names of |
| 954 | packages in the ``IMAGE_INSTALL`` variable. You must use the |
| 955 | OpenEmbedded notation and not the Debian notation for the names (e.g. |
| 956 | ``glibc-dev`` instead of ``libc6-dev``). |
| 957 | |
| 958 | The other method for creating a custom image is to base it on an |
| 959 | existing image. For example, if you want to create an image based on |
| 960 | ``core-image-sato`` but add the additional package ``strace`` to the |
| 961 | image, copy the ``meta/recipes-sato/images/core-image-sato.bb`` to a new |
| 962 | ``.bb`` and add the following line to the end of the copy: |
| 963 | :: |
| 964 | |
| 965 | IMAGE_INSTALL += "strace" |
| 966 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 967 | Customizing Images Using Custom Package Groups |
| 968 | ---------------------------------------------- |
| 969 | |
| 970 | For complex custom images, the best approach for customizing an image is |
| 971 | to create a custom package group recipe that is used to build the image |
| 972 | or images. A good example of a package group recipe is |
| 973 | ``meta/recipes-core/packagegroups/packagegroup-base.bb``. |
| 974 | |
| 975 | If you examine that recipe, you see that the ``PACKAGES`` variable lists |
| 976 | the package group packages to produce. The ``inherit packagegroup`` |
| 977 | statement sets appropriate default values and automatically adds |
| 978 | ``-dev``, ``-dbg``, and ``-ptest`` complementary packages for each |
| 979 | package specified in the ``PACKAGES`` statement. |
| 980 | |
| 981 | .. note:: |
| 982 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 983 | The ``inherit packagegroup`` line should be located near the top of the |
| 984 | recipe, certainly before the ``PACKAGES`` statement. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 985 | |
| 986 | For each package you specify in ``PACKAGES``, you can use ``RDEPENDS`` |
| 987 | and ``RRECOMMENDS`` entries to provide a list of packages the parent |
| 988 | task package should contain. You can see examples of these further down |
| 989 | in the ``packagegroup-base.bb`` recipe. |
| 990 | |
| 991 | Here is a short, fabricated example showing the same basic pieces for a |
| 992 | hypothetical packagegroup defined in ``packagegroup-custom.bb``, where |
| 993 | the variable ``PN`` is the standard way to abbreviate the reference to |
| 994 | the full packagegroup name ``packagegroup-custom``: |
| 995 | :: |
| 996 | |
| 997 | DESCRIPTION = "My Custom Package Groups" |
| 998 | |
| 999 | inherit packagegroup |
| 1000 | |
| 1001 | PACKAGES = "\ |
| 1002 | ${PN}-apps \ |
| 1003 | ${PN}-tools \ |
| 1004 | " |
| 1005 | |
| 1006 | RDEPENDS_${PN}-apps = "\ |
| 1007 | dropbear \ |
| 1008 | portmap \ |
| 1009 | psplash" |
| 1010 | |
| 1011 | RDEPENDS_${PN}-tools = "\ |
| 1012 | oprofile \ |
| 1013 | oprofileui-server \ |
| 1014 | lttng-tools" |
| 1015 | |
| 1016 | RRECOMMENDS_${PN}-tools = "\ |
| 1017 | kernel-module-oprofile" |
| 1018 | |
| 1019 | In the previous example, two package group packages are created with |
| 1020 | their dependencies and their recommended package dependencies listed: |
| 1021 | ``packagegroup-custom-apps``, and ``packagegroup-custom-tools``. To |
| 1022 | build an image using these package group packages, you need to add |
| 1023 | ``packagegroup-custom-apps`` and/or ``packagegroup-custom-tools`` to |
| 1024 | ``IMAGE_INSTALL``. For other forms of image dependencies see the other |
| 1025 | areas of this section. |
| 1026 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1027 | Customizing an Image Hostname |
| 1028 | ----------------------------- |
| 1029 | |
| 1030 | By default, the configured hostname (i.e. ``/etc/hostname``) in an image |
| 1031 | is the same as the machine name. For example, if |
| 1032 | :term:`MACHINE` equals "qemux86", the |
| 1033 | configured hostname written to ``/etc/hostname`` is "qemux86". |
| 1034 | |
| 1035 | You can customize this name by altering the value of the "hostname" |
| 1036 | variable in the ``base-files`` recipe using either an append file or a |
| 1037 | configuration file. Use the following in an append file: |
| 1038 | :: |
| 1039 | |
| 1040 | hostname = "myhostname" |
| 1041 | |
| 1042 | Use the following in a configuration file: |
| 1043 | :: |
| 1044 | |
| 1045 | hostname_pn-base-files = "myhostname" |
| 1046 | |
| 1047 | Changing the default value of the variable "hostname" can be useful in |
| 1048 | certain situations. For example, suppose you need to do extensive |
| 1049 | testing on an image and you would like to easily identify the image |
| 1050 | under test from existing images with typical default hostnames. In this |
| 1051 | situation, you could change the default hostname to "testme", which |
| 1052 | results in all the images using the name "testme". Once testing is |
| 1053 | complete and you do not need to rebuild the image for test any longer, |
| 1054 | you can easily reset the default hostname. |
| 1055 | |
| 1056 | Another point of interest is that if you unset the variable, the image |
| 1057 | will have no default hostname in the filesystem. Here is an example that |
| 1058 | unsets the variable in a configuration file: |
| 1059 | :: |
| 1060 | |
| 1061 | hostname_pn-base-files = "" |
| 1062 | |
| 1063 | Having no default hostname in the filesystem is suitable for |
| 1064 | environments that use dynamic hostnames such as virtual machines. |
| 1065 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1066 | Writing a New Recipe |
| 1067 | ==================== |
| 1068 | |
| 1069 | Recipes (``.bb`` files) are fundamental components in the Yocto Project |
| 1070 | environment. Each software component built by the OpenEmbedded build |
| 1071 | system requires a recipe to define the component. This section describes |
| 1072 | how to create, write, and test a new recipe. |
| 1073 | |
| 1074 | .. note:: |
| 1075 | |
| 1076 | For information on variables that are useful for recipes and for |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1077 | information about recipe naming issues, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 1078 | ":ref:`ref-manual/varlocality:recipes`" section of the Yocto Project |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1079 | Reference Manual. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1080 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1081 | Overview |
| 1082 | -------- |
| 1083 | |
| 1084 | The following figure shows the basic process for creating a new recipe. |
| 1085 | The remainder of the section provides details for the steps. |
| 1086 | |
| 1087 | .. image:: figures/recipe-workflow.png |
| 1088 | :align: center |
| 1089 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1090 | Locate or Automatically Create a Base Recipe |
| 1091 | -------------------------------------------- |
| 1092 | |
| 1093 | You can always write a recipe from scratch. However, three choices exist |
| 1094 | that can help you quickly get a start on a new recipe: |
| 1095 | |
| 1096 | - ``devtool add``: A command that assists in creating a recipe and an |
| 1097 | environment conducive to development. |
| 1098 | |
| 1099 | - ``recipetool create``: A command provided by the Yocto Project that |
| 1100 | automates creation of a base recipe based on the source files. |
| 1101 | |
| 1102 | - *Existing Recipes:* Location and modification of an existing recipe |
| 1103 | that is similar in function to the recipe you need. |
| 1104 | |
| 1105 | .. note:: |
| 1106 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1107 | For information on recipe syntax, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 1108 | ":ref:`dev-manual/common-tasks:recipe syntax`" section. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1109 | |
| 1110 | Creating the Base Recipe Using ``devtool add`` |
| 1111 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1112 | |
| 1113 | The ``devtool add`` command uses the same logic for auto-creating the |
| 1114 | recipe as ``recipetool create``, which is listed below. Additionally, |
| 1115 | however, ``devtool add`` sets up an environment that makes it easy for |
| 1116 | you to patch the source and to make changes to the recipe as is often |
| 1117 | necessary when adding a recipe to build a new piece of software to be |
| 1118 | included in a build. |
| 1119 | |
| 1120 | You can find a complete description of the ``devtool add`` command in |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 1121 | the ":ref:`sdk-manual/extensible:a closer look at \`\`devtool add\`\``" section |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1122 | in the Yocto Project Application Development and the Extensible Software |
| 1123 | Development Kit (eSDK) manual. |
| 1124 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1125 | Creating the Base Recipe Using ``recipetool create`` |
| 1126 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1127 | |
| 1128 | ``recipetool create`` automates creation of a base recipe given a set of |
| 1129 | source code files. As long as you can extract or point to the source |
| 1130 | files, the tool will construct a recipe and automatically configure all |
| 1131 | pre-build information into the recipe. For example, suppose you have an |
| 1132 | application that builds using Autotools. Creating the base recipe using |
| 1133 | ``recipetool`` results in a recipe that has the pre-build dependencies, |
| 1134 | license requirements, and checksums configured. |
| 1135 | |
| 1136 | To run the tool, you just need to be in your |
| 1137 | :term:`Build Directory` and have sourced the |
| 1138 | build environment setup script (i.e. |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1139 | :ref:`structure-core-script`). |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1140 | To get help on the tool, use the following command: |
| 1141 | :: |
| 1142 | |
| 1143 | $ recipetool -h |
| 1144 | NOTE: Starting bitbake server... |
| 1145 | usage: recipetool [-d] [-q] [--color COLOR] [-h] <subcommand> ... |
| 1146 | |
| 1147 | OpenEmbedded recipe tool |
| 1148 | |
| 1149 | options: |
| 1150 | -d, --debug Enable debug output |
| 1151 | -q, --quiet Print only errors |
| 1152 | --color COLOR Colorize output (where COLOR is auto, always, never) |
| 1153 | -h, --help show this help message and exit |
| 1154 | |
| 1155 | subcommands: |
| 1156 | create Create a new recipe |
| 1157 | newappend Create a bbappend for the specified target in the specified |
| 1158 | layer |
| 1159 | setvar Set a variable within a recipe |
| 1160 | appendfile Create/update a bbappend to replace a target file |
| 1161 | appendsrcfiles Create/update a bbappend to add or replace source files |
| 1162 | appendsrcfile Create/update a bbappend to add or replace a source file |
| 1163 | Use recipetool <subcommand> --help to get help on a specific command |
| 1164 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1165 | Running ``recipetool create -o OUTFILE`` creates the base recipe and |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1166 | locates it properly in the layer that contains your source files. |
| 1167 | Following are some syntax examples: |
| 1168 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1169 | - Use this syntax to generate a recipe based on source. Once generated, |
| 1170 | the recipe resides in the existing source code layer: |
| 1171 | :: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1172 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1173 | recipetool create -o OUTFILE source |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1174 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1175 | - Use this syntax to generate a recipe using code that |
| 1176 | you extract from source. The extracted code is placed in its own layer |
| 1177 | defined by ``EXTERNALSRC``. |
| 1178 | :: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1179 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1180 | recipetool create -o OUTFILE -x EXTERNALSRC source |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1181 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1182 | - Use this syntax to generate a recipe based on source. The options |
| 1183 | direct ``recipetool`` to generate debugging information. Once generated, |
| 1184 | the recipe resides in the existing source code layer: |
| 1185 | :: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1186 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1187 | recipetool create -d -o OUTFILE source |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1188 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1189 | Locating and Using a Similar Recipe |
| 1190 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1191 | |
| 1192 | Before writing a recipe from scratch, it is often useful to discover |
| 1193 | whether someone else has already written one that meets (or comes close |
| 1194 | to meeting) your needs. The Yocto Project and OpenEmbedded communities |
| 1195 | maintain many recipes that might be candidates for what you are doing. |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 1196 | You can find a good central index of these recipes in the |
| 1197 | :oe_layerindex:`OpenEmbedded Layer Index <>`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1198 | |
| 1199 | Working from an existing recipe or a skeleton recipe is the best way to |
| 1200 | get started. Here are some points on both methods: |
| 1201 | |
| 1202 | - *Locate and modify a recipe that is close to what you want to do:* |
| 1203 | This method works when you are familiar with the current recipe |
| 1204 | space. The method does not work so well for those new to the Yocto |
| 1205 | Project or writing recipes. |
| 1206 | |
| 1207 | Some risks associated with this method are using a recipe that has |
| 1208 | areas totally unrelated to what you are trying to accomplish with |
| 1209 | your recipe, not recognizing areas of the recipe that you might have |
| 1210 | to add from scratch, and so forth. All these risks stem from |
| 1211 | unfamiliarity with the existing recipe space. |
| 1212 | |
| 1213 | - *Use and modify the following skeleton recipe:* If for some reason |
| 1214 | you do not want to use ``recipetool`` and you cannot find an existing |
| 1215 | recipe that is close to meeting your needs, you can use the following |
| 1216 | structure to provide the fundamental areas of a new recipe. |
| 1217 | :: |
| 1218 | |
| 1219 | DESCRIPTION = "" |
| 1220 | HOMEPAGE = "" |
| 1221 | LICENSE = "" |
| 1222 | SECTION = "" |
| 1223 | DEPENDS = "" |
| 1224 | LIC_FILES_CHKSUM = "" |
| 1225 | |
| 1226 | SRC_URI = "" |
| 1227 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1228 | Storing and Naming the Recipe |
| 1229 | ----------------------------- |
| 1230 | |
| 1231 | Once you have your base recipe, you should put it in your own layer and |
| 1232 | name it appropriately. Locating it correctly ensures that the |
| 1233 | OpenEmbedded build system can find it when you use BitBake to process |
| 1234 | the recipe. |
| 1235 | |
| 1236 | - *Storing Your Recipe:* The OpenEmbedded build system locates your |
| 1237 | recipe through the layer's ``conf/layer.conf`` file and the |
| 1238 | :term:`BBFILES` variable. This |
| 1239 | variable sets up a path from which the build system can locate |
| 1240 | recipes. Here is the typical use: |
| 1241 | :: |
| 1242 | |
| 1243 | BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \ |
| 1244 | ${LAYERDIR}/recipes-*/*/*.bbappend" |
| 1245 | |
| 1246 | Consequently, you need to be sure you locate your new recipe inside |
| 1247 | your layer such that it can be found. |
| 1248 | |
| 1249 | You can find more information on how layers are structured in the |
| 1250 | "`Understanding and Creating |
| 1251 | Layers <#understanding-and-creating-layers>`__" section. |
| 1252 | |
| 1253 | - *Naming Your Recipe:* When you name your recipe, you need to follow |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1254 | this naming convention: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1255 | :: |
| 1256 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1257 | basename_version.bb |
| 1258 | |
| 1259 | Use lower-cased characters and do not include the reserved suffixes |
| 1260 | ``-native``, ``-cross``, ``-initial``, or ``-dev`` casually (i.e. do not use |
| 1261 | them as part of your recipe name unless the string applies). Here are some |
| 1262 | examples: |
| 1263 | |
| 1264 | .. code-block:: none |
| 1265 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1266 | cups_1.7.0.bb |
| 1267 | gawk_4.0.2.bb |
| 1268 | irssi_0.8.16-rc1.bb |
| 1269 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1270 | Running a Build on the Recipe |
| 1271 | ----------------------------- |
| 1272 | |
| 1273 | Creating a new recipe is usually an iterative process that requires |
| 1274 | using BitBake to process the recipe multiple times in order to |
| 1275 | progressively discover and add information to the recipe file. |
| 1276 | |
| 1277 | Assuming you have sourced the build environment setup script (i.e. |
| 1278 | :ref:`structure-core-script`) and you are in |
| 1279 | the :term:`Build Directory`, use |
| 1280 | BitBake to process your recipe. All you need to provide is the |
| 1281 | ``basename`` of the recipe as described in the previous section: |
| 1282 | :: |
| 1283 | |
| 1284 | $ bitbake basename |
| 1285 | |
| 1286 | During the build, the OpenEmbedded build system creates a temporary work |
| 1287 | directory for each recipe |
| 1288 | (``${``\ :term:`WORKDIR`\ ``}``) |
| 1289 | where it keeps extracted source files, log files, intermediate |
| 1290 | compilation and packaging files, and so forth. |
| 1291 | |
| 1292 | The path to the per-recipe temporary work directory depends on the |
| 1293 | context in which it is being built. The quickest way to find this path |
| 1294 | is to have BitBake return it by running the following: |
| 1295 | :: |
| 1296 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1297 | $ bitbake -e basename | grep ^WORKDIR= |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1298 | |
| 1299 | As an example, assume a Source Directory |
| 1300 | top-level folder named ``poky``, a default Build Directory at |
| 1301 | ``poky/build``, and a ``qemux86-poky-linux`` machine target system. |
| 1302 | Furthermore, suppose your recipe is named ``foo_1.3.0.bb``. In this |
| 1303 | case, the work directory the build system uses to build the package |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1304 | would be as follows: |
| 1305 | :: |
| 1306 | |
| 1307 | poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0 |
| 1308 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1309 | Inside this directory you can find sub-directories such as ``image``, |
| 1310 | ``packages-split``, and ``temp``. After the build, you can examine these |
| 1311 | to determine how well the build went. |
| 1312 | |
| 1313 | .. note:: |
| 1314 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1315 | You can find log files for each task in the recipe's ``temp`` |
| 1316 | directory (e.g. ``poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0/temp``). |
| 1317 | Log files are named ``log.taskname`` (e.g. ``log.do_configure``, |
| 1318 | ``log.do_fetch``, and ``log.do_compile``). |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1319 | |
| 1320 | You can find more information about the build process in |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 1321 | ":doc:`/overview-manual/development-environment`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1322 | chapter of the Yocto Project Overview and Concepts Manual. |
| 1323 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1324 | Fetching Code |
| 1325 | ------------- |
| 1326 | |
| 1327 | The first thing your recipe must do is specify how to fetch the source |
| 1328 | files. Fetching is controlled mainly through the |
| 1329 | :term:`SRC_URI` variable. Your recipe |
| 1330 | must have a ``SRC_URI`` variable that points to where the source is |
| 1331 | located. For a graphical representation of source locations, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 1332 | ":ref:`overview-manual/concepts:sources`" section in |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1333 | the Yocto Project Overview and Concepts Manual. |
| 1334 | |
| 1335 | The :ref:`ref-tasks-fetch` task uses |
| 1336 | the prefix of each entry in the ``SRC_URI`` variable value to determine |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 1337 | which :ref:`fetcher <bitbake:bitbake-user-manual/bitbake-user-manual-fetching:fetchers>` to use to get your |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1338 | source files. It is the ``SRC_URI`` variable that triggers the fetcher. |
| 1339 | The :ref:`ref-tasks-patch` task uses |
| 1340 | the variable after source is fetched to apply patches. The OpenEmbedded |
| 1341 | build system uses |
| 1342 | :term:`FILESOVERRIDES` for |
| 1343 | scanning directory locations for local files in ``SRC_URI``. |
| 1344 | |
| 1345 | The ``SRC_URI`` variable in your recipe must define each unique location |
| 1346 | for your source files. It is good practice to not hard-code version |
| 1347 | numbers in a URL used in ``SRC_URI``. Rather than hard-code these |
| 1348 | values, use ``${``\ :term:`PV`\ ``}``, |
| 1349 | which causes the fetch process to use the version specified in the |
| 1350 | recipe filename. Specifying the version in this manner means that |
| 1351 | upgrading the recipe to a future version is as simple as renaming the |
| 1352 | recipe to match the new version. |
| 1353 | |
| 1354 | Here is a simple example from the |
| 1355 | ``meta/recipes-devtools/strace/strace_5.5.bb`` recipe where the source |
| 1356 | comes from a single tarball. Notice the use of the |
| 1357 | :term:`PV` variable: |
| 1358 | :: |
| 1359 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1360 | SRC_URI = "https://strace.io/files/${PV}/strace-${PV}.tar.xz \ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1361 | |
| 1362 | Files mentioned in ``SRC_URI`` whose names end in a typical archive |
| 1363 | extension (e.g. ``.tar``, ``.tar.gz``, ``.tar.bz2``, ``.zip``, and so |
| 1364 | forth), are automatically extracted during the |
| 1365 | :ref:`ref-tasks-unpack` task. For |
| 1366 | another example that specifies these types of files, see the |
| 1367 | "`Autotooled Package <#new-recipe-autotooled-package>`__" section. |
| 1368 | |
| 1369 | Another way of specifying source is from an SCM. For Git repositories, |
| 1370 | you must specify :term:`SRCREV` and |
| 1371 | you should specify :term:`PV` to include |
| 1372 | the revision with :term:`SRCPV`. Here |
| 1373 | is an example from the recipe |
| 1374 | ``meta/recipes-kernel/blktrace/blktrace_git.bb``: |
| 1375 | :: |
| 1376 | |
| 1377 | SRCREV = "d6918c8832793b4205ed3bfede78c2f915c23385" |
| 1378 | |
| 1379 | PR = "r6" |
| 1380 | PV = "1.0.5+git${SRCPV}" |
| 1381 | |
| 1382 | SRC_URI = "git://git.kernel.dk/blktrace.git \ |
| 1383 | file://ldflags.patch" |
| 1384 | |
| 1385 | If your ``SRC_URI`` statement includes URLs pointing to individual files |
| 1386 | fetched from a remote server other than a version control system, |
| 1387 | BitBake attempts to verify the files against checksums defined in your |
| 1388 | recipe to ensure they have not been tampered with or otherwise modified |
| 1389 | since the recipe was written. Two checksums are used: |
| 1390 | ``SRC_URI[md5sum]`` and ``SRC_URI[sha256sum]``. |
| 1391 | |
| 1392 | If your ``SRC_URI`` variable points to more than a single URL (excluding |
| 1393 | SCM URLs), you need to provide the ``md5`` and ``sha256`` checksums for |
| 1394 | each URL. For these cases, you provide a name for each URL as part of |
| 1395 | the ``SRC_URI`` and then reference that name in the subsequent checksum |
| 1396 | statements. Here is an example combining lines from the files |
| 1397 | ``git.inc`` and ``git_2.24.1.bb``: |
| 1398 | :: |
| 1399 | |
| 1400 | SRC_URI = "${KERNELORG_MIRROR}/software/scm/git/git-${PV}.tar.gz;name=tarball \ |
| 1401 | ${KERNELORG_MIRROR}/software/scm/git/git-manpages-${PV}.tar.gz;name=manpages" |
| 1402 | |
| 1403 | SRC_URI[tarball.md5sum] = "166bde96adbbc11c8843d4f8f4f9811b" |
| 1404 | SRC_URI[tarball.sha256sum] = "ad5334956301c86841eb1e5b1bb20884a6bad89a10a6762c958220c7cf64da02" |
| 1405 | SRC_URI[manpages.md5sum] = "31c2272a8979022497ba3d4202df145d" |
| 1406 | SRC_URI[manpages.sha256sum] = "9a7ae3a093bea39770eb96ca3e5b40bff7af0b9f6123f089d7821d0e5b8e1230" |
| 1407 | |
| 1408 | Proper values for ``md5`` and ``sha256`` checksums might be available |
| 1409 | with other signatures on the download page for the upstream source (e.g. |
| 1410 | ``md5``, ``sha1``, ``sha256``, ``GPG``, and so forth). Because the |
| 1411 | OpenEmbedded build system only deals with ``sha256sum`` and ``md5sum``, |
| 1412 | you should verify all the signatures you find by hand. |
| 1413 | |
| 1414 | If no ``SRC_URI`` checksums are specified when you attempt to build the |
| 1415 | recipe, or you provide an incorrect checksum, the build will produce an |
| 1416 | error for each missing or incorrect checksum. As part of the error |
| 1417 | message, the build system provides the checksum string corresponding to |
| 1418 | the fetched file. Once you have the correct checksums, you can copy and |
| 1419 | paste them into your recipe and then run the build again to continue. |
| 1420 | |
| 1421 | .. note:: |
| 1422 | |
| 1423 | As mentioned, if the upstream source provides signatures for |
| 1424 | verifying the downloaded source code, you should verify those |
| 1425 | manually before setting the checksum values in the recipe and |
| 1426 | continuing with the build. |
| 1427 | |
| 1428 | This final example is a bit more complicated and is from the |
| 1429 | ``meta/recipes-sato/rxvt-unicode/rxvt-unicode_9.20.bb`` recipe. The |
| 1430 | example's ``SRC_URI`` statement identifies multiple files as the source |
| 1431 | files for the recipe: a tarball, a patch file, a desktop file, and an |
| 1432 | icon. |
| 1433 | :: |
| 1434 | |
| 1435 | SRC_URI = "http://dist.schmorp.de/rxvt-unicode/Attic/rxvt-unicode-${PV}.tar.bz2 \ |
| 1436 | file://xwc.patch \ |
| 1437 | file://rxvt.desktop \ |
| 1438 | file://rxvt.png" |
| 1439 | |
| 1440 | When you specify local files using the ``file://`` URI protocol, the |
| 1441 | build system fetches files from the local machine. The path is relative |
| 1442 | to the :term:`FILESPATH` variable |
| 1443 | and searches specific directories in a certain order: |
| 1444 | ``${``\ :term:`BP`\ ``}``, |
| 1445 | ``${``\ :term:`BPN`\ ``}``, and |
| 1446 | ``files``. The directories are assumed to be subdirectories of the |
| 1447 | directory in which the recipe or append file resides. For another |
| 1448 | example that specifies these types of files, see the "`Single .c File |
| 1449 | Package (Hello |
| 1450 | World!) <#new-recipe-single-c-file-package-hello-world>`__" section. |
| 1451 | |
| 1452 | The previous example also specifies a patch file. Patch files are files |
| 1453 | whose names usually end in ``.patch`` or ``.diff`` but can end with |
| 1454 | compressed suffixes such as ``diff.gz`` and ``patch.bz2``, for example. |
| 1455 | The build system automatically applies patches as described in the |
| 1456 | "`Patching Code <#new-recipe-patching-code>`__" section. |
| 1457 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1458 | Unpacking Code |
| 1459 | -------------- |
| 1460 | |
| 1461 | During the build, the |
| 1462 | :ref:`ref-tasks-unpack` task unpacks |
| 1463 | the source with ``${``\ :term:`S`\ ``}`` |
| 1464 | pointing to where it is unpacked. |
| 1465 | |
| 1466 | If you are fetching your source files from an upstream source archived |
| 1467 | tarball and the tarball's internal structure matches the common |
| 1468 | convention of a top-level subdirectory named |
| 1469 | ``${``\ :term:`BPN`\ ``}-${``\ :term:`PV`\ ``}``, |
| 1470 | then you do not need to set ``S``. However, if ``SRC_URI`` specifies to |
| 1471 | fetch source from an archive that does not use this convention, or from |
| 1472 | an SCM like Git or Subversion, your recipe needs to define ``S``. |
| 1473 | |
| 1474 | If processing your recipe using BitBake successfully unpacks the source |
| 1475 | files, you need to be sure that the directory pointed to by ``${S}`` |
| 1476 | matches the structure of the source. |
| 1477 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1478 | Patching Code |
| 1479 | ------------- |
| 1480 | |
| 1481 | Sometimes it is necessary to patch code after it has been fetched. Any |
| 1482 | files mentioned in ``SRC_URI`` whose names end in ``.patch`` or |
| 1483 | ``.diff`` or compressed versions of these suffixes (e.g. ``diff.gz`` are |
| 1484 | treated as patches. The |
| 1485 | :ref:`ref-tasks-patch` task |
| 1486 | automatically applies these patches. |
| 1487 | |
| 1488 | The build system should be able to apply patches with the "-p1" option |
| 1489 | (i.e. one directory level in the path will be stripped off). If your |
| 1490 | patch needs to have more directory levels stripped off, specify the |
| 1491 | number of levels using the "striplevel" option in the ``SRC_URI`` entry |
| 1492 | for the patch. Alternatively, if your patch needs to be applied in a |
| 1493 | specific subdirectory that is not specified in the patch file, use the |
| 1494 | "patchdir" option in the entry. |
| 1495 | |
| 1496 | As with all local files referenced in |
| 1497 | :term:`SRC_URI` using ``file://``, |
| 1498 | you should place patch files in a directory next to the recipe either |
| 1499 | named the same as the base name of the recipe |
| 1500 | (:term:`BP` and |
| 1501 | :term:`BPN`) or "files". |
| 1502 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1503 | Licensing |
| 1504 | --------- |
| 1505 | |
| 1506 | Your recipe needs to have both the |
| 1507 | :term:`LICENSE` and |
| 1508 | :term:`LIC_FILES_CHKSUM` |
| 1509 | variables: |
| 1510 | |
| 1511 | - ``LICENSE``: This variable specifies the license for the software. |
| 1512 | If you do not know the license under which the software you are |
| 1513 | building is distributed, you should go to the source code and look |
| 1514 | for that information. Typical files containing this information |
| 1515 | include ``COPYING``, ``LICENSE``, and ``README`` files. You could |
| 1516 | also find the information near the top of a source file. For example, |
| 1517 | given a piece of software licensed under the GNU General Public |
| 1518 | License version 2, you would set ``LICENSE`` as follows: |
| 1519 | :: |
| 1520 | |
| 1521 | LICENSE = "GPLv2" |
| 1522 | |
| 1523 | The licenses you specify within ``LICENSE`` can have any name as long |
| 1524 | as you do not use spaces, since spaces are used as separators between |
| 1525 | license names. For standard licenses, use the names of the files in |
| 1526 | ``meta/files/common-licenses/`` or the ``SPDXLICENSEMAP`` flag names |
| 1527 | defined in ``meta/conf/licenses.conf``. |
| 1528 | |
| 1529 | - ``LIC_FILES_CHKSUM``: The OpenEmbedded build system uses this |
| 1530 | variable to make sure the license text has not changed. If it has, |
| 1531 | the build produces an error and it affords you the chance to figure |
| 1532 | it out and correct the problem. |
| 1533 | |
| 1534 | You need to specify all applicable licensing files for the software. |
| 1535 | At the end of the configuration step, the build process will compare |
| 1536 | the checksums of the files to be sure the text has not changed. Any |
| 1537 | differences result in an error with the message containing the |
| 1538 | current checksum. For more explanation and examples of how to set the |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1539 | ``LIC_FILES_CHKSUM`` variable, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 1540 | ":ref:`dev-manual/common-tasks:tracking license changes`" section. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1541 | |
| 1542 | To determine the correct checksum string, you can list the |
| 1543 | appropriate files in the ``LIC_FILES_CHKSUM`` variable with incorrect |
| 1544 | md5 strings, attempt to build the software, and then note the |
| 1545 | resulting error messages that will report the correct md5 strings. |
| 1546 | See the "`Fetching Code <#new-recipe-fetching-code>`__" section for |
| 1547 | additional information. |
| 1548 | |
| 1549 | Here is an example that assumes the software has a ``COPYING`` file: |
| 1550 | :: |
| 1551 | |
| 1552 | LIC_FILES_CHKSUM = "file://COPYING;md5=xxx" |
| 1553 | |
| 1554 | When you try to build the |
| 1555 | software, the build system will produce an error and give you the |
| 1556 | correct string that you can substitute into the recipe file for a |
| 1557 | subsequent build. |
| 1558 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1559 | Dependencies |
| 1560 | ------------ |
| 1561 | |
| 1562 | Most software packages have a short list of other packages that they |
| 1563 | require, which are called dependencies. These dependencies fall into two |
| 1564 | main categories: build-time dependencies, which are required when the |
| 1565 | software is built; and runtime dependencies, which are required to be |
| 1566 | installed on the target in order for the software to run. |
| 1567 | |
| 1568 | Within a recipe, you specify build-time dependencies using the |
| 1569 | :term:`DEPENDS` variable. Although |
| 1570 | nuances exist, items specified in ``DEPENDS`` should be names of other |
| 1571 | recipes. It is important that you specify all build-time dependencies |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1572 | explicitly. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1573 | |
| 1574 | Another consideration is that configure scripts might automatically |
| 1575 | check for optional dependencies and enable corresponding functionality |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1576 | if those dependencies are found. If you wish to make a recipe that is |
| 1577 | more generally useful (e.g. publish the recipe in a layer for others to |
| 1578 | use), instead of hard-disabling the functionality, you can use the |
| 1579 | :term:`PACKAGECONFIG` variable to allow functionality and the |
| 1580 | corresponding dependencies to be enabled and disabled easily by other |
| 1581 | users of the recipe. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1582 | |
| 1583 | Similar to build-time dependencies, you specify runtime dependencies |
| 1584 | through a variable - |
| 1585 | :term:`RDEPENDS`, which is |
| 1586 | package-specific. All variables that are package-specific need to have |
| 1587 | the name of the package added to the end as an override. Since the main |
| 1588 | package for a recipe has the same name as the recipe, and the recipe's |
| 1589 | name can be found through the |
| 1590 | ``${``\ :term:`PN`\ ``}`` variable, then |
| 1591 | you specify the dependencies for the main package by setting |
| 1592 | ``RDEPENDS_${PN}``. If the package were named ``${PN}-tools``, then you |
| 1593 | would set ``RDEPENDS_${PN}-tools``, and so forth. |
| 1594 | |
| 1595 | Some runtime dependencies will be set automatically at packaging time. |
| 1596 | These dependencies include any shared library dependencies (i.e. if a |
| 1597 | package "example" contains "libexample" and another package "mypackage" |
| 1598 | contains a binary that links to "libexample" then the OpenEmbedded build |
| 1599 | system will automatically add a runtime dependency to "mypackage" on |
| 1600 | "example"). See the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 1601 | ":ref:`overview-manual/concepts:automatically added runtime dependencies`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1602 | section in the Yocto Project Overview and Concepts Manual for further |
| 1603 | details. |
| 1604 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1605 | Configuring the Recipe |
| 1606 | ---------------------- |
| 1607 | |
| 1608 | Most software provides some means of setting build-time configuration |
| 1609 | options before compilation. Typically, setting these options is |
| 1610 | accomplished by running a configure script with options, or by modifying |
| 1611 | a build configuration file. |
| 1612 | |
| 1613 | .. note:: |
| 1614 | |
| 1615 | As of Yocto Project Release 1.7, some of the core recipes that |
| 1616 | package binary configuration scripts now disable the scripts due to |
| 1617 | the scripts previously requiring error-prone path substitution. The |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1618 | OpenEmbedded build system uses ``pkg-config`` now, which is much more |
| 1619 | robust. You can find a list of the ``*-config`` scripts that are disabled |
| 1620 | in the ":ref:`migration-1.7-binary-configuration-scripts-disabled`" section |
| 1621 | in the Yocto Project Reference Manual. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1622 | |
| 1623 | A major part of build-time configuration is about checking for |
| 1624 | build-time dependencies and possibly enabling optional functionality as |
| 1625 | a result. You need to specify any build-time dependencies for the |
| 1626 | software you are building in your recipe's |
| 1627 | :term:`DEPENDS` value, in terms of |
| 1628 | other recipes that satisfy those dependencies. You can often find |
| 1629 | build-time or runtime dependencies described in the software's |
| 1630 | documentation. |
| 1631 | |
| 1632 | The following list provides configuration items of note based on how |
| 1633 | your software is built: |
| 1634 | |
| 1635 | - *Autotools:* If your source files have a ``configure.ac`` file, then |
| 1636 | your software is built using Autotools. If this is the case, you just |
| 1637 | need to worry about modifying the configuration. |
| 1638 | |
| 1639 | When using Autotools, your recipe needs to inherit the |
| 1640 | :ref:`autotools <ref-classes-autotools>` class |
| 1641 | and your recipe does not have to contain a |
| 1642 | :ref:`ref-tasks-configure` task. |
| 1643 | However, you might still want to make some adjustments. For example, |
| 1644 | you can set |
| 1645 | :term:`EXTRA_OECONF` or |
| 1646 | :term:`PACKAGECONFIG_CONFARGS` |
| 1647 | to pass any needed configure options that are specific to the recipe. |
| 1648 | |
| 1649 | - *CMake:* If your source files have a ``CMakeLists.txt`` file, then |
| 1650 | your software is built using CMake. If this is the case, you just |
| 1651 | need to worry about modifying the configuration. |
| 1652 | |
| 1653 | When you use CMake, your recipe needs to inherit the |
| 1654 | :ref:`cmake <ref-classes-cmake>` class and your |
| 1655 | recipe does not have to contain a |
| 1656 | :ref:`ref-tasks-configure` task. |
| 1657 | You can make some adjustments by setting |
| 1658 | :term:`EXTRA_OECMAKE` to |
| 1659 | pass any needed configure options that are specific to the recipe. |
| 1660 | |
| 1661 | .. note:: |
| 1662 | |
| 1663 | If you need to install one or more custom CMake toolchain files |
| 1664 | that are supplied by the application you are building, install the |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1665 | files to ``${D}${datadir}/cmake/Modules`` during ``do_install``. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1666 | |
| 1667 | - *Other:* If your source files do not have a ``configure.ac`` or |
| 1668 | ``CMakeLists.txt`` file, then your software is built using some |
| 1669 | method other than Autotools or CMake. If this is the case, you |
| 1670 | normally need to provide a |
| 1671 | :ref:`ref-tasks-configure` task |
| 1672 | in your recipe unless, of course, there is nothing to configure. |
| 1673 | |
| 1674 | Even if your software is not being built by Autotools or CMake, you |
| 1675 | still might not need to deal with any configuration issues. You need |
| 1676 | to determine if configuration is even a required step. You might need |
| 1677 | to modify a Makefile or some configuration file used for the build to |
| 1678 | specify necessary build options. Or, perhaps you might need to run a |
| 1679 | provided, custom configure script with the appropriate options. |
| 1680 | |
| 1681 | For the case involving a custom configure script, you would run |
| 1682 | ``./configure --help`` and look for the options you need to set. |
| 1683 | |
| 1684 | Once configuration succeeds, it is always good practice to look at the |
| 1685 | ``log.do_configure`` file to ensure that the appropriate options have |
| 1686 | been enabled and no additional build-time dependencies need to be added |
| 1687 | to ``DEPENDS``. For example, if the configure script reports that it |
| 1688 | found something not mentioned in ``DEPENDS``, or that it did not find |
| 1689 | something that it needed for some desired optional functionality, then |
| 1690 | you would need to add those to ``DEPENDS``. Looking at the log might |
| 1691 | also reveal items being checked for, enabled, or both that you do not |
| 1692 | want, or items not being found that are in ``DEPENDS``, in which case |
| 1693 | you would need to look at passing extra options to the configure script |
| 1694 | as needed. For reference information on configure options specific to |
| 1695 | the software you are building, you can consult the output of the |
| 1696 | ``./configure --help`` command within ``${S}`` or consult the software's |
| 1697 | upstream documentation. |
| 1698 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1699 | Using Headers to Interface with Devices |
| 1700 | --------------------------------------- |
| 1701 | |
| 1702 | If your recipe builds an application that needs to communicate with some |
| 1703 | device or needs an API into a custom kernel, you will need to provide |
| 1704 | appropriate header files. Under no circumstances should you ever modify |
| 1705 | the existing |
| 1706 | ``meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc`` file. |
| 1707 | These headers are used to build ``libc`` and must not be compromised |
| 1708 | with custom or machine-specific header information. If you customize |
| 1709 | ``libc`` through modified headers all other applications that use |
| 1710 | ``libc`` thus become affected. |
| 1711 | |
| 1712 | .. note:: |
| 1713 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1714 | Never copy and customize the ``libc`` header file (i.e. |
| 1715 | ``meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc``). |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1716 | |
| 1717 | The correct way to interface to a device or custom kernel is to use a |
| 1718 | separate package that provides the additional headers for the driver or |
| 1719 | other unique interfaces. When doing so, your application also becomes |
| 1720 | responsible for creating a dependency on that specific provider. |
| 1721 | |
| 1722 | Consider the following: |
| 1723 | |
| 1724 | - Never modify ``linux-libc-headers.inc``. Consider that file to be |
| 1725 | part of the ``libc`` system, and not something you use to access the |
| 1726 | kernel directly. You should access ``libc`` through specific ``libc`` |
| 1727 | calls. |
| 1728 | |
| 1729 | - Applications that must talk directly to devices should either provide |
| 1730 | necessary headers themselves, or establish a dependency on a special |
| 1731 | headers package that is specific to that driver. |
| 1732 | |
| 1733 | For example, suppose you want to modify an existing header that adds I/O |
| 1734 | control or network support. If the modifications are used by a small |
| 1735 | number programs, providing a unique version of a header is easy and has |
| 1736 | little impact. When doing so, bear in mind the guidelines in the |
| 1737 | previous list. |
| 1738 | |
| 1739 | .. note:: |
| 1740 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1741 | If for some reason your changes need to modify the behavior of the ``libc``, |
| 1742 | and subsequently all other applications on the system, use a ``.bbappend`` |
| 1743 | to modify the ``linux-kernel-headers.inc`` file. However, take care to not |
| 1744 | make the changes machine specific. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1745 | |
| 1746 | Consider a case where your kernel is older and you need an older |
| 1747 | ``libc`` ABI. The headers installed by your recipe should still be a |
| 1748 | standard mainline kernel, not your own custom one. |
| 1749 | |
| 1750 | When you use custom kernel headers you need to get them from |
| 1751 | :term:`STAGING_KERNEL_DIR`, |
| 1752 | which is the directory with kernel headers that are required to build |
| 1753 | out-of-tree modules. Your recipe will also need the following: |
| 1754 | :: |
| 1755 | |
| 1756 | do_configure[depends] += "virtual/kernel:do_shared_workdir" |
| 1757 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1758 | Compilation |
| 1759 | ----------- |
| 1760 | |
| 1761 | During a build, the ``do_compile`` task happens after source is fetched, |
| 1762 | unpacked, and configured. If the recipe passes through ``do_compile`` |
| 1763 | successfully, nothing needs to be done. |
| 1764 | |
| 1765 | However, if the compile step fails, you need to diagnose the failure. |
| 1766 | Here are some common issues that cause failures. |
| 1767 | |
| 1768 | .. note:: |
| 1769 | |
| 1770 | For cases where improper paths are detected for configuration files |
| 1771 | or for when libraries/headers cannot be found, be sure you are using |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1772 | the more robust ``pkg-config``. See the note in section |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 1773 | ":ref:`dev-manual/common-tasks:Configuring the Recipe`" for additional information. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1774 | |
| 1775 | - *Parallel build failures:* These failures manifest themselves as |
| 1776 | intermittent errors, or errors reporting that a file or directory |
| 1777 | that should be created by some other part of the build process could |
| 1778 | not be found. This type of failure can occur even if, upon |
| 1779 | inspection, the file or directory does exist after the build has |
| 1780 | failed, because that part of the build process happened in the wrong |
| 1781 | order. |
| 1782 | |
| 1783 | To fix the problem, you need to either satisfy the missing dependency |
| 1784 | in the Makefile or whatever script produced the Makefile, or (as a |
| 1785 | workaround) set :term:`PARALLEL_MAKE` to an empty string: |
| 1786 | :: |
| 1787 | |
| 1788 | PARALLEL_MAKE = "" |
| 1789 | |
| 1790 | For information on parallel Makefile issues, see the "`Debugging |
| 1791 | Parallel Make Races <#debugging-parallel-make-races>`__" section. |
| 1792 | |
| 1793 | - *Improper host path usage:* This failure applies to recipes building |
| 1794 | for the target or ``nativesdk`` only. The failure occurs when the |
| 1795 | compilation process uses improper headers, libraries, or other files |
| 1796 | from the host system when cross-compiling for the target. |
| 1797 | |
| 1798 | To fix the problem, examine the ``log.do_compile`` file to identify |
| 1799 | the host paths being used (e.g. ``/usr/include``, ``/usr/lib``, and |
| 1800 | so forth) and then either add configure options, apply a patch, or do |
| 1801 | both. |
| 1802 | |
| 1803 | - *Failure to find required libraries/headers:* If a build-time |
| 1804 | dependency is missing because it has not been declared in |
| 1805 | :term:`DEPENDS`, or because the |
| 1806 | dependency exists but the path used by the build process to find the |
| 1807 | file is incorrect and the configure step did not detect it, the |
| 1808 | compilation process could fail. For either of these failures, the |
| 1809 | compilation process notes that files could not be found. In these |
| 1810 | cases, you need to go back and add additional options to the |
| 1811 | configure script as well as possibly add additional build-time |
| 1812 | dependencies to ``DEPENDS``. |
| 1813 | |
| 1814 | Occasionally, it is necessary to apply a patch to the source to |
| 1815 | ensure the correct paths are used. If you need to specify paths to |
| 1816 | find files staged into the sysroot from other recipes, use the |
| 1817 | variables that the OpenEmbedded build system provides (e.g. |
| 1818 | ``STAGING_BINDIR``, ``STAGING_INCDIR``, ``STAGING_DATADIR``, and so |
| 1819 | forth). |
| 1820 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1821 | Installing |
| 1822 | ---------- |
| 1823 | |
| 1824 | During ``do_install``, the task copies the built files along with their |
| 1825 | hierarchy to locations that would mirror their locations on the target |
| 1826 | device. The installation process copies files from the |
| 1827 | ``${``\ :term:`S`\ ``}``, |
| 1828 | ``${``\ :term:`B`\ ``}``, and |
| 1829 | ``${``\ :term:`WORKDIR`\ ``}`` |
| 1830 | directories to the ``${``\ :term:`D`\ ``}`` |
| 1831 | directory to create the structure as it should appear on the target |
| 1832 | system. |
| 1833 | |
| 1834 | How your software is built affects what you must do to be sure your |
| 1835 | software is installed correctly. The following list describes what you |
| 1836 | must do for installation depending on the type of build system used by |
| 1837 | the software being built: |
| 1838 | |
| 1839 | - *Autotools and CMake:* If the software your recipe is building uses |
| 1840 | Autotools or CMake, the OpenEmbedded build system understands how to |
| 1841 | install the software. Consequently, you do not have to have a |
| 1842 | ``do_install`` task as part of your recipe. You just need to make |
| 1843 | sure the install portion of the build completes with no issues. |
| 1844 | However, if you wish to install additional files not already being |
| 1845 | installed by ``make install``, you should do this using a |
| 1846 | ``do_install_append`` function using the install command as described |
| 1847 | in the "Manual" bulleted item later in this list. |
| 1848 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1849 | - *Other (using* ``make install``\ *)*: You need to define a ``do_install`` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1850 | function in your recipe. The function should call |
| 1851 | ``oe_runmake install`` and will likely need to pass in the |
| 1852 | destination directory as well. How you pass that path is dependent on |
| 1853 | how the ``Makefile`` being run is written (e.g. ``DESTDIR=${D}``, |
| 1854 | ``PREFIX=${D}``, ``INSTALLROOT=${D}``, and so forth). |
| 1855 | |
| 1856 | For an example recipe using ``make install``, see the |
| 1857 | "`Makefile-Based Package <#new-recipe-makefile-based-package>`__" |
| 1858 | section. |
| 1859 | |
| 1860 | - *Manual:* You need to define a ``do_install`` function in your |
| 1861 | recipe. The function must first use ``install -d`` to create the |
| 1862 | directories under |
| 1863 | ``${``\ :term:`D`\ ``}``. Once the |
| 1864 | directories exist, your function can use ``install`` to manually |
| 1865 | install the built software into the directories. |
| 1866 | |
| 1867 | You can find more information on ``install`` at |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1868 | https://www.gnu.org/software/coreutils/manual/html_node/install-invocation.html. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1869 | |
| 1870 | For the scenarios that do not use Autotools or CMake, you need to track |
| 1871 | the installation and diagnose and fix any issues until everything |
| 1872 | installs correctly. You need to look in the default location of |
| 1873 | ``${D}``, which is ``${WORKDIR}/image``, to be sure your files have been |
| 1874 | installed correctly. |
| 1875 | |
| 1876 | .. note:: |
| 1877 | |
| 1878 | - During the installation process, you might need to modify some of |
| 1879 | the installed files to suit the target layout. For example, you |
| 1880 | might need to replace hard-coded paths in an initscript with |
| 1881 | values of variables provided by the build system, such as |
| 1882 | replacing ``/usr/bin/`` with ``${bindir}``. If you do perform such |
| 1883 | modifications during ``do_install``, be sure to modify the |
| 1884 | destination file after copying rather than before copying. |
| 1885 | Modifying after copying ensures that the build system can |
| 1886 | re-execute ``do_install`` if needed. |
| 1887 | |
| 1888 | - ``oe_runmake install``, which can be run directly or can be run |
| 1889 | indirectly by the |
| 1890 | :ref:`autotools <ref-classes-autotools>` and |
| 1891 | :ref:`cmake <ref-classes-cmake>` classes, |
| 1892 | runs ``make install`` in parallel. Sometimes, a Makefile can have |
| 1893 | missing dependencies between targets that can result in race |
| 1894 | conditions. If you experience intermittent failures during |
| 1895 | ``do_install``, you might be able to work around them by disabling |
| 1896 | parallel Makefile installs by adding the following to the recipe: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1897 | :: |
| 1898 | |
| 1899 | PARALLEL_MAKEINST = "" |
| 1900 | |
| 1901 | See :term:`PARALLEL_MAKEINST` for additional information. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1902 | |
| 1903 | - If you need to install one or more custom CMake toolchain files |
| 1904 | that are supplied by the application you are building, install the |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1905 | files to ``${D}${datadir}/cmake/Modules`` during |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1906 | :ref:`ref-tasks-install`. |
| 1907 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1908 | Enabling System Services |
| 1909 | ------------------------ |
| 1910 | |
| 1911 | If you want to install a service, which is a process that usually starts |
| 1912 | on boot and runs in the background, then you must include some |
| 1913 | additional definitions in your recipe. |
| 1914 | |
| 1915 | If you are adding services and the service initialization script or the |
| 1916 | service file itself is not installed, you must provide for that |
| 1917 | installation in your recipe using a ``do_install_append`` function. If |
| 1918 | your recipe already has a ``do_install`` function, update the function |
| 1919 | near its end rather than adding an additional ``do_install_append`` |
| 1920 | function. |
| 1921 | |
| 1922 | When you create the installation for your services, you need to |
| 1923 | accomplish what is normally done by ``make install``. In other words, |
| 1924 | make sure your installation arranges the output similar to how it is |
| 1925 | arranged on the target system. |
| 1926 | |
| 1927 | The OpenEmbedded build system provides support for starting services two |
| 1928 | different ways: |
| 1929 | |
| 1930 | - *SysVinit:* SysVinit is a system and service manager that manages the |
| 1931 | init system used to control the very basic functions of your system. |
| 1932 | The init program is the first program started by the Linux kernel |
| 1933 | when the system boots. Init then controls the startup, running and |
| 1934 | shutdown of all other programs. |
| 1935 | |
| 1936 | To enable a service using SysVinit, your recipe needs to inherit the |
| 1937 | :ref:`update-rc.d <ref-classes-update-rc.d>` |
| 1938 | class. The class helps facilitate safely installing the package on |
| 1939 | the target. |
| 1940 | |
| 1941 | You will need to set the |
| 1942 | :term:`INITSCRIPT_PACKAGES`, |
| 1943 | :term:`INITSCRIPT_NAME`, |
| 1944 | and |
| 1945 | :term:`INITSCRIPT_PARAMS` |
| 1946 | variables within your recipe. |
| 1947 | |
| 1948 | - *systemd:* System Management Daemon (systemd) was designed to replace |
| 1949 | SysVinit and to provide enhanced management of services. For more |
| 1950 | information on systemd, see the systemd homepage at |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1951 | https://freedesktop.org/wiki/Software/systemd/. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1952 | |
| 1953 | To enable a service using systemd, your recipe needs to inherit the |
| 1954 | :ref:`systemd <ref-classes-systemd>` class. See |
| 1955 | the ``systemd.bbclass`` file located in your :term:`Source Directory` |
| 1956 | section for |
| 1957 | more information. |
| 1958 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1959 | Packaging |
| 1960 | --------- |
| 1961 | |
| 1962 | Successful packaging is a combination of automated processes performed |
| 1963 | by the OpenEmbedded build system and some specific steps you need to |
| 1964 | take. The following list describes the process: |
| 1965 | |
| 1966 | - *Splitting Files*: The ``do_package`` task splits the files produced |
| 1967 | by the recipe into logical components. Even software that produces a |
| 1968 | single binary might still have debug symbols, documentation, and |
| 1969 | other logical components that should be split out. The ``do_package`` |
| 1970 | task ensures that files are split up and packaged correctly. |
| 1971 | |
| 1972 | - *Running QA Checks*: The |
| 1973 | :ref:`insane <ref-classes-insane>` class adds a |
| 1974 | step to the package generation process so that output quality |
| 1975 | assurance checks are generated by the OpenEmbedded build system. This |
| 1976 | step performs a range of checks to be sure the build's output is free |
| 1977 | of common problems that show up during runtime. For information on |
| 1978 | these checks, see the |
| 1979 | :ref:`insane <ref-classes-insane>` class and |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 1980 | the ":ref:`ref-manual/qa-checks:qa error and warning messages`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1981 | chapter in the Yocto Project Reference Manual. |
| 1982 | |
| 1983 | - *Hand-Checking Your Packages*: After you build your software, you |
| 1984 | need to be sure your packages are correct. Examine the |
| 1985 | ``${``\ :term:`WORKDIR`\ ``}/packages-split`` |
| 1986 | directory and make sure files are where you expect them to be. If you |
| 1987 | discover problems, you can set |
| 1988 | :term:`PACKAGES`, |
| 1989 | :term:`FILES`, |
| 1990 | ``do_install(_append)``, and so forth as needed. |
| 1991 | |
| 1992 | - *Splitting an Application into Multiple Packages*: If you need to |
| 1993 | split an application into several packages, see the "`Splitting an |
| 1994 | Application into Multiple |
| 1995 | Packages <#splitting-an-application-into-multiple-packages>`__" |
| 1996 | section for an example. |
| 1997 | |
| 1998 | - *Installing a Post-Installation Script*: For an example showing how |
| 1999 | to install a post-installation script, see the "`Post-Installation |
| 2000 | Scripts <#new-recipe-post-installation-scripts>`__" section. |
| 2001 | |
| 2002 | - *Marking Package Architecture*: Depending on what your recipe is |
| 2003 | building and how it is configured, it might be important to mark the |
| 2004 | packages produced as being specific to a particular machine, or to |
| 2005 | mark them as not being specific to a particular machine or |
| 2006 | architecture at all. |
| 2007 | |
| 2008 | By default, packages apply to any machine with the same architecture |
| 2009 | as the target machine. When a recipe produces packages that are |
| 2010 | machine-specific (e.g. the |
| 2011 | :term:`MACHINE` value is passed |
| 2012 | into the configure script or a patch is applied only for a particular |
| 2013 | machine), you should mark them as such by adding the following to the |
| 2014 | recipe: |
| 2015 | :: |
| 2016 | |
| 2017 | PACKAGE_ARCH = "${MACHINE_ARCH}" |
| 2018 | |
| 2019 | On the other hand, if the recipe produces packages that do not |
| 2020 | contain anything specific to the target machine or architecture at |
| 2021 | all (e.g. recipes that simply package script files or configuration |
| 2022 | files), you should use the |
| 2023 | :ref:`allarch <ref-classes-allarch>` class to |
| 2024 | do this for you by adding this to your recipe: |
| 2025 | :: |
| 2026 | |
| 2027 | inherit allarch |
| 2028 | |
| 2029 | Ensuring that the package architecture is correct is not critical |
| 2030 | while you are doing the first few builds of your recipe. However, it |
| 2031 | is important in order to ensure that your recipe rebuilds (or does |
| 2032 | not rebuild) appropriately in response to changes in configuration, |
| 2033 | and to ensure that you get the appropriate packages installed on the |
| 2034 | target machine, particularly if you run separate builds for more than |
| 2035 | one target machine. |
| 2036 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2037 | Sharing Files Between Recipes |
| 2038 | ----------------------------- |
| 2039 | |
| 2040 | Recipes often need to use files provided by other recipes on the build |
| 2041 | host. For example, an application linking to a common library needs |
| 2042 | access to the library itself and its associated headers. The way this |
| 2043 | access is accomplished is by populating a sysroot with files. Each |
| 2044 | recipe has two sysroots in its work directory, one for target files |
| 2045 | (``recipe-sysroot``) and one for files that are native to the build host |
| 2046 | (``recipe-sysroot-native``). |
| 2047 | |
| 2048 | .. note:: |
| 2049 | |
| 2050 | You could find the term "staging" used within the Yocto project |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2051 | regarding files populating sysroots (e.g. the :term:`STAGING_DIR` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2052 | variable). |
| 2053 | |
| 2054 | Recipes should never populate the sysroot directly (i.e. write files |
| 2055 | into sysroot). Instead, files should be installed into standard |
| 2056 | locations during the |
| 2057 | :ref:`ref-tasks-install` task within |
| 2058 | the ``${``\ :term:`D`\ ``}`` directory. The |
| 2059 | reason for this limitation is that almost all files that populate the |
| 2060 | sysroot are cataloged in manifests in order to ensure the files can be |
| 2061 | removed later when a recipe is either modified or removed. Thus, the |
| 2062 | sysroot is able to remain free from stale files. |
| 2063 | |
| 2064 | A subset of the files installed by the |
| 2065 | :ref:`ref-tasks-install` task are |
| 2066 | used by the |
| 2067 | :ref:`ref-tasks-populate_sysroot` |
| 2068 | task as defined by the the |
| 2069 | :term:`SYSROOT_DIRS` variable to |
| 2070 | automatically populate the sysroot. It is possible to modify the list of |
| 2071 | directories that populate the sysroot. The following example shows how |
| 2072 | you could add the ``/opt`` directory to the list of directories within a |
| 2073 | recipe: |
| 2074 | :: |
| 2075 | |
| 2076 | SYSROOT_DIRS += "/opt" |
| 2077 | |
| 2078 | For a more complete description of the |
| 2079 | :ref:`ref-tasks-populate_sysroot` |
| 2080 | task and its associated functions, see the |
| 2081 | :ref:`staging <ref-classes-staging>` class. |
| 2082 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2083 | Using Virtual Providers |
| 2084 | ----------------------- |
| 2085 | |
| 2086 | Prior to a build, if you know that several different recipes provide the |
| 2087 | same functionality, you can use a virtual provider (i.e. ``virtual/*``) |
| 2088 | as a placeholder for the actual provider. The actual provider is |
| 2089 | determined at build-time. |
| 2090 | |
| 2091 | A common scenario where a virtual provider is used would be for the |
| 2092 | kernel recipe. Suppose you have three kernel recipes whose |
| 2093 | :term:`PN` values map to ``kernel-big``, |
| 2094 | ``kernel-mid``, and ``kernel-small``. Furthermore, each of these recipes |
| 2095 | in some way uses a :term:`PROVIDES` |
| 2096 | statement that essentially identifies itself as being able to provide |
| 2097 | ``virtual/kernel``. Here is one way through the |
| 2098 | :ref:`kernel <ref-classes-kernel>` class: |
| 2099 | :: |
| 2100 | |
| 2101 | PROVIDES += "${@ "virtual/kernel" if (d.getVar("KERNEL_PACKAGE_NAME") == "kernel") else "" }" |
| 2102 | |
| 2103 | Any recipe that inherits the ``kernel`` class is |
| 2104 | going to utilize a ``PROVIDES`` statement that identifies that recipe as |
| 2105 | being able to provide the ``virtual/kernel`` item. |
| 2106 | |
| 2107 | Now comes the time to actually build an image and you need a kernel |
| 2108 | recipe, but which one? You can configure your build to call out the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 2109 | kernel recipe you want by using the :term:`PREFERRED_PROVIDER` variable. As |
| 2110 | an example, consider the :yocto_git:`x86-base.inc |
| 2111 | </poky/tree/meta/conf/machine/include/x86-base.inc>` include file, which is a |
| 2112 | machine (i.e. :term:`MACHINE`) configuration file. This include file is the |
| 2113 | reason all x86-based machines use the ``linux-yocto`` kernel. Here are the |
| 2114 | relevant lines from the include file: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2115 | :: |
| 2116 | |
| 2117 | PREFERRED_PROVIDER_virtual/kernel ??= "linux-yocto" |
| 2118 | PREFERRED_VERSION_linux-yocto ??= "4.15%" |
| 2119 | |
| 2120 | When you use a virtual provider, you do not have to "hard code" a recipe |
| 2121 | name as a build dependency. You can use the |
| 2122 | :term:`DEPENDS` variable to state the |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2123 | build is dependent on ``virtual/kernel`` for example: |
| 2124 | :: |
| 2125 | |
| 2126 | DEPENDS = "virtual/kernel" |
| 2127 | |
| 2128 | During the build, the OpenEmbedded build system picks |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2129 | the correct recipe needed for the ``virtual/kernel`` dependency based on |
| 2130 | the ``PREFERRED_PROVIDER`` variable. If you want to use the small kernel |
| 2131 | mentioned at the beginning of this section, configure your build as |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2132 | follows: |
| 2133 | :: |
| 2134 | |
| 2135 | PREFERRED_PROVIDER_virtual/kernel ??= "kernel-small" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2136 | |
| 2137 | .. note:: |
| 2138 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2139 | Any recipe that ``PROVIDES`` a ``virtual/*`` item that is ultimately not |
| 2140 | selected through ``PREFERRED_PROVIDER`` does not get built. Preventing these |
| 2141 | recipes from building is usually the desired behavior since this mechanism's |
| 2142 | purpose is to select between mutually exclusive alternative providers. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2143 | |
| 2144 | The following lists specific examples of virtual providers: |
| 2145 | |
| 2146 | - ``virtual/kernel``: Provides the name of the kernel recipe to use |
| 2147 | when building a kernel image. |
| 2148 | |
| 2149 | - ``virtual/bootloader``: Provides the name of the bootloader to use |
| 2150 | when building an image. |
| 2151 | |
| 2152 | - ``virtual/libgbm``: Provides ``gbm.pc``. |
| 2153 | |
| 2154 | - ``virtual/egl``: Provides ``egl.pc`` and possibly ``wayland-egl.pc``. |
| 2155 | |
| 2156 | - ``virtual/libgl``: Provides ``gl.pc`` (i.e. libGL). |
| 2157 | |
| 2158 | - ``virtual/libgles1``: Provides ``glesv1_cm.pc`` (i.e. libGLESv1_CM). |
| 2159 | |
| 2160 | - ``virtual/libgles2``: Provides ``glesv2.pc`` (i.e. libGLESv2). |
| 2161 | |
| 2162 | .. note:: |
| 2163 | |
| 2164 | Virtual providers only apply to build time dependencies specified with |
| 2165 | :term:`PROVIDES` and :term:`DEPENDS`. They do not apply to runtime |
| 2166 | dependencies specified with :term:`RPROVIDES` and :term:`RDEPENDS`. |
| 2167 | |
| 2168 | Properly Versioning Pre-Release Recipes |
| 2169 | --------------------------------------- |
| 2170 | |
| 2171 | Sometimes the name of a recipe can lead to versioning problems when the |
| 2172 | recipe is upgraded to a final release. For example, consider the |
| 2173 | ``irssi_0.8.16-rc1.bb`` recipe file in the list of example recipes in |
| 2174 | the "`Storing and Naming the |
| 2175 | Recipe <#new-recipe-storing-and-naming-the-recipe>`__" section. This |
| 2176 | recipe is at a release candidate stage (i.e. "rc1"). When the recipe is |
| 2177 | released, the recipe filename becomes ``irssi_0.8.16.bb``. The version |
| 2178 | change from ``0.8.16-rc1`` to ``0.8.16`` is seen as a decrease by the |
| 2179 | build system and package managers, so the resulting packages will not |
| 2180 | correctly trigger an upgrade. |
| 2181 | |
| 2182 | In order to ensure the versions compare properly, the recommended |
| 2183 | convention is to set :term:`PV` within the |
| 2184 | recipe to "previous_version+current_version". You can use an additional |
| 2185 | variable so that you can use the current version elsewhere. Here is an |
| 2186 | example: |
| 2187 | :: |
| 2188 | |
| 2189 | REALPV = "0.8.16-rc1" |
| 2190 | PV = "0.8.15+${REALPV}" |
| 2191 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2192 | Post-Installation Scripts |
| 2193 | ------------------------- |
| 2194 | |
| 2195 | Post-installation scripts run immediately after installing a package on |
| 2196 | the target or during image creation when a package is included in an |
| 2197 | image. To add a post-installation script to a package, add a |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2198 | ``pkg_postinst_``\ `PACKAGENAME`\ ``()`` function to the recipe file |
| 2199 | (``.bb``) and replace `PACKAGENAME` with the name of the package you want |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2200 | to attach to the ``postinst`` script. To apply the post-installation |
| 2201 | script to the main package for the recipe, which is usually what is |
| 2202 | required, specify |
| 2203 | ``${``\ :term:`PN`\ ``}`` in place of |
| 2204 | PACKAGENAME. |
| 2205 | |
| 2206 | A post-installation function has the following structure: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2207 | :: |
| 2208 | |
| 2209 | pkg_postinst_PACKAGENAME() { |
| 2210 | # Commands to carry out |
| 2211 | } |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2212 | |
| 2213 | The script defined in the post-installation function is called when the |
| 2214 | root filesystem is created. If the script succeeds, the package is |
| 2215 | marked as installed. |
| 2216 | |
| 2217 | .. note:: |
| 2218 | |
| 2219 | Any RPM post-installation script that runs on the target should |
| 2220 | return a 0 exit code. RPM does not allow non-zero exit codes for |
| 2221 | these scripts, and the RPM package manager will cause the package to |
| 2222 | fail installation on the target. |
| 2223 | |
| 2224 | Sometimes it is necessary for the execution of a post-installation |
| 2225 | script to be delayed until the first boot. For example, the script might |
| 2226 | need to be executed on the device itself. To delay script execution |
| 2227 | until boot time, you must explicitly mark post installs to defer to the |
| 2228 | target. You can use ``pkg_postinst_ontarget()`` or call |
| 2229 | ``postinst_intercept delay_to_first_boot`` from ``pkg_postinst()``. Any |
| 2230 | failure of a ``pkg_postinst()`` script (including exit 1) triggers an |
| 2231 | error during the |
| 2232 | :ref:`ref-tasks-rootfs` task. |
| 2233 | |
| 2234 | If you have recipes that use ``pkg_postinst`` function and they require |
| 2235 | the use of non-standard native tools that have dependencies during |
| 2236 | rootfs construction, you need to use the |
| 2237 | :term:`PACKAGE_WRITE_DEPS` |
| 2238 | variable in your recipe to list these tools. If you do not use this |
| 2239 | variable, the tools might be missing and execution of the |
| 2240 | post-installation script is deferred until first boot. Deferring the |
| 2241 | script to first boot is undesirable and for read-only rootfs impossible. |
| 2242 | |
| 2243 | .. note:: |
| 2244 | |
| 2245 | Equivalent support for pre-install, pre-uninstall, and post-uninstall |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2246 | scripts exist by way of ``pkg_preinst``, ``pkg_prerm``, and ``pkg_postrm``, |
| 2247 | respectively. These scrips work in exactly the same way as does |
| 2248 | ``pkg_postinst`` with the exception that they run at different times. Also, |
| 2249 | because of when they run, they are not applicable to being run at image |
| 2250 | creation time like ``pkg_postinst``. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2251 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2252 | Testing |
| 2253 | ------- |
| 2254 | |
| 2255 | The final step for completing your recipe is to be sure that the |
| 2256 | software you built runs correctly. To accomplish runtime testing, add |
| 2257 | the build's output packages to your image and test them on the target. |
| 2258 | |
| 2259 | For information on how to customize your image by adding specific |
| 2260 | packages, see the "`Customizing |
| 2261 | Images <#usingpoky-extend-customimage>`__" section. |
| 2262 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2263 | Examples |
| 2264 | -------- |
| 2265 | |
| 2266 | To help summarize how to write a recipe, this section provides some |
| 2267 | examples given various scenarios: |
| 2268 | |
| 2269 | - Recipes that use local files |
| 2270 | |
| 2271 | - Using an Autotooled package |
| 2272 | |
| 2273 | - Using a Makefile-based package |
| 2274 | |
| 2275 | - Splitting an application into multiple packages |
| 2276 | |
| 2277 | - Adding binaries to an image |
| 2278 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2279 | Single .c File Package (Hello World!) |
| 2280 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2281 | |
| 2282 | Building an application from a single file that is stored locally (e.g. |
| 2283 | under ``files``) requires a recipe that has the file listed in the |
| 2284 | ``SRC_URI`` variable. Additionally, you need to manually write the |
| 2285 | ``do_compile`` and ``do_install`` tasks. The ``S`` variable defines the |
| 2286 | directory containing the source code, which is set to |
| 2287 | :term:`WORKDIR` in this case - the |
| 2288 | directory BitBake uses for the build. |
| 2289 | :: |
| 2290 | |
| 2291 | SUMMARY = "Simple helloworld application" |
| 2292 | SECTION = "examples" |
| 2293 | LICENSE = "MIT" |
| 2294 | LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" |
| 2295 | |
| 2296 | SRC_URI = "file://helloworld.c" |
| 2297 | |
| 2298 | S = "${WORKDIR}" |
| 2299 | |
| 2300 | do_compile() { |
| 2301 | ${CC} helloworld.c -o helloworld |
| 2302 | } |
| 2303 | |
| 2304 | do_install() { |
| 2305 | install -d ${D}${bindir} |
| 2306 | install -m 0755 helloworld ${D}${bindir} |
| 2307 | } |
| 2308 | |
| 2309 | By default, the ``helloworld``, ``helloworld-dbg``, and |
| 2310 | ``helloworld-dev`` packages are built. For information on how to |
| 2311 | customize the packaging process, see the "`Splitting an Application into |
| 2312 | Multiple Packages <#splitting-an-application-into-multiple-packages>`__" |
| 2313 | section. |
| 2314 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2315 | Autotooled Package |
| 2316 | ~~~~~~~~~~~~~~~~~~ |
| 2317 | |
| 2318 | Applications that use Autotools such as ``autoconf`` and ``automake`` |
| 2319 | require a recipe that has a source archive listed in ``SRC_URI`` and |
| 2320 | also inherit the |
| 2321 | :ref:`autotools <ref-classes-autotools>` class, |
| 2322 | which contains the definitions of all the steps needed to build an |
| 2323 | Autotool-based application. The result of the build is automatically |
| 2324 | packaged. And, if the application uses NLS for localization, packages |
| 2325 | with local information are generated (one package per language). |
| 2326 | Following is one example: (``hello_2.3.bb``) |
| 2327 | :: |
| 2328 | |
| 2329 | SUMMARY = "GNU Helloworld application" |
| 2330 | SECTION = "examples" |
| 2331 | LICENSE = "GPLv2+" |
| 2332 | LIC_FILES_CHKSUM = "file://COPYING;md5=751419260aa954499f7abaabaa882bbe" |
| 2333 | |
| 2334 | SRC_URI = "${GNU_MIRROR}/hello/hello-${PV}.tar.gz" |
| 2335 | |
| 2336 | inherit autotools gettext |
| 2337 | |
| 2338 | The variable ``LIC_FILES_CHKSUM`` is used to track source license |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2339 | changes as described in the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 2340 | ":ref:`dev-manual/common-tasks:tracking license changes`" section in |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2341 | the Yocto Project Overview and Concepts Manual. You can quickly create |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2342 | Autotool-based recipes in a manner similar to the previous example. |
| 2343 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2344 | Makefile-Based Package |
| 2345 | ~~~~~~~~~~~~~~~~~~~~~~ |
| 2346 | |
| 2347 | Applications that use GNU ``make`` also require a recipe that has the |
| 2348 | source archive listed in ``SRC_URI``. You do not need to add a |
| 2349 | ``do_compile`` step since by default BitBake starts the ``make`` command |
| 2350 | to compile the application. If you need additional ``make`` options, you |
| 2351 | should store them in the |
| 2352 | :term:`EXTRA_OEMAKE` or |
| 2353 | :term:`PACKAGECONFIG_CONFARGS` |
| 2354 | variables. BitBake passes these options into the GNU ``make`` |
| 2355 | invocation. Note that a ``do_install`` task is still required. |
| 2356 | Otherwise, BitBake runs an empty ``do_install`` task by default. |
| 2357 | |
| 2358 | Some applications might require extra parameters to be passed to the |
| 2359 | compiler. For example, the application might need an additional header |
| 2360 | path. You can accomplish this by adding to the ``CFLAGS`` variable. The |
| 2361 | following example shows this: |
| 2362 | :: |
| 2363 | |
| 2364 | CFLAGS_prepend = "-I ${S}/include " |
| 2365 | |
| 2366 | In the following example, ``mtd-utils`` is a makefile-based package: |
| 2367 | :: |
| 2368 | |
| 2369 | SUMMARY = "Tools for managing memory technology devices" |
| 2370 | SECTION = "base" |
| 2371 | DEPENDS = "zlib lzo e2fsprogs util-linux" |
| 2372 | HOMEPAGE = "http://www.linux-mtd.infradead.org/" |
| 2373 | LICENSE = "GPLv2+" |
| 2374 | LIC_FILES_CHKSUM = "file://COPYING;md5=0636e73ff0215e8d672dc4c32c317bb3 \ |
| 2375 | file://include/common.h;beginline=1;endline=17;md5=ba05b07912a44ea2bf81ce409380049c" |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2376 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2377 | # Use the latest version at 26 Oct, 2013 |
| 2378 | SRCREV = "9f107132a6a073cce37434ca9cda6917dd8d866b" |
| 2379 | SRC_URI = "git://git.infradead.org/mtd-utils.git \ |
| 2380 | file://add-exclusion-to-mkfs-jffs2-git-2.patch \ |
| 2381 | " |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2382 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2383 | PV = "1.5.1+git${SRCPV}" |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2384 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2385 | S = "${WORKDIR}/git" |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2386 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2387 | EXTRA_OEMAKE = "'CC=${CC}' 'RANLIB=${RANLIB}' 'AR=${AR}' 'CFLAGS=${CFLAGS} -I${S}/include -DWITHOUT_XATTR' 'BUILDDIR=${S}'" |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2388 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2389 | do_install () { |
| 2390 | oe_runmake install DESTDIR=${D} SBINDIR=${sbindir} MANDIR=${mandir} INCLUDEDIR=${includedir} |
| 2391 | } |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2392 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2393 | PACKAGES =+ "mtd-utils-jffs2 mtd-utils-ubifs mtd-utils-misc" |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2394 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2395 | FILES_mtd-utils-jffs2 = "${sbindir}/mkfs.jffs2 ${sbindir}/jffs2dump ${sbindir}/jffs2reader ${sbindir}/sumtool" |
| 2396 | FILES_mtd-utils-ubifs = "${sbindir}/mkfs.ubifs ${sbindir}/ubi*" |
| 2397 | FILES_mtd-utils-misc = "${sbindir}/nftl* ${sbindir}/ftl* ${sbindir}/rfd* ${sbindir}/doc* ${sbindir}/serve_image ${sbindir}/recv_image" |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2398 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2399 | PARALLEL_MAKE = "" |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2400 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2401 | BBCLASSEXTEND = "native" |
| 2402 | |
| 2403 | Splitting an Application into Multiple Packages |
| 2404 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2405 | |
| 2406 | You can use the variables ``PACKAGES`` and ``FILES`` to split an |
| 2407 | application into multiple packages. |
| 2408 | |
| 2409 | Following is an example that uses the ``libxpm`` recipe. By default, |
| 2410 | this recipe generates a single package that contains the library along |
| 2411 | with a few binaries. You can modify the recipe to split the binaries |
| 2412 | into separate packages: |
| 2413 | :: |
| 2414 | |
| 2415 | require xorg-lib-common.inc |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2416 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2417 | SUMMARY = "Xpm: X Pixmap extension library" |
| 2418 | LICENSE = "BSD" |
| 2419 | LIC_FILES_CHKSUM = "file://COPYING;md5=51f4270b012ecd4ab1a164f5f4ed6cf7" |
| 2420 | DEPENDS += "libxext libsm libxt" |
| 2421 | PE = "1" |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2422 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2423 | XORG_PN = "libXpm" |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2424 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2425 | PACKAGES =+ "sxpm cxpm" |
| 2426 | FILES_cxpm = "${bindir}/cxpm" |
| 2427 | FILES_sxpm = "${bindir}/sxpm" |
| 2428 | |
| 2429 | In the previous example, we want to ship the ``sxpm`` and ``cxpm`` |
| 2430 | binaries in separate packages. Since ``bindir`` would be packaged into |
| 2431 | the main ``PN`` package by default, we prepend the ``PACKAGES`` variable |
| 2432 | so additional package names are added to the start of list. This results |
| 2433 | in the extra ``FILES_*`` variables then containing information that |
| 2434 | define which files and directories go into which packages. Files |
| 2435 | included by earlier packages are skipped by latter packages. Thus, the |
| 2436 | main ``PN`` package does not include the above listed files. |
| 2437 | |
| 2438 | Packaging Externally Produced Binaries |
| 2439 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2440 | |
| 2441 | Sometimes, you need to add pre-compiled binaries to an image. For |
| 2442 | example, suppose that binaries for proprietary code exist, which are |
| 2443 | created by a particular division of a company. Your part of the company |
| 2444 | needs to use those binaries as part of an image that you are building |
| 2445 | using the OpenEmbedded build system. Since you only have the binaries |
| 2446 | and not the source code, you cannot use a typical recipe that expects to |
| 2447 | fetch the source specified in |
| 2448 | :term:`SRC_URI` and then compile it. |
| 2449 | |
| 2450 | One method is to package the binaries and then install them as part of |
| 2451 | the image. Generally, it is not a good idea to package binaries since, |
| 2452 | among other things, it can hinder the ability to reproduce builds and |
| 2453 | could lead to compatibility problems with ABI in the future. However, |
| 2454 | sometimes you have no choice. |
| 2455 | |
| 2456 | The easiest solution is to create a recipe that uses the |
| 2457 | :ref:`bin_package <ref-classes-bin-package>` class |
| 2458 | and to be sure that you are using default locations for build artifacts. |
| 2459 | In most cases, the ``bin_package`` class handles "skipping" the |
| 2460 | configure and compile steps as well as sets things up to grab packages |
| 2461 | from the appropriate area. In particular, this class sets ``noexec`` on |
| 2462 | both the :ref:`ref-tasks-configure` |
| 2463 | and :ref:`ref-tasks-compile` tasks, |
| 2464 | sets ``FILES_${PN}`` to "/" so that it picks up all files, and sets up a |
| 2465 | :ref:`ref-tasks-install` task, which |
| 2466 | effectively copies all files from ``${S}`` to ``${D}``. The |
| 2467 | ``bin_package`` class works well when the files extracted into ``${S}`` |
| 2468 | are already laid out in the way they should be laid out on the target. |
| 2469 | For more information on these variables, see the |
| 2470 | :term:`FILES`, |
| 2471 | :term:`PN`, |
| 2472 | :term:`S`, and |
| 2473 | :term:`D` variables in the Yocto Project |
| 2474 | Reference Manual's variable glossary. |
| 2475 | |
| 2476 | .. note:: |
| 2477 | |
| 2478 | - Using :term:`DEPENDS` is a good |
| 2479 | idea even for components distributed in binary form, and is often |
| 2480 | necessary for shared libraries. For a shared library, listing the |
| 2481 | library dependencies in ``DEPENDS`` makes sure that the libraries |
| 2482 | are available in the staging sysroot when other recipes link |
| 2483 | against the library, which might be necessary for successful |
| 2484 | linking. |
| 2485 | |
| 2486 | - Using ``DEPENDS`` also allows runtime dependencies between |
| 2487 | packages to be added automatically. See the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 2488 | ":ref:`overview-manual/concepts:automatically added runtime dependencies`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2489 | section in the Yocto Project Overview and Concepts Manual for more |
| 2490 | information. |
| 2491 | |
| 2492 | If you cannot use the ``bin_package`` class, you need to be sure you are |
| 2493 | doing the following: |
| 2494 | |
| 2495 | - Create a recipe where the |
| 2496 | :ref:`ref-tasks-configure` and |
| 2497 | :ref:`ref-tasks-compile` tasks do |
| 2498 | nothing: It is usually sufficient to just not define these tasks in |
| 2499 | the recipe, because the default implementations do nothing unless a |
| 2500 | Makefile is found in |
| 2501 | ``${``\ :term:`S`\ ``}``. |
| 2502 | |
| 2503 | If ``${S}`` might contain a Makefile, or if you inherit some class |
| 2504 | that replaces ``do_configure`` and ``do_compile`` with custom |
| 2505 | versions, then you can use the |
| 2506 | ``[``\ :ref:`noexec <bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ``]`` |
| 2507 | flag to turn the tasks into no-ops, as follows: |
| 2508 | :: |
| 2509 | |
| 2510 | do_configure[noexec] = "1" |
| 2511 | do_compile[noexec] = "1" |
| 2512 | |
| 2513 | Unlike |
| 2514 | :ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:deleting a task`, |
| 2515 | using the flag preserves the dependency chain from the |
| 2516 | :ref:`ref-tasks-fetch`, |
| 2517 | :ref:`ref-tasks-unpack`, and |
| 2518 | :ref:`ref-tasks-patch` tasks to the |
| 2519 | :ref:`ref-tasks-install` task. |
| 2520 | |
| 2521 | - Make sure your ``do_install`` task installs the binaries |
| 2522 | appropriately. |
| 2523 | |
| 2524 | - Ensure that you set up :term:`FILES` |
| 2525 | (usually |
| 2526 | ``FILES_${``\ :term:`PN`\ ``}``) to |
| 2527 | point to the files you have installed, which of course depends on |
| 2528 | where you have installed them and whether those files are in |
| 2529 | different locations than the defaults. |
| 2530 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 2531 | .. note:: |
| 2532 | |
| 2533 | If image prelinking is enabled (e.g. "image-prelink" is in :term:`USER_CLASSES` |
| 2534 | which it is by default), prelink will change the binaries in the generated images |
| 2535 | and this often catches people out. Remove that class to ensure binaries are |
| 2536 | preserved exactly if that is necessary. |
| 2537 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2538 | Following Recipe Style Guidelines |
| 2539 | --------------------------------- |
| 2540 | |
| 2541 | When writing recipes, it is good to conform to existing style |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 2542 | guidelines. The :oe_wiki:`OpenEmbedded Styleguide </Styleguide>` wiki page |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2543 | provides rough guidelines for preferred recipe style. |
| 2544 | |
| 2545 | It is common for existing recipes to deviate a bit from this style. |
| 2546 | However, aiming for at least a consistent style is a good idea. Some |
| 2547 | practices, such as omitting spaces around ``=`` operators in assignments |
| 2548 | or ordering recipe components in an erratic way, are widely seen as poor |
| 2549 | style. |
| 2550 | |
| 2551 | Recipe Syntax |
| 2552 | ------------- |
| 2553 | |
| 2554 | Understanding recipe file syntax is important for writing recipes. The |
| 2555 | following list overviews the basic items that make up a BitBake recipe |
| 2556 | file. For more complete BitBake syntax descriptions, see the |
| 2557 | ":doc:`bitbake-user-manual/bitbake-user-manual-metadata`" |
| 2558 | chapter of the BitBake User Manual. |
| 2559 | |
| 2560 | - *Variable Assignments and Manipulations:* Variable assignments allow |
| 2561 | a value to be assigned to a variable. The assignment can be static |
| 2562 | text or might include the contents of other variables. In addition to |
| 2563 | the assignment, appending and prepending operations are also |
| 2564 | supported. |
| 2565 | |
| 2566 | The following example shows some of the ways you can use variables in |
| 2567 | recipes: |
| 2568 | :: |
| 2569 | |
| 2570 | S = "${WORKDIR}/postfix-${PV}" |
| 2571 | CFLAGS += "-DNO_ASM" |
| 2572 | SRC_URI_append = " file://fixup.patch" |
| 2573 | |
| 2574 | - *Functions:* Functions provide a series of actions to be performed. |
| 2575 | You usually use functions to override the default implementation of a |
| 2576 | task function or to complement a default function (i.e. append or |
| 2577 | prepend to an existing function). Standard functions use ``sh`` shell |
| 2578 | syntax, although access to OpenEmbedded variables and internal |
| 2579 | methods are also available. |
| 2580 | |
| 2581 | The following is an example function from the ``sed`` recipe: |
| 2582 | :: |
| 2583 | |
| 2584 | do_install () { |
| 2585 | autotools_do_install |
| 2586 | install -d ${D}${base_bindir} |
| 2587 | mv ${D}${bindir}/sed ${D}${base_bindir}/sed |
| 2588 | rmdir ${D}${bindir}/ |
| 2589 | } |
| 2590 | |
| 2591 | It is |
| 2592 | also possible to implement new functions that are called between |
| 2593 | existing tasks as long as the new functions are not replacing or |
| 2594 | complementing the default functions. You can implement functions in |
| 2595 | Python instead of shell. Both of these options are not seen in the |
| 2596 | majority of recipes. |
| 2597 | |
| 2598 | - *Keywords:* BitBake recipes use only a few keywords. You use keywords |
| 2599 | to include common functions (``inherit``), load parts of a recipe |
| 2600 | from other files (``include`` and ``require``) and export variables |
| 2601 | to the environment (``export``). |
| 2602 | |
| 2603 | The following example shows the use of some of these keywords: |
| 2604 | :: |
| 2605 | |
| 2606 | export POSTCONF = "${STAGING_BINDIR}/postconf" |
| 2607 | inherit autoconf |
| 2608 | require otherfile.inc |
| 2609 | |
| 2610 | - *Comments (#):* Any lines that begin with the hash character (``#``) |
| 2611 | are treated as comment lines and are ignored: |
| 2612 | :: |
| 2613 | |
| 2614 | # This is a comment |
| 2615 | |
| 2616 | This next list summarizes the most important and most commonly used |
| 2617 | parts of the recipe syntax. For more information on these parts of the |
| 2618 | syntax, you can reference the |
| 2619 | :doc:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata` chapter |
| 2620 | in the BitBake User Manual. |
| 2621 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2622 | - *Line Continuation (\\):* Use the backward slash (``\``) character to |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2623 | split a statement over multiple lines. Place the slash character at |
| 2624 | the end of the line that is to be continued on the next line: |
| 2625 | :: |
| 2626 | |
| 2627 | VAR = "A really long \ |
| 2628 | line" |
| 2629 | |
| 2630 | .. note:: |
| 2631 | |
| 2632 | You cannot have any characters including spaces or tabs after the |
| 2633 | slash character. |
| 2634 | |
| 2635 | - *Using Variables (${VARNAME}):* Use the ``${VARNAME}`` syntax to |
| 2636 | access the contents of a variable: |
| 2637 | :: |
| 2638 | |
| 2639 | SRC_URI = "${SOURCEFORGE_MIRROR}/libpng/zlib-${PV}.tar.gz" |
| 2640 | |
| 2641 | .. note:: |
| 2642 | |
| 2643 | It is important to understand that the value of a variable |
| 2644 | expressed in this form does not get substituted automatically. The |
| 2645 | expansion of these expressions happens on-demand later (e.g. |
| 2646 | usually when a function that makes reference to the variable |
| 2647 | executes). This behavior ensures that the values are most |
| 2648 | appropriate for the context in which they are finally used. On the |
| 2649 | rare occasion that you do need the variable expression to be |
| 2650 | expanded immediately, you can use the |
| 2651 | := |
| 2652 | operator instead of |
| 2653 | = |
| 2654 | when you make the assignment, but this is not generally needed. |
| 2655 | |
| 2656 | - *Quote All Assignments ("value"):* Use double quotes around values in |
| 2657 | all variable assignments (e.g. ``"value"``). Following is an example: |
| 2658 | :: |
| 2659 | |
| 2660 | VAR1 = "${OTHERVAR}" |
| 2661 | VAR2 = "The version is ${PV}" |
| 2662 | |
| 2663 | - *Conditional Assignment (?=):* Conditional assignment is used to |
| 2664 | assign a value to a variable, but only when the variable is currently |
| 2665 | unset. Use the question mark followed by the equal sign (``?=``) to |
| 2666 | make a "soft" assignment used for conditional assignment. Typically, |
| 2667 | "soft" assignments are used in the ``local.conf`` file for variables |
| 2668 | that are allowed to come through from the external environment. |
| 2669 | |
| 2670 | Here is an example where ``VAR1`` is set to "New value" if it is |
| 2671 | currently empty. However, if ``VAR1`` has already been set, it |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2672 | remains unchanged: |
| 2673 | :: |
| 2674 | |
| 2675 | VAR1 ?= "New value" |
| 2676 | |
| 2677 | In this next example, ``VAR1`` is left with the value "Original value": |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2678 | :: |
| 2679 | |
| 2680 | VAR1 = "Original value" |
| 2681 | VAR1 ?= "New value" |
| 2682 | |
| 2683 | - *Appending (+=):* Use the plus character followed by the equals sign |
| 2684 | (``+=``) to append values to existing variables. |
| 2685 | |
| 2686 | .. note:: |
| 2687 | |
| 2688 | This operator adds a space between the existing content of the |
| 2689 | variable and the new content. |
| 2690 | |
| 2691 | Here is an example: |
| 2692 | :: |
| 2693 | |
| 2694 | SRC_URI += "file://fix-makefile.patch" |
| 2695 | |
| 2696 | - *Prepending (=+):* Use the equals sign followed by the plus character |
| 2697 | (``=+``) to prepend values to existing variables. |
| 2698 | |
| 2699 | .. note:: |
| 2700 | |
| 2701 | This operator adds a space between the new content and the |
| 2702 | existing content of the variable. |
| 2703 | |
| 2704 | Here is an example: |
| 2705 | :: |
| 2706 | |
| 2707 | VAR =+ "Starts" |
| 2708 | |
| 2709 | - *Appending (_append):* Use the ``_append`` operator to append values |
| 2710 | to existing variables. This operator does not add any additional |
| 2711 | space. Also, the operator is applied after all the ``+=``, and ``=+`` |
| 2712 | operators have been applied and after all ``=`` assignments have |
| 2713 | occurred. |
| 2714 | |
| 2715 | The following example shows the space being explicitly added to the |
| 2716 | start to ensure the appended value is not merged with the existing |
| 2717 | value: |
| 2718 | :: |
| 2719 | |
| 2720 | SRC_URI_append = " file://fix-makefile.patch" |
| 2721 | |
| 2722 | You can also use |
| 2723 | the ``_append`` operator with overrides, which results in the actions |
| 2724 | only being performed for the specified target or machine: |
| 2725 | :: |
| 2726 | |
| 2727 | SRC_URI_append_sh4 = " file://fix-makefile.patch" |
| 2728 | |
| 2729 | - *Prepending (_prepend):* Use the ``_prepend`` operator to prepend |
| 2730 | values to existing variables. This operator does not add any |
| 2731 | additional space. Also, the operator is applied after all the ``+=``, |
| 2732 | and ``=+`` operators have been applied and after all ``=`` |
| 2733 | assignments have occurred. |
| 2734 | |
| 2735 | The following example shows the space being explicitly added to the |
| 2736 | end to ensure the prepended value is not merged with the existing |
| 2737 | value: |
| 2738 | :: |
| 2739 | |
| 2740 | CFLAGS_prepend = "-I${S}/myincludes " |
| 2741 | |
| 2742 | You can also use the |
| 2743 | ``_prepend`` operator with overrides, which results in the actions |
| 2744 | only being performed for the specified target or machine: |
| 2745 | :: |
| 2746 | |
| 2747 | CFLAGS_prepend_sh4 = "-I${S}/myincludes " |
| 2748 | |
| 2749 | - *Overrides:* You can use overrides to set a value conditionally, |
| 2750 | typically based on how the recipe is being built. For example, to set |
| 2751 | the :term:`KBRANCH` variable's |
| 2752 | value to "standard/base" for any target |
| 2753 | :term:`MACHINE`, except for |
| 2754 | qemuarm where it should be set to "standard/arm-versatile-926ejs", |
| 2755 | you would do the following: |
| 2756 | :: |
| 2757 | |
| 2758 | KBRANCH = "standard/base" |
| 2759 | KBRANCH_qemuarm = "standard/arm-versatile-926ejs" |
| 2760 | |
| 2761 | Overrides are also used to separate |
| 2762 | alternate values of a variable in other situations. For example, when |
| 2763 | setting variables such as |
| 2764 | :term:`FILES` and |
| 2765 | :term:`RDEPENDS` that are |
| 2766 | specific to individual packages produced by a recipe, you should |
| 2767 | always use an override that specifies the name of the package. |
| 2768 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2769 | - *Indentation:* Use spaces for indentation rather than tabs. For |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2770 | shell functions, both currently work. However, it is a policy |
| 2771 | decision of the Yocto Project to use tabs in shell functions. Realize |
| 2772 | that some layers have a policy to use spaces for all indentation. |
| 2773 | |
| 2774 | - *Using Python for Complex Operations:* For more advanced processing, |
| 2775 | it is possible to use Python code during variable assignments (e.g. |
| 2776 | search and replacement on a variable). |
| 2777 | |
| 2778 | You indicate Python code using the ``${@python_code}`` syntax for the |
| 2779 | variable assignment: |
| 2780 | :: |
| 2781 | |
| 2782 | SRC_URI = "ftp://ftp.info-zip.org/pub/infozip/src/zip${@d.getVar('PV',1).replace('.', '')}.tgz |
| 2783 | |
| 2784 | - *Shell Function Syntax:* Write shell functions as if you were writing |
| 2785 | a shell script when you describe a list of actions to take. You |
| 2786 | should ensure that your script works with a generic ``sh`` and that |
| 2787 | it does not require any ``bash`` or other shell-specific |
| 2788 | functionality. The same considerations apply to various system |
| 2789 | utilities (e.g. ``sed``, ``grep``, ``awk``, and so forth) that you |
| 2790 | might wish to use. If in doubt, you should check with multiple |
| 2791 | implementations - including those from BusyBox. |
| 2792 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2793 | Adding a New Machine |
| 2794 | ==================== |
| 2795 | |
| 2796 | Adding a new machine to the Yocto Project is a straightforward process. |
| 2797 | This section describes how to add machines that are similar to those |
| 2798 | that the Yocto Project already supports. |
| 2799 | |
| 2800 | .. note:: |
| 2801 | |
| 2802 | Although well within the capabilities of the Yocto Project, adding a |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2803 | totally new architecture might require changes to ``gcc``/``glibc`` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2804 | and to the site information, which is beyond the scope of this |
| 2805 | manual. |
| 2806 | |
| 2807 | For a complete example that shows how to add a new machine, see the |
| 2808 | ":ref:`bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script`" |
| 2809 | section in the Yocto Project Board Support Package (BSP) Developer's |
| 2810 | Guide. |
| 2811 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2812 | Adding the Machine Configuration File |
| 2813 | ------------------------------------- |
| 2814 | |
| 2815 | To add a new machine, you need to add a new machine configuration file |
| 2816 | to the layer's ``conf/machine`` directory. This configuration file |
| 2817 | provides details about the device you are adding. |
| 2818 | |
| 2819 | The OpenEmbedded build system uses the root name of the machine |
| 2820 | configuration file to reference the new machine. For example, given a |
| 2821 | machine configuration file named ``crownbay.conf``, the build system |
| 2822 | recognizes the machine as "crownbay". |
| 2823 | |
| 2824 | The most important variables you must set in your machine configuration |
| 2825 | file or include from a lower-level configuration file are as follows: |
| 2826 | |
| 2827 | - ``TARGET_ARCH`` (e.g. "arm") |
| 2828 | |
| 2829 | - ``PREFERRED_PROVIDER_virtual/kernel`` |
| 2830 | |
| 2831 | - ``MACHINE_FEATURES`` (e.g. "apm screen wifi") |
| 2832 | |
| 2833 | You might also need these variables: |
| 2834 | |
| 2835 | - ``SERIAL_CONSOLES`` (e.g. "115200;ttyS0 115200;ttyS1") |
| 2836 | |
| 2837 | - ``KERNEL_IMAGETYPE`` (e.g. "zImage") |
| 2838 | |
| 2839 | - ``IMAGE_FSTYPES`` (e.g. "tar.gz jffs2") |
| 2840 | |
| 2841 | You can find full details on these variables in the reference section. |
| 2842 | You can leverage existing machine ``.conf`` files from |
| 2843 | ``meta-yocto-bsp/conf/machine/``. |
| 2844 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2845 | Adding a Kernel for the Machine |
| 2846 | ------------------------------- |
| 2847 | |
| 2848 | The OpenEmbedded build system needs to be able to build a kernel for the |
| 2849 | machine. You need to either create a new kernel recipe for this machine, |
| 2850 | or extend an existing kernel recipe. You can find several kernel recipe |
| 2851 | examples in the Source Directory at ``meta/recipes-kernel/linux`` that |
| 2852 | you can use as references. |
| 2853 | |
| 2854 | If you are creating a new kernel recipe, normal recipe-writing rules |
| 2855 | apply for setting up a ``SRC_URI``. Thus, you need to specify any |
| 2856 | necessary patches and set ``S`` to point at the source code. You need to |
| 2857 | create a ``do_configure`` task that configures the unpacked kernel with |
| 2858 | a ``defconfig`` file. You can do this by using a ``make defconfig`` |
| 2859 | command or, more commonly, by copying in a suitable ``defconfig`` file |
| 2860 | and then running ``make oldconfig``. By making use of ``inherit kernel`` |
| 2861 | and potentially some of the ``linux-*.inc`` files, most other |
| 2862 | functionality is centralized and the defaults of the class normally work |
| 2863 | well. |
| 2864 | |
| 2865 | If you are extending an existing kernel recipe, it is usually a matter |
| 2866 | of adding a suitable ``defconfig`` file. The file needs to be added into |
| 2867 | a location similar to ``defconfig`` files used for other machines in a |
| 2868 | given kernel recipe. A possible way to do this is by listing the file in |
| 2869 | the ``SRC_URI`` and adding the machine to the expression in |
| 2870 | ``COMPATIBLE_MACHINE``: |
| 2871 | :: |
| 2872 | |
| 2873 | COMPATIBLE_MACHINE = '(qemux86|qemumips)' |
| 2874 | |
| 2875 | For more information on ``defconfig`` files, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 2876 | ":ref:`kernel-dev/common:changing the configuration`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2877 | section in the Yocto Project Linux Kernel Development Manual. |
| 2878 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2879 | Adding a Formfactor Configuration File |
| 2880 | -------------------------------------- |
| 2881 | |
| 2882 | A formfactor configuration file provides information about the target |
| 2883 | hardware for which the image is being built and information that the |
| 2884 | build system cannot obtain from other sources such as the kernel. Some |
| 2885 | examples of information contained in a formfactor configuration file |
| 2886 | include framebuffer orientation, whether or not the system has a |
| 2887 | keyboard, the positioning of the keyboard in relation to the screen, and |
| 2888 | the screen resolution. |
| 2889 | |
| 2890 | The build system uses reasonable defaults in most cases. However, if |
| 2891 | customization is necessary, you need to create a ``machconfig`` file in |
| 2892 | the ``meta/recipes-bsp/formfactor/files`` directory. This directory |
| 2893 | contains directories for specific machines such as ``qemuarm`` and |
| 2894 | ``qemux86``. For information about the settings available and the |
| 2895 | defaults, see the ``meta/recipes-bsp/formfactor/files/config`` file |
| 2896 | found in the same area. |
| 2897 | |
| 2898 | Following is an example for "qemuarm" machine: |
| 2899 | :: |
| 2900 | |
| 2901 | HAVE_TOUCHSCREEN=1 |
| 2902 | HAVE_KEYBOARD=1 |
| 2903 | DISPLAY_CAN_ROTATE=0 |
| 2904 | DISPLAY_ORIENTATION=0 |
| 2905 | #DISPLAY_WIDTH_PIXELS=640 |
| 2906 | #DISPLAY_HEIGHT_PIXELS=480 |
| 2907 | #DISPLAY_BPP=16 |
| 2908 | DISPLAY_DPI=150 |
| 2909 | DISPLAY_SUBPIXEL_ORDER=vrgb |
| 2910 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2911 | Upgrading Recipes |
| 2912 | ================= |
| 2913 | |
| 2914 | Over time, upstream developers publish new versions for software built |
| 2915 | by layer recipes. It is recommended to keep recipes up-to-date with |
| 2916 | upstream version releases. |
| 2917 | |
| 2918 | While several methods exist that allow you upgrade a recipe, you might |
| 2919 | consider checking on the upgrade status of a recipe first. You can do so |
| 2920 | using the ``devtool check-upgrade-status`` command. See the |
| 2921 | ":ref:`devtool-checking-on-the-upgrade-status-of-a-recipe`" |
| 2922 | section in the Yocto Project Reference Manual for more information. |
| 2923 | |
| 2924 | The remainder of this section describes three ways you can upgrade a |
| 2925 | recipe. You can use the Automated Upgrade Helper (AUH) to set up |
| 2926 | automatic version upgrades. Alternatively, you can use |
| 2927 | ``devtool upgrade`` to set up semi-automatic version upgrades. Finally, |
| 2928 | you can manually upgrade a recipe by editing the recipe itself. |
| 2929 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2930 | Using the Auto Upgrade Helper (AUH) |
| 2931 | ----------------------------------- |
| 2932 | |
| 2933 | The AUH utility works in conjunction with the OpenEmbedded build system |
| 2934 | in order to automatically generate upgrades for recipes based on new |
| 2935 | versions being published upstream. Use AUH when you want to create a |
| 2936 | service that performs the upgrades automatically and optionally sends |
| 2937 | you an email with the results. |
| 2938 | |
| 2939 | AUH allows you to update several recipes with a single use. You can also |
| 2940 | optionally perform build and integration tests using images with the |
| 2941 | results saved to your hard drive and emails of results optionally sent |
| 2942 | to recipe maintainers. Finally, AUH creates Git commits with appropriate |
| 2943 | commit messages in the layer's tree for the changes made to recipes. |
| 2944 | |
| 2945 | .. note:: |
| 2946 | |
| 2947 | Conditions do exist when you should not use AUH to upgrade recipes |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2948 | and you should instead use either ``devtool upgrade`` or upgrade your |
| 2949 | recipes manually: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2950 | |
| 2951 | - When AUH cannot complete the upgrade sequence. This situation |
| 2952 | usually results because custom patches carried by the recipe |
| 2953 | cannot be automatically rebased to the new version. In this case, |
| 2954 | ``devtool upgrade`` allows you to manually resolve conflicts. |
| 2955 | |
| 2956 | - When for any reason you want fuller control over the upgrade |
| 2957 | process. For example, when you want special arrangements for |
| 2958 | testing. |
| 2959 | |
| 2960 | The following steps describe how to set up the AUH utility: |
| 2961 | |
| 2962 | 1. *Be Sure the Development Host is Set Up:* You need to be sure that |
| 2963 | your development host is set up to use the Yocto Project. For |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2964 | information on how to set up your host, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 2965 | ":ref:`dev-manual/start:Preparing the Build Host`" section. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2966 | |
| 2967 | 2. *Make Sure Git is Configured:* The AUH utility requires Git to be |
| 2968 | configured because AUH uses Git to save upgrades. Thus, you must have |
| 2969 | Git user and email configured. The following command shows your |
| 2970 | configurations: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2971 | :: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2972 | |
| 2973 | $ git config --list |
| 2974 | |
| 2975 | If you do not have the user and |
| 2976 | email configured, you can use the following commands to do so: |
| 2977 | :: |
| 2978 | |
| 2979 | $ git config --global user.name some_name |
| 2980 | $ git config --global user.email username@domain.com |
| 2981 | |
| 2982 | 3. *Clone the AUH Repository:* To use AUH, you must clone the repository |
| 2983 | onto your development host. The following command uses Git to create |
| 2984 | a local copy of the repository on your system: |
| 2985 | :: |
| 2986 | |
| 2987 | $ git clone git://git.yoctoproject.org/auto-upgrade-helper |
| 2988 | Cloning into 'auto-upgrade-helper'... remote: Counting objects: 768, done. |
| 2989 | remote: Compressing objects: 100% (300/300), done. |
| 2990 | remote: Total 768 (delta 499), reused 703 (delta 434) |
| 2991 | Receiving objects: 100% (768/768), 191.47 KiB | 98.00 KiB/s, done. |
| 2992 | Resolving deltas: 100% (499/499), done. |
| 2993 | Checking connectivity... done. |
| 2994 | |
| 2995 | AUH is not part of the :term:`OpenEmbedded-Core (OE-Core)` or |
| 2996 | :term:`Poky` repositories. |
| 2997 | |
| 2998 | 4. *Create a Dedicated Build Directory:* Run the |
| 2999 | :ref:`structure-core-script` |
| 3000 | script to create a fresh build directory that you use exclusively for |
| 3001 | running the AUH utility: |
| 3002 | :: |
| 3003 | |
| 3004 | $ cd ~/poky |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3005 | $ source oe-init-build-env your_AUH_build_directory |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3006 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3007 | Re-using an existing build directory and its configurations is not |
| 3008 | recommended as existing settings could cause AUH to fail or behave |
| 3009 | undesirably. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3010 | |
| 3011 | 5. *Make Configurations in Your Local Configuration File:* Several |
| 3012 | settings need to exist in the ``local.conf`` file in the build |
| 3013 | directory you just created for AUH. Make these following |
| 3014 | configurations: |
| 3015 | |
| 3016 | - If you want to enable :ref:`Build |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 3017 | History <dev-manual/common-tasks:maintaining build output quality>`, |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3018 | which is optional, you need the following lines in the |
| 3019 | ``conf/local.conf`` file: |
| 3020 | :: |
| 3021 | |
| 3022 | INHERIT =+ "buildhistory" |
| 3023 | BUILDHISTORY_COMMIT = "1" |
| 3024 | |
| 3025 | With this configuration and a successful |
| 3026 | upgrade, a build history "diff" file appears in the |
| 3027 | ``upgrade-helper/work/recipe/buildhistory-diff.txt`` file found in |
| 3028 | your build directory. |
| 3029 | |
| 3030 | - If you want to enable testing through the |
| 3031 | :ref:`testimage <ref-classes-testimage*>` |
| 3032 | class, which is optional, you need to have the following set in |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3033 | your ``conf/local.conf`` file: |
| 3034 | :: |
| 3035 | |
| 3036 | INHERIT += "testimage" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3037 | |
| 3038 | .. note:: |
| 3039 | |
| 3040 | If your distro does not enable by default ptest, which Poky |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3041 | does, you need the following in your ``local.conf`` file: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3042 | :: |
| 3043 | |
| 3044 | DISTRO_FEATURES_append = " ptest" |
| 3045 | |
| 3046 | |
| 3047 | 6. *Optionally Start a vncserver:* If you are running in a server |
| 3048 | without an X11 session, you need to start a vncserver: |
| 3049 | :: |
| 3050 | |
| 3051 | $ vncserver :1 |
| 3052 | $ export DISPLAY=:1 |
| 3053 | |
| 3054 | 7. *Create and Edit an AUH Configuration File:* You need to have the |
| 3055 | ``upgrade-helper/upgrade-helper.conf`` configuration file in your |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3056 | build directory. You can find a sample configuration file in the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 3057 | :yocto_git:`AUH source repository </auto-upgrade-helper/tree/>`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3058 | |
| 3059 | Read through the sample file and make configurations as needed. For |
| 3060 | example, if you enabled build history in your ``local.conf`` as |
| 3061 | described earlier, you must enable it in ``upgrade-helper.conf``. |
| 3062 | |
| 3063 | Also, if you are using the default ``maintainers.inc`` file supplied |
| 3064 | with Poky and located in ``meta-yocto`` and you do not set a |
| 3065 | "maintainers_whitelist" or "global_maintainer_override" in the |
| 3066 | ``upgrade-helper.conf`` configuration, and you specify "-e all" on |
| 3067 | the AUH command-line, the utility automatically sends out emails to |
| 3068 | all the default maintainers. Please avoid this. |
| 3069 | |
| 3070 | This next set of examples describes how to use the AUH: |
| 3071 | |
| 3072 | - *Upgrading a Specific Recipe:* To upgrade a specific recipe, use the |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3073 | following form: |
| 3074 | :: |
| 3075 | |
| 3076 | $ upgrade-helper.py recipe_name |
| 3077 | |
| 3078 | For example, this command upgrades the ``xmodmap`` recipe: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3079 | :: |
| 3080 | |
| 3081 | $ upgrade-helper.py xmodmap |
| 3082 | |
| 3083 | - *Upgrading a Specific Recipe to a Particular Version:* To upgrade a |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3084 | specific recipe to a particular version, use the following form: |
| 3085 | :: |
| 3086 | |
| 3087 | $ upgrade-helper.py recipe_name -t version |
| 3088 | |
| 3089 | For example, this command upgrades the ``xmodmap`` recipe to version 1.2.3: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3090 | :: |
| 3091 | |
| 3092 | $ upgrade-helper.py xmodmap -t 1.2.3 |
| 3093 | |
| 3094 | - *Upgrading all Recipes to the Latest Versions and Suppressing Email |
| 3095 | Notifications:* To upgrade all recipes to their most recent versions |
| 3096 | and suppress the email notifications, use the following command: |
| 3097 | :: |
| 3098 | |
| 3099 | $ upgrade-helper.py all |
| 3100 | |
| 3101 | - *Upgrading all Recipes to the Latest Versions and Send Email |
| 3102 | Notifications:* To upgrade all recipes to their most recent versions |
| 3103 | and send email messages to maintainers for each attempted recipe as |
| 3104 | well as a status email, use the following command: |
| 3105 | :: |
| 3106 | |
| 3107 | $ upgrade-helper.py -e all |
| 3108 | |
| 3109 | Once you have run the AUH utility, you can find the results in the AUH |
| 3110 | build directory: |
| 3111 | :: |
| 3112 | |
| 3113 | ${BUILDDIR}/upgrade-helper/timestamp |
| 3114 | |
| 3115 | The AUH utility |
| 3116 | also creates recipe update commits from successful upgrade attempts in |
| 3117 | the layer tree. |
| 3118 | |
| 3119 | You can easily set up to run the AUH utility on a regular basis by using |
| 3120 | a cron job. See the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 3121 | :yocto_git:`weeklyjob.sh </auto-upgrade-helper/tree/weeklyjob.sh>` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3122 | file distributed with the utility for an example. |
| 3123 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3124 | Using ``devtool upgrade`` |
| 3125 | ------------------------- |
| 3126 | |
| 3127 | As mentioned earlier, an alternative method for upgrading recipes to |
| 3128 | newer versions is to use |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 3129 | :doc:`devtool upgrade </ref-manual/devtool-reference>`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3130 | You can read about ``devtool upgrade`` in general in the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 3131 | ":ref:`sdk-manual/extensible:use \`\`devtool upgrade\`\` to create a version of the recipe that supports a newer version of the software`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3132 | section in the Yocto Project Application Development and the Extensible |
| 3133 | Software Development Kit (eSDK) Manual. |
| 3134 | |
| 3135 | To see all the command-line options available with ``devtool upgrade``, |
| 3136 | use the following help command: |
| 3137 | :: |
| 3138 | |
| 3139 | $ devtool upgrade -h |
| 3140 | |
| 3141 | If you want to find out what version a recipe is currently at upstream |
| 3142 | without any attempt to upgrade your local version of the recipe, you can |
| 3143 | use the following command: |
| 3144 | :: |
| 3145 | |
| 3146 | $ devtool latest-version recipe_name |
| 3147 | |
| 3148 | As mentioned in the previous section describing AUH, ``devtool upgrade`` |
| 3149 | works in a less-automated manner than AUH. Specifically, |
| 3150 | ``devtool upgrade`` only works on a single recipe that you name on the |
| 3151 | command line, cannot perform build and integration testing using images, |
| 3152 | and does not automatically generate commits for changes in the source |
| 3153 | tree. Despite all these "limitations", ``devtool upgrade`` updates the |
| 3154 | recipe file to the new upstream version and attempts to rebase custom |
| 3155 | patches contained by the recipe as needed. |
| 3156 | |
| 3157 | .. note:: |
| 3158 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3159 | AUH uses much of ``devtool upgrade`` behind the scenes making AUH somewhat |
| 3160 | of a "wrapper" application for ``devtool upgrade``. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3161 | |
| 3162 | A typical scenario involves having used Git to clone an upstream |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3163 | repository that you use during build operations. Because you have built the |
| 3164 | recipe in the past, the layer is likely added to your |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3165 | configuration already. If for some reason, the layer is not added, you |
| 3166 | could add it easily using the |
| 3167 | ":ref:`bitbake-layers <bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script>`" |
| 3168 | script. For example, suppose you use the ``nano.bb`` recipe from the |
| 3169 | ``meta-oe`` layer in the ``meta-openembedded`` repository. For this |
| 3170 | example, assume that the layer has been cloned into following area: |
| 3171 | :: |
| 3172 | |
| 3173 | /home/scottrif/meta-openembedded |
| 3174 | |
| 3175 | The following command from your |
| 3176 | :term:`Build Directory` adds the layer to |
| 3177 | your build configuration (i.e. ``${BUILDDIR}/conf/bblayers.conf``): |
| 3178 | :: |
| 3179 | |
| 3180 | $ bitbake-layers add-layer /home/scottrif/meta-openembedded/meta-oe |
| 3181 | NOTE: Starting bitbake server... |
| 3182 | Parsing recipes: 100% |##########################################| Time: 0:00:55 |
| 3183 | Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors. |
| 3184 | Removing 12 recipes from the x86_64 sysroot: 100% |##############| Time: 0:00:00 |
| 3185 | Removing 1 recipes from the x86_64_i586 sysroot: 100% |##########| Time: 0:00:00 |
| 3186 | Removing 5 recipes from the i586 sysroot: 100% |#################| Time: 0:00:00 |
| 3187 | Removing 5 recipes from the qemux86 sysroot: 100% |##############| Time: 0:00:00 |
| 3188 | |
| 3189 | For this example, assume that the ``nano.bb`` recipe that |
| 3190 | is upstream has a 2.9.3 version number. However, the version in the |
| 3191 | local repository is 2.7.4. The following command from your build |
| 3192 | directory automatically upgrades the recipe for you: |
| 3193 | |
| 3194 | .. note:: |
| 3195 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3196 | Using the ``-V`` option is not necessary. Omitting the version number causes |
| 3197 | ``devtool upgrade`` to upgrade the recipe to the most recent version. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3198 | |
| 3199 | :: |
| 3200 | |
| 3201 | $ devtool upgrade nano -V 2.9.3 |
| 3202 | NOTE: Starting bitbake server... |
| 3203 | NOTE: Creating workspace layer in /home/scottrif/poky/build/workspace |
| 3204 | Parsing recipes: 100% |##########################################| Time: 0:00:46 |
| 3205 | Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors. |
| 3206 | NOTE: Extracting current version source... |
| 3207 | NOTE: Resolving any missing task queue dependencies |
| 3208 | . |
| 3209 | . |
| 3210 | . |
| 3211 | NOTE: Executing SetScene Tasks |
| 3212 | NOTE: Executing RunQueue Tasks |
| 3213 | NOTE: Tasks Summary: Attempted 74 tasks of which 72 didn't need to be rerun and all succeeded. |
| 3214 | Adding changed files: 100% |#####################################| Time: 0:00:00 |
| 3215 | NOTE: Upgraded source extracted to /home/scottrif/poky/build/workspace/sources/nano |
| 3216 | NOTE: New recipe is /home/scottrif/poky/build/workspace/recipes/nano/nano_2.9.3.bb |
| 3217 | |
| 3218 | Continuing with this example, you can use ``devtool build`` to build the |
| 3219 | newly upgraded recipe: |
| 3220 | :: |
| 3221 | |
| 3222 | $ devtool build nano |
| 3223 | NOTE: Starting bitbake server... |
| 3224 | Loading cache: 100% |################################################################################################| Time: 0:00:01 |
| 3225 | Loaded 2040 entries from dependency cache. |
| 3226 | Parsing recipes: 100% |##############################################################################################| Time: 0:00:00 |
| 3227 | Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors. |
| 3228 | NOTE: Resolving any missing task queue dependencies |
| 3229 | . |
| 3230 | . |
| 3231 | . |
| 3232 | NOTE: Executing SetScene Tasks |
| 3233 | NOTE: Executing RunQueue Tasks |
| 3234 | NOTE: nano: compiling from external source tree /home/scottrif/poky/build/workspace/sources/nano |
| 3235 | NOTE: Tasks Summary: Attempted 520 tasks of which 304 didn't need to be rerun and all succeeded. |
| 3236 | |
| 3237 | Within the ``devtool upgrade`` workflow, opportunity |
| 3238 | exists to deploy and test your rebuilt software. For this example, |
| 3239 | however, running ``devtool finish`` cleans up the workspace once the |
| 3240 | source in your workspace is clean. This usually means using Git to stage |
| 3241 | and submit commits for the changes generated by the upgrade process. |
| 3242 | |
| 3243 | Once the tree is clean, you can clean things up in this example with the |
| 3244 | following command from the ``${BUILDDIR}/workspace/sources/nano`` |
| 3245 | directory: |
| 3246 | :: |
| 3247 | |
| 3248 | $ devtool finish nano meta-oe |
| 3249 | NOTE: Starting bitbake server... |
| 3250 | Loading cache: 100% |################################################################################################| Time: 0:00:00 |
| 3251 | Loaded 2040 entries from dependency cache. |
| 3252 | Parsing recipes: 100% |##############################################################################################| Time: 0:00:01 |
| 3253 | Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors. |
| 3254 | NOTE: Adding new patch 0001-nano.bb-Stuff-I-changed-when-upgrading-nano.bb.patch |
| 3255 | NOTE: Updating recipe nano_2.9.3.bb |
| 3256 | NOTE: Removing file /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano/nano_2.7.4.bb |
| 3257 | NOTE: Moving recipe file to /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano |
| 3258 | NOTE: Leaving source tree /home/scottrif/poky/build/workspace/sources/nano as-is; if you no longer need it then please delete it manually |
| 3259 | |
| 3260 | |
| 3261 | Using the ``devtool finish`` command cleans up the workspace and creates a patch |
| 3262 | file based on your commits. The tool puts all patch files back into the |
| 3263 | source directory in a sub-directory named ``nano`` in this case. |
| 3264 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3265 | Manually Upgrading a Recipe |
| 3266 | --------------------------- |
| 3267 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3268 | If for some reason you choose not to upgrade recipes using |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 3269 | :ref:`dev-manual/common-tasks:Using the Auto Upgrade Helper (AUH)` or |
| 3270 | by :ref:`dev-manual/common-tasks:Using \`\`devtool upgrade\`\``, |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3271 | you can manually edit the recipe files to upgrade the versions. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3272 | |
| 3273 | .. note:: |
| 3274 | |
| 3275 | Manually updating multiple recipes scales poorly and involves many |
| 3276 | steps. The recommendation to upgrade recipe versions is through AUH |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3277 | or ``devtool upgrade``, both of which automate some steps and provide |
| 3278 | guidance for others needed for the manual process. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3279 | |
| 3280 | To manually upgrade recipe versions, follow these general steps: |
| 3281 | |
| 3282 | 1. *Change the Version:* Rename the recipe such that the version (i.e. |
| 3283 | the :term:`PV` part of the recipe name) |
| 3284 | changes appropriately. If the version is not part of the recipe name, |
| 3285 | change the value as it is set for ``PV`` within the recipe itself. |
| 3286 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3287 | 2. *Update* ``SRCREV`` *if Needed*: If the source code your recipe builds |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3288 | is fetched from Git or some other version control system, update |
| 3289 | :term:`SRCREV` to point to the |
| 3290 | commit hash that matches the new version. |
| 3291 | |
| 3292 | 3. *Build the Software:* Try to build the recipe using BitBake. Typical |
| 3293 | build failures include the following: |
| 3294 | |
| 3295 | - License statements were updated for the new version. For this |
| 3296 | case, you need to review any changes to the license and update the |
| 3297 | values of :term:`LICENSE` and |
| 3298 | :term:`LIC_FILES_CHKSUM` |
| 3299 | as needed. |
| 3300 | |
| 3301 | .. note:: |
| 3302 | |
| 3303 | License changes are often inconsequential. For example, the |
| 3304 | license text's copyright year might have changed. |
| 3305 | |
| 3306 | - Custom patches carried by the older version of the recipe might |
| 3307 | fail to apply to the new version. For these cases, you need to |
| 3308 | review the failures. Patches might not be necessary for the new |
| 3309 | version of the software if the upgraded version has fixed those |
| 3310 | issues. If a patch is necessary and failing, you need to rebase it |
| 3311 | into the new version. |
| 3312 | |
| 3313 | 4. *Optionally Attempt to Build for Several Architectures:* Once you |
| 3314 | successfully build the new software for a given architecture, you |
| 3315 | could test the build for other architectures by changing the |
| 3316 | :term:`MACHINE` variable and |
| 3317 | rebuilding the software. This optional step is especially important |
| 3318 | if the recipe is to be released publicly. |
| 3319 | |
| 3320 | 5. *Check the Upstream Change Log or Release Notes:* Checking both these |
| 3321 | reveals if new features exist that could break |
| 3322 | backwards-compatibility. If so, you need to take steps to mitigate or |
| 3323 | eliminate that situation. |
| 3324 | |
| 3325 | 6. *Optionally Create a Bootable Image and Test:* If you want, you can |
| 3326 | test the new software by booting it onto actual hardware. |
| 3327 | |
| 3328 | 7. *Create a Commit with the Change in the Layer Repository:* After all |
| 3329 | builds work and any testing is successful, you can create commits for |
| 3330 | any changes in the layer holding your upgraded recipe. |
| 3331 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3332 | Finding Temporary Source Code |
| 3333 | ============================= |
| 3334 | |
| 3335 | You might find it helpful during development to modify the temporary |
| 3336 | source code used by recipes to build packages. For example, suppose you |
| 3337 | are developing a patch and you need to experiment a bit to figure out |
| 3338 | your solution. After you have initially built the package, you can |
| 3339 | iteratively tweak the source code, which is located in the |
| 3340 | :term:`Build Directory`, and then you can |
| 3341 | force a re-compile and quickly test your altered code. Once you settle |
| 3342 | on a solution, you can then preserve your changes in the form of |
| 3343 | patches. |
| 3344 | |
| 3345 | During a build, the unpacked temporary source code used by recipes to |
| 3346 | build packages is available in the Build Directory as defined by the |
| 3347 | :term:`S` variable. Below is the default |
| 3348 | value for the ``S`` variable as defined in the |
| 3349 | ``meta/conf/bitbake.conf`` configuration file in the |
| 3350 | :term:`Source Directory`: |
| 3351 | :: |
| 3352 | |
| 3353 | S = "${WORKDIR}/${BP}" |
| 3354 | |
| 3355 | You should be aware that many recipes override the |
| 3356 | ``S`` variable. For example, recipes that fetch their source from Git |
| 3357 | usually set ``S`` to ``${WORKDIR}/git``. |
| 3358 | |
| 3359 | .. note:: |
| 3360 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3361 | The :term:`BP` represents the base recipe name, which consists of the name |
| 3362 | and version: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3363 | :: |
| 3364 | |
| 3365 | BP = "${BPN}-${PV}" |
| 3366 | |
| 3367 | |
| 3368 | The path to the work directory for the recipe |
| 3369 | (:term:`WORKDIR`) is defined as |
| 3370 | follows: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3371 | :: |
| 3372 | |
| 3373 | ${TMPDIR}/work/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR} |
| 3374 | |
| 3375 | The actual directory depends on several things: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3376 | |
| 3377 | - :term:`TMPDIR`: The top-level build |
| 3378 | output directory. |
| 3379 | |
| 3380 | - :term:`MULTIMACH_TARGET_SYS`: |
| 3381 | The target system identifier. |
| 3382 | |
| 3383 | - :term:`PN`: The recipe name. |
| 3384 | |
| 3385 | - :term:`EXTENDPE`: The epoch - (if |
| 3386 | :term:`PE` is not specified, which is |
| 3387 | usually the case for most recipes, then ``EXTENDPE`` is blank). |
| 3388 | |
| 3389 | - :term:`PV`: The recipe version. |
| 3390 | |
| 3391 | - :term:`PR`: The recipe revision. |
| 3392 | |
| 3393 | As an example, assume a Source Directory top-level folder named |
| 3394 | ``poky``, a default Build Directory at ``poky/build``, and a |
| 3395 | ``qemux86-poky-linux`` machine target system. Furthermore, suppose your |
| 3396 | recipe is named ``foo_1.3.0.bb``. In this case, the work directory the |
| 3397 | build system uses to build the package would be as follows: |
| 3398 | :: |
| 3399 | |
| 3400 | poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0 |
| 3401 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3402 | Using Quilt in Your Workflow |
| 3403 | ============================ |
| 3404 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3405 | `Quilt <https://savannah.nongnu.org/projects/quilt>`__ is a powerful tool |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3406 | that allows you to capture source code changes without having a clean |
| 3407 | source tree. This section outlines the typical workflow you can use to |
| 3408 | modify source code, test changes, and then preserve the changes in the |
| 3409 | form of a patch all using Quilt. |
| 3410 | |
| 3411 | .. note:: |
| 3412 | |
| 3413 | With regard to preserving changes to source files, if you clean a |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3414 | recipe or have ``rm_work`` enabled, the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 3415 | :ref:`devtool workflow <sdk-manual/extensible:using \`\`devtool\`\` in your sdk workflow>` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3416 | as described in the Yocto Project Application Development and the |
| 3417 | Extensible Software Development Kit (eSDK) manual is a safer |
| 3418 | development flow than the flow that uses Quilt. |
| 3419 | |
| 3420 | Follow these general steps: |
| 3421 | |
| 3422 | 1. *Find the Source Code:* Temporary source code used by the |
| 3423 | OpenEmbedded build system is kept in the |
| 3424 | :term:`Build Directory`. See the |
| 3425 | "`Finding Temporary Source |
| 3426 | Code <#finding-the-temporary-source-code>`__" section to learn how to |
| 3427 | locate the directory that has the temporary source code for a |
| 3428 | particular package. |
| 3429 | |
| 3430 | 2. *Change Your Working Directory:* You need to be in the directory that |
| 3431 | has the temporary source code. That directory is defined by the |
| 3432 | :term:`S` variable. |
| 3433 | |
| 3434 | 3. *Create a New Patch:* Before modifying source code, you need to |
| 3435 | create a new patch. To create a new patch file, use ``quilt new`` as |
| 3436 | below: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3437 | :: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3438 | |
| 3439 | $ quilt new my_changes.patch |
| 3440 | |
| 3441 | 4. *Notify Quilt and Add Files:* After creating the patch, you need to |
| 3442 | notify Quilt about the files you plan to edit. You notify Quilt by |
| 3443 | adding the files to the patch you just created: |
| 3444 | :: |
| 3445 | |
| 3446 | $ quilt add file1.c file2.c file3.c |
| 3447 | |
| 3448 | 5. *Edit the Files:* Make your changes in the source code to the files |
| 3449 | you added to the patch. |
| 3450 | |
| 3451 | 6. *Test Your Changes:* Once you have modified the source code, the |
| 3452 | easiest way to test your changes is by calling the ``do_compile`` |
| 3453 | task as shown in the following example: |
| 3454 | :: |
| 3455 | |
| 3456 | $ bitbake -c compile -f package |
| 3457 | |
| 3458 | The ``-f`` or ``--force`` option forces the specified task to |
| 3459 | execute. If you find problems with your code, you can just keep |
| 3460 | editing and re-testing iteratively until things work as expected. |
| 3461 | |
| 3462 | .. note:: |
| 3463 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3464 | All the modifications you make to the temporary source code disappear |
| 3465 | once you run the ``do_clean`` or ``do_cleanall`` tasks using BitBake |
| 3466 | (i.e. ``bitbake -c clean package`` and ``bitbake -c cleanall package``). |
| 3467 | Modifications will also disappear if you use the ``rm_work`` feature as |
| 3468 | described in the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 3469 | ":ref:`dev-manual/common-tasks:conserving disk space during builds`" |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3470 | section. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3471 | |
| 3472 | 7. *Generate the Patch:* Once your changes work as expected, you need to |
| 3473 | use Quilt to generate the final patch that contains all your |
| 3474 | modifications. |
| 3475 | :: |
| 3476 | |
| 3477 | $ quilt refresh |
| 3478 | |
| 3479 | At this point, the |
| 3480 | ``my_changes.patch`` file has all your edits made to the ``file1.c``, |
| 3481 | ``file2.c``, and ``file3.c`` files. |
| 3482 | |
| 3483 | You can find the resulting patch file in the ``patches/`` |
| 3484 | subdirectory of the source (``S``) directory. |
| 3485 | |
| 3486 | 8. *Copy the Patch File:* For simplicity, copy the patch file into a |
| 3487 | directory named ``files``, which you can create in the same directory |
| 3488 | that holds the recipe (``.bb``) file or the append (``.bbappend``) |
| 3489 | file. Placing the patch here guarantees that the OpenEmbedded build |
| 3490 | system will find the patch. Next, add the patch into the ``SRC_URI`` |
| 3491 | of the recipe. Here is an example: |
| 3492 | :: |
| 3493 | |
| 3494 | SRC_URI += "file://my_changes.patch" |
| 3495 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3496 | Using a Development Shell |
| 3497 | ========================= |
| 3498 | |
| 3499 | When debugging certain commands or even when just editing packages, |
| 3500 | ``devshell`` can be a useful tool. When you invoke ``devshell``, all |
| 3501 | tasks up to and including |
| 3502 | :ref:`ref-tasks-patch` are run for the |
| 3503 | specified target. Then, a new terminal is opened and you are placed in |
| 3504 | ``${``\ :term:`S`\ ``}``, the source |
| 3505 | directory. In the new terminal, all the OpenEmbedded build-related |
| 3506 | environment variables are still defined so you can use commands such as |
| 3507 | ``configure`` and ``make``. The commands execute just as if the |
| 3508 | OpenEmbedded build system were executing them. Consequently, working |
| 3509 | this way can be helpful when debugging a build or preparing software to |
| 3510 | be used with the OpenEmbedded build system. |
| 3511 | |
| 3512 | Following is an example that uses ``devshell`` on a target named |
| 3513 | ``matchbox-desktop``: |
| 3514 | :: |
| 3515 | |
| 3516 | $ bitbake matchbox-desktop -c devshell |
| 3517 | |
| 3518 | This command spawns a terminal with a shell prompt within the |
| 3519 | OpenEmbedded build environment. The |
| 3520 | :term:`OE_TERMINAL` variable |
| 3521 | controls what type of shell is opened. |
| 3522 | |
| 3523 | For spawned terminals, the following occurs: |
| 3524 | |
| 3525 | - The ``PATH`` variable includes the cross-toolchain. |
| 3526 | |
| 3527 | - The ``pkgconfig`` variables find the correct ``.pc`` files. |
| 3528 | |
| 3529 | - The ``configure`` command finds the Yocto Project site files as well |
| 3530 | as any other necessary files. |
| 3531 | |
| 3532 | Within this environment, you can run configure or compile commands as if |
| 3533 | they were being run by the OpenEmbedded build system itself. As noted |
| 3534 | earlier, the working directory also automatically changes to the Source |
| 3535 | Directory (:term:`S`). |
| 3536 | |
| 3537 | To manually run a specific task using ``devshell``, run the |
| 3538 | corresponding ``run.*`` script in the |
| 3539 | ``${``\ :term:`WORKDIR`\ ``}/temp`` |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3540 | directory (e.g., ``run.do_configure.``\ `pid`). If a task's script does |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3541 | not exist, which would be the case if the task was skipped by way of the |
| 3542 | sstate cache, you can create the task by first running it outside of the |
| 3543 | ``devshell``: |
| 3544 | :: |
| 3545 | |
| 3546 | $ bitbake -c task |
| 3547 | |
| 3548 | .. note:: |
| 3549 | |
| 3550 | - Execution of a task's ``run.*`` script and BitBake's execution of |
| 3551 | a task are identical. In other words, running the script re-runs |
| 3552 | the task just as it would be run using the ``bitbake -c`` command. |
| 3553 | |
| 3554 | - Any ``run.*`` file that does not have a ``.pid`` extension is a |
| 3555 | symbolic link (symlink) to the most recent version of that file. |
| 3556 | |
| 3557 | Remember, that the ``devshell`` is a mechanism that allows you to get |
| 3558 | into the BitBake task execution environment. And as such, all commands |
| 3559 | must be called just as BitBake would call them. That means you need to |
| 3560 | provide the appropriate options for cross-compilation and so forth as |
| 3561 | applicable. |
| 3562 | |
| 3563 | When you are finished using ``devshell``, exit the shell or close the |
| 3564 | terminal window. |
| 3565 | |
| 3566 | .. note:: |
| 3567 | |
| 3568 | - It is worth remembering that when using ``devshell`` you need to |
| 3569 | use the full compiler name such as ``arm-poky-linux-gnueabi-gcc`` |
| 3570 | instead of just using ``gcc``. The same applies to other |
| 3571 | applications such as ``binutils``, ``libtool`` and so forth. |
| 3572 | BitBake sets up environment variables such as ``CC`` to assist |
| 3573 | applications, such as ``make`` to find the correct tools. |
| 3574 | |
| 3575 | - It is also worth noting that ``devshell`` still works over X11 |
| 3576 | forwarding and similar situations. |
| 3577 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3578 | Using a Development Python Shell |
| 3579 | ================================ |
| 3580 | |
| 3581 | Similar to working within a development shell as described in the |
| 3582 | previous section, you can also spawn and work within an interactive |
| 3583 | Python development shell. When debugging certain commands or even when |
| 3584 | just editing packages, ``devpyshell`` can be a useful tool. When you |
| 3585 | invoke ``devpyshell``, all tasks up to and including |
| 3586 | :ref:`ref-tasks-patch` are run for the |
| 3587 | specified target. Then a new terminal is opened. Additionally, key |
| 3588 | Python objects and code are available in the same way they are to |
| 3589 | BitBake tasks, in particular, the data store 'd'. So, commands such as |
| 3590 | the following are useful when exploring the data store and running |
| 3591 | functions: |
| 3592 | :: |
| 3593 | |
| 3594 | pydevshell> d.getVar("STAGING_DIR") |
| 3595 | '/media/build1/poky/build/tmp/sysroots' |
| 3596 | pydevshell> d.getVar("STAGING_DIR") |
| 3597 | '${TMPDIR}/sysroots' |
| 3598 | pydevshell> d.setVar("FOO", "bar") |
| 3599 | pydevshell> d.getVar("FOO") |
| 3600 | 'bar' |
| 3601 | pydevshell> d.delVar("FOO") |
| 3602 | pydevshell> d.getVar("FOO") |
| 3603 | pydevshell> bb.build.exec_func("do_unpack", d) |
| 3604 | pydevshell> |
| 3605 | |
| 3606 | The commands execute just as if the OpenEmbedded build |
| 3607 | system were executing them. Consequently, working this way can be |
| 3608 | helpful when debugging a build or preparing software to be used with the |
| 3609 | OpenEmbedded build system. |
| 3610 | |
| 3611 | Following is an example that uses ``devpyshell`` on a target named |
| 3612 | ``matchbox-desktop``: |
| 3613 | :: |
| 3614 | |
| 3615 | $ bitbake matchbox-desktop -c devpyshell |
| 3616 | |
| 3617 | This command spawns a terminal and places you in an interactive Python |
| 3618 | interpreter within the OpenEmbedded build environment. The |
| 3619 | :term:`OE_TERMINAL` variable |
| 3620 | controls what type of shell is opened. |
| 3621 | |
| 3622 | When you are finished using ``devpyshell``, you can exit the shell |
| 3623 | either by using Ctrl+d or closing the terminal window. |
| 3624 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3625 | Building |
| 3626 | ======== |
| 3627 | |
| 3628 | This section describes various build procedures. For example, the steps |
| 3629 | needed for a simple build, a target that uses multiple configurations, |
| 3630 | building an image for more than one machine, and so forth. |
| 3631 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3632 | Building a Simple Image |
| 3633 | ----------------------- |
| 3634 | |
| 3635 | In the development environment, you need to build an image whenever you |
| 3636 | change hardware support, add or change system libraries, or add or |
| 3637 | change services that have dependencies. Several methods exist that allow |
| 3638 | you to build an image within the Yocto Project. This section presents |
| 3639 | the basic steps you need to build a simple image using BitBake from a |
| 3640 | build host running Linux. |
| 3641 | |
| 3642 | .. note:: |
| 3643 | |
| 3644 | - For information on how to build an image using |
| 3645 | :term:`Toaster`, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 3646 | :doc:`/toaster-manual/index`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3647 | |
| 3648 | - For information on how to use ``devtool`` to build images, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 3649 | ":ref:`sdk-manual/extensible:using \`\`devtool\`\` in your sdk workflow`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3650 | section in the Yocto Project Application Development and the |
| 3651 | Extensible Software Development Kit (eSDK) manual. |
| 3652 | |
| 3653 | - For a quick example on how to build an image using the |
| 3654 | OpenEmbedded build system, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 3655 | :doc:`/brief-yoctoprojectqs/index` document. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3656 | |
| 3657 | The build process creates an entire Linux distribution from source and |
| 3658 | places it in your :term:`Build Directory` under |
| 3659 | ``tmp/deploy/images``. For detailed information on the build process |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 3660 | using BitBake, see the ":ref:`overview-manual/concepts:images`" section in the |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3661 | Yocto Project Overview and Concepts Manual. |
| 3662 | |
| 3663 | The following figure and list overviews the build process: |
| 3664 | |
| 3665 | .. image:: figures/bitbake-build-flow.png |
| 3666 | :align: center |
| 3667 | |
| 3668 | 1. *Set up Your Host Development System to Support Development Using the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 3669 | Yocto Project*: See the ":doc:`start`" section for options on how to get a |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3670 | build host ready to use the Yocto Project. |
| 3671 | |
| 3672 | 2. *Initialize the Build Environment:* Initialize the build environment |
| 3673 | by sourcing the build environment script (i.e. |
| 3674 | :ref:`structure-core-script`): |
| 3675 | :: |
| 3676 | |
| 3677 | $ source oe-init-build-env [build_dir] |
| 3678 | |
| 3679 | When you use the initialization script, the OpenEmbedded build system |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3680 | uses ``build`` as the default :term:`Build Directory` in your current work |
| 3681 | directory. You can use a `build_dir` argument with the script to |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3682 | specify a different build directory. |
| 3683 | |
| 3684 | .. note:: |
| 3685 | |
| 3686 | A common practice is to use a different Build Directory for |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3687 | different targets. For example, ``~/build/x86`` for a ``qemux86`` |
| 3688 | target, and ``~/build/arm`` for a ``qemuarm`` target. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3689 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3690 | 3. *Make Sure Your* ``local.conf`` *File is Correct*: Ensure the |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3691 | ``conf/local.conf`` configuration file, which is found in the Build |
| 3692 | Directory, is set up how you want it. This file defines many aspects |
| 3693 | of the build environment including the target machine architecture |
| 3694 | through the ``MACHINE`` variable, the packaging format used during |
| 3695 | the build |
| 3696 | (:term:`PACKAGE_CLASSES`), |
| 3697 | and a centralized tarball download directory through the |
| 3698 | :term:`DL_DIR` variable. |
| 3699 | |
| 3700 | 4. *Build the Image:* Build the image using the ``bitbake`` command: |
| 3701 | :: |
| 3702 | |
| 3703 | $ bitbake target |
| 3704 | |
| 3705 | .. note:: |
| 3706 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3707 | For information on BitBake, see the :doc:`bitbake:index`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3708 | |
| 3709 | The target is the name of the recipe you want to build. Common |
| 3710 | targets are the images in ``meta/recipes-core/images``, |
| 3711 | ``meta/recipes-sato/images``, and so forth all found in the |
| 3712 | :term:`Source Directory`. Or, the target |
| 3713 | can be the name of a recipe for a specific piece of software such as |
| 3714 | BusyBox. For more details about the images the OpenEmbedded build |
| 3715 | system supports, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 3716 | ":ref:`ref-manual/images:Images`" chapter in the Yocto |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3717 | Project Reference Manual. |
| 3718 | |
| 3719 | As an example, the following command builds the |
| 3720 | ``core-image-minimal`` image: |
| 3721 | :: |
| 3722 | |
| 3723 | $ bitbake core-image-minimal |
| 3724 | |
| 3725 | Once an |
| 3726 | image has been built, it often needs to be installed. The images and |
| 3727 | kernels built by the OpenEmbedded build system are placed in the |
| 3728 | Build Directory in ``tmp/deploy/images``. For information on how to |
| 3729 | run pre-built images such as ``qemux86`` and ``qemuarm``, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 3730 | :doc:`/sdk-manual/index` manual. For |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3731 | information about how to install these images, see the documentation |
| 3732 | for your particular board or machine. |
| 3733 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3734 | Building Images for Multiple Targets Using Multiple Configurations |
| 3735 | ------------------------------------------------------------------ |
| 3736 | |
| 3737 | You can use a single ``bitbake`` command to build multiple images or |
| 3738 | packages for different targets where each image or package requires a |
| 3739 | different configuration (multiple configuration builds). The builds, in |
| 3740 | this scenario, are sometimes referred to as "multiconfigs", and this |
| 3741 | section uses that term throughout. |
| 3742 | |
| 3743 | This section describes how to set up for multiple configuration builds |
| 3744 | and how to account for cross-build dependencies between the |
| 3745 | multiconfigs. |
| 3746 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3747 | Setting Up and Running a Multiple Configuration Build |
| 3748 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3749 | |
| 3750 | To accomplish a multiple configuration build, you must define each |
| 3751 | target's configuration separately using a parallel configuration file in |
| 3752 | the :term:`Build Directory`, and you |
| 3753 | must follow a required file hierarchy. Additionally, you must enable the |
| 3754 | multiple configuration builds in your ``local.conf`` file. |
| 3755 | |
| 3756 | Follow these steps to set up and execute multiple configuration builds: |
| 3757 | |
| 3758 | - *Create Separate Configuration Files*: You need to create a single |
| 3759 | configuration file for each build target (each multiconfig). |
| 3760 | Minimally, each configuration file must define the machine and the |
| 3761 | temporary directory BitBake uses for the build. Suggested practice |
| 3762 | dictates that you do not overlap the temporary directories used |
| 3763 | during the builds. However, it is possible that you can share the |
| 3764 | temporary directory |
| 3765 | (:term:`TMPDIR`). For example, |
| 3766 | consider a scenario with two different multiconfigs for the same |
| 3767 | :term:`MACHINE`: "qemux86" built |
| 3768 | for two distributions such as "poky" and "poky-lsb". In this case, |
| 3769 | you might want to use the same ``TMPDIR``. |
| 3770 | |
| 3771 | Here is an example showing the minimal statements needed in a |
| 3772 | configuration file for a "qemux86" target whose temporary build |
| 3773 | directory is ``tmpmultix86``: |
| 3774 | :: |
| 3775 | |
| 3776 | MACHINE = "qemux86" |
| 3777 | TMPDIR = "${TOPDIR}/tmpmultix86" |
| 3778 | |
| 3779 | The location for these multiconfig configuration files is specific. |
| 3780 | They must reside in the current build directory in a sub-directory of |
| 3781 | ``conf`` named ``multiconfig``. Following is an example that defines |
| 3782 | two configuration files for the "x86" and "arm" multiconfigs: |
| 3783 | |
| 3784 | .. image:: figures/multiconfig_files.png |
| 3785 | :align: center |
| 3786 | |
| 3787 | The reason for this required file hierarchy is because the ``BBPATH`` |
| 3788 | variable is not constructed until the layers are parsed. |
| 3789 | Consequently, using the configuration file as a pre-configuration |
| 3790 | file is not possible unless it is located in the current working |
| 3791 | directory. |
| 3792 | |
| 3793 | - *Add the BitBake Multi-configuration Variable to the Local |
| 3794 | Configuration File*: Use the |
| 3795 | :term:`BBMULTICONFIG` |
| 3796 | variable in your ``conf/local.conf`` configuration file to specify |
| 3797 | each multiconfig. Continuing with the example from the previous |
| 3798 | figure, the ``BBMULTICONFIG`` variable needs to enable two |
| 3799 | multiconfigs: "x86" and "arm" by specifying each configuration file: |
| 3800 | :: |
| 3801 | |
| 3802 | BBMULTICONFIG = "x86 arm" |
| 3803 | |
| 3804 | .. note:: |
| 3805 | |
| 3806 | A "default" configuration already exists by definition. This |
| 3807 | configuration is named: "" (i.e. empty string) and is defined by |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3808 | the variables coming from your ``local.conf`` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3809 | file. Consequently, the previous example actually adds two |
| 3810 | additional configurations to your build: "arm" and "x86" along |
| 3811 | with "". |
| 3812 | |
| 3813 | - *Launch BitBake*: Use the following BitBake command form to launch |
| 3814 | the multiple configuration build: |
| 3815 | :: |
| 3816 | |
| 3817 | $ bitbake [mc:multiconfigname:]target [[[mc:multiconfigname:]target] ... ] |
| 3818 | |
| 3819 | For the example in this section, the following command applies: |
| 3820 | :: |
| 3821 | |
| 3822 | $ bitbake mc:x86:core-image-minimal mc:arm:core-image-sato mc::core-image-base |
| 3823 | |
| 3824 | The previous BitBake command builds a ``core-image-minimal`` image |
| 3825 | that is configured through the ``x86.conf`` configuration file, a |
| 3826 | ``core-image-sato`` image that is configured through the ``arm.conf`` |
| 3827 | configuration file and a ``core-image-base`` that is configured |
| 3828 | through your ``local.conf`` configuration file. |
| 3829 | |
| 3830 | .. note:: |
| 3831 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3832 | Support for multiple configuration builds in the Yocto Project &DISTRO; |
| 3833 | (&DISTRO_NAME;) Release does not include Shared State (sstate) |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3834 | optimizations. Consequently, if a build uses the same object twice |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3835 | in, for example, two different ``TMPDIR`` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3836 | directories, the build either loads from an existing sstate cache for |
| 3837 | that build at the start or builds the object fresh. |
| 3838 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3839 | Enabling Multiple Configuration Build Dependencies |
| 3840 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3841 | |
| 3842 | Sometimes dependencies can exist between targets (multiconfigs) in a |
| 3843 | multiple configuration build. For example, suppose that in order to |
| 3844 | build a ``core-image-sato`` image for an "x86" multiconfig, the root |
| 3845 | filesystem of an "arm" multiconfig must exist. This dependency is |
| 3846 | essentially that the |
| 3847 | :ref:`ref-tasks-image` task in the |
| 3848 | ``core-image-sato`` recipe depends on the completion of the |
| 3849 | :ref:`ref-tasks-rootfs` task of the |
| 3850 | ``core-image-minimal`` recipe. |
| 3851 | |
| 3852 | To enable dependencies in a multiple configuration build, you must |
| 3853 | declare the dependencies in the recipe using the following statement |
| 3854 | form: |
| 3855 | :: |
| 3856 | |
| 3857 | task_or_package[mcdepends] = "mc:from_multiconfig:to_multiconfig:recipe_name:task_on_which_to_depend" |
| 3858 | |
| 3859 | To better show how to use this statement, consider the example scenario |
| 3860 | from the first paragraph of this section. The following statement needs |
| 3861 | to be added to the recipe that builds the ``core-image-sato`` image: |
| 3862 | :: |
| 3863 | |
| 3864 | do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_rootfs" |
| 3865 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3866 | In this example, the `from_multiconfig` is "x86". The `to_multiconfig` is "arm". The |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3867 | task on which the ``do_image`` task in the recipe depends is the |
| 3868 | ``do_rootfs`` task from the ``core-image-minimal`` recipe associated |
| 3869 | with the "arm" multiconfig. |
| 3870 | |
| 3871 | Once you set up this dependency, you can build the "x86" multiconfig |
| 3872 | using a BitBake command as follows: |
| 3873 | :: |
| 3874 | |
| 3875 | $ bitbake mc:x86:core-image-sato |
| 3876 | |
| 3877 | This command executes all the tasks needed to create the |
| 3878 | ``core-image-sato`` image for the "x86" multiconfig. Because of the |
| 3879 | dependency, BitBake also executes through the ``do_rootfs`` task for the |
| 3880 | "arm" multiconfig build. |
| 3881 | |
| 3882 | Having a recipe depend on the root filesystem of another build might not |
| 3883 | seem that useful. Consider this change to the statement in the |
| 3884 | ``core-image-sato`` recipe: |
| 3885 | :: |
| 3886 | |
| 3887 | do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_image" |
| 3888 | |
| 3889 | In this case, BitBake must |
| 3890 | create the ``core-image-minimal`` image for the "arm" build since the |
| 3891 | "x86" build depends on it. |
| 3892 | |
| 3893 | Because "x86" and "arm" are enabled for multiple configuration builds |
| 3894 | and have separate configuration files, BitBake places the artifacts for |
| 3895 | each build in the respective temporary build directories (i.e. |
| 3896 | :term:`TMPDIR`). |
| 3897 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3898 | Building an Initial RAM Filesystem (initramfs) Image |
| 3899 | ---------------------------------------------------- |
| 3900 | |
| 3901 | An initial RAM filesystem (initramfs) image provides a temporary root |
| 3902 | filesystem used for early system initialization (e.g. loading of modules |
| 3903 | needed to locate and mount the "real" root filesystem). |
| 3904 | |
| 3905 | .. note:: |
| 3906 | |
| 3907 | The initramfs image is the successor of initial RAM disk (initrd). It |
| 3908 | is a "copy in and out" (cpio) archive of the initial filesystem that |
| 3909 | gets loaded into memory during the Linux startup process. Because |
| 3910 | Linux uses the contents of the archive during initialization, the |
| 3911 | initramfs image needs to contain all of the device drivers and tools |
| 3912 | needed to mount the final root filesystem. |
| 3913 | |
| 3914 | Follow these steps to create an initramfs image: |
| 3915 | |
| 3916 | 1. *Create the initramfs Image Recipe:* You can reference the |
| 3917 | ``core-image-minimal-initramfs.bb`` recipe found in the |
| 3918 | ``meta/recipes-core`` directory of the :term:`Source Directory` |
| 3919 | as an example |
| 3920 | from which to work. |
| 3921 | |
| 3922 | 2. *Decide if You Need to Bundle the initramfs Image Into the Kernel |
| 3923 | Image:* If you want the initramfs image that is built to be bundled |
| 3924 | in with the kernel image, set the |
| 3925 | :term:`INITRAMFS_IMAGE_BUNDLE` |
| 3926 | variable to "1" in your ``local.conf`` configuration file and set the |
| 3927 | :term:`INITRAMFS_IMAGE` |
| 3928 | variable in the recipe that builds the kernel image. |
| 3929 | |
| 3930 | .. note:: |
| 3931 | |
| 3932 | It is recommended that you do bundle the initramfs image with the |
| 3933 | kernel image to avoid circular dependencies between the kernel |
| 3934 | recipe and the initramfs recipe should the initramfs image include |
| 3935 | kernel modules. |
| 3936 | |
| 3937 | Setting the ``INITRAMFS_IMAGE_BUNDLE`` flag causes the initramfs |
| 3938 | image to be unpacked into the ``${B}/usr/`` directory. The unpacked |
| 3939 | initramfs image is then passed to the kernel's ``Makefile`` using the |
| 3940 | :term:`CONFIG_INITRAMFS_SOURCE` |
| 3941 | variable, allowing the initramfs image to be built into the kernel |
| 3942 | normally. |
| 3943 | |
| 3944 | .. note:: |
| 3945 | |
| 3946 | If you choose to not bundle the initramfs image with the kernel |
| 3947 | image, you are essentially using an |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3948 | `Initial RAM Disk (initrd) <https://en.wikipedia.org/wiki/Initrd>`__. |
| 3949 | Creating an initrd is handled primarily through the :term:`INITRD_IMAGE`, |
| 3950 | ``INITRD_LIVE``, and ``INITRD_IMAGE_LIVE`` variables. For more |
| 3951 | information, see the :ref:`ref-classes-image-live` file. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3952 | |
| 3953 | 3. *Optionally Add Items to the initramfs Image Through the initramfs |
| 3954 | Image Recipe:* If you add items to the initramfs image by way of its |
| 3955 | recipe, you should use |
| 3956 | :term:`PACKAGE_INSTALL` |
| 3957 | rather than |
| 3958 | :term:`IMAGE_INSTALL`. |
| 3959 | ``PACKAGE_INSTALL`` gives more direct control of what is added to the |
| 3960 | image as compared to the defaults you might not necessarily want that |
| 3961 | are set by the :ref:`image <ref-classes-image>` |
| 3962 | or :ref:`core-image <ref-classes-core-image>` |
| 3963 | classes. |
| 3964 | |
| 3965 | 4. *Build the Kernel Image and the initramfs Image:* Build your kernel |
| 3966 | image using BitBake. Because the initramfs image recipe is a |
| 3967 | dependency of the kernel image, the initramfs image is built as well |
| 3968 | and bundled with the kernel image if you used the |
| 3969 | :term:`INITRAMFS_IMAGE_BUNDLE` |
| 3970 | variable described earlier. |
| 3971 | |
| 3972 | Building a Tiny System |
| 3973 | ---------------------- |
| 3974 | |
| 3975 | Very small distributions have some significant advantages such as |
| 3976 | requiring less on-die or in-package memory (cheaper), better performance |
| 3977 | through efficient cache usage, lower power requirements due to less |
| 3978 | memory, faster boot times, and reduced development overhead. Some |
| 3979 | real-world examples where a very small distribution gives you distinct |
| 3980 | advantages are digital cameras, medical devices, and small headless |
| 3981 | systems. |
| 3982 | |
| 3983 | This section presents information that shows you how you can trim your |
| 3984 | distribution to even smaller sizes than the ``poky-tiny`` distribution, |
| 3985 | which is around 5 Mbytes, that can be built out-of-the-box using the |
| 3986 | Yocto Project. |
| 3987 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3988 | Tiny System Overview |
| 3989 | ~~~~~~~~~~~~~~~~~~~~ |
| 3990 | |
| 3991 | The following list presents the overall steps you need to consider and |
| 3992 | perform to create distributions with smaller root filesystems, achieve |
| 3993 | faster boot times, maintain your critical functionality, and avoid |
| 3994 | initial RAM disks: |
| 3995 | |
| 3996 | - `Determine your goals and guiding |
| 3997 | principles. <#goals-and-guiding-principles>`__ |
| 3998 | |
| 3999 | - `Understand what contributes to your image |
| 4000 | size. <#understand-what-gives-your-image-size>`__ |
| 4001 | |
| 4002 | - `Reduce the size of the root |
| 4003 | filesystem. <#trim-the-root-filesystem>`__ |
| 4004 | |
| 4005 | - `Reduce the size of the kernel. <#trim-the-kernel>`__ |
| 4006 | |
| 4007 | - `Eliminate packaging |
| 4008 | requirements. <#remove-package-management-requirements>`__ |
| 4009 | |
| 4010 | - `Look for other ways to minimize |
| 4011 | size. <#look-for-other-ways-to-minimize-size>`__ |
| 4012 | |
| 4013 | - `Iterate on the process. <#iterate-on-the-process>`__ |
| 4014 | |
| 4015 | Goals and Guiding Principles |
| 4016 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 4017 | |
| 4018 | Before you can reach your destination, you need to know where you are |
| 4019 | going. Here is an example list that you can use as a guide when creating |
| 4020 | very small distributions: |
| 4021 | |
| 4022 | - Determine how much space you need (e.g. a kernel that is 1 Mbyte or |
| 4023 | less and a root filesystem that is 3 Mbytes or less). |
| 4024 | |
| 4025 | - Find the areas that are currently taking 90% of the space and |
| 4026 | concentrate on reducing those areas. |
| 4027 | |
| 4028 | - Do not create any difficult "hacks" to achieve your goals. |
| 4029 | |
| 4030 | - Leverage the device-specific options. |
| 4031 | |
| 4032 | - Work in a separate layer so that you keep changes isolated. For |
| 4033 | information on how to create layers, see the "`Understanding and |
| 4034 | Creating Layers <#understanding-and-creating-layers>`__" section. |
| 4035 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4036 | Understand What Contributes to Your Image Size |
| 4037 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 4038 | |
| 4039 | It is easiest to have something to start with when creating your own |
| 4040 | distribution. You can use the Yocto Project out-of-the-box to create the |
| 4041 | ``poky-tiny`` distribution. Ultimately, you will want to make changes in |
| 4042 | your own distribution that are likely modeled after ``poky-tiny``. |
| 4043 | |
| 4044 | .. note:: |
| 4045 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 4046 | To use ``poky-tiny`` in your build, set the ``DISTRO`` variable in your |
| 4047 | ``local.conf`` file to "poky-tiny" as described in the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 4048 | ":ref:`dev-manual/common-tasks:creating your own distribution`" |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 4049 | section. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4050 | |
| 4051 | Understanding some memory concepts will help you reduce the system size. |
| 4052 | Memory consists of static, dynamic, and temporary memory. Static memory |
| 4053 | is the TEXT (code), DATA (initialized data in the code), and BSS |
| 4054 | (uninitialized data) sections. Dynamic memory represents memory that is |
| 4055 | allocated at runtime: stacks, hash tables, and so forth. Temporary |
| 4056 | memory is recovered after the boot process. This memory consists of |
| 4057 | memory used for decompressing the kernel and for the ``__init__`` |
| 4058 | functions. |
| 4059 | |
| 4060 | To help you see where you currently are with kernel and root filesystem |
| 4061 | sizes, you can use two tools found in the :term:`Source Directory` |
| 4062 | in the |
| 4063 | ``scripts/tiny/`` directory: |
| 4064 | |
| 4065 | - ``ksize.py``: Reports component sizes for the kernel build objects. |
| 4066 | |
| 4067 | - ``dirsize.py``: Reports component sizes for the root filesystem. |
| 4068 | |
| 4069 | This next tool and command help you organize configuration fragments and |
| 4070 | view file dependencies in a human-readable form: |
| 4071 | |
| 4072 | - ``merge_config.sh``: Helps you manage configuration files and |
| 4073 | fragments within the kernel. With this tool, you can merge individual |
| 4074 | configuration fragments together. The tool allows you to make |
| 4075 | overrides and warns you of any missing configuration options. The |
| 4076 | tool is ideal for allowing you to iterate on configurations, create |
| 4077 | minimal configurations, and create configuration files for different |
| 4078 | machines without having to duplicate your process. |
| 4079 | |
| 4080 | The ``merge_config.sh`` script is part of the Linux Yocto kernel Git |
| 4081 | repositories (i.e. ``linux-yocto-3.14``, ``linux-yocto-3.10``, |
| 4082 | ``linux-yocto-3.8``, and so forth) in the ``scripts/kconfig`` |
| 4083 | directory. |
| 4084 | |
| 4085 | For more information on configuration fragments, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 4086 | ":ref:`kernel-dev/common:creating configuration fragments`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4087 | section in the Yocto Project Linux Kernel Development Manual. |
| 4088 | |
| 4089 | - ``bitbake -u taskexp -g bitbake_target``: Using the BitBake command |
| 4090 | with these options brings up a Dependency Explorer from which you can |
| 4091 | view file dependencies. Understanding these dependencies allows you |
| 4092 | to make informed decisions when cutting out various pieces of the |
| 4093 | kernel and root filesystem. |
| 4094 | |
| 4095 | Trim the Root Filesystem |
| 4096 | ~~~~~~~~~~~~~~~~~~~~~~~~ |
| 4097 | |
| 4098 | The root filesystem is made up of packages for booting, libraries, and |
| 4099 | applications. To change things, you can configure how the packaging |
| 4100 | happens, which changes the way you build them. You can also modify the |
| 4101 | filesystem itself or select a different filesystem. |
| 4102 | |
| 4103 | First, find out what is hogging your root filesystem by running the |
| 4104 | ``dirsize.py`` script from your root directory: |
| 4105 | :: |
| 4106 | |
| 4107 | $ cd root-directory-of-image |
| 4108 | $ dirsize.py 100000 > dirsize-100k.log |
| 4109 | $ cat dirsize-100k.log |
| 4110 | |
| 4111 | You can apply a filter to the script to ignore files |
| 4112 | under a certain size. The previous example filters out any files below |
| 4113 | 100 Kbytes. The sizes reported by the tool are uncompressed, and thus |
| 4114 | will be smaller by a relatively constant factor in a compressed root |
| 4115 | filesystem. When you examine your log file, you can focus on areas of |
| 4116 | the root filesystem that take up large amounts of memory. |
| 4117 | |
| 4118 | You need to be sure that what you eliminate does not cripple the |
| 4119 | functionality you need. One way to see how packages relate to each other |
| 4120 | is by using the Dependency Explorer UI with the BitBake command: |
| 4121 | :: |
| 4122 | |
| 4123 | $ cd image-directory |
| 4124 | $ bitbake -u taskexp -g image |
| 4125 | |
| 4126 | Use the interface to |
| 4127 | select potential packages you wish to eliminate and see their dependency |
| 4128 | relationships. |
| 4129 | |
| 4130 | When deciding how to reduce the size, get rid of packages that result in |
| 4131 | minimal impact on the feature set. For example, you might not need a VGA |
| 4132 | display. Or, you might be able to get by with ``devtmpfs`` and ``mdev`` |
| 4133 | instead of ``udev``. |
| 4134 | |
| 4135 | Use your ``local.conf`` file to make changes. For example, to eliminate |
| 4136 | ``udev`` and ``glib``, set the following in the local configuration |
| 4137 | file: |
| 4138 | :: |
| 4139 | |
| 4140 | VIRTUAL-RUNTIME_dev_manager = "" |
| 4141 | |
| 4142 | Finally, you should consider exactly the type of root filesystem you |
| 4143 | need to meet your needs while also reducing its size. For example, |
| 4144 | consider ``cramfs``, ``squashfs``, ``ubifs``, ``ext2``, or an |
| 4145 | ``initramfs`` using ``initramfs``. Be aware that ``ext3`` requires a 1 |
| 4146 | Mbyte journal. If you are okay with running read-only, you do not need |
| 4147 | this journal. |
| 4148 | |
| 4149 | .. note:: |
| 4150 | |
| 4151 | After each round of elimination, you need to rebuild your system and |
| 4152 | then use the tools to see the effects of your reductions. |
| 4153 | |
| 4154 | Trim the Kernel |
| 4155 | ~~~~~~~~~~~~~~~ |
| 4156 | |
| 4157 | The kernel is built by including policies for hardware-independent |
| 4158 | aspects. What subsystems do you enable? For what architecture are you |
| 4159 | building? Which drivers do you build by default? |
| 4160 | |
| 4161 | .. note:: |
| 4162 | |
| 4163 | You can modify the kernel source if you want to help with boot time. |
| 4164 | |
| 4165 | Run the ``ksize.py`` script from the top-level Linux build directory to |
| 4166 | get an idea of what is making up the kernel: |
| 4167 | :: |
| 4168 | |
| 4169 | $ cd top-level-linux-build-directory |
| 4170 | $ ksize.py > ksize.log |
| 4171 | $ cat ksize.log |
| 4172 | |
| 4173 | When you examine the log, you will see how much space is taken up with |
| 4174 | the built-in ``.o`` files for drivers, networking, core kernel files, |
| 4175 | filesystem, sound, and so forth. The sizes reported by the tool are |
| 4176 | uncompressed, and thus will be smaller by a relatively constant factor |
| 4177 | in a compressed kernel image. Look to reduce the areas that are large |
| 4178 | and taking up around the "90% rule." |
| 4179 | |
| 4180 | To examine, or drill down, into any particular area, use the ``-d`` |
| 4181 | option with the script: |
| 4182 | :: |
| 4183 | |
| 4184 | $ ksize.py -d > ksize.log |
| 4185 | |
| 4186 | Using this option |
| 4187 | breaks out the individual file information for each area of the kernel |
| 4188 | (e.g. drivers, networking, and so forth). |
| 4189 | |
| 4190 | Use your log file to see what you can eliminate from the kernel based on |
| 4191 | features you can let go. For example, if you are not going to need |
| 4192 | sound, you do not need any drivers that support sound. |
| 4193 | |
| 4194 | After figuring out what to eliminate, you need to reconfigure the kernel |
| 4195 | to reflect those changes during the next build. You could run |
| 4196 | ``menuconfig`` and make all your changes at once. However, that makes it |
| 4197 | difficult to see the effects of your individual eliminations and also |
| 4198 | makes it difficult to replicate the changes for perhaps another target |
| 4199 | device. A better method is to start with no configurations using |
| 4200 | ``allnoconfig``, create configuration fragments for individual changes, |
| 4201 | and then manage the fragments into a single configuration file using |
| 4202 | ``merge_config.sh``. The tool makes it easy for you to iterate using the |
| 4203 | configuration change and build cycle. |
| 4204 | |
| 4205 | Each time you make configuration changes, you need to rebuild the kernel |
| 4206 | and check to see what impact your changes had on the overall size. |
| 4207 | |
| 4208 | Remove Package Management Requirements |
| 4209 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 4210 | |
| 4211 | Packaging requirements add size to the image. One way to reduce the size |
| 4212 | of the image is to remove all the packaging requirements from the image. |
| 4213 | This reduction includes both removing the package manager and its unique |
| 4214 | dependencies as well as removing the package management data itself. |
| 4215 | |
| 4216 | To eliminate all the packaging requirements for an image, be sure that |
| 4217 | "package-management" is not part of your |
| 4218 | :term:`IMAGE_FEATURES` |
| 4219 | statement for the image. When you remove this feature, you are removing |
| 4220 | the package manager as well as its dependencies from the root |
| 4221 | filesystem. |
| 4222 | |
| 4223 | Look for Other Ways to Minimize Size |
| 4224 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 4225 | |
| 4226 | Depending on your particular circumstances, other areas that you can |
| 4227 | trim likely exist. The key to finding these areas is through tools and |
| 4228 | methods described here combined with experimentation and iteration. Here |
| 4229 | are a couple of areas to experiment with: |
| 4230 | |
| 4231 | - ``glibc``: In general, follow this process: |
| 4232 | |
| 4233 | 1. Remove ``glibc`` features from |
| 4234 | :term:`DISTRO_FEATURES` |
| 4235 | that you think you do not need. |
| 4236 | |
| 4237 | 2. Build your distribution. |
| 4238 | |
| 4239 | 3. If the build fails due to missing symbols in a package, determine |
| 4240 | if you can reconfigure the package to not need those features. For |
| 4241 | example, change the configuration to not support wide character |
| 4242 | support as is done for ``ncurses``. Or, if support for those |
| 4243 | characters is needed, determine what ``glibc`` features provide |
| 4244 | the support and restore the configuration. |
| 4245 | |
| 4246 | 4. Rebuild and repeat the process. |
| 4247 | |
| 4248 | - ``busybox``: For BusyBox, use a process similar as described for |
| 4249 | ``glibc``. A difference is you will need to boot the resulting system |
| 4250 | to see if you are able to do everything you expect from the running |
| 4251 | system. You need to be sure to integrate configuration fragments into |
| 4252 | Busybox because BusyBox handles its own core features and then allows |
| 4253 | you to add configuration fragments on top. |
| 4254 | |
| 4255 | Iterate on the Process |
| 4256 | ~~~~~~~~~~~~~~~~~~~~~~ |
| 4257 | |
| 4258 | If you have not reached your goals on system size, you need to iterate |
| 4259 | on the process. The process is the same. Use the tools and see just what |
| 4260 | is taking up 90% of the root filesystem and the kernel. Decide what you |
| 4261 | can eliminate without limiting your device beyond what you need. |
| 4262 | |
| 4263 | Depending on your system, a good place to look might be Busybox, which |
| 4264 | provides a stripped down version of Unix tools in a single, executable |
| 4265 | file. You might be able to drop virtual terminal services or perhaps |
| 4266 | ipv6. |
| 4267 | |
| 4268 | Building Images for More than One Machine |
| 4269 | ----------------------------------------- |
| 4270 | |
| 4271 | A common scenario developers face is creating images for several |
| 4272 | different machines that use the same software environment. In this |
| 4273 | situation, it is tempting to set the tunings and optimization flags for |
| 4274 | each build specifically for the targeted hardware (i.e. "maxing out" the |
| 4275 | tunings). Doing so can considerably add to build times and package feed |
| 4276 | maintenance collectively for the machines. For example, selecting tunes |
| 4277 | that are extremely specific to a CPU core used in a system might enable |
| 4278 | some micro optimizations in GCC for that particular system but would |
| 4279 | otherwise not gain you much of a performance difference across the other |
| 4280 | systems as compared to using a more general tuning across all the builds |
| 4281 | (e.g. setting :term:`DEFAULTTUNE` |
| 4282 | specifically for each machine's build). Rather than "max out" each |
| 4283 | build's tunings, you can take steps that cause the OpenEmbedded build |
| 4284 | system to reuse software across the various machines where it makes |
| 4285 | sense. |
| 4286 | |
| 4287 | If build speed and package feed maintenance are considerations, you |
| 4288 | should consider the points in this section that can help you optimize |
| 4289 | your tunings to best consider build times and package feed maintenance. |
| 4290 | |
| 4291 | - *Share the Build Directory:* If at all possible, share the |
| 4292 | :term:`TMPDIR` across builds. The |
| 4293 | Yocto Project supports switching between different |
| 4294 | :term:`MACHINE` values in the same |
| 4295 | ``TMPDIR``. This practice is well supported and regularly used by |
| 4296 | developers when building for multiple machines. When you use the same |
| 4297 | ``TMPDIR`` for multiple machine builds, the OpenEmbedded build system |
| 4298 | can reuse the existing native and often cross-recipes for multiple |
| 4299 | machines. Thus, build time decreases. |
| 4300 | |
| 4301 | .. note:: |
| 4302 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 4303 | If :term:`DISTRO` settings change or fundamental configuration settings |
| 4304 | such as the filesystem layout, you need to work with a clean ``TMPDIR``. |
| 4305 | Sharing ``TMPDIR`` under these circumstances might work but since it is |
| 4306 | not guaranteed, you should use a clean ``TMPDIR``. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4307 | |
| 4308 | - *Enable the Appropriate Package Architecture:* By default, the |
| 4309 | OpenEmbedded build system enables three levels of package |
| 4310 | architectures: "all", "tune" or "package", and "machine". Any given |
| 4311 | recipe usually selects one of these package architectures (types) for |
| 4312 | its output. Depending for what a given recipe creates packages, |
| 4313 | making sure you enable the appropriate package architecture can |
| 4314 | directly impact the build time. |
| 4315 | |
| 4316 | A recipe that just generates scripts can enable "all" architecture |
| 4317 | because there are no binaries to build. To specifically enable "all" |
| 4318 | architecture, be sure your recipe inherits the |
| 4319 | :ref:`allarch <ref-classes-allarch>` class. |
| 4320 | This class is useful for "all" architectures because it configures |
| 4321 | many variables so packages can be used across multiple architectures. |
| 4322 | |
| 4323 | If your recipe needs to generate packages that are machine-specific |
| 4324 | or when one of the build or runtime dependencies is already |
| 4325 | machine-architecture dependent, which makes your recipe also |
| 4326 | machine-architecture dependent, make sure your recipe enables the |
| 4327 | "machine" package architecture through the |
| 4328 | :term:`MACHINE_ARCH` |
| 4329 | variable: |
| 4330 | :: |
| 4331 | |
| 4332 | PACKAGE_ARCH = "${MACHINE_ARCH}" |
| 4333 | |
| 4334 | When you do not |
| 4335 | specifically enable a package architecture through the |
| 4336 | :term:`PACKAGE_ARCH`, The |
| 4337 | OpenEmbedded build system defaults to the |
| 4338 | :term:`TUNE_PKGARCH` setting: |
| 4339 | :: |
| 4340 | |
| 4341 | PACKAGE_ARCH = "${TUNE_PKGARCH}" |
| 4342 | |
| 4343 | - *Choose a Generic Tuning File if Possible:* Some tunes are more |
| 4344 | generic and can run on multiple targets (e.g. an ``armv5`` set of |
| 4345 | packages could run on ``armv6`` and ``armv7`` processors in most |
| 4346 | cases). Similarly, ``i486`` binaries could work on ``i586`` and |
| 4347 | higher processors. You should realize, however, that advances on |
| 4348 | newer processor versions would not be used. |
| 4349 | |
| 4350 | If you select the same tune for several different machines, the |
| 4351 | OpenEmbedded build system reuses software previously built, thus |
| 4352 | speeding up the overall build time. Realize that even though a new |
| 4353 | sysroot for each machine is generated, the software is not recompiled |
| 4354 | and only one package feed exists. |
| 4355 | |
| 4356 | - *Manage Granular Level Packaging:* Sometimes cases exist where |
| 4357 | injecting another level of package architecture beyond the three |
| 4358 | higher levels noted earlier can be useful. For example, consider how |
| 4359 | NXP (formerly Freescale) allows for the easy reuse of binary packages |
| 4360 | in their layer |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 4361 | :yocto_git:`meta-freescale </meta-freescale/>`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4362 | In this example, the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 4363 | :yocto_git:`fsl-dynamic-packagearch </meta-freescale/tree/classes/fsl-dynamic-packagearch.bbclass>` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4364 | class shares GPU packages for i.MX53 boards because all boards share |
| 4365 | the AMD GPU. The i.MX6-based boards can do the same because all |
| 4366 | boards share the Vivante GPU. This class inspects the BitBake |
| 4367 | datastore to identify if the package provides or depends on one of |
| 4368 | the sub-architecture values. If so, the class sets the |
| 4369 | :term:`PACKAGE_ARCH` value |
| 4370 | based on the ``MACHINE_SUBARCH`` value. If the package does not |
| 4371 | provide or depend on one of the sub-architecture values but it |
| 4372 | matches a value in the machine-specific filter, it sets |
| 4373 | :term:`MACHINE_ARCH`. This |
| 4374 | behavior reduces the number of packages built and saves build time by |
| 4375 | reusing binaries. |
| 4376 | |
| 4377 | - *Use Tools to Debug Issues:* Sometimes you can run into situations |
| 4378 | where software is being rebuilt when you think it should not be. For |
| 4379 | example, the OpenEmbedded build system might not be using shared |
| 4380 | state between machines when you think it should be. These types of |
| 4381 | situations are usually due to references to machine-specific |
| 4382 | variables such as :term:`MACHINE`, |
| 4383 | :term:`SERIAL_CONSOLES`, |
| 4384 | :term:`XSERVER`, |
| 4385 | :term:`MACHINE_FEATURES`, |
| 4386 | and so forth in code that is supposed to only be tune-specific or |
| 4387 | when the recipe depends |
| 4388 | (:term:`DEPENDS`, |
| 4389 | :term:`RDEPENDS`, |
| 4390 | :term:`RRECOMMENDS`, |
| 4391 | :term:`RSUGGESTS`, and so forth) |
| 4392 | on some other recipe that already has |
| 4393 | :term:`PACKAGE_ARCH` defined |
| 4394 | as "${MACHINE_ARCH}". |
| 4395 | |
| 4396 | .. note:: |
| 4397 | |
| 4398 | Patches to fix any issues identified are most welcome as these |
| 4399 | issues occasionally do occur. |
| 4400 | |
| 4401 | For such cases, you can use some tools to help you sort out the |
| 4402 | situation: |
| 4403 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 4404 | - ``state-diff-machines.sh``*:* You can find this tool in the |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4405 | ``scripts`` directory of the Source Repositories. See the comments |
| 4406 | in the script for information on how to use the tool. |
| 4407 | |
| 4408 | - *BitBake's "-S printdiff" Option:* Using this option causes |
| 4409 | BitBake to try to establish the closest signature match it can |
| 4410 | (e.g. in the shared state cache) and then run ``bitbake-diffsigs`` |
| 4411 | over the matches to determine the stamps and delta where these two |
| 4412 | stamp trees diverge. |
| 4413 | |
| 4414 | Building Software from an External Source |
| 4415 | ----------------------------------------- |
| 4416 | |
| 4417 | By default, the OpenEmbedded build system uses the |
| 4418 | :term:`Build Directory` when building source |
| 4419 | code. The build process involves fetching the source files, unpacking |
| 4420 | them, and then patching them if necessary before the build takes place. |
| 4421 | |
| 4422 | Situations exist where you might want to build software from source |
| 4423 | files that are external to and thus outside of the OpenEmbedded build |
| 4424 | system. For example, suppose you have a project that includes a new BSP |
| 4425 | with a heavily customized kernel. And, you want to minimize exposing the |
| 4426 | build system to the development team so that they can focus on their |
| 4427 | project and maintain everyone's workflow as much as possible. In this |
| 4428 | case, you want a kernel source directory on the development machine |
| 4429 | where the development occurs. You want the recipe's |
| 4430 | :term:`SRC_URI` variable to point to |
| 4431 | the external directory and use it as is, not copy it. |
| 4432 | |
| 4433 | To build from software that comes from an external source, all you need |
| 4434 | to do is inherit the |
| 4435 | :ref:`externalsrc <ref-classes-externalsrc>` class |
| 4436 | and then set the |
| 4437 | :term:`EXTERNALSRC` variable to |
| 4438 | point to your external source code. Here are the statements to put in |
| 4439 | your ``local.conf`` file: |
| 4440 | :: |
| 4441 | |
| 4442 | INHERIT += "externalsrc" |
| 4443 | EXTERNALSRC_pn-myrecipe = "path-to-your-source-tree" |
| 4444 | |
| 4445 | This next example shows how to accomplish the same thing by setting |
| 4446 | ``EXTERNALSRC`` in the recipe itself or in the recipe's append file: |
| 4447 | :: |
| 4448 | |
| 4449 | EXTERNALSRC = "path" |
| 4450 | EXTERNALSRC_BUILD = "path" |
| 4451 | |
| 4452 | .. note:: |
| 4453 | |
| 4454 | In order for these settings to take effect, you must globally or |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 4455 | locally inherit the :ref:`externalsrc <ref-classes-externalsrc>` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4456 | class. |
| 4457 | |
| 4458 | By default, ``externalsrc.bbclass`` builds the source code in a |
| 4459 | directory separate from the external source directory as specified by |
| 4460 | :term:`EXTERNALSRC`. If you need |
| 4461 | to have the source built in the same directory in which it resides, or |
| 4462 | some other nominated directory, you can set |
| 4463 | :term:`EXTERNALSRC_BUILD` |
| 4464 | to point to that directory: |
| 4465 | :: |
| 4466 | |
| 4467 | EXTERNALSRC_BUILD_pn-myrecipe = "path-to-your-source-tree" |
| 4468 | |
| 4469 | Replicating a Build Offline |
| 4470 | --------------------------- |
| 4471 | |
| 4472 | It can be useful to take a "snapshot" of upstream sources used in a |
| 4473 | build and then use that "snapshot" later to replicate the build offline. |
| 4474 | To do so, you need to first prepare and populate your downloads |
| 4475 | directory your "snapshot" of files. Once your downloads directory is |
| 4476 | ready, you can use it at any time and from any machine to replicate your |
| 4477 | build. |
| 4478 | |
| 4479 | Follow these steps to populate your Downloads directory: |
| 4480 | |
| 4481 | 1. *Create a Clean Downloads Directory:* Start with an empty downloads |
| 4482 | directory (:term:`DL_DIR`). You |
| 4483 | start with an empty downloads directory by either removing the files |
| 4484 | in the existing directory or by setting ``DL_DIR`` to point to either |
| 4485 | an empty location or one that does not yet exist. |
| 4486 | |
| 4487 | 2. *Generate Tarballs of the Source Git Repositories:* Edit your |
| 4488 | ``local.conf`` configuration file as follows: |
| 4489 | :: |
| 4490 | |
| 4491 | DL_DIR = "/home/your-download-dir/" |
| 4492 | BB_GENERATE_MIRROR_TARBALLS = "1" |
| 4493 | |
| 4494 | During |
| 4495 | the fetch process in the next step, BitBake gathers the source files |
| 4496 | and creates tarballs in the directory pointed to by ``DL_DIR``. See |
| 4497 | the |
| 4498 | :term:`BB_GENERATE_MIRROR_TARBALLS` |
| 4499 | variable for more information. |
| 4500 | |
| 4501 | 3. *Populate Your Downloads Directory Without Building:* Use BitBake to |
| 4502 | fetch your sources but inhibit the build: |
| 4503 | :: |
| 4504 | |
| 4505 | $ bitbake target --runonly=fetch |
| 4506 | |
| 4507 | The downloads directory (i.e. ``${DL_DIR}``) now has |
| 4508 | a "snapshot" of the source files in the form of tarballs, which can |
| 4509 | be used for the build. |
| 4510 | |
| 4511 | 4. *Optionally Remove Any Git or other SCM Subdirectories From the |
| 4512 | Downloads Directory:* If you want, you can clean up your downloads |
| 4513 | directory by removing any Git or other Source Control Management |
| 4514 | (SCM) subdirectories such as ``${DL_DIR}/git2/*``. The tarballs |
| 4515 | already contain these subdirectories. |
| 4516 | |
| 4517 | Once your downloads directory has everything it needs regarding source |
| 4518 | files, you can create your "own-mirror" and build your target. |
| 4519 | Understand that you can use the files to build the target offline from |
| 4520 | any machine and at any time. |
| 4521 | |
| 4522 | Follow these steps to build your target using the files in the downloads |
| 4523 | directory: |
| 4524 | |
| 4525 | 1. *Using Local Files Only:* Inside your ``local.conf`` file, add the |
| 4526 | :term:`SOURCE_MIRROR_URL` |
| 4527 | variable, inherit the |
| 4528 | :ref:`own-mirrors <ref-classes-own-mirrors>` |
| 4529 | class, and use the |
| 4530 | :term:`bitbake:BB_NO_NETWORK` |
| 4531 | variable to your ``local.conf``. |
| 4532 | :: |
| 4533 | |
| 4534 | SOURCE_MIRROR_URL ?= "file:///home/your-download-dir/" |
| 4535 | INHERIT += "own-mirrors" |
| 4536 | BB_NO_NETWORK = "1" |
| 4537 | |
| 4538 | The ``SOURCE_MIRROR_URL`` and ``own-mirror`` |
| 4539 | class set up the system to use the downloads directory as your "own |
| 4540 | mirror". Using the ``BB_NO_NETWORK`` variable makes sure that |
| 4541 | BitBake's fetching process in step 3 stays local, which means files |
| 4542 | from your "own-mirror" are used. |
| 4543 | |
| 4544 | 2. *Start With a Clean Build:* You can start with a clean build by |
| 4545 | removing the |
| 4546 | ``${``\ :term:`TMPDIR`\ ``}`` |
| 4547 | directory or using a new :term:`Build Directory`. |
| 4548 | |
| 4549 | 3. *Build Your Target:* Use BitBake to build your target: |
| 4550 | :: |
| 4551 | |
| 4552 | $ bitbake target |
| 4553 | |
| 4554 | The build completes using the known local "snapshot" of source |
| 4555 | files from your mirror. The resulting tarballs for your "snapshot" of |
| 4556 | source files are in the downloads directory. |
| 4557 | |
| 4558 | .. note:: |
| 4559 | |
| 4560 | The offline build does not work if recipes attempt to find the |
| 4561 | latest version of software by setting |
| 4562 | :term:`SRCREV` to |
| 4563 | ``${``\ :term:`AUTOREV`\ ``}``: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 4564 | :: |
| 4565 | |
| 4566 | SRCREV = "${AUTOREV}" |
| 4567 | |
| 4568 | When a recipe sets ``SRCREV`` to |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4569 | ``${AUTOREV}``, the build system accesses the network in an |
| 4570 | attempt to determine the latest version of software from the SCM. |
| 4571 | Typically, recipes that use ``AUTOREV`` are custom or modified |
| 4572 | recipes. Recipes that reside in public repositories usually do not |
| 4573 | use ``AUTOREV``. |
| 4574 | |
| 4575 | If you do have recipes that use ``AUTOREV``, you can take steps to |
| 4576 | still use the recipes in an offline build. Do the following: |
| 4577 | |
| 4578 | 1. Use a configuration generated by enabling `build |
| 4579 | history <#maintaining-build-output-quality>`__. |
| 4580 | |
| 4581 | 2. Use the ``buildhistory-collect-srcrevs`` command to collect the |
| 4582 | stored ``SRCREV`` values from the build's history. For more |
| 4583 | information on collecting these values, see the "`Build History |
| 4584 | Package Information <#build-history-package-information>`__" |
| 4585 | section. |
| 4586 | |
| 4587 | 3. Once you have the correct source revisions, you can modify |
| 4588 | those recipes to to set ``SRCREV`` to specific versions of the |
| 4589 | software. |
| 4590 | |
| 4591 | Speeding Up a Build |
| 4592 | =================== |
| 4593 | |
| 4594 | Build time can be an issue. By default, the build system uses simple |
| 4595 | controls to try and maximize build efficiency. In general, the default |
| 4596 | settings for all the following variables result in the most efficient |
| 4597 | build times when dealing with single socket systems (i.e. a single CPU). |
| 4598 | If you have multiple CPUs, you might try increasing the default values |
| 4599 | to gain more speed. See the descriptions in the glossary for each |
| 4600 | variable for more information: |
| 4601 | |
| 4602 | - :term:`BB_NUMBER_THREADS`: |
| 4603 | The maximum number of threads BitBake simultaneously executes. |
| 4604 | |
| 4605 | - :term:`bitbake:BB_NUMBER_PARSE_THREADS`: |
| 4606 | The number of threads BitBake uses during parsing. |
| 4607 | |
| 4608 | - :term:`PARALLEL_MAKE`: Extra |
| 4609 | options passed to the ``make`` command during the |
| 4610 | :ref:`ref-tasks-compile` task in |
| 4611 | order to specify parallel compilation on the local build host. |
| 4612 | |
| 4613 | - :term:`PARALLEL_MAKEINST`: |
| 4614 | Extra options passed to the ``make`` command during the |
| 4615 | :ref:`ref-tasks-install` task in |
| 4616 | order to specify parallel installation on the local build host. |
| 4617 | |
| 4618 | As mentioned, these variables all scale to the number of processor cores |
| 4619 | available on the build system. For single socket systems, this |
| 4620 | auto-scaling ensures that the build system fundamentally takes advantage |
| 4621 | of potential parallel operations during the build based on the build |
| 4622 | machine's capabilities. |
| 4623 | |
| 4624 | Following are additional factors that can affect build speed: |
| 4625 | |
| 4626 | - File system type: The file system type that the build is being |
| 4627 | performed on can also influence performance. Using ``ext4`` is |
| 4628 | recommended as compared to ``ext2`` and ``ext3`` due to ``ext4`` |
| 4629 | improved features such as extents. |
| 4630 | |
| 4631 | - Disabling the updating of access time using ``noatime``: The |
| 4632 | ``noatime`` mount option prevents the build system from updating file |
| 4633 | and directory access times. |
| 4634 | |
| 4635 | - Setting a longer commit: Using the "commit=" mount option increases |
| 4636 | the interval in seconds between disk cache writes. Changing this |
| 4637 | interval from the five second default to something longer increases |
| 4638 | the risk of data loss but decreases the need to write to the disk, |
| 4639 | thus increasing the build performance. |
| 4640 | |
| 4641 | - Choosing the packaging backend: Of the available packaging backends, |
| 4642 | IPK is the fastest. Additionally, selecting a singular packaging |
| 4643 | backend also helps. |
| 4644 | |
| 4645 | - Using ``tmpfs`` for :term:`TMPDIR` |
| 4646 | as a temporary file system: While this can help speed up the build, |
| 4647 | the benefits are limited due to the compiler using ``-pipe``. The |
| 4648 | build system goes to some lengths to avoid ``sync()`` calls into the |
| 4649 | file system on the principle that if there was a significant failure, |
| 4650 | the :term:`Build Directory` |
| 4651 | contents could easily be rebuilt. |
| 4652 | |
| 4653 | - Inheriting the |
| 4654 | :ref:`rm_work <ref-classes-rm-work>` class: |
| 4655 | Inheriting this class has shown to speed up builds due to |
| 4656 | significantly lower amounts of data stored in the data cache as well |
| 4657 | as on disk. Inheriting this class also makes cleanup of |
| 4658 | :term:`TMPDIR` faster, at the |
| 4659 | expense of being easily able to dive into the source code. File |
| 4660 | system maintainers have recommended that the fastest way to clean up |
| 4661 | large numbers of files is to reformat partitions rather than delete |
| 4662 | files due to the linear nature of partitions. This, of course, |
| 4663 | assumes you structure the disk partitions and file systems in a way |
| 4664 | that this is practical. |
| 4665 | |
| 4666 | Aside from the previous list, you should keep some trade offs in mind |
| 4667 | that can help you speed up the build: |
| 4668 | |
| 4669 | - Remove items from |
| 4670 | :term:`DISTRO_FEATURES` |
| 4671 | that you might not need. |
| 4672 | |
| 4673 | - Exclude debug symbols and other debug information: If you do not need |
| 4674 | these symbols and other debug information, disabling the ``*-dbg`` |
| 4675 | package generation can speed up the build. You can disable this |
| 4676 | generation by setting the |
| 4677 | :term:`INHIBIT_PACKAGE_DEBUG_SPLIT` |
| 4678 | variable to "1". |
| 4679 | |
| 4680 | - Disable static library generation for recipes derived from |
| 4681 | ``autoconf`` or ``libtool``: Following is an example showing how to |
| 4682 | disable static libraries and still provide an override to handle |
| 4683 | exceptions: |
| 4684 | :: |
| 4685 | |
| 4686 | STATICLIBCONF = "--disable-static" |
| 4687 | STATICLIBCONF_sqlite3-native = "" |
| 4688 | EXTRA_OECONF += "${STATICLIBCONF}" |
| 4689 | |
| 4690 | .. note:: |
| 4691 | |
| 4692 | - Some recipes need static libraries in order to work correctly |
| 4693 | (e.g. ``pseudo-native`` needs ``sqlite3-native``). Overrides, |
| 4694 | as in the previous example, account for these kinds of |
| 4695 | exceptions. |
| 4696 | |
| 4697 | - Some packages have packaging code that assumes the presence of |
| 4698 | the static libraries. If so, you might need to exclude them as |
| 4699 | well. |
| 4700 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4701 | Working With Libraries |
| 4702 | ====================== |
| 4703 | |
| 4704 | Libraries are an integral part of your system. This section describes |
| 4705 | some common practices you might find helpful when working with libraries |
| 4706 | to build your system: |
| 4707 | |
| 4708 | - `How to include static library |
| 4709 | files <#including-static-library-files>`__ |
| 4710 | |
| 4711 | - `How to use the Multilib feature to combine multiple versions of |
| 4712 | library files into a single |
| 4713 | image <#combining-multiple-versions-library-files-into-one-image>`__ |
| 4714 | |
| 4715 | - `How to install multiple versions of the same library in parallel on |
| 4716 | the same |
| 4717 | system <#installing-multiple-versions-of-the-same-library>`__ |
| 4718 | |
| 4719 | Including Static Library Files |
| 4720 | ------------------------------ |
| 4721 | |
| 4722 | If you are building a library and the library offers static linking, you |
| 4723 | can control which static library files (``*.a`` files) get included in |
| 4724 | the built library. |
| 4725 | |
| 4726 | The :term:`PACKAGES` and |
| 4727 | :term:`FILES_* <FILES>` variables in the |
| 4728 | ``meta/conf/bitbake.conf`` configuration file define how files installed |
| 4729 | by the ``do_install`` task are packaged. By default, the ``PACKAGES`` |
| 4730 | variable includes ``${PN}-staticdev``, which represents all static |
| 4731 | library files. |
| 4732 | |
| 4733 | .. note:: |
| 4734 | |
| 4735 | Some previously released versions of the Yocto Project defined the |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 4736 | static library files through ``${PN}-dev``. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4737 | |
| 4738 | Following is part of the BitBake configuration file, where you can see |
| 4739 | how the static library files are defined: |
| 4740 | :: |
| 4741 | |
| 4742 | PACKAGE_BEFORE_PN ?= "" |
| 4743 | PACKAGES = "${PN}-dbg ${PN}-staticdev ${PN}-dev ${PN}-doc ${PN}-locale ${PACKAGE_BEFORE_PN} ${PN}" |
| 4744 | PACKAGES_DYNAMIC = "^${PN}-locale-.*" |
| 4745 | FILES = "" |
| 4746 | |
| 4747 | FILES_${PN} = "${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*${SOLIBS} \ |
| 4748 | ${sysconfdir} ${sharedstatedir} ${localstatedir} \ |
| 4749 | ${base_bindir}/* ${base_sbindir}/* \ |
| 4750 | ${base_libdir}/*${SOLIBS} \ |
| 4751 | ${base_prefix}/lib/udev/rules.d ${prefix}/lib/udev/rules.d \ |
| 4752 | ${datadir}/${BPN} ${libdir}/${BPN}/* \ |
| 4753 | ${datadir}/pixmaps ${datadir}/applications \ |
| 4754 | ${datadir}/idl ${datadir}/omf ${datadir}/sounds \ |
| 4755 | ${libdir}/bonobo/servers" |
| 4756 | |
| 4757 | FILES_${PN}-bin = "${bindir}/* ${sbindir}/*" |
| 4758 | |
| 4759 | FILES_${PN}-doc = "${docdir} ${mandir} ${infodir} ${datadir}/gtk-doc \ |
| 4760 | ${datadir}/gnome/help" |
| 4761 | SECTION_${PN}-doc = "doc" |
| 4762 | |
| 4763 | FILES_SOLIBSDEV ?= "${base_libdir}/lib*${SOLIBSDEV} ${libdir}/lib*${SOLIBSDEV}" |
| 4764 | FILES_${PN}-dev = "${includedir} ${FILES_SOLIBSDEV} ${libdir}/*.la \ |
| 4765 | ${libdir}/*.o ${libdir}/pkgconfig ${datadir}/pkgconfig \ |
| 4766 | ${datadir}/aclocal ${base_libdir}/*.o \ |
| 4767 | ${libdir}/${BPN}/*.la ${base_libdir}/*.la" |
| 4768 | SECTION_${PN}-dev = "devel" |
| 4769 | ALLOW_EMPTY_${PN}-dev = "1" |
| 4770 | RDEPENDS_${PN}-dev = "${PN} (= ${EXTENDPKGV})" |
| 4771 | |
| 4772 | FILES_${PN}-staticdev = "${libdir}/*.a ${base_libdir}/*.a ${libdir}/${BPN}/*.a" |
| 4773 | SECTION_${PN}-staticdev = "devel" |
| 4774 | RDEPENDS_${PN}-staticdev = "${PN}-dev (= ${EXTENDPKGV})" |
| 4775 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4776 | Combining Multiple Versions of Library Files into One Image |
| 4777 | ----------------------------------------------------------- |
| 4778 | |
| 4779 | The build system offers the ability to build libraries with different |
| 4780 | target optimizations or architecture formats and combine these together |
| 4781 | into one system image. You can link different binaries in the image |
| 4782 | against the different libraries as needed for specific use cases. This |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 4783 | feature is called "Multilib". |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4784 | |
| 4785 | An example would be where you have most of a system compiled in 32-bit |
| 4786 | mode using 32-bit libraries, but you have something large, like a |
| 4787 | database engine, that needs to be a 64-bit application and uses 64-bit |
| 4788 | libraries. Multilib allows you to get the best of both 32-bit and 64-bit |
| 4789 | libraries. |
| 4790 | |
| 4791 | While the Multilib feature is most commonly used for 32 and 64-bit |
| 4792 | differences, the approach the build system uses facilitates different |
| 4793 | target optimizations. You could compile some binaries to use one set of |
| 4794 | libraries and other binaries to use a different set of libraries. The |
| 4795 | libraries could differ in architecture, compiler options, or other |
| 4796 | optimizations. |
| 4797 | |
| 4798 | Several examples exist in the ``meta-skeleton`` layer found in the |
| 4799 | :term:`Source Directory`: |
| 4800 | |
| 4801 | - ``conf/multilib-example.conf`` configuration file |
| 4802 | |
| 4803 | - ``conf/multilib-example2.conf`` configuration file |
| 4804 | |
| 4805 | - ``recipes-multilib/images/core-image-multilib-example.bb`` recipe |
| 4806 | |
| 4807 | Preparing to Use Multilib |
| 4808 | ~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 4809 | |
| 4810 | User-specific requirements drive the Multilib feature. Consequently, |
| 4811 | there is no one "out-of-the-box" configuration that likely exists to |
| 4812 | meet your needs. |
| 4813 | |
| 4814 | In order to enable Multilib, you first need to ensure your recipe is |
| 4815 | extended to support multiple libraries. Many standard recipes are |
| 4816 | already extended and support multiple libraries. You can check in the |
| 4817 | ``meta/conf/multilib.conf`` configuration file in the |
| 4818 | :term:`Source Directory` to see how this is |
| 4819 | done using the |
| 4820 | :term:`BBCLASSEXTEND` variable. |
| 4821 | Eventually, all recipes will be covered and this list will not be |
| 4822 | needed. |
| 4823 | |
| 4824 | For the most part, the Multilib class extension works automatically to |
| 4825 | extend the package name from ``${PN}`` to ``${MLPREFIX}${PN}``, where |
| 4826 | ``MLPREFIX`` is the particular multilib (e.g. "lib32-" or "lib64-"). |
| 4827 | Standard variables such as |
| 4828 | :term:`DEPENDS`, |
| 4829 | :term:`RDEPENDS`, |
| 4830 | :term:`RPROVIDES`, |
| 4831 | :term:`RRECOMMENDS`, |
| 4832 | :term:`PACKAGES`, and |
| 4833 | :term:`PACKAGES_DYNAMIC` are |
| 4834 | automatically extended by the system. If you are extending any manual |
| 4835 | code in the recipe, you can use the ``${MLPREFIX}`` variable to ensure |
| 4836 | those names are extended correctly. This automatic extension code |
| 4837 | resides in ``multilib.bbclass``. |
| 4838 | |
| 4839 | Using Multilib |
| 4840 | ~~~~~~~~~~~~~~ |
| 4841 | |
| 4842 | After you have set up the recipes, you need to define the actual |
| 4843 | combination of multiple libraries you want to build. You accomplish this |
| 4844 | through your ``local.conf`` configuration file in the |
| 4845 | :term:`Build Directory`. An example |
| 4846 | configuration would be as follows: |
| 4847 | :: |
| 4848 | |
| 4849 | MACHINE = "qemux86-64" |
| 4850 | require conf/multilib.conf |
| 4851 | MULTILIBS = "multilib:lib32" |
| 4852 | DEFAULTTUNE_virtclass-multilib-lib32 = "x86" |
| 4853 | IMAGE_INSTALL_append = "lib32-glib-2.0" |
| 4854 | |
| 4855 | This example enables an additional library named |
| 4856 | ``lib32`` alongside the normal target packages. When combining these |
| 4857 | "lib32" alternatives, the example uses "x86" for tuning. For information |
| 4858 | on this particular tuning, see |
| 4859 | ``meta/conf/machine/include/ia32/arch-ia32.inc``. |
| 4860 | |
| 4861 | The example then includes ``lib32-glib-2.0`` in all the images, which |
| 4862 | illustrates one method of including a multiple library dependency. You |
| 4863 | can use a normal image build to include this dependency, for example: |
| 4864 | :: |
| 4865 | |
| 4866 | $ bitbake core-image-sato |
| 4867 | |
| 4868 | You can also build Multilib packages |
| 4869 | specifically with a command like this: |
| 4870 | :: |
| 4871 | |
| 4872 | $ bitbake lib32-glib-2.0 |
| 4873 | |
| 4874 | Additional Implementation Details |
| 4875 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 4876 | |
| 4877 | Generic implementation details as well as details that are specific to |
| 4878 | package management systems exist. Following are implementation details |
| 4879 | that exist regardless of the package management system: |
| 4880 | |
| 4881 | - The typical convention used for the class extension code as used by |
| 4882 | Multilib assumes that all package names specified in |
| 4883 | :term:`PACKAGES` that contain |
| 4884 | ``${PN}`` have ``${PN}`` at the start of the name. When that |
| 4885 | convention is not followed and ``${PN}`` appears at the middle or the |
| 4886 | end of a name, problems occur. |
| 4887 | |
| 4888 | - The :term:`TARGET_VENDOR` |
| 4889 | value under Multilib will be extended to "-vendormlmultilib" (e.g. |
| 4890 | "-pokymllib32" for a "lib32" Multilib with Poky). The reason for this |
| 4891 | slightly unwieldy contraction is that any "-" characters in the |
| 4892 | vendor string presently break Autoconf's ``config.sub``, and other |
| 4893 | separators are problematic for different reasons. |
| 4894 | |
| 4895 | For the RPM Package Management System, the following implementation |
| 4896 | details exist: |
| 4897 | |
| 4898 | - A unique architecture is defined for the Multilib packages, along |
| 4899 | with creating a unique deploy folder under ``tmp/deploy/rpm`` in the |
| 4900 | :term:`Build Directory`. For |
| 4901 | example, consider ``lib32`` in a ``qemux86-64`` image. The possible |
| 4902 | architectures in the system are "all", "qemux86_64", |
| 4903 | "lib32_qemux86_64", and "lib32_x86". |
| 4904 | |
| 4905 | - The ``${MLPREFIX}`` variable is stripped from ``${PN}`` during RPM |
| 4906 | packaging. The naming for a normal RPM package and a Multilib RPM |
| 4907 | package in a ``qemux86-64`` system resolves to something similar to |
| 4908 | ``bash-4.1-r2.x86_64.rpm`` and ``bash-4.1.r2.lib32_x86.rpm``, |
| 4909 | respectively. |
| 4910 | |
| 4911 | - When installing a Multilib image, the RPM backend first installs the |
| 4912 | base image and then installs the Multilib libraries. |
| 4913 | |
| 4914 | - The build system relies on RPM to resolve the identical files in the |
| 4915 | two (or more) Multilib packages. |
| 4916 | |
| 4917 | For the IPK Package Management System, the following implementation |
| 4918 | details exist: |
| 4919 | |
| 4920 | - The ``${MLPREFIX}`` is not stripped from ``${PN}`` during IPK |
| 4921 | packaging. The naming for a normal RPM package and a Multilib IPK |
| 4922 | package in a ``qemux86-64`` system resolves to something like |
| 4923 | ``bash_4.1-r2.x86_64.ipk`` and ``lib32-bash_4.1-rw_x86.ipk``, |
| 4924 | respectively. |
| 4925 | |
| 4926 | - The IPK deploy folder is not modified with ``${MLPREFIX}`` because |
| 4927 | packages with and without the Multilib feature can exist in the same |
| 4928 | folder due to the ``${PN}`` differences. |
| 4929 | |
| 4930 | - IPK defines a sanity check for Multilib installation using certain |
| 4931 | rules for file comparison, overridden, etc. |
| 4932 | |
| 4933 | Installing Multiple Versions of the Same Library |
| 4934 | ------------------------------------------------ |
| 4935 | |
| 4936 | Situations can exist where you need to install and use multiple versions |
| 4937 | of the same library on the same system at the same time. These |
| 4938 | situations almost always exist when a library API changes and you have |
| 4939 | multiple pieces of software that depend on the separate versions of the |
| 4940 | library. To accommodate these situations, you can install multiple |
| 4941 | versions of the same library in parallel on the same system. |
| 4942 | |
| 4943 | The process is straightforward as long as the libraries use proper |
| 4944 | versioning. With properly versioned libraries, all you need to do to |
| 4945 | individually specify the libraries is create separate, appropriately |
| 4946 | named recipes where the :term:`PN` part of |
| 4947 | the name includes a portion that differentiates each library version |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 4948 | (e.g. the major part of the version number). Thus, instead of having a |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4949 | single recipe that loads one version of a library (e.g. ``clutter``), |
| 4950 | you provide multiple recipes that result in different versions of the |
| 4951 | libraries you want. As an example, the following two recipes would allow |
| 4952 | the two separate versions of the ``clutter`` library to co-exist on the |
| 4953 | same system: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 4954 | |
| 4955 | .. code-block:: none |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4956 | |
| 4957 | clutter-1.6_1.6.20.bb |
| 4958 | clutter-1.8_1.8.4.bb |
| 4959 | |
| 4960 | Additionally, if |
| 4961 | you have other recipes that depend on a given library, you need to use |
| 4962 | the :term:`DEPENDS` variable to |
| 4963 | create the dependency. Continuing with the same example, if you want to |
| 4964 | have a recipe depend on the 1.8 version of the ``clutter`` library, use |
| 4965 | the following in your recipe: |
| 4966 | :: |
| 4967 | |
| 4968 | DEPENDS = "clutter-1.8" |
| 4969 | |
| 4970 | Using x32 psABI |
| 4971 | =============== |
| 4972 | |
| 4973 | x32 processor-specific Application Binary Interface (`x32 |
| 4974 | psABI <https://software.intel.com/en-us/node/628948>`__) is a native |
| 4975 | 32-bit processor-specific ABI for Intel 64 (x86-64) architectures. An |
| 4976 | ABI defines the calling conventions between functions in a processing |
| 4977 | environment. The interface determines what registers are used and what |
| 4978 | the sizes are for various C data types. |
| 4979 | |
| 4980 | Some processing environments prefer using 32-bit applications even when |
| 4981 | running on Intel 64-bit platforms. Consider the i386 psABI, which is a |
| 4982 | very old 32-bit ABI for Intel 64-bit platforms. The i386 psABI does not |
| 4983 | provide efficient use and access of the Intel 64-bit processor |
| 4984 | resources, leaving the system underutilized. Now consider the x86_64 |
| 4985 | psABI. This ABI is newer and uses 64-bits for data sizes and program |
| 4986 | pointers. The extra bits increase the footprint size of the programs, |
| 4987 | libraries, and also increases the memory and file system size |
| 4988 | requirements. Executing under the x32 psABI enables user programs to |
| 4989 | utilize CPU and system resources more efficiently while keeping the |
| 4990 | memory footprint of the applications low. Extra bits are used for |
| 4991 | registers but not for addressing mechanisms. |
| 4992 | |
| 4993 | The Yocto Project supports the final specifications of x32 psABI as |
| 4994 | follows: |
| 4995 | |
| 4996 | - You can create packages and images in x32 psABI format on x86_64 |
| 4997 | architecture targets. |
| 4998 | |
| 4999 | - You can successfully build recipes with the x32 toolchain. |
| 5000 | |
| 5001 | - You can create and boot ``core-image-minimal`` and |
| 5002 | ``core-image-sato`` images. |
| 5003 | |
| 5004 | - RPM Package Manager (RPM) support exists for x32 binaries. |
| 5005 | |
| 5006 | - Support for large images exists. |
| 5007 | |
| 5008 | To use the x32 psABI, you need to edit your ``conf/local.conf`` |
| 5009 | configuration file as follows: |
| 5010 | :: |
| 5011 | |
| 5012 | MACHINE = "qemux86-64" |
| 5013 | DEFAULTTUNE = "x86-64-x32" |
| 5014 | baselib = "${@d.getVar('BASE_LIB_tune-' + (d.getVar('DEFAULTTUNE') \ |
| 5015 | or 'INVALID')) or 'lib'}" |
| 5016 | |
| 5017 | Once you have set |
| 5018 | up your configuration file, use BitBake to build an image that supports |
| 5019 | the x32 psABI. Here is an example: |
| 5020 | :: |
| 5021 | |
| 5022 | $ bitbake core-image-sato |
| 5023 | |
| 5024 | Enabling GObject Introspection Support |
| 5025 | ====================================== |
| 5026 | |
| 5027 | `GObject |
| 5028 | introspection <https://wiki.gnome.org/Projects/GObjectIntrospection>`__ |
| 5029 | is the standard mechanism for accessing GObject-based software from |
| 5030 | runtime environments. GObject is a feature of the GLib library that |
| 5031 | provides an object framework for the GNOME desktop and related software. |
| 5032 | GObject Introspection adds information to GObject that allows objects |
| 5033 | created within it to be represented across different programming |
| 5034 | languages. If you want to construct GStreamer pipelines using Python, or |
| 5035 | control UPnP infrastructure using Javascript and GUPnP, GObject |
| 5036 | introspection is the only way to do it. |
| 5037 | |
| 5038 | This section describes the Yocto Project support for generating and |
| 5039 | packaging GObject introspection data. GObject introspection data is a |
| 5040 | description of the API provided by libraries built on top of GLib |
| 5041 | framework, and, in particular, that framework's GObject mechanism. |
| 5042 | GObject Introspection Repository (GIR) files go to ``-dev`` packages, |
| 5043 | ``typelib`` files go to main packages as they are packaged together with |
| 5044 | libraries that are introspected. |
| 5045 | |
| 5046 | The data is generated when building such a library, by linking the |
| 5047 | library with a small executable binary that asks the library to describe |
| 5048 | itself, and then executing the binary and processing its output. |
| 5049 | |
| 5050 | Generating this data in a cross-compilation environment is difficult |
| 5051 | because the library is produced for the target architecture, but its |
| 5052 | code needs to be executed on the build host. This problem is solved with |
| 5053 | the OpenEmbedded build system by running the code through QEMU, which |
| 5054 | allows precisely that. Unfortunately, QEMU does not always work |
| 5055 | perfectly as mentioned in the "`Known Issues <#known-issues>`__" |
| 5056 | section. |
| 5057 | |
| 5058 | Enabling the Generation of Introspection Data |
| 5059 | --------------------------------------------- |
| 5060 | |
| 5061 | Enabling the generation of introspection data (GIR files) in your |
| 5062 | library package involves the following: |
| 5063 | |
| 5064 | 1. Inherit the |
| 5065 | :ref:`gobject-introspection <ref-classes-gobject-introspection>` |
| 5066 | class. |
| 5067 | |
| 5068 | 2. Make sure introspection is not disabled anywhere in the recipe or |
| 5069 | from anything the recipe includes. Also, make sure that |
| 5070 | "gobject-introspection-data" is not in |
| 5071 | :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED` |
| 5072 | and that "qemu-usermode" is not in |
| 5073 | :term:`MACHINE_FEATURES_BACKFILL_CONSIDERED`. |
| 5074 | If either of these conditions exist, nothing will happen. |
| 5075 | |
| 5076 | 3. Try to build the recipe. If you encounter build errors that look like |
| 5077 | something is unable to find ``.so`` libraries, check where these |
| 5078 | libraries are located in the source tree and add the following to the |
| 5079 | recipe: |
| 5080 | :: |
| 5081 | |
| 5082 | GIR_EXTRA_LIBS_PATH = "${B}/something/.libs" |
| 5083 | |
| 5084 | .. note:: |
| 5085 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 5086 | See recipes in the ``oe-core`` repository that use that |
| 5087 | ``GIR_EXTRA_LIBS_PATH`` variable as an example. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5088 | |
| 5089 | 4. Look for any other errors, which probably mean that introspection |
| 5090 | support in a package is not entirely standard, and thus breaks down |
| 5091 | in a cross-compilation environment. For such cases, custom-made fixes |
| 5092 | are needed. A good place to ask and receive help in these cases is |
| 5093 | the :ref:`Yocto Project mailing |
| 5094 | lists <resources-mailinglist>`. |
| 5095 | |
| 5096 | .. note:: |
| 5097 | |
| 5098 | Using a library that no longer builds against the latest Yocto |
| 5099 | Project release and prints introspection related errors is a good |
| 5100 | candidate for the previous procedure. |
| 5101 | |
| 5102 | Disabling the Generation of Introspection Data |
| 5103 | ---------------------------------------------- |
| 5104 | |
| 5105 | You might find that you do not want to generate introspection data. Or, |
| 5106 | perhaps QEMU does not work on your build host and target architecture |
| 5107 | combination. If so, you can use either of the following methods to |
| 5108 | disable GIR file generations: |
| 5109 | |
| 5110 | - Add the following to your distro configuration: |
| 5111 | :: |
| 5112 | |
| 5113 | DISTRO_FEATURES_BACKFILL_CONSIDERED = "gobject-introspection-data" |
| 5114 | |
| 5115 | Adding this statement disables generating introspection data using |
| 5116 | QEMU but will still enable building introspection tools and libraries |
| 5117 | (i.e. building them does not require the use of QEMU). |
| 5118 | |
| 5119 | - Add the following to your machine configuration: |
| 5120 | :: |
| 5121 | |
| 5122 | MACHINE_FEATURES_BACKFILL_CONSIDERED = "qemu-usermode" |
| 5123 | |
| 5124 | Adding this statement disables the use of QEMU when building packages for your |
| 5125 | machine. Currently, this feature is used only by introspection |
| 5126 | recipes and has the same effect as the previously described option. |
| 5127 | |
| 5128 | .. note:: |
| 5129 | |
| 5130 | Future releases of the Yocto Project might have other features |
| 5131 | affected by this option. |
| 5132 | |
| 5133 | If you disable introspection data, you can still obtain it through other |
| 5134 | means such as copying the data from a suitable sysroot, or by generating |
| 5135 | it on the target hardware. The OpenEmbedded build system does not |
| 5136 | currently provide specific support for these techniques. |
| 5137 | |
| 5138 | Testing that Introspection Works in an Image |
| 5139 | -------------------------------------------- |
| 5140 | |
| 5141 | Use the following procedure to test if generating introspection data is |
| 5142 | working in an image: |
| 5143 | |
| 5144 | 1. Make sure that "gobject-introspection-data" is not in |
| 5145 | :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED` |
| 5146 | and that "qemu-usermode" is not in |
| 5147 | :term:`MACHINE_FEATURES_BACKFILL_CONSIDERED`. |
| 5148 | |
| 5149 | 2. Build ``core-image-sato``. |
| 5150 | |
| 5151 | 3. Launch a Terminal and then start Python in the terminal. |
| 5152 | |
| 5153 | 4. Enter the following in the terminal: |
| 5154 | :: |
| 5155 | |
| 5156 | >>> from gi.repository import GLib |
| 5157 | >>> GLib.get_host_name() |
| 5158 | |
| 5159 | 5. For something a little more advanced, enter the following see: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 5160 | https://python-gtk-3-tutorial.readthedocs.io/en/latest/introduction.html |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5161 | |
| 5162 | Known Issues |
| 5163 | ------------ |
| 5164 | |
| 5165 | The following know issues exist for GObject Introspection Support: |
| 5166 | |
| 5167 | - ``qemu-ppc64`` immediately crashes. Consequently, you cannot build |
| 5168 | introspection data on that architecture. |
| 5169 | |
| 5170 | - x32 is not supported by QEMU. Consequently, introspection data is |
| 5171 | disabled. |
| 5172 | |
| 5173 | - musl causes transient GLib binaries to crash on assertion failures. |
| 5174 | Consequently, generating introspection data is disabled. |
| 5175 | |
| 5176 | - Because QEMU is not able to run the binaries correctly, introspection |
| 5177 | is disabled for some specific packages under specific architectures |
| 5178 | (e.g. ``gcr``, ``libsecret``, and ``webkit``). |
| 5179 | |
| 5180 | - QEMU usermode might not work properly when running 64-bit binaries |
| 5181 | under 32-bit host machines. In particular, "qemumips64" is known to |
| 5182 | not work under i686. |
| 5183 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5184 | Optionally Using an External Toolchain |
| 5185 | ====================================== |
| 5186 | |
| 5187 | You might want to use an external toolchain as part of your development. |
| 5188 | If this is the case, the fundamental steps you need to accomplish are as |
| 5189 | follows: |
| 5190 | |
| 5191 | - Understand where the installed toolchain resides. For cases where you |
| 5192 | need to build the external toolchain, you would need to take separate |
| 5193 | steps to build and install the toolchain. |
| 5194 | |
| 5195 | - Make sure you add the layer that contains the toolchain to your |
| 5196 | ``bblayers.conf`` file through the |
| 5197 | :term:`BBLAYERS` variable. |
| 5198 | |
| 5199 | - Set the ``EXTERNAL_TOOLCHAIN`` variable in your ``local.conf`` file |
| 5200 | to the location in which you installed the toolchain. |
| 5201 | |
| 5202 | A good example of an external toolchain used with the Yocto Project is |
| 5203 | Mentor Graphics Sourcery G++ Toolchain. You can see information on how |
| 5204 | to use that particular layer in the ``README`` file at |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 5205 | https://github.com/MentorEmbedded/meta-sourcery/. You can find |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5206 | further information by reading about the |
| 5207 | :term:`TCMODE` variable in the Yocto |
| 5208 | Project Reference Manual's variable glossary. |
| 5209 | |
| 5210 | Creating Partitioned Images Using Wic |
| 5211 | ===================================== |
| 5212 | |
| 5213 | Creating an image for a particular hardware target using the |
| 5214 | OpenEmbedded build system does not necessarily mean you can boot that |
| 5215 | image as is on your device. Physical devices accept and boot images in |
| 5216 | various ways depending on the specifics of the device. Usually, |
| 5217 | information about the hardware can tell you what image format the device |
| 5218 | requires. Should your device require multiple partitions on an SD card, |
| 5219 | flash, or an HDD, you can use the OpenEmbedded Image Creator, Wic, to |
| 5220 | create the properly partitioned image. |
| 5221 | |
| 5222 | The ``wic`` command generates partitioned images from existing |
| 5223 | OpenEmbedded build artifacts. Image generation is driven by partitioning |
| 5224 | commands contained in an Openembedded kickstart file (``.wks``) |
| 5225 | specified either directly on the command line or as one of a selection |
| 5226 | of canned kickstart files as shown with the ``wic list images`` command |
| 5227 | in the "`Using an Existing Kickstart |
| 5228 | File <#using-a-provided-kickstart-file>`__" section. When you apply the |
| 5229 | command to a given set of build artifacts, the result is an image or set |
| 5230 | of images that can be directly written onto media and used on a |
| 5231 | particular system. |
| 5232 | |
| 5233 | .. note:: |
| 5234 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 5235 | For a kickstart file reference, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 5236 | ":ref:`ref-manual/kickstart:openembedded kickstart (\`\`.wks\`\`) reference`" |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 5237 | Chapter in the Yocto Project Reference Manual. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5238 | |
| 5239 | The ``wic`` command and the infrastructure it is based on is by |
| 5240 | definition incomplete. The purpose of the command is to allow the |
| 5241 | generation of customized images, and as such, was designed to be |
| 5242 | completely extensible through a plugin interface. See the "`Using the |
| 5243 | Wic PlugIn Interface <#wic-using-the-wic-plugin-interface>`__" section |
| 5244 | for information on these plugins. |
| 5245 | |
| 5246 | This section provides some background information on Wic, describes what |
| 5247 | you need to have in place to run the tool, provides instruction on how |
| 5248 | to use the Wic utility, provides information on using the Wic plugins |
| 5249 | interface, and provides several examples that show how to use Wic. |
| 5250 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5251 | Background |
| 5252 | ---------- |
| 5253 | |
| 5254 | This section provides some background on the Wic utility. While none of |
| 5255 | this information is required to use Wic, you might find it interesting. |
| 5256 | |
| 5257 | - The name "Wic" is derived from OpenEmbedded Image Creator (oeic). The |
| 5258 | "oe" diphthong in "oeic" was promoted to the letter "w", because |
| 5259 | "oeic" is both difficult to remember and to pronounce. |
| 5260 | |
| 5261 | - Wic is loosely based on the Meego Image Creator (``mic``) framework. |
| 5262 | The Wic implementation has been heavily modified to make direct use |
| 5263 | of OpenEmbedded build artifacts instead of package installation and |
| 5264 | configuration, which are already incorporated within the OpenEmbedded |
| 5265 | artifacts. |
| 5266 | |
| 5267 | - Wic is a completely independent standalone utility that initially |
| 5268 | provides easier-to-use and more flexible replacements for an existing |
| 5269 | functionality in OE-Core's |
| 5270 | :ref:`image-live <ref-classes-image-live>` |
| 5271 | class. The difference between Wic and those examples is that with Wic |
| 5272 | the functionality of those scripts is implemented by a |
| 5273 | general-purpose partitioning language, which is based on Redhat |
| 5274 | kickstart syntax. |
| 5275 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5276 | Requirements |
| 5277 | ------------ |
| 5278 | |
| 5279 | In order to use the Wic utility with the OpenEmbedded Build system, your |
| 5280 | system needs to meet the following requirements: |
| 5281 | |
| 5282 | - The Linux distribution on your development host must support the |
| 5283 | Yocto Project. See the ":ref:`detailed-supported-distros`" |
| 5284 | section in the Yocto Project Reference Manual for the list of |
| 5285 | distributions that support the Yocto Project. |
| 5286 | |
| 5287 | - The standard system utilities, such as ``cp``, must be installed on |
| 5288 | your development host system. |
| 5289 | |
| 5290 | - You must have sourced the build environment setup script (i.e. |
| 5291 | :ref:`structure-core-script`) found in the |
| 5292 | :term:`Build Directory`. |
| 5293 | |
| 5294 | - You need to have the build artifacts already available, which |
| 5295 | typically means that you must have already created an image using the |
| 5296 | Openembedded build system (e.g. ``core-image-minimal``). While it |
| 5297 | might seem redundant to generate an image in order to create an image |
| 5298 | using Wic, the current version of Wic requires the artifacts in the |
| 5299 | form generated by the OpenEmbedded build system. |
| 5300 | |
| 5301 | - You must build several native tools, which are built to run on the |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 5302 | build system: |
| 5303 | :: |
| 5304 | |
| 5305 | $ bitbake parted-native dosfstools-native mtools-native |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5306 | |
| 5307 | - Include "wic" as part of the |
| 5308 | :term:`IMAGE_FSTYPES` |
| 5309 | variable. |
| 5310 | |
| 5311 | - Include the name of the :ref:`wic kickstart file <openembedded-kickstart-wks-reference>` |
| 5312 | as part of the :term:`WKS_FILE` variable |
| 5313 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5314 | Getting Help |
| 5315 | ------------ |
| 5316 | |
| 5317 | You can get general help for the ``wic`` command by entering the ``wic`` |
| 5318 | command by itself or by entering the command with a help argument as |
| 5319 | follows: |
| 5320 | :: |
| 5321 | |
| 5322 | $ wic -h |
| 5323 | $ wic --help |
| 5324 | $ wic help |
| 5325 | |
| 5326 | Currently, Wic supports seven commands: ``cp``, ``create``, ``help``, |
| 5327 | ``list``, ``ls``, ``rm``, and ``write``. You can get help for all these |
| 5328 | commands except "help" by using the following form: |
| 5329 | :: |
| 5330 | |
| 5331 | $ wic help command |
| 5332 | |
| 5333 | For example, the following command returns help for the ``write`` |
| 5334 | command: |
| 5335 | :: |
| 5336 | |
| 5337 | $ wic help write |
| 5338 | |
| 5339 | Wic supports help for three topics: ``overview``, ``plugins``, and |
| 5340 | ``kickstart``. You can get help for any topic using the following form: |
| 5341 | :: |
| 5342 | |
| 5343 | $ wic help topic |
| 5344 | |
| 5345 | For example, the following returns overview help for Wic: |
| 5346 | :: |
| 5347 | |
| 5348 | $ wic help overview |
| 5349 | |
| 5350 | One additional level of help exists for Wic. You can get help on |
| 5351 | individual images through the ``list`` command. You can use the ``list`` |
| 5352 | command to return the available Wic images as follows: |
| 5353 | :: |
| 5354 | |
| 5355 | $ wic list images |
| 5356 | genericx86 Create an EFI disk image for genericx86* |
| 5357 | beaglebone-yocto Create SD card image for Beaglebone |
| 5358 | edgerouter Create SD card image for Edgerouter |
| 5359 | qemux86-directdisk Create a qemu machine 'pcbios' direct disk image |
| 5360 | directdisk-gpt Create a 'pcbios' direct disk image |
| 5361 | mkefidisk Create an EFI disk image |
| 5362 | directdisk Create a 'pcbios' direct disk image |
| 5363 | systemd-bootdisk Create an EFI disk image with systemd-boot |
| 5364 | mkhybridiso Create a hybrid ISO image |
| 5365 | sdimage-bootpart Create SD card image with a boot partition |
| 5366 | directdisk-multi-rootfs Create multi rootfs image using rootfs plugin |
| 5367 | directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config |
| 5368 | |
| 5369 | Once you know the list of available |
| 5370 | Wic images, you can use ``help`` with the command to get help on a |
| 5371 | particular image. For example, the following command returns help on the |
| 5372 | "beaglebone-yocto" image: |
| 5373 | :: |
| 5374 | |
| 5375 | $ wic list beaglebone-yocto help |
| 5376 | |
| 5377 | Creates a partitioned SD card image for Beaglebone. |
| 5378 | Boot files are located in the first vfat partition. |
| 5379 | |
| 5380 | Operational Modes |
| 5381 | ----------------- |
| 5382 | |
| 5383 | You can use Wic in two different modes, depending on how much control |
| 5384 | you need for specifying the Openembedded build artifacts that are used |
| 5385 | for creating the image: Raw and Cooked: |
| 5386 | |
| 5387 | - *Raw Mode:* You explicitly specify build artifacts through Wic |
| 5388 | command-line arguments. |
| 5389 | |
| 5390 | - *Cooked Mode:* The current |
| 5391 | :term:`MACHINE` setting and image |
| 5392 | name are used to automatically locate and provide the build |
| 5393 | artifacts. You just supply a kickstart file and the name of the image |
| 5394 | from which to use artifacts. |
| 5395 | |
| 5396 | Regardless of the mode you use, you need to have the build artifacts |
| 5397 | ready and available. |
| 5398 | |
| 5399 | Raw Mode |
| 5400 | ~~~~~~~~ |
| 5401 | |
| 5402 | Running Wic in raw mode allows you to specify all the partitions through |
| 5403 | the ``wic`` command line. The primary use for raw mode is if you have |
| 5404 | built your kernel outside of the Yocto Project |
| 5405 | :term:`Build Directory`. In other words, you |
| 5406 | can point to arbitrary kernel, root filesystem locations, and so forth. |
| 5407 | Contrast this behavior with cooked mode where Wic looks in the Build |
| 5408 | Directory (e.g. ``tmp/deploy/images/``\ machine). |
| 5409 | |
| 5410 | The general form of the ``wic`` command in raw mode is: |
| 5411 | :: |
| 5412 | |
| 5413 | $ wic create wks_file options ... |
| 5414 | |
| 5415 | Where: |
| 5416 | |
| 5417 | wks_file: |
| 5418 | An OpenEmbedded kickstart file. You can provide |
| 5419 | your own custom file or use a file from a set of |
| 5420 | existing files as described by further options. |
| 5421 | |
| 5422 | optional arguments: |
| 5423 | -h, --help show this help message and exit |
| 5424 | -o OUTDIR, --outdir OUTDIR |
| 5425 | name of directory to create image in |
| 5426 | -e IMAGE_NAME, --image-name IMAGE_NAME |
| 5427 | name of the image to use the artifacts from e.g. core- |
| 5428 | image-sato |
| 5429 | -r ROOTFS_DIR, --rootfs-dir ROOTFS_DIR |
| 5430 | path to the /rootfs dir to use as the .wks rootfs |
| 5431 | source |
| 5432 | -b BOOTIMG_DIR, --bootimg-dir BOOTIMG_DIR |
| 5433 | path to the dir containing the boot artifacts (e.g. |
| 5434 | /EFI or /syslinux dirs) to use as the .wks bootimg |
| 5435 | source |
| 5436 | -k KERNEL_DIR, --kernel-dir KERNEL_DIR |
| 5437 | path to the dir containing the kernel to use in the |
| 5438 | .wks bootimg |
| 5439 | -n NATIVE_SYSROOT, --native-sysroot NATIVE_SYSROOT |
| 5440 | path to the native sysroot containing the tools to use |
| 5441 | to build the image |
| 5442 | -s, --skip-build-check |
| 5443 | skip the build check |
| 5444 | -f, --build-rootfs build rootfs |
| 5445 | -c {gzip,bzip2,xz}, --compress-with {gzip,bzip2,xz} |
| 5446 | compress image with specified compressor |
| 5447 | -m, --bmap generate .bmap |
| 5448 | --no-fstab-update Do not change fstab file. |
| 5449 | -v VARS_DIR, --vars VARS_DIR |
| 5450 | directory with <image>.env files that store bitbake |
| 5451 | variables |
| 5452 | -D, --debug output debug information |
| 5453 | |
| 5454 | .. note:: |
| 5455 | |
| 5456 | You do not need root privileges to run Wic. In fact, you should not |
| 5457 | run as root when using the utility. |
| 5458 | |
| 5459 | Cooked Mode |
| 5460 | ~~~~~~~~~~~ |
| 5461 | |
| 5462 | Running Wic in cooked mode leverages off artifacts in the Build |
| 5463 | Directory. In other words, you do not have to specify kernel or root |
| 5464 | filesystem locations as part of the command. All you need to provide is |
| 5465 | a kickstart file and the name of the image from which to use artifacts |
| 5466 | by using the "-e" option. Wic looks in the Build Directory (e.g. |
| 5467 | ``tmp/deploy/images/``\ machine) for artifacts. |
| 5468 | |
| 5469 | The general form of the ``wic`` command using Cooked Mode is as follows: |
| 5470 | :: |
| 5471 | |
| 5472 | $ wic create wks_file -e IMAGE_NAME |
| 5473 | |
| 5474 | Where: |
| 5475 | |
| 5476 | wks_file: |
| 5477 | An OpenEmbedded kickstart file. You can provide |
| 5478 | your own custom file or use a file from a set of |
| 5479 | existing files provided with the Yocto Project |
| 5480 | release. |
| 5481 | |
| 5482 | required argument: |
| 5483 | -e IMAGE_NAME, --image-name IMAGE_NAME |
| 5484 | name of the image to use the artifacts from e.g. core- |
| 5485 | image-sato |
| 5486 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5487 | Using an Existing Kickstart File |
| 5488 | -------------------------------- |
| 5489 | |
| 5490 | If you do not want to create your own kickstart file, you can use an |
| 5491 | existing file provided by the Wic installation. As shipped, kickstart |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 5492 | files can be found in the :ref:`overview-manual/development-environment:yocto project source repositories` in the |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5493 | following two locations: |
| 5494 | :: |
| 5495 | |
| 5496 | poky/meta-yocto-bsp/wic |
| 5497 | poky/scripts/lib/wic/canned-wks |
| 5498 | |
| 5499 | Use the following command to list the available kickstart files: |
| 5500 | :: |
| 5501 | |
| 5502 | $ wic list images |
| 5503 | genericx86 Create an EFI disk image for genericx86* |
| 5504 | beaglebone-yocto Create SD card image for Beaglebone |
| 5505 | edgerouter Create SD card image for Edgerouter |
| 5506 | qemux86-directdisk Create a qemu machine 'pcbios' direct disk image |
| 5507 | directdisk-gpt Create a 'pcbios' direct disk image |
| 5508 | mkefidisk Create an EFI disk image |
| 5509 | directdisk Create a 'pcbios' direct disk image |
| 5510 | systemd-bootdisk Create an EFI disk image with systemd-boot |
| 5511 | mkhybridiso Create a hybrid ISO image |
| 5512 | sdimage-bootpart Create SD card image with a boot partition |
| 5513 | directdisk-multi-rootfs Create multi rootfs image using rootfs plugin |
| 5514 | directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config |
| 5515 | |
| 5516 | When you use an existing file, you |
| 5517 | do not have to use the ``.wks`` extension. Here is an example in Raw |
| 5518 | Mode that uses the ``directdisk`` file: |
| 5519 | :: |
| 5520 | |
| 5521 | $ wic create directdisk -r rootfs_dir -b bootimg_dir \ |
| 5522 | -k kernel_dir -n native_sysroot |
| 5523 | |
| 5524 | Here are the actual partition language commands used in the |
| 5525 | ``genericx86.wks`` file to generate an image: |
| 5526 | :: |
| 5527 | |
| 5528 | # short-description: Create an EFI disk image for genericx86* |
| 5529 | # long-description: Creates a partitioned EFI disk image for genericx86* machines |
| 5530 | part /boot --source bootimg-efi --sourceparams="loader=grub-efi" --ondisk sda --label msdos --active --align 1024 |
| 5531 | part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid |
| 5532 | part swap --ondisk sda --size 44 --label swap1 --fstype=swap |
| 5533 | |
| 5534 | bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=ttyS0,115200 console=tty0" |
| 5535 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5536 | Using the Wic Plugin Interface |
| 5537 | ------------------------------ |
| 5538 | |
| 5539 | You can extend and specialize Wic functionality by using Wic plugins. |
| 5540 | This section explains the Wic plugin interface. |
| 5541 | |
| 5542 | .. note:: |
| 5543 | |
| 5544 | Wic plugins consist of "source" and "imager" plugins. Imager plugins |
| 5545 | are beyond the scope of this section. |
| 5546 | |
| 5547 | Source plugins provide a mechanism to customize partition content during |
| 5548 | the Wic image generation process. You can use source plugins to map |
| 5549 | values that you specify using ``--source`` commands in kickstart files |
| 5550 | (i.e. ``*.wks``) to a plugin implementation used to populate a given |
| 5551 | partition. |
| 5552 | |
| 5553 | .. note:: |
| 5554 | |
| 5555 | If you use plugins that have build-time dependencies (e.g. native |
| 5556 | tools, bootloaders, and so forth) when building a Wic image, you need |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 5557 | to specify those dependencies using the :term:`WKS_FILE_DEPENDS` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5558 | variable. |
| 5559 | |
| 5560 | Source plugins are subclasses defined in plugin files. As shipped, the |
| 5561 | Yocto Project provides several plugin files. You can see the source |
| 5562 | plugin files that ship with the Yocto Project |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 5563 | :yocto_git:`here </poky/tree/scripts/lib/wic/plugins/source>`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5564 | Each of these plugin files contains source plugins that are designed to |
| 5565 | populate a specific Wic image partition. |
| 5566 | |
| 5567 | Source plugins are subclasses of the ``SourcePlugin`` class, which is |
| 5568 | defined in the ``poky/scripts/lib/wic/pluginbase.py`` file. For example, |
| 5569 | the ``BootimgEFIPlugin`` source plugin found in the ``bootimg-efi.py`` |
| 5570 | file is a subclass of the ``SourcePlugin`` class, which is found in the |
| 5571 | ``pluginbase.py`` file. |
| 5572 | |
| 5573 | You can also implement source plugins in a layer outside of the Source |
| 5574 | Repositories (external layer). To do so, be sure that your plugin files |
| 5575 | are located in a directory whose path is |
| 5576 | ``scripts/lib/wic/plugins/source/`` within your external layer. When the |
| 5577 | plugin files are located there, the source plugins they contain are made |
| 5578 | available to Wic. |
| 5579 | |
| 5580 | When the Wic implementation needs to invoke a partition-specific |
| 5581 | implementation, it looks for the plugin with the same name as the |
| 5582 | ``--source`` parameter used in the kickstart file given to that |
| 5583 | partition. For example, if the partition is set up using the following |
| 5584 | command in a kickstart file: |
| 5585 | :: |
| 5586 | |
| 5587 | part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024 |
| 5588 | |
| 5589 | The methods defined as class |
| 5590 | members of the matching source plugin (i.e. ``bootimg-pcbios``) in the |
| 5591 | ``bootimg-pcbios.py`` plugin file are used. |
| 5592 | |
| 5593 | To be more concrete, here is the corresponding plugin definition from |
| 5594 | the ``bootimg-pcbios.py`` file for the previous command along with an |
| 5595 | example method called by the Wic implementation when it needs to prepare |
| 5596 | a partition using an implementation-specific function: |
| 5597 | :: |
| 5598 | |
| 5599 | . |
| 5600 | . |
| 5601 | . |
| 5602 | class BootimgPcbiosPlugin(SourcePlugin): |
| 5603 | """ |
| 5604 | Create MBR boot partition and install syslinux on it. |
| 5605 | """ |
| 5606 | |
| 5607 | name = 'bootimg-pcbios' |
| 5608 | . |
| 5609 | . |
| 5610 | . |
| 5611 | @classmethod |
| 5612 | def do_prepare_partition(cls, part, source_params, creator, cr_workdir, |
| 5613 | oe_builddir, bootimg_dir, kernel_dir, |
| 5614 | rootfs_dir, native_sysroot): |
| 5615 | """ |
| 5616 | Called to do the actual content population for a partition i.e. it |
| 5617 | 'prepares' the partition to be incorporated into the image. |
| 5618 | In this case, prepare content for legacy bios boot partition. |
| 5619 | """ |
| 5620 | . |
| 5621 | . |
| 5622 | . |
| 5623 | |
| 5624 | If a |
| 5625 | subclass (plugin) itself does not implement a particular function, Wic |
| 5626 | locates and uses the default version in the superclass. It is for this |
| 5627 | reason that all source plugins are derived from the ``SourcePlugin`` |
| 5628 | class. |
| 5629 | |
| 5630 | The ``SourcePlugin`` class defined in the ``pluginbase.py`` file defines |
| 5631 | a set of methods that source plugins can implement or override. Any |
| 5632 | plugins (subclass of ``SourcePlugin``) that do not implement a |
| 5633 | particular method inherit the implementation of the method from the |
| 5634 | ``SourcePlugin`` class. For more information, see the ``SourcePlugin`` |
| 5635 | class in the ``pluginbase.py`` file for details: |
| 5636 | |
| 5637 | The following list describes the methods implemented in the |
| 5638 | ``SourcePlugin`` class: |
| 5639 | |
| 5640 | - ``do_prepare_partition()``: Called to populate a partition with |
| 5641 | actual content. In other words, the method prepares the final |
| 5642 | partition image that is incorporated into the disk image. |
| 5643 | |
| 5644 | - ``do_configure_partition()``: Called before |
| 5645 | ``do_prepare_partition()`` to create custom configuration files for a |
| 5646 | partition (e.g. syslinux or grub configuration files). |
| 5647 | |
| 5648 | - ``do_install_disk()``: Called after all partitions have been |
| 5649 | prepared and assembled into a disk image. This method provides a hook |
| 5650 | to allow finalization of a disk image (e.g. writing an MBR). |
| 5651 | |
| 5652 | - ``do_stage_partition()``: Special content-staging hook called |
| 5653 | before ``do_prepare_partition()``. This method is normally empty. |
| 5654 | |
| 5655 | Typically, a partition just uses the passed-in parameters (e.g. the |
| 5656 | unmodified value of ``bootimg_dir``). However, in some cases, things |
| 5657 | might need to be more tailored. As an example, certain files might |
| 5658 | additionally need to be taken from ``bootimg_dir + /boot``. This hook |
| 5659 | allows those files to be staged in a customized fashion. |
| 5660 | |
| 5661 | .. note:: |
| 5662 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 5663 | ``get_bitbake_var()`` allows you to access non-standard variables that |
| 5664 | you might want to use for this behavior. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5665 | |
| 5666 | You can extend the source plugin mechanism. To add more hooks, create |
| 5667 | more source plugin methods within ``SourcePlugin`` and the corresponding |
| 5668 | derived subclasses. The code that calls the plugin methods uses the |
| 5669 | ``plugin.get_source_plugin_methods()`` function to find the method or |
| 5670 | methods needed by the call. Retrieval of those methods is accomplished |
| 5671 | by filling up a dict with keys that contain the method names of |
| 5672 | interest. On success, these will be filled in with the actual methods. |
| 5673 | See the Wic implementation for examples and details. |
| 5674 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5675 | Wic Examples |
| 5676 | ------------ |
| 5677 | |
| 5678 | This section provides several examples that show how to use the Wic |
| 5679 | utility. All the examples assume the list of requirements in the |
| 5680 | "`Requirements <#wic-requirements>`__" section have been met. The |
| 5681 | examples assume the previously generated image is |
| 5682 | ``core-image-minimal``. |
| 5683 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5684 | Generate an Image using an Existing Kickstart File |
| 5685 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 5686 | |
| 5687 | This example runs in Cooked Mode and uses the ``mkefidisk`` kickstart |
| 5688 | file: |
| 5689 | :: |
| 5690 | |
| 5691 | $ wic create mkefidisk -e core-image-minimal |
| 5692 | INFO: Building wic-tools... |
| 5693 | . |
| 5694 | . |
| 5695 | . |
| 5696 | INFO: The new image(s) can be found here: |
| 5697 | ./mkefidisk-201804191017-sda.direct |
| 5698 | |
| 5699 | The following build artifacts were used to create the image(s): |
| 5700 | ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs |
| 5701 | BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share |
| 5702 | KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86 |
| 5703 | NATIVE_SYSROOT: /home/stephano/build/master/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native |
| 5704 | |
| 5705 | INFO: The image(s) were created using OE kickstart file: |
| 5706 | /home/stephano/build/master/openembedded-core/scripts/lib/wic/canned-wks/mkefidisk.wks |
| 5707 | |
| 5708 | The previous example shows the easiest way to create an image by running |
| 5709 | in cooked mode and supplying a kickstart file and the "-e" option to |
| 5710 | point to the existing build artifacts. Your ``local.conf`` file needs to |
| 5711 | have the :term:`MACHINE` variable set |
| 5712 | to the machine you are using, which is "qemux86" in this example. |
| 5713 | |
| 5714 | Once the image builds, the output provides image location, artifact use, |
| 5715 | and kickstart file information. |
| 5716 | |
| 5717 | .. note:: |
| 5718 | |
| 5719 | You should always verify the details provided in the output to make |
| 5720 | sure that the image was indeed created exactly as expected. |
| 5721 | |
| 5722 | Continuing with the example, you can now write the image from the Build |
| 5723 | Directory onto a USB stick, or whatever media for which you built your |
| 5724 | image, and boot from the media. You can write the image by using |
| 5725 | ``bmaptool`` or ``dd``: |
| 5726 | :: |
| 5727 | |
| 5728 | $ oe-run-native bmaptool copy mkefidisk-201804191017-sda.direct /dev/sdX |
| 5729 | |
| 5730 | or :: |
| 5731 | |
| 5732 | $ sudo dd if=mkefidisk-201804191017-sda.direct of=/dev/sdX |
| 5733 | |
| 5734 | .. note:: |
| 5735 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 5736 | For more information on how to use the ``bmaptool`` |
| 5737 | to flash a device with an image, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 5738 | ":ref:`dev-manual/common-tasks:flashing images using \`\`bmaptool\`\``" |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 5739 | section. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5740 | |
| 5741 | Using a Modified Kickstart File |
| 5742 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 5743 | |
| 5744 | Because partitioned image creation is driven by the kickstart file, it |
| 5745 | is easy to affect image creation by changing the parameters in the file. |
| 5746 | This next example demonstrates that through modification of the |
| 5747 | ``directdisk-gpt`` kickstart file. |
| 5748 | |
| 5749 | As mentioned earlier, you can use the command ``wic list images`` to |
| 5750 | show the list of existing kickstart files. The directory in which the |
| 5751 | ``directdisk-gpt.wks`` file resides is |
| 5752 | ``scripts/lib/image/canned-wks/``, which is located in the |
| 5753 | :term:`Source Directory` (e.g. ``poky``). |
| 5754 | Because available files reside in this directory, you can create and add |
| 5755 | your own custom files to the directory. Subsequent use of the |
| 5756 | ``wic list images`` command would then include your kickstart files. |
| 5757 | |
| 5758 | In this example, the existing ``directdisk-gpt`` file already does most |
| 5759 | of what is needed. However, for the hardware in this example, the image |
| 5760 | will need to boot from ``sdb`` instead of ``sda``, which is what the |
| 5761 | ``directdisk-gpt`` kickstart file uses. |
| 5762 | |
| 5763 | The example begins by making a copy of the ``directdisk-gpt.wks`` file |
| 5764 | in the ``scripts/lib/image/canned-wks`` directory and then by changing |
| 5765 | the lines that specify the target disk from which to boot. |
| 5766 | :: |
| 5767 | |
| 5768 | $ cp /home/stephano/poky/scripts/lib/wic/canned-wks/directdisk-gpt.wks \ |
| 5769 | /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks |
| 5770 | |
| 5771 | Next, the example modifies the ``directdisksdb-gpt.wks`` file and |
| 5772 | changes all instances of "``--ondisk sda``" to "``--ondisk sdb``". The |
| 5773 | example changes the following two lines and leaves the remaining lines |
| 5774 | untouched: |
| 5775 | :: |
| 5776 | |
| 5777 | part /boot --source bootimg-pcbios --ondisk sdb --label boot --active --align 1024 |
| 5778 | part / --source rootfs --ondisk sdb --fstype=ext4 --label platform --align 1024 --use-uuid |
| 5779 | |
| 5780 | Once the lines are changed, the |
| 5781 | example generates the ``directdisksdb-gpt`` image. The command points |
| 5782 | the process at the ``core-image-minimal`` artifacts for the Next Unit of |
| 5783 | Computing (nuc) :term:`MACHINE` the |
| 5784 | ``local.conf``. |
| 5785 | :: |
| 5786 | |
| 5787 | $ wic create directdisksdb-gpt -e core-image-minimal |
| 5788 | INFO: Building wic-tools... |
| 5789 | . |
| 5790 | . |
| 5791 | . |
| 5792 | Initialising tasks: 100% |#######################################| Time: 0:00:01 |
| 5793 | NOTE: Executing SetScene Tasks |
| 5794 | NOTE: Executing RunQueue Tasks |
| 5795 | NOTE: Tasks Summary: Attempted 1161 tasks of which 1157 didn't need to be rerun and all succeeded. |
| 5796 | INFO: Creating image(s)... |
| 5797 | |
| 5798 | INFO: The new image(s) can be found here: |
| 5799 | ./directdisksdb-gpt-201710090938-sdb.direct |
| 5800 | |
| 5801 | The following build artifacts were used to create the image(s): |
| 5802 | ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs |
| 5803 | BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share |
| 5804 | KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86 |
| 5805 | NATIVE_SYSROOT: /home/stephano/build/master/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native |
| 5806 | |
| 5807 | INFO: The image(s) were created using OE kickstart file: |
| 5808 | /home/stephano/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks |
| 5809 | |
| 5810 | Continuing with the example, you can now directly ``dd`` the image to a |
| 5811 | USB stick, or whatever media for which you built your image, and boot |
| 5812 | the resulting media: |
| 5813 | :: |
| 5814 | |
| 5815 | $ sudo dd if=directdisksdb-gpt-201710090938-sdb.direct of=/dev/sdb |
| 5816 | 140966+0 records in |
| 5817 | 140966+0 records out |
| 5818 | 72174592 bytes (72 MB, 69 MiB) copied, 78.0282 s, 925 kB/s |
| 5819 | $ sudo eject /dev/sdb |
| 5820 | |
| 5821 | Using a Modified Kickstart File and Running in Raw Mode |
| 5822 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 5823 | |
| 5824 | This next example manually specifies each build artifact (runs in Raw |
| 5825 | Mode) and uses a modified kickstart file. The example also uses the |
| 5826 | ``-o`` option to cause Wic to create the output somewhere other than the |
| 5827 | default output directory, which is the current directory: |
| 5828 | :: |
| 5829 | |
| 5830 | $ wic create /home/stephano/my_yocto/test.wks -o /home/stephano/testwic \ |
| 5831 | --rootfs-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/rootfs \ |
| 5832 | --bootimg-dir /home/stephano/build/master/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share \ |
| 5833 | --kernel-dir /home/stephano/build/master/build/tmp/deploy/images/qemux86 \ |
| 5834 | --native-sysroot /home/stephano/build/master/build/tmp/work/i586-poky-linux/wic-tools/1.0-r0/recipe-sysroot-native |
| 5835 | |
| 5836 | INFO: Creating image(s)... |
| 5837 | |
| 5838 | INFO: The new image(s) can be found here: |
| 5839 | /home/stephano/testwic/test-201710091445-sdb.direct |
| 5840 | |
| 5841 | The following build artifacts were used to create the image(s): |
| 5842 | ROOTFS_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs |
| 5843 | BOOTIMG_DIR: /home/stephano/build/master/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share |
| 5844 | KERNEL_DIR: /home/stephano/build/master/build/tmp-glibc/deploy/images/qemux86 |
| 5845 | NATIVE_SYSROOT: /home/stephano/build/master/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native |
| 5846 | |
| 5847 | INFO: The image(s) were created using OE kickstart file: |
| 5848 | /home/stephano/my_yocto/test.wks |
| 5849 | |
| 5850 | For this example, |
| 5851 | :term:`MACHINE` did not have to be |
| 5852 | specified in the ``local.conf`` file since the artifact is manually |
| 5853 | specified. |
| 5854 | |
| 5855 | Using Wic to Manipulate an Image |
| 5856 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 5857 | |
| 5858 | Wic image manipulation allows you to shorten turnaround time during |
| 5859 | image development. For example, you can use Wic to delete the kernel |
| 5860 | partition of a Wic image and then insert a newly built kernel. This |
| 5861 | saves you time from having to rebuild the entire image each time you |
| 5862 | modify the kernel. |
| 5863 | |
| 5864 | .. note:: |
| 5865 | |
| 5866 | In order to use Wic to manipulate a Wic image as in this example, |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 5867 | your development machine must have the ``mtools`` package installed. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5868 | |
| 5869 | The following example examines the contents of the Wic image, deletes |
| 5870 | the existing kernel, and then inserts a new kernel: |
| 5871 | |
| 5872 | 1. *List the Partitions:* Use the ``wic ls`` command to list all the |
| 5873 | partitions in the Wic image: |
| 5874 | :: |
| 5875 | |
| 5876 | $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic |
| 5877 | Num Start End Size Fstype |
| 5878 | 1 1048576 25041919 23993344 fat16 |
| 5879 | 2 25165824 72157183 46991360 ext4 |
| 5880 | |
| 5881 | The previous output shows two partitions in the |
| 5882 | ``core-image-minimal-qemux86.wic`` image. |
| 5883 | |
| 5884 | 2. *Examine a Particular Partition:* Use the ``wic ls`` command again |
| 5885 | but in a different form to examine a particular partition. |
| 5886 | |
| 5887 | .. note:: |
| 5888 | |
| 5889 | You can get command usage on any Wic command using the following |
| 5890 | form: |
| 5891 | :: |
| 5892 | |
| 5893 | $ wic help command |
| 5894 | |
| 5895 | |
| 5896 | For example, the following command shows you the various ways to |
| 5897 | use the |
| 5898 | wic ls |
| 5899 | command: |
| 5900 | :: |
| 5901 | |
| 5902 | $ wic help ls |
| 5903 | |
| 5904 | |
| 5905 | The following command shows what is in Partition one: |
| 5906 | :: |
| 5907 | |
| 5908 | $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1 |
| 5909 | Volume in drive : is boot |
| 5910 | Volume Serial Number is E894-1809 |
| 5911 | Directory for ::/ |
| 5912 | |
| 5913 | libcom32 c32 186500 2017-10-09 16:06 |
| 5914 | libutil c32 24148 2017-10-09 16:06 |
| 5915 | syslinux cfg 220 2017-10-09 16:06 |
| 5916 | vesamenu c32 27104 2017-10-09 16:06 |
| 5917 | vmlinuz 6904608 2017-10-09 16:06 |
| 5918 | 5 files 7 142 580 bytes |
| 5919 | 16 582 656 bytes free |
| 5920 | |
| 5921 | The previous output shows five files, with the |
| 5922 | ``vmlinuz`` being the kernel. |
| 5923 | |
| 5924 | .. note:: |
| 5925 | |
| 5926 | If you see the following error, you need to update or create a |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 5927 | ``~/.mtoolsrc`` file and be sure to have the line "mtools_skip_check=1" |
| 5928 | in the file. Then, run the Wic command again: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5929 | :: |
| 5930 | |
| 5931 | ERROR: _exec_cmd: /usr/bin/mdir -i /tmp/wic-parttfokuwra ::/ returned '1' instead of 0 |
| 5932 | output: Total number of sectors (47824) not a multiple of sectors per track (32)! |
| 5933 | Add mtools_skip_check=1 to your .mtoolsrc file to skip this test |
| 5934 | |
| 5935 | |
| 5936 | 3. *Remove the Old Kernel:* Use the ``wic rm`` command to remove the |
| 5937 | ``vmlinuz`` file (kernel): |
| 5938 | :: |
| 5939 | |
| 5940 | $ wic rm tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz |
| 5941 | |
| 5942 | 4. *Add In the New Kernel:* Use the ``wic cp`` command to add the |
| 5943 | updated kernel to the Wic image. Depending on how you built your |
| 5944 | kernel, it could be in different places. If you used ``devtool`` and |
| 5945 | an SDK to build your kernel, it resides in the ``tmp/work`` directory |
| 5946 | of the extensible SDK. If you used ``make`` to build the kernel, the |
| 5947 | kernel will be in the ``workspace/sources`` area. |
| 5948 | |
| 5949 | The following example assumes ``devtool`` was used to build the |
| 5950 | kernel: |
| 5951 | :: |
| 5952 | |
| 5953 | 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 \ |
| 5954 | ~/poky/build/tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz |
| 5955 | |
| 5956 | Once the new kernel is added back into the image, you can use the |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 5957 | ``dd`` command or :ref:`bmaptool |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 5958 | <dev-manual/common-tasks:flashing images using \`\`bmaptool\`\`>` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5959 | to flash your wic image onto an SD card or USB stick and test your |
| 5960 | target. |
| 5961 | |
| 5962 | .. note:: |
| 5963 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 5964 | Using ``bmaptool`` is generally 10 to 20 times faster than using ``dd``. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5965 | |
| 5966 | Flashing Images Using ``bmaptool`` |
| 5967 | ================================== |
| 5968 | |
| 5969 | A fast and easy way to flash an image to a bootable device is to use |
| 5970 | Bmaptool, which is integrated into the OpenEmbedded build system. |
| 5971 | Bmaptool is a generic tool that creates a file's block map (bmap) and |
| 5972 | then uses that map to copy the file. As compared to traditional tools |
| 5973 | such as dd or cp, Bmaptool can copy (or flash) large files like raw |
| 5974 | system image files much faster. |
| 5975 | |
| 5976 | .. note:: |
| 5977 | |
| 5978 | - If you are using Ubuntu or Debian distributions, you can install |
| 5979 | the ``bmap-tools`` package using the following command and then |
| 5980 | use the tool without specifying ``PATH`` even from the root |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 5981 | account: |
| 5982 | :: |
| 5983 | |
| 5984 | $ sudo apt-get install bmap-tools |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5985 | |
| 5986 | - If you are unable to install the ``bmap-tools`` package, you will |
| 5987 | need to build Bmaptool before using it. Use the following command: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 5988 | :: |
| 5989 | |
| 5990 | $ bitbake bmap-tools-native |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5991 | |
| 5992 | Following, is an example that shows how to flash a Wic image. Realize |
| 5993 | that while this example uses a Wic image, you can use Bmaptool to flash |
| 5994 | any type of image. Use these steps to flash an image using Bmaptool: |
| 5995 | |
| 5996 | 1. *Update your local.conf File:* You need to have the following set |
| 5997 | in your ``local.conf`` file before building your image: |
| 5998 | :: |
| 5999 | |
| 6000 | IMAGE_FSTYPES += "wic wic.bmap" |
| 6001 | |
| 6002 | 2. *Get Your Image:* Either have your image ready (pre-built with the |
| 6003 | :term:`IMAGE_FSTYPES` |
| 6004 | setting previously mentioned) or take the step to build the image: |
| 6005 | :: |
| 6006 | |
| 6007 | $ bitbake image |
| 6008 | |
| 6009 | 3. *Flash the Device:* Flash the device with the image by using Bmaptool |
| 6010 | depending on your particular setup. The following commands assume the |
| 6011 | image resides in the Build Directory's ``deploy/images/`` area: |
| 6012 | |
| 6013 | - If you have write access to the media, use this command form: |
| 6014 | :: |
| 6015 | |
| 6016 | $ oe-run-native bmap-tools-native bmaptool copy build-directory/tmp/deploy/images/machine/image.wic /dev/sdX |
| 6017 | |
| 6018 | - If you do not have write access to the media, set your permissions |
| 6019 | first and then use the same command form: |
| 6020 | :: |
| 6021 | |
| 6022 | $ sudo chmod 666 /dev/sdX |
| 6023 | $ oe-run-native bmap-tools-native bmaptool copy build-directory/tmp/deploy/images/machine/image.wic /dev/sdX |
| 6024 | |
| 6025 | For help on the ``bmaptool`` command, use the following command: |
| 6026 | :: |
| 6027 | |
| 6028 | $ bmaptool --help |
| 6029 | |
| 6030 | Making Images More Secure |
| 6031 | ========================= |
| 6032 | |
| 6033 | Security is of increasing concern for embedded devices. Consider the |
| 6034 | issues and problems discussed in just this sampling of work found across |
| 6035 | the Internet: |
| 6036 | |
| 6037 | - *"*\ `Security Risks of Embedded |
| 6038 | Systems <https://www.schneier.com/blog/archives/2014/01/security_risks_9.html>`__\ *"* |
| 6039 | by Bruce Schneier |
| 6040 | |
| 6041 | - *"*\ `Internet Census |
| 6042 | 2012 <http://census2012.sourceforge.net/paper.html>`__\ *"* by Carna |
| 6043 | Botnet |
| 6044 | |
| 6045 | - *"*\ `Security Issues for Embedded |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 6046 | Devices <https://elinux.org/images/6/6f/Security-issues.pdf>`__\ *"* |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6047 | by Jake Edge |
| 6048 | |
| 6049 | When securing your image is of concern, there are steps, tools, and |
| 6050 | variables that you can consider to help you reach the security goals you |
| 6051 | need for your particular device. Not all situations are identical when |
| 6052 | it comes to making an image secure. Consequently, this section provides |
| 6053 | some guidance and suggestions for consideration when you want to make |
| 6054 | your image more secure. |
| 6055 | |
| 6056 | .. note:: |
| 6057 | |
| 6058 | Because the security requirements and risks are different for every |
| 6059 | type of device, this section cannot provide a complete reference on |
| 6060 | securing your custom OS. It is strongly recommended that you also |
| 6061 | consult other sources of information on embedded Linux system |
| 6062 | hardening and on security. |
| 6063 | |
| 6064 | General Considerations |
| 6065 | ---------------------- |
| 6066 | |
| 6067 | General considerations exist that help you create more secure images. |
| 6068 | You should consider the following suggestions to help make your device |
| 6069 | more secure: |
| 6070 | |
| 6071 | - Scan additional code you are adding to the system (e.g. application |
| 6072 | code) by using static analysis tools. Look for buffer overflows and |
| 6073 | other potential security problems. |
| 6074 | |
| 6075 | - Pay particular attention to the security for any web-based |
| 6076 | administration interface. |
| 6077 | |
| 6078 | Web interfaces typically need to perform administrative functions and |
| 6079 | tend to need to run with elevated privileges. Thus, the consequences |
| 6080 | resulting from the interface's security becoming compromised can be |
| 6081 | serious. Look for common web vulnerabilities such as |
| 6082 | cross-site-scripting (XSS), unvalidated inputs, and so forth. |
| 6083 | |
| 6084 | As with system passwords, the default credentials for accessing a |
| 6085 | web-based interface should not be the same across all devices. This |
| 6086 | is particularly true if the interface is enabled by default as it can |
| 6087 | be assumed that many end-users will not change the credentials. |
| 6088 | |
| 6089 | - Ensure you can update the software on the device to mitigate |
| 6090 | vulnerabilities discovered in the future. This consideration |
| 6091 | especially applies when your device is network-enabled. |
| 6092 | |
| 6093 | - Ensure you remove or disable debugging functionality before producing |
| 6094 | the final image. For information on how to do this, see the |
| 6095 | "`Considerations Specific to the OpenEmbedded Build |
| 6096 | System <#considerations-specific-to-the-openembedded-build-system>`__" |
| 6097 | section. |
| 6098 | |
| 6099 | - Ensure you have no network services listening that are not needed. |
| 6100 | |
| 6101 | - Remove any software from the image that is not needed. |
| 6102 | |
| 6103 | - Enable hardware support for secure boot functionality when your |
| 6104 | device supports this functionality. |
| 6105 | |
| 6106 | Security Flags |
| 6107 | -------------- |
| 6108 | |
| 6109 | The Yocto Project has security flags that you can enable that help make |
| 6110 | your build output more secure. The security flags are in the |
| 6111 | ``meta/conf/distro/include/security_flags.inc`` file in your |
| 6112 | :term:`Source Directory` (e.g. ``poky``). |
| 6113 | |
| 6114 | .. note:: |
| 6115 | |
| 6116 | Depending on the recipe, certain security flags are enabled and |
| 6117 | disabled by default. |
| 6118 | |
| 6119 | Use the following line in your ``local.conf`` file or in your custom |
| 6120 | distribution configuration file to enable the security compiler and |
| 6121 | linker flags for your build: |
| 6122 | :: |
| 6123 | |
| 6124 | require conf/distro/include/security_flags.inc |
| 6125 | |
| 6126 | Considerations Specific to the OpenEmbedded Build System |
| 6127 | -------------------------------------------------------- |
| 6128 | |
| 6129 | You can take some steps that are specific to the OpenEmbedded build |
| 6130 | system to make your images more secure: |
| 6131 | |
| 6132 | - Ensure "debug-tweaks" is not one of your selected |
| 6133 | :term:`IMAGE_FEATURES`. |
| 6134 | When creating a new project, the default is to provide you with an |
| 6135 | initial ``local.conf`` file that enables this feature using the |
| 6136 | :term:`EXTRA_IMAGE_FEATURES` |
| 6137 | variable with the line: |
| 6138 | :: |
| 6139 | |
| 6140 | EXTRA_IMAGE_FEATURES = "debug-tweaks" |
| 6141 | |
| 6142 | To disable that feature, simply comment out that line in your |
| 6143 | ``local.conf`` file, or make sure ``IMAGE_FEATURES`` does not contain |
| 6144 | "debug-tweaks" before producing your final image. Among other things, |
| 6145 | leaving this in place sets the root password as blank, which makes |
| 6146 | logging in for debugging or inspection easy during development but |
| 6147 | also means anyone can easily log in during production. |
| 6148 | |
| 6149 | - It is possible to set a root password for the image and also to set |
| 6150 | passwords for any extra users you might add (e.g. administrative or |
| 6151 | service type users). When you set up passwords for multiple images or |
| 6152 | users, you should not duplicate passwords. |
| 6153 | |
| 6154 | To set up passwords, use the |
| 6155 | :ref:`extrausers <ref-classes-extrausers>` |
| 6156 | class, which is the preferred method. For an example on how to set up |
| 6157 | both root and user passwords, see the |
| 6158 | ":ref:`extrausers.bbclass <ref-classes-extrausers>`" |
| 6159 | section. |
| 6160 | |
| 6161 | .. note:: |
| 6162 | |
| 6163 | When adding extra user accounts or setting a root password, be |
| 6164 | cautious about setting the same password on every device. If you |
| 6165 | do this, and the password you have set is exposed, then every |
| 6166 | device is now potentially compromised. If you need this access but |
| 6167 | want to ensure security, consider setting a different, random |
| 6168 | password for each device. Typically, you do this as a separate |
| 6169 | step after you deploy the image onto the device. |
| 6170 | |
| 6171 | - Consider enabling a Mandatory Access Control (MAC) framework such as |
| 6172 | SMACK or SELinux and tuning it appropriately for your device's usage. |
| 6173 | You can find more information in the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 6174 | :yocto_git:`meta-selinux </meta-selinux/>` layer. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6175 | |
| 6176 | Tools for Hardening Your Image |
| 6177 | ------------------------------ |
| 6178 | |
| 6179 | The Yocto Project provides tools for making your image more secure. You |
| 6180 | can find these tools in the ``meta-security`` layer of the |
| 6181 | :yocto_git:`Yocto Project Source Repositories <>`. |
| 6182 | |
| 6183 | Creating Your Own Distribution |
| 6184 | ============================== |
| 6185 | |
| 6186 | When you build an image using the Yocto Project and do not alter any |
| 6187 | distribution :term:`Metadata`, you are |
| 6188 | creating a Poky distribution. If you wish to gain more control over |
| 6189 | package alternative selections, compile-time options, and other |
| 6190 | low-level configurations, you can create your own distribution. |
| 6191 | |
| 6192 | To create your own distribution, the basic steps consist of creating |
| 6193 | your own distribution layer, creating your own distribution |
| 6194 | configuration file, and then adding any needed code and Metadata to the |
| 6195 | layer. The following steps provide some more detail: |
| 6196 | |
| 6197 | - *Create a layer for your new distro:* Create your distribution layer |
| 6198 | so that you can keep your Metadata and code for the distribution |
| 6199 | separate. It is strongly recommended that you create and use your own |
| 6200 | layer for configuration and code. Using your own layer as compared to |
| 6201 | just placing configurations in a ``local.conf`` configuration file |
| 6202 | makes it easier to reproduce the same build configuration when using |
| 6203 | multiple build machines. See the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 6204 | ":ref:`dev-manual/common-tasks:creating a general layer using the \`\`bitbake-layers\`\` script`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6205 | section for information on how to quickly set up a layer. |
| 6206 | |
| 6207 | - *Create the distribution configuration file:* The distribution |
| 6208 | configuration file needs to be created in the ``conf/distro`` |
| 6209 | directory of your layer. You need to name it using your distribution |
| 6210 | name (e.g. ``mydistro.conf``). |
| 6211 | |
| 6212 | .. note:: |
| 6213 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 6214 | The :term:`DISTRO` variable in your ``local.conf`` file determines the |
| 6215 | name of your distribution. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6216 | |
| 6217 | You can split out parts of your configuration file into include files |
| 6218 | and then "require" them from within your distribution configuration |
| 6219 | file. Be sure to place the include files in the |
| 6220 | ``conf/distro/include`` directory of your layer. A common example |
| 6221 | usage of include files would be to separate out the selection of |
| 6222 | desired version and revisions for individual recipes. |
| 6223 | |
| 6224 | Your configuration file needs to set the following required |
| 6225 | variables: |
| 6226 | |
| 6227 | - :term:`DISTRO_NAME` |
| 6228 | |
| 6229 | - :term:`DISTRO_VERSION` |
| 6230 | |
| 6231 | These following variables are optional and you typically set them |
| 6232 | from the distribution configuration file: |
| 6233 | |
| 6234 | - :term:`DISTRO_FEATURES` |
| 6235 | |
| 6236 | - :term:`DISTRO_EXTRA_RDEPENDS` |
| 6237 | |
| 6238 | - :term:`DISTRO_EXTRA_RRECOMMENDS` |
| 6239 | |
| 6240 | - :term:`TCLIBC` |
| 6241 | |
| 6242 | .. tip:: |
| 6243 | |
| 6244 | If you want to base your distribution configuration file on the |
| 6245 | very basic configuration from OE-Core, you can use |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 6246 | ``conf/distro/defaultsetup.conf`` as a reference and just include |
| 6247 | variables that differ as compared to ``defaultsetup.conf``. |
| 6248 | Alternatively, you can create a distribution configuration file |
| 6249 | from scratch using the ``defaultsetup.conf`` file or configuration files |
| 6250 | from other distributions such as Poky or Angstrom as references. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6251 | |
| 6252 | - *Provide miscellaneous variables:* Be sure to define any other |
| 6253 | variables for which you want to create a default or enforce as part |
| 6254 | of the distribution configuration. You can include nearly any |
| 6255 | variable from the ``local.conf`` file. The variables you use are not |
| 6256 | limited to the list in the previous bulleted item. |
| 6257 | |
| 6258 | - *Point to Your distribution configuration file:* In your |
| 6259 | ``local.conf`` file in the :term:`Build Directory`, |
| 6260 | set your |
| 6261 | :term:`DISTRO` variable to point to |
| 6262 | your distribution's configuration file. For example, if your |
| 6263 | distribution's configuration file is named ``mydistro.conf``, then |
| 6264 | you point to it as follows: |
| 6265 | :: |
| 6266 | |
| 6267 | DISTRO = "mydistro" |
| 6268 | |
| 6269 | - *Add more to the layer if necessary:* Use your layer to hold other |
| 6270 | information needed for the distribution: |
| 6271 | |
| 6272 | - Add recipes for installing distro-specific configuration files |
| 6273 | that are not already installed by another recipe. If you have |
| 6274 | distro-specific configuration files that are included by an |
| 6275 | existing recipe, you should add an append file (``.bbappend``) for |
| 6276 | those. For general information and recommendations on how to add |
| 6277 | recipes to your layer, see the "`Creating Your Own |
| 6278 | Layer <#creating-your-own-layer>`__" and "`Following Best |
| 6279 | Practices When Creating |
| 6280 | Layers <#best-practices-to-follow-when-creating-layers>`__" |
| 6281 | sections. |
| 6282 | |
| 6283 | - Add any image recipes that are specific to your distribution. |
| 6284 | |
| 6285 | - Add a ``psplash`` append file for a branded splash screen. For |
| 6286 | information on append files, see the "`Using .bbappend Files in |
| 6287 | Your Layer <#using-bbappend-files>`__" section. |
| 6288 | |
| 6289 | - Add any other append files to make custom changes that are |
| 6290 | specific to individual recipes. |
| 6291 | |
| 6292 | Creating a Custom Template Configuration Directory |
| 6293 | ================================================== |
| 6294 | |
| 6295 | If you are producing your own customized version of the build system for |
| 6296 | use by other users, you might want to customize the message shown by the |
| 6297 | setup script or you might want to change the template configuration |
| 6298 | files (i.e. ``local.conf`` and ``bblayers.conf``) that are created in a |
| 6299 | new build directory. |
| 6300 | |
| 6301 | The OpenEmbedded build system uses the environment variable |
| 6302 | ``TEMPLATECONF`` to locate the directory from which it gathers |
| 6303 | configuration information that ultimately ends up in the |
| 6304 | :term:`Build Directory` ``conf`` directory. |
| 6305 | By default, ``TEMPLATECONF`` is set as follows in the ``poky`` |
| 6306 | repository: |
| 6307 | :: |
| 6308 | |
| 6309 | TEMPLATECONF=${TEMPLATECONF:-meta-poky/conf} |
| 6310 | |
| 6311 | This is the |
| 6312 | directory used by the build system to find templates from which to build |
| 6313 | some key configuration files. If you look at this directory, you will |
| 6314 | see the ``bblayers.conf.sample``, ``local.conf.sample``, and |
| 6315 | ``conf-notes.txt`` files. The build system uses these files to form the |
| 6316 | respective ``bblayers.conf`` file, ``local.conf`` file, and display the |
| 6317 | list of BitBake targets when running the setup script. |
| 6318 | |
| 6319 | To override these default configuration files with configurations you |
| 6320 | want used within every new Build Directory, simply set the |
| 6321 | ``TEMPLATECONF`` variable to your directory. The ``TEMPLATECONF`` |
| 6322 | variable is set in the ``.templateconf`` file, which is in the top-level |
| 6323 | :term:`Source Directory` folder |
| 6324 | (e.g. ``poky``). Edit the ``.templateconf`` so that it can locate your |
| 6325 | directory. |
| 6326 | |
| 6327 | Best practices dictate that you should keep your template configuration |
| 6328 | directory in your custom distribution layer. For example, suppose you |
| 6329 | have a layer named ``meta-mylayer`` located in your home directory and |
| 6330 | you want your template configuration directory named ``myconf``. |
| 6331 | Changing the ``.templateconf`` as follows causes the OpenEmbedded build |
| 6332 | system to look in your directory and base its configuration files on the |
| 6333 | ``*.sample`` configuration files it finds. The final configuration files |
| 6334 | (i.e. ``local.conf`` and ``bblayers.conf`` ultimately still end up in |
| 6335 | your Build Directory, but they are based on your ``*.sample`` files. |
| 6336 | :: |
| 6337 | |
| 6338 | TEMPLATECONF=${TEMPLATECONF:-meta-mylayer/myconf} |
| 6339 | |
| 6340 | Aside from the ``*.sample`` configuration files, the ``conf-notes.txt`` |
| 6341 | also resides in the default ``meta-poky/conf`` directory. The script |
| 6342 | that sets up the build environment (i.e. |
| 6343 | :ref:`structure-core-script`) uses this file to |
| 6344 | display BitBake targets as part of the script output. Customizing this |
| 6345 | ``conf-notes.txt`` file is a good way to make sure your list of custom |
| 6346 | targets appears as part of the script's output. |
| 6347 | |
| 6348 | Here is the default list of targets displayed as a result of running |
| 6349 | either of the setup scripts: |
| 6350 | :: |
| 6351 | |
| 6352 | You can now run 'bitbake <target>' |
| 6353 | |
| 6354 | Common targets are: |
| 6355 | core-image-minimal |
| 6356 | core-image-sato |
| 6357 | meta-toolchain |
| 6358 | meta-ide-support |
| 6359 | |
| 6360 | Changing the listed common targets is as easy as editing your version of |
| 6361 | ``conf-notes.txt`` in your custom template configuration directory and |
| 6362 | making sure you have ``TEMPLATECONF`` set to your directory. |
| 6363 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6364 | Conserving Disk Space During Builds |
| 6365 | =================================== |
| 6366 | |
| 6367 | To help conserve disk space during builds, you can add the following |
| 6368 | statement to your project's ``local.conf`` configuration file found in |
| 6369 | the :term:`Build Directory`: |
| 6370 | :: |
| 6371 | |
| 6372 | INHERIT += "rm_work" |
| 6373 | |
| 6374 | Adding this statement deletes the work directory used for |
| 6375 | building a recipe once the recipe is built. For more information on |
| 6376 | "rm_work", see the |
| 6377 | :ref:`rm_work <ref-classes-rm-work>` class in the |
| 6378 | Yocto Project Reference Manual. |
| 6379 | |
| 6380 | Working with Packages |
| 6381 | ===================== |
| 6382 | |
| 6383 | This section describes a few tasks that involve packages: |
| 6384 | |
| 6385 | - `Excluding packages from an |
| 6386 | image <#excluding-packages-from-an-image>`__ |
| 6387 | |
| 6388 | - `Incrementing a binary package |
| 6389 | version <#incrementing-a-binary-package-version>`__ |
| 6390 | |
| 6391 | - `Handling optional module |
| 6392 | packaging <#handling-optional-module-packaging>`__ |
| 6393 | |
| 6394 | - `Using runtime package |
| 6395 | management <#using-runtime-package-management>`__ |
| 6396 | |
| 6397 | - `Generating and using signed |
| 6398 | packages <#generating-and-using-signed-packages>`__ |
| 6399 | |
| 6400 | - `Setting up and running package test |
| 6401 | (ptest) <#testing-packages-with-ptest>`__ |
| 6402 | |
| 6403 | - `Creating node package manager (NPM) |
| 6404 | packages <#creating-node-package-manager-npm-packages>`__ |
| 6405 | |
| 6406 | - `Adding custom metadata to |
| 6407 | packages <#adding-custom-metadata-to-packages>`__ |
| 6408 | |
| 6409 | Excluding Packages from an Image |
| 6410 | -------------------------------- |
| 6411 | |
| 6412 | You might find it necessary to prevent specific packages from being |
| 6413 | installed into an image. If so, you can use several variables to direct |
| 6414 | the build system to essentially ignore installing recommended packages |
| 6415 | or to not install a package at all. |
| 6416 | |
| 6417 | The following list introduces variables you can use to prevent packages |
| 6418 | from being installed into your image. Each of these variables only works |
| 6419 | with IPK and RPM package types. Support for Debian packages does not |
| 6420 | exist. Also, you can use these variables from your ``local.conf`` file |
| 6421 | or attach them to a specific image recipe by using a recipe name |
| 6422 | override. For more detail on the variables, see the descriptions in the |
| 6423 | Yocto Project Reference Manual's glossary chapter. |
| 6424 | |
| 6425 | - :term:`BAD_RECOMMENDATIONS`: |
| 6426 | Use this variable to specify "recommended-only" packages that you do |
| 6427 | not want installed. |
| 6428 | |
| 6429 | - :term:`NO_RECOMMENDATIONS`: |
| 6430 | Use this variable to prevent all "recommended-only" packages from |
| 6431 | being installed. |
| 6432 | |
| 6433 | - :term:`PACKAGE_EXCLUDE`: |
| 6434 | Use this variable to prevent specific packages from being installed |
| 6435 | regardless of whether they are "recommended-only" or not. You need to |
| 6436 | realize that the build process could fail with an error when you |
| 6437 | prevent the installation of a package whose presence is required by |
| 6438 | an installed package. |
| 6439 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6440 | Incrementing a Package Version |
| 6441 | ------------------------------ |
| 6442 | |
| 6443 | This section provides some background on how binary package versioning |
| 6444 | is accomplished and presents some of the services, variables, and |
| 6445 | terminology involved. |
| 6446 | |
| 6447 | In order to understand binary package versioning, you need to consider |
| 6448 | the following: |
| 6449 | |
| 6450 | - Binary Package: The binary package that is eventually built and |
| 6451 | installed into an image. |
| 6452 | |
| 6453 | - Binary Package Version: The binary package version is composed of two |
| 6454 | components - a version and a revision. |
| 6455 | |
| 6456 | .. note:: |
| 6457 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 6458 | Technically, a third component, the "epoch" (i.e. :term:`PE`) is involved |
| 6459 | but this discussion for the most part ignores ``PE``. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6460 | |
| 6461 | The version and revision are taken from the |
| 6462 | :term:`PV` and |
| 6463 | :term:`PR` variables, respectively. |
| 6464 | |
| 6465 | - ``PV``: The recipe version. ``PV`` represents the version of the |
| 6466 | software being packaged. Do not confuse ``PV`` with the binary |
| 6467 | package version. |
| 6468 | |
| 6469 | - ``PR``: The recipe revision. |
| 6470 | |
| 6471 | - :term:`SRCPV`: The OpenEmbedded |
| 6472 | build system uses this string to help define the value of ``PV`` when |
| 6473 | the source code revision needs to be included in it. |
| 6474 | |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 6475 | - :yocto_wiki:`PR Service </PR_Service>`: A |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6476 | network-based service that helps automate keeping package feeds |
| 6477 | compatible with existing package manager applications such as RPM, |
| 6478 | APT, and OPKG. |
| 6479 | |
| 6480 | Whenever the binary package content changes, the binary package version |
| 6481 | must change. Changing the binary package version is accomplished by |
| 6482 | changing or "bumping" the ``PR`` and/or ``PV`` values. Increasing these |
| 6483 | values occurs one of two ways: |
| 6484 | |
| 6485 | - Automatically using a Package Revision Service (PR Service). |
| 6486 | |
| 6487 | - Manually incrementing the ``PR`` and/or ``PV`` variables. |
| 6488 | |
| 6489 | Given a primary challenge of any build system and its users is how to |
| 6490 | maintain a package feed that is compatible with existing package manager |
| 6491 | applications such as RPM, APT, and OPKG, using an automated system is |
| 6492 | much preferred over a manual system. In either system, the main |
| 6493 | requirement is that binary package version numbering increases in a |
| 6494 | linear fashion and that a number of version components exist that |
| 6495 | support that linear progression. For information on how to ensure |
| 6496 | package revisioning remains linear, see the "`Automatically Incrementing |
| 6497 | a Binary Package Revision |
| 6498 | Number <#automatically-incrementing-a-binary-package-revision-number>`__" |
| 6499 | section. |
| 6500 | |
| 6501 | The following three sections provide related information on the PR |
| 6502 | Service, the manual method for "bumping" ``PR`` and/or ``PV``, and on |
| 6503 | how to ensure binary package revisioning remains linear. |
| 6504 | |
| 6505 | Working With a PR Service |
| 6506 | ~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 6507 | |
| 6508 | As mentioned, attempting to maintain revision numbers in the |
| 6509 | :term:`Metadata` is error prone, inaccurate, |
| 6510 | and causes problems for people submitting recipes. Conversely, the PR |
| 6511 | Service automatically generates increasing numbers, particularly the |
| 6512 | revision field, which removes the human element. |
| 6513 | |
| 6514 | .. note:: |
| 6515 | |
| 6516 | For additional information on using a PR Service, you can see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 6517 | :yocto_wiki:`PR Service </PR_Service>` wiki page. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6518 | |
| 6519 | The Yocto Project uses variables in order of decreasing priority to |
| 6520 | facilitate revision numbering (i.e. |
| 6521 | :term:`PE`, |
| 6522 | :term:`PV`, and |
| 6523 | :term:`PR` for epoch, version, and |
| 6524 | revision, respectively). The values are highly dependent on the policies |
| 6525 | and procedures of a given distribution and package feed. |
| 6526 | |
| 6527 | Because the OpenEmbedded build system uses |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 6528 | ":ref:`signatures <overview-manual/concepts:checksums (signatures)>`", which are |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6529 | unique to a given build, the build system knows when to rebuild |
| 6530 | packages. All the inputs into a given task are represented by a |
| 6531 | signature, which can trigger a rebuild when different. Thus, the build |
| 6532 | system itself does not rely on the ``PR``, ``PV``, and ``PE`` numbers to |
| 6533 | trigger a rebuild. The signatures, however, can be used to generate |
| 6534 | these values. |
| 6535 | |
| 6536 | The PR Service works with both ``OEBasic`` and ``OEBasicHash`` |
| 6537 | generators. The value of ``PR`` bumps when the checksum changes and the |
| 6538 | different generator mechanisms change signatures under different |
| 6539 | circumstances. |
| 6540 | |
| 6541 | As implemented, the build system includes values from the PR Service |
| 6542 | into the ``PR`` field as an addition using the form "``.x``" so ``r0`` |
| 6543 | becomes ``r0.1``, ``r0.2`` and so forth. This scheme allows existing |
| 6544 | ``PR`` values to be used for whatever reasons, which include manual |
| 6545 | ``PR`` bumps, should it be necessary. |
| 6546 | |
| 6547 | By default, the PR Service is not enabled or running. Thus, the packages |
| 6548 | generated are just "self consistent". The build system adds and removes |
| 6549 | packages and there are no guarantees about upgrade paths but images will |
| 6550 | be consistent and correct with the latest changes. |
| 6551 | |
| 6552 | The simplest form for a PR Service is for it to exist for a single host |
| 6553 | development system that builds the package feed (building system). For |
| 6554 | this scenario, you can enable a local PR Service by setting |
| 6555 | :term:`PRSERV_HOST` in your |
| 6556 | ``local.conf`` file in the :term:`Build Directory`: |
| 6557 | :: |
| 6558 | |
| 6559 | PRSERV_HOST = "localhost:0" |
| 6560 | |
| 6561 | Once the service is started, packages will automatically |
| 6562 | get increasing ``PR`` values and BitBake takes care of starting and |
| 6563 | stopping the server. |
| 6564 | |
| 6565 | If you have a more complex setup where multiple host development systems |
| 6566 | work against a common, shared package feed, you have a single PR Service |
| 6567 | running and it is connected to each building system. For this scenario, |
| 6568 | you need to start the PR Service using the ``bitbake-prserv`` command: |
| 6569 | :: |
| 6570 | |
| 6571 | bitbake-prserv --host ip --port port --start |
| 6572 | |
| 6573 | In addition to |
| 6574 | hand-starting the service, you need to update the ``local.conf`` file of |
| 6575 | each building system as described earlier so each system points to the |
| 6576 | server and port. |
| 6577 | |
| 6578 | It is also recommended you use build history, which adds some sanity |
| 6579 | checks to binary package versions, in conjunction with the server that |
| 6580 | is running the PR Service. To enable build history, add the following to |
| 6581 | each building system's ``local.conf`` file: |
| 6582 | :: |
| 6583 | |
| 6584 | # It is recommended to activate "buildhistory" for testing the PR service |
| 6585 | INHERIT += "buildhistory" |
| 6586 | BUILDHISTORY_COMMIT = "1" |
| 6587 | |
| 6588 | For information on build |
| 6589 | history, see the "`Maintaining Build Output |
| 6590 | Quality <#maintaining-build-output-quality>`__" section. |
| 6591 | |
| 6592 | .. note:: |
| 6593 | |
| 6594 | The OpenEmbedded build system does not maintain ``PR`` information as |
| 6595 | part of the shared state (sstate) packages. If you maintain an sstate |
| 6596 | feed, its expected that either all your building systems that |
| 6597 | contribute to the sstate feed use a shared PR Service, or you do not |
| 6598 | run a PR Service on any of your building systems. Having some systems |
| 6599 | use a PR Service while others do not leads to obvious problems. |
| 6600 | |
| 6601 | For more information on shared state, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 6602 | ":ref:`overview-manual/concepts:shared state cache`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6603 | section in the Yocto Project Overview and Concepts Manual. |
| 6604 | |
| 6605 | Manually Bumping PR |
| 6606 | ~~~~~~~~~~~~~~~~~~~ |
| 6607 | |
| 6608 | The alternative to setting up a PR Service is to manually "bump" the |
| 6609 | :term:`PR` variable. |
| 6610 | |
| 6611 | If a committed change results in changing the package output, then the |
| 6612 | value of the PR variable needs to be increased (or "bumped") as part of |
| 6613 | that commit. For new recipes you should add the ``PR`` variable and set |
| 6614 | its initial value equal to "r0", which is the default. Even though the |
| 6615 | default value is "r0", the practice of adding it to a new recipe makes |
| 6616 | it harder to forget to bump the variable when you make changes to the |
| 6617 | recipe in future. |
| 6618 | |
| 6619 | If you are sharing a common ``.inc`` file with multiple recipes, you can |
| 6620 | also use the ``INC_PR`` variable to ensure that the recipes sharing the |
| 6621 | ``.inc`` file are rebuilt when the ``.inc`` file itself is changed. The |
| 6622 | ``.inc`` file must set ``INC_PR`` (initially to "r0"), and all recipes |
| 6623 | referring to it should set ``PR`` to "${INC_PR}.0" initially, |
| 6624 | incrementing the last number when the recipe is changed. If the ``.inc`` |
| 6625 | file is changed then its ``INC_PR`` should be incremented. |
| 6626 | |
| 6627 | When upgrading the version of a binary package, assuming the ``PV`` |
| 6628 | changes, the ``PR`` variable should be reset to "r0" (or "${INC_PR}.0" |
| 6629 | if you are using ``INC_PR``). |
| 6630 | |
| 6631 | Usually, version increases occur only to binary packages. However, if |
| 6632 | for some reason ``PV`` changes but does not increase, you can increase |
| 6633 | the ``PE`` variable (Package Epoch). The ``PE`` variable defaults to |
| 6634 | "0". |
| 6635 | |
| 6636 | Binary package version numbering strives to follow the `Debian Version |
| 6637 | Field Policy |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 6638 | Guidelines <https://www.debian.org/doc/debian-policy/ch-controlfields.html>`__. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6639 | These guidelines define how versions are compared and what "increasing" |
| 6640 | a version means. |
| 6641 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6642 | Automatically Incrementing a Package Version Number |
| 6643 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 6644 | |
| 6645 | When fetching a repository, BitBake uses the |
| 6646 | :term:`SRCREV` variable to determine |
| 6647 | the specific source code revision from which to build. You set the |
| 6648 | ``SRCREV`` variable to |
| 6649 | :term:`AUTOREV` to cause the |
| 6650 | OpenEmbedded build system to automatically use the latest revision of |
| 6651 | the software: |
| 6652 | :: |
| 6653 | |
| 6654 | SRCREV = "${AUTOREV}" |
| 6655 | |
| 6656 | Furthermore, you need to reference ``SRCPV`` in ``PV`` in order to |
| 6657 | automatically update the version whenever the revision of the source |
| 6658 | code changes. Here is an example: |
| 6659 | :: |
| 6660 | |
| 6661 | PV = "1.0+git${SRCPV}" |
| 6662 | |
| 6663 | The OpenEmbedded build system substitutes ``SRCPV`` with the following: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 6664 | |
| 6665 | .. code-block:: none |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6666 | |
| 6667 | AUTOINC+source_code_revision |
| 6668 | |
| 6669 | The build system replaces the ``AUTOINC`` |
| 6670 | with a number. The number used depends on the state of the PR Service: |
| 6671 | |
| 6672 | - If PR Service is enabled, the build system increments the number, |
| 6673 | which is similar to the behavior of |
| 6674 | :term:`PR`. This behavior results in |
| 6675 | linearly increasing package versions, which is desirable. Here is an |
| 6676 | example: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 6677 | |
| 6678 | .. code-block:: none |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6679 | |
| 6680 | hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk |
| 6681 | hello-world-git_0.0+git1+dd2f5c3565-r0.0_armv7a-neon.ipk |
| 6682 | |
| 6683 | - If PR Service is not enabled, the build system replaces the |
| 6684 | ``AUTOINC`` placeholder with zero (i.e. "0"). This results in |
| 6685 | changing the package version since the source revision is included. |
| 6686 | However, package versions are not increased linearly. Here is an |
| 6687 | example: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 6688 | |
| 6689 | .. code-block:: none |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6690 | |
| 6691 | hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk |
| 6692 | hello-world-git_0.0+git0+dd2f5c3565-r0.0_armv7a-neon.ipk |
| 6693 | |
| 6694 | In summary, the OpenEmbedded build system does not track the history of |
| 6695 | binary package versions for this purpose. ``AUTOINC``, in this case, is |
| 6696 | comparable to ``PR``. If PR server is not enabled, ``AUTOINC`` in the |
| 6697 | package version is simply replaced by "0". If PR server is enabled, the |
| 6698 | build system keeps track of the package versions and bumps the number |
| 6699 | when the package revision changes. |
| 6700 | |
| 6701 | Handling Optional Module Packaging |
| 6702 | ---------------------------------- |
| 6703 | |
| 6704 | Many pieces of software split functionality into optional modules (or |
| 6705 | plugins) and the plugins that are built might depend on configuration |
| 6706 | options. To avoid having to duplicate the logic that determines what |
| 6707 | modules are available in your recipe or to avoid having to package each |
| 6708 | module by hand, the OpenEmbedded build system provides functionality to |
| 6709 | handle module packaging dynamically. |
| 6710 | |
| 6711 | To handle optional module packaging, you need to do two things: |
| 6712 | |
| 6713 | - Ensure the module packaging is actually done. |
| 6714 | |
| 6715 | - Ensure that any dependencies on optional modules from other recipes |
| 6716 | are satisfied by your recipe. |
| 6717 | |
| 6718 | Making Sure the Packaging is Done |
| 6719 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 6720 | |
| 6721 | To ensure the module packaging actually gets done, you use the |
| 6722 | ``do_split_packages`` function within the ``populate_packages`` Python |
| 6723 | function in your recipe. The ``do_split_packages`` function searches for |
| 6724 | a pattern of files or directories under a specified path and creates a |
| 6725 | package for each one it finds by appending to the |
| 6726 | :term:`PACKAGES` variable and |
| 6727 | setting the appropriate values for ``FILES_packagename``, |
| 6728 | ``RDEPENDS_packagename``, ``DESCRIPTION_packagename``, and so forth. |
| 6729 | Here is an example from the ``lighttpd`` recipe: |
| 6730 | :: |
| 6731 | |
| 6732 | python populate_packages_prepend () { |
| 6733 | lighttpd_libdir = d.expand('${libdir}') |
| 6734 | do_split_packages(d, lighttpd_libdir, '^mod_(.*).so$', |
| 6735 | 'lighttpd-module-%s', 'Lighttpd module for %s', |
| 6736 | extra_depends='') |
| 6737 | } |
| 6738 | |
| 6739 | The previous example specifies a number of things in the call to |
| 6740 | ``do_split_packages``. |
| 6741 | |
| 6742 | - A directory within the files installed by your recipe through |
| 6743 | ``do_install`` in which to search. |
| 6744 | |
| 6745 | - A regular expression used to match module files in that directory. In |
| 6746 | the example, note the parentheses () that mark the part of the |
| 6747 | expression from which the module name should be derived. |
| 6748 | |
| 6749 | - A pattern to use for the package names. |
| 6750 | |
| 6751 | - A description for each package. |
| 6752 | |
| 6753 | - An empty string for ``extra_depends``, which disables the default |
| 6754 | dependency on the main ``lighttpd`` package. Thus, if a file in |
| 6755 | ``${libdir}`` called ``mod_alias.so`` is found, a package called |
| 6756 | ``lighttpd-module-alias`` is created for it and the |
| 6757 | :term:`DESCRIPTION` is set to |
| 6758 | "Lighttpd module for alias". |
| 6759 | |
| 6760 | Often, packaging modules is as simple as the previous example. However, |
| 6761 | more advanced options exist that you can use within |
| 6762 | ``do_split_packages`` to modify its behavior. And, if you need to, you |
| 6763 | can add more logic by specifying a hook function that is called for each |
| 6764 | package. It is also perfectly acceptable to call ``do_split_packages`` |
| 6765 | multiple times if you have more than one set of modules to package. |
| 6766 | |
| 6767 | For more examples that show how to use ``do_split_packages``, see the |
| 6768 | ``connman.inc`` file in the ``meta/recipes-connectivity/connman/`` |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 6769 | directory of the ``poky`` :ref:`source repository <overview-manual/development-environment:yocto project source repositories>`. You can |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6770 | also find examples in ``meta/classes/kernel.bbclass``. |
| 6771 | |
| 6772 | Following is a reference that shows ``do_split_packages`` mandatory and |
| 6773 | optional arguments: |
| 6774 | :: |
| 6775 | |
| 6776 | Mandatory arguments |
| 6777 | |
| 6778 | root |
| 6779 | The path in which to search |
| 6780 | file_regex |
| 6781 | Regular expression to match searched files. |
| 6782 | Use parentheses () to mark the part of this |
| 6783 | expression that should be used to derive the |
| 6784 | module name (to be substituted where %s is |
| 6785 | used in other function arguments as noted below) |
| 6786 | output_pattern |
| 6787 | Pattern to use for the package names. Must |
| 6788 | include %s. |
| 6789 | description |
| 6790 | Description to set for each package. Must |
| 6791 | include %s. |
| 6792 | |
| 6793 | Optional arguments |
| 6794 | |
| 6795 | postinst |
| 6796 | Postinstall script to use for all packages |
| 6797 | (as a string) |
| 6798 | recursive |
| 6799 | True to perform a recursive search - default |
| 6800 | False |
| 6801 | hook |
| 6802 | A hook function to be called for every match. |
| 6803 | The function will be called with the following |
| 6804 | arguments (in the order listed): |
| 6805 | |
| 6806 | f |
| 6807 | Full path to the file/directory match |
| 6808 | pkg |
| 6809 | The package name |
| 6810 | file_regex |
| 6811 | As above |
| 6812 | output_pattern |
| 6813 | As above |
| 6814 | modulename |
| 6815 | The module name derived using file_regex |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 6816 | extra_depends |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6817 | Extra runtime dependencies (RDEPENDS) to be |
| 6818 | set for all packages. The default value of None |
| 6819 | causes a dependency on the main package |
| 6820 | (${PN}) - if you do not want this, pass empty |
| 6821 | string '' for this parameter. |
| 6822 | aux_files_pattern |
| 6823 | Extra item(s) to be added to FILES for each |
| 6824 | package. Can be a single string item or a list |
| 6825 | of strings for multiple items. Must include %s. |
| 6826 | postrm |
| 6827 | postrm script to use for all packages (as a |
| 6828 | string) |
| 6829 | allow_dirs |
| 6830 | True to allow directories to be matched - |
| 6831 | default False |
| 6832 | prepend |
| 6833 | If True, prepend created packages to PACKAGES |
| 6834 | instead of the default False which appends them |
| 6835 | match_path |
| 6836 | match file_regex on the whole relative path to |
| 6837 | the root rather than just the file name |
| 6838 | aux_files_pattern_verbatim |
| 6839 | Extra item(s) to be added to FILES for each |
| 6840 | package, using the actual derived module name |
| 6841 | rather than converting it to something legal |
| 6842 | for a package name. Can be a single string item |
| 6843 | or a list of strings for multiple items. Must |
| 6844 | include %s. |
| 6845 | allow_links |
| 6846 | True to allow symlinks to be matched - default |
| 6847 | False |
| 6848 | summary |
| 6849 | Summary to set for each package. Must include %s; |
| 6850 | defaults to description if not set. |
| 6851 | |
| 6852 | |
| 6853 | |
| 6854 | Satisfying Dependencies |
| 6855 | ~~~~~~~~~~~~~~~~~~~~~~~ |
| 6856 | |
| 6857 | The second part for handling optional module packaging is to ensure that |
| 6858 | any dependencies on optional modules from other recipes are satisfied by |
| 6859 | your recipe. You can be sure these dependencies are satisfied by using |
| 6860 | the :term:`PACKAGES_DYNAMIC` |
| 6861 | variable. Here is an example that continues with the ``lighttpd`` recipe |
| 6862 | shown earlier: |
| 6863 | :: |
| 6864 | |
| 6865 | PACKAGES_DYNAMIC = "lighttpd-module-.*" |
| 6866 | |
| 6867 | The name |
| 6868 | specified in the regular expression can of course be anything. In this |
| 6869 | example, it is ``lighttpd-module-`` and is specified as the prefix to |
| 6870 | ensure that any :term:`RDEPENDS` and |
| 6871 | :term:`RRECOMMENDS` on a package |
| 6872 | name starting with the prefix are satisfied during build time. If you |
| 6873 | are using ``do_split_packages`` as described in the previous section, |
| 6874 | the value you put in ``PACKAGES_DYNAMIC`` should correspond to the name |
| 6875 | pattern specified in the call to ``do_split_packages``. |
| 6876 | |
| 6877 | Using Runtime Package Management |
| 6878 | -------------------------------- |
| 6879 | |
| 6880 | During a build, BitBake always transforms a recipe into one or more |
| 6881 | packages. For example, BitBake takes the ``bash`` recipe and produces a |
| 6882 | number of packages (e.g. ``bash``, ``bash-bashbug``, |
| 6883 | ``bash-completion``, ``bash-completion-dbg``, ``bash-completion-dev``, |
| 6884 | ``bash-completion-extra``, ``bash-dbg``, and so forth). Not all |
| 6885 | generated packages are included in an image. |
| 6886 | |
| 6887 | In several situations, you might need to update, add, remove, or query |
| 6888 | the packages on a target device at runtime (i.e. without having to |
| 6889 | generate a new image). Examples of such situations include: |
| 6890 | |
| 6891 | - You want to provide in-the-field updates to deployed devices (e.g. |
| 6892 | security updates). |
| 6893 | |
| 6894 | - You want to have a fast turn-around development cycle for one or more |
| 6895 | applications that run on your device. |
| 6896 | |
| 6897 | - You want to temporarily install the "debug" packages of various |
| 6898 | applications on your device so that debugging can be greatly improved |
| 6899 | by allowing access to symbols and source debugging. |
| 6900 | |
| 6901 | - You want to deploy a more minimal package selection of your device |
| 6902 | but allow in-the-field updates to add a larger selection for |
| 6903 | customization. |
| 6904 | |
| 6905 | In all these situations, you have something similar to a more |
| 6906 | traditional Linux distribution in that in-field devices are able to |
| 6907 | receive pre-compiled packages from a server for installation or update. |
| 6908 | Being able to install these packages on a running, in-field device is |
| 6909 | what is termed "runtime package management". |
| 6910 | |
| 6911 | In order to use runtime package management, you need a host or server |
| 6912 | machine that serves up the pre-compiled packages plus the required |
| 6913 | metadata. You also need package manipulation tools on the target. The |
| 6914 | build machine is a likely candidate to act as the server. However, that |
| 6915 | machine does not necessarily have to be the package server. The build |
| 6916 | machine could push its artifacts to another machine that acts as the |
| 6917 | server (e.g. Internet-facing). In fact, doing so is advantageous for a |
| 6918 | production environment as getting the packages away from the development |
| 6919 | system's build directory prevents accidental overwrites. |
| 6920 | |
| 6921 | A simple build that targets just one device produces more than one |
| 6922 | package database. In other words, the packages produced by a build are |
| 6923 | separated out into a couple of different package groupings based on |
| 6924 | criteria such as the target's CPU architecture, the target board, or the |
| 6925 | C library used on the target. For example, a build targeting the |
| 6926 | ``qemux86`` device produces the following three package databases: |
| 6927 | ``noarch``, ``i586``, and ``qemux86``. If you wanted your ``qemux86`` |
| 6928 | device to be aware of all the packages that were available to it, you |
| 6929 | would need to point it to each of these databases individually. In a |
| 6930 | similar way, a traditional Linux distribution usually is configured to |
| 6931 | be aware of a number of software repositories from which it retrieves |
| 6932 | packages. |
| 6933 | |
| 6934 | Using runtime package management is completely optional and not required |
| 6935 | for a successful build or deployment in any way. But if you want to make |
| 6936 | use of runtime package management, you need to do a couple things above |
| 6937 | and beyond the basics. The remainder of this section describes what you |
| 6938 | need to do. |
| 6939 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6940 | Build Considerations |
| 6941 | ~~~~~~~~~~~~~~~~~~~~ |
| 6942 | |
| 6943 | This section describes build considerations of which you need to be |
| 6944 | aware in order to provide support for runtime package management. |
| 6945 | |
| 6946 | When BitBake generates packages, it needs to know what format or formats |
| 6947 | to use. In your configuration, you use the |
| 6948 | :term:`PACKAGE_CLASSES` |
| 6949 | variable to specify the format: |
| 6950 | |
| 6951 | 1. Open the ``local.conf`` file inside your |
| 6952 | :term:`Build Directory` (e.g. |
| 6953 | ``~/poky/build/conf/local.conf``). |
| 6954 | |
| 6955 | 2. Select the desired package format as follows: |
| 6956 | :: |
| 6957 | |
| 6958 | PACKAGE_CLASSES ?= "package_packageformat" |
| 6959 | |
| 6960 | where packageformat can be "ipk", "rpm", |
| 6961 | "deb", or "tar" which are the supported package formats. |
| 6962 | |
| 6963 | .. note:: |
| 6964 | |
| 6965 | Because the Yocto Project supports four different package formats, |
| 6966 | you can set the variable with more than one argument. However, the |
| 6967 | OpenEmbedded build system only uses the first argument when |
| 6968 | creating an image or Software Development Kit (SDK). |
| 6969 | |
| 6970 | If you would like your image to start off with a basic package database |
| 6971 | containing the packages in your current build as well as to have the |
| 6972 | relevant tools available on the target for runtime package management, |
| 6973 | you can include "package-management" in the |
| 6974 | :term:`IMAGE_FEATURES` |
| 6975 | variable. Including "package-management" in this configuration variable |
| 6976 | ensures that when the image is assembled for your target, the image |
| 6977 | includes the currently-known package databases as well as the |
| 6978 | target-specific tools required for runtime package management to be |
| 6979 | performed on the target. However, this is not strictly necessary. You |
| 6980 | could start your image off without any databases but only include the |
| 6981 | required on-target package tool(s). As an example, you could include |
| 6982 | "opkg" in your |
| 6983 | :term:`IMAGE_INSTALL` variable |
| 6984 | if you are using the IPK package format. You can then initialize your |
| 6985 | target's package database(s) later once your image is up and running. |
| 6986 | |
| 6987 | Whenever you perform any sort of build step that can potentially |
| 6988 | generate a package or modify existing package, it is always a good idea |
| 6989 | to re-generate the package index after the build by using the following |
| 6990 | command: |
| 6991 | :: |
| 6992 | |
| 6993 | $ bitbake package-index |
| 6994 | |
| 6995 | It might be tempting to build the |
| 6996 | package and the package index at the same time with a command such as |
| 6997 | the following: |
| 6998 | :: |
| 6999 | |
| 7000 | $ bitbake some-package package-index |
| 7001 | |
| 7002 | Do not do this as |
| 7003 | BitBake does not schedule the package index for after the completion of |
| 7004 | the package you are building. Consequently, you cannot be sure of the |
| 7005 | package index including information for the package you just built. |
| 7006 | Thus, be sure to run the package update step separately after building |
| 7007 | any packages. |
| 7008 | |
| 7009 | You can use the |
| 7010 | :term:`PACKAGE_FEED_ARCHS`, |
| 7011 | :term:`PACKAGE_FEED_BASE_PATHS`, |
| 7012 | and |
| 7013 | :term:`PACKAGE_FEED_URIS` |
| 7014 | variables to pre-configure target images to use a package feed. If you |
| 7015 | do not define these variables, then manual steps as described in the |
| 7016 | subsequent sections are necessary to configure the target. You should |
| 7017 | set these variables before building the image in order to produce a |
| 7018 | correctly configured image. |
| 7019 | |
| 7020 | When your build is complete, your packages reside in the |
| 7021 | ``${TMPDIR}/deploy/packageformat`` directory. For example, if |
| 7022 | ``${``\ :term:`TMPDIR`\ ``}`` is |
| 7023 | ``tmp`` and your selected package type is RPM, then your RPM packages |
| 7024 | are available in ``tmp/deploy/rpm``. |
| 7025 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7026 | Host or Server Machine Setup |
| 7027 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 7028 | |
| 7029 | Although other protocols are possible, a server using HTTP typically |
| 7030 | serves packages. If you want to use HTTP, then set up and configure a |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7031 | web server such as Apache 2, lighttpd, or Python web server on the |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7032 | machine serving the packages. |
| 7033 | |
| 7034 | To keep things simple, this section describes how to set up a |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7035 | Python web server to share package feeds from the developer's |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7036 | machine. Although this server might not be the best for a production |
| 7037 | environment, the setup is simple and straight forward. Should you want |
| 7038 | to use a different server more suited for production (e.g. Apache 2, |
| 7039 | Lighttpd, or Nginx), take the appropriate steps to do so. |
| 7040 | |
| 7041 | From within the build directory where you have built an image based on |
| 7042 | your packaging choice (i.e. the |
| 7043 | :term:`PACKAGE_CLASSES` |
| 7044 | setting), simply start the server. The following example assumes a build |
| 7045 | directory of ``~/poky/build/tmp/deploy/rpm`` and a ``PACKAGE_CLASSES`` |
| 7046 | setting of "package_rpm": |
| 7047 | :: |
| 7048 | |
| 7049 | $ cd ~/poky/build/tmp/deploy/rpm |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7050 | $ python3 -m http.server |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7051 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7052 | Target Setup |
| 7053 | ~~~~~~~~~~~~ |
| 7054 | |
| 7055 | Setting up the target differs depending on the package management |
| 7056 | system. This section provides information for RPM, IPK, and DEB. |
| 7057 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7058 | Using RPM |
| 7059 | ^^^^^^^^^ |
| 7060 | |
| 7061 | The `Dandified Packaging |
| 7062 | Tool <https://en.wikipedia.org/wiki/DNF_(software)>`__ (DNF) performs |
| 7063 | runtime package management of RPM packages. In order to use DNF for |
| 7064 | runtime package management, you must perform an initial setup on the |
| 7065 | target machine for cases where the ``PACKAGE_FEED_*`` variables were not |
| 7066 | set as part of the image that is running on the target. This means if |
| 7067 | you built your image and did not not use these variables as part of the |
| 7068 | build and your image is now running on the target, you need to perform |
| 7069 | the steps in this section if you want to use runtime package management. |
| 7070 | |
| 7071 | .. note:: |
| 7072 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7073 | For information on the ``PACKAGE_FEED_*`` variables, see |
| 7074 | :term:`PACKAGE_FEED_ARCHS`, :term:`PACKAGE_FEED_BASE_PATHS`, and |
| 7075 | :term:`PACKAGE_FEED_URIS` in the Yocto Project Reference Manual variables |
| 7076 | glossary. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7077 | |
| 7078 | On the target, you must inform DNF that package databases are available. |
| 7079 | You do this by creating a file named |
| 7080 | ``/etc/yum.repos.d/oe-packages.repo`` and defining the ``oe-packages``. |
| 7081 | |
| 7082 | As an example, assume the target is able to use the following package |
| 7083 | databases: ``all``, ``i586``, and ``qemux86`` from a server named |
| 7084 | ``my.server``. The specifics for setting up the web server are up to |
| 7085 | you. The critical requirement is that the URIs in the target repository |
| 7086 | configuration point to the correct remote location for the feeds. |
| 7087 | |
| 7088 | .. note:: |
| 7089 | |
| 7090 | For development purposes, you can point the web server to the build |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7091 | system's ``deploy`` directory. However, for production use, it is better to |
| 7092 | copy the package directories to a location outside of the build area and use |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7093 | that location. Doing so avoids situations where the build system |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7094 | overwrites or changes the ``deploy`` directory. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7095 | |
| 7096 | When telling DNF where to look for the package databases, you must |
| 7097 | declare individual locations per architecture or a single location used |
| 7098 | for all architectures. You cannot do both: |
| 7099 | |
| 7100 | - *Create an Explicit List of Architectures:* Define individual base |
| 7101 | URLs to identify where each package database is located: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7102 | |
| 7103 | .. code-block:: none |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7104 | |
| 7105 | [oe-packages] |
| 7106 | baseurl=http://my.server/rpm/i586 http://my.server/rpm/qemux86 http://my.server/rpm/all |
| 7107 | |
| 7108 | This example |
| 7109 | informs DNF about individual package databases for all three |
| 7110 | architectures. |
| 7111 | |
| 7112 | - *Create a Single (Full) Package Index:* Define a single base URL that |
| 7113 | identifies where a full package database is located: |
| 7114 | :: |
| 7115 | |
| 7116 | [oe-packages] |
| 7117 | baseurl=http://my.server/rpm |
| 7118 | |
| 7119 | This example informs DNF about a single |
| 7120 | package database that contains all the package index information for |
| 7121 | all supported architectures. |
| 7122 | |
| 7123 | Once you have informed DNF where to find the package databases, you need |
| 7124 | to fetch them: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7125 | |
| 7126 | .. code-block:: none |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7127 | |
| 7128 | # dnf makecache |
| 7129 | |
| 7130 | DNF is now able to find, install, and |
| 7131 | upgrade packages from the specified repository or repositories. |
| 7132 | |
| 7133 | .. note:: |
| 7134 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7135 | See the `DNF documentation <https://dnf.readthedocs.io/en/latest/>`__ for |
| 7136 | additional information. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7137 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7138 | Using IPK |
| 7139 | ^^^^^^^^^ |
| 7140 | |
| 7141 | The ``opkg`` application performs runtime package management of IPK |
| 7142 | packages. You must perform an initial setup for ``opkg`` on the target |
| 7143 | machine if the |
| 7144 | :term:`PACKAGE_FEED_ARCHS`, |
| 7145 | :term:`PACKAGE_FEED_BASE_PATHS`, |
| 7146 | and |
| 7147 | :term:`PACKAGE_FEED_URIS` |
| 7148 | variables have not been set or the target image was built before the |
| 7149 | variables were set. |
| 7150 | |
| 7151 | The ``opkg`` application uses configuration files to find available |
| 7152 | package databases. Thus, you need to create a configuration file inside |
| 7153 | the ``/etc/opkg/`` direction, which informs ``opkg`` of any repository |
| 7154 | you want to use. |
| 7155 | |
| 7156 | As an example, suppose you are serving packages from a ``ipk/`` |
| 7157 | directory containing the ``i586``, ``all``, and ``qemux86`` databases |
| 7158 | through an HTTP server named ``my.server``. On the target, create a |
| 7159 | configuration file (e.g. ``my_repo.conf``) inside the ``/etc/opkg/`` |
| 7160 | directory containing the following: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7161 | |
| 7162 | .. code-block:: none |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7163 | |
| 7164 | src/gz all http://my.server/ipk/all |
| 7165 | src/gz i586 http://my.server/ipk/i586 |
| 7166 | src/gz qemux86 http://my.server/ipk/qemux86 |
| 7167 | |
| 7168 | Next, instruct ``opkg`` to fetch the |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7169 | repository information: |
| 7170 | |
| 7171 | .. code-block:: none |
| 7172 | |
| 7173 | # opkg update |
| 7174 | |
| 7175 | The ``opkg`` application is now able to find, install, and upgrade packages |
| 7176 | from the specified repository. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7177 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7178 | Using DEB |
| 7179 | ^^^^^^^^^ |
| 7180 | |
| 7181 | The ``apt`` application performs runtime package management of DEB |
| 7182 | packages. This application uses a source list file to find available |
| 7183 | package databases. You must perform an initial setup for ``apt`` on the |
| 7184 | target machine if the |
| 7185 | :term:`PACKAGE_FEED_ARCHS`, |
| 7186 | :term:`PACKAGE_FEED_BASE_PATHS`, |
| 7187 | and |
| 7188 | :term:`PACKAGE_FEED_URIS` |
| 7189 | variables have not been set or the target image was built before the |
| 7190 | variables were set. |
| 7191 | |
| 7192 | To inform ``apt`` of the repository you want to use, you might create a |
| 7193 | list file (e.g. ``my_repo.list``) inside the |
| 7194 | ``/etc/apt/sources.list.d/`` directory. As an example, suppose you are |
| 7195 | serving packages from a ``deb/`` directory containing the ``i586``, |
| 7196 | ``all``, and ``qemux86`` databases through an HTTP server named |
| 7197 | ``my.server``. The list file should contain: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7198 | |
| 7199 | .. code-block:: none |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7200 | |
| 7201 | deb http://my.server/deb/all ./ |
| 7202 | deb http://my.server/deb/i586 ./ |
| 7203 | deb http://my.server/deb/qemux86 ./ |
| 7204 | |
| 7205 | Next, instruct the ``apt`` application |
| 7206 | to fetch the repository information: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7207 | |
| 7208 | .. code-block:: none |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7209 | |
| 7210 | # apt-get update |
| 7211 | |
| 7212 | After this step, |
| 7213 | ``apt`` is able to find, install, and upgrade packages from the |
| 7214 | specified repository. |
| 7215 | |
| 7216 | Generating and Using Signed Packages |
| 7217 | ------------------------------------ |
| 7218 | |
| 7219 | In order to add security to RPM packages used during a build, you can |
| 7220 | take steps to securely sign them. Once a signature is verified, the |
| 7221 | OpenEmbedded build system can use the package in the build. If security |
| 7222 | fails for a signed package, the build system aborts the build. |
| 7223 | |
| 7224 | This section describes how to sign RPM packages during a build and how |
| 7225 | to use signed package feeds (repositories) when doing a build. |
| 7226 | |
| 7227 | Signing RPM Packages |
| 7228 | ~~~~~~~~~~~~~~~~~~~~ |
| 7229 | |
| 7230 | To enable signing RPM packages, you must set up the following |
| 7231 | configurations in either your ``local.config`` or ``distro.config`` |
| 7232 | file: |
| 7233 | :: |
| 7234 | |
| 7235 | # Inherit sign_rpm.bbclass to enable signing functionality |
| 7236 | INHERIT += " sign_rpm" |
| 7237 | # Define the GPG key that will be used for signing. |
| 7238 | RPM_GPG_NAME = "key_name" |
| 7239 | # Provide passphrase for the key |
| 7240 | RPM_GPG_PASSPHRASE = "passphrase" |
| 7241 | |
| 7242 | .. note:: |
| 7243 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7244 | Be sure to supply appropriate values for both `key_name` and |
| 7245 | `passphrase`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7246 | |
| 7247 | Aside from the ``RPM_GPG_NAME`` and ``RPM_GPG_PASSPHRASE`` variables in |
| 7248 | the previous example, two optional variables related to signing exist: |
| 7249 | |
| 7250 | - *GPG_BIN:* Specifies a ``gpg`` binary/wrapper that is executed |
| 7251 | when the package is signed. |
| 7252 | |
| 7253 | - *GPG_PATH:* Specifies the ``gpg`` home directory used when the |
| 7254 | package is signed. |
| 7255 | |
| 7256 | Processing Package Feeds |
| 7257 | ~~~~~~~~~~~~~~~~~~~~~~~~ |
| 7258 | |
| 7259 | In addition to being able to sign RPM packages, you can also enable |
| 7260 | signed package feeds for IPK and RPM packages. |
| 7261 | |
| 7262 | The steps you need to take to enable signed package feed use are similar |
| 7263 | to the steps used to sign RPM packages. You must define the following in |
| 7264 | your ``local.config`` or ``distro.config`` file: |
| 7265 | :: |
| 7266 | |
| 7267 | INHERIT += "sign_package_feed" |
| 7268 | PACKAGE_FEED_GPG_NAME = "key_name" |
| 7269 | PACKAGE_FEED_GPG_PASSPHRASE_FILE = "path_to_file_containing_passphrase" |
| 7270 | |
| 7271 | For signed package feeds, the passphrase must exist in a separate file, |
| 7272 | which is pointed to by the ``PACKAGE_FEED_GPG_PASSPHRASE_FILE`` |
| 7273 | variable. Regarding security, keeping a plain text passphrase out of the |
| 7274 | configuration is more secure. |
| 7275 | |
| 7276 | Aside from the ``PACKAGE_FEED_GPG_NAME`` and |
| 7277 | ``PACKAGE_FEED_GPG_PASSPHRASE_FILE`` variables, three optional variables |
| 7278 | related to signed package feeds exist: |
| 7279 | |
| 7280 | - *GPG_BIN* Specifies a ``gpg`` binary/wrapper that is executed |
| 7281 | when the package is signed. |
| 7282 | |
| 7283 | - *GPG_PATH:* Specifies the ``gpg`` home directory used when the |
| 7284 | package is signed. |
| 7285 | |
| 7286 | - *PACKAGE_FEED_GPG_SIGNATURE_TYPE:* Specifies the type of ``gpg`` |
| 7287 | signature. This variable applies only to RPM and IPK package feeds. |
| 7288 | Allowable values for the ``PACKAGE_FEED_GPG_SIGNATURE_TYPE`` are |
| 7289 | "ASC", which is the default and specifies ascii armored, and "BIN", |
| 7290 | which specifies binary. |
| 7291 | |
| 7292 | Testing Packages With ptest |
| 7293 | --------------------------- |
| 7294 | |
| 7295 | A Package Test (ptest) runs tests against packages built by the |
| 7296 | OpenEmbedded build system on the target machine. A ptest contains at |
| 7297 | least two items: the actual test, and a shell script (``run-ptest``) |
| 7298 | that starts the test. The shell script that starts the test must not |
| 7299 | contain the actual test - the script only starts the test. On the other |
| 7300 | hand, the test can be anything from a simple shell script that runs a |
| 7301 | binary and checks the output to an elaborate system of test binaries and |
| 7302 | data files. |
| 7303 | |
| 7304 | The test generates output in the format used by Automake: |
| 7305 | :: |
| 7306 | |
| 7307 | result: testname |
| 7308 | |
| 7309 | where the result can be ``PASS``, ``FAIL``, or ``SKIP``, and |
| 7310 | the testname can be any identifying string. |
| 7311 | |
| 7312 | For a list of Yocto Project recipes that are already enabled with ptest, |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 7313 | see the :yocto_wiki:`Ptest </Ptest>` wiki page. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7314 | |
| 7315 | .. note:: |
| 7316 | |
| 7317 | A recipe is "ptest-enabled" if it inherits the |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7318 | :ref:`ptest <ref-classes-ptest>` class. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7319 | |
| 7320 | Adding ptest to Your Build |
| 7321 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 7322 | |
| 7323 | To add package testing to your build, add the |
| 7324 | :term:`DISTRO_FEATURES` and |
| 7325 | :term:`EXTRA_IMAGE_FEATURES` |
| 7326 | variables to your ``local.conf`` file, which is found in the |
| 7327 | :term:`Build Directory`: |
| 7328 | :: |
| 7329 | |
| 7330 | DISTRO_FEATURES_append = " ptest" |
| 7331 | EXTRA_IMAGE_FEATURES += "ptest-pkgs" |
| 7332 | |
| 7333 | Once your build is complete, the ptest files are installed into the |
| 7334 | ``/usr/lib/package/ptest`` directory within the image, where ``package`` |
| 7335 | is the name of the package. |
| 7336 | |
| 7337 | Running ptest |
| 7338 | ~~~~~~~~~~~~~ |
| 7339 | |
| 7340 | The ``ptest-runner`` package installs a shell script that loops through |
| 7341 | all installed ptest test suites and runs them in sequence. Consequently, |
| 7342 | you might want to add this package to your image. |
| 7343 | |
| 7344 | Getting Your Package Ready |
| 7345 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 7346 | |
| 7347 | In order to enable a recipe to run installed ptests on target hardware, |
| 7348 | you need to prepare the recipes that build the packages you want to |
| 7349 | test. Here is what you have to do for each recipe: |
| 7350 | |
| 7351 | - *Be sure the recipe inherits |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7352 | the* :ref:`ptest <ref-classes-ptest>` *class:* |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7353 | Include the following line in each recipe: |
| 7354 | :: |
| 7355 | |
| 7356 | inherit ptest |
| 7357 | |
| 7358 | - *Create run-ptest:* This script starts your test. Locate the |
| 7359 | script where you will refer to it using |
| 7360 | :term:`SRC_URI`. Here is an |
| 7361 | example that starts a test for ``dbus``: |
| 7362 | :: |
| 7363 | |
| 7364 | #!/bin/sh |
| 7365 | cd test |
| 7366 | make -k runtest-TESTS |
| 7367 | |
| 7368 | - *Ensure dependencies are met:* If the test adds build or runtime |
| 7369 | dependencies that normally do not exist for the package (such as |
| 7370 | requiring "make" to run the test suite), use the |
| 7371 | :term:`DEPENDS` and |
| 7372 | :term:`RDEPENDS` variables in |
| 7373 | your recipe in order for the package to meet the dependencies. Here |
| 7374 | is an example where the package has a runtime dependency on "make": |
| 7375 | :: |
| 7376 | |
| 7377 | RDEPENDS_${PN}-ptest += "make" |
| 7378 | |
| 7379 | - *Add a function to build the test suite:* Not many packages support |
| 7380 | cross-compilation of their test suites. Consequently, you usually |
| 7381 | need to add a cross-compilation function to the package. |
| 7382 | |
| 7383 | Many packages based on Automake compile and run the test suite by |
| 7384 | using a single command such as ``make check``. However, the host |
| 7385 | ``make check`` builds and runs on the same computer, while |
| 7386 | cross-compiling requires that the package is built on the host but |
| 7387 | executed for the target architecture (though often, as in the case |
| 7388 | for ptest, the execution occurs on the host). The built version of |
| 7389 | Automake that ships with the Yocto Project includes a patch that |
| 7390 | separates building and execution. Consequently, packages that use the |
| 7391 | unaltered, patched version of ``make check`` automatically |
| 7392 | cross-compiles. |
| 7393 | |
| 7394 | Regardless, you still must add a ``do_compile_ptest`` function to |
| 7395 | build the test suite. Add a function similar to the following to your |
| 7396 | recipe: |
| 7397 | :: |
| 7398 | |
| 7399 | do_compile_ptest() { |
| 7400 | oe_runmake buildtest-TESTS |
| 7401 | } |
| 7402 | |
| 7403 | - *Ensure special configurations are set:* If the package requires |
| 7404 | special configurations prior to compiling the test code, you must |
| 7405 | insert a ``do_configure_ptest`` function into the recipe. |
| 7406 | |
| 7407 | - *Install the test suite:* The ``ptest`` class automatically copies |
| 7408 | the file ``run-ptest`` to the target and then runs make |
| 7409 | ``install-ptest`` to run the tests. If this is not enough, you need |
| 7410 | to create a ``do_install_ptest`` function and make sure it gets |
| 7411 | called after the "make install-ptest" completes. |
| 7412 | |
| 7413 | Creating Node Package Manager (NPM) Packages |
| 7414 | -------------------------------------------- |
| 7415 | |
| 7416 | `NPM <https://en.wikipedia.org/wiki/Npm_(software)>`__ is a package |
| 7417 | manager for the JavaScript programming language. The Yocto Project |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 7418 | supports the NPM :ref:`fetcher <bitbake:bitbake-user-manual/bitbake-user-manual-fetching:fetchers>`. You can |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7419 | use this fetcher in combination with |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 7420 | :doc:`devtool </ref-manual/devtool-reference>` to create |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7421 | recipes that produce NPM packages. |
| 7422 | |
| 7423 | Two workflows exist that allow you to create NPM packages using |
| 7424 | ``devtool``: the NPM registry modules method and the NPM project code |
| 7425 | method. |
| 7426 | |
| 7427 | .. note:: |
| 7428 | |
| 7429 | While it is possible to create NPM recipes manually, using |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7430 | ``devtool`` is far simpler. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7431 | |
| 7432 | Additionally, some requirements and caveats exist. |
| 7433 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7434 | Requirements and Caveats |
| 7435 | ~~~~~~~~~~~~~~~~~~~~~~~~ |
| 7436 | |
| 7437 | You need to be aware of the following before using ``devtool`` to create |
| 7438 | NPM packages: |
| 7439 | |
| 7440 | - Of the two methods that you can use ``devtool`` to create NPM |
| 7441 | packages, the registry approach is slightly simpler. However, you |
| 7442 | might consider the project approach because you do not have to |
| 7443 | publish your module in the NPM registry |
| 7444 | (`npm-registry <https://docs.npmjs.com/misc/registry>`_), which |
| 7445 | is NPM's public registry. |
| 7446 | |
| 7447 | - Be familiar with |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 7448 | :doc:`devtool </ref-manual/devtool-reference>`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7449 | |
| 7450 | - The NPM host tools need the native ``nodejs-npm`` package, which is |
| 7451 | part of the OpenEmbedded environment. You need to get the package by |
| 7452 | cloning the https://github.com/openembedded/meta-openembedded |
| 7453 | repository out of GitHub. Be sure to add the path to your local copy |
| 7454 | to your ``bblayers.conf`` file. |
| 7455 | |
| 7456 | - ``devtool`` cannot detect native libraries in module dependencies. |
| 7457 | Consequently, you must manually add packages to your recipe. |
| 7458 | |
| 7459 | - While deploying NPM packages, ``devtool`` cannot determine which |
| 7460 | dependent packages are missing on the target (e.g. the node runtime |
| 7461 | ``nodejs``). Consequently, you need to find out what files are |
| 7462 | missing and be sure they are on the target. |
| 7463 | |
| 7464 | - Although you might not need NPM to run your node package, it is |
| 7465 | useful to have NPM on your target. The NPM package name is |
| 7466 | ``nodejs-npm``. |
| 7467 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7468 | Using the Registry Modules Method |
| 7469 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 7470 | |
| 7471 | This section presents an example that uses the ``cute-files`` module, |
| 7472 | which is a file browser web application. |
| 7473 | |
| 7474 | .. note:: |
| 7475 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7476 | You must know the ``cute-files`` module version. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7477 | |
| 7478 | The first thing you need to do is use ``devtool`` and the NPM fetcher to |
| 7479 | create the recipe: |
| 7480 | :: |
| 7481 | |
| 7482 | $ devtool add "npm://registry.npmjs.org;package=cute-files;version=1.0.2" |
| 7483 | |
| 7484 | The |
| 7485 | ``devtool add`` command runs ``recipetool create`` and uses the same |
| 7486 | fetch URI to download each dependency and capture license details where |
| 7487 | possible. The result is a generated recipe. |
| 7488 | |
| 7489 | The recipe file is fairly simple and contains every license that |
| 7490 | ``recipetool`` finds and includes the licenses in the recipe's |
| 7491 | :term:`LIC_FILES_CHKSUM` |
| 7492 | variables. You need to examine the variables and look for those with |
| 7493 | "unknown" in the :term:`LICENSE` |
| 7494 | field. You need to track down the license information for "unknown" |
| 7495 | modules and manually add the information to the recipe. |
| 7496 | |
| 7497 | ``recipetool`` creates a "shrinkwrap" file for your recipe. Shrinkwrap |
| 7498 | files capture the version of all dependent modules. Many packages do not |
| 7499 | provide shrinkwrap files. ``recipetool`` create a shrinkwrap file as it |
| 7500 | runs. |
| 7501 | |
| 7502 | .. note:: |
| 7503 | |
| 7504 | A package is created for each sub-module. This policy is the only |
| 7505 | practical way to have the licenses for all of the dependencies |
| 7506 | represented in the license manifest of the image. |
| 7507 | |
| 7508 | The ``devtool edit-recipe`` command lets you take a look at the recipe: |
| 7509 | :: |
| 7510 | |
| 7511 | $ devtool edit-recipe cute-files |
| 7512 | SUMMARY = "Turn any folder on your computer into a cute file browser, available on the local network." |
| 7513 | LICENSE = "MIT & ISC & Unknown" |
| 7514 | LIC_FILES_CHKSUM = "file://LICENSE;md5=71d98c0a1db42956787b1909c74a86ca \ |
| 7515 | file://node_modules/toidentifier/LICENSE;md5=1a261071a044d02eb6f2bb47f51a3502 \ |
| 7516 | file://node_modules/debug/LICENSE;md5=ddd815a475e7338b0be7a14d8ee35a99 \ |
| 7517 | ... |
| 7518 | SRC_URI = " \ |
| 7519 | npm://registry.npmjs.org/;package=cute-files;version=${PV} \ |
| 7520 | npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \ |
| 7521 | " |
| 7522 | S = "${WORKDIR}/npm" |
| 7523 | inherit npm LICENSE_${PN} = "MIT" |
| 7524 | LICENSE_${PN}-accepts = "MIT" |
| 7525 | LICENSE_${PN}-array-flatten = "MIT" |
| 7526 | ... |
| 7527 | LICENSE_${PN}-vary = "MIT" |
| 7528 | |
| 7529 | Three key points exist in the previous example: |
| 7530 | |
| 7531 | - :term:`SRC_URI` uses the NPM |
| 7532 | scheme so that the NPM fetcher is used. |
| 7533 | |
| 7534 | - ``recipetool`` collects all the license information. If a |
| 7535 | sub-module's license is unavailable, the sub-module's name appears in |
| 7536 | the comments. |
| 7537 | |
| 7538 | - The ``inherit npm`` statement causes the |
| 7539 | :ref:`npm <ref-classes-npm>` class to package |
| 7540 | up all the modules. |
| 7541 | |
| 7542 | You can run the following command to build the ``cute-files`` package: |
| 7543 | :: |
| 7544 | |
| 7545 | $ devtool build cute-files |
| 7546 | |
| 7547 | Remember that ``nodejs`` must be installed on |
| 7548 | the target before your package. |
| 7549 | |
| 7550 | Assuming 192.168.7.2 for the target's IP address, use the following |
| 7551 | command to deploy your package: |
| 7552 | :: |
| 7553 | |
| 7554 | $ devtool deploy-target -s cute-files root@192.168.7.2 |
| 7555 | |
| 7556 | Once the package is installed on the target, you can |
| 7557 | test the application: |
| 7558 | |
| 7559 | .. note:: |
| 7560 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7561 | Because of a known issue, you cannot simply run ``cute-files`` as you would |
| 7562 | if you had run ``npm install``. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7563 | |
| 7564 | :: |
| 7565 | |
| 7566 | $ cd /usr/lib/node_modules/cute-files |
| 7567 | $ node cute-files.js |
| 7568 | |
| 7569 | On a browser, |
| 7570 | go to ``http://192.168.7.2:3000`` and you see the following: |
| 7571 | |
| 7572 | .. image:: figures/cute-files-npm-example.png |
| 7573 | :align: center |
| 7574 | |
| 7575 | You can find the recipe in ``workspace/recipes/cute-files``. You can use |
| 7576 | the recipe in any layer you choose. |
| 7577 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7578 | Using the NPM Projects Code Method |
| 7579 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 7580 | |
| 7581 | Although it is useful to package modules already in the NPM registry, |
| 7582 | adding ``node.js`` projects under development is a more common developer |
| 7583 | use case. |
| 7584 | |
| 7585 | This section covers the NPM projects code method, which is very similar |
| 7586 | to the "registry" approach described in the previous section. In the NPM |
| 7587 | projects method, you provide ``devtool`` with an URL that points to the |
| 7588 | source files. |
| 7589 | |
| 7590 | Replicating the same example, (i.e. ``cute-files``) use the following |
| 7591 | command: |
| 7592 | :: |
| 7593 | |
| 7594 | $ devtool add https://github.com/martinaglv/cute-files.git |
| 7595 | |
| 7596 | The |
| 7597 | recipe this command generates is very similar to the recipe created in |
| 7598 | the previous section. However, the ``SRC_URI`` looks like the following: |
| 7599 | :: |
| 7600 | |
| 7601 | SRC_URI = " \ |
| 7602 | git://github.com/martinaglv/cute-files.git;protocol=https \ |
| 7603 | npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \ |
| 7604 | " |
| 7605 | |
| 7606 | In this example, |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7607 | the main module is taken from the Git repository and dependencies are |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7608 | taken from the NPM registry. Other than those differences, the recipe is |
| 7609 | basically the same between the two methods. You can build and deploy the |
| 7610 | package exactly as described in the previous section that uses the |
| 7611 | registry modules method. |
| 7612 | |
| 7613 | Adding custom metadata to packages |
| 7614 | ---------------------------------- |
| 7615 | |
| 7616 | The variable |
| 7617 | :term:`PACKAGE_ADD_METADATA` |
| 7618 | can be used to add additional metadata to packages. This is reflected in |
| 7619 | the package control/spec file. To take the ipk format for example, the |
| 7620 | CONTROL file stored inside would contain the additional metadata as |
| 7621 | additional lines. |
| 7622 | |
| 7623 | The variable can be used in multiple ways, including using suffixes to |
| 7624 | set it for a specific package type and/or package. Note that the order |
| 7625 | of precedence is the same as this list: |
| 7626 | |
| 7627 | - ``PACKAGE_ADD_METADATA_<PKGTYPE>_<PN>`` |
| 7628 | |
| 7629 | - ``PACKAGE_ADD_METADATA_<PKGTYPE>`` |
| 7630 | |
| 7631 | - ``PACKAGE_ADD_METADATA_<PN>`` |
| 7632 | |
| 7633 | - ``PACKAGE_ADD_METADATA`` |
| 7634 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7635 | `<PKGTYPE>` is a parameter and expected to be a distinct name of specific |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7636 | package type: |
| 7637 | |
| 7638 | - IPK for .ipk packages |
| 7639 | |
| 7640 | - DEB for .deb packages |
| 7641 | |
| 7642 | - RPM for .rpm packages |
| 7643 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7644 | `<PN>` is a parameter and expected to be a package name. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7645 | |
| 7646 | The variable can contain multiple [one-line] metadata fields separated |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7647 | by the literal sequence '\\n'. The separator can be redefined using the |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7648 | variable flag ``separator``. |
| 7649 | |
| 7650 | The following is an example that adds two custom fields for ipk |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7651 | packages: |
| 7652 | :: |
| 7653 | |
| 7654 | PACKAGE_ADD_METADATA_IPK = "Vendor: CustomIpk\nGroup:Applications/Spreadsheets" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7655 | |
| 7656 | Efficiently Fetching Source Files During a Build |
| 7657 | ================================================ |
| 7658 | |
| 7659 | The OpenEmbedded build system works with source files located through |
| 7660 | the :term:`SRC_URI` variable. When |
| 7661 | you build something using BitBake, a big part of the operation is |
| 7662 | locating and downloading all the source tarballs. For images, |
| 7663 | downloading all the source for various packages can take a significant |
| 7664 | amount of time. |
| 7665 | |
| 7666 | This section shows you how you can use mirrors to speed up fetching |
| 7667 | source files and how you can pre-fetch files all of which leads to more |
| 7668 | efficient use of resources and time. |
| 7669 | |
| 7670 | Setting up Effective Mirrors |
| 7671 | ---------------------------- |
| 7672 | |
| 7673 | A good deal that goes into a Yocto Project build is simply downloading |
| 7674 | all of the source tarballs. Maybe you have been working with another |
| 7675 | build system (OpenEmbedded or Angstrom) for which you have built up a |
| 7676 | sizable directory of source tarballs. Or, perhaps someone else has such |
| 7677 | a directory for which you have read access. If so, you can save time by |
| 7678 | adding statements to your configuration file so that the build process |
| 7679 | checks local directories first for existing tarballs before checking the |
| 7680 | Internet. |
| 7681 | |
| 7682 | Here is an efficient way to set it up in your ``local.conf`` file: |
| 7683 | :: |
| 7684 | |
| 7685 | SOURCE_MIRROR_URL ?= "file:///home/you/your-download-dir/" |
| 7686 | INHERIT += "own-mirrors" |
| 7687 | BB_GENERATE_MIRROR_TARBALLS = "1" |
| 7688 | # BB_NO_NETWORK = "1" |
| 7689 | |
| 7690 | In the previous example, the |
| 7691 | :term:`BB_GENERATE_MIRROR_TARBALLS` |
| 7692 | variable causes the OpenEmbedded build system to generate tarballs of |
| 7693 | the Git repositories and store them in the |
| 7694 | :term:`DL_DIR` directory. Due to |
| 7695 | performance reasons, generating and storing these tarballs is not the |
| 7696 | build system's default behavior. |
| 7697 | |
| 7698 | You can also use the |
| 7699 | :term:`PREMIRRORS` variable. For |
| 7700 | an example, see the variable's glossary entry in the Yocto Project |
| 7701 | Reference Manual. |
| 7702 | |
| 7703 | Getting Source Files and Suppressing the Build |
| 7704 | ---------------------------------------------- |
| 7705 | |
| 7706 | Another technique you can use to ready yourself for a successive string |
| 7707 | of build operations, is to pre-fetch all the source files without |
| 7708 | actually starting a build. This technique lets you work through any |
| 7709 | download issues and ultimately gathers all the source files into your |
| 7710 | download directory :ref:`structure-build-downloads`, |
| 7711 | which is located with :term:`DL_DIR`. |
| 7712 | |
| 7713 | Use the following BitBake command form to fetch all the necessary |
| 7714 | sources without starting the build: |
| 7715 | :: |
| 7716 | |
| 7717 | $ bitbake target --runall=fetch |
| 7718 | |
| 7719 | This |
| 7720 | variation of the BitBake command guarantees that you have all the |
| 7721 | sources for that BitBake target should you disconnect from the Internet |
| 7722 | and want to do the build later offline. |
| 7723 | |
| 7724 | Selecting an Initialization Manager |
| 7725 | =================================== |
| 7726 | |
| 7727 | By default, the Yocto Project uses SysVinit as the initialization |
| 7728 | manager. However, support also exists for systemd, which is a full |
| 7729 | replacement for init with parallel starting of services, reduced shell |
| 7730 | overhead and other features that are used by many distributions. |
| 7731 | |
| 7732 | Within the system, SysVinit treats system components as services. These |
| 7733 | services are maintained as shell scripts stored in the ``/etc/init.d/`` |
| 7734 | directory. Services organize into different run levels. This |
| 7735 | organization is maintained by putting links to the services in the |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7736 | ``/etc/rcN.d/`` directories, where `N/` is one of the following options: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7737 | "S", "0", "1", "2", "3", "4", "5", or "6". |
| 7738 | |
| 7739 | .. note:: |
| 7740 | |
| 7741 | Each runlevel has a dependency on the previous runlevel. This |
| 7742 | dependency allows the services to work properly. |
| 7743 | |
| 7744 | In comparison, systemd treats components as units. Using units is a |
| 7745 | broader concept as compared to using a service. A unit includes several |
| 7746 | different types of entities. Service is one of the types of entities. |
| 7747 | The runlevel concept in SysVinit corresponds to the concept of a target |
| 7748 | in systemd, where target is also a type of supported unit. |
| 7749 | |
| 7750 | In a SysVinit-based system, services load sequentially (i.e. one by one) |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7751 | during init and parallelization is not supported. With systemd, services |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7752 | start in parallel. Needless to say, the method can have an impact on |
| 7753 | system startup performance. |
| 7754 | |
| 7755 | If you want to use SysVinit, you do not have to do anything. But, if you |
| 7756 | want to use systemd, you must take some steps as described in the |
| 7757 | following sections. |
| 7758 | |
| 7759 | Using systemd Exclusively |
| 7760 | ------------------------- |
| 7761 | |
| 7762 | Set these variables in your distribution configuration file as follows: |
| 7763 | :: |
| 7764 | |
| 7765 | DISTRO_FEATURES_append = " systemd" |
| 7766 | VIRTUAL-RUNTIME_init_manager = "systemd" |
| 7767 | |
| 7768 | You can also prevent the SysVinit distribution feature from |
| 7769 | being automatically enabled as follows: |
| 7770 | :: |
| 7771 | |
| 7772 | DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit" |
| 7773 | |
| 7774 | Doing so removes any |
| 7775 | redundant SysVinit scripts. |
| 7776 | |
| 7777 | To remove initscripts from your image altogether, set this variable |
| 7778 | also: |
| 7779 | :: |
| 7780 | |
| 7781 | VIRTUAL-RUNTIME_initscripts = "" |
| 7782 | |
| 7783 | For information on the backfill variable, see |
| 7784 | :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`. |
| 7785 | |
| 7786 | Using systemd for the Main Image and Using SysVinit for the Rescue Image |
| 7787 | ------------------------------------------------------------------------ |
| 7788 | |
| 7789 | Set these variables in your distribution configuration file as follows: |
| 7790 | :: |
| 7791 | |
| 7792 | DISTRO_FEATURES_append = " systemd" |
| 7793 | VIRTUAL-RUNTIME_init_manager = "systemd" |
| 7794 | |
| 7795 | Doing so causes your main image to use the |
| 7796 | ``packagegroup-core-boot.bb`` recipe and systemd. The rescue/minimal |
| 7797 | image cannot use this package group. However, it can install SysVinit |
| 7798 | and the appropriate packages will have support for both systemd and |
| 7799 | SysVinit. |
| 7800 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7801 | Selecting a Device Manager |
| 7802 | ========================== |
| 7803 | |
| 7804 | The Yocto Project provides multiple ways to manage the device manager |
| 7805 | (``/dev``): |
| 7806 | |
| 7807 | - Persistent and Pre-Populated\ ``/dev``: For this case, the ``/dev`` |
| 7808 | directory is persistent and the required device nodes are created |
| 7809 | during the build. |
| 7810 | |
| 7811 | - Use ``devtmpfs`` with a Device Manager: For this case, the ``/dev`` |
| 7812 | directory is provided by the kernel as an in-memory file system and |
| 7813 | is automatically populated by the kernel at runtime. Additional |
| 7814 | configuration of device nodes is done in user space by a device |
| 7815 | manager like ``udev`` or ``busybox-mdev``. |
| 7816 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7817 | Using Persistent and Pre-Populated\ ``/dev`` |
| 7818 | -------------------------------------------- |
| 7819 | |
| 7820 | To use the static method for device population, you need to set the |
| 7821 | :term:`USE_DEVFS` variable to "0" |
| 7822 | as follows: |
| 7823 | :: |
| 7824 | |
| 7825 | USE_DEVFS = "0" |
| 7826 | |
| 7827 | The content of the resulting ``/dev`` directory is defined in a Device |
| 7828 | Table file. The |
| 7829 | :term:`IMAGE_DEVICE_TABLES` |
| 7830 | variable defines the Device Table to use and should be set in the |
| 7831 | machine or distro configuration file. Alternatively, you can set this |
| 7832 | variable in your ``local.conf`` configuration file. |
| 7833 | |
| 7834 | If you do not define the ``IMAGE_DEVICE_TABLES`` variable, the default |
| 7835 | ``device_table-minimal.txt`` is used: |
| 7836 | :: |
| 7837 | |
| 7838 | IMAGE_DEVICE_TABLES = "device_table-mymachine.txt" |
| 7839 | |
| 7840 | The population is handled by the ``makedevs`` utility during image |
| 7841 | creation: |
| 7842 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7843 | Using ``devtmpfs`` and a Device Manager |
| 7844 | --------------------------------------- |
| 7845 | |
| 7846 | To use the dynamic method for device population, you need to use (or be |
| 7847 | sure to set) the :term:`USE_DEVFS` |
| 7848 | variable to "1", which is the default: |
| 7849 | :: |
| 7850 | |
| 7851 | USE_DEVFS = "1" |
| 7852 | |
| 7853 | With this |
| 7854 | setting, the resulting ``/dev`` directory is populated by the kernel |
| 7855 | using ``devtmpfs``. Make sure the corresponding kernel configuration |
| 7856 | variable ``CONFIG_DEVTMPFS`` is set when building you build a Linux |
| 7857 | kernel. |
| 7858 | |
| 7859 | All devices created by ``devtmpfs`` will be owned by ``root`` and have |
| 7860 | permissions ``0600``. |
| 7861 | |
| 7862 | To have more control over the device nodes, you can use a device manager |
| 7863 | like ``udev`` or ``busybox-mdev``. You choose the device manager by |
| 7864 | defining the ``VIRTUAL-RUNTIME_dev_manager`` variable in your machine or |
| 7865 | distro configuration file. Alternatively, you can set this variable in |
| 7866 | your ``local.conf`` configuration file: |
| 7867 | :: |
| 7868 | |
| 7869 | VIRTUAL-RUNTIME_dev_manager = "udev" |
| 7870 | |
| 7871 | # Some alternative values |
| 7872 | # VIRTUAL-RUNTIME_dev_manager = "busybox-mdev" |
| 7873 | # VIRTUAL-RUNTIME_dev_manager = "systemd" |
| 7874 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7875 | Using an External SCM |
| 7876 | ===================== |
| 7877 | |
| 7878 | If you're working on a recipe that pulls from an external Source Code |
| 7879 | Manager (SCM), it is possible to have the OpenEmbedded build system |
| 7880 | notice new recipe changes added to the SCM and then build the resulting |
| 7881 | packages that depend on the new recipes by using the latest versions. |
| 7882 | This only works for SCMs from which it is possible to get a sensible |
| 7883 | revision number for changes. Currently, you can do this with Apache |
| 7884 | Subversion (SVN), Git, and Bazaar (BZR) repositories. |
| 7885 | |
| 7886 | To enable this behavior, the :term:`PV` of |
| 7887 | the recipe needs to reference |
| 7888 | :term:`SRCPV`. Here is an example: |
| 7889 | :: |
| 7890 | |
| 7891 | PV = "1.2.3+git${SRCPV}" |
| 7892 | |
| 7893 | Then, you can add the following to your |
| 7894 | ``local.conf``: |
| 7895 | :: |
| 7896 | |
| 7897 | SRCREV_pn-PN = "${AUTOREV}" |
| 7898 | |
| 7899 | :term:`PN` is the name of the recipe for |
| 7900 | which you want to enable automatic source revision updating. |
| 7901 | |
| 7902 | If you do not want to update your local configuration file, you can add |
| 7903 | the following directly to the recipe to finish enabling the feature: |
| 7904 | :: |
| 7905 | |
| 7906 | SRCREV = "${AUTOREV}" |
| 7907 | |
| 7908 | The Yocto Project provides a distribution named ``poky-bleeding``, whose |
| 7909 | configuration file contains the line: |
| 7910 | :: |
| 7911 | |
| 7912 | require conf/distro/include/poky-floating-revisions.inc |
| 7913 | |
| 7914 | This line pulls in the |
| 7915 | listed include file that contains numerous lines of exactly that form: |
| 7916 | :: |
| 7917 | |
| 7918 | #SRCREV_pn-opkg-native ?= "${AUTOREV}" |
| 7919 | #SRCREV_pn-opkg-sdk ?= "${AUTOREV}" |
| 7920 | #SRCREV_pn-opkg ?= "${AUTOREV}" |
| 7921 | #SRCREV_pn-opkg-utils-native ?= "${AUTOREV}" |
| 7922 | #SRCREV_pn-opkg-utils ?= "${AUTOREV}" |
| 7923 | SRCREV_pn-gconf-dbus ?= "${AUTOREV}" |
| 7924 | SRCREV_pn-matchbox-common ?= "${AUTOREV}" |
| 7925 | SRCREV_pn-matchbox-config-gtk ?= "${AUTOREV}" |
| 7926 | SRCREV_pn-matchbox-desktop ?= "${AUTOREV}" |
| 7927 | SRCREV_pn-matchbox-keyboard ?= "${AUTOREV}" |
| 7928 | SRCREV_pn-matchbox-panel-2 ?= "${AUTOREV}" |
| 7929 | SRCREV_pn-matchbox-themes-extra ?= "${AUTOREV}" |
| 7930 | SRCREV_pn-matchbox-terminal ?= "${AUTOREV}" |
| 7931 | SRCREV_pn-matchbox-wm ?= "${AUTOREV}" |
| 7932 | SRCREV_pn-settings-daemon ?= "${AUTOREV}" |
| 7933 | SRCREV_pn-screenshot ?= "${AUTOREV}" |
| 7934 | . . . |
| 7935 | |
| 7936 | These lines allow you to |
| 7937 | experiment with building a distribution that tracks the latest |
| 7938 | development source for numerous packages. |
| 7939 | |
| 7940 | .. note:: |
| 7941 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7942 | The ``poky-bleeding`` distribution is not tested on a regular basis. Keep |
| 7943 | this in mind if you use it. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7944 | |
| 7945 | Creating a Read-Only Root Filesystem |
| 7946 | ==================================== |
| 7947 | |
| 7948 | Suppose, for security reasons, you need to disable your target device's |
| 7949 | root filesystem's write permissions (i.e. you need a read-only root |
| 7950 | filesystem). Or, perhaps you are running the device's operating system |
| 7951 | from a read-only storage device. For either case, you can customize your |
| 7952 | image for that behavior. |
| 7953 | |
| 7954 | .. note:: |
| 7955 | |
| 7956 | Supporting a read-only root filesystem requires that the system and |
| 7957 | applications do not try to write to the root filesystem. You must |
| 7958 | configure all parts of the target system to write elsewhere, or to |
| 7959 | gracefully fail in the event of attempting to write to the root |
| 7960 | filesystem. |
| 7961 | |
| 7962 | Creating the Root Filesystem |
| 7963 | ---------------------------- |
| 7964 | |
| 7965 | To create the read-only root filesystem, simply add the |
| 7966 | "read-only-rootfs" feature to your image, normally in one of two ways. |
| 7967 | The first way is to add the "read-only-rootfs" image feature in the |
| 7968 | image's recipe file via the ``IMAGE_FEATURES`` variable: |
| 7969 | :: |
| 7970 | |
| 7971 | IMAGE_FEATURES += "read-only-rootfs" |
| 7972 | |
| 7973 | As an alternative, you can add the same feature |
| 7974 | from within your build directory's ``local.conf`` file with the |
| 7975 | associated ``EXTRA_IMAGE_FEATURES`` variable, as in: |
| 7976 | :: |
| 7977 | |
| 7978 | EXTRA_IMAGE_FEATURES = "read-only-rootfs" |
| 7979 | |
| 7980 | For more information on how to use these variables, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 7981 | ":ref:`dev-manual/common-tasks:Customizing Images Using Custom \`\`IMAGE_FEATURES\`\` and \`\`EXTRA_IMAGE_FEATURES\`\``" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7982 | section. For information on the variables, see |
| 7983 | :term:`IMAGE_FEATURES` and |
| 7984 | :term:`EXTRA_IMAGE_FEATURES`. |
| 7985 | |
| 7986 | Post-Installation Scripts and Read-Only Root Filesystem |
| 7987 | ------------------------------------------------------- |
| 7988 | |
| 7989 | It is very important that you make sure all post-Installation |
| 7990 | (``pkg_postinst``) scripts for packages that are installed into the |
| 7991 | image can be run at the time when the root filesystem is created during |
| 7992 | the build on the host system. These scripts cannot attempt to run during |
| 7993 | first-boot on the target device. With the "read-only-rootfs" feature |
| 7994 | enabled, the build system checks during root filesystem creation to make |
| 7995 | sure all post-installation scripts succeed. If any of these scripts |
| 7996 | still need to be run after the root filesystem is created, the build |
| 7997 | immediately fails. These build-time checks ensure that the build fails |
| 7998 | rather than the target device fails later during its initial boot |
| 7999 | operation. |
| 8000 | |
| 8001 | Most of the common post-installation scripts generated by the build |
| 8002 | system for the out-of-the-box Yocto Project are engineered so that they |
| 8003 | can run during root filesystem creation (e.g. post-installation scripts |
| 8004 | for caching fonts). However, if you create and add custom scripts, you |
| 8005 | need to be sure they can be run during this file system creation. |
| 8006 | |
| 8007 | Here are some common problems that prevent post-installation scripts |
| 8008 | from running during root filesystem creation: |
| 8009 | |
| 8010 | - *Not using $D in front of absolute paths:* The build system defines |
| 8011 | ``$``\ :term:`D` when the root |
| 8012 | filesystem is created. Furthermore, ``$D`` is blank when the script |
| 8013 | is run on the target device. This implies two purposes for ``$D``: |
| 8014 | ensuring paths are valid in both the host and target environments, |
| 8015 | and checking to determine which environment is being used as a method |
| 8016 | for taking appropriate actions. |
| 8017 | |
| 8018 | - *Attempting to run processes that are specific to or dependent on the |
| 8019 | target architecture:* You can work around these attempts by using |
| 8020 | native tools, which run on the host system, to accomplish the same |
| 8021 | tasks, or by alternatively running the processes under QEMU, which |
| 8022 | has the ``qemu_run_binary`` function. For more information, see the |
| 8023 | :ref:`qemu <ref-classes-qemu>` class. |
| 8024 | |
| 8025 | Areas With Write Access |
| 8026 | ----------------------- |
| 8027 | |
| 8028 | With the "read-only-rootfs" feature enabled, any attempt by the target |
| 8029 | to write to the root filesystem at runtime fails. Consequently, you must |
| 8030 | make sure that you configure processes and applications that attempt |
| 8031 | these types of writes do so to directories with write access (e.g. |
| 8032 | ``/tmp`` or ``/var/run``). |
| 8033 | |
| 8034 | Maintaining Build Output Quality |
| 8035 | ================================ |
| 8036 | |
| 8037 | Many factors can influence the quality of a build. For example, if you |
| 8038 | upgrade a recipe to use a new version of an upstream software package or |
| 8039 | you experiment with some new configuration options, subtle changes can |
| 8040 | occur that you might not detect until later. Consider the case where |
| 8041 | your recipe is using a newer version of an upstream package. In this |
| 8042 | case, a new version of a piece of software might introduce an optional |
| 8043 | dependency on another library, which is auto-detected. If that library |
| 8044 | has already been built when the software is building, the software will |
| 8045 | link to the built library and that library will be pulled into your |
| 8046 | image along with the new software even if you did not want the library. |
| 8047 | |
| 8048 | The :ref:`buildhistory <ref-classes-buildhistory>` |
| 8049 | class exists to help you maintain the quality of your build output. You |
| 8050 | can use the class to highlight unexpected and possibly unwanted changes |
| 8051 | in the build output. When you enable build history, it records |
| 8052 | information about the contents of each package and image and then |
| 8053 | commits that information to a local Git repository where you can examine |
| 8054 | the information. |
| 8055 | |
| 8056 | The remainder of this section describes the following: |
| 8057 | |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 8058 | - :ref:`How you can enable and disable build history <dev-manual/common-tasks:enabling and disabling build history>` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8059 | |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 8060 | - :ref:`How to understand what the build history contains <dev-manual/common-tasks:understanding what the build history contains>` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8061 | |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 8062 | - :ref:`How to limit the information used for build history <dev-manual/common-tasks:using build history to gather image information only>` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8063 | |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 8064 | - :ref:`How to examine the build history from both a command-line and web interface <dev-manual/common-tasks:examining build history information>` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8065 | |
| 8066 | Enabling and Disabling Build History |
| 8067 | ------------------------------------ |
| 8068 | |
| 8069 | Build history is disabled by default. To enable it, add the following |
| 8070 | ``INHERIT`` statement and set the |
| 8071 | :term:`BUILDHISTORY_COMMIT` |
| 8072 | variable to "1" at the end of your ``conf/local.conf`` file found in the |
| 8073 | :term:`Build Directory`: |
| 8074 | :: |
| 8075 | |
| 8076 | INHERIT += "buildhistory" |
| 8077 | BUILDHISTORY_COMMIT = "1" |
| 8078 | |
| 8079 | Enabling build history as |
| 8080 | previously described causes the OpenEmbedded build system to collect |
| 8081 | build output information and commit it as a single commit to a local |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 8082 | :ref:`overview-manual/development-environment:git` repository. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8083 | |
| 8084 | .. note:: |
| 8085 | |
| 8086 | Enabling build history increases your build times slightly, |
| 8087 | particularly for images, and increases the amount of disk space used |
| 8088 | during the build. |
| 8089 | |
| 8090 | You can disable build history by removing the previous statements from |
| 8091 | your ``conf/local.conf`` file. |
| 8092 | |
| 8093 | Understanding What the Build History Contains |
| 8094 | --------------------------------------------- |
| 8095 | |
| 8096 | Build history information is kept in |
| 8097 | ``${``\ :term:`TOPDIR`\ ``}/buildhistory`` |
| 8098 | in the Build Directory as defined by the |
| 8099 | :term:`BUILDHISTORY_DIR` |
| 8100 | variable. The following is an example abbreviated listing: |
| 8101 | |
| 8102 | .. image:: figures/buildhistory.png |
| 8103 | :align: center |
| 8104 | |
| 8105 | At the top level, a ``metadata-revs`` file exists that lists the |
| 8106 | revisions of the repositories for the enabled layers when the build was |
| 8107 | produced. The rest of the data splits into separate ``packages``, |
| 8108 | ``images`` and ``sdk`` directories, the contents of which are described |
| 8109 | as follows. |
| 8110 | |
| 8111 | Build History Package Information |
| 8112 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 8113 | |
| 8114 | The history for each package contains a text file that has name-value |
| 8115 | pairs with information about the package. For example, |
| 8116 | ``buildhistory/packages/i586-poky-linux/busybox/busybox/latest`` |
| 8117 | contains the following: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8118 | |
| 8119 | .. code-block:: none |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8120 | |
| 8121 | PV = 1.22.1 |
| 8122 | PR = r32 |
| 8123 | RPROVIDES = |
| 8124 | RDEPENDS = glibc (>= 2.20) update-alternatives-opkg |
| 8125 | RRECOMMENDS = busybox-syslog busybox-udhcpc update-rc.d |
| 8126 | PKGSIZE = 540168 |
| 8127 | FILES = /usr/bin/* /usr/sbin/* /usr/lib/busybox/* /usr/lib/lib*.so.* \ |
| 8128 | /etc /com /var /bin/* /sbin/* /lib/*.so.* /lib/udev/rules.d \ |
| 8129 | /usr/lib/udev/rules.d /usr/share/busybox /usr/lib/busybox/* \ |
| 8130 | /usr/share/pixmaps /usr/share/applications /usr/share/idl \ |
| 8131 | /usr/share/omf /usr/share/sounds /usr/lib/bonobo/servers |
| 8132 | FILELIST = /bin/busybox /bin/busybox.nosuid /bin/busybox.suid /bin/sh \ |
| 8133 | /etc/busybox.links.nosuid /etc/busybox.links.suid |
| 8134 | |
| 8135 | Most of these |
| 8136 | name-value pairs correspond to variables used to produce the package. |
| 8137 | The exceptions are ``FILELIST``, which is the actual list of files in |
| 8138 | the package, and ``PKGSIZE``, which is the total size of files in the |
| 8139 | package in bytes. |
| 8140 | |
| 8141 | A file also exists that corresponds to the recipe from which the package |
| 8142 | came (e.g. ``buildhistory/packages/i586-poky-linux/busybox/latest``): |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8143 | |
| 8144 | .. code-block:: none |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8145 | |
| 8146 | PV = 1.22.1 |
| 8147 | PR = r32 |
| 8148 | DEPENDS = initscripts kern-tools-native update-rc.d-native \ |
| 8149 | virtual/i586-poky-linux-compilerlibs virtual/i586-poky-linux-gcc \ |
| 8150 | virtual/libc virtual/update-alternatives |
| 8151 | PACKAGES = busybox-ptest busybox-httpd busybox-udhcpd busybox-udhcpc \ |
| 8152 | busybox-syslog busybox-mdev busybox-hwclock busybox-dbg \ |
| 8153 | busybox-staticdev busybox-dev busybox-doc busybox-locale busybox |
| 8154 | |
| 8155 | Finally, for those recipes fetched from a version control system (e.g., |
| 8156 | Git), a file exists that lists source revisions that are specified in |
| 8157 | the recipe and lists the actual revisions used during the build. Listed |
| 8158 | and actual revisions might differ when |
| 8159 | :term:`SRCREV` is set to |
| 8160 | ${:term:`AUTOREV`}. Here is an |
| 8161 | example assuming |
| 8162 | ``buildhistory/packages/qemux86-poky-linux/linux-yocto/latest_srcrev``): |
| 8163 | :: |
| 8164 | |
| 8165 | # SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1" |
| 8166 | SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1" |
| 8167 | # SRCREV_meta = "a227f20eff056e511d504b2e490f3774ab260d6f" |
| 8168 | SRCREV_meta ="a227f20eff056e511d504b2e490f3774ab260d6f" |
| 8169 | |
| 8170 | You can use the |
| 8171 | ``buildhistory-collect-srcrevs`` command with the ``-a`` option to |
| 8172 | collect the stored ``SRCREV`` values from build history and report them |
| 8173 | in a format suitable for use in global configuration (e.g., |
| 8174 | ``local.conf`` or a distro include file) to override floating |
| 8175 | ``AUTOREV`` values to a fixed set of revisions. Here is some example |
| 8176 | output from this command: |
| 8177 | :: |
| 8178 | |
| 8179 | $ buildhistory-collect-srcrevs -a |
| 8180 | # i586-poky-linux |
| 8181 | SRCREV_pn-glibc = "b8079dd0d360648e4e8de48656c5c38972621072" |
| 8182 | SRCREV_pn-glibc-initial = "b8079dd0d360648e4e8de48656c5c38972621072" |
| 8183 | SRCREV_pn-opkg-utils = "53274f087565fd45d8452c5367997ba6a682a37a" |
| 8184 | SRCREV_pn-kmod = "fd56638aed3fe147015bfa10ed4a5f7491303cb4" |
| 8185 | # x86_64-linux |
| 8186 | SRCREV_pn-gtk-doc-stub-native = "1dea266593edb766d6d898c79451ef193eb17cfa" |
| 8187 | SRCREV_pn-dtc-native = "65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf" |
| 8188 | SRCREV_pn-update-rc.d-native = "eca680ddf28d024954895f59a241a622dd575c11" |
| 8189 | SRCREV_glibc_pn-cross-localedef-native = "b8079dd0d360648e4e8de48656c5c38972621072" |
| 8190 | SRCREV_localedef_pn-cross-localedef-native = "c833367348d39dad7ba018990bfdaffaec8e9ed3" |
| 8191 | SRCREV_pn-prelink-native = "faa069deec99bf61418d0bab831c83d7c1b797ca" |
| 8192 | SRCREV_pn-opkg-utils-native = "53274f087565fd45d8452c5367997ba6a682a37a" |
| 8193 | SRCREV_pn-kern-tools-native = "23345b8846fe4bd167efdf1bd8a1224b2ba9a5ff" |
| 8194 | SRCREV_pn-kmod-native = "fd56638aed3fe147015bfa10ed4a5f7491303cb4" |
| 8195 | # qemux86-poky-linux |
| 8196 | SRCREV_machine_pn-linux-yocto = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1" |
| 8197 | SRCREV_meta_pn-linux-yocto = "a227f20eff056e511d504b2e490f3774ab260d6f" |
| 8198 | # all-poky-linux |
| 8199 | SRCREV_pn-update-rc.d = "eca680ddf28d024954895f59a241a622dd575c11" |
| 8200 | |
| 8201 | .. note:: |
| 8202 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8203 | Here are some notes on using the ``buildhistory-collect-srcrevs`` command: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8204 | |
| 8205 | - By default, only values where the ``SRCREV`` was not hardcoded |
| 8206 | (usually when ``AUTOREV`` is used) are reported. Use the ``-a`` |
| 8207 | option to see all ``SRCREV`` values. |
| 8208 | |
| 8209 | - The output statements might not have any effect if overrides are |
| 8210 | applied elsewhere in the build system configuration. Use the |
| 8211 | ``-f`` option to add the ``forcevariable`` override to each output |
| 8212 | line if you need to work around this restriction. |
| 8213 | |
| 8214 | - The script does apply special handling when building for multiple |
| 8215 | machines. However, the script does place a comment before each set |
| 8216 | of values that specifies which triplet to which they belong as |
| 8217 | previously shown (e.g., ``i586-poky-linux``). |
| 8218 | |
| 8219 | Build History Image Information |
| 8220 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 8221 | |
| 8222 | The files produced for each image are as follows: |
| 8223 | |
| 8224 | - ``image-files:`` A directory containing selected files from the root |
| 8225 | filesystem. The files are defined by |
| 8226 | :term:`BUILDHISTORY_IMAGE_FILES`. |
| 8227 | |
| 8228 | - ``build-id.txt:`` Human-readable information about the build |
| 8229 | configuration and metadata source revisions. This file contains the |
| 8230 | full build header as printed by BitBake. |
| 8231 | |
| 8232 | - ``*.dot:`` Dependency graphs for the image that are compatible with |
| 8233 | ``graphviz``. |
| 8234 | |
| 8235 | - ``files-in-image.txt:`` A list of files in the image with |
| 8236 | permissions, owner, group, size, and symlink information. |
| 8237 | |
| 8238 | - ``image-info.txt:`` A text file containing name-value pairs with |
| 8239 | information about the image. See the following listing example for |
| 8240 | more information. |
| 8241 | |
| 8242 | - ``installed-package-names.txt:`` A list of installed packages by name |
| 8243 | only. |
| 8244 | |
| 8245 | - ``installed-package-sizes.txt:`` A list of installed packages ordered |
| 8246 | by size. |
| 8247 | |
| 8248 | - ``installed-packages.txt:`` A list of installed packages with full |
| 8249 | package filenames. |
| 8250 | |
| 8251 | .. note:: |
| 8252 | |
| 8253 | Installed package information is able to be gathered and produced |
| 8254 | even if package management is disabled for the final image. |
| 8255 | |
| 8256 | Here is an example of ``image-info.txt``: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8257 | |
| 8258 | .. code-block:: none |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8259 | |
| 8260 | DISTRO = poky |
| 8261 | DISTRO_VERSION = 1.7 |
| 8262 | USER_CLASSES = buildstats image-mklibs image-prelink |
| 8263 | IMAGE_CLASSES = image_types |
| 8264 | IMAGE_FEATURES = debug-tweaks |
| 8265 | IMAGE_LINGUAS = |
| 8266 | IMAGE_INSTALL = packagegroup-core-boot run-postinsts |
| 8267 | BAD_RECOMMENDATIONS = |
| 8268 | NO_RECOMMENDATIONS = |
| 8269 | PACKAGE_EXCLUDE = |
| 8270 | ROOTFS_POSTPROCESS_COMMAND = write_package_manifest; license_create_manifest; \ |
| 8271 | write_image_manifest ; buildhistory_list_installed_image ; \ |
| 8272 | buildhistory_get_image_installed ; ssh_allow_empty_password; \ |
| 8273 | postinst_enable_logging; rootfs_update_timestamp ; ssh_disable_dns_lookup ; |
| 8274 | IMAGE_POSTPROCESS_COMMAND = buildhistory_get_imageinfo ; |
| 8275 | IMAGESIZE = 6900 |
| 8276 | |
| 8277 | Other than ``IMAGESIZE``, |
| 8278 | which is the total size of the files in the image in Kbytes, the |
| 8279 | name-value pairs are variables that may have influenced the content of |
| 8280 | the image. This information is often useful when you are trying to |
| 8281 | determine why a change in the package or file listings has occurred. |
| 8282 | |
| 8283 | Using Build History to Gather Image Information Only |
| 8284 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 8285 | |
| 8286 | As you can see, build history produces image information, including |
| 8287 | dependency graphs, so you can see why something was pulled into the |
| 8288 | image. If you are just interested in this information and not interested |
| 8289 | in collecting specific package or SDK information, you can enable |
| 8290 | writing only image information without any history by adding the |
| 8291 | following to your ``conf/local.conf`` file found in the |
| 8292 | :term:`Build Directory`: |
| 8293 | :: |
| 8294 | |
| 8295 | INHERIT += "buildhistory" |
| 8296 | BUILDHISTORY_COMMIT = "0" |
| 8297 | BUILDHISTORY_FEATURES = "image" |
| 8298 | |
| 8299 | Here, you set the |
| 8300 | :term:`BUILDHISTORY_FEATURES` |
| 8301 | variable to use the image feature only. |
| 8302 | |
| 8303 | Build History SDK Information |
| 8304 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 8305 | |
| 8306 | Build history collects similar information on the contents of SDKs (e.g. |
| 8307 | ``bitbake -c populate_sdk imagename``) as compared to information it |
| 8308 | collects for images. Furthermore, this information differs depending on |
| 8309 | whether an extensible or standard SDK is being produced. |
| 8310 | |
| 8311 | The following list shows the files produced for SDKs: |
| 8312 | |
| 8313 | - ``files-in-sdk.txt:`` A list of files in the SDK with permissions, |
| 8314 | owner, group, size, and symlink information. This list includes both |
| 8315 | the host and target parts of the SDK. |
| 8316 | |
| 8317 | - ``sdk-info.txt:`` A text file containing name-value pairs with |
| 8318 | information about the SDK. See the following listing example for more |
| 8319 | information. |
| 8320 | |
| 8321 | - ``sstate-task-sizes.txt:`` A text file containing name-value pairs |
| 8322 | with information about task group sizes (e.g. ``do_populate_sysroot`` |
| 8323 | tasks have a total size). The ``sstate-task-sizes.txt`` file exists |
| 8324 | only when an extensible SDK is created. |
| 8325 | |
| 8326 | - ``sstate-package-sizes.txt:`` A text file containing name-value pairs |
| 8327 | with information for the shared-state packages and sizes in the SDK. |
| 8328 | The ``sstate-package-sizes.txt`` file exists only when an extensible |
| 8329 | SDK is created. |
| 8330 | |
| 8331 | - ``sdk-files:`` A folder that contains copies of the files mentioned |
| 8332 | in ``BUILDHISTORY_SDK_FILES`` if the files are present in the output. |
| 8333 | Additionally, the default value of ``BUILDHISTORY_SDK_FILES`` is |
| 8334 | specific to the extensible SDK although you can set it differently if |
| 8335 | you would like to pull in specific files from the standard SDK. |
| 8336 | |
| 8337 | The default files are ``conf/local.conf``, ``conf/bblayers.conf``, |
| 8338 | ``conf/auto.conf``, ``conf/locked-sigs.inc``, and |
| 8339 | ``conf/devtool.conf``. Thus, for an extensible SDK, these files get |
| 8340 | copied into the ``sdk-files`` directory. |
| 8341 | |
| 8342 | - The following information appears under each of the ``host`` and |
| 8343 | ``target`` directories for the portions of the SDK that run on the |
| 8344 | host and on the target, respectively: |
| 8345 | |
| 8346 | .. note:: |
| 8347 | |
| 8348 | The following files for the most part are empty when producing an |
| 8349 | extensible SDK because this type of SDK is not constructed from |
| 8350 | packages as is the standard SDK. |
| 8351 | |
| 8352 | - ``depends.dot:`` Dependency graph for the SDK that is compatible |
| 8353 | with ``graphviz``. |
| 8354 | |
| 8355 | - ``installed-package-names.txt:`` A list of installed packages by |
| 8356 | name only. |
| 8357 | |
| 8358 | - ``installed-package-sizes.txt:`` A list of installed packages |
| 8359 | ordered by size. |
| 8360 | |
| 8361 | - ``installed-packages.txt:`` A list of installed packages with full |
| 8362 | package filenames. |
| 8363 | |
| 8364 | Here is an example of ``sdk-info.txt``: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8365 | |
| 8366 | .. code-block:: none |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8367 | |
| 8368 | DISTRO = poky |
| 8369 | DISTRO_VERSION = 1.3+snapshot-20130327 |
| 8370 | SDK_NAME = poky-glibc-i686-arm |
| 8371 | SDK_VERSION = 1.3+snapshot |
| 8372 | SDKMACHINE = |
| 8373 | SDKIMAGE_FEATURES = dev-pkgs dbg-pkgs |
| 8374 | BAD_RECOMMENDATIONS = |
| 8375 | SDKSIZE = 352712 |
| 8376 | |
| 8377 | Other than ``SDKSIZE``, which is |
| 8378 | the total size of the files in the SDK in Kbytes, the name-value pairs |
| 8379 | are variables that might have influenced the content of the SDK. This |
| 8380 | information is often useful when you are trying to determine why a |
| 8381 | change in the package or file listings has occurred. |
| 8382 | |
| 8383 | Examining Build History Information |
| 8384 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 8385 | |
| 8386 | You can examine build history output from the command line or from a web |
| 8387 | interface. |
| 8388 | |
| 8389 | To see any changes that have occurred (assuming you have |
| 8390 | :term:`BUILDHISTORY_COMMIT` = "1"), |
| 8391 | you can simply use any Git command that allows you to view the history |
| 8392 | of a repository. Here is one method: |
| 8393 | :: |
| 8394 | |
| 8395 | $ git log -p |
| 8396 | |
| 8397 | You need to realize, |
| 8398 | however, that this method does show changes that are not significant |
| 8399 | (e.g. a package's size changing by a few bytes). |
| 8400 | |
| 8401 | A command-line tool called ``buildhistory-diff`` does exist, though, |
| 8402 | that queries the Git repository and prints just the differences that |
| 8403 | might be significant in human-readable form. Here is an example: |
| 8404 | :: |
| 8405 | |
| 8406 | $ ~/poky/poky/scripts/buildhistory-diff . HEAD^ |
| 8407 | Changes to images/qemux86_64/glibc/core-image-minimal (files-in-image.txt): |
| 8408 | /etc/anotherpkg.conf was added |
| 8409 | /sbin/anotherpkg was added |
| 8410 | * (installed-package-names.txt): |
| 8411 | * anotherpkg was added |
| 8412 | Changes to images/qemux86_64/glibc/core-image-minimal (installed-package-names.txt): |
| 8413 | anotherpkg was added |
| 8414 | packages/qemux86_64-poky-linux/v86d: PACKAGES: added "v86d-extras" |
| 8415 | * PR changed from "r0" to "r1" |
| 8416 | * PV changed from "0.1.10" to "0.1.12" |
| 8417 | packages/qemux86_64-poky-linux/v86d/v86d: PKGSIZE changed from 110579 to 144381 (+30%) |
| 8418 | * PR changed from "r0" to "r1" |
| 8419 | * PV changed from "0.1.10" to "0.1.12" |
| 8420 | |
| 8421 | .. note:: |
| 8422 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8423 | The ``buildhistory-diff`` tool requires the ``GitPython`` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8424 | package. Be sure to install it using Pip3 as follows: |
| 8425 | :: |
| 8426 | |
| 8427 | $ pip3 install GitPython --user |
| 8428 | |
| 8429 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8430 | Alternatively, you can install ``python3-git`` using the appropriate |
| 8431 | distribution package manager (e.g. ``apt-get``, ``dnf``, or ``zipper``). |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8432 | |
| 8433 | To see changes to the build history using a web interface, follow the |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8434 | instruction in the ``README`` file |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 8435 | :yocto_git:`here </buildhistory-web/>`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8436 | |
| 8437 | Here is a sample screenshot of the interface: |
| 8438 | |
| 8439 | .. image:: figures/buildhistory-web.png |
| 8440 | :align: center |
| 8441 | |
| 8442 | Performing Automated Runtime Testing |
| 8443 | ==================================== |
| 8444 | |
| 8445 | The OpenEmbedded build system makes available a series of automated |
| 8446 | tests for images to verify runtime functionality. You can run these |
| 8447 | tests on either QEMU or actual target hardware. Tests are written in |
| 8448 | Python making use of the ``unittest`` module, and the majority of them |
| 8449 | run commands on the target system over SSH. This section describes how |
| 8450 | you set up the environment to use these tests, run available tests, and |
| 8451 | write and add your own tests. |
| 8452 | |
| 8453 | For information on the test and QA infrastructure available within the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 8454 | Yocto Project, see the ":ref:`ref-manual/release-process:testing and quality assurance`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8455 | section in the Yocto Project Reference Manual. |
| 8456 | |
| 8457 | Enabling Tests |
| 8458 | -------------- |
| 8459 | |
| 8460 | Depending on whether you are planning to run tests using QEMU or on the |
| 8461 | hardware, you have to take different steps to enable the tests. See the |
| 8462 | following subsections for information on how to enable both types of |
| 8463 | tests. |
| 8464 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8465 | Enabling Runtime Tests on QEMU |
| 8466 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 8467 | |
| 8468 | In order to run tests, you need to do the following: |
| 8469 | |
| 8470 | - *Set up to avoid interaction with sudo for networking:* To |
| 8471 | accomplish this, you must do one of the following: |
| 8472 | |
| 8473 | - Add ``NOPASSWD`` for your user in ``/etc/sudoers`` either for all |
| 8474 | commands or just for ``runqemu-ifup``. You must provide the full |
| 8475 | path as that can change if you are using multiple clones of the |
| 8476 | source repository. |
| 8477 | |
| 8478 | .. note:: |
| 8479 | |
| 8480 | On some distributions, you also need to comment out "Defaults |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8481 | requiretty" in ``/etc/sudoers``. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8482 | |
| 8483 | - Manually configure a tap interface for your system. |
| 8484 | |
| 8485 | - Run as root the script in ``scripts/runqemu-gen-tapdevs``, which |
| 8486 | should generate a list of tap devices. This is the option |
| 8487 | typically chosen for Autobuilder-type environments. |
| 8488 | |
| 8489 | .. note:: |
| 8490 | |
| 8491 | - Be sure to use an absolute path when calling this script |
| 8492 | with sudo. |
| 8493 | |
| 8494 | - The package recipe ``qemu-helper-native`` is required to run |
| 8495 | this script. Build the package using the following command: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8496 | :: |
| 8497 | |
| 8498 | $ bitbake qemu-helper-native |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8499 | |
| 8500 | - *Set the DISPLAY variable:* You need to set this variable so that |
| 8501 | you have an X server available (e.g. start ``vncserver`` for a |
| 8502 | headless machine). |
| 8503 | |
| 8504 | - *Be sure your host's firewall accepts incoming connections from |
| 8505 | 192.168.7.0/24:* Some of the tests (in particular DNF tests) start an |
| 8506 | HTTP server on a random high number port, which is used to serve |
| 8507 | files to the target. The DNF module serves |
| 8508 | ``${WORKDIR}/oe-rootfs-repo`` so it can run DNF channel commands. |
| 8509 | That means your host's firewall must accept incoming connections from |
| 8510 | 192.168.7.0/24, which is the default IP range used for tap devices by |
| 8511 | ``runqemu``. |
| 8512 | |
| 8513 | - *Be sure your host has the correct packages installed:* Depending |
| 8514 | your host's distribution, you need to have the following packages |
| 8515 | installed: |
| 8516 | |
| 8517 | - Ubuntu and Debian: ``sysstat`` and ``iproute2`` |
| 8518 | |
| 8519 | - OpenSUSE: ``sysstat`` and ``iproute2`` |
| 8520 | |
| 8521 | - Fedora: ``sysstat`` and ``iproute`` |
| 8522 | |
| 8523 | - CentOS: ``sysstat`` and ``iproute`` |
| 8524 | |
| 8525 | Once you start running the tests, the following happens: |
| 8526 | |
| 8527 | 1. A copy of the root filesystem is written to ``${WORKDIR}/testimage``. |
| 8528 | |
| 8529 | 2. The image is booted under QEMU using the standard ``runqemu`` script. |
| 8530 | |
| 8531 | 3. A default timeout of 500 seconds occurs to allow for the boot process |
| 8532 | to reach the login prompt. You can change the timeout period by |
| 8533 | setting |
| 8534 | :term:`TEST_QEMUBOOT_TIMEOUT` |
| 8535 | in the ``local.conf`` file. |
| 8536 | |
| 8537 | 4. Once the boot process is reached and the login prompt appears, the |
| 8538 | tests run. The full boot log is written to |
| 8539 | ``${WORKDIR}/testimage/qemu_boot_log``. |
| 8540 | |
| 8541 | 5. Each test module loads in the order found in ``TEST_SUITES``. You can |
| 8542 | find the full output of the commands run over SSH in |
| 8543 | ``${WORKDIR}/testimgage/ssh_target_log``. |
| 8544 | |
| 8545 | 6. If no failures occur, the task running the tests ends successfully. |
| 8546 | You can find the output from the ``unittest`` in the task log at |
| 8547 | ``${WORKDIR}/temp/log.do_testimage``. |
| 8548 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8549 | Enabling Runtime Tests on Hardware |
| 8550 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 8551 | |
| 8552 | The OpenEmbedded build system can run tests on real hardware, and for |
| 8553 | certain devices it can also deploy the image to be tested onto the |
| 8554 | device beforehand. |
| 8555 | |
| 8556 | For automated deployment, a "master image" is installed onto the |
| 8557 | hardware once as part of setup. Then, each time tests are to be run, the |
| 8558 | following occurs: |
| 8559 | |
| 8560 | 1. The master image is booted into and used to write the image to be |
| 8561 | tested to a second partition. |
| 8562 | |
| 8563 | 2. The device is then rebooted using an external script that you need to |
| 8564 | provide. |
| 8565 | |
| 8566 | 3. The device boots into the image to be tested. |
| 8567 | |
| 8568 | When running tests (independent of whether the image has been deployed |
| 8569 | automatically or not), the device is expected to be connected to a |
| 8570 | network on a pre-determined IP address. You can either use static IP |
| 8571 | addresses written into the image, or set the image to use DHCP and have |
| 8572 | your DHCP server on the test network assign a known IP address based on |
| 8573 | the MAC address of the device. |
| 8574 | |
| 8575 | In order to run tests on hardware, you need to set ``TEST_TARGET`` to an |
| 8576 | appropriate value. For QEMU, you do not have to change anything, the |
| 8577 | default value is "qemu". For running tests on hardware, the following |
| 8578 | options exist: |
| 8579 | |
| 8580 | - *"simpleremote":* Choose "simpleremote" if you are going to run tests |
| 8581 | on a target system that is already running the image to be tested and |
| 8582 | is available on the network. You can use "simpleremote" in |
| 8583 | conjunction with either real hardware or an image running within a |
| 8584 | separately started QEMU or any other virtual machine manager. |
| 8585 | |
| 8586 | - *"SystemdbootTarget":* Choose "SystemdbootTarget" if your hardware is |
| 8587 | an EFI-based machine with ``systemd-boot`` as bootloader and |
| 8588 | ``core-image-testmaster`` (or something similar) is installed. Also, |
| 8589 | your hardware under test must be in a DHCP-enabled network that gives |
| 8590 | it the same IP address for each reboot. |
| 8591 | |
| 8592 | If you choose "SystemdbootTarget", there are additional requirements |
| 8593 | and considerations. See the "`Selecting |
| 8594 | SystemdbootTarget <#selecting-systemdboottarget>`__" section, which |
| 8595 | follows, for more information. |
| 8596 | |
| 8597 | - *"BeagleBoneTarget":* Choose "BeagleBoneTarget" if you are deploying |
| 8598 | images and running tests on the BeagleBone "Black" or original |
| 8599 | "White" hardware. For information on how to use these tests, see the |
| 8600 | comments at the top of the BeagleBoneTarget |
| 8601 | ``meta-yocto-bsp/lib/oeqa/controllers/beaglebonetarget.py`` file. |
| 8602 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8603 | - *"EdgeRouterTarget":* Choose "EdgeRouterTarget" if you are deploying |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8604 | images and running tests on the Ubiquiti Networks EdgeRouter Lite. |
| 8605 | For information on how to use these tests, see the comments at the |
| 8606 | top of the EdgeRouterTarget |
| 8607 | ``meta-yocto-bsp/lib/oeqa/controllers/edgeroutertarget.py`` file. |
| 8608 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8609 | - *"GrubTarget":* Choose "GrubTarget" if you are deploying images and running |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8610 | tests on any generic PC that boots using GRUB. For information on how |
| 8611 | to use these tests, see the comments at the top of the GrubTarget |
| 8612 | ``meta-yocto-bsp/lib/oeqa/controllers/grubtarget.py`` file. |
| 8613 | |
| 8614 | - *"your-target":* Create your own custom target if you want to run |
| 8615 | tests when you are deploying images and running tests on a custom |
| 8616 | machine within your BSP layer. To do this, you need to add a Python |
| 8617 | unit that defines the target class under ``lib/oeqa/controllers/`` |
| 8618 | within your layer. You must also provide an empty ``__init__.py``. |
| 8619 | For examples, see files in ``meta-yocto-bsp/lib/oeqa/controllers/``. |
| 8620 | |
| 8621 | Selecting SystemdbootTarget |
| 8622 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 8623 | |
| 8624 | If you did not set ``TEST_TARGET`` to "SystemdbootTarget", then you do |
| 8625 | not need any information in this section. You can skip down to the |
| 8626 | "`Running Tests <#qemu-image-running-tests>`__" section. |
| 8627 | |
| 8628 | If you did set ``TEST_TARGET`` to "SystemdbootTarget", you also need to |
| 8629 | perform a one-time setup of your master image by doing the following: |
| 8630 | |
| 8631 | 1. *Set EFI_PROVIDER:* Be sure that ``EFI_PROVIDER`` is as follows: |
| 8632 | :: |
| 8633 | |
| 8634 | EFI_PROVIDER = "systemd-boot" |
| 8635 | |
| 8636 | 2. *Build the master image:* Build the ``core-image-testmaster`` image. |
| 8637 | The ``core-image-testmaster`` recipe is provided as an example for a |
| 8638 | "master" image and you can customize the image recipe as you would |
| 8639 | any other recipe. |
| 8640 | |
| 8641 | Here are the image recipe requirements: |
| 8642 | |
| 8643 | - Inherits ``core-image`` so that kernel modules are installed. |
| 8644 | |
| 8645 | - Installs normal linux utilities not busybox ones (e.g. ``bash``, |
| 8646 | ``coreutils``, ``tar``, ``gzip``, and ``kmod``). |
| 8647 | |
| 8648 | - Uses a custom Initial RAM Disk (initramfs) image with a custom |
| 8649 | installer. A normal image that you can install usually creates a |
| 8650 | single rootfs partition. This image uses another installer that |
| 8651 | creates a specific partition layout. Not all Board Support |
| 8652 | Packages (BSPs) can use an installer. For such cases, you need to |
| 8653 | manually create the following partition layout on the target: |
| 8654 | |
| 8655 | - First partition mounted under ``/boot``, labeled "boot". |
| 8656 | |
| 8657 | - The main rootfs partition where this image gets installed, |
| 8658 | which is mounted under ``/``. |
| 8659 | |
| 8660 | - Another partition labeled "testrootfs" where test images get |
| 8661 | deployed. |
| 8662 | |
| 8663 | 3. *Install image:* Install the image that you just built on the target |
| 8664 | system. |
| 8665 | |
| 8666 | The final thing you need to do when setting ``TEST_TARGET`` to |
| 8667 | "SystemdbootTarget" is to set up the test image: |
| 8668 | |
| 8669 | 1. *Set up your local.conf file:* Make sure you have the following |
| 8670 | statements in your ``local.conf`` file: |
| 8671 | :: |
| 8672 | |
| 8673 | IMAGE_FSTYPES += "tar.gz" |
| 8674 | INHERIT += "testimage" |
| 8675 | TEST_TARGET = "SystemdbootTarget" |
| 8676 | TEST_TARGET_IP = "192.168.2.3" |
| 8677 | |
| 8678 | 2. *Build your test image:* Use BitBake to build the image: |
| 8679 | :: |
| 8680 | |
| 8681 | $ bitbake core-image-sato |
| 8682 | |
| 8683 | Power Control |
| 8684 | ~~~~~~~~~~~~~ |
| 8685 | |
| 8686 | For most hardware targets other than "simpleremote", you can control |
| 8687 | power: |
| 8688 | |
| 8689 | - You can use ``TEST_POWERCONTROL_CMD`` together with |
| 8690 | ``TEST_POWERCONTROL_EXTRA_ARGS`` as a command that runs on the host |
| 8691 | and does power cycling. The test code passes one argument to that |
| 8692 | command: off, on or cycle (off then on). Here is an example that |
| 8693 | could appear in your ``local.conf`` file: |
| 8694 | :: |
| 8695 | |
| 8696 | TEST_POWERCONTROL_CMD = "powercontrol.exp test 10.11.12.1 nuc1" |
| 8697 | |
| 8698 | In this example, the expect |
| 8699 | script does the following: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8700 | |
| 8701 | .. code-block:: shell |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8702 | |
| 8703 | ssh test@10.11.12.1 "pyctl nuc1 arg" |
| 8704 | |
| 8705 | It then runs a Python script that controls power for a label called |
| 8706 | ``nuc1``. |
| 8707 | |
| 8708 | .. note:: |
| 8709 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8710 | You need to customize ``TEST_POWERCONTROL_CMD`` and |
| 8711 | ``TEST_POWERCONTROL_EXTRA_ARGS`` for your own setup. The one requirement |
| 8712 | is that it accepts "on", "off", and "cycle" as the last argument. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8713 | |
| 8714 | - When no command is defined, it connects to the device over SSH and |
| 8715 | uses the classic reboot command to reboot the device. Classic reboot |
| 8716 | is fine as long as the machine actually reboots (i.e. the SSH test |
| 8717 | has not failed). It is useful for scenarios where you have a simple |
| 8718 | setup, typically with a single board, and where some manual |
| 8719 | interaction is okay from time to time. |
| 8720 | |
| 8721 | If you have no hardware to automatically perform power control but still |
| 8722 | wish to experiment with automated hardware testing, you can use the |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8723 | ``dialog-power-control`` script that shows a dialog prompting you to perform |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8724 | the required power action. This script requires either KDialog or Zenity |
| 8725 | to be installed. To use this script, set the |
| 8726 | :term:`TEST_POWERCONTROL_CMD` |
| 8727 | variable as follows: |
| 8728 | :: |
| 8729 | |
| 8730 | TEST_POWERCONTROL_CMD = "${COREBASE}/scripts/contrib/dialog-power-control" |
| 8731 | |
| 8732 | Serial Console Connection |
| 8733 | ~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 8734 | |
| 8735 | For test target classes requiring a serial console to interact with the |
| 8736 | bootloader (e.g. BeagleBoneTarget, EdgeRouterTarget, and GrubTarget), |
| 8737 | you need to specify a command to use to connect to the serial console of |
| 8738 | the target machine by using the |
| 8739 | :term:`TEST_SERIALCONTROL_CMD` |
| 8740 | variable and optionally the |
| 8741 | :term:`TEST_SERIALCONTROL_EXTRA_ARGS` |
| 8742 | variable. |
| 8743 | |
| 8744 | These cases could be a serial terminal program if the machine is |
| 8745 | connected to a local serial port, or a ``telnet`` or ``ssh`` command |
| 8746 | connecting to a remote console server. Regardless of the case, the |
| 8747 | command simply needs to connect to the serial console and forward that |
| 8748 | connection to standard input and output as any normal terminal program |
| 8749 | does. For example, to use the picocom terminal program on serial device |
| 8750 | ``/dev/ttyUSB0`` at 115200bps, you would set the variable as follows: |
| 8751 | :: |
| 8752 | |
| 8753 | TEST_SERIALCONTROL_CMD = "picocom /dev/ttyUSB0 -b 115200" |
| 8754 | |
| 8755 | For local |
| 8756 | devices where the serial port device disappears when the device reboots, |
| 8757 | an additional "serdevtry" wrapper script is provided. To use this |
| 8758 | wrapper, simply prefix the terminal command with |
| 8759 | ``${COREBASE}/scripts/contrib/serdevtry``: |
| 8760 | :: |
| 8761 | |
| 8762 | TEST_SERIALCONTROL_CMD = "${COREBASE}/scripts/contrib/serdevtry picocom -b 115200 /dev/ttyUSB0" |
| 8763 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8764 | Running Tests |
| 8765 | ------------- |
| 8766 | |
| 8767 | You can start the tests automatically or manually: |
| 8768 | |
| 8769 | - *Automatically running tests:* To run the tests automatically after |
| 8770 | the OpenEmbedded build system successfully creates an image, first |
| 8771 | set the |
| 8772 | :term:`TESTIMAGE_AUTO` |
| 8773 | variable to "1" in your ``local.conf`` file in the |
| 8774 | :term:`Build Directory`: |
| 8775 | :: |
| 8776 | |
| 8777 | TESTIMAGE_AUTO = "1" |
| 8778 | |
| 8779 | Next, build your image. If the image successfully builds, the |
| 8780 | tests run: |
| 8781 | :: |
| 8782 | |
| 8783 | bitbake core-image-sato |
| 8784 | |
| 8785 | - *Manually running tests:* To manually run the tests, first globally |
| 8786 | inherit the |
| 8787 | :ref:`testimage <ref-classes-testimage*>` class |
| 8788 | by editing your ``local.conf`` file: |
| 8789 | :: |
| 8790 | |
| 8791 | INHERIT += "testimage" |
| 8792 | |
| 8793 | Next, use BitBake to run the tests: |
| 8794 | :: |
| 8795 | |
| 8796 | bitbake -c testimage image |
| 8797 | |
| 8798 | All test files reside in ``meta/lib/oeqa/runtime`` in the |
| 8799 | :term:`Source Directory`. A test name maps |
| 8800 | directly to a Python module. Each test module may contain a number of |
| 8801 | individual tests. Tests are usually grouped together by the area tested |
| 8802 | (e.g tests for systemd reside in ``meta/lib/oeqa/runtime/systemd.py``). |
| 8803 | |
| 8804 | You can add tests to any layer provided you place them in the proper |
| 8805 | area and you extend :term:`BBPATH` in |
| 8806 | the ``local.conf`` file as normal. Be sure that tests reside in |
| 8807 | ``layer/lib/oeqa/runtime``. |
| 8808 | |
| 8809 | .. note:: |
| 8810 | |
| 8811 | Be sure that module names do not collide with module names used in |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8812 | the default set of test modules in ``meta/lib/oeqa/runtime``. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8813 | |
| 8814 | You can change the set of tests run by appending or overriding |
| 8815 | :term:`TEST_SUITES` variable in |
| 8816 | ``local.conf``. Each name in ``TEST_SUITES`` represents a required test |
| 8817 | for the image. Test modules named within ``TEST_SUITES`` cannot be |
| 8818 | skipped even if a test is not suitable for an image (e.g. running the |
| 8819 | RPM tests on an image without ``rpm``). Appending "auto" to |
| 8820 | ``TEST_SUITES`` causes the build system to try to run all tests that are |
| 8821 | suitable for the image (i.e. each test module may elect to skip itself). |
| 8822 | |
| 8823 | The order you list tests in ``TEST_SUITES`` is important and influences |
| 8824 | test dependencies. Consequently, tests that depend on other tests should |
| 8825 | be added after the test on which they depend. For example, since the |
| 8826 | ``ssh`` test depends on the ``ping`` test, "ssh" needs to come after |
| 8827 | "ping" in the list. The test class provides no re-ordering or dependency |
| 8828 | handling. |
| 8829 | |
| 8830 | .. note:: |
| 8831 | |
| 8832 | Each module can have multiple classes with multiple test methods. |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8833 | And, Python ``unittest`` rules apply. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8834 | |
| 8835 | Here are some things to keep in mind when running tests: |
| 8836 | |
| 8837 | - The default tests for the image are defined as: |
| 8838 | :: |
| 8839 | |
| 8840 | DEFAULT_TEST_SUITES_pn-image = "ping ssh df connman syslog xorg scp vnc date rpm dnf dmesg" |
| 8841 | |
| 8842 | - Add your own test to the list of the by using the following: |
| 8843 | :: |
| 8844 | |
| 8845 | TEST_SUITES_append = " mytest" |
| 8846 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8847 | - Run a specific list of tests as follows: |
| 8848 | :: |
| 8849 | |
| 8850 | TEST_SUITES = "test1 test2 test3" |
| 8851 | |
| 8852 | Remember, order is important. Be sure to place a test that is |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8853 | dependent on another test later in the order. |
| 8854 | |
| 8855 | Exporting Tests |
| 8856 | --------------- |
| 8857 | |
| 8858 | You can export tests so that they can run independently of the build |
| 8859 | system. Exporting tests is required if you want to be able to hand the |
| 8860 | test execution off to a scheduler. You can only export tests that are |
| 8861 | defined in :term:`TEST_SUITES`. |
| 8862 | |
| 8863 | If your image is already built, make sure the following are set in your |
| 8864 | ``local.conf`` file: |
| 8865 | :: |
| 8866 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8867 | INHERIT += "testexport" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8868 | TEST_TARGET_IP = "IP-address-for-the-test-target" |
| 8869 | TEST_SERVER_IP = "IP-address-for-the-test-server" |
| 8870 | |
| 8871 | You can then export the tests with the |
| 8872 | following BitBake command form: |
| 8873 | :: |
| 8874 | |
| 8875 | $ bitbake image -c testexport |
| 8876 | |
| 8877 | Exporting the tests places them in the |
| 8878 | :term:`Build Directory` in |
| 8879 | ``tmp/testexport/``\ image, which is controlled by the |
| 8880 | ``TEST_EXPORT_DIR`` variable. |
| 8881 | |
| 8882 | You can now run the tests outside of the build environment: |
| 8883 | :: |
| 8884 | |
| 8885 | $ cd tmp/testexport/image |
| 8886 | $ ./runexported.py testdata.json |
| 8887 | |
| 8888 | Here is a complete example that shows IP addresses and uses the |
| 8889 | ``core-image-sato`` image: |
| 8890 | :: |
| 8891 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8892 | INHERIT += "testexport" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8893 | TEST_TARGET_IP = "192.168.7.2" |
| 8894 | TEST_SERVER_IP = "192.168.7.1" |
| 8895 | |
| 8896 | Use BitBake to export the tests: |
| 8897 | :: |
| 8898 | |
| 8899 | $ bitbake core-image-sato -c testexport |
| 8900 | |
| 8901 | Run the tests outside of |
| 8902 | the build environment using the following: |
| 8903 | :: |
| 8904 | |
| 8905 | $ cd tmp/testexport/core-image-sato |
| 8906 | $ ./runexported.py testdata.json |
| 8907 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8908 | Writing New Tests |
| 8909 | ----------------- |
| 8910 | |
| 8911 | As mentioned previously, all new test files need to be in the proper |
| 8912 | place for the build system to find them. New tests for additional |
| 8913 | functionality outside of the core should be added to the layer that adds |
| 8914 | the functionality, in ``layer/lib/oeqa/runtime`` (as long as |
| 8915 | :term:`BBPATH` is extended in the |
| 8916 | layer's ``layer.conf`` file as normal). Just remember the following: |
| 8917 | |
| 8918 | - Filenames need to map directly to test (module) names. |
| 8919 | |
| 8920 | - Do not use module names that collide with existing core tests. |
| 8921 | |
| 8922 | - Minimally, an empty ``__init__.py`` file must exist in the runtime |
| 8923 | directory. |
| 8924 | |
| 8925 | To create a new test, start by copying an existing module (e.g. |
| 8926 | ``syslog.py`` or ``gcc.py`` are good ones to use). Test modules can use |
| 8927 | code from ``meta/lib/oeqa/utils``, which are helper classes. |
| 8928 | |
| 8929 | .. note:: |
| 8930 | |
| 8931 | Structure shell commands such that you rely on them and they return a |
| 8932 | single code for success. Be aware that sometimes you will need to |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8933 | parse the output. See the ``df.py`` and ``date.py`` modules for examples. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8934 | |
| 8935 | You will notice that all test classes inherit ``oeRuntimeTest``, which |
| 8936 | is found in ``meta/lib/oetest.py``. This base class offers some helper |
| 8937 | attributes, which are described in the following sections: |
| 8938 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8939 | Class Methods |
| 8940 | ~~~~~~~~~~~~~ |
| 8941 | |
| 8942 | Class methods are as follows: |
| 8943 | |
| 8944 | - *hasPackage(pkg):* Returns "True" if ``pkg`` is in the installed |
| 8945 | package list of the image, which is based on the manifest file that |
| 8946 | is generated during the ``do_rootfs`` task. |
| 8947 | |
| 8948 | - *hasFeature(feature):* Returns "True" if the feature is in |
| 8949 | :term:`IMAGE_FEATURES` or |
| 8950 | :term:`DISTRO_FEATURES`. |
| 8951 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8952 | Class Attributes |
| 8953 | ~~~~~~~~~~~~~~~~ |
| 8954 | |
| 8955 | Class attributes are as follows: |
| 8956 | |
| 8957 | - *pscmd:* Equals "ps -ef" if ``procps`` is installed in the image. |
| 8958 | Otherwise, ``pscmd`` equals "ps" (busybox). |
| 8959 | |
| 8960 | - *tc:* The called test context, which gives access to the |
| 8961 | following attributes: |
| 8962 | |
| 8963 | - *d:* The BitBake datastore, which allows you to use stuff such |
| 8964 | as ``oeRuntimeTest.tc.d.getVar("VIRTUAL-RUNTIME_init_manager")``. |
| 8965 | |
| 8966 | - *testslist and testsrequired:* Used internally. The tests |
| 8967 | do not need these. |
| 8968 | |
| 8969 | - *filesdir:* The absolute path to |
| 8970 | ``meta/lib/oeqa/runtime/files``, which contains helper files for |
| 8971 | tests meant for copying on the target such as small files written |
| 8972 | in C for compilation. |
| 8973 | |
| 8974 | - *target:* The target controller object used to deploy and |
| 8975 | start an image on a particular target (e.g. Qemu, SimpleRemote, |
| 8976 | and SystemdbootTarget). Tests usually use the following: |
| 8977 | |
| 8978 | - *ip:* The target's IP address. |
| 8979 | |
| 8980 | - *server_ip:* The host's IP address, which is usually used |
| 8981 | by the DNF test suite. |
| 8982 | |
| 8983 | - *run(cmd, timeout=None):* The single, most used method. |
| 8984 | This command is a wrapper for: ``ssh root@host "cmd"``. The |
| 8985 | command returns a tuple: (status, output), which are what their |
| 8986 | names imply - the return code of "cmd" and whatever output it |
| 8987 | produces. The optional timeout argument represents the number |
| 8988 | of seconds the test should wait for "cmd" to return. If the |
| 8989 | argument is "None", the test uses the default instance's |
| 8990 | timeout period, which is 300 seconds. If the argument is "0", |
| 8991 | the test runs until the command returns. |
| 8992 | |
| 8993 | - *copy_to(localpath, remotepath):* |
| 8994 | ``scp localpath root@ip:remotepath``. |
| 8995 | |
| 8996 | - *copy_from(remotepath, localpath):* |
| 8997 | ``scp root@host:remotepath localpath``. |
| 8998 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8999 | Instance Attributes |
| 9000 | ~~~~~~~~~~~~~~~~~~~ |
| 9001 | |
| 9002 | A single instance attribute exists, which is ``target``. The ``target`` |
| 9003 | instance attribute is identical to the class attribute of the same name, |
| 9004 | which is described in the previous section. This attribute exists as |
| 9005 | both an instance and class attribute so tests can use |
| 9006 | ``self.target.run(cmd)`` in instance methods instead of |
| 9007 | ``oeRuntimeTest.tc.target.run(cmd)``. |
| 9008 | |
| 9009 | Installing Packages in the DUT Without the Package Manager |
| 9010 | ---------------------------------------------------------- |
| 9011 | |
| 9012 | When a test requires a package built by BitBake, it is possible to |
| 9013 | install that package. Installing the package does not require a package |
| 9014 | manager be installed in the device under test (DUT). It does, however, |
| 9015 | require an SSH connection and the target must be using the |
| 9016 | ``sshcontrol`` class. |
| 9017 | |
| 9018 | .. note:: |
| 9019 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9020 | This method uses ``scp`` to copy files from the host to the target, which |
| 9021 | causes permissions and special attributes to be lost. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9022 | |
| 9023 | A JSON file is used to define the packages needed by a test. This file |
| 9024 | must be in the same path as the file used to define the tests. |
| 9025 | Furthermore, the filename must map directly to the test module name with |
| 9026 | a ``.json`` extension. |
| 9027 | |
| 9028 | The JSON file must include an object with the test name as keys of an |
| 9029 | object or an array. This object (or array of objects) uses the following |
| 9030 | data: |
| 9031 | |
| 9032 | - "pkg" - A mandatory string that is the name of the package to be |
| 9033 | installed. |
| 9034 | |
| 9035 | - "rm" - An optional boolean, which defaults to "false", that specifies |
| 9036 | to remove the package after the test. |
| 9037 | |
| 9038 | - "extract" - An optional boolean, which defaults to "false", that |
| 9039 | specifies if the package must be extracted from the package format. |
| 9040 | When set to "true", the package is not automatically installed into |
| 9041 | the DUT. |
| 9042 | |
| 9043 | Following is an example JSON file that handles test "foo" installing |
| 9044 | package "bar" and test "foobar" installing packages "foo" and "bar". |
| 9045 | Once the test is complete, the packages are removed from the DUT. |
| 9046 | :: |
| 9047 | |
| 9048 | { |
| 9049 | "foo": { |
| 9050 | "pkg": "bar" |
| 9051 | }, |
| 9052 | "foobar": [ |
| 9053 | { |
| 9054 | "pkg": "foo", |
| 9055 | "rm": true |
| 9056 | }, |
| 9057 | { |
| 9058 | "pkg": "bar", |
| 9059 | "rm": true |
| 9060 | } |
| 9061 | ] |
| 9062 | } |
| 9063 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9064 | Debugging Tools and Techniques |
| 9065 | ============================== |
| 9066 | |
| 9067 | The exact method for debugging build failures depends on the nature of |
| 9068 | the problem and on the system's area from which the bug originates. |
| 9069 | Standard debugging practices such as comparison against the last known |
| 9070 | working version with examination of the changes and the re-application |
| 9071 | of steps to identify the one causing the problem are valid for the Yocto |
| 9072 | Project just as they are for any other system. Even though it is |
| 9073 | impossible to detail every possible potential failure, this section |
| 9074 | provides some general tips to aid in debugging given a variety of |
| 9075 | situations. |
| 9076 | |
| 9077 | .. note:: |
| 9078 | |
| 9079 | A useful feature for debugging is the error reporting tool. |
| 9080 | Configuring the Yocto Project to use this tool causes the |
| 9081 | OpenEmbedded build system to produce error reporting commands as part |
| 9082 | of the console output. You can enter the commands after the build |
| 9083 | completes to log error information into a common database, that can |
| 9084 | help you figure out what might be going wrong. For information on how |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9085 | to enable and use this feature, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 9086 | ":ref:`dev-manual/common-tasks:using the error reporting tool`" |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9087 | section. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9088 | |
| 9089 | The following list shows the debugging topics in the remainder of this |
| 9090 | section: |
| 9091 | |
| 9092 | - "`Viewing Logs from Failed |
| 9093 | Tasks <#dev-debugging-viewing-logs-from-failed-tasks>`__" describes |
| 9094 | how to find and view logs from tasks that failed during the build |
| 9095 | process. |
| 9096 | |
| 9097 | - "`Viewing Variable |
| 9098 | Values <#dev-debugging-viewing-variable-values>`__" describes how to |
| 9099 | use the BitBake ``-e`` option to examine variable values after a |
| 9100 | recipe has been parsed. |
| 9101 | |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 9102 | - ":ref:`dev-manual/common-tasks:viewing package information with \`\`oe-pkgdata-util\`\``" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9103 | describes how to use the ``oe-pkgdata-util`` utility to query |
| 9104 | :term:`PKGDATA_DIR` and |
| 9105 | display package-related information for built packages. |
| 9106 | |
| 9107 | - "`Viewing Dependencies Between Recipes and |
| 9108 | Tasks <#dev-viewing-dependencies-between-recipes-and-tasks>`__" |
| 9109 | describes how to use the BitBake ``-g`` option to display recipe |
| 9110 | dependency information used during the build. |
| 9111 | |
| 9112 | - "`Viewing Task Variable |
| 9113 | Dependencies <#dev-viewing-task-variable-dependencies>`__" describes |
| 9114 | how to use the ``bitbake-dumpsig`` command in conjunction with key |
| 9115 | subdirectories in the |
| 9116 | :term:`Build Directory` to determine |
| 9117 | variable dependencies. |
| 9118 | |
| 9119 | - "`Running Specific Tasks <#dev-debugging-taskrunning>`__" describes |
| 9120 | how to use several BitBake options (e.g. ``-c``, ``-C``, and ``-f``) |
| 9121 | to run specific tasks in the build chain. It can be useful to run |
| 9122 | tasks "out-of-order" when trying isolate build issues. |
| 9123 | |
| 9124 | - "`General BitBake Problems <#dev-debugging-bitbake>`__" describes how |
| 9125 | to use BitBake's ``-D`` debug output option to reveal more about what |
| 9126 | BitBake is doing during the build. |
| 9127 | |
| 9128 | - "`Building with No Dependencies <#dev-debugging-buildfile>`__" |
| 9129 | describes how to use the BitBake ``-b`` option to build a recipe |
| 9130 | while ignoring dependencies. |
| 9131 | |
| 9132 | - "`Recipe Logging Mechanisms <#recipe-logging-mechanisms>`__" |
| 9133 | describes how to use the many recipe logging functions to produce |
| 9134 | debugging output and report errors and warnings. |
| 9135 | |
| 9136 | - "`Debugging Parallel Make Races <#debugging-parallel-make-races>`__" |
| 9137 | describes how to debug situations where the build consists of several |
| 9138 | parts that are run simultaneously and when the output or result of |
| 9139 | one part is not ready for use with a different part of the build that |
| 9140 | depends on that output. |
| 9141 | |
| 9142 | - "`Debugging With the GNU Project Debugger (GDB) |
| 9143 | Remotely <#platdev-gdb-remotedebug>`__" describes how to use GDB to |
| 9144 | allow you to examine running programs, which can help you fix |
| 9145 | problems. |
| 9146 | |
| 9147 | - "`Debugging with the GNU Project Debugger (GDB) on the |
| 9148 | Target <#debugging-with-the-gnu-project-debugger-gdb-on-the-target>`__" |
| 9149 | describes how to use GDB directly on target hardware for debugging. |
| 9150 | |
| 9151 | - "`Other Debugging Tips <#dev-other-debugging-others>`__" describes |
| 9152 | miscellaneous debugging tips that can be useful. |
| 9153 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9154 | Viewing Logs from Failed Tasks |
| 9155 | ------------------------------ |
| 9156 | |
| 9157 | You can find the log for a task in the file |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9158 | ``${``\ :term:`WORKDIR`\ ``}/temp/log.do_``\ `taskname`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9159 | For example, the log for the |
| 9160 | :ref:`ref-tasks-compile` task of the |
| 9161 | QEMU minimal image for the x86 machine (``qemux86``) might be in |
| 9162 | ``tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/temp/log.do_compile``. |
| 9163 | To see the commands :term:`BitBake` ran |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9164 | to generate a log, look at the corresponding ``run.do_``\ `taskname` file |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9165 | in the same directory. |
| 9166 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9167 | ``log.do_``\ `taskname` and ``run.do_``\ `taskname` are actually symbolic |
| 9168 | links to ``log.do_``\ `taskname`\ ``.``\ `pid` and |
| 9169 | ``log.run_``\ `taskname`\ ``.``\ `pid`, where `pid` is the PID the task had |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9170 | when it ran. The symlinks always point to the files corresponding to the |
| 9171 | most recent run. |
| 9172 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9173 | Viewing Variable Values |
| 9174 | ----------------------- |
| 9175 | |
| 9176 | Sometimes you need to know the value of a variable as a result of |
| 9177 | BitBake's parsing step. This could be because some unexpected behavior |
| 9178 | occurred in your project. Perhaps an attempt to :ref:`modify a variable |
| 9179 | <bitbake:bitbake-user-manual/bitbake-user-manual-metadata:modifying existing |
| 9180 | variables>` did not work out as expected. |
| 9181 | |
| 9182 | BitBake's ``-e`` option is used to display variable values after |
| 9183 | parsing. The following command displays the variable values after the |
| 9184 | configuration files (i.e. ``local.conf``, ``bblayers.conf``, |
| 9185 | ``bitbake.conf`` and so forth) have been parsed: |
| 9186 | :: |
| 9187 | |
| 9188 | $ bitbake -e |
| 9189 | |
| 9190 | The following command displays variable values after a specific recipe has |
| 9191 | been parsed. The variables include those from the configuration as well: |
| 9192 | :: |
| 9193 | |
| 9194 | $ bitbake -e recipename |
| 9195 | |
| 9196 | .. note:: |
| 9197 | |
| 9198 | Each recipe has its own private set of variables (datastore). |
| 9199 | Internally, after parsing the configuration, a copy of the resulting |
| 9200 | datastore is made prior to parsing each recipe. This copying implies |
| 9201 | that variables set in one recipe will not be visible to other |
| 9202 | recipes. |
| 9203 | |
| 9204 | Likewise, each task within a recipe gets a private datastore based on |
| 9205 | the recipe datastore, which means that variables set within one task |
| 9206 | will not be visible to other tasks. |
| 9207 | |
| 9208 | In the output of ``bitbake -e``, each variable is preceded by a |
| 9209 | description of how the variable got its value, including temporary |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9210 | values that were later overridden. This description also includes |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9211 | variable flags (varflags) set on the variable. The output can be very |
| 9212 | helpful during debugging. |
| 9213 | |
| 9214 | Variables that are exported to the environment are preceded by |
| 9215 | ``export`` in the output of ``bitbake -e``. See the following example: |
| 9216 | :: |
| 9217 | |
| 9218 | export CC="i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/ulf/poky/build/tmp/sysroots/qemux86" |
| 9219 | |
| 9220 | In addition to variable values, the output of the ``bitbake -e`` and |
| 9221 | ``bitbake -e`` recipe commands includes the following information: |
| 9222 | |
| 9223 | - The output starts with a tree listing all configuration files and |
| 9224 | classes included globally, recursively listing the files they include |
| 9225 | or inherit in turn. Much of the behavior of the OpenEmbedded build |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 9226 | system (including the behavior of the :ref:`ref-manual/tasks:normal recipe build tasks`) is |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9227 | implemented in the |
| 9228 | :ref:`base <ref-classes-base>` class and the |
| 9229 | classes it inherits, rather than being built into BitBake itself. |
| 9230 | |
| 9231 | - After the variable values, all functions appear in the output. For |
| 9232 | shell functions, variables referenced within the function body are |
| 9233 | expanded. If a function has been modified using overrides or using |
| 9234 | override-style operators like ``_append`` and ``_prepend``, then the |
| 9235 | final assembled function body appears in the output. |
| 9236 | |
| 9237 | Viewing Package Information with ``oe-pkgdata-util`` |
| 9238 | ---------------------------------------------------- |
| 9239 | |
| 9240 | You can use the ``oe-pkgdata-util`` command-line utility to query |
| 9241 | :term:`PKGDATA_DIR` and display |
| 9242 | various package-related information. When you use the utility, you must |
| 9243 | use it to view information on packages that have already been built. |
| 9244 | |
| 9245 | Following are a few of the available ``oe-pkgdata-util`` subcommands. |
| 9246 | |
| 9247 | .. note:: |
| 9248 | |
| 9249 | You can use the standard \* and ? globbing wildcards as part of |
| 9250 | package names and paths. |
| 9251 | |
| 9252 | - ``oe-pkgdata-util list-pkgs [pattern]``: Lists all packages |
| 9253 | that have been built, optionally limiting the match to packages that |
| 9254 | match pattern. |
| 9255 | |
| 9256 | - ``oe-pkgdata-util list-pkg-files package ...``: Lists the |
| 9257 | files and directories contained in the given packages. |
| 9258 | |
| 9259 | .. note:: |
| 9260 | |
| 9261 | A different way to view the contents of a package is to look at |
| 9262 | the |
| 9263 | ``${``\ :term:`WORKDIR`\ ``}/packages-split`` |
| 9264 | directory of the recipe that generates the package. This directory |
| 9265 | is created by the |
| 9266 | :ref:`ref-tasks-package` task |
| 9267 | and has one subdirectory for each package the recipe generates, |
| 9268 | which contains the files stored in that package. |
| 9269 | |
| 9270 | If you want to inspect the ``${WORKDIR}/packages-split`` |
| 9271 | directory, make sure that |
| 9272 | :ref:`rm_work <ref-classes-rm-work>` is not |
| 9273 | enabled when you build the recipe. |
| 9274 | |
| 9275 | - ``oe-pkgdata-util find-path path ...``: Lists the names of |
| 9276 | the packages that contain the given paths. For example, the following |
| 9277 | tells us that ``/usr/share/man/man1/make.1`` is contained in the |
| 9278 | ``make-doc`` package: |
| 9279 | :: |
| 9280 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9281 | $ oe-pkgdata-util find-path /usr/share/man/man1/make.1 |
| 9282 | make-doc: /usr/share/man/man1/make.1 |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9283 | |
| 9284 | - ``oe-pkgdata-util lookup-recipe package ...``: Lists the name |
| 9285 | of the recipes that produce the given packages. |
| 9286 | |
| 9287 | For more information on the ``oe-pkgdata-util`` command, use the help |
| 9288 | facility: |
| 9289 | :: |
| 9290 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9291 | $ oe-pkgdata-util --help |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9292 | $ oe-pkgdata-util subcommand --help |
| 9293 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9294 | Viewing Dependencies Between Recipes and Tasks |
| 9295 | ---------------------------------------------- |
| 9296 | |
| 9297 | Sometimes it can be hard to see why BitBake wants to build other recipes |
| 9298 | before the one you have specified. Dependency information can help you |
| 9299 | understand why a recipe is built. |
| 9300 | |
| 9301 | To generate dependency information for a recipe, run the following |
| 9302 | command: |
| 9303 | :: |
| 9304 | |
| 9305 | $ bitbake -g recipename |
| 9306 | |
| 9307 | This command writes the following files in the current directory: |
| 9308 | |
| 9309 | - ``pn-buildlist``: A list of recipes/targets involved in building |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9310 | `recipename`. "Involved" here means that at least one task from the |
| 9311 | recipe needs to run when building `recipename` from scratch. Targets |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9312 | that are in |
| 9313 | :term:`ASSUME_PROVIDED` |
| 9314 | are not listed. |
| 9315 | |
| 9316 | - ``task-depends.dot``: A graph showing dependencies between tasks. |
| 9317 | |
| 9318 | The graphs are in |
| 9319 | `DOT <https://en.wikipedia.org/wiki/DOT_%28graph_description_language%29>`__ |
| 9320 | format and can be converted to images (e.g. using the ``dot`` tool from |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9321 | `Graphviz <https://www.graphviz.org/>`__). |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9322 | |
| 9323 | .. note:: |
| 9324 | |
| 9325 | - DOT files use a plain text format. The graphs generated using the |
| 9326 | ``bitbake -g`` command are often so large as to be difficult to |
| 9327 | read without special pruning (e.g. with Bitbake's ``-I`` option) |
| 9328 | and processing. Despite the form and size of the graphs, the |
| 9329 | corresponding ``.dot`` files can still be possible to read and |
| 9330 | provide useful information. |
| 9331 | |
| 9332 | As an example, the ``task-depends.dot`` file contains lines such |
| 9333 | as the following: |
| 9334 | :: |
| 9335 | |
| 9336 | "libxslt.do_configure" -> "libxml2.do_populate_sysroot" |
| 9337 | |
| 9338 | The above example line reveals that the |
| 9339 | :ref:`ref-tasks-configure` |
| 9340 | task in ``libxslt`` depends on the |
| 9341 | :ref:`ref-tasks-populate_sysroot` |
| 9342 | task in ``libxml2``, which is a normal |
| 9343 | :term:`DEPENDS` dependency |
| 9344 | between the two recipes. |
| 9345 | |
| 9346 | - For an example of how ``.dot`` files can be processed, see the |
| 9347 | ``scripts/contrib/graph-tool`` Python script, which finds and |
| 9348 | displays paths between graph nodes. |
| 9349 | |
| 9350 | You can use a different method to view dependency information by using |
| 9351 | the following command: |
| 9352 | :: |
| 9353 | |
| 9354 | $ bitbake -g -u taskexp recipename |
| 9355 | |
| 9356 | This command |
| 9357 | displays a GUI window from which you can view build-time and runtime |
| 9358 | dependencies for the recipes involved in building recipename. |
| 9359 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9360 | Viewing Task Variable Dependencies |
| 9361 | ---------------------------------- |
| 9362 | |
| 9363 | As mentioned in the |
| 9364 | ":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-execution:checksums (signatures)`" section of the BitBake |
| 9365 | User Manual, BitBake tries to automatically determine what variables a |
| 9366 | task depends on so that it can rerun the task if any values of the |
| 9367 | variables change. This determination is usually reliable. However, if |
| 9368 | you do things like construct variable names at runtime, then you might |
| 9369 | have to manually declare dependencies on those variables using |
| 9370 | ``vardeps`` as described in the |
| 9371 | ":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags`" section of the BitBake |
| 9372 | User Manual. |
| 9373 | |
| 9374 | If you are unsure whether a variable dependency is being picked up |
| 9375 | automatically for a given task, you can list the variable dependencies |
| 9376 | BitBake has determined by doing the following: |
| 9377 | |
| 9378 | 1. Build the recipe containing the task: |
| 9379 | :: |
| 9380 | |
| 9381 | $ bitbake recipename |
| 9382 | |
| 9383 | 2. Inside the :term:`STAMPS_DIR` |
| 9384 | directory, find the signature data (``sigdata``) file that |
| 9385 | corresponds to the task. The ``sigdata`` files contain a pickled |
| 9386 | Python database of all the metadata that went into creating the input |
| 9387 | checksum for the task. As an example, for the |
| 9388 | :ref:`ref-tasks-fetch` task of the |
| 9389 | ``db`` recipe, the ``sigdata`` file might be found in the following |
| 9390 | location: |
| 9391 | :: |
| 9392 | |
| 9393 | ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1 |
| 9394 | |
| 9395 | For tasks that are accelerated through the shared state |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 9396 | (:ref:`sstate <overview-manual/concepts:shared state cache>`) cache, an |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9397 | additional ``siginfo`` file is written into |
| 9398 | :term:`SSTATE_DIR` along with |
| 9399 | the cached task output. The ``siginfo`` files contain exactly the |
| 9400 | same information as ``sigdata`` files. |
| 9401 | |
| 9402 | 3. Run ``bitbake-dumpsig`` on the ``sigdata`` or ``siginfo`` file. Here |
| 9403 | is an example: |
| 9404 | :: |
| 9405 | |
| 9406 | $ bitbake-dumpsig ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1 |
| 9407 | |
| 9408 | In the output of the above command, you will find a line like the |
| 9409 | following, which lists all the (inferred) variable dependencies for |
| 9410 | the task. This list also includes indirect dependencies from |
| 9411 | variables depending on other variables, recursively. |
| 9412 | :: |
| 9413 | |
| 9414 | Task dependencies: ['PV', 'SRCREV', 'SRC_URI', 'SRC_URI[md5sum]', 'SRC_URI[sha256sum]', 'base_do_fetch'] |
| 9415 | |
| 9416 | .. note:: |
| 9417 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9418 | Functions (e.g. ``base_do_fetch``) also count as variable dependencies. |
| 9419 | These functions in turn depend on the variables they reference. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9420 | |
| 9421 | The output of ``bitbake-dumpsig`` also includes the value each |
| 9422 | variable had, a list of dependencies for each variable, and |
| 9423 | :term:`bitbake:BB_HASHBASE_WHITELIST` |
| 9424 | information. |
| 9425 | |
| 9426 | There is also a ``bitbake-diffsigs`` command for comparing two |
| 9427 | ``siginfo`` or ``sigdata`` files. This command can be helpful when |
| 9428 | trying to figure out what changed between two versions of a task. If you |
| 9429 | call ``bitbake-diffsigs`` with just one file, the command behaves like |
| 9430 | ``bitbake-dumpsig``. |
| 9431 | |
| 9432 | You can also use BitBake to dump out the signature construction |
| 9433 | information without executing tasks by using either of the following |
| 9434 | BitBake command-line options: |
| 9435 | :: |
| 9436 | |
| 9437 | ‐‐dump-signatures=SIGNATURE_HANDLER |
| 9438 | -S SIGNATURE_HANDLER |
| 9439 | |
| 9440 | |
| 9441 | .. note:: |
| 9442 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9443 | Two common values for `SIGNATURE_HANDLER` are "none" and "printdiff", which |
| 9444 | dump only the signature or compare the dumped signature with the cached one, |
| 9445 | respectively. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9446 | |
| 9447 | Using BitBake with either of these options causes BitBake to dump out |
| 9448 | ``sigdata`` files in the ``stamps`` directory for every task it would |
| 9449 | have executed instead of building the specified target package. |
| 9450 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9451 | Viewing Metadata Used to Create the Input Signature of a Shared State Task |
| 9452 | -------------------------------------------------------------------------- |
| 9453 | |
| 9454 | Seeing what metadata went into creating the input signature of a shared |
| 9455 | state (sstate) task can be a useful debugging aid. This information is |
| 9456 | available in signature information (``siginfo``) files in |
| 9457 | :term:`SSTATE_DIR`. For |
| 9458 | information on how to view and interpret information in ``siginfo`` |
| 9459 | files, see the "`Viewing Task Variable |
| 9460 | Dependencies <#dev-viewing-task-variable-dependencies>`__" section. |
| 9461 | |
| 9462 | For conceptual information on shared state, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 9463 | ":ref:`overview-manual/concepts:shared state`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9464 | section in the Yocto Project Overview and Concepts Manual. |
| 9465 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9466 | Invalidating Shared State to Force a Task to Run |
| 9467 | ------------------------------------------------ |
| 9468 | |
| 9469 | The OpenEmbedded build system uses |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 9470 | :ref:`checksums <overview-manual/concepts:checksums (signatures)>` and |
| 9471 | :ref:`overview-manual/concepts:shared state` cache to avoid unnecessarily |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9472 | rebuilding tasks. Collectively, this scheme is known as "shared state |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9473 | code". |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9474 | |
| 9475 | As with all schemes, this one has some drawbacks. It is possible that |
| 9476 | you could make implicit changes to your code that the checksum |
| 9477 | calculations do not take into account. These implicit changes affect a |
| 9478 | task's output but do not trigger the shared state code into rebuilding a |
| 9479 | recipe. Consider an example during which a tool changes its output. |
| 9480 | Assume that the output of ``rpmdeps`` changes. The result of the change |
| 9481 | should be that all the ``package`` and ``package_write_rpm`` shared |
| 9482 | state cache items become invalid. However, because the change to the |
| 9483 | output is external to the code and therefore implicit, the associated |
| 9484 | shared state cache items do not become invalidated. In this case, the |
| 9485 | build process uses the cached items rather than running the task again. |
| 9486 | Obviously, these types of implicit changes can cause problems. |
| 9487 | |
| 9488 | To avoid these problems during the build, you need to understand the |
| 9489 | effects of any changes you make. Realize that changes you make directly |
| 9490 | to a function are automatically factored into the checksum calculation. |
| 9491 | Thus, these explicit changes invalidate the associated area of shared |
| 9492 | state cache. However, you need to be aware of any implicit changes that |
| 9493 | are not obvious changes to the code and could affect the output of a |
| 9494 | given task. |
| 9495 | |
| 9496 | When you identify an implicit change, you can easily take steps to |
| 9497 | invalidate the cache and force the tasks to run. The steps you can take |
| 9498 | are as simple as changing a function's comments in the source code. For |
| 9499 | example, to invalidate package shared state files, change the comment |
| 9500 | statements of |
| 9501 | :ref:`ref-tasks-package` or the |
| 9502 | comments of one of the functions it calls. Even though the change is |
| 9503 | purely cosmetic, it causes the checksum to be recalculated and forces |
| 9504 | the build system to run the task again. |
| 9505 | |
| 9506 | .. note:: |
| 9507 | |
| 9508 | For an example of a commit that makes a cosmetic change to invalidate |
| 9509 | shared state, see this |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 9510 | :yocto_git:`commit </poky/commit/meta/classes/package.bbclass?id=737f8bbb4f27b4837047cb9b4fbfe01dfde36d54>`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9511 | |
| 9512 | Running Specific Tasks |
| 9513 | ---------------------- |
| 9514 | |
| 9515 | Any given recipe consists of a set of tasks. The standard BitBake |
| 9516 | behavior in most cases is: ``do_fetch``, ``do_unpack``, ``do_patch``, |
| 9517 | ``do_configure``, ``do_compile``, ``do_install``, ``do_package``, |
| 9518 | ``do_package_write_*``, and ``do_build``. The default task is |
| 9519 | ``do_build`` and any tasks on which it depends build first. Some tasks, |
| 9520 | such as ``do_devshell``, are not part of the default build chain. If you |
| 9521 | wish to run a task that is not part of the default build chain, you can |
| 9522 | use the ``-c`` option in BitBake. Here is an example: |
| 9523 | :: |
| 9524 | |
| 9525 | $ bitbake matchbox-desktop -c devshell |
| 9526 | |
| 9527 | The ``-c`` option respects task dependencies, which means that all other |
| 9528 | tasks (including tasks from other recipes) that the specified task |
| 9529 | depends on will be run before the task. Even when you manually specify a |
| 9530 | task to run with ``-c``, BitBake will only run the task if it considers |
| 9531 | it "out of date". See the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 9532 | ":ref:`overview-manual/concepts:stamp files and the rerunning of tasks`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9533 | section in the Yocto Project Overview and Concepts Manual for how |
| 9534 | BitBake determines whether a task is "out of date". |
| 9535 | |
| 9536 | If you want to force an up-to-date task to be rerun (e.g. because you |
| 9537 | made manual modifications to the recipe's |
| 9538 | :term:`WORKDIR` that you want to try |
| 9539 | out), then you can use the ``-f`` option. |
| 9540 | |
| 9541 | .. note:: |
| 9542 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9543 | The reason ``-f`` is never required when running the |
| 9544 | :ref:`ref-tasks-devshell` task is because the |
| 9545 | [\ :ref:`nostamp <bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ] |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9546 | variable flag is already set for the task. |
| 9547 | |
| 9548 | The following example shows one way you can use the ``-f`` option: |
| 9549 | :: |
| 9550 | |
| 9551 | $ bitbake matchbox-desktop |
| 9552 | . |
| 9553 | . |
| 9554 | make some changes to the source code in the work directory |
| 9555 | . |
| 9556 | . |
| 9557 | $ bitbake matchbox-desktop -c compile -f |
| 9558 | $ bitbake matchbox-desktop |
| 9559 | |
| 9560 | This sequence first builds and then recompiles ``matchbox-desktop``. The |
| 9561 | last command reruns all tasks (basically the packaging tasks) after the |
| 9562 | compile. BitBake recognizes that the ``do_compile`` task was rerun and |
| 9563 | therefore understands that the other tasks also need to be run again. |
| 9564 | |
| 9565 | Another, shorter way to rerun a task and all |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 9566 | :ref:`ref-manual/tasks:normal recipe build tasks` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9567 | that depend on it is to use the ``-C`` option. |
| 9568 | |
| 9569 | .. note:: |
| 9570 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9571 | This option is upper-cased and is separate from the ``-c`` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9572 | option, which is lower-cased. |
| 9573 | |
| 9574 | Using this option invalidates the given task and then runs the |
| 9575 | :ref:`ref-tasks-build` task, which is |
| 9576 | the default task if no task is given, and the tasks on which it depends. |
| 9577 | You could replace the final two commands in the previous example with |
| 9578 | the following single command: |
| 9579 | :: |
| 9580 | |
| 9581 | $ bitbake matchbox-desktop -C compile |
| 9582 | |
| 9583 | Internally, the ``-f`` and ``-C`` options work by tainting (modifying) |
| 9584 | the input checksum of the specified task. This tainting indirectly |
| 9585 | causes the task and its dependent tasks to be rerun through the normal |
| 9586 | task dependency mechanisms. |
| 9587 | |
| 9588 | .. note:: |
| 9589 | |
| 9590 | BitBake explicitly keeps track of which tasks have been tainted in |
| 9591 | this fashion, and will print warnings such as the following for |
| 9592 | builds involving such tasks: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9593 | |
| 9594 | .. code-block:: none |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9595 | |
| 9596 | WARNING: /home/ulf/poky/meta/recipes-sato/matchbox-desktop/matchbox-desktop_2.1.bb.do_compile is tainted from a forced run |
| 9597 | |
| 9598 | |
| 9599 | The purpose of the warning is to let you know that the work directory |
| 9600 | and build output might not be in the clean state they would be in for |
| 9601 | a "normal" build, depending on what actions you took. To get rid of |
| 9602 | such warnings, you can remove the work directory and rebuild the |
| 9603 | recipe, as follows: |
| 9604 | :: |
| 9605 | |
| 9606 | $ bitbake matchbox-desktop -c clean |
| 9607 | $ bitbake matchbox-desktop |
| 9608 | |
| 9609 | |
| 9610 | You can view a list of tasks in a given package by running the |
| 9611 | ``do_listtasks`` task as follows: |
| 9612 | :: |
| 9613 | |
| 9614 | $ bitbake matchbox-desktop -c listtasks |
| 9615 | |
| 9616 | The results appear as output to the console and are also in |
| 9617 | the file ``${WORKDIR}/temp/log.do_listtasks``. |
| 9618 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9619 | General BitBake Problems |
| 9620 | ------------------------ |
| 9621 | |
| 9622 | You can see debug output from BitBake by using the ``-D`` option. The |
| 9623 | debug output gives more information about what BitBake is doing and the |
| 9624 | reason behind it. Each ``-D`` option you use increases the logging |
| 9625 | level. The most common usage is ``-DDD``. |
| 9626 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9627 | The output from ``bitbake -DDD -v targetname`` can reveal why BitBake |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9628 | chose a certain version of a package or why BitBake picked a certain |
| 9629 | provider. This command could also help you in a situation where you |
| 9630 | think BitBake did something unexpected. |
| 9631 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9632 | Building with No Dependencies |
| 9633 | ----------------------------- |
| 9634 | |
| 9635 | To build a specific recipe (``.bb`` file), you can use the following |
| 9636 | command form: |
| 9637 | :: |
| 9638 | |
| 9639 | $ bitbake -b somepath/somerecipe.bb |
| 9640 | |
| 9641 | This command form does |
| 9642 | not check for dependencies. Consequently, you should use it only when |
| 9643 | you know existing dependencies have been met. |
| 9644 | |
| 9645 | .. note:: |
| 9646 | |
| 9647 | You can also specify fragments of the filename. In this case, BitBake |
| 9648 | checks for a unique match. |
| 9649 | |
| 9650 | Recipe Logging Mechanisms |
| 9651 | ------------------------- |
| 9652 | |
| 9653 | The Yocto Project provides several logging functions for producing |
| 9654 | debugging output and reporting errors and warnings. For Python |
| 9655 | functions, the following logging functions exist. All of these functions |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9656 | log to ``${T}/log.do_``\ `task`, and can also log to standard output |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9657 | (stdout) with the right settings: |
| 9658 | |
| 9659 | - ``bb.plain(msg)``: Writes msg as is to the log while also |
| 9660 | logging to stdout. |
| 9661 | |
| 9662 | - ``bb.note(msg)``: Writes "NOTE: msg" to the log. Also logs to |
| 9663 | stdout if BitBake is called with "-v". |
| 9664 | |
| 9665 | - ``bb.debug(level, msg)``: Writes "DEBUG: msg" to the |
| 9666 | log. Also logs to stdout if the log level is greater than or equal to |
| 9667 | level. See the ":ref:`-D <bitbake:bitbake-user-manual/bitbake-user-manual-intro:usage and syntax>`" option |
| 9668 | in the BitBake User Manual for more information. |
| 9669 | |
| 9670 | - ``bb.warn(msg)``: Writes "WARNING: msg" to the log while also |
| 9671 | logging to stdout. |
| 9672 | |
| 9673 | - ``bb.error(msg)``: Writes "ERROR: msg" to the log while also |
| 9674 | logging to standard out (stdout). |
| 9675 | |
| 9676 | .. note:: |
| 9677 | |
| 9678 | Calling this function does not cause the task to fail. |
| 9679 | |
| 9680 | - ``bb.fatal(``\ msg\ ``)``: This logging function is similar to |
| 9681 | ``bb.error(``\ msg\ ``)`` but also causes the calling task to fail. |
| 9682 | |
| 9683 | .. note:: |
| 9684 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9685 | ``bb.fatal()`` raises an exception, which means you do not need to put a |
| 9686 | "return" statement after the function. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9687 | |
| 9688 | The same logging functions are also available in shell functions, under |
| 9689 | the names ``bbplain``, ``bbnote``, ``bbdebug``, ``bbwarn``, ``bberror``, |
| 9690 | and ``bbfatal``. The |
| 9691 | :ref:`logging <ref-classes-logging>` class |
| 9692 | implements these functions. See that class in the ``meta/classes`` |
| 9693 | folder of the :term:`Source Directory` for information. |
| 9694 | |
| 9695 | Logging With Python |
| 9696 | ~~~~~~~~~~~~~~~~~~~ |
| 9697 | |
| 9698 | When creating recipes using Python and inserting code that handles build |
| 9699 | logs, keep in mind the goal is to have informative logs while keeping |
| 9700 | the console as "silent" as possible. Also, if you want status messages |
| 9701 | in the log, use the "debug" loglevel. |
| 9702 | |
| 9703 | Following is an example written in Python. The code handles logging for |
| 9704 | a function that determines the number of tasks needed to be run. See the |
| 9705 | ":ref:`ref-tasks-listtasks`" |
| 9706 | section for additional information: |
| 9707 | :: |
| 9708 | |
| 9709 | python do_listtasks() { |
| 9710 | bb.debug(2, "Starting to figure out the task list") |
| 9711 | if noteworthy_condition: |
| 9712 | bb.note("There are 47 tasks to run") |
| 9713 | bb.debug(2, "Got to point xyz") |
| 9714 | if warning_trigger: |
| 9715 | bb.warn("Detected warning_trigger, this might be a problem later.") |
| 9716 | if recoverable_error: |
| 9717 | bb.error("Hit recoverable_error, you really need to fix this!") |
| 9718 | if fatal_error: |
| 9719 | bb.fatal("fatal_error detected, unable to print the task list") |
| 9720 | bb.plain("The tasks present are abc") |
| 9721 | bb.debug(2, "Finished figuring out the tasklist") |
| 9722 | } |
| 9723 | |
| 9724 | Logging With Bash |
| 9725 | ~~~~~~~~~~~~~~~~~ |
| 9726 | |
| 9727 | When creating recipes using Bash and inserting code that handles build |
| 9728 | logs, you have the same goals - informative with minimal console output. |
| 9729 | The syntax you use for recipes written in Bash is similar to that of |
| 9730 | recipes written in Python described in the previous section. |
| 9731 | |
| 9732 | Following is an example written in Bash. The code logs the progress of |
| 9733 | the ``do_my_function`` function. |
| 9734 | :: |
| 9735 | |
| 9736 | do_my_function() { |
| 9737 | bbdebug 2 "Running do_my_function" |
| 9738 | if [ exceptional_condition ]; then |
| 9739 | bbnote "Hit exceptional_condition" |
| 9740 | fi |
| 9741 | bbdebug 2 "Got to point xyz" |
| 9742 | if [ warning_trigger ]; then |
| 9743 | bbwarn "Detected warning_trigger, this might cause a problem later." |
| 9744 | fi |
| 9745 | if [ recoverable_error ]; then |
| 9746 | bberror "Hit recoverable_error, correcting" |
| 9747 | fi |
| 9748 | if [ fatal_error ]; then |
| 9749 | bbfatal "fatal_error detected" |
| 9750 | fi |
| 9751 | bbdebug 2 "Completed do_my_function" |
| 9752 | } |
| 9753 | |
| 9754 | |
| 9755 | Debugging Parallel Make Races |
| 9756 | ----------------------------- |
| 9757 | |
| 9758 | A parallel ``make`` race occurs when the build consists of several parts |
| 9759 | that are run simultaneously and a situation occurs when the output or |
| 9760 | result of one part is not ready for use with a different part of the |
| 9761 | build that depends on that output. Parallel make races are annoying and |
| 9762 | can sometimes be difficult to reproduce and fix. However, some simple |
| 9763 | tips and tricks exist that can help you debug and fix them. This section |
| 9764 | presents a real-world example of an error encountered on the Yocto |
| 9765 | Project autobuilder and the process used to fix it. |
| 9766 | |
| 9767 | .. note:: |
| 9768 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9769 | If you cannot properly fix a ``make`` race condition, you can work around it |
| 9770 | by clearing either the :term:`PARALLEL_MAKE` or :term:`PARALLEL_MAKEINST` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9771 | variables. |
| 9772 | |
| 9773 | The Failure |
| 9774 | ~~~~~~~~~~~ |
| 9775 | |
| 9776 | For this example, assume that you are building an image that depends on |
| 9777 | the "neard" package. And, during the build, BitBake runs into problems |
| 9778 | and creates the following output. |
| 9779 | |
| 9780 | .. note:: |
| 9781 | |
| 9782 | This example log file has longer lines artificially broken to make |
| 9783 | the listing easier to read. |
| 9784 | |
| 9785 | If you examine the output or the log file, you see the failure during |
| 9786 | ``make``: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9787 | |
| 9788 | .. code-block:: none |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9789 | |
| 9790 | | DEBUG: SITE files ['endian-little', 'bit-32', 'ix86-common', 'common-linux', 'common-glibc', 'i586-linux', 'common'] |
| 9791 | | DEBUG: Executing shell function do_compile |
| 9792 | | NOTE: make -j 16 |
| 9793 | | make --no-print-directory all-am |
| 9794 | | /bin/mkdir -p include/near |
| 9795 | | /bin/mkdir -p include/near |
| 9796 | | /bin/mkdir -p include/near |
| 9797 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9798 | 0.14-r0/neard-0.14/include/types.h include/near/types.h |
| 9799 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9800 | 0.14-r0/neard-0.14/include/log.h include/near/log.h |
| 9801 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9802 | 0.14-r0/neard-0.14/include/plugin.h include/near/plugin.h |
| 9803 | | /bin/mkdir -p include/near |
| 9804 | | /bin/mkdir -p include/near |
| 9805 | | /bin/mkdir -p include/near |
| 9806 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9807 | 0.14-r0/neard-0.14/include/tag.h include/near/tag.h |
| 9808 | | /bin/mkdir -p include/near |
| 9809 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9810 | 0.14-r0/neard-0.14/include/adapter.h include/near/adapter.h |
| 9811 | | /bin/mkdir -p include/near |
| 9812 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9813 | 0.14-r0/neard-0.14/include/ndef.h include/near/ndef.h |
| 9814 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9815 | 0.14-r0/neard-0.14/include/tlv.h include/near/tlv.h |
| 9816 | | /bin/mkdir -p include/near |
| 9817 | | /bin/mkdir -p include/near |
| 9818 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9819 | 0.14-r0/neard-0.14/include/setting.h include/near/setting.h |
| 9820 | | /bin/mkdir -p include/near |
| 9821 | | /bin/mkdir -p include/near |
| 9822 | | /bin/mkdir -p include/near |
| 9823 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9824 | 0.14-r0/neard-0.14/include/device.h include/near/device.h |
| 9825 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9826 | 0.14-r0/neard-0.14/include/nfc_copy.h include/near/nfc_copy.h |
| 9827 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9828 | 0.14-r0/neard-0.14/include/snep.h include/near/snep.h |
| 9829 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9830 | 0.14-r0/neard-0.14/include/version.h include/near/version.h |
| 9831 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9832 | 0.14-r0/neard-0.14/include/dbus.h include/near/dbus.h |
| 9833 | | ./src/genbuiltin nfctype1 nfctype2 nfctype3 nfctype4 p2p > src/builtin.h |
| 9834 | | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/ |
| 9835 | build/build/tmp/sysroots/qemux86 -DHAVE_CONFIG_H -I. -I./include -I./src -I./gdbus -I/home/pokybuild/ |
| 9836 | yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/glib-2.0 |
| 9837 | -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/ |
| 9838 | lib/glib-2.0/include -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/ |
| 9839 | tmp/sysroots/qemux86/usr/include/dbus-1.0 -I/home/pokybuild/yocto-autobuilder/yocto-slave/ |
| 9840 | nightly-x86/build/build/tmp/sysroots/qemux86/usr/lib/dbus-1.0/include -I/home/pokybuild/yocto-autobuilder/ |
| 9841 | yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/libnl3 |
| 9842 | -DNEAR_PLUGIN_BUILTIN -DPLUGINDIR=\""/usr/lib/near/plugins"\" |
| 9843 | -DCONFIGDIR=\""/etc/neard\"" -O2 -pipe -g -feliminate-unused-debug-types -c |
| 9844 | -o tools/snep-send.o tools/snep-send.c |
| 9845 | | In file included from tools/snep-send.c:16:0: |
| 9846 | | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory |
| 9847 | | #include <near/dbus.h> |
| 9848 | | ^ |
| 9849 | | compilation terminated. |
| 9850 | | make[1]: *** [tools/snep-send.o] Error 1 |
| 9851 | | make[1]: *** Waiting for unfinished jobs.... |
| 9852 | | make: *** [all] Error 2 |
| 9853 | | ERROR: oe_runmake failed |
| 9854 | |
| 9855 | Reproducing the Error |
| 9856 | ~~~~~~~~~~~~~~~~~~~~~ |
| 9857 | |
| 9858 | Because race conditions are intermittent, they do not manifest |
| 9859 | themselves every time you do the build. In fact, most times the build |
| 9860 | will complete without problems even though the potential race condition |
| 9861 | exists. Thus, once the error surfaces, you need a way to reproduce it. |
| 9862 | |
| 9863 | In this example, compiling the "neard" package is causing the problem. |
| 9864 | So the first thing to do is build "neard" locally. Before you start the |
| 9865 | build, set the |
| 9866 | :term:`PARALLEL_MAKE` variable |
| 9867 | in your ``local.conf`` file to a high number (e.g. "-j 20"). Using a |
| 9868 | high value for ``PARALLEL_MAKE`` increases the chances of the race |
| 9869 | condition showing up: |
| 9870 | :: |
| 9871 | |
| 9872 | $ bitbake neard |
| 9873 | |
| 9874 | Once the local build for "neard" completes, start a ``devshell`` build: |
| 9875 | :: |
| 9876 | |
| 9877 | $ bitbake neard -c devshell |
| 9878 | |
| 9879 | For information on how to use a |
| 9880 | ``devshell``, see the "`Using a Development |
| 9881 | Shell <#platdev-appdev-devshell>`__" section. |
| 9882 | |
| 9883 | In the ``devshell``, do the following: |
| 9884 | :: |
| 9885 | |
| 9886 | $ make clean |
| 9887 | $ make tools/snep-send.o |
| 9888 | |
| 9889 | The ``devshell`` commands cause the failure to clearly |
| 9890 | be visible. In this case, a missing dependency exists for the "neard" |
| 9891 | Makefile target. Here is some abbreviated, sample output with the |
| 9892 | missing dependency clearly visible at the end: |
| 9893 | :: |
| 9894 | |
| 9895 | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/scott-lenovo/...... |
| 9896 | . |
| 9897 | . |
| 9898 | . |
| 9899 | tools/snep-send.c |
| 9900 | In file included from tools/snep-send.c:16:0: |
| 9901 | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory |
| 9902 | #include <near/dbus.h> |
| 9903 | ^ |
| 9904 | compilation terminated. |
| 9905 | make: *** [tools/snep-send.o] Error 1 |
| 9906 | $ |
| 9907 | |
| 9908 | |
| 9909 | Creating a Patch for the Fix |
| 9910 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 9911 | |
| 9912 | Because there is a missing dependency for the Makefile target, you need |
| 9913 | to patch the ``Makefile.am`` file, which is generated from |
| 9914 | ``Makefile.in``. You can use Quilt to create the patch: |
| 9915 | :: |
| 9916 | |
| 9917 | $ quilt new parallelmake.patch |
| 9918 | Patch patches/parallelmake.patch is now on top |
| 9919 | $ quilt add Makefile.am |
| 9920 | File Makefile.am added to patch patches/parallelmake.patch |
| 9921 | |
| 9922 | For more information on using Quilt, see the |
| 9923 | "`Using Quilt in Your Workflow <#using-a-quilt-workflow>`__" section. |
| 9924 | |
| 9925 | At this point you need to make the edits to ``Makefile.am`` to add the |
| 9926 | missing dependency. For our example, you have to add the following line |
| 9927 | to the file: |
| 9928 | :: |
| 9929 | |
| 9930 | tools/snep-send.$(OBJEXT): include/near/dbus.h |
| 9931 | |
| 9932 | Once you have edited the file, use the ``refresh`` command to create the |
| 9933 | patch: |
| 9934 | :: |
| 9935 | |
| 9936 | $ quilt refresh |
| 9937 | Refreshed patch patches/parallelmake.patch |
| 9938 | |
| 9939 | Once |
| 9940 | the patch file exists, you need to add it back to the originating recipe |
| 9941 | folder. Here is an example assuming a top-level |
| 9942 | :term:`Source Directory` named ``poky``: |
| 9943 | :: |
| 9944 | |
| 9945 | $ cp patches/parallelmake.patch poky/meta/recipes-connectivity/neard/neard |
| 9946 | |
| 9947 | The final thing you need to do to implement the fix in the build is to |
| 9948 | update the "neard" recipe (i.e. ``neard-0.14.bb``) so that the |
| 9949 | :term:`SRC_URI` statement includes |
| 9950 | the patch file. The recipe file is in the folder above the patch. Here |
| 9951 | is what the edited ``SRC_URI`` statement would look like: |
| 9952 | :: |
| 9953 | |
| 9954 | SRC_URI = "${KERNELORG_MIRROR}/linux/network/nfc/${BPN}-${PV}.tar.xz \ |
| 9955 | file://neard.in \ |
| 9956 | file://neard.service.in \ |
| 9957 | file://parallelmake.patch \ |
| 9958 | " |
| 9959 | |
| 9960 | With the patch complete and moved to the correct folder and the |
| 9961 | ``SRC_URI`` statement updated, you can exit the ``devshell``: |
| 9962 | :: |
| 9963 | |
| 9964 | $ exit |
| 9965 | |
| 9966 | Testing the Build |
| 9967 | ~~~~~~~~~~~~~~~~~ |
| 9968 | |
| 9969 | With everything in place, you can get back to trying the build again |
| 9970 | locally: |
| 9971 | :: |
| 9972 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9973 | $ bitbake neard |
| 9974 | |
| 9975 | This build should succeed. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9976 | |
| 9977 | Now you can open up a ``devshell`` again and repeat the clean and make |
| 9978 | operations as follows: |
| 9979 | :: |
| 9980 | |
| 9981 | $ bitbake neard -c devshell |
| 9982 | $ make clean |
| 9983 | $ make tools/snep-send.o |
| 9984 | |
| 9985 | The build should work without issue. |
| 9986 | |
| 9987 | As with all solved problems, if they originated upstream, you need to |
| 9988 | submit the fix for the recipe in OE-Core and upstream so that the |
| 9989 | problem is taken care of at its source. See the "`Submitting a Change to |
| 9990 | the Yocto Project <#how-to-submit-a-change>`__" section for more |
| 9991 | information. |
| 9992 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9993 | Debugging With the GNU Project Debugger (GDB) Remotely |
| 9994 | ------------------------------------------------------ |
| 9995 | |
| 9996 | GDB allows you to examine running programs, which in turn helps you to |
| 9997 | understand and fix problems. It also allows you to perform post-mortem |
| 9998 | style analysis of program crashes. GDB is available as a package within |
| 9999 | the Yocto Project and is installed in SDK images by default. See the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 10000 | ":ref:`ref-manual/images:Images`" chapter in the Yocto |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10001 | Project Reference Manual for a description of these images. You can find |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10002 | information on GDB at https://sourceware.org/gdb/. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10003 | |
| 10004 | .. note:: |
| 10005 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10006 | For best results, install debug (``-dbg``) packages for the applications you |
| 10007 | are going to debug. Doing so makes extra debug symbols available that give |
| 10008 | you more meaningful output. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10009 | |
| 10010 | Sometimes, due to memory or disk space constraints, it is not possible |
| 10011 | to use GDB directly on the remote target to debug applications. These |
| 10012 | constraints arise because GDB needs to load the debugging information |
| 10013 | and the binaries of the process being debugged. Additionally, GDB needs |
| 10014 | to perform many computations to locate information such as function |
| 10015 | names, variable names and values, stack traces and so forth - even |
| 10016 | before starting the debugging process. These extra computations place |
| 10017 | more load on the target system and can alter the characteristics of the |
| 10018 | program being debugged. |
| 10019 | |
| 10020 | To help get past the previously mentioned constraints, you can use |
| 10021 | gdbserver, which runs on the remote target and does not load any |
| 10022 | debugging information from the debugged process. Instead, a GDB instance |
| 10023 | processes the debugging information that is run on a remote computer - |
| 10024 | the host GDB. The host GDB then sends control commands to gdbserver to |
| 10025 | make it stop or start the debugged program, as well as read or write |
| 10026 | memory regions of that debugged program. All the debugging information |
| 10027 | loaded and processed as well as all the heavy debugging is done by the |
| 10028 | host GDB. Offloading these processes gives the gdbserver running on the |
| 10029 | target a chance to remain small and fast. |
| 10030 | |
| 10031 | Because the host GDB is responsible for loading the debugging |
| 10032 | information and for doing the necessary processing to make actual |
| 10033 | debugging happen, you have to make sure the host can access the |
| 10034 | unstripped binaries complete with their debugging information and also |
| 10035 | be sure the target is compiled with no optimizations. The host GDB must |
| 10036 | also have local access to all the libraries used by the debugged |
| 10037 | program. Because gdbserver does not need any local debugging |
| 10038 | information, the binaries on the remote target can remain stripped. |
| 10039 | However, the binaries must also be compiled without optimization so they |
| 10040 | match the host's binaries. |
| 10041 | |
| 10042 | To remain consistent with GDB documentation and terminology, the binary |
| 10043 | being debugged on the remote target machine is referred to as the |
| 10044 | "inferior" binary. For documentation on GDB see the `GDB |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10045 | site <https://sourceware.org/gdb/documentation/>`__. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10046 | |
| 10047 | The following steps show you how to debug using the GNU project |
| 10048 | debugger. |
| 10049 | |
| 10050 | 1. *Configure your build system to construct the companion debug |
| 10051 | filesystem:* |
| 10052 | |
| 10053 | In your ``local.conf`` file, set the following: |
| 10054 | :: |
| 10055 | |
| 10056 | IMAGE_GEN_DEBUGFS = "1" |
| 10057 | IMAGE_FSTYPES_DEBUGFS = "tar.bz2" |
| 10058 | |
| 10059 | These options cause the |
| 10060 | OpenEmbedded build system to generate a special companion filesystem |
| 10061 | fragment, which contains the matching source and debug symbols to |
| 10062 | your deployable filesystem. The build system does this by looking at |
| 10063 | what is in the deployed filesystem, and pulling the corresponding |
| 10064 | ``-dbg`` packages. |
| 10065 | |
| 10066 | The companion debug filesystem is not a complete filesystem, but only |
| 10067 | contains the debug fragments. This filesystem must be combined with |
| 10068 | the full filesystem for debugging. Subsequent steps in this procedure |
| 10069 | show how to combine the partial filesystem with the full filesystem. |
| 10070 | |
| 10071 | 2. *Configure the system to include gdbserver in the target filesystem:* |
| 10072 | |
| 10073 | Make the following addition in either your ``local.conf`` file or in |
| 10074 | an image recipe: |
| 10075 | :: |
| 10076 | |
| 10077 | IMAGE_INSTALL_append = " gdbserver" |
| 10078 | |
| 10079 | The change makes |
| 10080 | sure the ``gdbserver`` package is included. |
| 10081 | |
| 10082 | 3. *Build the environment:* |
| 10083 | |
| 10084 | Use the following command to construct the image and the companion |
| 10085 | Debug Filesystem: |
| 10086 | :: |
| 10087 | |
| 10088 | $ bitbake image |
| 10089 | |
| 10090 | Build the cross GDB component and |
| 10091 | make it available for debugging. Build the SDK that matches the |
| 10092 | image. Building the SDK is best for a production build that can be |
| 10093 | used later for debugging, especially during long term maintenance: |
| 10094 | :: |
| 10095 | |
| 10096 | $ bitbake -c populate_sdk image |
| 10097 | |
| 10098 | Alternatively, you can build the minimal toolchain components that |
| 10099 | match the target. Doing so creates a smaller than typical SDK and |
| 10100 | only contains a minimal set of components with which to build simple |
| 10101 | test applications, as well as run the debugger: |
| 10102 | :: |
| 10103 | |
| 10104 | $ bitbake meta-toolchain |
| 10105 | |
| 10106 | A final method is to build Gdb itself within the build system: |
| 10107 | :: |
| 10108 | |
| 10109 | $ bitbake gdb-cross-<architecture> |
| 10110 | |
| 10111 | Doing so produces a temporary copy of |
| 10112 | ``cross-gdb`` you can use for debugging during development. While |
| 10113 | this is the quickest approach, the two previous methods in this step |
| 10114 | are better when considering long-term maintenance strategies. |
| 10115 | |
| 10116 | .. note:: |
| 10117 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10118 | If you run ``bitbake gdb-cross``, the OpenEmbedded build system suggests |
| 10119 | the actual image (e.g. ``gdb-cross-i586``). The suggestion is usually the |
| 10120 | actual name you want to use. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10121 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10122 | 4. *Set up the* ``debugfs``\ *:* |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10123 | |
| 10124 | Run the following commands to set up the ``debugfs``: |
| 10125 | :: |
| 10126 | |
| 10127 | $ mkdir debugfs |
| 10128 | $ cd debugfs |
| 10129 | $ tar xvfj build-dir/tmp-glibc/deploy/images/machine/image.rootfs.tar.bz2 |
| 10130 | $ tar xvfj build-dir/tmp-glibc/deploy/images/machine/image-dbg.rootfs.tar.bz2 |
| 10131 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10132 | 5. *Set up GDB:* |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10133 | |
| 10134 | Install the SDK (if you built one) and then source the correct |
| 10135 | environment file. Sourcing the environment file puts the SDK in your |
| 10136 | ``PATH`` environment variable. |
| 10137 | |
| 10138 | If you are using the build system, Gdb is located in |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10139 | `build-dir`\ ``/tmp/sysroots/``\ `host`\ ``/usr/bin/``\ `architecture`\ ``/``\ `architecture`\ ``-gdb`` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10140 | |
| 10141 | 6. *Boot the target:* |
| 10142 | |
| 10143 | For information on how to run QEMU, see the `QEMU |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10144 | Documentation <https://wiki.qemu.org/Documentation/GettingStartedDevelopers>`__. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10145 | |
| 10146 | .. note:: |
| 10147 | |
| 10148 | Be sure to verify that your host can access the target via TCP. |
| 10149 | |
| 10150 | 7. *Debug a program:* |
| 10151 | |
| 10152 | Debugging a program involves running gdbserver on the target and then |
| 10153 | running Gdb on the host. The example in this step debugs ``gzip``: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10154 | |
| 10155 | .. code-block:: shell |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10156 | |
| 10157 | root@qemux86:~# gdbserver localhost:1234 /bin/gzip —help |
| 10158 | |
| 10159 | For |
| 10160 | additional gdbserver options, see the `GDB Server |
| 10161 | Documentation <https://www.gnu.org/software/gdb/documentation/>`__. |
| 10162 | |
| 10163 | After running gdbserver on the target, you need to run Gdb on the |
| 10164 | host and configure it and connect to the target. Use these commands: |
| 10165 | :: |
| 10166 | |
| 10167 | $ cd directory-holding-the-debugfs-directory |
| 10168 | $ arch-gdb |
| 10169 | (gdb) set sysroot debugfs |
| 10170 | (gdb) set substitute-path /usr/src/debug debugfs/usr/src/debug |
| 10171 | (gdb) target remote IP-of-target:1234 |
| 10172 | |
| 10173 | At this |
| 10174 | point, everything should automatically load (i.e. matching binaries, |
| 10175 | symbols and headers). |
| 10176 | |
| 10177 | .. note:: |
| 10178 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10179 | The Gdb ``set`` commands in the previous example can be placed into the |
| 10180 | users ``~/.gdbinit`` file. Upon starting, Gdb automatically runs whatever |
| 10181 | commands are in that file. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10182 | |
| 10183 | 8. *Deploying without a full image rebuild:* |
| 10184 | |
| 10185 | In many cases, during development you want a quick method to deploy a |
| 10186 | new binary to the target and debug it, without waiting for a full |
| 10187 | image build. |
| 10188 | |
| 10189 | One approach to solving this situation is to just build the component |
| 10190 | you want to debug. Once you have built the component, copy the |
| 10191 | executable directly to both the target and the host ``debugfs``. |
| 10192 | |
| 10193 | If the binary is processed through the debug splitting in |
| 10194 | OpenEmbedded, you should also copy the debug items (i.e. ``.debug`` |
| 10195 | contents and corresponding ``/usr/src/debug`` files) from the work |
| 10196 | directory. Here is an example: |
| 10197 | :: |
| 10198 | |
| 10199 | $ bitbake bash |
| 10200 | $ bitbake -c devshell bash |
| 10201 | $ cd .. |
| 10202 | $ scp packages-split/bash/bin/bash target:/bin/bash |
| 10203 | $ cp -a packages-split/bash-dbg/\* path/debugfs |
| 10204 | |
| 10205 | Debugging with the GNU Project Debugger (GDB) on the Target |
| 10206 | ----------------------------------------------------------- |
| 10207 | |
| 10208 | The previous section addressed using GDB remotely for debugging |
| 10209 | purposes, which is the most usual case due to the inherent hardware |
| 10210 | limitations on many embedded devices. However, debugging in the target |
| 10211 | hardware itself is also possible with more powerful devices. This |
| 10212 | section describes what you need to do in order to support using GDB to |
| 10213 | debug on the target hardware. |
| 10214 | |
| 10215 | To support this kind of debugging, you need do the following: |
| 10216 | |
| 10217 | - Ensure that GDB is on the target. You can do this by adding "gdb" to |
| 10218 | :term:`IMAGE_INSTALL`: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10219 | :: |
| 10220 | |
| 10221 | IMAGE_INSTALL_append = " gdb" |
| 10222 | |
| 10223 | Alternatively, you can add "tools-debug" to :term:`IMAGE_FEATURES`: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10224 | :: |
| 10225 | |
| 10226 | IMAGE_FEATURES_append = " tools-debug" |
| 10227 | |
| 10228 | - Ensure that debug symbols are present. You can make sure these |
| 10229 | symbols are present by installing ``-dbg``: |
| 10230 | :: |
| 10231 | |
| 10232 | IMAGE_INSTALL_append = "packagename-dbg" |
| 10233 | |
| 10234 | Alternatively, you can do the following to include |
| 10235 | all the debug symbols: |
| 10236 | :: |
| 10237 | |
| 10238 | IMAGE_FEATURES_append = " dbg-pkgs" |
| 10239 | |
| 10240 | .. note:: |
| 10241 | |
| 10242 | To improve the debug information accuracy, you can reduce the level |
| 10243 | of optimization used by the compiler. For example, when adding the |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10244 | following line to your ``local.conf`` file, you will reduce optimization |
| 10245 | from :term:`FULL_OPTIMIZATION` of "-O2" to :term:`DEBUG_OPTIMIZATION` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10246 | of "-O -fno-omit-frame-pointer": |
| 10247 | :: |
| 10248 | |
| 10249 | DEBUG_BUILD = "1" |
| 10250 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10251 | Consider that this will reduce the application's performance and is |
| 10252 | recommended only for debugging purposes. |
| 10253 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10254 | Other Debugging Tips |
| 10255 | -------------------- |
| 10256 | |
| 10257 | Here are some other tips that you might find useful: |
| 10258 | |
| 10259 | - When adding new packages, it is worth watching for undesirable items |
| 10260 | making their way into compiler command lines. For example, you do not |
| 10261 | want references to local system files like ``/usr/lib/`` or |
| 10262 | ``/usr/include/``. |
| 10263 | |
| 10264 | - If you want to remove the ``psplash`` boot splashscreen, add |
| 10265 | ``psplash=false`` to the kernel command line. Doing so prevents |
| 10266 | ``psplash`` from loading and thus allows you to see the console. It |
| 10267 | is also possible to switch out of the splashscreen by switching the |
| 10268 | virtual console (e.g. Fn+Left or Fn+Right on a Zaurus). |
| 10269 | |
| 10270 | - Removing :term:`TMPDIR` (usually |
| 10271 | ``tmp/``, within the |
| 10272 | :term:`Build Directory`) can often fix |
| 10273 | temporary build issues. Removing ``TMPDIR`` is usually a relatively |
| 10274 | cheap operation, because task output will be cached in |
| 10275 | :term:`SSTATE_DIR` (usually |
| 10276 | ``sstate-cache/``, which is also in the Build Directory). |
| 10277 | |
| 10278 | .. note:: |
| 10279 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10280 | Removing ``TMPDIR`` might be a workaround rather than a fix. |
| 10281 | Consequently, trying to determine the underlying cause of an issue before |
| 10282 | removing the directory is a good idea. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10283 | |
| 10284 | - Understanding how a feature is used in practice within existing |
| 10285 | recipes can be very helpful. It is recommended that you configure |
| 10286 | some method that allows you to quickly search through files. |
| 10287 | |
| 10288 | Using GNU Grep, you can use the following shell function to |
| 10289 | recursively search through common recipe-related files, skipping |
| 10290 | binary files, ``.git`` directories, and the Build Directory (assuming |
| 10291 | its name starts with "build"): |
| 10292 | :: |
| 10293 | |
| 10294 | g() { |
| 10295 | grep -Ir \ |
| 10296 | --exclude-dir=.git \ |
| 10297 | --exclude-dir='build*' \ |
| 10298 | --include='*.bb*' \ |
| 10299 | --include='*.inc*' \ |
| 10300 | --include='*.conf*' \ |
| 10301 | --include='*.py*' \ |
| 10302 | "$@" |
| 10303 | } |
| 10304 | |
| 10305 | Following are some usage examples: |
| 10306 | :: |
| 10307 | |
| 10308 | $ g FOO # Search recursively for "FOO" |
| 10309 | $ g -i foo # Search recursively for "foo", ignoring case |
| 10310 | $ g -w FOO # Search recursively for "FOO" as a word, ignoring e.g. "FOOBAR" |
| 10311 | |
| 10312 | If figuring |
| 10313 | out how some feature works requires a lot of searching, it might |
| 10314 | indicate that the documentation should be extended or improved. In |
| 10315 | such cases, consider filing a documentation bug using the Yocto |
| 10316 | Project implementation of |
| 10317 | :yocto_bugs:`Bugzilla <>`. For information on |
| 10318 | how to submit a bug against the Yocto Project, see the Yocto Project |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 10319 | Bugzilla :yocto_wiki:`wiki page </Bugzilla_Configuration_and_Bug_Tracking>` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10320 | and the "`Submitting a Defect Against the Yocto |
| 10321 | Project <#submitting-a-defect-against-the-yocto-project>`__" section. |
| 10322 | |
| 10323 | .. note:: |
| 10324 | |
| 10325 | The manuals might not be the right place to document variables |
| 10326 | that are purely internal and have a limited scope (e.g. internal |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10327 | variables used to implement a single ``.bbclass`` file). |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10328 | |
| 10329 | Making Changes to the Yocto Project |
| 10330 | =================================== |
| 10331 | |
| 10332 | Because the Yocto Project is an open-source, community-based project, |
| 10333 | you can effect changes to the project. This section presents procedures |
| 10334 | that show you how to submit a defect against the project and how to |
| 10335 | submit a change. |
| 10336 | |
| 10337 | Submitting a Defect Against the Yocto Project |
| 10338 | --------------------------------------------- |
| 10339 | |
| 10340 | Use the Yocto Project implementation of |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10341 | `Bugzilla <https://www.bugzilla.org/about/>`__ to submit a defect (bug) |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10342 | against the Yocto Project. For additional information on this |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10343 | implementation of Bugzilla see the ":ref:`Yocto Project |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10344 | Bugzilla <resources-bugtracker>`" section in the |
| 10345 | Yocto Project Reference Manual. For more detail on any of the following |
| 10346 | steps, see the Yocto Project |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 10347 | :yocto_wiki:`Bugzilla wiki page </Bugzilla_Configuration_and_Bug_Tracking>`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10348 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10349 | Use the following general steps to submit a bug: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10350 | |
| 10351 | 1. Open the Yocto Project implementation of :yocto_bugs:`Bugzilla <>`. |
| 10352 | |
| 10353 | 2. Click "File a Bug" to enter a new bug. |
| 10354 | |
| 10355 | 3. Choose the appropriate "Classification", "Product", and "Component" |
| 10356 | for which the bug was found. Bugs for the Yocto Project fall into |
| 10357 | one of several classifications, which in turn break down into |
| 10358 | several products and components. For example, for a bug against the |
| 10359 | ``meta-intel`` layer, you would choose "Build System, Metadata & |
| 10360 | Runtime", "BSPs", and "bsps-meta-intel", respectively. |
| 10361 | |
| 10362 | 4. Choose the "Version" of the Yocto Project for which you found the |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10363 | bug (e.g. &DISTRO;). |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10364 | |
| 10365 | 5. Determine and select the "Severity" of the bug. The severity |
| 10366 | indicates how the bug impacted your work. |
| 10367 | |
| 10368 | 6. Choose the "Hardware" that the bug impacts. |
| 10369 | |
| 10370 | 7. Choose the "Architecture" that the bug impacts. |
| 10371 | |
| 10372 | 8. Choose a "Documentation change" item for the bug. Fixing a bug might |
| 10373 | or might not affect the Yocto Project documentation. If you are |
| 10374 | unsure of the impact to the documentation, select "Don't Know". |
| 10375 | |
| 10376 | 9. Provide a brief "Summary" of the bug. Try to limit your summary to |
| 10377 | just a line or two and be sure to capture the essence of the bug. |
| 10378 | |
| 10379 | 10. Provide a detailed "Description" of the bug. You should provide as |
| 10380 | much detail as you can about the context, behavior, output, and so |
| 10381 | forth that surrounds the bug. You can even attach supporting files |
| 10382 | for output from logs by using the "Add an attachment" button. |
| 10383 | |
| 10384 | 11. Click the "Submit Bug" button submit the bug. A new Bugzilla number |
| 10385 | is assigned to the bug and the defect is logged in the bug tracking |
| 10386 | system. |
| 10387 | |
| 10388 | Once you file a bug, the bug is processed by the Yocto Project Bug |
| 10389 | Triage Team and further details concerning the bug are assigned (e.g. |
| 10390 | priority and owner). You are the "Submitter" of the bug and any further |
| 10391 | categorization, progress, or comments on the bug result in Bugzilla |
| 10392 | sending you an automated email concerning the particular change or |
| 10393 | progress to the bug. |
| 10394 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10395 | Submitting a Change to the Yocto Project |
| 10396 | ---------------------------------------- |
| 10397 | |
| 10398 | Contributions to the Yocto Project and OpenEmbedded are very welcome. |
| 10399 | Because the system is extremely configurable and flexible, we recognize |
| 10400 | that developers will want to extend, configure or optimize it for their |
| 10401 | specific uses. |
| 10402 | |
| 10403 | The Yocto Project uses a mailing list and a patch-based workflow that is |
| 10404 | similar to the Linux kernel but contains important differences. In |
| 10405 | general, a mailing list exists through which you can submit patches. You |
| 10406 | should send patches to the appropriate mailing list so that they can be |
| 10407 | reviewed and merged by the appropriate maintainer. The specific mailing |
| 10408 | list you need to use depends on the location of the code you are |
| 10409 | changing. Each component (e.g. layer) should have a ``README`` file that |
| 10410 | indicates where to send the changes and which process to follow. |
| 10411 | |
| 10412 | You can send the patch to the mailing list using whichever approach you |
| 10413 | feel comfortable with to generate the patch. Once sent, the patch is |
| 10414 | usually reviewed by the community at large. If somebody has concerns |
| 10415 | with the patch, they will usually voice their concern over the mailing |
| 10416 | list. If a patch does not receive any negative reviews, the maintainer |
| 10417 | of the affected layer typically takes the patch, tests it, and then |
| 10418 | based on successful testing, merges the patch. |
| 10419 | |
| 10420 | The "poky" repository, which is the Yocto Project's reference build |
| 10421 | environment, is a hybrid repository that contains several individual |
| 10422 | pieces (e.g. BitBake, Metadata, documentation, and so forth) built using |
| 10423 | the combo-layer tool. The upstream location used for submitting changes |
| 10424 | varies by component: |
| 10425 | |
| 10426 | - *Core Metadata:* Send your patch to the |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10427 | :oe_lists:`openembedded-core </g/openembedded-core>` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10428 | mailing list. For example, a change to anything under the ``meta`` or |
| 10429 | ``scripts`` directories should be sent to this mailing list. |
| 10430 | |
| 10431 | - *BitBake:* For changes to BitBake (i.e. anything under the |
| 10432 | ``bitbake`` directory), send your patch to the |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10433 | :oe_lists:`bitbake-devel </g/bitbake-devel>` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10434 | mailing list. |
| 10435 | |
Andrew Geissler | c3d88e4 | 2020-10-02 09:45:00 -0500 | [diff] [blame] | 10436 | - *"meta-\*" trees:* These trees contain Metadata. Use the |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10437 | :yocto_lists:`poky </g/poky>` mailing list. |
Andrew Geissler | c3d88e4 | 2020-10-02 09:45:00 -0500 | [diff] [blame] | 10438 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10439 | - *Documentation*: For changes to the Yocto Project documentation, use the |
| 10440 | :yocto_lists:`docs </g/docs>` mailing list. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10441 | |
| 10442 | For changes to other layers hosted in the Yocto Project source |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10443 | repositories (i.e. ``yoctoproject.org``) and tools use the |
| 10444 | :yocto_lists:`Yocto Project </g/yocto/>` general mailing list. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10445 | |
| 10446 | .. note:: |
| 10447 | |
| 10448 | Sometimes a layer's documentation specifies to use a particular |
| 10449 | mailing list. If so, use that list. |
| 10450 | |
| 10451 | For additional recipes that do not fit into the core Metadata, you |
| 10452 | should determine which layer the recipe should go into and submit the |
| 10453 | change in the manner recommended by the documentation (e.g. the |
| 10454 | ``README`` file) supplied with the layer. If in doubt, please ask on the |
| 10455 | Yocto general mailing list or on the openembedded-devel mailing list. |
| 10456 | |
| 10457 | You can also push a change upstream and request a maintainer to pull the |
| 10458 | change into the component's upstream repository. You do this by pushing |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 10459 | to a contribution repository that is upstream. See the |
| 10460 | ":ref:`overview-manual/development-environment:git workflows and the yocto project`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10461 | section in the Yocto Project Overview and Concepts Manual for additional |
| 10462 | concepts on working in the Yocto Project development environment. |
| 10463 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10464 | Maintainers commonly use ``-next`` branches to test submissions prior to |
| 10465 | merging patches. Thus, you can get an idea of the status of a patch based on |
| 10466 | whether the patch has been merged into one of these branches. The commonly |
| 10467 | used testing branches for OpenEmbedded-Core are as follows: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10468 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10469 | - *openembedded-core "master-next" branch:* This branch is part of the |
| 10470 | :oe_git:`openembedded-core </openembedded-core/>` repository and contains |
| 10471 | proposed changes to the core metadata. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10472 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10473 | - *poky "master-next" branch:* This branch is part of the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 10474 | :yocto_git:`poky </poky/>` repository and combines proposed |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10475 | changes to bitbake, the core metadata and the poky distro. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10476 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10477 | Similarly, stable branches maintained by the project may have corresponding |
| 10478 | ``-next`` branches which collect proposed changes. For example, |
| 10479 | ``&DISTRO_NAME_NO_CAP;-next`` and ``&DISTRO_NAME_NO_CAP_MINUS_ONE;-next`` |
| 10480 | branches in both the "openembdedded-core" and "poky" repositories. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10481 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10482 | Other layers may have similar testing branches but there is no formal |
| 10483 | requirement or standard for these so please check the documentation for the |
| 10484 | layers you are contributing to. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10485 | |
| 10486 | The following sections provide procedures for submitting a change. |
| 10487 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10488 | Preparing Changes for Submission |
| 10489 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10490 | |
| 10491 | 1. *Make Your Changes Locally:* Make your changes in your local Git |
| 10492 | repository. You should make small, controlled, isolated changes. |
| 10493 | Keeping changes small and isolated aids review, makes |
| 10494 | merging/rebasing easier and keeps the change history clean should |
| 10495 | anyone need to refer to it in future. |
| 10496 | |
| 10497 | 2. *Stage Your Changes:* Stage your changes by using the ``git add`` |
| 10498 | command on each file you changed. |
| 10499 | |
| 10500 | 3. *Commit Your Changes:* Commit the change by using the ``git commit`` |
| 10501 | command. Make sure your commit information follows standards by |
| 10502 | following these accepted conventions: |
| 10503 | |
| 10504 | - Be sure to include a "Signed-off-by:" line in the same style as |
| 10505 | required by the Linux kernel. Adding this line signifies that you, |
| 10506 | the submitter, have agreed to the Developer's Certificate of |
| 10507 | Origin 1.1 as follows: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10508 | |
| 10509 | .. code-block:: none |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10510 | |
| 10511 | Developer's Certificate of Origin 1.1 |
| 10512 | |
| 10513 | By making a contribution to this project, I certify that: |
| 10514 | |
| 10515 | (a) The contribution was created in whole or in part by me and I |
| 10516 | have the right to submit it under the open source license |
| 10517 | indicated in the file; or |
| 10518 | |
| 10519 | (b) The contribution is based upon previous work that, to the best |
| 10520 | of my knowledge, is covered under an appropriate open source |
| 10521 | license and I have the right under that license to submit that |
| 10522 | work with modifications, whether created in whole or in part |
| 10523 | by me, under the same open source license (unless I am |
| 10524 | permitted to submit under a different license), as indicated |
| 10525 | in the file; or |
| 10526 | |
| 10527 | (c) The contribution was provided directly to me by some other |
| 10528 | person who certified (a), (b) or (c) and I have not modified |
| 10529 | it. |
| 10530 | |
| 10531 | (d) I understand and agree that this project and the contribution |
| 10532 | are public and that a record of the contribution (including all |
| 10533 | personal information I submit with it, including my sign-off) is |
| 10534 | maintained indefinitely and may be redistributed consistent with |
| 10535 | this project or the open source license(s) involved. |
| 10536 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10537 | - Provide a single-line summary of the change and, if more |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10538 | explanation is needed, provide more detail in the body of the |
| 10539 | commit. This summary is typically viewable in the "shortlist" of |
| 10540 | changes. Thus, providing something short and descriptive that |
| 10541 | gives the reader a summary of the change is useful when viewing a |
| 10542 | list of many commits. You should prefix this short description |
| 10543 | with the recipe name (if changing a recipe), or else with the |
| 10544 | short form path to the file being changed. |
| 10545 | |
| 10546 | - For the body of the commit message, provide detailed information |
| 10547 | that describes what you changed, why you made the change, and the |
| 10548 | approach you used. It might also be helpful if you mention how you |
| 10549 | tested the change. Provide as much detail as you can in the body |
| 10550 | of the commit message. |
| 10551 | |
| 10552 | .. note:: |
| 10553 | |
| 10554 | You do not need to provide a more detailed explanation of a |
| 10555 | change if the change is minor to the point of the single line |
| 10556 | summary providing all the information. |
| 10557 | |
| 10558 | - If the change addresses a specific bug or issue that is associated |
| 10559 | with a bug-tracking ID, include a reference to that ID in your |
| 10560 | detailed description. For example, the Yocto Project uses a |
| 10561 | specific convention for bug references - any commit that addresses |
| 10562 | a specific bug should use the following form for the detailed |
| 10563 | description. Be sure to use the actual bug-tracking ID from |
| 10564 | Bugzilla for bug-id: |
| 10565 | :: |
| 10566 | |
| 10567 | Fixes [YOCTO #bug-id] |
| 10568 | |
| 10569 | detailed description of change |
| 10570 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10571 | Using Email to Submit a Patch |
| 10572 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 10573 | |
| 10574 | Depending on the components changed, you need to submit the email to a |
| 10575 | specific mailing list. For some guidance on which mailing list to use, |
| 10576 | see the `list <#figuring-out-the-mailing-list-to-use>`__ at the |
| 10577 | beginning of this section. For a description of all the available |
| 10578 | mailing lists, see the ":ref:`Mailing Lists <resources-mailinglist>`" section in the |
| 10579 | Yocto Project Reference Manual. |
| 10580 | |
| 10581 | Here is the general procedure on how to submit a patch through email |
| 10582 | without using the scripts once the steps in |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 10583 | :ref:`dev-manual/common-tasks:preparing changes for submission` have been followed: |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10584 | |
| 10585 | 1. *Format the Commit:* Format the commit into an email message. To |
| 10586 | format commits, use the ``git format-patch`` command. When you |
| 10587 | provide the command, you must include a revision list or a number of |
| 10588 | patches as part of the command. For example, either of these two |
| 10589 | commands takes your most recent single commit and formats it as an |
| 10590 | email message in the current directory: |
| 10591 | :: |
| 10592 | |
| 10593 | $ git format-patch -1 |
| 10594 | |
| 10595 | or :: |
| 10596 | |
| 10597 | $ git format-patch HEAD~ |
| 10598 | |
| 10599 | After the command is run, the current directory contains a numbered |
| 10600 | ``.patch`` file for the commit. |
| 10601 | |
| 10602 | If you provide several commits as part of the command, the |
| 10603 | ``git format-patch`` command produces a series of numbered files in |
| 10604 | the current directory – one for each commit. If you have more than |
| 10605 | one patch, you should also use the ``--cover`` option with the |
| 10606 | command, which generates a cover letter as the first "patch" in the |
| 10607 | series. You can then edit the cover letter to provide a description |
| 10608 | for the series of patches. For information on the |
| 10609 | ``git format-patch`` command, see ``GIT_FORMAT_PATCH(1)`` displayed |
| 10610 | using the ``man git-format-patch`` command. |
| 10611 | |
| 10612 | .. note:: |
| 10613 | |
| 10614 | If you are or will be a frequent contributor to the Yocto Project |
| 10615 | or to OpenEmbedded, you might consider requesting a contrib area |
| 10616 | and the necessary associated rights. |
| 10617 | |
| 10618 | 2. *Send the patches via email:* Send the patches to the recipients and |
| 10619 | relevant mailing lists by using the ``git send-email`` command. |
| 10620 | |
| 10621 | .. note:: |
| 10622 | |
| 10623 | In order to use ``git send-email``, you must have the proper Git packages |
| 10624 | installed on your host. |
| 10625 | For Ubuntu, Debian, and Fedora the package is ``git-email``. |
| 10626 | |
| 10627 | The ``git send-email`` command sends email by using a local or remote |
| 10628 | Mail Transport Agent (MTA) such as ``msmtp``, ``sendmail``, or |
| 10629 | through a direct ``smtp`` configuration in your Git ``~/.gitconfig`` |
| 10630 | file. If you are submitting patches through email only, it is very |
| 10631 | important that you submit them without any whitespace or HTML |
| 10632 | formatting that either you or your mailer introduces. The maintainer |
| 10633 | that receives your patches needs to be able to save and apply them |
| 10634 | directly from your emails. A good way to verify that what you are |
| 10635 | sending will be applicable by the maintainer is to do a dry run and |
| 10636 | send them to yourself and then save and apply them as the maintainer |
| 10637 | would. |
| 10638 | |
| 10639 | The ``git send-email`` command is the preferred method for sending |
| 10640 | your patches using email since there is no risk of compromising |
| 10641 | whitespace in the body of the message, which can occur when you use |
| 10642 | your own mail client. The command also has several options that let |
| 10643 | you specify recipients and perform further editing of the email |
| 10644 | message. For information on how to use the ``git send-email`` |
| 10645 | command, see ``GIT-SEND-EMAIL(1)`` displayed using the |
| 10646 | ``man git-send-email`` command. |
| 10647 | |
| 10648 | The Yocto Project uses a `Patchwork instance <https://patchwork.openembedded.org/>`__ |
| 10649 | to track the status of patches submitted to the various mailing lists and to |
| 10650 | support automated patch testing. Each submitted patch is checked for common |
| 10651 | mistakes and deviations from the expected patch format and submitters are |
| 10652 | notified by patchtest if such mistakes are found. This process helps to |
| 10653 | reduce the burden of patch review on maintainers. |
| 10654 | |
| 10655 | .. note:: |
| 10656 | |
| 10657 | This system is imperfect and changes can sometimes get lost in the flow. |
| 10658 | Asking about the status of a patch or change is reasonable if the change |
| 10659 | has been idle for a while with no feedback. |
| 10660 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10661 | Using Scripts to Push a Change Upstream and Request a Pull |
| 10662 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 10663 | |
| 10664 | For larger patch series it is preferable to send a pull request which not |
| 10665 | only includes the patch but also a pointer to a branch that can be pulled |
| 10666 | from. This involves making a local branch for your changes, pushing this |
| 10667 | branch to an accessible repository and then using the ``create-pull-request`` |
| 10668 | and ``send-pull-request`` scripts from openembedded-core to create and send a |
| 10669 | patch series with a link to the branch for review. |
| 10670 | |
| 10671 | Follow this procedure to push a change to an upstream "contrib" Git |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 10672 | repository once the steps in :ref:`dev-manual/common-tasks:preparing changes for submission` have |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10673 | been followed: |
| 10674 | |
| 10675 | .. note:: |
| 10676 | |
| 10677 | You can find general Git information on how to push a change upstream |
| 10678 | in the |
| 10679 | `Git Community Book <https://git-scm.com/book/en/v2/Distributed-Git-Distributed-Workflows>`__. |
| 10680 | |
| 10681 | 1. *Push Your Commits to a "Contrib" Upstream:* If you have arranged for |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10682 | permissions to push to an upstream contrib repository, push the |
| 10683 | change to that repository: |
| 10684 | :: |
| 10685 | |
| 10686 | $ git push upstream_remote_repo local_branch_name |
| 10687 | |
| 10688 | For example, suppose you have permissions to push |
| 10689 | into the upstream ``meta-intel-contrib`` repository and you are |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10690 | working in a local branch named `your_name`\ ``/README``. The following |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10691 | command pushes your local commits to the ``meta-intel-contrib`` |
| 10692 | upstream repository and puts the commit in a branch named |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10693 | `your_name`\ ``/README``: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10694 | :: |
| 10695 | |
| 10696 | $ git push meta-intel-contrib your_name/README |
| 10697 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10698 | 2. *Determine Who to Notify:* Determine the maintainer or the mailing |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10699 | list that you need to notify for the change. |
| 10700 | |
| 10701 | Before submitting any change, you need to be sure who the maintainer |
| 10702 | is or what mailing list that you need to notify. Use either these |
| 10703 | methods to find out: |
| 10704 | |
| 10705 | - *Maintenance File:* Examine the ``maintainers.inc`` file, which is |
| 10706 | located in the :term:`Source Directory` at |
| 10707 | ``meta/conf/distro/include``, to see who is responsible for code. |
| 10708 | |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 10709 | - *Search by File:* Using :ref:`overview-manual/development-environment:git`, you can |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10710 | enter the following command to bring up a short list of all |
| 10711 | commits against a specific file: |
| 10712 | :: |
| 10713 | |
| 10714 | git shortlog -- filename |
| 10715 | |
| 10716 | Just provide the name of the file for which you are interested. The |
| 10717 | information returned is not ordered by history but does include a |
| 10718 | list of everyone who has committed grouped by name. From the list, |
| 10719 | you can see who is responsible for the bulk of the changes against |
| 10720 | the file. |
| 10721 | |
| 10722 | - *Examine the List of Mailing Lists:* For a list of the Yocto |
| 10723 | Project and related mailing lists, see the ":ref:`Mailing |
| 10724 | lists <resources-mailinglist>`" section in |
| 10725 | the Yocto Project Reference Manual. |
| 10726 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10727 | 3. *Make a Pull Request:* Notify the maintainer or the mailing list that |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10728 | you have pushed a change by making a pull request. |
| 10729 | |
| 10730 | The Yocto Project provides two scripts that conveniently let you |
| 10731 | generate and send pull requests to the Yocto Project. These scripts |
| 10732 | are ``create-pull-request`` and ``send-pull-request``. You can find |
| 10733 | these scripts in the ``scripts`` directory within the |
| 10734 | :term:`Source Directory` (e.g. |
| 10735 | ``~/poky/scripts``). |
| 10736 | |
| 10737 | Using these scripts correctly formats the requests without |
| 10738 | introducing any whitespace or HTML formatting. The maintainer that |
| 10739 | receives your patches either directly or through the mailing list |
| 10740 | needs to be able to save and apply them directly from your emails. |
| 10741 | Using these scripts is the preferred method for sending patches. |
| 10742 | |
| 10743 | First, create the pull request. For example, the following command |
| 10744 | runs the script, specifies the upstream repository in the contrib |
| 10745 | directory into which you pushed the change, and provides a subject |
| 10746 | line in the created patch files: |
| 10747 | :: |
| 10748 | |
| 10749 | $ ~/poky/scripts/create-pull-request -u meta-intel-contrib -s "Updated Manual Section Reference in README" |
| 10750 | |
| 10751 | Running this script forms ``*.patch`` files in a folder named |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10752 | ``pull-``\ `PID` in the current directory. One of the patch files is a |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10753 | cover letter. |
| 10754 | |
| 10755 | Before running the ``send-pull-request`` script, you must edit the |
| 10756 | cover letter patch to insert information about your change. After |
| 10757 | editing the cover letter, send the pull request. For example, the |
| 10758 | following command runs the script and specifies the patch directory |
| 10759 | and email address. In this example, the email address is a mailing |
| 10760 | list: |
| 10761 | :: |
| 10762 | |
| 10763 | $ ~/poky/scripts/send-pull-request -p ~/meta-intel/pull-10565 -t meta-intel@yoctoproject.org |
| 10764 | |
| 10765 | You need to follow the prompts as the script is interactive. |
| 10766 | |
| 10767 | .. note:: |
| 10768 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10769 | For help on using these scripts, simply provide the ``-h`` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10770 | argument as follows: |
| 10771 | :: |
| 10772 | |
| 10773 | $ poky/scripts/create-pull-request -h |
| 10774 | $ poky/scripts/send-pull-request -h |
| 10775 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10776 | Responding to Patch Review |
| 10777 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10778 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10779 | You may get feedback on your submitted patches from other community members |
| 10780 | or from the automated patchtest service. If issues are identified in your |
| 10781 | patch then it is usually necessary to address these before the patch will be |
| 10782 | accepted into the project. In this case you should amend the patch according |
| 10783 | to the feedback and submit an updated version to the relevant mailing list, |
| 10784 | copying in the reviewers who provided feedback to the previous version of the |
| 10785 | patch. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10786 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10787 | The patch should be amended using ``git commit --amend`` or perhaps ``git |
| 10788 | rebase`` for more expert git users. You should also modify the ``[PATCH]`` |
| 10789 | tag in the email subject line when sending the revised patch to mark the new |
| 10790 | iteration as ``[PATCH v2]``, ``[PATCH v3]``, etc as appropriate. This can be |
| 10791 | done by passing the ``-v`` argument to ``git format-patch`` with a version |
| 10792 | number. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10793 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10794 | Lastly please ensure that you also test your revised changes. In particular |
| 10795 | please don't just edit the patch file written out by ``git format-patch`` and |
| 10796 | resend it. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10797 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10798 | Submitting Changes to Stable Release Branches |
| 10799 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10800 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10801 | The process for proposing changes to a Yocto Project stable branch differs |
| 10802 | from the steps described above. Changes to a stable branch must address |
| 10803 | identified bugs or CVEs and should be made carefully in order to avoid the |
| 10804 | risk of introducing new bugs or breaking backwards compatibility. Typically |
| 10805 | bug fixes must already be accepted into the master branch before they can be |
| 10806 | backported to a stable branch unless the bug in question does not affect the |
| 10807 | master branch or the fix on the master branch is unsuitable for backporting. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10808 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10809 | The list of stable branches along with the status and maintainer for each |
| 10810 | branch can be obtained from the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 10811 | :yocto_wiki:`Releases wiki page </Releases>`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10812 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10813 | .. note:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10814 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10815 | Changes will not typically be accepted for branches which are marked as |
| 10816 | End-Of-Life (EOL). |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10817 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10818 | With this in mind, the steps to submit a change for a stable branch are as |
| 10819 | follows: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10820 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10821 | 1. *Identify the bug or CVE to be fixed:* This information should be |
| 10822 | collected so that it can be included in your submission. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10823 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10824 | 2. *Check if the fix is already present in the master branch:* This will |
| 10825 | result in the most straightforward path into the stable branch for the |
| 10826 | fix. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10827 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10828 | a. *If the fix is present in the master branch - Submit a backport request |
| 10829 | by email:* You should send an email to the relevant stable branch |
| 10830 | maintainer and the mailing list with details of the bug or CVE to be |
| 10831 | fixed, the commit hash on the master branch that fixes the issue and |
| 10832 | the stable branches which you would like this fix to be backported to. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10833 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10834 | b. *If the fix is not present in the master branch - Submit the fix to the |
| 10835 | master branch first:* This will ensure that the fix passes through the |
| 10836 | project's usual patch review and test processes before being accepted. |
| 10837 | It will also ensure that bugs are not left unresolved in the master |
| 10838 | branch itself. Once the fix is accepted in the master branch a backport |
| 10839 | request can be submitted as above. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10840 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10841 | c. *If the fix is unsuitable for the master branch - Submit a patch |
| 10842 | directly for the stable branch:* This method should be considered as a |
| 10843 | last resort. It is typically necessary when the master branch is using |
| 10844 | a newer version of the software which includes an upstream fix for the |
| 10845 | issue or when the issue has been fixed on the master branch in a way |
| 10846 | that introduces backwards incompatible changes. In this case follow the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 10847 | steps in :ref:`dev-manual/common-tasks:preparing changes for submission` and |
| 10848 | :ref:`dev-manual/common-tasks:using email to submit a patch` but modify the subject header of your patch |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10849 | email to include the name of the stable branch which you are |
| 10850 | targetting. This can be done using the ``--subject-prefix`` argument to |
| 10851 | ``git format-patch``, for example to submit a patch to the dunfell |
| 10852 | branch use |
| 10853 | ``git format-patch --subject-prefix='&DISTRO_NAME_NO_CAP_MINUS_ONE;][PATCH' ...``. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10854 | |
| 10855 | Working With Licenses |
| 10856 | ===================== |
| 10857 | |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 10858 | As mentioned in the ":ref:`overview-manual/development-environment:licensing`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10859 | section in the Yocto Project Overview and Concepts Manual, open source |
| 10860 | projects are open to the public and they consequently have different |
| 10861 | licensing structures in place. This section describes the mechanism by |
| 10862 | which the :term:`OpenEmbedded Build System` |
| 10863 | tracks changes to |
| 10864 | licensing text and covers how to maintain open source license compliance |
| 10865 | during your project's lifecycle. The section also describes how to |
| 10866 | enable commercially licensed recipes, which by default are disabled. |
| 10867 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10868 | Tracking License Changes |
| 10869 | ------------------------ |
| 10870 | |
| 10871 | The license of an upstream project might change in the future. In order |
| 10872 | to prevent these changes going unnoticed, the |
| 10873 | :term:`LIC_FILES_CHKSUM` |
| 10874 | variable tracks changes to the license text. The checksums are validated |
| 10875 | at the end of the configure step, and if the checksums do not match, the |
| 10876 | build will fail. |
| 10877 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10878 | Specifying the ``LIC_FILES_CHKSUM`` Variable |
| 10879 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 10880 | |
| 10881 | The ``LIC_FILES_CHKSUM`` variable contains checksums of the license text |
| 10882 | in the source code for the recipe. Following is an example of how to |
| 10883 | specify ``LIC_FILES_CHKSUM``: |
| 10884 | :: |
| 10885 | |
| 10886 | LIC_FILES_CHKSUM = "file://COPYING;md5=xxxx \ |
| 10887 | file://licfile1.txt;beginline=5;endline=29;md5=yyyy \ |
| 10888 | file://licfile2.txt;endline=50;md5=zzzz \ |
| 10889 | ..." |
| 10890 | |
| 10891 | .. note:: |
| 10892 | |
| 10893 | - When using "beginline" and "endline", realize that line numbering |
| 10894 | begins with one and not zero. Also, the included lines are |
| 10895 | inclusive (i.e. lines five through and including 29 in the |
| 10896 | previous example for ``licfile1.txt``). |
| 10897 | |
| 10898 | - When a license check fails, the selected license text is included |
| 10899 | as part of the QA message. Using this output, you can determine |
| 10900 | the exact start and finish for the needed license text. |
| 10901 | |
| 10902 | The build system uses the :term:`S` |
| 10903 | variable as the default directory when searching files listed in |
| 10904 | ``LIC_FILES_CHKSUM``. The previous example employs the default |
| 10905 | directory. |
| 10906 | |
| 10907 | Consider this next example: |
| 10908 | :: |
| 10909 | |
| 10910 | LIC_FILES_CHKSUM = "file://src/ls.c;beginline=5;endline=16;\ |
| 10911 | md5=bb14ed3c4cda583abc85401304b5cd4e" |
| 10912 | LIC_FILES_CHKSUM = "file://${WORKDIR}/license.html;md5=5c94767cedb5d6987c902ac850ded2c6" |
| 10913 | |
| 10914 | The first line locates a file in ``${S}/src/ls.c`` and isolates lines |
| 10915 | five through 16 as license text. The second line refers to a file in |
| 10916 | :term:`WORKDIR`. |
| 10917 | |
| 10918 | Note that ``LIC_FILES_CHKSUM`` variable is mandatory for all recipes, |
| 10919 | unless the ``LICENSE`` variable is set to "CLOSED". |
| 10920 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10921 | Explanation of Syntax |
| 10922 | ~~~~~~~~~~~~~~~~~~~~~ |
| 10923 | |
| 10924 | As mentioned in the previous section, the ``LIC_FILES_CHKSUM`` variable |
| 10925 | lists all the important files that contain the license text for the |
| 10926 | source code. It is possible to specify a checksum for an entire file, or |
| 10927 | a specific section of a file (specified by beginning and ending line |
| 10928 | numbers with the "beginline" and "endline" parameters, respectively). |
| 10929 | The latter is useful for source files with a license notice header, |
| 10930 | README documents, and so forth. If you do not use the "beginline" |
| 10931 | parameter, then it is assumed that the text begins on the first line of |
| 10932 | the file. Similarly, if you do not use the "endline" parameter, it is |
| 10933 | assumed that the license text ends with the last line of the file. |
| 10934 | |
| 10935 | The "md5" parameter stores the md5 checksum of the license text. If the |
| 10936 | license text changes in any way as compared to this parameter then a |
| 10937 | mismatch occurs. This mismatch triggers a build failure and notifies the |
| 10938 | developer. Notification allows the developer to review and address the |
| 10939 | license text changes. Also note that if a mismatch occurs during the |
| 10940 | build, the correct md5 checksum is placed in the build log and can be |
| 10941 | easily copied to the recipe. |
| 10942 | |
| 10943 | There is no limit to how many files you can specify using the |
| 10944 | ``LIC_FILES_CHKSUM`` variable. Generally, however, every project |
| 10945 | requires a few specifications for license tracking. Many projects have a |
| 10946 | "COPYING" file that stores the license information for all the source |
| 10947 | code files. This practice allows you to just track the "COPYING" file as |
| 10948 | long as it is kept up to date. |
| 10949 | |
| 10950 | .. note:: |
| 10951 | |
| 10952 | - If you specify an empty or invalid "md5" parameter, |
| 10953 | :term:`BitBake` returns an md5 |
| 10954 | mis-match error and displays the correct "md5" parameter value |
| 10955 | during the build. The correct parameter is also captured in the |
| 10956 | build log. |
| 10957 | |
| 10958 | - If the whole file contains only license text, you do not need to |
| 10959 | use the "beginline" and "endline" parameters. |
| 10960 | |
| 10961 | Enabling Commercially Licensed Recipes |
| 10962 | -------------------------------------- |
| 10963 | |
| 10964 | By default, the OpenEmbedded build system disables components that have |
| 10965 | commercial or other special licensing requirements. Such requirements |
| 10966 | are defined on a recipe-by-recipe basis through the |
| 10967 | :term:`LICENSE_FLAGS` variable |
| 10968 | definition in the affected recipe. For instance, the |
| 10969 | ``poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly`` recipe |
| 10970 | contains the following statement: |
| 10971 | :: |
| 10972 | |
| 10973 | LICENSE_FLAGS = "commercial" |
| 10974 | |
| 10975 | Here is a |
| 10976 | slightly more complicated example that contains both an explicit recipe |
| 10977 | name and version (after variable expansion): |
| 10978 | :: |
| 10979 | |
| 10980 | LICENSE_FLAGS = "license_${PN}_${PV}" |
| 10981 | |
| 10982 | In order for a component restricted by a |
| 10983 | ``LICENSE_FLAGS`` definition to be enabled and included in an image, it |
| 10984 | needs to have a matching entry in the global |
| 10985 | :term:`LICENSE_FLAGS_WHITELIST` |
| 10986 | variable, which is a variable typically defined in your ``local.conf`` |
| 10987 | file. For example, to enable the |
| 10988 | ``poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly`` package, you |
| 10989 | could add either the string "commercial_gst-plugins-ugly" or the more |
| 10990 | general string "commercial" to ``LICENSE_FLAGS_WHITELIST``. See the |
| 10991 | "`License Flag Matching <#license-flag-matching>`__" section for a full |
| 10992 | explanation of how ``LICENSE_FLAGS`` matching works. Here is the |
| 10993 | example: |
| 10994 | :: |
| 10995 | |
| 10996 | LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly" |
| 10997 | |
| 10998 | Likewise, to additionally enable the package built from the recipe |
| 10999 | containing ``LICENSE_FLAGS = "license_${PN}_${PV}"``, and assuming that |
| 11000 | the actual recipe name was ``emgd_1.10.bb``, the following string would |
| 11001 | enable that package as well as the original ``gst-plugins-ugly`` |
| 11002 | package: |
| 11003 | :: |
| 11004 | |
| 11005 | LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly license_emgd_1.10" |
| 11006 | |
| 11007 | As a convenience, you do not need to specify the |
| 11008 | complete license string in the whitelist for every package. You can use |
| 11009 | an abbreviated form, which consists of just the first portion or |
| 11010 | portions of the license string before the initial underscore character |
| 11011 | or characters. A partial string will match any license that contains the |
| 11012 | given string as the first portion of its license. For example, the |
| 11013 | following whitelist string will also match both of the packages |
| 11014 | previously mentioned as well as any other packages that have licenses |
| 11015 | starting with "commercial" or "license". |
| 11016 | :: |
| 11017 | |
| 11018 | LICENSE_FLAGS_WHITELIST = "commercial license" |
| 11019 | |
| 11020 | License Flag Matching |
| 11021 | ~~~~~~~~~~~~~~~~~~~~~ |
| 11022 | |
| 11023 | License flag matching allows you to control what recipes the |
| 11024 | OpenEmbedded build system includes in the build. Fundamentally, the |
| 11025 | build system attempts to match ``LICENSE_FLAGS`` strings found in |
| 11026 | recipes against ``LICENSE_FLAGS_WHITELIST`` strings found in the |
| 11027 | whitelist. A match causes the build system to include a recipe in the |
| 11028 | build, while failure to find a match causes the build system to exclude |
| 11029 | a recipe. |
| 11030 | |
| 11031 | In general, license flag matching is simple. However, understanding some |
| 11032 | concepts will help you correctly and effectively use matching. |
| 11033 | |
| 11034 | Before a flag defined by a particular recipe is tested against the |
| 11035 | contents of the whitelist, the expanded string ``_${PN}`` is appended to |
| 11036 | the flag. This expansion makes each ``LICENSE_FLAGS`` value |
| 11037 | recipe-specific. After expansion, the string is then matched against the |
| 11038 | whitelist. Thus, specifying ``LICENSE_FLAGS = "commercial"`` in recipe |
| 11039 | "foo", for example, results in the string ``"commercial_foo"``. And, to |
| 11040 | create a match, that string must appear in the whitelist. |
| 11041 | |
| 11042 | Judicious use of the ``LICENSE_FLAGS`` strings and the contents of the |
| 11043 | ``LICENSE_FLAGS_WHITELIST`` variable allows you a lot of flexibility for |
| 11044 | including or excluding recipes based on licensing. For example, you can |
| 11045 | broaden the matching capabilities by using license flags string subsets |
| 11046 | in the whitelist. |
| 11047 | |
| 11048 | .. note:: |
| 11049 | |
| 11050 | When using a string subset, be sure to use the part of the expanded |
| 11051 | string that precedes the appended underscore character (e.g. |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 11052 | ``usethispart_1.3``, ``usethispart_1.4``, and so forth). |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11053 | |
| 11054 | For example, simply specifying the string "commercial" in the whitelist |
| 11055 | matches any expanded ``LICENSE_FLAGS`` definition that starts with the |
| 11056 | string "commercial" such as "commercial_foo" and "commercial_bar", which |
| 11057 | are the strings the build system automatically generates for |
| 11058 | hypothetical recipes named "foo" and "bar" assuming those recipes simply |
| 11059 | specify the following: |
| 11060 | :: |
| 11061 | |
| 11062 | LICENSE_FLAGS = "commercial" |
| 11063 | |
| 11064 | Thus, you can choose |
| 11065 | to exhaustively enumerate each license flag in the whitelist and allow |
| 11066 | only specific recipes into the image, or you can use a string subset |
| 11067 | that causes a broader range of matches to allow a range of recipes into |
| 11068 | the image. |
| 11069 | |
| 11070 | This scheme works even if the ``LICENSE_FLAGS`` string already has |
| 11071 | ``_${PN}`` appended. For example, the build system turns the license |
| 11072 | flag "commercial_1.2_foo" into "commercial_1.2_foo_foo" and would match |
| 11073 | both the general "commercial" and the specific "commercial_1.2_foo" |
| 11074 | strings found in the whitelist, as expected. |
| 11075 | |
| 11076 | Here are some other scenarios: |
| 11077 | |
| 11078 | - You can specify a versioned string in the recipe such as |
| 11079 | "commercial_foo_1.2" in a "foo" recipe. The build system expands this |
| 11080 | string to "commercial_foo_1.2_foo". Combine this license flag with a |
| 11081 | whitelist that has the string "commercial" and you match the flag |
| 11082 | along with any other flag that starts with the string "commercial". |
| 11083 | |
| 11084 | - Under the same circumstances, you can use "commercial_foo" in the |
| 11085 | whitelist and the build system not only matches "commercial_foo_1.2" |
| 11086 | but also matches any license flag with the string "commercial_foo", |
| 11087 | regardless of the version. |
| 11088 | |
| 11089 | - You can be very specific and use both the package and version parts |
| 11090 | in the whitelist (e.g. "commercial_foo_1.2") to specifically match a |
| 11091 | versioned recipe. |
| 11092 | |
| 11093 | Other Variables Related to Commercial Licenses |
| 11094 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 11095 | |
| 11096 | Other helpful variables related to commercial license handling exist and |
| 11097 | are defined in the |
| 11098 | ``poky/meta/conf/distro/include/default-distrovars.inc`` file: |
| 11099 | :: |
| 11100 | |
| 11101 | COMMERCIAL_AUDIO_PLUGINS ?= "" |
| 11102 | COMMERCIAL_VIDEO_PLUGINS ?= "" |
| 11103 | |
| 11104 | If you |
| 11105 | want to enable these components, you can do so by making sure you have |
| 11106 | statements similar to the following in your ``local.conf`` configuration |
| 11107 | file: |
| 11108 | :: |
| 11109 | |
| 11110 | COMMERCIAL_AUDIO_PLUGINS = "gst-plugins-ugly-mad \ |
| 11111 | gst-plugins-ugly-mpegaudioparse" |
| 11112 | COMMERCIAL_VIDEO_PLUGINS = "gst-plugins-ugly-mpeg2dec \ |
| 11113 | gst-plugins-ugly-mpegstream gst-plugins-bad-mpegvideoparse" |
| 11114 | LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly commercial_gst-plugins-bad commercial_qmmp" |
| 11115 | |
| 11116 | |
| 11117 | Of course, you could also create a matching whitelist for those |
| 11118 | components using the more general "commercial" in the whitelist, but |
| 11119 | that would also enable all the other packages with ``LICENSE_FLAGS`` |
| 11120 | containing "commercial", which you may or may not want: |
| 11121 | :: |
| 11122 | |
| 11123 | LICENSE_FLAGS_WHITELIST = "commercial" |
| 11124 | |
| 11125 | Specifying audio and video plugins as part of the |
| 11126 | ``COMMERCIAL_AUDIO_PLUGINS`` and ``COMMERCIAL_VIDEO_PLUGINS`` statements |
| 11127 | (along with the enabling ``LICENSE_FLAGS_WHITELIST``) includes the |
| 11128 | plugins or components into built images, thus adding support for media |
| 11129 | formats or components. |
| 11130 | |
| 11131 | Maintaining Open Source License Compliance During Your Product's Lifecycle |
| 11132 | -------------------------------------------------------------------------- |
| 11133 | |
| 11134 | One of the concerns for a development organization using open source |
| 11135 | software is how to maintain compliance with various open source |
| 11136 | licensing during the lifecycle of the product. While this section does |
| 11137 | not provide legal advice or comprehensively cover all scenarios, it does |
| 11138 | present methods that you can use to assist you in meeting the compliance |
| 11139 | requirements during a software release. |
| 11140 | |
| 11141 | With hundreds of different open source licenses that the Yocto Project |
| 11142 | tracks, it is difficult to know the requirements of each and every |
| 11143 | license. However, the requirements of the major FLOSS licenses can begin |
| 11144 | to be covered by assuming that three main areas of concern exist: |
| 11145 | |
| 11146 | - Source code must be provided. |
| 11147 | |
| 11148 | - License text for the software must be provided. |
| 11149 | |
| 11150 | - Compilation scripts and modifications to the source code must be |
| 11151 | provided. |
| 11152 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 11153 | - spdx files can be provided. |
| 11154 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11155 | There are other requirements beyond the scope of these three and the |
| 11156 | methods described in this section (e.g. the mechanism through which |
| 11157 | source code is distributed). |
| 11158 | |
| 11159 | As different organizations have different methods of complying with open |
| 11160 | source licensing, this section is not meant to imply that there is only |
| 11161 | one single way to meet your compliance obligations, but rather to |
| 11162 | describe one method of achieving compliance. The remainder of this |
| 11163 | section describes methods supported to meet the previously mentioned |
| 11164 | three requirements. Once you take steps to meet these requirements, and |
| 11165 | prior to releasing images, sources, and the build system, you should |
| 11166 | audit all artifacts to ensure completeness. |
| 11167 | |
| 11168 | .. note:: |
| 11169 | |
| 11170 | The Yocto Project generates a license manifest during image creation |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 11171 | that is located in ``${DEPLOY_DIR}/licenses/``\ `image_name`\ ``-``\ `datestamp` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11172 | to assist with any audits. |
| 11173 | |
| 11174 | Providing the Source Code |
| 11175 | ~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 11176 | |
| 11177 | Compliance activities should begin before you generate the final image. |
| 11178 | The first thing you should look at is the requirement that tops the list |
| 11179 | for most compliance groups - providing the source. The Yocto Project has |
| 11180 | a few ways of meeting this requirement. |
| 11181 | |
| 11182 | One of the easiest ways to meet this requirement is to provide the |
| 11183 | entire :term:`DL_DIR` used by the |
| 11184 | build. This method, however, has a few issues. The most obvious is the |
| 11185 | size of the directory since it includes all sources used in the build |
| 11186 | and not just the source used in the released image. It will include |
| 11187 | toolchain source, and other artifacts, which you would not generally |
| 11188 | release. However, the more serious issue for most companies is |
| 11189 | accidental release of proprietary software. The Yocto Project provides |
| 11190 | an :ref:`archiver <ref-classes-archiver>` class to |
| 11191 | help avoid some of these concerns. |
| 11192 | |
| 11193 | Before you employ ``DL_DIR`` or the ``archiver`` class, you need to |
| 11194 | decide how you choose to provide source. The source ``archiver`` class |
| 11195 | can generate tarballs and SRPMs and can create them with various levels |
| 11196 | of compliance in mind. |
| 11197 | |
| 11198 | One way of doing this (but certainly not the only way) is to release |
| 11199 | just the source as a tarball. You can do this by adding the following to |
| 11200 | the ``local.conf`` file found in the |
| 11201 | :term:`Build Directory`: |
| 11202 | :: |
| 11203 | |
| 11204 | INHERIT += "archiver" |
| 11205 | ARCHIVER_MODE[src] = "original" |
| 11206 | |
| 11207 | During the creation of your |
| 11208 | image, the source from all recipes that deploy packages to the image is |
| 11209 | placed within subdirectories of ``DEPLOY_DIR/sources`` based on the |
| 11210 | :term:`LICENSE` for each recipe. |
| 11211 | Releasing the entire directory enables you to comply with requirements |
| 11212 | concerning providing the unmodified source. It is important to note that |
| 11213 | the size of the directory can get large. |
| 11214 | |
| 11215 | A way to help mitigate the size issue is to only release tarballs for |
| 11216 | licenses that require the release of source. Let us assume you are only |
| 11217 | concerned with GPL code as identified by running the following script: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 11218 | |
| 11219 | .. code-block:: shell |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11220 | |
| 11221 | # Script to archive a subset of packages matching specific license(s) |
| 11222 | # Source and license files are copied into sub folders of package folder |
| 11223 | # Must be run from build folder |
| 11224 | #!/bin/bash |
| 11225 | src_release_dir="source-release" |
| 11226 | mkdir -p $src_release_dir |
| 11227 | for a in tmp/deploy/sources/*; do |
| 11228 | for d in $a/*; do |
| 11229 | # Get package name from path |
| 11230 | p=`basename $d` |
| 11231 | p=${p%-*} |
| 11232 | p=${p%-*} |
| 11233 | # Only archive GPL packages (update *GPL* regex for your license check) |
| 11234 | numfiles=`ls tmp/deploy/licenses/$p/*GPL* 2> /dev/null | wc -l` |
| 11235 | if [ $numfiles -gt 1 ]; then |
| 11236 | echo Archiving $p |
| 11237 | mkdir -p $src_release_dir/$p/source |
| 11238 | cp $d/* $src_release_dir/$p/source 2> /dev/null |
| 11239 | mkdir -p $src_release_dir/$p/license |
| 11240 | cp tmp/deploy/licenses/$p/* $src_release_dir/$p/license 2> /dev/null |
| 11241 | fi |
| 11242 | done |
| 11243 | done |
| 11244 | |
| 11245 | At this point, you |
| 11246 | could create a tarball from the ``gpl_source_release`` directory and |
| 11247 | provide that to the end user. This method would be a step toward |
| 11248 | achieving compliance with section 3a of GPLv2 and with section 6 of |
| 11249 | GPLv3. |
| 11250 | |
| 11251 | Providing License Text |
| 11252 | ~~~~~~~~~~~~~~~~~~~~~~ |
| 11253 | |
| 11254 | One requirement that is often overlooked is inclusion of license text. |
| 11255 | This requirement also needs to be dealt with prior to generating the |
| 11256 | final image. Some licenses require the license text to accompany the |
| 11257 | binary. You can achieve this by adding the following to your |
| 11258 | ``local.conf`` file: |
| 11259 | :: |
| 11260 | |
| 11261 | COPY_LIC_MANIFEST = "1" |
| 11262 | COPY_LIC_DIRS = "1" |
| 11263 | LICENSE_CREATE_PACKAGE = "1" |
| 11264 | |
| 11265 | Adding these statements to the |
| 11266 | configuration file ensures that the licenses collected during package |
| 11267 | generation are included on your image. |
| 11268 | |
| 11269 | .. note:: |
| 11270 | |
| 11271 | Setting all three variables to "1" results in the image having two |
| 11272 | copies of the same license file. One copy resides in |
| 11273 | ``/usr/share/common-licenses`` and the other resides in |
| 11274 | ``/usr/share/license``. |
| 11275 | |
| 11276 | The reason for this behavior is because |
| 11277 | :term:`COPY_LIC_DIRS` and |
| 11278 | :term:`COPY_LIC_MANIFEST` |
| 11279 | add a copy of the license when the image is built but do not offer a |
| 11280 | path for adding licenses for newly installed packages to an image. |
| 11281 | :term:`LICENSE_CREATE_PACKAGE` |
| 11282 | adds a separate package and an upgrade path for adding licenses to an |
| 11283 | image. |
| 11284 | |
| 11285 | As the source ``archiver`` class has already archived the original |
| 11286 | unmodified source that contains the license files, you would have |
| 11287 | already met the requirements for inclusion of the license information |
| 11288 | with source as defined by the GPL and other open source licenses. |
| 11289 | |
| 11290 | Providing Compilation Scripts and Source Code Modifications |
| 11291 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 11292 | |
| 11293 | At this point, we have addressed all we need to prior to generating the |
| 11294 | image. The next two requirements are addressed during the final |
| 11295 | packaging of the release. |
| 11296 | |
| 11297 | By releasing the version of the OpenEmbedded build system and the layers |
| 11298 | used during the build, you will be providing both compilation scripts |
| 11299 | and the source code modifications in one step. |
| 11300 | |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 11301 | If the deployment team has a :ref:`overview-manual/concepts:bsp layer` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11302 | and a distro layer, and those |
| 11303 | those layers are used to patch, compile, package, or modify (in any way) |
| 11304 | any open source software included in your released images, you might be |
| 11305 | required to release those layers under section 3 of GPLv2 or section 1 |
| 11306 | of GPLv3. One way of doing that is with a clean checkout of the version |
| 11307 | of the Yocto Project and layers used during your build. Here is an |
| 11308 | example: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 11309 | |
| 11310 | .. code-block:: shell |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11311 | |
| 11312 | # We built using the dunfell branch of the poky repo |
| 11313 | $ git clone -b dunfell git://git.yoctoproject.org/poky |
| 11314 | $ cd poky |
| 11315 | # We built using the release_branch for our layers |
| 11316 | $ git clone -b release_branch git://git.mycompany.com/meta-my-bsp-layer |
| 11317 | $ git clone -b release_branch git://git.mycompany.com/meta-my-software-layer |
| 11318 | # clean up the .git repos |
| 11319 | $ find . -name ".git" -type d -exec rm -rf {} \; |
| 11320 | |
| 11321 | One |
| 11322 | thing a development organization might want to consider for end-user |
| 11323 | convenience is to modify ``meta-poky/conf/bblayers.conf.sample`` to |
| 11324 | ensure that when the end user utilizes the released build system to |
| 11325 | build an image, the development organization's layers are included in |
| 11326 | the ``bblayers.conf`` file automatically: |
| 11327 | :: |
| 11328 | |
| 11329 | # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf |
| 11330 | # changes incompatibly |
| 11331 | POKY_BBLAYERS_CONF_VERSION = "2" |
| 11332 | |
| 11333 | BBPATH = "${TOPDIR}" |
| 11334 | BBFILES ?= "" |
| 11335 | |
| 11336 | BBLAYERS ?= " \ |
| 11337 | ##OEROOT##/meta \ |
| 11338 | ##OEROOT##/meta-poky \ |
| 11339 | ##OEROOT##/meta-yocto-bsp \ |
| 11340 | ##OEROOT##/meta-mylayer \ |
| 11341 | " |
| 11342 | |
| 11343 | Creating and |
| 11344 | providing an archive of the :term:`Metadata` |
| 11345 | layers (recipes, configuration files, and so forth) enables you to meet |
| 11346 | your requirements to include the scripts to control compilation as well |
| 11347 | as any modifications to the original source. |
| 11348 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 11349 | Providing spdx files |
| 11350 | ~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 11351 | |
| 11352 | The spdx module has been integrated to a layer named meta-spdxscanner. |
| 11353 | meta-spdxscanner provides several kinds of scanner. If you want to enable |
| 11354 | this function, you have to follow the following steps: |
| 11355 | |
| 11356 | 1. Add meta-spdxscanner layer into ``bblayers.conf``. |
| 11357 | |
| 11358 | 2. Refer to the README in meta-spdxscanner to setup the environment (e.g, |
| 11359 | setup a fossology server) needed for the scanner. |
| 11360 | |
| 11361 | 3. Meta-spdxscanner provides several methods within the bbclass to create spdx files. |
| 11362 | Please choose one that you want to use and enable the spdx task. You have to |
| 11363 | add some config options in ``local.conf`` file in your :term:`Build |
| 11364 | Directory`. The following is an example showing how to generate spdx files |
| 11365 | during bitbake using the fossology-python.bbclass:: |
| 11366 | |
| 11367 | # Select fossology-python.bbclass. |
| 11368 | INHERIT += "fossology-python" |
| 11369 | # For fossology-python.bbclass, TOKEN is necessary, so, after setup a |
| 11370 | # Fossology server, you have to create a token. |
| 11371 | TOKEN = "eyJ0eXAiO..." |
| 11372 | # The fossology server is necessary for fossology-python.bbclass. |
| 11373 | FOSSOLOGY_SERVER = "http://xx.xx.xx.xx:8081/repo" |
| 11374 | # If you want to upload the source code to a special folder: |
| 11375 | FOLDER_NAME = "xxxx" //Optional |
| 11376 | # If you don't want to put spdx files in tmp/deploy/spdx, you can enable: |
| 11377 | SPDX_DEPLOY_DIR = "${DEPLOY_DIR}" //Optional |
| 11378 | |
| 11379 | For more usage information refer to :yocto_git:`the meta-spdxscanner repository |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 11380 | </meta-spdxscanner/>`. |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 11381 | |
| 11382 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11383 | Copying Licenses that Do Not Exist |
| 11384 | ---------------------------------- |
| 11385 | |
| 11386 | Some packages, such as the linux-firmware package, have many licenses |
| 11387 | that are not in any way common. You can avoid adding a lot of these |
| 11388 | types of common license files, which are only applicable to a specific |
| 11389 | package, by using the |
| 11390 | :term:`NO_GENERIC_LICENSE` |
| 11391 | variable. Using this variable also avoids QA errors when you use a |
| 11392 | non-common, non-CLOSED license in a recipe. |
| 11393 | |
| 11394 | The following is an example that uses the ``LICENSE.Abilis.txt`` file as |
| 11395 | the license from the fetched source: |
| 11396 | :: |
| 11397 | |
| 11398 | NO_GENERIC_LICENSE[Firmware-Abilis] = "LICENSE.Abilis.txt" |
| 11399 | |
| 11400 | Using the Error Reporting Tool |
| 11401 | ============================== |
| 11402 | |
| 11403 | The error reporting tool allows you to submit errors encountered during |
| 11404 | builds to a central database. Outside of the build environment, you can |
| 11405 | use a web interface to browse errors, view statistics, and query for |
| 11406 | errors. The tool works using a client-server system where the client |
| 11407 | portion is integrated with the installed Yocto Project |
| 11408 | :term:`Source Directory` (e.g. ``poky``). |
| 11409 | The server receives the information collected and saves it in a |
| 11410 | database. |
| 11411 | |
| 11412 | A live instance of the error reporting server exists at |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 11413 | https://errors.yoctoproject.org. This server exists so that when |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11414 | you want to get help with build failures, you can submit all of the |
| 11415 | information on the failure easily and then point to the URL in your bug |
| 11416 | report or send an email to the mailing list. |
| 11417 | |
| 11418 | .. note:: |
| 11419 | |
| 11420 | If you send error reports to this server, the reports become publicly |
| 11421 | visible. |
| 11422 | |
| 11423 | Enabling and Using the Tool |
| 11424 | --------------------------- |
| 11425 | |
| 11426 | By default, the error reporting tool is disabled. You can enable it by |
| 11427 | inheriting the |
| 11428 | :ref:`report-error <ref-classes-report-error>` |
| 11429 | class by adding the following statement to the end of your |
| 11430 | ``local.conf`` file in your |
| 11431 | :term:`Build Directory`. |
| 11432 | :: |
| 11433 | |
| 11434 | INHERIT += "report-error" |
| 11435 | |
| 11436 | By default, the error reporting feature stores information in |
| 11437 | ``${``\ :term:`LOG_DIR`\ ``}/error-report``. |
| 11438 | However, you can specify a directory to use by adding the following to |
| 11439 | your ``local.conf`` file: |
| 11440 | :: |
| 11441 | |
| 11442 | ERR_REPORT_DIR = "path" |
| 11443 | |
| 11444 | Enabling error |
| 11445 | reporting causes the build process to collect the errors and store them |
| 11446 | in a file as previously described. When the build system encounters an |
| 11447 | error, it includes a command as part of the console output. You can run |
| 11448 | the command to send the error file to the server. For example, the |
| 11449 | following command sends the errors to an upstream server: |
| 11450 | :: |
| 11451 | |
| 11452 | $ send-error-report /home/brandusa/project/poky/build/tmp/log/error-report/error_report_201403141617.txt |
| 11453 | |
| 11454 | In the previous example, the errors are sent to a public database |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 11455 | available at https://errors.yoctoproject.org, which is used by the |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11456 | entire community. If you specify a particular server, you can send the |
| 11457 | errors to a different database. Use the following command for more |
| 11458 | information on available options: |
| 11459 | :: |
| 11460 | |
| 11461 | $ send-error-report --help |
| 11462 | |
| 11463 | When sending the error file, you are prompted to review the data being |
| 11464 | sent as well as to provide a name and optional email address. Once you |
| 11465 | satisfy these prompts, the command returns a link from the server that |
| 11466 | corresponds to your entry in the database. For example, here is a |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 11467 | typical link: https://errors.yoctoproject.org/Errors/Details/9522/ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11468 | |
| 11469 | Following the link takes you to a web interface where you can browse, |
| 11470 | query the errors, and view statistics. |
| 11471 | |
| 11472 | Disabling the Tool |
| 11473 | ------------------ |
| 11474 | |
| 11475 | To disable the error reporting feature, simply remove or comment out the |
| 11476 | following statement from the end of your ``local.conf`` file in your |
| 11477 | :term:`Build Directory`. |
| 11478 | :: |
| 11479 | |
| 11480 | INHERIT += "report-error" |
| 11481 | |
| 11482 | Setting Up Your Own Error Reporting Server |
| 11483 | ------------------------------------------ |
| 11484 | |
| 11485 | If you want to set up your own error reporting server, you can obtain |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 11486 | the code from the Git repository at :yocto_git:`/error-report-web/`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11487 | Instructions on how to set it up are in the README document. |
| 11488 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11489 | Using Wayland and Weston |
| 11490 | ======================== |
| 11491 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 11492 | `Wayland <https://en.wikipedia.org/wiki/Wayland_(display_server_protocol)>`__ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11493 | is a computer display server protocol that provides a method for |
| 11494 | compositing window managers to communicate directly with applications |
| 11495 | and video hardware and expects them to communicate with input hardware |
| 11496 | using other libraries. Using Wayland with supporting targets can result |
| 11497 | in better control over graphics frame rendering than an application |
| 11498 | might otherwise achieve. |
| 11499 | |
| 11500 | The Yocto Project provides the Wayland protocol libraries and the |
| 11501 | reference |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 11502 | `Weston <https://en.wikipedia.org/wiki/Wayland_(display_server_protocol)#Weston>`__ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11503 | compositor as part of its release. You can find the integrated packages |
| 11504 | in the ``meta`` layer of the :term:`Source Directory`. |
| 11505 | Specifically, you |
| 11506 | can find the recipes that build both Wayland and Weston at |
| 11507 | ``meta/recipes-graphics/wayland``. |
| 11508 | |
| 11509 | You can build both the Wayland and Weston packages for use only with |
| 11510 | targets that accept the `Mesa 3D and Direct Rendering |
| 11511 | Infrastructure <https://en.wikipedia.org/wiki/Mesa_(computer_graphics)>`__, |
| 11512 | which is also known as Mesa DRI. This implies that you cannot build and |
| 11513 | use the packages if your target uses, for example, the Intel Embedded |
| 11514 | Media and Graphics Driver (Intel EMGD) that overrides Mesa DRI. |
| 11515 | |
| 11516 | .. note:: |
| 11517 | |
| 11518 | Due to lack of EGL support, Weston 1.0.3 will not run directly on the |
| 11519 | emulated QEMU hardware. However, this version of Weston will run |
| 11520 | under X emulation without issues. |
| 11521 | |
| 11522 | This section describes what you need to do to implement Wayland and use |
| 11523 | the Weston compositor when building an image for a supporting target. |
| 11524 | |
| 11525 | Enabling Wayland in an Image |
| 11526 | ---------------------------- |
| 11527 | |
| 11528 | To enable Wayland, you need to enable it to be built and enable it to be |
| 11529 | included (installed) in the image. |
| 11530 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11531 | Building Wayland |
| 11532 | ~~~~~~~~~~~~~~~~ |
| 11533 | |
| 11534 | To cause Mesa to build the ``wayland-egl`` platform and Weston to build |
| 11535 | Wayland with Kernel Mode Setting |
| 11536 | (`KMS <https://wiki.archlinux.org/index.php/Kernel_Mode_Setting>`__) |
| 11537 | support, include the "wayland" flag in the |
| 11538 | :term:`DISTRO_FEATURES` |
| 11539 | statement in your ``local.conf`` file: |
| 11540 | :: |
| 11541 | |
| 11542 | DISTRO_FEATURES_append = " wayland" |
| 11543 | |
| 11544 | .. note:: |
| 11545 | |
| 11546 | If X11 has been enabled elsewhere, Weston will build Wayland with X11 |
| 11547 | support |
| 11548 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11549 | Installing Wayland and Weston |
| 11550 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 11551 | |
| 11552 | To install the Wayland feature into an image, you must include the |
| 11553 | following |
| 11554 | :term:`CORE_IMAGE_EXTRA_INSTALL` |
| 11555 | statement in your ``local.conf`` file: |
| 11556 | :: |
| 11557 | |
| 11558 | CORE_IMAGE_EXTRA_INSTALL += "wayland weston" |
| 11559 | |
| 11560 | Running Weston |
| 11561 | -------------- |
| 11562 | |
| 11563 | To run Weston inside X11, enabling it as described earlier and building |
| 11564 | a Sato image is sufficient. If you are running your image under Sato, a |
| 11565 | Weston Launcher appears in the "Utility" category. |
| 11566 | |
| 11567 | Alternatively, you can run Weston through the command-line interpretor |
| 11568 | (CLI), which is better suited for development work. To run Weston under |
| 11569 | the CLI, you need to do the following after your image is built: |
| 11570 | |
| 11571 | 1. Run these commands to export ``XDG_RUNTIME_DIR``: |
| 11572 | :: |
| 11573 | |
| 11574 | mkdir -p /tmp/$USER-weston |
| 11575 | chmod 0700 /tmp/$USER-weston |
| 11576 | export XDG_RUNTIME_DIR=/tmp/$USER-weston |
| 11577 | |
| 11578 | 2. Launch Weston in the shell: |
| 11579 | :: |
| 11580 | |
| 11581 | weston |