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 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 27 | .. note:: |
| 28 | |
| 29 | It is very easy to create your own layers to use with the OpenEmbedded |
| 30 | build system, as the Yocto Project ships with tools that speed up creating |
| 31 | layers. This section describes the steps you perform by hand to create |
| 32 | layers so that you can better understand them. For information about the |
| 33 | layer-creation tools, see the |
| 34 | ":ref:`bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script`" |
| 35 | section in the Yocto Project Board Support Package (BSP) Developer's |
| 36 | Guide and the ":ref:`dev-manual/common-tasks:creating a general layer using the \`\`bitbake-layers\`\` script`" |
| 37 | section further down in this manual. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 38 | |
| 39 | Follow these general steps to create your layer without using tools: |
| 40 | |
| 41 | 1. *Check Existing Layers:* Before creating a new layer, you should be |
| 42 | sure someone has not already created a layer containing the Metadata |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 43 | you need. You can see the :oe_layerindex:`OpenEmbedded Metadata Index <>` |
| 44 | for a list of layers from the OpenEmbedded community that can be used in |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 45 | the Yocto Project. You could find a layer that is identical or close |
| 46 | to what you need. |
| 47 | |
| 48 | 2. *Create a Directory:* Create the directory for your layer. When you |
| 49 | create the layer, be sure to create the directory in an area not |
| 50 | associated with the Yocto Project :term:`Source Directory` |
| 51 | (e.g. the cloned ``poky`` repository). |
| 52 | |
| 53 | While not strictly required, prepend the name of the directory with |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 54 | the string "meta-". For example:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 55 | |
| 56 | meta-mylayer |
| 57 | meta-GUI_xyz |
| 58 | meta-mymachine |
| 59 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 60 | With rare exceptions, a layer's name follows this form:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 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" |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 80 | for a layer named "meta-machinexyz"):: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 81 | |
| 82 | # We have a conf and classes directory, add to BBPATH |
| 83 | BBPATH .= ":${LAYERDIR}" |
| 84 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 85 | # We have recipes-* directories, add to BBFILES |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 86 | BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \ |
| 87 | ${LAYERDIR}/recipes-*/*/*.bbappend" |
| 88 | |
| 89 | BBFILE_COLLECTIONS += "yoctobsp" |
| 90 | BBFILE_PATTERN_yoctobsp = "^${LAYERDIR}/" |
| 91 | BBFILE_PRIORITY_yoctobsp = "5" |
| 92 | LAYERVERSION_yoctobsp = "4" |
| 93 | LAYERSERIES_COMPAT_yoctobsp = "dunfell" |
| 94 | |
| 95 | Following is an explanation of the layer configuration file: |
| 96 | |
| 97 | - :term:`BBPATH`: Adds the layer's |
| 98 | root directory to BitBake's search path. Through the use of the |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 99 | :term:`BBPATH` variable, BitBake locates class files (``.bbclass``), |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 100 | configuration files, and files that are included with ``include`` |
| 101 | and ``require`` statements. For these cases, BitBake uses the |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 102 | first file that matches the name found in :term:`BBPATH`. This is |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 103 | similar to the way the ``PATH`` variable is used for binaries. It |
| 104 | is recommended, therefore, that you use unique class and |
| 105 | configuration filenames in your custom layer. |
| 106 | |
| 107 | - :term:`BBFILES`: Defines the |
| 108 | location for all recipes in the layer. |
| 109 | |
| 110 | - :term:`BBFILE_COLLECTIONS`: |
| 111 | Establishes the current layer through a unique identifier that is |
| 112 | used throughout the OpenEmbedded build system to refer to the |
| 113 | layer. In this example, the identifier "yoctobsp" is the |
| 114 | representation for the container layer named "meta-yocto-bsp". |
| 115 | |
| 116 | - :term:`BBFILE_PATTERN`: |
| 117 | Expands immediately during parsing to provide the directory of the |
| 118 | layer. |
| 119 | |
| 120 | - :term:`BBFILE_PRIORITY`: |
| 121 | Establishes a priority to use for recipes in the layer when the |
| 122 | OpenEmbedded build finds recipes of the same name in different |
| 123 | layers. |
| 124 | |
| 125 | - :term:`LAYERVERSION`: |
| 126 | Establishes a version number for the layer. You can use this |
| 127 | version number to specify this exact version of the layer as a |
| 128 | dependency when using the |
| 129 | :term:`LAYERDEPENDS` |
| 130 | variable. |
| 131 | |
| 132 | - :term:`LAYERDEPENDS`: |
| 133 | Lists all layers on which this layer depends (if any). |
| 134 | |
| 135 | - :term:`LAYERSERIES_COMPAT`: |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 136 | Lists the :yocto_wiki:`Yocto Project </Releases>` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 137 | releases for which the current version is compatible. This |
| 138 | variable is a good way to indicate if your particular layer is |
| 139 | current. |
| 140 | |
| 141 | 4. *Add Content:* Depending on the type of layer, add the content. If |
| 142 | the layer adds support for a machine, add the machine configuration |
| 143 | in a ``conf/machine/`` file within the layer. If the layer adds |
| 144 | distro policy, add the distro configuration in a ``conf/distro/`` |
| 145 | file within the layer. If the layer introduces new recipes, put the |
| 146 | recipes you need in ``recipes-*`` subdirectories within the layer. |
| 147 | |
| 148 | .. note:: |
| 149 | |
| 150 | For an explanation of layer hierarchy that is compliant with the |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 151 | Yocto Project, see the ":ref:`bsp-guide/bsp:example filesystem layout`" |
| 152 | section in the Yocto Project Board Support Package (BSP) Developer's Guide. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 153 | |
| 154 | 5. *Optionally Test for Compatibility:* If you want permission to use |
| 155 | the Yocto Project Compatibility logo with your layer or application |
| 156 | that uses your layer, perform the steps to apply for compatibility. |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 157 | See the |
| 158 | ":ref:`dev-manual/common-tasks:making sure your layer is compatible with yocto project`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 159 | section for more information. |
| 160 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 161 | Following Best Practices When Creating Layers |
| 162 | --------------------------------------------- |
| 163 | |
| 164 | To create layers that are easier to maintain and that will not impact |
| 165 | builds for other machines, you should consider the information in the |
| 166 | following list: |
| 167 | |
| 168 | - *Avoid "Overlaying" Entire Recipes from Other Layers in Your |
| 169 | Configuration:* In other words, do not copy an entire recipe into |
| 170 | your layer and then modify it. Rather, use an append file |
| 171 | (``.bbappend``) to override only those parts of the original recipe |
| 172 | you need to modify. |
| 173 | |
| 174 | - *Avoid Duplicating Include Files:* Use append files (``.bbappend``) |
| 175 | for each recipe that uses an include file. Or, if you are introducing |
| 176 | a new recipe that requires the included file, use the path relative |
| 177 | to the original layer directory to refer to the file. For example, |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 178 | use ``require recipes-core/``\ `package`\ ``/``\ `file`\ ``.inc`` instead |
| 179 | of ``require`` `file`\ ``.inc``. If you're finding you have to overlay |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 180 | the include file, it could indicate a deficiency in the include file |
| 181 | in the layer to which it originally belongs. If this is the case, you |
| 182 | should try to address that deficiency instead of overlaying the |
| 183 | include file. For example, you could address this by getting the |
| 184 | maintainer of the include file to add a variable or variables to make |
| 185 | it easy to override the parts needing to be overridden. |
| 186 | |
| 187 | - *Structure Your Layers:* Proper use of overrides within append files |
| 188 | and placement of machine-specific files within your layer can ensure |
| 189 | that a build is not using the wrong Metadata and negatively impacting |
| 190 | a build for a different machine. Following are some examples: |
| 191 | |
| 192 | - *Modify Variables to Support a Different Machine:* Suppose you |
| 193 | have a layer named ``meta-one`` that adds support for building |
| 194 | machine "one". To do so, you use an append file named |
| 195 | ``base-files.bbappend`` and create a dependency on "foo" by |
| 196 | altering the :term:`DEPENDS` |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 197 | variable:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 198 | |
| 199 | DEPENDS = "foo" |
| 200 | |
| 201 | The dependency is created during any |
| 202 | build that includes the layer ``meta-one``. However, you might not |
| 203 | want this dependency for all machines. For example, suppose you |
| 204 | are building for machine "two" but your ``bblayers.conf`` file has |
| 205 | the ``meta-one`` layer included. During the build, the |
| 206 | ``base-files`` for machine "two" will also have the dependency on |
| 207 | ``foo``. |
| 208 | |
| 209 | To make sure your changes apply only when building machine "one", |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 210 | use a machine override with the :term:`DEPENDS` statement:: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 211 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 212 | DEPENDS:one = "foo" |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 213 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 214 | You should follow the same strategy when using ``:append`` |
| 215 | and ``:prepend`` operations:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 216 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 217 | DEPENDS:append:one = " foo" |
| 218 | DEPENDS:prepend:one = "foo " |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 219 | |
| 220 | As an actual example, here's a |
| 221 | snippet from the generic kernel include file ``linux-yocto.inc``, |
| 222 | wherein the kernel compile and link options are adjusted in the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 223 | case of a subset of the supported architectures:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 224 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 225 | DEPENDS:append:aarch64 = " libgcc" |
| 226 | KERNEL_CC:append:aarch64 = " ${TOOLCHAIN_OPTIONS}" |
| 227 | KERNEL_LD:append:aarch64 = " ${TOOLCHAIN_OPTIONS}" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 228 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 229 | DEPENDS:append:nios2 = " libgcc" |
| 230 | KERNEL_CC:append:nios2 = " ${TOOLCHAIN_OPTIONS}" |
| 231 | KERNEL_LD:append:nios2 = " ${TOOLCHAIN_OPTIONS}" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 232 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 233 | DEPENDS:append:arc = " libgcc" |
| 234 | KERNEL_CC:append:arc = " ${TOOLCHAIN_OPTIONS}" |
| 235 | KERNEL_LD:append:arc = " ${TOOLCHAIN_OPTIONS}" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 236 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 237 | KERNEL_FEATURES:append:qemuall=" features/debug/printk.scc" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 238 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 239 | - *Place Machine-Specific Files in Machine-Specific Locations:* When |
| 240 | you have a base recipe, such as ``base-files.bb``, that contains a |
| 241 | :term:`SRC_URI` statement to a |
| 242 | file, you can use an append file to cause the build to use your |
| 243 | own version of the file. For example, an append file in your layer |
| 244 | at ``meta-one/recipes-core/base-files/base-files.bbappend`` could |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 245 | extend :term:`FILESPATH` using :term:`FILESEXTRAPATHS` as follows:: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 246 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 247 | FILESEXTRAPATHS:prepend := "${THISDIR}/${BPN}:" |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 248 | |
| 249 | 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] | 250 | long as you have the file in |
| 251 | ``meta-one/recipes-core/base-files/base-files/``. However, if you |
| 252 | are building for a different machine and the ``bblayers.conf`` |
| 253 | file includes the ``meta-one`` layer and the location of your |
| 254 | machine-specific file is the first location where that file is |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 255 | found according to :term:`FILESPATH`, builds for all machines will |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 256 | also use that machine-specific file. |
| 257 | |
| 258 | You can make sure that a machine-specific file is used for a |
| 259 | particular machine by putting the file in a subdirectory specific |
| 260 | to the machine. For example, rather than placing the file in |
| 261 | ``meta-one/recipes-core/base-files/base-files/`` as shown above, |
| 262 | put it in ``meta-one/recipes-core/base-files/base-files/one/``. |
| 263 | Not only does this make sure the file is used only when building |
| 264 | for machine "one", but the build process locates the file more |
| 265 | quickly. |
| 266 | |
| 267 | In summary, you need to place all files referenced from |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 268 | :term:`SRC_URI` in a machine-specific subdirectory within the layer in |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 269 | order to restrict those files to machine-specific builds. |
| 270 | |
| 271 | - *Perform Steps to Apply for Yocto Project Compatibility:* If you want |
| 272 | permission to use the Yocto Project Compatibility logo with your |
| 273 | layer or application that uses your layer, perform the steps to apply |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 274 | for compatibility. See the |
| 275 | ":ref:`dev-manual/common-tasks:making sure your layer is compatible with yocto project`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 276 | section for more information. |
| 277 | |
| 278 | - *Follow the Layer Naming Convention:* Store custom layers in a Git |
| 279 | repository that use the ``meta-layer_name`` format. |
| 280 | |
| 281 | - *Group Your Layers Locally:* Clone your repository alongside other |
| 282 | cloned ``meta`` directories from the :term:`Source Directory`. |
| 283 | |
| 284 | Making Sure Your Layer is Compatible With Yocto Project |
| 285 | ------------------------------------------------------- |
| 286 | |
| 287 | When you create a layer used with the Yocto Project, it is advantageous |
| 288 | to make sure that the layer interacts well with existing Yocto Project |
| 289 | layers (i.e. the layer is compatible with the Yocto Project). Ensuring |
| 290 | compatibility makes the layer easy to be consumed by others in the Yocto |
| 291 | Project community and could allow you permission to use the Yocto |
| 292 | Project Compatible Logo. |
| 293 | |
| 294 | .. note:: |
| 295 | |
| 296 | Only Yocto Project member organizations are permitted to use the |
| 297 | Yocto Project Compatible Logo. The logo is not available for general |
| 298 | use. For information on how to become a Yocto Project member |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 299 | organization, see the :yocto_home:`Yocto Project Website <>`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 300 | |
| 301 | The Yocto Project Compatibility Program consists of a layer application |
| 302 | process that requests permission to use the Yocto Project Compatibility |
| 303 | Logo for your layer and application. The process consists of two parts: |
| 304 | |
| 305 | 1. Successfully passing a script (``yocto-check-layer``) that when run |
| 306 | against your layer, tests it against constraints based on experiences |
| 307 | of how layers have worked in the real world and where pitfalls have |
| 308 | been found. Getting a "PASS" result from the script is required for |
| 309 | successful compatibility registration. |
| 310 | |
| 311 | 2. Completion of an application acceptance form, which you can find at |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 312 | :yocto_home:`/webform/yocto-project-compatible-registration`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 313 | |
| 314 | To be granted permission to use the logo, you need to satisfy the |
| 315 | following: |
| 316 | |
| 317 | - Be able to check the box indicating that you got a "PASS" when |
| 318 | running the script against your layer. |
| 319 | |
| 320 | - Answer "Yes" to the questions on the form or have an acceptable |
| 321 | explanation for any questions answered "No". |
| 322 | |
| 323 | - Be a Yocto Project Member Organization. |
| 324 | |
| 325 | The remainder of this section presents information on the registration |
| 326 | form and on the ``yocto-check-layer`` script. |
| 327 | |
| 328 | Yocto Project Compatible Program Application |
| 329 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 330 | |
| 331 | Use the form to apply for your layer's approval. Upon successful |
| 332 | application, you can use the Yocto Project Compatibility Logo with your |
| 333 | layer and the application that uses your layer. |
| 334 | |
| 335 | To access the form, use this link: |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 336 | :yocto_home:`/webform/yocto-project-compatible-registration`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 337 | Follow the instructions on the form to complete your application. |
| 338 | |
| 339 | The application consists of the following sections: |
| 340 | |
| 341 | - *Contact Information:* Provide your contact information as the fields |
| 342 | require. Along with your information, provide the released versions |
| 343 | of the Yocto Project for which your layer is compatible. |
| 344 | |
| 345 | - *Acceptance Criteria:* Provide "Yes" or "No" answers for each of the |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 346 | items in the checklist. There is space at the bottom of the form for |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 347 | any explanations for items for which you answered "No". |
| 348 | |
| 349 | - *Recommendations:* Provide answers for the questions regarding Linux |
| 350 | kernel use and build success. |
| 351 | |
| 352 | ``yocto-check-layer`` Script |
| 353 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 354 | |
| 355 | The ``yocto-check-layer`` script provides you a way to assess how |
| 356 | compatible your layer is with the Yocto Project. You should run this |
| 357 | script prior to using the form to apply for compatibility as described |
| 358 | in the previous section. You need to achieve a "PASS" result in order to |
| 359 | have your application form successfully processed. |
| 360 | |
| 361 | The script divides tests into three areas: COMMON, BSP, and DISTRO. For |
| 362 | example, given a distribution layer (DISTRO), the layer must pass both |
| 363 | the COMMON and DISTRO related tests. Furthermore, if your layer is a BSP |
| 364 | layer, the layer must pass the COMMON and BSP set of tests. |
| 365 | |
| 366 | To execute the script, enter the following commands from your build |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 367 | directory:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 368 | |
| 369 | $ source oe-init-build-env |
| 370 | $ yocto-check-layer your_layer_directory |
| 371 | |
| 372 | Be sure to provide the actual directory for your |
| 373 | layer as part of the command. |
| 374 | |
| 375 | Entering the command causes the script to determine the type of layer |
| 376 | and then to execute a set of specific tests against the layer. The |
| 377 | following list overviews the test: |
| 378 | |
| 379 | - ``common.test_readme``: Tests if a ``README`` file exists in the |
| 380 | layer and the file is not empty. |
| 381 | |
| 382 | - ``common.test_parse``: Tests to make sure that BitBake can parse the |
| 383 | files without error (i.e. ``bitbake -p``). |
| 384 | |
| 385 | - ``common.test_show_environment``: Tests that the global or per-recipe |
| 386 | environment is in order without errors (i.e. ``bitbake -e``). |
| 387 | |
| 388 | - ``common.test_world``: Verifies that ``bitbake world`` works. |
| 389 | |
| 390 | - ``common.test_signatures``: Tests to be sure that BSP and DISTRO |
| 391 | layers do not come with recipes that change signatures. |
| 392 | |
| 393 | - ``common.test_layerseries_compat``: Verifies layer compatibility is |
| 394 | set properly. |
| 395 | |
| 396 | - ``bsp.test_bsp_defines_machines``: Tests if a BSP layer has machine |
| 397 | configurations. |
| 398 | |
| 399 | - ``bsp.test_bsp_no_set_machine``: Tests to ensure a BSP layer does not |
| 400 | set the machine when the layer is added. |
| 401 | |
| 402 | - ``bsp.test_machine_world``: Verifies that ``bitbake world`` works |
| 403 | regardless of which machine is selected. |
| 404 | |
| 405 | - ``bsp.test_machine_signatures``: Verifies that building for a |
| 406 | particular machine affects only the signature of tasks specific to |
| 407 | that machine. |
| 408 | |
| 409 | - ``distro.test_distro_defines_distros``: Tests if a DISTRO layer has |
| 410 | distro configurations. |
| 411 | |
| 412 | - ``distro.test_distro_no_set_distros``: Tests to ensure a DISTRO layer |
| 413 | does not set the distribution when the layer is added. |
| 414 | |
| 415 | Enabling Your Layer |
| 416 | ------------------- |
| 417 | |
| 418 | Before the OpenEmbedded build system can use your new layer, you need to |
| 419 | enable it. To enable your layer, simply add your layer's path to the |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 420 | :term:`BBLAYERS` variable in your ``conf/bblayers.conf`` file, which is |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 421 | found in the :term:`Build Directory`. |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 422 | The following example shows how to enable your new |
| 423 | ``meta-mylayer`` layer (note how your new layer exists outside of |
| 424 | the official ``poky`` repository which you would have checked out earlier):: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 425 | |
| 426 | # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf |
| 427 | # changes incompatibly |
| 428 | POKY_BBLAYERS_CONF_VERSION = "2" |
| 429 | BBPATH = "${TOPDIR}" |
| 430 | BBFILES ?= "" |
| 431 | BBLAYERS ?= " \ |
| 432 | /home/user/poky/meta \ |
| 433 | /home/user/poky/meta-poky \ |
| 434 | /home/user/poky/meta-yocto-bsp \ |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 435 | /home/user/mystuff/meta-mylayer \ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 436 | " |
| 437 | |
| 438 | BitBake parses each ``conf/layer.conf`` file from the top down as |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 439 | specified in the :term:`BBLAYERS` variable within the ``conf/bblayers.conf`` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 440 | file. During the processing of each ``conf/layer.conf`` file, BitBake |
| 441 | adds the recipes, classes and configurations contained within the |
| 442 | particular layer to the source directory. |
| 443 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 444 | Appending Other Layers Metadata With Your Layer |
| 445 | ----------------------------------------------- |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 446 | |
| 447 | A recipe that appends Metadata to another recipe is called a BitBake |
| 448 | append file. A BitBake append file uses the ``.bbappend`` file type |
| 449 | suffix, while the corresponding recipe to which Metadata is being |
| 450 | appended uses the ``.bb`` file type suffix. |
| 451 | |
| 452 | You can use a ``.bbappend`` file in your layer to make additions or |
| 453 | changes to the content of another layer's recipe without having to copy |
| 454 | the other layer's recipe into your layer. Your ``.bbappend`` file |
| 455 | resides in your layer, while the main ``.bb`` recipe file to which you |
| 456 | are appending Metadata resides in a different layer. |
| 457 | |
| 458 | Being able to append information to an existing recipe not only avoids |
| 459 | duplication, but also automatically applies recipe changes from a |
| 460 | different layer into your layer. If you were copying recipes, you would |
| 461 | have to manually merge changes as they occur. |
| 462 | |
| 463 | When you create an append file, you must use the same root name as the |
| 464 | corresponding recipe file. For example, the append file |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 465 | ``someapp_3.1.bbappend`` must apply to ``someapp_3.1.bb``. This |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 466 | means the original recipe and append filenames are version |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 467 | number-specific. If the corresponding recipe is renamed to update to a |
| 468 | newer version, you must also rename and possibly update the |
| 469 | corresponding ``.bbappend`` as well. During the build process, BitBake |
| 470 | displays an error on starting if it detects a ``.bbappend`` file that |
| 471 | does not have a corresponding recipe with a matching name. See the |
| 472 | :term:`BB_DANGLINGAPPENDS_WARNONLY` |
| 473 | variable for information on how to handle this error. |
| 474 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 475 | Overlaying a File Using Your Layer |
| 476 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 477 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 478 | As an example, consider the main formfactor recipe and a corresponding |
| 479 | formfactor append file both from the :term:`Source Directory`. |
| 480 | Here is the main |
| 481 | formfactor recipe, which is named ``formfactor_0.0.bb`` and located in |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 482 | the "meta" layer at ``meta/recipes-bsp/formfactor``:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 483 | |
| 484 | SUMMARY = "Device formfactor information" |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 485 | DESCRIPTION = "A formfactor configuration file provides information about the \ |
| 486 | target hardware for which the image is being built and information that the \ |
| 487 | build system cannot obtain from other sources such as the kernel." |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 488 | SECTION = "base" |
| 489 | LICENSE = "MIT" |
| 490 | LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" |
| 491 | PR = "r45" |
| 492 | |
| 493 | SRC_URI = "file://config file://machconfig" |
| 494 | S = "${WORKDIR}" |
| 495 | |
| 496 | PACKAGE_ARCH = "${MACHINE_ARCH}" |
| 497 | INHIBIT_DEFAULT_DEPS = "1" |
| 498 | |
| 499 | do_install() { |
| 500 | # Install file only if it has contents |
| 501 | install -d ${D}${sysconfdir}/formfactor/ |
| 502 | install -m 0644 ${S}/config ${D}${sysconfdir}/formfactor/ |
| 503 | if [ -s "${S}/machconfig" ]; then |
| 504 | install -m 0644 ${S}/machconfig ${D}${sysconfdir}/formfactor/ |
| 505 | fi |
| 506 | } |
| 507 | |
| 508 | In the main recipe, note the :term:`SRC_URI` |
| 509 | variable, which tells the OpenEmbedded build system where to find files |
| 510 | during the build. |
| 511 | |
| 512 | Following is the append file, which is named ``formfactor_0.0.bbappend`` |
| 513 | and is from the Raspberry Pi BSP Layer named ``meta-raspberrypi``. The |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 514 | file is in the layer at ``recipes-bsp/formfactor``:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 515 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 516 | FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 517 | |
| 518 | By default, the build system uses the |
| 519 | :term:`FILESPATH` variable to |
| 520 | locate files. This append file extends the locations by setting the |
| 521 | :term:`FILESEXTRAPATHS` |
| 522 | variable. Setting this variable in the ``.bbappend`` file is the most |
| 523 | reliable and recommended method for adding directories to the search |
| 524 | path used by the build system to find files. |
| 525 | |
| 526 | The statement in this example extends the directories to include |
| 527 | ``${``\ :term:`THISDIR`\ ``}/${``\ :term:`PN`\ ``}``, |
| 528 | which resolves to a directory named ``formfactor`` in the same directory |
| 529 | in which the append file resides (i.e. |
| 530 | ``meta-raspberrypi/recipes-bsp/formfactor``. This implies that you must |
| 531 | have the supporting directory structure set up that will contain any |
| 532 | files or patches you will be including from the layer. |
| 533 | |
| 534 | Using the immediate expansion assignment operator ``:=`` is important |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 535 | because of the reference to :term:`THISDIR`. The trailing colon character is |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 536 | important as it ensures that items in the list remain colon-separated. |
| 537 | |
| 538 | .. note:: |
| 539 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 540 | BitBake automatically defines the :term:`THISDIR` variable. You should |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 541 | never set this variable yourself. Using ":prepend" as part of the |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 542 | :term:`FILESEXTRAPATHS` ensures your path will be searched prior to other |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 543 | paths in the final list. |
| 544 | |
| 545 | Also, not all append files add extra files. Many append files simply |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 546 | allow to add build options (e.g. ``systemd``). For these cases, your |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 547 | append file would not even use the :term:`FILESEXTRAPATHS` statement. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 548 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 549 | The end result of this ``.bbappend`` file is that on a Raspberry Pi, where |
| 550 | ``rpi`` will exist in the list of :term:`OVERRIDES`, the file |
| 551 | ``meta-raspberrypi/recipes-bsp/formfactor/formfactor/rpi/machconfig`` will be |
| 552 | used during :ref:`ref-tasks-fetch` and the test for a non-zero file size in |
| 553 | :ref:`ref-tasks-install` will return true, and the file will be installed. |
| 554 | |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 555 | Installing Additional Files Using Your Layer |
| 556 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 557 | |
| 558 | As another example, consider the main ``xserver-xf86-config`` recipe and a |
| 559 | corresponding ``xserver-xf86-config`` append file both from the :term:`Source |
| 560 | Directory`. Here is the main ``xserver-xf86-config`` recipe, which is named |
| 561 | ``xserver-xf86-config_0.1.bb`` and located in the "meta" layer at |
| 562 | ``meta/recipes-graphics/xorg-xserver``:: |
| 563 | |
| 564 | SUMMARY = "X.Org X server configuration file" |
| 565 | HOMEPAGE = "http://www.x.org" |
| 566 | SECTION = "x11/base" |
| 567 | LICENSE = "MIT-X" |
| 568 | LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" |
| 569 | PR = "r33" |
| 570 | |
| 571 | SRC_URI = "file://xorg.conf" |
| 572 | |
| 573 | S = "${WORKDIR}" |
| 574 | |
| 575 | CONFFILES:${PN} = "${sysconfdir}/X11/xorg.conf" |
| 576 | |
| 577 | PACKAGE_ARCH = "${MACHINE_ARCH}" |
| 578 | ALLOW_EMPTY:${PN} = "1" |
| 579 | |
| 580 | do_install () { |
| 581 | if test -s ${WORKDIR}/xorg.conf; then |
| 582 | install -d ${D}/${sysconfdir}/X11 |
| 583 | install -m 0644 ${WORKDIR}/xorg.conf ${D}/${sysconfdir}/X11/ |
| 584 | fi |
| 585 | } |
| 586 | |
| 587 | Following is the append file, which is named ``xserver-xf86-config_%.bbappend`` |
| 588 | and is from the Raspberry Pi BSP Layer named ``meta-raspberrypi``. The |
| 589 | file is in the layer at ``recipes-graphics/xorg-xserver``:: |
| 590 | |
| 591 | FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:" |
| 592 | |
| 593 | SRC_URI:append:rpi = " \ |
| 594 | file://xorg.conf.d/98-pitft.conf \ |
| 595 | file://xorg.conf.d/99-calibration.conf \ |
| 596 | " |
| 597 | do_install:append:rpi () { |
| 598 | PITFT="${@bb.utils.contains("MACHINE_FEATURES", "pitft", "1", "0", d)}" |
| 599 | if [ "${PITFT}" = "1" ]; then |
| 600 | install -d ${D}/${sysconfdir}/X11/xorg.conf.d/ |
| 601 | install -m 0644 ${WORKDIR}/xorg.conf.d/98-pitft.conf ${D}/${sysconfdir}/X11/xorg.conf.d/ |
| 602 | install -m 0644 ${WORKDIR}/xorg.conf.d/99-calibration.conf ${D}/${sysconfdir}/X11/xorg.conf.d/ |
| 603 | fi |
| 604 | } |
| 605 | |
| 606 | FILES:${PN}:append:rpi = " ${sysconfdir}/X11/xorg.conf.d/*" |
| 607 | |
| 608 | Building off of the previous example, we once again are setting the |
| 609 | :term:`FILESEXTRAPATHS` variable. In this case we are also using |
| 610 | :term:`SRC_URI` to list additional source files to use when ``rpi`` is found in |
| 611 | the list of :term:`OVERRIDES`. The :ref:`ref-tasks-install` task will then perform a |
| 612 | check for an additional :term:`MACHINE_FEATURES` that if set will cause these |
| 613 | additional files to be installed. These additional files are listed in |
| 614 | :term:`FILES` so that they will be packaged. |
| 615 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 616 | Prioritizing Your Layer |
| 617 | ----------------------- |
| 618 | |
| 619 | Each layer is assigned a priority value. Priority values control which |
| 620 | layer takes precedence if there are recipe files with the same name in |
| 621 | multiple layers. For these cases, the recipe file from the layer with a |
| 622 | higher priority number takes precedence. Priority values also affect the |
| 623 | order in which multiple ``.bbappend`` files for the same recipe are |
| 624 | applied. You can either specify the priority manually, or allow the |
| 625 | build system to calculate it based on the layer's dependencies. |
| 626 | |
| 627 | To specify the layer's priority manually, use the |
| 628 | :term:`BBFILE_PRIORITY` |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 629 | variable and append the layer's root name:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 630 | |
| 631 | BBFILE_PRIORITY_mylayer = "1" |
| 632 | |
| 633 | .. note:: |
| 634 | |
| 635 | It is possible for a recipe with a lower version number |
| 636 | :term:`PV` in a layer that has a higher |
| 637 | priority to take precedence. |
| 638 | |
| 639 | Also, the layer priority does not currently affect the precedence |
| 640 | order of ``.conf`` or ``.bbclass`` files. Future versions of BitBake |
| 641 | might address this. |
| 642 | |
| 643 | Managing Layers |
| 644 | --------------- |
| 645 | |
| 646 | You can use the BitBake layer management tool ``bitbake-layers`` to |
| 647 | provide a view into the structure of recipes across a multi-layer |
| 648 | project. Being able to generate output that reports on configured layers |
| 649 | with their paths and priorities and on ``.bbappend`` files and their |
| 650 | applicable recipes can help to reveal potential problems. |
| 651 | |
| 652 | For help on the BitBake layer management tool, use the following |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 653 | command:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 654 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 655 | $ bitbake-layers --help |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 656 | NOTE: Starting bitbake server... |
| 657 | usage: bitbake-layers [-d] [-q] [-F] [--color COLOR] [-h] <subcommand> ... |
| 658 | |
| 659 | BitBake layers utility |
| 660 | |
| 661 | optional arguments: |
| 662 | -d, --debug Enable debug output |
| 663 | -q, --quiet Print only errors |
| 664 | -F, --force Force add without recipe parse verification |
| 665 | --color COLOR Colorize output (where COLOR is auto, always, never) |
| 666 | -h, --help show this help message and exit |
| 667 | |
| 668 | subcommands: |
| 669 | <subcommand> |
| 670 | layerindex-fetch Fetches a layer from a layer index along with its |
| 671 | dependent layers, and adds them to conf/bblayers.conf. |
| 672 | layerindex-show-depends |
| 673 | Find layer dependencies from layer index. |
| 674 | add-layer Add one or more layers to bblayers.conf. |
| 675 | remove-layer Remove one or more layers from bblayers.conf. |
| 676 | flatten flatten layer configuration into a separate output |
| 677 | directory. |
| 678 | show-layers show current configured layers. |
| 679 | show-overlayed list overlayed recipes (where the same recipe exists |
| 680 | in another layer) |
| 681 | show-recipes list available recipes, showing the layer they are |
| 682 | provided by |
| 683 | show-appends list bbappend files and recipe files they apply to |
| 684 | show-cross-depends Show dependencies between recipes that cross layer |
| 685 | boundaries. |
| 686 | create-layer Create a basic layer |
| 687 | |
| 688 | Use bitbake-layers <subcommand> --help to get help on a specific command |
| 689 | |
| 690 | The following list describes the available commands: |
| 691 | |
| 692 | - ``help:`` Displays general help or help on a specified command. |
| 693 | |
| 694 | - ``show-layers:`` Shows the current configured layers. |
| 695 | |
| 696 | - ``show-overlayed:`` Lists overlayed recipes. A recipe is overlayed |
| 697 | when a recipe with the same name exists in another layer that has a |
| 698 | higher layer priority. |
| 699 | |
| 700 | - ``show-recipes:`` Lists available recipes and the layers that |
| 701 | provide them. |
| 702 | |
| 703 | - ``show-appends:`` Lists ``.bbappend`` files and the recipe files to |
| 704 | which they apply. |
| 705 | |
| 706 | - ``show-cross-depends:`` Lists dependency relationships between |
| 707 | recipes that cross layer boundaries. |
| 708 | |
| 709 | - ``add-layer:`` Adds a layer to ``bblayers.conf``. |
| 710 | |
| 711 | - ``remove-layer:`` Removes a layer from ``bblayers.conf`` |
| 712 | |
| 713 | - ``flatten:`` Flattens the layer configuration into a separate |
| 714 | output directory. Flattening your layer configuration builds a |
| 715 | "flattened" directory that contains the contents of all layers, with |
| 716 | any overlayed recipes removed and any ``.bbappend`` files appended to |
| 717 | the corresponding recipes. You might have to perform some manual |
| 718 | cleanup of the flattened layer as follows: |
| 719 | |
| 720 | - Non-recipe files (such as patches) are overwritten. The flatten |
| 721 | command shows a warning for these files. |
| 722 | |
| 723 | - Anything beyond the normal layer setup has been added to the |
| 724 | ``layer.conf`` file. Only the lowest priority layer's |
| 725 | ``layer.conf`` is used. |
| 726 | |
| 727 | - Overridden and appended items from ``.bbappend`` files need to be |
| 728 | cleaned up. The contents of each ``.bbappend`` end up in the |
| 729 | flattened recipe. However, if there are appended or changed |
| 730 | variable values, you need to tidy these up yourself. Consider the |
| 731 | following example. Here, the ``bitbake-layers`` command adds the |
| 732 | line ``#### bbappended ...`` so that you know where the following |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 733 | lines originate:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 734 | |
| 735 | ... |
| 736 | DESCRIPTION = "A useful utility" |
| 737 | ... |
| 738 | EXTRA_OECONF = "--enable-something" |
| 739 | ... |
| 740 | |
| 741 | #### bbappended from meta-anotherlayer #### |
| 742 | |
| 743 | DESCRIPTION = "Customized utility" |
| 744 | EXTRA_OECONF += "--enable-somethingelse" |
| 745 | |
| 746 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 747 | Ideally, you would tidy up these utilities as follows:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 748 | |
| 749 | ... |
| 750 | DESCRIPTION = "Customized utility" |
| 751 | ... |
| 752 | EXTRA_OECONF = "--enable-something --enable-somethingelse" |
| 753 | ... |
| 754 | |
| 755 | - ``layerindex-fetch``: Fetches a layer from a layer index, along |
| 756 | with its dependent layers, and adds the layers to the |
| 757 | ``conf/bblayers.conf`` file. |
| 758 | |
| 759 | - ``layerindex-show-depends``: Finds layer dependencies from the |
| 760 | layer index. |
| 761 | |
| 762 | - ``create-layer``: Creates a basic layer. |
| 763 | |
| 764 | Creating a General Layer Using the ``bitbake-layers`` Script |
| 765 | ------------------------------------------------------------ |
| 766 | |
| 767 | The ``bitbake-layers`` script with the ``create-layer`` subcommand |
| 768 | simplifies creating a new general layer. |
| 769 | |
| 770 | .. note:: |
| 771 | |
| 772 | - For information on BSP layers, see the ":ref:`bsp-guide/bsp:bsp layers`" |
| 773 | section in the Yocto |
| 774 | Project Board Specific (BSP) Developer's Guide. |
| 775 | |
| 776 | - In order to use a layer with the OpenEmbedded build system, you |
| 777 | need to add the layer to your ``bblayers.conf`` configuration |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 778 | 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] | 779 | section for more information. |
| 780 | |
| 781 | The default mode of the script's operation with this subcommand is to |
| 782 | create a layer with the following: |
| 783 | |
| 784 | - A layer priority of 6. |
| 785 | |
| 786 | - A ``conf`` subdirectory that contains a ``layer.conf`` file. |
| 787 | |
| 788 | - A ``recipes-example`` subdirectory that contains a further |
| 789 | subdirectory named ``example``, which contains an ``example.bb`` |
| 790 | recipe file. |
| 791 | |
| 792 | - A ``COPYING.MIT``, which is the license statement for the layer. The |
| 793 | script assumes you want to use the MIT license, which is typical for |
| 794 | most layers, for the contents of the layer itself. |
| 795 | |
| 796 | - A ``README`` file, which is a file describing the contents of your |
| 797 | new layer. |
| 798 | |
| 799 | In its simplest form, you can use the following command form to create a |
| 800 | layer. The command creates a layer whose name corresponds to |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 801 | "your_layer_name" in the current directory:: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 802 | |
| 803 | $ bitbake-layers create-layer your_layer_name |
| 804 | |
| 805 | As an example, the following command creates a layer named ``meta-scottrif`` |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 806 | in your home directory:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 807 | |
| 808 | $ cd /usr/home |
| 809 | $ bitbake-layers create-layer meta-scottrif |
| 810 | NOTE: Starting bitbake server... |
| 811 | Add your new layer with 'bitbake-layers add-layer meta-scottrif' |
| 812 | |
| 813 | 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] | 814 | value of "6", you can either use the ``--priority`` option or you |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 815 | can edit the |
| 816 | :term:`BBFILE_PRIORITY` value |
| 817 | in the ``conf/layer.conf`` after the script creates it. Furthermore, if |
| 818 | 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] | 819 | default, you can use the ``--example-recipe-name`` option. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 820 | |
| 821 | The easiest way to see how the ``bitbake-layers create-layer`` command |
| 822 | works is to experiment with the script. You can also read the usage |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 823 | information by entering the following:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 824 | |
| 825 | $ bitbake-layers create-layer --help |
| 826 | NOTE: Starting bitbake server... |
| 827 | usage: bitbake-layers create-layer [-h] [--priority PRIORITY] |
| 828 | [--example-recipe-name EXAMPLERECIPE] |
| 829 | layerdir |
| 830 | |
| 831 | Create a basic layer |
| 832 | |
| 833 | positional arguments: |
| 834 | layerdir Layer directory to create |
| 835 | |
| 836 | optional arguments: |
| 837 | -h, --help show this help message and exit |
| 838 | --priority PRIORITY, -p PRIORITY |
| 839 | Layer directory to create |
| 840 | --example-recipe-name EXAMPLERECIPE, -e EXAMPLERECIPE |
| 841 | Filename of the example recipe |
| 842 | |
| 843 | Adding a Layer Using the ``bitbake-layers`` Script |
| 844 | -------------------------------------------------- |
| 845 | |
| 846 | Once you create your general layer, you must add it to your |
| 847 | ``bblayers.conf`` file. Adding the layer to this configuration file |
| 848 | makes the OpenEmbedded build system aware of your layer so that it can |
| 849 | search it for metadata. |
| 850 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 851 | Add your layer by using the ``bitbake-layers add-layer`` command:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 852 | |
| 853 | $ bitbake-layers add-layer your_layer_name |
| 854 | |
| 855 | Here is an example that adds a |
| 856 | layer named ``meta-scottrif`` to the configuration file. Following the |
| 857 | command that adds the layer is another ``bitbake-layers`` command that |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 858 | shows the layers that are in your ``bblayers.conf`` file:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 859 | |
| 860 | $ bitbake-layers add-layer meta-scottrif |
| 861 | NOTE: Starting bitbake server... |
| 862 | Parsing recipes: 100% |##########################################################| Time: 0:00:49 |
| 863 | Parsing of 1441 .bb files complete (0 cached, 1441 parsed). 2055 targets, 56 skipped, 0 masked, 0 errors. |
| 864 | $ bitbake-layers show-layers |
| 865 | NOTE: Starting bitbake server... |
| 866 | layer path priority |
| 867 | ========================================================================== |
| 868 | meta /home/scottrif/poky/meta 5 |
| 869 | meta-poky /home/scottrif/poky/meta-poky 5 |
| 870 | meta-yocto-bsp /home/scottrif/poky/meta-yocto-bsp 5 |
| 871 | workspace /home/scottrif/poky/build/workspace 99 |
| 872 | meta-scottrif /home/scottrif/poky/build/meta-scottrif 6 |
| 873 | |
| 874 | |
| 875 | Adding the layer to this file |
| 876 | enables the build system to locate the layer during the build. |
| 877 | |
| 878 | .. note:: |
| 879 | |
| 880 | During a build, the OpenEmbedded build system looks in the layers |
| 881 | from the top of the list down to the bottom in that order. |
| 882 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 883 | Customizing Images |
| 884 | ================== |
| 885 | |
| 886 | You can customize images to satisfy particular requirements. This |
| 887 | section describes several methods and provides guidelines for each. |
| 888 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 889 | Customizing Images Using ``local.conf`` |
| 890 | --------------------------------------- |
| 891 | |
| 892 | Probably the easiest way to customize an image is to add a package by |
| 893 | way of the ``local.conf`` configuration file. Because it is limited to |
| 894 | local use, this method generally only allows you to add packages and is |
| 895 | not as flexible as creating your own customized image. When you add |
| 896 | packages using local variables this way, you need to realize that these |
| 897 | variable changes are in effect for every build and consequently affect |
| 898 | all images, which might not be what you require. |
| 899 | |
| 900 | To add a package to your image using the local configuration file, use |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 901 | the :term:`IMAGE_INSTALL` variable with the ``:append`` operator:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 902 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 903 | IMAGE_INSTALL:append = " strace" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 904 | |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 905 | Use of the syntax is important; specifically, the leading space |
| 906 | after the opening quote and before the package name, which is |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 907 | ``strace`` in this example. This space is required since the ``:append`` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 908 | operator does not add the space. |
| 909 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 910 | Furthermore, you must use ``:append`` instead of the ``+=`` operator if |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 911 | you want to avoid ordering issues. The reason for this is because doing |
| 912 | so unconditionally appends to the variable and avoids ordering problems |
| 913 | due to the variable being set in image recipes and ``.bbclass`` files |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 914 | with operators like ``?=``. Using ``:append`` ensures the operation |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 915 | takes effect. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 916 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 917 | As shown in its simplest use, ``IMAGE_INSTALL:append`` affects all |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 918 | images. It is possible to extend the syntax so that the variable applies |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 919 | to a specific image only. Here is an example:: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 920 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 921 | IMAGE_INSTALL:append:pn-core-image-minimal = " strace" |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 922 | |
| 923 | This example adds ``strace`` to the ``core-image-minimal`` image only. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 924 | |
| 925 | You can add packages using a similar approach through the |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 926 | :term:`CORE_IMAGE_EXTRA_INSTALL` variable. If you use this variable, only |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 927 | ``core-image-*`` images are affected. |
| 928 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 929 | Customizing Images Using Custom ``IMAGE_FEATURES`` and ``EXTRA_IMAGE_FEATURES`` |
| 930 | ------------------------------------------------------------------------------- |
| 931 | |
| 932 | Another method for customizing your image is to enable or disable |
| 933 | high-level image features by using the |
| 934 | :term:`IMAGE_FEATURES` and |
| 935 | :term:`EXTRA_IMAGE_FEATURES` |
| 936 | variables. Although the functions for both variables are nearly |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 937 | equivalent, best practices dictate using :term:`IMAGE_FEATURES` from within |
| 938 | a recipe and using :term:`EXTRA_IMAGE_FEATURES` from within your |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 939 | ``local.conf`` file, which is found in the |
| 940 | :term:`Build Directory`. |
| 941 | |
| 942 | To understand how these features work, the best reference is |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 943 | :ref:`meta/classes/image.bbclass <ref-classes-image>`. |
| 944 | This class lists out the available |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 945 | :term:`IMAGE_FEATURES` of which most map to package groups while some, such |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 946 | as ``debug-tweaks`` and ``read-only-rootfs``, resolve as general |
| 947 | configuration settings. |
| 948 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 949 | In summary, the file looks at the contents of the :term:`IMAGE_FEATURES` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 950 | variable and then maps or configures the feature accordingly. Based on |
| 951 | this information, the build system automatically adds the appropriate |
| 952 | packages or configurations to the |
| 953 | :term:`IMAGE_INSTALL` variable. |
| 954 | Effectively, you are enabling extra features by extending the class or |
| 955 | creating a custom class for use with specialized image ``.bb`` files. |
| 956 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 957 | Use the :term:`EXTRA_IMAGE_FEATURES` variable from within your local |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 958 | configuration file. Using a separate area from which to enable features |
| 959 | with this variable helps you avoid overwriting the features in the image |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 960 | recipe that are enabled with :term:`IMAGE_FEATURES`. The value of |
| 961 | :term:`EXTRA_IMAGE_FEATURES` is added to :term:`IMAGE_FEATURES` within |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 962 | ``meta/conf/bitbake.conf``. |
| 963 | |
| 964 | To illustrate how you can use these variables to modify your image, |
| 965 | consider an example that selects the SSH server. The Yocto Project ships |
| 966 | with two SSH servers you can use with your images: Dropbear and OpenSSH. |
| 967 | Dropbear is a minimal SSH server appropriate for resource-constrained |
| 968 | environments, while OpenSSH is a well-known standard SSH server |
| 969 | implementation. By default, the ``core-image-sato`` image is configured |
| 970 | to use Dropbear. The ``core-image-full-cmdline`` and ``core-image-lsb`` |
| 971 | images both include OpenSSH. The ``core-image-minimal`` image does not |
| 972 | contain an SSH server. |
| 973 | |
| 974 | You can customize your image and change these defaults. Edit the |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 975 | :term:`IMAGE_FEATURES` variable in your recipe or use the |
| 976 | :term:`EXTRA_IMAGE_FEATURES` in your ``local.conf`` file so that it |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 977 | configures the image you are working with to include |
| 978 | ``ssh-server-dropbear`` or ``ssh-server-openssh``. |
| 979 | |
| 980 | .. note:: |
| 981 | |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 982 | See the ":ref:`ref-manual/features:image features`" section in the Yocto |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 983 | Project Reference Manual for a complete list of image features that ship |
| 984 | with the Yocto Project. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 985 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 986 | Customizing Images Using Custom .bb Files |
| 987 | ----------------------------------------- |
| 988 | |
| 989 | You can also customize an image by creating a custom recipe that defines |
| 990 | additional software as part of the image. The following example shows |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 991 | the form for the two lines you need:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 992 | |
| 993 | IMAGE_INSTALL = "packagegroup-core-x11-base package1 package2" |
| 994 | inherit core-image |
| 995 | |
| 996 | Defining the software using a custom recipe gives you total control over |
| 997 | the contents of the image. It is important to use the correct names of |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 998 | packages in the :term:`IMAGE_INSTALL` variable. You must use the |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 999 | OpenEmbedded notation and not the Debian notation for the names (e.g. |
| 1000 | ``glibc-dev`` instead of ``libc6-dev``). |
| 1001 | |
| 1002 | The other method for creating a custom image is to base it on an |
| 1003 | existing image. For example, if you want to create an image based on |
| 1004 | ``core-image-sato`` but add the additional package ``strace`` to the |
| 1005 | image, copy the ``meta/recipes-sato/images/core-image-sato.bb`` to a new |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 1006 | ``.bb`` and add the following line to the end of the copy:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1007 | |
| 1008 | IMAGE_INSTALL += "strace" |
| 1009 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1010 | Customizing Images Using Custom Package Groups |
| 1011 | ---------------------------------------------- |
| 1012 | |
| 1013 | For complex custom images, the best approach for customizing an image is |
| 1014 | to create a custom package group recipe that is used to build the image |
| 1015 | or images. A good example of a package group recipe is |
| 1016 | ``meta/recipes-core/packagegroups/packagegroup-base.bb``. |
| 1017 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1018 | If you examine that recipe, you see that the :term:`PACKAGES` variable lists |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1019 | the package group packages to produce. The ``inherit packagegroup`` |
| 1020 | statement sets appropriate default values and automatically adds |
| 1021 | ``-dev``, ``-dbg``, and ``-ptest`` complementary packages for each |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1022 | package specified in the :term:`PACKAGES` statement. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1023 | |
| 1024 | .. note:: |
| 1025 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1026 | The ``inherit packagegroup`` line should be located near the top of the |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1027 | recipe, certainly before the :term:`PACKAGES` statement. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1028 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1029 | For each package you specify in :term:`PACKAGES`, you can use :term:`RDEPENDS` |
| 1030 | and :term:`RRECOMMENDS` entries to provide a list of packages the parent |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1031 | task package should contain. You can see examples of these further down |
| 1032 | in the ``packagegroup-base.bb`` recipe. |
| 1033 | |
| 1034 | Here is a short, fabricated example showing the same basic pieces for a |
| 1035 | hypothetical packagegroup defined in ``packagegroup-custom.bb``, where |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1036 | the variable :term:`PN` is the standard way to abbreviate the reference to |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 1037 | the full packagegroup name ``packagegroup-custom``:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1038 | |
| 1039 | DESCRIPTION = "My Custom Package Groups" |
| 1040 | |
| 1041 | inherit packagegroup |
| 1042 | |
| 1043 | PACKAGES = "\ |
| 1044 | ${PN}-apps \ |
| 1045 | ${PN}-tools \ |
| 1046 | " |
| 1047 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 1048 | RDEPENDS:${PN}-apps = "\ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1049 | dropbear \ |
| 1050 | portmap \ |
| 1051 | psplash" |
| 1052 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 1053 | RDEPENDS:${PN}-tools = "\ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1054 | oprofile \ |
| 1055 | oprofileui-server \ |
| 1056 | lttng-tools" |
| 1057 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 1058 | RRECOMMENDS:${PN}-tools = "\ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1059 | kernel-module-oprofile" |
| 1060 | |
| 1061 | In the previous example, two package group packages are created with |
| 1062 | their dependencies and their recommended package dependencies listed: |
| 1063 | ``packagegroup-custom-apps``, and ``packagegroup-custom-tools``. To |
| 1064 | build an image using these package group packages, you need to add |
| 1065 | ``packagegroup-custom-apps`` and/or ``packagegroup-custom-tools`` to |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1066 | :term:`IMAGE_INSTALL`. For other forms of image dependencies see the other |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1067 | areas of this section. |
| 1068 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1069 | Customizing an Image Hostname |
| 1070 | ----------------------------- |
| 1071 | |
| 1072 | By default, the configured hostname (i.e. ``/etc/hostname``) in an image |
| 1073 | is the same as the machine name. For example, if |
| 1074 | :term:`MACHINE` equals "qemux86", the |
| 1075 | configured hostname written to ``/etc/hostname`` is "qemux86". |
| 1076 | |
| 1077 | You can customize this name by altering the value of the "hostname" |
| 1078 | variable in the ``base-files`` recipe using either an append file or a |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 1079 | configuration file. Use the following in an append file:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1080 | |
| 1081 | hostname = "myhostname" |
| 1082 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 1083 | Use the following in a configuration file:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1084 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 1085 | hostname:pn-base-files = "myhostname" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1086 | |
| 1087 | Changing the default value of the variable "hostname" can be useful in |
| 1088 | certain situations. For example, suppose you need to do extensive |
| 1089 | testing on an image and you would like to easily identify the image |
| 1090 | under test from existing images with typical default hostnames. In this |
| 1091 | situation, you could change the default hostname to "testme", which |
| 1092 | results in all the images using the name "testme". Once testing is |
| 1093 | complete and you do not need to rebuild the image for test any longer, |
| 1094 | you can easily reset the default hostname. |
| 1095 | |
| 1096 | Another point of interest is that if you unset the variable, the image |
| 1097 | will have no default hostname in the filesystem. Here is an example that |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 1098 | unsets the variable in a configuration file:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1099 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 1100 | hostname:pn-base-files = "" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1101 | |
| 1102 | Having no default hostname in the filesystem is suitable for |
| 1103 | environments that use dynamic hostnames such as virtual machines. |
| 1104 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1105 | Writing a New Recipe |
| 1106 | ==================== |
| 1107 | |
| 1108 | Recipes (``.bb`` files) are fundamental components in the Yocto Project |
| 1109 | environment. Each software component built by the OpenEmbedded build |
| 1110 | system requires a recipe to define the component. This section describes |
| 1111 | how to create, write, and test a new recipe. |
| 1112 | |
| 1113 | .. note:: |
| 1114 | |
| 1115 | For information on variables that are useful for recipes and for |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1116 | information about recipe naming issues, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 1117 | ":ref:`ref-manual/varlocality:recipes`" section of the Yocto Project |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1118 | Reference Manual. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1119 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1120 | Overview |
| 1121 | -------- |
| 1122 | |
| 1123 | The following figure shows the basic process for creating a new recipe. |
| 1124 | The remainder of the section provides details for the steps. |
| 1125 | |
| 1126 | .. image:: figures/recipe-workflow.png |
| 1127 | :align: center |
| 1128 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1129 | Locate or Automatically Create a Base Recipe |
| 1130 | -------------------------------------------- |
| 1131 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 1132 | You can always write a recipe from scratch. However, there are three choices |
| 1133 | that can help you quickly get started with a new recipe: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1134 | |
| 1135 | - ``devtool add``: A command that assists in creating a recipe and an |
| 1136 | environment conducive to development. |
| 1137 | |
| 1138 | - ``recipetool create``: A command provided by the Yocto Project that |
| 1139 | automates creation of a base recipe based on the source files. |
| 1140 | |
| 1141 | - *Existing Recipes:* Location and modification of an existing recipe |
| 1142 | that is similar in function to the recipe you need. |
| 1143 | |
| 1144 | .. note:: |
| 1145 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1146 | For information on recipe syntax, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 1147 | ":ref:`dev-manual/common-tasks:recipe syntax`" section. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1148 | |
| 1149 | Creating the Base Recipe Using ``devtool add`` |
| 1150 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1151 | |
| 1152 | The ``devtool add`` command uses the same logic for auto-creating the |
| 1153 | recipe as ``recipetool create``, which is listed below. Additionally, |
| 1154 | however, ``devtool add`` sets up an environment that makes it easy for |
| 1155 | you to patch the source and to make changes to the recipe as is often |
| 1156 | necessary when adding a recipe to build a new piece of software to be |
| 1157 | included in a build. |
| 1158 | |
| 1159 | You can find a complete description of the ``devtool add`` command in |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 1160 | the ":ref:`sdk-manual/extensible:a closer look at \`\`devtool add\`\``" section |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1161 | in the Yocto Project Application Development and the Extensible Software |
| 1162 | Development Kit (eSDK) manual. |
| 1163 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1164 | Creating the Base Recipe Using ``recipetool create`` |
| 1165 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1166 | |
| 1167 | ``recipetool create`` automates creation of a base recipe given a set of |
| 1168 | source code files. As long as you can extract or point to the source |
| 1169 | files, the tool will construct a recipe and automatically configure all |
| 1170 | pre-build information into the recipe. For example, suppose you have an |
| 1171 | application that builds using Autotools. Creating the base recipe using |
| 1172 | ``recipetool`` results in a recipe that has the pre-build dependencies, |
| 1173 | license requirements, and checksums configured. |
| 1174 | |
| 1175 | To run the tool, you just need to be in your |
| 1176 | :term:`Build Directory` and have sourced the |
| 1177 | build environment setup script (i.e. |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1178 | :ref:`structure-core-script`). |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 1179 | To get help on the tool, use the following command:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1180 | |
| 1181 | $ recipetool -h |
| 1182 | NOTE: Starting bitbake server... |
| 1183 | usage: recipetool [-d] [-q] [--color COLOR] [-h] <subcommand> ... |
| 1184 | |
| 1185 | OpenEmbedded recipe tool |
| 1186 | |
| 1187 | options: |
| 1188 | -d, --debug Enable debug output |
| 1189 | -q, --quiet Print only errors |
| 1190 | --color COLOR Colorize output (where COLOR is auto, always, never) |
| 1191 | -h, --help show this help message and exit |
| 1192 | |
| 1193 | subcommands: |
| 1194 | create Create a new recipe |
| 1195 | newappend Create a bbappend for the specified target in the specified |
| 1196 | layer |
| 1197 | setvar Set a variable within a recipe |
| 1198 | appendfile Create/update a bbappend to replace a target file |
| 1199 | appendsrcfiles Create/update a bbappend to add or replace source files |
| 1200 | appendsrcfile Create/update a bbappend to add or replace a source file |
| 1201 | Use recipetool <subcommand> --help to get help on a specific command |
| 1202 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1203 | Running ``recipetool create -o OUTFILE`` creates the base recipe and |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1204 | locates it properly in the layer that contains your source files. |
| 1205 | Following are some syntax examples: |
| 1206 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1207 | - Use this syntax to generate a recipe based on source. Once generated, |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 1208 | the recipe resides in the existing source code layer:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1209 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1210 | recipetool create -o OUTFILE source |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1211 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1212 | - Use this syntax to generate a recipe using code that |
| 1213 | you extract from source. The extracted code is placed in its own layer |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1214 | defined by :term:`EXTERNALSRC`. |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1215 | :: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1216 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1217 | recipetool create -o OUTFILE -x EXTERNALSRC source |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1218 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1219 | - Use this syntax to generate a recipe based on source. The options |
| 1220 | direct ``recipetool`` to generate debugging information. Once generated, |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 1221 | the recipe resides in the existing source code layer:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1222 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1223 | recipetool create -d -o OUTFILE source |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1224 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1225 | Locating and Using a Similar Recipe |
| 1226 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1227 | |
| 1228 | Before writing a recipe from scratch, it is often useful to discover |
| 1229 | whether someone else has already written one that meets (or comes close |
| 1230 | to meeting) your needs. The Yocto Project and OpenEmbedded communities |
| 1231 | maintain many recipes that might be candidates for what you are doing. |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 1232 | You can find a good central index of these recipes in the |
| 1233 | :oe_layerindex:`OpenEmbedded Layer Index <>`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1234 | |
| 1235 | Working from an existing recipe or a skeleton recipe is the best way to |
| 1236 | get started. Here are some points on both methods: |
| 1237 | |
| 1238 | - *Locate and modify a recipe that is close to what you want to do:* |
| 1239 | This method works when you are familiar with the current recipe |
| 1240 | space. The method does not work so well for those new to the Yocto |
| 1241 | Project or writing recipes. |
| 1242 | |
| 1243 | Some risks associated with this method are using a recipe that has |
| 1244 | areas totally unrelated to what you are trying to accomplish with |
| 1245 | your recipe, not recognizing areas of the recipe that you might have |
| 1246 | to add from scratch, and so forth. All these risks stem from |
| 1247 | unfamiliarity with the existing recipe space. |
| 1248 | |
| 1249 | - *Use and modify the following skeleton recipe:* If for some reason |
| 1250 | you do not want to use ``recipetool`` and you cannot find an existing |
| 1251 | recipe that is close to meeting your needs, you can use the following |
| 1252 | structure to provide the fundamental areas of a new recipe. |
| 1253 | :: |
| 1254 | |
| 1255 | DESCRIPTION = "" |
| 1256 | HOMEPAGE = "" |
| 1257 | LICENSE = "" |
| 1258 | SECTION = "" |
| 1259 | DEPENDS = "" |
| 1260 | LIC_FILES_CHKSUM = "" |
| 1261 | |
| 1262 | SRC_URI = "" |
| 1263 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1264 | Storing and Naming the Recipe |
| 1265 | ----------------------------- |
| 1266 | |
| 1267 | Once you have your base recipe, you should put it in your own layer and |
| 1268 | name it appropriately. Locating it correctly ensures that the |
| 1269 | OpenEmbedded build system can find it when you use BitBake to process |
| 1270 | the recipe. |
| 1271 | |
| 1272 | - *Storing Your Recipe:* The OpenEmbedded build system locates your |
| 1273 | recipe through the layer's ``conf/layer.conf`` file and the |
| 1274 | :term:`BBFILES` variable. This |
| 1275 | variable sets up a path from which the build system can locate |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 1276 | recipes. Here is the typical use:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1277 | |
| 1278 | BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \ |
| 1279 | ${LAYERDIR}/recipes-*/*/*.bbappend" |
| 1280 | |
| 1281 | Consequently, you need to be sure you locate your new recipe inside |
| 1282 | your layer such that it can be found. |
| 1283 | |
| 1284 | You can find more information on how layers are structured in the |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 1285 | ":ref:`dev-manual/common-tasks:understanding and creating layers`" section. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1286 | |
| 1287 | - *Naming Your Recipe:* When you name your recipe, you need to follow |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 1288 | this naming convention:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1289 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1290 | basename_version.bb |
| 1291 | |
| 1292 | Use lower-cased characters and do not include the reserved suffixes |
| 1293 | ``-native``, ``-cross``, ``-initial``, or ``-dev`` casually (i.e. do not use |
| 1294 | them as part of your recipe name unless the string applies). Here are some |
| 1295 | examples: |
| 1296 | |
| 1297 | .. code-block:: none |
| 1298 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1299 | cups_1.7.0.bb |
| 1300 | gawk_4.0.2.bb |
| 1301 | irssi_0.8.16-rc1.bb |
| 1302 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1303 | Running a Build on the Recipe |
| 1304 | ----------------------------- |
| 1305 | |
| 1306 | Creating a new recipe is usually an iterative process that requires |
| 1307 | using BitBake to process the recipe multiple times in order to |
| 1308 | progressively discover and add information to the recipe file. |
| 1309 | |
| 1310 | Assuming you have sourced the build environment setup script (i.e. |
| 1311 | :ref:`structure-core-script`) and you are in |
| 1312 | the :term:`Build Directory`, use |
| 1313 | BitBake to process your recipe. All you need to provide is the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 1314 | ``basename`` of the recipe as described in the previous section:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1315 | |
| 1316 | $ bitbake basename |
| 1317 | |
| 1318 | During the build, the OpenEmbedded build system creates a temporary work |
| 1319 | directory for each recipe |
| 1320 | (``${``\ :term:`WORKDIR`\ ``}``) |
| 1321 | where it keeps extracted source files, log files, intermediate |
| 1322 | compilation and packaging files, and so forth. |
| 1323 | |
| 1324 | The path to the per-recipe temporary work directory depends on the |
| 1325 | context in which it is being built. The quickest way to find this path |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 1326 | is to have BitBake return it by running the following:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1327 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1328 | $ bitbake -e basename | grep ^WORKDIR= |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1329 | |
| 1330 | As an example, assume a Source Directory |
| 1331 | top-level folder named ``poky``, a default Build Directory at |
| 1332 | ``poky/build``, and a ``qemux86-poky-linux`` machine target system. |
| 1333 | Furthermore, suppose your recipe is named ``foo_1.3.0.bb``. In this |
| 1334 | case, the work directory the build system uses to build the package |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 1335 | would be as follows:: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1336 | |
| 1337 | poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0 |
| 1338 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1339 | Inside this directory you can find sub-directories such as ``image``, |
| 1340 | ``packages-split``, and ``temp``. After the build, you can examine these |
| 1341 | to determine how well the build went. |
| 1342 | |
| 1343 | .. note:: |
| 1344 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1345 | You can find log files for each task in the recipe's ``temp`` |
| 1346 | directory (e.g. ``poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0/temp``). |
| 1347 | Log files are named ``log.taskname`` (e.g. ``log.do_configure``, |
| 1348 | ``log.do_fetch``, and ``log.do_compile``). |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1349 | |
| 1350 | You can find more information about the build process in |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 1351 | ":doc:`/overview-manual/development-environment`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1352 | chapter of the Yocto Project Overview and Concepts Manual. |
| 1353 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1354 | Fetching Code |
| 1355 | ------------- |
| 1356 | |
| 1357 | The first thing your recipe must do is specify how to fetch the source |
| 1358 | files. Fetching is controlled mainly through the |
| 1359 | :term:`SRC_URI` variable. Your recipe |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1360 | must have a :term:`SRC_URI` variable that points to where the source is |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1361 | located. For a graphical representation of source locations, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 1362 | ":ref:`overview-manual/concepts:sources`" section in |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1363 | the Yocto Project Overview and Concepts Manual. |
| 1364 | |
| 1365 | The :ref:`ref-tasks-fetch` task uses |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1366 | the prefix of each entry in the :term:`SRC_URI` variable value to determine |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 1367 | which :ref:`fetcher <bitbake:bitbake-user-manual/bitbake-user-manual-fetching:fetchers>` to use to get your |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1368 | source files. It is the :term:`SRC_URI` variable that triggers the fetcher. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1369 | The :ref:`ref-tasks-patch` task uses |
| 1370 | the variable after source is fetched to apply patches. The OpenEmbedded |
| 1371 | build system uses |
| 1372 | :term:`FILESOVERRIDES` for |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1373 | scanning directory locations for local files in :term:`SRC_URI`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1374 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1375 | The :term:`SRC_URI` variable in your recipe must define each unique location |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1376 | for your source files. It is good practice to not hard-code version |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 1377 | numbers in a URL used in :term:`SRC_URI`. Rather than hard-code these |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1378 | values, use ``${``\ :term:`PV`\ ``}``, |
| 1379 | which causes the fetch process to use the version specified in the |
| 1380 | recipe filename. Specifying the version in this manner means that |
| 1381 | upgrading the recipe to a future version is as simple as renaming the |
| 1382 | recipe to match the new version. |
| 1383 | |
| 1384 | Here is a simple example from the |
| 1385 | ``meta/recipes-devtools/strace/strace_5.5.bb`` recipe where the source |
| 1386 | comes from a single tarball. Notice the use of the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 1387 | :term:`PV` variable:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1388 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1389 | SRC_URI = "https://strace.io/files/${PV}/strace-${PV}.tar.xz \ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1390 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1391 | Files mentioned in :term:`SRC_URI` whose names end in a typical archive |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1392 | extension (e.g. ``.tar``, ``.tar.gz``, ``.tar.bz2``, ``.zip``, and so |
| 1393 | forth), are automatically extracted during the |
| 1394 | :ref:`ref-tasks-unpack` task. For |
| 1395 | another example that specifies these types of files, see the |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 1396 | ":ref:`dev-manual/common-tasks:autotooled package`" section. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1397 | |
| 1398 | Another way of specifying source is from an SCM. For Git repositories, |
| 1399 | you must specify :term:`SRCREV` and |
| 1400 | you should specify :term:`PV` to include |
| 1401 | the revision with :term:`SRCPV`. Here |
| 1402 | is an example from the recipe |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 1403 | ``meta/recipes-kernel/blktrace/blktrace_git.bb``:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1404 | |
| 1405 | SRCREV = "d6918c8832793b4205ed3bfede78c2f915c23385" |
| 1406 | |
| 1407 | PR = "r6" |
| 1408 | PV = "1.0.5+git${SRCPV}" |
| 1409 | |
| 1410 | SRC_URI = "git://git.kernel.dk/blktrace.git \ |
| 1411 | file://ldflags.patch" |
| 1412 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1413 | If your :term:`SRC_URI` statement includes URLs pointing to individual files |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1414 | fetched from a remote server other than a version control system, |
| 1415 | BitBake attempts to verify the files against checksums defined in your |
| 1416 | recipe to ensure they have not been tampered with or otherwise modified |
| 1417 | since the recipe was written. Two checksums are used: |
| 1418 | ``SRC_URI[md5sum]`` and ``SRC_URI[sha256sum]``. |
| 1419 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1420 | If your :term:`SRC_URI` variable points to more than a single URL (excluding |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1421 | SCM URLs), you need to provide the ``md5`` and ``sha256`` checksums for |
| 1422 | each URL. For these cases, you provide a name for each URL as part of |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1423 | the :term:`SRC_URI` and then reference that name in the subsequent checksum |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1424 | statements. Here is an example combining lines from the files |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 1425 | ``git.inc`` and ``git_2.24.1.bb``:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1426 | |
| 1427 | SRC_URI = "${KERNELORG_MIRROR}/software/scm/git/git-${PV}.tar.gz;name=tarball \ |
| 1428 | ${KERNELORG_MIRROR}/software/scm/git/git-manpages-${PV}.tar.gz;name=manpages" |
| 1429 | |
| 1430 | SRC_URI[tarball.md5sum] = "166bde96adbbc11c8843d4f8f4f9811b" |
| 1431 | SRC_URI[tarball.sha256sum] = "ad5334956301c86841eb1e5b1bb20884a6bad89a10a6762c958220c7cf64da02" |
| 1432 | SRC_URI[manpages.md5sum] = "31c2272a8979022497ba3d4202df145d" |
| 1433 | SRC_URI[manpages.sha256sum] = "9a7ae3a093bea39770eb96ca3e5b40bff7af0b9f6123f089d7821d0e5b8e1230" |
| 1434 | |
| 1435 | Proper values for ``md5`` and ``sha256`` checksums might be available |
| 1436 | with other signatures on the download page for the upstream source (e.g. |
| 1437 | ``md5``, ``sha1``, ``sha256``, ``GPG``, and so forth). Because the |
| 1438 | OpenEmbedded build system only deals with ``sha256sum`` and ``md5sum``, |
| 1439 | you should verify all the signatures you find by hand. |
| 1440 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1441 | If no :term:`SRC_URI` checksums are specified when you attempt to build the |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1442 | recipe, or you provide an incorrect checksum, the build will produce an |
| 1443 | error for each missing or incorrect checksum. As part of the error |
| 1444 | message, the build system provides the checksum string corresponding to |
| 1445 | the fetched file. Once you have the correct checksums, you can copy and |
| 1446 | paste them into your recipe and then run the build again to continue. |
| 1447 | |
| 1448 | .. note:: |
| 1449 | |
| 1450 | As mentioned, if the upstream source provides signatures for |
| 1451 | verifying the downloaded source code, you should verify those |
| 1452 | manually before setting the checksum values in the recipe and |
| 1453 | continuing with the build. |
| 1454 | |
| 1455 | This final example is a bit more complicated and is from the |
| 1456 | ``meta/recipes-sato/rxvt-unicode/rxvt-unicode_9.20.bb`` recipe. The |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1457 | example's :term:`SRC_URI` statement identifies multiple files as the source |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1458 | files for the recipe: a tarball, a patch file, a desktop file, and an |
| 1459 | icon. |
| 1460 | :: |
| 1461 | |
| 1462 | SRC_URI = "http://dist.schmorp.de/rxvt-unicode/Attic/rxvt-unicode-${PV}.tar.bz2 \ |
| 1463 | file://xwc.patch \ |
| 1464 | file://rxvt.desktop \ |
| 1465 | file://rxvt.png" |
| 1466 | |
| 1467 | When you specify local files using the ``file://`` URI protocol, the |
| 1468 | build system fetches files from the local machine. The path is relative |
| 1469 | to the :term:`FILESPATH` variable |
| 1470 | and searches specific directories in a certain order: |
| 1471 | ``${``\ :term:`BP`\ ``}``, |
| 1472 | ``${``\ :term:`BPN`\ ``}``, and |
| 1473 | ``files``. The directories are assumed to be subdirectories of the |
| 1474 | directory in which the recipe or append file resides. For another |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 1475 | example that specifies these types of files, see the |
| 1476 | ":ref:`dev-manual/common-tasks:single .c file package (hello world!)`" section. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1477 | |
| 1478 | The previous example also specifies a patch file. Patch files are files |
| 1479 | whose names usually end in ``.patch`` or ``.diff`` but can end with |
| 1480 | compressed suffixes such as ``diff.gz`` and ``patch.bz2``, for example. |
| 1481 | The build system automatically applies patches as described in the |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 1482 | ":ref:`dev-manual/common-tasks:patching code`" section. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1483 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1484 | Unpacking Code |
| 1485 | -------------- |
| 1486 | |
| 1487 | During the build, the |
| 1488 | :ref:`ref-tasks-unpack` task unpacks |
| 1489 | the source with ``${``\ :term:`S`\ ``}`` |
| 1490 | pointing to where it is unpacked. |
| 1491 | |
| 1492 | If you are fetching your source files from an upstream source archived |
| 1493 | tarball and the tarball's internal structure matches the common |
| 1494 | convention of a top-level subdirectory named |
| 1495 | ``${``\ :term:`BPN`\ ``}-${``\ :term:`PV`\ ``}``, |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1496 | then you do not need to set :term:`S`. However, if :term:`SRC_URI` specifies to |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1497 | fetch source from an archive that does not use this convention, or from |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1498 | an SCM like Git or Subversion, your recipe needs to define :term:`S`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1499 | |
| 1500 | If processing your recipe using BitBake successfully unpacks the source |
| 1501 | files, you need to be sure that the directory pointed to by ``${S}`` |
| 1502 | matches the structure of the source. |
| 1503 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1504 | Patching Code |
| 1505 | ------------- |
| 1506 | |
| 1507 | Sometimes it is necessary to patch code after it has been fetched. Any |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1508 | files mentioned in :term:`SRC_URI` whose names end in ``.patch`` or |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1509 | ``.diff`` or compressed versions of these suffixes (e.g. ``diff.gz`` are |
| 1510 | treated as patches. The |
| 1511 | :ref:`ref-tasks-patch` task |
| 1512 | automatically applies these patches. |
| 1513 | |
| 1514 | The build system should be able to apply patches with the "-p1" option |
| 1515 | (i.e. one directory level in the path will be stripped off). If your |
| 1516 | patch needs to have more directory levels stripped off, specify the |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1517 | number of levels using the "striplevel" option in the :term:`SRC_URI` entry |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1518 | for the patch. Alternatively, if your patch needs to be applied in a |
| 1519 | specific subdirectory that is not specified in the patch file, use the |
| 1520 | "patchdir" option in the entry. |
| 1521 | |
| 1522 | As with all local files referenced in |
| 1523 | :term:`SRC_URI` using ``file://``, |
| 1524 | you should place patch files in a directory next to the recipe either |
| 1525 | named the same as the base name of the recipe |
| 1526 | (:term:`BP` and |
| 1527 | :term:`BPN`) or "files". |
| 1528 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1529 | Licensing |
| 1530 | --------- |
| 1531 | |
| 1532 | Your recipe needs to have both the |
| 1533 | :term:`LICENSE` and |
| 1534 | :term:`LIC_FILES_CHKSUM` |
| 1535 | variables: |
| 1536 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1537 | - :term:`LICENSE`: This variable specifies the license for the software. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1538 | If you do not know the license under which the software you are |
| 1539 | building is distributed, you should go to the source code and look |
| 1540 | for that information. Typical files containing this information |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1541 | include ``COPYING``, :term:`LICENSE`, and ``README`` files. You could |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1542 | also find the information near the top of a source file. For example, |
| 1543 | given a piece of software licensed under the GNU General Public |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1544 | License version 2, you would set :term:`LICENSE` as follows:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1545 | |
| 1546 | LICENSE = "GPLv2" |
| 1547 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1548 | The licenses you specify within :term:`LICENSE` can have any name as long |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1549 | as you do not use spaces, since spaces are used as separators between |
| 1550 | license names. For standard licenses, use the names of the files in |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1551 | ``meta/files/common-licenses/`` or the :term:`SPDXLICENSEMAP` flag names |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1552 | defined in ``meta/conf/licenses.conf``. |
| 1553 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1554 | - :term:`LIC_FILES_CHKSUM`: The OpenEmbedded build system uses this |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1555 | variable to make sure the license text has not changed. If it has, |
| 1556 | the build produces an error and it affords you the chance to figure |
| 1557 | it out and correct the problem. |
| 1558 | |
| 1559 | You need to specify all applicable licensing files for the software. |
| 1560 | At the end of the configuration step, the build process will compare |
| 1561 | the checksums of the files to be sure the text has not changed. Any |
| 1562 | differences result in an error with the message containing the |
| 1563 | current checksum. For more explanation and examples of how to set the |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1564 | :term:`LIC_FILES_CHKSUM` variable, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 1565 | ":ref:`dev-manual/common-tasks:tracking license changes`" section. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1566 | |
| 1567 | To determine the correct checksum string, you can list the |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1568 | appropriate files in the :term:`LIC_FILES_CHKSUM` variable with incorrect |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1569 | md5 strings, attempt to build the software, and then note the |
| 1570 | resulting error messages that will report the correct md5 strings. |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 1571 | See the ":ref:`dev-manual/common-tasks:fetching code`" section for |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1572 | additional information. |
| 1573 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 1574 | Here is an example that assumes the software has a ``COPYING`` file:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1575 | |
| 1576 | LIC_FILES_CHKSUM = "file://COPYING;md5=xxx" |
| 1577 | |
| 1578 | When you try to build the |
| 1579 | software, the build system will produce an error and give you the |
| 1580 | correct string that you can substitute into the recipe file for a |
| 1581 | subsequent build. |
| 1582 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1583 | Dependencies |
| 1584 | ------------ |
| 1585 | |
| 1586 | Most software packages have a short list of other packages that they |
| 1587 | require, which are called dependencies. These dependencies fall into two |
| 1588 | main categories: build-time dependencies, which are required when the |
| 1589 | software is built; and runtime dependencies, which are required to be |
| 1590 | installed on the target in order for the software to run. |
| 1591 | |
| 1592 | Within a recipe, you specify build-time dependencies using the |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 1593 | :term:`DEPENDS` variable. Although there are nuances, |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1594 | items specified in :term:`DEPENDS` should be names of other |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1595 | recipes. It is important that you specify all build-time dependencies |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1596 | explicitly. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1597 | |
| 1598 | Another consideration is that configure scripts might automatically |
| 1599 | check for optional dependencies and enable corresponding functionality |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1600 | if those dependencies are found. If you wish to make a recipe that is |
| 1601 | more generally useful (e.g. publish the recipe in a layer for others to |
| 1602 | use), instead of hard-disabling the functionality, you can use the |
| 1603 | :term:`PACKAGECONFIG` variable to allow functionality and the |
| 1604 | corresponding dependencies to be enabled and disabled easily by other |
| 1605 | users of the recipe. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1606 | |
| 1607 | Similar to build-time dependencies, you specify runtime dependencies |
| 1608 | through a variable - |
| 1609 | :term:`RDEPENDS`, which is |
| 1610 | package-specific. All variables that are package-specific need to have |
| 1611 | the name of the package added to the end as an override. Since the main |
| 1612 | package for a recipe has the same name as the recipe, and the recipe's |
| 1613 | name can be found through the |
| 1614 | ``${``\ :term:`PN`\ ``}`` variable, then |
| 1615 | you specify the dependencies for the main package by setting |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 1616 | ``RDEPENDS:${PN}``. If the package were named ``${PN}-tools``, then you |
| 1617 | would set ``RDEPENDS:${PN}-tools``, and so forth. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1618 | |
| 1619 | Some runtime dependencies will be set automatically at packaging time. |
| 1620 | These dependencies include any shared library dependencies (i.e. if a |
| 1621 | package "example" contains "libexample" and another package "mypackage" |
| 1622 | contains a binary that links to "libexample" then the OpenEmbedded build |
| 1623 | system will automatically add a runtime dependency to "mypackage" on |
| 1624 | "example"). See the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 1625 | ":ref:`overview-manual/concepts:automatically added runtime dependencies`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1626 | section in the Yocto Project Overview and Concepts Manual for further |
| 1627 | details. |
| 1628 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1629 | Configuring the Recipe |
| 1630 | ---------------------- |
| 1631 | |
| 1632 | Most software provides some means of setting build-time configuration |
| 1633 | options before compilation. Typically, setting these options is |
| 1634 | accomplished by running a configure script with options, or by modifying |
| 1635 | a build configuration file. |
| 1636 | |
| 1637 | .. note:: |
| 1638 | |
| 1639 | As of Yocto Project Release 1.7, some of the core recipes that |
| 1640 | package binary configuration scripts now disable the scripts due to |
| 1641 | the scripts previously requiring error-prone path substitution. The |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1642 | OpenEmbedded build system uses ``pkg-config`` now, which is much more |
| 1643 | robust. You can find a list of the ``*-config`` scripts that are disabled |
| 1644 | in the ":ref:`migration-1.7-binary-configuration-scripts-disabled`" section |
| 1645 | in the Yocto Project Reference Manual. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1646 | |
| 1647 | A major part of build-time configuration is about checking for |
| 1648 | build-time dependencies and possibly enabling optional functionality as |
| 1649 | a result. You need to specify any build-time dependencies for the |
| 1650 | software you are building in your recipe's |
| 1651 | :term:`DEPENDS` value, in terms of |
| 1652 | other recipes that satisfy those dependencies. You can often find |
| 1653 | build-time or runtime dependencies described in the software's |
| 1654 | documentation. |
| 1655 | |
| 1656 | The following list provides configuration items of note based on how |
| 1657 | your software is built: |
| 1658 | |
| 1659 | - *Autotools:* If your source files have a ``configure.ac`` file, then |
| 1660 | your software is built using Autotools. If this is the case, you just |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 1661 | need to modify the configuration. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1662 | |
| 1663 | When using Autotools, your recipe needs to inherit the |
| 1664 | :ref:`autotools <ref-classes-autotools>` class |
| 1665 | and your recipe does not have to contain a |
| 1666 | :ref:`ref-tasks-configure` task. |
| 1667 | However, you might still want to make some adjustments. For example, |
| 1668 | you can set |
| 1669 | :term:`EXTRA_OECONF` or |
| 1670 | :term:`PACKAGECONFIG_CONFARGS` |
| 1671 | to pass any needed configure options that are specific to the recipe. |
| 1672 | |
| 1673 | - *CMake:* If your source files have a ``CMakeLists.txt`` file, then |
| 1674 | your software is built using CMake. If this is the case, you just |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 1675 | need to modify the configuration. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1676 | |
| 1677 | When you use CMake, your recipe needs to inherit the |
| 1678 | :ref:`cmake <ref-classes-cmake>` class and your |
| 1679 | recipe does not have to contain a |
| 1680 | :ref:`ref-tasks-configure` task. |
| 1681 | You can make some adjustments by setting |
| 1682 | :term:`EXTRA_OECMAKE` to |
| 1683 | pass any needed configure options that are specific to the recipe. |
| 1684 | |
| 1685 | .. note:: |
| 1686 | |
| 1687 | If you need to install one or more custom CMake toolchain files |
| 1688 | that are supplied by the application you are building, install the |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1689 | files to ``${D}${datadir}/cmake/Modules`` during ``do_install``. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1690 | |
| 1691 | - *Other:* If your source files do not have a ``configure.ac`` or |
| 1692 | ``CMakeLists.txt`` file, then your software is built using some |
| 1693 | method other than Autotools or CMake. If this is the case, you |
| 1694 | normally need to provide a |
| 1695 | :ref:`ref-tasks-configure` task |
| 1696 | in your recipe unless, of course, there is nothing to configure. |
| 1697 | |
| 1698 | Even if your software is not being built by Autotools or CMake, you |
| 1699 | still might not need to deal with any configuration issues. You need |
| 1700 | to determine if configuration is even a required step. You might need |
| 1701 | to modify a Makefile or some configuration file used for the build to |
| 1702 | specify necessary build options. Or, perhaps you might need to run a |
| 1703 | provided, custom configure script with the appropriate options. |
| 1704 | |
| 1705 | For the case involving a custom configure script, you would run |
| 1706 | ``./configure --help`` and look for the options you need to set. |
| 1707 | |
| 1708 | Once configuration succeeds, it is always good practice to look at the |
| 1709 | ``log.do_configure`` file to ensure that the appropriate options have |
| 1710 | been enabled and no additional build-time dependencies need to be added |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1711 | to :term:`DEPENDS`. For example, if the configure script reports that it |
| 1712 | found something not mentioned in :term:`DEPENDS`, or that it did not find |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1713 | something that it needed for some desired optional functionality, then |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1714 | you would need to add those to :term:`DEPENDS`. Looking at the log might |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1715 | also reveal items being checked for, enabled, or both that you do not |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1716 | want, or items not being found that are in :term:`DEPENDS`, in which case |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1717 | you would need to look at passing extra options to the configure script |
| 1718 | as needed. For reference information on configure options specific to |
| 1719 | the software you are building, you can consult the output of the |
| 1720 | ``./configure --help`` command within ``${S}`` or consult the software's |
| 1721 | upstream documentation. |
| 1722 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1723 | Using Headers to Interface with Devices |
| 1724 | --------------------------------------- |
| 1725 | |
| 1726 | If your recipe builds an application that needs to communicate with some |
| 1727 | device or needs an API into a custom kernel, you will need to provide |
| 1728 | appropriate header files. Under no circumstances should you ever modify |
| 1729 | the existing |
| 1730 | ``meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc`` file. |
| 1731 | These headers are used to build ``libc`` and must not be compromised |
| 1732 | with custom or machine-specific header information. If you customize |
| 1733 | ``libc`` through modified headers all other applications that use |
| 1734 | ``libc`` thus become affected. |
| 1735 | |
| 1736 | .. note:: |
| 1737 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1738 | Never copy and customize the ``libc`` header file (i.e. |
| 1739 | ``meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc``). |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1740 | |
| 1741 | The correct way to interface to a device or custom kernel is to use a |
| 1742 | separate package that provides the additional headers for the driver or |
| 1743 | other unique interfaces. When doing so, your application also becomes |
| 1744 | responsible for creating a dependency on that specific provider. |
| 1745 | |
| 1746 | Consider the following: |
| 1747 | |
| 1748 | - Never modify ``linux-libc-headers.inc``. Consider that file to be |
| 1749 | part of the ``libc`` system, and not something you use to access the |
| 1750 | kernel directly. You should access ``libc`` through specific ``libc`` |
| 1751 | calls. |
| 1752 | |
| 1753 | - Applications that must talk directly to devices should either provide |
| 1754 | necessary headers themselves, or establish a dependency on a special |
| 1755 | headers package that is specific to that driver. |
| 1756 | |
| 1757 | For example, suppose you want to modify an existing header that adds I/O |
| 1758 | control or network support. If the modifications are used by a small |
| 1759 | number programs, providing a unique version of a header is easy and has |
| 1760 | little impact. When doing so, bear in mind the guidelines in the |
| 1761 | previous list. |
| 1762 | |
| 1763 | .. note:: |
| 1764 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1765 | If for some reason your changes need to modify the behavior of the ``libc``, |
| 1766 | and subsequently all other applications on the system, use a ``.bbappend`` |
| 1767 | to modify the ``linux-kernel-headers.inc`` file. However, take care to not |
| 1768 | make the changes machine specific. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1769 | |
| 1770 | Consider a case where your kernel is older and you need an older |
| 1771 | ``libc`` ABI. The headers installed by your recipe should still be a |
| 1772 | standard mainline kernel, not your own custom one. |
| 1773 | |
| 1774 | When you use custom kernel headers you need to get them from |
| 1775 | :term:`STAGING_KERNEL_DIR`, |
| 1776 | which is the directory with kernel headers that are required to build |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 1777 | out-of-tree modules. Your recipe will also need the following:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1778 | |
| 1779 | do_configure[depends] += "virtual/kernel:do_shared_workdir" |
| 1780 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1781 | Compilation |
| 1782 | ----------- |
| 1783 | |
| 1784 | During a build, the ``do_compile`` task happens after source is fetched, |
| 1785 | unpacked, and configured. If the recipe passes through ``do_compile`` |
| 1786 | successfully, nothing needs to be done. |
| 1787 | |
| 1788 | However, if the compile step fails, you need to diagnose the failure. |
| 1789 | Here are some common issues that cause failures. |
| 1790 | |
| 1791 | .. note:: |
| 1792 | |
| 1793 | For cases where improper paths are detected for configuration files |
| 1794 | 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] | 1795 | the more robust ``pkg-config``. See the note in section |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 1796 | ":ref:`dev-manual/common-tasks:Configuring the Recipe`" for additional information. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1797 | |
| 1798 | - *Parallel build failures:* These failures manifest themselves as |
| 1799 | intermittent errors, or errors reporting that a file or directory |
| 1800 | that should be created by some other part of the build process could |
| 1801 | not be found. This type of failure can occur even if, upon |
| 1802 | inspection, the file or directory does exist after the build has |
| 1803 | failed, because that part of the build process happened in the wrong |
| 1804 | order. |
| 1805 | |
| 1806 | To fix the problem, you need to either satisfy the missing dependency |
| 1807 | in the Makefile or whatever script produced the Makefile, or (as a |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 1808 | workaround) set :term:`PARALLEL_MAKE` to an empty string:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1809 | |
| 1810 | PARALLEL_MAKE = "" |
| 1811 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 1812 | For information on parallel Makefile issues, see the |
| 1813 | ":ref:`dev-manual/common-tasks:debugging parallel make races`" section. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1814 | |
| 1815 | - *Improper host path usage:* This failure applies to recipes building |
| 1816 | for the target or ``nativesdk`` only. The failure occurs when the |
| 1817 | compilation process uses improper headers, libraries, or other files |
| 1818 | from the host system when cross-compiling for the target. |
| 1819 | |
| 1820 | To fix the problem, examine the ``log.do_compile`` file to identify |
| 1821 | the host paths being used (e.g. ``/usr/include``, ``/usr/lib``, and |
| 1822 | so forth) and then either add configure options, apply a patch, or do |
| 1823 | both. |
| 1824 | |
| 1825 | - *Failure to find required libraries/headers:* If a build-time |
| 1826 | dependency is missing because it has not been declared in |
| 1827 | :term:`DEPENDS`, or because the |
| 1828 | dependency exists but the path used by the build process to find the |
| 1829 | file is incorrect and the configure step did not detect it, the |
| 1830 | compilation process could fail. For either of these failures, the |
| 1831 | compilation process notes that files could not be found. In these |
| 1832 | cases, you need to go back and add additional options to the |
| 1833 | configure script as well as possibly add additional build-time |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1834 | dependencies to :term:`DEPENDS`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1835 | |
| 1836 | Occasionally, it is necessary to apply a patch to the source to |
| 1837 | ensure the correct paths are used. If you need to specify paths to |
| 1838 | find files staged into the sysroot from other recipes, use the |
| 1839 | variables that the OpenEmbedded build system provides (e.g. |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 1840 | :term:`STAGING_BINDIR`, :term:`STAGING_INCDIR`, :term:`STAGING_DATADIR`, and so |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1841 | forth). |
| 1842 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1843 | Installing |
| 1844 | ---------- |
| 1845 | |
| 1846 | During ``do_install``, the task copies the built files along with their |
| 1847 | hierarchy to locations that would mirror their locations on the target |
| 1848 | device. The installation process copies files from the |
| 1849 | ``${``\ :term:`S`\ ``}``, |
| 1850 | ``${``\ :term:`B`\ ``}``, and |
| 1851 | ``${``\ :term:`WORKDIR`\ ``}`` |
| 1852 | directories to the ``${``\ :term:`D`\ ``}`` |
| 1853 | directory to create the structure as it should appear on the target |
| 1854 | system. |
| 1855 | |
| 1856 | How your software is built affects what you must do to be sure your |
| 1857 | software is installed correctly. The following list describes what you |
| 1858 | must do for installation depending on the type of build system used by |
| 1859 | the software being built: |
| 1860 | |
| 1861 | - *Autotools and CMake:* If the software your recipe is building uses |
| 1862 | Autotools or CMake, the OpenEmbedded build system understands how to |
| 1863 | install the software. Consequently, you do not have to have a |
| 1864 | ``do_install`` task as part of your recipe. You just need to make |
| 1865 | sure the install portion of the build completes with no issues. |
| 1866 | However, if you wish to install additional files not already being |
| 1867 | installed by ``make install``, you should do this using a |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 1868 | ``do_install:append`` function using the install command as described |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1869 | in the "Manual" bulleted item later in this list. |
| 1870 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1871 | - *Other (using* ``make install``\ *)*: You need to define a ``do_install`` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1872 | function in your recipe. The function should call |
| 1873 | ``oe_runmake install`` and will likely need to pass in the |
| 1874 | destination directory as well. How you pass that path is dependent on |
| 1875 | how the ``Makefile`` being run is written (e.g. ``DESTDIR=${D}``, |
| 1876 | ``PREFIX=${D}``, ``INSTALLROOT=${D}``, and so forth). |
| 1877 | |
| 1878 | For an example recipe using ``make install``, see the |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 1879 | ":ref:`dev-manual/common-tasks:makefile-based package`" section. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1880 | |
| 1881 | - *Manual:* You need to define a ``do_install`` function in your |
| 1882 | recipe. The function must first use ``install -d`` to create the |
| 1883 | directories under |
| 1884 | ``${``\ :term:`D`\ ``}``. Once the |
| 1885 | directories exist, your function can use ``install`` to manually |
| 1886 | install the built software into the directories. |
| 1887 | |
| 1888 | You can find more information on ``install`` at |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1889 | https://www.gnu.org/software/coreutils/manual/html_node/install-invocation.html. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1890 | |
| 1891 | For the scenarios that do not use Autotools or CMake, you need to track |
| 1892 | the installation and diagnose and fix any issues until everything |
| 1893 | installs correctly. You need to look in the default location of |
| 1894 | ``${D}``, which is ``${WORKDIR}/image``, to be sure your files have been |
| 1895 | installed correctly. |
| 1896 | |
| 1897 | .. note:: |
| 1898 | |
| 1899 | - During the installation process, you might need to modify some of |
| 1900 | the installed files to suit the target layout. For example, you |
| 1901 | might need to replace hard-coded paths in an initscript with |
| 1902 | values of variables provided by the build system, such as |
| 1903 | replacing ``/usr/bin/`` with ``${bindir}``. If you do perform such |
| 1904 | modifications during ``do_install``, be sure to modify the |
| 1905 | destination file after copying rather than before copying. |
| 1906 | Modifying after copying ensures that the build system can |
| 1907 | re-execute ``do_install`` if needed. |
| 1908 | |
| 1909 | - ``oe_runmake install``, which can be run directly or can be run |
| 1910 | indirectly by the |
| 1911 | :ref:`autotools <ref-classes-autotools>` and |
| 1912 | :ref:`cmake <ref-classes-cmake>` classes, |
| 1913 | runs ``make install`` in parallel. Sometimes, a Makefile can have |
| 1914 | missing dependencies between targets that can result in race |
| 1915 | conditions. If you experience intermittent failures during |
| 1916 | ``do_install``, you might be able to work around them by disabling |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 1917 | parallel Makefile installs by adding the following to the recipe:: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1918 | |
| 1919 | PARALLEL_MAKEINST = "" |
| 1920 | |
| 1921 | See :term:`PARALLEL_MAKEINST` for additional information. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1922 | |
| 1923 | - If you need to install one or more custom CMake toolchain files |
| 1924 | that are supplied by the application you are building, install the |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1925 | files to ``${D}${datadir}/cmake/Modules`` during |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1926 | :ref:`ref-tasks-install`. |
| 1927 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1928 | Enabling System Services |
| 1929 | ------------------------ |
| 1930 | |
| 1931 | If you want to install a service, which is a process that usually starts |
| 1932 | on boot and runs in the background, then you must include some |
| 1933 | additional definitions in your recipe. |
| 1934 | |
| 1935 | If you are adding services and the service initialization script or the |
| 1936 | service file itself is not installed, you must provide for that |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 1937 | installation in your recipe using a ``do_install:append`` function. If |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1938 | your recipe already has a ``do_install`` function, update the function |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 1939 | near its end rather than adding an additional ``do_install:append`` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1940 | function. |
| 1941 | |
| 1942 | When you create the installation for your services, you need to |
| 1943 | accomplish what is normally done by ``make install``. In other words, |
| 1944 | make sure your installation arranges the output similar to how it is |
| 1945 | arranged on the target system. |
| 1946 | |
| 1947 | The OpenEmbedded build system provides support for starting services two |
| 1948 | different ways: |
| 1949 | |
| 1950 | - *SysVinit:* SysVinit is a system and service manager that manages the |
| 1951 | init system used to control the very basic functions of your system. |
| 1952 | The init program is the first program started by the Linux kernel |
| 1953 | when the system boots. Init then controls the startup, running and |
| 1954 | shutdown of all other programs. |
| 1955 | |
| 1956 | To enable a service using SysVinit, your recipe needs to inherit the |
| 1957 | :ref:`update-rc.d <ref-classes-update-rc.d>` |
| 1958 | class. The class helps facilitate safely installing the package on |
| 1959 | the target. |
| 1960 | |
| 1961 | You will need to set the |
| 1962 | :term:`INITSCRIPT_PACKAGES`, |
| 1963 | :term:`INITSCRIPT_NAME`, |
| 1964 | and |
| 1965 | :term:`INITSCRIPT_PARAMS` |
| 1966 | variables within your recipe. |
| 1967 | |
| 1968 | - *systemd:* System Management Daemon (systemd) was designed to replace |
| 1969 | SysVinit and to provide enhanced management of services. For more |
| 1970 | information on systemd, see the systemd homepage at |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 1971 | https://freedesktop.org/wiki/Software/systemd/. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1972 | |
| 1973 | To enable a service using systemd, your recipe needs to inherit the |
| 1974 | :ref:`systemd <ref-classes-systemd>` class. See |
| 1975 | the ``systemd.bbclass`` file located in your :term:`Source Directory` |
| 1976 | section for |
| 1977 | more information. |
| 1978 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1979 | Packaging |
| 1980 | --------- |
| 1981 | |
| 1982 | Successful packaging is a combination of automated processes performed |
| 1983 | by the OpenEmbedded build system and some specific steps you need to |
| 1984 | take. The following list describes the process: |
| 1985 | |
| 1986 | - *Splitting Files*: The ``do_package`` task splits the files produced |
| 1987 | by the recipe into logical components. Even software that produces a |
| 1988 | single binary might still have debug symbols, documentation, and |
| 1989 | other logical components that should be split out. The ``do_package`` |
| 1990 | task ensures that files are split up and packaged correctly. |
| 1991 | |
| 1992 | - *Running QA Checks*: The |
| 1993 | :ref:`insane <ref-classes-insane>` class adds a |
| 1994 | step to the package generation process so that output quality |
| 1995 | assurance checks are generated by the OpenEmbedded build system. This |
| 1996 | step performs a range of checks to be sure the build's output is free |
| 1997 | of common problems that show up during runtime. For information on |
| 1998 | these checks, see the |
| 1999 | :ref:`insane <ref-classes-insane>` class and |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 2000 | the ":ref:`ref-manual/qa-checks:qa error and warning messages`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2001 | chapter in the Yocto Project Reference Manual. |
| 2002 | |
| 2003 | - *Hand-Checking Your Packages*: After you build your software, you |
| 2004 | need to be sure your packages are correct. Examine the |
| 2005 | ``${``\ :term:`WORKDIR`\ ``}/packages-split`` |
| 2006 | directory and make sure files are where you expect them to be. If you |
| 2007 | discover problems, you can set |
| 2008 | :term:`PACKAGES`, |
| 2009 | :term:`FILES`, |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 2010 | ``do_install(:append)``, and so forth as needed. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2011 | |
| 2012 | - *Splitting an Application into Multiple Packages*: If you need to |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 2013 | split an application into several packages, see the |
| 2014 | ":ref:`dev-manual/common-tasks:splitting an application into multiple packages`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2015 | section for an example. |
| 2016 | |
| 2017 | - *Installing a Post-Installation Script*: For an example showing how |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 2018 | to install a post-installation script, see the |
| 2019 | ":ref:`dev-manual/common-tasks:post-installation scripts`" section. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2020 | |
| 2021 | - *Marking Package Architecture*: Depending on what your recipe is |
| 2022 | building and how it is configured, it might be important to mark the |
| 2023 | packages produced as being specific to a particular machine, or to |
| 2024 | mark them as not being specific to a particular machine or |
| 2025 | architecture at all. |
| 2026 | |
| 2027 | By default, packages apply to any machine with the same architecture |
| 2028 | as the target machine. When a recipe produces packages that are |
| 2029 | machine-specific (e.g. the |
| 2030 | :term:`MACHINE` value is passed |
| 2031 | into the configure script or a patch is applied only for a particular |
| 2032 | machine), you should mark them as such by adding the following to the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2033 | recipe:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2034 | |
| 2035 | PACKAGE_ARCH = "${MACHINE_ARCH}" |
| 2036 | |
| 2037 | On the other hand, if the recipe produces packages that do not |
| 2038 | contain anything specific to the target machine or architecture at |
| 2039 | all (e.g. recipes that simply package script files or configuration |
| 2040 | files), you should use the |
| 2041 | :ref:`allarch <ref-classes-allarch>` class to |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2042 | do this for you by adding this to your recipe:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2043 | |
| 2044 | inherit allarch |
| 2045 | |
| 2046 | Ensuring that the package architecture is correct is not critical |
| 2047 | while you are doing the first few builds of your recipe. However, it |
| 2048 | is important in order to ensure that your recipe rebuilds (or does |
| 2049 | not rebuild) appropriately in response to changes in configuration, |
| 2050 | and to ensure that you get the appropriate packages installed on the |
| 2051 | target machine, particularly if you run separate builds for more than |
| 2052 | one target machine. |
| 2053 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2054 | Sharing Files Between Recipes |
| 2055 | ----------------------------- |
| 2056 | |
| 2057 | Recipes often need to use files provided by other recipes on the build |
| 2058 | host. For example, an application linking to a common library needs |
| 2059 | access to the library itself and its associated headers. The way this |
| 2060 | access is accomplished is by populating a sysroot with files. Each |
| 2061 | recipe has two sysroots in its work directory, one for target files |
| 2062 | (``recipe-sysroot``) and one for files that are native to the build host |
| 2063 | (``recipe-sysroot-native``). |
| 2064 | |
| 2065 | .. note:: |
| 2066 | |
| 2067 | You could find the term "staging" used within the Yocto project |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2068 | regarding files populating sysroots (e.g. the :term:`STAGING_DIR` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2069 | variable). |
| 2070 | |
| 2071 | Recipes should never populate the sysroot directly (i.e. write files |
| 2072 | into sysroot). Instead, files should be installed into standard |
| 2073 | locations during the |
| 2074 | :ref:`ref-tasks-install` task within |
| 2075 | the ``${``\ :term:`D`\ ``}`` directory. The |
| 2076 | reason for this limitation is that almost all files that populate the |
| 2077 | sysroot are cataloged in manifests in order to ensure the files can be |
| 2078 | removed later when a recipe is either modified or removed. Thus, the |
| 2079 | sysroot is able to remain free from stale files. |
| 2080 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 2081 | A subset of the files installed by the :ref:`ref-tasks-install` task are |
| 2082 | used by the :ref:`ref-tasks-populate_sysroot` task as defined by the the |
| 2083 | :term:`SYSROOT_DIRS` variable to automatically populate the sysroot. It |
| 2084 | is possible to modify the list of directories that populate the sysroot. |
| 2085 | The following example shows how you could add the ``/opt`` directory to |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2086 | the list of directories within a recipe:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2087 | |
| 2088 | SYSROOT_DIRS += "/opt" |
| 2089 | |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 2090 | .. note:: |
| 2091 | |
| 2092 | The `/sysroot-only` is to be used by recipes that generate artifacts |
| 2093 | that are not included in the target filesystem, allowing them to share |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 2094 | these artifacts without needing to use the :term:`DEPLOY_DIR`. |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 2095 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 2096 | For a more complete description of the :ref:`ref-tasks-populate_sysroot` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2097 | task and its associated functions, see the |
| 2098 | :ref:`staging <ref-classes-staging>` class. |
| 2099 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2100 | Using Virtual Providers |
| 2101 | ----------------------- |
| 2102 | |
| 2103 | Prior to a build, if you know that several different recipes provide the |
| 2104 | same functionality, you can use a virtual provider (i.e. ``virtual/*``) |
| 2105 | as a placeholder for the actual provider. The actual provider is |
| 2106 | determined at build-time. |
| 2107 | |
| 2108 | A common scenario where a virtual provider is used would be for the |
| 2109 | kernel recipe. Suppose you have three kernel recipes whose |
| 2110 | :term:`PN` values map to ``kernel-big``, |
| 2111 | ``kernel-mid``, and ``kernel-small``. Furthermore, each of these recipes |
| 2112 | in some way uses a :term:`PROVIDES` |
| 2113 | statement that essentially identifies itself as being able to provide |
| 2114 | ``virtual/kernel``. Here is one way through the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2115 | :ref:`kernel <ref-classes-kernel>` class:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2116 | |
| 2117 | PROVIDES += "${@ "virtual/kernel" if (d.getVar("KERNEL_PACKAGE_NAME") == "kernel") else "" }" |
| 2118 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 2119 | Any recipe that inherits the :ref:`kernel <ref-classes-kernel>` class is |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 2120 | going to utilize a :term:`PROVIDES` statement that identifies that recipe as |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2121 | being able to provide the ``virtual/kernel`` item. |
| 2122 | |
| 2123 | Now comes the time to actually build an image and you need a kernel |
| 2124 | 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] | 2125 | kernel recipe you want by using the :term:`PREFERRED_PROVIDER` variable. As |
| 2126 | an example, consider the :yocto_git:`x86-base.inc |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 2127 | </poky/tree/meta/conf/machine/include/x86/x86-base.inc>` include file, which is a |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 2128 | machine (i.e. :term:`MACHINE`) configuration file. This include file is the |
| 2129 | reason all x86-based machines use the ``linux-yocto`` kernel. Here are the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2130 | relevant lines from the include file:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2131 | |
| 2132 | PREFERRED_PROVIDER_virtual/kernel ??= "linux-yocto" |
| 2133 | PREFERRED_VERSION_linux-yocto ??= "4.15%" |
| 2134 | |
| 2135 | When you use a virtual provider, you do not have to "hard code" a recipe |
| 2136 | name as a build dependency. You can use the |
| 2137 | :term:`DEPENDS` variable to state the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2138 | build is dependent on ``virtual/kernel`` for example:: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2139 | |
| 2140 | DEPENDS = "virtual/kernel" |
| 2141 | |
| 2142 | During the build, the OpenEmbedded build system picks |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2143 | the correct recipe needed for the ``virtual/kernel`` dependency based on |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 2144 | the :term:`PREFERRED_PROVIDER` variable. If you want to use the small kernel |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2145 | mentioned at the beginning of this section, configure your build as |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2146 | follows:: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2147 | |
| 2148 | PREFERRED_PROVIDER_virtual/kernel ??= "kernel-small" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2149 | |
| 2150 | .. note:: |
| 2151 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 2152 | Any recipe that :term:`PROVIDES` a ``virtual/*`` item that is ultimately not |
| 2153 | selected through :term:`PREFERRED_PROVIDER` does not get built. Preventing these |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2154 | recipes from building is usually the desired behavior since this mechanism's |
| 2155 | purpose is to select between mutually exclusive alternative providers. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2156 | |
| 2157 | The following lists specific examples of virtual providers: |
| 2158 | |
| 2159 | - ``virtual/kernel``: Provides the name of the kernel recipe to use |
| 2160 | when building a kernel image. |
| 2161 | |
| 2162 | - ``virtual/bootloader``: Provides the name of the bootloader to use |
| 2163 | when building an image. |
| 2164 | |
| 2165 | - ``virtual/libgbm``: Provides ``gbm.pc``. |
| 2166 | |
| 2167 | - ``virtual/egl``: Provides ``egl.pc`` and possibly ``wayland-egl.pc``. |
| 2168 | |
| 2169 | - ``virtual/libgl``: Provides ``gl.pc`` (i.e. libGL). |
| 2170 | |
| 2171 | - ``virtual/libgles1``: Provides ``glesv1_cm.pc`` (i.e. libGLESv1_CM). |
| 2172 | |
| 2173 | - ``virtual/libgles2``: Provides ``glesv2.pc`` (i.e. libGLESv2). |
| 2174 | |
| 2175 | .. note:: |
| 2176 | |
| 2177 | Virtual providers only apply to build time dependencies specified with |
| 2178 | :term:`PROVIDES` and :term:`DEPENDS`. They do not apply to runtime |
| 2179 | dependencies specified with :term:`RPROVIDES` and :term:`RDEPENDS`. |
| 2180 | |
| 2181 | Properly Versioning Pre-Release Recipes |
| 2182 | --------------------------------------- |
| 2183 | |
| 2184 | Sometimes the name of a recipe can lead to versioning problems when the |
| 2185 | recipe is upgraded to a final release. For example, consider the |
| 2186 | ``irssi_0.8.16-rc1.bb`` recipe file in the list of example recipes in |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 2187 | the ":ref:`dev-manual/common-tasks:storing and naming the recipe`" section. |
| 2188 | This recipe is at a release candidate stage (i.e. "rc1"). When the recipe is |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2189 | released, the recipe filename becomes ``irssi_0.8.16.bb``. The version |
| 2190 | change from ``0.8.16-rc1`` to ``0.8.16`` is seen as a decrease by the |
| 2191 | build system and package managers, so the resulting packages will not |
| 2192 | correctly trigger an upgrade. |
| 2193 | |
| 2194 | In order to ensure the versions compare properly, the recommended |
| 2195 | convention is to set :term:`PV` within the |
| 2196 | recipe to "previous_version+current_version". You can use an additional |
| 2197 | variable so that you can use the current version elsewhere. Here is an |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2198 | example:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2199 | |
| 2200 | REALPV = "0.8.16-rc1" |
| 2201 | PV = "0.8.15+${REALPV}" |
| 2202 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2203 | Post-Installation Scripts |
| 2204 | ------------------------- |
| 2205 | |
| 2206 | Post-installation scripts run immediately after installing a package on |
| 2207 | the target or during image creation when a package is included in an |
| 2208 | image. To add a post-installation script to a package, add a |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 2209 | ``pkg_postinst:``\ `PACKAGENAME`\ ``()`` function to the recipe file |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2210 | (``.bb``) and replace `PACKAGENAME` with the name of the package you want |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2211 | to attach to the ``postinst`` script. To apply the post-installation |
| 2212 | script to the main package for the recipe, which is usually what is |
| 2213 | required, specify |
| 2214 | ``${``\ :term:`PN`\ ``}`` in place of |
| 2215 | PACKAGENAME. |
| 2216 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2217 | A post-installation function has the following structure:: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2218 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 2219 | pkg_postinst:PACKAGENAME() { |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2220 | # Commands to carry out |
| 2221 | } |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2222 | |
| 2223 | The script defined in the post-installation function is called when the |
| 2224 | root filesystem is created. If the script succeeds, the package is |
| 2225 | marked as installed. |
| 2226 | |
| 2227 | .. note:: |
| 2228 | |
| 2229 | Any RPM post-installation script that runs on the target should |
| 2230 | return a 0 exit code. RPM does not allow non-zero exit codes for |
| 2231 | these scripts, and the RPM package manager will cause the package to |
| 2232 | fail installation on the target. |
| 2233 | |
| 2234 | Sometimes it is necessary for the execution of a post-installation |
| 2235 | script to be delayed until the first boot. For example, the script might |
| 2236 | need to be executed on the device itself. To delay script execution |
| 2237 | until boot time, you must explicitly mark post installs to defer to the |
| 2238 | target. You can use ``pkg_postinst_ontarget()`` or call |
| 2239 | ``postinst_intercept delay_to_first_boot`` from ``pkg_postinst()``. Any |
| 2240 | failure of a ``pkg_postinst()`` script (including exit 1) triggers an |
| 2241 | error during the |
| 2242 | :ref:`ref-tasks-rootfs` task. |
| 2243 | |
| 2244 | If you have recipes that use ``pkg_postinst`` function and they require |
| 2245 | the use of non-standard native tools that have dependencies during |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 2246 | root filesystem construction, you need to use the |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2247 | :term:`PACKAGE_WRITE_DEPS` |
| 2248 | variable in your recipe to list these tools. If you do not use this |
| 2249 | variable, the tools might be missing and execution of the |
| 2250 | post-installation script is deferred until first boot. Deferring the |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 2251 | script to the first boot is undesirable and impossible for read-only |
| 2252 | root filesystems. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2253 | |
| 2254 | .. note:: |
| 2255 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 2256 | There is equivalent support for pre-install, pre-uninstall, and post-uninstall |
| 2257 | scripts by way of ``pkg_preinst``, ``pkg_prerm``, and ``pkg_postrm``, |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2258 | respectively. These scrips work in exactly the same way as does |
| 2259 | ``pkg_postinst`` with the exception that they run at different times. Also, |
| 2260 | because of when they run, they are not applicable to being run at image |
| 2261 | creation time like ``pkg_postinst``. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2262 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2263 | Testing |
| 2264 | ------- |
| 2265 | |
| 2266 | The final step for completing your recipe is to be sure that the |
| 2267 | software you built runs correctly. To accomplish runtime testing, add |
| 2268 | the build's output packages to your image and test them on the target. |
| 2269 | |
| 2270 | For information on how to customize your image by adding specific |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 2271 | packages, see ":ref:`dev-manual/common-tasks:customizing images`" section. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2272 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2273 | Examples |
| 2274 | -------- |
| 2275 | |
| 2276 | To help summarize how to write a recipe, this section provides some |
| 2277 | examples given various scenarios: |
| 2278 | |
| 2279 | - Recipes that use local files |
| 2280 | |
| 2281 | - Using an Autotooled package |
| 2282 | |
| 2283 | - Using a Makefile-based package |
| 2284 | |
| 2285 | - Splitting an application into multiple packages |
| 2286 | |
| 2287 | - Adding binaries to an image |
| 2288 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2289 | Single .c File Package (Hello World!) |
| 2290 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2291 | |
| 2292 | Building an application from a single file that is stored locally (e.g. |
| 2293 | under ``files``) requires a recipe that has the file listed in the |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 2294 | :term:`SRC_URI` variable. Additionally, you need to manually write the |
| 2295 | ``do_compile`` and ``do_install`` tasks. The :term:`S` variable defines the |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2296 | directory containing the source code, which is set to |
| 2297 | :term:`WORKDIR` in this case - the |
| 2298 | directory BitBake uses for the build. |
| 2299 | :: |
| 2300 | |
| 2301 | SUMMARY = "Simple helloworld application" |
| 2302 | SECTION = "examples" |
| 2303 | LICENSE = "MIT" |
| 2304 | LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" |
| 2305 | |
| 2306 | SRC_URI = "file://helloworld.c" |
| 2307 | |
| 2308 | S = "${WORKDIR}" |
| 2309 | |
| 2310 | do_compile() { |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 2311 | ${CC} ${LDFLAGS} helloworld.c -o helloworld |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2312 | } |
| 2313 | |
| 2314 | do_install() { |
| 2315 | install -d ${D}${bindir} |
| 2316 | install -m 0755 helloworld ${D}${bindir} |
| 2317 | } |
| 2318 | |
| 2319 | By default, the ``helloworld``, ``helloworld-dbg``, and |
| 2320 | ``helloworld-dev`` packages are built. For information on how to |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 2321 | customize the packaging process, see the |
| 2322 | ":ref:`dev-manual/common-tasks:splitting an application into multiple packages`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2323 | section. |
| 2324 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2325 | Autotooled Package |
| 2326 | ~~~~~~~~~~~~~~~~~~ |
| 2327 | |
| 2328 | Applications that use Autotools such as ``autoconf`` and ``automake`` |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 2329 | require a recipe that has a source archive listed in :term:`SRC_URI` and |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2330 | also inherit the |
| 2331 | :ref:`autotools <ref-classes-autotools>` class, |
| 2332 | which contains the definitions of all the steps needed to build an |
| 2333 | Autotool-based application. The result of the build is automatically |
| 2334 | packaged. And, if the application uses NLS for localization, packages |
| 2335 | with local information are generated (one package per language). |
| 2336 | Following is one example: (``hello_2.3.bb``) |
| 2337 | :: |
| 2338 | |
| 2339 | SUMMARY = "GNU Helloworld application" |
| 2340 | SECTION = "examples" |
| 2341 | LICENSE = "GPLv2+" |
| 2342 | LIC_FILES_CHKSUM = "file://COPYING;md5=751419260aa954499f7abaabaa882bbe" |
| 2343 | |
| 2344 | SRC_URI = "${GNU_MIRROR}/hello/hello-${PV}.tar.gz" |
| 2345 | |
| 2346 | inherit autotools gettext |
| 2347 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 2348 | The variable :term:`LIC_FILES_CHKSUM` is used to track source license |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2349 | changes as described in the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 2350 | ":ref:`dev-manual/common-tasks:tracking license changes`" section in |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2351 | the Yocto Project Overview and Concepts Manual. You can quickly create |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2352 | Autotool-based recipes in a manner similar to the previous example. |
| 2353 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2354 | Makefile-Based Package |
| 2355 | ~~~~~~~~~~~~~~~~~~~~~~ |
| 2356 | |
| 2357 | Applications that use GNU ``make`` also require a recipe that has the |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 2358 | source archive listed in :term:`SRC_URI`. You do not need to add a |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2359 | ``do_compile`` step since by default BitBake starts the ``make`` command |
| 2360 | to compile the application. If you need additional ``make`` options, you |
| 2361 | should store them in the |
| 2362 | :term:`EXTRA_OEMAKE` or |
| 2363 | :term:`PACKAGECONFIG_CONFARGS` |
| 2364 | variables. BitBake passes these options into the GNU ``make`` |
| 2365 | invocation. Note that a ``do_install`` task is still required. |
| 2366 | Otherwise, BitBake runs an empty ``do_install`` task by default. |
| 2367 | |
| 2368 | Some applications might require extra parameters to be passed to the |
| 2369 | compiler. For example, the application might need an additional header |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 2370 | path. You can accomplish this by adding to the :term:`CFLAGS` variable. The |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2371 | following example shows this:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2372 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 2373 | CFLAGS:prepend = "-I ${S}/include " |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2374 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2375 | In the following example, ``mtd-utils`` is a makefile-based package:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2376 | |
| 2377 | SUMMARY = "Tools for managing memory technology devices" |
| 2378 | SECTION = "base" |
| 2379 | DEPENDS = "zlib lzo e2fsprogs util-linux" |
| 2380 | HOMEPAGE = "http://www.linux-mtd.infradead.org/" |
| 2381 | LICENSE = "GPLv2+" |
| 2382 | LIC_FILES_CHKSUM = "file://COPYING;md5=0636e73ff0215e8d672dc4c32c317bb3 \ |
| 2383 | file://include/common.h;beginline=1;endline=17;md5=ba05b07912a44ea2bf81ce409380049c" |
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 | # Use the latest version at 26 Oct, 2013 |
| 2386 | SRCREV = "9f107132a6a073cce37434ca9cda6917dd8d866b" |
| 2387 | SRC_URI = "git://git.infradead.org/mtd-utils.git \ |
| 2388 | file://add-exclusion-to-mkfs-jffs2-git-2.patch \ |
| 2389 | " |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2390 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2391 | PV = "1.5.1+git${SRCPV}" |
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 | S = "${WORKDIR}/git" |
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 | 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] | 2396 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2397 | do_install () { |
| 2398 | oe_runmake install DESTDIR=${D} SBINDIR=${sbindir} MANDIR=${mandir} INCLUDEDIR=${includedir} |
| 2399 | } |
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 | PACKAGES =+ "mtd-utils-jffs2 mtd-utils-ubifs mtd-utils-misc" |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2402 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 2403 | FILES:mtd-utils-jffs2 = "${sbindir}/mkfs.jffs2 ${sbindir}/jffs2dump ${sbindir}/jffs2reader ${sbindir}/sumtool" |
| 2404 | FILES:mtd-utils-ubifs = "${sbindir}/mkfs.ubifs ${sbindir}/ubi*" |
| 2405 | 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] | 2406 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2407 | PARALLEL_MAKE = "" |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2408 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2409 | BBCLASSEXTEND = "native" |
| 2410 | |
| 2411 | Splitting an Application into Multiple Packages |
| 2412 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2413 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 2414 | You can use the variables :term:`PACKAGES` and :term:`FILES` to split an |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2415 | application into multiple packages. |
| 2416 | |
| 2417 | Following is an example that uses the ``libxpm`` recipe. By default, |
| 2418 | this recipe generates a single package that contains the library along |
| 2419 | with a few binaries. You can modify the recipe to split the binaries |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2420 | into separate packages:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2421 | |
| 2422 | require xorg-lib-common.inc |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2423 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2424 | SUMMARY = "Xpm: X Pixmap extension library" |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 2425 | LICENSE = "MIT" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2426 | LIC_FILES_CHKSUM = "file://COPYING;md5=51f4270b012ecd4ab1a164f5f4ed6cf7" |
| 2427 | DEPENDS += "libxext libsm libxt" |
| 2428 | PE = "1" |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2429 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2430 | XORG_PN = "libXpm" |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2431 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2432 | PACKAGES =+ "sxpm cxpm" |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 2433 | FILES:cxpm = "${bindir}/cxpm" |
| 2434 | FILES:sxpm = "${bindir}/sxpm" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2435 | |
| 2436 | In the previous example, we want to ship the ``sxpm`` and ``cxpm`` |
| 2437 | binaries in separate packages. Since ``bindir`` would be packaged into |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 2438 | the main :term:`PN` package by default, we prepend the :term:`PACKAGES` variable |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2439 | so additional package names are added to the start of list. This results |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 2440 | in the extra ``FILES:*`` variables then containing information that |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2441 | define which files and directories go into which packages. Files |
| 2442 | included by earlier packages are skipped by latter packages. Thus, the |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 2443 | main :term:`PN` package does not include the above listed files. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2444 | |
| 2445 | Packaging Externally Produced Binaries |
| 2446 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2447 | |
| 2448 | Sometimes, you need to add pre-compiled binaries to an image. For |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 2449 | example, suppose that there are binaries for proprietary code, |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2450 | created by a particular division of a company. Your part of the company |
| 2451 | needs to use those binaries as part of an image that you are building |
| 2452 | using the OpenEmbedded build system. Since you only have the binaries |
| 2453 | and not the source code, you cannot use a typical recipe that expects to |
| 2454 | fetch the source specified in |
| 2455 | :term:`SRC_URI` and then compile it. |
| 2456 | |
| 2457 | One method is to package the binaries and then install them as part of |
| 2458 | the image. Generally, it is not a good idea to package binaries since, |
| 2459 | among other things, it can hinder the ability to reproduce builds and |
| 2460 | could lead to compatibility problems with ABI in the future. However, |
| 2461 | sometimes you have no choice. |
| 2462 | |
| 2463 | The easiest solution is to create a recipe that uses the |
| 2464 | :ref:`bin_package <ref-classes-bin-package>` class |
| 2465 | and to be sure that you are using default locations for build artifacts. |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 2466 | In most cases, the :ref:`bin_package <ref-classes-bin-package>` class handles "skipping" the |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2467 | configure and compile steps as well as sets things up to grab packages |
| 2468 | from the appropriate area. In particular, this class sets ``noexec`` on |
| 2469 | both the :ref:`ref-tasks-configure` |
| 2470 | and :ref:`ref-tasks-compile` tasks, |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 2471 | sets ``FILES:${PN}`` to "/" so that it picks up all files, and sets up a |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2472 | :ref:`ref-tasks-install` task, which |
| 2473 | effectively copies all files from ``${S}`` to ``${D}``. The |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 2474 | :ref:`bin_package <ref-classes-bin-package>` class works well when the files extracted into ``${S}`` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2475 | are already laid out in the way they should be laid out on the target. |
| 2476 | For more information on these variables, see the |
| 2477 | :term:`FILES`, |
| 2478 | :term:`PN`, |
| 2479 | :term:`S`, and |
| 2480 | :term:`D` variables in the Yocto Project |
| 2481 | Reference Manual's variable glossary. |
| 2482 | |
| 2483 | .. note:: |
| 2484 | |
| 2485 | - Using :term:`DEPENDS` is a good |
| 2486 | idea even for components distributed in binary form, and is often |
| 2487 | necessary for shared libraries. For a shared library, listing the |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 2488 | library dependencies in :term:`DEPENDS` makes sure that the libraries |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2489 | are available in the staging sysroot when other recipes link |
| 2490 | against the library, which might be necessary for successful |
| 2491 | linking. |
| 2492 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 2493 | - Using :term:`DEPENDS` also allows runtime dependencies between |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2494 | packages to be added automatically. See the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 2495 | ":ref:`overview-manual/concepts:automatically added runtime dependencies`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2496 | section in the Yocto Project Overview and Concepts Manual for more |
| 2497 | information. |
| 2498 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 2499 | If you cannot use the :ref:`bin_package <ref-classes-bin-package>` class, you need to be sure you are |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2500 | doing the following: |
| 2501 | |
| 2502 | - Create a recipe where the |
| 2503 | :ref:`ref-tasks-configure` and |
| 2504 | :ref:`ref-tasks-compile` tasks do |
| 2505 | nothing: It is usually sufficient to just not define these tasks in |
| 2506 | the recipe, because the default implementations do nothing unless a |
| 2507 | Makefile is found in |
| 2508 | ``${``\ :term:`S`\ ``}``. |
| 2509 | |
| 2510 | If ``${S}`` might contain a Makefile, or if you inherit some class |
| 2511 | that replaces ``do_configure`` and ``do_compile`` with custom |
| 2512 | versions, then you can use the |
| 2513 | ``[``\ :ref:`noexec <bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ``]`` |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2514 | flag to turn the tasks into no-ops, as follows:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2515 | |
| 2516 | do_configure[noexec] = "1" |
| 2517 | do_compile[noexec] = "1" |
| 2518 | |
| 2519 | Unlike |
| 2520 | :ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:deleting a task`, |
| 2521 | using the flag preserves the dependency chain from the |
| 2522 | :ref:`ref-tasks-fetch`, |
| 2523 | :ref:`ref-tasks-unpack`, and |
| 2524 | :ref:`ref-tasks-patch` tasks to the |
| 2525 | :ref:`ref-tasks-install` task. |
| 2526 | |
| 2527 | - Make sure your ``do_install`` task installs the binaries |
| 2528 | appropriately. |
| 2529 | |
| 2530 | - Ensure that you set up :term:`FILES` |
| 2531 | (usually |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 2532 | ``FILES:${``\ :term:`PN`\ ``}``) to |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2533 | point to the files you have installed, which of course depends on |
| 2534 | where you have installed them and whether those files are in |
| 2535 | different locations than the defaults. |
| 2536 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 2537 | .. note:: |
| 2538 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 2539 | If image prelinking is enabled (e.g. :ref:`image-prelink <ref-classes-image-prelink>` is in :term:`USER_CLASSES` |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 2540 | which it is by default), prelink will change the binaries in the generated images |
| 2541 | and this often catches people out. Remove that class to ensure binaries are |
| 2542 | preserved exactly if that is necessary. |
| 2543 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2544 | Following Recipe Style Guidelines |
| 2545 | --------------------------------- |
| 2546 | |
| 2547 | When writing recipes, it is good to conform to existing style |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 2548 | guidelines. The :oe_wiki:`OpenEmbedded Styleguide </Styleguide>` wiki page |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2549 | provides rough guidelines for preferred recipe style. |
| 2550 | |
| 2551 | It is common for existing recipes to deviate a bit from this style. |
| 2552 | However, aiming for at least a consistent style is a good idea. Some |
| 2553 | practices, such as omitting spaces around ``=`` operators in assignments |
| 2554 | or ordering recipe components in an erratic way, are widely seen as poor |
| 2555 | style. |
| 2556 | |
| 2557 | Recipe Syntax |
| 2558 | ------------- |
| 2559 | |
| 2560 | Understanding recipe file syntax is important for writing recipes. The |
| 2561 | following list overviews the basic items that make up a BitBake recipe |
| 2562 | file. For more complete BitBake syntax descriptions, see the |
| 2563 | ":doc:`bitbake-user-manual/bitbake-user-manual-metadata`" |
| 2564 | chapter of the BitBake User Manual. |
| 2565 | |
| 2566 | - *Variable Assignments and Manipulations:* Variable assignments allow |
| 2567 | a value to be assigned to a variable. The assignment can be static |
| 2568 | text or might include the contents of other variables. In addition to |
| 2569 | the assignment, appending and prepending operations are also |
| 2570 | supported. |
| 2571 | |
| 2572 | The following example shows some of the ways you can use variables in |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2573 | recipes:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2574 | |
| 2575 | S = "${WORKDIR}/postfix-${PV}" |
| 2576 | CFLAGS += "-DNO_ASM" |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 2577 | SRC_URI:append = " file://fixup.patch" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2578 | |
| 2579 | - *Functions:* Functions provide a series of actions to be performed. |
| 2580 | You usually use functions to override the default implementation of a |
| 2581 | task function or to complement a default function (i.e. append or |
| 2582 | prepend to an existing function). Standard functions use ``sh`` shell |
| 2583 | syntax, although access to OpenEmbedded variables and internal |
| 2584 | methods are also available. |
| 2585 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 2586 | Here is an example function from the ``sed`` recipe:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2587 | |
| 2588 | do_install () { |
| 2589 | autotools_do_install |
| 2590 | install -d ${D}${base_bindir} |
| 2591 | mv ${D}${bindir}/sed ${D}${base_bindir}/sed |
| 2592 | rmdir ${D}${bindir}/ |
| 2593 | } |
| 2594 | |
| 2595 | It is |
| 2596 | also possible to implement new functions that are called between |
| 2597 | existing tasks as long as the new functions are not replacing or |
| 2598 | complementing the default functions. You can implement functions in |
| 2599 | Python instead of shell. Both of these options are not seen in the |
| 2600 | majority of recipes. |
| 2601 | |
| 2602 | - *Keywords:* BitBake recipes use only a few keywords. You use keywords |
| 2603 | to include common functions (``inherit``), load parts of a recipe |
| 2604 | from other files (``include`` and ``require``) and export variables |
| 2605 | to the environment (``export``). |
| 2606 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2607 | The following example shows the use of some of these keywords:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2608 | |
| 2609 | export POSTCONF = "${STAGING_BINDIR}/postconf" |
| 2610 | inherit autoconf |
| 2611 | require otherfile.inc |
| 2612 | |
| 2613 | - *Comments (#):* Any lines that begin with the hash character (``#``) |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2614 | are treated as comment lines and are ignored:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2615 | |
| 2616 | # This is a comment |
| 2617 | |
| 2618 | This next list summarizes the most important and most commonly used |
| 2619 | parts of the recipe syntax. For more information on these parts of the |
| 2620 | syntax, you can reference the |
| 2621 | :doc:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata` chapter |
| 2622 | in the BitBake User Manual. |
| 2623 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2624 | - *Line Continuation (\\):* Use the backward slash (``\``) character to |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2625 | split a statement over multiple lines. Place the slash character at |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2626 | the end of the line that is to be continued on the next line:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2627 | |
| 2628 | VAR = "A really long \ |
| 2629 | line" |
| 2630 | |
| 2631 | .. note:: |
| 2632 | |
| 2633 | You cannot have any characters including spaces or tabs after the |
| 2634 | slash character. |
| 2635 | |
| 2636 | - *Using Variables (${VARNAME}):* Use the ``${VARNAME}`` syntax to |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2637 | access the contents of a variable:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 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 |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2657 | all variable assignments (e.g. ``"value"``). Following is an example:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2658 | |
| 2659 | VAR1 = "${OTHERVAR}" |
| 2660 | VAR2 = "The version is ${PV}" |
| 2661 | |
| 2662 | - *Conditional Assignment (?=):* Conditional assignment is used to |
| 2663 | assign a value to a variable, but only when the variable is currently |
| 2664 | unset. Use the question mark followed by the equal sign (``?=``) to |
| 2665 | make a "soft" assignment used for conditional assignment. Typically, |
| 2666 | "soft" assignments are used in the ``local.conf`` file for variables |
| 2667 | that are allowed to come through from the external environment. |
| 2668 | |
| 2669 | Here is an example where ``VAR1`` is set to "New value" if it is |
| 2670 | currently empty. However, if ``VAR1`` has already been set, it |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2671 | remains unchanged:: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2672 | |
| 2673 | VAR1 ?= "New value" |
| 2674 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2675 | In this next example, ``VAR1`` is left with the value "Original value":: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2676 | |
| 2677 | VAR1 = "Original value" |
| 2678 | VAR1 ?= "New value" |
| 2679 | |
| 2680 | - *Appending (+=):* Use the plus character followed by the equals sign |
| 2681 | (``+=``) to append values to existing variables. |
| 2682 | |
| 2683 | .. note:: |
| 2684 | |
| 2685 | This operator adds a space between the existing content of the |
| 2686 | variable and the new content. |
| 2687 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2688 | Here is an example:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2689 | |
| 2690 | SRC_URI += "file://fix-makefile.patch" |
| 2691 | |
| 2692 | - *Prepending (=+):* Use the equals sign followed by the plus character |
| 2693 | (``=+``) to prepend values to existing variables. |
| 2694 | |
| 2695 | .. note:: |
| 2696 | |
| 2697 | This operator adds a space between the new content and the |
| 2698 | existing content of the variable. |
| 2699 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2700 | Here is an example:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2701 | |
| 2702 | VAR =+ "Starts" |
| 2703 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 2704 | - *Appending (:append):* Use the ``:append`` operator to append values |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2705 | to existing variables. This operator does not add any additional |
| 2706 | space. Also, the operator is applied after all the ``+=``, and ``=+`` |
| 2707 | operators have been applied and after all ``=`` assignments have |
| 2708 | occurred. |
| 2709 | |
| 2710 | The following example shows the space being explicitly added to the |
| 2711 | start to ensure the appended value is not merged with the existing |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2712 | value:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2713 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 2714 | SRC_URI:append = " file://fix-makefile.patch" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2715 | |
| 2716 | You can also use |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 2717 | the ``:append`` operator with overrides, which results in the actions |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2718 | only being performed for the specified target or machine:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2719 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 2720 | SRC_URI:append:sh4 = " file://fix-makefile.patch" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2721 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 2722 | - *Prepending (:prepend):* Use the ``:prepend`` operator to prepend |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2723 | values to existing variables. This operator does not add any |
| 2724 | additional space. Also, the operator is applied after all the ``+=``, |
| 2725 | and ``=+`` operators have been applied and after all ``=`` |
| 2726 | assignments have occurred. |
| 2727 | |
| 2728 | The following example shows the space being explicitly added to the |
| 2729 | end to ensure the prepended value is not merged with the existing |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2730 | value:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2731 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 2732 | CFLAGS:prepend = "-I${S}/myincludes " |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2733 | |
| 2734 | You can also use the |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 2735 | ``:prepend`` operator with overrides, which results in the actions |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2736 | only being performed for the specified target or machine:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2737 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 2738 | CFLAGS:prepend:sh4 = "-I${S}/myincludes " |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2739 | |
| 2740 | - *Overrides:* You can use overrides to set a value conditionally, |
| 2741 | typically based on how the recipe is being built. For example, to set |
| 2742 | the :term:`KBRANCH` variable's |
| 2743 | value to "standard/base" for any target |
| 2744 | :term:`MACHINE`, except for |
| 2745 | qemuarm where it should be set to "standard/arm-versatile-926ejs", |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2746 | you would do the following:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2747 | |
| 2748 | KBRANCH = "standard/base" |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 2749 | KBRANCH:qemuarm = "standard/arm-versatile-926ejs" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2750 | |
| 2751 | Overrides are also used to separate |
| 2752 | alternate values of a variable in other situations. For example, when |
| 2753 | setting variables such as |
| 2754 | :term:`FILES` and |
| 2755 | :term:`RDEPENDS` that are |
| 2756 | specific to individual packages produced by a recipe, you should |
| 2757 | always use an override that specifies the name of the package. |
| 2758 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2759 | - *Indentation:* Use spaces for indentation rather than tabs. For |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2760 | shell functions, both currently work. However, it is a policy |
| 2761 | decision of the Yocto Project to use tabs in shell functions. Realize |
| 2762 | that some layers have a policy to use spaces for all indentation. |
| 2763 | |
| 2764 | - *Using Python for Complex Operations:* For more advanced processing, |
| 2765 | it is possible to use Python code during variable assignments (e.g. |
| 2766 | search and replacement on a variable). |
| 2767 | |
| 2768 | You indicate Python code using the ``${@python_code}`` syntax for the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2769 | variable assignment:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2770 | |
| 2771 | SRC_URI = "ftp://ftp.info-zip.org/pub/infozip/src/zip${@d.getVar('PV',1).replace('.', '')}.tgz |
| 2772 | |
| 2773 | - *Shell Function Syntax:* Write shell functions as if you were writing |
| 2774 | a shell script when you describe a list of actions to take. You |
| 2775 | should ensure that your script works with a generic ``sh`` and that |
| 2776 | it does not require any ``bash`` or other shell-specific |
| 2777 | functionality. The same considerations apply to various system |
| 2778 | utilities (e.g. ``sed``, ``grep``, ``awk``, and so forth) that you |
| 2779 | might wish to use. If in doubt, you should check with multiple |
| 2780 | implementations - including those from BusyBox. |
| 2781 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2782 | Adding a New Machine |
| 2783 | ==================== |
| 2784 | |
| 2785 | Adding a new machine to the Yocto Project is a straightforward process. |
| 2786 | This section describes how to add machines that are similar to those |
| 2787 | that the Yocto Project already supports. |
| 2788 | |
| 2789 | .. note:: |
| 2790 | |
| 2791 | Although well within the capabilities of the Yocto Project, adding a |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2792 | totally new architecture might require changes to ``gcc``/``glibc`` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2793 | and to the site information, which is beyond the scope of this |
| 2794 | manual. |
| 2795 | |
| 2796 | For a complete example that shows how to add a new machine, see the |
| 2797 | ":ref:`bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script`" |
| 2798 | section in the Yocto Project Board Support Package (BSP) Developer's |
| 2799 | Guide. |
| 2800 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2801 | Adding the Machine Configuration File |
| 2802 | ------------------------------------- |
| 2803 | |
| 2804 | To add a new machine, you need to add a new machine configuration file |
| 2805 | to the layer's ``conf/machine`` directory. This configuration file |
| 2806 | provides details about the device you are adding. |
| 2807 | |
| 2808 | The OpenEmbedded build system uses the root name of the machine |
| 2809 | configuration file to reference the new machine. For example, given a |
| 2810 | machine configuration file named ``crownbay.conf``, the build system |
| 2811 | recognizes the machine as "crownbay". |
| 2812 | |
| 2813 | The most important variables you must set in your machine configuration |
| 2814 | file or include from a lower-level configuration file are as follows: |
| 2815 | |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 2816 | - :term:`TARGET_ARCH` (e.g. "arm") |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2817 | |
| 2818 | - ``PREFERRED_PROVIDER_virtual/kernel`` |
| 2819 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 2820 | - :term:`MACHINE_FEATURES` (e.g. "apm screen wifi") |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2821 | |
| 2822 | You might also need these variables: |
| 2823 | |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 2824 | - :term:`SERIAL_CONSOLES` (e.g. "115200;ttyS0 115200;ttyS1") |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2825 | |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 2826 | - :term:`KERNEL_IMAGETYPE` (e.g. "zImage") |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2827 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 2828 | - :term:`IMAGE_FSTYPES` (e.g. "tar.gz jffs2") |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2829 | |
| 2830 | You can find full details on these variables in the reference section. |
| 2831 | You can leverage existing machine ``.conf`` files from |
| 2832 | ``meta-yocto-bsp/conf/machine/``. |
| 2833 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2834 | Adding a Kernel for the Machine |
| 2835 | ------------------------------- |
| 2836 | |
| 2837 | The OpenEmbedded build system needs to be able to build a kernel for the |
| 2838 | machine. You need to either create a new kernel recipe for this machine, |
| 2839 | or extend an existing kernel recipe. You can find several kernel recipe |
| 2840 | examples in the Source Directory at ``meta/recipes-kernel/linux`` that |
| 2841 | you can use as references. |
| 2842 | |
| 2843 | If you are creating a new kernel recipe, normal recipe-writing rules |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 2844 | apply for setting up a :term:`SRC_URI`. Thus, you need to specify any |
| 2845 | necessary patches and set :term:`S` to point at the source code. You need to |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2846 | create a ``do_configure`` task that configures the unpacked kernel with |
| 2847 | a ``defconfig`` file. You can do this by using a ``make defconfig`` |
| 2848 | command or, more commonly, by copying in a suitable ``defconfig`` file |
| 2849 | and then running ``make oldconfig``. By making use of ``inherit kernel`` |
| 2850 | and potentially some of the ``linux-*.inc`` files, most other |
| 2851 | functionality is centralized and the defaults of the class normally work |
| 2852 | well. |
| 2853 | |
| 2854 | If you are extending an existing kernel recipe, it is usually a matter |
| 2855 | of adding a suitable ``defconfig`` file. The file needs to be added into |
| 2856 | a location similar to ``defconfig`` files used for other machines in a |
| 2857 | given kernel recipe. A possible way to do this is by listing the file in |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 2858 | the :term:`SRC_URI` and adding the machine to the expression in |
| 2859 | :term:`COMPATIBLE_MACHINE`:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2860 | |
| 2861 | COMPATIBLE_MACHINE = '(qemux86|qemumips)' |
| 2862 | |
| 2863 | For more information on ``defconfig`` files, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 2864 | ":ref:`kernel-dev/common:changing the configuration`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2865 | section in the Yocto Project Linux Kernel Development Manual. |
| 2866 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2867 | Adding a Formfactor Configuration File |
| 2868 | -------------------------------------- |
| 2869 | |
| 2870 | A formfactor configuration file provides information about the target |
| 2871 | hardware for which the image is being built and information that the |
| 2872 | build system cannot obtain from other sources such as the kernel. Some |
| 2873 | examples of information contained in a formfactor configuration file |
| 2874 | include framebuffer orientation, whether or not the system has a |
| 2875 | keyboard, the positioning of the keyboard in relation to the screen, and |
| 2876 | the screen resolution. |
| 2877 | |
| 2878 | The build system uses reasonable defaults in most cases. However, if |
| 2879 | customization is necessary, you need to create a ``machconfig`` file in |
| 2880 | the ``meta/recipes-bsp/formfactor/files`` directory. This directory |
| 2881 | contains directories for specific machines such as ``qemuarm`` and |
| 2882 | ``qemux86``. For information about the settings available and the |
| 2883 | defaults, see the ``meta/recipes-bsp/formfactor/files/config`` file |
| 2884 | found in the same area. |
| 2885 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2886 | Following is an example for "qemuarm" machine:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2887 | |
| 2888 | HAVE_TOUCHSCREEN=1 |
| 2889 | HAVE_KEYBOARD=1 |
| 2890 | DISPLAY_CAN_ROTATE=0 |
| 2891 | DISPLAY_ORIENTATION=0 |
| 2892 | #DISPLAY_WIDTH_PIXELS=640 |
| 2893 | #DISPLAY_HEIGHT_PIXELS=480 |
| 2894 | #DISPLAY_BPP=16 |
| 2895 | DISPLAY_DPI=150 |
| 2896 | DISPLAY_SUBPIXEL_ORDER=vrgb |
| 2897 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2898 | Upgrading Recipes |
| 2899 | ================= |
| 2900 | |
| 2901 | Over time, upstream developers publish new versions for software built |
| 2902 | by layer recipes. It is recommended to keep recipes up-to-date with |
| 2903 | upstream version releases. |
| 2904 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 2905 | While there are several methods to upgrade a recipe, you might |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2906 | consider checking on the upgrade status of a recipe first. You can do so |
| 2907 | using the ``devtool check-upgrade-status`` command. See the |
| 2908 | ":ref:`devtool-checking-on-the-upgrade-status-of-a-recipe`" |
| 2909 | section in the Yocto Project Reference Manual for more information. |
| 2910 | |
| 2911 | The remainder of this section describes three ways you can upgrade a |
| 2912 | recipe. You can use the Automated Upgrade Helper (AUH) to set up |
| 2913 | automatic version upgrades. Alternatively, you can use |
| 2914 | ``devtool upgrade`` to set up semi-automatic version upgrades. Finally, |
| 2915 | you can manually upgrade a recipe by editing the recipe itself. |
| 2916 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2917 | Using the Auto Upgrade Helper (AUH) |
| 2918 | ----------------------------------- |
| 2919 | |
| 2920 | The AUH utility works in conjunction with the OpenEmbedded build system |
| 2921 | in order to automatically generate upgrades for recipes based on new |
| 2922 | versions being published upstream. Use AUH when you want to create a |
| 2923 | service that performs the upgrades automatically and optionally sends |
| 2924 | you an email with the results. |
| 2925 | |
| 2926 | AUH allows you to update several recipes with a single use. You can also |
| 2927 | optionally perform build and integration tests using images with the |
| 2928 | results saved to your hard drive and emails of results optionally sent |
| 2929 | to recipe maintainers. Finally, AUH creates Git commits with appropriate |
| 2930 | commit messages in the layer's tree for the changes made to recipes. |
| 2931 | |
| 2932 | .. note:: |
| 2933 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 2934 | In some conditions, you should not use AUH to upgrade recipes |
| 2935 | and should instead use either ``devtool upgrade`` or upgrade your |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2936 | recipes manually: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2937 | |
| 2938 | - When AUH cannot complete the upgrade sequence. This situation |
| 2939 | usually results because custom patches carried by the recipe |
| 2940 | cannot be automatically rebased to the new version. In this case, |
| 2941 | ``devtool upgrade`` allows you to manually resolve conflicts. |
| 2942 | |
| 2943 | - When for any reason you want fuller control over the upgrade |
| 2944 | process. For example, when you want special arrangements for |
| 2945 | testing. |
| 2946 | |
| 2947 | The following steps describe how to set up the AUH utility: |
| 2948 | |
| 2949 | 1. *Be Sure the Development Host is Set Up:* You need to be sure that |
| 2950 | your development host is set up to use the Yocto Project. For |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2951 | information on how to set up your host, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 2952 | ":ref:`dev-manual/start:Preparing the Build Host`" section. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2953 | |
| 2954 | 2. *Make Sure Git is Configured:* The AUH utility requires Git to be |
| 2955 | configured because AUH uses Git to save upgrades. Thus, you must have |
| 2956 | Git user and email configured. The following command shows your |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2957 | configurations:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2958 | |
| 2959 | $ git config --list |
| 2960 | |
| 2961 | If you do not have the user and |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2962 | email configured, you can use the following commands to do so:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2963 | |
| 2964 | $ git config --global user.name some_name |
| 2965 | $ git config --global user.email username@domain.com |
| 2966 | |
| 2967 | 3. *Clone the AUH Repository:* To use AUH, you must clone the repository |
| 2968 | onto your development host. The following command uses Git to create |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2969 | a local copy of the repository on your system:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2970 | |
| 2971 | $ git clone git://git.yoctoproject.org/auto-upgrade-helper |
| 2972 | Cloning into 'auto-upgrade-helper'... remote: Counting objects: 768, done. |
| 2973 | remote: Compressing objects: 100% (300/300), done. |
| 2974 | remote: Total 768 (delta 499), reused 703 (delta 434) |
| 2975 | Receiving objects: 100% (768/768), 191.47 KiB | 98.00 KiB/s, done. |
| 2976 | Resolving deltas: 100% (499/499), done. |
| 2977 | Checking connectivity... done. |
| 2978 | |
| 2979 | AUH is not part of the :term:`OpenEmbedded-Core (OE-Core)` or |
| 2980 | :term:`Poky` repositories. |
| 2981 | |
| 2982 | 4. *Create a Dedicated Build Directory:* Run the |
| 2983 | :ref:`structure-core-script` |
| 2984 | script to create a fresh build directory that you use exclusively for |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2985 | running the AUH utility:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2986 | |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 2987 | $ cd poky |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2988 | $ source oe-init-build-env your_AUH_build_directory |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2989 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 2990 | Re-using an existing build directory and its configurations is not |
| 2991 | recommended as existing settings could cause AUH to fail or behave |
| 2992 | undesirably. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2993 | |
| 2994 | 5. *Make Configurations in Your Local Configuration File:* Several |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 2995 | settings are needed in the ``local.conf`` file in the build |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2996 | directory you just created for AUH. Make these following |
| 2997 | configurations: |
| 2998 | |
| 2999 | - If you want to enable :ref:`Build |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 3000 | History <dev-manual/common-tasks:maintaining build output quality>`, |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3001 | which is optional, you need the following lines in the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3002 | ``conf/local.conf`` file:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3003 | |
| 3004 | INHERIT =+ "buildhistory" |
| 3005 | BUILDHISTORY_COMMIT = "1" |
| 3006 | |
| 3007 | With this configuration and a successful |
| 3008 | upgrade, a build history "diff" file appears in the |
| 3009 | ``upgrade-helper/work/recipe/buildhistory-diff.txt`` file found in |
| 3010 | your build directory. |
| 3011 | |
| 3012 | - If you want to enable testing through the |
| 3013 | :ref:`testimage <ref-classes-testimage*>` |
| 3014 | class, which is optional, you need to have the following set in |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3015 | your ``conf/local.conf`` file:: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3016 | |
| 3017 | INHERIT += "testimage" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3018 | |
| 3019 | .. note:: |
| 3020 | |
| 3021 | If your distro does not enable by default ptest, which Poky |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3022 | does, you need the following in your ``local.conf`` file:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3023 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 3024 | DISTRO_FEATURES:append = " ptest" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3025 | |
| 3026 | |
| 3027 | 6. *Optionally Start a vncserver:* If you are running in a server |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3028 | without an X11 session, you need to start a vncserver:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3029 | |
| 3030 | $ vncserver :1 |
| 3031 | $ export DISPLAY=:1 |
| 3032 | |
| 3033 | 7. *Create and Edit an AUH Configuration File:* You need to have the |
| 3034 | ``upgrade-helper/upgrade-helper.conf`` configuration file in your |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3035 | build directory. You can find a sample configuration file in the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 3036 | :yocto_git:`AUH source repository </auto-upgrade-helper/tree/>`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3037 | |
| 3038 | Read through the sample file and make configurations as needed. For |
| 3039 | example, if you enabled build history in your ``local.conf`` as |
| 3040 | described earlier, you must enable it in ``upgrade-helper.conf``. |
| 3041 | |
| 3042 | Also, if you are using the default ``maintainers.inc`` file supplied |
| 3043 | with Poky and located in ``meta-yocto`` and you do not set a |
| 3044 | "maintainers_whitelist" or "global_maintainer_override" in the |
| 3045 | ``upgrade-helper.conf`` configuration, and you specify "-e all" on |
| 3046 | the AUH command-line, the utility automatically sends out emails to |
| 3047 | all the default maintainers. Please avoid this. |
| 3048 | |
| 3049 | This next set of examples describes how to use the AUH: |
| 3050 | |
| 3051 | - *Upgrading a Specific Recipe:* To upgrade a specific recipe, use the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3052 | following form:: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3053 | |
| 3054 | $ upgrade-helper.py recipe_name |
| 3055 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3056 | For example, this command upgrades the ``xmodmap`` recipe:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3057 | |
| 3058 | $ upgrade-helper.py xmodmap |
| 3059 | |
| 3060 | - *Upgrading a Specific Recipe to a Particular Version:* To upgrade a |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3061 | specific recipe to a particular version, use the following form:: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3062 | |
| 3063 | $ upgrade-helper.py recipe_name -t version |
| 3064 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3065 | 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] | 3066 | |
| 3067 | $ upgrade-helper.py xmodmap -t 1.2.3 |
| 3068 | |
| 3069 | - *Upgrading all Recipes to the Latest Versions and Suppressing Email |
| 3070 | Notifications:* To upgrade all recipes to their most recent versions |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3071 | and suppress the email notifications, use the following command:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3072 | |
| 3073 | $ upgrade-helper.py all |
| 3074 | |
| 3075 | - *Upgrading all Recipes to the Latest Versions and Send Email |
| 3076 | Notifications:* To upgrade all recipes to their most recent versions |
| 3077 | and send email messages to maintainers for each attempted recipe as |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3078 | well as a status email, use the following command:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3079 | |
| 3080 | $ upgrade-helper.py -e all |
| 3081 | |
| 3082 | Once you have run the AUH utility, you can find the results in the AUH |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3083 | build directory:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3084 | |
| 3085 | ${BUILDDIR}/upgrade-helper/timestamp |
| 3086 | |
| 3087 | The AUH utility |
| 3088 | also creates recipe update commits from successful upgrade attempts in |
| 3089 | the layer tree. |
| 3090 | |
| 3091 | You can easily set up to run the AUH utility on a regular basis by using |
| 3092 | a cron job. See the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 3093 | :yocto_git:`weeklyjob.sh </auto-upgrade-helper/tree/weeklyjob.sh>` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3094 | file distributed with the utility for an example. |
| 3095 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3096 | Using ``devtool upgrade`` |
| 3097 | ------------------------- |
| 3098 | |
| 3099 | As mentioned earlier, an alternative method for upgrading recipes to |
| 3100 | newer versions is to use |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 3101 | :doc:`devtool upgrade </ref-manual/devtool-reference>`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3102 | You can read about ``devtool upgrade`` in general in the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 3103 | ":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] | 3104 | section in the Yocto Project Application Development and the Extensible |
| 3105 | Software Development Kit (eSDK) Manual. |
| 3106 | |
| 3107 | To see all the command-line options available with ``devtool upgrade``, |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3108 | use the following help command:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3109 | |
| 3110 | $ devtool upgrade -h |
| 3111 | |
| 3112 | If you want to find out what version a recipe is currently at upstream |
| 3113 | without any attempt to upgrade your local version of the recipe, you can |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3114 | use the following command:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3115 | |
| 3116 | $ devtool latest-version recipe_name |
| 3117 | |
| 3118 | As mentioned in the previous section describing AUH, ``devtool upgrade`` |
| 3119 | works in a less-automated manner than AUH. Specifically, |
| 3120 | ``devtool upgrade`` only works on a single recipe that you name on the |
| 3121 | command line, cannot perform build and integration testing using images, |
| 3122 | and does not automatically generate commits for changes in the source |
| 3123 | tree. Despite all these "limitations", ``devtool upgrade`` updates the |
| 3124 | recipe file to the new upstream version and attempts to rebase custom |
| 3125 | patches contained by the recipe as needed. |
| 3126 | |
| 3127 | .. note:: |
| 3128 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3129 | AUH uses much of ``devtool upgrade`` behind the scenes making AUH somewhat |
| 3130 | of a "wrapper" application for ``devtool upgrade``. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3131 | |
| 3132 | A typical scenario involves having used Git to clone an upstream |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3133 | repository that you use during build operations. Because you have built the |
| 3134 | recipe in the past, the layer is likely added to your |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3135 | configuration already. If for some reason, the layer is not added, you |
| 3136 | could add it easily using the |
| 3137 | ":ref:`bitbake-layers <bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script>`" |
| 3138 | script. For example, suppose you use the ``nano.bb`` recipe from the |
| 3139 | ``meta-oe`` layer in the ``meta-openembedded`` repository. For this |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3140 | example, assume that the layer has been cloned into following area:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3141 | |
| 3142 | /home/scottrif/meta-openembedded |
| 3143 | |
| 3144 | The following command from your |
| 3145 | :term:`Build Directory` adds the layer to |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3146 | your build configuration (i.e. ``${BUILDDIR}/conf/bblayers.conf``):: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3147 | |
| 3148 | $ bitbake-layers add-layer /home/scottrif/meta-openembedded/meta-oe |
| 3149 | NOTE: Starting bitbake server... |
| 3150 | Parsing recipes: 100% |##########################################| Time: 0:00:55 |
| 3151 | Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors. |
| 3152 | Removing 12 recipes from the x86_64 sysroot: 100% |##############| Time: 0:00:00 |
| 3153 | Removing 1 recipes from the x86_64_i586 sysroot: 100% |##########| Time: 0:00:00 |
| 3154 | Removing 5 recipes from the i586 sysroot: 100% |#################| Time: 0:00:00 |
| 3155 | Removing 5 recipes from the qemux86 sysroot: 100% |##############| Time: 0:00:00 |
| 3156 | |
| 3157 | For this example, assume that the ``nano.bb`` recipe that |
| 3158 | is upstream has a 2.9.3 version number. However, the version in the |
| 3159 | local repository is 2.7.4. The following command from your build |
| 3160 | directory automatically upgrades the recipe for you: |
| 3161 | |
| 3162 | .. note:: |
| 3163 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3164 | Using the ``-V`` option is not necessary. Omitting the version number causes |
| 3165 | ``devtool upgrade`` to upgrade the recipe to the most recent version. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3166 | |
| 3167 | :: |
| 3168 | |
| 3169 | $ devtool upgrade nano -V 2.9.3 |
| 3170 | NOTE: Starting bitbake server... |
| 3171 | NOTE: Creating workspace layer in /home/scottrif/poky/build/workspace |
| 3172 | Parsing recipes: 100% |##########################################| Time: 0:00:46 |
| 3173 | Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors. |
| 3174 | NOTE: Extracting current version source... |
| 3175 | NOTE: Resolving any missing task queue dependencies |
| 3176 | . |
| 3177 | . |
| 3178 | . |
| 3179 | NOTE: Executing SetScene Tasks |
| 3180 | NOTE: Executing RunQueue Tasks |
| 3181 | NOTE: Tasks Summary: Attempted 74 tasks of which 72 didn't need to be rerun and all succeeded. |
| 3182 | Adding changed files: 100% |#####################################| Time: 0:00:00 |
| 3183 | NOTE: Upgraded source extracted to /home/scottrif/poky/build/workspace/sources/nano |
| 3184 | NOTE: New recipe is /home/scottrif/poky/build/workspace/recipes/nano/nano_2.9.3.bb |
| 3185 | |
| 3186 | Continuing with this example, you can use ``devtool build`` to build the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3187 | newly upgraded recipe:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3188 | |
| 3189 | $ devtool build nano |
| 3190 | NOTE: Starting bitbake server... |
| 3191 | Loading cache: 100% |################################################################################################| Time: 0:00:01 |
| 3192 | Loaded 2040 entries from dependency cache. |
| 3193 | Parsing recipes: 100% |##############################################################################################| Time: 0:00:00 |
| 3194 | Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors. |
| 3195 | NOTE: Resolving any missing task queue dependencies |
| 3196 | . |
| 3197 | . |
| 3198 | . |
| 3199 | NOTE: Executing SetScene Tasks |
| 3200 | NOTE: Executing RunQueue Tasks |
| 3201 | NOTE: nano: compiling from external source tree /home/scottrif/poky/build/workspace/sources/nano |
| 3202 | NOTE: Tasks Summary: Attempted 520 tasks of which 304 didn't need to be rerun and all succeeded. |
| 3203 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 3204 | Within the ``devtool upgrade`` workflow, you can |
| 3205 | deploy and test your rebuilt software. For this example, |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3206 | however, running ``devtool finish`` cleans up the workspace once the |
| 3207 | source in your workspace is clean. This usually means using Git to stage |
| 3208 | and submit commits for the changes generated by the upgrade process. |
| 3209 | |
| 3210 | Once the tree is clean, you can clean things up in this example with the |
| 3211 | following command from the ``${BUILDDIR}/workspace/sources/nano`` |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3212 | directory:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3213 | |
| 3214 | $ devtool finish nano meta-oe |
| 3215 | NOTE: Starting bitbake server... |
| 3216 | Loading cache: 100% |################################################################################################| Time: 0:00:00 |
| 3217 | Loaded 2040 entries from dependency cache. |
| 3218 | Parsing recipes: 100% |##############################################################################################| Time: 0:00:01 |
| 3219 | Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors. |
| 3220 | NOTE: Adding new patch 0001-nano.bb-Stuff-I-changed-when-upgrading-nano.bb.patch |
| 3221 | NOTE: Updating recipe nano_2.9.3.bb |
| 3222 | NOTE: Removing file /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano/nano_2.7.4.bb |
| 3223 | NOTE: Moving recipe file to /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano |
| 3224 | NOTE: Leaving source tree /home/scottrif/poky/build/workspace/sources/nano as-is; if you no longer need it then please delete it manually |
| 3225 | |
| 3226 | |
| 3227 | Using the ``devtool finish`` command cleans up the workspace and creates a patch |
| 3228 | file based on your commits. The tool puts all patch files back into the |
| 3229 | source directory in a sub-directory named ``nano`` in this case. |
| 3230 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3231 | Manually Upgrading a Recipe |
| 3232 | --------------------------- |
| 3233 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3234 | If for some reason you choose not to upgrade recipes using |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 3235 | :ref:`dev-manual/common-tasks:Using the Auto Upgrade Helper (AUH)` or |
| 3236 | by :ref:`dev-manual/common-tasks:Using \`\`devtool upgrade\`\``, |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3237 | you can manually edit the recipe files to upgrade the versions. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3238 | |
| 3239 | .. note:: |
| 3240 | |
| 3241 | Manually updating multiple recipes scales poorly and involves many |
| 3242 | steps. The recommendation to upgrade recipe versions is through AUH |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3243 | or ``devtool upgrade``, both of which automate some steps and provide |
| 3244 | guidance for others needed for the manual process. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3245 | |
| 3246 | To manually upgrade recipe versions, follow these general steps: |
| 3247 | |
| 3248 | 1. *Change the Version:* Rename the recipe such that the version (i.e. |
| 3249 | the :term:`PV` part of the recipe name) |
| 3250 | changes appropriately. If the version is not part of the recipe name, |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 3251 | change the value as it is set for :term:`PV` within the recipe itself. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3252 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 3253 | 2. *Update* :term:`SRCREV` *if Needed*: If the source code your recipe builds |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3254 | is fetched from Git or some other version control system, update |
| 3255 | :term:`SRCREV` to point to the |
| 3256 | commit hash that matches the new version. |
| 3257 | |
| 3258 | 3. *Build the Software:* Try to build the recipe using BitBake. Typical |
| 3259 | build failures include the following: |
| 3260 | |
| 3261 | - License statements were updated for the new version. For this |
| 3262 | case, you need to review any changes to the license and update the |
| 3263 | values of :term:`LICENSE` and |
| 3264 | :term:`LIC_FILES_CHKSUM` |
| 3265 | as needed. |
| 3266 | |
| 3267 | .. note:: |
| 3268 | |
| 3269 | License changes are often inconsequential. For example, the |
| 3270 | license text's copyright year might have changed. |
| 3271 | |
| 3272 | - Custom patches carried by the older version of the recipe might |
| 3273 | fail to apply to the new version. For these cases, you need to |
| 3274 | review the failures. Patches might not be necessary for the new |
| 3275 | version of the software if the upgraded version has fixed those |
| 3276 | issues. If a patch is necessary and failing, you need to rebase it |
| 3277 | into the new version. |
| 3278 | |
| 3279 | 4. *Optionally Attempt to Build for Several Architectures:* Once you |
| 3280 | successfully build the new software for a given architecture, you |
| 3281 | could test the build for other architectures by changing the |
| 3282 | :term:`MACHINE` variable and |
| 3283 | rebuilding the software. This optional step is especially important |
| 3284 | if the recipe is to be released publicly. |
| 3285 | |
| 3286 | 5. *Check the Upstream Change Log or Release Notes:* Checking both these |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 3287 | reveals if there are new features that could break |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3288 | backwards-compatibility. If so, you need to take steps to mitigate or |
| 3289 | eliminate that situation. |
| 3290 | |
| 3291 | 6. *Optionally Create a Bootable Image and Test:* If you want, you can |
| 3292 | test the new software by booting it onto actual hardware. |
| 3293 | |
| 3294 | 7. *Create a Commit with the Change in the Layer Repository:* After all |
| 3295 | builds work and any testing is successful, you can create commits for |
| 3296 | any changes in the layer holding your upgraded recipe. |
| 3297 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3298 | Finding Temporary Source Code |
| 3299 | ============================= |
| 3300 | |
| 3301 | You might find it helpful during development to modify the temporary |
| 3302 | source code used by recipes to build packages. For example, suppose you |
| 3303 | are developing a patch and you need to experiment a bit to figure out |
| 3304 | your solution. After you have initially built the package, you can |
| 3305 | iteratively tweak the source code, which is located in the |
| 3306 | :term:`Build Directory`, and then you can |
| 3307 | force a re-compile and quickly test your altered code. Once you settle |
| 3308 | on a solution, you can then preserve your changes in the form of |
| 3309 | patches. |
| 3310 | |
| 3311 | During a build, the unpacked temporary source code used by recipes to |
| 3312 | build packages is available in the Build Directory as defined by the |
| 3313 | :term:`S` variable. Below is the default |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 3314 | value for the :term:`S` variable as defined in the |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3315 | ``meta/conf/bitbake.conf`` configuration file in the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3316 | :term:`Source Directory`:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3317 | |
| 3318 | S = "${WORKDIR}/${BP}" |
| 3319 | |
| 3320 | You should be aware that many recipes override the |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 3321 | :term:`S` variable. For example, recipes that fetch their source from Git |
| 3322 | usually set :term:`S` to ``${WORKDIR}/git``. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3323 | |
| 3324 | .. note:: |
| 3325 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3326 | The :term:`BP` represents the base recipe name, which consists of the name |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3327 | and version:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3328 | |
| 3329 | BP = "${BPN}-${PV}" |
| 3330 | |
| 3331 | |
| 3332 | The path to the work directory for the recipe |
| 3333 | (:term:`WORKDIR`) is defined as |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3334 | follows:: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3335 | |
| 3336 | ${TMPDIR}/work/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR} |
| 3337 | |
| 3338 | The actual directory depends on several things: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3339 | |
| 3340 | - :term:`TMPDIR`: The top-level build |
| 3341 | output directory. |
| 3342 | |
| 3343 | - :term:`MULTIMACH_TARGET_SYS`: |
| 3344 | The target system identifier. |
| 3345 | |
| 3346 | - :term:`PN`: The recipe name. |
| 3347 | |
| 3348 | - :term:`EXTENDPE`: The epoch - (if |
| 3349 | :term:`PE` is not specified, which is |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 3350 | usually the case for most recipes, then :term:`EXTENDPE` is blank). |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3351 | |
| 3352 | - :term:`PV`: The recipe version. |
| 3353 | |
| 3354 | - :term:`PR`: The recipe revision. |
| 3355 | |
| 3356 | As an example, assume a Source Directory top-level folder named |
| 3357 | ``poky``, a default Build Directory at ``poky/build``, and a |
| 3358 | ``qemux86-poky-linux`` machine target system. Furthermore, suppose your |
| 3359 | recipe is named ``foo_1.3.0.bb``. In this case, the work directory the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3360 | build system uses to build the package would be as follows:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3361 | |
| 3362 | poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0 |
| 3363 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3364 | Using Quilt in Your Workflow |
| 3365 | ============================ |
| 3366 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3367 | `Quilt <https://savannah.nongnu.org/projects/quilt>`__ is a powerful tool |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3368 | that allows you to capture source code changes without having a clean |
| 3369 | source tree. This section outlines the typical workflow you can use to |
| 3370 | modify source code, test changes, and then preserve the changes in the |
| 3371 | form of a patch all using Quilt. |
| 3372 | |
| 3373 | .. note:: |
| 3374 | |
| 3375 | With regard to preserving changes to source files, if you clean a |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3376 | recipe or have ``rm_work`` enabled, the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 3377 | :ref:`devtool workflow <sdk-manual/extensible:using \`\`devtool\`\` in your sdk workflow>` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3378 | as described in the Yocto Project Application Development and the |
| 3379 | Extensible Software Development Kit (eSDK) manual is a safer |
| 3380 | development flow than the flow that uses Quilt. |
| 3381 | |
| 3382 | Follow these general steps: |
| 3383 | |
| 3384 | 1. *Find the Source Code:* Temporary source code used by the |
| 3385 | OpenEmbedded build system is kept in the |
| 3386 | :term:`Build Directory`. See the |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 3387 | ":ref:`dev-manual/common-tasks:finding temporary source code`" section to |
| 3388 | learn how to locate the directory that has the temporary source code for a |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3389 | particular package. |
| 3390 | |
| 3391 | 2. *Change Your Working Directory:* You need to be in the directory that |
| 3392 | has the temporary source code. That directory is defined by the |
| 3393 | :term:`S` variable. |
| 3394 | |
| 3395 | 3. *Create a New Patch:* Before modifying source code, you need to |
| 3396 | create a new patch. To create a new patch file, use ``quilt new`` as |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3397 | below:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3398 | |
| 3399 | $ quilt new my_changes.patch |
| 3400 | |
| 3401 | 4. *Notify Quilt and Add Files:* After creating the patch, you need to |
| 3402 | notify Quilt about the files you plan to edit. You notify Quilt by |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3403 | adding the files to the patch you just created:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3404 | |
| 3405 | $ quilt add file1.c file2.c file3.c |
| 3406 | |
| 3407 | 5. *Edit the Files:* Make your changes in the source code to the files |
| 3408 | you added to the patch. |
| 3409 | |
| 3410 | 6. *Test Your Changes:* Once you have modified the source code, the |
| 3411 | easiest way to test your changes is by calling the ``do_compile`` |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3412 | task as shown in the following example:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3413 | |
| 3414 | $ bitbake -c compile -f package |
| 3415 | |
| 3416 | The ``-f`` or ``--force`` option forces the specified task to |
| 3417 | execute. If you find problems with your code, you can just keep |
| 3418 | editing and re-testing iteratively until things work as expected. |
| 3419 | |
| 3420 | .. note:: |
| 3421 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3422 | All the modifications you make to the temporary source code disappear |
| 3423 | once you run the ``do_clean`` or ``do_cleanall`` tasks using BitBake |
| 3424 | (i.e. ``bitbake -c clean package`` and ``bitbake -c cleanall package``). |
| 3425 | Modifications will also disappear if you use the ``rm_work`` feature as |
| 3426 | described in the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 3427 | ":ref:`dev-manual/common-tasks:conserving disk space during builds`" |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3428 | section. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3429 | |
| 3430 | 7. *Generate the Patch:* Once your changes work as expected, you need to |
| 3431 | use Quilt to generate the final patch that contains all your |
| 3432 | modifications. |
| 3433 | :: |
| 3434 | |
| 3435 | $ quilt refresh |
| 3436 | |
| 3437 | At this point, the |
| 3438 | ``my_changes.patch`` file has all your edits made to the ``file1.c``, |
| 3439 | ``file2.c``, and ``file3.c`` files. |
| 3440 | |
| 3441 | You can find the resulting patch file in the ``patches/`` |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 3442 | subdirectory of the source (:term:`S`) directory. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3443 | |
| 3444 | 8. *Copy the Patch File:* For simplicity, copy the patch file into a |
| 3445 | directory named ``files``, which you can create in the same directory |
| 3446 | that holds the recipe (``.bb``) file or the append (``.bbappend``) |
| 3447 | file. Placing the patch here guarantees that the OpenEmbedded build |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 3448 | system will find the patch. Next, add the patch into the :term:`SRC_URI` |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3449 | of the recipe. Here is an example:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3450 | |
| 3451 | SRC_URI += "file://my_changes.patch" |
| 3452 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3453 | Using a Development Shell |
| 3454 | ========================= |
| 3455 | |
| 3456 | When debugging certain commands or even when just editing packages, |
| 3457 | ``devshell`` can be a useful tool. When you invoke ``devshell``, all |
| 3458 | tasks up to and including |
| 3459 | :ref:`ref-tasks-patch` are run for the |
| 3460 | specified target. Then, a new terminal is opened and you are placed in |
| 3461 | ``${``\ :term:`S`\ ``}``, the source |
| 3462 | directory. In the new terminal, all the OpenEmbedded build-related |
| 3463 | environment variables are still defined so you can use commands such as |
| 3464 | ``configure`` and ``make``. The commands execute just as if the |
| 3465 | OpenEmbedded build system were executing them. Consequently, working |
| 3466 | this way can be helpful when debugging a build or preparing software to |
| 3467 | be used with the OpenEmbedded build system. |
| 3468 | |
| 3469 | Following is an example that uses ``devshell`` on a target named |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3470 | ``matchbox-desktop``:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3471 | |
| 3472 | $ bitbake matchbox-desktop -c devshell |
| 3473 | |
| 3474 | This command spawns a terminal with a shell prompt within the |
| 3475 | OpenEmbedded build environment. The |
| 3476 | :term:`OE_TERMINAL` variable |
| 3477 | controls what type of shell is opened. |
| 3478 | |
| 3479 | For spawned terminals, the following occurs: |
| 3480 | |
| 3481 | - The ``PATH`` variable includes the cross-toolchain. |
| 3482 | |
| 3483 | - The ``pkgconfig`` variables find the correct ``.pc`` files. |
| 3484 | |
| 3485 | - The ``configure`` command finds the Yocto Project site files as well |
| 3486 | as any other necessary files. |
| 3487 | |
| 3488 | Within this environment, you can run configure or compile commands as if |
| 3489 | they were being run by the OpenEmbedded build system itself. As noted |
| 3490 | earlier, the working directory also automatically changes to the Source |
| 3491 | Directory (:term:`S`). |
| 3492 | |
| 3493 | To manually run a specific task using ``devshell``, run the |
| 3494 | corresponding ``run.*`` script in the |
| 3495 | ``${``\ :term:`WORKDIR`\ ``}/temp`` |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3496 | 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] | 3497 | not exist, which would be the case if the task was skipped by way of the |
| 3498 | sstate cache, you can create the task by first running it outside of the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3499 | ``devshell``:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3500 | |
| 3501 | $ bitbake -c task |
| 3502 | |
| 3503 | .. note:: |
| 3504 | |
| 3505 | - Execution of a task's ``run.*`` script and BitBake's execution of |
| 3506 | a task are identical. In other words, running the script re-runs |
| 3507 | the task just as it would be run using the ``bitbake -c`` command. |
| 3508 | |
| 3509 | - Any ``run.*`` file that does not have a ``.pid`` extension is a |
| 3510 | symbolic link (symlink) to the most recent version of that file. |
| 3511 | |
| 3512 | Remember, that the ``devshell`` is a mechanism that allows you to get |
| 3513 | into the BitBake task execution environment. And as such, all commands |
| 3514 | must be called just as BitBake would call them. That means you need to |
| 3515 | provide the appropriate options for cross-compilation and so forth as |
| 3516 | applicable. |
| 3517 | |
| 3518 | When you are finished using ``devshell``, exit the shell or close the |
| 3519 | terminal window. |
| 3520 | |
| 3521 | .. note:: |
| 3522 | |
| 3523 | - It is worth remembering that when using ``devshell`` you need to |
| 3524 | use the full compiler name such as ``arm-poky-linux-gnueabi-gcc`` |
| 3525 | instead of just using ``gcc``. The same applies to other |
| 3526 | applications such as ``binutils``, ``libtool`` and so forth. |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 3527 | BitBake sets up environment variables such as :term:`CC` to assist |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3528 | applications, such as ``make`` to find the correct tools. |
| 3529 | |
| 3530 | - It is also worth noting that ``devshell`` still works over X11 |
| 3531 | forwarding and similar situations. |
| 3532 | |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 3533 | Using a Python Development Shell |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3534 | ================================ |
| 3535 | |
| 3536 | Similar to working within a development shell as described in the |
| 3537 | previous section, you can also spawn and work within an interactive |
| 3538 | Python development shell. When debugging certain commands or even when |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 3539 | just editing packages, ``pydevshell`` can be a useful tool. When you |
| 3540 | invoke the ``pydevshell`` task, all tasks up to and including |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3541 | :ref:`ref-tasks-patch` are run for the |
| 3542 | specified target. Then a new terminal is opened. Additionally, key |
| 3543 | Python objects and code are available in the same way they are to |
| 3544 | BitBake tasks, in particular, the data store 'd'. So, commands such as |
| 3545 | the following are useful when exploring the data store and running |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3546 | functions:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3547 | |
| 3548 | pydevshell> d.getVar("STAGING_DIR") |
| 3549 | '/media/build1/poky/build/tmp/sysroots' |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 3550 | pydevshell> d.getVar("STAGING_DIR", False) |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3551 | '${TMPDIR}/sysroots' |
| 3552 | pydevshell> d.setVar("FOO", "bar") |
| 3553 | pydevshell> d.getVar("FOO") |
| 3554 | 'bar' |
| 3555 | pydevshell> d.delVar("FOO") |
| 3556 | pydevshell> d.getVar("FOO") |
| 3557 | pydevshell> bb.build.exec_func("do_unpack", d) |
| 3558 | pydevshell> |
| 3559 | |
| 3560 | The commands execute just as if the OpenEmbedded build |
| 3561 | system were executing them. Consequently, working this way can be |
| 3562 | helpful when debugging a build or preparing software to be used with the |
| 3563 | OpenEmbedded build system. |
| 3564 | |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 3565 | Following is an example that uses ``pydevshell`` on a target named |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3566 | ``matchbox-desktop``:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3567 | |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 3568 | $ bitbake matchbox-desktop -c pydevshell |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3569 | |
| 3570 | This command spawns a terminal and places you in an interactive Python |
| 3571 | interpreter within the OpenEmbedded build environment. The |
| 3572 | :term:`OE_TERMINAL` variable |
| 3573 | controls what type of shell is opened. |
| 3574 | |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 3575 | When you are finished using ``pydevshell``, you can exit the shell |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3576 | either by using Ctrl+d or closing the terminal window. |
| 3577 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3578 | Building |
| 3579 | ======== |
| 3580 | |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 3581 | This section describes various build procedures, such as the steps |
| 3582 | needed for a simple build, building a target for multiple configurations, |
| 3583 | generating an image for more than one machine, and so forth. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3584 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3585 | Building a Simple Image |
| 3586 | ----------------------- |
| 3587 | |
| 3588 | In the development environment, you need to build an image whenever you |
| 3589 | change hardware support, add or change system libraries, or add or |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 3590 | change services that have dependencies. There are several methods that allow |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3591 | you to build an image within the Yocto Project. This section presents |
| 3592 | the basic steps you need to build a simple image using BitBake from a |
| 3593 | build host running Linux. |
| 3594 | |
| 3595 | .. note:: |
| 3596 | |
| 3597 | - For information on how to build an image using |
| 3598 | :term:`Toaster`, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 3599 | :doc:`/toaster-manual/index`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3600 | |
| 3601 | - For information on how to use ``devtool`` to build images, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 3602 | ":ref:`sdk-manual/extensible:using \`\`devtool\`\` in your sdk workflow`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3603 | section in the Yocto Project Application Development and the |
| 3604 | Extensible Software Development Kit (eSDK) manual. |
| 3605 | |
| 3606 | - For a quick example on how to build an image using the |
| 3607 | OpenEmbedded build system, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 3608 | :doc:`/brief-yoctoprojectqs/index` document. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3609 | |
| 3610 | The build process creates an entire Linux distribution from source and |
| 3611 | places it in your :term:`Build Directory` under |
| 3612 | ``tmp/deploy/images``. For detailed information on the build process |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 3613 | using BitBake, see the ":ref:`overview-manual/concepts:images`" section in the |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3614 | Yocto Project Overview and Concepts Manual. |
| 3615 | |
| 3616 | The following figure and list overviews the build process: |
| 3617 | |
| 3618 | .. image:: figures/bitbake-build-flow.png |
| 3619 | :align: center |
| 3620 | |
| 3621 | 1. *Set up Your Host Development System to Support Development Using the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 3622 | 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] | 3623 | build host ready to use the Yocto Project. |
| 3624 | |
| 3625 | 2. *Initialize the Build Environment:* Initialize the build environment |
| 3626 | by sourcing the build environment script (i.e. |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3627 | :ref:`structure-core-script`):: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3628 | |
| 3629 | $ source oe-init-build-env [build_dir] |
| 3630 | |
| 3631 | When you use the initialization script, the OpenEmbedded build system |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3632 | uses ``build`` as the default :term:`Build Directory` in your current work |
| 3633 | directory. You can use a `build_dir` argument with the script to |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3634 | specify a different build directory. |
| 3635 | |
| 3636 | .. note:: |
| 3637 | |
| 3638 | A common practice is to use a different Build Directory for |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 3639 | different targets; for example, ``~/build/x86`` for a ``qemux86`` |
| 3640 | target, and ``~/build/arm`` for a ``qemuarm`` target. In any |
| 3641 | event, it's typically cleaner to locate the build directory |
| 3642 | somewhere outside of your source directory. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3643 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3644 | 3. *Make Sure Your* ``local.conf`` *File is Correct*: Ensure the |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3645 | ``conf/local.conf`` configuration file, which is found in the Build |
| 3646 | Directory, is set up how you want it. This file defines many aspects |
| 3647 | of the build environment including the target machine architecture |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 3648 | through the :term:`MACHINE` variable, the packaging format used during |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3649 | the build |
| 3650 | (:term:`PACKAGE_CLASSES`), |
| 3651 | and a centralized tarball download directory through the |
| 3652 | :term:`DL_DIR` variable. |
| 3653 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3654 | 4. *Build the Image:* Build the image using the ``bitbake`` command:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3655 | |
| 3656 | $ bitbake target |
| 3657 | |
| 3658 | .. note:: |
| 3659 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3660 | For information on BitBake, see the :doc:`bitbake:index`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3661 | |
| 3662 | The target is the name of the recipe you want to build. Common |
| 3663 | targets are the images in ``meta/recipes-core/images``, |
| 3664 | ``meta/recipes-sato/images``, and so forth all found in the |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 3665 | :term:`Source Directory`. Alternatively, the target |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3666 | can be the name of a recipe for a specific piece of software such as |
| 3667 | BusyBox. For more details about the images the OpenEmbedded build |
| 3668 | system supports, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 3669 | ":ref:`ref-manual/images:Images`" chapter in the Yocto |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3670 | Project Reference Manual. |
| 3671 | |
| 3672 | As an example, the following command builds the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3673 | ``core-image-minimal`` image:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3674 | |
| 3675 | $ bitbake core-image-minimal |
| 3676 | |
| 3677 | Once an |
| 3678 | image has been built, it often needs to be installed. The images and |
| 3679 | kernels built by the OpenEmbedded build system are placed in the |
| 3680 | Build Directory in ``tmp/deploy/images``. For information on how to |
| 3681 | run pre-built images such as ``qemux86`` and ``qemuarm``, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 3682 | :doc:`/sdk-manual/index` manual. For |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3683 | information about how to install these images, see the documentation |
| 3684 | for your particular board or machine. |
| 3685 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3686 | Building Images for Multiple Targets Using Multiple Configurations |
| 3687 | ------------------------------------------------------------------ |
| 3688 | |
| 3689 | You can use a single ``bitbake`` command to build multiple images or |
| 3690 | packages for different targets where each image or package requires a |
| 3691 | different configuration (multiple configuration builds). The builds, in |
| 3692 | this scenario, are sometimes referred to as "multiconfigs", and this |
| 3693 | section uses that term throughout. |
| 3694 | |
| 3695 | This section describes how to set up for multiple configuration builds |
| 3696 | and how to account for cross-build dependencies between the |
| 3697 | multiconfigs. |
| 3698 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3699 | Setting Up and Running a Multiple Configuration Build |
| 3700 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3701 | |
| 3702 | To accomplish a multiple configuration build, you must define each |
| 3703 | target's configuration separately using a parallel configuration file in |
| 3704 | the :term:`Build Directory`, and you |
| 3705 | must follow a required file hierarchy. Additionally, you must enable the |
| 3706 | multiple configuration builds in your ``local.conf`` file. |
| 3707 | |
| 3708 | Follow these steps to set up and execute multiple configuration builds: |
| 3709 | |
| 3710 | - *Create Separate Configuration Files*: You need to create a single |
| 3711 | configuration file for each build target (each multiconfig). |
| 3712 | Minimally, each configuration file must define the machine and the |
| 3713 | temporary directory BitBake uses for the build. Suggested practice |
| 3714 | dictates that you do not overlap the temporary directories used |
| 3715 | during the builds. However, it is possible that you can share the |
| 3716 | temporary directory |
| 3717 | (:term:`TMPDIR`). For example, |
| 3718 | consider a scenario with two different multiconfigs for the same |
| 3719 | :term:`MACHINE`: "qemux86" built |
| 3720 | for two distributions such as "poky" and "poky-lsb". In this case, |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 3721 | you might want to use the same :term:`TMPDIR`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3722 | |
| 3723 | Here is an example showing the minimal statements needed in a |
| 3724 | configuration file for a "qemux86" target whose temporary build |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3725 | directory is ``tmpmultix86``:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3726 | |
| 3727 | MACHINE = "qemux86" |
| 3728 | TMPDIR = "${TOPDIR}/tmpmultix86" |
| 3729 | |
| 3730 | The location for these multiconfig configuration files is specific. |
| 3731 | They must reside in the current build directory in a sub-directory of |
| 3732 | ``conf`` named ``multiconfig``. Following is an example that defines |
| 3733 | two configuration files for the "x86" and "arm" multiconfigs: |
| 3734 | |
| 3735 | .. image:: figures/multiconfig_files.png |
| 3736 | :align: center |
| 3737 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 3738 | The reason for this required file hierarchy is because the :term:`BBPATH` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3739 | variable is not constructed until the layers are parsed. |
| 3740 | Consequently, using the configuration file as a pre-configuration |
| 3741 | file is not possible unless it is located in the current working |
| 3742 | directory. |
| 3743 | |
| 3744 | - *Add the BitBake Multi-configuration Variable to the Local |
| 3745 | Configuration File*: Use the |
| 3746 | :term:`BBMULTICONFIG` |
| 3747 | variable in your ``conf/local.conf`` configuration file to specify |
| 3748 | each multiconfig. Continuing with the example from the previous |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 3749 | figure, the :term:`BBMULTICONFIG` variable needs to enable two |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3750 | multiconfigs: "x86" and "arm" by specifying each configuration file:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3751 | |
| 3752 | BBMULTICONFIG = "x86 arm" |
| 3753 | |
| 3754 | .. note:: |
| 3755 | |
| 3756 | A "default" configuration already exists by definition. This |
| 3757 | configuration is named: "" (i.e. empty string) and is defined by |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3758 | the variables coming from your ``local.conf`` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3759 | file. Consequently, the previous example actually adds two |
| 3760 | additional configurations to your build: "arm" and "x86" along |
| 3761 | with "". |
| 3762 | |
| 3763 | - *Launch BitBake*: Use the following BitBake command form to launch |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3764 | the multiple configuration build:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3765 | |
| 3766 | $ bitbake [mc:multiconfigname:]target [[[mc:multiconfigname:]target] ... ] |
| 3767 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3768 | For the example in this section, the following command applies:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3769 | |
| 3770 | $ bitbake mc:x86:core-image-minimal mc:arm:core-image-sato mc::core-image-base |
| 3771 | |
| 3772 | The previous BitBake command builds a ``core-image-minimal`` image |
| 3773 | that is configured through the ``x86.conf`` configuration file, a |
| 3774 | ``core-image-sato`` image that is configured through the ``arm.conf`` |
| 3775 | configuration file and a ``core-image-base`` that is configured |
| 3776 | through your ``local.conf`` configuration file. |
| 3777 | |
| 3778 | .. note:: |
| 3779 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3780 | Support for multiple configuration builds in the Yocto Project &DISTRO; |
| 3781 | (&DISTRO_NAME;) Release does not include Shared State (sstate) |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3782 | optimizations. Consequently, if a build uses the same object twice |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 3783 | in, for example, two different :term:`TMPDIR` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3784 | directories, the build either loads from an existing sstate cache for |
| 3785 | that build at the start or builds the object fresh. |
| 3786 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3787 | Enabling Multiple Configuration Build Dependencies |
| 3788 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3789 | |
| 3790 | Sometimes dependencies can exist between targets (multiconfigs) in a |
| 3791 | multiple configuration build. For example, suppose that in order to |
| 3792 | build a ``core-image-sato`` image for an "x86" multiconfig, the root |
| 3793 | filesystem of an "arm" multiconfig must exist. This dependency is |
| 3794 | essentially that the |
| 3795 | :ref:`ref-tasks-image` task in the |
| 3796 | ``core-image-sato`` recipe depends on the completion of the |
| 3797 | :ref:`ref-tasks-rootfs` task of the |
| 3798 | ``core-image-minimal`` recipe. |
| 3799 | |
| 3800 | To enable dependencies in a multiple configuration build, you must |
| 3801 | declare the dependencies in the recipe using the following statement |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3802 | form:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3803 | |
| 3804 | task_or_package[mcdepends] = "mc:from_multiconfig:to_multiconfig:recipe_name:task_on_which_to_depend" |
| 3805 | |
| 3806 | To better show how to use this statement, consider the example scenario |
| 3807 | from the first paragraph of this section. The following statement needs |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3808 | to be added to the recipe that builds the ``core-image-sato`` image:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3809 | |
| 3810 | do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_rootfs" |
| 3811 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3812 | 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] | 3813 | task on which the ``do_image`` task in the recipe depends is the |
| 3814 | ``do_rootfs`` task from the ``core-image-minimal`` recipe associated |
| 3815 | with the "arm" multiconfig. |
| 3816 | |
| 3817 | Once you set up this dependency, you can build the "x86" multiconfig |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3818 | using a BitBake command as follows:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3819 | |
| 3820 | $ bitbake mc:x86:core-image-sato |
| 3821 | |
| 3822 | This command executes all the tasks needed to create the |
| 3823 | ``core-image-sato`` image for the "x86" multiconfig. Because of the |
| 3824 | dependency, BitBake also executes through the ``do_rootfs`` task for the |
| 3825 | "arm" multiconfig build. |
| 3826 | |
| 3827 | Having a recipe depend on the root filesystem of another build might not |
| 3828 | seem that useful. Consider this change to the statement in the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 3829 | ``core-image-sato`` recipe:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3830 | |
| 3831 | do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_image" |
| 3832 | |
| 3833 | In this case, BitBake must |
| 3834 | create the ``core-image-minimal`` image for the "arm" build since the |
| 3835 | "x86" build depends on it. |
| 3836 | |
| 3837 | Because "x86" and "arm" are enabled for multiple configuration builds |
| 3838 | and have separate configuration files, BitBake places the artifacts for |
| 3839 | each build in the respective temporary build directories (i.e. |
| 3840 | :term:`TMPDIR`). |
| 3841 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3842 | Building an Initial RAM Filesystem (initramfs) Image |
| 3843 | ---------------------------------------------------- |
| 3844 | |
| 3845 | An initial RAM filesystem (initramfs) image provides a temporary root |
| 3846 | filesystem used for early system initialization (e.g. loading of modules |
| 3847 | needed to locate and mount the "real" root filesystem). |
| 3848 | |
| 3849 | .. note:: |
| 3850 | |
| 3851 | The initramfs image is the successor of initial RAM disk (initrd). It |
| 3852 | is a "copy in and out" (cpio) archive of the initial filesystem that |
| 3853 | gets loaded into memory during the Linux startup process. Because |
| 3854 | Linux uses the contents of the archive during initialization, the |
| 3855 | initramfs image needs to contain all of the device drivers and tools |
| 3856 | needed to mount the final root filesystem. |
| 3857 | |
| 3858 | Follow these steps to create an initramfs image: |
| 3859 | |
| 3860 | 1. *Create the initramfs Image Recipe:* You can reference the |
| 3861 | ``core-image-minimal-initramfs.bb`` recipe found in the |
| 3862 | ``meta/recipes-core`` directory of the :term:`Source Directory` |
| 3863 | as an example |
| 3864 | from which to work. |
| 3865 | |
| 3866 | 2. *Decide if You Need to Bundle the initramfs Image Into the Kernel |
| 3867 | Image:* If you want the initramfs image that is built to be bundled |
| 3868 | in with the kernel image, set the |
| 3869 | :term:`INITRAMFS_IMAGE_BUNDLE` |
| 3870 | variable to "1" in your ``local.conf`` configuration file and set the |
| 3871 | :term:`INITRAMFS_IMAGE` |
| 3872 | variable in the recipe that builds the kernel image. |
| 3873 | |
| 3874 | .. note:: |
| 3875 | |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 3876 | It is recommended that you bundle the initramfs image with the |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3877 | kernel image to avoid circular dependencies between the kernel |
| 3878 | recipe and the initramfs recipe should the initramfs image include |
| 3879 | kernel modules. |
| 3880 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 3881 | Setting the :term:`INITRAMFS_IMAGE_BUNDLE` flag causes the initramfs |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3882 | image to be unpacked into the ``${B}/usr/`` directory. The unpacked |
| 3883 | initramfs image is then passed to the kernel's ``Makefile`` using the |
| 3884 | :term:`CONFIG_INITRAMFS_SOURCE` |
| 3885 | variable, allowing the initramfs image to be built into the kernel |
| 3886 | normally. |
| 3887 | |
| 3888 | .. note:: |
| 3889 | |
Patrick Williams | 93c203f | 2021-10-06 16:15:23 -0500 | [diff] [blame] | 3890 | Bundling the initramfs with the kernel conflates the code in the initramfs |
| 3891 | with the GPLv2 licensed Linux kernel binary. Thus only GPLv2 compatible |
| 3892 | software may be part of a bundled initramfs. |
| 3893 | |
| 3894 | .. note:: |
| 3895 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3896 | If you choose to not bundle the initramfs image with the kernel |
| 3897 | image, you are essentially using an |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3898 | `Initial RAM Disk (initrd) <https://en.wikipedia.org/wiki/Initrd>`__. |
| 3899 | Creating an initrd is handled primarily through the :term:`INITRD_IMAGE`, |
| 3900 | ``INITRD_LIVE``, and ``INITRD_IMAGE_LIVE`` variables. For more |
| 3901 | information, see the :ref:`ref-classes-image-live` file. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3902 | |
| 3903 | 3. *Optionally Add Items to the initramfs Image Through the initramfs |
| 3904 | Image Recipe:* If you add items to the initramfs image by way of its |
| 3905 | recipe, you should use |
| 3906 | :term:`PACKAGE_INSTALL` |
| 3907 | rather than |
| 3908 | :term:`IMAGE_INSTALL`. |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 3909 | :term:`PACKAGE_INSTALL` gives more direct control of what is added to the |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3910 | image as compared to the defaults you might not necessarily want that |
| 3911 | are set by the :ref:`image <ref-classes-image>` |
| 3912 | or :ref:`core-image <ref-classes-core-image>` |
| 3913 | classes. |
| 3914 | |
| 3915 | 4. *Build the Kernel Image and the initramfs Image:* Build your kernel |
| 3916 | image using BitBake. Because the initramfs image recipe is a |
| 3917 | dependency of the kernel image, the initramfs image is built as well |
| 3918 | and bundled with the kernel image if you used the |
| 3919 | :term:`INITRAMFS_IMAGE_BUNDLE` |
| 3920 | variable described earlier. |
| 3921 | |
| 3922 | Building a Tiny System |
| 3923 | ---------------------- |
| 3924 | |
| 3925 | Very small distributions have some significant advantages such as |
| 3926 | requiring less on-die or in-package memory (cheaper), better performance |
| 3927 | through efficient cache usage, lower power requirements due to less |
| 3928 | memory, faster boot times, and reduced development overhead. Some |
| 3929 | real-world examples where a very small distribution gives you distinct |
| 3930 | advantages are digital cameras, medical devices, and small headless |
| 3931 | systems. |
| 3932 | |
| 3933 | This section presents information that shows you how you can trim your |
| 3934 | distribution to even smaller sizes than the ``poky-tiny`` distribution, |
| 3935 | which is around 5 Mbytes, that can be built out-of-the-box using the |
| 3936 | Yocto Project. |
| 3937 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3938 | Tiny System Overview |
| 3939 | ~~~~~~~~~~~~~~~~~~~~ |
| 3940 | |
| 3941 | The following list presents the overall steps you need to consider and |
| 3942 | perform to create distributions with smaller root filesystems, achieve |
| 3943 | faster boot times, maintain your critical functionality, and avoid |
| 3944 | initial RAM disks: |
| 3945 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 3946 | - :ref:`Determine your goals and guiding principles |
| 3947 | <dev-manual/common-tasks:goals and guiding principles>` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3948 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 3949 | - :ref:`dev-manual/common-tasks:understand what contributes to your image size` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3950 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 3951 | - :ref:`Reduce the size of the root filesystem |
| 3952 | <dev-manual/common-tasks:trim the root filesystem>` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3953 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 3954 | - :ref:`Reduce the size of the kernel <dev-manual/common-tasks:trim the kernel>` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3955 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 3956 | - :ref:`dev-manual/common-tasks:remove package management requirements` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3957 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 3958 | - :ref:`dev-manual/common-tasks:look for other ways to minimize size` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3959 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 3960 | - :ref:`dev-manual/common-tasks:iterate on the process` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3961 | |
| 3962 | Goals and Guiding Principles |
| 3963 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3964 | |
| 3965 | Before you can reach your destination, you need to know where you are |
| 3966 | going. Here is an example list that you can use as a guide when creating |
| 3967 | very small distributions: |
| 3968 | |
| 3969 | - Determine how much space you need (e.g. a kernel that is 1 Mbyte or |
| 3970 | less and a root filesystem that is 3 Mbytes or less). |
| 3971 | |
| 3972 | - Find the areas that are currently taking 90% of the space and |
| 3973 | concentrate on reducing those areas. |
| 3974 | |
| 3975 | - Do not create any difficult "hacks" to achieve your goals. |
| 3976 | |
| 3977 | - Leverage the device-specific options. |
| 3978 | |
| 3979 | - Work in a separate layer so that you keep changes isolated. For |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 3980 | information on how to create layers, see the |
| 3981 | ":ref:`dev-manual/common-tasks:understanding and creating layers`" section. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3982 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3983 | Understand What Contributes to Your Image Size |
| 3984 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3985 | |
| 3986 | It is easiest to have something to start with when creating your own |
| 3987 | distribution. You can use the Yocto Project out-of-the-box to create the |
| 3988 | ``poky-tiny`` distribution. Ultimately, you will want to make changes in |
| 3989 | your own distribution that are likely modeled after ``poky-tiny``. |
| 3990 | |
| 3991 | .. note:: |
| 3992 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 3993 | To use ``poky-tiny`` in your build, set the :term:`DISTRO` variable in your |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3994 | ``local.conf`` file to "poky-tiny" as described in the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 3995 | ":ref:`dev-manual/common-tasks:creating your own distribution`" |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 3996 | section. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 3997 | |
| 3998 | Understanding some memory concepts will help you reduce the system size. |
| 3999 | Memory consists of static, dynamic, and temporary memory. Static memory |
| 4000 | is the TEXT (code), DATA (initialized data in the code), and BSS |
| 4001 | (uninitialized data) sections. Dynamic memory represents memory that is |
| 4002 | allocated at runtime: stacks, hash tables, and so forth. Temporary |
| 4003 | memory is recovered after the boot process. This memory consists of |
| 4004 | memory used for decompressing the kernel and for the ``__init__`` |
| 4005 | functions. |
| 4006 | |
| 4007 | To help you see where you currently are with kernel and root filesystem |
| 4008 | sizes, you can use two tools found in the :term:`Source Directory` |
| 4009 | in the |
| 4010 | ``scripts/tiny/`` directory: |
| 4011 | |
| 4012 | - ``ksize.py``: Reports component sizes for the kernel build objects. |
| 4013 | |
| 4014 | - ``dirsize.py``: Reports component sizes for the root filesystem. |
| 4015 | |
| 4016 | This next tool and command help you organize configuration fragments and |
| 4017 | view file dependencies in a human-readable form: |
| 4018 | |
| 4019 | - ``merge_config.sh``: Helps you manage configuration files and |
| 4020 | fragments within the kernel. With this tool, you can merge individual |
| 4021 | configuration fragments together. The tool allows you to make |
| 4022 | overrides and warns you of any missing configuration options. The |
| 4023 | tool is ideal for allowing you to iterate on configurations, create |
| 4024 | minimal configurations, and create configuration files for different |
| 4025 | machines without having to duplicate your process. |
| 4026 | |
| 4027 | The ``merge_config.sh`` script is part of the Linux Yocto kernel Git |
| 4028 | repositories (i.e. ``linux-yocto-3.14``, ``linux-yocto-3.10``, |
| 4029 | ``linux-yocto-3.8``, and so forth) in the ``scripts/kconfig`` |
| 4030 | directory. |
| 4031 | |
| 4032 | For more information on configuration fragments, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 4033 | ":ref:`kernel-dev/common:creating configuration fragments`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4034 | section in the Yocto Project Linux Kernel Development Manual. |
| 4035 | |
| 4036 | - ``bitbake -u taskexp -g bitbake_target``: Using the BitBake command |
| 4037 | with these options brings up a Dependency Explorer from which you can |
| 4038 | view file dependencies. Understanding these dependencies allows you |
| 4039 | to make informed decisions when cutting out various pieces of the |
| 4040 | kernel and root filesystem. |
| 4041 | |
| 4042 | Trim the Root Filesystem |
| 4043 | ~~~~~~~~~~~~~~~~~~~~~~~~ |
| 4044 | |
| 4045 | The root filesystem is made up of packages for booting, libraries, and |
| 4046 | applications. To change things, you can configure how the packaging |
| 4047 | happens, which changes the way you build them. You can also modify the |
| 4048 | filesystem itself or select a different filesystem. |
| 4049 | |
| 4050 | First, find out what is hogging your root filesystem by running the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 4051 | ``dirsize.py`` script from your root directory:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4052 | |
| 4053 | $ cd root-directory-of-image |
| 4054 | $ dirsize.py 100000 > dirsize-100k.log |
| 4055 | $ cat dirsize-100k.log |
| 4056 | |
| 4057 | You can apply a filter to the script to ignore files |
| 4058 | under a certain size. The previous example filters out any files below |
| 4059 | 100 Kbytes. The sizes reported by the tool are uncompressed, and thus |
| 4060 | will be smaller by a relatively constant factor in a compressed root |
| 4061 | filesystem. When you examine your log file, you can focus on areas of |
| 4062 | the root filesystem that take up large amounts of memory. |
| 4063 | |
| 4064 | You need to be sure that what you eliminate does not cripple the |
| 4065 | functionality you need. One way to see how packages relate to each other |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 4066 | is by using the Dependency Explorer UI with the BitBake command:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4067 | |
| 4068 | $ cd image-directory |
| 4069 | $ bitbake -u taskexp -g image |
| 4070 | |
| 4071 | Use the interface to |
| 4072 | select potential packages you wish to eliminate and see their dependency |
| 4073 | relationships. |
| 4074 | |
| 4075 | When deciding how to reduce the size, get rid of packages that result in |
| 4076 | minimal impact on the feature set. For example, you might not need a VGA |
| 4077 | display. Or, you might be able to get by with ``devtmpfs`` and ``mdev`` |
| 4078 | instead of ``udev``. |
| 4079 | |
| 4080 | Use your ``local.conf`` file to make changes. For example, to eliminate |
| 4081 | ``udev`` and ``glib``, set the following in the local configuration |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 4082 | file:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4083 | |
| 4084 | VIRTUAL-RUNTIME_dev_manager = "" |
| 4085 | |
| 4086 | Finally, you should consider exactly the type of root filesystem you |
| 4087 | need to meet your needs while also reducing its size. For example, |
| 4088 | consider ``cramfs``, ``squashfs``, ``ubifs``, ``ext2``, or an |
| 4089 | ``initramfs`` using ``initramfs``. Be aware that ``ext3`` requires a 1 |
| 4090 | Mbyte journal. If you are okay with running read-only, you do not need |
| 4091 | this journal. |
| 4092 | |
| 4093 | .. note:: |
| 4094 | |
| 4095 | After each round of elimination, you need to rebuild your system and |
| 4096 | then use the tools to see the effects of your reductions. |
| 4097 | |
| 4098 | Trim the Kernel |
| 4099 | ~~~~~~~~~~~~~~~ |
| 4100 | |
| 4101 | The kernel is built by including policies for hardware-independent |
| 4102 | aspects. What subsystems do you enable? For what architecture are you |
| 4103 | building? Which drivers do you build by default? |
| 4104 | |
| 4105 | .. note:: |
| 4106 | |
| 4107 | You can modify the kernel source if you want to help with boot time. |
| 4108 | |
| 4109 | Run the ``ksize.py`` script from the top-level Linux build directory to |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 4110 | get an idea of what is making up the kernel:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4111 | |
| 4112 | $ cd top-level-linux-build-directory |
| 4113 | $ ksize.py > ksize.log |
| 4114 | $ cat ksize.log |
| 4115 | |
| 4116 | When you examine the log, you will see how much space is taken up with |
| 4117 | the built-in ``.o`` files for drivers, networking, core kernel files, |
| 4118 | filesystem, sound, and so forth. The sizes reported by the tool are |
| 4119 | uncompressed, and thus will be smaller by a relatively constant factor |
| 4120 | in a compressed kernel image. Look to reduce the areas that are large |
| 4121 | and taking up around the "90% rule." |
| 4122 | |
| 4123 | To examine, or drill down, into any particular area, use the ``-d`` |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 4124 | option with the script:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4125 | |
| 4126 | $ ksize.py -d > ksize.log |
| 4127 | |
| 4128 | Using this option |
| 4129 | breaks out the individual file information for each area of the kernel |
| 4130 | (e.g. drivers, networking, and so forth). |
| 4131 | |
| 4132 | Use your log file to see what you can eliminate from the kernel based on |
| 4133 | features you can let go. For example, if you are not going to need |
| 4134 | sound, you do not need any drivers that support sound. |
| 4135 | |
| 4136 | After figuring out what to eliminate, you need to reconfigure the kernel |
| 4137 | to reflect those changes during the next build. You could run |
| 4138 | ``menuconfig`` and make all your changes at once. However, that makes it |
| 4139 | difficult to see the effects of your individual eliminations and also |
| 4140 | makes it difficult to replicate the changes for perhaps another target |
| 4141 | device. A better method is to start with no configurations using |
| 4142 | ``allnoconfig``, create configuration fragments for individual changes, |
| 4143 | and then manage the fragments into a single configuration file using |
| 4144 | ``merge_config.sh``. The tool makes it easy for you to iterate using the |
| 4145 | configuration change and build cycle. |
| 4146 | |
| 4147 | Each time you make configuration changes, you need to rebuild the kernel |
| 4148 | and check to see what impact your changes had on the overall size. |
| 4149 | |
| 4150 | Remove Package Management Requirements |
| 4151 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 4152 | |
| 4153 | Packaging requirements add size to the image. One way to reduce the size |
| 4154 | of the image is to remove all the packaging requirements from the image. |
| 4155 | This reduction includes both removing the package manager and its unique |
| 4156 | dependencies as well as removing the package management data itself. |
| 4157 | |
| 4158 | To eliminate all the packaging requirements for an image, be sure that |
| 4159 | "package-management" is not part of your |
| 4160 | :term:`IMAGE_FEATURES` |
| 4161 | statement for the image. When you remove this feature, you are removing |
| 4162 | the package manager as well as its dependencies from the root |
| 4163 | filesystem. |
| 4164 | |
| 4165 | Look for Other Ways to Minimize Size |
| 4166 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 4167 | |
| 4168 | Depending on your particular circumstances, other areas that you can |
| 4169 | trim likely exist. The key to finding these areas is through tools and |
| 4170 | methods described here combined with experimentation and iteration. Here |
| 4171 | are a couple of areas to experiment with: |
| 4172 | |
| 4173 | - ``glibc``: In general, follow this process: |
| 4174 | |
| 4175 | 1. Remove ``glibc`` features from |
| 4176 | :term:`DISTRO_FEATURES` |
| 4177 | that you think you do not need. |
| 4178 | |
| 4179 | 2. Build your distribution. |
| 4180 | |
| 4181 | 3. If the build fails due to missing symbols in a package, determine |
| 4182 | if you can reconfigure the package to not need those features. For |
| 4183 | example, change the configuration to not support wide character |
| 4184 | support as is done for ``ncurses``. Or, if support for those |
| 4185 | characters is needed, determine what ``glibc`` features provide |
| 4186 | the support and restore the configuration. |
| 4187 | |
| 4188 | 4. Rebuild and repeat the process. |
| 4189 | |
| 4190 | - ``busybox``: For BusyBox, use a process similar as described for |
| 4191 | ``glibc``. A difference is you will need to boot the resulting system |
| 4192 | to see if you are able to do everything you expect from the running |
| 4193 | system. You need to be sure to integrate configuration fragments into |
| 4194 | Busybox because BusyBox handles its own core features and then allows |
| 4195 | you to add configuration fragments on top. |
| 4196 | |
| 4197 | Iterate on the Process |
| 4198 | ~~~~~~~~~~~~~~~~~~~~~~ |
| 4199 | |
| 4200 | If you have not reached your goals on system size, you need to iterate |
| 4201 | on the process. The process is the same. Use the tools and see just what |
| 4202 | is taking up 90% of the root filesystem and the kernel. Decide what you |
| 4203 | can eliminate without limiting your device beyond what you need. |
| 4204 | |
| 4205 | Depending on your system, a good place to look might be Busybox, which |
| 4206 | provides a stripped down version of Unix tools in a single, executable |
| 4207 | file. You might be able to drop virtual terminal services or perhaps |
| 4208 | ipv6. |
| 4209 | |
| 4210 | Building Images for More than One Machine |
| 4211 | ----------------------------------------- |
| 4212 | |
| 4213 | A common scenario developers face is creating images for several |
| 4214 | different machines that use the same software environment. In this |
| 4215 | situation, it is tempting to set the tunings and optimization flags for |
| 4216 | each build specifically for the targeted hardware (i.e. "maxing out" the |
| 4217 | tunings). Doing so can considerably add to build times and package feed |
| 4218 | maintenance collectively for the machines. For example, selecting tunes |
| 4219 | that are extremely specific to a CPU core used in a system might enable |
| 4220 | some micro optimizations in GCC for that particular system but would |
| 4221 | otherwise not gain you much of a performance difference across the other |
| 4222 | systems as compared to using a more general tuning across all the builds |
| 4223 | (e.g. setting :term:`DEFAULTTUNE` |
| 4224 | specifically for each machine's build). Rather than "max out" each |
| 4225 | build's tunings, you can take steps that cause the OpenEmbedded build |
| 4226 | system to reuse software across the various machines where it makes |
| 4227 | sense. |
| 4228 | |
| 4229 | If build speed and package feed maintenance are considerations, you |
| 4230 | should consider the points in this section that can help you optimize |
| 4231 | your tunings to best consider build times and package feed maintenance. |
| 4232 | |
| 4233 | - *Share the Build Directory:* If at all possible, share the |
| 4234 | :term:`TMPDIR` across builds. The |
| 4235 | Yocto Project supports switching between different |
| 4236 | :term:`MACHINE` values in the same |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 4237 | :term:`TMPDIR`. This practice is well supported and regularly used by |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4238 | developers when building for multiple machines. When you use the same |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 4239 | :term:`TMPDIR` for multiple machine builds, the OpenEmbedded build system |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4240 | can reuse the existing native and often cross-recipes for multiple |
| 4241 | machines. Thus, build time decreases. |
| 4242 | |
| 4243 | .. note:: |
| 4244 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 4245 | If :term:`DISTRO` settings change or fundamental configuration settings |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 4246 | such as the filesystem layout, you need to work with a clean :term:`TMPDIR`. |
| 4247 | Sharing :term:`TMPDIR` under these circumstances might work but since it is |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 4248 | not guaranteed, you should use a clean :term:`TMPDIR`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4249 | |
| 4250 | - *Enable the Appropriate Package Architecture:* By default, the |
| 4251 | OpenEmbedded build system enables three levels of package |
| 4252 | architectures: "all", "tune" or "package", and "machine". Any given |
| 4253 | recipe usually selects one of these package architectures (types) for |
| 4254 | its output. Depending for what a given recipe creates packages, |
| 4255 | making sure you enable the appropriate package architecture can |
| 4256 | directly impact the build time. |
| 4257 | |
| 4258 | A recipe that just generates scripts can enable "all" architecture |
| 4259 | because there are no binaries to build. To specifically enable "all" |
| 4260 | architecture, be sure your recipe inherits the |
| 4261 | :ref:`allarch <ref-classes-allarch>` class. |
| 4262 | This class is useful for "all" architectures because it configures |
| 4263 | many variables so packages can be used across multiple architectures. |
| 4264 | |
| 4265 | If your recipe needs to generate packages that are machine-specific |
| 4266 | or when one of the build or runtime dependencies is already |
| 4267 | machine-architecture dependent, which makes your recipe also |
| 4268 | machine-architecture dependent, make sure your recipe enables the |
| 4269 | "machine" package architecture through the |
| 4270 | :term:`MACHINE_ARCH` |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 4271 | variable:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4272 | |
| 4273 | PACKAGE_ARCH = "${MACHINE_ARCH}" |
| 4274 | |
| 4275 | When you do not |
| 4276 | specifically enable a package architecture through the |
| 4277 | :term:`PACKAGE_ARCH`, The |
| 4278 | OpenEmbedded build system defaults to the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 4279 | :term:`TUNE_PKGARCH` setting:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4280 | |
| 4281 | PACKAGE_ARCH = "${TUNE_PKGARCH}" |
| 4282 | |
| 4283 | - *Choose a Generic Tuning File if Possible:* Some tunes are more |
| 4284 | generic and can run on multiple targets (e.g. an ``armv5`` set of |
| 4285 | packages could run on ``armv6`` and ``armv7`` processors in most |
| 4286 | cases). Similarly, ``i486`` binaries could work on ``i586`` and |
| 4287 | higher processors. You should realize, however, that advances on |
| 4288 | newer processor versions would not be used. |
| 4289 | |
| 4290 | If you select the same tune for several different machines, the |
| 4291 | OpenEmbedded build system reuses software previously built, thus |
| 4292 | speeding up the overall build time. Realize that even though a new |
| 4293 | sysroot for each machine is generated, the software is not recompiled |
| 4294 | and only one package feed exists. |
| 4295 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 4296 | - *Manage Granular Level Packaging:* Sometimes there are cases where |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4297 | injecting another level of package architecture beyond the three |
| 4298 | higher levels noted earlier can be useful. For example, consider how |
| 4299 | NXP (formerly Freescale) allows for the easy reuse of binary packages |
| 4300 | in their layer |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 4301 | :yocto_git:`meta-freescale </meta-freescale/>`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4302 | In this example, the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 4303 | :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] | 4304 | class shares GPU packages for i.MX53 boards because all boards share |
| 4305 | the AMD GPU. The i.MX6-based boards can do the same because all |
| 4306 | boards share the Vivante GPU. This class inspects the BitBake |
| 4307 | datastore to identify if the package provides or depends on one of |
| 4308 | the sub-architecture values. If so, the class sets the |
| 4309 | :term:`PACKAGE_ARCH` value |
| 4310 | based on the ``MACHINE_SUBARCH`` value. If the package does not |
| 4311 | provide or depend on one of the sub-architecture values but it |
| 4312 | matches a value in the machine-specific filter, it sets |
| 4313 | :term:`MACHINE_ARCH`. This |
| 4314 | behavior reduces the number of packages built and saves build time by |
| 4315 | reusing binaries. |
| 4316 | |
| 4317 | - *Use Tools to Debug Issues:* Sometimes you can run into situations |
| 4318 | where software is being rebuilt when you think it should not be. For |
| 4319 | example, the OpenEmbedded build system might not be using shared |
| 4320 | state between machines when you think it should be. These types of |
| 4321 | situations are usually due to references to machine-specific |
| 4322 | variables such as :term:`MACHINE`, |
| 4323 | :term:`SERIAL_CONSOLES`, |
| 4324 | :term:`XSERVER`, |
| 4325 | :term:`MACHINE_FEATURES`, |
| 4326 | and so forth in code that is supposed to only be tune-specific or |
| 4327 | when the recipe depends |
| 4328 | (:term:`DEPENDS`, |
| 4329 | :term:`RDEPENDS`, |
| 4330 | :term:`RRECOMMENDS`, |
| 4331 | :term:`RSUGGESTS`, and so forth) |
| 4332 | on some other recipe that already has |
| 4333 | :term:`PACKAGE_ARCH` defined |
| 4334 | as "${MACHINE_ARCH}". |
| 4335 | |
| 4336 | .. note:: |
| 4337 | |
| 4338 | Patches to fix any issues identified are most welcome as these |
| 4339 | issues occasionally do occur. |
| 4340 | |
| 4341 | For such cases, you can use some tools to help you sort out the |
| 4342 | situation: |
| 4343 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 4344 | - ``state-diff-machines.sh``*:* You can find this tool in the |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4345 | ``scripts`` directory of the Source Repositories. See the comments |
| 4346 | in the script for information on how to use the tool. |
| 4347 | |
| 4348 | - *BitBake's "-S printdiff" Option:* Using this option causes |
| 4349 | BitBake to try to establish the closest signature match it can |
| 4350 | (e.g. in the shared state cache) and then run ``bitbake-diffsigs`` |
| 4351 | over the matches to determine the stamps and delta where these two |
| 4352 | stamp trees diverge. |
| 4353 | |
| 4354 | Building Software from an External Source |
| 4355 | ----------------------------------------- |
| 4356 | |
| 4357 | By default, the OpenEmbedded build system uses the |
| 4358 | :term:`Build Directory` when building source |
| 4359 | code. The build process involves fetching the source files, unpacking |
| 4360 | them, and then patching them if necessary before the build takes place. |
| 4361 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 4362 | There are situations where you might want to build software from source |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4363 | files that are external to and thus outside of the OpenEmbedded build |
| 4364 | system. For example, suppose you have a project that includes a new BSP |
| 4365 | with a heavily customized kernel. And, you want to minimize exposing the |
| 4366 | build system to the development team so that they can focus on their |
| 4367 | project and maintain everyone's workflow as much as possible. In this |
| 4368 | case, you want a kernel source directory on the development machine |
| 4369 | where the development occurs. You want the recipe's |
| 4370 | :term:`SRC_URI` variable to point to |
| 4371 | the external directory and use it as is, not copy it. |
| 4372 | |
| 4373 | To build from software that comes from an external source, all you need |
| 4374 | to do is inherit the |
| 4375 | :ref:`externalsrc <ref-classes-externalsrc>` class |
| 4376 | and then set the |
| 4377 | :term:`EXTERNALSRC` variable to |
| 4378 | point to your external source code. Here are the statements to put in |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 4379 | your ``local.conf`` file:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4380 | |
| 4381 | INHERIT += "externalsrc" |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 4382 | EXTERNALSRC:pn-myrecipe = "path-to-your-source-tree" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4383 | |
| 4384 | This next example shows how to accomplish the same thing by setting |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 4385 | :term:`EXTERNALSRC` in the recipe itself or in the recipe's append file:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4386 | |
| 4387 | EXTERNALSRC = "path" |
| 4388 | EXTERNALSRC_BUILD = "path" |
| 4389 | |
| 4390 | .. note:: |
| 4391 | |
| 4392 | In order for these settings to take effect, you must globally or |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 4393 | locally inherit the :ref:`externalsrc <ref-classes-externalsrc>` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4394 | class. |
| 4395 | |
| 4396 | By default, ``externalsrc.bbclass`` builds the source code in a |
| 4397 | directory separate from the external source directory as specified by |
| 4398 | :term:`EXTERNALSRC`. If you need |
| 4399 | to have the source built in the same directory in which it resides, or |
| 4400 | some other nominated directory, you can set |
| 4401 | :term:`EXTERNALSRC_BUILD` |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 4402 | to point to that directory:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4403 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 4404 | EXTERNALSRC_BUILD:pn-myrecipe = "path-to-your-source-tree" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4405 | |
| 4406 | Replicating a Build Offline |
| 4407 | --------------------------- |
| 4408 | |
| 4409 | It can be useful to take a "snapshot" of upstream sources used in a |
| 4410 | build and then use that "snapshot" later to replicate the build offline. |
| 4411 | To do so, you need to first prepare and populate your downloads |
| 4412 | directory your "snapshot" of files. Once your downloads directory is |
| 4413 | ready, you can use it at any time and from any machine to replicate your |
| 4414 | build. |
| 4415 | |
| 4416 | Follow these steps to populate your Downloads directory: |
| 4417 | |
| 4418 | 1. *Create a Clean Downloads Directory:* Start with an empty downloads |
| 4419 | directory (:term:`DL_DIR`). You |
| 4420 | start with an empty downloads directory by either removing the files |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 4421 | in the existing directory or by setting :term:`DL_DIR` to point to either |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4422 | an empty location or one that does not yet exist. |
| 4423 | |
| 4424 | 2. *Generate Tarballs of the Source Git Repositories:* Edit your |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 4425 | ``local.conf`` configuration file as follows:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4426 | |
| 4427 | DL_DIR = "/home/your-download-dir/" |
| 4428 | BB_GENERATE_MIRROR_TARBALLS = "1" |
| 4429 | |
| 4430 | During |
| 4431 | the fetch process in the next step, BitBake gathers the source files |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 4432 | and creates tarballs in the directory pointed to by :term:`DL_DIR`. See |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4433 | the |
| 4434 | :term:`BB_GENERATE_MIRROR_TARBALLS` |
| 4435 | variable for more information. |
| 4436 | |
| 4437 | 3. *Populate Your Downloads Directory Without Building:* Use BitBake to |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 4438 | fetch your sources but inhibit the build:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4439 | |
| 4440 | $ bitbake target --runonly=fetch |
| 4441 | |
| 4442 | The downloads directory (i.e. ``${DL_DIR}``) now has |
| 4443 | a "snapshot" of the source files in the form of tarballs, which can |
| 4444 | be used for the build. |
| 4445 | |
| 4446 | 4. *Optionally Remove Any Git or other SCM Subdirectories From the |
| 4447 | Downloads Directory:* If you want, you can clean up your downloads |
| 4448 | directory by removing any Git or other Source Control Management |
| 4449 | (SCM) subdirectories such as ``${DL_DIR}/git2/*``. The tarballs |
| 4450 | already contain these subdirectories. |
| 4451 | |
| 4452 | Once your downloads directory has everything it needs regarding source |
| 4453 | files, you can create your "own-mirror" and build your target. |
| 4454 | Understand that you can use the files to build the target offline from |
| 4455 | any machine and at any time. |
| 4456 | |
| 4457 | Follow these steps to build your target using the files in the downloads |
| 4458 | directory: |
| 4459 | |
| 4460 | 1. *Using Local Files Only:* Inside your ``local.conf`` file, add the |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 4461 | :term:`SOURCE_MIRROR_URL` variable, inherit the |
| 4462 | :ref:`own-mirrors <ref-classes-own-mirrors>` class, and use the |
| 4463 | :term:`BB_NO_NETWORK` variable to your ``local.conf``. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4464 | :: |
| 4465 | |
| 4466 | SOURCE_MIRROR_URL ?= "file:///home/your-download-dir/" |
| 4467 | INHERIT += "own-mirrors" |
| 4468 | BB_NO_NETWORK = "1" |
| 4469 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 4470 | The :term:`SOURCE_MIRROR_URL` and :ref:`own-mirrors <ref-classes-own-mirrors>` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4471 | class set up the system to use the downloads directory as your "own |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 4472 | mirror". Using the :term:`BB_NO_NETWORK` variable makes sure that |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4473 | BitBake's fetching process in step 3 stays local, which means files |
| 4474 | from your "own-mirror" are used. |
| 4475 | |
| 4476 | 2. *Start With a Clean Build:* You can start with a clean build by |
| 4477 | removing the |
| 4478 | ``${``\ :term:`TMPDIR`\ ``}`` |
| 4479 | directory or using a new :term:`Build Directory`. |
| 4480 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 4481 | 3. *Build Your Target:* Use BitBake to build your target:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4482 | |
| 4483 | $ bitbake target |
| 4484 | |
| 4485 | The build completes using the known local "snapshot" of source |
| 4486 | files from your mirror. The resulting tarballs for your "snapshot" of |
| 4487 | source files are in the downloads directory. |
| 4488 | |
| 4489 | .. note:: |
| 4490 | |
| 4491 | The offline build does not work if recipes attempt to find the |
| 4492 | latest version of software by setting |
| 4493 | :term:`SRCREV` to |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 4494 | ``${``\ :term:`AUTOREV`\ ``}``:: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 4495 | |
| 4496 | SRCREV = "${AUTOREV}" |
| 4497 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 4498 | When a recipe sets :term:`SRCREV` to |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 4499 | ``${``\ :term:`AUTOREV`\ ``}``, the build system accesses the network in an |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4500 | attempt to determine the latest version of software from the SCM. |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 4501 | Typically, recipes that use :term:`AUTOREV` are custom or modified |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4502 | recipes. Recipes that reside in public repositories usually do not |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 4503 | use :term:`AUTOREV`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4504 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 4505 | If you do have recipes that use :term:`AUTOREV`, you can take steps to |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4506 | still use the recipes in an offline build. Do the following: |
| 4507 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 4508 | 1. Use a configuration generated by enabling :ref:`build |
| 4509 | history <dev-manual/common-tasks:maintaining build output quality>`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4510 | |
| 4511 | 2. Use the ``buildhistory-collect-srcrevs`` command to collect the |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 4512 | stored :term:`SRCREV` values from the build's history. For more |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 4513 | information on collecting these values, see the |
| 4514 | ":ref:`dev-manual/common-tasks:build history package information`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4515 | section. |
| 4516 | |
| 4517 | 3. Once you have the correct source revisions, you can modify |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 4518 | those recipes to set :term:`SRCREV` to specific versions of the |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4519 | software. |
| 4520 | |
| 4521 | Speeding Up a Build |
| 4522 | =================== |
| 4523 | |
| 4524 | Build time can be an issue. By default, the build system uses simple |
| 4525 | controls to try and maximize build efficiency. In general, the default |
| 4526 | settings for all the following variables result in the most efficient |
| 4527 | build times when dealing with single socket systems (i.e. a single CPU). |
| 4528 | If you have multiple CPUs, you might try increasing the default values |
| 4529 | to gain more speed. See the descriptions in the glossary for each |
| 4530 | variable for more information: |
| 4531 | |
| 4532 | - :term:`BB_NUMBER_THREADS`: |
| 4533 | The maximum number of threads BitBake simultaneously executes. |
| 4534 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 4535 | - :term:`BB_NUMBER_PARSE_THREADS`: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4536 | The number of threads BitBake uses during parsing. |
| 4537 | |
| 4538 | - :term:`PARALLEL_MAKE`: Extra |
| 4539 | options passed to the ``make`` command during the |
| 4540 | :ref:`ref-tasks-compile` task in |
| 4541 | order to specify parallel compilation on the local build host. |
| 4542 | |
| 4543 | - :term:`PARALLEL_MAKEINST`: |
| 4544 | Extra options passed to the ``make`` command during the |
| 4545 | :ref:`ref-tasks-install` task in |
| 4546 | order to specify parallel installation on the local build host. |
| 4547 | |
| 4548 | As mentioned, these variables all scale to the number of processor cores |
| 4549 | available on the build system. For single socket systems, this |
| 4550 | auto-scaling ensures that the build system fundamentally takes advantage |
| 4551 | of potential parallel operations during the build based on the build |
| 4552 | machine's capabilities. |
| 4553 | |
| 4554 | Following are additional factors that can affect build speed: |
| 4555 | |
| 4556 | - File system type: The file system type that the build is being |
| 4557 | performed on can also influence performance. Using ``ext4`` is |
| 4558 | recommended as compared to ``ext2`` and ``ext3`` due to ``ext4`` |
| 4559 | improved features such as extents. |
| 4560 | |
| 4561 | - Disabling the updating of access time using ``noatime``: The |
| 4562 | ``noatime`` mount option prevents the build system from updating file |
| 4563 | and directory access times. |
| 4564 | |
| 4565 | - Setting a longer commit: Using the "commit=" mount option increases |
| 4566 | the interval in seconds between disk cache writes. Changing this |
| 4567 | interval from the five second default to something longer increases |
| 4568 | the risk of data loss but decreases the need to write to the disk, |
| 4569 | thus increasing the build performance. |
| 4570 | |
| 4571 | - Choosing the packaging backend: Of the available packaging backends, |
| 4572 | IPK is the fastest. Additionally, selecting a singular packaging |
| 4573 | backend also helps. |
| 4574 | |
| 4575 | - Using ``tmpfs`` for :term:`TMPDIR` |
| 4576 | as a temporary file system: While this can help speed up the build, |
| 4577 | the benefits are limited due to the compiler using ``-pipe``. The |
| 4578 | build system goes to some lengths to avoid ``sync()`` calls into the |
| 4579 | file system on the principle that if there was a significant failure, |
| 4580 | the :term:`Build Directory` |
| 4581 | contents could easily be rebuilt. |
| 4582 | |
| 4583 | - Inheriting the |
| 4584 | :ref:`rm_work <ref-classes-rm-work>` class: |
| 4585 | Inheriting this class has shown to speed up builds due to |
| 4586 | significantly lower amounts of data stored in the data cache as well |
| 4587 | as on disk. Inheriting this class also makes cleanup of |
| 4588 | :term:`TMPDIR` faster, at the |
| 4589 | expense of being easily able to dive into the source code. File |
| 4590 | system maintainers have recommended that the fastest way to clean up |
| 4591 | large numbers of files is to reformat partitions rather than delete |
| 4592 | files due to the linear nature of partitions. This, of course, |
| 4593 | assumes you structure the disk partitions and file systems in a way |
| 4594 | that this is practical. |
| 4595 | |
| 4596 | Aside from the previous list, you should keep some trade offs in mind |
| 4597 | that can help you speed up the build: |
| 4598 | |
| 4599 | - Remove items from |
| 4600 | :term:`DISTRO_FEATURES` |
| 4601 | that you might not need. |
| 4602 | |
| 4603 | - Exclude debug symbols and other debug information: If you do not need |
| 4604 | these symbols and other debug information, disabling the ``*-dbg`` |
| 4605 | package generation can speed up the build. You can disable this |
| 4606 | generation by setting the |
| 4607 | :term:`INHIBIT_PACKAGE_DEBUG_SPLIT` |
| 4608 | variable to "1". |
| 4609 | |
| 4610 | - Disable static library generation for recipes derived from |
| 4611 | ``autoconf`` or ``libtool``: Following is an example showing how to |
| 4612 | disable static libraries and still provide an override to handle |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 4613 | exceptions:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4614 | |
| 4615 | STATICLIBCONF = "--disable-static" |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 4616 | STATICLIBCONF:sqlite3-native = "" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4617 | EXTRA_OECONF += "${STATICLIBCONF}" |
| 4618 | |
| 4619 | .. note:: |
| 4620 | |
| 4621 | - Some recipes need static libraries in order to work correctly |
| 4622 | (e.g. ``pseudo-native`` needs ``sqlite3-native``). Overrides, |
| 4623 | as in the previous example, account for these kinds of |
| 4624 | exceptions. |
| 4625 | |
| 4626 | - Some packages have packaging code that assumes the presence of |
| 4627 | the static libraries. If so, you might need to exclude them as |
| 4628 | well. |
| 4629 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4630 | Working With Libraries |
| 4631 | ====================== |
| 4632 | |
| 4633 | Libraries are an integral part of your system. This section describes |
| 4634 | some common practices you might find helpful when working with libraries |
| 4635 | to build your system: |
| 4636 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 4637 | - :ref:`How to include static library files |
| 4638 | <dev-manual/common-tasks:including static library files>` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4639 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 4640 | - :ref:`How to use the Multilib feature to combine multiple versions of |
| 4641 | library files into a single image |
| 4642 | <dev-manual/common-tasks:combining multiple versions of library files into one image>` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4643 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 4644 | - :ref:`How to install multiple versions of the same library in parallel on |
| 4645 | the same system |
| 4646 | <dev-manual/common-tasks:installing multiple versions of the same library>` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4647 | |
| 4648 | Including Static Library Files |
| 4649 | ------------------------------ |
| 4650 | |
| 4651 | If you are building a library and the library offers static linking, you |
| 4652 | can control which static library files (``*.a`` files) get included in |
| 4653 | the built library. |
| 4654 | |
| 4655 | The :term:`PACKAGES` and |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 4656 | :term:`FILES:* <FILES>` variables in the |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4657 | ``meta/conf/bitbake.conf`` configuration file define how files installed |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 4658 | by the ``do_install`` task are packaged. By default, the :term:`PACKAGES` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4659 | variable includes ``${PN}-staticdev``, which represents all static |
| 4660 | library files. |
| 4661 | |
| 4662 | .. note:: |
| 4663 | |
| 4664 | Some previously released versions of the Yocto Project defined the |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 4665 | static library files through ``${PN}-dev``. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4666 | |
| 4667 | Following is part of the BitBake configuration file, where you can see |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 4668 | how the static library files are defined:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4669 | |
| 4670 | PACKAGE_BEFORE_PN ?= "" |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 4671 | PACKAGES = "${PN}-src ${PN}-dbg ${PN}-staticdev ${PN}-dev ${PN}-doc ${PN}-locale ${PACKAGE_BEFORE_PN} ${PN}" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4672 | PACKAGES_DYNAMIC = "^${PN}-locale-.*" |
| 4673 | FILES = "" |
| 4674 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 4675 | FILES:${PN} = "${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*${SOLIBS} \ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4676 | ${sysconfdir} ${sharedstatedir} ${localstatedir} \ |
| 4677 | ${base_bindir}/* ${base_sbindir}/* \ |
| 4678 | ${base_libdir}/*${SOLIBS} \ |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 4679 | ${base_prefix}/lib/udev ${prefix}/lib/udev \ |
| 4680 | ${base_libdir}/udev ${libdir}/udev \ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4681 | ${datadir}/${BPN} ${libdir}/${BPN}/* \ |
| 4682 | ${datadir}/pixmaps ${datadir}/applications \ |
| 4683 | ${datadir}/idl ${datadir}/omf ${datadir}/sounds \ |
| 4684 | ${libdir}/bonobo/servers" |
| 4685 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 4686 | FILES:${PN}-bin = "${bindir}/* ${sbindir}/*" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4687 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 4688 | FILES:${PN}-doc = "${docdir} ${mandir} ${infodir} ${datadir}/gtk-doc \ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4689 | ${datadir}/gnome/help" |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 4690 | SECTION:${PN}-doc = "doc" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4691 | |
| 4692 | FILES_SOLIBSDEV ?= "${base_libdir}/lib*${SOLIBSDEV} ${libdir}/lib*${SOLIBSDEV}" |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 4693 | FILES:${PN}-dev = "${includedir} ${FILES_SOLIBSDEV} ${libdir}/*.la \ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4694 | ${libdir}/*.o ${libdir}/pkgconfig ${datadir}/pkgconfig \ |
| 4695 | ${datadir}/aclocal ${base_libdir}/*.o \ |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 4696 | ${libdir}/${BPN}/*.la ${base_libdir}/*.la \ |
| 4697 | ${libdir}/cmake ${datadir}/cmake" |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 4698 | SECTION:${PN}-dev = "devel" |
| 4699 | ALLOW_EMPTY:${PN}-dev = "1" |
| 4700 | RDEPENDS:${PN}-dev = "${PN} (= ${EXTENDPKGV})" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4701 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 4702 | FILES:${PN}-staticdev = "${libdir}/*.a ${base_libdir}/*.a ${libdir}/${BPN}/*.a" |
| 4703 | SECTION:${PN}-staticdev = "devel" |
| 4704 | RDEPENDS:${PN}-staticdev = "${PN}-dev (= ${EXTENDPKGV})" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4705 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4706 | Combining Multiple Versions of Library Files into One Image |
| 4707 | ----------------------------------------------------------- |
| 4708 | |
| 4709 | The build system offers the ability to build libraries with different |
| 4710 | target optimizations or architecture formats and combine these together |
| 4711 | into one system image. You can link different binaries in the image |
| 4712 | against the different libraries as needed for specific use cases. This |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 4713 | feature is called "Multilib". |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4714 | |
| 4715 | An example would be where you have most of a system compiled in 32-bit |
| 4716 | mode using 32-bit libraries, but you have something large, like a |
| 4717 | database engine, that needs to be a 64-bit application and uses 64-bit |
| 4718 | libraries. Multilib allows you to get the best of both 32-bit and 64-bit |
| 4719 | libraries. |
| 4720 | |
| 4721 | While the Multilib feature is most commonly used for 32 and 64-bit |
| 4722 | differences, the approach the build system uses facilitates different |
| 4723 | target optimizations. You could compile some binaries to use one set of |
| 4724 | libraries and other binaries to use a different set of libraries. The |
| 4725 | libraries could differ in architecture, compiler options, or other |
| 4726 | optimizations. |
| 4727 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 4728 | There are several examples in the ``meta-skeleton`` layer found in the |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4729 | :term:`Source Directory`: |
| 4730 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 4731 | - :oe_git:`conf/multilib-example.conf </openembedded-core/tree/meta-skeleton/conf/multilib-example.conf>` |
| 4732 | configuration file. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4733 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 4734 | - :oe_git:`conf/multilib-example2.conf </openembedded-core/tree/meta-skeleton/conf/multilib-example2.conf>` |
| 4735 | configuration file. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4736 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 4737 | - :oe_git:`recipes-multilib/images/core-image-multilib-example.bb </openembedded-core/tree/meta-skeleton/recipes-multilib/images/core-image-multilib-example.bb>` |
| 4738 | recipe |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4739 | |
| 4740 | Preparing to Use Multilib |
| 4741 | ~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 4742 | |
| 4743 | User-specific requirements drive the Multilib feature. Consequently, |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 4744 | there is no one "out-of-the-box" configuration that would |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4745 | meet your needs. |
| 4746 | |
| 4747 | In order to enable Multilib, you first need to ensure your recipe is |
| 4748 | extended to support multiple libraries. Many standard recipes are |
| 4749 | already extended and support multiple libraries. You can check in the |
| 4750 | ``meta/conf/multilib.conf`` configuration file in the |
| 4751 | :term:`Source Directory` to see how this is |
| 4752 | done using the |
| 4753 | :term:`BBCLASSEXTEND` variable. |
| 4754 | Eventually, all recipes will be covered and this list will not be |
| 4755 | needed. |
| 4756 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 4757 | For the most part, the :ref:`Multilib <ref-classes-multilib*>` |
| 4758 | class extension works automatically to |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4759 | extend the package name from ``${PN}`` to ``${MLPREFIX}${PN}``, where |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 4760 | :term:`MLPREFIX` is the particular multilib (e.g. "lib32-" or "lib64-"). |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4761 | Standard variables such as |
| 4762 | :term:`DEPENDS`, |
| 4763 | :term:`RDEPENDS`, |
| 4764 | :term:`RPROVIDES`, |
| 4765 | :term:`RRECOMMENDS`, |
| 4766 | :term:`PACKAGES`, and |
| 4767 | :term:`PACKAGES_DYNAMIC` are |
| 4768 | automatically extended by the system. If you are extending any manual |
| 4769 | code in the recipe, you can use the ``${MLPREFIX}`` variable to ensure |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 4770 | those names are extended correctly. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4771 | |
| 4772 | Using Multilib |
| 4773 | ~~~~~~~~~~~~~~ |
| 4774 | |
| 4775 | After you have set up the recipes, you need to define the actual |
| 4776 | combination of multiple libraries you want to build. You accomplish this |
| 4777 | through your ``local.conf`` configuration file in the |
| 4778 | :term:`Build Directory`. An example |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 4779 | configuration would be as follows:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4780 | |
| 4781 | MACHINE = "qemux86-64" |
| 4782 | require conf/multilib.conf |
| 4783 | MULTILIBS = "multilib:lib32" |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 4784 | DEFAULTTUNE:virtclass-multilib-lib32 = "x86" |
| 4785 | IMAGE_INSTALL:append = "lib32-glib-2.0" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4786 | |
| 4787 | This example enables an additional library named |
| 4788 | ``lib32`` alongside the normal target packages. When combining these |
| 4789 | "lib32" alternatives, the example uses "x86" for tuning. For information |
| 4790 | on this particular tuning, see |
| 4791 | ``meta/conf/machine/include/ia32/arch-ia32.inc``. |
| 4792 | |
| 4793 | The example then includes ``lib32-glib-2.0`` in all the images, which |
| 4794 | illustrates one method of including a multiple library dependency. You |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 4795 | can use a normal image build to include this dependency, for example:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4796 | |
| 4797 | $ bitbake core-image-sato |
| 4798 | |
| 4799 | You can also build Multilib packages |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 4800 | specifically with a command like this:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4801 | |
| 4802 | $ bitbake lib32-glib-2.0 |
| 4803 | |
| 4804 | Additional Implementation Details |
| 4805 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 4806 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 4807 | There are generic implementation details as well as details that are specific to |
| 4808 | package management systems. Following are implementation details |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4809 | that exist regardless of the package management system: |
| 4810 | |
| 4811 | - The typical convention used for the class extension code as used by |
| 4812 | Multilib assumes that all package names specified in |
| 4813 | :term:`PACKAGES` that contain |
| 4814 | ``${PN}`` have ``${PN}`` at the start of the name. When that |
| 4815 | convention is not followed and ``${PN}`` appears at the middle or the |
| 4816 | end of a name, problems occur. |
| 4817 | |
| 4818 | - The :term:`TARGET_VENDOR` |
| 4819 | value under Multilib will be extended to "-vendormlmultilib" (e.g. |
| 4820 | "-pokymllib32" for a "lib32" Multilib with Poky). The reason for this |
| 4821 | slightly unwieldy contraction is that any "-" characters in the |
| 4822 | vendor string presently break Autoconf's ``config.sub``, and other |
| 4823 | separators are problematic for different reasons. |
| 4824 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 4825 | Here are the implementation details for the RPM Package Management System: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4826 | |
| 4827 | - A unique architecture is defined for the Multilib packages, along |
| 4828 | with creating a unique deploy folder under ``tmp/deploy/rpm`` in the |
| 4829 | :term:`Build Directory`. For |
| 4830 | example, consider ``lib32`` in a ``qemux86-64`` image. The possible |
| 4831 | architectures in the system are "all", "qemux86_64", |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 4832 | "lib32:qemux86_64", and "lib32:x86". |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4833 | |
| 4834 | - The ``${MLPREFIX}`` variable is stripped from ``${PN}`` during RPM |
| 4835 | packaging. The naming for a normal RPM package and a Multilib RPM |
| 4836 | package in a ``qemux86-64`` system resolves to something similar to |
| 4837 | ``bash-4.1-r2.x86_64.rpm`` and ``bash-4.1.r2.lib32_x86.rpm``, |
| 4838 | respectively. |
| 4839 | |
| 4840 | - When installing a Multilib image, the RPM backend first installs the |
| 4841 | base image and then installs the Multilib libraries. |
| 4842 | |
| 4843 | - The build system relies on RPM to resolve the identical files in the |
| 4844 | two (or more) Multilib packages. |
| 4845 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 4846 | Here are the implementation details for the IPK Package Management System: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4847 | |
| 4848 | - The ``${MLPREFIX}`` is not stripped from ``${PN}`` during IPK |
| 4849 | packaging. The naming for a normal RPM package and a Multilib IPK |
| 4850 | package in a ``qemux86-64`` system resolves to something like |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 4851 | ``bash_4.1-r2.x86_64.ipk`` and ``lib32-bash_4.1-rw:x86.ipk``, |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4852 | respectively. |
| 4853 | |
| 4854 | - The IPK deploy folder is not modified with ``${MLPREFIX}`` because |
| 4855 | packages with and without the Multilib feature can exist in the same |
| 4856 | folder due to the ``${PN}`` differences. |
| 4857 | |
| 4858 | - IPK defines a sanity check for Multilib installation using certain |
| 4859 | rules for file comparison, overridden, etc. |
| 4860 | |
| 4861 | Installing Multiple Versions of the Same Library |
| 4862 | ------------------------------------------------ |
| 4863 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 4864 | There are be situations where you need to install and use multiple versions |
| 4865 | of the same library on the same system at the same time. This |
| 4866 | almost always happens when a library API changes and you have |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4867 | multiple pieces of software that depend on the separate versions of the |
| 4868 | library. To accommodate these situations, you can install multiple |
| 4869 | versions of the same library in parallel on the same system. |
| 4870 | |
| 4871 | The process is straightforward as long as the libraries use proper |
| 4872 | versioning. With properly versioned libraries, all you need to do to |
| 4873 | individually specify the libraries is create separate, appropriately |
| 4874 | named recipes where the :term:`PN` part of |
| 4875 | the name includes a portion that differentiates each library version |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 4876 | (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] | 4877 | single recipe that loads one version of a library (e.g. ``clutter``), |
| 4878 | you provide multiple recipes that result in different versions of the |
| 4879 | libraries you want. As an example, the following two recipes would allow |
| 4880 | the two separate versions of the ``clutter`` library to co-exist on the |
| 4881 | same system: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 4882 | |
| 4883 | .. code-block:: none |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4884 | |
| 4885 | clutter-1.6_1.6.20.bb |
| 4886 | clutter-1.8_1.8.4.bb |
| 4887 | |
| 4888 | Additionally, if |
| 4889 | you have other recipes that depend on a given library, you need to use |
| 4890 | the :term:`DEPENDS` variable to |
| 4891 | create the dependency. Continuing with the same example, if you want to |
| 4892 | have a recipe depend on the 1.8 version of the ``clutter`` library, use |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 4893 | the following in your recipe:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4894 | |
| 4895 | DEPENDS = "clutter-1.8" |
| 4896 | |
| 4897 | Using x32 psABI |
| 4898 | =============== |
| 4899 | |
| 4900 | x32 processor-specific Application Binary Interface (`x32 |
| 4901 | psABI <https://software.intel.com/en-us/node/628948>`__) is a native |
| 4902 | 32-bit processor-specific ABI for Intel 64 (x86-64) architectures. An |
| 4903 | ABI defines the calling conventions between functions in a processing |
| 4904 | environment. The interface determines what registers are used and what |
| 4905 | the sizes are for various C data types. |
| 4906 | |
| 4907 | Some processing environments prefer using 32-bit applications even when |
| 4908 | running on Intel 64-bit platforms. Consider the i386 psABI, which is a |
| 4909 | very old 32-bit ABI for Intel 64-bit platforms. The i386 psABI does not |
| 4910 | provide efficient use and access of the Intel 64-bit processor |
| 4911 | resources, leaving the system underutilized. Now consider the x86_64 |
| 4912 | psABI. This ABI is newer and uses 64-bits for data sizes and program |
| 4913 | pointers. The extra bits increase the footprint size of the programs, |
| 4914 | libraries, and also increases the memory and file system size |
| 4915 | requirements. Executing under the x32 psABI enables user programs to |
| 4916 | utilize CPU and system resources more efficiently while keeping the |
| 4917 | memory footprint of the applications low. Extra bits are used for |
| 4918 | registers but not for addressing mechanisms. |
| 4919 | |
| 4920 | The Yocto Project supports the final specifications of x32 psABI as |
| 4921 | follows: |
| 4922 | |
| 4923 | - You can create packages and images in x32 psABI format on x86_64 |
| 4924 | architecture targets. |
| 4925 | |
| 4926 | - You can successfully build recipes with the x32 toolchain. |
| 4927 | |
| 4928 | - You can create and boot ``core-image-minimal`` and |
| 4929 | ``core-image-sato`` images. |
| 4930 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 4931 | - There is RPM Package Manager (RPM) support for x32 binaries. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4932 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 4933 | - There is support for large images. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4934 | |
| 4935 | To use the x32 psABI, you need to edit your ``conf/local.conf`` |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 4936 | configuration file as follows:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4937 | |
| 4938 | MACHINE = "qemux86-64" |
| 4939 | DEFAULTTUNE = "x86-64-x32" |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 4940 | baselib = "${@d.getVar('BASE_LIB:tune-' + (d.getVar('DEFAULTTUNE') \ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4941 | or 'INVALID')) or 'lib'}" |
| 4942 | |
| 4943 | Once you have set |
| 4944 | up your configuration file, use BitBake to build an image that supports |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 4945 | the x32 psABI. Here is an example:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4946 | |
| 4947 | $ bitbake core-image-sato |
| 4948 | |
| 4949 | Enabling GObject Introspection Support |
| 4950 | ====================================== |
| 4951 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 4952 | `GObject introspection <https://gi.readthedocs.io/en/latest/>`__ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4953 | is the standard mechanism for accessing GObject-based software from |
| 4954 | runtime environments. GObject is a feature of the GLib library that |
| 4955 | provides an object framework for the GNOME desktop and related software. |
| 4956 | GObject Introspection adds information to GObject that allows objects |
| 4957 | created within it to be represented across different programming |
| 4958 | languages. If you want to construct GStreamer pipelines using Python, or |
| 4959 | control UPnP infrastructure using Javascript and GUPnP, GObject |
| 4960 | introspection is the only way to do it. |
| 4961 | |
| 4962 | This section describes the Yocto Project support for generating and |
| 4963 | packaging GObject introspection data. GObject introspection data is a |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 4964 | description of the API provided by libraries built on top of the GLib |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4965 | framework, and, in particular, that framework's GObject mechanism. |
| 4966 | GObject Introspection Repository (GIR) files go to ``-dev`` packages, |
| 4967 | ``typelib`` files go to main packages as they are packaged together with |
| 4968 | libraries that are introspected. |
| 4969 | |
| 4970 | The data is generated when building such a library, by linking the |
| 4971 | library with a small executable binary that asks the library to describe |
| 4972 | itself, and then executing the binary and processing its output. |
| 4973 | |
| 4974 | Generating this data in a cross-compilation environment is difficult |
| 4975 | because the library is produced for the target architecture, but its |
| 4976 | code needs to be executed on the build host. This problem is solved with |
| 4977 | the OpenEmbedded build system by running the code through QEMU, which |
| 4978 | allows precisely that. Unfortunately, QEMU does not always work |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 4979 | perfectly as mentioned in the ":ref:`dev-manual/common-tasks:known issues`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4980 | section. |
| 4981 | |
| 4982 | Enabling the Generation of Introspection Data |
| 4983 | --------------------------------------------- |
| 4984 | |
| 4985 | Enabling the generation of introspection data (GIR files) in your |
| 4986 | library package involves the following: |
| 4987 | |
| 4988 | 1. Inherit the |
| 4989 | :ref:`gobject-introspection <ref-classes-gobject-introspection>` |
| 4990 | class. |
| 4991 | |
| 4992 | 2. Make sure introspection is not disabled anywhere in the recipe or |
| 4993 | from anything the recipe includes. Also, make sure that |
| 4994 | "gobject-introspection-data" is not in |
| 4995 | :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED` |
| 4996 | and that "qemu-usermode" is not in |
| 4997 | :term:`MACHINE_FEATURES_BACKFILL_CONSIDERED`. |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 4998 | In either of these conditions, nothing will happen. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 4999 | |
| 5000 | 3. Try to build the recipe. If you encounter build errors that look like |
| 5001 | something is unable to find ``.so`` libraries, check where these |
| 5002 | libraries are located in the source tree and add the following to the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5003 | recipe:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5004 | |
| 5005 | GIR_EXTRA_LIBS_PATH = "${B}/something/.libs" |
| 5006 | |
| 5007 | .. note:: |
| 5008 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 5009 | See recipes in the ``oe-core`` repository that use that |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 5010 | :term:`GIR_EXTRA_LIBS_PATH` variable as an example. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5011 | |
| 5012 | 4. Look for any other errors, which probably mean that introspection |
| 5013 | support in a package is not entirely standard, and thus breaks down |
| 5014 | in a cross-compilation environment. For such cases, custom-made fixes |
| 5015 | are needed. A good place to ask and receive help in these cases is |
| 5016 | the :ref:`Yocto Project mailing |
| 5017 | lists <resources-mailinglist>`. |
| 5018 | |
| 5019 | .. note:: |
| 5020 | |
| 5021 | Using a library that no longer builds against the latest Yocto |
| 5022 | Project release and prints introspection related errors is a good |
| 5023 | candidate for the previous procedure. |
| 5024 | |
| 5025 | Disabling the Generation of Introspection Data |
| 5026 | ---------------------------------------------- |
| 5027 | |
| 5028 | You might find that you do not want to generate introspection data. Or, |
| 5029 | perhaps QEMU does not work on your build host and target architecture |
| 5030 | combination. If so, you can use either of the following methods to |
| 5031 | disable GIR file generations: |
| 5032 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5033 | - Add the following to your distro configuration:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5034 | |
| 5035 | DISTRO_FEATURES_BACKFILL_CONSIDERED = "gobject-introspection-data" |
| 5036 | |
| 5037 | Adding this statement disables generating introspection data using |
| 5038 | QEMU but will still enable building introspection tools and libraries |
| 5039 | (i.e. building them does not require the use of QEMU). |
| 5040 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5041 | - Add the following to your machine configuration:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5042 | |
| 5043 | MACHINE_FEATURES_BACKFILL_CONSIDERED = "qemu-usermode" |
| 5044 | |
| 5045 | Adding this statement disables the use of QEMU when building packages for your |
| 5046 | machine. Currently, this feature is used only by introspection |
| 5047 | recipes and has the same effect as the previously described option. |
| 5048 | |
| 5049 | .. note:: |
| 5050 | |
| 5051 | Future releases of the Yocto Project might have other features |
| 5052 | affected by this option. |
| 5053 | |
| 5054 | If you disable introspection data, you can still obtain it through other |
| 5055 | means such as copying the data from a suitable sysroot, or by generating |
| 5056 | it on the target hardware. The OpenEmbedded build system does not |
| 5057 | currently provide specific support for these techniques. |
| 5058 | |
| 5059 | Testing that Introspection Works in an Image |
| 5060 | -------------------------------------------- |
| 5061 | |
| 5062 | Use the following procedure to test if generating introspection data is |
| 5063 | working in an image: |
| 5064 | |
| 5065 | 1. Make sure that "gobject-introspection-data" is not in |
| 5066 | :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED` |
| 5067 | and that "qemu-usermode" is not in |
| 5068 | :term:`MACHINE_FEATURES_BACKFILL_CONSIDERED`. |
| 5069 | |
| 5070 | 2. Build ``core-image-sato``. |
| 5071 | |
| 5072 | 3. Launch a Terminal and then start Python in the terminal. |
| 5073 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5074 | 4. Enter the following in the terminal:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5075 | |
| 5076 | >>> from gi.repository import GLib |
| 5077 | >>> GLib.get_host_name() |
| 5078 | |
| 5079 | 5. For something a little more advanced, enter the following see: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 5080 | https://python-gtk-3-tutorial.readthedocs.io/en/latest/introduction.html |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5081 | |
| 5082 | Known Issues |
| 5083 | ------------ |
| 5084 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 5085 | Here are know issues in GObject Introspection Support: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5086 | |
| 5087 | - ``qemu-ppc64`` immediately crashes. Consequently, you cannot build |
| 5088 | introspection data on that architecture. |
| 5089 | |
| 5090 | - x32 is not supported by QEMU. Consequently, introspection data is |
| 5091 | disabled. |
| 5092 | |
| 5093 | - musl causes transient GLib binaries to crash on assertion failures. |
| 5094 | Consequently, generating introspection data is disabled. |
| 5095 | |
| 5096 | - Because QEMU is not able to run the binaries correctly, introspection |
| 5097 | is disabled for some specific packages under specific architectures |
| 5098 | (e.g. ``gcr``, ``libsecret``, and ``webkit``). |
| 5099 | |
| 5100 | - QEMU usermode might not work properly when running 64-bit binaries |
| 5101 | under 32-bit host machines. In particular, "qemumips64" is known to |
| 5102 | not work under i686. |
| 5103 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5104 | Optionally Using an External Toolchain |
| 5105 | ====================================== |
| 5106 | |
| 5107 | You might want to use an external toolchain as part of your development. |
| 5108 | If this is the case, the fundamental steps you need to accomplish are as |
| 5109 | follows: |
| 5110 | |
| 5111 | - Understand where the installed toolchain resides. For cases where you |
| 5112 | need to build the external toolchain, you would need to take separate |
| 5113 | steps to build and install the toolchain. |
| 5114 | |
| 5115 | - Make sure you add the layer that contains the toolchain to your |
| 5116 | ``bblayers.conf`` file through the |
| 5117 | :term:`BBLAYERS` variable. |
| 5118 | |
| 5119 | - Set the ``EXTERNAL_TOOLCHAIN`` variable in your ``local.conf`` file |
| 5120 | to the location in which you installed the toolchain. |
| 5121 | |
| 5122 | A good example of an external toolchain used with the Yocto Project is |
| 5123 | Mentor Graphics Sourcery G++ Toolchain. You can see information on how |
| 5124 | to use that particular layer in the ``README`` file at |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 5125 | https://github.com/MentorEmbedded/meta-sourcery/. You can find |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5126 | further information by reading about the |
| 5127 | :term:`TCMODE` variable in the Yocto |
| 5128 | Project Reference Manual's variable glossary. |
| 5129 | |
| 5130 | Creating Partitioned Images Using Wic |
| 5131 | ===================================== |
| 5132 | |
| 5133 | Creating an image for a particular hardware target using the |
| 5134 | OpenEmbedded build system does not necessarily mean you can boot that |
| 5135 | image as is on your device. Physical devices accept and boot images in |
| 5136 | various ways depending on the specifics of the device. Usually, |
| 5137 | information about the hardware can tell you what image format the device |
| 5138 | requires. Should your device require multiple partitions on an SD card, |
| 5139 | flash, or an HDD, you can use the OpenEmbedded Image Creator, Wic, to |
| 5140 | create the properly partitioned image. |
| 5141 | |
| 5142 | The ``wic`` command generates partitioned images from existing |
| 5143 | OpenEmbedded build artifacts. Image generation is driven by partitioning |
| 5144 | commands contained in an Openembedded kickstart file (``.wks``) |
| 5145 | specified either directly on the command line or as one of a selection |
| 5146 | of canned kickstart files as shown with the ``wic list images`` command |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 5147 | in the |
| 5148 | ":ref:`dev-manual/common-tasks:generate an image using an existing kickstart file`" |
| 5149 | section. When you apply the command to a given set of build artifacts, the |
| 5150 | result is an image or set of images that can be directly written onto media and |
| 5151 | used on a particular system. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5152 | |
| 5153 | .. note:: |
| 5154 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 5155 | For a kickstart file reference, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 5156 | ":ref:`ref-manual/kickstart:openembedded kickstart (\`\`.wks\`\`) reference`" |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 5157 | Chapter in the Yocto Project Reference Manual. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5158 | |
| 5159 | The ``wic`` command and the infrastructure it is based on is by |
| 5160 | definition incomplete. The purpose of the command is to allow the |
| 5161 | generation of customized images, and as such, was designed to be |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 5162 | completely extensible through a plugin interface. See the |
| 5163 | ":ref:`dev-manual/common-tasks:using the wic plugin interface`" section |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5164 | for information on these plugins. |
| 5165 | |
| 5166 | This section provides some background information on Wic, describes what |
| 5167 | you need to have in place to run the tool, provides instruction on how |
| 5168 | to use the Wic utility, provides information on using the Wic plugins |
| 5169 | interface, and provides several examples that show how to use Wic. |
| 5170 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5171 | Background |
| 5172 | ---------- |
| 5173 | |
| 5174 | This section provides some background on the Wic utility. While none of |
| 5175 | this information is required to use Wic, you might find it interesting. |
| 5176 | |
| 5177 | - The name "Wic" is derived from OpenEmbedded Image Creator (oeic). The |
| 5178 | "oe" diphthong in "oeic" was promoted to the letter "w", because |
| 5179 | "oeic" is both difficult to remember and to pronounce. |
| 5180 | |
| 5181 | - Wic is loosely based on the Meego Image Creator (``mic``) framework. |
| 5182 | The Wic implementation has been heavily modified to make direct use |
| 5183 | of OpenEmbedded build artifacts instead of package installation and |
| 5184 | configuration, which are already incorporated within the OpenEmbedded |
| 5185 | artifacts. |
| 5186 | |
| 5187 | - Wic is a completely independent standalone utility that initially |
| 5188 | provides easier-to-use and more flexible replacements for an existing |
| 5189 | functionality in OE-Core's |
| 5190 | :ref:`image-live <ref-classes-image-live>` |
| 5191 | class. The difference between Wic and those examples is that with Wic |
| 5192 | the functionality of those scripts is implemented by a |
| 5193 | general-purpose partitioning language, which is based on Redhat |
| 5194 | kickstart syntax. |
| 5195 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5196 | Requirements |
| 5197 | ------------ |
| 5198 | |
| 5199 | In order to use the Wic utility with the OpenEmbedded Build system, your |
| 5200 | system needs to meet the following requirements: |
| 5201 | |
| 5202 | - The Linux distribution on your development host must support the |
| 5203 | Yocto Project. See the ":ref:`detailed-supported-distros`" |
| 5204 | section in the Yocto Project Reference Manual for the list of |
| 5205 | distributions that support the Yocto Project. |
| 5206 | |
| 5207 | - The standard system utilities, such as ``cp``, must be installed on |
| 5208 | your development host system. |
| 5209 | |
| 5210 | - You must have sourced the build environment setup script (i.e. |
| 5211 | :ref:`structure-core-script`) found in the |
| 5212 | :term:`Build Directory`. |
| 5213 | |
| 5214 | - You need to have the build artifacts already available, which |
| 5215 | typically means that you must have already created an image using the |
| 5216 | Openembedded build system (e.g. ``core-image-minimal``). While it |
| 5217 | might seem redundant to generate an image in order to create an image |
| 5218 | using Wic, the current version of Wic requires the artifacts in the |
| 5219 | form generated by the OpenEmbedded build system. |
| 5220 | |
| 5221 | - You must build several native tools, which are built to run on the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5222 | build system:: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 5223 | |
| 5224 | $ bitbake parted-native dosfstools-native mtools-native |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5225 | |
| 5226 | - Include "wic" as part of the |
| 5227 | :term:`IMAGE_FSTYPES` |
| 5228 | variable. |
| 5229 | |
| 5230 | - Include the name of the :ref:`wic kickstart file <openembedded-kickstart-wks-reference>` |
| 5231 | as part of the :term:`WKS_FILE` variable |
| 5232 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5233 | Getting Help |
| 5234 | ------------ |
| 5235 | |
| 5236 | You can get general help for the ``wic`` command by entering the ``wic`` |
| 5237 | command by itself or by entering the command with a help argument as |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5238 | follows:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5239 | |
| 5240 | $ wic -h |
| 5241 | $ wic --help |
| 5242 | $ wic help |
| 5243 | |
| 5244 | Currently, Wic supports seven commands: ``cp``, ``create``, ``help``, |
| 5245 | ``list``, ``ls``, ``rm``, and ``write``. You can get help for all these |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5246 | commands except "help" by using the following form:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5247 | |
| 5248 | $ wic help command |
| 5249 | |
| 5250 | For example, the following command returns help for the ``write`` |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5251 | command:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5252 | |
| 5253 | $ wic help write |
| 5254 | |
| 5255 | Wic supports help for three topics: ``overview``, ``plugins``, and |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5256 | ``kickstart``. You can get help for any topic using the following form:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5257 | |
| 5258 | $ wic help topic |
| 5259 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5260 | For example, the following returns overview help for Wic:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5261 | |
| 5262 | $ wic help overview |
| 5263 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 5264 | There is one additional level of help for Wic. You can get help on |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5265 | individual images through the ``list`` command. You can use the ``list`` |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5266 | command to return the available Wic images as follows:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5267 | |
| 5268 | $ wic list images |
| 5269 | genericx86 Create an EFI disk image for genericx86* |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5270 | edgerouter Create SD card image for Edgerouter |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 5271 | beaglebone-yocto Create SD card image for Beaglebone |
| 5272 | qemux86-directdisk Create a qemu machine 'pcbios' direct disk image |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5273 | systemd-bootdisk Create an EFI disk image with systemd-boot |
| 5274 | mkhybridiso Create a hybrid ISO image |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 5275 | mkefidisk Create an EFI disk image |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5276 | sdimage-bootpart Create SD card image with a boot partition |
| 5277 | directdisk-multi-rootfs Create multi rootfs image using rootfs plugin |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 5278 | directdisk Create a 'pcbios' direct disk image |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5279 | directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 5280 | qemuriscv Create qcow2 image for RISC-V QEMU machines |
| 5281 | directdisk-gpt Create a 'pcbios' direct disk image |
| 5282 | efi-bootdisk |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5283 | |
| 5284 | Once you know the list of available |
| 5285 | Wic images, you can use ``help`` with the command to get help on a |
| 5286 | particular image. For example, the following command returns help on the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5287 | "beaglebone-yocto" image:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5288 | |
| 5289 | $ wic list beaglebone-yocto help |
| 5290 | |
| 5291 | Creates a partitioned SD card image for Beaglebone. |
| 5292 | Boot files are located in the first vfat partition. |
| 5293 | |
| 5294 | Operational Modes |
| 5295 | ----------------- |
| 5296 | |
| 5297 | You can use Wic in two different modes, depending on how much control |
| 5298 | you need for specifying the Openembedded build artifacts that are used |
| 5299 | for creating the image: Raw and Cooked: |
| 5300 | |
| 5301 | - *Raw Mode:* You explicitly specify build artifacts through Wic |
| 5302 | command-line arguments. |
| 5303 | |
| 5304 | - *Cooked Mode:* The current |
| 5305 | :term:`MACHINE` setting and image |
| 5306 | name are used to automatically locate and provide the build |
| 5307 | artifacts. You just supply a kickstart file and the name of the image |
| 5308 | from which to use artifacts. |
| 5309 | |
| 5310 | Regardless of the mode you use, you need to have the build artifacts |
| 5311 | ready and available. |
| 5312 | |
| 5313 | Raw Mode |
| 5314 | ~~~~~~~~ |
| 5315 | |
| 5316 | Running Wic in raw mode allows you to specify all the partitions through |
| 5317 | the ``wic`` command line. The primary use for raw mode is if you have |
| 5318 | built your kernel outside of the Yocto Project |
| 5319 | :term:`Build Directory`. In other words, you |
| 5320 | can point to arbitrary kernel, root filesystem locations, and so forth. |
| 5321 | Contrast this behavior with cooked mode where Wic looks in the Build |
| 5322 | Directory (e.g. ``tmp/deploy/images/``\ machine). |
| 5323 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5324 | The general form of the ``wic`` command in raw mode is:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5325 | |
| 5326 | $ wic create wks_file options ... |
| 5327 | |
| 5328 | Where: |
| 5329 | |
| 5330 | wks_file: |
| 5331 | An OpenEmbedded kickstart file. You can provide |
| 5332 | your own custom file or use a file from a set of |
| 5333 | existing files as described by further options. |
| 5334 | |
| 5335 | optional arguments: |
| 5336 | -h, --help show this help message and exit |
| 5337 | -o OUTDIR, --outdir OUTDIR |
| 5338 | name of directory to create image in |
| 5339 | -e IMAGE_NAME, --image-name IMAGE_NAME |
| 5340 | name of the image to use the artifacts from e.g. core- |
| 5341 | image-sato |
| 5342 | -r ROOTFS_DIR, --rootfs-dir ROOTFS_DIR |
| 5343 | path to the /rootfs dir to use as the .wks rootfs |
| 5344 | source |
| 5345 | -b BOOTIMG_DIR, --bootimg-dir BOOTIMG_DIR |
| 5346 | path to the dir containing the boot artifacts (e.g. |
| 5347 | /EFI or /syslinux dirs) to use as the .wks bootimg |
| 5348 | source |
| 5349 | -k KERNEL_DIR, --kernel-dir KERNEL_DIR |
| 5350 | path to the dir containing the kernel to use in the |
| 5351 | .wks bootimg |
| 5352 | -n NATIVE_SYSROOT, --native-sysroot NATIVE_SYSROOT |
| 5353 | path to the native sysroot containing the tools to use |
| 5354 | to build the image |
| 5355 | -s, --skip-build-check |
| 5356 | skip the build check |
| 5357 | -f, --build-rootfs build rootfs |
| 5358 | -c {gzip,bzip2,xz}, --compress-with {gzip,bzip2,xz} |
| 5359 | compress image with specified compressor |
| 5360 | -m, --bmap generate .bmap |
| 5361 | --no-fstab-update Do not change fstab file. |
| 5362 | -v VARS_DIR, --vars VARS_DIR |
| 5363 | directory with <image>.env files that store bitbake |
| 5364 | variables |
| 5365 | -D, --debug output debug information |
| 5366 | |
| 5367 | .. note:: |
| 5368 | |
| 5369 | You do not need root privileges to run Wic. In fact, you should not |
| 5370 | run as root when using the utility. |
| 5371 | |
| 5372 | Cooked Mode |
| 5373 | ~~~~~~~~~~~ |
| 5374 | |
| 5375 | Running Wic in cooked mode leverages off artifacts in the Build |
| 5376 | Directory. In other words, you do not have to specify kernel or root |
| 5377 | filesystem locations as part of the command. All you need to provide is |
| 5378 | a kickstart file and the name of the image from which to use artifacts |
| 5379 | by using the "-e" option. Wic looks in the Build Directory (e.g. |
| 5380 | ``tmp/deploy/images/``\ machine) for artifacts. |
| 5381 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5382 | The general form of the ``wic`` command using Cooked Mode is as follows:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5383 | |
| 5384 | $ wic create wks_file -e IMAGE_NAME |
| 5385 | |
| 5386 | Where: |
| 5387 | |
| 5388 | wks_file: |
| 5389 | An OpenEmbedded kickstart file. You can provide |
| 5390 | your own custom file or use a file from a set of |
| 5391 | existing files provided with the Yocto Project |
| 5392 | release. |
| 5393 | |
| 5394 | required argument: |
| 5395 | -e IMAGE_NAME, --image-name IMAGE_NAME |
| 5396 | name of the image to use the artifacts from e.g. core- |
| 5397 | image-sato |
| 5398 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5399 | Using an Existing Kickstart File |
| 5400 | -------------------------------- |
| 5401 | |
| 5402 | If you do not want to create your own kickstart file, you can use an |
| 5403 | existing file provided by the Wic installation. As shipped, kickstart |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 5404 | files can be found in the :ref:`overview-manual/development-environment:yocto project source repositories` in the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5405 | following two locations:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5406 | |
| 5407 | poky/meta-yocto-bsp/wic |
| 5408 | poky/scripts/lib/wic/canned-wks |
| 5409 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5410 | Use the following command to list the available kickstart files:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5411 | |
| 5412 | $ wic list images |
| 5413 | genericx86 Create an EFI disk image for genericx86* |
| 5414 | beaglebone-yocto Create SD card image for Beaglebone |
| 5415 | edgerouter Create SD card image for Edgerouter |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 5416 | qemux86-directdisk Create a QEMU machine 'pcbios' direct disk image |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5417 | directdisk-gpt Create a 'pcbios' direct disk image |
| 5418 | mkefidisk Create an EFI disk image |
| 5419 | directdisk Create a 'pcbios' direct disk image |
| 5420 | systemd-bootdisk Create an EFI disk image with systemd-boot |
| 5421 | mkhybridiso Create a hybrid ISO image |
| 5422 | sdimage-bootpart Create SD card image with a boot partition |
| 5423 | directdisk-multi-rootfs Create multi rootfs image using rootfs plugin |
| 5424 | directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config |
| 5425 | |
| 5426 | When you use an existing file, you |
| 5427 | do not have to use the ``.wks`` extension. Here is an example in Raw |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5428 | Mode that uses the ``directdisk`` file:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5429 | |
| 5430 | $ wic create directdisk -r rootfs_dir -b bootimg_dir \ |
| 5431 | -k kernel_dir -n native_sysroot |
| 5432 | |
| 5433 | Here are the actual partition language commands used in the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5434 | ``genericx86.wks`` file to generate an image:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5435 | |
| 5436 | # short-description: Create an EFI disk image for genericx86* |
| 5437 | # long-description: Creates a partitioned EFI disk image for genericx86* machines |
| 5438 | part /boot --source bootimg-efi --sourceparams="loader=grub-efi" --ondisk sda --label msdos --active --align 1024 |
| 5439 | part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid |
| 5440 | part swap --ondisk sda --size 44 --label swap1 --fstype=swap |
| 5441 | |
| 5442 | bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=ttyS0,115200 console=tty0" |
| 5443 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5444 | Using the Wic Plugin Interface |
| 5445 | ------------------------------ |
| 5446 | |
| 5447 | You can extend and specialize Wic functionality by using Wic plugins. |
| 5448 | This section explains the Wic plugin interface. |
| 5449 | |
| 5450 | .. note:: |
| 5451 | |
| 5452 | Wic plugins consist of "source" and "imager" plugins. Imager plugins |
| 5453 | are beyond the scope of this section. |
| 5454 | |
| 5455 | Source plugins provide a mechanism to customize partition content during |
| 5456 | the Wic image generation process. You can use source plugins to map |
| 5457 | values that you specify using ``--source`` commands in kickstart files |
| 5458 | (i.e. ``*.wks``) to a plugin implementation used to populate a given |
| 5459 | partition. |
| 5460 | |
| 5461 | .. note:: |
| 5462 | |
| 5463 | If you use plugins that have build-time dependencies (e.g. native |
| 5464 | tools, bootloaders, and so forth) when building a Wic image, you need |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 5465 | to specify those dependencies using the :term:`WKS_FILE_DEPENDS` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5466 | variable. |
| 5467 | |
| 5468 | Source plugins are subclasses defined in plugin files. As shipped, the |
| 5469 | Yocto Project provides several plugin files. You can see the source |
| 5470 | plugin files that ship with the Yocto Project |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 5471 | :yocto_git:`here </poky/tree/scripts/lib/wic/plugins/source>`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5472 | Each of these plugin files contains source plugins that are designed to |
| 5473 | populate a specific Wic image partition. |
| 5474 | |
| 5475 | Source plugins are subclasses of the ``SourcePlugin`` class, which is |
| 5476 | defined in the ``poky/scripts/lib/wic/pluginbase.py`` file. For example, |
| 5477 | the ``BootimgEFIPlugin`` source plugin found in the ``bootimg-efi.py`` |
| 5478 | file is a subclass of the ``SourcePlugin`` class, which is found in the |
| 5479 | ``pluginbase.py`` file. |
| 5480 | |
| 5481 | You can also implement source plugins in a layer outside of the Source |
| 5482 | Repositories (external layer). To do so, be sure that your plugin files |
| 5483 | are located in a directory whose path is |
| 5484 | ``scripts/lib/wic/plugins/source/`` within your external layer. When the |
| 5485 | plugin files are located there, the source plugins they contain are made |
| 5486 | available to Wic. |
| 5487 | |
| 5488 | When the Wic implementation needs to invoke a partition-specific |
| 5489 | implementation, it looks for the plugin with the same name as the |
| 5490 | ``--source`` parameter used in the kickstart file given to that |
| 5491 | partition. For example, if the partition is set up using the following |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5492 | command in a kickstart file:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5493 | |
| 5494 | part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024 |
| 5495 | |
| 5496 | The methods defined as class |
| 5497 | members of the matching source plugin (i.e. ``bootimg-pcbios``) in the |
| 5498 | ``bootimg-pcbios.py`` plugin file are used. |
| 5499 | |
| 5500 | To be more concrete, here is the corresponding plugin definition from |
| 5501 | the ``bootimg-pcbios.py`` file for the previous command along with an |
| 5502 | example method called by the Wic implementation when it needs to prepare |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5503 | a partition using an implementation-specific function:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5504 | |
| 5505 | . |
| 5506 | . |
| 5507 | . |
| 5508 | class BootimgPcbiosPlugin(SourcePlugin): |
| 5509 | """ |
| 5510 | Create MBR boot partition and install syslinux on it. |
| 5511 | """ |
| 5512 | |
| 5513 | name = 'bootimg-pcbios' |
| 5514 | . |
| 5515 | . |
| 5516 | . |
| 5517 | @classmethod |
| 5518 | def do_prepare_partition(cls, part, source_params, creator, cr_workdir, |
| 5519 | oe_builddir, bootimg_dir, kernel_dir, |
| 5520 | rootfs_dir, native_sysroot): |
| 5521 | """ |
| 5522 | Called to do the actual content population for a partition i.e. it |
| 5523 | 'prepares' the partition to be incorporated into the image. |
| 5524 | In this case, prepare content for legacy bios boot partition. |
| 5525 | """ |
| 5526 | . |
| 5527 | . |
| 5528 | . |
| 5529 | |
| 5530 | If a |
| 5531 | subclass (plugin) itself does not implement a particular function, Wic |
| 5532 | locates and uses the default version in the superclass. It is for this |
| 5533 | reason that all source plugins are derived from the ``SourcePlugin`` |
| 5534 | class. |
| 5535 | |
| 5536 | The ``SourcePlugin`` class defined in the ``pluginbase.py`` file defines |
| 5537 | a set of methods that source plugins can implement or override. Any |
| 5538 | plugins (subclass of ``SourcePlugin``) that do not implement a |
| 5539 | particular method inherit the implementation of the method from the |
| 5540 | ``SourcePlugin`` class. For more information, see the ``SourcePlugin`` |
| 5541 | class in the ``pluginbase.py`` file for details: |
| 5542 | |
| 5543 | The following list describes the methods implemented in the |
| 5544 | ``SourcePlugin`` class: |
| 5545 | |
| 5546 | - ``do_prepare_partition()``: Called to populate a partition with |
| 5547 | actual content. In other words, the method prepares the final |
| 5548 | partition image that is incorporated into the disk image. |
| 5549 | |
| 5550 | - ``do_configure_partition()``: Called before |
| 5551 | ``do_prepare_partition()`` to create custom configuration files for a |
| 5552 | partition (e.g. syslinux or grub configuration files). |
| 5553 | |
| 5554 | - ``do_install_disk()``: Called after all partitions have been |
| 5555 | prepared and assembled into a disk image. This method provides a hook |
| 5556 | to allow finalization of a disk image (e.g. writing an MBR). |
| 5557 | |
| 5558 | - ``do_stage_partition()``: Special content-staging hook called |
| 5559 | before ``do_prepare_partition()``. This method is normally empty. |
| 5560 | |
| 5561 | Typically, a partition just uses the passed-in parameters (e.g. the |
| 5562 | unmodified value of ``bootimg_dir``). However, in some cases, things |
| 5563 | might need to be more tailored. As an example, certain files might |
| 5564 | additionally need to be taken from ``bootimg_dir + /boot``. This hook |
| 5565 | allows those files to be staged in a customized fashion. |
| 5566 | |
| 5567 | .. note:: |
| 5568 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 5569 | ``get_bitbake_var()`` allows you to access non-standard variables that |
| 5570 | you might want to use for this behavior. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5571 | |
| 5572 | You can extend the source plugin mechanism. To add more hooks, create |
| 5573 | more source plugin methods within ``SourcePlugin`` and the corresponding |
| 5574 | derived subclasses. The code that calls the plugin methods uses the |
| 5575 | ``plugin.get_source_plugin_methods()`` function to find the method or |
| 5576 | methods needed by the call. Retrieval of those methods is accomplished |
| 5577 | by filling up a dict with keys that contain the method names of |
| 5578 | interest. On success, these will be filled in with the actual methods. |
| 5579 | See the Wic implementation for examples and details. |
| 5580 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5581 | Wic Examples |
| 5582 | ------------ |
| 5583 | |
| 5584 | This section provides several examples that show how to use the Wic |
| 5585 | utility. All the examples assume the list of requirements in the |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 5586 | ":ref:`dev-manual/common-tasks:requirements`" section have been met. The |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5587 | examples assume the previously generated image is |
| 5588 | ``core-image-minimal``. |
| 5589 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5590 | Generate an Image using an Existing Kickstart File |
| 5591 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 5592 | |
| 5593 | This example runs in Cooked Mode and uses the ``mkefidisk`` kickstart |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5594 | file:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5595 | |
| 5596 | $ wic create mkefidisk -e core-image-minimal |
| 5597 | INFO: Building wic-tools... |
| 5598 | . |
| 5599 | . |
| 5600 | . |
| 5601 | INFO: The new image(s) can be found here: |
| 5602 | ./mkefidisk-201804191017-sda.direct |
| 5603 | |
| 5604 | The following build artifacts were used to create the image(s): |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 5605 | ROOTFS_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs |
| 5606 | BOOTIMG_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share |
| 5607 | KERNEL_DIR: /home/stephano/yocto/build/tmp-glibc/deploy/images/qemux86 |
| 5608 | NATIVE_SYSROOT: /home/stephano/yocto/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5609 | |
| 5610 | INFO: The image(s) were created using OE kickstart file: |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 5611 | /home/stephano/yocto/openembedded-core/scripts/lib/wic/canned-wks/mkefidisk.wks |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5612 | |
| 5613 | The previous example shows the easiest way to create an image by running |
| 5614 | in cooked mode and supplying a kickstart file and the "-e" option to |
| 5615 | point to the existing build artifacts. Your ``local.conf`` file needs to |
| 5616 | have the :term:`MACHINE` variable set |
| 5617 | to the machine you are using, which is "qemux86" in this example. |
| 5618 | |
| 5619 | Once the image builds, the output provides image location, artifact use, |
| 5620 | and kickstart file information. |
| 5621 | |
| 5622 | .. note:: |
| 5623 | |
| 5624 | You should always verify the details provided in the output to make |
| 5625 | sure that the image was indeed created exactly as expected. |
| 5626 | |
| 5627 | Continuing with the example, you can now write the image from the Build |
| 5628 | Directory onto a USB stick, or whatever media for which you built your |
| 5629 | image, and boot from the media. You can write the image by using |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5630 | ``bmaptool`` or ``dd``:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5631 | |
| 5632 | $ oe-run-native bmaptool copy mkefidisk-201804191017-sda.direct /dev/sdX |
| 5633 | |
| 5634 | or :: |
| 5635 | |
| 5636 | $ sudo dd if=mkefidisk-201804191017-sda.direct of=/dev/sdX |
| 5637 | |
| 5638 | .. note:: |
| 5639 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 5640 | For more information on how to use the ``bmaptool`` |
| 5641 | to flash a device with an image, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 5642 | ":ref:`dev-manual/common-tasks:flashing images using \`\`bmaptool\`\``" |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 5643 | section. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5644 | |
| 5645 | Using a Modified Kickstart File |
| 5646 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 5647 | |
| 5648 | Because partitioned image creation is driven by the kickstart file, it |
| 5649 | is easy to affect image creation by changing the parameters in the file. |
| 5650 | This next example demonstrates that through modification of the |
| 5651 | ``directdisk-gpt`` kickstart file. |
| 5652 | |
| 5653 | As mentioned earlier, you can use the command ``wic list images`` to |
| 5654 | show the list of existing kickstart files. The directory in which the |
| 5655 | ``directdisk-gpt.wks`` file resides is |
| 5656 | ``scripts/lib/image/canned-wks/``, which is located in the |
| 5657 | :term:`Source Directory` (e.g. ``poky``). |
| 5658 | Because available files reside in this directory, you can create and add |
| 5659 | your own custom files to the directory. Subsequent use of the |
| 5660 | ``wic list images`` command would then include your kickstart files. |
| 5661 | |
| 5662 | In this example, the existing ``directdisk-gpt`` file already does most |
| 5663 | of what is needed. However, for the hardware in this example, the image |
| 5664 | will need to boot from ``sdb`` instead of ``sda``, which is what the |
| 5665 | ``directdisk-gpt`` kickstart file uses. |
| 5666 | |
| 5667 | The example begins by making a copy of the ``directdisk-gpt.wks`` file |
| 5668 | in the ``scripts/lib/image/canned-wks`` directory and then by changing |
| 5669 | the lines that specify the target disk from which to boot. |
| 5670 | :: |
| 5671 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 5672 | $ cp /home/stephano/yocto/poky/scripts/lib/wic/canned-wks/directdisk-gpt.wks \ |
| 5673 | /home/stephano/yocto/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5674 | |
| 5675 | Next, the example modifies the ``directdisksdb-gpt.wks`` file and |
| 5676 | changes all instances of "``--ondisk sda``" to "``--ondisk sdb``". The |
| 5677 | example changes the following two lines and leaves the remaining lines |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5678 | untouched:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5679 | |
| 5680 | part /boot --source bootimg-pcbios --ondisk sdb --label boot --active --align 1024 |
| 5681 | part / --source rootfs --ondisk sdb --fstype=ext4 --label platform --align 1024 --use-uuid |
| 5682 | |
| 5683 | Once the lines are changed, the |
| 5684 | example generates the ``directdisksdb-gpt`` image. The command points |
| 5685 | the process at the ``core-image-minimal`` artifacts for the Next Unit of |
| 5686 | Computing (nuc) :term:`MACHINE` the |
| 5687 | ``local.conf``. |
| 5688 | :: |
| 5689 | |
| 5690 | $ wic create directdisksdb-gpt -e core-image-minimal |
| 5691 | INFO: Building wic-tools... |
| 5692 | . |
| 5693 | . |
| 5694 | . |
| 5695 | Initialising tasks: 100% |#######################################| Time: 0:00:01 |
| 5696 | NOTE: Executing SetScene Tasks |
| 5697 | NOTE: Executing RunQueue Tasks |
| 5698 | NOTE: Tasks Summary: Attempted 1161 tasks of which 1157 didn't need to be rerun and all succeeded. |
| 5699 | INFO: Creating image(s)... |
| 5700 | |
| 5701 | INFO: The new image(s) can be found here: |
| 5702 | ./directdisksdb-gpt-201710090938-sdb.direct |
| 5703 | |
| 5704 | The following build artifacts were used to create the image(s): |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 5705 | ROOTFS_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs |
| 5706 | BOOTIMG_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share |
| 5707 | KERNEL_DIR: /home/stephano/yocto/build/tmp-glibc/deploy/images/qemux86 |
| 5708 | NATIVE_SYSROOT: /home/stephano/yocto/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5709 | |
| 5710 | INFO: The image(s) were created using OE kickstart file: |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 5711 | /home/stephano/yocto/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5712 | |
| 5713 | Continuing with the example, you can now directly ``dd`` the image to a |
| 5714 | USB stick, or whatever media for which you built your image, and boot |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5715 | the resulting media:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5716 | |
| 5717 | $ sudo dd if=directdisksdb-gpt-201710090938-sdb.direct of=/dev/sdb |
| 5718 | 140966+0 records in |
| 5719 | 140966+0 records out |
| 5720 | 72174592 bytes (72 MB, 69 MiB) copied, 78.0282 s, 925 kB/s |
| 5721 | $ sudo eject /dev/sdb |
| 5722 | |
| 5723 | Using a Modified Kickstart File and Running in Raw Mode |
| 5724 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 5725 | |
| 5726 | This next example manually specifies each build artifact (runs in Raw |
| 5727 | Mode) and uses a modified kickstart file. The example also uses the |
| 5728 | ``-o`` option to cause Wic to create the output somewhere other than the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5729 | default output directory, which is the current directory:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5730 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 5731 | $ wic create test.wks -o /home/stephano/testwic \ |
| 5732 | --rootfs-dir /home/stephano/yocto/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/rootfs \ |
| 5733 | --bootimg-dir /home/stephano/yocto/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share \ |
| 5734 | --kernel-dir /home/stephano/yocto/build/tmp/deploy/images/qemux86 \ |
| 5735 | --native-sysroot /home/stephano/yocto/build/tmp/work/i586-poky-linux/wic-tools/1.0-r0/recipe-sysroot-native |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5736 | |
| 5737 | INFO: Creating image(s)... |
| 5738 | |
| 5739 | INFO: The new image(s) can be found here: |
| 5740 | /home/stephano/testwic/test-201710091445-sdb.direct |
| 5741 | |
| 5742 | The following build artifacts were used to create the image(s): |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 5743 | ROOTFS_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs |
| 5744 | BOOTIMG_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share |
| 5745 | KERNEL_DIR: /home/stephano/yocto/build/tmp-glibc/deploy/images/qemux86 |
| 5746 | NATIVE_SYSROOT: /home/stephano/yocto/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5747 | |
| 5748 | INFO: The image(s) were created using OE kickstart file: |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 5749 | test.wks |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5750 | |
| 5751 | For this example, |
| 5752 | :term:`MACHINE` did not have to be |
| 5753 | specified in the ``local.conf`` file since the artifact is manually |
| 5754 | specified. |
| 5755 | |
| 5756 | Using Wic to Manipulate an Image |
| 5757 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 5758 | |
| 5759 | Wic image manipulation allows you to shorten turnaround time during |
| 5760 | image development. For example, you can use Wic to delete the kernel |
| 5761 | partition of a Wic image and then insert a newly built kernel. This |
| 5762 | saves you time from having to rebuild the entire image each time you |
| 5763 | modify the kernel. |
| 5764 | |
| 5765 | .. note:: |
| 5766 | |
| 5767 | 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] | 5768 | your development machine must have the ``mtools`` package installed. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5769 | |
| 5770 | The following example examines the contents of the Wic image, deletes |
| 5771 | the existing kernel, and then inserts a new kernel: |
| 5772 | |
| 5773 | 1. *List the Partitions:* Use the ``wic ls`` command to list all the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5774 | partitions in the Wic image:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5775 | |
| 5776 | $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic |
| 5777 | Num Start End Size Fstype |
| 5778 | 1 1048576 25041919 23993344 fat16 |
| 5779 | 2 25165824 72157183 46991360 ext4 |
| 5780 | |
| 5781 | The previous output shows two partitions in the |
| 5782 | ``core-image-minimal-qemux86.wic`` image. |
| 5783 | |
| 5784 | 2. *Examine a Particular Partition:* Use the ``wic ls`` command again |
| 5785 | but in a different form to examine a particular partition. |
| 5786 | |
| 5787 | .. note:: |
| 5788 | |
| 5789 | You can get command usage on any Wic command using the following |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5790 | form:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5791 | |
| 5792 | $ wic help command |
| 5793 | |
| 5794 | |
| 5795 | For example, the following command shows you the various ways to |
| 5796 | use the |
| 5797 | wic ls |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5798 | command:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5799 | |
| 5800 | $ wic help ls |
| 5801 | |
| 5802 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5803 | The following command shows what is in partition one:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5804 | |
| 5805 | $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1 |
| 5806 | Volume in drive : is boot |
| 5807 | Volume Serial Number is E894-1809 |
| 5808 | Directory for ::/ |
| 5809 | |
| 5810 | libcom32 c32 186500 2017-10-09 16:06 |
| 5811 | libutil c32 24148 2017-10-09 16:06 |
| 5812 | syslinux cfg 220 2017-10-09 16:06 |
| 5813 | vesamenu c32 27104 2017-10-09 16:06 |
| 5814 | vmlinuz 6904608 2017-10-09 16:06 |
| 5815 | 5 files 7 142 580 bytes |
| 5816 | 16 582 656 bytes free |
| 5817 | |
| 5818 | The previous output shows five files, with the |
| 5819 | ``vmlinuz`` being the kernel. |
| 5820 | |
| 5821 | .. note:: |
| 5822 | |
| 5823 | 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] | 5824 | ``~/.mtoolsrc`` file and be sure to have the line "mtools_skip_check=1" |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5825 | in the file. Then, run the Wic command again:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5826 | |
| 5827 | ERROR: _exec_cmd: /usr/bin/mdir -i /tmp/wic-parttfokuwra ::/ returned '1' instead of 0 |
| 5828 | output: Total number of sectors (47824) not a multiple of sectors per track (32)! |
| 5829 | Add mtools_skip_check=1 to your .mtoolsrc file to skip this test |
| 5830 | |
| 5831 | |
| 5832 | 3. *Remove the Old Kernel:* Use the ``wic rm`` command to remove the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5833 | ``vmlinuz`` file (kernel):: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5834 | |
| 5835 | $ wic rm tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz |
| 5836 | |
| 5837 | 4. *Add In the New Kernel:* Use the ``wic cp`` command to add the |
| 5838 | updated kernel to the Wic image. Depending on how you built your |
| 5839 | kernel, it could be in different places. If you used ``devtool`` and |
| 5840 | an SDK to build your kernel, it resides in the ``tmp/work`` directory |
| 5841 | of the extensible SDK. If you used ``make`` to build the kernel, the |
| 5842 | kernel will be in the ``workspace/sources`` area. |
| 5843 | |
| 5844 | The following example assumes ``devtool`` was used to build the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5845 | kernel:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5846 | |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 5847 | $ wic cp poky_sdk/tmp/work/qemux86-poky-linux/linux-yocto/4.12.12+git999-r0/linux-yocto-4.12.12+git999/arch/x86/boot/bzImage \ |
| 5848 | poky/build/tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5849 | |
| 5850 | 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] | 5851 | ``dd`` command or :ref:`bmaptool |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 5852 | <dev-manual/common-tasks:flashing images using \`\`bmaptool\`\`>` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5853 | to flash your wic image onto an SD card or USB stick and test your |
| 5854 | target. |
| 5855 | |
| 5856 | .. note:: |
| 5857 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 5858 | Using ``bmaptool`` is generally 10 to 20 times faster than using ``dd``. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5859 | |
| 5860 | Flashing Images Using ``bmaptool`` |
| 5861 | ================================== |
| 5862 | |
| 5863 | A fast and easy way to flash an image to a bootable device is to use |
| 5864 | Bmaptool, which is integrated into the OpenEmbedded build system. |
| 5865 | Bmaptool is a generic tool that creates a file's block map (bmap) and |
| 5866 | then uses that map to copy the file. As compared to traditional tools |
| 5867 | such as dd or cp, Bmaptool can copy (or flash) large files like raw |
| 5868 | system image files much faster. |
| 5869 | |
| 5870 | .. note:: |
| 5871 | |
| 5872 | - If you are using Ubuntu or Debian distributions, you can install |
| 5873 | the ``bmap-tools`` package using the following command and then |
| 5874 | use the tool without specifying ``PATH`` even from the root |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5875 | account:: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 5876 | |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 5877 | $ sudo apt install bmap-tools |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5878 | |
| 5879 | - If you are unable to install the ``bmap-tools`` package, you will |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5880 | need to build Bmaptool before using it. Use the following command:: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 5881 | |
| 5882 | $ bitbake bmap-tools-native |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5883 | |
| 5884 | Following, is an example that shows how to flash a Wic image. Realize |
| 5885 | that while this example uses a Wic image, you can use Bmaptool to flash |
| 5886 | any type of image. Use these steps to flash an image using Bmaptool: |
| 5887 | |
| 5888 | 1. *Update your local.conf File:* You need to have the following set |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5889 | in your ``local.conf`` file before building your image:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5890 | |
| 5891 | IMAGE_FSTYPES += "wic wic.bmap" |
| 5892 | |
| 5893 | 2. *Get Your Image:* Either have your image ready (pre-built with the |
| 5894 | :term:`IMAGE_FSTYPES` |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5895 | setting previously mentioned) or take the step to build the image:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5896 | |
| 5897 | $ bitbake image |
| 5898 | |
| 5899 | 3. *Flash the Device:* Flash the device with the image by using Bmaptool |
| 5900 | depending on your particular setup. The following commands assume the |
| 5901 | image resides in the Build Directory's ``deploy/images/`` area: |
| 5902 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5903 | - If you have write access to the media, use this command form:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5904 | |
| 5905 | $ oe-run-native bmap-tools-native bmaptool copy build-directory/tmp/deploy/images/machine/image.wic /dev/sdX |
| 5906 | |
| 5907 | - If you do not have write access to the media, set your permissions |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5908 | first and then use the same command form:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5909 | |
| 5910 | $ sudo chmod 666 /dev/sdX |
| 5911 | $ oe-run-native bmap-tools-native bmaptool copy build-directory/tmp/deploy/images/machine/image.wic /dev/sdX |
| 5912 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 5913 | For help on the ``bmaptool`` command, use the following command:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5914 | |
| 5915 | $ bmaptool --help |
| 5916 | |
| 5917 | Making Images More Secure |
| 5918 | ========================= |
| 5919 | |
| 5920 | Security is of increasing concern for embedded devices. Consider the |
| 5921 | issues and problems discussed in just this sampling of work found across |
| 5922 | the Internet: |
| 5923 | |
| 5924 | - *"*\ `Security Risks of Embedded |
| 5925 | Systems <https://www.schneier.com/blog/archives/2014/01/security_risks_9.html>`__\ *"* |
| 5926 | by Bruce Schneier |
| 5927 | |
| 5928 | - *"*\ `Internet Census |
| 5929 | 2012 <http://census2012.sourceforge.net/paper.html>`__\ *"* by Carna |
| 5930 | Botnet |
| 5931 | |
| 5932 | - *"*\ `Security Issues for Embedded |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 5933 | Devices <https://elinux.org/images/6/6f/Security-issues.pdf>`__\ *"* |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5934 | by Jake Edge |
| 5935 | |
| 5936 | When securing your image is of concern, there are steps, tools, and |
| 5937 | variables that you can consider to help you reach the security goals you |
| 5938 | need for your particular device. Not all situations are identical when |
| 5939 | it comes to making an image secure. Consequently, this section provides |
| 5940 | some guidance and suggestions for consideration when you want to make |
| 5941 | your image more secure. |
| 5942 | |
| 5943 | .. note:: |
| 5944 | |
| 5945 | Because the security requirements and risks are different for every |
| 5946 | type of device, this section cannot provide a complete reference on |
| 5947 | securing your custom OS. It is strongly recommended that you also |
| 5948 | consult other sources of information on embedded Linux system |
| 5949 | hardening and on security. |
| 5950 | |
| 5951 | General Considerations |
| 5952 | ---------------------- |
| 5953 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 5954 | There are general considerations that help you create more secure images. |
| 5955 | You should consider the following suggestions to make your device |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5956 | more secure: |
| 5957 | |
| 5958 | - Scan additional code you are adding to the system (e.g. application |
| 5959 | code) by using static analysis tools. Look for buffer overflows and |
| 5960 | other potential security problems. |
| 5961 | |
| 5962 | - Pay particular attention to the security for any web-based |
| 5963 | administration interface. |
| 5964 | |
| 5965 | Web interfaces typically need to perform administrative functions and |
| 5966 | tend to need to run with elevated privileges. Thus, the consequences |
| 5967 | resulting from the interface's security becoming compromised can be |
| 5968 | serious. Look for common web vulnerabilities such as |
| 5969 | cross-site-scripting (XSS), unvalidated inputs, and so forth. |
| 5970 | |
| 5971 | As with system passwords, the default credentials for accessing a |
| 5972 | web-based interface should not be the same across all devices. This |
| 5973 | is particularly true if the interface is enabled by default as it can |
| 5974 | be assumed that many end-users will not change the credentials. |
| 5975 | |
| 5976 | - Ensure you can update the software on the device to mitigate |
| 5977 | vulnerabilities discovered in the future. This consideration |
| 5978 | especially applies when your device is network-enabled. |
| 5979 | |
| 5980 | - Ensure you remove or disable debugging functionality before producing |
| 5981 | the final image. For information on how to do this, see the |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 5982 | ":ref:`dev-manual/common-tasks:considerations specific to the openembedded build system`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5983 | section. |
| 5984 | |
| 5985 | - Ensure you have no network services listening that are not needed. |
| 5986 | |
| 5987 | - Remove any software from the image that is not needed. |
| 5988 | |
| 5989 | - Enable hardware support for secure boot functionality when your |
| 5990 | device supports this functionality. |
| 5991 | |
| 5992 | Security Flags |
| 5993 | -------------- |
| 5994 | |
| 5995 | The Yocto Project has security flags that you can enable that help make |
| 5996 | your build output more secure. The security flags are in the |
| 5997 | ``meta/conf/distro/include/security_flags.inc`` file in your |
| 5998 | :term:`Source Directory` (e.g. ``poky``). |
| 5999 | |
| 6000 | .. note:: |
| 6001 | |
| 6002 | Depending on the recipe, certain security flags are enabled and |
| 6003 | disabled by default. |
| 6004 | |
| 6005 | Use the following line in your ``local.conf`` file or in your custom |
| 6006 | distribution configuration file to enable the security compiler and |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 6007 | linker flags for your build:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6008 | |
| 6009 | require conf/distro/include/security_flags.inc |
| 6010 | |
| 6011 | Considerations Specific to the OpenEmbedded Build System |
| 6012 | -------------------------------------------------------- |
| 6013 | |
| 6014 | You can take some steps that are specific to the OpenEmbedded build |
| 6015 | system to make your images more secure: |
| 6016 | |
| 6017 | - Ensure "debug-tweaks" is not one of your selected |
| 6018 | :term:`IMAGE_FEATURES`. |
| 6019 | When creating a new project, the default is to provide you with an |
| 6020 | initial ``local.conf`` file that enables this feature using the |
| 6021 | :term:`EXTRA_IMAGE_FEATURES` |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 6022 | variable with the line:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6023 | |
| 6024 | EXTRA_IMAGE_FEATURES = "debug-tweaks" |
| 6025 | |
| 6026 | To disable that feature, simply comment out that line in your |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 6027 | ``local.conf`` file, or make sure :term:`IMAGE_FEATURES` does not contain |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6028 | "debug-tweaks" before producing your final image. Among other things, |
| 6029 | leaving this in place sets the root password as blank, which makes |
| 6030 | logging in for debugging or inspection easy during development but |
| 6031 | also means anyone can easily log in during production. |
| 6032 | |
| 6033 | - It is possible to set a root password for the image and also to set |
| 6034 | passwords for any extra users you might add (e.g. administrative or |
| 6035 | service type users). When you set up passwords for multiple images or |
| 6036 | users, you should not duplicate passwords. |
| 6037 | |
| 6038 | To set up passwords, use the |
| 6039 | :ref:`extrausers <ref-classes-extrausers>` |
| 6040 | class, which is the preferred method. For an example on how to set up |
| 6041 | both root and user passwords, see the |
| 6042 | ":ref:`extrausers.bbclass <ref-classes-extrausers>`" |
| 6043 | section. |
| 6044 | |
| 6045 | .. note:: |
| 6046 | |
| 6047 | When adding extra user accounts or setting a root password, be |
| 6048 | cautious about setting the same password on every device. If you |
| 6049 | do this, and the password you have set is exposed, then every |
| 6050 | device is now potentially compromised. If you need this access but |
| 6051 | want to ensure security, consider setting a different, random |
| 6052 | password for each device. Typically, you do this as a separate |
| 6053 | step after you deploy the image onto the device. |
| 6054 | |
| 6055 | - Consider enabling a Mandatory Access Control (MAC) framework such as |
| 6056 | SMACK or SELinux and tuning it appropriately for your device's usage. |
| 6057 | You can find more information in the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 6058 | :yocto_git:`meta-selinux </meta-selinux/>` layer. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6059 | |
| 6060 | Tools for Hardening Your Image |
| 6061 | ------------------------------ |
| 6062 | |
| 6063 | The Yocto Project provides tools for making your image more secure. You |
| 6064 | can find these tools in the ``meta-security`` layer of the |
| 6065 | :yocto_git:`Yocto Project Source Repositories <>`. |
| 6066 | |
| 6067 | Creating Your Own Distribution |
| 6068 | ============================== |
| 6069 | |
| 6070 | When you build an image using the Yocto Project and do not alter any |
| 6071 | distribution :term:`Metadata`, you are |
| 6072 | creating a Poky distribution. If you wish to gain more control over |
| 6073 | package alternative selections, compile-time options, and other |
| 6074 | low-level configurations, you can create your own distribution. |
| 6075 | |
| 6076 | To create your own distribution, the basic steps consist of creating |
| 6077 | your own distribution layer, creating your own distribution |
| 6078 | configuration file, and then adding any needed code and Metadata to the |
| 6079 | layer. The following steps provide some more detail: |
| 6080 | |
| 6081 | - *Create a layer for your new distro:* Create your distribution layer |
| 6082 | so that you can keep your Metadata and code for the distribution |
| 6083 | separate. It is strongly recommended that you create and use your own |
| 6084 | layer for configuration and code. Using your own layer as compared to |
| 6085 | just placing configurations in a ``local.conf`` configuration file |
| 6086 | makes it easier to reproduce the same build configuration when using |
| 6087 | multiple build machines. See the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 6088 | ":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] | 6089 | section for information on how to quickly set up a layer. |
| 6090 | |
| 6091 | - *Create the distribution configuration file:* The distribution |
| 6092 | configuration file needs to be created in the ``conf/distro`` |
| 6093 | directory of your layer. You need to name it using your distribution |
| 6094 | name (e.g. ``mydistro.conf``). |
| 6095 | |
| 6096 | .. note:: |
| 6097 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 6098 | The :term:`DISTRO` variable in your ``local.conf`` file determines the |
| 6099 | name of your distribution. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6100 | |
| 6101 | You can split out parts of your configuration file into include files |
| 6102 | and then "require" them from within your distribution configuration |
| 6103 | file. Be sure to place the include files in the |
| 6104 | ``conf/distro/include`` directory of your layer. A common example |
| 6105 | usage of include files would be to separate out the selection of |
| 6106 | desired version and revisions for individual recipes. |
| 6107 | |
| 6108 | Your configuration file needs to set the following required |
| 6109 | variables: |
| 6110 | |
| 6111 | - :term:`DISTRO_NAME` |
| 6112 | |
| 6113 | - :term:`DISTRO_VERSION` |
| 6114 | |
| 6115 | These following variables are optional and you typically set them |
| 6116 | from the distribution configuration file: |
| 6117 | |
| 6118 | - :term:`DISTRO_FEATURES` |
| 6119 | |
| 6120 | - :term:`DISTRO_EXTRA_RDEPENDS` |
| 6121 | |
| 6122 | - :term:`DISTRO_EXTRA_RRECOMMENDS` |
| 6123 | |
| 6124 | - :term:`TCLIBC` |
| 6125 | |
| 6126 | .. tip:: |
| 6127 | |
| 6128 | If you want to base your distribution configuration file on the |
| 6129 | very basic configuration from OE-Core, you can use |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 6130 | ``conf/distro/defaultsetup.conf`` as a reference and just include |
| 6131 | variables that differ as compared to ``defaultsetup.conf``. |
| 6132 | Alternatively, you can create a distribution configuration file |
| 6133 | from scratch using the ``defaultsetup.conf`` file or configuration files |
| 6134 | from other distributions such as Poky or Angstrom as references. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6135 | |
| 6136 | - *Provide miscellaneous variables:* Be sure to define any other |
| 6137 | variables for which you want to create a default or enforce as part |
| 6138 | of the distribution configuration. You can include nearly any |
| 6139 | variable from the ``local.conf`` file. The variables you use are not |
| 6140 | limited to the list in the previous bulleted item. |
| 6141 | |
| 6142 | - *Point to Your distribution configuration file:* In your |
| 6143 | ``local.conf`` file in the :term:`Build Directory`, |
| 6144 | set your |
| 6145 | :term:`DISTRO` variable to point to |
| 6146 | your distribution's configuration file. For example, if your |
| 6147 | distribution's configuration file is named ``mydistro.conf``, then |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 6148 | you point to it as follows:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6149 | |
| 6150 | DISTRO = "mydistro" |
| 6151 | |
| 6152 | - *Add more to the layer if necessary:* Use your layer to hold other |
| 6153 | information needed for the distribution: |
| 6154 | |
| 6155 | - Add recipes for installing distro-specific configuration files |
| 6156 | that are not already installed by another recipe. If you have |
| 6157 | distro-specific configuration files that are included by an |
| 6158 | existing recipe, you should add an append file (``.bbappend``) for |
| 6159 | those. For general information and recommendations on how to add |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 6160 | recipes to your layer, see the |
| 6161 | ":ref:`dev-manual/common-tasks:creating your own layer`" and |
| 6162 | ":ref:`dev-manual/common-tasks:following best practices when creating layers`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6163 | sections. |
| 6164 | |
| 6165 | - Add any image recipes that are specific to your distribution. |
| 6166 | |
| 6167 | - Add a ``psplash`` append file for a branded splash screen. For |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 6168 | information on append files, see the |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 6169 | ":ref:`dev-manual/common-tasks:appending other layers metadata with your layer`" |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 6170 | section. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6171 | |
| 6172 | - Add any other append files to make custom changes that are |
| 6173 | specific to individual recipes. |
| 6174 | |
| 6175 | Creating a Custom Template Configuration Directory |
| 6176 | ================================================== |
| 6177 | |
| 6178 | If you are producing your own customized version of the build system for |
| 6179 | use by other users, you might want to customize the message shown by the |
| 6180 | setup script or you might want to change the template configuration |
| 6181 | files (i.e. ``local.conf`` and ``bblayers.conf``) that are created in a |
| 6182 | new build directory. |
| 6183 | |
| 6184 | The OpenEmbedded build system uses the environment variable |
| 6185 | ``TEMPLATECONF`` to locate the directory from which it gathers |
| 6186 | configuration information that ultimately ends up in the |
| 6187 | :term:`Build Directory` ``conf`` directory. |
| 6188 | By default, ``TEMPLATECONF`` is set as follows in the ``poky`` |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 6189 | repository:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6190 | |
| 6191 | TEMPLATECONF=${TEMPLATECONF:-meta-poky/conf} |
| 6192 | |
| 6193 | This is the |
| 6194 | directory used by the build system to find templates from which to build |
| 6195 | some key configuration files. If you look at this directory, you will |
| 6196 | see the ``bblayers.conf.sample``, ``local.conf.sample``, and |
| 6197 | ``conf-notes.txt`` files. The build system uses these files to form the |
| 6198 | respective ``bblayers.conf`` file, ``local.conf`` file, and display the |
| 6199 | list of BitBake targets when running the setup script. |
| 6200 | |
| 6201 | To override these default configuration files with configurations you |
| 6202 | want used within every new Build Directory, simply set the |
| 6203 | ``TEMPLATECONF`` variable to your directory. The ``TEMPLATECONF`` |
| 6204 | variable is set in the ``.templateconf`` file, which is in the top-level |
| 6205 | :term:`Source Directory` folder |
| 6206 | (e.g. ``poky``). Edit the ``.templateconf`` so that it can locate your |
| 6207 | directory. |
| 6208 | |
| 6209 | Best practices dictate that you should keep your template configuration |
| 6210 | directory in your custom distribution layer. For example, suppose you |
| 6211 | have a layer named ``meta-mylayer`` located in your home directory and |
| 6212 | you want your template configuration directory named ``myconf``. |
| 6213 | Changing the ``.templateconf`` as follows causes the OpenEmbedded build |
| 6214 | system to look in your directory and base its configuration files on the |
| 6215 | ``*.sample`` configuration files it finds. The final configuration files |
| 6216 | (i.e. ``local.conf`` and ``bblayers.conf`` ultimately still end up in |
| 6217 | your Build Directory, but they are based on your ``*.sample`` files. |
| 6218 | :: |
| 6219 | |
| 6220 | TEMPLATECONF=${TEMPLATECONF:-meta-mylayer/myconf} |
| 6221 | |
| 6222 | Aside from the ``*.sample`` configuration files, the ``conf-notes.txt`` |
| 6223 | also resides in the default ``meta-poky/conf`` directory. The script |
| 6224 | that sets up the build environment (i.e. |
| 6225 | :ref:`structure-core-script`) uses this file to |
| 6226 | display BitBake targets as part of the script output. Customizing this |
| 6227 | ``conf-notes.txt`` file is a good way to make sure your list of custom |
| 6228 | targets appears as part of the script's output. |
| 6229 | |
| 6230 | Here is the default list of targets displayed as a result of running |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 6231 | either of the setup scripts:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6232 | |
| 6233 | You can now run 'bitbake <target>' |
| 6234 | |
| 6235 | Common targets are: |
| 6236 | core-image-minimal |
| 6237 | core-image-sato |
| 6238 | meta-toolchain |
| 6239 | meta-ide-support |
| 6240 | |
| 6241 | Changing the listed common targets is as easy as editing your version of |
| 6242 | ``conf-notes.txt`` in your custom template configuration directory and |
| 6243 | making sure you have ``TEMPLATECONF`` set to your directory. |
| 6244 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 6245 | Conserving Disk Space |
| 6246 | ===================== |
| 6247 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6248 | Conserving Disk Space During Builds |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 6249 | ----------------------------------- |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6250 | |
| 6251 | To help conserve disk space during builds, you can add the following |
| 6252 | statement to your project's ``local.conf`` configuration file found in |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 6253 | the :term:`Build Directory`:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6254 | |
| 6255 | INHERIT += "rm_work" |
| 6256 | |
| 6257 | Adding this statement deletes the work directory used for |
| 6258 | building a recipe once the recipe is built. For more information on |
| 6259 | "rm_work", see the |
| 6260 | :ref:`rm_work <ref-classes-rm-work>` class in the |
| 6261 | Yocto Project Reference Manual. |
| 6262 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 6263 | Purging Duplicate Shared State Cache Files |
| 6264 | ------------------------------------------- |
| 6265 | |
| 6266 | After multiple build iterations, the Shared State (sstate) cache can contain |
| 6267 | duplicate cache files for a given package, while only the most recent one |
| 6268 | is likely to be reusable. The following command purges all but the |
| 6269 | newest sstate cache file for each package:: |
| 6270 | |
| 6271 | sstate-cache-management.sh --remove-duplicated --cache-dir=build/sstate-cache |
| 6272 | |
| 6273 | This command will ask you to confirm the deletions it identifies. |
| 6274 | |
| 6275 | Note:: |
| 6276 | |
| 6277 | The duplicated sstate cache files of one package must have the same |
| 6278 | architecture, which means that sstate cache files with multiple |
| 6279 | architectures are not considered as duplicate. |
| 6280 | |
| 6281 | Run ``sstate-cache-management.sh`` for more details about this script. |
| 6282 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6283 | Working with Packages |
| 6284 | ===================== |
| 6285 | |
| 6286 | This section describes a few tasks that involve packages: |
| 6287 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 6288 | - :ref:`dev-manual/common-tasks:excluding packages from an image` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6289 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 6290 | - :ref:`dev-manual/common-tasks:incrementing a package version` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6291 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 6292 | - :ref:`dev-manual/common-tasks:handling optional module packaging` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6293 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 6294 | - :ref:`dev-manual/common-tasks:using runtime package management` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6295 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 6296 | - :ref:`dev-manual/common-tasks:generating and using signed packages` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6297 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 6298 | - :ref:`Setting up and running package test |
| 6299 | (ptest) <dev-manual/common-tasks:testing packages with ptest>` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6300 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 6301 | - :ref:`dev-manual/common-tasks:creating node package manager (npm) packages` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6302 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 6303 | - :ref:`dev-manual/common-tasks:adding custom metadata to packages` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6304 | |
| 6305 | Excluding Packages from an Image |
| 6306 | -------------------------------- |
| 6307 | |
| 6308 | You might find it necessary to prevent specific packages from being |
| 6309 | installed into an image. If so, you can use several variables to direct |
| 6310 | the build system to essentially ignore installing recommended packages |
| 6311 | or to not install a package at all. |
| 6312 | |
| 6313 | The following list introduces variables you can use to prevent packages |
| 6314 | from being installed into your image. Each of these variables only works |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 6315 | with IPK and RPM package types, not for Debian packages. |
| 6316 | Also, you can use these variables from your ``local.conf`` file |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6317 | or attach them to a specific image recipe by using a recipe name |
| 6318 | override. For more detail on the variables, see the descriptions in the |
| 6319 | Yocto Project Reference Manual's glossary chapter. |
| 6320 | |
| 6321 | - :term:`BAD_RECOMMENDATIONS`: |
| 6322 | Use this variable to specify "recommended-only" packages that you do |
| 6323 | not want installed. |
| 6324 | |
| 6325 | - :term:`NO_RECOMMENDATIONS`: |
| 6326 | Use this variable to prevent all "recommended-only" packages from |
| 6327 | being installed. |
| 6328 | |
| 6329 | - :term:`PACKAGE_EXCLUDE`: |
| 6330 | Use this variable to prevent specific packages from being installed |
| 6331 | regardless of whether they are "recommended-only" or not. You need to |
| 6332 | realize that the build process could fail with an error when you |
| 6333 | prevent the installation of a package whose presence is required by |
| 6334 | an installed package. |
| 6335 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6336 | Incrementing a Package Version |
| 6337 | ------------------------------ |
| 6338 | |
| 6339 | This section provides some background on how binary package versioning |
| 6340 | is accomplished and presents some of the services, variables, and |
| 6341 | terminology involved. |
| 6342 | |
| 6343 | In order to understand binary package versioning, you need to consider |
| 6344 | the following: |
| 6345 | |
| 6346 | - Binary Package: The binary package that is eventually built and |
| 6347 | installed into an image. |
| 6348 | |
| 6349 | - Binary Package Version: The binary package version is composed of two |
| 6350 | components - a version and a revision. |
| 6351 | |
| 6352 | .. note:: |
| 6353 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 6354 | Technically, a third component, the "epoch" (i.e. :term:`PE`) is involved |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 6355 | but this discussion for the most part ignores :term:`PE`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6356 | |
| 6357 | The version and revision are taken from the |
| 6358 | :term:`PV` and |
| 6359 | :term:`PR` variables, respectively. |
| 6360 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 6361 | - :term:`PV`: The recipe version. :term:`PV` represents the version of the |
| 6362 | software being packaged. Do not confuse :term:`PV` with the binary |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6363 | package version. |
| 6364 | |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 6365 | - :term:`PR`: The recipe revision. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6366 | |
| 6367 | - :term:`SRCPV`: The OpenEmbedded |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 6368 | build system uses this string to help define the value of :term:`PV` when |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6369 | the source code revision needs to be included in it. |
| 6370 | |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 6371 | - :yocto_wiki:`PR Service </PR_Service>`: A |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6372 | network-based service that helps automate keeping package feeds |
| 6373 | compatible with existing package manager applications such as RPM, |
| 6374 | APT, and OPKG. |
| 6375 | |
| 6376 | Whenever the binary package content changes, the binary package version |
| 6377 | must change. Changing the binary package version is accomplished by |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 6378 | changing or "bumping" the :term:`PR` and/or :term:`PV` values. Increasing these |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6379 | values occurs one of two ways: |
| 6380 | |
| 6381 | - Automatically using a Package Revision Service (PR Service). |
| 6382 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 6383 | - Manually incrementing the :term:`PR` and/or :term:`PV` variables. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6384 | |
| 6385 | Given a primary challenge of any build system and its users is how to |
| 6386 | maintain a package feed that is compatible with existing package manager |
| 6387 | applications such as RPM, APT, and OPKG, using an automated system is |
| 6388 | much preferred over a manual system. In either system, the main |
| 6389 | requirement is that binary package version numbering increases in a |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 6390 | linear fashion and that there is a number of version components that |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6391 | support that linear progression. For information on how to ensure |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 6392 | package revisioning remains linear, see the |
| 6393 | ":ref:`dev-manual/common-tasks:automatically incrementing a package version number`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6394 | section. |
| 6395 | |
| 6396 | The following three sections provide related information on the PR |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 6397 | Service, the manual method for "bumping" :term:`PR` and/or :term:`PV`, and on |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6398 | how to ensure binary package revisioning remains linear. |
| 6399 | |
| 6400 | Working With a PR Service |
| 6401 | ~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 6402 | |
| 6403 | As mentioned, attempting to maintain revision numbers in the |
| 6404 | :term:`Metadata` is error prone, inaccurate, |
| 6405 | and causes problems for people submitting recipes. Conversely, the PR |
| 6406 | Service automatically generates increasing numbers, particularly the |
| 6407 | revision field, which removes the human element. |
| 6408 | |
| 6409 | .. note:: |
| 6410 | |
| 6411 | For additional information on using a PR Service, you can see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 6412 | :yocto_wiki:`PR Service </PR_Service>` wiki page. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6413 | |
| 6414 | The Yocto Project uses variables in order of decreasing priority to |
| 6415 | facilitate revision numbering (i.e. |
| 6416 | :term:`PE`, |
| 6417 | :term:`PV`, and |
| 6418 | :term:`PR` for epoch, version, and |
| 6419 | revision, respectively). The values are highly dependent on the policies |
| 6420 | and procedures of a given distribution and package feed. |
| 6421 | |
| 6422 | Because the OpenEmbedded build system uses |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 6423 | ":ref:`signatures <overview-manual/concepts:checksums (signatures)>`", which are |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6424 | unique to a given build, the build system knows when to rebuild |
| 6425 | packages. All the inputs into a given task are represented by a |
| 6426 | signature, which can trigger a rebuild when different. Thus, the build |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 6427 | system itself does not rely on the :term:`PR`, :term:`PV`, and :term:`PE` numbers to |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6428 | trigger a rebuild. The signatures, however, can be used to generate |
| 6429 | these values. |
| 6430 | |
| 6431 | The PR Service works with both ``OEBasic`` and ``OEBasicHash`` |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 6432 | generators. The value of :term:`PR` bumps when the checksum changes and the |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6433 | different generator mechanisms change signatures under different |
| 6434 | circumstances. |
| 6435 | |
| 6436 | As implemented, the build system includes values from the PR Service |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 6437 | into the :term:`PR` field as an addition using the form "``.x``" so ``r0`` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6438 | becomes ``r0.1``, ``r0.2`` and so forth. This scheme allows existing |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 6439 | :term:`PR` values to be used for whatever reasons, which include manual |
| 6440 | :term:`PR` bumps, should it be necessary. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6441 | |
| 6442 | By default, the PR Service is not enabled or running. Thus, the packages |
| 6443 | generated are just "self consistent". The build system adds and removes |
| 6444 | packages and there are no guarantees about upgrade paths but images will |
| 6445 | be consistent and correct with the latest changes. |
| 6446 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 6447 | The simplest form for a PR Service is for a single host |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6448 | development system that builds the package feed (building system). For |
| 6449 | this scenario, you can enable a local PR Service by setting |
| 6450 | :term:`PRSERV_HOST` in your |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 6451 | ``local.conf`` file in the :term:`Build Directory`:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6452 | |
| 6453 | PRSERV_HOST = "localhost:0" |
| 6454 | |
| 6455 | Once the service is started, packages will automatically |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 6456 | get increasing :term:`PR` values and BitBake takes care of starting and |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6457 | stopping the server. |
| 6458 | |
| 6459 | If you have a more complex setup where multiple host development systems |
| 6460 | work against a common, shared package feed, you have a single PR Service |
| 6461 | running and it is connected to each building system. For this scenario, |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 6462 | you need to start the PR Service using the ``bitbake-prserv`` command:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6463 | |
| 6464 | bitbake-prserv --host ip --port port --start |
| 6465 | |
| 6466 | In addition to |
| 6467 | hand-starting the service, you need to update the ``local.conf`` file of |
| 6468 | each building system as described earlier so each system points to the |
| 6469 | server and port. |
| 6470 | |
| 6471 | It is also recommended you use build history, which adds some sanity |
| 6472 | checks to binary package versions, in conjunction with the server that |
| 6473 | is running the PR Service. To enable build history, add the following to |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 6474 | each building system's ``local.conf`` file:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6475 | |
| 6476 | # It is recommended to activate "buildhistory" for testing the PR service |
| 6477 | INHERIT += "buildhistory" |
| 6478 | BUILDHISTORY_COMMIT = "1" |
| 6479 | |
| 6480 | For information on build |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 6481 | history, see the |
| 6482 | ":ref:`dev-manual/common-tasks:maintaining build output quality`" section. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6483 | |
| 6484 | .. note:: |
| 6485 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 6486 | The OpenEmbedded build system does not maintain :term:`PR` information as |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6487 | part of the shared state (sstate) packages. If you maintain an sstate |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 6488 | feed, it's expected that either all your building systems that |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6489 | contribute to the sstate feed use a shared PR Service, or you do not |
| 6490 | run a PR Service on any of your building systems. Having some systems |
| 6491 | use a PR Service while others do not leads to obvious problems. |
| 6492 | |
| 6493 | For more information on shared state, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 6494 | ":ref:`overview-manual/concepts:shared state cache`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6495 | section in the Yocto Project Overview and Concepts Manual. |
| 6496 | |
| 6497 | Manually Bumping PR |
| 6498 | ~~~~~~~~~~~~~~~~~~~ |
| 6499 | |
| 6500 | The alternative to setting up a PR Service is to manually "bump" the |
| 6501 | :term:`PR` variable. |
| 6502 | |
| 6503 | If a committed change results in changing the package output, then the |
| 6504 | value of the PR variable needs to be increased (or "bumped") as part of |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 6505 | that commit. For new recipes you should add the :term:`PR` variable and set |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6506 | its initial value equal to "r0", which is the default. Even though the |
| 6507 | default value is "r0", the practice of adding it to a new recipe makes |
| 6508 | it harder to forget to bump the variable when you make changes to the |
| 6509 | recipe in future. |
| 6510 | |
| 6511 | If you are sharing a common ``.inc`` file with multiple recipes, you can |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 6512 | also use the :term:`INC_PR` variable to ensure that the recipes sharing the |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6513 | ``.inc`` file are rebuilt when the ``.inc`` file itself is changed. The |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 6514 | ``.inc`` file must set :term:`INC_PR` (initially to "r0"), and all recipes |
| 6515 | referring to it should set :term:`PR` to "${INC_PR}.0" initially, |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6516 | incrementing the last number when the recipe is changed. If the ``.inc`` |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 6517 | file is changed then its :term:`INC_PR` should be incremented. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6518 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 6519 | When upgrading the version of a binary package, assuming the :term:`PV` |
| 6520 | changes, the :term:`PR` variable should be reset to "r0" (or "${INC_PR}.0" |
| 6521 | if you are using :term:`INC_PR`). |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6522 | |
| 6523 | Usually, version increases occur only to binary packages. However, if |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 6524 | for some reason :term:`PV` changes but does not increase, you can increase |
| 6525 | the :term:`PE` variable (Package Epoch). The :term:`PE` variable defaults to |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6526 | "0". |
| 6527 | |
| 6528 | Binary package version numbering strives to follow the `Debian Version |
| 6529 | Field Policy |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 6530 | Guidelines <https://www.debian.org/doc/debian-policy/ch-controlfields.html>`__. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6531 | These guidelines define how versions are compared and what "increasing" |
| 6532 | a version means. |
| 6533 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6534 | Automatically Incrementing a Package Version Number |
| 6535 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 6536 | |
| 6537 | When fetching a repository, BitBake uses the |
| 6538 | :term:`SRCREV` variable to determine |
| 6539 | the specific source code revision from which to build. You set the |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 6540 | :term:`SRCREV` variable to |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6541 | :term:`AUTOREV` to cause the |
| 6542 | OpenEmbedded build system to automatically use the latest revision of |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 6543 | the software:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6544 | |
| 6545 | SRCREV = "${AUTOREV}" |
| 6546 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 6547 | Furthermore, you need to reference :term:`SRCPV` in :term:`PV` in order to |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6548 | automatically update the version whenever the revision of the source |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 6549 | code changes. Here is an example:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6550 | |
| 6551 | PV = "1.0+git${SRCPV}" |
| 6552 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 6553 | The OpenEmbedded build system substitutes :term:`SRCPV` with the following: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 6554 | |
| 6555 | .. code-block:: none |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6556 | |
| 6557 | AUTOINC+source_code_revision |
| 6558 | |
| 6559 | The build system replaces the ``AUTOINC`` |
| 6560 | with a number. The number used depends on the state of the PR Service: |
| 6561 | |
| 6562 | - If PR Service is enabled, the build system increments the number, |
| 6563 | which is similar to the behavior of |
| 6564 | :term:`PR`. This behavior results in |
| 6565 | linearly increasing package versions, which is desirable. Here is an |
| 6566 | example: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 6567 | |
| 6568 | .. code-block:: none |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6569 | |
| 6570 | hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk |
| 6571 | hello-world-git_0.0+git1+dd2f5c3565-r0.0_armv7a-neon.ipk |
| 6572 | |
| 6573 | - If PR Service is not enabled, the build system replaces the |
| 6574 | ``AUTOINC`` placeholder with zero (i.e. "0"). This results in |
| 6575 | changing the package version since the source revision is included. |
| 6576 | However, package versions are not increased linearly. Here is an |
| 6577 | example: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 6578 | |
| 6579 | .. code-block:: none |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6580 | |
| 6581 | hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk |
| 6582 | hello-world-git_0.0+git0+dd2f5c3565-r0.0_armv7a-neon.ipk |
| 6583 | |
| 6584 | In summary, the OpenEmbedded build system does not track the history of |
| 6585 | binary package versions for this purpose. ``AUTOINC``, in this case, is |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 6586 | comparable to :term:`PR`. If PR server is not enabled, ``AUTOINC`` in the |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6587 | package version is simply replaced by "0". If PR server is enabled, the |
| 6588 | build system keeps track of the package versions and bumps the number |
| 6589 | when the package revision changes. |
| 6590 | |
| 6591 | Handling Optional Module Packaging |
| 6592 | ---------------------------------- |
| 6593 | |
| 6594 | Many pieces of software split functionality into optional modules (or |
| 6595 | plugins) and the plugins that are built might depend on configuration |
| 6596 | options. To avoid having to duplicate the logic that determines what |
| 6597 | modules are available in your recipe or to avoid having to package each |
| 6598 | module by hand, the OpenEmbedded build system provides functionality to |
| 6599 | handle module packaging dynamically. |
| 6600 | |
| 6601 | To handle optional module packaging, you need to do two things: |
| 6602 | |
| 6603 | - Ensure the module packaging is actually done. |
| 6604 | |
| 6605 | - Ensure that any dependencies on optional modules from other recipes |
| 6606 | are satisfied by your recipe. |
| 6607 | |
| 6608 | Making Sure the Packaging is Done |
| 6609 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 6610 | |
| 6611 | To ensure the module packaging actually gets done, you use the |
| 6612 | ``do_split_packages`` function within the ``populate_packages`` Python |
| 6613 | function in your recipe. The ``do_split_packages`` function searches for |
| 6614 | a pattern of files or directories under a specified path and creates a |
| 6615 | package for each one it finds by appending to the |
| 6616 | :term:`PACKAGES` variable and |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 6617 | setting the appropriate values for ``FILES:packagename``, |
| 6618 | ``RDEPENDS:packagename``, ``DESCRIPTION:packagename``, and so forth. |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 6619 | Here is an example from the ``lighttpd`` recipe:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6620 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 6621 | python populate_packages:prepend () { |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6622 | lighttpd_libdir = d.expand('${libdir}') |
| 6623 | do_split_packages(d, lighttpd_libdir, '^mod_(.*).so$', |
| 6624 | 'lighttpd-module-%s', 'Lighttpd module for %s', |
| 6625 | extra_depends='') |
| 6626 | } |
| 6627 | |
| 6628 | The previous example specifies a number of things in the call to |
| 6629 | ``do_split_packages``. |
| 6630 | |
| 6631 | - A directory within the files installed by your recipe through |
| 6632 | ``do_install`` in which to search. |
| 6633 | |
| 6634 | - A regular expression used to match module files in that directory. In |
| 6635 | the example, note the parentheses () that mark the part of the |
| 6636 | expression from which the module name should be derived. |
| 6637 | |
| 6638 | - A pattern to use for the package names. |
| 6639 | |
| 6640 | - A description for each package. |
| 6641 | |
| 6642 | - An empty string for ``extra_depends``, which disables the default |
| 6643 | dependency on the main ``lighttpd`` package. Thus, if a file in |
| 6644 | ``${libdir}`` called ``mod_alias.so`` is found, a package called |
| 6645 | ``lighttpd-module-alias`` is created for it and the |
| 6646 | :term:`DESCRIPTION` is set to |
| 6647 | "Lighttpd module for alias". |
| 6648 | |
| 6649 | Often, packaging modules is as simple as the previous example. However, |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 6650 | there are more advanced options that you can use within |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6651 | ``do_split_packages`` to modify its behavior. And, if you need to, you |
| 6652 | can add more logic by specifying a hook function that is called for each |
| 6653 | package. It is also perfectly acceptable to call ``do_split_packages`` |
| 6654 | multiple times if you have more than one set of modules to package. |
| 6655 | |
| 6656 | For more examples that show how to use ``do_split_packages``, see the |
| 6657 | ``connman.inc`` file in the ``meta/recipes-connectivity/connman/`` |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 6658 | 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] | 6659 | also find examples in ``meta/classes/kernel.bbclass``. |
| 6660 | |
| 6661 | Following is a reference that shows ``do_split_packages`` mandatory and |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 6662 | optional arguments:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6663 | |
| 6664 | Mandatory arguments |
| 6665 | |
| 6666 | root |
| 6667 | The path in which to search |
| 6668 | file_regex |
| 6669 | Regular expression to match searched files. |
| 6670 | Use parentheses () to mark the part of this |
| 6671 | expression that should be used to derive the |
| 6672 | module name (to be substituted where %s is |
| 6673 | used in other function arguments as noted below) |
| 6674 | output_pattern |
| 6675 | Pattern to use for the package names. Must |
| 6676 | include %s. |
| 6677 | description |
| 6678 | Description to set for each package. Must |
| 6679 | include %s. |
| 6680 | |
| 6681 | Optional arguments |
| 6682 | |
| 6683 | postinst |
| 6684 | Postinstall script to use for all packages |
| 6685 | (as a string) |
| 6686 | recursive |
| 6687 | True to perform a recursive search - default |
| 6688 | False |
| 6689 | hook |
| 6690 | A hook function to be called for every match. |
| 6691 | The function will be called with the following |
| 6692 | arguments (in the order listed): |
| 6693 | |
| 6694 | f |
| 6695 | Full path to the file/directory match |
| 6696 | pkg |
| 6697 | The package name |
| 6698 | file_regex |
| 6699 | As above |
| 6700 | output_pattern |
| 6701 | As above |
| 6702 | modulename |
| 6703 | The module name derived using file_regex |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 6704 | extra_depends |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6705 | Extra runtime dependencies (RDEPENDS) to be |
| 6706 | set for all packages. The default value of None |
| 6707 | causes a dependency on the main package |
| 6708 | (${PN}) - if you do not want this, pass empty |
| 6709 | string '' for this parameter. |
| 6710 | aux_files_pattern |
| 6711 | Extra item(s) to be added to FILES for each |
| 6712 | package. Can be a single string item or a list |
| 6713 | of strings for multiple items. Must include %s. |
| 6714 | postrm |
| 6715 | postrm script to use for all packages (as a |
| 6716 | string) |
| 6717 | allow_dirs |
| 6718 | True to allow directories to be matched - |
| 6719 | default False |
| 6720 | prepend |
| 6721 | If True, prepend created packages to PACKAGES |
| 6722 | instead of the default False which appends them |
| 6723 | match_path |
| 6724 | match file_regex on the whole relative path to |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 6725 | the root rather than just the filename |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6726 | aux_files_pattern_verbatim |
| 6727 | Extra item(s) to be added to FILES for each |
| 6728 | package, using the actual derived module name |
| 6729 | rather than converting it to something legal |
| 6730 | for a package name. Can be a single string item |
| 6731 | or a list of strings for multiple items. Must |
| 6732 | include %s. |
| 6733 | allow_links |
| 6734 | True to allow symlinks to be matched - default |
| 6735 | False |
| 6736 | summary |
| 6737 | Summary to set for each package. Must include %s; |
| 6738 | defaults to description if not set. |
| 6739 | |
| 6740 | |
| 6741 | |
| 6742 | Satisfying Dependencies |
| 6743 | ~~~~~~~~~~~~~~~~~~~~~~~ |
| 6744 | |
| 6745 | The second part for handling optional module packaging is to ensure that |
| 6746 | any dependencies on optional modules from other recipes are satisfied by |
| 6747 | your recipe. You can be sure these dependencies are satisfied by using |
| 6748 | the :term:`PACKAGES_DYNAMIC` |
| 6749 | variable. Here is an example that continues with the ``lighttpd`` recipe |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 6750 | shown earlier:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6751 | |
| 6752 | PACKAGES_DYNAMIC = "lighttpd-module-.*" |
| 6753 | |
| 6754 | The name |
| 6755 | specified in the regular expression can of course be anything. In this |
| 6756 | example, it is ``lighttpd-module-`` and is specified as the prefix to |
| 6757 | ensure that any :term:`RDEPENDS` and |
| 6758 | :term:`RRECOMMENDS` on a package |
| 6759 | name starting with the prefix are satisfied during build time. If you |
| 6760 | are using ``do_split_packages`` as described in the previous section, |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 6761 | the value you put in :term:`PACKAGES_DYNAMIC` should correspond to the name |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6762 | pattern specified in the call to ``do_split_packages``. |
| 6763 | |
| 6764 | Using Runtime Package Management |
| 6765 | -------------------------------- |
| 6766 | |
| 6767 | During a build, BitBake always transforms a recipe into one or more |
| 6768 | packages. For example, BitBake takes the ``bash`` recipe and produces a |
| 6769 | number of packages (e.g. ``bash``, ``bash-bashbug``, |
| 6770 | ``bash-completion``, ``bash-completion-dbg``, ``bash-completion-dev``, |
| 6771 | ``bash-completion-extra``, ``bash-dbg``, and so forth). Not all |
| 6772 | generated packages are included in an image. |
| 6773 | |
| 6774 | In several situations, you might need to update, add, remove, or query |
| 6775 | the packages on a target device at runtime (i.e. without having to |
| 6776 | generate a new image). Examples of such situations include: |
| 6777 | |
| 6778 | - You want to provide in-the-field updates to deployed devices (e.g. |
| 6779 | security updates). |
| 6780 | |
| 6781 | - You want to have a fast turn-around development cycle for one or more |
| 6782 | applications that run on your device. |
| 6783 | |
| 6784 | - You want to temporarily install the "debug" packages of various |
| 6785 | applications on your device so that debugging can be greatly improved |
| 6786 | by allowing access to symbols and source debugging. |
| 6787 | |
| 6788 | - You want to deploy a more minimal package selection of your device |
| 6789 | but allow in-the-field updates to add a larger selection for |
| 6790 | customization. |
| 6791 | |
| 6792 | In all these situations, you have something similar to a more |
| 6793 | traditional Linux distribution in that in-field devices are able to |
| 6794 | receive pre-compiled packages from a server for installation or update. |
| 6795 | Being able to install these packages on a running, in-field device is |
| 6796 | what is termed "runtime package management". |
| 6797 | |
| 6798 | In order to use runtime package management, you need a host or server |
| 6799 | machine that serves up the pre-compiled packages plus the required |
| 6800 | metadata. You also need package manipulation tools on the target. The |
| 6801 | build machine is a likely candidate to act as the server. However, that |
| 6802 | machine does not necessarily have to be the package server. The build |
| 6803 | machine could push its artifacts to another machine that acts as the |
| 6804 | server (e.g. Internet-facing). In fact, doing so is advantageous for a |
| 6805 | production environment as getting the packages away from the development |
| 6806 | system's build directory prevents accidental overwrites. |
| 6807 | |
| 6808 | A simple build that targets just one device produces more than one |
| 6809 | package database. In other words, the packages produced by a build are |
| 6810 | separated out into a couple of different package groupings based on |
| 6811 | criteria such as the target's CPU architecture, the target board, or the |
| 6812 | C library used on the target. For example, a build targeting the |
| 6813 | ``qemux86`` device produces the following three package databases: |
| 6814 | ``noarch``, ``i586``, and ``qemux86``. If you wanted your ``qemux86`` |
| 6815 | device to be aware of all the packages that were available to it, you |
| 6816 | would need to point it to each of these databases individually. In a |
| 6817 | similar way, a traditional Linux distribution usually is configured to |
| 6818 | be aware of a number of software repositories from which it retrieves |
| 6819 | packages. |
| 6820 | |
| 6821 | Using runtime package management is completely optional and not required |
| 6822 | for a successful build or deployment in any way. But if you want to make |
| 6823 | use of runtime package management, you need to do a couple things above |
| 6824 | and beyond the basics. The remainder of this section describes what you |
| 6825 | need to do. |
| 6826 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6827 | Build Considerations |
| 6828 | ~~~~~~~~~~~~~~~~~~~~ |
| 6829 | |
| 6830 | This section describes build considerations of which you need to be |
| 6831 | aware in order to provide support for runtime package management. |
| 6832 | |
| 6833 | When BitBake generates packages, it needs to know what format or formats |
| 6834 | to use. In your configuration, you use the |
| 6835 | :term:`PACKAGE_CLASSES` |
| 6836 | variable to specify the format: |
| 6837 | |
| 6838 | 1. Open the ``local.conf`` file inside your |
| 6839 | :term:`Build Directory` (e.g. |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 6840 | ``poky/build/conf/local.conf``). |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6841 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 6842 | 2. Select the desired package format as follows:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6843 | |
| 6844 | PACKAGE_CLASSES ?= "package_packageformat" |
| 6845 | |
| 6846 | where packageformat can be "ipk", "rpm", |
| 6847 | "deb", or "tar" which are the supported package formats. |
| 6848 | |
| 6849 | .. note:: |
| 6850 | |
| 6851 | Because the Yocto Project supports four different package formats, |
| 6852 | you can set the variable with more than one argument. However, the |
| 6853 | OpenEmbedded build system only uses the first argument when |
| 6854 | creating an image or Software Development Kit (SDK). |
| 6855 | |
| 6856 | If you would like your image to start off with a basic package database |
| 6857 | containing the packages in your current build as well as to have the |
| 6858 | relevant tools available on the target for runtime package management, |
| 6859 | you can include "package-management" in the |
| 6860 | :term:`IMAGE_FEATURES` |
| 6861 | variable. Including "package-management" in this configuration variable |
| 6862 | ensures that when the image is assembled for your target, the image |
| 6863 | includes the currently-known package databases as well as the |
| 6864 | target-specific tools required for runtime package management to be |
| 6865 | performed on the target. However, this is not strictly necessary. You |
| 6866 | could start your image off without any databases but only include the |
| 6867 | required on-target package tool(s). As an example, you could include |
| 6868 | "opkg" in your |
| 6869 | :term:`IMAGE_INSTALL` variable |
| 6870 | if you are using the IPK package format. You can then initialize your |
| 6871 | target's package database(s) later once your image is up and running. |
| 6872 | |
| 6873 | Whenever you perform any sort of build step that can potentially |
| 6874 | generate a package or modify existing package, it is always a good idea |
| 6875 | to re-generate the package index after the build by using the following |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 6876 | command:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6877 | |
| 6878 | $ bitbake package-index |
| 6879 | |
| 6880 | It might be tempting to build the |
| 6881 | package and the package index at the same time with a command such as |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 6882 | the following:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6883 | |
| 6884 | $ bitbake some-package package-index |
| 6885 | |
| 6886 | Do not do this as |
| 6887 | BitBake does not schedule the package index for after the completion of |
| 6888 | the package you are building. Consequently, you cannot be sure of the |
| 6889 | package index including information for the package you just built. |
| 6890 | Thus, be sure to run the package update step separately after building |
| 6891 | any packages. |
| 6892 | |
| 6893 | You can use the |
| 6894 | :term:`PACKAGE_FEED_ARCHS`, |
| 6895 | :term:`PACKAGE_FEED_BASE_PATHS`, |
| 6896 | and |
| 6897 | :term:`PACKAGE_FEED_URIS` |
| 6898 | variables to pre-configure target images to use a package feed. If you |
| 6899 | do not define these variables, then manual steps as described in the |
| 6900 | subsequent sections are necessary to configure the target. You should |
| 6901 | set these variables before building the image in order to produce a |
| 6902 | correctly configured image. |
| 6903 | |
| 6904 | When your build is complete, your packages reside in the |
| 6905 | ``${TMPDIR}/deploy/packageformat`` directory. For example, if |
| 6906 | ``${``\ :term:`TMPDIR`\ ``}`` is |
| 6907 | ``tmp`` and your selected package type is RPM, then your RPM packages |
| 6908 | are available in ``tmp/deploy/rpm``. |
| 6909 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6910 | Host or Server Machine Setup |
| 6911 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 6912 | |
| 6913 | Although other protocols are possible, a server using HTTP typically |
| 6914 | 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] | 6915 | 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] | 6916 | machine serving the packages. |
| 6917 | |
| 6918 | To keep things simple, this section describes how to set up a |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 6919 | Python web server to share package feeds from the developer's |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6920 | machine. Although this server might not be the best for a production |
| 6921 | environment, the setup is simple and straight forward. Should you want |
| 6922 | to use a different server more suited for production (e.g. Apache 2, |
| 6923 | Lighttpd, or Nginx), take the appropriate steps to do so. |
| 6924 | |
| 6925 | From within the build directory where you have built an image based on |
| 6926 | your packaging choice (i.e. the |
| 6927 | :term:`PACKAGE_CLASSES` |
| 6928 | setting), simply start the server. The following example assumes a build |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 6929 | directory of ``poky/build/tmp/deploy/rpm`` and a :term:`PACKAGE_CLASSES` |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 6930 | setting of "package_rpm":: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6931 | |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 6932 | $ cd poky/build/tmp/deploy/rpm |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 6933 | $ python3 -m http.server |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6934 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6935 | Target Setup |
| 6936 | ~~~~~~~~~~~~ |
| 6937 | |
| 6938 | Setting up the target differs depending on the package management |
| 6939 | system. This section provides information for RPM, IPK, and DEB. |
| 6940 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6941 | Using RPM |
| 6942 | ^^^^^^^^^ |
| 6943 | |
| 6944 | The `Dandified Packaging |
| 6945 | Tool <https://en.wikipedia.org/wiki/DNF_(software)>`__ (DNF) performs |
| 6946 | runtime package management of RPM packages. In order to use DNF for |
| 6947 | runtime package management, you must perform an initial setup on the |
| 6948 | target machine for cases where the ``PACKAGE_FEED_*`` variables were not |
| 6949 | set as part of the image that is running on the target. This means if |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 6950 | you built your image and did not use these variables as part of the |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6951 | build and your image is now running on the target, you need to perform |
| 6952 | the steps in this section if you want to use runtime package management. |
| 6953 | |
| 6954 | .. note:: |
| 6955 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 6956 | For information on the ``PACKAGE_FEED_*`` variables, see |
| 6957 | :term:`PACKAGE_FEED_ARCHS`, :term:`PACKAGE_FEED_BASE_PATHS`, and |
| 6958 | :term:`PACKAGE_FEED_URIS` in the Yocto Project Reference Manual variables |
| 6959 | glossary. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6960 | |
| 6961 | On the target, you must inform DNF that package databases are available. |
| 6962 | You do this by creating a file named |
| 6963 | ``/etc/yum.repos.d/oe-packages.repo`` and defining the ``oe-packages``. |
| 6964 | |
| 6965 | As an example, assume the target is able to use the following package |
| 6966 | databases: ``all``, ``i586``, and ``qemux86`` from a server named |
| 6967 | ``my.server``. The specifics for setting up the web server are up to |
| 6968 | you. The critical requirement is that the URIs in the target repository |
| 6969 | configuration point to the correct remote location for the feeds. |
| 6970 | |
| 6971 | .. note:: |
| 6972 | |
| 6973 | For development purposes, you can point the web server to the build |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 6974 | system's ``deploy`` directory. However, for production use, it is better to |
| 6975 | 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] | 6976 | that location. Doing so avoids situations where the build system |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 6977 | overwrites or changes the ``deploy`` directory. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6978 | |
| 6979 | When telling DNF where to look for the package databases, you must |
| 6980 | declare individual locations per architecture or a single location used |
| 6981 | for all architectures. You cannot do both: |
| 6982 | |
| 6983 | - *Create an Explicit List of Architectures:* Define individual base |
| 6984 | URLs to identify where each package database is located: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 6985 | |
| 6986 | .. code-block:: none |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6987 | |
| 6988 | [oe-packages] |
| 6989 | baseurl=http://my.server/rpm/i586 http://my.server/rpm/qemux86 http://my.server/rpm/all |
| 6990 | |
| 6991 | This example |
| 6992 | informs DNF about individual package databases for all three |
| 6993 | architectures. |
| 6994 | |
| 6995 | - *Create a Single (Full) Package Index:* Define a single base URL that |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 6996 | identifies where a full package database is located:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 6997 | |
| 6998 | [oe-packages] |
| 6999 | baseurl=http://my.server/rpm |
| 7000 | |
| 7001 | This example informs DNF about a single |
| 7002 | package database that contains all the package index information for |
| 7003 | all supported architectures. |
| 7004 | |
| 7005 | Once you have informed DNF where to find the package databases, you need |
| 7006 | to fetch them: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7007 | |
| 7008 | .. code-block:: none |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7009 | |
| 7010 | # dnf makecache |
| 7011 | |
| 7012 | DNF is now able to find, install, and |
| 7013 | upgrade packages from the specified repository or repositories. |
| 7014 | |
| 7015 | .. note:: |
| 7016 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7017 | See the `DNF documentation <https://dnf.readthedocs.io/en/latest/>`__ for |
| 7018 | additional information. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7019 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7020 | Using IPK |
| 7021 | ^^^^^^^^^ |
| 7022 | |
| 7023 | The ``opkg`` application performs runtime package management of IPK |
| 7024 | packages. You must perform an initial setup for ``opkg`` on the target |
| 7025 | machine if the |
| 7026 | :term:`PACKAGE_FEED_ARCHS`, |
| 7027 | :term:`PACKAGE_FEED_BASE_PATHS`, |
| 7028 | and |
| 7029 | :term:`PACKAGE_FEED_URIS` |
| 7030 | variables have not been set or the target image was built before the |
| 7031 | variables were set. |
| 7032 | |
| 7033 | The ``opkg`` application uses configuration files to find available |
| 7034 | package databases. Thus, you need to create a configuration file inside |
| 7035 | the ``/etc/opkg/`` direction, which informs ``opkg`` of any repository |
| 7036 | you want to use. |
| 7037 | |
| 7038 | As an example, suppose you are serving packages from a ``ipk/`` |
| 7039 | directory containing the ``i586``, ``all``, and ``qemux86`` databases |
| 7040 | through an HTTP server named ``my.server``. On the target, create a |
| 7041 | configuration file (e.g. ``my_repo.conf``) inside the ``/etc/opkg/`` |
| 7042 | directory containing the following: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7043 | |
| 7044 | .. code-block:: none |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7045 | |
| 7046 | src/gz all http://my.server/ipk/all |
| 7047 | src/gz i586 http://my.server/ipk/i586 |
| 7048 | src/gz qemux86 http://my.server/ipk/qemux86 |
| 7049 | |
| 7050 | Next, instruct ``opkg`` to fetch the |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7051 | repository information: |
| 7052 | |
| 7053 | .. code-block:: none |
| 7054 | |
| 7055 | # opkg update |
| 7056 | |
| 7057 | The ``opkg`` application is now able to find, install, and upgrade packages |
| 7058 | from the specified repository. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7059 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7060 | Using DEB |
| 7061 | ^^^^^^^^^ |
| 7062 | |
| 7063 | The ``apt`` application performs runtime package management of DEB |
| 7064 | packages. This application uses a source list file to find available |
| 7065 | package databases. You must perform an initial setup for ``apt`` on the |
| 7066 | target machine if the |
| 7067 | :term:`PACKAGE_FEED_ARCHS`, |
| 7068 | :term:`PACKAGE_FEED_BASE_PATHS`, |
| 7069 | and |
| 7070 | :term:`PACKAGE_FEED_URIS` |
| 7071 | variables have not been set or the target image was built before the |
| 7072 | variables were set. |
| 7073 | |
| 7074 | To inform ``apt`` of the repository you want to use, you might create a |
| 7075 | list file (e.g. ``my_repo.list``) inside the |
| 7076 | ``/etc/apt/sources.list.d/`` directory. As an example, suppose you are |
| 7077 | serving packages from a ``deb/`` directory containing the ``i586``, |
| 7078 | ``all``, and ``qemux86`` databases through an HTTP server named |
| 7079 | ``my.server``. The list file should contain: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7080 | |
| 7081 | .. code-block:: none |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7082 | |
| 7083 | deb http://my.server/deb/all ./ |
| 7084 | deb http://my.server/deb/i586 ./ |
| 7085 | deb http://my.server/deb/qemux86 ./ |
| 7086 | |
| 7087 | Next, instruct the ``apt`` application |
| 7088 | to fetch the repository information: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7089 | |
| 7090 | .. code-block:: none |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7091 | |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 7092 | $ sudo apt update |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7093 | |
| 7094 | After this step, |
| 7095 | ``apt`` is able to find, install, and upgrade packages from the |
| 7096 | specified repository. |
| 7097 | |
| 7098 | Generating and Using Signed Packages |
| 7099 | ------------------------------------ |
| 7100 | |
| 7101 | In order to add security to RPM packages used during a build, you can |
| 7102 | take steps to securely sign them. Once a signature is verified, the |
| 7103 | OpenEmbedded build system can use the package in the build. If security |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 7104 | fails for a signed package, the build system stops the build. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7105 | |
| 7106 | This section describes how to sign RPM packages during a build and how |
| 7107 | to use signed package feeds (repositories) when doing a build. |
| 7108 | |
| 7109 | Signing RPM Packages |
| 7110 | ~~~~~~~~~~~~~~~~~~~~ |
| 7111 | |
| 7112 | To enable signing RPM packages, you must set up the following |
| 7113 | configurations in either your ``local.config`` or ``distro.config`` |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 7114 | file:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7115 | |
| 7116 | # Inherit sign_rpm.bbclass to enable signing functionality |
| 7117 | INHERIT += " sign_rpm" |
| 7118 | # Define the GPG key that will be used for signing. |
| 7119 | RPM_GPG_NAME = "key_name" |
| 7120 | # Provide passphrase for the key |
| 7121 | RPM_GPG_PASSPHRASE = "passphrase" |
| 7122 | |
| 7123 | .. note:: |
| 7124 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7125 | Be sure to supply appropriate values for both `key_name` and |
| 7126 | `passphrase`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7127 | |
| 7128 | Aside from the ``RPM_GPG_NAME`` and ``RPM_GPG_PASSPHRASE`` variables in |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 7129 | the previous example, two optional variables related to signing are available: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7130 | |
| 7131 | - *GPG_BIN:* Specifies a ``gpg`` binary/wrapper that is executed |
| 7132 | when the package is signed. |
| 7133 | |
| 7134 | - *GPG_PATH:* Specifies the ``gpg`` home directory used when the |
| 7135 | package is signed. |
| 7136 | |
| 7137 | Processing Package Feeds |
| 7138 | ~~~~~~~~~~~~~~~~~~~~~~~~ |
| 7139 | |
| 7140 | In addition to being able to sign RPM packages, you can also enable |
| 7141 | signed package feeds for IPK and RPM packages. |
| 7142 | |
| 7143 | The steps you need to take to enable signed package feed use are similar |
| 7144 | to the steps used to sign RPM packages. You must define the following in |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 7145 | your ``local.config`` or ``distro.config`` file:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7146 | |
| 7147 | INHERIT += "sign_package_feed" |
| 7148 | PACKAGE_FEED_GPG_NAME = "key_name" |
| 7149 | PACKAGE_FEED_GPG_PASSPHRASE_FILE = "path_to_file_containing_passphrase" |
| 7150 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 7151 | For signed package feeds, the passphrase must be specified in a separate file, |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7152 | which is pointed to by the ``PACKAGE_FEED_GPG_PASSPHRASE_FILE`` |
| 7153 | variable. Regarding security, keeping a plain text passphrase out of the |
| 7154 | configuration is more secure. |
| 7155 | |
| 7156 | Aside from the ``PACKAGE_FEED_GPG_NAME`` and |
| 7157 | ``PACKAGE_FEED_GPG_PASSPHRASE_FILE`` variables, three optional variables |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 7158 | related to signed package feeds are available: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7159 | |
| 7160 | - *GPG_BIN* Specifies a ``gpg`` binary/wrapper that is executed |
| 7161 | when the package is signed. |
| 7162 | |
| 7163 | - *GPG_PATH:* Specifies the ``gpg`` home directory used when the |
| 7164 | package is signed. |
| 7165 | |
| 7166 | - *PACKAGE_FEED_GPG_SIGNATURE_TYPE:* Specifies the type of ``gpg`` |
| 7167 | signature. This variable applies only to RPM and IPK package feeds. |
| 7168 | Allowable values for the ``PACKAGE_FEED_GPG_SIGNATURE_TYPE`` are |
| 7169 | "ASC", which is the default and specifies ascii armored, and "BIN", |
| 7170 | which specifies binary. |
| 7171 | |
| 7172 | Testing Packages With ptest |
| 7173 | --------------------------- |
| 7174 | |
| 7175 | A Package Test (ptest) runs tests against packages built by the |
| 7176 | OpenEmbedded build system on the target machine. A ptest contains at |
| 7177 | least two items: the actual test, and a shell script (``run-ptest``) |
| 7178 | that starts the test. The shell script that starts the test must not |
| 7179 | contain the actual test - the script only starts the test. On the other |
| 7180 | hand, the test can be anything from a simple shell script that runs a |
| 7181 | binary and checks the output to an elaborate system of test binaries and |
| 7182 | data files. |
| 7183 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 7184 | The test generates output in the format used by Automake:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7185 | |
| 7186 | result: testname |
| 7187 | |
| 7188 | where the result can be ``PASS``, ``FAIL``, or ``SKIP``, and |
| 7189 | the testname can be any identifying string. |
| 7190 | |
| 7191 | 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] | 7192 | see the :yocto_wiki:`Ptest </Ptest>` wiki page. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7193 | |
| 7194 | .. note:: |
| 7195 | |
| 7196 | A recipe is "ptest-enabled" if it inherits the |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7197 | :ref:`ptest <ref-classes-ptest>` class. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7198 | |
| 7199 | Adding ptest to Your Build |
| 7200 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 7201 | |
| 7202 | To add package testing to your build, add the |
| 7203 | :term:`DISTRO_FEATURES` and |
| 7204 | :term:`EXTRA_IMAGE_FEATURES` |
| 7205 | variables to your ``local.conf`` file, which is found in the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 7206 | :term:`Build Directory`:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7207 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 7208 | DISTRO_FEATURES:append = " ptest" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7209 | EXTRA_IMAGE_FEATURES += "ptest-pkgs" |
| 7210 | |
| 7211 | Once your build is complete, the ptest files are installed into the |
| 7212 | ``/usr/lib/package/ptest`` directory within the image, where ``package`` |
| 7213 | is the name of the package. |
| 7214 | |
| 7215 | Running ptest |
| 7216 | ~~~~~~~~~~~~~ |
| 7217 | |
| 7218 | The ``ptest-runner`` package installs a shell script that loops through |
| 7219 | all installed ptest test suites and runs them in sequence. Consequently, |
| 7220 | you might want to add this package to your image. |
| 7221 | |
| 7222 | Getting Your Package Ready |
| 7223 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 7224 | |
| 7225 | In order to enable a recipe to run installed ptests on target hardware, |
| 7226 | you need to prepare the recipes that build the packages you want to |
| 7227 | test. Here is what you have to do for each recipe: |
| 7228 | |
| 7229 | - *Be sure the recipe inherits |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7230 | the* :ref:`ptest <ref-classes-ptest>` *class:* |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 7231 | Include the following line in each recipe:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7232 | |
| 7233 | inherit ptest |
| 7234 | |
| 7235 | - *Create run-ptest:* This script starts your test. Locate the |
| 7236 | script where you will refer to it using |
| 7237 | :term:`SRC_URI`. Here is an |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 7238 | example that starts a test for ``dbus``:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7239 | |
| 7240 | #!/bin/sh |
| 7241 | cd test |
| 7242 | make -k runtest-TESTS |
| 7243 | |
| 7244 | - *Ensure dependencies are met:* If the test adds build or runtime |
| 7245 | dependencies that normally do not exist for the package (such as |
| 7246 | requiring "make" to run the test suite), use the |
| 7247 | :term:`DEPENDS` and |
| 7248 | :term:`RDEPENDS` variables in |
| 7249 | your recipe in order for the package to meet the dependencies. Here |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 7250 | is an example where the package has a runtime dependency on "make":: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7251 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 7252 | RDEPENDS:${PN}-ptest += "make" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7253 | |
| 7254 | - *Add a function to build the test suite:* Not many packages support |
| 7255 | cross-compilation of their test suites. Consequently, you usually |
| 7256 | need to add a cross-compilation function to the package. |
| 7257 | |
| 7258 | Many packages based on Automake compile and run the test suite by |
| 7259 | using a single command such as ``make check``. However, the host |
| 7260 | ``make check`` builds and runs on the same computer, while |
| 7261 | cross-compiling requires that the package is built on the host but |
| 7262 | executed for the target architecture (though often, as in the case |
| 7263 | for ptest, the execution occurs on the host). The built version of |
| 7264 | Automake that ships with the Yocto Project includes a patch that |
| 7265 | separates building and execution. Consequently, packages that use the |
| 7266 | unaltered, patched version of ``make check`` automatically |
| 7267 | cross-compiles. |
| 7268 | |
| 7269 | Regardless, you still must add a ``do_compile_ptest`` function to |
| 7270 | build the test suite. Add a function similar to the following to your |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 7271 | recipe:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7272 | |
| 7273 | do_compile_ptest() { |
| 7274 | oe_runmake buildtest-TESTS |
| 7275 | } |
| 7276 | |
| 7277 | - *Ensure special configurations are set:* If the package requires |
| 7278 | special configurations prior to compiling the test code, you must |
| 7279 | insert a ``do_configure_ptest`` function into the recipe. |
| 7280 | |
| 7281 | - *Install the test suite:* The ``ptest`` class automatically copies |
| 7282 | the file ``run-ptest`` to the target and then runs make |
| 7283 | ``install-ptest`` to run the tests. If this is not enough, you need |
| 7284 | to create a ``do_install_ptest`` function and make sure it gets |
| 7285 | called after the "make install-ptest" completes. |
| 7286 | |
| 7287 | Creating Node Package Manager (NPM) Packages |
| 7288 | -------------------------------------------- |
| 7289 | |
| 7290 | `NPM <https://en.wikipedia.org/wiki/Npm_(software)>`__ is a package |
| 7291 | manager for the JavaScript programming language. The Yocto Project |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 7292 | 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] | 7293 | use this fetcher in combination with |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 7294 | :doc:`devtool </ref-manual/devtool-reference>` to create |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7295 | recipes that produce NPM packages. |
| 7296 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 7297 | There are two workflows that allow you to create NPM packages using |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7298 | ``devtool``: the NPM registry modules method and the NPM project code |
| 7299 | method. |
| 7300 | |
| 7301 | .. note:: |
| 7302 | |
| 7303 | While it is possible to create NPM recipes manually, using |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7304 | ``devtool`` is far simpler. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7305 | |
| 7306 | Additionally, some requirements and caveats exist. |
| 7307 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7308 | Requirements and Caveats |
| 7309 | ~~~~~~~~~~~~~~~~~~~~~~~~ |
| 7310 | |
| 7311 | You need to be aware of the following before using ``devtool`` to create |
| 7312 | NPM packages: |
| 7313 | |
| 7314 | - Of the two methods that you can use ``devtool`` to create NPM |
| 7315 | packages, the registry approach is slightly simpler. However, you |
| 7316 | might consider the project approach because you do not have to |
| 7317 | publish your module in the NPM registry |
| 7318 | (`npm-registry <https://docs.npmjs.com/misc/registry>`_), which |
| 7319 | is NPM's public registry. |
| 7320 | |
| 7321 | - Be familiar with |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 7322 | :doc:`devtool </ref-manual/devtool-reference>`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7323 | |
| 7324 | - The NPM host tools need the native ``nodejs-npm`` package, which is |
| 7325 | part of the OpenEmbedded environment. You need to get the package by |
| 7326 | cloning the https://github.com/openembedded/meta-openembedded |
| 7327 | repository out of GitHub. Be sure to add the path to your local copy |
| 7328 | to your ``bblayers.conf`` file. |
| 7329 | |
| 7330 | - ``devtool`` cannot detect native libraries in module dependencies. |
| 7331 | Consequently, you must manually add packages to your recipe. |
| 7332 | |
| 7333 | - While deploying NPM packages, ``devtool`` cannot determine which |
| 7334 | dependent packages are missing on the target (e.g. the node runtime |
| 7335 | ``nodejs``). Consequently, you need to find out what files are |
| 7336 | missing and be sure they are on the target. |
| 7337 | |
| 7338 | - Although you might not need NPM to run your node package, it is |
| 7339 | useful to have NPM on your target. The NPM package name is |
| 7340 | ``nodejs-npm``. |
| 7341 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7342 | Using the Registry Modules Method |
| 7343 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 7344 | |
| 7345 | This section presents an example that uses the ``cute-files`` module, |
| 7346 | which is a file browser web application. |
| 7347 | |
| 7348 | .. note:: |
| 7349 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7350 | You must know the ``cute-files`` module version. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7351 | |
| 7352 | The first thing you need to do is use ``devtool`` and the NPM fetcher to |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 7353 | create the recipe:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7354 | |
| 7355 | $ devtool add "npm://registry.npmjs.org;package=cute-files;version=1.0.2" |
| 7356 | |
| 7357 | The |
| 7358 | ``devtool add`` command runs ``recipetool create`` and uses the same |
| 7359 | fetch URI to download each dependency and capture license details where |
| 7360 | possible. The result is a generated recipe. |
| 7361 | |
| 7362 | The recipe file is fairly simple and contains every license that |
| 7363 | ``recipetool`` finds and includes the licenses in the recipe's |
| 7364 | :term:`LIC_FILES_CHKSUM` |
| 7365 | variables. You need to examine the variables and look for those with |
| 7366 | "unknown" in the :term:`LICENSE` |
| 7367 | field. You need to track down the license information for "unknown" |
| 7368 | modules and manually add the information to the recipe. |
| 7369 | |
| 7370 | ``recipetool`` creates a "shrinkwrap" file for your recipe. Shrinkwrap |
| 7371 | files capture the version of all dependent modules. Many packages do not |
| 7372 | provide shrinkwrap files. ``recipetool`` create a shrinkwrap file as it |
| 7373 | runs. |
| 7374 | |
| 7375 | .. note:: |
| 7376 | |
| 7377 | A package is created for each sub-module. This policy is the only |
| 7378 | practical way to have the licenses for all of the dependencies |
| 7379 | represented in the license manifest of the image. |
| 7380 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 7381 | The ``devtool edit-recipe`` command lets you take a look at the recipe:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7382 | |
| 7383 | $ devtool edit-recipe cute-files |
| 7384 | SUMMARY = "Turn any folder on your computer into a cute file browser, available on the local network." |
| 7385 | LICENSE = "MIT & ISC & Unknown" |
| 7386 | LIC_FILES_CHKSUM = "file://LICENSE;md5=71d98c0a1db42956787b1909c74a86ca \ |
| 7387 | file://node_modules/toidentifier/LICENSE;md5=1a261071a044d02eb6f2bb47f51a3502 \ |
| 7388 | file://node_modules/debug/LICENSE;md5=ddd815a475e7338b0be7a14d8ee35a99 \ |
| 7389 | ... |
| 7390 | SRC_URI = " \ |
| 7391 | npm://registry.npmjs.org/;package=cute-files;version=${PV} \ |
| 7392 | npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \ |
| 7393 | " |
| 7394 | S = "${WORKDIR}/npm" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 7395 | inherit npm |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 7396 | LICENSE:${PN} = "MIT" |
| 7397 | LICENSE:${PN}-accepts = "MIT" |
| 7398 | LICENSE:${PN}-array-flatten = "MIT" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7399 | ... |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 7400 | LICENSE:${PN}-vary = "MIT" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7401 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 7402 | Here are three key points in the previous example: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7403 | |
| 7404 | - :term:`SRC_URI` uses the NPM |
| 7405 | scheme so that the NPM fetcher is used. |
| 7406 | |
| 7407 | - ``recipetool`` collects all the license information. If a |
| 7408 | sub-module's license is unavailable, the sub-module's name appears in |
| 7409 | the comments. |
| 7410 | |
| 7411 | - The ``inherit npm`` statement causes the |
| 7412 | :ref:`npm <ref-classes-npm>` class to package |
| 7413 | up all the modules. |
| 7414 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 7415 | You can run the following command to build the ``cute-files`` package:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7416 | |
| 7417 | $ devtool build cute-files |
| 7418 | |
| 7419 | Remember that ``nodejs`` must be installed on |
| 7420 | the target before your package. |
| 7421 | |
| 7422 | Assuming 192.168.7.2 for the target's IP address, use the following |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 7423 | command to deploy your package:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7424 | |
| 7425 | $ devtool deploy-target -s cute-files root@192.168.7.2 |
| 7426 | |
| 7427 | Once the package is installed on the target, you can |
| 7428 | test the application: |
| 7429 | |
| 7430 | .. note:: |
| 7431 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7432 | Because of a known issue, you cannot simply run ``cute-files`` as you would |
| 7433 | if you had run ``npm install``. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7434 | |
| 7435 | :: |
| 7436 | |
| 7437 | $ cd /usr/lib/node_modules/cute-files |
| 7438 | $ node cute-files.js |
| 7439 | |
| 7440 | On a browser, |
| 7441 | go to ``http://192.168.7.2:3000`` and you see the following: |
| 7442 | |
| 7443 | .. image:: figures/cute-files-npm-example.png |
| 7444 | :align: center |
| 7445 | |
| 7446 | You can find the recipe in ``workspace/recipes/cute-files``. You can use |
| 7447 | the recipe in any layer you choose. |
| 7448 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7449 | Using the NPM Projects Code Method |
| 7450 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 7451 | |
| 7452 | Although it is useful to package modules already in the NPM registry, |
| 7453 | adding ``node.js`` projects under development is a more common developer |
| 7454 | use case. |
| 7455 | |
| 7456 | This section covers the NPM projects code method, which is very similar |
| 7457 | to the "registry" approach described in the previous section. In the NPM |
| 7458 | projects method, you provide ``devtool`` with an URL that points to the |
| 7459 | source files. |
| 7460 | |
| 7461 | Replicating the same example, (i.e. ``cute-files``) use the following |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 7462 | command:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7463 | |
| 7464 | $ devtool add https://github.com/martinaglv/cute-files.git |
| 7465 | |
| 7466 | The |
| 7467 | recipe this command generates is very similar to the recipe created in |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 7468 | the previous section. However, the :term:`SRC_URI` looks like the following:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7469 | |
| 7470 | SRC_URI = " \ |
| 7471 | git://github.com/martinaglv/cute-files.git;protocol=https \ |
| 7472 | npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \ |
| 7473 | " |
| 7474 | |
| 7475 | In this example, |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7476 | the main module is taken from the Git repository and dependencies are |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7477 | taken from the NPM registry. Other than those differences, the recipe is |
| 7478 | basically the same between the two methods. You can build and deploy the |
| 7479 | package exactly as described in the previous section that uses the |
| 7480 | registry modules method. |
| 7481 | |
| 7482 | Adding custom metadata to packages |
| 7483 | ---------------------------------- |
| 7484 | |
| 7485 | The variable |
| 7486 | :term:`PACKAGE_ADD_METADATA` |
| 7487 | can be used to add additional metadata to packages. This is reflected in |
| 7488 | the package control/spec file. To take the ipk format for example, the |
| 7489 | CONTROL file stored inside would contain the additional metadata as |
| 7490 | additional lines. |
| 7491 | |
| 7492 | The variable can be used in multiple ways, including using suffixes to |
| 7493 | set it for a specific package type and/or package. Note that the order |
| 7494 | of precedence is the same as this list: |
| 7495 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 7496 | - ``PACKAGE_ADD_METADATA_<PKGTYPE>:<PN>`` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7497 | |
| 7498 | - ``PACKAGE_ADD_METADATA_<PKGTYPE>`` |
| 7499 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 7500 | - ``PACKAGE_ADD_METADATA:<PN>`` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7501 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 7502 | - :term:`PACKAGE_ADD_METADATA` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7503 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7504 | `<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] | 7505 | package type: |
| 7506 | |
| 7507 | - IPK for .ipk packages |
| 7508 | |
| 7509 | - DEB for .deb packages |
| 7510 | |
| 7511 | - RPM for .rpm packages |
| 7512 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7513 | `<PN>` is a parameter and expected to be a package name. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7514 | |
| 7515 | The variable can contain multiple [one-line] metadata fields separated |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7516 | by the literal sequence '\\n'. The separator can be redefined using the |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7517 | variable flag ``separator``. |
| 7518 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 7519 | Here is an example that adds two custom fields for ipk |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 7520 | packages:: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7521 | |
| 7522 | PACKAGE_ADD_METADATA_IPK = "Vendor: CustomIpk\nGroup:Applications/Spreadsheets" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7523 | |
| 7524 | Efficiently Fetching Source Files During a Build |
| 7525 | ================================================ |
| 7526 | |
| 7527 | The OpenEmbedded build system works with source files located through |
| 7528 | the :term:`SRC_URI` variable. When |
| 7529 | you build something using BitBake, a big part of the operation is |
| 7530 | locating and downloading all the source tarballs. For images, |
| 7531 | downloading all the source for various packages can take a significant |
| 7532 | amount of time. |
| 7533 | |
| 7534 | This section shows you how you can use mirrors to speed up fetching |
| 7535 | source files and how you can pre-fetch files all of which leads to more |
| 7536 | efficient use of resources and time. |
| 7537 | |
| 7538 | Setting up Effective Mirrors |
| 7539 | ---------------------------- |
| 7540 | |
| 7541 | A good deal that goes into a Yocto Project build is simply downloading |
| 7542 | all of the source tarballs. Maybe you have been working with another |
| 7543 | build system (OpenEmbedded or Angstrom) for which you have built up a |
| 7544 | sizable directory of source tarballs. Or, perhaps someone else has such |
| 7545 | a directory for which you have read access. If so, you can save time by |
| 7546 | adding statements to your configuration file so that the build process |
| 7547 | checks local directories first for existing tarballs before checking the |
| 7548 | Internet. |
| 7549 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 7550 | Here is an efficient way to set it up in your ``local.conf`` file:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7551 | |
| 7552 | SOURCE_MIRROR_URL ?= "file:///home/you/your-download-dir/" |
| 7553 | INHERIT += "own-mirrors" |
| 7554 | BB_GENERATE_MIRROR_TARBALLS = "1" |
| 7555 | # BB_NO_NETWORK = "1" |
| 7556 | |
| 7557 | In the previous example, the |
| 7558 | :term:`BB_GENERATE_MIRROR_TARBALLS` |
| 7559 | variable causes the OpenEmbedded build system to generate tarballs of |
| 7560 | the Git repositories and store them in the |
| 7561 | :term:`DL_DIR` directory. Due to |
| 7562 | performance reasons, generating and storing these tarballs is not the |
| 7563 | build system's default behavior. |
| 7564 | |
| 7565 | You can also use the |
| 7566 | :term:`PREMIRRORS` variable. For |
| 7567 | an example, see the variable's glossary entry in the Yocto Project |
| 7568 | Reference Manual. |
| 7569 | |
| 7570 | Getting Source Files and Suppressing the Build |
| 7571 | ---------------------------------------------- |
| 7572 | |
| 7573 | Another technique you can use to ready yourself for a successive string |
| 7574 | of build operations, is to pre-fetch all the source files without |
| 7575 | actually starting a build. This technique lets you work through any |
| 7576 | download issues and ultimately gathers all the source files into your |
| 7577 | download directory :ref:`structure-build-downloads`, |
| 7578 | which is located with :term:`DL_DIR`. |
| 7579 | |
| 7580 | Use the following BitBake command form to fetch all the necessary |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 7581 | sources without starting the build:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7582 | |
| 7583 | $ bitbake target --runall=fetch |
| 7584 | |
| 7585 | This |
| 7586 | variation of the BitBake command guarantees that you have all the |
| 7587 | sources for that BitBake target should you disconnect from the Internet |
| 7588 | and want to do the build later offline. |
| 7589 | |
| 7590 | Selecting an Initialization Manager |
| 7591 | =================================== |
| 7592 | |
| 7593 | By default, the Yocto Project uses SysVinit as the initialization |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 7594 | manager. However, there is also support for systemd, which is a full |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7595 | replacement for init with parallel starting of services, reduced shell |
| 7596 | overhead and other features that are used by many distributions. |
| 7597 | |
| 7598 | Within the system, SysVinit treats system components as services. These |
| 7599 | services are maintained as shell scripts stored in the ``/etc/init.d/`` |
| 7600 | directory. Services organize into different run levels. This |
| 7601 | organization is maintained by putting links to the services in the |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7602 | ``/etc/rcN.d/`` directories, where `N/` is one of the following options: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7603 | "S", "0", "1", "2", "3", "4", "5", or "6". |
| 7604 | |
| 7605 | .. note:: |
| 7606 | |
| 7607 | Each runlevel has a dependency on the previous runlevel. This |
| 7608 | dependency allows the services to work properly. |
| 7609 | |
| 7610 | In comparison, systemd treats components as units. Using units is a |
| 7611 | broader concept as compared to using a service. A unit includes several |
| 7612 | different types of entities. Service is one of the types of entities. |
| 7613 | The runlevel concept in SysVinit corresponds to the concept of a target |
| 7614 | in systemd, where target is also a type of supported unit. |
| 7615 | |
| 7616 | 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] | 7617 | during init and parallelization is not supported. With systemd, services |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7618 | start in parallel. Needless to say, the method can have an impact on |
| 7619 | system startup performance. |
| 7620 | |
| 7621 | If you want to use SysVinit, you do not have to do anything. But, if you |
| 7622 | want to use systemd, you must take some steps as described in the |
| 7623 | following sections. |
| 7624 | |
| 7625 | Using systemd Exclusively |
| 7626 | ------------------------- |
| 7627 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 7628 | Set these variables in your distribution configuration file as follows:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7629 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 7630 | DISTRO_FEATURES:append = " systemd" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7631 | VIRTUAL-RUNTIME_init_manager = "systemd" |
| 7632 | |
| 7633 | You can also prevent the SysVinit distribution feature from |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 7634 | being automatically enabled as follows:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7635 | |
| 7636 | DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit" |
| 7637 | |
| 7638 | Doing so removes any |
| 7639 | redundant SysVinit scripts. |
| 7640 | |
| 7641 | To remove initscripts from your image altogether, set this variable |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 7642 | also:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7643 | |
| 7644 | VIRTUAL-RUNTIME_initscripts = "" |
| 7645 | |
| 7646 | For information on the backfill variable, see |
| 7647 | :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`. |
| 7648 | |
| 7649 | Using systemd for the Main Image and Using SysVinit for the Rescue Image |
| 7650 | ------------------------------------------------------------------------ |
| 7651 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 7652 | Set these variables in your distribution configuration file as follows:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7653 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 7654 | DISTRO_FEATURES:append = " systemd" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7655 | VIRTUAL-RUNTIME_init_manager = "systemd" |
| 7656 | |
| 7657 | Doing so causes your main image to use the |
| 7658 | ``packagegroup-core-boot.bb`` recipe and systemd. The rescue/minimal |
| 7659 | image cannot use this package group. However, it can install SysVinit |
| 7660 | and the appropriate packages will have support for both systemd and |
| 7661 | SysVinit. |
| 7662 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7663 | Selecting a Device Manager |
| 7664 | ========================== |
| 7665 | |
| 7666 | The Yocto Project provides multiple ways to manage the device manager |
| 7667 | (``/dev``): |
| 7668 | |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 7669 | - Persistent and Pre-Populated ``/dev``: For this case, the ``/dev`` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7670 | directory is persistent and the required device nodes are created |
| 7671 | during the build. |
| 7672 | |
| 7673 | - Use ``devtmpfs`` with a Device Manager: For this case, the ``/dev`` |
| 7674 | directory is provided by the kernel as an in-memory file system and |
| 7675 | is automatically populated by the kernel at runtime. Additional |
| 7676 | configuration of device nodes is done in user space by a device |
| 7677 | manager like ``udev`` or ``busybox-mdev``. |
| 7678 | |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 7679 | Using Persistent and Pre-Populated ``/dev`` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7680 | -------------------------------------------- |
| 7681 | |
| 7682 | To use the static method for device population, you need to set the |
| 7683 | :term:`USE_DEVFS` variable to "0" |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 7684 | as follows:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7685 | |
| 7686 | USE_DEVFS = "0" |
| 7687 | |
| 7688 | The content of the resulting ``/dev`` directory is defined in a Device |
| 7689 | Table file. The |
| 7690 | :term:`IMAGE_DEVICE_TABLES` |
| 7691 | variable defines the Device Table to use and should be set in the |
| 7692 | machine or distro configuration file. Alternatively, you can set this |
| 7693 | variable in your ``local.conf`` configuration file. |
| 7694 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 7695 | If you do not define the :term:`IMAGE_DEVICE_TABLES` variable, the default |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 7696 | ``device_table-minimal.txt`` is used:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7697 | |
| 7698 | IMAGE_DEVICE_TABLES = "device_table-mymachine.txt" |
| 7699 | |
| 7700 | The population is handled by the ``makedevs`` utility during image |
| 7701 | creation: |
| 7702 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7703 | Using ``devtmpfs`` and a Device Manager |
| 7704 | --------------------------------------- |
| 7705 | |
| 7706 | To use the dynamic method for device population, you need to use (or be |
| 7707 | sure to set) the :term:`USE_DEVFS` |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 7708 | variable to "1", which is the default:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7709 | |
| 7710 | USE_DEVFS = "1" |
| 7711 | |
| 7712 | With this |
| 7713 | setting, the resulting ``/dev`` directory is populated by the kernel |
| 7714 | using ``devtmpfs``. Make sure the corresponding kernel configuration |
| 7715 | variable ``CONFIG_DEVTMPFS`` is set when building you build a Linux |
| 7716 | kernel. |
| 7717 | |
| 7718 | All devices created by ``devtmpfs`` will be owned by ``root`` and have |
| 7719 | permissions ``0600``. |
| 7720 | |
| 7721 | To have more control over the device nodes, you can use a device manager |
| 7722 | like ``udev`` or ``busybox-mdev``. You choose the device manager by |
| 7723 | defining the ``VIRTUAL-RUNTIME_dev_manager`` variable in your machine or |
| 7724 | distro configuration file. Alternatively, you can set this variable in |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 7725 | your ``local.conf`` configuration file:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7726 | |
| 7727 | VIRTUAL-RUNTIME_dev_manager = "udev" |
| 7728 | |
| 7729 | # Some alternative values |
| 7730 | # VIRTUAL-RUNTIME_dev_manager = "busybox-mdev" |
| 7731 | # VIRTUAL-RUNTIME_dev_manager = "systemd" |
| 7732 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7733 | Using an External SCM |
| 7734 | ===================== |
| 7735 | |
| 7736 | If you're working on a recipe that pulls from an external Source Code |
| 7737 | Manager (SCM), it is possible to have the OpenEmbedded build system |
| 7738 | notice new recipe changes added to the SCM and then build the resulting |
| 7739 | packages that depend on the new recipes by using the latest versions. |
| 7740 | This only works for SCMs from which it is possible to get a sensible |
| 7741 | revision number for changes. Currently, you can do this with Apache |
| 7742 | Subversion (SVN), Git, and Bazaar (BZR) repositories. |
| 7743 | |
| 7744 | To enable this behavior, the :term:`PV` of |
| 7745 | the recipe needs to reference |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 7746 | :term:`SRCPV`. Here is an example:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7747 | |
| 7748 | PV = "1.2.3+git${SRCPV}" |
| 7749 | |
| 7750 | Then, you can add the following to your |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 7751 | ``local.conf``:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7752 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 7753 | SRCREV:pn-PN = "${AUTOREV}" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7754 | |
| 7755 | :term:`PN` is the name of the recipe for |
| 7756 | which you want to enable automatic source revision updating. |
| 7757 | |
| 7758 | If you do not want to update your local configuration file, you can add |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 7759 | the following directly to the recipe to finish enabling the feature:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7760 | |
| 7761 | SRCREV = "${AUTOREV}" |
| 7762 | |
| 7763 | The Yocto Project provides a distribution named ``poky-bleeding``, whose |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 7764 | configuration file contains the line:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7765 | |
| 7766 | require conf/distro/include/poky-floating-revisions.inc |
| 7767 | |
| 7768 | This line pulls in the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 7769 | listed include file that contains numerous lines of exactly that form:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7770 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 7771 | #SRCREV:pn-opkg-native ?= "${AUTOREV}" |
| 7772 | #SRCREV:pn-opkg-sdk ?= "${AUTOREV}" |
| 7773 | #SRCREV:pn-opkg ?= "${AUTOREV}" |
| 7774 | #SRCREV:pn-opkg-utils-native ?= "${AUTOREV}" |
| 7775 | #SRCREV:pn-opkg-utils ?= "${AUTOREV}" |
| 7776 | SRCREV:pn-gconf-dbus ?= "${AUTOREV}" |
| 7777 | SRCREV:pn-matchbox-common ?= "${AUTOREV}" |
| 7778 | SRCREV:pn-matchbox-config-gtk ?= "${AUTOREV}" |
| 7779 | SRCREV:pn-matchbox-desktop ?= "${AUTOREV}" |
| 7780 | SRCREV:pn-matchbox-keyboard ?= "${AUTOREV}" |
| 7781 | SRCREV:pn-matchbox-panel-2 ?= "${AUTOREV}" |
| 7782 | SRCREV:pn-matchbox-themes-extra ?= "${AUTOREV}" |
| 7783 | SRCREV:pn-matchbox-terminal ?= "${AUTOREV}" |
| 7784 | SRCREV:pn-matchbox-wm ?= "${AUTOREV}" |
| 7785 | SRCREV:pn-settings-daemon ?= "${AUTOREV}" |
| 7786 | SRCREV:pn-screenshot ?= "${AUTOREV}" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7787 | . . . |
| 7788 | |
| 7789 | These lines allow you to |
| 7790 | experiment with building a distribution that tracks the latest |
| 7791 | development source for numerous packages. |
| 7792 | |
| 7793 | .. note:: |
| 7794 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7795 | The ``poky-bleeding`` distribution is not tested on a regular basis. Keep |
| 7796 | this in mind if you use it. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7797 | |
| 7798 | Creating a Read-Only Root Filesystem |
| 7799 | ==================================== |
| 7800 | |
| 7801 | Suppose, for security reasons, you need to disable your target device's |
| 7802 | root filesystem's write permissions (i.e. you need a read-only root |
| 7803 | filesystem). Or, perhaps you are running the device's operating system |
| 7804 | from a read-only storage device. For either case, you can customize your |
| 7805 | image for that behavior. |
| 7806 | |
| 7807 | .. note:: |
| 7808 | |
| 7809 | Supporting a read-only root filesystem requires that the system and |
| 7810 | applications do not try to write to the root filesystem. You must |
| 7811 | configure all parts of the target system to write elsewhere, or to |
| 7812 | gracefully fail in the event of attempting to write to the root |
| 7813 | filesystem. |
| 7814 | |
| 7815 | Creating the Root Filesystem |
| 7816 | ---------------------------- |
| 7817 | |
| 7818 | To create the read-only root filesystem, simply add the |
| 7819 | "read-only-rootfs" feature to your image, normally in one of two ways. |
| 7820 | The first way is to add the "read-only-rootfs" image feature in the |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 7821 | image's recipe file via the :term:`IMAGE_FEATURES` variable:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7822 | |
| 7823 | IMAGE_FEATURES += "read-only-rootfs" |
| 7824 | |
| 7825 | As an alternative, you can add the same feature |
| 7826 | from within your build directory's ``local.conf`` file with the |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 7827 | associated :term:`EXTRA_IMAGE_FEATURES` variable, as in:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7828 | |
| 7829 | EXTRA_IMAGE_FEATURES = "read-only-rootfs" |
| 7830 | |
| 7831 | For more information on how to use these variables, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 7832 | ":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] | 7833 | section. For information on the variables, see |
| 7834 | :term:`IMAGE_FEATURES` and |
| 7835 | :term:`EXTRA_IMAGE_FEATURES`. |
| 7836 | |
| 7837 | Post-Installation Scripts and Read-Only Root Filesystem |
| 7838 | ------------------------------------------------------- |
| 7839 | |
| 7840 | It is very important that you make sure all post-Installation |
| 7841 | (``pkg_postinst``) scripts for packages that are installed into the |
| 7842 | image can be run at the time when the root filesystem is created during |
| 7843 | the build on the host system. These scripts cannot attempt to run during |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 7844 | the first boot on the target device. With the "read-only-rootfs" feature |
| 7845 | enabled, the build system makes sure that all post-installation scripts |
| 7846 | succeed at file system creation time. If any of these scripts |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7847 | still need to be run after the root filesystem is created, the build |
| 7848 | immediately fails. These build-time checks ensure that the build fails |
| 7849 | rather than the target device fails later during its initial boot |
| 7850 | operation. |
| 7851 | |
| 7852 | Most of the common post-installation scripts generated by the build |
| 7853 | system for the out-of-the-box Yocto Project are engineered so that they |
| 7854 | can run during root filesystem creation (e.g. post-installation scripts |
| 7855 | for caching fonts). However, if you create and add custom scripts, you |
| 7856 | need to be sure they can be run during this file system creation. |
| 7857 | |
| 7858 | Here are some common problems that prevent post-installation scripts |
| 7859 | from running during root filesystem creation: |
| 7860 | |
| 7861 | - *Not using $D in front of absolute paths:* The build system defines |
| 7862 | ``$``\ :term:`D` when the root |
| 7863 | filesystem is created. Furthermore, ``$D`` is blank when the script |
| 7864 | is run on the target device. This implies two purposes for ``$D``: |
| 7865 | ensuring paths are valid in both the host and target environments, |
| 7866 | and checking to determine which environment is being used as a method |
| 7867 | for taking appropriate actions. |
| 7868 | |
| 7869 | - *Attempting to run processes that are specific to or dependent on the |
| 7870 | target architecture:* You can work around these attempts by using |
| 7871 | native tools, which run on the host system, to accomplish the same |
| 7872 | tasks, or by alternatively running the processes under QEMU, which |
| 7873 | has the ``qemu_run_binary`` function. For more information, see the |
| 7874 | :ref:`qemu <ref-classes-qemu>` class. |
| 7875 | |
| 7876 | Areas With Write Access |
| 7877 | ----------------------- |
| 7878 | |
| 7879 | With the "read-only-rootfs" feature enabled, any attempt by the target |
| 7880 | to write to the root filesystem at runtime fails. Consequently, you must |
| 7881 | make sure that you configure processes and applications that attempt |
| 7882 | these types of writes do so to directories with write access (e.g. |
| 7883 | ``/tmp`` or ``/var/run``). |
| 7884 | |
| 7885 | Maintaining Build Output Quality |
| 7886 | ================================ |
| 7887 | |
| 7888 | Many factors can influence the quality of a build. For example, if you |
| 7889 | upgrade a recipe to use a new version of an upstream software package or |
| 7890 | you experiment with some new configuration options, subtle changes can |
| 7891 | occur that you might not detect until later. Consider the case where |
| 7892 | your recipe is using a newer version of an upstream package. In this |
| 7893 | case, a new version of a piece of software might introduce an optional |
| 7894 | dependency on another library, which is auto-detected. If that library |
| 7895 | has already been built when the software is building, the software will |
| 7896 | link to the built library and that library will be pulled into your |
| 7897 | image along with the new software even if you did not want the library. |
| 7898 | |
| 7899 | The :ref:`buildhistory <ref-classes-buildhistory>` |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 7900 | class helps you maintain the quality of your build output. You |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7901 | can use the class to highlight unexpected and possibly unwanted changes |
| 7902 | in the build output. When you enable build history, it records |
| 7903 | information about the contents of each package and image and then |
| 7904 | commits that information to a local Git repository where you can examine |
| 7905 | the information. |
| 7906 | |
| 7907 | The remainder of this section describes the following: |
| 7908 | |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 7909 | - :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] | 7910 | |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 7911 | - :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] | 7912 | |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 7913 | - :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] | 7914 | |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 7915 | - :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] | 7916 | |
| 7917 | Enabling and Disabling Build History |
| 7918 | ------------------------------------ |
| 7919 | |
| 7920 | Build history is disabled by default. To enable it, add the following |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 7921 | :term:`INHERIT` statement and set the |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7922 | :term:`BUILDHISTORY_COMMIT` |
| 7923 | variable to "1" at the end of your ``conf/local.conf`` file found in the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 7924 | :term:`Build Directory`:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7925 | |
| 7926 | INHERIT += "buildhistory" |
| 7927 | BUILDHISTORY_COMMIT = "1" |
| 7928 | |
| 7929 | Enabling build history as |
| 7930 | previously described causes the OpenEmbedded build system to collect |
| 7931 | 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] | 7932 | :ref:`overview-manual/development-environment:git` repository. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7933 | |
| 7934 | .. note:: |
| 7935 | |
| 7936 | Enabling build history increases your build times slightly, |
| 7937 | particularly for images, and increases the amount of disk space used |
| 7938 | during the build. |
| 7939 | |
| 7940 | You can disable build history by removing the previous statements from |
| 7941 | your ``conf/local.conf`` file. |
| 7942 | |
| 7943 | Understanding What the Build History Contains |
| 7944 | --------------------------------------------- |
| 7945 | |
| 7946 | Build history information is kept in |
| 7947 | ``${``\ :term:`TOPDIR`\ ``}/buildhistory`` |
| 7948 | in the Build Directory as defined by the |
| 7949 | :term:`BUILDHISTORY_DIR` |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 7950 | variable. Here is an example abbreviated listing: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7951 | |
| 7952 | .. image:: figures/buildhistory.png |
| 7953 | :align: center |
| 7954 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 7955 | At the top level, there is a ``metadata-revs`` file that lists the |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7956 | revisions of the repositories for the enabled layers when the build was |
| 7957 | produced. The rest of the data splits into separate ``packages``, |
| 7958 | ``images`` and ``sdk`` directories, the contents of which are described |
| 7959 | as follows. |
| 7960 | |
| 7961 | Build History Package Information |
| 7962 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 7963 | |
| 7964 | The history for each package contains a text file that has name-value |
| 7965 | pairs with information about the package. For example, |
| 7966 | ``buildhistory/packages/i586-poky-linux/busybox/busybox/latest`` |
| 7967 | contains the following: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7968 | |
| 7969 | .. code-block:: none |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7970 | |
| 7971 | PV = 1.22.1 |
| 7972 | PR = r32 |
| 7973 | RPROVIDES = |
| 7974 | RDEPENDS = glibc (>= 2.20) update-alternatives-opkg |
| 7975 | RRECOMMENDS = busybox-syslog busybox-udhcpc update-rc.d |
| 7976 | PKGSIZE = 540168 |
| 7977 | FILES = /usr/bin/* /usr/sbin/* /usr/lib/busybox/* /usr/lib/lib*.so.* \ |
| 7978 | /etc /com /var /bin/* /sbin/* /lib/*.so.* /lib/udev/rules.d \ |
| 7979 | /usr/lib/udev/rules.d /usr/share/busybox /usr/lib/busybox/* \ |
| 7980 | /usr/share/pixmaps /usr/share/applications /usr/share/idl \ |
| 7981 | /usr/share/omf /usr/share/sounds /usr/lib/bonobo/servers |
| 7982 | FILELIST = /bin/busybox /bin/busybox.nosuid /bin/busybox.suid /bin/sh \ |
| 7983 | /etc/busybox.links.nosuid /etc/busybox.links.suid |
| 7984 | |
| 7985 | Most of these |
| 7986 | name-value pairs correspond to variables used to produce the package. |
| 7987 | The exceptions are ``FILELIST``, which is the actual list of files in |
| 7988 | the package, and ``PKGSIZE``, which is the total size of files in the |
| 7989 | package in bytes. |
| 7990 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 7991 | There is also a file that corresponds to the recipe from which the package |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7992 | came (e.g. ``buildhistory/packages/i586-poky-linux/busybox/latest``): |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 7993 | |
| 7994 | .. code-block:: none |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 7995 | |
| 7996 | PV = 1.22.1 |
| 7997 | PR = r32 |
| 7998 | DEPENDS = initscripts kern-tools-native update-rc.d-native \ |
| 7999 | virtual/i586-poky-linux-compilerlibs virtual/i586-poky-linux-gcc \ |
| 8000 | virtual/libc virtual/update-alternatives |
| 8001 | PACKAGES = busybox-ptest busybox-httpd busybox-udhcpd busybox-udhcpc \ |
| 8002 | busybox-syslog busybox-mdev busybox-hwclock busybox-dbg \ |
| 8003 | busybox-staticdev busybox-dev busybox-doc busybox-locale busybox |
| 8004 | |
| 8005 | Finally, for those recipes fetched from a version control system (e.g., |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 8006 | Git), there is a file that lists source revisions that are specified in |
| 8007 | the recipe and the actual revisions used during the build. Listed |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8008 | and actual revisions might differ when |
| 8009 | :term:`SRCREV` is set to |
| 8010 | ${:term:`AUTOREV`}. Here is an |
| 8011 | example assuming |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 8012 | ``buildhistory/packages/qemux86-poky-linux/linux-yocto/latest_srcrev``):: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8013 | |
| 8014 | # SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1" |
| 8015 | SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1" |
| 8016 | # SRCREV_meta = "a227f20eff056e511d504b2e490f3774ab260d6f" |
| 8017 | SRCREV_meta ="a227f20eff056e511d504b2e490f3774ab260d6f" |
| 8018 | |
| 8019 | You can use the |
| 8020 | ``buildhistory-collect-srcrevs`` command with the ``-a`` option to |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 8021 | collect the stored :term:`SRCREV` values from build history and report them |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8022 | in a format suitable for use in global configuration (e.g., |
| 8023 | ``local.conf`` or a distro include file) to override floating |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 8024 | :term:`AUTOREV` values to a fixed set of revisions. Here is some example |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 8025 | output from this command:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8026 | |
| 8027 | $ buildhistory-collect-srcrevs -a |
| 8028 | # i586-poky-linux |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 8029 | SRCREV:pn-glibc = "b8079dd0d360648e4e8de48656c5c38972621072" |
| 8030 | SRCREV:pn-glibc-initial = "b8079dd0d360648e4e8de48656c5c38972621072" |
| 8031 | SRCREV:pn-opkg-utils = "53274f087565fd45d8452c5367997ba6a682a37a" |
| 8032 | SRCREV:pn-kmod = "fd56638aed3fe147015bfa10ed4a5f7491303cb4" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8033 | # x86_64-linux |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 8034 | SRCREV:pn-gtk-doc-stub-native = "1dea266593edb766d6d898c79451ef193eb17cfa" |
| 8035 | SRCREV:pn-dtc-native = "65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf" |
| 8036 | SRCREV:pn-update-rc.d-native = "eca680ddf28d024954895f59a241a622dd575c11" |
| 8037 | SRCREV_glibc:pn-cross-localedef-native = "b8079dd0d360648e4e8de48656c5c38972621072" |
| 8038 | SRCREV_localedef:pn-cross-localedef-native = "c833367348d39dad7ba018990bfdaffaec8e9ed3" |
| 8039 | SRCREV:pn-prelink-native = "faa069deec99bf61418d0bab831c83d7c1b797ca" |
| 8040 | SRCREV:pn-opkg-utils-native = "53274f087565fd45d8452c5367997ba6a682a37a" |
| 8041 | SRCREV:pn-kern-tools-native = "23345b8846fe4bd167efdf1bd8a1224b2ba9a5ff" |
| 8042 | SRCREV:pn-kmod-native = "fd56638aed3fe147015bfa10ed4a5f7491303cb4" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8043 | # qemux86-poky-linux |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 8044 | SRCREV_machine:pn-linux-yocto = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1" |
| 8045 | SRCREV_meta:pn-linux-yocto = "a227f20eff056e511d504b2e490f3774ab260d6f" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8046 | # all-poky-linux |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 8047 | SRCREV:pn-update-rc.d = "eca680ddf28d024954895f59a241a622dd575c11" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8048 | |
| 8049 | .. note:: |
| 8050 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8051 | Here are some notes on using the ``buildhistory-collect-srcrevs`` command: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8052 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 8053 | - By default, only values where the :term:`SRCREV` was not hardcoded |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 8054 | (usually when :term:`AUTOREV` is used) are reported. Use the ``-a`` |
| 8055 | option to see all :term:`SRCREV` values. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8056 | |
| 8057 | - The output statements might not have any effect if overrides are |
| 8058 | applied elsewhere in the build system configuration. Use the |
| 8059 | ``-f`` option to add the ``forcevariable`` override to each output |
| 8060 | line if you need to work around this restriction. |
| 8061 | |
| 8062 | - The script does apply special handling when building for multiple |
| 8063 | machines. However, the script does place a comment before each set |
| 8064 | of values that specifies which triplet to which they belong as |
| 8065 | previously shown (e.g., ``i586-poky-linux``). |
| 8066 | |
| 8067 | Build History Image Information |
| 8068 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 8069 | |
| 8070 | The files produced for each image are as follows: |
| 8071 | |
| 8072 | - ``image-files:`` A directory containing selected files from the root |
| 8073 | filesystem. The files are defined by |
| 8074 | :term:`BUILDHISTORY_IMAGE_FILES`. |
| 8075 | |
| 8076 | - ``build-id.txt:`` Human-readable information about the build |
| 8077 | configuration and metadata source revisions. This file contains the |
| 8078 | full build header as printed by BitBake. |
| 8079 | |
| 8080 | - ``*.dot:`` Dependency graphs for the image that are compatible with |
| 8081 | ``graphviz``. |
| 8082 | |
| 8083 | - ``files-in-image.txt:`` A list of files in the image with |
| 8084 | permissions, owner, group, size, and symlink information. |
| 8085 | |
| 8086 | - ``image-info.txt:`` A text file containing name-value pairs with |
| 8087 | information about the image. See the following listing example for |
| 8088 | more information. |
| 8089 | |
| 8090 | - ``installed-package-names.txt:`` A list of installed packages by name |
| 8091 | only. |
| 8092 | |
| 8093 | - ``installed-package-sizes.txt:`` A list of installed packages ordered |
| 8094 | by size. |
| 8095 | |
| 8096 | - ``installed-packages.txt:`` A list of installed packages with full |
| 8097 | package filenames. |
| 8098 | |
| 8099 | .. note:: |
| 8100 | |
| 8101 | Installed package information is able to be gathered and produced |
| 8102 | even if package management is disabled for the final image. |
| 8103 | |
| 8104 | Here is an example of ``image-info.txt``: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8105 | |
| 8106 | .. code-block:: none |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8107 | |
| 8108 | DISTRO = poky |
| 8109 | DISTRO_VERSION = 1.7 |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 8110 | USER_CLASSES = buildstats image-prelink |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8111 | IMAGE_CLASSES = image_types |
| 8112 | IMAGE_FEATURES = debug-tweaks |
| 8113 | IMAGE_LINGUAS = |
| 8114 | IMAGE_INSTALL = packagegroup-core-boot run-postinsts |
| 8115 | BAD_RECOMMENDATIONS = |
| 8116 | NO_RECOMMENDATIONS = |
| 8117 | PACKAGE_EXCLUDE = |
| 8118 | ROOTFS_POSTPROCESS_COMMAND = write_package_manifest; license_create_manifest; \ |
| 8119 | write_image_manifest ; buildhistory_list_installed_image ; \ |
| 8120 | buildhistory_get_image_installed ; ssh_allow_empty_password; \ |
| 8121 | postinst_enable_logging; rootfs_update_timestamp ; ssh_disable_dns_lookup ; |
| 8122 | IMAGE_POSTPROCESS_COMMAND = buildhistory_get_imageinfo ; |
| 8123 | IMAGESIZE = 6900 |
| 8124 | |
| 8125 | Other than ``IMAGESIZE``, |
| 8126 | which is the total size of the files in the image in Kbytes, the |
| 8127 | name-value pairs are variables that may have influenced the content of |
| 8128 | the image. This information is often useful when you are trying to |
| 8129 | determine why a change in the package or file listings has occurred. |
| 8130 | |
| 8131 | Using Build History to Gather Image Information Only |
| 8132 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 8133 | |
| 8134 | As you can see, build history produces image information, including |
| 8135 | dependency graphs, so you can see why something was pulled into the |
| 8136 | image. If you are just interested in this information and not interested |
| 8137 | in collecting specific package or SDK information, you can enable |
| 8138 | writing only image information without any history by adding the |
| 8139 | following to your ``conf/local.conf`` file found in the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 8140 | :term:`Build Directory`:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8141 | |
| 8142 | INHERIT += "buildhistory" |
| 8143 | BUILDHISTORY_COMMIT = "0" |
| 8144 | BUILDHISTORY_FEATURES = "image" |
| 8145 | |
| 8146 | Here, you set the |
| 8147 | :term:`BUILDHISTORY_FEATURES` |
| 8148 | variable to use the image feature only. |
| 8149 | |
| 8150 | Build History SDK Information |
| 8151 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 8152 | |
| 8153 | Build history collects similar information on the contents of SDKs (e.g. |
| 8154 | ``bitbake -c populate_sdk imagename``) as compared to information it |
| 8155 | collects for images. Furthermore, this information differs depending on |
| 8156 | whether an extensible or standard SDK is being produced. |
| 8157 | |
| 8158 | The following list shows the files produced for SDKs: |
| 8159 | |
| 8160 | - ``files-in-sdk.txt:`` A list of files in the SDK with permissions, |
| 8161 | owner, group, size, and symlink information. This list includes both |
| 8162 | the host and target parts of the SDK. |
| 8163 | |
| 8164 | - ``sdk-info.txt:`` A text file containing name-value pairs with |
| 8165 | information about the SDK. See the following listing example for more |
| 8166 | information. |
| 8167 | |
| 8168 | - ``sstate-task-sizes.txt:`` A text file containing name-value pairs |
| 8169 | with information about task group sizes (e.g. ``do_populate_sysroot`` |
| 8170 | tasks have a total size). The ``sstate-task-sizes.txt`` file exists |
| 8171 | only when an extensible SDK is created. |
| 8172 | |
| 8173 | - ``sstate-package-sizes.txt:`` A text file containing name-value pairs |
| 8174 | with information for the shared-state packages and sizes in the SDK. |
| 8175 | The ``sstate-package-sizes.txt`` file exists only when an extensible |
| 8176 | SDK is created. |
| 8177 | |
| 8178 | - ``sdk-files:`` A folder that contains copies of the files mentioned |
| 8179 | in ``BUILDHISTORY_SDK_FILES`` if the files are present in the output. |
| 8180 | Additionally, the default value of ``BUILDHISTORY_SDK_FILES`` is |
| 8181 | specific to the extensible SDK although you can set it differently if |
| 8182 | you would like to pull in specific files from the standard SDK. |
| 8183 | |
| 8184 | The default files are ``conf/local.conf``, ``conf/bblayers.conf``, |
| 8185 | ``conf/auto.conf``, ``conf/locked-sigs.inc``, and |
| 8186 | ``conf/devtool.conf``. Thus, for an extensible SDK, these files get |
| 8187 | copied into the ``sdk-files`` directory. |
| 8188 | |
| 8189 | - The following information appears under each of the ``host`` and |
| 8190 | ``target`` directories for the portions of the SDK that run on the |
| 8191 | host and on the target, respectively: |
| 8192 | |
| 8193 | .. note:: |
| 8194 | |
| 8195 | The following files for the most part are empty when producing an |
| 8196 | extensible SDK because this type of SDK is not constructed from |
| 8197 | packages as is the standard SDK. |
| 8198 | |
| 8199 | - ``depends.dot:`` Dependency graph for the SDK that is compatible |
| 8200 | with ``graphviz``. |
| 8201 | |
| 8202 | - ``installed-package-names.txt:`` A list of installed packages by |
| 8203 | name only. |
| 8204 | |
| 8205 | - ``installed-package-sizes.txt:`` A list of installed packages |
| 8206 | ordered by size. |
| 8207 | |
| 8208 | - ``installed-packages.txt:`` A list of installed packages with full |
| 8209 | package filenames. |
| 8210 | |
| 8211 | Here is an example of ``sdk-info.txt``: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8212 | |
| 8213 | .. code-block:: none |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8214 | |
| 8215 | DISTRO = poky |
| 8216 | DISTRO_VERSION = 1.3+snapshot-20130327 |
| 8217 | SDK_NAME = poky-glibc-i686-arm |
| 8218 | SDK_VERSION = 1.3+snapshot |
| 8219 | SDKMACHINE = |
| 8220 | SDKIMAGE_FEATURES = dev-pkgs dbg-pkgs |
| 8221 | BAD_RECOMMENDATIONS = |
| 8222 | SDKSIZE = 352712 |
| 8223 | |
| 8224 | Other than ``SDKSIZE``, which is |
| 8225 | the total size of the files in the SDK in Kbytes, the name-value pairs |
| 8226 | are variables that might have influenced the content of the SDK. This |
| 8227 | information is often useful when you are trying to determine why a |
| 8228 | change in the package or file listings has occurred. |
| 8229 | |
| 8230 | Examining Build History Information |
| 8231 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 8232 | |
| 8233 | You can examine build history output from the command line or from a web |
| 8234 | interface. |
| 8235 | |
| 8236 | To see any changes that have occurred (assuming you have |
| 8237 | :term:`BUILDHISTORY_COMMIT` = "1"), |
| 8238 | you can simply use any Git command that allows you to view the history |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 8239 | of a repository. Here is one method:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8240 | |
| 8241 | $ git log -p |
| 8242 | |
| 8243 | You need to realize, |
| 8244 | however, that this method does show changes that are not significant |
| 8245 | (e.g. a package's size changing by a few bytes). |
| 8246 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 8247 | There is a command-line tool called ``buildhistory-diff``, though, |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8248 | that queries the Git repository and prints just the differences that |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 8249 | might be significant in human-readable form. Here is an example:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8250 | |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 8251 | $ poky/poky/scripts/buildhistory-diff . HEAD^ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8252 | Changes to images/qemux86_64/glibc/core-image-minimal (files-in-image.txt): |
| 8253 | /etc/anotherpkg.conf was added |
| 8254 | /sbin/anotherpkg was added |
| 8255 | * (installed-package-names.txt): |
| 8256 | * anotherpkg was added |
| 8257 | Changes to images/qemux86_64/glibc/core-image-minimal (installed-package-names.txt): |
| 8258 | anotherpkg was added |
| 8259 | packages/qemux86_64-poky-linux/v86d: PACKAGES: added "v86d-extras" |
| 8260 | * PR changed from "r0" to "r1" |
| 8261 | * PV changed from "0.1.10" to "0.1.12" |
| 8262 | packages/qemux86_64-poky-linux/v86d/v86d: PKGSIZE changed from 110579 to 144381 (+30%) |
| 8263 | * PR changed from "r0" to "r1" |
| 8264 | * PV changed from "0.1.10" to "0.1.12" |
| 8265 | |
| 8266 | .. note:: |
| 8267 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8268 | The ``buildhistory-diff`` tool requires the ``GitPython`` |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 8269 | package. Be sure to install it using Pip3 as follows:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8270 | |
| 8271 | $ pip3 install GitPython --user |
| 8272 | |
| 8273 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8274 | Alternatively, you can install ``python3-git`` using the appropriate |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 8275 | distribution package manager (e.g. ``apt``, ``dnf``, or ``zipper``). |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8276 | |
| 8277 | 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] | 8278 | instruction in the ``README`` file |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 8279 | :yocto_git:`here </buildhistory-web/>`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8280 | |
| 8281 | Here is a sample screenshot of the interface: |
| 8282 | |
| 8283 | .. image:: figures/buildhistory-web.png |
| 8284 | :align: center |
| 8285 | |
| 8286 | Performing Automated Runtime Testing |
| 8287 | ==================================== |
| 8288 | |
| 8289 | The OpenEmbedded build system makes available a series of automated |
| 8290 | tests for images to verify runtime functionality. You can run these |
| 8291 | tests on either QEMU or actual target hardware. Tests are written in |
| 8292 | Python making use of the ``unittest`` module, and the majority of them |
| 8293 | run commands on the target system over SSH. This section describes how |
| 8294 | you set up the environment to use these tests, run available tests, and |
| 8295 | write and add your own tests. |
| 8296 | |
| 8297 | For information on the test and QA infrastructure available within the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 8298 | 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] | 8299 | section in the Yocto Project Reference Manual. |
| 8300 | |
| 8301 | Enabling Tests |
| 8302 | -------------- |
| 8303 | |
| 8304 | Depending on whether you are planning to run tests using QEMU or on the |
| 8305 | hardware, you have to take different steps to enable the tests. See the |
| 8306 | following subsections for information on how to enable both types of |
| 8307 | tests. |
| 8308 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8309 | Enabling Runtime Tests on QEMU |
| 8310 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 8311 | |
| 8312 | In order to run tests, you need to do the following: |
| 8313 | |
| 8314 | - *Set up to avoid interaction with sudo for networking:* To |
| 8315 | accomplish this, you must do one of the following: |
| 8316 | |
| 8317 | - Add ``NOPASSWD`` for your user in ``/etc/sudoers`` either for all |
| 8318 | commands or just for ``runqemu-ifup``. You must provide the full |
| 8319 | path as that can change if you are using multiple clones of the |
| 8320 | source repository. |
| 8321 | |
| 8322 | .. note:: |
| 8323 | |
| 8324 | On some distributions, you also need to comment out "Defaults |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8325 | requiretty" in ``/etc/sudoers``. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8326 | |
| 8327 | - Manually configure a tap interface for your system. |
| 8328 | |
| 8329 | - Run as root the script in ``scripts/runqemu-gen-tapdevs``, which |
| 8330 | should generate a list of tap devices. This is the option |
| 8331 | typically chosen for Autobuilder-type environments. |
| 8332 | |
| 8333 | .. note:: |
| 8334 | |
| 8335 | - Be sure to use an absolute path when calling this script |
| 8336 | with sudo. |
| 8337 | |
| 8338 | - The package recipe ``qemu-helper-native`` is required to run |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 8339 | this script. Build the package using the following command:: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8340 | |
| 8341 | $ bitbake qemu-helper-native |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8342 | |
| 8343 | - *Set the DISPLAY variable:* You need to set this variable so that |
| 8344 | you have an X server available (e.g. start ``vncserver`` for a |
| 8345 | headless machine). |
| 8346 | |
| 8347 | - *Be sure your host's firewall accepts incoming connections from |
| 8348 | 192.168.7.0/24:* Some of the tests (in particular DNF tests) start an |
| 8349 | HTTP server on a random high number port, which is used to serve |
| 8350 | files to the target. The DNF module serves |
| 8351 | ``${WORKDIR}/oe-rootfs-repo`` so it can run DNF channel commands. |
| 8352 | That means your host's firewall must accept incoming connections from |
| 8353 | 192.168.7.0/24, which is the default IP range used for tap devices by |
| 8354 | ``runqemu``. |
| 8355 | |
| 8356 | - *Be sure your host has the correct packages installed:* Depending |
| 8357 | your host's distribution, you need to have the following packages |
| 8358 | installed: |
| 8359 | |
| 8360 | - Ubuntu and Debian: ``sysstat`` and ``iproute2`` |
| 8361 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 8362 | - openSUSE: ``sysstat`` and ``iproute2`` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8363 | |
| 8364 | - Fedora: ``sysstat`` and ``iproute`` |
| 8365 | |
| 8366 | - CentOS: ``sysstat`` and ``iproute`` |
| 8367 | |
| 8368 | Once you start running the tests, the following happens: |
| 8369 | |
| 8370 | 1. A copy of the root filesystem is written to ``${WORKDIR}/testimage``. |
| 8371 | |
| 8372 | 2. The image is booted under QEMU using the standard ``runqemu`` script. |
| 8373 | |
| 8374 | 3. A default timeout of 500 seconds occurs to allow for the boot process |
| 8375 | to reach the login prompt. You can change the timeout period by |
| 8376 | setting |
| 8377 | :term:`TEST_QEMUBOOT_TIMEOUT` |
| 8378 | in the ``local.conf`` file. |
| 8379 | |
| 8380 | 4. Once the boot process is reached and the login prompt appears, the |
| 8381 | tests run. The full boot log is written to |
| 8382 | ``${WORKDIR}/testimage/qemu_boot_log``. |
| 8383 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 8384 | 5. Each test module loads in the order found in :term:`TEST_SUITES`. You can |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8385 | find the full output of the commands run over SSH in |
| 8386 | ``${WORKDIR}/testimgage/ssh_target_log``. |
| 8387 | |
| 8388 | 6. If no failures occur, the task running the tests ends successfully. |
| 8389 | You can find the output from the ``unittest`` in the task log at |
| 8390 | ``${WORKDIR}/temp/log.do_testimage``. |
| 8391 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8392 | Enabling Runtime Tests on Hardware |
| 8393 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 8394 | |
| 8395 | The OpenEmbedded build system can run tests on real hardware, and for |
| 8396 | certain devices it can also deploy the image to be tested onto the |
| 8397 | device beforehand. |
| 8398 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 8399 | For automated deployment, a "controller image" is installed onto the |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8400 | hardware once as part of setup. Then, each time tests are to be run, the |
| 8401 | following occurs: |
| 8402 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 8403 | 1. The controller image is booted into and used to write the image to be |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8404 | tested to a second partition. |
| 8405 | |
| 8406 | 2. The device is then rebooted using an external script that you need to |
| 8407 | provide. |
| 8408 | |
| 8409 | 3. The device boots into the image to be tested. |
| 8410 | |
| 8411 | When running tests (independent of whether the image has been deployed |
| 8412 | automatically or not), the device is expected to be connected to a |
| 8413 | network on a pre-determined IP address. You can either use static IP |
| 8414 | addresses written into the image, or set the image to use DHCP and have |
| 8415 | your DHCP server on the test network assign a known IP address based on |
| 8416 | the MAC address of the device. |
| 8417 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 8418 | In order to run tests on hardware, you need to set :term:`TEST_TARGET` to an |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8419 | appropriate value. For QEMU, you do not have to change anything, the |
| 8420 | default value is "qemu". For running tests on hardware, the following |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 8421 | options are available: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8422 | |
| 8423 | - *"simpleremote":* Choose "simpleremote" if you are going to run tests |
| 8424 | on a target system that is already running the image to be tested and |
| 8425 | is available on the network. You can use "simpleremote" in |
| 8426 | conjunction with either real hardware or an image running within a |
| 8427 | separately started QEMU or any other virtual machine manager. |
| 8428 | |
| 8429 | - *"SystemdbootTarget":* Choose "SystemdbootTarget" if your hardware is |
| 8430 | an EFI-based machine with ``systemd-boot`` as bootloader and |
| 8431 | ``core-image-testmaster`` (or something similar) is installed. Also, |
| 8432 | your hardware under test must be in a DHCP-enabled network that gives |
| 8433 | it the same IP address for each reboot. |
| 8434 | |
| 8435 | If you choose "SystemdbootTarget", there are additional requirements |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 8436 | and considerations. See the |
| 8437 | ":ref:`dev-manual/common-tasks:selecting systemdboottarget`" section, which |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8438 | follows, for more information. |
| 8439 | |
| 8440 | - *"BeagleBoneTarget":* Choose "BeagleBoneTarget" if you are deploying |
| 8441 | images and running tests on the BeagleBone "Black" or original |
| 8442 | "White" hardware. For information on how to use these tests, see the |
| 8443 | comments at the top of the BeagleBoneTarget |
| 8444 | ``meta-yocto-bsp/lib/oeqa/controllers/beaglebonetarget.py`` file. |
| 8445 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8446 | - *"EdgeRouterTarget":* Choose "EdgeRouterTarget" if you are deploying |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8447 | images and running tests on the Ubiquiti Networks EdgeRouter Lite. |
| 8448 | For information on how to use these tests, see the comments at the |
| 8449 | top of the EdgeRouterTarget |
| 8450 | ``meta-yocto-bsp/lib/oeqa/controllers/edgeroutertarget.py`` file. |
| 8451 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8452 | - *"GrubTarget":* Choose "GrubTarget" if you are deploying images and running |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8453 | tests on any generic PC that boots using GRUB. For information on how |
| 8454 | to use these tests, see the comments at the top of the GrubTarget |
| 8455 | ``meta-yocto-bsp/lib/oeqa/controllers/grubtarget.py`` file. |
| 8456 | |
| 8457 | - *"your-target":* Create your own custom target if you want to run |
| 8458 | tests when you are deploying images and running tests on a custom |
| 8459 | machine within your BSP layer. To do this, you need to add a Python |
| 8460 | unit that defines the target class under ``lib/oeqa/controllers/`` |
| 8461 | within your layer. You must also provide an empty ``__init__.py``. |
| 8462 | For examples, see files in ``meta-yocto-bsp/lib/oeqa/controllers/``. |
| 8463 | |
| 8464 | Selecting SystemdbootTarget |
| 8465 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 8466 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 8467 | If you did not set :term:`TEST_TARGET` to "SystemdbootTarget", then you do |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8468 | not need any information in this section. You can skip down to the |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 8469 | ":ref:`dev-manual/common-tasks:running tests`" section. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8470 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 8471 | If you did set :term:`TEST_TARGET` to "SystemdbootTarget", you also need to |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 8472 | perform a one-time setup of your controller image by doing the following: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8473 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 8474 | 1. *Set EFI_PROVIDER:* Be sure that :term:`EFI_PROVIDER` is as follows:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8475 | |
| 8476 | EFI_PROVIDER = "systemd-boot" |
| 8477 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 8478 | 2. *Build the controller image:* Build the ``core-image-testmaster`` image. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8479 | The ``core-image-testmaster`` recipe is provided as an example for a |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 8480 | "controller" image and you can customize the image recipe as you would |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8481 | any other recipe. |
| 8482 | |
| 8483 | Here are the image recipe requirements: |
| 8484 | |
| 8485 | - Inherits ``core-image`` so that kernel modules are installed. |
| 8486 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 8487 | - Installs normal linux utilities not BusyBox ones (e.g. ``bash``, |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8488 | ``coreutils``, ``tar``, ``gzip``, and ``kmod``). |
| 8489 | |
| 8490 | - Uses a custom Initial RAM Disk (initramfs) image with a custom |
| 8491 | installer. A normal image that you can install usually creates a |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 8492 | single root filesystem partition. This image uses another installer that |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8493 | creates a specific partition layout. Not all Board Support |
| 8494 | Packages (BSPs) can use an installer. For such cases, you need to |
| 8495 | manually create the following partition layout on the target: |
| 8496 | |
| 8497 | - First partition mounted under ``/boot``, labeled "boot". |
| 8498 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 8499 | - The main root filesystem partition where this image gets installed, |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8500 | which is mounted under ``/``. |
| 8501 | |
| 8502 | - Another partition labeled "testrootfs" where test images get |
| 8503 | deployed. |
| 8504 | |
| 8505 | 3. *Install image:* Install the image that you just built on the target |
| 8506 | system. |
| 8507 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 8508 | The final thing you need to do when setting :term:`TEST_TARGET` to |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8509 | "SystemdbootTarget" is to set up the test image: |
| 8510 | |
| 8511 | 1. *Set up your local.conf file:* Make sure you have the following |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 8512 | statements in your ``local.conf`` file:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8513 | |
| 8514 | IMAGE_FSTYPES += "tar.gz" |
| 8515 | INHERIT += "testimage" |
| 8516 | TEST_TARGET = "SystemdbootTarget" |
| 8517 | TEST_TARGET_IP = "192.168.2.3" |
| 8518 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 8519 | 2. *Build your test image:* Use BitBake to build the image:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8520 | |
| 8521 | $ bitbake core-image-sato |
| 8522 | |
| 8523 | Power Control |
| 8524 | ~~~~~~~~~~~~~ |
| 8525 | |
| 8526 | For most hardware targets other than "simpleremote", you can control |
| 8527 | power: |
| 8528 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 8529 | - You can use :term:`TEST_POWERCONTROL_CMD` together with |
| 8530 | :term:`TEST_POWERCONTROL_EXTRA_ARGS` as a command that runs on the host |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8531 | and does power cycling. The test code passes one argument to that |
| 8532 | command: off, on or cycle (off then on). Here is an example that |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 8533 | could appear in your ``local.conf`` file:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8534 | |
| 8535 | TEST_POWERCONTROL_CMD = "powercontrol.exp test 10.11.12.1 nuc1" |
| 8536 | |
| 8537 | In this example, the expect |
| 8538 | script does the following: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8539 | |
| 8540 | .. code-block:: shell |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8541 | |
| 8542 | ssh test@10.11.12.1 "pyctl nuc1 arg" |
| 8543 | |
| 8544 | It then runs a Python script that controls power for a label called |
| 8545 | ``nuc1``. |
| 8546 | |
| 8547 | .. note:: |
| 8548 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 8549 | You need to customize :term:`TEST_POWERCONTROL_CMD` and |
| 8550 | :term:`TEST_POWERCONTROL_EXTRA_ARGS` for your own setup. The one requirement |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8551 | is that it accepts "on", "off", and "cycle" as the last argument. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8552 | |
| 8553 | - When no command is defined, it connects to the device over SSH and |
| 8554 | uses the classic reboot command to reboot the device. Classic reboot |
| 8555 | is fine as long as the machine actually reboots (i.e. the SSH test |
| 8556 | has not failed). It is useful for scenarios where you have a simple |
| 8557 | setup, typically with a single board, and where some manual |
| 8558 | interaction is okay from time to time. |
| 8559 | |
| 8560 | If you have no hardware to automatically perform power control but still |
| 8561 | wish to experiment with automated hardware testing, you can use the |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8562 | ``dialog-power-control`` script that shows a dialog prompting you to perform |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8563 | the required power action. This script requires either KDialog or Zenity |
| 8564 | to be installed. To use this script, set the |
| 8565 | :term:`TEST_POWERCONTROL_CMD` |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 8566 | variable as follows:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8567 | |
| 8568 | TEST_POWERCONTROL_CMD = "${COREBASE}/scripts/contrib/dialog-power-control" |
| 8569 | |
| 8570 | Serial Console Connection |
| 8571 | ~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 8572 | |
| 8573 | For test target classes requiring a serial console to interact with the |
| 8574 | bootloader (e.g. BeagleBoneTarget, EdgeRouterTarget, and GrubTarget), |
| 8575 | you need to specify a command to use to connect to the serial console of |
| 8576 | the target machine by using the |
| 8577 | :term:`TEST_SERIALCONTROL_CMD` |
| 8578 | variable and optionally the |
| 8579 | :term:`TEST_SERIALCONTROL_EXTRA_ARGS` |
| 8580 | variable. |
| 8581 | |
| 8582 | These cases could be a serial terminal program if the machine is |
| 8583 | connected to a local serial port, or a ``telnet`` or ``ssh`` command |
| 8584 | connecting to a remote console server. Regardless of the case, the |
| 8585 | command simply needs to connect to the serial console and forward that |
| 8586 | connection to standard input and output as any normal terminal program |
| 8587 | does. For example, to use the picocom terminal program on serial device |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 8588 | ``/dev/ttyUSB0`` at 115200bps, you would set the variable as follows:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8589 | |
| 8590 | TEST_SERIALCONTROL_CMD = "picocom /dev/ttyUSB0 -b 115200" |
| 8591 | |
| 8592 | For local |
| 8593 | devices where the serial port device disappears when the device reboots, |
| 8594 | an additional "serdevtry" wrapper script is provided. To use this |
| 8595 | wrapper, simply prefix the terminal command with |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 8596 | ``${COREBASE}/scripts/contrib/serdevtry``:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8597 | |
| 8598 | TEST_SERIALCONTROL_CMD = "${COREBASE}/scripts/contrib/serdevtry picocom -b 115200 /dev/ttyUSB0" |
| 8599 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8600 | Running Tests |
| 8601 | ------------- |
| 8602 | |
| 8603 | You can start the tests automatically or manually: |
| 8604 | |
| 8605 | - *Automatically running tests:* To run the tests automatically after |
| 8606 | the OpenEmbedded build system successfully creates an image, first |
| 8607 | set the |
| 8608 | :term:`TESTIMAGE_AUTO` |
| 8609 | variable to "1" in your ``local.conf`` file in the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 8610 | :term:`Build Directory`:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8611 | |
| 8612 | TESTIMAGE_AUTO = "1" |
| 8613 | |
| 8614 | Next, build your image. If the image successfully builds, the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 8615 | tests run:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8616 | |
| 8617 | bitbake core-image-sato |
| 8618 | |
| 8619 | - *Manually running tests:* To manually run the tests, first globally |
| 8620 | inherit the |
| 8621 | :ref:`testimage <ref-classes-testimage*>` class |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 8622 | by editing your ``local.conf`` file:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8623 | |
| 8624 | INHERIT += "testimage" |
| 8625 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 8626 | Next, use BitBake to run the tests:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8627 | |
| 8628 | bitbake -c testimage image |
| 8629 | |
| 8630 | All test files reside in ``meta/lib/oeqa/runtime`` in the |
| 8631 | :term:`Source Directory`. A test name maps |
| 8632 | directly to a Python module. Each test module may contain a number of |
| 8633 | individual tests. Tests are usually grouped together by the area tested |
| 8634 | (e.g tests for systemd reside in ``meta/lib/oeqa/runtime/systemd.py``). |
| 8635 | |
| 8636 | You can add tests to any layer provided you place them in the proper |
| 8637 | area and you extend :term:`BBPATH` in |
| 8638 | the ``local.conf`` file as normal. Be sure that tests reside in |
| 8639 | ``layer/lib/oeqa/runtime``. |
| 8640 | |
| 8641 | .. note:: |
| 8642 | |
| 8643 | 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] | 8644 | the default set of test modules in ``meta/lib/oeqa/runtime``. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8645 | |
| 8646 | You can change the set of tests run by appending or overriding |
| 8647 | :term:`TEST_SUITES` variable in |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 8648 | ``local.conf``. Each name in :term:`TEST_SUITES` represents a required test |
| 8649 | for the image. Test modules named within :term:`TEST_SUITES` cannot be |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8650 | skipped even if a test is not suitable for an image (e.g. running the |
| 8651 | RPM tests on an image without ``rpm``). Appending "auto" to |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 8652 | :term:`TEST_SUITES` causes the build system to try to run all tests that are |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8653 | suitable for the image (i.e. each test module may elect to skip itself). |
| 8654 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 8655 | The order you list tests in :term:`TEST_SUITES` is important and influences |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8656 | test dependencies. Consequently, tests that depend on other tests should |
| 8657 | be added after the test on which they depend. For example, since the |
| 8658 | ``ssh`` test depends on the ``ping`` test, "ssh" needs to come after |
| 8659 | "ping" in the list. The test class provides no re-ordering or dependency |
| 8660 | handling. |
| 8661 | |
| 8662 | .. note:: |
| 8663 | |
| 8664 | Each module can have multiple classes with multiple test methods. |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8665 | And, Python ``unittest`` rules apply. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8666 | |
| 8667 | Here are some things to keep in mind when running tests: |
| 8668 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 8669 | - The default tests for the image are defined as:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8670 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 8671 | DEFAULT_TEST_SUITES:pn-image = "ping ssh df connman syslog xorg scp vnc date rpm dnf dmesg" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8672 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 8673 | - Add your own test to the list of the by using the following:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8674 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 8675 | TEST_SUITES:append = " mytest" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8676 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 8677 | - Run a specific list of tests as follows:: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8678 | |
| 8679 | TEST_SUITES = "test1 test2 test3" |
| 8680 | |
| 8681 | Remember, order is important. Be sure to place a test that is |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8682 | dependent on another test later in the order. |
| 8683 | |
| 8684 | Exporting Tests |
| 8685 | --------------- |
| 8686 | |
| 8687 | You can export tests so that they can run independently of the build |
| 8688 | system. Exporting tests is required if you want to be able to hand the |
| 8689 | test execution off to a scheduler. You can only export tests that are |
| 8690 | defined in :term:`TEST_SUITES`. |
| 8691 | |
| 8692 | If your image is already built, make sure the following are set in your |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 8693 | ``local.conf`` file:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8694 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8695 | INHERIT += "testexport" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8696 | TEST_TARGET_IP = "IP-address-for-the-test-target" |
| 8697 | TEST_SERVER_IP = "IP-address-for-the-test-server" |
| 8698 | |
| 8699 | You can then export the tests with the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 8700 | following BitBake command form:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8701 | |
| 8702 | $ bitbake image -c testexport |
| 8703 | |
| 8704 | Exporting the tests places them in the |
| 8705 | :term:`Build Directory` in |
| 8706 | ``tmp/testexport/``\ image, which is controlled by the |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 8707 | :term:`TEST_EXPORT_DIR` variable. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8708 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 8709 | You can now run the tests outside of the build environment:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8710 | |
| 8711 | $ cd tmp/testexport/image |
| 8712 | $ ./runexported.py testdata.json |
| 8713 | |
| 8714 | Here is a complete example that shows IP addresses and uses the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 8715 | ``core-image-sato`` image:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8716 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8717 | INHERIT += "testexport" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8718 | TEST_TARGET_IP = "192.168.7.2" |
| 8719 | TEST_SERVER_IP = "192.168.7.1" |
| 8720 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 8721 | Use BitBake to export the tests:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8722 | |
| 8723 | $ bitbake core-image-sato -c testexport |
| 8724 | |
| 8725 | Run the tests outside of |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 8726 | the build environment using the following:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8727 | |
| 8728 | $ cd tmp/testexport/core-image-sato |
| 8729 | $ ./runexported.py testdata.json |
| 8730 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8731 | Writing New Tests |
| 8732 | ----------------- |
| 8733 | |
| 8734 | As mentioned previously, all new test files need to be in the proper |
| 8735 | place for the build system to find them. New tests for additional |
| 8736 | functionality outside of the core should be added to the layer that adds |
| 8737 | the functionality, in ``layer/lib/oeqa/runtime`` (as long as |
| 8738 | :term:`BBPATH` is extended in the |
| 8739 | layer's ``layer.conf`` file as normal). Just remember the following: |
| 8740 | |
| 8741 | - Filenames need to map directly to test (module) names. |
| 8742 | |
| 8743 | - Do not use module names that collide with existing core tests. |
| 8744 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 8745 | - Minimally, an empty ``__init__.py`` file must be present in the runtime |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8746 | directory. |
| 8747 | |
| 8748 | To create a new test, start by copying an existing module (e.g. |
| 8749 | ``syslog.py`` or ``gcc.py`` are good ones to use). Test modules can use |
| 8750 | code from ``meta/lib/oeqa/utils``, which are helper classes. |
| 8751 | |
| 8752 | .. note:: |
| 8753 | |
| 8754 | Structure shell commands such that you rely on them and they return a |
| 8755 | single code for success. Be aware that sometimes you will need to |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8756 | 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] | 8757 | |
| 8758 | You will notice that all test classes inherit ``oeRuntimeTest``, which |
| 8759 | is found in ``meta/lib/oetest.py``. This base class offers some helper |
| 8760 | attributes, which are described in the following sections: |
| 8761 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8762 | Class Methods |
| 8763 | ~~~~~~~~~~~~~ |
| 8764 | |
| 8765 | Class methods are as follows: |
| 8766 | |
| 8767 | - *hasPackage(pkg):* Returns "True" if ``pkg`` is in the installed |
| 8768 | package list of the image, which is based on the manifest file that |
| 8769 | is generated during the ``do_rootfs`` task. |
| 8770 | |
| 8771 | - *hasFeature(feature):* Returns "True" if the feature is in |
| 8772 | :term:`IMAGE_FEATURES` or |
| 8773 | :term:`DISTRO_FEATURES`. |
| 8774 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8775 | Class Attributes |
| 8776 | ~~~~~~~~~~~~~~~~ |
| 8777 | |
| 8778 | Class attributes are as follows: |
| 8779 | |
| 8780 | - *pscmd:* Equals "ps -ef" if ``procps`` is installed in the image. |
| 8781 | Otherwise, ``pscmd`` equals "ps" (busybox). |
| 8782 | |
| 8783 | - *tc:* The called test context, which gives access to the |
| 8784 | following attributes: |
| 8785 | |
| 8786 | - *d:* The BitBake datastore, which allows you to use stuff such |
| 8787 | as ``oeRuntimeTest.tc.d.getVar("VIRTUAL-RUNTIME_init_manager")``. |
| 8788 | |
| 8789 | - *testslist and testsrequired:* Used internally. The tests |
| 8790 | do not need these. |
| 8791 | |
| 8792 | - *filesdir:* The absolute path to |
| 8793 | ``meta/lib/oeqa/runtime/files``, which contains helper files for |
| 8794 | tests meant for copying on the target such as small files written |
| 8795 | in C for compilation. |
| 8796 | |
| 8797 | - *target:* The target controller object used to deploy and |
| 8798 | start an image on a particular target (e.g. Qemu, SimpleRemote, |
| 8799 | and SystemdbootTarget). Tests usually use the following: |
| 8800 | |
| 8801 | - *ip:* The target's IP address. |
| 8802 | |
| 8803 | - *server_ip:* The host's IP address, which is usually used |
| 8804 | by the DNF test suite. |
| 8805 | |
| 8806 | - *run(cmd, timeout=None):* The single, most used method. |
| 8807 | This command is a wrapper for: ``ssh root@host "cmd"``. The |
| 8808 | command returns a tuple: (status, output), which are what their |
| 8809 | names imply - the return code of "cmd" and whatever output it |
| 8810 | produces. The optional timeout argument represents the number |
| 8811 | of seconds the test should wait for "cmd" to return. If the |
| 8812 | argument is "None", the test uses the default instance's |
| 8813 | timeout period, which is 300 seconds. If the argument is "0", |
| 8814 | the test runs until the command returns. |
| 8815 | |
| 8816 | - *copy_to(localpath, remotepath):* |
| 8817 | ``scp localpath root@ip:remotepath``. |
| 8818 | |
| 8819 | - *copy_from(remotepath, localpath):* |
| 8820 | ``scp root@host:remotepath localpath``. |
| 8821 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8822 | Instance Attributes |
| 8823 | ~~~~~~~~~~~~~~~~~~~ |
| 8824 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 8825 | There is a single instance attribute, which is ``target``. The ``target`` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8826 | instance attribute is identical to the class attribute of the same name, |
| 8827 | which is described in the previous section. This attribute exists as |
| 8828 | both an instance and class attribute so tests can use |
| 8829 | ``self.target.run(cmd)`` in instance methods instead of |
| 8830 | ``oeRuntimeTest.tc.target.run(cmd)``. |
| 8831 | |
| 8832 | Installing Packages in the DUT Without the Package Manager |
| 8833 | ---------------------------------------------------------- |
| 8834 | |
| 8835 | When a test requires a package built by BitBake, it is possible to |
| 8836 | install that package. Installing the package does not require a package |
| 8837 | manager be installed in the device under test (DUT). It does, however, |
| 8838 | require an SSH connection and the target must be using the |
| 8839 | ``sshcontrol`` class. |
| 8840 | |
| 8841 | .. note:: |
| 8842 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8843 | This method uses ``scp`` to copy files from the host to the target, which |
| 8844 | causes permissions and special attributes to be lost. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8845 | |
| 8846 | A JSON file is used to define the packages needed by a test. This file |
| 8847 | must be in the same path as the file used to define the tests. |
| 8848 | Furthermore, the filename must map directly to the test module name with |
| 8849 | a ``.json`` extension. |
| 8850 | |
| 8851 | The JSON file must include an object with the test name as keys of an |
| 8852 | object or an array. This object (or array of objects) uses the following |
| 8853 | data: |
| 8854 | |
| 8855 | - "pkg" - A mandatory string that is the name of the package to be |
| 8856 | installed. |
| 8857 | |
| 8858 | - "rm" - An optional boolean, which defaults to "false", that specifies |
| 8859 | to remove the package after the test. |
| 8860 | |
| 8861 | - "extract" - An optional boolean, which defaults to "false", that |
| 8862 | specifies if the package must be extracted from the package format. |
| 8863 | When set to "true", the package is not automatically installed into |
| 8864 | the DUT. |
| 8865 | |
| 8866 | Following is an example JSON file that handles test "foo" installing |
| 8867 | package "bar" and test "foobar" installing packages "foo" and "bar". |
| 8868 | Once the test is complete, the packages are removed from the DUT. |
| 8869 | :: |
| 8870 | |
| 8871 | { |
| 8872 | "foo": { |
| 8873 | "pkg": "bar" |
| 8874 | }, |
| 8875 | "foobar": [ |
| 8876 | { |
| 8877 | "pkg": "foo", |
| 8878 | "rm": true |
| 8879 | }, |
| 8880 | { |
| 8881 | "pkg": "bar", |
| 8882 | "rm": true |
| 8883 | } |
| 8884 | ] |
| 8885 | } |
| 8886 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8887 | Debugging Tools and Techniques |
| 8888 | ============================== |
| 8889 | |
| 8890 | The exact method for debugging build failures depends on the nature of |
| 8891 | the problem and on the system's area from which the bug originates. |
| 8892 | Standard debugging practices such as comparison against the last known |
| 8893 | working version with examination of the changes and the re-application |
| 8894 | of steps to identify the one causing the problem are valid for the Yocto |
| 8895 | Project just as they are for any other system. Even though it is |
| 8896 | impossible to detail every possible potential failure, this section |
| 8897 | provides some general tips to aid in debugging given a variety of |
| 8898 | situations. |
| 8899 | |
| 8900 | .. note:: |
| 8901 | |
| 8902 | A useful feature for debugging is the error reporting tool. |
| 8903 | Configuring the Yocto Project to use this tool causes the |
| 8904 | OpenEmbedded build system to produce error reporting commands as part |
| 8905 | of the console output. You can enter the commands after the build |
| 8906 | completes to log error information into a common database, that can |
| 8907 | 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] | 8908 | to enable and use this feature, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 8909 | ":ref:`dev-manual/common-tasks:using the error reporting tool`" |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8910 | section. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8911 | |
| 8912 | The following list shows the debugging topics in the remainder of this |
| 8913 | section: |
| 8914 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 8915 | - ":ref:`dev-manual/common-tasks:viewing logs from failed tasks`" describes |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8916 | how to find and view logs from tasks that failed during the build |
| 8917 | process. |
| 8918 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 8919 | - ":ref:`dev-manual/common-tasks:viewing variable values`" describes how to |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8920 | use the BitBake ``-e`` option to examine variable values after a |
| 8921 | recipe has been parsed. |
| 8922 | |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 8923 | - ":ref:`dev-manual/common-tasks:viewing package information with \`\`oe-pkgdata-util\`\``" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8924 | describes how to use the ``oe-pkgdata-util`` utility to query |
| 8925 | :term:`PKGDATA_DIR` and |
| 8926 | display package-related information for built packages. |
| 8927 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 8928 | - ":ref:`dev-manual/common-tasks:viewing dependencies between recipes and tasks`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8929 | describes how to use the BitBake ``-g`` option to display recipe |
| 8930 | dependency information used during the build. |
| 8931 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 8932 | - ":ref:`dev-manual/common-tasks:viewing task variable dependencies`" describes |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8933 | how to use the ``bitbake-dumpsig`` command in conjunction with key |
| 8934 | subdirectories in the |
| 8935 | :term:`Build Directory` to determine |
| 8936 | variable dependencies. |
| 8937 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 8938 | - ":ref:`dev-manual/common-tasks:running specific tasks`" describes |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8939 | how to use several BitBake options (e.g. ``-c``, ``-C``, and ``-f``) |
| 8940 | to run specific tasks in the build chain. It can be useful to run |
| 8941 | tasks "out-of-order" when trying isolate build issues. |
| 8942 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 8943 | - ":ref:`dev-manual/common-tasks:general bitbake problems`" describes how |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8944 | to use BitBake's ``-D`` debug output option to reveal more about what |
| 8945 | BitBake is doing during the build. |
| 8946 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 8947 | - ":ref:`dev-manual/common-tasks:building with no dependencies`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8948 | describes how to use the BitBake ``-b`` option to build a recipe |
| 8949 | while ignoring dependencies. |
| 8950 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 8951 | - ":ref:`dev-manual/common-tasks:recipe logging mechanisms`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8952 | describes how to use the many recipe logging functions to produce |
| 8953 | debugging output and report errors and warnings. |
| 8954 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 8955 | - ":ref:`dev-manual/common-tasks:debugging parallel make races`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8956 | describes how to debug situations where the build consists of several |
| 8957 | parts that are run simultaneously and when the output or result of |
| 8958 | one part is not ready for use with a different part of the build that |
| 8959 | depends on that output. |
| 8960 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 8961 | - ":ref:`dev-manual/common-tasks:debugging with the gnu project debugger (gdb) remotely`" |
| 8962 | describes how to use GDB to allow you to examine running programs, which can |
| 8963 | help you fix problems. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8964 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 8965 | - ":ref:`dev-manual/common-tasks:debugging with the gnu project debugger (gdb) on the target`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8966 | describes how to use GDB directly on target hardware for debugging. |
| 8967 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 8968 | - ":ref:`dev-manual/common-tasks:other debugging tips`" describes |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8969 | miscellaneous debugging tips that can be useful. |
| 8970 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8971 | Viewing Logs from Failed Tasks |
| 8972 | ------------------------------ |
| 8973 | |
| 8974 | You can find the log for a task in the file |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8975 | ``${``\ :term:`WORKDIR`\ ``}/temp/log.do_``\ `taskname`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8976 | For example, the log for the |
| 8977 | :ref:`ref-tasks-compile` task of the |
| 8978 | QEMU minimal image for the x86 machine (``qemux86``) might be in |
| 8979 | ``tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/temp/log.do_compile``. |
| 8980 | To see the commands :term:`BitBake` ran |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8981 | to generate a log, look at the corresponding ``run.do_``\ `taskname` file |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8982 | in the same directory. |
| 8983 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 8984 | ``log.do_``\ `taskname` and ``run.do_``\ `taskname` are actually symbolic |
| 8985 | links to ``log.do_``\ `taskname`\ ``.``\ `pid` and |
| 8986 | ``log.run_``\ `taskname`\ ``.``\ `pid`, where `pid` is the PID the task had |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8987 | when it ran. The symlinks always point to the files corresponding to the |
| 8988 | most recent run. |
| 8989 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 8990 | Viewing Variable Values |
| 8991 | ----------------------- |
| 8992 | |
| 8993 | Sometimes you need to know the value of a variable as a result of |
| 8994 | BitBake's parsing step. This could be because some unexpected behavior |
| 8995 | occurred in your project. Perhaps an attempt to :ref:`modify a variable |
| 8996 | <bitbake:bitbake-user-manual/bitbake-user-manual-metadata:modifying existing |
| 8997 | variables>` did not work out as expected. |
| 8998 | |
| 8999 | BitBake's ``-e`` option is used to display variable values after |
| 9000 | parsing. The following command displays the variable values after the |
| 9001 | configuration files (i.e. ``local.conf``, ``bblayers.conf``, |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9002 | ``bitbake.conf`` and so forth) have been parsed:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9003 | |
| 9004 | $ bitbake -e |
| 9005 | |
| 9006 | The following command displays variable values after a specific recipe has |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9007 | been parsed. The variables include those from the configuration as well:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9008 | |
| 9009 | $ bitbake -e recipename |
| 9010 | |
| 9011 | .. note:: |
| 9012 | |
| 9013 | Each recipe has its own private set of variables (datastore). |
| 9014 | Internally, after parsing the configuration, a copy of the resulting |
| 9015 | datastore is made prior to parsing each recipe. This copying implies |
| 9016 | that variables set in one recipe will not be visible to other |
| 9017 | recipes. |
| 9018 | |
| 9019 | Likewise, each task within a recipe gets a private datastore based on |
| 9020 | the recipe datastore, which means that variables set within one task |
| 9021 | will not be visible to other tasks. |
| 9022 | |
| 9023 | In the output of ``bitbake -e``, each variable is preceded by a |
| 9024 | description of how the variable got its value, including temporary |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9025 | values that were later overridden. This description also includes |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9026 | variable flags (varflags) set on the variable. The output can be very |
| 9027 | helpful during debugging. |
| 9028 | |
| 9029 | Variables that are exported to the environment are preceded by |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9030 | ``export`` in the output of ``bitbake -e``. See the following example:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9031 | |
| 9032 | export CC="i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/ulf/poky/build/tmp/sysroots/qemux86" |
| 9033 | |
| 9034 | In addition to variable values, the output of the ``bitbake -e`` and |
| 9035 | ``bitbake -e`` recipe commands includes the following information: |
| 9036 | |
| 9037 | - The output starts with a tree listing all configuration files and |
| 9038 | classes included globally, recursively listing the files they include |
| 9039 | or inherit in turn. Much of the behavior of the OpenEmbedded build |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 9040 | 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] | 9041 | implemented in the |
| 9042 | :ref:`base <ref-classes-base>` class and the |
| 9043 | classes it inherits, rather than being built into BitBake itself. |
| 9044 | |
| 9045 | - After the variable values, all functions appear in the output. For |
| 9046 | shell functions, variables referenced within the function body are |
| 9047 | expanded. If a function has been modified using overrides or using |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 9048 | override-style operators like ``:append`` and ``:prepend``, then the |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9049 | final assembled function body appears in the output. |
| 9050 | |
| 9051 | Viewing Package Information with ``oe-pkgdata-util`` |
| 9052 | ---------------------------------------------------- |
| 9053 | |
| 9054 | You can use the ``oe-pkgdata-util`` command-line utility to query |
| 9055 | :term:`PKGDATA_DIR` and display |
| 9056 | various package-related information. When you use the utility, you must |
| 9057 | use it to view information on packages that have already been built. |
| 9058 | |
| 9059 | Following are a few of the available ``oe-pkgdata-util`` subcommands. |
| 9060 | |
| 9061 | .. note:: |
| 9062 | |
| 9063 | You can use the standard \* and ? globbing wildcards as part of |
| 9064 | package names and paths. |
| 9065 | |
| 9066 | - ``oe-pkgdata-util list-pkgs [pattern]``: Lists all packages |
| 9067 | that have been built, optionally limiting the match to packages that |
| 9068 | match pattern. |
| 9069 | |
| 9070 | - ``oe-pkgdata-util list-pkg-files package ...``: Lists the |
| 9071 | files and directories contained in the given packages. |
| 9072 | |
| 9073 | .. note:: |
| 9074 | |
| 9075 | A different way to view the contents of a package is to look at |
| 9076 | the |
| 9077 | ``${``\ :term:`WORKDIR`\ ``}/packages-split`` |
| 9078 | directory of the recipe that generates the package. This directory |
| 9079 | is created by the |
| 9080 | :ref:`ref-tasks-package` task |
| 9081 | and has one subdirectory for each package the recipe generates, |
| 9082 | which contains the files stored in that package. |
| 9083 | |
| 9084 | If you want to inspect the ``${WORKDIR}/packages-split`` |
| 9085 | directory, make sure that |
| 9086 | :ref:`rm_work <ref-classes-rm-work>` is not |
| 9087 | enabled when you build the recipe. |
| 9088 | |
| 9089 | - ``oe-pkgdata-util find-path path ...``: Lists the names of |
| 9090 | the packages that contain the given paths. For example, the following |
| 9091 | tells us that ``/usr/share/man/man1/make.1`` is contained in the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9092 | ``make-doc`` package:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9093 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9094 | $ oe-pkgdata-util find-path /usr/share/man/man1/make.1 |
| 9095 | make-doc: /usr/share/man/man1/make.1 |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9096 | |
| 9097 | - ``oe-pkgdata-util lookup-recipe package ...``: Lists the name |
| 9098 | of the recipes that produce the given packages. |
| 9099 | |
| 9100 | For more information on the ``oe-pkgdata-util`` command, use the help |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9101 | facility:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9102 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9103 | $ oe-pkgdata-util --help |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9104 | $ oe-pkgdata-util subcommand --help |
| 9105 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9106 | Viewing Dependencies Between Recipes and Tasks |
| 9107 | ---------------------------------------------- |
| 9108 | |
| 9109 | Sometimes it can be hard to see why BitBake wants to build other recipes |
| 9110 | before the one you have specified. Dependency information can help you |
| 9111 | understand why a recipe is built. |
| 9112 | |
| 9113 | To generate dependency information for a recipe, run the following |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9114 | command:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9115 | |
| 9116 | $ bitbake -g recipename |
| 9117 | |
| 9118 | This command writes the following files in the current directory: |
| 9119 | |
| 9120 | - ``pn-buildlist``: A list of recipes/targets involved in building |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9121 | `recipename`. "Involved" here means that at least one task from the |
| 9122 | recipe needs to run when building `recipename` from scratch. Targets |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9123 | that are in |
| 9124 | :term:`ASSUME_PROVIDED` |
| 9125 | are not listed. |
| 9126 | |
| 9127 | - ``task-depends.dot``: A graph showing dependencies between tasks. |
| 9128 | |
| 9129 | The graphs are in |
| 9130 | `DOT <https://en.wikipedia.org/wiki/DOT_%28graph_description_language%29>`__ |
| 9131 | 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] | 9132 | `Graphviz <https://www.graphviz.org/>`__). |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9133 | |
| 9134 | .. note:: |
| 9135 | |
| 9136 | - DOT files use a plain text format. The graphs generated using the |
| 9137 | ``bitbake -g`` command are often so large as to be difficult to |
| 9138 | read without special pruning (e.g. with Bitbake's ``-I`` option) |
| 9139 | and processing. Despite the form and size of the graphs, the |
| 9140 | corresponding ``.dot`` files can still be possible to read and |
| 9141 | provide useful information. |
| 9142 | |
| 9143 | As an example, the ``task-depends.dot`` file contains lines such |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9144 | as the following:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9145 | |
| 9146 | "libxslt.do_configure" -> "libxml2.do_populate_sysroot" |
| 9147 | |
| 9148 | The above example line reveals that the |
| 9149 | :ref:`ref-tasks-configure` |
| 9150 | task in ``libxslt`` depends on the |
| 9151 | :ref:`ref-tasks-populate_sysroot` |
| 9152 | task in ``libxml2``, which is a normal |
| 9153 | :term:`DEPENDS` dependency |
| 9154 | between the two recipes. |
| 9155 | |
| 9156 | - For an example of how ``.dot`` files can be processed, see the |
| 9157 | ``scripts/contrib/graph-tool`` Python script, which finds and |
| 9158 | displays paths between graph nodes. |
| 9159 | |
| 9160 | You can use a different method to view dependency information by using |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9161 | the following command:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9162 | |
| 9163 | $ bitbake -g -u taskexp recipename |
| 9164 | |
| 9165 | This command |
| 9166 | displays a GUI window from which you can view build-time and runtime |
| 9167 | dependencies for the recipes involved in building recipename. |
| 9168 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9169 | Viewing Task Variable Dependencies |
| 9170 | ---------------------------------- |
| 9171 | |
| 9172 | As mentioned in the |
| 9173 | ":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-execution:checksums (signatures)`" section of the BitBake |
| 9174 | User Manual, BitBake tries to automatically determine what variables a |
| 9175 | task depends on so that it can rerun the task if any values of the |
| 9176 | variables change. This determination is usually reliable. However, if |
| 9177 | you do things like construct variable names at runtime, then you might |
| 9178 | have to manually declare dependencies on those variables using |
| 9179 | ``vardeps`` as described in the |
| 9180 | ":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags`" section of the BitBake |
| 9181 | User Manual. |
| 9182 | |
| 9183 | If you are unsure whether a variable dependency is being picked up |
| 9184 | automatically for a given task, you can list the variable dependencies |
| 9185 | BitBake has determined by doing the following: |
| 9186 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9187 | 1. Build the recipe containing the task:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9188 | |
| 9189 | $ bitbake recipename |
| 9190 | |
| 9191 | 2. Inside the :term:`STAMPS_DIR` |
| 9192 | directory, find the signature data (``sigdata``) file that |
| 9193 | corresponds to the task. The ``sigdata`` files contain a pickled |
| 9194 | Python database of all the metadata that went into creating the input |
| 9195 | checksum for the task. As an example, for the |
| 9196 | :ref:`ref-tasks-fetch` task of the |
| 9197 | ``db`` recipe, the ``sigdata`` file might be found in the following |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9198 | location:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9199 | |
| 9200 | ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1 |
| 9201 | |
| 9202 | For tasks that are accelerated through the shared state |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 9203 | (:ref:`sstate <overview-manual/concepts:shared state cache>`) cache, an |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9204 | additional ``siginfo`` file is written into |
| 9205 | :term:`SSTATE_DIR` along with |
| 9206 | the cached task output. The ``siginfo`` files contain exactly the |
| 9207 | same information as ``sigdata`` files. |
| 9208 | |
| 9209 | 3. Run ``bitbake-dumpsig`` on the ``sigdata`` or ``siginfo`` file. Here |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9210 | is an example:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9211 | |
| 9212 | $ bitbake-dumpsig ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1 |
| 9213 | |
| 9214 | In the output of the above command, you will find a line like the |
| 9215 | following, which lists all the (inferred) variable dependencies for |
| 9216 | the task. This list also includes indirect dependencies from |
| 9217 | variables depending on other variables, recursively. |
| 9218 | :: |
| 9219 | |
| 9220 | Task dependencies: ['PV', 'SRCREV', 'SRC_URI', 'SRC_URI[md5sum]', 'SRC_URI[sha256sum]', 'base_do_fetch'] |
| 9221 | |
| 9222 | .. note:: |
| 9223 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9224 | Functions (e.g. ``base_do_fetch``) also count as variable dependencies. |
| 9225 | These functions in turn depend on the variables they reference. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9226 | |
| 9227 | The output of ``bitbake-dumpsig`` also includes the value each |
| 9228 | variable had, a list of dependencies for each variable, and |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 9229 | :term:`BB_HASHBASE_WHITELIST` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9230 | information. |
| 9231 | |
| 9232 | There is also a ``bitbake-diffsigs`` command for comparing two |
| 9233 | ``siginfo`` or ``sigdata`` files. This command can be helpful when |
| 9234 | trying to figure out what changed between two versions of a task. If you |
| 9235 | call ``bitbake-diffsigs`` with just one file, the command behaves like |
| 9236 | ``bitbake-dumpsig``. |
| 9237 | |
| 9238 | You can also use BitBake to dump out the signature construction |
| 9239 | information without executing tasks by using either of the following |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9240 | BitBake command-line options:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9241 | |
| 9242 | ‐‐dump-signatures=SIGNATURE_HANDLER |
| 9243 | -S SIGNATURE_HANDLER |
| 9244 | |
| 9245 | |
| 9246 | .. note:: |
| 9247 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9248 | Two common values for `SIGNATURE_HANDLER` are "none" and "printdiff", which |
| 9249 | dump only the signature or compare the dumped signature with the cached one, |
| 9250 | respectively. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9251 | |
| 9252 | Using BitBake with either of these options causes BitBake to dump out |
| 9253 | ``sigdata`` files in the ``stamps`` directory for every task it would |
| 9254 | have executed instead of building the specified target package. |
| 9255 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9256 | Viewing Metadata Used to Create the Input Signature of a Shared State Task |
| 9257 | -------------------------------------------------------------------------- |
| 9258 | |
| 9259 | Seeing what metadata went into creating the input signature of a shared |
| 9260 | state (sstate) task can be a useful debugging aid. This information is |
| 9261 | available in signature information (``siginfo``) files in |
| 9262 | :term:`SSTATE_DIR`. For |
| 9263 | information on how to view and interpret information in ``siginfo`` |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 9264 | files, see the |
| 9265 | ":ref:`dev-manual/common-tasks:viewing task variable dependencies`" section. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9266 | |
| 9267 | For conceptual information on shared state, see the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 9268 | ":ref:`overview-manual/concepts:shared state`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9269 | section in the Yocto Project Overview and Concepts Manual. |
| 9270 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9271 | Invalidating Shared State to Force a Task to Run |
| 9272 | ------------------------------------------------ |
| 9273 | |
| 9274 | The OpenEmbedded build system uses |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 9275 | :ref:`checksums <overview-manual/concepts:checksums (signatures)>` and |
| 9276 | :ref:`overview-manual/concepts:shared state` cache to avoid unnecessarily |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9277 | rebuilding tasks. Collectively, this scheme is known as "shared state |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9278 | code". |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9279 | |
| 9280 | As with all schemes, this one has some drawbacks. It is possible that |
| 9281 | you could make implicit changes to your code that the checksum |
| 9282 | calculations do not take into account. These implicit changes affect a |
| 9283 | task's output but do not trigger the shared state code into rebuilding a |
| 9284 | recipe. Consider an example during which a tool changes its output. |
| 9285 | Assume that the output of ``rpmdeps`` changes. The result of the change |
| 9286 | should be that all the ``package`` and ``package_write_rpm`` shared |
| 9287 | state cache items become invalid. However, because the change to the |
| 9288 | output is external to the code and therefore implicit, the associated |
| 9289 | shared state cache items do not become invalidated. In this case, the |
| 9290 | build process uses the cached items rather than running the task again. |
| 9291 | Obviously, these types of implicit changes can cause problems. |
| 9292 | |
| 9293 | To avoid these problems during the build, you need to understand the |
| 9294 | effects of any changes you make. Realize that changes you make directly |
| 9295 | to a function are automatically factored into the checksum calculation. |
| 9296 | Thus, these explicit changes invalidate the associated area of shared |
| 9297 | state cache. However, you need to be aware of any implicit changes that |
| 9298 | are not obvious changes to the code and could affect the output of a |
| 9299 | given task. |
| 9300 | |
| 9301 | When you identify an implicit change, you can easily take steps to |
| 9302 | invalidate the cache and force the tasks to run. The steps you can take |
| 9303 | are as simple as changing a function's comments in the source code. For |
| 9304 | example, to invalidate package shared state files, change the comment |
| 9305 | statements of |
| 9306 | :ref:`ref-tasks-package` or the |
| 9307 | comments of one of the functions it calls. Even though the change is |
| 9308 | purely cosmetic, it causes the checksum to be recalculated and forces |
| 9309 | the build system to run the task again. |
| 9310 | |
| 9311 | .. note:: |
| 9312 | |
| 9313 | For an example of a commit that makes a cosmetic change to invalidate |
| 9314 | shared state, see this |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 9315 | :yocto_git:`commit </poky/commit/meta/classes/package.bbclass?id=737f8bbb4f27b4837047cb9b4fbfe01dfde36d54>`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9316 | |
| 9317 | Running Specific Tasks |
| 9318 | ---------------------- |
| 9319 | |
| 9320 | Any given recipe consists of a set of tasks. The standard BitBake |
| 9321 | behavior in most cases is: ``do_fetch``, ``do_unpack``, ``do_patch``, |
| 9322 | ``do_configure``, ``do_compile``, ``do_install``, ``do_package``, |
| 9323 | ``do_package_write_*``, and ``do_build``. The default task is |
| 9324 | ``do_build`` and any tasks on which it depends build first. Some tasks, |
| 9325 | such as ``do_devshell``, are not part of the default build chain. If you |
| 9326 | wish to run a task that is not part of the default build chain, you can |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9327 | use the ``-c`` option in BitBake. Here is an example:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9328 | |
| 9329 | $ bitbake matchbox-desktop -c devshell |
| 9330 | |
| 9331 | The ``-c`` option respects task dependencies, which means that all other |
| 9332 | tasks (including tasks from other recipes) that the specified task |
| 9333 | depends on will be run before the task. Even when you manually specify a |
| 9334 | task to run with ``-c``, BitBake will only run the task if it considers |
| 9335 | it "out of date". See the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 9336 | ":ref:`overview-manual/concepts:stamp files and the rerunning of tasks`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9337 | section in the Yocto Project Overview and Concepts Manual for how |
| 9338 | BitBake determines whether a task is "out of date". |
| 9339 | |
| 9340 | If you want to force an up-to-date task to be rerun (e.g. because you |
| 9341 | made manual modifications to the recipe's |
| 9342 | :term:`WORKDIR` that you want to try |
| 9343 | out), then you can use the ``-f`` option. |
| 9344 | |
| 9345 | .. note:: |
| 9346 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9347 | The reason ``-f`` is never required when running the |
| 9348 | :ref:`ref-tasks-devshell` task is because the |
| 9349 | [\ :ref:`nostamp <bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ] |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9350 | variable flag is already set for the task. |
| 9351 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9352 | The following example shows one way you can use the ``-f`` option:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9353 | |
| 9354 | $ bitbake matchbox-desktop |
| 9355 | . |
| 9356 | . |
| 9357 | make some changes to the source code in the work directory |
| 9358 | . |
| 9359 | . |
| 9360 | $ bitbake matchbox-desktop -c compile -f |
| 9361 | $ bitbake matchbox-desktop |
| 9362 | |
| 9363 | This sequence first builds and then recompiles ``matchbox-desktop``. The |
| 9364 | last command reruns all tasks (basically the packaging tasks) after the |
| 9365 | compile. BitBake recognizes that the ``do_compile`` task was rerun and |
| 9366 | therefore understands that the other tasks also need to be run again. |
| 9367 | |
| 9368 | Another, shorter way to rerun a task and all |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 9369 | :ref:`ref-manual/tasks:normal recipe build tasks` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9370 | that depend on it is to use the ``-C`` option. |
| 9371 | |
| 9372 | .. note:: |
| 9373 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9374 | This option is upper-cased and is separate from the ``-c`` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9375 | option, which is lower-cased. |
| 9376 | |
| 9377 | Using this option invalidates the given task and then runs the |
| 9378 | :ref:`ref-tasks-build` task, which is |
| 9379 | the default task if no task is given, and the tasks on which it depends. |
| 9380 | You could replace the final two commands in the previous example with |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9381 | the following single command:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9382 | |
| 9383 | $ bitbake matchbox-desktop -C compile |
| 9384 | |
| 9385 | Internally, the ``-f`` and ``-C`` options work by tainting (modifying) |
| 9386 | the input checksum of the specified task. This tainting indirectly |
| 9387 | causes the task and its dependent tasks to be rerun through the normal |
| 9388 | task dependency mechanisms. |
| 9389 | |
| 9390 | .. note:: |
| 9391 | |
| 9392 | BitBake explicitly keeps track of which tasks have been tainted in |
| 9393 | this fashion, and will print warnings such as the following for |
| 9394 | builds involving such tasks: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9395 | |
| 9396 | .. code-block:: none |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9397 | |
| 9398 | WARNING: /home/ulf/poky/meta/recipes-sato/matchbox-desktop/matchbox-desktop_2.1.bb.do_compile is tainted from a forced run |
| 9399 | |
| 9400 | |
| 9401 | The purpose of the warning is to let you know that the work directory |
| 9402 | and build output might not be in the clean state they would be in for |
| 9403 | a "normal" build, depending on what actions you took. To get rid of |
| 9404 | such warnings, you can remove the work directory and rebuild the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9405 | recipe, as follows:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9406 | |
| 9407 | $ bitbake matchbox-desktop -c clean |
| 9408 | $ bitbake matchbox-desktop |
| 9409 | |
| 9410 | |
| 9411 | You can view a list of tasks in a given package by running the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9412 | ``do_listtasks`` task as follows:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9413 | |
| 9414 | $ bitbake matchbox-desktop -c listtasks |
| 9415 | |
| 9416 | The results appear as output to the console and are also in |
| 9417 | the file ``${WORKDIR}/temp/log.do_listtasks``. |
| 9418 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9419 | General BitBake Problems |
| 9420 | ------------------------ |
| 9421 | |
| 9422 | You can see debug output from BitBake by using the ``-D`` option. The |
| 9423 | debug output gives more information about what BitBake is doing and the |
| 9424 | reason behind it. Each ``-D`` option you use increases the logging |
| 9425 | level. The most common usage is ``-DDD``. |
| 9426 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9427 | The output from ``bitbake -DDD -v targetname`` can reveal why BitBake |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9428 | chose a certain version of a package or why BitBake picked a certain |
| 9429 | provider. This command could also help you in a situation where you |
| 9430 | think BitBake did something unexpected. |
| 9431 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9432 | Building with No Dependencies |
| 9433 | ----------------------------- |
| 9434 | |
| 9435 | To build a specific recipe (``.bb`` file), you can use the following |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9436 | command form:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9437 | |
| 9438 | $ bitbake -b somepath/somerecipe.bb |
| 9439 | |
| 9440 | This command form does |
| 9441 | not check for dependencies. Consequently, you should use it only when |
| 9442 | you know existing dependencies have been met. |
| 9443 | |
| 9444 | .. note:: |
| 9445 | |
| 9446 | You can also specify fragments of the filename. In this case, BitBake |
| 9447 | checks for a unique match. |
| 9448 | |
| 9449 | Recipe Logging Mechanisms |
| 9450 | ------------------------- |
| 9451 | |
| 9452 | The Yocto Project provides several logging functions for producing |
| 9453 | debugging output and reporting errors and warnings. For Python |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 9454 | functions, the following logging functions are available. All of these functions |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9455 | 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] | 9456 | (stdout) with the right settings: |
| 9457 | |
| 9458 | - ``bb.plain(msg)``: Writes msg as is to the log while also |
| 9459 | logging to stdout. |
| 9460 | |
| 9461 | - ``bb.note(msg)``: Writes "NOTE: msg" to the log. Also logs to |
| 9462 | stdout if BitBake is called with "-v". |
| 9463 | |
| 9464 | - ``bb.debug(level, msg)``: Writes "DEBUG: msg" to the |
| 9465 | log. Also logs to stdout if the log level is greater than or equal to |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 9466 | level. See the ":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-intro:usage and syntax`" option |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9467 | in the BitBake User Manual for more information. |
| 9468 | |
| 9469 | - ``bb.warn(msg)``: Writes "WARNING: msg" to the log while also |
| 9470 | logging to stdout. |
| 9471 | |
| 9472 | - ``bb.error(msg)``: Writes "ERROR: msg" to the log while also |
| 9473 | logging to standard out (stdout). |
| 9474 | |
| 9475 | .. note:: |
| 9476 | |
| 9477 | Calling this function does not cause the task to fail. |
| 9478 | |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 9479 | - ``bb.fatal(msg)``: This logging function is similar to |
| 9480 | ``bb.error(msg)`` but also causes the calling task to fail. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9481 | |
| 9482 | .. note:: |
| 9483 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9484 | ``bb.fatal()`` raises an exception, which means you do not need to put a |
| 9485 | "return" statement after the function. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9486 | |
| 9487 | The same logging functions are also available in shell functions, under |
| 9488 | the names ``bbplain``, ``bbnote``, ``bbdebug``, ``bbwarn``, ``bberror``, |
| 9489 | and ``bbfatal``. The |
| 9490 | :ref:`logging <ref-classes-logging>` class |
| 9491 | implements these functions. See that class in the ``meta/classes`` |
| 9492 | folder of the :term:`Source Directory` for information. |
| 9493 | |
| 9494 | Logging With Python |
| 9495 | ~~~~~~~~~~~~~~~~~~~ |
| 9496 | |
| 9497 | When creating recipes using Python and inserting code that handles build |
| 9498 | logs, keep in mind the goal is to have informative logs while keeping |
| 9499 | the console as "silent" as possible. Also, if you want status messages |
| 9500 | in the log, use the "debug" loglevel. |
| 9501 | |
| 9502 | Following is an example written in Python. The code handles logging for |
| 9503 | a function that determines the number of tasks needed to be run. See the |
| 9504 | ":ref:`ref-tasks-listtasks`" |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9505 | section for additional information:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9506 | |
| 9507 | python do_listtasks() { |
| 9508 | bb.debug(2, "Starting to figure out the task list") |
| 9509 | if noteworthy_condition: |
| 9510 | bb.note("There are 47 tasks to run") |
| 9511 | bb.debug(2, "Got to point xyz") |
| 9512 | if warning_trigger: |
| 9513 | bb.warn("Detected warning_trigger, this might be a problem later.") |
| 9514 | if recoverable_error: |
| 9515 | bb.error("Hit recoverable_error, you really need to fix this!") |
| 9516 | if fatal_error: |
| 9517 | bb.fatal("fatal_error detected, unable to print the task list") |
| 9518 | bb.plain("The tasks present are abc") |
| 9519 | bb.debug(2, "Finished figuring out the tasklist") |
| 9520 | } |
| 9521 | |
| 9522 | Logging With Bash |
| 9523 | ~~~~~~~~~~~~~~~~~ |
| 9524 | |
| 9525 | When creating recipes using Bash and inserting code that handles build |
| 9526 | logs, you have the same goals - informative with minimal console output. |
| 9527 | The syntax you use for recipes written in Bash is similar to that of |
| 9528 | recipes written in Python described in the previous section. |
| 9529 | |
| 9530 | Following is an example written in Bash. The code logs the progress of |
| 9531 | the ``do_my_function`` function. |
| 9532 | :: |
| 9533 | |
| 9534 | do_my_function() { |
| 9535 | bbdebug 2 "Running do_my_function" |
| 9536 | if [ exceptional_condition ]; then |
| 9537 | bbnote "Hit exceptional_condition" |
| 9538 | fi |
| 9539 | bbdebug 2 "Got to point xyz" |
| 9540 | if [ warning_trigger ]; then |
| 9541 | bbwarn "Detected warning_trigger, this might cause a problem later." |
| 9542 | fi |
| 9543 | if [ recoverable_error ]; then |
| 9544 | bberror "Hit recoverable_error, correcting" |
| 9545 | fi |
| 9546 | if [ fatal_error ]; then |
| 9547 | bbfatal "fatal_error detected" |
| 9548 | fi |
| 9549 | bbdebug 2 "Completed do_my_function" |
| 9550 | } |
| 9551 | |
| 9552 | |
| 9553 | Debugging Parallel Make Races |
| 9554 | ----------------------------- |
| 9555 | |
| 9556 | A parallel ``make`` race occurs when the build consists of several parts |
| 9557 | that are run simultaneously and a situation occurs when the output or |
| 9558 | result of one part is not ready for use with a different part of the |
| 9559 | build that depends on that output. Parallel make races are annoying and |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 9560 | can sometimes be difficult to reproduce and fix. However, there are some simple |
| 9561 | tips and tricks that can help you debug and fix them. This section |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9562 | presents a real-world example of an error encountered on the Yocto |
| 9563 | Project autobuilder and the process used to fix it. |
| 9564 | |
| 9565 | .. note:: |
| 9566 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9567 | If you cannot properly fix a ``make`` race condition, you can work around it |
| 9568 | by clearing either the :term:`PARALLEL_MAKE` or :term:`PARALLEL_MAKEINST` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9569 | variables. |
| 9570 | |
| 9571 | The Failure |
| 9572 | ~~~~~~~~~~~ |
| 9573 | |
| 9574 | For this example, assume that you are building an image that depends on |
| 9575 | the "neard" package. And, during the build, BitBake runs into problems |
| 9576 | and creates the following output. |
| 9577 | |
| 9578 | .. note:: |
| 9579 | |
| 9580 | This example log file has longer lines artificially broken to make |
| 9581 | the listing easier to read. |
| 9582 | |
| 9583 | If you examine the output or the log file, you see the failure during |
| 9584 | ``make``: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9585 | |
| 9586 | .. code-block:: none |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9587 | |
| 9588 | | DEBUG: SITE files ['endian-little', 'bit-32', 'ix86-common', 'common-linux', 'common-glibc', 'i586-linux', 'common'] |
| 9589 | | DEBUG: Executing shell function do_compile |
| 9590 | | NOTE: make -j 16 |
| 9591 | | make --no-print-directory all-am |
| 9592 | | /bin/mkdir -p include/near |
| 9593 | | /bin/mkdir -p include/near |
| 9594 | | /bin/mkdir -p include/near |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 9595 | | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9596 | 0.14-r0/neard-0.14/include/types.h include/near/types.h |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 9597 | | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9598 | 0.14-r0/neard-0.14/include/log.h include/near/log.h |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 9599 | | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9600 | 0.14-r0/neard-0.14/include/plugin.h include/near/plugin.h |
| 9601 | | /bin/mkdir -p include/near |
| 9602 | | /bin/mkdir -p include/near |
| 9603 | | /bin/mkdir -p include/near |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 9604 | | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9605 | 0.14-r0/neard-0.14/include/tag.h include/near/tag.h |
| 9606 | | /bin/mkdir -p include/near |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 9607 | | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9608 | 0.14-r0/neard-0.14/include/adapter.h include/near/adapter.h |
| 9609 | | /bin/mkdir -p include/near |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 9610 | | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9611 | 0.14-r0/neard-0.14/include/ndef.h include/near/ndef.h |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 9612 | | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9613 | 0.14-r0/neard-0.14/include/tlv.h include/near/tlv.h |
| 9614 | | /bin/mkdir -p include/near |
| 9615 | | /bin/mkdir -p include/near |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 9616 | | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9617 | 0.14-r0/neard-0.14/include/setting.h include/near/setting.h |
| 9618 | | /bin/mkdir -p include/near |
| 9619 | | /bin/mkdir -p include/near |
| 9620 | | /bin/mkdir -p include/near |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 9621 | | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9622 | 0.14-r0/neard-0.14/include/device.h include/near/device.h |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 9623 | | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9624 | 0.14-r0/neard-0.14/include/nfc_copy.h include/near/nfc_copy.h |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 9625 | | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9626 | 0.14-r0/neard-0.14/include/snep.h include/near/snep.h |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 9627 | | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9628 | 0.14-r0/neard-0.14/include/version.h include/near/version.h |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 9629 | | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9630 | 0.14-r0/neard-0.14/include/dbus.h include/near/dbus.h |
| 9631 | | ./src/genbuiltin nfctype1 nfctype2 nfctype3 nfctype4 p2p > src/builtin.h |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 9632 | | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/pokybuild/yocto-autobuilder/nightly-x86/ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9633 | build/build/tmp/sysroots/qemux86 -DHAVE_CONFIG_H -I. -I./include -I./src -I./gdbus -I/home/pokybuild/ |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 9634 | yocto-autobuilder/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/glib-2.0 |
| 9635 | -I/home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/sysroots/qemux86/usr/ |
| 9636 | lib/glib-2.0/include -I/home/pokybuild/yocto-autobuilder/nightly-x86/build/build/ |
| 9637 | tmp/sysroots/qemux86/usr/include/dbus-1.0 -I/home/pokybuild/yocto-autobuilder/ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9638 | nightly-x86/build/build/tmp/sysroots/qemux86/usr/lib/dbus-1.0/include -I/home/pokybuild/yocto-autobuilder/ |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 9639 | nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/libnl3 |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9640 | -DNEAR_PLUGIN_BUILTIN -DPLUGINDIR=\""/usr/lib/near/plugins"\" |
| 9641 | -DCONFIGDIR=\""/etc/neard\"" -O2 -pipe -g -feliminate-unused-debug-types -c |
| 9642 | -o tools/snep-send.o tools/snep-send.c |
| 9643 | | In file included from tools/snep-send.c:16:0: |
| 9644 | | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory |
| 9645 | | #include <near/dbus.h> |
| 9646 | | ^ |
| 9647 | | compilation terminated. |
| 9648 | | make[1]: *** [tools/snep-send.o] Error 1 |
| 9649 | | make[1]: *** Waiting for unfinished jobs.... |
| 9650 | | make: *** [all] Error 2 |
| 9651 | | ERROR: oe_runmake failed |
| 9652 | |
| 9653 | Reproducing the Error |
| 9654 | ~~~~~~~~~~~~~~~~~~~~~ |
| 9655 | |
| 9656 | Because race conditions are intermittent, they do not manifest |
| 9657 | themselves every time you do the build. In fact, most times the build |
| 9658 | will complete without problems even though the potential race condition |
| 9659 | exists. Thus, once the error surfaces, you need a way to reproduce it. |
| 9660 | |
| 9661 | In this example, compiling the "neard" package is causing the problem. |
| 9662 | So the first thing to do is build "neard" locally. Before you start the |
| 9663 | build, set the |
| 9664 | :term:`PARALLEL_MAKE` variable |
| 9665 | in your ``local.conf`` file to a high number (e.g. "-j 20"). Using a |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 9666 | high value for :term:`PARALLEL_MAKE` increases the chances of the race |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9667 | condition showing up:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9668 | |
| 9669 | $ bitbake neard |
| 9670 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9671 | Once the local build for "neard" completes, start a ``devshell`` build:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9672 | |
| 9673 | $ bitbake neard -c devshell |
| 9674 | |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 9675 | For information on how to use a ``devshell``, see the |
| 9676 | ":ref:`dev-manual/common-tasks:using a development shell`" section. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9677 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9678 | In the ``devshell``, do the following:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9679 | |
| 9680 | $ make clean |
| 9681 | $ make tools/snep-send.o |
| 9682 | |
| 9683 | The ``devshell`` commands cause the failure to clearly |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 9684 | be visible. In this case, there is a missing dependency for the ``neard`` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9685 | Makefile target. Here is some abbreviated, sample output with the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9686 | missing dependency clearly visible at the end:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9687 | |
| 9688 | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/scott-lenovo/...... |
| 9689 | . |
| 9690 | . |
| 9691 | . |
| 9692 | tools/snep-send.c |
| 9693 | In file included from tools/snep-send.c:16:0: |
| 9694 | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory |
| 9695 | #include <near/dbus.h> |
| 9696 | ^ |
| 9697 | compilation terminated. |
| 9698 | make: *** [tools/snep-send.o] Error 1 |
| 9699 | $ |
| 9700 | |
| 9701 | |
| 9702 | Creating a Patch for the Fix |
| 9703 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 9704 | |
| 9705 | Because there is a missing dependency for the Makefile target, you need |
| 9706 | to patch the ``Makefile.am`` file, which is generated from |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9707 | ``Makefile.in``. You can use Quilt to create the patch:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9708 | |
| 9709 | $ quilt new parallelmake.patch |
| 9710 | Patch patches/parallelmake.patch is now on top |
| 9711 | $ quilt add Makefile.am |
| 9712 | File Makefile.am added to patch patches/parallelmake.patch |
| 9713 | |
| 9714 | For more information on using Quilt, see the |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 9715 | ":ref:`dev-manual/common-tasks:using quilt in your workflow`" section. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9716 | |
| 9717 | At this point you need to make the edits to ``Makefile.am`` to add the |
| 9718 | missing dependency. For our example, you have to add the following line |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9719 | to the file:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9720 | |
| 9721 | tools/snep-send.$(OBJEXT): include/near/dbus.h |
| 9722 | |
| 9723 | Once you have edited the file, use the ``refresh`` command to create the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9724 | patch:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9725 | |
| 9726 | $ quilt refresh |
| 9727 | Refreshed patch patches/parallelmake.patch |
| 9728 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 9729 | Once the patch file is created, you need to add it back to the originating |
| 9730 | recipe folder. Here is an example assuming a top-level |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9731 | :term:`Source Directory` named ``poky``:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9732 | |
| 9733 | $ cp patches/parallelmake.patch poky/meta/recipes-connectivity/neard/neard |
| 9734 | |
| 9735 | The final thing you need to do to implement the fix in the build is to |
| 9736 | update the "neard" recipe (i.e. ``neard-0.14.bb``) so that the |
| 9737 | :term:`SRC_URI` statement includes |
| 9738 | the patch file. The recipe file is in the folder above the patch. Here |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 9739 | is what the edited :term:`SRC_URI` statement would look like:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9740 | |
| 9741 | SRC_URI = "${KERNELORG_MIRROR}/linux/network/nfc/${BPN}-${PV}.tar.xz \ |
| 9742 | file://neard.in \ |
| 9743 | file://neard.service.in \ |
| 9744 | file://parallelmake.patch \ |
| 9745 | " |
| 9746 | |
| 9747 | With the patch complete and moved to the correct folder and the |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 9748 | :term:`SRC_URI` statement updated, you can exit the ``devshell``:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9749 | |
| 9750 | $ exit |
| 9751 | |
| 9752 | Testing the Build |
| 9753 | ~~~~~~~~~~~~~~~~~ |
| 9754 | |
| 9755 | With everything in place, you can get back to trying the build again |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9756 | locally:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9757 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9758 | $ bitbake neard |
| 9759 | |
| 9760 | This build should succeed. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9761 | |
| 9762 | Now you can open up a ``devshell`` again and repeat the clean and make |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9763 | operations as follows:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9764 | |
| 9765 | $ bitbake neard -c devshell |
| 9766 | $ make clean |
| 9767 | $ make tools/snep-send.o |
| 9768 | |
| 9769 | The build should work without issue. |
| 9770 | |
| 9771 | As with all solved problems, if they originated upstream, you need to |
| 9772 | submit the fix for the recipe in OE-Core and upstream so that the |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 9773 | problem is taken care of at its source. See the |
| 9774 | ":ref:`dev-manual/common-tasks:submitting a change to the yocto project`" |
| 9775 | section for more information. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9776 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9777 | Debugging With the GNU Project Debugger (GDB) Remotely |
| 9778 | ------------------------------------------------------ |
| 9779 | |
| 9780 | GDB allows you to examine running programs, which in turn helps you to |
| 9781 | understand and fix problems. It also allows you to perform post-mortem |
| 9782 | style analysis of program crashes. GDB is available as a package within |
| 9783 | 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] | 9784 | ":ref:`ref-manual/images:Images`" chapter in the Yocto |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9785 | Project Reference Manual for a description of these images. You can find |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9786 | information on GDB at https://sourceware.org/gdb/. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9787 | |
| 9788 | .. note:: |
| 9789 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9790 | For best results, install debug (``-dbg``) packages for the applications you |
| 9791 | are going to debug. Doing so makes extra debug symbols available that give |
| 9792 | you more meaningful output. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9793 | |
| 9794 | Sometimes, due to memory or disk space constraints, it is not possible |
| 9795 | to use GDB directly on the remote target to debug applications. These |
| 9796 | constraints arise because GDB needs to load the debugging information |
| 9797 | and the binaries of the process being debugged. Additionally, GDB needs |
| 9798 | to perform many computations to locate information such as function |
| 9799 | names, variable names and values, stack traces and so forth - even |
| 9800 | before starting the debugging process. These extra computations place |
| 9801 | more load on the target system and can alter the characteristics of the |
| 9802 | program being debugged. |
| 9803 | |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 9804 | To help get past the previously mentioned constraints, there are two |
| 9805 | methods you can use: running a debuginfod server and using gdbserver. |
| 9806 | |
| 9807 | Using the debuginfod server method |
| 9808 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 9809 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9810 | ``debuginfod`` from ``elfutils`` is a way to distribute ``debuginfo`` files. |
| 9811 | Running a ``debuginfod`` server makes debug symbols readily available, |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 9812 | which means you don't need to download debugging information |
| 9813 | and the binaries of the process being debugged. You can just fetch |
| 9814 | debug symbols from the server. |
| 9815 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9816 | To run a ``debuginfod`` server, you need to do the following: |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 9817 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9818 | - Ensure that ``debuginfod`` is present in :term:`DISTRO_FEATURES` |
| 9819 | (it already is in ``OpenEmbedded-core`` defaults and ``poky`` reference distribution). |
| 9820 | If not, set in your distro config file or in ``local.conf``:: |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 9821 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 9822 | DISTRO_FEATURES:append = " debuginfod" |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 9823 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9824 | This distro feature enables the server and client library in ``elfutils``, |
| 9825 | and enables ``debuginfod`` support in clients (at the moment, ``gdb`` and ``binutils``). |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 9826 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9827 | - Run the following commands to launch the ``debuginfod`` server on the host:: |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 9828 | |
| 9829 | $ oe-debuginfod |
| 9830 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9831 | - To use ``debuginfod`` on the target, you need to know the ip:port where |
| 9832 | ``debuginfod`` is listening on the host (port defaults to 8002), and export |
| 9833 | that into the shell environment, for example in ``qemu``:: |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 9834 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9835 | root@qemux86-64:~# export DEBUGINFOD_URLS="http://192.168.7.1:8002/" |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 9836 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9837 | - Then debug info fetching should simply work when running the target ``gdb``, |
| 9838 | ``readelf`` or ``objdump``, for example:: |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 9839 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9840 | root@qemux86-64:~# gdb /bin/cat |
| 9841 | ... |
| 9842 | Reading symbols from /bin/cat... |
| 9843 | Downloading separate debug info for /bin/cat... |
| 9844 | Reading symbols from /home/root/.cache/debuginfod_client/923dc4780cfbc545850c616bffa884b6b5eaf322/debuginfo... |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 9845 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9846 | - It's also possible to use ``debuginfod-find`` to just query the server:: |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 9847 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9848 | root@qemux86-64:~# debuginfod-find debuginfo /bin/ls |
| 9849 | /home/root/.cache/debuginfod_client/356edc585f7f82d46f94fcb87a86a3fe2d2e60bd/debuginfo |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 9850 | |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 9851 | |
| 9852 | Using the gdbserver method |
| 9853 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 9854 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9855 | gdbserver, which runs on the remote target and does not load any |
| 9856 | debugging information from the debugged process. Instead, a GDB instance |
| 9857 | processes the debugging information that is run on a remote computer - |
| 9858 | the host GDB. The host GDB then sends control commands to gdbserver to |
| 9859 | make it stop or start the debugged program, as well as read or write |
| 9860 | memory regions of that debugged program. All the debugging information |
| 9861 | loaded and processed as well as all the heavy debugging is done by the |
| 9862 | host GDB. Offloading these processes gives the gdbserver running on the |
| 9863 | target a chance to remain small and fast. |
| 9864 | |
| 9865 | Because the host GDB is responsible for loading the debugging |
| 9866 | information and for doing the necessary processing to make actual |
| 9867 | debugging happen, you have to make sure the host can access the |
| 9868 | unstripped binaries complete with their debugging information and also |
| 9869 | be sure the target is compiled with no optimizations. The host GDB must |
| 9870 | also have local access to all the libraries used by the debugged |
| 9871 | program. Because gdbserver does not need any local debugging |
| 9872 | information, the binaries on the remote target can remain stripped. |
| 9873 | However, the binaries must also be compiled without optimization so they |
| 9874 | match the host's binaries. |
| 9875 | |
| 9876 | To remain consistent with GDB documentation and terminology, the binary |
| 9877 | being debugged on the remote target machine is referred to as the |
| 9878 | "inferior" binary. For documentation on GDB see the `GDB |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9879 | site <https://sourceware.org/gdb/documentation/>`__. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9880 | |
| 9881 | The following steps show you how to debug using the GNU project |
| 9882 | debugger. |
| 9883 | |
| 9884 | 1. *Configure your build system to construct the companion debug |
| 9885 | filesystem:* |
| 9886 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9887 | In your ``local.conf`` file, set the following:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9888 | |
| 9889 | IMAGE_GEN_DEBUGFS = "1" |
| 9890 | IMAGE_FSTYPES_DEBUGFS = "tar.bz2" |
| 9891 | |
| 9892 | These options cause the |
| 9893 | OpenEmbedded build system to generate a special companion filesystem |
| 9894 | fragment, which contains the matching source and debug symbols to |
| 9895 | your deployable filesystem. The build system does this by looking at |
| 9896 | what is in the deployed filesystem, and pulling the corresponding |
| 9897 | ``-dbg`` packages. |
| 9898 | |
| 9899 | The companion debug filesystem is not a complete filesystem, but only |
| 9900 | contains the debug fragments. This filesystem must be combined with |
| 9901 | the full filesystem for debugging. Subsequent steps in this procedure |
| 9902 | show how to combine the partial filesystem with the full filesystem. |
| 9903 | |
| 9904 | 2. *Configure the system to include gdbserver in the target filesystem:* |
| 9905 | |
| 9906 | Make the following addition in either your ``local.conf`` file or in |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9907 | an image recipe:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9908 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 9909 | IMAGE_INSTALL:append = " gdbserver" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9910 | |
| 9911 | The change makes |
| 9912 | sure the ``gdbserver`` package is included. |
| 9913 | |
| 9914 | 3. *Build the environment:* |
| 9915 | |
| 9916 | Use the following command to construct the image and the companion |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9917 | Debug Filesystem:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9918 | |
| 9919 | $ bitbake image |
| 9920 | |
| 9921 | Build the cross GDB component and |
| 9922 | make it available for debugging. Build the SDK that matches the |
| 9923 | image. Building the SDK is best for a production build that can be |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9924 | used later for debugging, especially during long term maintenance:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9925 | |
| 9926 | $ bitbake -c populate_sdk image |
| 9927 | |
| 9928 | Alternatively, you can build the minimal toolchain components that |
| 9929 | match the target. Doing so creates a smaller than typical SDK and |
| 9930 | only contains a minimal set of components with which to build simple |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9931 | test applications, as well as run the debugger:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9932 | |
| 9933 | $ bitbake meta-toolchain |
| 9934 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9935 | A final method is to build Gdb itself within the build system:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9936 | |
| 9937 | $ bitbake gdb-cross-<architecture> |
| 9938 | |
| 9939 | Doing so produces a temporary copy of |
| 9940 | ``cross-gdb`` you can use for debugging during development. While |
| 9941 | this is the quickest approach, the two previous methods in this step |
| 9942 | are better when considering long-term maintenance strategies. |
| 9943 | |
| 9944 | .. note:: |
| 9945 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9946 | If you run ``bitbake gdb-cross``, the OpenEmbedded build system suggests |
| 9947 | the actual image (e.g. ``gdb-cross-i586``). The suggestion is usually the |
| 9948 | actual name you want to use. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9949 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9950 | 4. *Set up the* ``debugfs``\ *:* |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9951 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9952 | Run the following commands to set up the ``debugfs``:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9953 | |
| 9954 | $ mkdir debugfs |
| 9955 | $ cd debugfs |
| 9956 | $ tar xvfj build-dir/tmp-glibc/deploy/images/machine/image.rootfs.tar.bz2 |
| 9957 | $ tar xvfj build-dir/tmp-glibc/deploy/images/machine/image-dbg.rootfs.tar.bz2 |
| 9958 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9959 | 5. *Set up GDB:* |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9960 | |
| 9961 | Install the SDK (if you built one) and then source the correct |
| 9962 | environment file. Sourcing the environment file puts the SDK in your |
| 9963 | ``PATH`` environment variable. |
| 9964 | |
| 9965 | If you are using the build system, Gdb is located in |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9966 | `build-dir`\ ``/tmp/sysroots/``\ `host`\ ``/usr/bin/``\ `architecture`\ ``/``\ `architecture`\ ``-gdb`` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9967 | |
| 9968 | 6. *Boot the target:* |
| 9969 | |
| 9970 | For information on how to run QEMU, see the `QEMU |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9971 | Documentation <https://wiki.qemu.org/Documentation/GettingStartedDevelopers>`__. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9972 | |
| 9973 | .. note:: |
| 9974 | |
| 9975 | Be sure to verify that your host can access the target via TCP. |
| 9976 | |
| 9977 | 7. *Debug a program:* |
| 9978 | |
| 9979 | Debugging a program involves running gdbserver on the target and then |
| 9980 | running Gdb on the host. The example in this step debugs ``gzip``: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 9981 | |
| 9982 | .. code-block:: shell |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9983 | |
| 9984 | root@qemux86:~# gdbserver localhost:1234 /bin/gzip —help |
| 9985 | |
| 9986 | For |
| 9987 | additional gdbserver options, see the `GDB Server |
| 9988 | Documentation <https://www.gnu.org/software/gdb/documentation/>`__. |
| 9989 | |
| 9990 | After running gdbserver on the target, you need to run Gdb on the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 9991 | host and configure it and connect to the target. Use these commands:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 9992 | |
| 9993 | $ cd directory-holding-the-debugfs-directory |
| 9994 | $ arch-gdb |
| 9995 | (gdb) set sysroot debugfs |
| 9996 | (gdb) set substitute-path /usr/src/debug debugfs/usr/src/debug |
| 9997 | (gdb) target remote IP-of-target:1234 |
| 9998 | |
| 9999 | At this |
| 10000 | point, everything should automatically load (i.e. matching binaries, |
| 10001 | symbols and headers). |
| 10002 | |
| 10003 | .. note:: |
| 10004 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10005 | The Gdb ``set`` commands in the previous example can be placed into the |
| 10006 | users ``~/.gdbinit`` file. Upon starting, Gdb automatically runs whatever |
| 10007 | commands are in that file. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10008 | |
| 10009 | 8. *Deploying without a full image rebuild:* |
| 10010 | |
| 10011 | In many cases, during development you want a quick method to deploy a |
| 10012 | new binary to the target and debug it, without waiting for a full |
| 10013 | image build. |
| 10014 | |
| 10015 | One approach to solving this situation is to just build the component |
| 10016 | you want to debug. Once you have built the component, copy the |
| 10017 | executable directly to both the target and the host ``debugfs``. |
| 10018 | |
| 10019 | If the binary is processed through the debug splitting in |
| 10020 | OpenEmbedded, you should also copy the debug items (i.e. ``.debug`` |
| 10021 | contents and corresponding ``/usr/src/debug`` files) from the work |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 10022 | directory. Here is an example:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10023 | |
| 10024 | $ bitbake bash |
| 10025 | $ bitbake -c devshell bash |
| 10026 | $ cd .. |
| 10027 | $ scp packages-split/bash/bin/bash target:/bin/bash |
| 10028 | $ cp -a packages-split/bash-dbg/\* path/debugfs |
| 10029 | |
| 10030 | Debugging with the GNU Project Debugger (GDB) on the Target |
| 10031 | ----------------------------------------------------------- |
| 10032 | |
| 10033 | The previous section addressed using GDB remotely for debugging |
| 10034 | purposes, which is the most usual case due to the inherent hardware |
| 10035 | limitations on many embedded devices. However, debugging in the target |
| 10036 | hardware itself is also possible with more powerful devices. This |
| 10037 | section describes what you need to do in order to support using GDB to |
| 10038 | debug on the target hardware. |
| 10039 | |
| 10040 | To support this kind of debugging, you need do the following: |
| 10041 | |
| 10042 | - Ensure that GDB is on the target. You can do this by adding "gdb" to |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 10043 | :term:`IMAGE_INSTALL`:: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10044 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 10045 | IMAGE_INSTALL:append = " gdb" |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10046 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 10047 | Alternatively, you can add "tools-debug" to :term:`IMAGE_FEATURES`:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10048 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 10049 | IMAGE_FEATURES:append = " tools-debug" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10050 | |
| 10051 | - Ensure that debug symbols are present. You can make sure these |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 10052 | symbols are present by installing ``-dbg``:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10053 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 10054 | IMAGE_INSTALL:append = "packagename-dbg" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10055 | |
| 10056 | Alternatively, you can do the following to include |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 10057 | all the debug symbols:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10058 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 10059 | IMAGE_FEATURES:append = " dbg-pkgs" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10060 | |
| 10061 | .. note:: |
| 10062 | |
| 10063 | To improve the debug information accuracy, you can reduce the level |
| 10064 | of optimization used by the compiler. For example, when adding the |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10065 | following line to your ``local.conf`` file, you will reduce optimization |
| 10066 | from :term:`FULL_OPTIMIZATION` of "-O2" to :term:`DEBUG_OPTIMIZATION` |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 10067 | of "-O -fno-omit-frame-pointer":: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10068 | |
| 10069 | DEBUG_BUILD = "1" |
| 10070 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10071 | Consider that this will reduce the application's performance and is |
| 10072 | recommended only for debugging purposes. |
| 10073 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10074 | Other Debugging Tips |
| 10075 | -------------------- |
| 10076 | |
| 10077 | Here are some other tips that you might find useful: |
| 10078 | |
| 10079 | - When adding new packages, it is worth watching for undesirable items |
| 10080 | making their way into compiler command lines. For example, you do not |
| 10081 | want references to local system files like ``/usr/lib/`` or |
| 10082 | ``/usr/include/``. |
| 10083 | |
| 10084 | - If you want to remove the ``psplash`` boot splashscreen, add |
| 10085 | ``psplash=false`` to the kernel command line. Doing so prevents |
| 10086 | ``psplash`` from loading and thus allows you to see the console. It |
| 10087 | is also possible to switch out of the splashscreen by switching the |
| 10088 | virtual console (e.g. Fn+Left or Fn+Right on a Zaurus). |
| 10089 | |
| 10090 | - Removing :term:`TMPDIR` (usually |
| 10091 | ``tmp/``, within the |
| 10092 | :term:`Build Directory`) can often fix |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 10093 | temporary build issues. Removing :term:`TMPDIR` is usually a relatively |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10094 | cheap operation, because task output will be cached in |
| 10095 | :term:`SSTATE_DIR` (usually |
| 10096 | ``sstate-cache/``, which is also in the Build Directory). |
| 10097 | |
| 10098 | .. note:: |
| 10099 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 10100 | Removing :term:`TMPDIR` might be a workaround rather than a fix. |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10101 | Consequently, trying to determine the underlying cause of an issue before |
| 10102 | removing the directory is a good idea. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10103 | |
| 10104 | - Understanding how a feature is used in practice within existing |
| 10105 | recipes can be very helpful. It is recommended that you configure |
| 10106 | some method that allows you to quickly search through files. |
| 10107 | |
| 10108 | Using GNU Grep, you can use the following shell function to |
| 10109 | recursively search through common recipe-related files, skipping |
| 10110 | binary files, ``.git`` directories, and the Build Directory (assuming |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 10111 | its name starts with "build"):: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10112 | |
| 10113 | g() { |
| 10114 | grep -Ir \ |
| 10115 | --exclude-dir=.git \ |
| 10116 | --exclude-dir='build*' \ |
| 10117 | --include='*.bb*' \ |
| 10118 | --include='*.inc*' \ |
| 10119 | --include='*.conf*' \ |
| 10120 | --include='*.py*' \ |
| 10121 | "$@" |
| 10122 | } |
| 10123 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 10124 | Following are some usage examples:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10125 | |
| 10126 | $ g FOO # Search recursively for "FOO" |
| 10127 | $ g -i foo # Search recursively for "foo", ignoring case |
| 10128 | $ g -w FOO # Search recursively for "FOO" as a word, ignoring e.g. "FOOBAR" |
| 10129 | |
| 10130 | If figuring |
| 10131 | out how some feature works requires a lot of searching, it might |
| 10132 | indicate that the documentation should be extended or improved. In |
| 10133 | such cases, consider filing a documentation bug using the Yocto |
| 10134 | Project implementation of |
| 10135 | :yocto_bugs:`Bugzilla <>`. For information on |
| 10136 | 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] | 10137 | Bugzilla :yocto_wiki:`wiki page </Bugzilla_Configuration_and_Bug_Tracking>` |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 10138 | and the |
| 10139 | ":ref:`dev-manual/common-tasks:submitting a defect against the yocto project`" |
| 10140 | section. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10141 | |
| 10142 | .. note:: |
| 10143 | |
| 10144 | The manuals might not be the right place to document variables |
| 10145 | that are purely internal and have a limited scope (e.g. internal |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10146 | variables used to implement a single ``.bbclass`` file). |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10147 | |
| 10148 | Making Changes to the Yocto Project |
| 10149 | =================================== |
| 10150 | |
| 10151 | Because the Yocto Project is an open-source, community-based project, |
| 10152 | you can effect changes to the project. This section presents procedures |
| 10153 | that show you how to submit a defect against the project and how to |
| 10154 | submit a change. |
| 10155 | |
| 10156 | Submitting a Defect Against the Yocto Project |
| 10157 | --------------------------------------------- |
| 10158 | |
| 10159 | Use the Yocto Project implementation of |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10160 | `Bugzilla <https://www.bugzilla.org/about/>`__ to submit a defect (bug) |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10161 | against the Yocto Project. For additional information on this |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10162 | implementation of Bugzilla see the ":ref:`Yocto Project |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10163 | Bugzilla <resources-bugtracker>`" section in the |
| 10164 | Yocto Project Reference Manual. For more detail on any of the following |
| 10165 | steps, see the Yocto Project |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 10166 | :yocto_wiki:`Bugzilla wiki page </Bugzilla_Configuration_and_Bug_Tracking>`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10167 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10168 | Use the following general steps to submit a bug: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10169 | |
| 10170 | 1. Open the Yocto Project implementation of :yocto_bugs:`Bugzilla <>`. |
| 10171 | |
| 10172 | 2. Click "File a Bug" to enter a new bug. |
| 10173 | |
| 10174 | 3. Choose the appropriate "Classification", "Product", and "Component" |
| 10175 | for which the bug was found. Bugs for the Yocto Project fall into |
| 10176 | one of several classifications, which in turn break down into |
| 10177 | several products and components. For example, for a bug against the |
| 10178 | ``meta-intel`` layer, you would choose "Build System, Metadata & |
| 10179 | Runtime", "BSPs", and "bsps-meta-intel", respectively. |
| 10180 | |
| 10181 | 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] | 10182 | bug (e.g. &DISTRO;). |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10183 | |
| 10184 | 5. Determine and select the "Severity" of the bug. The severity |
| 10185 | indicates how the bug impacted your work. |
| 10186 | |
| 10187 | 6. Choose the "Hardware" that the bug impacts. |
| 10188 | |
| 10189 | 7. Choose the "Architecture" that the bug impacts. |
| 10190 | |
| 10191 | 8. Choose a "Documentation change" item for the bug. Fixing a bug might |
| 10192 | or might not affect the Yocto Project documentation. If you are |
| 10193 | unsure of the impact to the documentation, select "Don't Know". |
| 10194 | |
| 10195 | 9. Provide a brief "Summary" of the bug. Try to limit your summary to |
| 10196 | just a line or two and be sure to capture the essence of the bug. |
| 10197 | |
| 10198 | 10. Provide a detailed "Description" of the bug. You should provide as |
| 10199 | much detail as you can about the context, behavior, output, and so |
| 10200 | forth that surrounds the bug. You can even attach supporting files |
| 10201 | for output from logs by using the "Add an attachment" button. |
| 10202 | |
| 10203 | 11. Click the "Submit Bug" button submit the bug. A new Bugzilla number |
| 10204 | is assigned to the bug and the defect is logged in the bug tracking |
| 10205 | system. |
| 10206 | |
| 10207 | Once you file a bug, the bug is processed by the Yocto Project Bug |
| 10208 | Triage Team and further details concerning the bug are assigned (e.g. |
| 10209 | priority and owner). You are the "Submitter" of the bug and any further |
| 10210 | categorization, progress, or comments on the bug result in Bugzilla |
| 10211 | sending you an automated email concerning the particular change or |
| 10212 | progress to the bug. |
| 10213 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10214 | Submitting a Change to the Yocto Project |
| 10215 | ---------------------------------------- |
| 10216 | |
| 10217 | Contributions to the Yocto Project and OpenEmbedded are very welcome. |
| 10218 | Because the system is extremely configurable and flexible, we recognize |
| 10219 | that developers will want to extend, configure or optimize it for their |
| 10220 | specific uses. |
| 10221 | |
| 10222 | The Yocto Project uses a mailing list and a patch-based workflow that is |
| 10223 | similar to the Linux kernel but contains important differences. In |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 10224 | general, there is a mailing list through which you can submit patches. You |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10225 | should send patches to the appropriate mailing list so that they can be |
| 10226 | reviewed and merged by the appropriate maintainer. The specific mailing |
| 10227 | list you need to use depends on the location of the code you are |
| 10228 | changing. Each component (e.g. layer) should have a ``README`` file that |
| 10229 | indicates where to send the changes and which process to follow. |
| 10230 | |
| 10231 | You can send the patch to the mailing list using whichever approach you |
| 10232 | feel comfortable with to generate the patch. Once sent, the patch is |
| 10233 | usually reviewed by the community at large. If somebody has concerns |
| 10234 | with the patch, they will usually voice their concern over the mailing |
| 10235 | list. If a patch does not receive any negative reviews, the maintainer |
| 10236 | of the affected layer typically takes the patch, tests it, and then |
| 10237 | based on successful testing, merges the patch. |
| 10238 | |
| 10239 | The "poky" repository, which is the Yocto Project's reference build |
| 10240 | environment, is a hybrid repository that contains several individual |
| 10241 | pieces (e.g. BitBake, Metadata, documentation, and so forth) built using |
| 10242 | the combo-layer tool. The upstream location used for submitting changes |
| 10243 | varies by component: |
| 10244 | |
| 10245 | - *Core Metadata:* Send your patch to the |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10246 | :oe_lists:`openembedded-core </g/openembedded-core>` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10247 | mailing list. For example, a change to anything under the ``meta`` or |
| 10248 | ``scripts`` directories should be sent to this mailing list. |
| 10249 | |
| 10250 | - *BitBake:* For changes to BitBake (i.e. anything under the |
| 10251 | ``bitbake`` directory), send your patch to the |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10252 | :oe_lists:`bitbake-devel </g/bitbake-devel>` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10253 | mailing list. |
| 10254 | |
Andrew Geissler | c3d88e4 | 2020-10-02 09:45:00 -0500 | [diff] [blame] | 10255 | - *"meta-\*" trees:* These trees contain Metadata. Use the |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10256 | :yocto_lists:`poky </g/poky>` mailing list. |
Andrew Geissler | c3d88e4 | 2020-10-02 09:45:00 -0500 | [diff] [blame] | 10257 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10258 | - *Documentation*: For changes to the Yocto Project documentation, use the |
| 10259 | :yocto_lists:`docs </g/docs>` mailing list. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10260 | |
| 10261 | For changes to other layers hosted in the Yocto Project source |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10262 | repositories (i.e. ``yoctoproject.org``) and tools use the |
| 10263 | :yocto_lists:`Yocto Project </g/yocto/>` general mailing list. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10264 | |
| 10265 | .. note:: |
| 10266 | |
| 10267 | Sometimes a layer's documentation specifies to use a particular |
| 10268 | mailing list. If so, use that list. |
| 10269 | |
| 10270 | For additional recipes that do not fit into the core Metadata, you |
| 10271 | should determine which layer the recipe should go into and submit the |
| 10272 | change in the manner recommended by the documentation (e.g. the |
| 10273 | ``README`` file) supplied with the layer. If in doubt, please ask on the |
| 10274 | Yocto general mailing list or on the openembedded-devel mailing list. |
| 10275 | |
| 10276 | You can also push a change upstream and request a maintainer to pull the |
| 10277 | change into the component's upstream repository. You do this by pushing |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 10278 | to a contribution repository that is upstream. See the |
| 10279 | ":ref:`overview-manual/development-environment:git workflows and the yocto project`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10280 | section in the Yocto Project Overview and Concepts Manual for additional |
| 10281 | concepts on working in the Yocto Project development environment. |
| 10282 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10283 | Maintainers commonly use ``-next`` branches to test submissions prior to |
| 10284 | merging patches. Thus, you can get an idea of the status of a patch based on |
| 10285 | whether the patch has been merged into one of these branches. The commonly |
| 10286 | used testing branches for OpenEmbedded-Core are as follows: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10287 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10288 | - *openembedded-core "master-next" branch:* This branch is part of the |
| 10289 | :oe_git:`openembedded-core </openembedded-core/>` repository and contains |
| 10290 | proposed changes to the core metadata. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10291 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10292 | - *poky "master-next" branch:* This branch is part of the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 10293 | :yocto_git:`poky </poky/>` repository and combines proposed |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10294 | changes to bitbake, the core metadata and the poky distro. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10295 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10296 | Similarly, stable branches maintained by the project may have corresponding |
| 10297 | ``-next`` branches which collect proposed changes. For example, |
| 10298 | ``&DISTRO_NAME_NO_CAP;-next`` and ``&DISTRO_NAME_NO_CAP_MINUS_ONE;-next`` |
| 10299 | branches in both the "openembdedded-core" and "poky" repositories. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10300 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10301 | Other layers may have similar testing branches but there is no formal |
| 10302 | requirement or standard for these so please check the documentation for the |
| 10303 | layers you are contributing to. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10304 | |
| 10305 | The following sections provide procedures for submitting a change. |
| 10306 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10307 | Preparing Changes for Submission |
| 10308 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10309 | |
| 10310 | 1. *Make Your Changes Locally:* Make your changes in your local Git |
| 10311 | repository. You should make small, controlled, isolated changes. |
| 10312 | Keeping changes small and isolated aids review, makes |
| 10313 | merging/rebasing easier and keeps the change history clean should |
| 10314 | anyone need to refer to it in future. |
| 10315 | |
| 10316 | 2. *Stage Your Changes:* Stage your changes by using the ``git add`` |
| 10317 | command on each file you changed. |
| 10318 | |
| 10319 | 3. *Commit Your Changes:* Commit the change by using the ``git commit`` |
| 10320 | command. Make sure your commit information follows standards by |
| 10321 | following these accepted conventions: |
| 10322 | |
| 10323 | - Be sure to include a "Signed-off-by:" line in the same style as |
| 10324 | required by the Linux kernel. Adding this line signifies that you, |
| 10325 | the submitter, have agreed to the Developer's Certificate of |
| 10326 | Origin 1.1 as follows: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10327 | |
| 10328 | .. code-block:: none |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10329 | |
| 10330 | Developer's Certificate of Origin 1.1 |
| 10331 | |
| 10332 | By making a contribution to this project, I certify that: |
| 10333 | |
| 10334 | (a) The contribution was created in whole or in part by me and I |
| 10335 | have the right to submit it under the open source license |
| 10336 | indicated in the file; or |
| 10337 | |
| 10338 | (b) The contribution is based upon previous work that, to the best |
| 10339 | of my knowledge, is covered under an appropriate open source |
| 10340 | license and I have the right under that license to submit that |
| 10341 | work with modifications, whether created in whole or in part |
| 10342 | by me, under the same open source license (unless I am |
| 10343 | permitted to submit under a different license), as indicated |
| 10344 | in the file; or |
| 10345 | |
| 10346 | (c) The contribution was provided directly to me by some other |
| 10347 | person who certified (a), (b) or (c) and I have not modified |
| 10348 | it. |
| 10349 | |
| 10350 | (d) I understand and agree that this project and the contribution |
| 10351 | are public and that a record of the contribution (including all |
| 10352 | personal information I submit with it, including my sign-off) is |
| 10353 | maintained indefinitely and may be redistributed consistent with |
| 10354 | this project or the open source license(s) involved. |
| 10355 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10356 | - Provide a single-line summary of the change and, if more |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10357 | explanation is needed, provide more detail in the body of the |
| 10358 | commit. This summary is typically viewable in the "shortlist" of |
| 10359 | changes. Thus, providing something short and descriptive that |
| 10360 | gives the reader a summary of the change is useful when viewing a |
| 10361 | list of many commits. You should prefix this short description |
| 10362 | with the recipe name (if changing a recipe), or else with the |
| 10363 | short form path to the file being changed. |
| 10364 | |
| 10365 | - For the body of the commit message, provide detailed information |
| 10366 | that describes what you changed, why you made the change, and the |
| 10367 | approach you used. It might also be helpful if you mention how you |
| 10368 | tested the change. Provide as much detail as you can in the body |
| 10369 | of the commit message. |
| 10370 | |
| 10371 | .. note:: |
| 10372 | |
| 10373 | You do not need to provide a more detailed explanation of a |
| 10374 | change if the change is minor to the point of the single line |
| 10375 | summary providing all the information. |
| 10376 | |
| 10377 | - If the change addresses a specific bug or issue that is associated |
| 10378 | with a bug-tracking ID, include a reference to that ID in your |
| 10379 | detailed description. For example, the Yocto Project uses a |
| 10380 | specific convention for bug references - any commit that addresses |
| 10381 | a specific bug should use the following form for the detailed |
| 10382 | description. Be sure to use the actual bug-tracking ID from |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 10383 | Bugzilla for bug-id:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10384 | |
| 10385 | Fixes [YOCTO #bug-id] |
| 10386 | |
| 10387 | detailed description of change |
| 10388 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10389 | Using Email to Submit a Patch |
| 10390 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 10391 | |
| 10392 | Depending on the components changed, you need to submit the email to a |
| 10393 | specific mailing list. For some guidance on which mailing list to use, |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 10394 | see the |
| 10395 | :ref:`list <dev-manual/common-tasks:submitting a change to the yocto project>` |
| 10396 | at the beginning of this section. For a description of all the available |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10397 | mailing lists, see the ":ref:`Mailing Lists <resources-mailinglist>`" section in the |
| 10398 | Yocto Project Reference Manual. |
| 10399 | |
| 10400 | Here is the general procedure on how to submit a patch through email |
| 10401 | without using the scripts once the steps in |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 10402 | :ref:`dev-manual/common-tasks:preparing changes for submission` have been followed: |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10403 | |
| 10404 | 1. *Format the Commit:* Format the commit into an email message. To |
| 10405 | format commits, use the ``git format-patch`` command. When you |
| 10406 | provide the command, you must include a revision list or a number of |
| 10407 | patches as part of the command. For example, either of these two |
| 10408 | commands takes your most recent single commit and formats it as an |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 10409 | email message in the current directory:: |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10410 | |
| 10411 | $ git format-patch -1 |
| 10412 | |
| 10413 | or :: |
| 10414 | |
| 10415 | $ git format-patch HEAD~ |
| 10416 | |
| 10417 | After the command is run, the current directory contains a numbered |
| 10418 | ``.patch`` file for the commit. |
| 10419 | |
| 10420 | If you provide several commits as part of the command, the |
| 10421 | ``git format-patch`` command produces a series of numbered files in |
| 10422 | the current directory – one for each commit. If you have more than |
| 10423 | one patch, you should also use the ``--cover`` option with the |
| 10424 | command, which generates a cover letter as the first "patch" in the |
| 10425 | series. You can then edit the cover letter to provide a description |
| 10426 | for the series of patches. For information on the |
| 10427 | ``git format-patch`` command, see ``GIT_FORMAT_PATCH(1)`` displayed |
| 10428 | using the ``man git-format-patch`` command. |
| 10429 | |
| 10430 | .. note:: |
| 10431 | |
| 10432 | If you are or will be a frequent contributor to the Yocto Project |
| 10433 | or to OpenEmbedded, you might consider requesting a contrib area |
| 10434 | and the necessary associated rights. |
| 10435 | |
| 10436 | 2. *Send the patches via email:* Send the patches to the recipients and |
| 10437 | relevant mailing lists by using the ``git send-email`` command. |
| 10438 | |
| 10439 | .. note:: |
| 10440 | |
| 10441 | In order to use ``git send-email``, you must have the proper Git packages |
| 10442 | installed on your host. |
| 10443 | For Ubuntu, Debian, and Fedora the package is ``git-email``. |
| 10444 | |
| 10445 | The ``git send-email`` command sends email by using a local or remote |
| 10446 | Mail Transport Agent (MTA) such as ``msmtp``, ``sendmail``, or |
| 10447 | through a direct ``smtp`` configuration in your Git ``~/.gitconfig`` |
| 10448 | file. If you are submitting patches through email only, it is very |
| 10449 | important that you submit them without any whitespace or HTML |
| 10450 | formatting that either you or your mailer introduces. The maintainer |
| 10451 | that receives your patches needs to be able to save and apply them |
| 10452 | directly from your emails. A good way to verify that what you are |
| 10453 | sending will be applicable by the maintainer is to do a dry run and |
| 10454 | send them to yourself and then save and apply them as the maintainer |
| 10455 | would. |
| 10456 | |
| 10457 | The ``git send-email`` command is the preferred method for sending |
| 10458 | your patches using email since there is no risk of compromising |
| 10459 | whitespace in the body of the message, which can occur when you use |
| 10460 | your own mail client. The command also has several options that let |
| 10461 | you specify recipients and perform further editing of the email |
| 10462 | message. For information on how to use the ``git send-email`` |
| 10463 | command, see ``GIT-SEND-EMAIL(1)`` displayed using the |
| 10464 | ``man git-send-email`` command. |
| 10465 | |
| 10466 | The Yocto Project uses a `Patchwork instance <https://patchwork.openembedded.org/>`__ |
| 10467 | to track the status of patches submitted to the various mailing lists and to |
| 10468 | support automated patch testing. Each submitted patch is checked for common |
| 10469 | mistakes and deviations from the expected patch format and submitters are |
| 10470 | notified by patchtest if such mistakes are found. This process helps to |
| 10471 | reduce the burden of patch review on maintainers. |
| 10472 | |
| 10473 | .. note:: |
| 10474 | |
| 10475 | This system is imperfect and changes can sometimes get lost in the flow. |
| 10476 | Asking about the status of a patch or change is reasonable if the change |
| 10477 | has been idle for a while with no feedback. |
| 10478 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10479 | Using Scripts to Push a Change Upstream and Request a Pull |
| 10480 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 10481 | |
| 10482 | For larger patch series it is preferable to send a pull request which not |
| 10483 | only includes the patch but also a pointer to a branch that can be pulled |
| 10484 | from. This involves making a local branch for your changes, pushing this |
| 10485 | branch to an accessible repository and then using the ``create-pull-request`` |
| 10486 | and ``send-pull-request`` scripts from openembedded-core to create and send a |
| 10487 | patch series with a link to the branch for review. |
| 10488 | |
| 10489 | Follow this procedure to push a change to an upstream "contrib" Git |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 10490 | 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] | 10491 | been followed: |
| 10492 | |
| 10493 | .. note:: |
| 10494 | |
| 10495 | You can find general Git information on how to push a change upstream |
| 10496 | in the |
| 10497 | `Git Community Book <https://git-scm.com/book/en/v2/Distributed-Git-Distributed-Workflows>`__. |
| 10498 | |
| 10499 | 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] | 10500 | permissions to push to an upstream contrib repository, push the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 10501 | change to that repository:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10502 | |
| 10503 | $ git push upstream_remote_repo local_branch_name |
| 10504 | |
| 10505 | For example, suppose you have permissions to push |
| 10506 | into the upstream ``meta-intel-contrib`` repository and you are |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10507 | working in a local branch named `your_name`\ ``/README``. The following |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10508 | command pushes your local commits to the ``meta-intel-contrib`` |
| 10509 | upstream repository and puts the commit in a branch named |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 10510 | `your_name`\ ``/README``:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10511 | |
| 10512 | $ git push meta-intel-contrib your_name/README |
| 10513 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10514 | 2. *Determine Who to Notify:* Determine the maintainer or the mailing |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10515 | list that you need to notify for the change. |
| 10516 | |
| 10517 | Before submitting any change, you need to be sure who the maintainer |
| 10518 | is or what mailing list that you need to notify. Use either these |
| 10519 | methods to find out: |
| 10520 | |
| 10521 | - *Maintenance File:* Examine the ``maintainers.inc`` file, which is |
| 10522 | located in the :term:`Source Directory` at |
| 10523 | ``meta/conf/distro/include``, to see who is responsible for code. |
| 10524 | |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 10525 | - *Search by File:* Using :ref:`overview-manual/development-environment:git`, you can |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10526 | enter the following command to bring up a short list of all |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 10527 | commits against a specific file:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10528 | |
| 10529 | git shortlog -- filename |
| 10530 | |
| 10531 | Just provide the name of the file for which you are interested. The |
| 10532 | information returned is not ordered by history but does include a |
| 10533 | list of everyone who has committed grouped by name. From the list, |
| 10534 | you can see who is responsible for the bulk of the changes against |
| 10535 | the file. |
| 10536 | |
| 10537 | - *Examine the List of Mailing Lists:* For a list of the Yocto |
| 10538 | Project and related mailing lists, see the ":ref:`Mailing |
| 10539 | lists <resources-mailinglist>`" section in |
| 10540 | the Yocto Project Reference Manual. |
| 10541 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10542 | 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] | 10543 | you have pushed a change by making a pull request. |
| 10544 | |
| 10545 | The Yocto Project provides two scripts that conveniently let you |
| 10546 | generate and send pull requests to the Yocto Project. These scripts |
| 10547 | are ``create-pull-request`` and ``send-pull-request``. You can find |
| 10548 | these scripts in the ``scripts`` directory within the |
| 10549 | :term:`Source Directory` (e.g. |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 10550 | ``poky/scripts``). |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10551 | |
| 10552 | Using these scripts correctly formats the requests without |
| 10553 | introducing any whitespace or HTML formatting. The maintainer that |
| 10554 | receives your patches either directly or through the mailing list |
| 10555 | needs to be able to save and apply them directly from your emails. |
| 10556 | Using these scripts is the preferred method for sending patches. |
| 10557 | |
| 10558 | First, create the pull request. For example, the following command |
| 10559 | runs the script, specifies the upstream repository in the contrib |
| 10560 | directory into which you pushed the change, and provides a subject |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 10561 | line in the created patch files:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10562 | |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 10563 | $ poky/scripts/create-pull-request -u meta-intel-contrib -s "Updated Manual Section Reference in README" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10564 | |
| 10565 | Running this script forms ``*.patch`` files in a folder named |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10566 | ``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] | 10567 | cover letter. |
| 10568 | |
| 10569 | Before running the ``send-pull-request`` script, you must edit the |
| 10570 | cover letter patch to insert information about your change. After |
| 10571 | editing the cover letter, send the pull request. For example, the |
| 10572 | following command runs the script and specifies the patch directory |
| 10573 | and email address. In this example, the email address is a mailing |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 10574 | list:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10575 | |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 10576 | $ poky/scripts/send-pull-request -p ~/meta-intel/pull-10565 -t meta-intel@lists.yoctoproject.org |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10577 | |
| 10578 | You need to follow the prompts as the script is interactive. |
| 10579 | |
| 10580 | .. note:: |
| 10581 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10582 | For help on using these scripts, simply provide the ``-h`` |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 10583 | argument as follows:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10584 | |
| 10585 | $ poky/scripts/create-pull-request -h |
| 10586 | $ poky/scripts/send-pull-request -h |
| 10587 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10588 | Responding to Patch Review |
| 10589 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10590 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10591 | You may get feedback on your submitted patches from other community members |
| 10592 | or from the automated patchtest service. If issues are identified in your |
| 10593 | patch then it is usually necessary to address these before the patch will be |
| 10594 | accepted into the project. In this case you should amend the patch according |
| 10595 | to the feedback and submit an updated version to the relevant mailing list, |
| 10596 | copying in the reviewers who provided feedback to the previous version of the |
| 10597 | patch. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10598 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10599 | The patch should be amended using ``git commit --amend`` or perhaps ``git |
| 10600 | rebase`` for more expert git users. You should also modify the ``[PATCH]`` |
| 10601 | tag in the email subject line when sending the revised patch to mark the new |
| 10602 | iteration as ``[PATCH v2]``, ``[PATCH v3]``, etc as appropriate. This can be |
| 10603 | done by passing the ``-v`` argument to ``git format-patch`` with a version |
| 10604 | number. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10605 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10606 | Lastly please ensure that you also test your revised changes. In particular |
| 10607 | please don't just edit the patch file written out by ``git format-patch`` and |
| 10608 | resend it. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10609 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10610 | Submitting Changes to Stable Release Branches |
| 10611 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10612 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10613 | The process for proposing changes to a Yocto Project stable branch differs |
| 10614 | from the steps described above. Changes to a stable branch must address |
| 10615 | identified bugs or CVEs and should be made carefully in order to avoid the |
| 10616 | risk of introducing new bugs or breaking backwards compatibility. Typically |
| 10617 | bug fixes must already be accepted into the master branch before they can be |
| 10618 | backported to a stable branch unless the bug in question does not affect the |
| 10619 | 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] | 10620 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10621 | The list of stable branches along with the status and maintainer for each |
| 10622 | branch can be obtained from the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 10623 | :yocto_wiki:`Releases wiki page </Releases>`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10624 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10625 | .. note:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10626 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10627 | Changes will not typically be accepted for branches which are marked as |
| 10628 | End-Of-Life (EOL). |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10629 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10630 | With this in mind, the steps to submit a change for a stable branch are as |
| 10631 | follows: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10632 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10633 | 1. *Identify the bug or CVE to be fixed:* This information should be |
| 10634 | collected so that it can be included in your submission. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10635 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 10636 | See :ref:`dev-manual/common-tasks:checking for vulnerabilities` |
| 10637 | for details about CVE tracking. |
| 10638 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10639 | 2. *Check if the fix is already present in the master branch:* This will |
| 10640 | result in the most straightforward path into the stable branch for the |
| 10641 | fix. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10642 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10643 | a. *If the fix is present in the master branch - Submit a backport request |
| 10644 | by email:* You should send an email to the relevant stable branch |
| 10645 | maintainer and the mailing list with details of the bug or CVE to be |
| 10646 | fixed, the commit hash on the master branch that fixes the issue and |
| 10647 | 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] | 10648 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10649 | b. *If the fix is not present in the master branch - Submit the fix to the |
| 10650 | master branch first:* This will ensure that the fix passes through the |
| 10651 | project's usual patch review and test processes before being accepted. |
| 10652 | It will also ensure that bugs are not left unresolved in the master |
| 10653 | branch itself. Once the fix is accepted in the master branch a backport |
| 10654 | request can be submitted as above. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10655 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 10656 | c. *If the fix is unsuitable for the master branch - Submit a patch |
| 10657 | directly for the stable branch:* This method should be considered as a |
| 10658 | last resort. It is typically necessary when the master branch is using |
| 10659 | a newer version of the software which includes an upstream fix for the |
| 10660 | issue or when the issue has been fixed on the master branch in a way |
| 10661 | that introduces backwards incompatible changes. In this case follow the |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 10662 | steps in :ref:`dev-manual/common-tasks:preparing changes for submission` and |
| 10663 | :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] | 10664 | email to include the name of the stable branch which you are |
| 10665 | targetting. This can be done using the ``--subject-prefix`` argument to |
| 10666 | ``git format-patch``, for example to submit a patch to the dunfell |
| 10667 | branch use |
| 10668 | ``git format-patch --subject-prefix='&DISTRO_NAME_NO_CAP_MINUS_ONE;][PATCH' ...``. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10669 | |
| 10670 | Working With Licenses |
| 10671 | ===================== |
| 10672 | |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 10673 | As mentioned in the ":ref:`overview-manual/development-environment:licensing`" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10674 | section in the Yocto Project Overview and Concepts Manual, open source |
| 10675 | projects are open to the public and they consequently have different |
| 10676 | licensing structures in place. This section describes the mechanism by |
| 10677 | which the :term:`OpenEmbedded Build System` |
| 10678 | tracks changes to |
| 10679 | licensing text and covers how to maintain open source license compliance |
| 10680 | during your project's lifecycle. The section also describes how to |
| 10681 | enable commercially licensed recipes, which by default are disabled. |
| 10682 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10683 | Tracking License Changes |
| 10684 | ------------------------ |
| 10685 | |
| 10686 | The license of an upstream project might change in the future. In order |
| 10687 | to prevent these changes going unnoticed, the |
| 10688 | :term:`LIC_FILES_CHKSUM` |
| 10689 | variable tracks changes to the license text. The checksums are validated |
| 10690 | at the end of the configure step, and if the checksums do not match, the |
| 10691 | build will fail. |
| 10692 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10693 | Specifying the ``LIC_FILES_CHKSUM`` Variable |
| 10694 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 10695 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 10696 | The :term:`LIC_FILES_CHKSUM` variable contains checksums of the license text |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10697 | in the source code for the recipe. Following is an example of how to |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 10698 | specify :term:`LIC_FILES_CHKSUM`:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10699 | |
| 10700 | LIC_FILES_CHKSUM = "file://COPYING;md5=xxxx \ |
| 10701 | file://licfile1.txt;beginline=5;endline=29;md5=yyyy \ |
| 10702 | file://licfile2.txt;endline=50;md5=zzzz \ |
| 10703 | ..." |
| 10704 | |
| 10705 | .. note:: |
| 10706 | |
| 10707 | - When using "beginline" and "endline", realize that line numbering |
| 10708 | begins with one and not zero. Also, the included lines are |
| 10709 | inclusive (i.e. lines five through and including 29 in the |
| 10710 | previous example for ``licfile1.txt``). |
| 10711 | |
| 10712 | - When a license check fails, the selected license text is included |
| 10713 | as part of the QA message. Using this output, you can determine |
| 10714 | the exact start and finish for the needed license text. |
| 10715 | |
| 10716 | The build system uses the :term:`S` |
| 10717 | variable as the default directory when searching files listed in |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 10718 | :term:`LIC_FILES_CHKSUM`. The previous example employs the default |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10719 | directory. |
| 10720 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 10721 | Consider this next example:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10722 | |
| 10723 | LIC_FILES_CHKSUM = "file://src/ls.c;beginline=5;endline=16;\ |
| 10724 | md5=bb14ed3c4cda583abc85401304b5cd4e" |
| 10725 | LIC_FILES_CHKSUM = "file://${WORKDIR}/license.html;md5=5c94767cedb5d6987c902ac850ded2c6" |
| 10726 | |
| 10727 | The first line locates a file in ``${S}/src/ls.c`` and isolates lines |
| 10728 | five through 16 as license text. The second line refers to a file in |
| 10729 | :term:`WORKDIR`. |
| 10730 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 10731 | Note that :term:`LIC_FILES_CHKSUM` variable is mandatory for all recipes, |
| 10732 | unless the :term:`LICENSE` variable is set to "CLOSED". |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10733 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10734 | Explanation of Syntax |
| 10735 | ~~~~~~~~~~~~~~~~~~~~~ |
| 10736 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 10737 | As mentioned in the previous section, the :term:`LIC_FILES_CHKSUM` variable |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10738 | lists all the important files that contain the license text for the |
| 10739 | source code. It is possible to specify a checksum for an entire file, or |
| 10740 | a specific section of a file (specified by beginning and ending line |
| 10741 | numbers with the "beginline" and "endline" parameters, respectively). |
| 10742 | The latter is useful for source files with a license notice header, |
| 10743 | README documents, and so forth. If you do not use the "beginline" |
| 10744 | parameter, then it is assumed that the text begins on the first line of |
| 10745 | the file. Similarly, if you do not use the "endline" parameter, it is |
| 10746 | assumed that the license text ends with the last line of the file. |
| 10747 | |
| 10748 | The "md5" parameter stores the md5 checksum of the license text. If the |
| 10749 | license text changes in any way as compared to this parameter then a |
| 10750 | mismatch occurs. This mismatch triggers a build failure and notifies the |
| 10751 | developer. Notification allows the developer to review and address the |
| 10752 | license text changes. Also note that if a mismatch occurs during the |
| 10753 | build, the correct md5 checksum is placed in the build log and can be |
| 10754 | easily copied to the recipe. |
| 10755 | |
| 10756 | There is no limit to how many files you can specify using the |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 10757 | :term:`LIC_FILES_CHKSUM` variable. Generally, however, every project |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10758 | requires a few specifications for license tracking. Many projects have a |
| 10759 | "COPYING" file that stores the license information for all the source |
| 10760 | code files. This practice allows you to just track the "COPYING" file as |
| 10761 | long as it is kept up to date. |
| 10762 | |
| 10763 | .. note:: |
| 10764 | |
| 10765 | - If you specify an empty or invalid "md5" parameter, |
| 10766 | :term:`BitBake` returns an md5 |
| 10767 | mis-match error and displays the correct "md5" parameter value |
| 10768 | during the build. The correct parameter is also captured in the |
| 10769 | build log. |
| 10770 | |
| 10771 | - If the whole file contains only license text, you do not need to |
| 10772 | use the "beginline" and "endline" parameters. |
| 10773 | |
| 10774 | Enabling Commercially Licensed Recipes |
| 10775 | -------------------------------------- |
| 10776 | |
| 10777 | By default, the OpenEmbedded build system disables components that have |
| 10778 | commercial or other special licensing requirements. Such requirements |
| 10779 | are defined on a recipe-by-recipe basis through the |
| 10780 | :term:`LICENSE_FLAGS` variable |
| 10781 | definition in the affected recipe. For instance, the |
| 10782 | ``poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly`` recipe |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 10783 | contains the following statement:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10784 | |
| 10785 | LICENSE_FLAGS = "commercial" |
| 10786 | |
| 10787 | Here is a |
| 10788 | slightly more complicated example that contains both an explicit recipe |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 10789 | name and version (after variable expansion):: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10790 | |
| 10791 | LICENSE_FLAGS = "license_${PN}_${PV}" |
| 10792 | |
| 10793 | In order for a component restricted by a |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 10794 | :term:`LICENSE_FLAGS` definition to be enabled and included in an image, it |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10795 | needs to have a matching entry in the global |
| 10796 | :term:`LICENSE_FLAGS_WHITELIST` |
| 10797 | variable, which is a variable typically defined in your ``local.conf`` |
| 10798 | file. For example, to enable the |
| 10799 | ``poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly`` package, you |
| 10800 | could add either the string "commercial_gst-plugins-ugly" or the more |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 10801 | general string "commercial" to :term:`LICENSE_FLAGS_WHITELIST`. See the |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 10802 | ":ref:`dev-manual/common-tasks:license flag matching`" section for a full |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 10803 | explanation of how :term:`LICENSE_FLAGS` matching works. Here is the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 10804 | example:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10805 | |
| 10806 | LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly" |
| 10807 | |
| 10808 | Likewise, to additionally enable the package built from the recipe |
| 10809 | containing ``LICENSE_FLAGS = "license_${PN}_${PV}"``, and assuming that |
| 10810 | the actual recipe name was ``emgd_1.10.bb``, the following string would |
| 10811 | enable that package as well as the original ``gst-plugins-ugly`` |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 10812 | package:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10813 | |
| 10814 | LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly license_emgd_1.10" |
| 10815 | |
| 10816 | As a convenience, you do not need to specify the |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 10817 | complete license string for every package. You can use |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10818 | an abbreviated form, which consists of just the first portion or |
| 10819 | portions of the license string before the initial underscore character |
| 10820 | or characters. A partial string will match any license that contains the |
| 10821 | given string as the first portion of its license. For example, the |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 10822 | following value will also match both of the packages |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10823 | previously mentioned as well as any other packages that have licenses |
| 10824 | starting with "commercial" or "license". |
| 10825 | :: |
| 10826 | |
| 10827 | LICENSE_FLAGS_WHITELIST = "commercial license" |
| 10828 | |
| 10829 | License Flag Matching |
| 10830 | ~~~~~~~~~~~~~~~~~~~~~ |
| 10831 | |
| 10832 | License flag matching allows you to control what recipes the |
| 10833 | OpenEmbedded build system includes in the build. Fundamentally, the |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 10834 | build system attempts to match :term:`LICENSE_FLAGS` strings found in |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 10835 | recipes against strings found in :term:`LICENSE_FLAGS_WHITELIST`. |
| 10836 | A match causes the build system to include a recipe in the |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10837 | build, while failure to find a match causes the build system to exclude |
| 10838 | a recipe. |
| 10839 | |
| 10840 | In general, license flag matching is simple. However, understanding some |
| 10841 | concepts will help you correctly and effectively use matching. |
| 10842 | |
| 10843 | Before a flag defined by a particular recipe is tested against the |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 10844 | entries of :term:`LICENSE_FLAGS_WHITELIST`, the expanded |
| 10845 | string ``_${PN}`` is appended to the flag. This expansion makes each |
| 10846 | :term:`LICENSE_FLAGS` value recipe-specific. After expansion, the |
| 10847 | string is then matched against the entries. Thus, specifying |
| 10848 | ``LICENSE_FLAGS = "commercial"`` in recipe "foo", for example, results |
| 10849 | in the string ``"commercial_foo"``. And, to create a match, that string |
| 10850 | must appear among the entries of :term:`LICENSE_FLAGS_WHITELIST`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10851 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 10852 | Judicious use of the :term:`LICENSE_FLAGS` strings and the contents of the |
| 10853 | :term:`LICENSE_FLAGS_WHITELIST` variable allows you a lot of flexibility for |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10854 | including or excluding recipes based on licensing. For example, you can |
| 10855 | broaden the matching capabilities by using license flags string subsets |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 10856 | in :term:`LICENSE_FLAGS_WHITELIST`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10857 | |
| 10858 | .. note:: |
| 10859 | |
| 10860 | When using a string subset, be sure to use the part of the expanded |
| 10861 | string that precedes the appended underscore character (e.g. |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10862 | ``usethispart_1.3``, ``usethispart_1.4``, and so forth). |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10863 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 10864 | For example, simply specifying the string "commercial" in the |
| 10865 | :term:`LICENSE_FLAGS_WHITELIST` variable matches any expanded |
| 10866 | :term:`LICENSE_FLAGS` definition that starts with the string |
| 10867 | "commercial" such as "commercial_foo" and "commercial_bar", which |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10868 | are the strings the build system automatically generates for |
| 10869 | hypothetical recipes named "foo" and "bar" assuming those recipes simply |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 10870 | specify the following:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10871 | |
| 10872 | LICENSE_FLAGS = "commercial" |
| 10873 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 10874 | Thus, you can choose to exhaustively enumerate each license flag in the |
| 10875 | list and allow only specific recipes into the image, or you can use a |
| 10876 | string subset that causes a broader range of matches to allow a range of |
| 10877 | recipes into the image. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10878 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 10879 | This scheme works even if the :term:`LICENSE_FLAGS` string already has |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10880 | ``_${PN}`` appended. For example, the build system turns the license |
| 10881 | flag "commercial_1.2_foo" into "commercial_1.2_foo_foo" and would match |
| 10882 | both the general "commercial" and the specific "commercial_1.2_foo" |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 10883 | strings found in the :term:`LICENSE_FLAGS_WHITELIST` variable, as expected. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10884 | |
| 10885 | Here are some other scenarios: |
| 10886 | |
| 10887 | - You can specify a versioned string in the recipe such as |
| 10888 | "commercial_foo_1.2" in a "foo" recipe. The build system expands this |
| 10889 | string to "commercial_foo_1.2_foo". Combine this license flag with a |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 10890 | :term:`LICENSE_FLAGS_WHITELIST` variable that has the string |
| 10891 | "commercial" and you match the flag along with any other flag that |
| 10892 | starts with the string "commercial". |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10893 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 10894 | - Under the same circumstances, you can add "commercial_foo" in the |
| 10895 | :term:`LICENSE_FLAGS_WHITELIST` variable and the build system not only |
| 10896 | matches "commercial_foo_1.2" but also matches any license flag with |
| 10897 | the string "commercial_foo", regardless of the version. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10898 | |
| 10899 | - You can be very specific and use both the package and version parts |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 10900 | in the :term:`LICENSE_FLAGS_WHITELIST` list (e.g. |
| 10901 | "commercial_foo_1.2") to specifically match a versioned recipe. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10902 | |
| 10903 | Other Variables Related to Commercial Licenses |
| 10904 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 10905 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 10906 | There are other helpful variables related to commercial license handling, |
| 10907 | defined in the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 10908 | ``poky/meta/conf/distro/include/default-distrovars.inc`` file:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10909 | |
| 10910 | COMMERCIAL_AUDIO_PLUGINS ?= "" |
| 10911 | COMMERCIAL_VIDEO_PLUGINS ?= "" |
| 10912 | |
| 10913 | If you |
| 10914 | want to enable these components, you can do so by making sure you have |
| 10915 | statements similar to the following in your ``local.conf`` configuration |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 10916 | file:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10917 | |
| 10918 | COMMERCIAL_AUDIO_PLUGINS = "gst-plugins-ugly-mad \ |
| 10919 | gst-plugins-ugly-mpegaudioparse" |
| 10920 | COMMERCIAL_VIDEO_PLUGINS = "gst-plugins-ugly-mpeg2dec \ |
| 10921 | gst-plugins-ugly-mpegstream gst-plugins-bad-mpegvideoparse" |
| 10922 | LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly commercial_gst-plugins-bad commercial_qmmp" |
| 10923 | |
| 10924 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 10925 | Of course, you could also create a matching list for those |
| 10926 | components using the more general "commercial" in the |
| 10927 | :term:`LICENSE_FLAGS_WHITELIST` variable, but that would also enable all |
| 10928 | the other packages with :term:`LICENSE_FLAGS` |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 10929 | containing "commercial", which you may or may not want:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10930 | |
| 10931 | LICENSE_FLAGS_WHITELIST = "commercial" |
| 10932 | |
| 10933 | Specifying audio and video plugins as part of the |
| 10934 | ``COMMERCIAL_AUDIO_PLUGINS`` and ``COMMERCIAL_VIDEO_PLUGINS`` statements |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 10935 | (along with the enabling :term:`LICENSE_FLAGS_WHITELIST`) includes the |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10936 | plugins or components into built images, thus adding support for media |
| 10937 | formats or components. |
| 10938 | |
| 10939 | Maintaining Open Source License Compliance During Your Product's Lifecycle |
| 10940 | -------------------------------------------------------------------------- |
| 10941 | |
| 10942 | One of the concerns for a development organization using open source |
| 10943 | software is how to maintain compliance with various open source |
| 10944 | licensing during the lifecycle of the product. While this section does |
| 10945 | not provide legal advice or comprehensively cover all scenarios, it does |
| 10946 | present methods that you can use to assist you in meeting the compliance |
| 10947 | requirements during a software release. |
| 10948 | |
| 10949 | With hundreds of different open source licenses that the Yocto Project |
| 10950 | tracks, it is difficult to know the requirements of each and every |
| 10951 | license. However, the requirements of the major FLOSS licenses can begin |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 10952 | to be covered by assuming that there are three main areas of concern: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10953 | |
| 10954 | - Source code must be provided. |
| 10955 | |
| 10956 | - License text for the software must be provided. |
| 10957 | |
| 10958 | - Compilation scripts and modifications to the source code must be |
| 10959 | provided. |
| 10960 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10961 | - spdx files can be provided. |
| 10962 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10963 | There are other requirements beyond the scope of these three and the |
| 10964 | methods described in this section (e.g. the mechanism through which |
| 10965 | source code is distributed). |
| 10966 | |
| 10967 | As different organizations have different methods of complying with open |
| 10968 | source licensing, this section is not meant to imply that there is only |
| 10969 | one single way to meet your compliance obligations, but rather to |
| 10970 | describe one method of achieving compliance. The remainder of this |
| 10971 | section describes methods supported to meet the previously mentioned |
| 10972 | three requirements. Once you take steps to meet these requirements, and |
| 10973 | prior to releasing images, sources, and the build system, you should |
| 10974 | audit all artifacts to ensure completeness. |
| 10975 | |
| 10976 | .. note:: |
| 10977 | |
| 10978 | The Yocto Project generates a license manifest during image creation |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 10979 | that is located in ``${DEPLOY_DIR}/licenses/``\ `image_name`\ ``-``\ `datestamp` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10980 | to assist with any audits. |
| 10981 | |
| 10982 | Providing the Source Code |
| 10983 | ~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 10984 | |
| 10985 | Compliance activities should begin before you generate the final image. |
| 10986 | The first thing you should look at is the requirement that tops the list |
| 10987 | for most compliance groups - providing the source. The Yocto Project has |
| 10988 | a few ways of meeting this requirement. |
| 10989 | |
| 10990 | One of the easiest ways to meet this requirement is to provide the |
| 10991 | entire :term:`DL_DIR` used by the |
| 10992 | build. This method, however, has a few issues. The most obvious is the |
| 10993 | size of the directory since it includes all sources used in the build |
| 10994 | and not just the source used in the released image. It will include |
| 10995 | toolchain source, and other artifacts, which you would not generally |
| 10996 | release. However, the more serious issue for most companies is |
| 10997 | accidental release of proprietary software. The Yocto Project provides |
| 10998 | an :ref:`archiver <ref-classes-archiver>` class to |
| 10999 | help avoid some of these concerns. |
| 11000 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 11001 | Before you employ :term:`DL_DIR` or the :ref:`archiver <ref-classes-archiver>` class, you need to |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11002 | decide how you choose to provide source. The source ``archiver`` class |
| 11003 | can generate tarballs and SRPMs and can create them with various levels |
| 11004 | of compliance in mind. |
| 11005 | |
| 11006 | One way of doing this (but certainly not the only way) is to release |
| 11007 | just the source as a tarball. You can do this by adding the following to |
| 11008 | the ``local.conf`` file found in the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 11009 | :term:`Build Directory`:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11010 | |
| 11011 | INHERIT += "archiver" |
| 11012 | ARCHIVER_MODE[src] = "original" |
| 11013 | |
| 11014 | During the creation of your |
| 11015 | image, the source from all recipes that deploy packages to the image is |
| 11016 | placed within subdirectories of ``DEPLOY_DIR/sources`` based on the |
| 11017 | :term:`LICENSE` for each recipe. |
| 11018 | Releasing the entire directory enables you to comply with requirements |
| 11019 | concerning providing the unmodified source. It is important to note that |
| 11020 | the size of the directory can get large. |
| 11021 | |
| 11022 | A way to help mitigate the size issue is to only release tarballs for |
| 11023 | licenses that require the release of source. Let us assume you are only |
| 11024 | concerned with GPL code as identified by running the following script: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 11025 | |
| 11026 | .. code-block:: shell |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11027 | |
| 11028 | # Script to archive a subset of packages matching specific license(s) |
| 11029 | # Source and license files are copied into sub folders of package folder |
| 11030 | # Must be run from build folder |
| 11031 | #!/bin/bash |
| 11032 | src_release_dir="source-release" |
| 11033 | mkdir -p $src_release_dir |
| 11034 | for a in tmp/deploy/sources/*; do |
| 11035 | for d in $a/*; do |
| 11036 | # Get package name from path |
| 11037 | p=`basename $d` |
| 11038 | p=${p%-*} |
| 11039 | p=${p%-*} |
| 11040 | # Only archive GPL packages (update *GPL* regex for your license check) |
| 11041 | numfiles=`ls tmp/deploy/licenses/$p/*GPL* 2> /dev/null | wc -l` |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 11042 | if [ $numfiles -ge 1 ]; then |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11043 | echo Archiving $p |
| 11044 | mkdir -p $src_release_dir/$p/source |
| 11045 | cp $d/* $src_release_dir/$p/source 2> /dev/null |
| 11046 | mkdir -p $src_release_dir/$p/license |
| 11047 | cp tmp/deploy/licenses/$p/* $src_release_dir/$p/license 2> /dev/null |
| 11048 | fi |
| 11049 | done |
| 11050 | done |
| 11051 | |
| 11052 | At this point, you |
| 11053 | could create a tarball from the ``gpl_source_release`` directory and |
| 11054 | provide that to the end user. This method would be a step toward |
| 11055 | achieving compliance with section 3a of GPLv2 and with section 6 of |
| 11056 | GPLv3. |
| 11057 | |
| 11058 | Providing License Text |
| 11059 | ~~~~~~~~~~~~~~~~~~~~~~ |
| 11060 | |
| 11061 | One requirement that is often overlooked is inclusion of license text. |
| 11062 | This requirement also needs to be dealt with prior to generating the |
| 11063 | final image. Some licenses require the license text to accompany the |
| 11064 | binary. You can achieve this by adding the following to your |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 11065 | ``local.conf`` file:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11066 | |
| 11067 | COPY_LIC_MANIFEST = "1" |
| 11068 | COPY_LIC_DIRS = "1" |
| 11069 | LICENSE_CREATE_PACKAGE = "1" |
| 11070 | |
| 11071 | Adding these statements to the |
| 11072 | configuration file ensures that the licenses collected during package |
| 11073 | generation are included on your image. |
| 11074 | |
| 11075 | .. note:: |
| 11076 | |
| 11077 | Setting all three variables to "1" results in the image having two |
| 11078 | copies of the same license file. One copy resides in |
| 11079 | ``/usr/share/common-licenses`` and the other resides in |
| 11080 | ``/usr/share/license``. |
| 11081 | |
| 11082 | The reason for this behavior is because |
| 11083 | :term:`COPY_LIC_DIRS` and |
| 11084 | :term:`COPY_LIC_MANIFEST` |
| 11085 | add a copy of the license when the image is built but do not offer a |
| 11086 | path for adding licenses for newly installed packages to an image. |
| 11087 | :term:`LICENSE_CREATE_PACKAGE` |
| 11088 | adds a separate package and an upgrade path for adding licenses to an |
| 11089 | image. |
| 11090 | |
| 11091 | As the source ``archiver`` class has already archived the original |
| 11092 | unmodified source that contains the license files, you would have |
| 11093 | already met the requirements for inclusion of the license information |
| 11094 | with source as defined by the GPL and other open source licenses. |
| 11095 | |
| 11096 | Providing Compilation Scripts and Source Code Modifications |
| 11097 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 11098 | |
| 11099 | At this point, we have addressed all we need to prior to generating the |
| 11100 | image. The next two requirements are addressed during the final |
| 11101 | packaging of the release. |
| 11102 | |
| 11103 | By releasing the version of the OpenEmbedded build system and the layers |
| 11104 | used during the build, you will be providing both compilation scripts |
| 11105 | and the source code modifications in one step. |
| 11106 | |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 11107 | If the deployment team has a :ref:`overview-manual/concepts:bsp layer` |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11108 | and a distro layer, and those |
| 11109 | those layers are used to patch, compile, package, or modify (in any way) |
| 11110 | any open source software included in your released images, you might be |
| 11111 | required to release those layers under section 3 of GPLv2 or section 1 |
| 11112 | of GPLv3. One way of doing that is with a clean checkout of the version |
| 11113 | of the Yocto Project and layers used during your build. Here is an |
| 11114 | example: |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 11115 | |
| 11116 | .. code-block:: shell |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11117 | |
| 11118 | # We built using the dunfell branch of the poky repo |
| 11119 | $ git clone -b dunfell git://git.yoctoproject.org/poky |
| 11120 | $ cd poky |
| 11121 | # We built using the release_branch for our layers |
| 11122 | $ git clone -b release_branch git://git.mycompany.com/meta-my-bsp-layer |
| 11123 | $ git clone -b release_branch git://git.mycompany.com/meta-my-software-layer |
| 11124 | # clean up the .git repos |
| 11125 | $ find . -name ".git" -type d -exec rm -rf {} \; |
| 11126 | |
| 11127 | One |
| 11128 | thing a development organization might want to consider for end-user |
| 11129 | convenience is to modify ``meta-poky/conf/bblayers.conf.sample`` to |
| 11130 | ensure that when the end user utilizes the released build system to |
| 11131 | build an image, the development organization's layers are included in |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 11132 | the ``bblayers.conf`` file automatically:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11133 | |
| 11134 | # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf |
| 11135 | # changes incompatibly |
| 11136 | POKY_BBLAYERS_CONF_VERSION = "2" |
| 11137 | |
| 11138 | BBPATH = "${TOPDIR}" |
| 11139 | BBFILES ?= "" |
| 11140 | |
| 11141 | BBLAYERS ?= " \ |
| 11142 | ##OEROOT##/meta \ |
| 11143 | ##OEROOT##/meta-poky \ |
| 11144 | ##OEROOT##/meta-yocto-bsp \ |
| 11145 | ##OEROOT##/meta-mylayer \ |
| 11146 | " |
| 11147 | |
| 11148 | Creating and |
| 11149 | providing an archive of the :term:`Metadata` |
| 11150 | layers (recipes, configuration files, and so forth) enables you to meet |
| 11151 | your requirements to include the scripts to control compilation as well |
| 11152 | as any modifications to the original source. |
| 11153 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 11154 | Providing spdx files |
| 11155 | ~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 11156 | |
| 11157 | The spdx module has been integrated to a layer named meta-spdxscanner. |
| 11158 | meta-spdxscanner provides several kinds of scanner. If you want to enable |
| 11159 | this function, you have to follow the following steps: |
| 11160 | |
| 11161 | 1. Add meta-spdxscanner layer into ``bblayers.conf``. |
| 11162 | |
| 11163 | 2. Refer to the README in meta-spdxscanner to setup the environment (e.g, |
| 11164 | setup a fossology server) needed for the scanner. |
| 11165 | |
| 11166 | 3. Meta-spdxscanner provides several methods within the bbclass to create spdx files. |
| 11167 | Please choose one that you want to use and enable the spdx task. You have to |
| 11168 | add some config options in ``local.conf`` file in your :term:`Build |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 11169 | Directory`. Here is an example showing how to generate spdx files |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 11170 | during bitbake using the fossology-python.bbclass:: |
| 11171 | |
| 11172 | # Select fossology-python.bbclass. |
| 11173 | INHERIT += "fossology-python" |
| 11174 | # For fossology-python.bbclass, TOKEN is necessary, so, after setup a |
| 11175 | # Fossology server, you have to create a token. |
| 11176 | TOKEN = "eyJ0eXAiO..." |
| 11177 | # The fossology server is necessary for fossology-python.bbclass. |
| 11178 | FOSSOLOGY_SERVER = "http://xx.xx.xx.xx:8081/repo" |
| 11179 | # If you want to upload the source code to a special folder: |
| 11180 | FOLDER_NAME = "xxxx" //Optional |
| 11181 | # If you don't want to put spdx files in tmp/deploy/spdx, you can enable: |
| 11182 | SPDX_DEPLOY_DIR = "${DEPLOY_DIR}" //Optional |
| 11183 | |
| 11184 | For more usage information refer to :yocto_git:`the meta-spdxscanner repository |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 11185 | </meta-spdxscanner/>`. |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 11186 | |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 11187 | Compliance Limitations with Executables Built from Static Libraries |
| 11188 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 11189 | |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 11190 | When package A is added to an image via the :term:`RDEPENDS` or :term:`RRECOMMENDS` |
| 11191 | mechanisms as well as explicitly included in the image recipe with |
| 11192 | :term:`IMAGE_INSTALL`, and depends on a static linked library recipe B |
| 11193 | (``DEPENDS += "B"``), package B will neither appear in the generated license |
| 11194 | manifest nor in the generated source tarballs. This occurs as the |
| 11195 | :ref:`license <ref-classes-license>` and :ref:`archiver <ref-classes-archiver>` |
| 11196 | classes assume that only packages included via :term:`RDEPENDS` or :term:`RRECOMMENDS` |
| 11197 | end up in the image. |
| 11198 | |
| 11199 | As a result, potential obligations regarding license compliance for package B |
| 11200 | may not be met. |
| 11201 | |
| 11202 | The Yocto Project doesn't enable static libraries by default, in part because |
| 11203 | of this issue. Before a solution to this limitation is found, you need to |
| 11204 | keep in mind that if your root filesystem is built from static libraries, |
| 11205 | you will need to manually ensure that your deliveries are compliant |
| 11206 | with the licenses of these libraries. |
| 11207 | |
| 11208 | Copying Non Standard Licenses |
| 11209 | ----------------------------- |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11210 | |
| 11211 | Some packages, such as the linux-firmware package, have many licenses |
| 11212 | that are not in any way common. You can avoid adding a lot of these |
| 11213 | types of common license files, which are only applicable to a specific |
| 11214 | package, by using the |
| 11215 | :term:`NO_GENERIC_LICENSE` |
| 11216 | variable. Using this variable also avoids QA errors when you use a |
| 11217 | non-common, non-CLOSED license in a recipe. |
| 11218 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 11219 | Here is an example that uses the ``LICENSE.Abilis.txt`` file as |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 11220 | the license from the fetched source:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11221 | |
| 11222 | NO_GENERIC_LICENSE[Firmware-Abilis] = "LICENSE.Abilis.txt" |
| 11223 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 11224 | Checking for Vulnerabilities |
| 11225 | ============================ |
| 11226 | |
| 11227 | Vulnerabilities in images |
| 11228 | ------------------------- |
| 11229 | |
| 11230 | The Yocto Project has an infrastructure to track and address unfixed |
| 11231 | known security vulnerabilities, as tracked by the public |
| 11232 | `Common Vulnerabilities and Exposures (CVE) <https://en.wikipedia.org/wiki/Common_Vulnerabilities_and_Exposures>`__ |
| 11233 | database. |
| 11234 | |
| 11235 | To know which packages are vulnerable to known security vulnerabilities, |
| 11236 | add the following setting to your configuration:: |
| 11237 | |
| 11238 | INHERIT += "cve-check" |
| 11239 | |
| 11240 | This way, at build time, BitBake will warn you about known CVEs |
| 11241 | as in the example below:: |
| 11242 | |
| 11243 | WARNING: flex-2.6.4-r0 do_cve_check: Found unpatched CVE (CVE-2019-6293), for more information check /poky/build/tmp/work/core2-64-poky-linux/flex/2.6.4-r0/temp/cve.log |
| 11244 | WARNING: libarchive-3.5.1-r0 do_cve_check: Found unpatched CVE (CVE-2021-36976), for more information check /poky/build/tmp/work/core2-64-poky-linux/libarchive/3.5.1-r0/temp/cve.log |
| 11245 | |
| 11246 | It is also possible to check the CVE status of individual packages as follows:: |
| 11247 | |
| 11248 | bitbake -c cve_check flex libarchive |
| 11249 | |
| 11250 | Note that OpenEmbedded-Core keeps a list of known unfixed CVE issues which can |
| 11251 | be ignored. You can pass this list to the check as follows:: |
| 11252 | |
| 11253 | bitbake -c cve_check libarchive -R conf/distro/include/cve-extra-exclusions.inc |
| 11254 | |
| 11255 | Enabling vulnerabily tracking in recipes |
| 11256 | ---------------------------------------- |
| 11257 | |
| 11258 | The :term:`CVE_PRODUCT` variable defines the name used to match the recipe name |
| 11259 | against the name in the upstream `NIST CVE database <https://nvd.nist.gov/>`__. |
| 11260 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 11261 | Editing recipes to fix vulnerabilities |
| 11262 | -------------------------------------- |
| 11263 | |
| 11264 | To fix a given known vulnerability, you need to add a patch file to your recipe. Here's |
| 11265 | an example from the :oe_layerindex:`ffmpeg recipe</layerindex/recipe/47350>`:: |
| 11266 | |
| 11267 | SRC_URI = "https://www.ffmpeg.org/releases/${BP}.tar.xz \ |
| 11268 | file://0001-libavutil-include-assembly-with-full-path-from-sourc.patch \ |
| 11269 | file://fix-CVE-2020-20446.patch \ |
| 11270 | file://fix-CVE-2020-20453.patch \ |
| 11271 | file://fix-CVE-2020-22015.patch \ |
| 11272 | file://fix-CVE-2020-22021.patch \ |
| 11273 | file://fix-CVE-2020-22033-CVE-2020-22019.patch \ |
| 11274 | file://fix-CVE-2021-33815.patch \ |
| 11275 | |
| 11276 | The :ref:`cve-check <ref-classes-cve-check>` class defines two ways of |
| 11277 | supplying a patch for a given CVE. The first |
| 11278 | way is to use a patch filename that matches the below pattern:: |
| 11279 | |
| 11280 | cve_file_name_match = re.compile(".*([Cc][Vv][Ee]\-\d{4}\-\d+)") |
| 11281 | |
| 11282 | As shown in the example above, multiple CVE IDs can appear in a patch filename, |
| 11283 | but the :ref:`cve-check <ref-classes-cve-check>` class will only consider |
| 11284 | the last CVE ID in the filename as patched. |
| 11285 | |
| 11286 | The second way to recognize a patched CVE ID is when a line matching the |
| 11287 | below pattern is found in any patch file provided by the recipe:: |
| 11288 | |
| 11289 | cve_match = re.compile("CVE:( CVE\-\d{4}\-\d+)+") |
| 11290 | |
| 11291 | This allows a single patch file to address multiple CVE IDs at the same time. |
| 11292 | |
| 11293 | Of course, another way to fix vulnerabilities is to upgrade to a version |
| 11294 | of the package which is not impacted, typically a more recent one. |
| 11295 | The NIST database knows which versions are vulnerable and which ones |
| 11296 | are not. |
| 11297 | |
| 11298 | Last but not least, you can choose to ignore vulnerabilities through |
| 11299 | the :term:`CVE_CHECK_PN_WHITELIST` and :term:`CVE_CHECK_WHITELIST` |
| 11300 | variables. |
| 11301 | |
| 11302 | Implementation details |
| 11303 | ---------------------- |
| 11304 | |
| 11305 | Here's what the :ref:`cve-check <ref-classes-cve-check>` class does to |
| 11306 | find unpatched CVE IDs. |
| 11307 | |
| 11308 | First the code goes through each patch file provided by a recipe. If a valid CVE ID |
| 11309 | is found in the name of the file, the corresponding CVE is considered as patched. |
| 11310 | Don't forget that if multiple CVE IDs are found in the filename, only the last |
| 11311 | one is considered. Then, the code looks for ``CVE: CVE-ID`` lines in the patch |
| 11312 | file. The found CVE IDs are also considered as patched. |
| 11313 | |
| 11314 | Then, the code looks up all the CVE IDs in the NIST database for all the |
| 11315 | products defined in :term:`CVE_PRODUCT`. Then, for each found CVE: |
| 11316 | |
| 11317 | - If the package name (:term:`PN`) is part of |
| 11318 | :term:`CVE_CHECK_PN_WHITELIST`, it is considered as patched. |
| 11319 | |
| 11320 | - If the CVE ID is part of :term:`CVE_CHECK_WHITELIST`, it is |
| 11321 | considered as patched too. |
| 11322 | |
| 11323 | - If the CVE ID is part of the patched CVE for the recipe, it is |
| 11324 | already considered as patched. |
| 11325 | |
| 11326 | - Otherwise, the code checks whether the recipe version (:term:`PV`) |
| 11327 | is within the range of versions impacted by the CVE. If so, the CVE |
| 11328 | is considered as unpatched. |
| 11329 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 11330 | The CVE database is stored in :term:`DL_DIR` and can be inspected using |
| 11331 | ``sqlite3`` command as follows:: |
| 11332 | |
| 11333 | sqlite3 downloads/CVE_CHECK/nvdcve_1.1.db .dump | grep CVE-2021-37462 |
| 11334 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11335 | Using the Error Reporting Tool |
| 11336 | ============================== |
| 11337 | |
| 11338 | The error reporting tool allows you to submit errors encountered during |
| 11339 | builds to a central database. Outside of the build environment, you can |
| 11340 | use a web interface to browse errors, view statistics, and query for |
| 11341 | errors. The tool works using a client-server system where the client |
| 11342 | portion is integrated with the installed Yocto Project |
| 11343 | :term:`Source Directory` (e.g. ``poky``). |
| 11344 | The server receives the information collected and saves it in a |
| 11345 | database. |
| 11346 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 11347 | There is a live instance of the error reporting server at |
| 11348 | https://errors.yoctoproject.org. |
| 11349 | When you want to get help with build failures, you can submit all of the |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11350 | information on the failure easily and then point to the URL in your bug |
| 11351 | report or send an email to the mailing list. |
| 11352 | |
| 11353 | .. note:: |
| 11354 | |
| 11355 | If you send error reports to this server, the reports become publicly |
| 11356 | visible. |
| 11357 | |
| 11358 | Enabling and Using the Tool |
| 11359 | --------------------------- |
| 11360 | |
| 11361 | By default, the error reporting tool is disabled. You can enable it by |
| 11362 | inheriting the |
| 11363 | :ref:`report-error <ref-classes-report-error>` |
| 11364 | class by adding the following statement to the end of your |
| 11365 | ``local.conf`` file in your |
| 11366 | :term:`Build Directory`. |
| 11367 | :: |
| 11368 | |
| 11369 | INHERIT += "report-error" |
| 11370 | |
| 11371 | By default, the error reporting feature stores information in |
| 11372 | ``${``\ :term:`LOG_DIR`\ ``}/error-report``. |
| 11373 | However, you can specify a directory to use by adding the following to |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 11374 | your ``local.conf`` file:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11375 | |
| 11376 | ERR_REPORT_DIR = "path" |
| 11377 | |
| 11378 | Enabling error |
| 11379 | reporting causes the build process to collect the errors and store them |
| 11380 | in a file as previously described. When the build system encounters an |
| 11381 | error, it includes a command as part of the console output. You can run |
| 11382 | the command to send the error file to the server. For example, the |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 11383 | following command sends the errors to an upstream server:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11384 | |
| 11385 | $ send-error-report /home/brandusa/project/poky/build/tmp/log/error-report/error_report_201403141617.txt |
| 11386 | |
| 11387 | In the previous example, the errors are sent to a public database |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 11388 | available at https://errors.yoctoproject.org, which is used by the |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11389 | entire community. If you specify a particular server, you can send the |
| 11390 | errors to a different database. Use the following command for more |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 11391 | information on available options:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11392 | |
| 11393 | $ send-error-report --help |
| 11394 | |
| 11395 | When sending the error file, you are prompted to review the data being |
| 11396 | sent as well as to provide a name and optional email address. Once you |
| 11397 | satisfy these prompts, the command returns a link from the server that |
| 11398 | corresponds to your entry in the database. For example, here is a |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 11399 | typical link: https://errors.yoctoproject.org/Errors/Details/9522/ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11400 | |
| 11401 | Following the link takes you to a web interface where you can browse, |
| 11402 | query the errors, and view statistics. |
| 11403 | |
| 11404 | Disabling the Tool |
| 11405 | ------------------ |
| 11406 | |
| 11407 | To disable the error reporting feature, simply remove or comment out the |
| 11408 | following statement from the end of your ``local.conf`` file in your |
| 11409 | :term:`Build Directory`. |
| 11410 | :: |
| 11411 | |
| 11412 | INHERIT += "report-error" |
| 11413 | |
| 11414 | Setting Up Your Own Error Reporting Server |
| 11415 | ------------------------------------------ |
| 11416 | |
| 11417 | 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] | 11418 | the code from the Git repository at :yocto_git:`/error-report-web/`. |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11419 | Instructions on how to set it up are in the README document. |
| 11420 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11421 | Using Wayland and Weston |
| 11422 | ======================== |
| 11423 | |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 11424 | `Wayland <https://en.wikipedia.org/wiki/Wayland_(display_server_protocol)>`__ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11425 | is a computer display server protocol that provides a method for |
| 11426 | compositing window managers to communicate directly with applications |
| 11427 | and video hardware and expects them to communicate with input hardware |
| 11428 | using other libraries. Using Wayland with supporting targets can result |
| 11429 | in better control over graphics frame rendering than an application |
| 11430 | might otherwise achieve. |
| 11431 | |
| 11432 | The Yocto Project provides the Wayland protocol libraries and the |
| 11433 | reference |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 11434 | `Weston <https://en.wikipedia.org/wiki/Wayland_(display_server_protocol)#Weston>`__ |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11435 | compositor as part of its release. You can find the integrated packages |
| 11436 | in the ``meta`` layer of the :term:`Source Directory`. |
| 11437 | Specifically, you |
| 11438 | can find the recipes that build both Wayland and Weston at |
| 11439 | ``meta/recipes-graphics/wayland``. |
| 11440 | |
| 11441 | You can build both the Wayland and Weston packages for use only with |
| 11442 | targets that accept the `Mesa 3D and Direct Rendering |
| 11443 | Infrastructure <https://en.wikipedia.org/wiki/Mesa_(computer_graphics)>`__, |
| 11444 | which is also known as Mesa DRI. This implies that you cannot build and |
| 11445 | use the packages if your target uses, for example, the Intel Embedded |
| 11446 | Media and Graphics Driver (Intel EMGD) that overrides Mesa DRI. |
| 11447 | |
| 11448 | .. note:: |
| 11449 | |
| 11450 | Due to lack of EGL support, Weston 1.0.3 will not run directly on the |
| 11451 | emulated QEMU hardware. However, this version of Weston will run |
| 11452 | under X emulation without issues. |
| 11453 | |
| 11454 | This section describes what you need to do to implement Wayland and use |
| 11455 | the Weston compositor when building an image for a supporting target. |
| 11456 | |
| 11457 | Enabling Wayland in an Image |
| 11458 | ---------------------------- |
| 11459 | |
| 11460 | To enable Wayland, you need to enable it to be built and enable it to be |
| 11461 | included (installed) in the image. |
| 11462 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11463 | Building Wayland |
| 11464 | ~~~~~~~~~~~~~~~~ |
| 11465 | |
| 11466 | To cause Mesa to build the ``wayland-egl`` platform and Weston to build |
| 11467 | Wayland with Kernel Mode Setting |
| 11468 | (`KMS <https://wiki.archlinux.org/index.php/Kernel_Mode_Setting>`__) |
| 11469 | support, include the "wayland" flag in the |
| 11470 | :term:`DISTRO_FEATURES` |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 11471 | statement in your ``local.conf`` file:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11472 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 11473 | DISTRO_FEATURES:append = " wayland" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11474 | |
| 11475 | .. note:: |
| 11476 | |
| 11477 | If X11 has been enabled elsewhere, Weston will build Wayland with X11 |
| 11478 | support |
| 11479 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11480 | Installing Wayland and Weston |
| 11481 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 11482 | |
| 11483 | To install the Wayland feature into an image, you must include the |
| 11484 | following |
| 11485 | :term:`CORE_IMAGE_EXTRA_INSTALL` |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 11486 | statement in your ``local.conf`` file:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11487 | |
| 11488 | CORE_IMAGE_EXTRA_INSTALL += "wayland weston" |
| 11489 | |
| 11490 | Running Weston |
| 11491 | -------------- |
| 11492 | |
| 11493 | To run Weston inside X11, enabling it as described earlier and building |
| 11494 | a Sato image is sufficient. If you are running your image under Sato, a |
| 11495 | Weston Launcher appears in the "Utility" category. |
| 11496 | |
| 11497 | Alternatively, you can run Weston through the command-line interpretor |
| 11498 | (CLI), which is better suited for development work. To run Weston under |
| 11499 | the CLI, you need to do the following after your image is built: |
| 11500 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 11501 | 1. Run these commands to export ``XDG_RUNTIME_DIR``:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11502 | |
| 11503 | mkdir -p /tmp/$USER-weston |
| 11504 | chmod 0700 /tmp/$USER-weston |
| 11505 | export XDG_RUNTIME_DIR=/tmp/$USER-weston |
| 11506 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 11507 | 2. Launch Weston in the shell:: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 11508 | |
| 11509 | weston |