Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | <!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" |
| 2 | "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" |
| 3 | [<!ENTITY % poky SYSTEM "../poky.ent"> %poky; ] > |
| 4 | |
| 5 | <chapter id='extendpoky'> |
| 6 | |
| 7 | <title>Common Tasks</title> |
| 8 | <para> |
| 9 | This chapter describes fundamental procedures such as creating layers, |
| 10 | adding new software packages, extending or customizing images, |
| 11 | porting work to new hardware (adding a new machine), and so forth. |
| 12 | You will find that the procedures documented here occur often in the |
| 13 | development cycle using the Yocto Project. |
| 14 | </para> |
| 15 | |
| 16 | <section id="understanding-and-creating-layers"> |
| 17 | <title>Understanding and Creating Layers</title> |
| 18 | |
| 19 | <para> |
| 20 | The OpenEmbedded build system supports organizing |
| 21 | <link linkend='metadata'>Metadata</link> into multiple layers. |
| 22 | Layers allow you to isolate different types of customizations from |
| 23 | each other. |
| 24 | You might find it tempting to keep everything in one layer when |
| 25 | working on a single project. |
| 26 | However, the more modular your Metadata, the easier |
| 27 | it is to cope with future changes. |
| 28 | </para> |
| 29 | |
| 30 | <para> |
| 31 | To illustrate how layers are used to keep things modular, consider |
| 32 | machine customizations. |
| 33 | These types of customizations typically reside in a special layer, |
| 34 | rather than a general layer, called a Board Support Package (BSP) |
| 35 | Layer. |
| 36 | Furthermore, the machine customizations should be isolated from |
| 37 | recipes and Metadata that support a new GUI environment, |
| 38 | for example. |
| 39 | This situation gives you a couple of layers: one for the machine |
| 40 | configurations, and one for the GUI environment. |
| 41 | It is important to understand, however, that the BSP layer can |
| 42 | still make machine-specific additions to recipes within the GUI |
| 43 | environment layer without polluting the GUI layer itself |
| 44 | with those machine-specific changes. |
| 45 | You can accomplish this through a recipe that is a BitBake append |
| 46 | (<filename>.bbappend</filename>) file, which is described later |
| 47 | in this section. |
| 48 | </para> |
| 49 | |
| 50 | <para> |
| 51 | </para> |
| 52 | |
| 53 | <section id='yocto-project-layers'> |
| 54 | <title>Layers</title> |
| 55 | |
| 56 | <para> |
| 57 | The <link linkend='source-directory'>Source Directory</link> |
| 58 | contains both general layers and BSP |
| 59 | layers right out of the box. |
| 60 | You can easily identify layers that ship with a |
| 61 | Yocto Project release in the Source Directory by their |
| 62 | folder names. |
| 63 | Folders that represent layers typically have names that begin with |
| 64 | the string <filename>meta-</filename>. |
| 65 | <note> |
| 66 | It is not a requirement that a layer name begin with the |
| 67 | prefix <filename>meta-</filename>, but it is a commonly |
| 68 | accepted standard in the Yocto Project community. |
| 69 | </note> |
| 70 | For example, when you set up the Source Directory structure, |
| 71 | you will see several layers: |
| 72 | <filename>meta</filename>, |
| 73 | <filename>meta-skeleton</filename>, |
| 74 | <filename>meta-selftest</filename>, |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 75 | <filename>meta-poky</filename>, and |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 76 | <filename>meta-yocto-bsp</filename>. |
| 77 | Each of these folders represents a distinct layer. |
| 78 | </para> |
| 79 | |
| 80 | <para> |
| 81 | As another example, if you set up a local copy of the |
| 82 | <filename>meta-intel</filename> Git repository |
| 83 | and then explore the folder of that general layer, |
| 84 | you will discover many Intel-specific BSP layers inside. |
| 85 | For more information on BSP layers, see the |
| 86 | "<ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP Layers</ulink>" |
| 87 | section in the Yocto Project Board Support Package (BSP) |
| 88 | Developer's Guide. |
| 89 | </para> |
| 90 | </section> |
| 91 | |
| 92 | <section id='creating-your-own-layer'> |
| 93 | <title>Creating Your Own Layer</title> |
| 94 | |
| 95 | <para> |
| 96 | It is very easy to create your own layers to use with the |
| 97 | OpenEmbedded build system. |
| 98 | The Yocto Project ships with scripts that speed up creating |
| 99 | general layers and BSP layers. |
| 100 | This section describes the steps you perform by hand to create |
| 101 | a layer so that you can better understand them. |
| 102 | For information about the layer-creation scripts, see the |
| 103 | "<ulink url='&YOCTO_DOCS_BSP_URL;#creating-a-new-bsp-layer-using-the-yocto-bsp-script'>Creating a New BSP Layer Using the yocto-bsp Script</ulink>" |
| 104 | section in the Yocto Project Board Support Package (BSP) |
| 105 | Developer's Guide and the |
| 106 | "<link linkend='creating-a-general-layer-using-the-yocto-layer-script'>Creating a General Layer Using the yocto-layer Script</link>" |
| 107 | section further down in this manual. |
| 108 | </para> |
| 109 | |
| 110 | <para> |
| 111 | Follow these general steps to create your layer: |
| 112 | <orderedlist> |
| 113 | <listitem><para><emphasis>Check Existing Layers:</emphasis> |
| 114 | Before creating a new layer, you should be sure someone |
| 115 | has not already created a layer containing the Metadata |
| 116 | you need. |
| 117 | You can see the |
| 118 | <ulink url='http://layers.openembedded.org/layerindex/layers/'><filename>OpenEmbedded Metadata Index</filename></ulink> |
| 119 | for a list of layers from the OpenEmbedded community |
| 120 | that can be used in the Yocto Project. |
| 121 | </para></listitem> |
| 122 | <listitem><para><emphasis>Create a Directory:</emphasis> |
| 123 | Create the directory for your layer. |
| 124 | While not strictly required, prepend the name of the |
| 125 | folder with the string <filename>meta-</filename>. |
| 126 | For example: |
| 127 | <literallayout class='monospaced'> |
| 128 | meta-mylayer |
| 129 | meta-GUI_xyz |
| 130 | meta-mymachine |
| 131 | </literallayout> |
| 132 | </para></listitem> |
| 133 | <listitem><para><emphasis>Create a Layer Configuration |
| 134 | File:</emphasis> |
| 135 | Inside your new layer folder, you need to create a |
| 136 | <filename>conf/layer.conf</filename> file. |
| 137 | It is easiest to take an existing layer configuration |
| 138 | file and copy that to your layer's |
| 139 | <filename>conf</filename> directory and then modify the |
| 140 | file as needed.</para> |
| 141 | <para>The |
| 142 | <filename>meta-yocto-bsp/conf/layer.conf</filename> file |
| 143 | demonstrates the required syntax: |
| 144 | <literallayout class='monospaced'> |
| 145 | # We have a conf and classes directory, add to BBPATH |
| 146 | BBPATH .= ":${LAYERDIR}" |
| 147 | |
| 148 | # We have recipes-* directories, add to BBFILES |
| 149 | BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \ |
| 150 | ${LAYERDIR}/recipes-*/*/*.bbappend" |
| 151 | |
| 152 | BBFILE_COLLECTIONS += "yoctobsp" |
| 153 | BBFILE_PATTERN_yoctobsp = "^${LAYERDIR}/" |
| 154 | BBFILE_PRIORITY_yoctobsp = "5" |
| 155 | LAYERVERSION_yoctobsp = "3" |
| 156 | </literallayout></para> |
| 157 | <para>Here is an explanation of the example: |
| 158 | <itemizedlist> |
| 159 | <listitem><para>The configuration and |
| 160 | classes directory is appended to |
| 161 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink>. |
| 162 | <note> |
| 163 | All non-distro layers, which include all BSP |
| 164 | layers, are expected to append the layer |
| 165 | directory to the |
| 166 | <filename>BBPATH</filename>. |
| 167 | On the other hand, distro layers, such as |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 168 | <filename>meta-poky</filename>, can choose |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 169 | to enforce their own precedence over |
| 170 | <filename>BBPATH</filename>. |
| 171 | For an example of that syntax, see the |
| 172 | <filename>layer.conf</filename> file for |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 173 | the <filename>meta-poky</filename> layer. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 174 | </note></para></listitem> |
| 175 | <listitem><para>The recipes for the layers are |
| 176 | appended to |
| 177 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILES'>BBFILES</ulink></filename>. |
| 178 | </para></listitem> |
| 179 | <listitem><para>The |
| 180 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_COLLECTIONS'>BBFILE_COLLECTIONS</ulink></filename> |
| 181 | variable is then appended with the layer name. |
| 182 | </para></listitem> |
| 183 | <listitem><para>The |
| 184 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PATTERN'>BBFILE_PATTERN</ulink></filename> |
| 185 | variable is set to a regular expression and is |
| 186 | used to match files from |
| 187 | <filename>BBFILES</filename> into a particular |
| 188 | layer. |
| 189 | In this case, |
| 190 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LAYERDIR'>LAYERDIR</ulink></filename> |
| 191 | is used to make <filename>BBFILE_PATTERN</filename> match within the |
| 192 | layer's path.</para></listitem> |
| 193 | <listitem><para>The |
| 194 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PRIORITY'>BBFILE_PRIORITY</ulink></filename> |
| 195 | variable then assigns a priority to the layer. |
| 196 | Applying priorities is useful in situations |
| 197 | where the same recipe might appear in multiple |
| 198 | layers and allows you to choose the layer |
| 199 | that takes precedence.</para></listitem> |
| 200 | <listitem><para>The |
| 201 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LAYERVERSION'>LAYERVERSION</ulink></filename> |
| 202 | variable optionally specifies the version of a |
| 203 | layer as a single number.</para></listitem> |
| 204 | </itemizedlist></para> |
| 205 | <para>Note the use of the |
| 206 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LAYERDIR'>LAYERDIR</ulink></filename> |
| 207 | variable, which expands to the directory of the current |
| 208 | layer.</para> |
| 209 | <para>Through the use of the <filename>BBPATH</filename> |
| 210 | variable, BitBake locates class files |
| 211 | (<filename>.bbclass</filename>), |
| 212 | configuration files, and files that are included |
| 213 | with <filename>include</filename> and |
| 214 | <filename>require</filename> statements. |
| 215 | For these cases, BitBake uses the first file that |
| 216 | matches the name found in <filename>BBPATH</filename>. |
| 217 | This is similar to the way the <filename>PATH</filename> |
| 218 | variable is used for binaries. |
| 219 | It is recommended, therefore, that you use unique |
| 220 | class and configuration |
| 221 | filenames in your custom layer.</para></listitem> |
| 222 | <listitem><para><emphasis>Add Content:</emphasis> Depending |
| 223 | on the type of layer, add the content. |
| 224 | If the layer adds support for a machine, add the machine |
| 225 | configuration in a <filename>conf/machine/</filename> |
| 226 | file within the layer. |
| 227 | If the layer adds distro policy, add the distro |
| 228 | configuration in a <filename>conf/distro/</filename> |
| 229 | file within the layer. |
| 230 | If the layer introduces new recipes, put the recipes |
| 231 | you need in <filename>recipes-*</filename> |
| 232 | subdirectories within the layer. |
| 233 | <note>In order to be compliant with the Yocto Project, |
| 234 | a layer must contain a |
| 235 | <ulink url='&YOCTO_DOCS_BSP_URL;#bsp-filelayout-readme'>README file.</ulink> |
| 236 | </note></para></listitem> |
| 237 | </orderedlist> |
| 238 | </para> |
| 239 | </section> |
| 240 | |
| 241 | <section id='best-practices-to-follow-when-creating-layers'> |
| 242 | <title>Best Practices to Follow When Creating Layers</title> |
| 243 | |
| 244 | <para> |
| 245 | To create layers that are easier to maintain and that will |
| 246 | not impact builds for other machines, you should consider the |
| 247 | information in the following sections. |
| 248 | </para> |
| 249 | |
| 250 | <section id='avoid-overlaying-entire-recipes'> |
| 251 | <title>Avoid "Overlaying" Entire Recipes</title> |
| 252 | |
| 253 | <para> |
| 254 | Avoid "overlaying" entire recipes from other layers in your |
| 255 | configuration. |
| 256 | In other words, do not copy an entire recipe into your |
| 257 | layer and then modify it. |
| 258 | Rather, use an append file (<filename>.bbappend</filename>) |
| 259 | to override |
| 260 | only those parts of the original recipe you need to modify. |
| 261 | </para> |
| 262 | </section> |
| 263 | |
| 264 | <section id='avoid-duplicating-include-files'> |
| 265 | <title>Avoid Duplicating Include Files</title> |
| 266 | |
| 267 | <para> |
| 268 | Avoid duplicating include files. |
| 269 | Use append files (<filename>.bbappend</filename>) |
| 270 | for each recipe |
| 271 | that uses an include file. |
| 272 | Or, if you are introducing a new recipe that requires |
| 273 | the included file, use the path relative to the original |
| 274 | layer directory to refer to the file. |
| 275 | For example, use |
| 276 | <filename>require recipes-core/</filename><replaceable>package</replaceable><filename>/</filename><replaceable>file</replaceable><filename>.inc</filename> |
| 277 | instead of <filename>require </filename><replaceable>file</replaceable><filename>.inc</filename>. |
| 278 | If you're finding you have to overlay the include file, |
| 279 | it could indicate a deficiency in the include file in |
| 280 | the layer to which it originally belongs. |
| 281 | If this is the case, you should try to address that |
| 282 | deficiency instead of overlaying the include file. |
| 283 | For example, you could address this by getting the |
| 284 | maintainer of the include file to add a variable or |
| 285 | variables to make it easy to override the parts needing |
| 286 | to be overridden. |
| 287 | </para> |
| 288 | </section> |
| 289 | |
| 290 | <section id='structure-your-layers'> |
| 291 | <title>Structure Your Layers</title> |
| 292 | |
| 293 | <para> |
| 294 | Proper use of overrides within append files and placement |
| 295 | of machine-specific files within your layer can ensure that |
| 296 | a build is not using the wrong Metadata and negatively |
| 297 | impacting a build for a different machine. |
| 298 | Following are some examples: |
| 299 | <itemizedlist> |
| 300 | <listitem><para><emphasis>Modifying Variables to Support |
| 301 | a Different Machine:</emphasis> |
| 302 | Suppose you have a layer named |
| 303 | <filename>meta-one</filename> that adds support |
| 304 | for building machine "one". |
| 305 | To do so, you use an append file named |
| 306 | <filename>base-files.bbappend</filename> and |
| 307 | create a dependency on "foo" by altering the |
| 308 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink> |
| 309 | variable: |
| 310 | <literallayout class='monospaced'> |
| 311 | DEPENDS = "foo" |
| 312 | </literallayout> |
| 313 | The dependency is created during any build that |
| 314 | includes the layer |
| 315 | <filename>meta-one</filename>. |
| 316 | However, you might not want this dependency |
| 317 | for all machines. |
| 318 | For example, suppose you are building for |
| 319 | machine "two" but your |
| 320 | <filename>bblayers.conf</filename> file has the |
| 321 | <filename>meta-one</filename> layer included. |
| 322 | During the build, the |
| 323 | <filename>base-files</filename> for machine |
| 324 | "two" will also have the dependency on |
| 325 | <filename>foo</filename>.</para> |
| 326 | <para>To make sure your changes apply only when |
| 327 | building machine "one", use a machine override |
| 328 | with the <filename>DEPENDS</filename> statement: |
| 329 | <literallayout class='monospaced'> |
| 330 | DEPENDS_one = "foo" |
| 331 | </literallayout> |
| 332 | You should follow the same strategy when using |
| 333 | <filename>_append</filename> and |
| 334 | <filename>_prepend</filename> operations: |
| 335 | <literallayout class='monospaced'> |
| 336 | DEPENDS_append_one = " foo" |
| 337 | DEPENDS_prepend_one = "foo " |
| 338 | </literallayout> |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 339 | As an actual example, here's a line from the recipe |
| 340 | for gnutls, which adds dependencies on |
| 341 | "argp-standalone" when building with the musl C |
| 342 | library: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 343 | <literallayout class='monospaced'> |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 344 | DEPENDS_append_libc-musl = " argp-standalone" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 345 | </literallayout> |
| 346 | <note> |
| 347 | Avoiding "+=" and "=+" and using |
| 348 | machine-specific |
| 349 | <filename>_append</filename> |
| 350 | and <filename>_prepend</filename> operations |
| 351 | is recommended as well. |
| 352 | </note></para></listitem> |
| 353 | <listitem><para><emphasis>Place Machine-Specific Files |
| 354 | in Machine-Specific Locations:</emphasis> |
| 355 | When you have a base recipe, such as |
| 356 | <filename>base-files.bb</filename>, that |
| 357 | contains a |
| 358 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> |
| 359 | statement to a file, you can use an append file |
| 360 | to cause the build to use your own version of |
| 361 | the file. |
| 362 | For example, an append file in your layer at |
| 363 | <filename>meta-one/recipes-core/base-files/base-files.bbappend</filename> |
| 364 | could extend |
| 365 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink> |
| 366 | using |
| 367 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink> |
| 368 | as follows: |
| 369 | <literallayout class='monospaced'> |
| 370 | FILESEXTRAPATHS_prepend := "${THISDIR}/${BPN}:" |
| 371 | </literallayout> |
| 372 | The build for machine "one" will pick up your |
| 373 | machine-specific file as long as you have the |
| 374 | file in |
| 375 | <filename>meta-one/recipes-core/base-files/base-files/</filename>. |
| 376 | However, if you are building for a different |
| 377 | machine and the |
| 378 | <filename>bblayers.conf</filename> file includes |
| 379 | the <filename>meta-one</filename> layer and |
| 380 | the location of your machine-specific file is |
| 381 | the first location where that file is found |
| 382 | according to <filename>FILESPATH</filename>, |
| 383 | builds for all machines will also use that |
| 384 | machine-specific file.</para> |
| 385 | <para>You can make sure that a machine-specific |
| 386 | file is used for a particular machine by putting |
| 387 | the file in a subdirectory specific to the |
| 388 | machine. |
| 389 | For example, rather than placing the file in |
| 390 | <filename>meta-one/recipes-core/base-files/base-files/</filename> |
| 391 | as shown above, put it in |
| 392 | <filename>meta-one/recipes-core/base-files/base-files/one/</filename>. |
| 393 | Not only does this make sure the file is used |
| 394 | only when building for machine "one", but the |
| 395 | build process locates the file more quickly.</para> |
| 396 | <para>In summary, you need to place all files |
| 397 | referenced from <filename>SRC_URI</filename> |
| 398 | in a machine-specific subdirectory within the |
| 399 | layer in order to restrict those files to |
| 400 | machine-specific builds.</para></listitem> |
| 401 | </itemizedlist> |
| 402 | </para> |
| 403 | </section> |
| 404 | |
| 405 | <section id='other-recommendations'> |
| 406 | <title>Other Recommendations</title> |
| 407 | |
| 408 | <para> |
| 409 | We also recommend the following: |
| 410 | <itemizedlist> |
| 411 | <listitem><para>Store custom layers in a Git repository |
| 412 | that uses the |
| 413 | <filename>meta-<replaceable>layer_name</replaceable></filename> format. |
| 414 | </para></listitem> |
| 415 | <listitem><para>Clone the repository alongside other |
| 416 | <filename>meta</filename> directories in the |
| 417 | <link linkend='source-directory'>Source Directory</link>. |
| 418 | </para></listitem> |
| 419 | </itemizedlist> |
| 420 | Following these recommendations keeps your Source Directory and |
| 421 | its configuration entirely inside the Yocto Project's core |
| 422 | base. |
| 423 | </para> |
| 424 | </section> |
| 425 | </section> |
| 426 | |
| 427 | <section id='enabling-your-layer'> |
| 428 | <title>Enabling Your Layer</title> |
| 429 | |
| 430 | <para> |
| 431 | Before the OpenEmbedded build system can use your new layer, |
| 432 | you need to enable it. |
| 433 | To enable your layer, simply add your layer's path to the |
| 434 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'>BBLAYERS</ulink></filename> |
| 435 | variable in your <filename>conf/bblayers.conf</filename> file, |
| 436 | which is found in the |
| 437 | <link linkend='build-directory'>Build Directory</link>. |
| 438 | The following example shows how to enable a layer named |
| 439 | <filename>meta-mylayer</filename>: |
| 440 | <literallayout class='monospaced'> |
| 441 | LCONF_VERSION = "6" |
| 442 | |
| 443 | BBPATH = "${TOPDIR}" |
| 444 | BBFILES ?= "" |
| 445 | |
| 446 | BBLAYERS ?= " \ |
| 447 | $HOME/poky/meta \ |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 448 | $HOME/poky/meta-poky \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 449 | $HOME/poky/meta-yocto-bsp \ |
| 450 | $HOME/poky/meta-mylayer \ |
| 451 | " |
| 452 | </literallayout> |
| 453 | </para> |
| 454 | |
| 455 | <para> |
| 456 | BitBake parses each <filename>conf/layer.conf</filename> file |
| 457 | as specified in the <filename>BBLAYERS</filename> variable |
| 458 | within the <filename>conf/bblayers.conf</filename> file. |
| 459 | During the processing of each |
| 460 | <filename>conf/layer.conf</filename> file, BitBake adds the |
| 461 | recipes, classes and configurations contained within the |
| 462 | particular layer to the source directory. |
| 463 | </para> |
| 464 | </section> |
| 465 | |
| 466 | <section id='using-bbappend-files'> |
| 467 | <title>Using .bbappend Files</title> |
| 468 | |
| 469 | <para> |
| 470 | Recipes used to append Metadata to other recipes are called |
| 471 | BitBake append files. |
| 472 | BitBake append files use the <filename>.bbappend</filename> file |
| 473 | type suffix, while the corresponding recipes to which Metadata |
| 474 | is being appended use the <filename>.bb</filename> file type |
| 475 | suffix. |
| 476 | </para> |
| 477 | |
| 478 | <para> |
| 479 | A <filename>.bbappend</filename> file allows your layer to make |
| 480 | additions or changes to the content of another layer's recipe |
| 481 | without having to copy the other recipe into your layer. |
| 482 | Your <filename>.bbappend</filename> file resides in your layer, |
| 483 | while the main <filename>.bb</filename> recipe file to |
| 484 | which you are appending Metadata resides in a different layer. |
| 485 | </para> |
| 486 | |
| 487 | <para> |
| 488 | Append files must have the same root names as their corresponding |
| 489 | recipes. |
| 490 | For example, the append file |
| 491 | <filename>someapp_&DISTRO;.bbappend</filename> must apply to |
| 492 | <filename>someapp_&DISTRO;.bb</filename>. |
| 493 | This means the original recipe and append file names are version |
| 494 | number-specific. |
| 495 | If the corresponding recipe is renamed to update to a newer |
| 496 | version, the corresponding <filename>.bbappend</filename> file must |
| 497 | be renamed (and possibly updated) as well. |
| 498 | During the build process, BitBake displays an error on starting |
| 499 | if it detects a <filename>.bbappend</filename> file that does |
| 500 | not have a corresponding recipe with a matching name. |
| 501 | See the |
| 502 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_DANGLINGAPPENDS_WARNONLY'><filename>BB_DANGLINGAPPENDS_WARNONLY</filename></ulink> |
| 503 | variable for information on how to handle this error. |
| 504 | </para> |
| 505 | |
| 506 | <para> |
| 507 | Being able to append information to an existing recipe not only |
| 508 | avoids duplication, but also automatically applies recipe |
| 509 | changes in a different layer to your layer. |
| 510 | If you were copying recipes, you would have to manually merge |
| 511 | changes as they occur. |
| 512 | </para> |
| 513 | |
| 514 | <para> |
| 515 | As an example, consider the main formfactor recipe and a |
| 516 | corresponding formfactor append file both from the |
| 517 | <link linkend='source-directory'>Source Directory</link>. |
| 518 | Here is the main formfactor recipe, which is named |
| 519 | <filename>formfactor_0.0.bb</filename> and located in the |
| 520 | "meta" layer at |
| 521 | <filename>meta/recipes-bsp/formfactor</filename>: |
| 522 | <literallayout class='monospaced'> |
| 523 | SUMMARY = "Device formfactor information" |
| 524 | SECTION = "base" |
| 525 | LICENSE = "MIT" |
| 526 | LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=4d92cd373abda3937c2bc47fbc49d690 \ |
| 527 | file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" |
| 528 | PR = "r45" |
| 529 | |
| 530 | SRC_URI = "file://config file://machconfig" |
| 531 | S = "${WORKDIR}" |
| 532 | |
| 533 | PACKAGE_ARCH = "${MACHINE_ARCH}" |
| 534 | INHIBIT_DEFAULT_DEPS = "1" |
| 535 | |
| 536 | do_install() { |
| 537 | # Install file only if it has contents |
| 538 | install -d ${D}${sysconfdir}/formfactor/ |
| 539 | install -m 0644 ${S}/config ${D}${sysconfdir}/formfactor/ |
| 540 | if [ -s "${S}/machconfig" ]; then |
| 541 | install -m 0644 ${S}/machconfig ${D}${sysconfdir}/formfactor/ |
| 542 | fi |
| 543 | } |
| 544 | </literallayout> |
| 545 | In the main recipe, note the |
| 546 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> |
| 547 | variable, which tells the OpenEmbedded build system where to |
| 548 | find files during the build. |
| 549 | </para> |
| 550 | |
| 551 | <para> |
| 552 | Following is the append file, which is named |
| 553 | <filename>formfactor_0.0.bbappend</filename> and is from the |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 554 | Raspberry Pi BSP Layer named |
| 555 | <filename>meta-raspberrypi</filename>. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 556 | The file is in <filename>recipes-bsp/formfactor</filename>: |
| 557 | <literallayout class='monospaced'> |
| 558 | FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" |
| 559 | </literallayout> |
| 560 | </para> |
| 561 | |
| 562 | <para> |
| 563 | By default, the build system uses the |
| 564 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink> |
| 565 | variable to locate files. |
| 566 | This append file extends the locations by setting the |
| 567 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink> |
| 568 | variable. |
| 569 | Setting this variable in the <filename>.bbappend</filename> |
| 570 | file is the most reliable and recommended method for adding |
| 571 | directories to the search path used by the build system |
| 572 | to find files. |
| 573 | </para> |
| 574 | |
| 575 | <para> |
| 576 | The statement in this example extends the directories to include |
| 577 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-THISDIR'><filename>THISDIR</filename></ulink><filename>}/${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>, |
| 578 | which resolves to a directory named |
| 579 | <filename>formfactor</filename> in the same directory |
| 580 | in which the append file resides (i.e. |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 581 | <filename>meta-raspberrypi/recipes-bsp/formfactor/formfactor</filename>. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 582 | This implies that you must have the supporting directory |
| 583 | structure set up that will contain any files or patches you |
| 584 | will be including from the layer. |
| 585 | </para> |
| 586 | |
| 587 | <para> |
| 588 | Using the immediate expansion assignment operator |
| 589 | <filename>:=</filename> is important because of the reference to |
| 590 | <filename>THISDIR</filename>. |
| 591 | The trailing colon character is important as it ensures that |
| 592 | items in the list remain colon-separated. |
| 593 | <note> |
| 594 | <para> |
| 595 | BitBake automatically defines the |
| 596 | <filename>THISDIR</filename> variable. |
| 597 | You should never set this variable yourself. |
| 598 | Using "_prepend" as part of the |
| 599 | <filename>FILESEXTRAPATHS</filename> ensures your path |
| 600 | will be searched prior to other paths in the final |
| 601 | list. |
| 602 | </para> |
| 603 | |
| 604 | <para> |
| 605 | Also, not all append files add extra files. |
| 606 | Many append files simply exist to add build options |
| 607 | (e.g. <filename>systemd</filename>). |
| 608 | For these cases, your append file would not even |
| 609 | use the <filename>FILESEXTRAPATHS</filename> statement. |
| 610 | </para> |
| 611 | </note> |
| 612 | </para> |
| 613 | </section> |
| 614 | |
| 615 | <section id='prioritizing-your-layer'> |
| 616 | <title>Prioritizing Your Layer</title> |
| 617 | |
| 618 | <para> |
| 619 | Each layer is assigned a priority value. |
| 620 | Priority values control which layer takes precedence if there |
| 621 | are recipe files with the same name in multiple layers. |
| 622 | For these cases, the recipe file from the layer with a higher |
| 623 | priority number takes precedence. |
| 624 | Priority values also affect the order in which multiple |
| 625 | <filename>.bbappend</filename> files for the same recipe are |
| 626 | applied. |
| 627 | You can either specify the priority manually, or allow the |
| 628 | build system to calculate it based on the layer's dependencies. |
| 629 | </para> |
| 630 | |
| 631 | <para> |
| 632 | To specify the layer's priority manually, use the |
| 633 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PRIORITY'><filename>BBFILE_PRIORITY</filename></ulink> |
| 634 | variable. |
| 635 | For example: |
| 636 | <literallayout class='monospaced'> |
| 637 | BBFILE_PRIORITY_mylayer = "1" |
| 638 | </literallayout> |
| 639 | </para> |
| 640 | |
| 641 | <note> |
| 642 | <para>It is possible for a recipe with a lower version number |
| 643 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink> |
| 644 | in a layer that has a higher priority to take precedence.</para> |
| 645 | <para>Also, the layer priority does not currently affect the |
| 646 | precedence order of <filename>.conf</filename> |
| 647 | or <filename>.bbclass</filename> files. |
| 648 | Future versions of BitBake might address this.</para> |
| 649 | </note> |
| 650 | </section> |
| 651 | |
| 652 | <section id='managing-layers'> |
| 653 | <title>Managing Layers</title> |
| 654 | |
| 655 | <para> |
| 656 | You can use the BitBake layer management tool to provide a view |
| 657 | into the structure of recipes across a multi-layer project. |
| 658 | Being able to generate output that reports on configured layers |
| 659 | with their paths and priorities and on |
| 660 | <filename>.bbappend</filename> files and their applicable |
| 661 | recipes can help to reveal potential problems. |
| 662 | </para> |
| 663 | |
| 664 | <para> |
| 665 | Use the following form when running the layer management tool. |
| 666 | <literallayout class='monospaced'> |
| 667 | $ bitbake-layers <replaceable>command</replaceable> [<replaceable>arguments</replaceable>] |
| 668 | </literallayout> |
| 669 | The following list describes the available commands: |
| 670 | <itemizedlist> |
| 671 | <listitem><para><filename><emphasis>help:</emphasis></filename> |
| 672 | Displays general help or help on a specified command. |
| 673 | </para></listitem> |
| 674 | <listitem><para><filename><emphasis>show-layers:</emphasis></filename> |
| 675 | Shows the current configured layers. |
| 676 | </para></listitem> |
| 677 | <listitem><para><filename><emphasis>show-recipes:</emphasis></filename> |
| 678 | Lists available recipes and the layers that provide them. |
| 679 | </para></listitem> |
| 680 | <listitem><para><filename><emphasis>show-overlayed:</emphasis></filename> |
| 681 | Lists overlayed recipes. |
| 682 | A recipe is overlayed when a recipe with the same name |
| 683 | exists in another layer that has a higher layer |
| 684 | priority. |
| 685 | </para></listitem> |
| 686 | <listitem><para><filename><emphasis>show-appends:</emphasis></filename> |
| 687 | Lists <filename>.bbappend</filename> files and the |
| 688 | recipe files to which they apply. |
| 689 | </para></listitem> |
| 690 | <listitem><para><filename><emphasis>show-cross-depends:</emphasis></filename> |
| 691 | Lists dependency relationships between recipes that |
| 692 | cross layer boundaries. |
| 693 | </para></listitem> |
| 694 | <listitem><para><filename><emphasis>add-layer:</emphasis></filename> |
| 695 | Adds a layer to <filename>bblayers.conf</filename>. |
| 696 | </para></listitem> |
| 697 | <listitem><para><filename><emphasis>remove-layer:</emphasis></filename> |
| 698 | Removes a layer from <filename>bblayers.conf</filename> |
| 699 | </para></listitem> |
| 700 | <listitem><para><filename><emphasis>flatten:</emphasis></filename> |
| 701 | Flattens the layer configuration into a separate output |
| 702 | directory. |
| 703 | Flattening your layer configuration builds a "flattened" |
| 704 | directory that contains the contents of all layers, |
| 705 | with any overlayed recipes removed and any |
| 706 | <filename>.bbappend</filename> files appended to the |
| 707 | corresponding recipes. |
| 708 | You might have to perform some manual cleanup of the |
| 709 | flattened layer as follows: |
| 710 | <itemizedlist> |
| 711 | <listitem><para>Non-recipe files (such as patches) |
| 712 | are overwritten. |
| 713 | The flatten command shows a warning for these |
| 714 | files. |
| 715 | </para></listitem> |
| 716 | <listitem><para>Anything beyond the normal layer |
| 717 | setup has been added to the |
| 718 | <filename>layer.conf</filename> file. |
| 719 | Only the lowest priority layer's |
| 720 | <filename>layer.conf</filename> is used. |
| 721 | </para></listitem> |
| 722 | <listitem><para>Overridden and appended items from |
| 723 | <filename>.bbappend</filename> files need to be |
| 724 | cleaned up. |
| 725 | The contents of each |
| 726 | <filename>.bbappend</filename> end up in the |
| 727 | flattened recipe. |
| 728 | However, if there are appended or changed |
| 729 | variable values, you need to tidy these up |
| 730 | yourself. |
| 731 | Consider the following example. |
| 732 | Here, the <filename>bitbake-layers</filename> |
| 733 | command adds the line |
| 734 | <filename>#### bbappended ...</filename> so that |
| 735 | you know where the following lines originate: |
| 736 | <literallayout class='monospaced'> |
| 737 | ... |
| 738 | DESCRIPTION = "A useful utility" |
| 739 | ... |
| 740 | EXTRA_OECONF = "--enable-something" |
| 741 | ... |
| 742 | |
| 743 | #### bbappended from meta-anotherlayer #### |
| 744 | |
| 745 | DESCRIPTION = "Customized utility" |
| 746 | EXTRA_OECONF += "--enable-somethingelse" |
| 747 | </literallayout> |
| 748 | Ideally, you would tidy up these utilities as |
| 749 | follows: |
| 750 | <literallayout class='monospaced'> |
| 751 | ... |
| 752 | DESCRIPTION = "Customized utility" |
| 753 | ... |
| 754 | EXTRA_OECONF = "--enable-something --enable-somethingelse" |
| 755 | ... |
| 756 | </literallayout></para></listitem> |
| 757 | </itemizedlist></para></listitem> |
| 758 | </itemizedlist> |
| 759 | </para> |
| 760 | </section> |
| 761 | |
| 762 | <section id='creating-a-general-layer-using-the-yocto-layer-script'> |
| 763 | <title>Creating a General Layer Using the yocto-layer Script</title> |
| 764 | |
| 765 | <para> |
| 766 | The <filename>yocto-layer</filename> script simplifies |
| 767 | creating a new general layer. |
| 768 | <note> |
| 769 | For information on BSP layers, see the |
| 770 | "<ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP Layers</ulink>" |
| 771 | section in the Yocto Project Board Specific (BSP) |
| 772 | Developer's Guide. |
| 773 | </note> |
| 774 | The default mode of the script's operation is to prompt you for |
| 775 | information needed to generate the layer: |
| 776 | <itemizedlist> |
| 777 | <listitem><para>The layer priority. |
| 778 | </para></listitem> |
| 779 | <listitem><para>Whether or not to create a sample recipe. |
| 780 | </para></listitem> |
| 781 | <listitem><para>Whether or not to create a sample |
| 782 | append file. |
| 783 | </para></listitem> |
| 784 | </itemizedlist> |
| 785 | </para> |
| 786 | |
| 787 | <para> |
| 788 | Use the <filename>yocto-layer create</filename> sub-command |
| 789 | to create a new general layer. |
| 790 | In its simplest form, you can create a layer as follows: |
| 791 | <literallayout class='monospaced'> |
| 792 | $ yocto-layer create mylayer |
| 793 | </literallayout> |
| 794 | The previous example creates a layer named |
| 795 | <filename>meta-mylayer</filename> in the current directory. |
| 796 | </para> |
| 797 | |
| 798 | <para> |
| 799 | As the <filename>yocto-layer create</filename> command runs, |
| 800 | default values for the prompts appear in brackets. |
| 801 | Pressing enter without supplying anything for the prompts |
| 802 | or pressing enter and providing an invalid response causes the |
| 803 | script to accept the default value. |
| 804 | Once the script completes, the new layer |
| 805 | is created in the current working directory. |
| 806 | The script names the layer by prepending |
| 807 | <filename>meta-</filename> to the name you provide. |
| 808 | </para> |
| 809 | |
| 810 | <para> |
| 811 | Minimally, the script creates the following within the layer: |
| 812 | <itemizedlist> |
| 813 | <listitem><para><emphasis>The <filename>conf</filename> |
| 814 | directory:</emphasis> |
| 815 | This directory contains the layer's configuration file. |
| 816 | The root name for the file is the same as the root name |
| 817 | your provided for the layer (e.g. |
| 818 | <filename><replaceable>layer</replaceable>.conf</filename>). |
| 819 | </para></listitem> |
| 820 | <listitem><para><emphasis>The |
| 821 | <filename>COPYING.MIT</filename> file:</emphasis> |
| 822 | The copyright and use notice for the software. |
| 823 | </para></listitem> |
| 824 | <listitem><para><emphasis>The <filename>README</filename> |
| 825 | file:</emphasis> |
| 826 | A file describing the contents of your new layer. |
| 827 | </para></listitem> |
| 828 | </itemizedlist> |
| 829 | </para> |
| 830 | |
| 831 | <para> |
| 832 | If you choose to generate a sample recipe file, the script |
| 833 | prompts you for the name for the recipe and then creates it |
| 834 | in <filename><replaceable>layer</replaceable>/recipes-example/example/</filename>. |
| 835 | The script creates a <filename>.bb</filename> file and a |
| 836 | directory, which contains a sample |
| 837 | <filename>helloworld.c</filename> source file, along with |
| 838 | a sample patch file. |
| 839 | If you do not provide a recipe name, the script uses |
| 840 | "example". |
| 841 | </para> |
| 842 | |
| 843 | <para> |
| 844 | If you choose to generate a sample append file, the script |
| 845 | prompts you for the name for the file and then creates it |
| 846 | in <filename><replaceable>layer</replaceable>/recipes-example-bbappend/example-bbappend/</filename>. |
| 847 | The script creates a <filename>.bbappend</filename> file and a |
| 848 | directory, which contains a sample patch file. |
| 849 | If you do not provide a recipe name, the script uses |
| 850 | "example". |
| 851 | The script also prompts you for the version of the append file. |
| 852 | The version should match the recipe to which the append file |
| 853 | is associated. |
| 854 | </para> |
| 855 | |
| 856 | <para> |
| 857 | The easiest way to see how the <filename>yocto-layer</filename> |
| 858 | script works is to experiment with the script. |
| 859 | You can also read the usage information by entering the |
| 860 | following: |
| 861 | <literallayout class='monospaced'> |
| 862 | $ yocto-layer help |
| 863 | </literallayout> |
| 864 | </para> |
| 865 | |
| 866 | <para> |
| 867 | Once you create your general layer, you must add it to your |
| 868 | <filename>bblayers.conf</filename> file. |
| 869 | Here is an example where a layer named |
| 870 | <filename>meta-mylayer</filename> is added: |
| 871 | <literallayout class='monospaced'> |
| 872 | BBLAYERS = ?" \ |
| 873 | /usr/local/src/yocto/meta \ |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 874 | /usr/local/src/yocto/meta-poky \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 875 | /usr/local/src/yocto/meta-yocto-bsp \ |
| 876 | /usr/local/src/yocto/meta-mylayer \ |
| 877 | " |
| 878 | </literallayout> |
| 879 | Adding the layer to this file enables the build system to |
| 880 | locate the layer during the build. |
| 881 | </para> |
| 882 | </section> |
| 883 | </section> |
| 884 | |
| 885 | <section id='usingpoky-extend-customimage'> |
| 886 | <title>Customizing Images</title> |
| 887 | |
| 888 | <para> |
| 889 | You can customize images to satisfy particular requirements. |
| 890 | This section describes several methods and provides guidelines for each. |
| 891 | </para> |
| 892 | |
| 893 | <section id='usingpoky-extend-customimage-localconf'> |
| 894 | <title>Customizing Images Using <filename>local.conf</filename></title> |
| 895 | |
| 896 | <para> |
| 897 | Probably the easiest way to customize an image is to add a |
| 898 | package by way of the <filename>local.conf</filename> |
| 899 | configuration file. |
| 900 | Because it is limited to local use, this method generally only |
| 901 | allows you to add packages and is not as flexible as creating |
| 902 | your own customized image. |
| 903 | When you add packages using local variables this way, you need |
| 904 | to realize that these variable changes are in effect for every |
| 905 | build and consequently affect all images, which might not |
| 906 | be what you require. |
| 907 | </para> |
| 908 | |
| 909 | <para> |
| 910 | To add a package to your image using the local configuration |
| 911 | file, use the |
| 912 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename> |
| 913 | variable with the <filename>_append</filename> operator: |
| 914 | <literallayout class='monospaced'> |
| 915 | IMAGE_INSTALL_append = " strace" |
| 916 | </literallayout> |
| 917 | Use of the syntax is important - specifically, the space between |
| 918 | the quote and the package name, which is |
| 919 | <filename>strace</filename> in this example. |
| 920 | This space is required since the <filename>_append</filename> |
| 921 | operator does not add the space. |
| 922 | </para> |
| 923 | |
| 924 | <para> |
| 925 | Furthermore, you must use <filename>_append</filename> instead |
| 926 | of the <filename>+=</filename> operator if you want to avoid |
| 927 | ordering issues. |
| 928 | The reason for this is because doing so unconditionally appends |
| 929 | to the variable and avoids ordering problems due to the |
| 930 | variable being set in image recipes and |
| 931 | <filename>.bbclass</filename> files with operators like |
| 932 | <filename>?=</filename>. |
| 933 | Using <filename>_append</filename> ensures the operation takes |
| 934 | affect. |
| 935 | </para> |
| 936 | |
| 937 | <para> |
| 938 | As shown in its simplest use, |
| 939 | <filename>IMAGE_INSTALL_append</filename> affects all images. |
| 940 | It is possible to extend the syntax so that the variable |
| 941 | applies to a specific image only. |
| 942 | Here is an example: |
| 943 | <literallayout class='monospaced'> |
| 944 | IMAGE_INSTALL_append_pn-core-image-minimal = " strace" |
| 945 | </literallayout> |
| 946 | This example adds <filename>strace</filename> to the |
| 947 | <filename>core-image-minimal</filename> image only. |
| 948 | </para> |
| 949 | |
| 950 | <para> |
| 951 | You can add packages using a similar approach through the |
| 952 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-CORE_IMAGE_EXTRA_INSTALL'>CORE_IMAGE_EXTRA_INSTALL</ulink></filename> |
| 953 | variable. |
| 954 | If you use this variable, only |
| 955 | <filename>core-image-*</filename> images are affected. |
| 956 | </para> |
| 957 | </section> |
| 958 | |
| 959 | <section id='usingpoky-extend-customimage-imagefeatures'> |
| 960 | <title>Customizing Images Using Custom <filename>IMAGE_FEATURES</filename> and |
| 961 | <filename>EXTRA_IMAGE_FEATURES</filename></title> |
| 962 | |
| 963 | <para> |
| 964 | Another method for customizing your image is to enable or |
| 965 | disable high-level image features by using the |
| 966 | <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink> |
| 967 | and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink> |
| 968 | variables. |
| 969 | Although the functions for both variables are nearly equivalent, |
| 970 | best practices dictate using <filename>IMAGE_FEATURES</filename> |
| 971 | from within a recipe and using |
| 972 | <filename>EXTRA_IMAGE_FEATURES</filename> from within |
| 973 | your <filename>local.conf</filename> file, which is found in the |
| 974 | <link linkend='build-directory'>Build Directory</link>. |
| 975 | </para> |
| 976 | |
| 977 | <para> |
| 978 | To understand how these features work, the best reference is |
| 979 | <filename>meta/classes/core-image.bbclass</filename>. |
| 980 | This class lists out the available |
| 981 | <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink> |
| 982 | of which most map to package groups while some, such as |
| 983 | <filename>debug-tweaks</filename> and |
| 984 | <filename>read-only-rootfs</filename>, resolve as general |
| 985 | configuration settings. |
| 986 | </para> |
| 987 | |
| 988 | <para> |
| 989 | In summary, the file looks at the contents of the |
| 990 | <filename>IMAGE_FEATURES</filename> variable and then maps |
| 991 | or configures the feature accordingly. |
| 992 | Based on this information, the build system automatically |
| 993 | adds the appropriate packages or configurations to the |
| 994 | <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink> |
| 995 | variable. |
| 996 | Effectively, you are enabling extra features by extending the |
| 997 | class or creating a custom class for use with specialized image |
| 998 | <filename>.bb</filename> files. |
| 999 | </para> |
| 1000 | |
| 1001 | <para> |
| 1002 | Use the <filename>EXTRA_IMAGE_FEATURES</filename> variable |
| 1003 | from within your local configuration file. |
| 1004 | Using a separate area from which to enable features with |
| 1005 | this variable helps you avoid overwriting the features in the |
| 1006 | image recipe that are enabled with |
| 1007 | <filename>IMAGE_FEATURES</filename>. |
| 1008 | The value of <filename>EXTRA_IMAGE_FEATURES</filename> is added |
| 1009 | to <filename>IMAGE_FEATURES</filename> within |
| 1010 | <filename>meta/conf/bitbake.conf</filename>. |
| 1011 | </para> |
| 1012 | |
| 1013 | <para> |
| 1014 | To illustrate how you can use these variables to modify your |
| 1015 | image, consider an example that selects the SSH server. |
| 1016 | The Yocto Project ships with two SSH servers you can use |
| 1017 | with your images: Dropbear and OpenSSH. |
| 1018 | Dropbear is a minimal SSH server appropriate for |
| 1019 | resource-constrained environments, while OpenSSH is a |
| 1020 | well-known standard SSH server implementation. |
| 1021 | By default, the <filename>core-image-sato</filename> image |
| 1022 | is configured to use Dropbear. |
| 1023 | The <filename>core-image-full-cmdline</filename> and |
| 1024 | <filename>core-image-lsb</filename> images both |
| 1025 | include OpenSSH. |
| 1026 | The <filename>core-image-minimal</filename> image does not |
| 1027 | contain an SSH server. |
| 1028 | </para> |
| 1029 | |
| 1030 | <para> |
| 1031 | You can customize your image and change these defaults. |
| 1032 | Edit the <filename>IMAGE_FEATURES</filename> variable |
| 1033 | in your recipe or use the |
| 1034 | <filename>EXTRA_IMAGE_FEATURES</filename> in your |
| 1035 | <filename>local.conf</filename> file so that it configures the |
| 1036 | image you are working with to include |
| 1037 | <filename>ssh-server-dropbear</filename> or |
| 1038 | <filename>ssh-server-openssh</filename>. |
| 1039 | </para> |
| 1040 | |
| 1041 | <note> |
| 1042 | See the |
| 1043 | "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>" |
| 1044 | section in the Yocto Project Reference Manual for a complete |
| 1045 | list of image features that ship with the Yocto Project. |
| 1046 | </note> |
| 1047 | </section> |
| 1048 | |
| 1049 | <section id='usingpoky-extend-customimage-custombb'> |
| 1050 | <title>Customizing Images Using Custom .bb Files</title> |
| 1051 | |
| 1052 | <para> |
| 1053 | You can also customize an image by creating a custom recipe |
| 1054 | that defines additional software as part of the image. |
| 1055 | The following example shows the form for the two lines you need: |
| 1056 | <literallayout class='monospaced'> |
| 1057 | IMAGE_INSTALL = "packagegroup-core-x11-base package1 package2" |
| 1058 | |
| 1059 | inherit core-image |
| 1060 | </literallayout> |
| 1061 | </para> |
| 1062 | |
| 1063 | <para> |
| 1064 | Defining the software using a custom recipe gives you total |
| 1065 | control over the contents of the image. |
| 1066 | It is important to use the correct names of packages in the |
| 1067 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename> |
| 1068 | variable. |
| 1069 | You must use the OpenEmbedded notation and not the Debian notation for the names |
| 1070 | (e.g. <filename>glibc-dev</filename> instead of <filename>libc6-dev</filename>). |
| 1071 | </para> |
| 1072 | |
| 1073 | <para> |
| 1074 | The other method for creating a custom image is to base it on an existing image. |
| 1075 | For example, if you want to create an image based on <filename>core-image-sato</filename> |
| 1076 | but add the additional package <filename>strace</filename> to the image, |
| 1077 | copy the <filename>meta/recipes-sato/images/core-image-sato.bb</filename> to a |
| 1078 | new <filename>.bb</filename> and add the following line to the end of the copy: |
| 1079 | <literallayout class='monospaced'> |
| 1080 | IMAGE_INSTALL += "strace" |
| 1081 | </literallayout> |
| 1082 | </para> |
| 1083 | </section> |
| 1084 | |
| 1085 | <section id='usingpoky-extend-customimage-customtasks'> |
| 1086 | <title>Customizing Images Using Custom Package Groups</title> |
| 1087 | |
| 1088 | <para> |
| 1089 | For complex custom images, the best approach for customizing |
| 1090 | an image is to create a custom package group recipe that is |
| 1091 | used to build the image or images. |
| 1092 | A good example of a package group recipe is |
| 1093 | <filename>meta/recipes-core/packagegroups/packagegroup-base.bb</filename>. |
| 1094 | </para> |
| 1095 | |
| 1096 | <para> |
| 1097 | If you examine that recipe, you see that the |
| 1098 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'>PACKAGES</ulink></filename> |
| 1099 | variable lists the package group packages to produce. |
| 1100 | The <filename>inherit packagegroup</filename> statement |
| 1101 | sets appropriate default values and automatically adds |
| 1102 | <filename>-dev</filename>, <filename>-dbg</filename>, and |
| 1103 | <filename>-ptest</filename> complementary packages for each |
| 1104 | package specified in the <filename>PACKAGES</filename> |
| 1105 | statement. |
| 1106 | <note> |
| 1107 | The <filename>inherit packages</filename> should be |
| 1108 | located near the top of the recipe, certainly before |
| 1109 | the <filename>PACKAGES</filename> statement. |
| 1110 | </note> |
| 1111 | </para> |
| 1112 | |
| 1113 | <para> |
| 1114 | For each package you specify in <filename>PACKAGES</filename>, |
| 1115 | you can use |
| 1116 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'>RDEPENDS</ulink></filename> |
| 1117 | and |
| 1118 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'>RRECOMMENDS</ulink></filename> |
| 1119 | entries to provide a list of packages the parent task package |
| 1120 | should contain. |
| 1121 | You can see examples of these further down in the |
| 1122 | <filename>packagegroup-base.bb</filename> recipe. |
| 1123 | </para> |
| 1124 | |
| 1125 | <para> |
| 1126 | Here is a short, fabricated example showing the same basic |
| 1127 | pieces: |
| 1128 | <literallayout class='monospaced'> |
| 1129 | DESCRIPTION = "My Custom Package Groups" |
| 1130 | |
| 1131 | inherit packagegroup |
| 1132 | |
| 1133 | PACKAGES = "\ |
| 1134 | packagegroup-custom-apps \ |
| 1135 | packagegroup-custom-tools \ |
| 1136 | " |
| 1137 | |
| 1138 | RDEPENDS_packagegroup-custom-apps = "\ |
| 1139 | dropbear \ |
| 1140 | portmap \ |
| 1141 | psplash" |
| 1142 | |
| 1143 | RDEPENDS_packagegroup-custom-tools = "\ |
| 1144 | oprofile \ |
| 1145 | oprofileui-server \ |
| 1146 | lttng-tools" |
| 1147 | |
| 1148 | RRECOMMENDS_packagegroup-custom-tools = "\ |
| 1149 | kernel-module-oprofile" |
| 1150 | </literallayout> |
| 1151 | </para> |
| 1152 | |
| 1153 | <para> |
| 1154 | In the previous example, two package group packages are created with their dependencies and their |
| 1155 | recommended package dependencies listed: <filename>packagegroup-custom-apps</filename>, and |
| 1156 | <filename>packagegroup-custom-tools</filename>. |
| 1157 | To build an image using these package group packages, you need to add |
| 1158 | <filename>packagegroup-custom-apps</filename> and/or |
| 1159 | <filename>packagegroup-custom-tools</filename> to |
| 1160 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename>. |
| 1161 | For other forms of image dependencies see the other areas of this section. |
| 1162 | </para> |
| 1163 | </section> |
| 1164 | |
| 1165 | <section id='usingpoky-extend-customimage-image-name'> |
| 1166 | <title>Customizing an Image Hostname</title> |
| 1167 | |
| 1168 | <para> |
| 1169 | By default, the configured hostname (i.e. |
| 1170 | <filename>/etc/hostname</filename>) in an image is the |
| 1171 | same as the machine name. |
| 1172 | For example, if |
| 1173 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink> |
| 1174 | equals "qemux86", the configured hostname written to |
| 1175 | <filename>/etc/hostname</filename> is "qemux86". |
| 1176 | </para> |
| 1177 | |
| 1178 | <para> |
| 1179 | You can customize this name by altering the value of the |
| 1180 | "hostname" variable in the |
| 1181 | <filename>base-files</filename> recipe using either |
| 1182 | an append file or a configuration file. |
| 1183 | Use the following in an append file: |
| 1184 | <literallayout class='monospaced'> |
| 1185 | hostname="myhostname" |
| 1186 | </literallayout> |
| 1187 | Use the following in a configuration file: |
| 1188 | <literallayout class='monospaced'> |
| 1189 | hostname_pn-base-files = "myhostname" |
| 1190 | </literallayout> |
| 1191 | </para> |
| 1192 | |
| 1193 | <para> |
| 1194 | Changing the default value of the variable "hostname" can be |
| 1195 | useful in certain situations. |
| 1196 | For example, suppose you need to do extensive testing on an |
| 1197 | image and you would like to easily identify the image |
| 1198 | under test from existing images with typical default |
| 1199 | hostnames. |
| 1200 | In this situation, you could change the default hostname to |
| 1201 | "testme", which results in all the images using the name |
| 1202 | "testme". |
| 1203 | Once testing is complete and you do not need to rebuild the |
| 1204 | image for test any longer, you can easily reset the default |
| 1205 | hostname. |
| 1206 | </para> |
| 1207 | |
| 1208 | <para> |
| 1209 | Another point of interest is that if you unset the variable, |
| 1210 | the image will have no default hostname in the filesystem. |
| 1211 | Here is an example that unsets the variable in a |
| 1212 | configuration file: |
| 1213 | <literallayout class='monospaced'> |
| 1214 | hostname_pn-base-files = "" |
| 1215 | </literallayout> |
| 1216 | Having no default hostname in the filesystem is suitable for |
| 1217 | environments that use dynamic hostnames such as virtual |
| 1218 | machines. |
| 1219 | </para> |
| 1220 | </section> |
| 1221 | </section> |
| 1222 | |
| 1223 | <section id='new-recipe-writing-a-new-recipe'> |
| 1224 | <title>Writing a New Recipe</title> |
| 1225 | |
| 1226 | <para> |
| 1227 | Recipes (<filename>.bb</filename> files) are fundamental components |
| 1228 | in the Yocto Project environment. |
| 1229 | Each software component built by the OpenEmbedded build system |
| 1230 | requires a recipe to define the component. |
| 1231 | This section describes how to create, write, and test a new |
| 1232 | recipe. |
| 1233 | <note> |
| 1234 | For information on variables that are useful for recipes and |
| 1235 | for information about recipe naming issues, see the |
| 1236 | "<ulink url='&YOCTO_DOCS_REF_URL;#ref-varlocality-recipe-required'>Required</ulink>" |
| 1237 | section of the Yocto Project Reference Manual. |
| 1238 | </note> |
| 1239 | </para> |
| 1240 | |
| 1241 | <section id='new-recipe-overview'> |
| 1242 | <title>Overview</title> |
| 1243 | |
| 1244 | <para> |
| 1245 | The following figure shows the basic process for creating a |
| 1246 | new recipe. |
| 1247 | The remainder of the section provides details for the steps. |
| 1248 | <imagedata fileref="figures/recipe-workflow.png" width="6in" depth="7in" align="center" scalefit="1" /> |
| 1249 | </para> |
| 1250 | </section> |
| 1251 | |
| 1252 | <section id='new-recipe-locate-or-automatically-create-a-base-recipe'> |
| 1253 | <title>Locate or Automatically Create a Base Recipe</title> |
| 1254 | |
| 1255 | <para> |
| 1256 | You can always write a recipe from scratch. |
| 1257 | However, two choices exist that can help you quickly get a |
| 1258 | start on a new recipe: |
| 1259 | <itemizedlist> |
| 1260 | <listitem><para><emphasis><filename>recipetool</filename>:</emphasis> |
| 1261 | A tool provided by the Yocto Project that automates |
| 1262 | creation of a base recipe based on the source |
| 1263 | files. |
| 1264 | </para></listitem> |
| 1265 | <listitem><para><emphasis>Existing Recipes:</emphasis> |
| 1266 | Location and modification of an existing recipe that is |
| 1267 | similar in function to the recipe you need. |
| 1268 | </para></listitem> |
| 1269 | </itemizedlist> |
| 1270 | </para> |
| 1271 | |
| 1272 | <section id='new-recipe-creating-the-base-recipe-using-recipetool'> |
| 1273 | <title>Creating the Base Recipe Using <filename>recipetool</filename></title> |
| 1274 | |
| 1275 | <para> |
| 1276 | <filename>recipetool</filename> automates creation of |
| 1277 | a base recipe given a set of source code files. |
| 1278 | As long as you can extract or point to the source files, |
| 1279 | the tool will construct a recipe and automatically |
| 1280 | configure all pre-build information into the recipe. |
| 1281 | For example, suppose you have an application that builds |
| 1282 | using Autotools. |
| 1283 | Creating the base recipe using |
| 1284 | <filename>recipetool</filename> results in a recipe |
| 1285 | that has the pre-build dependencies, license requirements, |
| 1286 | and checksums configured. |
| 1287 | </para> |
| 1288 | |
| 1289 | <para> |
| 1290 | To run the tool, you just need to be in your |
| 1291 | <link linkend='build-directory'>Build Directory</link> |
| 1292 | and have sourced the build environment setup script |
| 1293 | (i.e. |
| 1294 | <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>oe-init-build-env</filename></ulink> |
| 1295 | or |
| 1296 | <ulink url='&YOCTO_DOCS_REF_URL;#structure-memres-core-script'><filename>oe-init-build-env-memres</filename></ulink>). |
| 1297 | Here is the basic <filename>recipetool</filename> syntax: |
| 1298 | <note> |
| 1299 | Running <filename>recipetool -h</filename> or |
| 1300 | <filename>recipetool create -h</filename> produces the |
| 1301 | Python-generated help, which presented differently |
| 1302 | than what follows here. |
| 1303 | </note> |
| 1304 | <literallayout class='monospaced'> |
| 1305 | recipetool -h |
| 1306 | recipetool create [-h] |
| 1307 | recipetool [-d] [-q] [--color auto | always | never ] create -o <replaceable>OUTFILE</replaceable> [-m] [-x <replaceable>EXTERNALSRC</replaceable>] <replaceable>source</replaceable> |
| 1308 | |
| 1309 | -d Enables debug output. |
| 1310 | -q Outputs only errors (quiet mode). |
| 1311 | --color Colorizes the output automatically, always, or never. |
| 1312 | -h Displays Python generated syntax for recipetool. |
| 1313 | create Causes recipetool to create a base recipe. The create |
| 1314 | command is further defined with these options: |
| 1315 | |
| 1316 | -o <replaceable>OUTFILE</replaceable> Specifies the full path and filename for the generated |
| 1317 | recipe. |
| 1318 | -m Causes the recipe to be machine-specific rather than |
| 1319 | architecture-specific (default). |
| 1320 | -x <replaceable>EXTERNALSRC</replaceable> Fetches and extracts source files from <replaceable>source</replaceable> |
| 1321 | and places them in <replaceable>EXTERNALSRC</replaceable>. |
| 1322 | <replaceable>source</replaceable> must be a URL. |
| 1323 | -h Displays Python-generated syntax for create. |
| 1324 | <replaceable>source</replaceable> Specifies the source code on which to base the |
| 1325 | recipe. |
| 1326 | </literallayout> |
| 1327 | </para> |
| 1328 | |
| 1329 | <para> |
| 1330 | Running <filename>recipetool create -o</filename> <replaceable>OUTFILE</replaceable> |
| 1331 | creates the base recipe and locates it properly in the |
| 1332 | layer that contains your source files. |
| 1333 | Following are some syntax examples: |
| 1334 | </para> |
| 1335 | |
| 1336 | <para> |
| 1337 | Use this syntax to generate a recipe based on <replaceable>source</replaceable>. |
| 1338 | Once generated, the recipe resides in the existing source |
| 1339 | code layer: |
| 1340 | <literallayout class='monospaced'> |
| 1341 | recipetool create -o <replaceable>OUTFILE</replaceable> <replaceable>source</replaceable> |
| 1342 | </literallayout> |
| 1343 | Use this syntax to generate a recipe using code that you |
| 1344 | extract from <replaceable>source</replaceable>. |
| 1345 | The extracted code is placed in its own layer defined |
| 1346 | by <replaceable>EXTERNALSRC</replaceable>. |
| 1347 | <literallayout class='monospaced'> |
| 1348 | recipetool create -o <replaceable>OUTFILE</replaceable> -x <replaceable>EXTERNALSRC</replaceable> <replaceable>source</replaceable> |
| 1349 | </literallayout> |
| 1350 | Use this syntax to generate a recipe based on <replaceable>source</replaceable>. |
| 1351 | The options direct <filename>recipetool</filename> to |
| 1352 | run in "quiet mode" and to generate debugging information. |
| 1353 | Once generated, the recipe resides in the existing source |
| 1354 | code layer: |
| 1355 | <literallayout class='monospaced'> |
| 1356 | recipetool create -o <replaceable>OUTFILE</replaceable> <replaceable>source</replaceable> |
| 1357 | </literallayout> |
| 1358 | </para> |
| 1359 | </section> |
| 1360 | |
| 1361 | <section id='new-recipe-locating-and-using-a-similar-recipe'> |
| 1362 | <title>Locating and Using a Similar Recipe</title> |
| 1363 | |
| 1364 | <para> |
| 1365 | Before writing a recipe from scratch, it is often useful to |
| 1366 | discover whether someone else has already written one that |
| 1367 | meets (or comes close to meeting) your needs. |
| 1368 | The Yocto Project and OpenEmbedded communities maintain many |
| 1369 | recipes that might be candidates for what you are doing. |
| 1370 | You can find a good central index of these recipes in the |
| 1371 | <ulink url='http://layers.openembedded.org'>OpenEmbedded metadata index</ulink>. |
| 1372 | </para> |
| 1373 | |
| 1374 | <para> |
| 1375 | Working from an existing recipe or a skeleton recipe is the |
| 1376 | best way to get started. |
| 1377 | Here are some points on both methods: |
| 1378 | <itemizedlist> |
| 1379 | <listitem><para><emphasis>Locate and modify a recipe that |
| 1380 | is close to what you want to do:</emphasis> |
| 1381 | This method works when you are familiar with the |
| 1382 | current recipe space. |
| 1383 | The method does not work so well for those new to |
| 1384 | the Yocto Project or writing recipes.</para> |
| 1385 | <para>Some risks associated with this method are |
| 1386 | using a recipe that has areas totally unrelated to |
| 1387 | what you are trying to accomplish with your recipe, |
| 1388 | not recognizing areas of the recipe that you might |
| 1389 | have to add from scratch, and so forth. |
| 1390 | All these risks stem from unfamiliarity with the |
| 1391 | existing recipe space.</para></listitem> |
| 1392 | <listitem><para><emphasis>Use and modify the following |
| 1393 | skeleton recipe:</emphasis> |
| 1394 | If for some reason you do not want to use |
| 1395 | <filename>recipetool</filename> and you cannot |
| 1396 | find an existing recipe that is close to meeting |
| 1397 | your needs, you can use the following structure to |
| 1398 | provide the fundamental areas of a new recipe. |
| 1399 | <literallayout class='monospaced'> |
| 1400 | DESCRIPTION = "" |
| 1401 | HOMEPAGE = "" |
| 1402 | LICENSE = "" |
| 1403 | SECTION = "" |
| 1404 | DEPENDS = "" |
| 1405 | LIC_FILES_CHKSUM = "" |
| 1406 | |
| 1407 | SRC_URI = "" |
| 1408 | </literallayout> |
| 1409 | </para></listitem> |
| 1410 | </itemizedlist> |
| 1411 | </para> |
| 1412 | </section> |
| 1413 | </section> |
| 1414 | |
| 1415 | <section id='new-recipe-storing-and-naming-the-recipe'> |
| 1416 | <title>Storing and Naming the Recipe</title> |
| 1417 | |
| 1418 | <para> |
| 1419 | Once you have your base recipe, you should put it in your |
| 1420 | own layer and name it appropriately. |
| 1421 | Locating it correctly ensures that the OpenEmbedded build |
| 1422 | system can find it when you use BitBake to process the |
| 1423 | recipe. |
| 1424 | </para> |
| 1425 | |
| 1426 | <itemizedlist> |
| 1427 | <listitem><para><emphasis>Storing Your Recipe:</emphasis> |
| 1428 | The OpenEmbedded build system locates your recipe |
| 1429 | through the layer's <filename>conf/layer.conf</filename> |
| 1430 | file and the |
| 1431 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILES'><filename>BBFILES</filename></ulink> |
| 1432 | variable. |
| 1433 | This variable sets up a path from which the build system can |
| 1434 | locate recipes. |
| 1435 | Here is the typical use: |
| 1436 | <literallayout class='monospaced'> |
| 1437 | BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \ |
| 1438 | ${LAYERDIR}/recipes-*/*/*.bbappend" |
| 1439 | </literallayout> |
| 1440 | Consequently, you need to be sure you locate your new recipe |
| 1441 | inside your layer such that it can be found.</para> |
| 1442 | <para>You can find more information on how layers are |
| 1443 | structured in the |
| 1444 | "<link linkend='understanding-and-creating-layers'>Understanding and Creating Layers</link>" |
| 1445 | section.</para></listitem> |
| 1446 | <listitem><para><emphasis>Naming Your Recipe:</emphasis> |
| 1447 | When you name your recipe, you need to follow this naming |
| 1448 | convention: |
| 1449 | <literallayout class='monospaced'> |
| 1450 | <replaceable>basename</replaceable>_<replaceable>version</replaceable>.bb |
| 1451 | </literallayout> |
| 1452 | Use lower-cased characters and do not include the reserved |
| 1453 | suffixes <filename>-native</filename>, |
| 1454 | <filename>-cross</filename>, <filename>-initial</filename>, |
| 1455 | or <filename>-dev</filename> casually (i.e. do not use them |
| 1456 | as part of your recipe name unless the string applies). |
| 1457 | Here are some examples: |
| 1458 | <literallayout class='monospaced'> |
| 1459 | cups_1.7.0.bb |
| 1460 | gawk_4.0.2.bb |
| 1461 | irssi_0.8.16-rc1.bb |
| 1462 | </literallayout></para></listitem> |
| 1463 | </itemizedlist> |
| 1464 | </section> |
| 1465 | |
| 1466 | <section id='understanding-recipe-syntax'> |
| 1467 | <title>Understanding Recipe Syntax</title> |
| 1468 | |
| 1469 | <para> |
| 1470 | Understanding recipe file syntax is important for |
| 1471 | writing recipes. |
| 1472 | The following list overviews the basic items that make up a |
| 1473 | BitBake recipe file. |
| 1474 | For more complete BitBake syntax descriptions, see the |
| 1475 | "<ulink url='&YOCTO_DOCS_BB_URL;#bitbake-user-manual-metadata'>Syntax and Operators</ulink>" |
| 1476 | chapter of the BitBake User Manual. |
| 1477 | <itemizedlist> |
| 1478 | <listitem><para><emphasis>Variable Assignments and Manipulations:</emphasis> |
| 1479 | Variable assignments allow a value to be assigned to a |
| 1480 | variable. |
| 1481 | The assignment can be static text or might include |
| 1482 | the contents of other variables. |
| 1483 | In addition to the assignment, appending and prepending |
| 1484 | operations are also supported.</para> |
| 1485 | <para>The following example shows some of the ways |
| 1486 | you can use variables in recipes: |
| 1487 | <literallayout class='monospaced'> |
| 1488 | S = "${WORKDIR}/postfix-${PV}" |
| 1489 | CFLAGS += "-DNO_ASM" |
| 1490 | SRC_URI_append = " file://fixup.patch" |
| 1491 | </literallayout> |
| 1492 | </para></listitem> |
| 1493 | <listitem><para><emphasis>Functions:</emphasis> |
| 1494 | Functions provide a series of actions to be performed. |
| 1495 | You usually use functions to override the default |
| 1496 | implementation of a task function or to complement |
| 1497 | a default function (i.e. append or prepend to an |
| 1498 | existing function). |
| 1499 | Standard functions use <filename>sh</filename> shell |
| 1500 | syntax, although access to OpenEmbedded variables and |
| 1501 | internal methods are also available.</para> |
| 1502 | <para>The following is an example function from the |
| 1503 | <filename>sed</filename> recipe: |
| 1504 | <literallayout class='monospaced'> |
| 1505 | do_install () { |
| 1506 | autotools_do_install |
| 1507 | install -d ${D}${base_bindir} |
| 1508 | mv ${D}${bindir}/sed ${D}${base_bindir}/sed |
| 1509 | rmdir ${D}${bindir}/ |
| 1510 | } |
| 1511 | </literallayout> |
| 1512 | It is also possible to implement new functions that |
| 1513 | are called between existing tasks as long as the |
| 1514 | new functions are not replacing or complementing the |
| 1515 | default functions. |
| 1516 | You can implement functions in Python |
| 1517 | instead of shell. |
| 1518 | Both of these options are not seen in the majority of |
| 1519 | recipes.</para></listitem> |
| 1520 | <listitem><para><emphasis>Keywords:</emphasis> |
| 1521 | BitBake recipes use only a few keywords. |
| 1522 | You use keywords to include common |
| 1523 | functions (<filename>inherit</filename>), load parts |
| 1524 | of a recipe from other files |
| 1525 | (<filename>include</filename> and |
| 1526 | <filename>require</filename>) and export variables |
| 1527 | to the environment (<filename>export</filename>).</para> |
| 1528 | <para>The following example shows the use of some of |
| 1529 | these keywords: |
| 1530 | <literallayout class='monospaced'> |
| 1531 | export POSTCONF = "${STAGING_BINDIR}/postconf" |
| 1532 | inherit autoconf |
| 1533 | require otherfile.inc |
| 1534 | </literallayout> |
| 1535 | </para></listitem> |
| 1536 | <listitem><para><emphasis>Comments:</emphasis> |
| 1537 | Any lines that begin with the hash character |
| 1538 | (<filename>#</filename>) are treated as comment lines |
| 1539 | and are ignored: |
| 1540 | <literallayout class='monospaced'> |
| 1541 | # This is a comment |
| 1542 | </literallayout> |
| 1543 | </para></listitem> |
| 1544 | </itemizedlist> |
| 1545 | </para> |
| 1546 | |
| 1547 | <para> |
| 1548 | This next list summarizes the most important and most commonly |
| 1549 | used parts of the recipe syntax. |
| 1550 | For more information on these parts of the syntax, you can |
| 1551 | reference the |
| 1552 | <ulink url='&YOCTO_DOCS_BB_URL;#bitbake-user-manual-metadata'>Syntax and Operators</ulink> |
| 1553 | chapter in the BitBake User Manual. |
| 1554 | <itemizedlist> |
| 1555 | <listitem><para><emphasis>Line Continuation: <filename>\</filename></emphasis> - |
| 1556 | Use the backward slash (<filename>\</filename>) |
| 1557 | character to split a statement over multiple lines. |
| 1558 | Place the slash character at the end of the line that |
| 1559 | is to be continued on the next line: |
| 1560 | <literallayout class='monospaced'> |
| 1561 | VAR = "A really long \ |
| 1562 | line" |
| 1563 | </literallayout> |
| 1564 | <note> |
| 1565 | You cannot have any characters including spaces |
| 1566 | or tabs after the slash character. |
| 1567 | </note> |
| 1568 | </para></listitem> |
| 1569 | <listitem><para><emphasis>Using Variables: <filename>${...}</filename></emphasis> - |
| 1570 | Use the <filename>${<replaceable>varname</replaceable>}</filename> syntax to |
| 1571 | access the contents of a variable: |
| 1572 | <literallayout class='monospaced'> |
| 1573 | SRC_URI = "${SOURCEFORGE_MIRROR}/libpng/zlib-${PV}.tar.gz" |
| 1574 | </literallayout> |
| 1575 | </para></listitem> |
| 1576 | <listitem><para><emphasis>Quote All Assignments: <filename>"<replaceable>value</replaceable>"</filename></emphasis> - |
| 1577 | Use double quotes around the value in all variable |
| 1578 | assignments. |
| 1579 | <literallayout class='monospaced'> |
| 1580 | VAR1 = "${OTHERVAR}" |
| 1581 | VAR2 = "The version is ${PV}" |
| 1582 | </literallayout> |
| 1583 | </para></listitem> |
| 1584 | <listitem><para><emphasis>Conditional Assignment: <filename>?=</filename></emphasis> - |
| 1585 | Conditional assignment is used to assign a value to |
| 1586 | a variable, but only when the variable is currently |
| 1587 | unset. |
| 1588 | Use the question mark followed by the equal sign |
| 1589 | (<filename>?=</filename>) to make a "soft" assignment |
| 1590 | used for conditional assignment. |
| 1591 | Typically, "soft" assignments are used in the |
| 1592 | <filename>local.conf</filename> file for variables |
| 1593 | that are allowed to come through from the external |
| 1594 | environment. |
| 1595 | </para> |
| 1596 | <para>Here is an example where |
| 1597 | <filename>VAR1</filename> is set to "New value" if |
| 1598 | it is currently empty. |
| 1599 | However, if <filename>VAR1</filename> has already been |
| 1600 | set, it remains unchanged: |
| 1601 | <literallayout class='monospaced'> |
| 1602 | VAR1 ?= "New value" |
| 1603 | </literallayout> |
| 1604 | In this next example, <filename>VAR1</filename> |
| 1605 | is left with the value "Original value": |
| 1606 | <literallayout class='monospaced'> |
| 1607 | VAR1 = "Original value" |
| 1608 | VAR1 ?= "New value" |
| 1609 | </literallayout> |
| 1610 | </para></listitem> |
| 1611 | <listitem><para><emphasis>Appending: <filename>+=</filename></emphasis> - |
| 1612 | Use the plus character followed by the equals sign |
| 1613 | (<filename>+=</filename>) to append values to existing |
| 1614 | variables. |
| 1615 | <note> |
| 1616 | This operator adds a space between the existing |
| 1617 | content of the variable and the new content. |
| 1618 | </note></para> |
| 1619 | <para>Here is an example: |
| 1620 | <literallayout class='monospaced'> |
| 1621 | SRC_URI += "file://fix-makefile.patch" |
| 1622 | </literallayout> |
| 1623 | </para></listitem> |
| 1624 | <listitem><para><emphasis>Prepending: <filename>=+</filename></emphasis> - |
| 1625 | Use the equals sign followed by the plus character |
| 1626 | (<filename>=+</filename>) to prepend values to existing |
| 1627 | variables. |
| 1628 | <note> |
| 1629 | This operator adds a space between the new content |
| 1630 | and the existing content of the variable. |
| 1631 | </note></para> |
| 1632 | <para>Here is an example: |
| 1633 | <literallayout class='monospaced'> |
| 1634 | VAR =+ "Starts" |
| 1635 | </literallayout> |
| 1636 | </para></listitem> |
| 1637 | <listitem><para><emphasis>Appending: <filename>_append</filename></emphasis> - |
| 1638 | Use the <filename>_append</filename> operator to |
| 1639 | append values to existing variables. |
| 1640 | This operator does not add any additional space. |
| 1641 | Also, the operator is applied after all the |
| 1642 | <filename>+=</filename>, and |
| 1643 | <filename>=+</filename> operators have been applied and |
| 1644 | after all <filename>=</filename> assignments have |
| 1645 | occurred. |
| 1646 | </para> |
| 1647 | <para>The following example shows the space being |
| 1648 | explicitly added to the start to ensure the appended |
| 1649 | value is not merged with the existing value: |
| 1650 | <literallayout class='monospaced'> |
| 1651 | SRC_URI_append = " file://fix-makefile.patch" |
| 1652 | </literallayout> |
| 1653 | You can also use the <filename>_append</filename> |
| 1654 | operator with overrides, which results in the actions |
| 1655 | only being performed for the specified target or |
| 1656 | machine: |
| 1657 | <literallayout class='monospaced'> |
| 1658 | SRC_URI_append_sh4 = " file://fix-makefile.patch" |
| 1659 | </literallayout> |
| 1660 | </para></listitem> |
| 1661 | <listitem><para><emphasis>Prepending: <filename>_prepend</filename></emphasis> - |
| 1662 | Use the <filename>_prepend</filename> operator to |
| 1663 | prepend values to existing variables. |
| 1664 | This operator does not add any additional space. |
| 1665 | Also, the operator is applied after all the |
| 1666 | <filename>+=</filename>, and |
| 1667 | <filename>=+</filename> operators have been applied and |
| 1668 | after all <filename>=</filename> assignments have |
| 1669 | occurred. |
| 1670 | </para> |
| 1671 | <para>The following example shows the space being |
| 1672 | explicitly added to the end to ensure the prepended |
| 1673 | value is not merged with the existing value: |
| 1674 | <literallayout class='monospaced'> |
| 1675 | CFLAGS_prepend = "-I${S}/myincludes " |
| 1676 | </literallayout> |
| 1677 | You can also use the <filename>_prepend</filename> |
| 1678 | operator with overrides, which results in the actions |
| 1679 | only being performed for the specified target or |
| 1680 | machine: |
| 1681 | <literallayout class='monospaced'> |
| 1682 | CFLAGS_prepend_sh4 = "-I${S}/myincludes " |
| 1683 | </literallayout> |
| 1684 | </para></listitem> |
| 1685 | <listitem><para><emphasis>Overrides:</emphasis> - |
| 1686 | You can use overrides to set a value conditionally, |
| 1687 | typically based on how the recipe is being built. |
| 1688 | For example, to set the |
| 1689 | <ulink url='&YOCTO_DOCS_REF_URL;#var-KBRANCH'><filename>KBRANCH</filename></ulink> |
| 1690 | variable's value to "standard/base" for any target |
| 1691 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>, |
| 1692 | except for qemuarm where it should be set to |
| 1693 | "standard/arm-versatile-926ejs", you would do the |
| 1694 | following: |
| 1695 | <literallayout class='monospaced'> |
| 1696 | KBRANCH = "standard/base" |
| 1697 | KBRANCH_qemuarm = "standard/arm-versatile-926ejs" |
| 1698 | </literallayout> |
| 1699 | Overrides are also used to separate alternate values |
| 1700 | of a variable in other situations. |
| 1701 | For example, when setting variables such as |
| 1702 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink> |
| 1703 | and |
| 1704 | <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink> |
| 1705 | that are specific to individual packages produced by |
| 1706 | a recipe, you should always use an override that |
| 1707 | specifies the name of the package. |
| 1708 | </para></listitem> |
| 1709 | <listitem><para><emphasis>Indentation:</emphasis> |
| 1710 | Use spaces for indentation rather than than tabs. |
| 1711 | For shell functions, both currently work. |
| 1712 | However, it is a policy decision of the Yocto Project |
| 1713 | to use tabs in shell functions. |
| 1714 | Realize that some layers have a policy to use spaces |
| 1715 | for all indentation. |
| 1716 | </para></listitem> |
| 1717 | <listitem><para><emphasis>Using Python for Complex Operations: <filename>${@<replaceable>python_code</replaceable>}</filename></emphasis> - |
| 1718 | For more advanced processing, it is possible to use |
| 1719 | Python code during variable assignments (e.g. |
| 1720 | search and replacement on a variable).</para> |
| 1721 | <para>You indicate Python code using the |
| 1722 | <filename>${@<replaceable>python_code</replaceable>}</filename> |
| 1723 | syntax for the variable assignment: |
| 1724 | <literallayout class='monospaced'> |
| 1725 | SRC_URI = "ftp://ftp.info-zip.org/pub/infozip/src/zip${@d.getVar('PV',1).replace('.', '')}.tgz |
| 1726 | </literallayout> |
| 1727 | </para></listitem> |
| 1728 | <listitem><para><emphasis>Shell Function Syntax:</emphasis> |
| 1729 | Write shell functions as if you were writing a shell |
| 1730 | script when you describe a list of actions to take. |
| 1731 | You should ensure that your script works with a generic |
| 1732 | <filename>sh</filename> and that it does not require |
| 1733 | any <filename>bash</filename> or other shell-specific |
| 1734 | functionality. |
| 1735 | The same considerations apply to various system |
| 1736 | utilities (e.g. <filename>sed</filename>, |
| 1737 | <filename>grep</filename>, <filename>awk</filename>, |
| 1738 | and so forth) that you might wish to use. |
| 1739 | If in doubt, you should check with multiple |
| 1740 | implementations - including those from BusyBox. |
| 1741 | </para></listitem> |
| 1742 | </itemizedlist> |
| 1743 | </para> |
| 1744 | </section> |
| 1745 | |
| 1746 | <section id='new-recipe-running-a-build-on-the-recipe'> |
| 1747 | <title>Running a Build on the Recipe</title> |
| 1748 | |
| 1749 | <para> |
| 1750 | Creating a new recipe is usually an iterative process that |
| 1751 | requires using BitBake to process the recipe multiple times in |
| 1752 | order to progressively discover and add information to the |
| 1753 | recipe file. |
| 1754 | </para> |
| 1755 | |
| 1756 | <para> |
| 1757 | Assuming you have sourced a build environment setup script (i.e. |
| 1758 | <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink> |
| 1759 | or |
| 1760 | <ulink url='&YOCTO_DOCS_REF_URL;#structure-memres-core-script'><filename>oe-init-build-env-memres</filename></ulink>) |
| 1761 | and you are in the |
| 1762 | <link linkend='build-directory'>Build Directory</link>, |
| 1763 | use BitBake to process your recipe. |
| 1764 | All you need to provide is the |
| 1765 | <filename><replaceable>basename</replaceable></filename> of the recipe as described |
| 1766 | in the previous section: |
| 1767 | <literallayout class='monospaced'> |
| 1768 | $ bitbake <replaceable>basename</replaceable> |
| 1769 | </literallayout> |
| 1770 | |
| 1771 | </para> |
| 1772 | |
| 1773 | <para> |
| 1774 | During the build, the OpenEmbedded build system creates a |
| 1775 | temporary work directory for each recipe |
| 1776 | (<filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}</filename>) |
| 1777 | where it keeps extracted source files, log files, intermediate |
| 1778 | compilation and packaging files, and so forth. |
| 1779 | </para> |
| 1780 | |
| 1781 | <para> |
| 1782 | The per-recipe temporary work directory is constructed as follows and |
| 1783 | depends on several factors: |
| 1784 | <literallayout class='monospaced'> |
| 1785 | BASE_WORKDIR ?= "${TMPDIR}/work" |
| 1786 | WORKDIR = "${BASE_WORKDIR}/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR}" |
| 1787 | </literallayout> |
| 1788 | As an example, assume a Source Directory top-level folder named |
| 1789 | <filename>poky</filename>, a default Build Directory at |
| 1790 | <filename>poky/build</filename>, and a |
| 1791 | <filename>qemux86-poky-linux</filename> machine target system. |
| 1792 | Furthermore, suppose your recipe is named |
| 1793 | <filename>foo_1.3.0.bb</filename>. |
| 1794 | In this case, the work directory the build system uses to |
| 1795 | build the package would be as follows: |
| 1796 | <literallayout class='monospaced'> |
| 1797 | poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0 |
| 1798 | </literallayout> |
| 1799 | Inside this directory you can find sub-directories such as |
| 1800 | <filename>image</filename>, <filename>packages-split</filename>, |
| 1801 | and <filename>temp</filename>. |
| 1802 | After the build, you can examine these to determine how well |
| 1803 | the build went. |
| 1804 | <note> |
| 1805 | You can find log files for each task in the recipe's |
| 1806 | <filename>temp</filename> directory (e.g. |
| 1807 | <filename>poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0/temp</filename>). |
| 1808 | Log files are named <filename>log.<replaceable>taskname</replaceable></filename> |
| 1809 | (e.g. <filename>log.do_configure</filename>, |
| 1810 | <filename>log.do_fetch</filename>, and |
| 1811 | <filename>log.do_compile</filename>). |
| 1812 | </note> |
| 1813 | </para> |
| 1814 | |
| 1815 | <para> |
| 1816 | You can find more information about the build process in the |
| 1817 | "<ulink url='&YOCTO_DOCS_REF_URL;#closer-look'>A Closer Look at the Yocto Project Development Environment</ulink>" |
| 1818 | chapter of the Yocto Project Reference Manual. |
| 1819 | </para> |
| 1820 | |
| 1821 | <para> |
| 1822 | You can also reference the following variables in the |
| 1823 | Yocto Project Reference Manual's glossary for more information: |
| 1824 | <itemizedlist> |
| 1825 | <listitem><ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>: |
| 1826 | The top-level build output directory</listitem> |
| 1827 | <listitem><ulink url='&YOCTO_DOCS_REF_URL;#var-MULTIMACH_TARGET_SYS'><filename>MULTIMACH_TARGET_SYS</filename></ulink>: |
| 1828 | The target system identifier</listitem> |
| 1829 | <listitem><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>: |
| 1830 | The recipe name</listitem> |
| 1831 | <listitem><ulink url='&YOCTO_DOCS_REF_URL;#var-EXTENDPE'><filename>EXTENDPE</filename></ulink>: |
| 1832 | The epoch - (if |
| 1833 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PE'><filename>PE</filename></ulink> |
| 1834 | is not specified, which is usually the case for most |
| 1835 | recipes, then <filename>EXTENDPE</filename> is blank)</listitem> |
| 1836 | <listitem><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>: |
| 1837 | The recipe version</listitem> |
| 1838 | <listitem><ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>: |
| 1839 | The recipe revision</listitem> |
| 1840 | </itemizedlist> |
| 1841 | </para> |
| 1842 | </section> |
| 1843 | |
| 1844 | <section id='new-recipe-fetching-code'> |
| 1845 | <title>Fetching Code</title> |
| 1846 | |
| 1847 | <para> |
| 1848 | The first thing your recipe must do is specify how to fetch |
| 1849 | the source files. |
| 1850 | Fetching is controlled mainly through the |
| 1851 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> |
| 1852 | variable. |
| 1853 | Your recipe must have a <filename>SRC_URI</filename> variable |
| 1854 | that points to where the source is located. |
| 1855 | For a graphical representation of source locations, see the |
| 1856 | "<ulink url='&YOCTO_DOCS_REF_URL;#sources-dev-environment'>Sources</ulink>" |
| 1857 | section in the Yocto Project Reference Manual. |
| 1858 | </para> |
| 1859 | |
| 1860 | <para> |
| 1861 | The |
| 1862 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-fetch'><filename>do_fetch</filename></ulink> |
| 1863 | task uses the prefix of each entry in the |
| 1864 | <filename>SRC_URI</filename> variable value to determine which |
| 1865 | fetcher to use to get your source files. |
| 1866 | It is the <filename>SRC_URI</filename> variable that triggers |
| 1867 | the fetcher. |
| 1868 | The |
| 1869 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink> |
| 1870 | task uses the variable after source is fetched to apply |
| 1871 | patches. |
| 1872 | The OpenEmbedded build system uses |
| 1873 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESOVERRIDES'><filename>FILESOVERRIDES</filename></ulink> |
| 1874 | for scanning directory locations for local files in |
| 1875 | <filename>SRC_URI</filename>. |
| 1876 | </para> |
| 1877 | |
| 1878 | <para> |
| 1879 | The <filename>SRC_URI</filename> variable in your recipe must |
| 1880 | define each unique location for your source files. |
| 1881 | It is good practice to not hard-code pathnames in an URL used |
| 1882 | in <filename>SRC_URI</filename>. |
| 1883 | Rather than hard-code these paths, use |
| 1884 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink><filename>}</filename>, |
| 1885 | which causes the fetch process to use the version specified in |
| 1886 | the recipe filename. |
| 1887 | Specifying the version in this manner means that upgrading the |
| 1888 | recipe to a future version is as simple as renaming the recipe |
| 1889 | to match the new version. |
| 1890 | </para> |
| 1891 | |
| 1892 | <para> |
| 1893 | Here is a simple example from the |
| 1894 | <filename>meta/recipes-devtools/cdrtools/cdrtools-native_3.01a20.bb</filename> |
| 1895 | recipe where the source comes from a single tarball. |
| 1896 | Notice the use of the |
| 1897 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink> |
| 1898 | variable: |
| 1899 | <literallayout class='monospaced'> |
| 1900 | SRC_URI = "ftp://ftp.berlios.de/pub/cdrecord/alpha/cdrtools-${PV}.tar.bz2" |
| 1901 | </literallayout> |
| 1902 | </para> |
| 1903 | |
| 1904 | <para> |
| 1905 | Files mentioned in <filename>SRC_URI</filename> whose names end |
| 1906 | in a typical archive extension (e.g. <filename>.tar</filename>, |
| 1907 | <filename>.tar.gz</filename>, <filename>.tar.bz2</filename>, |
| 1908 | <filename>.zip</filename>, and so forth), are automatically |
| 1909 | extracted during the |
| 1910 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-unpack'><filename>do_unpack</filename></ulink> |
| 1911 | task. |
| 1912 | For another example that specifies these types of files, see |
| 1913 | the |
| 1914 | "<link linkend='new-recipe-autotooled-package'>Autotooled Package</link>" |
| 1915 | section. |
| 1916 | </para> |
| 1917 | |
| 1918 | <para> |
| 1919 | Another way of specifying source is from an SCM. |
| 1920 | For Git repositories, you must specify |
| 1921 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink> |
| 1922 | and you should specify |
| 1923 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink> |
| 1924 | to include the revision with |
| 1925 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>. |
| 1926 | Here is an example from the recipe |
| 1927 | <filename>meta/recipes-kernel/blktrace/blktrace_git.bb</filename>: |
| 1928 | <literallayout class='monospaced'> |
| 1929 | SRCREV = "d6918c8832793b4205ed3bfede78c2f915c23385" |
| 1930 | |
| 1931 | PR = "r6" |
| 1932 | PV = "1.0.5+git${SRCPV}" |
| 1933 | |
| 1934 | SRC_URI = "git://git.kernel.dk/blktrace.git \ |
| 1935 | file://ldflags.patch" |
| 1936 | </literallayout> |
| 1937 | </para> |
| 1938 | |
| 1939 | <para> |
| 1940 | If your <filename>SRC_URI</filename> statement includes |
| 1941 | URLs pointing to individual files fetched from a remote server |
| 1942 | other than a version control system, BitBake attempts to |
| 1943 | verify the files against checksums defined in your recipe to |
| 1944 | ensure they have not been tampered with or otherwise modified |
| 1945 | since the recipe was written. |
| 1946 | Two checksums are used: |
| 1947 | <filename>SRC_URI[md5sum]</filename> and |
| 1948 | <filename>SRC_URI[sha256sum]</filename>. |
| 1949 | </para> |
| 1950 | |
| 1951 | <para> |
| 1952 | If your <filename>SRC_URI</filename> variable points to |
| 1953 | more than a single URL (excluding SCM URLs), you need to |
| 1954 | provide the <filename>md5</filename> and |
| 1955 | <filename>sha256</filename> checksums for each URL. |
| 1956 | For these cases, you provide a name for each URL as part of |
| 1957 | the <filename>SRC_URI</filename> and then reference that name |
| 1958 | in the subsequent checksum statements. |
| 1959 | Here is an example: |
| 1960 | <literallayout class='monospaced'> |
| 1961 | SRC_URI = "${DEBIAN_MIRROR}/main/a/apmd/apmd_3.2.2.orig.tar.gz;name=tarball \ |
| 1962 | ${DEBIAN_MIRROR}/main/a/apmd/apmd_${PV}.diff.gz;name=patch |
| 1963 | |
| 1964 | SRC_URI[tarball.md5sum] = "b1e6309e8331e0f4e6efd311c2d97fa8" |
| 1965 | SRC_URI[tarball.sha256sum] = "7f7d9f60b7766b852881d40b8ff91d8e39fccb0d1d913102a5c75a2dbb52332d" |
| 1966 | |
| 1967 | SRC_URI[patch.md5sum] = "57e1b689264ea80f78353519eece0c92" |
| 1968 | SRC_URI[patch.sha256sum] = "7905ff96be93d725544d0040e425c42f9c05580db3c272f11cff75b9aa89d430" |
| 1969 | </literallayout> |
| 1970 | </para> |
| 1971 | |
| 1972 | <para> |
| 1973 | Proper values for <filename>md5</filename> and |
| 1974 | <filename>sha256</filename> checksums might be available |
| 1975 | with other signatures on the download page for the upstream |
| 1976 | source (e.g. <filename>md5</filename>, |
| 1977 | <filename>sha1</filename>, <filename>sha256</filename>, |
| 1978 | <filename>GPG</filename>, and so forth). |
| 1979 | Because the OpenEmbedded build system only deals with |
| 1980 | <filename>sha256sum</filename> and <filename>md5sum</filename>, |
| 1981 | you should verify all the signatures you find by hand. |
| 1982 | </para> |
| 1983 | |
| 1984 | <para> |
| 1985 | If no <filename>SRC_URI</filename> checksums are specified |
| 1986 | when you attempt to build the recipe, or you provide an |
| 1987 | incorrect checksum, the build will produce an error for each |
| 1988 | missing or incorrect checksum. |
| 1989 | As part of the error message, the build system provides |
| 1990 | the checksum string corresponding to the fetched file. |
| 1991 | Once you have the correct checksums, you can copy and paste |
| 1992 | them into your recipe and then run the build again to continue. |
| 1993 | <note> |
| 1994 | As mentioned, if the upstream source provides signatures |
| 1995 | for verifying the downloaded source code, you should |
| 1996 | verify those manually before setting the checksum values |
| 1997 | in the recipe and continuing with the build. |
| 1998 | </note> |
| 1999 | </para> |
| 2000 | |
| 2001 | <para> |
| 2002 | This final example is a bit more complicated and is from the |
| 2003 | <filename>meta/recipes-sato/rxvt-unicode/rxvt-unicode_9.20.bb</filename> |
| 2004 | recipe. |
| 2005 | The example's <filename>SRC_URI</filename> statement identifies |
| 2006 | multiple files as the source files for the recipe: a tarball, a |
| 2007 | patch file, a desktop file, and an icon. |
| 2008 | <literallayout class='monospaced'> |
| 2009 | SRC_URI = "http://dist.schmorp.de/rxvt-unicode/Attic/rxvt-unicode-${PV}.tar.bz2 \ |
| 2010 | file://xwc.patch \ |
| 2011 | file://rxvt.desktop \ |
| 2012 | file://rxvt.png" |
| 2013 | </literallayout> |
| 2014 | </para> |
| 2015 | |
| 2016 | <para> |
| 2017 | When you specify local files using the |
| 2018 | <filename>file://</filename> URI protocol, the build system |
| 2019 | fetches files from the local machine. |
| 2020 | The path is relative to the |
| 2021 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink> |
| 2022 | variable and searches specific directories in a certain order: |
| 2023 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BP'><filename>BP</filename></ulink><filename>}</filename>, |
| 2024 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BPN'><filename>BPN</filename></ulink><filename>}</filename>, |
| 2025 | and <filename>files</filename>. |
| 2026 | The directories are assumed to be subdirectories of the |
| 2027 | directory in which the recipe or append file resides. |
| 2028 | For another example that specifies these types of files, see the |
| 2029 | "<link linkend='new-recipe-single-c-file-package-hello-world'>Single .c File Package (Hello World!)</link>" |
| 2030 | section. |
| 2031 | </para> |
| 2032 | |
| 2033 | <para> |
| 2034 | The previous example also specifies a patch file. |
| 2035 | Patch files are files whose names usually end in |
| 2036 | <filename>.patch</filename> or <filename>.diff</filename> but |
| 2037 | can end with compressed suffixes such as |
| 2038 | <filename>diff.gz</filename> and |
| 2039 | <filename>patch.bz2</filename>, for example. |
| 2040 | The build system automatically applies patches as described |
| 2041 | in the |
| 2042 | "<link linkend='new-recipe-patching-code'>Patching Code</link>" section. |
| 2043 | </para> |
| 2044 | </section> |
| 2045 | |
| 2046 | <section id='new-recipe-unpacking-code'> |
| 2047 | <title>Unpacking Code</title> |
| 2048 | |
| 2049 | <para> |
| 2050 | During the build, the |
| 2051 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-unpack'><filename>do_unpack</filename></ulink> |
| 2052 | task unpacks the source with |
| 2053 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename> |
| 2054 | pointing to where it is unpacked. |
| 2055 | </para> |
| 2056 | |
| 2057 | <para> |
| 2058 | If you are fetching your source files from an upstream source |
| 2059 | archived tarball and the tarball's internal structure matches |
| 2060 | the common convention of a top-level subdirectory named |
| 2061 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BPN'><filename>BPN</filename></ulink><filename>}-${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink><filename>}</filename>, |
| 2062 | then you do not need to set <filename>S</filename>. |
| 2063 | However, if <filename>SRC_URI</filename> specifies to fetch |
| 2064 | source from an archive that does not use this convention, |
| 2065 | or from an SCM like Git or Subversion, your recipe needs to |
| 2066 | define <filename>S</filename>. |
| 2067 | </para> |
| 2068 | |
| 2069 | <para> |
| 2070 | If processing your recipe using BitBake successfully unpacks |
| 2071 | the source files, you need to be sure that the directory |
| 2072 | pointed to by <filename>${S}</filename> matches the structure |
| 2073 | of the source. |
| 2074 | </para> |
| 2075 | </section> |
| 2076 | |
| 2077 | <section id='new-recipe-patching-code'> |
| 2078 | <title>Patching Code</title> |
| 2079 | |
| 2080 | <para> |
| 2081 | Sometimes it is necessary to patch code after it has been |
| 2082 | fetched. |
| 2083 | Any files mentioned in <filename>SRC_URI</filename> whose |
| 2084 | names end in <filename>.patch</filename> or |
| 2085 | <filename>.diff</filename> or compressed versions of these |
| 2086 | suffixes (e.g. <filename>diff.gz</filename> are treated as |
| 2087 | patches. |
| 2088 | The |
| 2089 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink> |
| 2090 | task automatically applies these patches. |
| 2091 | </para> |
| 2092 | |
| 2093 | <para> |
| 2094 | The build system should be able to apply patches with the "-p1" |
| 2095 | option (i.e. one directory level in the path will be stripped |
| 2096 | off). |
| 2097 | If your patch needs to have more directory levels stripped off, |
| 2098 | specify the number of levels using the "striplevel" option in |
| 2099 | the <filename>SRC_URI</filename> entry for the patch. |
| 2100 | Alternatively, if your patch needs to be applied in a specific |
| 2101 | subdirectory that is not specified in the patch file, use the |
| 2102 | "patchdir" option in the entry. |
| 2103 | </para> |
| 2104 | |
| 2105 | <para> |
| 2106 | As with all local files referenced in |
| 2107 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> |
| 2108 | using <filename>file://</filename>, you should place |
| 2109 | patch files in a directory next to the recipe either |
| 2110 | named the same as the base name of the recipe |
| 2111 | (<ulink url='&YOCTO_DOCS_REF_URL;#var-BP'><filename>BP</filename></ulink> |
| 2112 | and |
| 2113 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BPN'><filename>BPN</filename></ulink>) |
| 2114 | or "files". |
| 2115 | </para> |
| 2116 | </section> |
| 2117 | |
| 2118 | <section id='new-recipe-licensing'> |
| 2119 | <title>Licensing</title> |
| 2120 | |
| 2121 | <para> |
| 2122 | Your recipe needs to have both the |
| 2123 | <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink> |
| 2124 | and |
| 2125 | <ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'><filename>LIC_FILES_CHKSUM</filename></ulink> |
| 2126 | variables: |
| 2127 | <itemizedlist> |
| 2128 | <listitem><para><emphasis><filename>LICENSE</filename>:</emphasis> |
| 2129 | This variable specifies the license for the software. |
| 2130 | If you do not know the license under which the software |
| 2131 | you are building is distributed, you should go to the |
| 2132 | source code and look for that information. |
| 2133 | Typical files containing this information include |
| 2134 | <filename>COPYING</filename>, |
| 2135 | <filename>LICENSE</filename>, and |
| 2136 | <filename>README</filename> files. |
| 2137 | You could also find the information near the top of |
| 2138 | a source file. |
| 2139 | For example, given a piece of software licensed under |
| 2140 | the GNU General Public License version 2, you would |
| 2141 | set <filename>LICENSE</filename> as follows: |
| 2142 | <literallayout class='monospaced'> |
| 2143 | LICENSE = "GPLv2" |
| 2144 | </literallayout></para> |
| 2145 | <para>The licenses you specify within |
| 2146 | <filename>LICENSE</filename> can have any name as long |
| 2147 | as you do not use spaces, since spaces are used as |
| 2148 | separators between license names. |
| 2149 | For standard licenses, use the names of the files in |
| 2150 | <filename>meta/files/common-licenses/</filename> |
| 2151 | or the <filename>SPDXLICENSEMAP</filename> flag names |
| 2152 | defined in <filename>meta/conf/licenses.conf</filename>. |
| 2153 | </para></listitem> |
| 2154 | <listitem><para><emphasis><filename>LIC_FILES_CHKSUM</filename>:</emphasis> |
| 2155 | The OpenEmbedded build system uses this variable to |
| 2156 | make sure the license text has not changed. |
| 2157 | If it has, the build produces an error and it affords |
| 2158 | you the chance to figure it out and correct the problem. |
| 2159 | </para> |
| 2160 | <para>You need to specify all applicable licensing |
| 2161 | files for the software. |
| 2162 | At the end of the configuration step, the build process |
| 2163 | will compare the checksums of the files to be sure |
| 2164 | the text has not changed. |
| 2165 | Any differences result in an error with the message |
| 2166 | containing the current checksum. |
| 2167 | For more explanation and examples of how to set the |
| 2168 | <filename>LIC_FILES_CHKSUM</filename> variable, see the |
| 2169 | "<ulink url='&YOCTO_DOCS_REF_URL;#usingpoky-configuring-LIC_FILES_CHKSUM'>Tracking License Changes</ulink>" |
| 2170 | section in the Yocto Project Reference Manual.</para> |
| 2171 | <para>To determine the correct checksum string, you |
| 2172 | can list the appropriate files in the |
| 2173 | <filename>LIC_FILES_CHKSUM</filename> variable with |
| 2174 | incorrect md5 strings, attempt to build the software, |
| 2175 | and then note the resulting error messages that will |
| 2176 | report the correct md5 strings. |
| 2177 | See the |
| 2178 | "<link linkend='new-recipe-fetching-code'>Fetching Code</link>" |
| 2179 | section for additional information. |
| 2180 | </para> |
| 2181 | |
| 2182 | <para> |
| 2183 | Here is an example that assumes the software has a |
| 2184 | <filename>COPYING</filename> file: |
| 2185 | <literallayout class='monospaced'> |
| 2186 | LIC_FILES_CHKSUM = "file://COPYING;md5=xxx" |
| 2187 | </literallayout> |
| 2188 | When you try to build the software, the build system |
| 2189 | will produce an error and give you the correct string |
| 2190 | that you can substitute into the recipe file for a |
| 2191 | subsequent build. |
| 2192 | </para></listitem> |
| 2193 | </itemizedlist> |
| 2194 | </para> |
| 2195 | |
| 2196 | <!-- |
| 2197 | |
| 2198 | <para> |
| 2199 | For trying this out I created a new recipe named |
| 2200 | <filename>htop_1.0.2.bb</filename> and put it in |
| 2201 | <filename>poky/meta/recipes-extended/htop</filename>. |
| 2202 | There are two license type statements in my very simple |
| 2203 | recipe: |
| 2204 | <literallayout class='monospaced'> |
| 2205 | LICENSE = "" |
| 2206 | |
| 2207 | LIC_FILES_CHKSUM = "" |
| 2208 | |
| 2209 | SRC_URI[md5sum] = "" |
| 2210 | SRC_URI[sha256sum] = "" |
| 2211 | </literallayout> |
| 2212 | Evidently, you need to run a <filename>bitbake -c cleanall htop</filename>. |
| 2213 | Next, you delete or comment out the two <filename>SRC_URI</filename> |
| 2214 | lines at the end and then attempt to build the software with |
| 2215 | <filename>bitbake htop</filename>. |
| 2216 | Doing so causes BitBake to report some errors and and give |
| 2217 | you the actual strings you need for the last two |
| 2218 | <filename>SRC_URI</filename> lines. |
| 2219 | Prior to this, you have to dig around in the home page of the |
| 2220 | source for <filename>htop</filename> and determine that the |
| 2221 | software is released under GPLv2. |
| 2222 | You can provide that in the <filename>LICENSE</filename> |
| 2223 | statement. |
| 2224 | Now you edit your recipe to have those two strings for |
| 2225 | the <filename>SRC_URI</filename> statements: |
| 2226 | <literallayout class='monospaced'> |
| 2227 | LICENSE = "GPLv2" |
| 2228 | |
| 2229 | LIC_FILES_CHKSUM = "" |
| 2230 | |
| 2231 | SRC_URI = "${SOURCEFORGE_MIRROR}/htop/htop-${PV}.tar.gz" |
| 2232 | SRC_URI[md5sum] = "0d01cca8df3349c74569cefebbd9919e" |
| 2233 | SRC_URI[sha256sum] = "ee60657b044ece0df096c053060df7abf3cce3a568ab34d260049e6a37ccd8a1" |
| 2234 | </literallayout> |
| 2235 | At this point, you can build the software again using the |
| 2236 | <filename>bitbake htop</filename> command. |
| 2237 | There is just a set of errors now associated with the |
| 2238 | empty <filename>LIC_FILES_CHKSUM</filename> variable now. |
| 2239 | </para> |
| 2240 | --> |
| 2241 | |
| 2242 | </section> |
| 2243 | |
| 2244 | <section id='new-recipe-configuring-the-recipe'> |
| 2245 | <title>Configuring the Recipe</title> |
| 2246 | |
| 2247 | <para> |
| 2248 | Most software provides some means of setting build-time |
| 2249 | configuration options before compilation. |
| 2250 | Typically, setting these options is accomplished by running a |
| 2251 | configure script with some options, or by modifying a build |
| 2252 | configuration file. |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 2253 | <note> |
| 2254 | As of Yocto Project Release 7.1, some of the core recipes |
| 2255 | that package binary configuration scripts now disable the |
| 2256 | scripts due to the scripts previously requiring error-prone |
| 2257 | path substitution. |
| 2258 | The OpenEmbedded build system uses |
| 2259 | <filename>pkg-config</filename> now, which is much more |
| 2260 | robust. |
| 2261 | You can find a list of the <filename>*-config</filename> |
| 2262 | scripts that are disabled list in the |
| 2263 | "<ulink url='&YOCTO_DOCS_REF_URL;#migration-1.7-binary-configuration-scripts-disabled'>Binary Configuration Scripts Disabled</ulink>" |
| 2264 | section in the Yocto Project Reference Manual. |
| 2265 | </note> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2266 | </para> |
| 2267 | |
| 2268 | <para> |
| 2269 | A major part of build-time configuration is about checking for |
| 2270 | build-time dependencies and possibly enabling optional |
| 2271 | functionality as a result. |
| 2272 | You need to specify any build-time dependencies for the |
| 2273 | software you are building in your recipe's |
| 2274 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink> |
| 2275 | value, in terms of other recipes that satisfy those |
| 2276 | dependencies. |
| 2277 | You can often find build-time or runtime |
| 2278 | dependencies described in the software's documentation. |
| 2279 | </para> |
| 2280 | |
| 2281 | <para> |
| 2282 | The following list provides configuration items of note based |
| 2283 | on how your software is built: |
| 2284 | <itemizedlist> |
| 2285 | <listitem><para><emphasis>Autotools:</emphasis> |
| 2286 | If your source files have a |
| 2287 | <filename>configure.ac</filename> file, then your |
| 2288 | software is built using Autotools. |
| 2289 | If this is the case, you just need to worry about |
| 2290 | modifying the configuration.</para> |
| 2291 | <para>When using Autotools, your recipe needs to inherit |
| 2292 | the |
| 2293 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink> |
| 2294 | class and your recipe does not have to contain a |
| 2295 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink> |
| 2296 | task. |
| 2297 | However, you might still want to make some adjustments. |
| 2298 | For example, you can set |
| 2299 | <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OECONF'><filename>EXTRA_OECONF</filename></ulink> |
| 2300 | to pass any needed configure options that are specific |
| 2301 | to the recipe.</para></listitem> |
| 2302 | <listitem><para><emphasis>CMake:</emphasis> |
| 2303 | If your source files have a |
| 2304 | <filename>CMakeLists.txt</filename> file, then your |
| 2305 | software is built using CMake. |
| 2306 | If this is the case, you just need to worry about |
| 2307 | modifying the configuration.</para> |
| 2308 | <para>When you use CMake, your recipe needs to inherit |
| 2309 | the |
| 2310 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-cmake'><filename>cmake</filename></ulink> |
| 2311 | class and your recipe does not have to contain a |
| 2312 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink> |
| 2313 | task. |
| 2314 | You can make some adjustments by setting |
| 2315 | <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OECMAKE'><filename>EXTRA_OECMAKE</filename></ulink> |
| 2316 | to pass any needed configure options that are specific |
| 2317 | to the recipe.</para></listitem> |
| 2318 | <listitem><para><emphasis>Other:</emphasis> |
| 2319 | If your source files do not have a |
| 2320 | <filename>configure.ac</filename> or |
| 2321 | <filename>CMakeLists.txt</filename> file, then your |
| 2322 | software is built using some method other than Autotools |
| 2323 | or CMake. |
| 2324 | If this is the case, you normally need to provide a |
| 2325 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink> |
| 2326 | task in your recipe |
| 2327 | unless, of course, there is nothing to configure. |
| 2328 | </para> |
| 2329 | <para>Even if your software is not being built by |
| 2330 | Autotools or CMake, you still might not need to deal |
| 2331 | with any configuration issues. |
| 2332 | You need to determine if configuration is even a required step. |
| 2333 | You might need to modify a Makefile or some configuration file |
| 2334 | used for the build to specify necessary build options. |
| 2335 | Or, perhaps you might need to run a provided, custom |
| 2336 | configure script with the appropriate options.</para> |
| 2337 | <para>For the case involving a custom configure |
| 2338 | script, you would run |
| 2339 | <filename>./configure --help</filename> and look for |
| 2340 | the options you need to set.</para></listitem> |
| 2341 | </itemizedlist> |
| 2342 | </para> |
| 2343 | |
| 2344 | <para> |
| 2345 | Once configuration succeeds, it is always good practice to |
| 2346 | look at the <filename>log.do_configure</filename> file to |
| 2347 | ensure that the appropriate options have been enabled and no |
| 2348 | additional build-time dependencies need to be added to |
| 2349 | <filename>DEPENDS</filename>. |
| 2350 | For example, if the configure script reports that it found |
| 2351 | something not mentioned in <filename>DEPENDS</filename>, or |
| 2352 | that it did not find something that it needed for some |
| 2353 | desired optional functionality, then you would need to add |
| 2354 | those to <filename>DEPENDS</filename>. |
| 2355 | Looking at the log might also reveal items being checked for, |
| 2356 | enabled, or both that you do not want, or items not being found |
| 2357 | that are in <filename>DEPENDS</filename>, in which case |
| 2358 | you would need to look at passing extra options to the |
| 2359 | configure script as needed. |
| 2360 | For reference information on configure options specific to the |
| 2361 | software you are building, you can consult the output of the |
| 2362 | <filename>./configure --help</filename> command within |
| 2363 | <filename>${S}</filename> or consult the software's upstream |
| 2364 | documentation. |
| 2365 | </para> |
| 2366 | </section> |
| 2367 | |
| 2368 | <section id='new-recipe-compilation'> |
| 2369 | <title>Compilation</title> |
| 2370 | |
| 2371 | <para> |
| 2372 | During a build, the <filename>do_compile</filename> task |
| 2373 | happens after source is fetched, unpacked, and configured. |
| 2374 | If the recipe passes through <filename>do_compile</filename> |
| 2375 | successfully, nothing needs to be done. |
| 2376 | </para> |
| 2377 | |
| 2378 | <para> |
| 2379 | However, if the compile step fails, you need to diagnose the |
| 2380 | failure. |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 2381 | Here are some common issues that cause failures. |
| 2382 | <note> |
| 2383 | For cases where improper paths are detected for |
| 2384 | configuration files or for when libraries/headers cannot |
| 2385 | be found, be sure you are using the more robust |
| 2386 | <filename>pkg-config</filename>. |
| 2387 | See the note in section |
| 2388 | "<link linkend='new-recipe-configuring-the-recipe'>Configuring the Recipe</link>" |
| 2389 | for additional information. |
| 2390 | </note> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2391 | <itemizedlist> |
| 2392 | <listitem><para><emphasis>Parallel build failures:</emphasis> |
| 2393 | These failures manifest themselves as intermittent |
| 2394 | errors, or errors reporting that a file or directory |
| 2395 | that should be created by some other part of the build |
| 2396 | process could not be found. |
| 2397 | This type of failure can occur even if, upon inspection, |
| 2398 | the file or directory does exist after the build has |
| 2399 | failed, because that part of the build process happened |
| 2400 | in the wrong order.</para> |
| 2401 | <para>To fix the problem, you need to either satisfy |
| 2402 | the missing dependency in the Makefile or whatever |
| 2403 | script produced the Makefile, or (as a workaround) |
| 2404 | set |
| 2405 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink> |
| 2406 | to an empty string: |
| 2407 | <literallayout class='monospaced'> |
| 2408 | PARALLEL_MAKE = "" |
| 2409 | </literallayout></para> |
| 2410 | <para> |
| 2411 | For information on parallel Makefile issues, see the |
| 2412 | "<link linkend='debugging-parallel-make-races'>Debugging Parallel Make Races</link>" |
| 2413 | section. |
| 2414 | </para></listitem> |
| 2415 | <listitem><para><emphasis>Improper host path usage:</emphasis> |
| 2416 | This failure applies to recipes building for the target |
| 2417 | or <filename>nativesdk</filename> only. |
| 2418 | The failure occurs when the compilation process uses |
| 2419 | improper headers, libraries, or other files from the |
| 2420 | host system when cross-compiling for the target. |
| 2421 | </para> |
| 2422 | <para>To fix the problem, examine the |
| 2423 | <filename>log.do_compile</filename> file to identify |
| 2424 | the host paths being used (e.g. |
| 2425 | <filename>/usr/include</filename>, |
| 2426 | <filename>/usr/lib</filename>, and so forth) and then |
| 2427 | either add configure options, apply a patch, or do both. |
| 2428 | </para></listitem> |
| 2429 | <listitem><para><emphasis>Failure to find required |
| 2430 | libraries/headers:</emphasis> |
| 2431 | If a build-time dependency is missing because it has |
| 2432 | not been declared in |
| 2433 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>, |
| 2434 | or because the dependency exists but the path used by |
| 2435 | the build process to find the file is incorrect and the |
| 2436 | configure step did not detect it, the compilation |
| 2437 | process could fail. |
| 2438 | For either of these failures, the compilation process |
| 2439 | notes that files could not be found. |
| 2440 | In these cases, you need to go back and add additional |
| 2441 | options to the configure script as well as possibly |
| 2442 | add additional build-time dependencies to |
| 2443 | <filename>DEPENDS</filename>.</para> |
| 2444 | <para>Occasionally, it is necessary to apply a patch |
| 2445 | to the source to ensure the correct paths are used. |
| 2446 | If you need to specify paths to find files staged |
| 2447 | into the sysroot from other recipes, use the variables |
| 2448 | that the OpenEmbedded build system provides |
| 2449 | (e.g. |
| 2450 | <filename>STAGING_BINDIR</filename>, |
| 2451 | <filename>STAGING_INCDIR</filename>, |
| 2452 | <filename>STAGING_DATADIR</filename>, and so forth). |
| 2453 | <!-- |
| 2454 | (e.g. |
| 2455 | <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_BINDIR'><filename>STAGING_BINDIR</filename></ulink>, |
| 2456 | <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_INCDIR'><filename>STAGING_INCDIR</filename></ulink>, |
| 2457 | <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_DATADIR'><filename>STAGING_DATADIR</filename></ulink>, |
| 2458 | and so forth). |
| 2459 | --> |
| 2460 | </para></listitem> |
| 2461 | </itemizedlist> |
| 2462 | </para> |
| 2463 | </section> |
| 2464 | |
| 2465 | <section id='new-recipe-installing'> |
| 2466 | <title>Installing</title> |
| 2467 | |
| 2468 | <para> |
| 2469 | During <filename>do_install</filename>, the task copies the |
| 2470 | built files along with their hierarchy to locations that |
| 2471 | would mirror their locations on the target device. |
| 2472 | The installation process copies files from the |
| 2473 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>, |
| 2474 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-B'><filename>B</filename></ulink><filename>}</filename>, |
| 2475 | and |
| 2476 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}</filename> |
| 2477 | directories to the |
| 2478 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink><filename>}</filename> |
| 2479 | directory to create the structure as it should appear on the |
| 2480 | target system. |
| 2481 | </para> |
| 2482 | |
| 2483 | <para> |
| 2484 | How your software is built affects what you must do to be |
| 2485 | sure your software is installed correctly. |
| 2486 | The following list describes what you must do for installation |
| 2487 | depending on the type of build system used by the software |
| 2488 | being built: |
| 2489 | <itemizedlist> |
| 2490 | <listitem><para><emphasis>Autotools and CMake:</emphasis> |
| 2491 | If the software your recipe is building uses Autotools |
| 2492 | or CMake, the OpenEmbedded build |
| 2493 | system understands how to install the software. |
| 2494 | Consequently, you do not have to have a |
| 2495 | <filename>do_install</filename> task as part of your |
| 2496 | recipe. |
| 2497 | You just need to make sure the install portion of the |
| 2498 | build completes with no issues. |
| 2499 | However, if you wish to install additional files not |
| 2500 | already being installed by |
| 2501 | <filename>make install</filename>, you should do this |
| 2502 | using a <filename>do_install_append</filename> function |
| 2503 | using the install command as described in |
| 2504 | the "Manual" bulleted item later in this list. |
| 2505 | </para></listitem> |
| 2506 | <listitem><para><emphasis>Other (using |
| 2507 | <filename>make install</filename>):</emphasis> |
| 2508 | You need to define a |
| 2509 | <filename>do_install</filename> function in your |
| 2510 | recipe. |
| 2511 | The function should call |
| 2512 | <filename>oe_runmake install</filename> and will likely |
| 2513 | need to pass in the destination directory as well. |
| 2514 | How you pass that path is dependent on how the |
| 2515 | <filename>Makefile</filename> being run is written |
| 2516 | (e.g. <filename>DESTDIR=${D}</filename>, |
| 2517 | <filename>PREFIX=${D}</filename>, |
| 2518 | <filename>INSTALLROOT=${D}</filename>, and so forth). |
| 2519 | </para> |
| 2520 | <para>For an example recipe using |
| 2521 | <filename>make install</filename>, see the |
| 2522 | "<link linkend='new-recipe-makefile-based-package'>Makefile-Based Package</link>" |
| 2523 | section.</para></listitem> |
| 2524 | <listitem><para><emphasis>Manual:</emphasis> |
| 2525 | You need to define a |
| 2526 | <filename>do_install</filename> function in your |
| 2527 | recipe. |
| 2528 | The function must first use |
| 2529 | <filename>install -d</filename> to create the |
| 2530 | directories under |
| 2531 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink><filename>}</filename>. |
| 2532 | Once the directories exist, your function can use |
| 2533 | <filename>install</filename> to manually install the |
| 2534 | built software into the directories.</para> |
| 2535 | <para>You can find more information on |
| 2536 | <filename>install</filename> at |
| 2537 | <ulink url='http://www.gnu.org/software/coreutils/manual/html_node/install-invocation.html'></ulink>. |
| 2538 | </para></listitem> |
| 2539 | </itemizedlist> |
| 2540 | </para> |
| 2541 | |
| 2542 | <para> |
| 2543 | For the scenarios that do not use Autotools or |
| 2544 | CMake, you need to track the installation |
| 2545 | and diagnose and fix any issues until everything installs |
| 2546 | correctly. |
| 2547 | You need to look in the default location of |
| 2548 | <filename>${D}</filename>, which is |
| 2549 | <filename>${WORKDIR}/image</filename>, to be sure your |
| 2550 | files have been installed correctly. |
| 2551 | </para> |
| 2552 | |
| 2553 | <note><title>Notes</title> |
| 2554 | <itemizedlist> |
| 2555 | <listitem><para> |
| 2556 | During the installation process, you might need to |
| 2557 | modify some of the installed files to suit the target |
| 2558 | layout. |
| 2559 | For example, you might need to replace hard-coded paths |
| 2560 | in an initscript with values of variables provided by |
| 2561 | the build system, such as replacing |
| 2562 | <filename>/usr/bin/</filename> with |
| 2563 | <filename>${bindir}</filename>. |
| 2564 | If you do perform such modifications during |
| 2565 | <filename>do_install</filename>, be sure to modify the |
| 2566 | destination file after copying rather than before |
| 2567 | copying. |
| 2568 | Modifying after copying ensures that the build system |
| 2569 | can re-execute <filename>do_install</filename> if |
| 2570 | needed. |
| 2571 | </para></listitem> |
| 2572 | <listitem><para> |
| 2573 | <filename>oe_runmake install</filename>, which can be |
| 2574 | run directly or can be run indirectly by the |
| 2575 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink> |
| 2576 | and |
| 2577 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-cmake'><filename>cmake</filename></ulink> |
| 2578 | classes, runs <filename>make install</filename> in |
| 2579 | parallel. |
| 2580 | Sometimes, a Makefile can have missing dependencies |
| 2581 | between targets that can result in race conditions. |
| 2582 | If you experience intermittent failures during |
| 2583 | <filename>do_install</filename>, you might be able to |
| 2584 | work around them by disabling parallel Makefile |
| 2585 | installs by adding the following to the recipe: |
| 2586 | <literallayout class='monospaced'> |
| 2587 | PARALLEL_MAKEINST = "" |
| 2588 | </literallayout> |
| 2589 | See |
| 2590 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKEINST'><filename>PARALLEL_MAKEINST</filename></ulink> |
| 2591 | for additional information. |
| 2592 | </para></listitem> |
| 2593 | </itemizedlist> |
| 2594 | </note> |
| 2595 | </section> |
| 2596 | |
| 2597 | <section id='new-recipe-enabling-system-services'> |
| 2598 | <title>Enabling System Services</title> |
| 2599 | |
| 2600 | <para> |
| 2601 | If you want to install a service, which is a process that |
| 2602 | usually starts on boot and runs in the background, then |
| 2603 | you must include some additional definitions in your recipe. |
| 2604 | </para> |
| 2605 | |
| 2606 | <para> |
| 2607 | If you are adding services and the service initialization |
| 2608 | script or the service file itself is not installed, you must |
| 2609 | provide for that installation in your recipe using a |
| 2610 | <filename>do_install_append</filename> function. |
| 2611 | If your recipe already has a <filename>do_install</filename> |
| 2612 | function, update the function near its end rather than |
| 2613 | adding an additional <filename>do_install_append</filename> |
| 2614 | function. |
| 2615 | </para> |
| 2616 | |
| 2617 | <para> |
| 2618 | When you create the installation for your services, you need |
| 2619 | to accomplish what is normally done by |
| 2620 | <filename>make install</filename>. |
| 2621 | In other words, make sure your installation arranges the output |
| 2622 | similar to how it is arranged on the target system. |
| 2623 | </para> |
| 2624 | |
| 2625 | <para> |
| 2626 | The OpenEmbedded build system provides support for starting |
| 2627 | services two different ways: |
| 2628 | <itemizedlist> |
| 2629 | <listitem><para><emphasis>SysVinit:</emphasis> |
| 2630 | SysVinit is a system and service manager that |
| 2631 | manages the init system used to control the very basic |
| 2632 | functions of your system. |
| 2633 | The init program is the first program |
| 2634 | started by the Linux kernel when the system boots. |
| 2635 | Init then controls the startup, running and shutdown |
| 2636 | of all other programs.</para> |
| 2637 | <para>To enable a service using SysVinit, your recipe |
| 2638 | needs to inherit the |
| 2639 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-update-rc.d'><filename>update-rc.d</filename></ulink> |
| 2640 | class. |
| 2641 | The class helps facilitate safely installing the |
| 2642 | package on the target.</para> |
| 2643 | <para>You will need to set the |
| 2644 | <ulink url='&YOCTO_DOCS_REF_URL;#var-INITSCRIPT_PACKAGES'><filename>INITSCRIPT_PACKAGES</filename></ulink>, |
| 2645 | <ulink url='&YOCTO_DOCS_REF_URL;#var-INITSCRIPT_NAME'><filename>INITSCRIPT_NAME</filename></ulink>, |
| 2646 | and |
| 2647 | <ulink url='&YOCTO_DOCS_REF_URL;#var-INITSCRIPT_PARAMS'><filename>INITSCRIPT_PARAMS</filename></ulink> |
| 2648 | variables within your recipe.</para></listitem> |
| 2649 | <listitem><para><emphasis>systemd:</emphasis> |
| 2650 | System Management Daemon (systemd) was designed to |
| 2651 | replace SysVinit and to provide |
| 2652 | enhanced management of services. |
| 2653 | For more information on systemd, see the systemd |
| 2654 | homepage at |
| 2655 | <ulink url='http://freedesktop.org/wiki/Software/systemd/'></ulink>. |
| 2656 | </para> |
| 2657 | <para>To enable a service using systemd, your recipe |
| 2658 | needs to inherit the |
| 2659 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-systemd'><filename>systemd</filename></ulink> |
| 2660 | class. |
| 2661 | See the <filename>systemd.bbclass</filename> file |
| 2662 | located in your |
| 2663 | <link linkend='source-directory'>Source Directory</link>. |
| 2664 | section for more information. |
| 2665 | </para></listitem> |
| 2666 | </itemizedlist> |
| 2667 | </para> |
| 2668 | </section> |
| 2669 | |
| 2670 | <section id='new-recipe-packaging'> |
| 2671 | <title>Packaging</title> |
| 2672 | |
| 2673 | <para> |
| 2674 | Successful packaging is a combination of automated processes |
| 2675 | performed by the OpenEmbedded build system and some |
| 2676 | specific steps you need to take. |
| 2677 | The following list describes the process: |
| 2678 | <itemizedlist> |
| 2679 | <listitem><para><emphasis>Splitting Files</emphasis>: |
| 2680 | The <filename>do_package</filename> task splits the |
| 2681 | files produced by the recipe into logical components. |
| 2682 | Even software that produces a single binary might |
| 2683 | still have debug symbols, documentation, and other |
| 2684 | logical components that should be split out. |
| 2685 | The <filename>do_package</filename> task ensures |
| 2686 | that files are split up and packaged correctly. |
| 2687 | </para></listitem> |
| 2688 | <listitem><para><emphasis>Running QA Checks</emphasis>: |
| 2689 | The |
| 2690 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-insane'><filename>insane</filename></ulink> |
| 2691 | class adds a step to |
| 2692 | the package generation process so that output quality |
| 2693 | assurance checks are generated by the OpenEmbedded |
| 2694 | build system. |
| 2695 | This step performs a range of checks to be sure the |
| 2696 | build's output is free of common problems that show |
| 2697 | up during runtime. |
| 2698 | For information on these checks, see the |
| 2699 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-insane'><filename>insane</filename></ulink> |
| 2700 | class and the |
| 2701 | "<ulink url='&YOCTO_DOCS_REF_URL;#ref-qa-checks'>QA Error and Warning Messages</ulink>" |
| 2702 | chapter in the Yocto Project Reference Manual. |
| 2703 | </para></listitem> |
| 2704 | <listitem><para><emphasis>Hand-Checking Your Packages</emphasis>: |
| 2705 | After you build your software, you need to be sure |
| 2706 | your packages are correct. |
| 2707 | Examine the |
| 2708 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/packages-split</filename> |
| 2709 | directory and make sure files are where you expect |
| 2710 | them to be. |
| 2711 | If you discover problems, you can set |
| 2712 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>, |
| 2713 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>, |
| 2714 | <filename>do_install(_append)</filename>, and so forth as |
| 2715 | needed. |
| 2716 | </para></listitem> |
| 2717 | <listitem><para><emphasis>Splitting an Application into Multiple Packages</emphasis>: |
| 2718 | If you need to split an application into several |
| 2719 | packages, see the |
| 2720 | "<link linkend='splitting-an-application-into-multiple-packages'>Splitting an Application into Multiple Packages</link>" |
| 2721 | section for an example. |
| 2722 | </para></listitem> |
| 2723 | <listitem><para><emphasis>Installing a Post-Installation Script</emphasis>: |
| 2724 | For an example showing how to install a |
| 2725 | post-installation script, see the |
| 2726 | "<link linkend='new-recipe-post-installation-scripts'>Post-Installation Scripts</link>" |
| 2727 | section. |
| 2728 | </para></listitem> |
| 2729 | <listitem><para><emphasis>Marking Package Architecture</emphasis>: |
| 2730 | Depending on what your recipe is building and how it |
| 2731 | is configured, it might be important to mark the |
| 2732 | packages produced as being specific to a particular |
| 2733 | machine, or to mark them as not being specific to |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 2734 | a particular machine or architecture at all.</para> |
| 2735 | <para>By default, packages apply to any machine with the |
| 2736 | same architecture as the target machine. |
| 2737 | When a recipe produces packages that are |
| 2738 | machine-specific (e.g. the |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2739 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink> |
| 2740 | value is passed into the configure script or a patch |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 2741 | is applied only for a particular machine), you should |
| 2742 | mark them as such by adding the following to the |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2743 | recipe: |
| 2744 | <literallayout class='monospaced'> |
| 2745 | PACKAGE_ARCH = "${MACHINE_ARCH}" |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 2746 | </literallayout></para> |
| 2747 | <para>On the other hand, if the recipe produces packages |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2748 | that do not contain anything specific to the target |
| 2749 | machine or architecture at all (e.g. recipes |
| 2750 | that simply package script files or configuration |
| 2751 | files), you should use the |
| 2752 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-allarch'><filename>allarch</filename></ulink> |
| 2753 | class to do this for you by adding this to your |
| 2754 | recipe: |
| 2755 | <literallayout class='monospaced'> |
| 2756 | inherit allarch |
| 2757 | </literallayout> |
| 2758 | Ensuring that the package architecture is correct is |
| 2759 | not critical while you are doing the first few builds |
| 2760 | of your recipe. |
| 2761 | However, it is important in order |
| 2762 | to ensure that your recipe rebuilds (or does not |
| 2763 | rebuild) appropriately in response to changes in |
| 2764 | configuration, and to ensure that you get the |
| 2765 | appropriate packages installed on the target machine, |
| 2766 | particularly if you run separate builds for more |
| 2767 | than one target machine. |
| 2768 | </para></listitem> |
| 2769 | </itemizedlist> |
| 2770 | </para> |
| 2771 | </section> |
| 2772 | |
| 2773 | <section id='properly-versioning-pre-release-recipes'> |
| 2774 | <title>Properly Versioning Pre-Release Recipes</title> |
| 2775 | |
| 2776 | <para> |
| 2777 | Sometimes the name of a recipe can lead to versioning |
| 2778 | problems when the recipe is upgraded to a final release. |
| 2779 | For example, consider the |
| 2780 | <filename>irssi_0.8.16-rc1.bb</filename> recipe file in |
| 2781 | the list of example recipes in the |
| 2782 | "<link linkend='new-recipe-storing-and-naming-the-recipe'>Storing and Naming the Recipe</link>" |
| 2783 | section. |
| 2784 | This recipe is at a release candidate stage (i.e. |
| 2785 | "rc1"). |
| 2786 | When the recipe is released, the recipe filename becomes |
| 2787 | <filename>irssi_0.8.16.bb</filename>. |
| 2788 | The version change from <filename>0.8.16-rc1</filename> |
| 2789 | to <filename>0.8.16</filename> is seen as a decrease by the |
| 2790 | build system and package managers, so the resulting packages |
| 2791 | will not correctly trigger an upgrade. |
| 2792 | </para> |
| 2793 | |
| 2794 | <para> |
| 2795 | In order to ensure the versions compare properly, the |
| 2796 | recommended convention is to set |
| 2797 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink> |
| 2798 | within the recipe to |
| 2799 | "<replaceable>previous_version</replaceable>+<replaceable>current_version</replaceable>". |
| 2800 | You can use an additional variable so that you can use the |
| 2801 | current version elsewhere. |
| 2802 | Here is an example: |
| 2803 | <literallayout class='monospaced'> |
| 2804 | REALPV = "0.8.16-rc1" |
| 2805 | PV = "0.8.15+${REALPV}" |
| 2806 | </literallayout> |
| 2807 | </para> |
| 2808 | </section> |
| 2809 | |
| 2810 | <section id='new-recipe-post-installation-scripts'> |
| 2811 | <title>Post-Installation Scripts</title> |
| 2812 | |
| 2813 | <para> |
| 2814 | Post-installation scripts run immediately after installing |
| 2815 | a package on the target or during image creation when a |
| 2816 | package is included in an image. |
| 2817 | To add a post-installation script to a package, add a |
| 2818 | <filename>pkg_postinst_PACKAGENAME()</filename> function to |
| 2819 | the recipe file (<filename>.bb</filename>) and replace |
| 2820 | <filename>PACKAGENAME</filename> with the name of the package |
| 2821 | you want to attach to the <filename>postinst</filename> |
| 2822 | script. |
| 2823 | To apply the post-installation script to the main package |
| 2824 | for the recipe, which is usually what is required, specify |
| 2825 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename> |
| 2826 | in place of <filename>PACKAGENAME</filename>. |
| 2827 | </para> |
| 2828 | |
| 2829 | <para> |
| 2830 | A post-installation function has the following structure: |
| 2831 | <literallayout class='monospaced'> |
| 2832 | pkg_postinst_PACKAGENAME() { |
| 2833 | # Commands to carry out |
| 2834 | } |
| 2835 | </literallayout> |
| 2836 | </para> |
| 2837 | |
| 2838 | <para> |
| 2839 | The script defined in the post-installation function is |
| 2840 | called when the root filesystem is created. |
| 2841 | If the script succeeds, the package is marked as installed. |
| 2842 | If the script fails, the package is marked as unpacked and |
| 2843 | the script is executed when the image boots again. |
| 2844 | </para> |
| 2845 | |
| 2846 | <para> |
| 2847 | Sometimes it is necessary for the execution of a |
| 2848 | post-installation script to be delayed until the first boot. |
| 2849 | For example, the script might need to be executed on the |
| 2850 | device itself. |
| 2851 | To delay script execution until boot time, use the following |
| 2852 | structure in the post-installation script: |
| 2853 | <literallayout class='monospaced'> |
| 2854 | pkg_postinst_PACKAGENAME() { |
| 2855 | if [ x"$D" = "x" ]; then |
| 2856 | # Actions to carry out on the device go here |
| 2857 | else |
| 2858 | exit 1 |
| 2859 | fi |
| 2860 | } |
| 2861 | </literallayout> |
| 2862 | </para> |
| 2863 | |
| 2864 | <para> |
| 2865 | The previous example delays execution until the image boots |
| 2866 | again because the environment variable <filename>D</filename> |
| 2867 | points to the directory containing the image when |
| 2868 | the root filesystem is created at build time but is unset |
| 2869 | when executed on the first boot. |
| 2870 | </para> |
| 2871 | |
| 2872 | <note> |
| 2873 | Equivalent support for pre-install, pre-uninstall, and |
| 2874 | post-uninstall scripts exist by way of |
| 2875 | <filename>pkg_preinst</filename>, |
| 2876 | <filename>pkg_prerm</filename>, and |
| 2877 | <filename>pkg_postrm</filename>, respectively. |
| 2878 | These scrips work in exactly the same way as does |
| 2879 | <filename>pkg_postinst</filename> with the exception that they |
| 2880 | run at different times. |
| 2881 | Also, because of when they run, they are not applicable to |
| 2882 | being run at image creation time like |
| 2883 | <filename>pkg_postinst</filename>. |
| 2884 | </note> |
| 2885 | </section> |
| 2886 | |
| 2887 | <section id='new-recipe-testing'> |
| 2888 | <title>Testing</title> |
| 2889 | |
| 2890 | <para> |
| 2891 | The final step for completing your recipe is to be sure that |
| 2892 | the software you built runs correctly. |
| 2893 | To accomplish runtime testing, add the build's output |
| 2894 | packages to your image and test them on the target. |
| 2895 | </para> |
| 2896 | |
| 2897 | <para> |
| 2898 | For information on how to customize your image by adding |
| 2899 | specific packages, see the |
| 2900 | "<link linkend='usingpoky-extend-customimage'>Customizing Images</link>" |
| 2901 | section. |
| 2902 | </para> |
| 2903 | </section> |
| 2904 | |
| 2905 | <section id='new-recipe-testing-examples'> |
| 2906 | <title>Examples</title> |
| 2907 | |
| 2908 | <para> |
| 2909 | To help summarize how to write a recipe, this section provides |
| 2910 | some examples given various scenarios: |
| 2911 | <itemizedlist> |
| 2912 | <listitem><para>Recipes that use local files</para></listitem> |
| 2913 | <listitem><para>Using an Autotooled package</para></listitem> |
| 2914 | <listitem><para>Using a Makefile-based package</para></listitem> |
| 2915 | <listitem><para>Splitting an application into multiple packages</para></listitem> |
| 2916 | <listitem><para>Adding binaries to an image</para></listitem> |
| 2917 | </itemizedlist> |
| 2918 | </para> |
| 2919 | |
| 2920 | <section id='new-recipe-single-c-file-package-hello-world'> |
| 2921 | <title>Single .c File Package (Hello World!)</title> |
| 2922 | |
| 2923 | <para> |
| 2924 | Building an application from a single file that is stored |
| 2925 | locally (e.g. under <filename>files</filename>) requires |
| 2926 | a recipe that has the file listed in the |
| 2927 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename> |
| 2928 | variable. |
| 2929 | Additionally, you need to manually write the |
| 2930 | <filename>do_compile</filename> and |
| 2931 | <filename>do_install</filename> tasks. |
| 2932 | The <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'>S</ulink></filename> |
| 2933 | variable defines the directory containing the source code, |
| 2934 | which is set to |
| 2935 | <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink> |
| 2936 | in this case - the directory BitBake uses for the build. |
| 2937 | <literallayout class='monospaced'> |
| 2938 | SUMMARY = "Simple helloworld application" |
| 2939 | SECTION = "examples" |
| 2940 | LICENSE = "MIT" |
| 2941 | LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" |
| 2942 | |
| 2943 | SRC_URI = "file://helloworld.c" |
| 2944 | |
| 2945 | S = "${WORKDIR}" |
| 2946 | |
| 2947 | do_compile() { |
| 2948 | ${CC} helloworld.c -o helloworld |
| 2949 | } |
| 2950 | |
| 2951 | do_install() { |
| 2952 | install -d ${D}${bindir} |
| 2953 | install -m 0755 helloworld ${D}${bindir} |
| 2954 | } |
| 2955 | </literallayout> |
| 2956 | </para> |
| 2957 | |
| 2958 | <para> |
| 2959 | By default, the <filename>helloworld</filename>, |
| 2960 | <filename>helloworld-dbg</filename>, and |
| 2961 | <filename>helloworld-dev</filename> packages are built. |
| 2962 | For information on how to customize the packaging process, |
| 2963 | see the |
| 2964 | "<link linkend='splitting-an-application-into-multiple-packages'>Splitting an Application into Multiple Packages</link>" |
| 2965 | section. |
| 2966 | </para> |
| 2967 | </section> |
| 2968 | |
| 2969 | <section id='new-recipe-autotooled-package'> |
| 2970 | <title>Autotooled Package</title> |
| 2971 | <para> |
| 2972 | Applications that use Autotools such as <filename>autoconf</filename> and |
| 2973 | <filename>automake</filename> require a recipe that has a source archive listed in |
| 2974 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename> and |
| 2975 | also inherit the |
| 2976 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink> |
| 2977 | class, which contains the definitions of all the steps |
| 2978 | needed to build an Autotool-based application. |
| 2979 | The result of the build is automatically packaged. |
| 2980 | And, if the application uses NLS for localization, packages with local information are |
| 2981 | generated (one package per language). |
| 2982 | Following is one example: (<filename>hello_2.3.bb</filename>) |
| 2983 | <literallayout class='monospaced'> |
| 2984 | SUMMARY = "GNU Helloworld application" |
| 2985 | SECTION = "examples" |
| 2986 | LICENSE = "GPLv2+" |
| 2987 | LIC_FILES_CHKSUM = "file://COPYING;md5=751419260aa954499f7abaabaa882bbe" |
| 2988 | |
| 2989 | SRC_URI = "${GNU_MIRROR}/hello/hello-${PV}.tar.gz" |
| 2990 | |
| 2991 | inherit autotools gettext |
| 2992 | </literallayout> |
| 2993 | </para> |
| 2994 | |
| 2995 | <para> |
| 2996 | The variable |
| 2997 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'>LIC_FILES_CHKSUM</ulink></filename> |
| 2998 | is used to track source license changes as described in the |
| 2999 | "<ulink url='&YOCTO_DOCS_REF_URL;#usingpoky-configuring-LIC_FILES_CHKSUM'>Tracking License Changes</ulink>" section. |
| 3000 | You can quickly create Autotool-based recipes in a manner similar to the previous example. |
| 3001 | </para> |
| 3002 | </section> |
| 3003 | |
| 3004 | <section id='new-recipe-makefile-based-package'> |
| 3005 | <title>Makefile-Based Package</title> |
| 3006 | |
| 3007 | <para> |
| 3008 | Applications that use GNU <filename>make</filename> also require a recipe that has |
| 3009 | the source archive listed in |
| 3010 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>. |
| 3011 | You do not need to add a <filename>do_compile</filename> step since by default BitBake |
| 3012 | starts the <filename>make</filename> command to compile the application. |
| 3013 | If you need additional <filename>make</filename> options, you should store them in the |
| 3014 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OEMAKE'>EXTRA_OEMAKE</ulink></filename> |
| 3015 | variable. |
| 3016 | BitBake passes these options into the GNU <filename>make</filename> invocation. |
| 3017 | Note that a <filename>do_install</filename> task is still required. |
| 3018 | Otherwise, BitBake runs an empty <filename>do_install</filename> task by default. |
| 3019 | </para> |
| 3020 | |
| 3021 | <para> |
| 3022 | Some applications might require extra parameters to be passed to the compiler. |
| 3023 | For example, the application might need an additional header path. |
| 3024 | You can accomplish this by adding to the |
| 3025 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-CFLAGS'>CFLAGS</ulink></filename> variable. |
| 3026 | The following example shows this: |
| 3027 | <literallayout class='monospaced'> |
| 3028 | CFLAGS_prepend = "-I ${S}/include " |
| 3029 | </literallayout> |
| 3030 | </para> |
| 3031 | |
| 3032 | <para> |
| 3033 | In the following example, <filename>mtd-utils</filename> is a makefile-based package: |
| 3034 | <literallayout class='monospaced'> |
| 3035 | SUMMARY = "Tools for managing memory technology devices" |
| 3036 | SECTION = "base" |
| 3037 | DEPENDS = "zlib lzo e2fsprogs util-linux" |
| 3038 | HOMEPAGE = "http://www.linux-mtd.infradead.org/" |
| 3039 | LICENSE = "GPLv2+" |
| 3040 | LIC_FILES_CHKSUM = "file://COPYING;md5=0636e73ff0215e8d672dc4c32c317bb3 \ |
| 3041 | file://include/common.h;beginline=1;endline=17;md5=ba05b07912a44ea2bf81ce409380049c" |
| 3042 | |
| 3043 | # Use the latest version at 26 Oct, 2013 |
| 3044 | SRCREV = "9f107132a6a073cce37434ca9cda6917dd8d866b" |
| 3045 | SRC_URI = "git://git.infradead.org/mtd-utils.git \ |
| 3046 | file://add-exclusion-to-mkfs-jffs2-git-2.patch \ |
| 3047 | " |
| 3048 | |
| 3049 | PV = "1.5.1+git${SRCPV}" |
| 3050 | |
| 3051 | S = "${WORKDIR}/git/" |
| 3052 | |
| 3053 | EXTRA_OEMAKE = "'CC=${CC}' 'RANLIB=${RANLIB}' 'AR=${AR}' 'CFLAGS=${CFLAGS} -I${S}/include -DWITHOUT_XATTR' 'BUILDDIR=${S}'" |
| 3054 | |
| 3055 | do_install () { |
| 3056 | oe_runmake install DESTDIR=${D} SBINDIR=${sbindir} MANDIR=${mandir} INCLUDEDIR=${includedir} |
| 3057 | } |
| 3058 | |
| 3059 | PACKAGES =+ "mtd-utils-jffs2 mtd-utils-ubifs mtd-utils-misc" |
| 3060 | |
| 3061 | FILES_mtd-utils-jffs2 = "${sbindir}/mkfs.jffs2 ${sbindir}/jffs2dump ${sbindir}/jffs2reader ${sbindir}/sumtool" |
| 3062 | FILES_mtd-utils-ubifs = "${sbindir}/mkfs.ubifs ${sbindir}/ubi*" |
| 3063 | FILES_mtd-utils-misc = "${sbindir}/nftl* ${sbindir}/ftl* ${sbindir}/rfd* ${sbindir}/doc* ${sbindir}/serve_image ${sbindir}/recv_image" |
| 3064 | |
| 3065 | PARALLEL_MAKE = "" |
| 3066 | |
| 3067 | BBCLASSEXTEND = "native" |
| 3068 | </literallayout> |
| 3069 | </para> |
| 3070 | </section> |
| 3071 | |
| 3072 | <section id='splitting-an-application-into-multiple-packages'> |
| 3073 | <title>Splitting an Application into Multiple Packages</title> |
| 3074 | |
| 3075 | <para> |
| 3076 | You can use the variables |
| 3077 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'>PACKAGES</ulink></filename> and |
| 3078 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'>FILES</ulink></filename> |
| 3079 | to split an application into multiple packages. |
| 3080 | </para> |
| 3081 | |
| 3082 | <para> |
| 3083 | Following is an example that uses the <filename>libxpm</filename> recipe. |
| 3084 | By default, this recipe generates a single package that contains the library along |
| 3085 | with a few binaries. |
| 3086 | You can modify the recipe to split the binaries into separate packages: |
| 3087 | <literallayout class='monospaced'> |
| 3088 | require xorg-lib-common.inc |
| 3089 | |
| 3090 | SUMMARY = "Xpm: X Pixmap extension library" |
| 3091 | LICENSE = "BSD" |
| 3092 | LIC_FILES_CHKSUM = "file://COPYING;md5=51f4270b012ecd4ab1a164f5f4ed6cf7" |
| 3093 | DEPENDS += "libxext libsm libxt" |
| 3094 | PE = "1" |
| 3095 | |
| 3096 | XORG_PN = "libXpm" |
| 3097 | |
| 3098 | PACKAGES =+ "sxpm cxpm" |
| 3099 | FILES_cxpm = "${bindir}/cxpm" |
| 3100 | FILES_sxpm = "${bindir}/sxpm" |
| 3101 | </literallayout> |
| 3102 | </para> |
| 3103 | |
| 3104 | <para> |
| 3105 | In the previous example, we want to ship the <filename>sxpm</filename> |
| 3106 | and <filename>cxpm</filename> binaries in separate packages. |
| 3107 | Since <filename>bindir</filename> would be packaged into the main |
| 3108 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'>PN</ulink></filename> |
| 3109 | package by default, we prepend the <filename>PACKAGES</filename> |
| 3110 | variable so additional package names are added to the start of list. |
| 3111 | This results in the extra <filename>FILES_*</filename> |
| 3112 | variables then containing information that define which files and |
| 3113 | directories go into which packages. |
| 3114 | Files included by earlier packages are skipped by latter packages. |
| 3115 | Thus, the main <filename>PN</filename> package |
| 3116 | does not include the above listed files. |
| 3117 | </para> |
| 3118 | </section> |
| 3119 | |
| 3120 | <section id='packaging-externally-produced-binaries'> |
| 3121 | <title>Packaging Externally Produced Binaries</title> |
| 3122 | |
| 3123 | <para> |
| 3124 | Sometimes, you need to add pre-compiled binaries to an |
| 3125 | image. |
| 3126 | For example, suppose that binaries for proprietary code |
| 3127 | exist, which are created by a particular division of a |
| 3128 | company. |
| 3129 | Your part of the company needs to use those binaries as |
| 3130 | part of an image that you are building using the |
| 3131 | OpenEmbedded build system. |
| 3132 | Since you only have the binaries and not the source code, |
| 3133 | you cannot use a typical recipe that expects to fetch the |
| 3134 | source specified in |
| 3135 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> |
| 3136 | and then compile it. |
| 3137 | </para> |
| 3138 | |
| 3139 | <para> |
| 3140 | One method is to package the binaries and then install them |
| 3141 | as part of the image. |
| 3142 | Generally, it is not a good idea to package binaries |
| 3143 | since, among other things, it can hinder the ability to |
| 3144 | reproduce builds and could lead to compatibility problems |
| 3145 | with ABI in the future. |
| 3146 | However, sometimes you have no choice. |
| 3147 | </para> |
| 3148 | |
| 3149 | <para> |
| 3150 | The easiest solution is to create a recipe that uses |
| 3151 | the |
| 3152 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-bin-package'><filename>bin_package</filename></ulink> |
| 3153 | class and to be sure that you are using default locations |
| 3154 | for build artifacts. |
| 3155 | In most cases, the <filename>bin_package</filename> class |
| 3156 | handles "skipping" the configure and compile steps as well |
| 3157 | as sets things up to grab packages from the appropriate |
| 3158 | area. |
| 3159 | In particular, this class sets <filename>noexec</filename> |
| 3160 | on both the |
| 3161 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink> |
| 3162 | and |
| 3163 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink> |
| 3164 | tasks, sets |
| 3165 | <filename>FILES_${PN}</filename> to "/" so that it picks |
| 3166 | up all files, and sets up a |
| 3167 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink> |
| 3168 | task, which effectively copies all files from |
| 3169 | <filename>${S}</filename> to <filename>${D}</filename>. |
| 3170 | The <filename>bin_package</filename> class works well when |
| 3171 | the files extracted into <filename>${S}</filename> are |
| 3172 | already laid out in the way they should be laid out |
| 3173 | on the target. |
| 3174 | For more information on these variables, see the |
| 3175 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>, |
| 3176 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>, |
| 3177 | <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>, |
| 3178 | and |
| 3179 | <ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink> |
| 3180 | variables in the Yocto Project Reference Manual's variable |
| 3181 | glossary. |
| 3182 | </para> |
| 3183 | |
| 3184 | <para> |
| 3185 | If you can't use the <filename>bin_package</filename> |
| 3186 | class, you need to be sure you are doing the following: |
| 3187 | <itemizedlist> |
| 3188 | <listitem><para>Create a recipe where the |
| 3189 | <filename>do_configure</filename> and |
| 3190 | <filename>do_compile</filename> tasks do nothing: |
| 3191 | <literallayout class='monospaced'> |
| 3192 | do_configure[noexec] = "1" |
| 3193 | do_compile[noexec] = "1" |
| 3194 | </literallayout> |
| 3195 | Alternatively, you can make these tasks an empty |
| 3196 | function. |
| 3197 | </para></listitem> |
| 3198 | <listitem><para>Make sure your |
| 3199 | <filename>do_install</filename> task installs the |
| 3200 | binaries appropriately. |
| 3201 | </para></listitem> |
| 3202 | <listitem><para>Ensure that you set up |
| 3203 | <filename>FILES</filename> (usually |
| 3204 | <filename>FILES_${PN}</filename>) to point to the |
| 3205 | files you have installed, which of course depends |
| 3206 | on where you have installed them and whether |
| 3207 | those files are in different locations than the |
| 3208 | defaults. |
| 3209 | </para></listitem> |
| 3210 | </itemizedlist> |
| 3211 | </para> |
| 3212 | </section> |
| 3213 | </section> |
| 3214 | </section> |
| 3215 | |
| 3216 | <section id="platdev-newmachine"> |
| 3217 | <title>Adding a New Machine</title> |
| 3218 | |
| 3219 | <para> |
| 3220 | Adding a new machine to the Yocto Project is a straightforward |
| 3221 | process. |
| 3222 | This section describes how to add machines that are similar |
| 3223 | to those that the Yocto Project already supports. |
| 3224 | <note> |
| 3225 | Although well within the capabilities of the Yocto Project, |
| 3226 | adding a totally new architecture might require |
| 3227 | changes to <filename>gcc/glibc</filename> and to the site |
| 3228 | information, which is beyond the scope of this manual. |
| 3229 | </note> |
| 3230 | </para> |
| 3231 | |
| 3232 | <para> |
| 3233 | For a complete example that shows how to add a new machine, |
| 3234 | see the |
| 3235 | "<ulink url='&YOCTO_DOCS_BSP_URL;#creating-a-new-bsp-layer-using-the-yocto-bsp-script'>Creating a New BSP Layer Using the yocto-bsp Script</ulink>" |
| 3236 | section in the Yocto Project Board Support Package (BSP) Developer's Guide. |
| 3237 | </para> |
| 3238 | |
| 3239 | <section id="platdev-newmachine-conffile"> |
| 3240 | <title>Adding the Machine Configuration File</title> |
| 3241 | |
| 3242 | <para> |
| 3243 | To add a new machine, you need to add a new machine |
| 3244 | configuration file to the layer's |
| 3245 | <filename>conf/machine</filename> directory. |
| 3246 | This configuration file provides details about the device |
| 3247 | you are adding. |
| 3248 | </para> |
| 3249 | |
| 3250 | <para> |
| 3251 | The OpenEmbedded build system uses the root name of the |
| 3252 | machine configuration file to reference the new machine. |
| 3253 | For example, given a machine configuration file named |
| 3254 | <filename>crownbay.conf</filename>, the build system |
| 3255 | recognizes the machine as "crownbay". |
| 3256 | </para> |
| 3257 | |
| 3258 | <para> |
| 3259 | The most important variables you must set in your machine |
| 3260 | configuration file or include from a lower-level configuration |
| 3261 | file are as follows: |
| 3262 | <itemizedlist> |
| 3263 | <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TARGET_ARCH'>TARGET_ARCH</ulink></filename> |
| 3264 | (e.g. "arm")</para></listitem> |
| 3265 | <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PREFERRED_PROVIDER'>PREFERRED_PROVIDER</ulink>_virtual/kernel</filename> |
| 3266 | </para></listitem> |
| 3267 | <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES'>MACHINE_FEATURES</ulink></filename> |
| 3268 | (e.g. "apm screen wifi")</para></listitem> |
| 3269 | </itemizedlist> |
| 3270 | </para> |
| 3271 | |
| 3272 | <para> |
| 3273 | You might also need these variables: |
| 3274 | <itemizedlist> |
| 3275 | <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SERIAL_CONSOLES'>SERIAL_CONSOLES</ulink></filename> |
| 3276 | (e.g. "115200;ttyS0 115200;ttyS1")</para></listitem> |
| 3277 | <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_IMAGETYPE'>KERNEL_IMAGETYPE</ulink></filename> |
| 3278 | (e.g. "zImage")</para></listitem> |
| 3279 | <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FSTYPES'>IMAGE_FSTYPES</ulink></filename> |
| 3280 | (e.g. "tar.gz jffs2")</para></listitem> |
| 3281 | </itemizedlist> |
| 3282 | </para> |
| 3283 | |
| 3284 | <para> |
| 3285 | You can find full details on these variables in the reference |
| 3286 | section. |
| 3287 | You can leverage existing machine <filename>.conf</filename> |
| 3288 | files from <filename>meta-yocto-bsp/conf/machine/</filename>. |
| 3289 | </para> |
| 3290 | </section> |
| 3291 | |
| 3292 | <section id="platdev-newmachine-kernel"> |
| 3293 | <title>Adding a Kernel for the Machine</title> |
| 3294 | |
| 3295 | <para> |
| 3296 | The OpenEmbedded build system needs to be able to build a kernel |
| 3297 | for the machine. |
| 3298 | You need to either create a new kernel recipe for this machine, |
| 3299 | or extend an existing kernel recipe. |
| 3300 | You can find several kernel recipe examples in the |
| 3301 | Source Directory at |
| 3302 | <filename>meta/recipes-kernel/linux</filename> |
| 3303 | that you can use as references. |
| 3304 | </para> |
| 3305 | |
| 3306 | <para> |
| 3307 | If you are creating a new kernel recipe, normal recipe-writing |
| 3308 | rules apply for setting up a |
| 3309 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>. |
| 3310 | Thus, you need to specify any necessary patches and set |
| 3311 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'>S</ulink></filename> |
| 3312 | to point at the source code. |
| 3313 | You need to create a <filename>do_configure</filename> task that |
| 3314 | configures the unpacked kernel with a |
| 3315 | <filename>defconfig</filename> file. |
| 3316 | You can do this by using a <filename>make defconfig</filename> |
| 3317 | command or, more commonly, by copying in a suitable |
| 3318 | <filename>defconfig</filename> file and then running |
| 3319 | <filename>make oldconfig</filename>. |
| 3320 | By making use of <filename>inherit kernel</filename> and |
| 3321 | potentially some of the <filename>linux-*.inc</filename> files, |
| 3322 | most other functionality is centralized and the defaults of the |
| 3323 | class normally work well. |
| 3324 | </para> |
| 3325 | |
| 3326 | <para> |
| 3327 | If you are extending an existing kernel recipe, it is usually |
| 3328 | a matter of adding a suitable <filename>defconfig</filename> |
| 3329 | file. |
| 3330 | The file needs to be added into a location similar to |
| 3331 | <filename>defconfig</filename> files used for other machines |
| 3332 | in a given kernel recipe. |
| 3333 | A possible way to do this is by listing the file in the |
| 3334 | <filename>SRC_URI</filename> and adding the machine to the |
| 3335 | expression in |
| 3336 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-COMPATIBLE_MACHINE'>COMPATIBLE_MACHINE</ulink></filename>: |
| 3337 | <literallayout class='monospaced'> |
| 3338 | COMPATIBLE_MACHINE = '(qemux86|qemumips)' |
| 3339 | </literallayout> |
| 3340 | For more information on <filename>defconfig</filename> files, |
| 3341 | see the |
| 3342 | "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#changing-the-configuration'>Changing the Configuration</ulink>" |
| 3343 | section in the Yocto Project Linux Kernel Development Manual. |
| 3344 | </para> |
| 3345 | </section> |
| 3346 | |
| 3347 | <section id="platdev-newmachine-formfactor"> |
| 3348 | <title>Adding a Formfactor Configuration File</title> |
| 3349 | |
| 3350 | <para> |
| 3351 | A formfactor configuration file provides information about the |
| 3352 | target hardware for which the image is being built and information that |
| 3353 | the build system cannot obtain from other sources such as the kernel. |
| 3354 | Some examples of information contained in a formfactor configuration file include |
| 3355 | framebuffer orientation, whether or not the system has a keyboard, |
| 3356 | the positioning of the keyboard in relation to the screen, and |
| 3357 | the screen resolution. |
| 3358 | </para> |
| 3359 | |
| 3360 | <para> |
| 3361 | The build system uses reasonable defaults in most cases. |
| 3362 | However, if customization is |
| 3363 | necessary, you need to create a <filename>machconfig</filename> file |
| 3364 | in the <filename>meta/recipes-bsp/formfactor/files</filename> |
| 3365 | directory. |
| 3366 | This directory contains directories for specific machines such as |
| 3367 | <filename>qemuarm</filename> and <filename>qemux86</filename>. |
| 3368 | For information about the settings available and the defaults, see the |
| 3369 | <filename>meta/recipes-bsp/formfactor/files/config</filename> file found in the |
| 3370 | same area. |
| 3371 | </para> |
| 3372 | |
| 3373 | <para> |
| 3374 | Following is an example for "qemuarm" machine: |
| 3375 | <literallayout class='monospaced'> |
| 3376 | HAVE_TOUCHSCREEN=1 |
| 3377 | HAVE_KEYBOARD=1 |
| 3378 | |
| 3379 | DISPLAY_CAN_ROTATE=0 |
| 3380 | DISPLAY_ORIENTATION=0 |
| 3381 | #DISPLAY_WIDTH_PIXELS=640 |
| 3382 | #DISPLAY_HEIGHT_PIXELS=480 |
| 3383 | #DISPLAY_BPP=16 |
| 3384 | DISPLAY_DPI=150 |
| 3385 | DISPLAY_SUBPIXEL_ORDER=vrgb |
| 3386 | </literallayout> |
| 3387 | </para> |
| 3388 | </section> |
| 3389 | </section> |
| 3390 | |
| 3391 | <section id="platdev-working-with-libraries"> |
| 3392 | <title>Working With Libraries</title> |
| 3393 | |
| 3394 | <para> |
| 3395 | Libraries are an integral part of your system. |
| 3396 | This section describes some common practices you might find |
| 3397 | helpful when working with libraries to build your system: |
| 3398 | <itemizedlist> |
| 3399 | <listitem><para><link linkend='including-static-library-files'>How to include static library files</link> |
| 3400 | </para></listitem> |
| 3401 | <listitem><para><link linkend='combining-multiple-versions-library-files-into-one-image'>How to use the Multilib feature to combine multiple versions of library files into a single image</link> |
| 3402 | </para></listitem> |
| 3403 | <listitem><para><link linkend='installing-multiple-versions-of-the-same-library'>How to install multiple versions of the same library in parallel on the same system</link> |
| 3404 | </para></listitem> |
| 3405 | </itemizedlist> |
| 3406 | </para> |
| 3407 | |
| 3408 | <section id='including-static-library-files'> |
| 3409 | <title>Including Static Library Files</title> |
| 3410 | |
| 3411 | <para> |
| 3412 | If you are building a library and the library offers static linking, you can control |
| 3413 | which static library files (<filename>*.a</filename> files) get included in the |
| 3414 | built library. |
| 3415 | </para> |
| 3416 | |
| 3417 | <para> |
| 3418 | The <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink> |
| 3419 | and <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES_*</filename></ulink> |
| 3420 | variables in the |
| 3421 | <filename>meta/conf/bitbake.conf</filename> configuration file define how files installed |
| 3422 | by the <filename>do_install</filename> task are packaged. |
| 3423 | By default, the <filename>PACKAGES</filename> variable includes |
| 3424 | <filename>${PN}-staticdev</filename>, which represents all static library files. |
| 3425 | <note> |
| 3426 | Some previously released versions of the Yocto Project |
| 3427 | defined the static library files through |
| 3428 | <filename>${PN}-dev</filename>. |
| 3429 | </note> |
| 3430 | Following is part of the BitBake configuration file, where |
| 3431 | you can see how the static library files are defined: |
| 3432 | <literallayout class='monospaced'> |
| 3433 | PACKAGE_BEFORE_PN ?= "" |
| 3434 | PACKAGES = "${PN}-dbg ${PN}-staticdev ${PN}-dev ${PN}-doc ${PN}-locale ${PACKAGE_BEFORE_PN} ${PN}" |
| 3435 | PACKAGES_DYNAMIC = "^${PN}-locale-.*" |
| 3436 | FILES = "" |
| 3437 | |
| 3438 | FILES_${PN} = "${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*${SOLIBS} \ |
| 3439 | ${sysconfdir} ${sharedstatedir} ${localstatedir} \ |
| 3440 | ${base_bindir}/* ${base_sbindir}/* \ |
| 3441 | ${base_libdir}/*${SOLIBS} \ |
| 3442 | ${base_prefix}/lib/udev/rules.d ${prefix}/lib/udev/rules.d \ |
| 3443 | ${datadir}/${BPN} ${libdir}/${BPN}/* \ |
| 3444 | ${datadir}/pixmaps ${datadir}/applications \ |
| 3445 | ${datadir}/idl ${datadir}/omf ${datadir}/sounds \ |
| 3446 | ${libdir}/bonobo/servers" |
| 3447 | |
| 3448 | FILES_${PN}-bin = "${bindir}/* ${sbindir}/*" |
| 3449 | |
| 3450 | FILES_${PN}-doc = "${docdir} ${mandir} ${infodir} ${datadir}/gtk-doc \ |
| 3451 | ${datadir}/gnome/help" |
| 3452 | SECTION_${PN}-doc = "doc" |
| 3453 | |
| 3454 | FILES_SOLIBSDEV ?= "${base_libdir}/lib*${SOLIBSDEV} ${libdir}/lib*${SOLIBSDEV}" |
| 3455 | FILES_${PN}-dev = "${includedir} ${FILES_SOLIBSDEV} ${libdir}/*.la \ |
| 3456 | ${libdir}/*.o ${libdir}/pkgconfig ${datadir}/pkgconfig \ |
| 3457 | ${datadir}/aclocal ${base_libdir}/*.o \ |
| 3458 | ${libdir}/${BPN}/*.la ${base_libdir}/*.la" |
| 3459 | SECTION_${PN}-dev = "devel" |
| 3460 | ALLOW_EMPTY_${PN}-dev = "1" |
| 3461 | RDEPENDS_${PN}-dev = "${PN} (= ${EXTENDPKGV})" |
| 3462 | |
| 3463 | FILES_${PN}-staticdev = "${libdir}/*.a ${base_libdir}/*.a ${libdir}/${BPN}/*.a" |
| 3464 | SECTION_${PN}-staticdev = "devel" |
| 3465 | RDEPENDS_${PN}-staticdev = "${PN}-dev (= ${EXTENDPKGV})" |
| 3466 | </literallayout> |
| 3467 | </para> |
| 3468 | </section> |
| 3469 | |
| 3470 | <section id="combining-multiple-versions-library-files-into-one-image"> |
| 3471 | <title>Combining Multiple Versions of Library Files into One Image</title> |
| 3472 | |
| 3473 | <para> |
| 3474 | The build system offers the ability to build libraries with different |
| 3475 | target optimizations or architecture formats and combine these together |
| 3476 | into one system image. |
| 3477 | You can link different binaries in the image |
| 3478 | against the different libraries as needed for specific use cases. |
| 3479 | This feature is called "Multilib." |
| 3480 | </para> |
| 3481 | |
| 3482 | <para> |
| 3483 | An example would be where you have most of a system compiled in 32-bit |
| 3484 | mode using 32-bit libraries, but you have something large, like a database |
| 3485 | engine, that needs to be a 64-bit application and uses 64-bit libraries. |
| 3486 | Multilib allows you to get the best of both 32-bit and 64-bit libraries. |
| 3487 | </para> |
| 3488 | |
| 3489 | <para> |
| 3490 | While the Multilib feature is most commonly used for 32 and 64-bit differences, |
| 3491 | the approach the build system uses facilitates different target optimizations. |
| 3492 | You could compile some binaries to use one set of libraries and other binaries |
| 3493 | to use a different set of libraries. |
| 3494 | The libraries could differ in architecture, compiler options, or other |
| 3495 | optimizations. |
| 3496 | </para> |
| 3497 | |
| 3498 | <para> |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 3499 | Several examples exist in the |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 3500 | <filename>meta-skeleton</filename> layer found in the |
| 3501 | <link linkend='source-directory'>Source Directory</link>: |
| 3502 | <itemizedlist> |
| 3503 | <listitem><para><filename>conf/multilib-example.conf</filename> |
| 3504 | configuration file</para></listitem> |
| 3505 | <listitem><para><filename>conf/multilib-example2.conf</filename> |
| 3506 | configuration file</para></listitem> |
| 3507 | <listitem><para><filename>recipes-multilib/images/core-image-multilib-example.bb</filename> |
| 3508 | recipe</para></listitem> |
| 3509 | </itemizedlist> |
| 3510 | </para> |
| 3511 | |
| 3512 | <section id='preparing-to-use-multilib'> |
| 3513 | <title>Preparing to Use Multilib</title> |
| 3514 | |
| 3515 | <para> |
| 3516 | User-specific requirements drive the Multilib feature. |
| 3517 | Consequently, there is no one "out-of-the-box" configuration that likely |
| 3518 | exists to meet your needs. |
| 3519 | </para> |
| 3520 | |
| 3521 | <para> |
| 3522 | In order to enable Multilib, you first need to ensure your recipe is |
| 3523 | extended to support multiple libraries. |
| 3524 | Many standard recipes are already extended and support multiple libraries. |
| 3525 | You can check in the <filename>meta/conf/multilib.conf</filename> |
| 3526 | configuration file in the |
| 3527 | <link linkend='source-directory'>Source Directory</link> to see how this is |
| 3528 | done using the |
| 3529 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BBCLASSEXTEND'><filename>BBCLASSEXTEND</filename></ulink> |
| 3530 | variable. |
| 3531 | Eventually, all recipes will be covered and this list will |
| 3532 | not be needed. |
| 3533 | </para> |
| 3534 | |
| 3535 | <para> |
| 3536 | For the most part, the Multilib class extension works automatically to |
| 3537 | extend the package name from <filename>${PN}</filename> to |
| 3538 | <filename>${MLPREFIX}${PN}</filename>, where <filename>MLPREFIX</filename> |
| 3539 | is the particular multilib (e.g. "lib32-" or "lib64-"). |
| 3540 | Standard variables such as |
| 3541 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>, |
| 3542 | <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>, |
| 3543 | <ulink url='&YOCTO_DOCS_REF_URL;#var-RPROVIDES'><filename>RPROVIDES</filename></ulink>, |
| 3544 | <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>, |
| 3545 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>, and |
| 3546 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES_DYNAMIC'><filename>PACKAGES_DYNAMIC</filename></ulink> |
| 3547 | are automatically extended by the system. |
| 3548 | If you are extending any manual code in the recipe, you can use the |
| 3549 | <filename>${MLPREFIX}</filename> variable to ensure those names are extended |
| 3550 | correctly. |
| 3551 | This automatic extension code resides in <filename>multilib.bbclass</filename>. |
| 3552 | </para> |
| 3553 | </section> |
| 3554 | |
| 3555 | <section id='using-multilib'> |
| 3556 | <title>Using Multilib</title> |
| 3557 | |
| 3558 | <para> |
| 3559 | After you have set up the recipes, you need to define the actual |
| 3560 | combination of multiple libraries you want to build. |
| 3561 | You accomplish this through your <filename>local.conf</filename> |
| 3562 | configuration file in the |
| 3563 | <link linkend='build-directory'>Build Directory</link>. |
| 3564 | An example configuration would be as follows: |
| 3565 | <literallayout class='monospaced'> |
| 3566 | MACHINE = "qemux86-64" |
| 3567 | require conf/multilib.conf |
| 3568 | MULTILIBS = "multilib:lib32" |
| 3569 | DEFAULTTUNE_virtclass-multilib-lib32 = "x86" |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 3570 | IMAGE_INSTALL_append = " lib32-glib-2.0" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 3571 | </literallayout> |
| 3572 | This example enables an |
| 3573 | additional library named <filename>lib32</filename> alongside the |
| 3574 | normal target packages. |
| 3575 | When combining these "lib32" alternatives, the example uses "x86" for tuning. |
| 3576 | For information on this particular tuning, see |
| 3577 | <filename>meta/conf/machine/include/ia32/arch-ia32.inc</filename>. |
| 3578 | </para> |
| 3579 | |
| 3580 | <para> |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 3581 | The example then includes <filename>lib32-glib-2.0</filename> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 3582 | in all the images, which illustrates one method of including a |
| 3583 | multiple library dependency. |
| 3584 | You can use a normal image build to include this dependency, |
| 3585 | for example: |
| 3586 | <literallayout class='monospaced'> |
| 3587 | $ bitbake core-image-sato |
| 3588 | </literallayout> |
| 3589 | You can also build Multilib packages specifically with a command like this: |
| 3590 | <literallayout class='monospaced'> |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 3591 | $ bitbake lib32-glib-2.0 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 3592 | </literallayout> |
| 3593 | </para> |
| 3594 | </section> |
| 3595 | |
| 3596 | <section id='additional-implementation-details'> |
| 3597 | <title>Additional Implementation Details</title> |
| 3598 | |
| 3599 | <para> |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 3600 | Generic implementation details as well as details that are |
| 3601 | specific to package management systems exist. |
| 3602 | Following are implementation details that exist regardless |
| 3603 | of the package management system: |
| 3604 | <itemizedlist> |
| 3605 | <listitem><para>The typical convention used for the |
| 3606 | class extension code as used by |
| 3607 | Multilib assumes that all package names specified |
| 3608 | in |
| 3609 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink> |
| 3610 | that contain <filename>${PN}</filename> have |
| 3611 | <filename>${PN}</filename> at the start of the name. |
| 3612 | When that convention is not followed and |
| 3613 | <filename>${PN}</filename> appears at |
| 3614 | the middle or the end of a name, problems occur. |
| 3615 | </para></listitem> |
| 3616 | <listitem><para>The |
| 3617 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TARGET_VENDOR'><filename>TARGET_VENDOR</filename></ulink> |
| 3618 | value under Multilib will be extended to |
| 3619 | "-<replaceable>vendor</replaceable>ml<replaceable>multilib</replaceable>" |
| 3620 | (e.g. "-pokymllib32" for a "lib32" Multilib with |
| 3621 | Poky). |
| 3622 | The reason for this slightly unwieldy contraction |
| 3623 | is that any "-" characters in the vendor |
| 3624 | string presently break Autoconf's |
| 3625 | <filename>config.sub</filename>, and |
| 3626 | other separators are problematic for different |
| 3627 | reasons. |
| 3628 | </para></listitem> |
| 3629 | </itemizedlist> |
| 3630 | </para> |
| 3631 | ' |
| 3632 | <para> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 3633 | For the RPM Package Management System, the following implementation details |
| 3634 | exist: |
| 3635 | <itemizedlist> |
| 3636 | <listitem><para>A unique architecture is defined for the Multilib packages, |
| 3637 | along with creating a unique deploy folder under |
| 3638 | <filename>tmp/deploy/rpm</filename> in the |
| 3639 | <link linkend='build-directory'>Build Directory</link>. |
| 3640 | For example, consider <filename>lib32</filename> in a |
| 3641 | <filename>qemux86-64</filename> image. |
| 3642 | The possible architectures in the system are "all", "qemux86_64", |
| 3643 | "lib32_qemux86_64", and "lib32_x86".</para></listitem> |
| 3644 | <listitem><para>The <filename>${MLPREFIX}</filename> variable is stripped from |
| 3645 | <filename>${PN}</filename> during RPM packaging. |
| 3646 | The naming for a normal RPM package and a Multilib RPM package in a |
| 3647 | <filename>qemux86-64</filename> system resolves to something similar to |
| 3648 | <filename>bash-4.1-r2.x86_64.rpm</filename> and |
| 3649 | <filename>bash-4.1.r2.lib32_x86.rpm</filename>, respectively. |
| 3650 | </para></listitem> |
| 3651 | <listitem><para>When installing a Multilib image, the RPM backend first |
| 3652 | installs the base image and then installs the Multilib libraries. |
| 3653 | </para></listitem> |
| 3654 | <listitem><para>The build system relies on RPM to resolve the identical files in the |
| 3655 | two (or more) Multilib packages.</para></listitem> |
| 3656 | </itemizedlist> |
| 3657 | </para> |
| 3658 | |
| 3659 | <para> |
| 3660 | For the IPK Package Management System, the following implementation details exist: |
| 3661 | <itemizedlist> |
| 3662 | <listitem><para>The <filename>${MLPREFIX}</filename> is not stripped from |
| 3663 | <filename>${PN}</filename> during IPK packaging. |
| 3664 | The naming for a normal RPM package and a Multilib IPK package in a |
| 3665 | <filename>qemux86-64</filename> system resolves to something like |
| 3666 | <filename>bash_4.1-r2.x86_64.ipk</filename> and |
| 3667 | <filename>lib32-bash_4.1-rw_x86.ipk</filename>, respectively. |
| 3668 | </para></listitem> |
| 3669 | <listitem><para>The IPK deploy folder is not modified with |
| 3670 | <filename>${MLPREFIX}</filename> because packages with and without |
| 3671 | the Multilib feature can exist in the same folder due to the |
| 3672 | <filename>${PN}</filename> differences.</para></listitem> |
| 3673 | <listitem><para>IPK defines a sanity check for Multilib installation |
| 3674 | using certain rules for file comparison, overridden, etc. |
| 3675 | </para></listitem> |
| 3676 | </itemizedlist> |
| 3677 | </para> |
| 3678 | </section> |
| 3679 | </section> |
| 3680 | |
| 3681 | <section id='installing-multiple-versions-of-the-same-library'> |
| 3682 | <title>Installing Multiple Versions of the Same Library</title> |
| 3683 | |
| 3684 | <para> |
| 3685 | Situations can exist where you need to install and use |
| 3686 | multiple versions of the same library on the same system |
| 3687 | at the same time. |
| 3688 | These situations almost always exist when a library API |
| 3689 | changes and you have multiple pieces of software that |
| 3690 | depend on the separate versions of the library. |
| 3691 | To accommodate these situations, you can install multiple |
| 3692 | versions of the same library in parallel on the same system. |
| 3693 | </para> |
| 3694 | |
| 3695 | <para> |
| 3696 | The process is straightforward as long as the libraries use |
| 3697 | proper versioning. |
| 3698 | With properly versioned libraries, all you need to do to |
| 3699 | individually specify the libraries is create separate, |
| 3700 | appropriately named recipes where the |
| 3701 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink> part of the |
| 3702 | name includes a portion that differentiates each library version |
| 3703 | (e.g.the major part of the version number). |
| 3704 | Thus, instead of having a single recipe that loads one version |
| 3705 | of a library (e.g. <filename>clutter</filename>), you provide |
| 3706 | multiple recipes that result in different versions |
| 3707 | of the libraries you want. |
| 3708 | As an example, the following two recipes would allow the |
| 3709 | two separate versions of the <filename>clutter</filename> |
| 3710 | library to co-exist on the same system: |
| 3711 | <literallayout class='monospaced'> |
| 3712 | clutter-1.6_1.6.20.bb |
| 3713 | clutter-1.8_1.8.4.bb |
| 3714 | </literallayout> |
| 3715 | Additionally, if you have other recipes that depend on a given |
| 3716 | library, you need to use the |
| 3717 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink> |
| 3718 | variable to create the dependency. |
| 3719 | Continuing with the same example, if you want to have a recipe |
| 3720 | depend on the 1.8 version of the <filename>clutter</filename> |
| 3721 | library, use the following in your recipe: |
| 3722 | <literallayout class='monospaced'> |
| 3723 | DEPENDS = "clutter-1.8" |
| 3724 | </literallayout> |
| 3725 | </para> |
| 3726 | </section> |
| 3727 | </section> |
| 3728 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 3729 | <section id='dev-optionally-using-an-external-toolchain'> |
| 3730 | <title>Optionally Using an External Toolchain</title> |
| 3731 | |
| 3732 | <para> |
| 3733 | You might want to use an external toolchain as part of your |
| 3734 | development. |
| 3735 | If this is the case, the fundamental steps you need to accomplish |
| 3736 | are as follows: |
| 3737 | <itemizedlist> |
| 3738 | <listitem><para> |
| 3739 | Understand where the installed toolchain resides. |
| 3740 | For cases where you need to build the external toolchain, |
| 3741 | you would need to take separate steps to build and install |
| 3742 | the toolchain. |
| 3743 | </para></listitem> |
| 3744 | <listitem><para> |
| 3745 | Make sure you add the layer that contains the toolchain to |
| 3746 | your <filename>bblayers.conf</filename> file through the |
| 3747 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'><filename>BBLAYERS</filename></ulink> |
| 3748 | variable. |
| 3749 | </para></listitem> |
| 3750 | <listitem><para> |
| 3751 | Set the |
| 3752 | <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNAL_TOOLCHAIN'><filename>EXTERNAL_TOOLCHAIN</filename></ulink> |
| 3753 | variable in your <filename>local.conf</filename> file |
| 3754 | to the location in which you installed the toolchain. |
| 3755 | </para></listitem> |
| 3756 | </itemizedlist> |
| 3757 | A good example of an external toolchain used with the Yocto Project |
| 3758 | is <trademark class='registered'>Mentor Graphics</trademark> |
| 3759 | Sourcery G++ Toolchain. |
| 3760 | You can see information on how to use that particular layer in the |
| 3761 | <filename>README</filename> file at |
| 3762 | <ulink url='http://github.com/MentorEmbedded/meta-sourcery/'></ulink>. |
| 3763 | You can find further information by reading about the |
| 3764 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TCMODE'><filename>TCMODE</filename></ulink> |
| 3765 | variable in the Yocto Project Reference Manual's variable glossary. |
| 3766 | </para> |
| 3767 | </section> |
| 3768 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 3769 | <section id='creating-partitioned-images'> |
| 3770 | <title>Creating Partitioned Images</title> |
| 3771 | |
| 3772 | <para> |
| 3773 | Creating an image for a particular hardware target using the |
| 3774 | OpenEmbedded build system does not necessarily mean you can boot |
| 3775 | that image as is on your device. |
| 3776 | Physical devices accept and boot images in various ways depending |
| 3777 | on the specifics of the device. |
| 3778 | Usually, information about the hardware can tell you what image |
| 3779 | format the device requires. |
| 3780 | Should your device require multiple partitions on an SD card, flash, |
| 3781 | or an HDD, you can use the OpenEmbedded Image Creator, |
| 3782 | <filename>wic</filename>, to create the properly partitioned image. |
| 3783 | </para> |
| 3784 | |
| 3785 | <para> |
| 3786 | The <filename>wic</filename> command generates partitioned images |
| 3787 | from existing OpenEmbedded build artifacts. |
| 3788 | Image generation is driven by partitioning commands contained |
| 3789 | in an Openembedded kickstart file (<filename>.wks</filename>) |
| 3790 | specified either directly on the command line or as one of a |
| 3791 | selection of canned <filename>.wks</filename> files as shown |
| 3792 | with the <filename>wic list images</filename> command in the |
| 3793 | "<link linkend='using-a-provided-kickstart_file'>Using an Existing Kickstart File</link>" |
| 3794 | section. |
| 3795 | When applied to a given set of build artifacts, the result is an |
| 3796 | image or set of images that can be directly written onto media and |
| 3797 | used on a particular system. |
| 3798 | </para> |
| 3799 | |
| 3800 | <para> |
| 3801 | The <filename>wic</filename> command and the infrastructure |
| 3802 | it is based on is by definition incomplete. |
| 3803 | Its purpose is to allow the generation of customized images, |
| 3804 | and as such was designed to be completely extensible through a |
| 3805 | plugin interface. |
| 3806 | See the |
| 3807 | "<link linkend='openembedded-kickstart-plugins'>Plugins</link>" |
| 3808 | section for information on these plugins. |
| 3809 | </para> |
| 3810 | |
| 3811 | <para> |
| 3812 | This section provides some background information on |
| 3813 | <filename>wic</filename>, describes what you need to have in |
| 3814 | place to run the tool, provides instruction on how to use |
| 3815 | <filename>wic</filename>, and provides several examples. |
| 3816 | </para> |
| 3817 | |
| 3818 | <section id='wic-background'> |
| 3819 | <title>Background</title> |
| 3820 | |
| 3821 | <para> |
| 3822 | This section provides some background on the |
| 3823 | <filename>wic</filename> utility. |
| 3824 | While none of this information is required to use |
| 3825 | <filename>wic</filename>, you might find it interesting. |
| 3826 | <itemizedlist> |
| 3827 | <listitem><para> |
| 3828 | The name "wic" is derived from OpenEmbedded |
| 3829 | Image Creator (oeic). |
| 3830 | The "oe" diphthong in "oeic" was promoted to the |
| 3831 | letter "w", because "oeic" is both difficult to remember and |
| 3832 | pronounce.</para></listitem> |
| 3833 | <listitem><para> |
| 3834 | <filename>wic</filename> is loosely based on the |
| 3835 | Meego Image Creator (<filename>mic</filename>) |
| 3836 | framework. |
| 3837 | The <filename>wic</filename> implementation has been |
| 3838 | heavily modified to make direct use of OpenEmbedded |
| 3839 | build artifacts instead of package installation and |
| 3840 | configuration, which are already incorporated within |
| 3841 | the OpenEmbedded artifacts.</para></listitem> |
| 3842 | <listitem><para> |
| 3843 | <filename>wic</filename> is a completely independent |
| 3844 | standalone utility that initially provides |
| 3845 | easier-to-use and more flexible replacements for a |
| 3846 | couple bits of existing functionality in OE Core's |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 3847 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-image-live'><filename>image-live</filename></ulink> |
| 3848 | class and <filename>mkefidisk.sh</filename> script. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 3849 | The difference between |
| 3850 | <filename>wic</filename> and those examples is |
| 3851 | that with <filename>wic</filename> the |
| 3852 | functionality of those scripts is implemented |
| 3853 | by a general-purpose partitioning language, which is |
| 3854 | based on Redhat kickstart syntax.</para></listitem> |
| 3855 | </itemizedlist> |
| 3856 | </para> |
| 3857 | </section> |
| 3858 | |
| 3859 | <section id='wic-requirements'> |
| 3860 | <title>Requirements</title> |
| 3861 | |
| 3862 | <para> |
| 3863 | In order to use the <filename>wic</filename> utility |
| 3864 | with the OpenEmbedded Build system, your system needs |
| 3865 | to meet the following requirements: |
| 3866 | <itemizedlist> |
| 3867 | <listitem><para>The Linux distribution on your |
| 3868 | development host must support the Yocto Project. |
| 3869 | See the |
| 3870 | "<ulink url='&YOCTO_DOCS_REF_URL;#detailed-supported-distros'>Supported Linux Distributions</ulink>" |
| 3871 | section in the Yocto Project Reference Manual for this |
| 3872 | list of distributions.</para></listitem> |
| 3873 | <listitem><para> |
| 3874 | The standard system utilities, such as |
| 3875 | <filename>cp</filename>, must be installed on your |
| 3876 | development host system. |
| 3877 | </para></listitem> |
| 3878 | <listitem><para> |
| 3879 | You need to have the build artifacts already |
| 3880 | available, which typically means that you must |
| 3881 | have already created an image using the |
| 3882 | Openembedded build system (e.g. |
| 3883 | <filename>core-image-minimal</filename>). |
| 3884 | While it might seem redundant to generate an image in |
| 3885 | order to create an image using |
| 3886 | <filename>wic</filename>, the current version of |
| 3887 | <filename>wic</filename> requires the artifacts |
| 3888 | in the form generated by the build system. |
| 3889 | </para></listitem> |
| 3890 | <listitem><para> |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 3891 | You must build several native tools, which are tools |
| 3892 | built to run on the build system: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 3893 | <literallayout class='monospaced'> |
| 3894 | $ bitbake parted-native dosfstools-native mtools-native |
| 3895 | </literallayout> |
| 3896 | </para></listitem> |
| 3897 | <listitem><para> |
| 3898 | You must have sourced one of the build environment |
| 3899 | setup scripts (i.e. |
| 3900 | <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink> |
| 3901 | or |
| 3902 | <ulink url='&YOCTO_DOCS_REF_URL;#structure-memres-core-script'><filename>oe-init-build-env-memres</filename></ulink>) |
| 3903 | found in the |
| 3904 | <link linkend='build-directory'>Build Directory</link>. |
| 3905 | </para></listitem> |
| 3906 | </itemizedlist> |
| 3907 | </para> |
| 3908 | </section> |
| 3909 | |
| 3910 | <section id='wic-getting-help'> |
| 3911 | <title>Getting Help</title> |
| 3912 | |
| 3913 | <para> |
| 3914 | You can get general help for the <filename>wic</filename> |
| 3915 | by entering the <filename>wic</filename> command by itself |
| 3916 | or by entering the command with a help argument as follows: |
| 3917 | <literallayout class='monospaced'> |
| 3918 | $ wic -h |
| 3919 | $ wic --help |
| 3920 | </literallayout> |
| 3921 | </para> |
| 3922 | |
| 3923 | <para> |
| 3924 | Currently, <filename>wic</filename> supports two commands: |
| 3925 | <filename>create</filename> and <filename>list</filename>. |
| 3926 | You can get help for these commands as follows: |
| 3927 | <literallayout class='monospaced'> |
| 3928 | $ wic help <replaceable>command</replaceable> |
| 3929 | </literallayout> |
| 3930 | </para> |
| 3931 | |
| 3932 | <para> |
| 3933 | You can also get detailed help on a number of topics |
| 3934 | from the help system. |
| 3935 | The output of <filename>wic --help</filename> |
| 3936 | displays a list of available help |
| 3937 | topics under a "Help topics" heading. |
| 3938 | You can have the help system display the help text for |
| 3939 | a given topic by prefacing the topic with |
| 3940 | <filename>wic help</filename>: |
| 3941 | <literallayout class='monospaced'> |
| 3942 | $ wic help <replaceable>help_topic</replaceable> |
| 3943 | </literallayout> |
| 3944 | </para> |
| 3945 | |
| 3946 | <para> |
| 3947 | You can find out more about the images |
| 3948 | <filename>wic</filename> creates using the existing |
| 3949 | kickstart files with the following form of the command: |
| 3950 | <literallayout class='monospaced'> |
| 3951 | $ wic list <replaceable>image</replaceable> help |
| 3952 | </literallayout> |
| 3953 | where <filename><replaceable>image</replaceable></filename> is either |
| 3954 | <filename>directdisk</filename> or |
| 3955 | <filename>mkefidisk</filename>. |
| 3956 | </para> |
| 3957 | </section> |
| 3958 | |
| 3959 | <section id='operational-modes'> |
| 3960 | <title>Operational Modes</title> |
| 3961 | |
| 3962 | <para> |
| 3963 | You can use <filename>wic</filename> in two different |
| 3964 | modes, depending on how much control you need for |
| 3965 | specifying the Openembedded build artifacts that are |
| 3966 | used for creating the image: Raw and Cooked: |
| 3967 | <itemizedlist> |
| 3968 | <listitem><para><emphasis>Raw Mode:</emphasis> |
| 3969 | You explicitly specify build artifacts through |
| 3970 | command-line arguments.</para></listitem> |
| 3971 | <listitem><para><emphasis>Cooked Mode:</emphasis> |
| 3972 | The current |
| 3973 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink> |
| 3974 | setting and image name are used to automatically locate |
| 3975 | and provide the build artifacts.</para></listitem> |
| 3976 | </itemizedlist> |
| 3977 | </para> |
| 3978 | |
| 3979 | <para> |
| 3980 | Regardless of the mode you use, you need to have the build |
| 3981 | artifacts ready and available. |
| 3982 | Additionally, the environment must be set up using the |
| 3983 | <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink> |
| 3984 | or |
| 3985 | <ulink url='&YOCTO_DOCS_REF_URL;#structure-memres-core-script'><filename>oe-init-build-env-memres</filename></ulink> |
| 3986 | script found in the |
| 3987 | <link linkend='build-directory'>Build Directory</link>. |
| 3988 | </para> |
| 3989 | |
| 3990 | <section id='raw-mode'> |
| 3991 | <title>Raw Mode</title> |
| 3992 | |
| 3993 | <para> |
| 3994 | The general form of the 'wic' command in raw mode is: |
| 3995 | <literallayout class='monospaced'> |
| 3996 | $ wic create <replaceable>image_name</replaceable>.wks [<replaceable>options</replaceable>] [...] |
| 3997 | |
| 3998 | Where: |
| 3999 | |
| 4000 | <replaceable>image_name</replaceable>.wks |
| 4001 | An OpenEmbedded kickstart file. You can provide |
| 4002 | your own custom file or use a file from a set of |
| 4003 | existing files as described by further options. |
| 4004 | |
| 4005 | -o <replaceable>OUTDIR</replaceable>, --outdir=<replaceable>OUTDIR</replaceable> |
| 4006 | The name of a directory in which to create image. |
| 4007 | |
| 4008 | -i <replaceable>PROPERTIES_FILE</replaceable>, --infile=<replaceable>PROPERTIES_FILE</replaceable> |
| 4009 | The name of a file containing the values for image |
| 4010 | properties as a JSON file. |
| 4011 | |
| 4012 | -e <replaceable>IMAGE_NAME</replaceable>, --image-name=<replaceable>IMAGE_NAME</replaceable> |
| 4013 | The name of the image from which to use the artifacts |
| 4014 | (e.g. <filename>core-image-sato</filename>). |
| 4015 | |
| 4016 | -r <replaceable>ROOTFS_DIR</replaceable>, --rootfs-dir=<replaceable>ROOTFS_DIR</replaceable> |
| 4017 | The path to the <filename>/rootfs</filename> directory to use as the |
| 4018 | <filename>.wks</filename> rootfs source. |
| 4019 | |
| 4020 | -b <replaceable>BOOTIMG_DIR</replaceable>, --bootimg-dir=<replaceable>BOOTIMG_DIR</replaceable> |
| 4021 | The path to the directory containing the boot artifacts |
| 4022 | (e.g. <filename>/EFI</filename> or <filename>/syslinux</filename>) to use as the <filename>.wks</filename> bootimg |
| 4023 | source. |
| 4024 | |
| 4025 | -k <replaceable>KERNEL_DIR</replaceable>, --kernel-dir=<replaceable>KERNEL_DIR</replaceable> |
| 4026 | The path to the directory containing the kernel to use |
| 4027 | in the <filename>.wks</filename> boot image. |
| 4028 | |
| 4029 | -n <replaceable>NATIVE_SYSROOT</replaceable>, --native-sysroot=<replaceable>NATIVE_SYSROOT</replaceable> |
| 4030 | The path to the native sysroot containing the tools to use |
| 4031 | to build the image. |
| 4032 | |
| 4033 | -s, --skip-build-check |
| 4034 | Skips the build check. |
| 4035 | |
| 4036 | -D, --debug |
| 4037 | Output debug information. |
| 4038 | </literallayout> |
| 4039 | <note> |
| 4040 | You do not need root privileges to run |
| 4041 | <filename>wic</filename>. |
| 4042 | In fact, you should not run as root when using the |
| 4043 | utility. |
| 4044 | </note> |
| 4045 | </para> |
| 4046 | </section> |
| 4047 | |
| 4048 | <section id='cooked-mode'> |
| 4049 | <title>Cooked Mode</title> |
| 4050 | |
| 4051 | <para> |
| 4052 | The general form of the <filename>wic</filename> command |
| 4053 | using Cooked Mode is: |
| 4054 | <literallayout class='monospaced'> |
| 4055 | $ wic create <replaceable>kickstart_file</replaceable> -e <replaceable>image_name</replaceable> |
| 4056 | |
| 4057 | Where: |
| 4058 | |
| 4059 | <replaceable>kickstart_file</replaceable> |
| 4060 | An OpenEmbedded kickstart file. You can provide your own |
| 4061 | custom file or supplied file. |
| 4062 | |
| 4063 | <replaceable>image_name</replaceable> |
| 4064 | Specifies the image built using the OpenEmbedded build |
| 4065 | system. |
| 4066 | </literallayout> |
| 4067 | This form is the simplest and most user-friendly, as it |
| 4068 | does not require specifying all individual parameters. |
| 4069 | All you need to provide is your own |
| 4070 | <filename>.wks</filename> file or one provided with the |
| 4071 | release. |
| 4072 | </para> |
| 4073 | </section> |
| 4074 | </section> |
| 4075 | |
| 4076 | <section id='using-a-provided-kickstart_file'> |
| 4077 | <title>Using an Existing Kickstart File</title> |
| 4078 | |
| 4079 | <para> |
| 4080 | If you do not want to create your own |
| 4081 | <filename>.wks</filename> file, you can use an existing |
| 4082 | file provided by the <filename>wic</filename> installation. |
| 4083 | Use the following command to list the available files: |
| 4084 | <literallayout class='monospaced'> |
| 4085 | $ wic list images |
| 4086 | directdisk Create a 'pcbios' direct disk image |
| 4087 | mkefidisk Create an EFI disk image |
| 4088 | </literallayout> |
| 4089 | When you use an existing file, you do not have to use the |
| 4090 | <filename>.wks</filename> extension. |
| 4091 | Here is an example in Raw Mode that uses the |
| 4092 | <filename>directdisk</filename> file: |
| 4093 | <literallayout class='monospaced'> |
| 4094 | $ wic create directdisk -r <replaceable>rootfs_dir</replaceable> -b <replaceable>bootimg_dir</replaceable> \ |
| 4095 | -k <replaceable>kernel_dir</replaceable> -n <replaceable>native_sysroot</replaceable> |
| 4096 | </literallayout> |
| 4097 | </para> |
| 4098 | |
| 4099 | <para> |
| 4100 | Here are the actual partition language commands |
| 4101 | used in the <filename>mkefidisk.wks</filename> file to generate |
| 4102 | an image: |
| 4103 | <literallayout class='monospaced'> |
| 4104 | # short-description: Create an EFI disk image |
| 4105 | # long-description: Creates a partitioned EFI disk image that the user |
| 4106 | # can directly dd to boot media. |
| 4107 | |
| 4108 | part /boot --source bootimg-efi --ondisk sda --label msdos --active --align 1024 |
| 4109 | |
| 4110 | part / --source rootfs --ondisk sda --fstype=ext3 --label platform --align 1024 |
| 4111 | |
| 4112 | part swap --ondisk sda --size 44 --label swap1 --fstype=swap |
| 4113 | |
| 4114 | bootloader --timeout=10 --append="rootwait rootfstype=ext3 console=ttyPCH0,115200 console=tty0 vmalloc=256MB snd-hda-intel.enable_msi=0" |
| 4115 | </literallayout> |
| 4116 | </para> |
| 4117 | </section> |
| 4118 | |
| 4119 | <section id='wic-usage-examples'> |
| 4120 | <title>Examples</title> |
| 4121 | |
| 4122 | <para> |
| 4123 | This section provides several examples that show how to use |
| 4124 | the <filename>wic</filename> utility. |
| 4125 | All the examples assume the list of requirements in the |
| 4126 | "<link linkend='wic-requirements'>Requirements</link>" section |
| 4127 | have been met. |
| 4128 | The examples assume the previously generated image is |
| 4129 | <filename>core-image-minimal</filename>. |
| 4130 | </para> |
| 4131 | |
| 4132 | <section id='generate-an-image-using-a-provided-kickstart-file'> |
| 4133 | <title>Generate an Image using an Existing Kickstart File</title> |
| 4134 | |
| 4135 | <para> |
| 4136 | This example runs in Cooked Mode and uses the |
| 4137 | <filename>mkefidisk</filename> kickstart file: |
| 4138 | <literallayout class='monospaced'> |
| 4139 | $ wic create mkefidisk -e core-image-minimal |
| 4140 | Checking basic build environment... |
| 4141 | Done. |
| 4142 | |
| 4143 | Creating image(s)... |
| 4144 | |
| 4145 | Info: The new image(s) can be found here: |
| 4146 | /var/tmp/wic/build/mkefidisk-201310230946-sda.direct |
| 4147 | |
| 4148 | The following build artifacts were used to create the image(s): |
| 4149 | ROOTFS_DIR: /home/trz/yocto/yocto-image/build/tmp/work/minnow-poky-linux/core-image-minimal/1.0-r0/rootfs |
| 4150 | BOOTIMG_DIR: /home/trz/yocto/yocto-image/build/tmp/work/minnow-poky-linux/core-image-minimal/1.0-r0/core-image-minimal-1.0/hddimg |
| 4151 | KERNEL_DIR: /home/trz/yocto/yocto-image/build/tmp/sysroots/minnow/usr/src/kernel |
| 4152 | NATIVE_SYSROOT: /home/trz/yocto/yocto-image/build/tmp/sysroots/x86_64-linux |
| 4153 | |
| 4154 | |
| 4155 | The image(s) were created using OE kickstart file: |
| 4156 | /home/trz/yocto/yocto-image/scripts/lib/image/canned-wks/mkefidisk.wks |
| 4157 | </literallayout> |
| 4158 | This example shows the easiest way to create an image |
| 4159 | by running in Cooked Mode and using the |
| 4160 | <filename>-e</filename> option with an existing kickstart |
| 4161 | file. |
| 4162 | All that is necessary is to specify the image used to |
| 4163 | generate the artifacts. |
| 4164 | Your <filename>local.conf</filename> needs to have the |
| 4165 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink> |
| 4166 | variable set to the machine you are using, which is |
| 4167 | "minnow" in this example. |
| 4168 | </para> |
| 4169 | |
| 4170 | <para> |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 4171 | The output specifies the exact image created as well as |
| 4172 | where it was created. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4173 | The output also names the artifacts used and the exact |
| 4174 | <filename>.wks</filename> script that was used to generate |
| 4175 | the image. |
| 4176 | <note> |
| 4177 | You should always verify the details provided in the |
| 4178 | output to make sure that the image was indeed created |
| 4179 | exactly as expected. |
| 4180 | </note> |
| 4181 | </para> |
| 4182 | |
| 4183 | <para> |
| 4184 | Continuing with the example, you can now directly |
| 4185 | <filename>dd</filename> the image to a USB stick, or |
| 4186 | whatever media for which you built your image, |
| 4187 | and boot the resulting media: |
| 4188 | <literallayout class='monospaced'> |
| 4189 | $ sudo dd if=/var/tmp/wic/build/mkefidisk-201310230946-sda.direct of=/dev/sdb |
| 4190 | [sudo] password for trz: |
| 4191 | 182274+0 records in |
| 4192 | 182274+0 records out |
| 4193 | 93324288 bytes (93 MB) copied, 14.4777 s, 6.4 MB/s |
| 4194 | [trz@empanada ~]$ sudo eject /dev/sdb |
| 4195 | </literallayout> |
| 4196 | </para> |
| 4197 | </section> |
| 4198 | |
| 4199 | <section id='using-a-modified-kickstart-file'> |
| 4200 | <title>Using a Modified Kickstart File</title> |
| 4201 | |
| 4202 | <para> |
| 4203 | Because <filename>wic</filename> image creation is driven |
| 4204 | by the kickstart file, it is easy to affect image creation |
| 4205 | by changing the parameters in the file. |
| 4206 | This next example demonstrates that through modification |
| 4207 | of the <filename>directdisk</filename> kickstart file. |
| 4208 | </para> |
| 4209 | |
| 4210 | <para> |
| 4211 | As mentioned earlier, you can use the command |
| 4212 | <filename>wic list images</filename> to show the list |
| 4213 | of existing kickstart files. |
| 4214 | The directory in which these files reside is |
| 4215 | <filename>scripts/lib/image/canned-wks/</filename> |
| 4216 | located in the |
| 4217 | <link linkend='source-directory'>Source Directory</link>. |
| 4218 | Because the available files reside in this directory, you |
| 4219 | can create and add your own custom files to the directory. |
| 4220 | Subsequent use of the <filename>wic list images</filename> |
| 4221 | command would then include your kickstart files. |
| 4222 | </para> |
| 4223 | |
| 4224 | <para> |
| 4225 | In this example, the existing |
| 4226 | <filename>directdisk</filename> file already does most |
| 4227 | of what is needed. |
| 4228 | However, for the hardware in this example, the image will |
| 4229 | need to boot from <filename>sdb</filename> instead of |
| 4230 | <filename>sda</filename>, which is what the |
| 4231 | <filename>directdisk</filename> kickstart file uses. |
| 4232 | </para> |
| 4233 | |
| 4234 | <para> |
| 4235 | The example begins by making a copy of the |
| 4236 | <filename>directdisk.wks</filename> file in the |
| 4237 | <filename>scripts/lib/image/canned-wks</filename> |
| 4238 | directory and then changing the lines that specify the |
| 4239 | target disk from which to boot. |
| 4240 | <literallayout class='monospaced'> |
| 4241 | $ cp /home/trz/yocto/yocto-image/scripts/lib/image/canned-wks/directdisk.wks \ |
| 4242 | /home/trz/yocto/yocto-image/scripts/lib/image/canned-wks/directdisksdb.wks |
| 4243 | </literallayout> |
| 4244 | Next, the example modifies the |
| 4245 | <filename>directdisksdb.wks</filename> file and changes all |
| 4246 | instances of "<filename>--ondisk sda</filename>" |
| 4247 | to "<filename>--ondisk sdb</filename>". |
| 4248 | The example changes the following two lines and leaves the |
| 4249 | remaining lines untouched: |
| 4250 | <literallayout class='monospaced'> |
| 4251 | part /boot --source bootimg-pcbios --ondisk sdb --label boot --active --align 1024 |
| 4252 | part / --source rootfs --ondisk sdb --fstype=ext3 --label platform --align 1024 |
| 4253 | </literallayout> |
| 4254 | Once the lines are changed, the example generates the |
| 4255 | <filename>directdisksdb</filename> image. |
| 4256 | The command points the process at the |
| 4257 | <filename>core-image-minimal</filename> artifacts for the |
| 4258 | Next Unit of Computing (nuc) |
| 4259 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink> |
| 4260 | the <filename>local.conf</filename>. |
| 4261 | <literallayout class='monospaced'> |
| 4262 | $ wic create directdisksdb -e core-image-minimal |
| 4263 | Checking basic build environment... |
| 4264 | Done. |
| 4265 | |
| 4266 | Creating image(s)... |
| 4267 | |
| 4268 | Info: The new image(s) can be found here: |
| 4269 | /var/tmp/wic/build/directdisksdb-201310231131-sdb.direct |
| 4270 | |
| 4271 | The following build artifacts were used to create the image(s): |
| 4272 | ROOTFS_DIR: /home/trz/yocto/yocto-image/build/tmp/work/nuc-poky-linux/core-image-minimal/1.0-r0/rootfs |
| 4273 | BOOTIMG_DIR: /home/trz/yocto/yocto-image/build/tmp/sysroots/nuc/usr/share |
| 4274 | KERNEL_DIR: /home/trz/yocto/yocto-image/build/tmp/sysroots/nuc/usr/src/kernel |
| 4275 | NATIVE_SYSROOT: /home/trz/yocto/yocto-image/build/tmp/sysroots/x86_64-linux |
| 4276 | |
| 4277 | |
| 4278 | The image(s) were created using OE kickstart file: |
| 4279 | /home/trz/yocto/yocto-image/scripts/lib/image/canned-wks/directdisksdb.wks |
| 4280 | </literallayout> |
| 4281 | Continuing with the example, you can now directly |
| 4282 | <filename>dd</filename> the image to a USB stick, or |
| 4283 | whatever media for which you built your image, |
| 4284 | and boot the resulting media: |
| 4285 | <literallayout class='monospaced'> |
| 4286 | $ sudo dd if=/var/tmp/wic/build/directdisksdb-201310231131-sdb.direct of=/dev/sdb |
| 4287 | 86018+0 records in |
| 4288 | 86018+0 records out |
| 4289 | 44041216 bytes (44 MB) copied, 13.0734 s, 3.4 MB/s |
| 4290 | [trz@empanada tmp]$ sudo eject /dev/sdb |
| 4291 | </literallayout> |
| 4292 | </para> |
| 4293 | </section> |
| 4294 | |
| 4295 | <section id='creating-an-image-based-on-core-image-minimal-and-crownbay-noemgd'> |
| 4296 | <title>Creating an Image Based on <filename>core-image-minimal</filename> and <filename>crownbay-noemgd</filename></title> |
| 4297 | |
| 4298 | <para> |
| 4299 | This example creates an image based on |
| 4300 | <filename>core-image-minimal</filename> and a |
| 4301 | <filename>crownbay-noemgd</filename> |
| 4302 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink> |
| 4303 | that works right out of the box. |
| 4304 | <literallayout class='monospaced'> |
| 4305 | $ wic create directdisk -e core-image-minimal |
| 4306 | |
| 4307 | Checking basic build environment... |
| 4308 | Done. |
| 4309 | |
| 4310 | Creating image(s)... |
| 4311 | |
| 4312 | Info: The new image(s) can be found here: |
| 4313 | /var/tmp/wic/build/directdisk-201309252350-sda.direct |
| 4314 | |
| 4315 | The following build artifacts were used to create the image(s): |
| 4316 | |
| 4317 | ROOTFS_DIR: /home/trz/yocto/yocto-image/build/tmp/work/crownbay_noemgd-poky-linux/core-image-minimal/1.0-r0/rootfs |
| 4318 | BOOTIMG_DIR: /home/trz/yocto/yocto-image/build/tmp/sysroots/crownbay-noemgd/usr/share |
| 4319 | KERNEL_DIR: /home/trz/yocto/yocto-image/build/tmp/sysroots/crownbay-noemgd/usr/src/kernel |
| 4320 | NATIVE_SYSROOT: /home/trz/yocto/yocto-image/build/tmp/sysroots/crownbay-noemgd/usr/src/kernel |
| 4321 | |
| 4322 | The image(s) were created using OE kickstart file: |
| 4323 | /home/trz/yocto/yocto-image/scripts/lib/image/canned-wks/directdisk.wks |
| 4324 | </literallayout> |
| 4325 | </para> |
| 4326 | </section> |
| 4327 | |
| 4328 | <section id='using-a-modified-kickstart-file-and-running-in-raw-mode'> |
| 4329 | <title>Using a Modified Kickstart File and Running in Raw Mode</title> |
| 4330 | |
| 4331 | <para> |
| 4332 | This next example manually specifies each build artifact |
| 4333 | (runs in Raw Mode) and uses a modified kickstart file. |
| 4334 | The example also uses the <filename>-o</filename> option |
| 4335 | to cause <filename>wic</filename> to create the output |
| 4336 | somewhere other than the default |
| 4337 | <filename>/var/tmp/wic</filename> directory: |
| 4338 | <literallayout class='monospaced'> |
| 4339 | $ wic create ~/test.wks -o /home/trz/testwic --rootfs-dir \ |
| 4340 | /home/trz/yocto/yocto-image/build/tmp/work/crownbay_noemgd-poky-linux/core-image-minimal/1.0-r0/rootfs \ |
| 4341 | --bootimg-dir /home/trz/yocto/yocto-image/build/tmp/sysroots/crownbay-noemgd/usr/share \ |
| 4342 | --kernel-dir /home/trz/yocto/yocto-image/build/tmp/sysroots/crownbay-noemgd/usr/src/kernel \ |
| 4343 | --native-sysroot /home/trz/yocto/yocto-image/build/tmp/sysroots/x86_64-linux |
| 4344 | |
| 4345 | Creating image(s)... |
| 4346 | |
| 4347 | Info: The new image(s) can be found here: |
| 4348 | /home/trz/testwic/build/test-201309260032-sda.direct |
| 4349 | |
| 4350 | The following build artifacts were used to create the image(s): |
| 4351 | |
| 4352 | ROOTFS_DIR: /home/trz/yocto/yocto-image/build/tmp/work/crownbay_noemgd-poky-linux/core-image-minimal/1.0-r0/rootfs |
| 4353 | BOOTIMG_DIR: /home/trz/yocto/yocto-image/build/tmp/sysroots/crownbay-noemgd/usr/share |
| 4354 | KERNEL_DIR: /home/trz/yocto/yocto-image/build/tmp/sysroots/crownbay-noemgd/usr/src/kernel |
| 4355 | NATIVE_SYSROOT: /home/trz/yocto/yocto-image/build/tmp/sysroots/crownbay-noemgd/usr/src/kernel |
| 4356 | |
| 4357 | The image(s) were created using OE kickstart file: |
| 4358 | /home/trz/test.wks |
| 4359 | </literallayout> |
| 4360 | For this example, |
| 4361 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink> |
| 4362 | did not have to be specified in the |
| 4363 | <filename>local.conf</filename> file since the artifact is |
| 4364 | manually specified. |
| 4365 | </para> |
| 4366 | </section> |
| 4367 | </section> |
| 4368 | |
| 4369 | <section id='openembedded-kickstart-plugins'> |
| 4370 | <title>Plugins</title> |
| 4371 | |
| 4372 | <para> |
| 4373 | Plugins allow <filename>wic</filename> functionality to |
| 4374 | be extended and specialized by users. |
| 4375 | This section documents the plugin interface, which is |
| 4376 | currently restricted to source plugins. |
| 4377 | </para> |
| 4378 | |
| 4379 | <para> |
| 4380 | Source plugins provide a mechanism to customize |
| 4381 | various aspects of the image generation process in |
| 4382 | <filename>wic</filename>, mainly the contents of |
| 4383 | partitions. |
| 4384 | The plugins provide a mechanism for mapping values |
| 4385 | specified in <filename>.wks</filename> files using the |
| 4386 | <filename>--source</filename> keyword to a |
| 4387 | particular plugin implementation that populates a |
| 4388 | corresponding partition. |
| 4389 | </para> |
| 4390 | |
| 4391 | <para> |
| 4392 | A source plugin is created as a subclass of |
| 4393 | <filename>SourcePlugin</filename>. |
| 4394 | The plugin file containing it is added to |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 4395 | <filename>scripts/lib/wic/plugins/source/</filename> to |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4396 | make the plugin implementation available to the |
| 4397 | <filename>wic</filename> implementation. |
| 4398 | For more information, see |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 4399 | <filename>scripts/lib/wic/pluginbase.py</filename>. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4400 | </para> |
| 4401 | |
| 4402 | <para> |
| 4403 | Source plugins can also be implemented and added by |
| 4404 | external layers. |
| 4405 | As such, any plugins found in a |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 4406 | <filename>scripts/lib/wic/plugins/source/</filename> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4407 | directory in an external layer are also made |
| 4408 | available. |
| 4409 | </para> |
| 4410 | |
| 4411 | <para> |
| 4412 | When the <filename>wic</filename> implementation needs |
| 4413 | to invoke a partition-specific implementation, it looks |
| 4414 | for the plugin that has the same name as the |
| 4415 | <filename>--source</filename> parameter given to |
| 4416 | that partition. |
| 4417 | For example, if the partition is set up as follows: |
| 4418 | <literallayout class='monospaced'> |
| 4419 | part /boot --source bootimg-pcbios ... |
| 4420 | </literallayout> |
| 4421 | The methods defined as class members of the plugin |
| 4422 | having the matching <filename>bootimg-pcbios.name</filename> |
| 4423 | class member are used. |
| 4424 | </para> |
| 4425 | |
| 4426 | <para> |
| 4427 | To be more concrete, here is the plugin definition that |
| 4428 | matches a |
| 4429 | <filename>--source bootimg-pcbios</filename> usage, |
| 4430 | along with an example |
| 4431 | method called by the <filename>wic</filename> implementation |
| 4432 | when it needs to invoke an implementation-specific |
| 4433 | partition-preparation function: |
| 4434 | <literallayout class='monospaced'> |
| 4435 | class BootimgPcbiosPlugin(SourcePlugin): |
| 4436 | name = 'bootimg-pcbios' |
| 4437 | |
| 4438 | @classmethod |
| 4439 | def do_prepare_partition(self, part, ...) |
| 4440 | </literallayout> |
| 4441 | If the subclass itself does not implement a function, a |
| 4442 | default version in a superclass is located and |
| 4443 | used, which is why all plugins must be derived from |
| 4444 | <filename>SourcePlugin</filename>. |
| 4445 | </para> |
| 4446 | |
| 4447 | <para> |
| 4448 | The <filename>SourcePlugin</filename> class defines the |
| 4449 | following methods, which is the current set of methods |
| 4450 | that can be implemented or overridden by |
| 4451 | <filename>--source</filename> plugins. |
| 4452 | Any methods not implemented by a |
| 4453 | <filename>SourcePlugin</filename> subclass inherit the |
| 4454 | implementations present in the |
| 4455 | <filename>SourcePlugin</filename> class. |
| 4456 | For more information, see the |
| 4457 | <filename>SourcePlugin</filename> source for details: |
| 4458 | </para> |
| 4459 | |
| 4460 | <para> |
| 4461 | <itemizedlist> |
| 4462 | <listitem><para><emphasis><filename>do_prepare_partition()</filename>:</emphasis> |
| 4463 | Called to do the actual content population for a |
| 4464 | partition. |
| 4465 | In other words, the method prepares the final |
| 4466 | partition image that is incorporated into the |
| 4467 | disk image. |
| 4468 | </para></listitem> |
| 4469 | <listitem><para><emphasis><filename>do_configure_partition()</filename>:</emphasis> |
| 4470 | Called before |
| 4471 | <filename>do_prepare_partition()</filename>. |
| 4472 | This method is typically used to create custom |
| 4473 | configuration files for a partition (e.g. syslinux or |
| 4474 | grub configuration files). |
| 4475 | </para></listitem> |
| 4476 | <listitem><para><emphasis><filename>do_install_disk()</filename>:</emphasis> |
| 4477 | Called after all partitions have been prepared and |
| 4478 | assembled into a disk image. |
| 4479 | This method provides a hook to allow finalization of a |
| 4480 | disk image, (e.g. writing an MBR). |
| 4481 | </para></listitem> |
| 4482 | <listitem><para><emphasis><filename>do_stage_partition()</filename>:</emphasis> |
| 4483 | Special content-staging hook called before |
| 4484 | <filename>do_prepare_partition()</filename>. |
| 4485 | This method is normally empty.</para> |
| 4486 | <para>Typically, a partition just uses the passed-in |
| 4487 | parameters (e.g. the unmodified value of |
| 4488 | <filename>bootimg_dir</filename>). |
| 4489 | However, in some cases things might need to be |
| 4490 | more tailored. |
| 4491 | As an example, certain files might additionally |
| 4492 | need to be taken from |
| 4493 | <filename>bootimg_dir + /boot</filename>. |
| 4494 | This hook allows those files to be staged in a |
| 4495 | customized fashion. |
| 4496 | <note> |
| 4497 | <filename>get_bitbake_var()</filename> |
| 4498 | allows you to access non-standard variables |
| 4499 | that you might want to use for this. |
| 4500 | </note> |
| 4501 | </para></listitem> |
| 4502 | </itemizedlist> |
| 4503 | </para> |
| 4504 | |
| 4505 | <para> |
| 4506 | This scheme is extensible. |
| 4507 | Adding more hooks is a simple matter of adding more |
| 4508 | plugin methods to <filename>SourcePlugin</filename> and |
| 4509 | derived classes. |
| 4510 | The code that then needs to call the plugin methods uses |
| 4511 | <filename>plugin.get_source_plugin_methods()</filename> |
| 4512 | to find the method or methods needed by the call. |
| 4513 | Retrieval of those methods is accomplished |
| 4514 | by filling up a dict with keys |
| 4515 | containing the method names of interest. |
| 4516 | On success, these will be filled in with the actual |
| 4517 | methods. |
| 4518 | Please see the <filename>wic</filename> |
| 4519 | implementation for examples and details. |
| 4520 | </para> |
| 4521 | </section> |
| 4522 | |
| 4523 | <section id='openembedded-kickstart-wks-reference'> |
| 4524 | <title>OpenEmbedded Kickstart (.wks) Reference</title> |
| 4525 | |
| 4526 | <para> |
| 4527 | The current <filename>wic</filename> implementation supports |
| 4528 | only the basic kickstart partitioning commands: |
| 4529 | <filename>partition</filename> (or <filename>part</filename> |
| 4530 | for short) and <filename>bootloader</filename>. |
| 4531 | <note> |
| 4532 | Future updates will implement more commands and options. |
| 4533 | If you use anything that is not specifically |
| 4534 | supported, results can be unpredictable. |
| 4535 | </note> |
| 4536 | </para> |
| 4537 | |
| 4538 | <para> |
| 4539 | The following is a list of the commands, their syntax, |
| 4540 | and meanings. |
| 4541 | The commands are based on the Fedora |
| 4542 | kickstart versions but with modifications to |
| 4543 | reflect <filename>wic</filename> capabilities. |
| 4544 | You can see the original documentation for those commands |
| 4545 | at the following links: |
| 4546 | <itemizedlist> |
| 4547 | <listitem><para> |
| 4548 | <ulink url='http://fedoraproject.org/wiki/Anaconda/Kickstart#part_or_partition'>http://fedoraproject.org/wiki/Anaconda/Kickstart#part_or_partition</ulink> |
| 4549 | </para></listitem> |
| 4550 | <listitem><para> |
| 4551 | <ulink url='http://fedoraproject.org/wiki/Anaconda/Kickstart#bootloader'>http://fedoraproject.org/wiki/Anaconda/Kickstart#bootloader</ulink> |
| 4552 | </para></listitem> |
| 4553 | </itemizedlist> |
| 4554 | </para> |
| 4555 | |
| 4556 | <section id='command-part-or-partition'> |
| 4557 | <title>Command: part or partition</title> |
| 4558 | |
| 4559 | <para> |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 4560 | Either of these commands create a partition on the system |
| 4561 | and uses the following syntax: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4562 | <literallayout class='monospaced'> |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 4563 | part [<replaceable>mntpoint</replaceable>] |
| 4564 | partition [<replaceable>mntpoint</replaceable>] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4565 | </literallayout> |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 4566 | If you do not provide |
| 4567 | <replaceable>mntpoint</replaceable>, wic creates a partition |
| 4568 | but does not mount it. |
| 4569 | </para> |
| 4570 | |
| 4571 | <para> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4572 | The <filename><replaceable>mntpoint</replaceable></filename> |
| 4573 | is where the |
| 4574 | partition will be mounted and must be of one of the |
| 4575 | following forms: |
| 4576 | <itemizedlist> |
| 4577 | <listitem><para><filename>/<replaceable>path</replaceable></filename>: |
| 4578 | For example, <filename>/</filename>, |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 4579 | <filename>/usr</filename>, or |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4580 | <filename>/home</filename></para></listitem> |
| 4581 | <listitem><para><filename>swap</filename>: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 4582 | The created partition is used as swap space. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4583 | </para></listitem> |
| 4584 | </itemizedlist> |
| 4585 | </para> |
| 4586 | |
| 4587 | <para> |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 4588 | Specifying a <replaceable>mntpoint</replaceable> causes |
| 4589 | the partition to automatically be mounted. |
| 4590 | Wic achieves this by adding entries to the filesystem |
| 4591 | table (fstab) during image generation. |
| 4592 | In order for wic to generate a valid fstab, you must |
| 4593 | also provide one of the <filename>--ondrive</filename>, |
| 4594 | <filename>--ondisk</filename>, or |
| 4595 | <filename>--use-uuid</filename> partition options as part |
| 4596 | of the command. |
| 4597 | Here is an example using "/" as the mountpoint. |
| 4598 | The command uses "--ondisk" to force the partition onto |
| 4599 | the <filename>sdb</filename> disk: |
| 4600 | <literallayout class='monospaced'> |
| 4601 | part / --source rootfs --ondisk sdb --fstype=ext3 --label platform --align 1024 |
| 4602 | </literallayout> |
| 4603 | </para> |
| 4604 | |
| 4605 | <para> |
| 4606 | Here is a list that describes other supported options you |
| 4607 | can use with the <filename>part</filename> and |
| 4608 | <filename>partition</filename> commands: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4609 | <itemizedlist> |
| 4610 | <listitem><para><emphasis><filename>--size</filename>:</emphasis> |
| 4611 | The minimum partition size in MBytes. |
| 4612 | Specify an integer value such as 500. |
| 4613 | Do not append the number with "MB". |
| 4614 | You do not need this option if you use |
| 4615 | <filename>--source</filename>.</para></listitem> |
| 4616 | <listitem><para><emphasis><filename>--source</filename>:</emphasis> |
| 4617 | This option is a |
| 4618 | <filename>wic</filename>-specific option that |
| 4619 | names the source of the data that populates |
| 4620 | the partition. |
| 4621 | The most common value for this option is |
| 4622 | "rootfs", but you can use any value that maps to |
| 4623 | a valid source plugin. |
| 4624 | For information on the source plugins, see the |
| 4625 | "<link linkend='openembedded-kickstart-plugins'>Plugins</link>" |
| 4626 | section.</para> |
| 4627 | <para>If you use |
| 4628 | <filename>--source rootfs</filename>, |
| 4629 | <filename>wic</filename> creates a partition as |
| 4630 | large as needed and to fill it with the contents of |
| 4631 | the root filesystem pointed to by the |
| 4632 | <filename>-r</filename> command-line option |
| 4633 | or the equivalent rootfs derived from the |
| 4634 | <filename>-e</filename> command-line |
| 4635 | option. |
| 4636 | The filesystem type used to create the |
| 4637 | partition is driven by the value of the |
| 4638 | <filename>--fstype</filename> option |
| 4639 | specified for the partition. |
| 4640 | See the entry on |
| 4641 | <filename>--fstype</filename> that |
| 4642 | follows for more information. |
| 4643 | </para> |
| 4644 | <para>If you use |
| 4645 | <filename>--source <replaceable>plugin-name</replaceable></filename>, |
| 4646 | <filename>wic</filename> creates a partition as |
| 4647 | large as needed and fills it with the contents of |
| 4648 | the partition that is generated by the |
| 4649 | specified plugin name using the data pointed |
| 4650 | to by the <filename>-r</filename> command-line |
| 4651 | option or the equivalent rootfs derived from the |
| 4652 | <filename>-e</filename> command-line |
| 4653 | option. |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 4654 | Exactly what those contents and filesystem type end |
| 4655 | up being are dependent on the given plugin |
| 4656 | implementation. |
| 4657 | </para> |
| 4658 | <para>If you do not use the |
| 4659 | <filename>--source</filename> option, the |
| 4660 | <filename>wic</filename> command creates an empty |
| 4661 | partition. |
| 4662 | Consequently, you must use the |
| 4663 | <filename>--size</filename> option to specify the |
| 4664 | size of the empty partition. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4665 | </para></listitem> |
| 4666 | <listitem><para><emphasis><filename>--ondisk</filename> or <filename>--ondrive</filename>:</emphasis> |
| 4667 | Forces the partition to be created on a particular |
| 4668 | disk.</para></listitem> |
| 4669 | <listitem><para><emphasis><filename>--fstype</filename>:</emphasis> |
| 4670 | Sets the file system type for the partition. |
| 4671 | Valid values are: |
| 4672 | <itemizedlist> |
| 4673 | <listitem><para><filename>ext4</filename> |
| 4674 | </para></listitem> |
| 4675 | <listitem><para><filename>ext3</filename> |
| 4676 | </para></listitem> |
| 4677 | <listitem><para><filename>ext2</filename> |
| 4678 | </para></listitem> |
| 4679 | <listitem><para><filename>btrfs</filename> |
| 4680 | </para></listitem> |
| 4681 | <listitem><para><filename>squashfs</filename> |
| 4682 | </para></listitem> |
| 4683 | <listitem><para><filename>swap</filename> |
| 4684 | </para></listitem> |
| 4685 | </itemizedlist></para></listitem> |
| 4686 | <listitem><para><emphasis><filename>--fsoptions</filename>:</emphasis> |
| 4687 | Specifies a free-form string of options to be |
| 4688 | used when mounting the filesystem. |
| 4689 | This string will be copied into the |
| 4690 | <filename>/etc/fstab</filename> file of the |
| 4691 | installed system and should be enclosed in |
| 4692 | quotes. |
| 4693 | If not specified, the default string |
| 4694 | is "defaults". |
| 4695 | </para></listitem> |
| 4696 | <listitem><para><emphasis><filename>--label label</filename>:</emphasis> |
| 4697 | Specifies the label to give to the filesystem to |
| 4698 | be made on the partition. |
| 4699 | If the given label is already in use by another |
| 4700 | filesystem, a new label is created for the |
| 4701 | partition.</para></listitem> |
| 4702 | <listitem><para><emphasis><filename>--active</filename>:</emphasis> |
| 4703 | Marks the partition as active.</para></listitem> |
| 4704 | <listitem><para><emphasis><filename>--align (in KBytes)</filename>:</emphasis> |
| 4705 | This option is a <filename>wic</filename>-specific |
| 4706 | option that says to start a partition on an |
| 4707 | x KBytes boundary.</para></listitem> |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 4708 | <listitem><para><emphasis><filename>--no-table</filename>:</emphasis> |
| 4709 | This option is a <filename>wic</filename>-specific |
| 4710 | option. |
| 4711 | Using the option reserves space for the partition |
| 4712 | and causes it to become populated. |
| 4713 | However, the partition is not added to the |
| 4714 | partition table. |
| 4715 | </para></listitem> |
| 4716 | <listitem><para><emphasis><filename>--extra-space</filename>:</emphasis> |
| 4717 | This option is a <filename>wic</filename>-specific |
| 4718 | option that adds extra space after the space |
| 4719 | filled by the content of the partition. |
| 4720 | The final size can go beyond the size specified |
| 4721 | by the <filename>--size</filename> option. |
| 4722 | The default value is 10 Mbytes. |
| 4723 | </para></listitem> |
| 4724 | <listitem><para><emphasis><filename>--overhead-factor</filename>:</emphasis> |
| 4725 | This option is a <filename>wic</filename>-specific |
| 4726 | option that multiplies the size of the partition by |
| 4727 | the option's value. |
| 4728 | You must supply a value greater than or equal to |
| 4729 | "1". |
| 4730 | The default value is "1.3". |
| 4731 | </para></listitem> |
| 4732 | <listitem><para><emphasis><filename>--part-type</filename>:</emphasis> |
| 4733 | This option is a <filename>wic</filename>-specific |
| 4734 | option that specifies the partition type globally |
| 4735 | unique identifier (GUID) for GPT partitions. |
| 4736 | You can find the list of partition type GUIDs |
| 4737 | at |
| 4738 | <ulink url='http://en.wikipedia.org/wiki/GUID_Partition_Table#Partition_type_GUIDs'></ulink>. |
| 4739 | </para></listitem> |
| 4740 | <listitem><para><emphasis><filename>--use-uuid</filename>:</emphasis> |
| 4741 | This option is a <filename>wic</filename>-specific |
| 4742 | option that causes <filename>wic</filename> to |
| 4743 | generate a random GUID for the partition. |
| 4744 | The generated identifier is used in the bootloader |
| 4745 | configuration to specify the root partition. |
| 4746 | </para></listitem> |
| 4747 | <listitem><para><emphasis><filename>--uuid</filename>:</emphasis> |
| 4748 | This option is a <filename>wic</filename>-specific |
| 4749 | option that specifies the partition UUID. |
| 4750 | </para></listitem> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4751 | </itemizedlist> |
| 4752 | </para> |
| 4753 | </section> |
| 4754 | |
| 4755 | <section id='command-bootloader'> |
| 4756 | <title>Command: bootloader</title> |
| 4757 | |
| 4758 | <para> |
| 4759 | This command specifies how the boot loader should be |
| 4760 | configured and supports the following options: |
| 4761 | <note> |
| 4762 | Bootloader functionality and boot partitions are |
| 4763 | implemented by the various |
| 4764 | <filename>--source</filename> |
| 4765 | plugins that implement bootloader functionality. |
| 4766 | The bootloader command essentially provides a means of |
| 4767 | modifying bootloader configuration. |
| 4768 | </note> |
| 4769 | <itemizedlist> |
| 4770 | <listitem><para><emphasis><filename>--timeout</filename>:</emphasis> |
| 4771 | Specifies the number of seconds before the |
| 4772 | bootloader times out and boots the default option. |
| 4773 | </para></listitem> |
| 4774 | <listitem><para><emphasis><filename>--append</filename>:</emphasis> |
| 4775 | Specifies kernel parameters. |
| 4776 | These parameters will be added to the syslinux |
| 4777 | <filename>APPEND</filename> or |
| 4778 | <filename>grub</filename> kernel command line. |
| 4779 | </para></listitem> |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 4780 | <listitem><para><emphasis><filename>--configfile</filename>:</emphasis> |
| 4781 | Specifies a user-defined configuration file for |
| 4782 | the bootloader. |
| 4783 | You can provide a full pathname for the file or |
| 4784 | a file that exists in the |
| 4785 | <filename>canned-wks</filename> folder. |
| 4786 | This option overrides all other bootloader options. |
| 4787 | </para></listitem> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4788 | </itemizedlist> |
| 4789 | </para> |
| 4790 | </section> |
| 4791 | </section> |
| 4792 | </section> |
| 4793 | |
| 4794 | <section id='configuring-the-kernel'> |
| 4795 | <title>Configuring the Kernel</title> |
| 4796 | |
| 4797 | <para> |
| 4798 | Configuring the Yocto Project kernel consists of making sure the |
| 4799 | <filename>.config</filename> file has all the right information |
| 4800 | in it for the image you are building. |
| 4801 | You can use the <filename>menuconfig</filename> tool and |
| 4802 | configuration fragments to make sure your |
| 4803 | <filename>.config</filename> file is just how you need it. |
| 4804 | You can also save known configurations in a |
| 4805 | <filename>defconfig</filename> file that the build system can use |
| 4806 | for kernel configuration. |
| 4807 | </para> |
| 4808 | |
| 4809 | <para> |
| 4810 | This section describes how to use <filename>menuconfig</filename>, |
| 4811 | create and use configuration fragments, and how to interactively |
| 4812 | modify your <filename>.config</filename> file to create the |
| 4813 | leanest kernel configuration file possible. |
| 4814 | </para> |
| 4815 | |
| 4816 | <para> |
| 4817 | For more information on kernel configuration, see the |
| 4818 | "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#changing-the-configuration'>Changing the Configuration</ulink>" |
| 4819 | section in the Yocto Project Linux Kernel Development Manual. |
| 4820 | </para> |
| 4821 | |
| 4822 | <section id='using-menuconfig'> |
| 4823 | <title>Using <filename>menuconfig</filename></title> |
| 4824 | |
| 4825 | <para> |
| 4826 | The easiest way to define kernel configurations is to set them through the |
| 4827 | <filename>menuconfig</filename> tool. |
| 4828 | This tool provides an interactive method with which |
| 4829 | to set kernel configurations. |
| 4830 | For general information on <filename>menuconfig</filename>, see |
| 4831 | <ulink url='http://en.wikipedia.org/wiki/Menuconfig'></ulink>. |
| 4832 | </para> |
| 4833 | |
| 4834 | <para> |
| 4835 | To use the <filename>menuconfig</filename> tool in the Yocto Project development |
| 4836 | environment, you must launch it using BitBake. |
| 4837 | Thus, the environment must be set up using the |
| 4838 | <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink> |
| 4839 | or |
| 4840 | <ulink url='&YOCTO_DOCS_REF_URL;#structure-memres-core-script'><filename>oe-init-build-env-memres</filename></ulink> |
| 4841 | script found in the |
| 4842 | <link linkend='build-directory'>Build Directory</link>. |
| 4843 | You must also be sure of the state of your build in the |
| 4844 | <link linkend='source-directory'>Source Directory</link>. |
| 4845 | The following commands run <filename>menuconfig</filename> |
| 4846 | assuming the Source Directory's top-level folder is |
| 4847 | <filename>~/poky</filename>: |
| 4848 | <literallayout class='monospaced'> |
| 4849 | $ cd poky |
| 4850 | $ source oe-init-build-env |
| 4851 | $ bitbake linux-yocto -c kernel_configme -f |
| 4852 | $ bitbake linux-yocto -c menuconfig |
| 4853 | </literallayout> |
| 4854 | Once <filename>menuconfig</filename> comes up, its standard |
| 4855 | interface allows you to interactively examine and configure |
| 4856 | all the kernel configuration parameters. |
| 4857 | After making your changes, simply exit the tool and save your |
| 4858 | changes to create an updated version of the |
| 4859 | <filename>.config</filename> configuration file. |
| 4860 | </para> |
| 4861 | |
| 4862 | <para> |
| 4863 | Consider an example that configures the <filename>linux-yocto-3.14</filename> |
| 4864 | kernel. |
| 4865 | The OpenEmbedded build system recognizes this kernel as |
| 4866 | <filename>linux-yocto</filename>. |
| 4867 | Thus, the following commands from the shell in which you previously sourced the |
| 4868 | environment initialization script cleans the shared state cache and the |
| 4869 | <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink> |
| 4870 | directory and then runs <filename>menuconfig</filename>: |
| 4871 | <literallayout class='monospaced'> |
| 4872 | $ bitbake linux-yocto -c menuconfig |
| 4873 | </literallayout> |
| 4874 | </para> |
| 4875 | |
| 4876 | <para> |
| 4877 | Once <filename>menuconfig</filename> launches, use the interface |
| 4878 | to navigate through the selections to find the configuration settings in |
| 4879 | which you are interested. |
| 4880 | For example, consider the <filename>CONFIG_SMP</filename> configuration setting. |
| 4881 | You can find it at <filename>Processor Type and Features</filename> under |
| 4882 | the configuration selection <filename>Symmetric Multi-processing Support</filename>. |
| 4883 | After highlighting the selection, use the arrow keys to select or deselect |
| 4884 | the setting. |
| 4885 | When you are finished with all your selections, exit out and save them. |
| 4886 | </para> |
| 4887 | |
| 4888 | <para> |
| 4889 | Saving the selections updates the <filename>.config</filename> configuration file. |
| 4890 | This is the file that the OpenEmbedded build system uses to configure the |
| 4891 | kernel during the build. |
| 4892 | You can find and examine this file in the Build Directory in |
| 4893 | <filename>tmp/work/</filename>. |
| 4894 | The actual <filename>.config</filename> is located in the area where the |
| 4895 | specific kernel is built. |
| 4896 | For example, if you were building a Linux Yocto kernel based on the |
| 4897 | Linux 3.14 kernel and you were building a QEMU image targeted for |
| 4898 | <filename>x86</filename> architecture, the |
| 4899 | <filename>.config</filename> file would be located here: |
| 4900 | <literallayout class='monospaced'> |
| 4901 | poky/build/tmp/work/qemux86-poky-linux/linux-yocto-3.14.11+git1+84f... |
| 4902 | ...656ed30-r1/linux-qemux86-standard-build |
| 4903 | </literallayout> |
| 4904 | <note> |
| 4905 | The previous example directory is artificially split and many of the characters |
| 4906 | in the actual filename are omitted in order to make it more readable. |
| 4907 | Also, depending on the kernel you are using, the exact pathname |
| 4908 | for <filename>linux-yocto-3.14...</filename> might differ. |
| 4909 | </note> |
| 4910 | </para> |
| 4911 | |
| 4912 | <para> |
| 4913 | Within the <filename>.config</filename> file, you can see the kernel settings. |
| 4914 | For example, the following entry shows that symmetric multi-processor support |
| 4915 | is not set: |
| 4916 | <literallayout class='monospaced'> |
| 4917 | # CONFIG_SMP is not set |
| 4918 | </literallayout> |
| 4919 | </para> |
| 4920 | |
| 4921 | <para> |
| 4922 | A good method to isolate changed configurations is to use a combination of the |
| 4923 | <filename>menuconfig</filename> tool and simple shell commands. |
| 4924 | Before changing configurations with <filename>menuconfig</filename>, copy the |
| 4925 | existing <filename>.config</filename> and rename it to something else, |
| 4926 | use <filename>menuconfig</filename> to make |
| 4927 | as many changes as you want and save them, then compare the renamed configuration |
| 4928 | file against the newly created file. |
| 4929 | You can use the resulting differences as your base to create configuration fragments |
| 4930 | to permanently save in your kernel layer. |
| 4931 | <note> |
| 4932 | Be sure to make a copy of the <filename>.config</filename> and don't just |
| 4933 | rename it. |
| 4934 | The build system needs an existing <filename>.config</filename> |
| 4935 | from which to work. |
| 4936 | </note> |
| 4937 | </para> |
| 4938 | </section> |
| 4939 | |
| 4940 | <section id='creating-a-defconfig-file'> |
| 4941 | <title>Creating a <filename>defconfig</filename> File</title> |
| 4942 | |
| 4943 | <para> |
| 4944 | A <filename>defconfig</filename> file is simply a |
| 4945 | <filename>.config</filename> renamed to "defconfig". |
| 4946 | You can use a <filename>defconfig</filename> file |
| 4947 | to retain a known set of kernel configurations from which the |
| 4948 | OpenEmbedded build system can draw to create the final |
| 4949 | <filename>.config</filename> file. |
| 4950 | <note> |
| 4951 | Out-of-the-box, the Yocto Project never ships a |
| 4952 | <filename>defconfig</filename> or |
| 4953 | <filename>.config</filename> file. |
| 4954 | The OpenEmbedded build system creates the final |
| 4955 | <filename>.config</filename> file used to configure the |
| 4956 | kernel. |
| 4957 | </note> |
| 4958 | </para> |
| 4959 | |
| 4960 | <para> |
| 4961 | To create a <filename>defconfig</filename>, start with a |
| 4962 | complete, working Linux kernel <filename>.config</filename> |
| 4963 | file. |
| 4964 | Copy that file to the appropriate |
| 4965 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename> |
| 4966 | directory in your layer's |
| 4967 | <filename>recipes-kernel/linux</filename> directory, and rename |
| 4968 | the copied file to "defconfig". |
| 4969 | Then, add the following lines to the linux-yocto |
| 4970 | <filename>.bbappend</filename> file in your layer: |
| 4971 | <literallayout class='monospaced'> |
| 4972 | FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" |
| 4973 | SRC_URI += "file://defconfig" |
| 4974 | </literallayout> |
| 4975 | The |
| 4976 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> |
| 4977 | tells the build system how to search for the file, while the |
| 4978 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink> |
| 4979 | extends the |
| 4980 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink> |
| 4981 | variable (search directories) to include the |
| 4982 | <filename>${PN}</filename> directory you created to hold the |
| 4983 | configuration changes. |
| 4984 | <note> |
| 4985 | The build system applies the configurations from the |
| 4986 | <filename>defconfig</filename> file before applying any |
| 4987 | subsequent configuration fragments. |
| 4988 | The final kernel configuration is a combination of the |
| 4989 | configurations in the <filename>defconfig</filename> |
| 4990 | file and any configuration fragments you provide. |
| 4991 | You need to realize that if you have any configuration |
| 4992 | fragments, the build system applies these on top of and |
| 4993 | after applying the existing defconfig file configurations. |
| 4994 | </note> |
| 4995 | For more information on configuring the kernel, see the |
| 4996 | "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#changing-the-configuration'>Changing the Configuration</ulink>" |
| 4997 | and |
| 4998 | "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#generating-configuration-files'>Generating Configuration Files</ulink>" |
| 4999 | sections, both in the Yocto Project Linux Kernel Development |
| 5000 | Manual. |
| 5001 | </para> |
| 5002 | </section> |
| 5003 | |
| 5004 | <section id='creating-config-fragments'> |
| 5005 | <title>Creating Configuration Fragments</title> |
| 5006 | |
| 5007 | <para> |
| 5008 | Configuration fragments are simply kernel options that appear in a file |
| 5009 | placed where the OpenEmbedded build system can find and apply them. |
| 5010 | Syntactically, the configuration statement is identical to what would appear |
| 5011 | in the <filename>.config</filename> file, which is in the |
| 5012 | <link linkend='build-directory'>Build Directory</link>: |
| 5013 | <literallayout class='monospaced'> |
| 5014 | tmp/work/<replaceable>arch</replaceable>-poky-linux/linux-yocto-<replaceable>release_specific_string</replaceable>/linux-<replaceable>arch</replaceable>-<replaceable>build_type</replaceable> |
| 5015 | </literallayout> |
| 5016 | </para> |
| 5017 | |
| 5018 | <para> |
| 5019 | It is simple to create a configuration fragment. |
| 5020 | For example, issuing the following from the shell creates a configuration fragment |
| 5021 | file named <filename>my_smp.cfg</filename> that enables multi-processor support |
| 5022 | within the kernel: |
| 5023 | <literallayout class='monospaced'> |
| 5024 | $ echo "CONFIG_SMP=y" >> my_smp.cfg |
| 5025 | </literallayout> |
| 5026 | <note> |
| 5027 | All configuration fragment files must use the |
| 5028 | <filename>.cfg</filename> extension in order for the |
| 5029 | OpenEmbedded build system to recognize them as a |
| 5030 | configuration fragment. |
| 5031 | </note> |
| 5032 | </para> |
| 5033 | |
| 5034 | <para> |
| 5035 | Where do you put your configuration fragment files? |
| 5036 | You can place these files in the same area pointed to by |
| 5037 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>. |
| 5038 | The OpenEmbedded build system picks up the configuration and |
| 5039 | adds it to the kernel's configuration. |
| 5040 | For example, suppose you had a set of configuration options |
| 5041 | in a file called <filename>myconfig.cfg</filename>. |
| 5042 | If you put that file inside a directory named |
| 5043 | <filename>linux-yocto</filename> that resides in the same |
| 5044 | directory as the kernel's append file and then add a |
| 5045 | <filename>SRC_URI</filename> statement such as the following |
| 5046 | to the kernel's append file, those configuration options |
| 5047 | will be picked up and applied when the kernel is built. |
| 5048 | <literallayout class='monospaced'> |
| 5049 | SRC_URI += "file://myconfig.cfg" |
| 5050 | </literallayout> |
| 5051 | </para> |
| 5052 | |
| 5053 | <para> |
| 5054 | As mentioned earlier, you can group related configurations into multiple files and |
| 5055 | name them all in the <filename>SRC_URI</filename> statement as well. |
| 5056 | For example, you could group separate configurations specifically for Ethernet and graphics |
| 5057 | into their own files and add those by using a <filename>SRC_URI</filename> statement like the |
| 5058 | following in your append file: |
| 5059 | <literallayout class='monospaced'> |
| 5060 | SRC_URI += "file://myconfig.cfg \ |
| 5061 | file://eth.cfg \ |
| 5062 | file://gfx.cfg" |
| 5063 | </literallayout> |
| 5064 | </para> |
| 5065 | </section> |
| 5066 | |
| 5067 | <section id='fine-tuning-the-kernel-configuration-file'> |
| 5068 | <title>Fine-Tuning the Kernel Configuration File</title> |
| 5069 | |
| 5070 | <para> |
| 5071 | You can make sure the <filename>.config</filename> file is as lean or efficient as |
| 5072 | possible by reading the output of the kernel configuration fragment audit, |
| 5073 | noting any issues, making changes to correct the issues, and then repeating. |
| 5074 | </para> |
| 5075 | |
| 5076 | <para> |
| 5077 | As part of the kernel build process, the |
| 5078 | <filename>do_kernel_configcheck</filename> task runs. |
| 5079 | This task validates the kernel configuration by checking the final |
| 5080 | <filename>.config</filename> file against the input files. |
| 5081 | During the check, the task produces warning messages for the following |
| 5082 | issues: |
| 5083 | <itemizedlist> |
| 5084 | <listitem><para>Requested options that did not make the final |
| 5085 | <filename>.config</filename> file.</para></listitem> |
| 5086 | <listitem><para>Configuration items that appear twice in the same |
| 5087 | configuration fragment.</para></listitem> |
| 5088 | <listitem><para>Configuration items tagged as "required" that were overridden. |
| 5089 | </para></listitem> |
| 5090 | <listitem><para>A board overrides a non-board specific option.</para></listitem> |
| 5091 | <listitem><para>Listed options not valid for the kernel being processed. |
| 5092 | In other words, the option does not appear anywhere.</para></listitem> |
| 5093 | </itemizedlist> |
| 5094 | <note> |
| 5095 | The <filename>do_kernel_configcheck</filename> task can |
| 5096 | also optionally report if an option is overridden during |
| 5097 | processing. |
| 5098 | </note> |
| 5099 | </para> |
| 5100 | |
| 5101 | <para> |
| 5102 | For each output warning, a message points to the file |
| 5103 | that contains a list of the options and a pointer to the |
| 5104 | configuration fragment that defines them. |
| 5105 | Collectively, the files are the key to streamlining the |
| 5106 | configuration. |
| 5107 | </para> |
| 5108 | |
| 5109 | <para> |
| 5110 | To streamline the configuration, do the following: |
| 5111 | <orderedlist> |
| 5112 | <listitem><para>Start with a full configuration that you |
| 5113 | know works - it builds and boots successfully. |
| 5114 | This configuration file will be your baseline. |
| 5115 | </para></listitem> |
| 5116 | <listitem><para>Separately run the |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 5117 | <filename>do_kernel_configme</filename> and |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5118 | <filename>do_kernel_configcheck</filename> tasks. |
| 5119 | </para></listitem> |
| 5120 | <listitem><para>Take the resulting list of files from the |
| 5121 | <filename>do_kernel_configcheck</filename> task |
| 5122 | warnings and do the following: |
| 5123 | <itemizedlist> |
| 5124 | <listitem><para> |
| 5125 | Drop values that are redefined in the fragment |
| 5126 | but do not change the final |
| 5127 | <filename>.config</filename> file. |
| 5128 | </para></listitem> |
| 5129 | <listitem><para> |
| 5130 | Analyze and potentially drop values from the |
| 5131 | <filename>.config</filename> file that override |
| 5132 | required configurations. |
| 5133 | </para></listitem> |
| 5134 | <listitem><para> |
| 5135 | Analyze and potentially remove non-board |
| 5136 | specific options. |
| 5137 | </para></listitem> |
| 5138 | <listitem><para> |
| 5139 | Remove repeated and invalid options. |
| 5140 | </para></listitem> |
| 5141 | </itemizedlist></para></listitem> |
| 5142 | <listitem><para> |
| 5143 | After you have worked through the output of the kernel |
| 5144 | configuration audit, you can re-run the |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 5145 | <filename>do_kernel_configme</filename> and |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5146 | <filename>do_kernel_configcheck</filename> tasks to |
| 5147 | see the results of your changes. |
| 5148 | If you have more issues, you can deal with them as |
| 5149 | described in the previous step. |
| 5150 | </para></listitem> |
| 5151 | </orderedlist> |
| 5152 | </para> |
| 5153 | |
| 5154 | <para> |
| 5155 | Iteratively working through steps two through four eventually yields |
| 5156 | a minimal, streamlined configuration file. |
| 5157 | Once you have the best <filename>.config</filename>, you can build the Linux |
| 5158 | Yocto kernel. |
| 5159 | </para> |
| 5160 | </section> |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 5161 | |
| 5162 | <section id='determining-hardware-and-non-hardware-features-for-the-kernel-configuration-audit-phase'> |
| 5163 | <title>Determining Hardware and Non-Hardware Features for the Kernel Configuration Audit Phase</title> |
| 5164 | |
| 5165 | <para> |
| 5166 | This section describes part of the kernel configuration audit |
| 5167 | phase that most developers can ignore. |
| 5168 | During this part of the audit phase, the contents of the final |
| 5169 | <filename>.config</filename> file are compared against the |
| 5170 | fragments specified by the system. |
| 5171 | These fragments can be system fragments, distro fragments, |
| 5172 | or user specified configuration elements. |
| 5173 | Regardless of their origin, the OpenEmbedded build system |
| 5174 | warns the user if a specific option is not included in the |
| 5175 | final kernel configuration. |
| 5176 | </para> |
| 5177 | |
| 5178 | <para> |
| 5179 | In order to not overwhelm the user with configuration warnings, |
| 5180 | by default the system only reports on missing "hardware" |
| 5181 | options because a missing hardware option could mean a boot |
| 5182 | failure or that important hardware is not available. |
| 5183 | </para> |
| 5184 | |
| 5185 | <para> |
| 5186 | To determine whether or not a given option is "hardware" or |
| 5187 | "non-hardware", the kernel Metadata contains files that |
| 5188 | classify individual or groups of options as either hardware |
| 5189 | or non-hardware. |
| 5190 | To better show this, consider a situation where the |
| 5191 | Yocto Project kernel cache contains the following files: |
| 5192 | <literallayout class='monospaced'> |
| 5193 | kernel-cache/features/drm-psb/hardware.cfg |
| 5194 | kernel-cache/features/kgdb/hardware.cfg |
| 5195 | kernel-cache/ktypes/base/hardware.cfg |
| 5196 | kernel-cache/bsp/mti-malta32/hardware.cfg |
| 5197 | kernel-cache/bsp/fsl-mpc8315e-rdb/hardware.cfg |
| 5198 | kernel-cache/bsp/qemu-ppc32/hardware.cfg |
| 5199 | kernel-cache/bsp/qemuarma9/hardware.cfg |
| 5200 | kernel-cache/bsp/mti-malta64/hardware.cfg |
| 5201 | kernel-cache/bsp/arm-versatile-926ejs/hardware.cfg |
| 5202 | kernel-cache/bsp/common-pc/hardware.cfg |
| 5203 | kernel-cache/bsp/common-pc-64/hardware.cfg |
| 5204 | kernel-cache/features/rfkill/non-hardware.cfg |
| 5205 | kernel-cache/ktypes/base/non-hardware.cfg |
| 5206 | kernel-cache/features/aufs/non-hardware.kcf |
| 5207 | kernel-cache/features/ocf/non-hardware.kcf |
| 5208 | kernel-cache/ktypes/base/non-hardware.kcf |
| 5209 | kernel-cache/ktypes/base/hardware.kcf |
| 5210 | kernel-cache/bsp/qemu-ppc32/hardware.kcf |
| 5211 | </literallayout> |
| 5212 | The following list provides explanations for the various |
| 5213 | files: |
| 5214 | <itemizedlist> |
| 5215 | <listitem><para><filename>hardware.kcf</filename>: |
| 5216 | Specifies a list of kernel Kconfig files that contain |
| 5217 | hardware options only. |
| 5218 | </para></listitem> |
| 5219 | <listitem><para><filename>non-hardware.kcf</filename>: |
| 5220 | Specifies a list of kernel Kconfig files that contain |
| 5221 | non-hardware options only. |
| 5222 | </para></listitem> |
| 5223 | <listitem><para><filename>hardware.cfg</filename>: |
| 5224 | Specifies a list of kernel |
| 5225 | <filename>CONFIG_</filename> options that are hardware, |
| 5226 | regardless of whether or not they are within a Kconfig |
| 5227 | file specified by a hardware or non-hardware |
| 5228 | Kconfig file (i.e. <filename>hardware.kcf</filename> or |
| 5229 | <filename>non-hardware.kcf</filename>). |
| 5230 | </para></listitem> |
| 5231 | <listitem><para><filename>non-hardware.cfg</filename>: |
| 5232 | Specifies a list of kernel |
| 5233 | <filename>CONFIG_</filename> options that are |
| 5234 | not hardware, regardless of whether or not they are |
| 5235 | within a Kconfig file specified by a hardware or |
| 5236 | non-hardware Kconfig file (i.e. |
| 5237 | <filename>hardware.kcf</filename> or |
| 5238 | <filename>non-hardware.kcf</filename>). |
| 5239 | </para></listitem> |
| 5240 | </itemizedlist> |
| 5241 | Here is a specific example using the |
| 5242 | <filename>kernel-cache/bsp/mti-malta32/hardware.cfg</filename>: |
| 5243 | <literallayout class='monospaced'> |
| 5244 | CONFIG_SERIAL_8250 |
| 5245 | CONFIG_SERIAL_8250_CONSOLE |
| 5246 | CONFIG_SERIAL_8250_NR_UARTS |
| 5247 | CONFIG_SERIAL_8250_PCI |
| 5248 | CONFIG_SERIAL_CORE |
| 5249 | CONFIG_SERIAL_CORE_CONSOLE |
| 5250 | CONFIG_VGA_ARB |
| 5251 | </literallayout> |
| 5252 | The kernel configuration audit automatically detects these |
| 5253 | files (hence the names must be exactly the ones discussed here), |
| 5254 | and uses them as inputs when generating warnings about the |
| 5255 | final <filename>.config</filename> file. |
| 5256 | </para> |
| 5257 | |
| 5258 | <para> |
| 5259 | A user-specified kernel Metadata repository, or recipe space |
| 5260 | feature, can use these same files to classify options that are |
| 5261 | found within its <filename>.cfg</filename> files as hardware |
| 5262 | or non-hardware, to prevent the OpenEmbedded build system from |
| 5263 | producing an error or warning when an option is not in the |
| 5264 | final <filename>.config</filename> file. |
| 5265 | </para> |
| 5266 | </section> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5267 | </section> |
| 5268 | |
| 5269 | <section id="patching-the-kernel"> |
| 5270 | <title>Patching the Kernel</title> |
| 5271 | |
| 5272 | <para> |
| 5273 | Patching the kernel involves changing or adding configurations to an existing kernel, |
| 5274 | changing or adding recipes to the kernel that are needed to support specific hardware features, |
| 5275 | or even altering the source code itself. |
| 5276 | <note> |
| 5277 | You can use the <filename>yocto-kernel</filename> script |
| 5278 | found in the <link linkend='source-directory'>Source Directory</link> |
| 5279 | under <filename>scripts</filename> to manage kernel patches and configuration. |
| 5280 | See the "<ulink url='&YOCTO_DOCS_BSP_URL;#managing-kernel-patches-and-config-items-with-yocto-kernel'>Managing kernel Patches and Config Items with yocto-kernel</ulink>" |
| 5281 | section in the Yocto Project Board Support Packages (BSP) Developer's Guide for |
| 5282 | more information.</note> |
| 5283 | </para> |
| 5284 | |
| 5285 | <para> |
| 5286 | This example creates a simple patch by adding some QEMU emulator console |
| 5287 | output at boot time through <filename>printk</filename> statements in the kernel's |
| 5288 | <filename>calibrate.c</filename> source code file. |
| 5289 | Applying the patch and booting the modified image causes the added |
| 5290 | messages to appear on the emulator's console. |
| 5291 | </para> |
| 5292 | |
| 5293 | <para> |
| 5294 | The example assumes a clean build exists for the <filename>qemux86</filename> |
| 5295 | machine in a |
| 5296 | <link linkend='source-directory'>Source Directory</link> |
| 5297 | named <filename>poky</filename>. |
| 5298 | Furthermore, the <link linkend='build-directory'>Build Directory</link> is |
| 5299 | <filename>build</filename> and is located in <filename>poky</filename> and |
| 5300 | the kernel is based on the Linux 3.4 kernel. |
| 5301 | </para> |
| 5302 | |
| 5303 | <para> |
| 5304 | Also, for more information on patching the kernel, see the |
| 5305 | "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#applying-patches'>Applying Patches</ulink>" |
| 5306 | section in the Yocto Project Linux Kernel Development Manual. |
| 5307 | </para> |
| 5308 | |
| 5309 | <section id='create-a-layer-for-your-changes'> |
| 5310 | <title>Create a Layer for your Changes</title> |
| 5311 | |
| 5312 | <para> |
| 5313 | The first step is to create a layer so you can isolate your |
| 5314 | changes. |
| 5315 | Rather than use the <filename>yocto-layer</filename> script |
| 5316 | to create the layer, this example steps through the process |
| 5317 | by hand. |
| 5318 | If you want information on the script that creates a general |
| 5319 | layer, see the |
| 5320 | "<link linkend='creating-a-general-layer-using-the-yocto-layer-script'>Creating a General Layer Using the yocto-layer Script</link>" |
| 5321 | section. |
| 5322 | </para> |
| 5323 | |
| 5324 | <para> |
| 5325 | These two commands create a directory you can use for your |
| 5326 | layer: |
| 5327 | <literallayout class='monospaced'> |
| 5328 | $ cd ~/poky |
| 5329 | $ mkdir meta-mylayer |
| 5330 | </literallayout> |
| 5331 | Creating a directory that follows the Yocto Project layer naming |
| 5332 | conventions sets up the layer for your changes. |
| 5333 | The layer is where you place your configuration files, append |
| 5334 | files, and patch files. |
| 5335 | To learn more about creating a layer and filling it with the |
| 5336 | files you need, see the "<link linkend='understanding-and-creating-layers'>Understanding |
| 5337 | and Creating Layers</link>" section. |
| 5338 | </para> |
| 5339 | </section> |
| 5340 | |
| 5341 | <section id='finding-the-kernel-source-code'> |
| 5342 | <title>Finding the Kernel Source Code</title> |
| 5343 | |
| 5344 | <para> |
| 5345 | Each time you build a kernel image, the kernel source code is fetched |
| 5346 | and unpacked into the following directory: |
| 5347 | <literallayout class='monospaced'> |
| 5348 | ${S}/linux |
| 5349 | </literallayout> |
| 5350 | See the "<link linkend='finding-the-temporary-source-code'>Finding Temporary Source Code</link>" |
| 5351 | section and the |
| 5352 | <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink> variable |
| 5353 | for more information about where source is kept during a build. |
| 5354 | </para> |
| 5355 | |
| 5356 | <para> |
| 5357 | For this example, we are going to patch the |
| 5358 | <filename>init/calibrate.c</filename> file |
| 5359 | by adding some simple console <filename>printk</filename> statements that we can |
| 5360 | see when we boot the image using QEMU. |
| 5361 | </para> |
| 5362 | </section> |
| 5363 | |
| 5364 | <section id='creating-the-patch'> |
| 5365 | <title>Creating the Patch</title> |
| 5366 | |
| 5367 | <para> |
| 5368 | Two methods exist by which you can create the patch: |
| 5369 | <link linkend='using-devtool-in-your-workflow'><filename>devtool</filename></link> and |
| 5370 | <link linkend='using-a-quilt-workflow'>Quilt</link>. |
| 5371 | For kernel patches, the Git workflow is more appropriate. |
| 5372 | This section assumes the Git workflow and shows the steps specific to |
| 5373 | this example. |
| 5374 | <orderedlist> |
| 5375 | <listitem><para><emphasis>Change the working directory</emphasis>: |
| 5376 | Change to where the kernel source code is before making |
| 5377 | your edits to the <filename>calibrate.c</filename> file: |
| 5378 | <literallayout class='monospaced'> |
| 5379 | $ cd ~/poky/build/tmp/work/qemux86-poky-linux/linux-yocto-${PV}-${PR}/linux |
| 5380 | </literallayout> |
| 5381 | Because you are working in an established Git repository, |
| 5382 | you must be in this directory in order to commit your changes |
| 5383 | and create the patch file. |
| 5384 | <note>The <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink> and |
| 5385 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink> variables |
| 5386 | represent the version and revision for the |
| 5387 | <filename>linux-yocto</filename> recipe. |
| 5388 | The <filename>PV</filename> variable includes the Git meta and machine |
| 5389 | hashes, which make the directory name longer than you might |
| 5390 | expect. |
| 5391 | </note></para></listitem> |
| 5392 | <listitem><para><emphasis>Edit the source file</emphasis>: |
| 5393 | Edit the <filename>init/calibrate.c</filename> file to have the |
| 5394 | following changes: |
| 5395 | <literallayout class='monospaced'> |
| 5396 | void calibrate_delay(void) |
| 5397 | { |
| 5398 | unsigned long lpj; |
| 5399 | static bool printed; |
| 5400 | int this_cpu = smp_processor_id(); |
| 5401 | |
| 5402 | printk("*************************************\n"); |
| 5403 | printk("* *\n"); |
| 5404 | printk("* HELLO YOCTO KERNEL *\n"); |
| 5405 | printk("* *\n"); |
| 5406 | printk("*************************************\n"); |
| 5407 | |
| 5408 | if (per_cpu(cpu_loops_per_jiffy, this_cpu)) { |
| 5409 | . |
| 5410 | . |
| 5411 | . |
| 5412 | </literallayout></para></listitem> |
| 5413 | <listitem><para><emphasis>Stage and commit your changes</emphasis>: |
| 5414 | These Git commands display the modified file, stage it, and then |
| 5415 | commit the file: |
| 5416 | <literallayout class='monospaced'> |
| 5417 | $ git status |
| 5418 | $ git add init/calibrate.c |
| 5419 | $ git commit -m "calibrate: Add printk example" |
| 5420 | </literallayout></para></listitem> |
| 5421 | <listitem><para><emphasis>Generate the patch file</emphasis>: |
| 5422 | This Git command creates the a patch file named |
| 5423 | <filename>0001-calibrate-Add-printk-example.patch</filename> |
| 5424 | in the current directory. |
| 5425 | <literallayout class='monospaced'> |
| 5426 | $ git format-patch -1 |
| 5427 | </literallayout> |
| 5428 | </para></listitem> |
| 5429 | </orderedlist> |
| 5430 | </para> |
| 5431 | </section> |
| 5432 | |
| 5433 | <section id='set-up-your-layer-for-the-build'> |
| 5434 | <title>Set Up Your Layer for the Build</title> |
| 5435 | |
| 5436 | <para>These steps get your layer set up for the build: |
| 5437 | <orderedlist> |
| 5438 | <listitem><para><emphasis>Create additional structure</emphasis>: |
| 5439 | Create the additional layer structure: |
| 5440 | <literallayout class='monospaced'> |
| 5441 | $ cd ~/poky/meta-mylayer |
| 5442 | $ mkdir conf |
| 5443 | $ mkdir recipes-kernel |
| 5444 | $ mkdir recipes-kernel/linux |
| 5445 | $ mkdir recipes-kernel/linux/linux-yocto |
| 5446 | </literallayout> |
| 5447 | The <filename>conf</filename> directory holds your configuration files, while the |
| 5448 | <filename>recipes-kernel</filename> directory holds your append file and |
| 5449 | your patch file.</para></listitem> |
| 5450 | <listitem><para><emphasis>Create the layer configuration file</emphasis>: |
| 5451 | Move to the <filename>meta-mylayer/conf</filename> directory and create |
| 5452 | the <filename>layer.conf</filename> file as follows: |
| 5453 | <literallayout class='monospaced'> |
| 5454 | # We have a conf and classes directory, add to BBPATH |
| 5455 | BBPATH .= ":${LAYERDIR}" |
| 5456 | |
| 5457 | # We have recipes-* directories, add to BBFILES |
| 5458 | BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \ |
| 5459 | ${LAYERDIR}/recipes-*/*/*.bbappend" |
| 5460 | |
| 5461 | BBFILE_COLLECTIONS += "mylayer" |
| 5462 | BBFILE_PATTERN_mylayer = "^${LAYERDIR}/" |
| 5463 | BBFILE_PRIORITY_mylayer = "5" |
| 5464 | </literallayout> |
| 5465 | Notice <filename>mylayer</filename> as part of the last three |
| 5466 | statements.</para></listitem> |
| 5467 | <listitem><para><emphasis>Create the kernel recipe append file</emphasis>: |
| 5468 | Move to the <filename>meta-mylayer/recipes-kernel/linux</filename> directory and create |
| 5469 | the <filename>linux-yocto_3.4.bbappend</filename> file as follows: |
| 5470 | <literallayout class='monospaced'> |
| 5471 | FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" |
| 5472 | |
| 5473 | SRC_URI += "file://0001-calibrate-Add-printk-example.patch" |
| 5474 | </literallayout> |
| 5475 | The <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink> |
| 5476 | and <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> |
| 5477 | statements enable the OpenEmbedded build system to find the patch file. |
| 5478 | For more information on using append files, see the |
| 5479 | "<link linkend='using-bbappend-files'>Using .bbappend Files</link>" |
| 5480 | section. |
| 5481 | </para></listitem> |
| 5482 | <listitem><para><emphasis>Put the patch file in your layer</emphasis>: |
| 5483 | Move the <filename>0001-calibrate-Add-printk-example.patch</filename> file to |
| 5484 | the <filename>meta-mylayer/recipes-kernel/linux/linux-yocto</filename> |
| 5485 | directory.</para></listitem> |
| 5486 | </orderedlist> |
| 5487 | </para> |
| 5488 | </section> |
| 5489 | |
| 5490 | <section id='set-up-for-the-build'> |
| 5491 | <title>Set Up for the Build</title> |
| 5492 | |
| 5493 | <para> |
| 5494 | Do the following to make sure the build parameters are set up for the example. |
| 5495 | Once you set up these build parameters, they do not have to change unless you |
| 5496 | change the target architecture of the machine you are building: |
| 5497 | <itemizedlist> |
| 5498 | <listitem><para><emphasis>Build for the correct target architecture:</emphasis> Your |
| 5499 | selected <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink> |
| 5500 | definition within the <filename>local.conf</filename> file in the |
| 5501 | <link linkend='build-directory'>Build Directory</link> |
| 5502 | specifies the target architecture used when building the Linux kernel. |
| 5503 | By default, <filename>MACHINE</filename> is set to |
| 5504 | <filename>qemux86</filename>, which specifies a 32-bit |
| 5505 | <trademark class='registered'>Intel</trademark> Architecture |
| 5506 | target machine suitable for the QEMU emulator.</para></listitem> |
| 5507 | <listitem><para><emphasis>Identify your <filename>meta-mylayer</filename> |
| 5508 | layer:</emphasis> The |
| 5509 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'><filename>BBLAYERS</filename></ulink> |
| 5510 | variable in the |
| 5511 | <filename>bblayers.conf</filename> file found in the |
| 5512 | <filename>poky/build/conf</filename> directory needs to have the path to your local |
| 5513 | <filename>meta-mylayer</filename> layer. |
| 5514 | By default, the <filename>BBLAYERS</filename> variable contains paths to |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 5515 | <filename>meta</filename>, <filename>meta-poky</filename>, and |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5516 | <filename>meta-yocto-bsp</filename> in the |
| 5517 | <filename>poky</filename> Git repository. |
| 5518 | Add the path to your <filename>meta-mylayer</filename> location: |
| 5519 | <literallayout class='monospaced'> |
| 5520 | BBLAYERS ?= " \ |
| 5521 | $HOME/poky/meta \ |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 5522 | $HOME/poky/meta-poky \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5523 | $HOME/poky/meta-yocto-bsp \ |
| 5524 | $HOME/poky/meta-mylayer \ |
| 5525 | " |
| 5526 | </literallayout></para></listitem> |
| 5527 | </itemizedlist> |
| 5528 | </para> |
| 5529 | </section> |
| 5530 | |
| 5531 | <section id='build-the-modified-qemu-kernel-image'> |
| 5532 | <title>Build the Modified QEMU Kernel Image</title> |
| 5533 | |
| 5534 | <para> |
| 5535 | The following steps build your modified kernel image: |
| 5536 | <orderedlist> |
| 5537 | <listitem><para><emphasis>Be sure your build environment is initialized</emphasis>: |
| 5538 | Your environment should be set up since you previously sourced |
| 5539 | the |
| 5540 | <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink> |
| 5541 | script. |
| 5542 | If it is not, source the script again from <filename>poky</filename>. |
| 5543 | <literallayout class='monospaced'> |
| 5544 | $ cd ~/poky |
| 5545 | $ source &OE_INIT_FILE; |
| 5546 | </literallayout> |
| 5547 | </para></listitem> |
| 5548 | <listitem><para><emphasis>Clean up</emphasis>: |
| 5549 | Be sure to clean the shared state out by using BitBake |
| 5550 | to run from within the Build Directory the |
| 5551 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-cleansstate'><filename>do_cleansstate</filename></ulink> |
| 5552 | task as follows: |
| 5553 | <literallayout class='monospaced'> |
| 5554 | $ bitbake -c cleansstate linux-yocto |
| 5555 | </literallayout></para> |
| 5556 | <para> |
| 5557 | <note> |
| 5558 | Never remove any files by hand from the |
| 5559 | <filename>tmp/deploy</filename> |
| 5560 | directory inside the |
| 5561 | <link linkend='build-directory'>Build Directory</link>. |
| 5562 | Always use the various BitBake clean tasks to |
| 5563 | clear out previous build artifacts. |
| 5564 | For information on the clean tasks, see the |
| 5565 | "<ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-clean'><filename>do_clean</filename></ulink>", |
| 5566 | "<ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-cleanall'><filename>do_cleanall</filename></ulink>", |
| 5567 | and |
| 5568 | "<ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-cleansstate'><filename>do_cleansstate</filename></ulink>" |
| 5569 | sections all in the Yocto Project Reference |
| 5570 | Manual. |
| 5571 | </note> |
| 5572 | </para></listitem> |
| 5573 | <listitem><para><emphasis>Build the image</emphasis>: |
| 5574 | Next, build the kernel image using this command: |
| 5575 | <literallayout class='monospaced'> |
| 5576 | $ bitbake -k linux-yocto |
| 5577 | </literallayout></para></listitem> |
| 5578 | </orderedlist> |
| 5579 | </para> |
| 5580 | </section> |
| 5581 | |
| 5582 | <section id='boot-the-image-and-verify-your-changes'> |
| 5583 | <title>Boot the Image and Verify Your Changes</title> |
| 5584 | |
| 5585 | <para> |
| 5586 | These steps boot the image and allow you to see the changes |
| 5587 | <orderedlist> |
| 5588 | <listitem><para><emphasis>Boot the image</emphasis>: |
| 5589 | Boot the modified image in the QEMU emulator |
| 5590 | using this command: |
| 5591 | <literallayout class='monospaced'> |
| 5592 | $ runqemu qemux86 |
| 5593 | </literallayout></para></listitem> |
| 5594 | <listitem><para><emphasis>Verify the changes</emphasis>: |
| 5595 | Log into the machine using <filename>root</filename> with no password and then |
| 5596 | use the following shell command to scroll through the console's boot output. |
| 5597 | <literallayout class='monospaced'> |
| 5598 | # dmesg | less |
| 5599 | </literallayout> |
| 5600 | You should see the results of your <filename>printk</filename> statements |
| 5601 | as part of the output.</para></listitem> |
| 5602 | </orderedlist> |
| 5603 | </para> |
| 5604 | </section> |
| 5605 | </section> |
| 5606 | |
| 5607 | <section id='making-images-more-secure'> |
| 5608 | <title>Making Images More Secure</title> |
| 5609 | |
| 5610 | <para> |
| 5611 | Security is of increasing concern for embedded devices. |
| 5612 | Consider the issues and problems discussed in just this |
| 5613 | sampling of work found across the Internet: |
| 5614 | <itemizedlist> |
| 5615 | <listitem><para><emphasis> |
| 5616 | "<ulink url='https://www.schneier.com/blog/archives/2014/01/security_risks_9.html'>Security Risks of Embedded Systems</ulink>"</emphasis> |
| 5617 | by Bruce Schneier |
| 5618 | </para></listitem> |
| 5619 | <listitem><para><emphasis> |
| 5620 | "<ulink url='http://internetcensus2012.bitbucket.org/paper.html'>Internet Census 2012</ulink>"</emphasis> |
| 5621 | by Carna Botnet</para></listitem> |
| 5622 | <listitem><para><emphasis> |
| 5623 | "<ulink url='http://elinux.org/images/6/6f/Security-issues.pdf'>Security Issues for Embedded Devices</ulink>"</emphasis> |
| 5624 | by Jake Edge |
| 5625 | </para></listitem> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5626 | </itemizedlist> |
| 5627 | </para> |
| 5628 | |
| 5629 | <para> |
| 5630 | When securing your image is of concern, there are steps, tools, |
| 5631 | and variables that you can consider to help you reach the |
| 5632 | security goals you need for your particular device. |
| 5633 | Not all situations are identical when it comes to making an |
| 5634 | image secure. |
| 5635 | Consequently, this section provides some guidance and suggestions |
| 5636 | for consideration when you want to make your image more secure. |
| 5637 | <note> |
| 5638 | Because the security requirements and risks are |
| 5639 | different for every type of device, this section cannot |
| 5640 | provide a complete reference on securing your custom OS. |
| 5641 | It is strongly recommended that you also consult other sources |
| 5642 | of information on embedded Linux system hardening and on |
| 5643 | security. |
| 5644 | </note> |
| 5645 | </para> |
| 5646 | |
| 5647 | <section id='general-considerations'> |
| 5648 | <title>General Considerations</title> |
| 5649 | |
| 5650 | <para> |
| 5651 | General considerations exist that help you create more |
| 5652 | secure images. |
| 5653 | You should consider the following suggestions to help |
| 5654 | make your device more secure: |
| 5655 | <itemizedlist> |
| 5656 | <listitem><para> |
| 5657 | Scan additional code you are adding to the system |
| 5658 | (e.g. application code) by using static analysis |
| 5659 | tools. |
| 5660 | Look for buffer overflows and other potential |
| 5661 | security problems. |
| 5662 | </para></listitem> |
| 5663 | <listitem><para> |
| 5664 | Pay particular attention to the security for |
| 5665 | any web-based administration interface. |
| 5666 | </para> |
| 5667 | <para>Web interfaces typically need to perform |
| 5668 | administrative functions and tend to need to run with |
| 5669 | elevated privileges. |
| 5670 | Thus, the consequences resulting from the interface's |
| 5671 | security becoming compromised can be serious. |
| 5672 | Look for common web vulnerabilities such as |
| 5673 | cross-site-scripting (XSS), unvalidated inputs, |
| 5674 | and so forth.</para> |
| 5675 | <para>As with system passwords, the default credentials |
| 5676 | for accessing a web-based interface should not be the |
| 5677 | same across all devices. |
| 5678 | This is particularly true if the interface is enabled |
| 5679 | by default as it can be assumed that many end-users |
| 5680 | will not change the credentials. |
| 5681 | </para></listitem> |
| 5682 | <listitem><para> |
| 5683 | Ensure you can update the software on the device to |
| 5684 | mitigate vulnerabilities discovered in the future. |
| 5685 | This consideration especially applies when your |
| 5686 | device is network-enabled. |
| 5687 | </para></listitem> |
| 5688 | <listitem><para> |
| 5689 | Ensure you remove or disable debugging functionality |
| 5690 | before producing the final image. |
| 5691 | For information on how to do this, see the |
| 5692 | "<link linkend='considerations-specific-to-the-openembedded-build-system'>Considerations Specific to the OpenEmbedded Build System</link>" |
| 5693 | section. |
| 5694 | </para></listitem> |
| 5695 | <listitem><para> |
| 5696 | Ensure you have no network services listening that |
| 5697 | are not needed. |
| 5698 | </para></listitem> |
| 5699 | <listitem><para> |
| 5700 | Remove any software from the image that is not needed. |
| 5701 | </para></listitem> |
| 5702 | <listitem><para> |
| 5703 | Enable hardware support for secure boot functionality |
| 5704 | when your device supports this functionality. |
| 5705 | </para></listitem> |
| 5706 | </itemizedlist> |
| 5707 | </para> |
| 5708 | </section> |
| 5709 | |
| 5710 | <section id='security-flags'> |
| 5711 | <title>Security Flags</title> |
| 5712 | |
| 5713 | <para> |
| 5714 | The Yocto Project has security flags that you can enable that |
| 5715 | help make your build output more secure. |
| 5716 | The security flags are in the |
| 5717 | <filename>meta/conf/distro/include/security_flags.inc</filename> |
| 5718 | file in your |
| 5719 | <link linkend='source-directory'>Source Directory</link> |
| 5720 | (e.g. <filename>poky</filename>). |
| 5721 | <note> |
| 5722 | Depending on the recipe, certain security flags are enabled |
| 5723 | and disabled by default. |
| 5724 | </note> |
| 5725 | </para> |
| 5726 | |
| 5727 | <para> |
| 5728 | <!-- |
| 5729 | The GCC/LD flags in <filename>security_flags.inc</filename> |
| 5730 | enable more secure code generation. |
| 5731 | By including the <filename>security_flags.inc</filename> |
| 5732 | file, you enable flags to the compiler and linker that cause |
| 5733 | them to generate more secure code. |
| 5734 | <note> |
| 5735 | The GCC/LD flags are enabled by default in the |
| 5736 | <filename>poky-lsb</filename> distribution. |
| 5737 | </note> |
| 5738 | --> |
| 5739 | Use the following line in your |
| 5740 | <filename>local.conf</filename> file or in your custom |
| 5741 | distribution configuration file to enable the security |
| 5742 | compiler and linker flags for your build: |
| 5743 | <literallayout class='monospaced'> |
| 5744 | require conf/distro/include/security_flags.inc |
| 5745 | </literallayout> |
| 5746 | </para> |
| 5747 | </section> |
| 5748 | |
| 5749 | <section id='considerations-specific-to-the-openembedded-build-system'> |
| 5750 | <title>Considerations Specific to the OpenEmbedded Build System</title> |
| 5751 | |
| 5752 | <para> |
| 5753 | You can take some steps that are specific to the |
| 5754 | OpenEmbedded build system to make your images more secure: |
| 5755 | <itemizedlist> |
| 5756 | <listitem><para> |
| 5757 | Ensure "debug-tweaks" is not one of your selected |
| 5758 | <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>. |
| 5759 | When creating a new project, the default is to provide you |
| 5760 | with an initial <filename>local.conf</filename> file that |
| 5761 | enables this feature using the |
| 5762 | <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink> variable with the line: |
| 5763 | <literallayout class='monospaced'> |
| 5764 | EXTRA_IMAGE_FEATURES = "debug-tweaks" |
| 5765 | </literallayout> |
| 5766 | To disable that feature, simply comment out that line in your |
| 5767 | <filename>local.conf</filename> file, or |
| 5768 | make sure <filename>IMAGE_FEATURES</filename> does not contain |
| 5769 | "debug-tweaks" before producing your final image. |
| 5770 | Among other things, leaving this in place sets the |
| 5771 | root password as blank, which makes logging in for |
| 5772 | debugging or inspection easy during |
| 5773 | development but also means anyone can easily log in |
| 5774 | during production. |
| 5775 | </para></listitem> |
| 5776 | <listitem><para> |
| 5777 | It is possible to set a root password for the image |
| 5778 | and also to set passwords for any extra users you might |
| 5779 | add (e.g. administrative or service type users). |
| 5780 | When you set up passwords for multiple images or |
| 5781 | users, you should not duplicate passwords. |
| 5782 | </para> |
| 5783 | <para> |
| 5784 | To set up passwords, use the |
| 5785 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-extrausers'><filename>extrausers</filename></ulink> |
| 5786 | class, which is the preferred method. |
| 5787 | For an example on how to set up both root and user |
| 5788 | passwords, see the |
| 5789 | "<ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-extrausers'><filename>extrausers.bbclass</filename></ulink>" |
| 5790 | section. |
| 5791 | <note> |
| 5792 | When adding extra user accounts or setting a |
| 5793 | root password, be cautious about setting the |
| 5794 | same password on every device. |
| 5795 | If you do this, and the password you have set |
| 5796 | is exposed, then every device is now potentially |
| 5797 | compromised. |
| 5798 | If you need this access but want to ensure |
| 5799 | security, consider setting a different, |
| 5800 | random password for each device. |
| 5801 | Typically, you do this as a separate step after |
| 5802 | you deploy the image onto the device. |
| 5803 | </note> |
| 5804 | </para></listitem> |
| 5805 | <listitem><para> |
| 5806 | Consider enabling a Mandatory Access Control (MAC) |
| 5807 | framework such as SMACK or SELinux and tuning it |
| 5808 | appropriately for your device's usage. |
| 5809 | You can find more information in the |
| 5810 | <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/meta-selinux/'><filename>meta-selinux</filename></ulink> |
| 5811 | layer. |
| 5812 | </para></listitem> |
| 5813 | </itemizedlist> |
| 5814 | </para> |
| 5815 | |
| 5816 | <para> |
| 5817 | </para> |
| 5818 | </section> |
| 5819 | |
| 5820 | <section id='tools-for-hardening-your-image'> |
| 5821 | <title>Tools for Hardening Your Image</title> |
| 5822 | |
| 5823 | <para> |
| 5824 | The Yocto Project provides tools for making your image |
| 5825 | more secure. |
| 5826 | You can find these tools in the |
| 5827 | <filename>meta-security</filename> layer of the |
| 5828 | <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi'>Yocto Project Source Repositories</ulink>. |
| 5829 | </para> |
| 5830 | </section> |
| 5831 | </section> |
| 5832 | |
| 5833 | <section id='creating-your-own-distribution'> |
| 5834 | <title>Creating Your Own Distribution</title> |
| 5835 | |
| 5836 | <para> |
| 5837 | When you build an image using the Yocto Project and |
| 5838 | do not alter any distribution |
| 5839 | <link linkend='metadata'>Metadata</link>, you are creating a |
| 5840 | Poky distribution. |
| 5841 | If you wish to gain more control over package alternative |
| 5842 | selections, compile-time options, and other low-level |
| 5843 | configurations, you can create your own distribution. |
| 5844 | </para> |
| 5845 | |
| 5846 | <para> |
| 5847 | To create your own distribution, the basic steps consist of |
| 5848 | creating your own distribution layer, creating your own |
| 5849 | distribution configuration file, and then adding any needed |
| 5850 | code and Metadata to the layer. |
| 5851 | The following steps provide some more detail: |
| 5852 | <itemizedlist> |
| 5853 | <listitem><para><emphasis>Create a layer for your new distro:</emphasis> |
| 5854 | Create your distribution layer so that you can keep your |
| 5855 | Metadata and code for the distribution separate. |
| 5856 | It is strongly recommended that you create and use your own |
| 5857 | layer for configuration and code. |
| 5858 | Using your own layer as compared to just placing |
| 5859 | configurations in a <filename>local.conf</filename> |
| 5860 | configuration file makes it easier to reproduce the same |
| 5861 | build configuration when using multiple build machines. |
| 5862 | See the |
| 5863 | "<link linkend='creating-a-general-layer-using-the-yocto-layer-script'>Creating a General Layer Using the yocto-layer Script</link>" |
| 5864 | section for information on how to quickly set up a layer. |
| 5865 | </para></listitem> |
| 5866 | <listitem><para><emphasis>Create the distribution configuration file:</emphasis> |
| 5867 | The distribution configuration file needs to be created in |
| 5868 | the <filename>conf/distro</filename> directory of your |
| 5869 | layer. |
| 5870 | You need to name it using your distribution name |
| 5871 | (e.g. <filename>mydistro.conf</filename>). |
| 5872 | <note> |
| 5873 | The |
| 5874 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink> |
| 5875 | variable in your |
| 5876 | <filename>local.conf</filename> file determines the |
| 5877 | name of your distribution. |
| 5878 | </note></para> |
| 5879 | <para>You can split out parts of your configuration file |
| 5880 | into include files and then "require" them from within |
| 5881 | your distribution configuration file. |
| 5882 | Be sure to place the include files in the |
| 5883 | <filename>conf/distro/include</filename> directory of |
| 5884 | your layer. |
| 5885 | A common example usage of include files would be to |
| 5886 | separate out the selection of desired version and revisions |
| 5887 | for individual recipes. |
| 5888 | </para> |
| 5889 | <para>Your configuration file needs to set the following |
| 5890 | required variables: |
| 5891 | <literallayout class='monospaced'> |
| 5892 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_NAME'><filename>DISTRO_NAME</filename></ulink> |
| 5893 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_VERSION'><filename>DISTRO_VERSION</filename></ulink> |
| 5894 | </literallayout> |
| 5895 | These following variables are optional and you typically |
| 5896 | set them from the distribution configuration file: |
| 5897 | <literallayout class='monospaced'> |
| 5898 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink> |
| 5899 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_EXTRA_RDEPENDS'><filename>DISTRO_EXTRA_RDEPENDS</filename></ulink> |
| 5900 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_EXTRA_RRECOMMENDS'><filename>DISTRO_EXTRA_RRECOMMENDS</filename></ulink> |
| 5901 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TCLIBC'><filename>TCLIBC</filename></ulink> |
| 5902 | </literallayout> |
| 5903 | <tip> |
| 5904 | If you want to base your distribution configuration file |
| 5905 | on the very basic configuration from OE-Core, you |
| 5906 | can use |
| 5907 | <filename>conf/distro/defaultsetup.conf</filename> as |
| 5908 | a reference and just include variables that differ |
| 5909 | as compared to <filename>defaultsetup.conf</filename>. |
| 5910 | Alternatively, you can create a distribution |
| 5911 | configuration file from scratch using the |
| 5912 | <filename>defaultsetup.conf</filename> file |
| 5913 | or configuration files from other distributions |
| 5914 | such as Poky or Angstrom as references. |
| 5915 | </tip></para></listitem> |
| 5916 | <listitem><para><emphasis>Provide miscellaneous variables:</emphasis> |
| 5917 | Be sure to define any other variables for which you want to |
| 5918 | create a default or enforce as part of the distribution |
| 5919 | configuration. |
| 5920 | You can include nearly any variable from the |
| 5921 | <filename>local.conf</filename> file. |
| 5922 | The variables you use are not limited to the list in the |
| 5923 | previous bulleted item.</para></listitem> |
| 5924 | <listitem><para><emphasis>Point to Your distribution configuration file:</emphasis> |
| 5925 | In your <filename>local.conf</filename> file in the |
| 5926 | <link linkend='build-directory'>Build Directory</link>, |
| 5927 | set your |
| 5928 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink> |
| 5929 | variable to point to your distribution's configuration file. |
| 5930 | For example, if your distribution's configuration file is |
| 5931 | named <filename>mydistro.conf</filename>, then you point |
| 5932 | to it as follows: |
| 5933 | <literallayout class='monospaced'> |
| 5934 | DISTRO = "mydistro" |
| 5935 | </literallayout></para></listitem> |
| 5936 | <listitem><para><emphasis>Add more to the layer if necessary:</emphasis> |
| 5937 | Use your layer to hold other information needed for the |
| 5938 | distribution: |
| 5939 | <itemizedlist> |
| 5940 | <listitem><para>Add recipes for installing |
| 5941 | distro-specific configuration files that are not |
| 5942 | already installed by another recipe. |
| 5943 | If you have distro-specific configuration files |
| 5944 | that are included by an existing recipe, you should |
| 5945 | add an append file (<filename>.bbappend</filename>) |
| 5946 | for those. |
| 5947 | For general information and recommendations |
| 5948 | on how to add recipes to your layer, see the |
| 5949 | "<link linkend='creating-your-own-layer'>Creating Your Own Layer</link>" |
| 5950 | and |
| 5951 | "<link linkend='best-practices-to-follow-when-creating-layers'>Best Practices to Follow When Creating Layers</link>" |
| 5952 | sections.</para></listitem> |
| 5953 | <listitem><para>Add any image recipes that are specific |
| 5954 | to your distribution.</para></listitem> |
| 5955 | <listitem><para>Add a <filename>psplash</filename> |
| 5956 | append file for a branded splash screen. |
| 5957 | For information on append files, see the |
| 5958 | "<link linkend='using-bbappend-files'>Using .bbappend Files</link>" |
| 5959 | section.</para></listitem> |
| 5960 | <listitem><para>Add any other append files to make |
| 5961 | custom changes that are specific to individual |
| 5962 | recipes.</para></listitem> |
| 5963 | </itemizedlist></para></listitem> |
| 5964 | </itemizedlist> |
| 5965 | </para> |
| 5966 | </section> |
| 5967 | |
| 5968 | <section id='creating-a-custom-template-configuration-directory'> |
| 5969 | <title>Creating a Custom Template Configuration Directory</title> |
| 5970 | |
| 5971 | <para> |
| 5972 | If you are producing your own customized version |
| 5973 | of the build system for use by other users, you might |
| 5974 | want to customize the message shown by the setup script or |
| 5975 | you might want to change the template configuration files (i.e. |
| 5976 | <filename>local.conf</filename> and |
| 5977 | <filename>bblayers.conf</filename>) that are created in |
| 5978 | a new build directory. |
| 5979 | </para> |
| 5980 | |
| 5981 | <para> |
| 5982 | The OpenEmbedded build system uses the environment variable |
| 5983 | <filename>TEMPLATECONF</filename> to locate the directory |
| 5984 | from which it gathers configuration information that ultimately |
| 5985 | ends up in the |
| 5986 | <link linkend='build-directory'>Build Directory's</link> |
| 5987 | <filename>conf</filename> directory. |
| 5988 | By default, <filename>TEMPLATECONF</filename> is set as |
| 5989 | follows in the <filename>poky</filename> repository: |
| 5990 | <literallayout class='monospaced'> |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 5991 | TEMPLATECONF=${TEMPLATECONF:-meta-poky/conf} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5992 | </literallayout> |
| 5993 | This is the directory used by the build system to find templates |
| 5994 | from which to build some key configuration files. |
| 5995 | If you look at this directory, you will see the |
| 5996 | <filename>bblayers.conf.sample</filename>, |
| 5997 | <filename>local.conf.sample</filename>, and |
| 5998 | <filename>conf-notes.txt</filename> files. |
| 5999 | The build system uses these files to form the respective |
| 6000 | <filename>bblayers.conf</filename> file, |
| 6001 | <filename>local.conf</filename> file, and display the list of |
| 6002 | BitBake targets when running the setup script. |
| 6003 | </para> |
| 6004 | |
| 6005 | <para> |
| 6006 | To override these default configuration files with |
| 6007 | configurations you want used within every new |
| 6008 | Build Directory, simply set the |
| 6009 | <filename>TEMPLATECONF</filename> variable to your directory. |
| 6010 | The <filename>TEMPLATECONF</filename> variable is set in the |
| 6011 | <filename>.templateconf</filename> file, which is in the |
| 6012 | top-level |
| 6013 | <link linkend='source-directory'>Source Directory</link> |
| 6014 | folder (e.g. <filename>poky</filename>). |
| 6015 | Edit the <filename>.templateconf</filename> so that it can locate |
| 6016 | your directory. |
| 6017 | </para> |
| 6018 | |
| 6019 | <para> |
| 6020 | Best practices dictate that you should keep your |
| 6021 | template configuration directory in your custom distribution layer. |
| 6022 | For example, suppose you have a layer named |
| 6023 | <filename>meta-mylayer</filename> located in your home directory |
| 6024 | and you want your template configuration directory named |
| 6025 | <filename>myconf</filename>. |
| 6026 | Changing the <filename>.templateconf</filename> as follows |
| 6027 | causes the OpenEmbedded build system to look in your directory |
| 6028 | and base its configuration files on the |
| 6029 | <filename>*.sample</filename> configuration files it finds. |
| 6030 | The final configuration files (i.e. |
| 6031 | <filename>local.conf</filename> and |
| 6032 | <filename>bblayers.conf</filename> ultimately still end up in |
| 6033 | your Build Directory, but they are based on your |
| 6034 | <filename>*.sample</filename> files. |
| 6035 | <literallayout class='monospaced'> |
| 6036 | TEMPLATECONF=${TEMPLATECONF:-meta-mylayer/myconf} |
| 6037 | </literallayout> |
| 6038 | </para> |
| 6039 | |
| 6040 | <para> |
| 6041 | Aside from the <filename>*.sample</filename> configuration files, |
| 6042 | the <filename>conf-notes.txt</filename> also resides in the |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 6043 | default <filename>meta-poky/conf</filename> directory. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6044 | The scripts that set up the build environment |
| 6045 | (i.e. |
| 6046 | <ulink url="&YOCTO_DOCS_REF_URL;#structure-core-script"><filename>&OE_INIT_FILE;</filename></ulink> |
| 6047 | and |
| 6048 | <ulink url="&YOCTO_DOCS_REF_URL;#structure-memres-core-script"><filename>oe-init-build-env-memres</filename></ulink>) |
| 6049 | use this file to display BitBake targets as part of the script |
| 6050 | output. |
| 6051 | Customizing this <filename>conf-notes.txt</filename> file is a |
| 6052 | good way to make sure your list of custom targets appears |
| 6053 | as part of the script's output. |
| 6054 | </para> |
| 6055 | |
| 6056 | <para> |
| 6057 | Here is the default list of targets displayed as a result of |
| 6058 | running either of the setup scripts: |
| 6059 | <literallayout class='monospaced'> |
| 6060 | You can now run 'bitbake <target>' |
| 6061 | |
| 6062 | Common targets are: |
| 6063 | core-image-minimal |
| 6064 | core-image-sato |
| 6065 | meta-toolchain |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6066 | meta-ide-support |
| 6067 | </literallayout> |
| 6068 | </para> |
| 6069 | |
| 6070 | <para> |
| 6071 | Changing the listed common targets is as easy as editing your |
| 6072 | version of <filename>conf-notes.txt</filename> in your |
| 6073 | custom template configuration directory and making sure you |
| 6074 | have <filename>TEMPLATECONF</filename> set to your directory. |
| 6075 | </para> |
| 6076 | </section> |
| 6077 | |
| 6078 | <section id='building-a-tiny-system'> |
| 6079 | <title>Building a Tiny System</title> |
| 6080 | |
| 6081 | <para> |
| 6082 | Very small distributions have some significant advantages such |
| 6083 | as requiring less on-die or in-package memory (cheaper), better |
| 6084 | performance through efficient cache usage, lower power requirements |
| 6085 | due to less memory, faster boot times, and reduced development |
| 6086 | overhead. |
| 6087 | Some real-world examples where a very small distribution gives |
| 6088 | you distinct advantages are digital cameras, medical devices, |
| 6089 | and small headless systems. |
| 6090 | </para> |
| 6091 | |
| 6092 | <para> |
| 6093 | This section presents information that shows you how you can |
| 6094 | trim your distribution to even smaller sizes than the |
| 6095 | <filename>poky-tiny</filename> distribution, which is around |
| 6096 | 5 Mbytes, that can be built out-of-the-box using the Yocto Project. |
| 6097 | </para> |
| 6098 | |
| 6099 | <section id='tiny-system-overview'> |
| 6100 | <title>Overview</title> |
| 6101 | |
| 6102 | <para> |
| 6103 | The following list presents the overall steps you need to |
| 6104 | consider and perform to create distributions with smaller |
| 6105 | root filesystems, achieve faster boot times, maintain your critical |
| 6106 | functionality, and avoid initial RAM disks: |
| 6107 | <itemizedlist> |
| 6108 | <listitem><para> |
| 6109 | <link linkend='goals-and-guiding-principles'>Determine your goals and guiding principles.</link> |
| 6110 | </para></listitem> |
| 6111 | <listitem><para> |
| 6112 | <link linkend='understand-what-gives-your-image-size'>Understand what contributes to your image size.</link> |
| 6113 | </para></listitem> |
| 6114 | <listitem><para> |
| 6115 | <link linkend='trim-the-root-filesystem'>Reduce the size of the root filesystem.</link> |
| 6116 | </para></listitem> |
| 6117 | <listitem><para> |
| 6118 | <link linkend='trim-the-kernel'>Reduce the size of the kernel.</link> |
| 6119 | </para></listitem> |
| 6120 | <listitem><para> |
| 6121 | <link linkend='remove-package-management-requirements'>Eliminate packaging requirements.</link> |
| 6122 | </para></listitem> |
| 6123 | <listitem><para> |
| 6124 | <link linkend='look-for-other-ways-to-minimize-size'>Look for other ways to minimize size.</link> |
| 6125 | </para></listitem> |
| 6126 | <listitem><para> |
| 6127 | <link linkend='iterate-on-the-process'>Iterate on the process.</link> |
| 6128 | </para></listitem> |
| 6129 | </itemizedlist> |
| 6130 | </para> |
| 6131 | </section> |
| 6132 | |
| 6133 | <section id='goals-and-guiding-principles'> |
| 6134 | <title>Goals and Guiding Principles</title> |
| 6135 | |
| 6136 | <para> |
| 6137 | Before you can reach your destination, you need to know |
| 6138 | where you are going. |
| 6139 | Here is an example list that you can use as a guide when |
| 6140 | creating very small distributions: |
| 6141 | <itemizedlist> |
| 6142 | <listitem><para>Determine how much space you need |
| 6143 | (e.g. a kernel that is 1 Mbyte or less and |
| 6144 | a root filesystem that is 3 Mbytes or less). |
| 6145 | </para></listitem> |
| 6146 | <listitem><para>Find the areas that are currently |
| 6147 | taking 90% of the space and concentrate on reducing |
| 6148 | those areas. |
| 6149 | </para></listitem> |
| 6150 | <listitem><para>Do not create any difficult "hacks" |
| 6151 | to achieve your goals.</para></listitem> |
| 6152 | <listitem><para>Leverage the device-specific |
| 6153 | options.</para></listitem> |
| 6154 | <listitem><para>Work in a separate layer so that you |
| 6155 | keep changes isolated. |
| 6156 | For information on how to create layers, see |
| 6157 | the "<link linkend='understanding-and-creating-layers'>Understanding and Creating Layers</link>" section. |
| 6158 | </para></listitem> |
| 6159 | </itemizedlist> |
| 6160 | </para> |
| 6161 | </section> |
| 6162 | |
| 6163 | <section id='understand-what-gives-your-image-size'> |
| 6164 | <title>Understand What Contributes to Your Image Size</title> |
| 6165 | |
| 6166 | <para> |
| 6167 | It is easiest to have something to start with when creating |
| 6168 | your own distribution. |
| 6169 | You can use the Yocto Project out-of-the-box to create the |
| 6170 | <filename>poky-tiny</filename> distribution. |
| 6171 | Ultimately, you will want to make changes in your own |
| 6172 | distribution that are likely modeled after |
| 6173 | <filename>poky-tiny</filename>. |
| 6174 | <note> |
| 6175 | To use <filename>poky-tiny</filename> in your build, |
| 6176 | set the |
| 6177 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink> |
| 6178 | variable in your |
| 6179 | <filename>local.conf</filename> file to "poky-tiny" |
| 6180 | as described in the |
| 6181 | "<link linkend='creating-your-own-distribution'>Creating Your Own Distribution</link>" |
| 6182 | section. |
| 6183 | </note> |
| 6184 | </para> |
| 6185 | |
| 6186 | <para> |
| 6187 | Understanding some memory concepts will help you reduce the |
| 6188 | system size. |
| 6189 | Memory consists of static, dynamic, and temporary memory. |
| 6190 | Static memory is the TEXT (code), DATA (initialized data |
| 6191 | in the code), and BSS (uninitialized data) sections. |
| 6192 | Dynamic memory represents memory that is allocated at runtime: |
| 6193 | stacks, hash tables, and so forth. |
| 6194 | Temporary memory is recovered after the boot process. |
| 6195 | This memory consists of memory used for decompressing |
| 6196 | the kernel and for the <filename>__init__</filename> |
| 6197 | functions. |
| 6198 | </para> |
| 6199 | |
| 6200 | <para> |
| 6201 | To help you see where you currently are with kernel and root |
| 6202 | filesystem sizes, you can use two tools found in the |
| 6203 | <link linkend='source-directory'>Source Directory</link> in |
| 6204 | the <filename>scripts/tiny/</filename> directory: |
| 6205 | <itemizedlist> |
| 6206 | <listitem><para><filename>ksize.py</filename>: Reports |
| 6207 | component sizes for the kernel build objects. |
| 6208 | </para></listitem> |
| 6209 | <listitem><para><filename>dirsize.py</filename>: Reports |
| 6210 | component sizes for the root filesystem.</para></listitem> |
| 6211 | </itemizedlist> |
| 6212 | This next tool and command help you organize configuration |
| 6213 | fragments and view file dependencies in a human-readable form: |
| 6214 | <itemizedlist> |
| 6215 | <listitem><para><filename>merge_config.sh</filename>: |
| 6216 | Helps you manage configuration files and fragments |
| 6217 | within the kernel. |
| 6218 | With this tool, you can merge individual configuration |
| 6219 | fragments together. |
| 6220 | The tool allows you to make overrides and warns you |
| 6221 | of any missing configuration options. |
| 6222 | The tool is ideal for allowing you to iterate on |
| 6223 | configurations, create minimal configurations, and |
| 6224 | create configuration files for different machines |
| 6225 | without having to duplicate your process.</para> |
| 6226 | <para>The <filename>merge_config.sh</filename> script is |
| 6227 | part of the Linux Yocto kernel Git repositories |
| 6228 | (i.e. <filename>linux-yocto-3.14</filename>, |
| 6229 | <filename>linux-yocto-3.10</filename>, |
| 6230 | <filename>linux-yocto-3.8</filename>, and so forth) |
| 6231 | in the |
| 6232 | <filename>scripts/kconfig</filename> directory.</para> |
| 6233 | <para>For more information on configuration fragments, |
| 6234 | see the |
| 6235 | "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#generating-configuration-files'>Generating Configuration Files</ulink>" |
| 6236 | section of the Yocto Project Linux Kernel Development |
| 6237 | Manual and the "<link linkend='creating-config-fragments'>Creating Configuration Fragments</link>" |
| 6238 | section, which is in this manual.</para></listitem> |
| 6239 | <listitem><para><filename>bitbake -u depexp -g <replaceable>bitbake_target</replaceable></filename>: |
| 6240 | Using the BitBake command with these options brings up |
| 6241 | a Dependency Explorer from which you can view file |
| 6242 | dependencies. |
| 6243 | Understanding these dependencies allows you to make |
| 6244 | informed decisions when cutting out various pieces of the |
| 6245 | kernel and root filesystem.</para></listitem> |
| 6246 | </itemizedlist> |
| 6247 | </para> |
| 6248 | </section> |
| 6249 | |
| 6250 | <section id='trim-the-root-filesystem'> |
| 6251 | <title>Trim the Root Filesystem</title> |
| 6252 | |
| 6253 | <para> |
| 6254 | The root filesystem is made up of packages for booting, |
| 6255 | libraries, and applications. |
| 6256 | To change things, you can configure how the packaging happens, |
| 6257 | which changes the way you build them. |
| 6258 | You can also modify the filesystem itself or select a different |
| 6259 | filesystem. |
| 6260 | </para> |
| 6261 | |
| 6262 | <para> |
| 6263 | First, find out what is hogging your root filesystem by running the |
| 6264 | <filename>dirsize.py</filename> script from your root directory: |
| 6265 | <literallayout class='monospaced'> |
| 6266 | $ cd <replaceable>root-directory-of-image</replaceable> |
| 6267 | $ dirsize.py 100000 > dirsize-100k.log |
| 6268 | $ cat dirsize-100k.log |
| 6269 | </literallayout> |
| 6270 | You can apply a filter to the script to ignore files under |
| 6271 | a certain size. |
| 6272 | The previous example filters out any files below 100 Kbytes. |
| 6273 | The sizes reported by the tool are uncompressed, and thus |
| 6274 | will be smaller by a relatively constant factor in a |
| 6275 | compressed root filesystem. |
| 6276 | When you examine your log file, you can focus on areas of the |
| 6277 | root filesystem that take up large amounts of memory. |
| 6278 | </para> |
| 6279 | |
| 6280 | <para> |
| 6281 | You need to be sure that what you eliminate does not cripple |
| 6282 | the functionality you need. |
| 6283 | One way to see how packages relate to each other is by using |
| 6284 | the Dependency Explorer UI with the BitBake command: |
| 6285 | <literallayout class='monospaced'> |
| 6286 | $ cd <replaceable>image-directory</replaceable> |
| 6287 | $ bitbake -u depexp -g <replaceable>image</replaceable> |
| 6288 | </literallayout> |
| 6289 | Use the interface to select potential packages you wish to |
| 6290 | eliminate and see their dependency relationships. |
| 6291 | </para> |
| 6292 | |
| 6293 | <para> |
| 6294 | When deciding how to reduce the size, get rid of packages that |
| 6295 | result in minimal impact on the feature set. |
| 6296 | For example, you might not need a VGA display. |
| 6297 | Or, you might be able to get by with <filename>devtmpfs</filename> |
| 6298 | and <filename>mdev</filename> instead of |
| 6299 | <filename>udev</filename>. |
| 6300 | </para> |
| 6301 | |
| 6302 | <para> |
| 6303 | Use your <filename>local.conf</filename> file to make changes. |
| 6304 | For example, to eliminate <filename>udev</filename> and |
| 6305 | <filename>glib</filename>, set the following in the |
| 6306 | local configuration file: |
| 6307 | <literallayout class='monospaced'> |
| 6308 | VIRTUAL-RUNTIME_dev_manager = "" |
| 6309 | </literallayout> |
| 6310 | </para> |
| 6311 | |
| 6312 | <para> |
| 6313 | Finally, you should consider exactly the type of root |
| 6314 | filesystem you need to meet your needs while also reducing |
| 6315 | its size. |
| 6316 | For example, consider <filename>cramfs</filename>, |
| 6317 | <filename>squashfs</filename>, <filename>ubifs</filename>, |
| 6318 | <filename>ext2</filename>, or an <filename>initramfs</filename> |
| 6319 | using <filename>initramfs</filename>. |
| 6320 | Be aware that <filename>ext3</filename> requires a 1 Mbyte |
| 6321 | journal. |
| 6322 | If you are okay with running read-only, you do not need this |
| 6323 | journal. |
| 6324 | </para> |
| 6325 | |
| 6326 | <note> |
| 6327 | After each round of elimination, you need to rebuild your |
| 6328 | system and then use the tools to see the effects of your |
| 6329 | reductions. |
| 6330 | </note> |
| 6331 | |
| 6332 | |
| 6333 | </section> |
| 6334 | |
| 6335 | <section id='trim-the-kernel'> |
| 6336 | <title>Trim the Kernel</title> |
| 6337 | |
| 6338 | <para> |
| 6339 | The kernel is built by including policies for hardware-independent |
| 6340 | aspects. |
| 6341 | What subsystems do you enable? |
| 6342 | For what architecture are you building? |
| 6343 | Which drivers do you build by default? |
| 6344 | <note>You can modify the kernel source if you want to help |
| 6345 | with boot time. |
| 6346 | </note> |
| 6347 | </para> |
| 6348 | |
| 6349 | <para> |
| 6350 | Run the <filename>ksize.py</filename> script from the top-level |
| 6351 | Linux build directory to get an idea of what is making up |
| 6352 | the kernel: |
| 6353 | <literallayout class='monospaced'> |
| 6354 | $ cd <replaceable>top-level-linux-build-directory</replaceable> |
| 6355 | $ ksize.py > ksize.log |
| 6356 | $ cat ksize.log |
| 6357 | </literallayout> |
| 6358 | When you examine the log, you will see how much space is |
| 6359 | taken up with the built-in <filename>.o</filename> files for |
| 6360 | drivers, networking, core kernel files, filesystem, sound, |
| 6361 | and so forth. |
| 6362 | The sizes reported by the tool are uncompressed, and thus |
| 6363 | will be smaller by a relatively constant factor in a compressed |
| 6364 | kernel image. |
| 6365 | Look to reduce the areas that are large and taking up around |
| 6366 | the "90% rule." |
| 6367 | </para> |
| 6368 | |
| 6369 | <para> |
| 6370 | To examine, or drill down, into any particular area, use the |
| 6371 | <filename>-d</filename> option with the script: |
| 6372 | <literallayout class='monospaced'> |
| 6373 | $ ksize.py -d > ksize.log |
| 6374 | </literallayout> |
| 6375 | Using this option breaks out the individual file information |
| 6376 | for each area of the kernel (e.g. drivers, networking, and |
| 6377 | so forth). |
| 6378 | </para> |
| 6379 | |
| 6380 | <para> |
| 6381 | Use your log file to see what you can eliminate from the kernel |
| 6382 | based on features you can let go. |
| 6383 | For example, if you are not going to need sound, you do not |
| 6384 | need any drivers that support sound. |
| 6385 | </para> |
| 6386 | |
| 6387 | <para> |
| 6388 | After figuring out what to eliminate, you need to reconfigure |
| 6389 | the kernel to reflect those changes during the next build. |
| 6390 | You could run <filename>menuconfig</filename> and make all your |
| 6391 | changes at once. |
| 6392 | However, that makes it difficult to see the effects of your |
| 6393 | individual eliminations and also makes it difficult to replicate |
| 6394 | the changes for perhaps another target device. |
| 6395 | A better method is to start with no configurations using |
| 6396 | <filename>allnoconfig</filename>, create configuration |
| 6397 | fragments for individual changes, and then manage the |
| 6398 | fragments into a single configuration file using |
| 6399 | <filename>merge_config.sh</filename>. |
| 6400 | The tool makes it easy for you to iterate using the |
| 6401 | configuration change and build cycle. |
| 6402 | </para> |
| 6403 | |
| 6404 | <para> |
| 6405 | Each time you make configuration changes, you need to rebuild |
| 6406 | the kernel and check to see what impact your changes had on |
| 6407 | the overall size. |
| 6408 | </para> |
| 6409 | </section> |
| 6410 | |
| 6411 | <section id='remove-package-management-requirements'> |
| 6412 | <title>Remove Package Management Requirements</title> |
| 6413 | |
| 6414 | <para> |
| 6415 | Packaging requirements add size to the image. |
| 6416 | One way to reduce the size of the image is to remove all the |
| 6417 | packaging requirements from the image. |
| 6418 | This reduction includes both removing the package manager |
| 6419 | and its unique dependencies as well as removing the package |
| 6420 | management data itself. |
| 6421 | </para> |
| 6422 | |
| 6423 | <para> |
| 6424 | To eliminate all the packaging requirements for an image, |
| 6425 | be sure that "package-management" is not part of your |
| 6426 | <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink> |
| 6427 | statement for the image. |
| 6428 | When you remove this feature, you are removing the package |
| 6429 | manager as well as its dependencies from the root filesystem. |
| 6430 | </para> |
| 6431 | </section> |
| 6432 | |
| 6433 | <section id='look-for-other-ways-to-minimize-size'> |
| 6434 | <title>Look for Other Ways to Minimize Size</title> |
| 6435 | |
| 6436 | <para> |
| 6437 | Depending on your particular circumstances, other areas that you |
| 6438 | can trim likely exist. |
| 6439 | The key to finding these areas is through tools and methods |
| 6440 | described here combined with experimentation and iteration. |
| 6441 | Here are a couple of areas to experiment with: |
| 6442 | <itemizedlist> |
| 6443 | <listitem><para><filename>glibc</filename>: |
| 6444 | In general, follow this process: |
| 6445 | <orderedlist> |
| 6446 | <listitem><para>Remove <filename>glibc</filename> |
| 6447 | features from |
| 6448 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink> |
| 6449 | that you think you do not need.</para></listitem> |
| 6450 | <listitem><para>Build your distribution. |
| 6451 | </para></listitem> |
| 6452 | <listitem><para>If the build fails due to missing |
| 6453 | symbols in a package, determine if you can |
| 6454 | reconfigure the package to not need those |
| 6455 | features. |
| 6456 | For example, change the configuration to not |
| 6457 | support wide character support as is done for |
| 6458 | <filename>ncurses</filename>. |
| 6459 | Or, if support for those characters is needed, |
| 6460 | determine what <filename>glibc</filename> |
| 6461 | features provide the support and restore the |
| 6462 | configuration. |
| 6463 | </para></listitem> |
| 6464 | <listitem><para>Rebuild and repeat the process. |
| 6465 | </para></listitem> |
| 6466 | </orderedlist></para></listitem> |
| 6467 | <listitem><para><filename>busybox</filename>: |
| 6468 | For BusyBox, use a process similar as described for |
| 6469 | <filename>glibc</filename>. |
| 6470 | A difference is you will need to boot the resulting |
| 6471 | system to see if you are able to do everything you |
| 6472 | expect from the running system. |
| 6473 | You need to be sure to integrate configuration fragments |
| 6474 | into Busybox because BusyBox handles its own core |
| 6475 | features and then allows you to add configuration |
| 6476 | fragments on top. |
| 6477 | </para></listitem> |
| 6478 | </itemizedlist> |
| 6479 | </para> |
| 6480 | </section> |
| 6481 | |
| 6482 | <section id='iterate-on-the-process'> |
| 6483 | <title>Iterate on the Process</title> |
| 6484 | |
| 6485 | <para> |
| 6486 | If you have not reached your goals on system size, you need |
| 6487 | to iterate on the process. |
| 6488 | The process is the same. |
| 6489 | Use the tools and see just what is taking up 90% of the root |
| 6490 | filesystem and the kernel. |
| 6491 | Decide what you can eliminate without limiting your device |
| 6492 | beyond what you need. |
| 6493 | </para> |
| 6494 | |
| 6495 | <para> |
| 6496 | Depending on your system, a good place to look might be |
| 6497 | Busybox, which provides a stripped down |
| 6498 | version of Unix tools in a single, executable file. |
| 6499 | You might be able to drop virtual terminal services or perhaps |
| 6500 | ipv6. |
| 6501 | </para> |
| 6502 | </section> |
| 6503 | </section> |
| 6504 | |
| 6505 | <section id='building-images-for-more-than-one-machine'> |
| 6506 | <title>Building Images for More than One Machine</title> |
| 6507 | |
| 6508 | <para> |
| 6509 | A common scenario developers face is creating images for several |
| 6510 | different machines that use the same software environment. |
| 6511 | In this situation, it is tempting to set the |
| 6512 | tunings and optimization flags for each build specifically for |
| 6513 | the targeted hardware (i.e. "maxing out" the tunings). |
| 6514 | Doing so can considerably add to build times and package feed |
| 6515 | maintenance collectively for the machines. |
| 6516 | For example, selecting tunes that are extremely specific to a |
| 6517 | CPU core used in a system might enable some micro optimizations |
| 6518 | in GCC for that particular system but would otherwise not gain |
| 6519 | you much of a performance difference across the other systems |
| 6520 | as compared to using a more general tuning across all the builds |
| 6521 | (e.g. setting |
| 6522 | <ulink url='var-DEFAULTTUNE'><filename>DEFAULTTUNE</filename></ulink> |
| 6523 | specifically for each machine's build). |
| 6524 | Rather than "max out" each build's tunings, you can take steps that |
| 6525 | cause the OpenEmbedded build system to reuse software across the |
| 6526 | various machines where it makes sense. |
| 6527 | </para> |
| 6528 | <para> |
| 6529 | If build speed and package feed maintenance are considerations, |
| 6530 | you should consider the points in this section that can help you |
| 6531 | optimize your tunings to best consider build times and package |
| 6532 | feed maintenance. |
| 6533 | <itemizedlist> |
| 6534 | <listitem><para><emphasis>Share the Build Directory:</emphasis> |
| 6535 | If at all possible, share the |
| 6536 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink> |
| 6537 | across builds. |
| 6538 | The Yocto Project supports switching between different |
| 6539 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink> |
| 6540 | values in the same <filename>TMPDIR</filename>. |
| 6541 | This practice is well supported and regularly used by |
| 6542 | developers when building for multiple machines. |
| 6543 | When you use the same <filename>TMPDIR</filename> for |
| 6544 | multiple machine builds, the OpenEmbedded build system can |
| 6545 | reuse the existing native and often cross-recipes for |
| 6546 | multiple machines. |
| 6547 | Thus, build time decreases. |
| 6548 | <note> |
| 6549 | If |
| 6550 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink> |
| 6551 | settings change or fundamental configuration settings |
| 6552 | such as the filesystem layout, you need to work with |
| 6553 | a clean <filename>TMPDIR</filename>. |
| 6554 | Sharing <filename>TMPDIR</filename> under these |
| 6555 | circumstances might work but since it is not |
| 6556 | guaranteed, you should use a clean |
| 6557 | <filename>TMPDIR</filename>. |
| 6558 | </note> |
| 6559 | </para></listitem> |
| 6560 | <listitem><para><emphasis>Enable the Appropriate Package Architecture:</emphasis> |
| 6561 | By default, the OpenEmbedded build system enables three |
| 6562 | levels of package architectures: "all", "tune" or "package", |
| 6563 | and "machine". |
| 6564 | Any given recipe usually selects one of these package |
| 6565 | architectures (types) for its output. |
| 6566 | Depending for what a given recipe creates packages, making |
| 6567 | sure you enable the appropriate package architecture can |
| 6568 | directly impact the build time.</para> |
| 6569 | <para>A recipe that just generates scripts can enable |
| 6570 | "all" architecture because there are no binaries to build. |
| 6571 | To specifically enable "all" architecture, be sure your |
| 6572 | recipe inherits the |
| 6573 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-allarch'><filename>allarch</filename></ulink> |
| 6574 | class. |
| 6575 | This class is useful for "all" architectures because it |
| 6576 | configures many variables so packages can be used across |
| 6577 | multiple architectures.</para> |
| 6578 | <para>If your recipe needs to generate packages that are |
| 6579 | machine-specific or when one of the build or runtime |
| 6580 | dependencies is already machine-architecture dependent, |
| 6581 | which makes your recipe also machine-architecture dependent, |
| 6582 | make sure your recipe enables the "machine" package |
| 6583 | architecture through the |
| 6584 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ARCH'><filename>MACHINE_ARCH</filename></ulink> |
| 6585 | variable: |
| 6586 | <literallayout class='monospaced'> |
| 6587 | PACKAGE_ARCH = "${MACHINE_ARCH}" |
| 6588 | </literallayout> |
| 6589 | When you do not specifically enable a package |
| 6590 | architecture through the |
| 6591 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>, |
| 6592 | The OpenEmbedded build system defaults to the |
| 6593 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TUNE_PKGARCH'><filename>TUNE_PKGARCH</filename></ulink> |
| 6594 | setting: |
| 6595 | <literallayout class='monospaced'> |
| 6596 | PACKAGE_ARCH = "${TUNE_PKGARCH}" |
| 6597 | </literallayout> |
| 6598 | </para></listitem> |
| 6599 | <listitem><para><emphasis>Choose a Generic Tuning File if Possible:</emphasis> |
| 6600 | Some tunes are more generic and can run on multiple targets |
| 6601 | (e.g. an <filename>armv5</filename> set of packages could |
| 6602 | run on <filename>armv6</filename> and |
| 6603 | <filename>armv7</filename> processors in most cases). |
| 6604 | Similarly, <filename>i486</filename> binaries could work |
| 6605 | on <filename>i586</filename> and higher processors. |
| 6606 | You should realize, however, that advances on newer |
| 6607 | processor versions would not be used.</para> |
| 6608 | <para>If you select the same tune for several different |
| 6609 | machines, the OpenEmbedded build system reuses software |
| 6610 | previously built, thus speeding up the overall build time. |
| 6611 | Realize that even though a new sysroot for each machine is |
| 6612 | generated, the software is not recompiled and only one |
| 6613 | package feed exists. |
| 6614 | </para></listitem> |
| 6615 | <listitem><para><emphasis>Manage Granular Level Packaging:</emphasis> |
| 6616 | Sometimes cases exist where injecting another level |
| 6617 | of package architecture beyond the three higher levels |
| 6618 | noted earlier can be useful. |
| 6619 | For example, consider the <filename>emgd</filename> |
| 6620 | graphics stack in the |
| 6621 | <filename>meta-intel</filename> layer. |
| 6622 | In this layer, a subset of software exists that is |
| 6623 | compiled against something different from the rest of the |
| 6624 | generic packages. |
| 6625 | You can examine the key code in the |
| 6626 | <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi'>Source Repositories</ulink> |
| 6627 | "daisy" branch in |
| 6628 | <filename>classes/emgd-gl.bbclass</filename>. |
| 6629 | For a specific set of packages, the code redefines |
| 6630 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>. |
| 6631 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_EXTRA_ARCHS'><filename>PACKAGE_EXTRA_ARCHS</filename></ulink> |
| 6632 | is then appended with this extra tune name in |
| 6633 | <filename>meta-intel-emgd.inc</filename>. |
| 6634 | The result is that when searching for packages, the |
| 6635 | build system uses a four-level search and the packages |
| 6636 | in this new level are preferred as compared to the standard |
| 6637 | tune. |
| 6638 | The overall result is that the build system reuses most |
| 6639 | software from the common tune except for specific cases |
| 6640 | as needed. |
| 6641 | </para></listitem> |
| 6642 | <listitem><para><emphasis>Use Tools to Debug Issues:</emphasis> |
| 6643 | Sometimes you can run into situations where software is |
| 6644 | being rebuilt when you think it should not be. |
| 6645 | For example, the OpenEmbedded build system might not be |
| 6646 | using shared state between machines when you think it |
| 6647 | should be. |
| 6648 | These types of situations are usually due to references |
| 6649 | to machine-specific variables such as |
| 6650 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>, |
| 6651 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SERIAL_CONSOLE'><filename>SERIAL_CONSOLE</filename></ulink>, |
| 6652 | <ulink url='&YOCTO_DOCS_REF_URL;#var-XSERVER'><filename>XSERVER</filename></ulink>, |
| 6653 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES'><filename>MACHINE_FEATURES</filename></ulink>, |
| 6654 | and so forth in code that is supposed to only be |
| 6655 | tune-specific or when the recipe depends |
| 6656 | (<ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>, |
| 6657 | <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>, |
| 6658 | <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>, |
| 6659 | <ulink url='&YOCTO_DOCS_REF_URL;#var-RSUGGESTS'><filename>RSUGGESTS</filename></ulink>, |
| 6660 | and so forth) on some other recipe that already has |
| 6661 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink> |
| 6662 | defined as "${MACHINE_ARCH}". |
| 6663 | <note> |
| 6664 | Patches to fix any issues identified are most welcome |
| 6665 | as these issues occasionally do occur. |
| 6666 | </note></para> |
| 6667 | <para>For such cases, you can use some tools to help you |
| 6668 | sort out the situation: |
| 6669 | <itemizedlist> |
| 6670 | <listitem><para><emphasis><filename>sstate-diff-machines.sh</filename>:</emphasis> |
| 6671 | You can find this tool in the |
| 6672 | <filename>scripts</filename> directory of the |
| 6673 | Source Repositories. |
| 6674 | See the comments in the script for information on |
| 6675 | how to use the tool. |
| 6676 | </para></listitem> |
| 6677 | <listitem><para><emphasis>BitBake's "-S printdiff" Option:</emphasis> |
| 6678 | Using this option causes BitBake to try to |
| 6679 | establish the closest signature match it can |
| 6680 | (e.g. in the shared state cache) and then run |
| 6681 | <filename>bitbake-diffsigs</filename> over the |
| 6682 | matches to determine the stamps and delta where |
| 6683 | these two stamp trees diverge. |
| 6684 | </para></listitem> |
| 6685 | </itemizedlist> |
| 6686 | </para></listitem> |
| 6687 | </itemizedlist> |
| 6688 | </para> |
| 6689 | </section> |
| 6690 | |
| 6691 | <section id='working-with-packages'> |
| 6692 | <title>Working with Packages</title> |
| 6693 | |
| 6694 | <para> |
| 6695 | This section describes a few tasks that involve packages: |
| 6696 | <itemizedlist> |
| 6697 | <listitem><para> |
| 6698 | <link linkend='excluding-packages-from-an-image'>Excluding packages from an image</link> |
| 6699 | </para></listitem> |
| 6700 | <listitem><para> |
| 6701 | <link linkend='incrementing-a-package-revision-number'>Incrementing a package revision number</link> |
| 6702 | </para></listitem> |
| 6703 | <listitem><para> |
| 6704 | <link linkend='handling-optional-module-packaging'>Handling optional module packaging</link> |
| 6705 | </para></listitem> |
| 6706 | <listitem><para> |
| 6707 | <link linkend='using-runtime-package-management'>Using Runtime Package Management</link> |
| 6708 | </para></listitem> |
| 6709 | <listitem><para> |
| 6710 | <link linkend='testing-packages-with-ptest'>Setting up and running package test (ptest)</link> |
| 6711 | </para></listitem> |
| 6712 | </itemizedlist> |
| 6713 | </para> |
| 6714 | |
| 6715 | <section id='excluding-packages-from-an-image'> |
| 6716 | <title>Excluding Packages from an Image</title> |
| 6717 | |
| 6718 | <para> |
| 6719 | You might find it necessary to prevent specific packages |
| 6720 | from being installed into an image. |
| 6721 | If so, you can use several variables to direct the build |
| 6722 | system to essentially ignore installing recommended packages |
| 6723 | or to not install a package at all. |
| 6724 | </para> |
| 6725 | |
| 6726 | <para> |
| 6727 | The following list introduces variables you can use to |
| 6728 | prevent packages from being installed into your image. |
| 6729 | Each of these variables only works with IPK and RPM |
| 6730 | package types. |
| 6731 | Support for Debian packages does not exist. |
| 6732 | Also, you can use these variables from your |
| 6733 | <filename>local.conf</filename> file or attach them to a |
| 6734 | specific image recipe by using a recipe name override. |
| 6735 | For more detail on the variables, see the descriptions in the |
| 6736 | Yocto Project Reference Manual's glossary chapter. |
| 6737 | <itemizedlist> |
| 6738 | <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-BAD_RECOMMENDATIONS'><filename>BAD_RECOMMENDATIONS</filename></ulink>: |
| 6739 | Use this variable to specify "recommended-only" |
| 6740 | packages that you do not want installed. |
| 6741 | </para></listitem> |
| 6742 | <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-NO_RECOMMENDATIONS'><filename>NO_RECOMMENDATIONS</filename></ulink>: |
| 6743 | Use this variable to prevent all "recommended-only" |
| 6744 | packages from being installed. |
| 6745 | </para></listitem> |
| 6746 | <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_EXCLUDE'><filename>PACKAGE_EXCLUDE</filename></ulink>: |
| 6747 | Use this variable to prevent specific packages from |
| 6748 | being installed regardless of whether they are |
| 6749 | "recommended-only" or not. |
| 6750 | You need to realize that the build process could |
| 6751 | fail with an error when you |
| 6752 | prevent the installation of a package whose presence |
| 6753 | is required by an installed package. |
| 6754 | </para></listitem> |
| 6755 | </itemizedlist> |
| 6756 | </para> |
| 6757 | </section> |
| 6758 | |
| 6759 | <section id='incrementing-a-package-revision-number'> |
| 6760 | <title>Incrementing a Package Revision Number</title> |
| 6761 | |
| 6762 | <para> |
| 6763 | If a committed change results in changing the package output, |
| 6764 | then the value of the |
| 6765 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink> |
| 6766 | variable needs to be increased (or "bumped"). |
| 6767 | Increasing <filename>PR</filename> occurs one of two ways: |
| 6768 | <itemizedlist> |
| 6769 | <listitem><para>Automatically using a Package Revision |
| 6770 | Service (PR Service).</para></listitem> |
| 6771 | <listitem><para>Manually incrementing the |
| 6772 | <filename>PR</filename> variable.</para></listitem> |
| 6773 | </itemizedlist> |
| 6774 | </para> |
| 6775 | |
| 6776 | <para> |
| 6777 | Given that one of the challenges any build system and its |
| 6778 | users face is how to maintain a package feed that is compatible |
| 6779 | with existing package manager applications such as |
| 6780 | RPM, APT, and OPKG, using an automated system is much |
| 6781 | preferred over a manual system. |
| 6782 | In either system, the main requirement is that version |
| 6783 | numbering increases in a linear fashion and that a number of |
| 6784 | version components exist that support that linear progression. |
| 6785 | </para> |
| 6786 | |
| 6787 | <para> |
| 6788 | The following two sections provide information on the PR Service |
| 6789 | and on manual <filename>PR</filename> bumping. |
| 6790 | </para> |
| 6791 | |
| 6792 | <section id='working-with-a-pr-service'> |
| 6793 | <title>Working With a PR Service</title> |
| 6794 | |
| 6795 | <para> |
| 6796 | As mentioned, attempting to maintain revision numbers in the |
| 6797 | <ulink url='&YOCTO_DOCS_DEV_URL;#metadata'>Metadata</ulink> |
| 6798 | is error prone, inaccurate, and causes problems for people |
| 6799 | submitting recipes. |
| 6800 | Conversely, the PR Service automatically generates |
| 6801 | increasing numbers, particularly the revision field, |
| 6802 | which removes the human element. |
| 6803 | <note> |
| 6804 | For additional information on using a PR Service, you |
| 6805 | can see the |
| 6806 | <ulink url='&YOCTO_WIKI_URL;/wiki/PR_Service'>PR Service</ulink> |
| 6807 | wiki page. |
| 6808 | </note> |
| 6809 | </para> |
| 6810 | |
| 6811 | <para> |
| 6812 | The Yocto Project uses variables in order of |
| 6813 | decreasing priority to facilitate revision numbering (i.e. |
| 6814 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PE'><filename>PE</filename></ulink>, |
| 6815 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>, and |
| 6816 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink> |
| 6817 | for epoch, version, and revision, respectively). |
| 6818 | The values are highly dependent on the policies and |
| 6819 | procedures of a given distribution and package feed. |
| 6820 | </para> |
| 6821 | |
| 6822 | <para> |
| 6823 | Because the OpenEmbedded build system uses |
| 6824 | "<ulink url='&YOCTO_DOCS_REF_URL;#checksums'>signatures</ulink>", |
| 6825 | which are unique to a given build, the build system |
| 6826 | knows when to rebuild packages. |
| 6827 | All the inputs into a given task are represented by a |
| 6828 | signature, which can trigger a rebuild when different. |
| 6829 | Thus, the build system itself does not rely on the |
| 6830 | <filename>PR</filename> numbers to trigger a rebuild. |
| 6831 | The signatures, however, can be used to generate |
| 6832 | <filename>PR</filename> values. |
| 6833 | </para> |
| 6834 | |
| 6835 | <para> |
| 6836 | The PR Service works with both |
| 6837 | <filename>OEBasic</filename> and |
| 6838 | <filename>OEBasicHash</filename> generators. |
| 6839 | The value of <filename>PR</filename> bumps when the |
| 6840 | checksum changes and the different generator mechanisms |
| 6841 | change signatures under different circumstances. |
| 6842 | </para> |
| 6843 | |
| 6844 | <para> |
| 6845 | As implemented, the build system includes values from |
| 6846 | the PR Service into the <filename>PR</filename> field as |
| 6847 | an addition using the form "<filename>.x</filename>" so |
| 6848 | <filename>r0</filename> becomes <filename>r0.1</filename>, |
| 6849 | <filename>r0.2</filename> and so forth. |
| 6850 | This scheme allows existing <filename>PR</filename> values |
| 6851 | to be used for whatever reasons, which include manual |
| 6852 | <filename>PR</filename> bumps, should it be necessary. |
| 6853 | </para> |
| 6854 | |
| 6855 | <para> |
| 6856 | By default, the PR Service is not enabled or running. |
| 6857 | Thus, the packages generated are just "self consistent". |
| 6858 | The build system adds and removes packages and |
| 6859 | there are no guarantees about upgrade paths but images |
| 6860 | will be consistent and correct with the latest changes. |
| 6861 | </para> |
| 6862 | |
| 6863 | <para> |
| 6864 | The simplest form for a PR Service is for it to exist |
| 6865 | for a single host development system that builds the |
| 6866 | package feed (building system). |
| 6867 | For this scenario, you can enable a local PR Service by |
| 6868 | setting |
| 6869 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PRSERV_HOST'><filename>PRSERV_HOST</filename></ulink> |
| 6870 | in your <filename>local.conf</filename> file in the |
| 6871 | <ulink url='&YOCTO_DOCS_DEV_URL;#build-directory'>Build Directory</ulink>: |
| 6872 | <literallayout class='monospaced'> |
| 6873 | PRSERV_HOST = "localhost:0" |
| 6874 | </literallayout> |
| 6875 | Once the service is started, packages will automatically |
| 6876 | get increasing <filename>PR</filename> values and |
| 6877 | BitBake will take care of starting and stopping the server. |
| 6878 | </para> |
| 6879 | |
| 6880 | <para> |
| 6881 | If you have a more complex setup where multiple host |
| 6882 | development systems work against a common, shared package |
| 6883 | feed, you have a single PR Service running and it is |
| 6884 | connected to each building system. |
| 6885 | For this scenario, you need to start the PR Service using |
| 6886 | the <filename>bitbake-prserv</filename> command: |
| 6887 | <literallayout class='monospaced'> |
| 6888 | bitbake-prserv --host <replaceable>ip</replaceable> --port <replaceable>port</replaceable> --start |
| 6889 | </literallayout> |
| 6890 | In addition to hand-starting the service, you need to |
| 6891 | update the <filename>local.conf</filename> file of each |
| 6892 | building system as described earlier so each system |
| 6893 | points to the server and port. |
| 6894 | </para> |
| 6895 | |
| 6896 | <para> |
| 6897 | It is also recommended you use build history, which adds |
| 6898 | some sanity checks to package versions, in conjunction with |
| 6899 | the server that is running the PR Service. |
| 6900 | To enable build history, add the following to each building |
| 6901 | system's <filename>local.conf</filename> file: |
| 6902 | <literallayout class='monospaced'> |
| 6903 | # It is recommended to activate "buildhistory" for testing the PR service |
| 6904 | INHERIT += "buildhistory" |
| 6905 | BUILDHISTORY_COMMIT = "1" |
| 6906 | </literallayout> |
| 6907 | For information on build history, see the |
| 6908 | "<ulink url='&YOCTO_DOCS_REF_URL;#maintaining-build-output-quality'>Maintaining Build Output Quality</ulink>" |
| 6909 | section in the Yocto Project Reference Manual. |
| 6910 | </para> |
| 6911 | |
| 6912 | <note> |
| 6913 | <para>The OpenEmbedded build system does not maintain |
| 6914 | <filename>PR</filename> information as part of the |
| 6915 | shared state (sstate) packages. |
| 6916 | If you maintain an sstate feed, its expected that either |
| 6917 | all your building systems that contribute to the sstate |
| 6918 | feed use a shared PR Service, or you do not run a PR |
| 6919 | Service on any of your building systems. |
| 6920 | Having some systems use a PR Service while others do |
| 6921 | not leads to obvious problems.</para> |
| 6922 | <para>For more information on shared state, see the |
| 6923 | "<ulink url='&YOCTO_DOCS_REF_URL;#shared-state-cache'>Shared State Cache</ulink>" |
| 6924 | section in the Yocto Project Reference Manual.</para> |
| 6925 | </note> |
| 6926 | </section> |
| 6927 | |
| 6928 | <section id='manually-bumping-pr'> |
| 6929 | <title>Manually Bumping PR</title> |
| 6930 | |
| 6931 | <para> |
| 6932 | The alternative to setting up a PR Service is to manually |
| 6933 | bump the |
| 6934 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink> |
| 6935 | variable. |
| 6936 | </para> |
| 6937 | |
| 6938 | <para> |
| 6939 | If a committed change results in changing the package output, |
| 6940 | then the value of the PR variable needs to be increased |
| 6941 | (or "bumped") as part of that commit. |
| 6942 | For new recipes you should add the <filename>PR</filename> |
| 6943 | variable and set its initial value equal to "r0", which is the default. |
| 6944 | Even though the default value is "r0", the practice of adding it to a new recipe makes |
| 6945 | it harder to forget to bump the variable when you make changes |
| 6946 | to the recipe in future. |
| 6947 | </para> |
| 6948 | |
| 6949 | <para> |
| 6950 | If you are sharing a common <filename>.inc</filename> file with multiple recipes, |
| 6951 | you can also use the |
| 6952 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-INC_PR'>INC_PR</ulink></filename> |
| 6953 | variable to ensure that |
| 6954 | the recipes sharing the <filename>.inc</filename> file are rebuilt when the |
| 6955 | <filename>.inc</filename> file itself is changed. |
| 6956 | The <filename>.inc</filename> file must set <filename>INC_PR</filename> |
| 6957 | (initially to "r0"), and all recipes referring to it should set <filename>PR</filename> |
| 6958 | to "$(INC_PR).0" initially, incrementing the last number when the recipe is changed. |
| 6959 | If the <filename>.inc</filename> file is changed then its |
| 6960 | <filename>INC_PR</filename> should be incremented. |
| 6961 | </para> |
| 6962 | |
| 6963 | <para> |
| 6964 | When upgrading the version of a package, assuming the |
| 6965 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'>PV</ulink></filename> |
| 6966 | changes, the <filename>PR</filename> variable should be |
| 6967 | reset to "r0" (or "$(INC_PR).0" if you are using |
| 6968 | <filename>INC_PR</filename>). |
| 6969 | </para> |
| 6970 | |
| 6971 | <para> |
| 6972 | Usually, version increases occur only to packages. |
| 6973 | However, if for some reason <filename>PV</filename> changes but does not |
| 6974 | increase, you can increase the |
| 6975 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PE'>PE</ulink></filename> |
| 6976 | variable (Package Epoch). |
| 6977 | The <filename>PE</filename> variable defaults to "0". |
| 6978 | </para> |
| 6979 | |
| 6980 | <para> |
| 6981 | Version numbering strives to follow the |
| 6982 | <ulink url='http://www.debian.org/doc/debian-policy/ch-controlfields.html'> |
| 6983 | Debian Version Field Policy Guidelines</ulink>. |
| 6984 | These guidelines define how versions are compared and what "increasing" a version means. |
| 6985 | </para> |
| 6986 | </section> |
| 6987 | </section> |
| 6988 | |
| 6989 | <section id='handling-optional-module-packaging'> |
| 6990 | <title>Handling Optional Module Packaging</title> |
| 6991 | |
| 6992 | <para> |
| 6993 | Many pieces of software split functionality into optional |
| 6994 | modules (or plug-ins) and the plug-ins that are built |
| 6995 | might depend on configuration options. |
| 6996 | To avoid having to duplicate the logic that determines what |
| 6997 | modules are available in your recipe or to avoid having |
| 6998 | to package each module by hand, the OpenEmbedded build system |
| 6999 | provides functionality to handle module packaging dynamically. |
| 7000 | </para> |
| 7001 | |
| 7002 | <para> |
| 7003 | To handle optional module packaging, you need to do two things: |
| 7004 | <itemizedlist> |
| 7005 | <listitem><para>Ensure the module packaging is actually |
| 7006 | done.</para></listitem> |
| 7007 | <listitem><para>Ensure that any dependencies on optional |
| 7008 | modules from other recipes are satisfied by your recipe. |
| 7009 | </para></listitem> |
| 7010 | </itemizedlist> |
| 7011 | </para> |
| 7012 | |
| 7013 | <section id='making-sure-the-packaging-is-done'> |
| 7014 | <title>Making Sure the Packaging is Done</title> |
| 7015 | |
| 7016 | <para> |
| 7017 | To ensure the module packaging actually gets done, you use |
| 7018 | the <filename>do_split_packages</filename> function within |
| 7019 | the <filename>populate_packages</filename> Python function |
| 7020 | in your recipe. |
| 7021 | The <filename>do_split_packages</filename> function |
| 7022 | searches for a pattern of files or directories under a |
| 7023 | specified path and creates a package for each one it finds |
| 7024 | by appending to the |
| 7025 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink> |
| 7026 | variable and setting the appropriate values for |
| 7027 | <filename>FILES_packagename</filename>, |
| 7028 | <filename>RDEPENDS_packagename</filename>, |
| 7029 | <filename>DESCRIPTION_packagename</filename>, and so forth. |
| 7030 | Here is an example from the <filename>lighttpd</filename> |
| 7031 | recipe: |
| 7032 | <literallayout class='monospaced'> |
| 7033 | python populate_packages_prepend () { |
| 7034 | lighttpd_libdir = d.expand('${libdir}') |
| 7035 | do_split_packages(d, lighttpd_libdir, '^mod_(.*)\.so$', |
| 7036 | 'lighttpd-module-%s', 'Lighttpd module for %s', |
| 7037 | extra_depends='') |
| 7038 | } |
| 7039 | </literallayout> |
| 7040 | The previous example specifies a number of things in the |
| 7041 | call to <filename>do_split_packages</filename>. |
| 7042 | <itemizedlist> |
| 7043 | <listitem><para>A directory within the files installed |
| 7044 | by your recipe through <filename>do_install</filename> |
| 7045 | in which to search.</para></listitem> |
| 7046 | <listitem><para>A regular expression used to match module |
| 7047 | files in that directory. |
| 7048 | In the example, note the parentheses () that mark |
| 7049 | the part of the expression from which the module |
| 7050 | name should be derived.</para></listitem> |
| 7051 | <listitem><para>A pattern to use for the package names. |
| 7052 | </para></listitem> |
| 7053 | <listitem><para>A description for each package. |
| 7054 | </para></listitem> |
| 7055 | <listitem><para>An empty string for |
| 7056 | <filename>extra_depends</filename>, which disables |
| 7057 | the default dependency on the main |
| 7058 | <filename>lighttpd</filename> package. |
| 7059 | Thus, if a file in <filename>${libdir}</filename> |
| 7060 | called <filename>mod_alias.so</filename> is found, |
| 7061 | a package called <filename>lighttpd-module-alias</filename> |
| 7062 | is created for it and the |
| 7063 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DESCRIPTION'><filename>DESCRIPTION</filename></ulink> |
| 7064 | is set to "Lighttpd module for alias".</para></listitem> |
| 7065 | </itemizedlist> |
| 7066 | </para> |
| 7067 | |
| 7068 | <para> |
| 7069 | Often, packaging modules is as simple as the previous |
| 7070 | example. |
| 7071 | However, more advanced options exist that you can use |
| 7072 | within <filename>do_split_packages</filename> to modify its |
| 7073 | behavior. |
| 7074 | And, if you need to, you can add more logic by specifying |
| 7075 | a hook function that is called for each package. |
| 7076 | It is also perfectly acceptable to call |
| 7077 | <filename>do_split_packages</filename> multiple times if |
| 7078 | you have more than one set of modules to package. |
| 7079 | </para> |
| 7080 | |
| 7081 | <para> |
| 7082 | For more examples that show how to use |
| 7083 | <filename>do_split_packages</filename>, see the |
| 7084 | <filename>connman.inc</filename> file in the |
| 7085 | <filename>meta/recipes-connectivity/connman/</filename> |
| 7086 | directory of the <filename>poky</filename> |
| 7087 | <link linkend='yocto-project-repositories'>source repository</link>. |
| 7088 | You can also find examples in |
| 7089 | <filename>meta/classes/kernel.bbclass</filename>. |
| 7090 | </para> |
| 7091 | |
| 7092 | <para> |
| 7093 | Following is a reference that shows |
| 7094 | <filename>do_split_packages</filename> mandatory and |
| 7095 | optional arguments: |
| 7096 | <literallayout class='monospaced'> |
| 7097 | Mandatory arguments |
| 7098 | |
| 7099 | root |
| 7100 | The path in which to search |
| 7101 | file_regex |
| 7102 | Regular expression to match searched files. |
| 7103 | Use parentheses () to mark the part of this |
| 7104 | expression that should be used to derive the |
| 7105 | module name (to be substituted where %s is |
| 7106 | used in other function arguments as noted below) |
| 7107 | output_pattern |
| 7108 | Pattern to use for the package names. Must |
| 7109 | include %s. |
| 7110 | description |
| 7111 | Description to set for each package. Must |
| 7112 | include %s. |
| 7113 | |
| 7114 | Optional arguments |
| 7115 | |
| 7116 | postinst |
| 7117 | Postinstall script to use for all packages |
| 7118 | (as a string) |
| 7119 | recursive |
| 7120 | True to perform a recursive search - default |
| 7121 | False |
| 7122 | hook |
| 7123 | A hook function to be called for every match. |
| 7124 | The function will be called with the following |
| 7125 | arguments (in the order listed): |
| 7126 | |
| 7127 | f |
| 7128 | Full path to the file/directory match |
| 7129 | pkg |
| 7130 | The package name |
| 7131 | file_regex |
| 7132 | As above |
| 7133 | output_pattern |
| 7134 | As above |
| 7135 | modulename |
| 7136 | The module name derived using file_regex |
| 7137 | |
| 7138 | extra_depends |
| 7139 | Extra runtime dependencies (RDEPENDS) to be |
| 7140 | set for all packages. The default value of None |
| 7141 | causes a dependency on the main package |
| 7142 | (${PN}) - if you do not want this, pass empty |
| 7143 | string '' for this parameter. |
| 7144 | aux_files_pattern |
| 7145 | Extra item(s) to be added to FILES for each |
| 7146 | package. Can be a single string item or a list |
| 7147 | of strings for multiple items. Must include %s. |
| 7148 | postrm |
| 7149 | postrm script to use for all packages (as a |
| 7150 | string) |
| 7151 | allow_dirs |
| 7152 | True to allow directories to be matched - |
| 7153 | default False |
| 7154 | prepend |
| 7155 | If True, prepend created packages to PACKAGES |
| 7156 | instead of the default False which appends them |
| 7157 | match_path |
| 7158 | match file_regex on the whole relative path to |
| 7159 | the root rather than just the file name |
| 7160 | aux_files_pattern_verbatim |
| 7161 | Extra item(s) to be added to FILES for each |
| 7162 | package, using the actual derived module name |
| 7163 | rather than converting it to something legal |
| 7164 | for a package name. Can be a single string item |
| 7165 | or a list of strings for multiple items. Must |
| 7166 | include %s. |
| 7167 | allow_links |
| 7168 | True to allow symlinks to be matched - default |
| 7169 | False |
| 7170 | summary |
| 7171 | Summary to set for each package. Must include %s; |
| 7172 | defaults to description if not set. |
| 7173 | </literallayout> |
| 7174 | </para> |
| 7175 | </section> |
| 7176 | |
| 7177 | <section id='satisfying-dependencies'> |
| 7178 | <title>Satisfying Dependencies</title> |
| 7179 | |
| 7180 | <para> |
| 7181 | The second part for handling optional module packaging |
| 7182 | is to ensure that any dependencies on optional modules |
| 7183 | from other recipes are satisfied by your recipe. |
| 7184 | You can be sure these dependencies are satisfied by |
| 7185 | using the |
| 7186 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES_DYNAMIC'><filename>PACKAGES_DYNAMIC</filename></ulink> variable. |
| 7187 | Here is an example that continues with the |
| 7188 | <filename>lighttpd</filename> recipe shown earlier: |
| 7189 | <literallayout class='monospaced'> |
| 7190 | PACKAGES_DYNAMIC = "lighttpd-module-.*" |
| 7191 | </literallayout> |
| 7192 | The name specified in the regular expression can of |
| 7193 | course be anything. |
| 7194 | In this example, it is <filename>lighttpd-module-</filename> |
| 7195 | and is specified as the prefix to ensure that any |
| 7196 | <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink> |
| 7197 | and <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink> |
| 7198 | on a package name starting with the prefix are satisfied |
| 7199 | during build time. |
| 7200 | If you are using <filename>do_split_packages</filename> |
| 7201 | as described in the previous section, the value you put in |
| 7202 | <filename>PACKAGES_DYNAMIC</filename> should correspond to |
| 7203 | the name pattern specified in the call to |
| 7204 | <filename>do_split_packages</filename>. |
| 7205 | </para> |
| 7206 | </section> |
| 7207 | </section> |
| 7208 | |
| 7209 | <section id='using-runtime-package-management'> |
| 7210 | <title>Using Runtime Package Management</title> |
| 7211 | |
| 7212 | <para> |
| 7213 | During a build, BitBake always transforms a recipe into one or |
| 7214 | more packages. |
| 7215 | For example, BitBake takes the <filename>bash</filename> recipe |
| 7216 | and currently produces the <filename>bash-dbg</filename>, |
| 7217 | <filename>bash-staticdev</filename>, |
| 7218 | <filename>bash-dev</filename>, <filename>bash-doc</filename>, |
| 7219 | <filename>bash-locale</filename>, and |
| 7220 | <filename>bash</filename> packages. |
| 7221 | Not all generated packages are included in an image. |
| 7222 | </para> |
| 7223 | |
| 7224 | <para> |
| 7225 | In several situations, you might need to update, add, remove, |
| 7226 | or query the packages on a target device at runtime |
| 7227 | (i.e. without having to generate a new image). |
| 7228 | Examples of such situations include: |
| 7229 | <itemizedlist> |
| 7230 | <listitem><para> |
| 7231 | You want to provide in-the-field updates to deployed |
| 7232 | devices (e.g. security updates). |
| 7233 | </para></listitem> |
| 7234 | <listitem><para> |
| 7235 | You want to have a fast turn-around development cycle |
| 7236 | for one or more applications that run on your device. |
| 7237 | </para></listitem> |
| 7238 | <listitem><para> |
| 7239 | You want to temporarily install the "debug" packages |
| 7240 | of various applications on your device so that |
| 7241 | debugging can be greatly improved by allowing |
| 7242 | access to symbols and source debugging. |
| 7243 | </para></listitem> |
| 7244 | <listitem><para> |
| 7245 | You want to deploy a more minimal package selection of |
| 7246 | your device but allow in-the-field updates to add a |
| 7247 | larger selection for customization. |
| 7248 | </para></listitem> |
| 7249 | </itemizedlist> |
| 7250 | </para> |
| 7251 | |
| 7252 | <para> |
| 7253 | In all these situations, you have something similar to a more |
| 7254 | traditional Linux distribution in that in-field devices |
| 7255 | are able to receive pre-compiled packages from a server for |
| 7256 | installation or update. |
| 7257 | Being able to install these packages on a running, |
| 7258 | in-field device is what is termed "runtime package |
| 7259 | management". |
| 7260 | </para> |
| 7261 | |
| 7262 | <para> |
| 7263 | In order to use runtime package management, you |
| 7264 | need a host/server machine that serves up the pre-compiled |
| 7265 | packages plus the required metadata. |
| 7266 | You also need package manipulation tools on the target. |
| 7267 | The build machine is a likely candidate to act as the server. |
| 7268 | However, that machine does not necessarily have to be the |
| 7269 | package server. |
| 7270 | The build machine could push its artifacts to another machine |
| 7271 | that acts as the server (e.g. Internet-facing). |
| 7272 | </para> |
| 7273 | |
| 7274 | <para> |
| 7275 | A simple build that targets just one device produces |
| 7276 | more than one package database. |
| 7277 | In other words, the packages produced by a build are separated |
| 7278 | out into a couple of different package groupings based on |
| 7279 | criteria such as the target's CPU architecture, the target |
| 7280 | board, or the C library used on the target. |
| 7281 | For example, a build targeting the <filename>qemuarm</filename> |
| 7282 | device produces the following three package databases: |
| 7283 | <filename>all</filename>, <filename>armv5te</filename>, and |
| 7284 | <filename>qemuarm</filename>. |
| 7285 | If you wanted your <filename>qemuarm</filename> device to be |
| 7286 | aware of all the packages that were available to it, |
| 7287 | you would need to point it to each of these databases |
| 7288 | individually. |
| 7289 | In a similar way, a traditional Linux distribution usually is |
| 7290 | configured to be aware of a number of software repositories |
| 7291 | from which it retrieves packages. |
| 7292 | </para> |
| 7293 | |
| 7294 | <para> |
| 7295 | Using runtime package management is completely optional and |
| 7296 | not required for a successful build or deployment in any |
| 7297 | way. |
| 7298 | But if you want to make use of runtime package management, |
| 7299 | you need to do a couple things above and beyond the basics. |
| 7300 | The remainder of this section describes what you need to do. |
| 7301 | </para> |
| 7302 | |
| 7303 | <section id='runtime-package-management-build'> |
| 7304 | <title>Build Considerations</title> |
| 7305 | |
| 7306 | <para> |
| 7307 | This section describes build considerations that you need |
| 7308 | to be aware of in order to provide support for runtime |
| 7309 | package management. |
| 7310 | </para> |
| 7311 | |
| 7312 | <para> |
| 7313 | When BitBake generates packages it needs to know |
| 7314 | what format or formats to use. |
| 7315 | In your configuration, you use the |
| 7316 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink> |
| 7317 | variable to specify the format. |
| 7318 | <note> |
| 7319 | You can choose to have more than one format but you must |
| 7320 | provide at least one. |
| 7321 | </note> |
| 7322 | </para> |
| 7323 | |
| 7324 | <para> |
| 7325 | If you would like your image to start off with a basic |
| 7326 | package database of the packages in your current build |
| 7327 | as well as have the relevant tools available on the |
| 7328 | target for runtime package management, you can include |
| 7329 | "package-management" in the |
| 7330 | <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink> |
| 7331 | variable. |
| 7332 | Including "package-management" in this |
| 7333 | configuration variable ensures that when the image |
| 7334 | is assembled for your target, the image includes |
| 7335 | the currently-known package databases as well as |
| 7336 | the target-specific tools required for runtime |
| 7337 | package management to be performed on the target. |
| 7338 | However, this is not strictly necessary. |
| 7339 | You could start your image off without any databases |
| 7340 | but only include the required on-target package |
| 7341 | tool(s). |
| 7342 | As an example, you could include "opkg" in your |
| 7343 | <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink> |
| 7344 | variable if you are using the IPK package format. |
| 7345 | You can then initialize your target's package database(s) |
| 7346 | later once your image is up and running. |
| 7347 | </para> |
| 7348 | |
| 7349 | <para> |
| 7350 | Whenever you perform any sort of build step that can |
| 7351 | potentially generate a package or modify an existing |
| 7352 | package, it is always a good idea to re-generate the |
| 7353 | package index with: |
| 7354 | <literallayout class='monospaced'> |
| 7355 | $ bitbake package-index |
| 7356 | </literallayout> |
| 7357 | Realize that it is not sufficient to simply do the |
| 7358 | following: |
| 7359 | <literallayout class='monospaced'> |
| 7360 | $ bitbake <replaceable>some-package</replaceable> package-index |
| 7361 | </literallayout> |
| 7362 | This is because BitBake does not properly schedule the |
| 7363 | <filename>package-index</filename> target fully after any |
| 7364 | other target has completed. |
| 7365 | Thus, be sure to run the package update step separately. |
| 7366 | </para> |
| 7367 | |
| 7368 | <para> |
| 7369 | As described below in the |
| 7370 | "<link linkend='runtime-package-management-target-ipk'>Using IPK</link>" |
| 7371 | section, if you are using IPK as your package format, you |
| 7372 | can make use of the |
| 7373 | <filename>distro-feed-configs</filename> recipe provided |
| 7374 | by <filename>meta-oe</filename> in order to configure your |
| 7375 | target to use your IPK databases. |
| 7376 | </para> |
| 7377 | |
| 7378 | <para> |
| 7379 | When your build is complete, your packages reside in the |
| 7380 | <filename>${TMPDIR}/deploy/<replaceable>package-format</replaceable></filename> |
| 7381 | directory. |
| 7382 | For example, if <filename>${TMPDIR}</filename> |
| 7383 | is <filename>tmp</filename> and your selected package type |
| 7384 | is IPK, then your IPK packages are available in |
| 7385 | <filename>tmp/deploy/ipk</filename>. |
| 7386 | </para> |
| 7387 | </section> |
| 7388 | |
| 7389 | <section id='runtime-package-management-server'> |
| 7390 | <title>Host or Server Machine Setup</title> |
| 7391 | |
| 7392 | <para> |
| 7393 | Typically, packages are served from a server using |
| 7394 | HTTP. |
| 7395 | However, other protocols are possible. |
| 7396 | If you want to use HTTP, then setup and configure a |
| 7397 | web server, such as Apache 2 or lighttpd, on the machine |
| 7398 | serving the packages. |
| 7399 | </para> |
| 7400 | |
| 7401 | <para> |
| 7402 | As previously mentioned, the build machine can act as the |
| 7403 | package server. |
| 7404 | In the following sections that describe server machine |
| 7405 | setups, the build machine is assumed to also be the server. |
| 7406 | </para> |
| 7407 | |
| 7408 | <section id='package-server-apache'> |
| 7409 | <title>Serving Packages via Apache 2</title> |
| 7410 | |
| 7411 | <para> |
| 7412 | This example assumes you are using the Apache 2 |
| 7413 | server: |
| 7414 | <orderedlist> |
| 7415 | <listitem><para> |
| 7416 | Add the directory to your Apache |
| 7417 | configuration, which you can find at |
| 7418 | <filename>/etc/httpd/conf/httpd.conf</filename>. |
| 7419 | Use commands similar to these on the |
| 7420 | development system. |
| 7421 | These example commands assume a top-level |
| 7422 | <link linkend='source-directory'>Source Directory</link> |
| 7423 | named <filename>poky</filename> in your home |
| 7424 | directory. |
| 7425 | The example also assumes an RPM package type. |
| 7426 | If you are using a different package type, such |
| 7427 | as IPK, use "ipk" in the pathnames: |
| 7428 | <literallayout class='monospaced'> |
| 7429 | <VirtualHost *:80> |
| 7430 | .... |
| 7431 | Alias /rpm ~/poky/build/tmp/deploy/rpm |
| 7432 | <Directory "~/poky/build/tmp/deploy/rpm"> |
| 7433 | Options +Indexes |
| 7434 | </Directory> |
| 7435 | </VirtualHost> |
| 7436 | </literallayout></para></listitem> |
| 7437 | <listitem><para> |
| 7438 | Reload the Apache configuration as described |
| 7439 | in this step. |
| 7440 | For all commands, be sure you have root |
| 7441 | privileges. |
| 7442 | </para> |
| 7443 | |
| 7444 | <para> |
| 7445 | If your development system is using Fedora or |
| 7446 | CentOS, use the following: |
| 7447 | <literallayout class='monospaced'> |
| 7448 | # service httpd reload |
| 7449 | </literallayout> |
| 7450 | For Ubuntu and Debian, use the following: |
| 7451 | <literallayout class='monospaced'> |
| 7452 | # /etc/init.d/apache2 reload |
| 7453 | </literallayout> |
| 7454 | For OpenSUSE, use the following: |
| 7455 | <literallayout class='monospaced'> |
| 7456 | # /etc/init.d/apache2 reload |
| 7457 | </literallayout></para></listitem> |
| 7458 | <listitem><para> |
| 7459 | If you are using Security-Enhanced Linux |
| 7460 | (SELinux), you need to label the files as |
| 7461 | being accessible through Apache. |
| 7462 | Use the following command from the development |
| 7463 | host. |
| 7464 | This example assumes RPM package types: |
| 7465 | <literallayout class='monospaced'> |
| 7466 | # chcon -R -h -t httpd_sys_content_t tmp/deploy/rpm |
| 7467 | </literallayout></para></listitem> |
| 7468 | </orderedlist> |
| 7469 | </para> |
| 7470 | </section> |
| 7471 | |
| 7472 | <section id='package-server-lighttpd'> |
| 7473 | <title>Serving Packages via lighttpd</title> |
| 7474 | |
| 7475 | <para> |
| 7476 | If you are using lighttpd, all you need |
| 7477 | to do is to provide a link from your |
| 7478 | <filename>${TMPDIR}/deploy/<replaceable>package-format</replaceable></filename> |
| 7479 | directory to lighttpd's document-root. |
| 7480 | You can determine the specifics of your lighttpd |
| 7481 | installation by looking through its configuration file, |
| 7482 | which is usually found at: |
| 7483 | <filename>/etc/lighttpd/lighttpd.conf</filename>. |
| 7484 | </para> |
| 7485 | |
| 7486 | <para> |
| 7487 | For example, if you are using IPK, lighttpd's |
| 7488 | document-root is set to |
| 7489 | <filename>/var/www/lighttpd</filename>, and you had |
| 7490 | packages for a target named "BOARD", |
| 7491 | then you might create a link from your build location |
| 7492 | to lighttpd's document-root as follows: |
| 7493 | <literallayout class='monospaced'> |
| 7494 | # ln -s $(PWD)/tmp/deploy/ipk /var/www/lighttpd/BOARD-dir |
| 7495 | </literallayout> |
| 7496 | </para> |
| 7497 | |
| 7498 | <para> |
| 7499 | At this point, you need to start the lighttpd server. |
| 7500 | The method used to start the server varies by |
| 7501 | distribution. |
| 7502 | However, one basic method that starts it by hand is: |
| 7503 | <literallayout class='monospaced'> |
| 7504 | # lighttpd -f /etc/lighttpd/lighttpd.conf |
| 7505 | </literallayout> |
| 7506 | </para> |
| 7507 | </section> |
| 7508 | </section> |
| 7509 | |
| 7510 | <section id='runtime-package-management-target'> |
| 7511 | <title>Target Setup</title> |
| 7512 | |
| 7513 | <para> |
| 7514 | Setting up the target differs depending on the |
| 7515 | package management system. |
| 7516 | This section provides information for RPM and IPK. |
| 7517 | </para> |
| 7518 | |
| 7519 | <section id='runtime-package-management-target-rpm'> |
| 7520 | <title>Using RPM</title> |
| 7521 | |
| 7522 | <para> |
| 7523 | The application for performing runtime package |
| 7524 | management of RPM packages on the target is called |
| 7525 | <filename>smart</filename>. |
| 7526 | </para> |
| 7527 | |
| 7528 | <para> |
| 7529 | On the target machine, you need to inform |
| 7530 | <filename>smart</filename> of every package database |
| 7531 | you want to use. |
| 7532 | As an example, suppose your target device can use the |
| 7533 | following three package databases from a server named |
| 7534 | <filename>server.name</filename>: |
| 7535 | <filename>all</filename>, <filename>i586</filename>, |
| 7536 | and <filename>qemux86</filename>. |
| 7537 | Given this example, issue the following commands on the |
| 7538 | target: |
| 7539 | <literallayout class='monospaced'> |
| 7540 | # smart channel --add all type=rpm-md baseurl=http://server.name/rpm/all |
| 7541 | # smart channel --add i585 type=rpm-md baseurl=http://server.name/rpm/i586 |
| 7542 | # smart channel --add qemux86 type=rpm-md baseurl=http://server.name/rpm/qemux86 |
| 7543 | </literallayout> |
| 7544 | Also from the target machine, fetch the repository |
| 7545 | information using this command: |
| 7546 | <literallayout class='monospaced'> |
| 7547 | # smart update |
| 7548 | </literallayout> |
| 7549 | You can now use the <filename>smart query</filename> |
| 7550 | and <filename>smart install</filename> commands to |
| 7551 | find and install packages from the repositories. |
| 7552 | </para> |
| 7553 | </section> |
| 7554 | |
| 7555 | <section id='runtime-package-management-target-ipk'> |
| 7556 | <title>Using IPK</title> |
| 7557 | |
| 7558 | <para> |
| 7559 | The application for performing runtime package |
| 7560 | management of IPK packages on the target is called |
| 7561 | <filename>opkg</filename>. |
| 7562 | </para> |
| 7563 | |
| 7564 | <para> |
| 7565 | In order to inform <filename>opkg</filename> of the |
| 7566 | package databases you want to use, simply create one |
| 7567 | or more <filename>*.conf</filename> files in the |
| 7568 | <filename>/etc/opkg</filename> directory on the target. |
| 7569 | The <filename>opkg</filename> application uses them |
| 7570 | to find its available package databases. |
| 7571 | As an example, suppose you configured your HTTP server |
| 7572 | on your machine named |
| 7573 | <filename>www.mysite.com</filename> to serve files |
| 7574 | from a <filename>BOARD-dir</filename> directory under |
| 7575 | its document-root. |
| 7576 | In this case, you might create a configuration |
| 7577 | file on the target called |
| 7578 | <filename>/etc/opkg/base-feeds.conf</filename> that |
| 7579 | contains: |
| 7580 | <literallayout class='monospaced'> |
| 7581 | src/gz all http://www.mysite.com/BOARD-dir/all |
| 7582 | src/gz armv7a http://www.mysite.com/BOARD-dir/armv7a |
| 7583 | src/gz beaglebone http://www.mysite.com/BOARD-dir/beaglebone |
| 7584 | </literallayout> |
| 7585 | </para> |
| 7586 | |
| 7587 | <para> |
| 7588 | As a way of making it easier to generate and make |
| 7589 | these IPK configuration files available on your |
| 7590 | target, simply define |
| 7591 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FEED_DEPLOYDIR_BASE_URI'><filename>FEED_DEPLOYDIR_BASE_URI</filename></ulink> |
| 7592 | to point to your server and the location within the |
| 7593 | document-root which contains the databases. |
| 7594 | For example: if you are serving your packages over |
| 7595 | HTTP, your server's IP address is 192.168.7.1, and |
| 7596 | your databases are located in a directory called |
| 7597 | <filename>BOARD-dir</filename> underneath your HTTP |
| 7598 | server's document-root, you need to set |
| 7599 | <filename>FEED_DEPLOYDIR_BASE_URI</filename> to |
| 7600 | <filename>http://192.168.7.1/BOARD-dir</filename> and |
| 7601 | a set of configuration files will be generated for you |
| 7602 | in your target to work with this feed. |
| 7603 | </para> |
| 7604 | |
| 7605 | <para> |
| 7606 | On the target machine, fetch (or refresh) the |
| 7607 | repository information using this command: |
| 7608 | <literallayout class='monospaced'> |
| 7609 | # opkg update |
| 7610 | </literallayout> |
| 7611 | You can now use the <filename>opkg list</filename> and |
| 7612 | <filename>opkg install</filename> commands to find and |
| 7613 | install packages from the repositories. |
| 7614 | </para> |
| 7615 | </section> |
| 7616 | </section> |
| 7617 | </section> |
| 7618 | |
| 7619 | <section id='testing-packages-with-ptest'> |
| 7620 | <title>Testing Packages With ptest</title> |
| 7621 | |
| 7622 | <para> |
| 7623 | A Package Test (ptest) runs tests against packages built |
| 7624 | by the OpenEmbedded build system on the target machine. |
| 7625 | A ptest contains at least two items: the actual test, and |
| 7626 | a shell script (<filename>run-ptest</filename>) that starts |
| 7627 | the test. |
| 7628 | The shell script that starts the test must not contain |
| 7629 | the actual test - the script only starts the test. |
| 7630 | On the other hand, the test can be anything from a simple |
| 7631 | shell script that runs a binary and checks the output to |
| 7632 | an elaborate system of test binaries and data files. |
| 7633 | </para> |
| 7634 | |
| 7635 | <para> |
| 7636 | The test generates output in the format used by |
| 7637 | Automake: |
| 7638 | <literallayout class='monospaced'> |
| 7639 | <replaceable>result</replaceable>: <replaceable>testname</replaceable> |
| 7640 | </literallayout> |
| 7641 | where the result can be <filename>PASS</filename>, |
| 7642 | <filename>FAIL</filename>, or <filename>SKIP</filename>, |
| 7643 | and the testname can be any identifying string. |
| 7644 | </para> |
| 7645 | |
| 7646 | <para> |
| 7647 | For a list of Yocto Project recipes that are already |
| 7648 | enabled with ptest, see the |
| 7649 | <ulink url='https://wiki.yoctoproject.org/wiki/Ptest'>Ptest</ulink> |
| 7650 | wiki page. |
| 7651 | <note> |
| 7652 | A recipe is "ptest-enabled" if it inherits the |
| 7653 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-ptest'><filename>ptest</filename></ulink> |
| 7654 | class. |
| 7655 | </note> |
| 7656 | </para> |
| 7657 | |
| 7658 | <section id='adding-ptest-to-your-build'> |
| 7659 | <title>Adding ptest to Your Build</title> |
| 7660 | |
| 7661 | <para> |
| 7662 | To add package testing to your build, add the |
| 7663 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink> |
| 7664 | and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink> |
| 7665 | variables to your <filename>local.conf</filename> file, |
| 7666 | which is found in the |
| 7667 | <link linkend='build-directory'>Build Directory</link>: |
| 7668 | <literallayout class='monospaced'> |
| 7669 | DISTRO_FEATURES_append = " ptest" |
| 7670 | EXTRA_IMAGE_FEATURES += "ptest-pkgs" |
| 7671 | </literallayout> |
| 7672 | Once your build is complete, the ptest files are installed |
| 7673 | into the |
| 7674 | <filename>/usr/lib/<replaceable>package</replaceable>/ptest</filename> |
| 7675 | directory within the image, where |
| 7676 | <filename><replaceable>package</replaceable></filename> |
| 7677 | is the name of the package. |
| 7678 | </para> |
| 7679 | </section> |
| 7680 | |
| 7681 | <section id='running-ptest'> |
| 7682 | <title>Running ptest</title> |
| 7683 | |
| 7684 | <para> |
| 7685 | The <filename>ptest-runner</filename> package installs a |
| 7686 | shell script that loops through all installed ptest test |
| 7687 | suites and runs them in sequence. |
| 7688 | Consequently, you might want to add this package to |
| 7689 | your image. |
| 7690 | </para> |
| 7691 | </section> |
| 7692 | |
| 7693 | <section id='getting-your-package-ready'> |
| 7694 | <title>Getting Your Package Ready</title> |
| 7695 | |
| 7696 | <para> |
| 7697 | In order to enable a recipe to run installed ptests |
| 7698 | on target hardware, |
| 7699 | you need to prepare the recipes that build the packages |
| 7700 | you want to test. |
| 7701 | Here is what you have to do for each recipe: |
| 7702 | <itemizedlist> |
| 7703 | <listitem><para><emphasis>Be sure the recipe |
| 7704 | inherits the |
| 7705 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-ptest'><filename>ptest</filename></ulink> |
| 7706 | class:</emphasis> |
| 7707 | Include the following line in each recipe: |
| 7708 | <literallayout class='monospaced'> |
| 7709 | inherit ptest |
| 7710 | </literallayout> |
| 7711 | </para></listitem> |
| 7712 | <listitem><para><emphasis>Create <filename>run-ptest</filename>:</emphasis> |
| 7713 | This script starts your test. |
| 7714 | Locate the script where you will refer to it |
| 7715 | using |
| 7716 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>. |
| 7717 | Here is an example that starts a test for |
| 7718 | <filename>dbus</filename>: |
| 7719 | <literallayout class='monospaced'> |
| 7720 | #!/bin/sh |
| 7721 | cd test |
| 7722 | make -k runtest-TESTS |
| 7723 | </literallayout> |
| 7724 | </para></listitem> |
| 7725 | <listitem><para><emphasis>Ensure dependencies are |
| 7726 | met:</emphasis> |
| 7727 | If the test adds build or runtime dependencies |
| 7728 | that normally do not exist for the package |
| 7729 | (such as requiring "make" to run the test suite), |
| 7730 | use the |
| 7731 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink> |
| 7732 | and |
| 7733 | <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink> |
| 7734 | variables in your recipe in order for the package |
| 7735 | to meet the dependencies. |
| 7736 | Here is an example where the package has a runtime |
| 7737 | dependency on "make": |
| 7738 | <literallayout class='monospaced'> |
| 7739 | RDEPENDS_${PN}-ptest += "make" |
| 7740 | </literallayout> |
| 7741 | </para></listitem> |
| 7742 | <listitem><para><emphasis>Add a function to build the |
| 7743 | test suite:</emphasis> |
| 7744 | Not many packages support cross-compilation of |
| 7745 | their test suites. |
| 7746 | Consequently, you usually need to add a |
| 7747 | cross-compilation function to the package. |
| 7748 | </para> |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 7749 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7750 | <para>Many packages based on Automake compile and |
| 7751 | run the test suite by using a single command |
| 7752 | such as <filename>make check</filename>. |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 7753 | However, the host <filename>make check</filename> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7754 | builds and runs on the same computer, while |
| 7755 | cross-compiling requires that the package is built |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 7756 | on the host but executed for the target |
| 7757 | architecture (though often, as in the case for |
| 7758 | ptest, the execution occurs on the host). |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7759 | The built version of Automake that ships with the |
| 7760 | Yocto Project includes a patch that separates |
| 7761 | building and execution. |
| 7762 | Consequently, packages that use the unaltered, |
| 7763 | patched version of <filename>make check</filename> |
| 7764 | automatically cross-compiles.</para> |
| 7765 | <para>Regardless, you still must add a |
| 7766 | <filename>do_compile_ptest</filename> function to |
| 7767 | build the test suite. |
| 7768 | Add a function similar to the following to your |
| 7769 | recipe: |
| 7770 | <literallayout class='monospaced'> |
| 7771 | do_compile_ptest() { |
| 7772 | oe_runmake buildtest-TESTS |
| 7773 | } |
| 7774 | </literallayout> |
| 7775 | </para></listitem> |
| 7776 | <listitem><para><emphasis>Ensure special configurations |
| 7777 | are set:</emphasis> |
| 7778 | If the package requires special configurations |
| 7779 | prior to compiling the test code, you must |
| 7780 | insert a <filename>do_configure_ptest</filename> |
| 7781 | function into the recipe. |
| 7782 | </para></listitem> |
| 7783 | <listitem><para><emphasis>Install the test |
| 7784 | suite:</emphasis> |
| 7785 | The <filename>ptest</filename> class |
| 7786 | automatically copies the file |
| 7787 | <filename>run-ptest</filename> to the target and |
| 7788 | then runs make <filename>install-ptest</filename> |
| 7789 | to run the tests. |
| 7790 | If this is not enough, you need to create a |
| 7791 | <filename>do_install_ptest</filename> function and |
| 7792 | make sure it gets called after the |
| 7793 | "make install-ptest" completes. |
| 7794 | </para></listitem> |
| 7795 | </itemizedlist> |
| 7796 | </para> |
| 7797 | </section> |
| 7798 | </section> |
| 7799 | </section> |
| 7800 | |
| 7801 | <section id='working-with-source-files'> |
| 7802 | <title>Working with Source Files</title> |
| 7803 | |
| 7804 | <para> |
| 7805 | The OpenEmbedded build system works with source files located |
| 7806 | through the |
| 7807 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> |
| 7808 | variable. |
| 7809 | When you build something using BitBake, a big part of the operation |
| 7810 | is locating and downloading all the source tarballs. |
| 7811 | For images, downloading all the source for various packages can |
| 7812 | take a significant amount of time. |
| 7813 | </para> |
| 7814 | |
| 7815 | <para> |
| 7816 | This section presents information for working with source |
| 7817 | files that can lead to more efficient use of resources and |
| 7818 | time. |
| 7819 | </para> |
| 7820 | |
| 7821 | <section id='setting-up-effective-mirrors'> |
| 7822 | <title>Setting up Effective Mirrors</title> |
| 7823 | |
| 7824 | <para> |
| 7825 | As mentioned, a good deal that goes into a Yocto Project |
| 7826 | build is simply downloading all of the source tarballs. |
| 7827 | Maybe you have been working with another build system |
| 7828 | (OpenEmbedded or Angstrom) for which you have built up a |
| 7829 | sizable directory of source tarballs. |
| 7830 | Or, perhaps someone else has such a directory for which you |
| 7831 | have read access. |
| 7832 | If so, you can save time by adding statements to your |
| 7833 | configuration file so that the build process checks local |
| 7834 | directories first for existing tarballs before checking the |
| 7835 | Internet. |
| 7836 | </para> |
| 7837 | |
| 7838 | <para> |
| 7839 | Here is an efficient way to set it up in your |
| 7840 | <filename>local.conf</filename> file: |
| 7841 | <literallayout class='monospaced'> |
| 7842 | SOURCE_MIRROR_URL ?= "file:///home/you/your-download-dir/" |
| 7843 | INHERIT += "own-mirrors" |
| 7844 | BB_GENERATE_MIRROR_TARBALLS = "1" |
| 7845 | # BB_NO_NETWORK = "1" |
| 7846 | </literallayout> |
| 7847 | </para> |
| 7848 | |
| 7849 | <para> |
| 7850 | In the previous example, the |
| 7851 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_GENERATE_MIRROR_TARBALLS'><filename>BB_GENERATE_MIRROR_TARBALLS</filename></ulink> |
| 7852 | variable causes the OpenEmbedded build system to generate |
| 7853 | tarballs of the Git repositories and store them in the |
| 7854 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink> |
| 7855 | directory. |
| 7856 | Due to performance reasons, generating and storing these |
| 7857 | tarballs is not the build system's default behavior. |
| 7858 | </para> |
| 7859 | |
| 7860 | <para> |
| 7861 | You can also use the |
| 7862 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PREMIRRORS'><filename>PREMIRRORS</filename></ulink> |
| 7863 | variable. |
| 7864 | For an example, see the variable's glossary entry in the |
| 7865 | Yocto Project Reference Manual. |
| 7866 | </para> |
| 7867 | </section> |
| 7868 | |
| 7869 | <section id='getting-source-files-and-suppressing-the-build'> |
| 7870 | <title>Getting Source Files and Suppressing the Build</title> |
| 7871 | |
| 7872 | <para> |
| 7873 | Another technique you can use to ready yourself for a |
| 7874 | successive string of build operations, is to pre-fetch |
| 7875 | all the source files without actually starting a build. |
| 7876 | This technique lets you work through any download issues |
| 7877 | and ultimately gathers all the source files into your |
| 7878 | download directory |
| 7879 | <ulink url='&YOCTO_DOCS_REF_URL;#structure-build-downloads'><filename>build/downloads</filename></ulink>, |
| 7880 | which is located with |
| 7881 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>. |
| 7882 | </para> |
| 7883 | |
| 7884 | <para> |
| 7885 | Use the following BitBake command form to fetch all the |
| 7886 | necessary sources without starting the build: |
| 7887 | <literallayout class='monospaced'> |
| 7888 | $ bitbake -c fetchall <replaceable>target</replaceable> |
| 7889 | </literallayout> |
| 7890 | This variation of the BitBake command guarantees that you |
| 7891 | have all the sources for that BitBake target should you |
| 7892 | disconnect from the Internet and want to do the build |
| 7893 | later offline. |
| 7894 | </para> |
| 7895 | </section> |
| 7896 | </section> |
| 7897 | |
| 7898 | <section id="building-software-from-an-external-source"> |
| 7899 | <title>Building Software from an External Source</title> |
| 7900 | |
| 7901 | <para> |
| 7902 | By default, the OpenEmbedded build system uses the |
| 7903 | <link linkend='build-directory'>Build Directory</link> when |
| 7904 | building source code. |
| 7905 | The build process involves fetching the source files, unpacking |
| 7906 | them, and then patching them if necessary before the build takes |
| 7907 | place. |
| 7908 | </para> |
| 7909 | |
| 7910 | <para> |
| 7911 | Situations exist where you might want to build software from source |
| 7912 | files that are external to and thus outside of the |
| 7913 | OpenEmbedded build system. |
| 7914 | For example, suppose you have a project that includes a new BSP with |
| 7915 | a heavily customized kernel. |
| 7916 | And, you want to minimize exposing the build system to the |
| 7917 | development team so that they can focus on their project and |
| 7918 | maintain everyone's workflow as much as possible. |
| 7919 | In this case, you want a kernel source directory on the development |
| 7920 | machine where the development occurs. |
| 7921 | You want the recipe's |
| 7922 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> |
| 7923 | variable to point to the external directory and use it as is, not |
| 7924 | copy it. |
| 7925 | </para> |
| 7926 | |
| 7927 | <para> |
| 7928 | To build from software that comes from an external source, all you |
| 7929 | need to do is inherit the |
| 7930 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-externalsrc'><filename>externalsrc</filename></ulink> |
| 7931 | class and then set the |
| 7932 | <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC'><filename>EXTERNALSRC</filename></ulink> |
| 7933 | variable to point to your external source code. |
| 7934 | Here are the statements to put in your |
| 7935 | <filename>local.conf</filename> file: |
| 7936 | <literallayout class='monospaced'> |
| 7937 | INHERIT += "externalsrc" |
| 7938 | EXTERNALSRC_pn-<replaceable>myrecipe</replaceable> = "<replaceable>path-to-your-source-tree</replaceable>" |
| 7939 | </literallayout> |
| 7940 | </para> |
| 7941 | |
| 7942 | <para> |
| 7943 | This next example shows how to accomplish the same thing by setting |
| 7944 | <filename>EXTERNALSRC</filename> in the recipe itself or in the |
| 7945 | recipe's append file: |
| 7946 | <literallayout class='monospaced'> |
| 7947 | EXTERNALSRC = "<replaceable>path</replaceable>" |
| 7948 | EXTERNALSRC_BUILD = "<replaceable>path</replaceable>" |
| 7949 | </literallayout> |
| 7950 | <note> |
| 7951 | In order for these settings to take effect, you must globally |
| 7952 | or locally inherit the |
| 7953 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-externalsrc'><filename>externalsrc</filename></ulink> |
| 7954 | class. |
| 7955 | </note> |
| 7956 | </para> |
| 7957 | |
| 7958 | <para> |
| 7959 | By default, <filename>externalsrc.bbclass</filename> builds |
| 7960 | the source code in a directory separate from the external source |
| 7961 | directory as specified by |
| 7962 | <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC'><filename>EXTERNALSRC</filename></ulink>. |
| 7963 | If you need to have the source built in the same directory in |
| 7964 | which it resides, or some other nominated directory, you can set |
| 7965 | <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC_BUILD'><filename>EXTERNALSRC_BUILD</filename></ulink> |
| 7966 | to point to that directory: |
| 7967 | <literallayout class='monospaced'> |
| 7968 | EXTERNALSRC_BUILD_pn-<replaceable>myrecipe</replaceable> = "<replaceable>path-to-your-source-tree</replaceable>" |
| 7969 | </literallayout> |
| 7970 | </para> |
| 7971 | </section> |
| 7972 | |
| 7973 | <section id="selecting-an-initialization-manager"> |
| 7974 | <title>Selecting an Initialization Manager</title> |
| 7975 | |
| 7976 | <para> |
| 7977 | By default, the Yocto Project uses SysVinit as the initialization |
| 7978 | manager. |
| 7979 | However, support also exists for systemd, |
| 7980 | which is a full replacement for init with |
| 7981 | parallel starting of services, reduced shell overhead and other |
| 7982 | features that are used by many distributions. |
| 7983 | </para> |
| 7984 | |
| 7985 | <para> |
| 7986 | If you want to use SysVinit, you do |
| 7987 | not have to do anything. |
| 7988 | But, if you want to use systemd, you must |
| 7989 | take some steps as described in the following sections. |
| 7990 | </para> |
| 7991 | |
| 7992 | <section id='using-systemd-exclusively'> |
| 7993 | <title>Using systemd Exclusively</title> |
| 7994 | |
| 7995 | <para> |
| 7996 | Set the these variables in your distribution configuration |
| 7997 | file as follows: |
| 7998 | <literallayout class='monospaced'> |
| 7999 | DISTRO_FEATURES_append = " systemd" |
| 8000 | VIRTUAL-RUNTIME_init_manager = "systemd" |
| 8001 | </literallayout> |
| 8002 | You can also prevent the SysVinit |
| 8003 | distribution feature from |
| 8004 | being automatically enabled as follows: |
| 8005 | <literallayout class='monospaced'> |
| 8006 | DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit" |
| 8007 | </literallayout> |
| 8008 | Doing so removes any redundant SysVinit scripts. |
| 8009 | </para> |
| 8010 | |
| 8011 | <para> |
| 8012 | To remove initscripts from your image altogether, |
| 8013 | set this variable also: |
| 8014 | <literallayout class='monospaced'> |
| 8015 | VIRTUAL-RUNTIME_initscripts = "" |
| 8016 | </literallayout> |
| 8017 | </para> |
| 8018 | |
| 8019 | <para> |
| 8020 | For information on the backfill variable, see |
| 8021 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES_BACKFILL_CONSIDERED'><filename>DISTRO_FEATURES_BACKFILL_CONSIDERED</filename></ulink>. |
| 8022 | </para> |
| 8023 | </section> |
| 8024 | |
| 8025 | <section id='using-systemd-for-the-main-image-and-using-sysvinit-for-the-rescue-image'> |
| 8026 | <title>Using systemd for the Main Image and Using SysVinit for the Rescue Image</title> |
| 8027 | |
| 8028 | <para> |
| 8029 | Set these variables in your distribution configuration |
| 8030 | file as follows: |
| 8031 | <literallayout class='monospaced'> |
| 8032 | DISTRO_FEATURES_append = " systemd" |
| 8033 | VIRTUAL-RUNTIME_init_manager = "systemd" |
| 8034 | </literallayout> |
| 8035 | Doing so causes your main image to use the |
| 8036 | <filename>packagegroup-core-boot.bb</filename> recipe and |
| 8037 | systemd. |
| 8038 | The rescue/minimal image cannot use this package group. |
| 8039 | However, it can install SysVinit |
| 8040 | and the appropriate packages will have support for both |
| 8041 | systemd and SysVinit. |
| 8042 | </para> |
| 8043 | </section> |
| 8044 | </section> |
| 8045 | |
| 8046 | <section id="selecting-dev-manager"> |
| 8047 | <title>Selecting a Device Manager</title> |
| 8048 | |
| 8049 | <para> |
| 8050 | The Yocto Project provides multiple ways to manage the device |
| 8051 | manager (<filename>/dev</filename>): |
| 8052 | <itemizedlist> |
| 8053 | <listitem><para><emphasis>Persistent and Pre-Populated<filename>/dev</filename>:</emphasis> |
| 8054 | For this case, the <filename>/dev</filename> directory |
| 8055 | is persistent and the required device nodes are created |
| 8056 | during the build. |
| 8057 | </para></listitem> |
| 8058 | <listitem><para><emphasis>Use <filename>devtmpfs</filename> with a Device Manager:</emphasis> |
| 8059 | For this case, the <filename>/dev</filename> directory |
| 8060 | is provided by the kernel as an in-memory file system and |
| 8061 | is automatically populated by the kernel at runtime. |
| 8062 | Additional configuration of device nodes is done in user |
| 8063 | space by a device manager like |
| 8064 | <filename>udev</filename> or |
| 8065 | <filename>busybox-mdev</filename>. |
| 8066 | </para></listitem> |
| 8067 | </itemizedlist> |
| 8068 | </para> |
| 8069 | |
| 8070 | <section id="static-dev-management"> |
| 8071 | <title>Using Persistent and Pre-Populated<filename>/dev</filename></title> |
| 8072 | |
| 8073 | <para> |
| 8074 | To use the static method for device population, you need to |
| 8075 | set the |
| 8076 | <ulink url='&YOCTO_DOCS_REF_URL;#var-USE_DEVFS'><filename>USE_DEVFS</filename></ulink> |
| 8077 | variable to "0" as follows: |
| 8078 | <literallayout class='monospaced'> |
| 8079 | USE_DEVFS = "0" |
| 8080 | </literallayout> |
| 8081 | </para> |
| 8082 | |
| 8083 | <para> |
| 8084 | The content of the resulting <filename>/dev</filename> |
| 8085 | directory is defined in a Device Table file. |
| 8086 | The |
| 8087 | <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_DEVICE_TABLES'><filename>IMAGE_DEVICE_TABLES</filename></ulink> |
| 8088 | variable defines the Device Table to use and should be set |
| 8089 | in the machine or distro configuration file. |
| 8090 | Alternatively, you can set this variable in your |
| 8091 | <filename>local.conf</filename> configuration file. |
| 8092 | </para> |
| 8093 | |
| 8094 | <para> |
| 8095 | If you do not define the |
| 8096 | <filename>IMAGE_DEVICE_TABLES</filename> variable, the default |
| 8097 | <filename>device_table-minimal.txt</filename> is used: |
| 8098 | <literallayout class='monospaced'> |
| 8099 | IMAGE_DEVICE_TABLES = "device_table-mymachine.txt" |
| 8100 | </literallayout> |
| 8101 | </para> |
| 8102 | |
| 8103 | <para> |
| 8104 | The population is handled by the <filename>makedevs</filename> |
| 8105 | utility during image creation: |
| 8106 | </para> |
| 8107 | </section> |
| 8108 | |
| 8109 | <section id="devtmpfs-dev-management"> |
| 8110 | <title>Using <filename>devtmpfs</filename> and a Device Manager</title> |
| 8111 | |
| 8112 | <para> |
| 8113 | To use the dynamic method for device population, you need to |
| 8114 | use (or be sure to set) the |
| 8115 | <ulink url='&YOCTO_DOCS_REF_URL;#var-USE_DEVFS'><filename>USE_DEVFS</filename></ulink> |
| 8116 | variable to "1", which is the default: |
| 8117 | <literallayout class='monospaced'> |
| 8118 | USE_DEVFS = "1" |
| 8119 | </literallayout> |
| 8120 | With this setting, the resulting <filename>/dev</filename> |
| 8121 | directory is populated by the kernel using |
| 8122 | <filename>devtmpfs</filename>. |
| 8123 | Make sure the corresponding kernel configuration variable |
| 8124 | <filename>CONFIG_DEVTMPFS</filename> is set when building |
| 8125 | you build a Linux kernel. |
| 8126 | </para> |
| 8127 | |
| 8128 | <para> |
| 8129 | All devices created by <filename>devtmpfs</filename> will be |
| 8130 | owned by <filename>root</filename> and have permissions |
| 8131 | <filename>0600</filename>. |
| 8132 | </para> |
| 8133 | |
| 8134 | <para> |
| 8135 | To have more control over the device nodes, you can use a |
| 8136 | device manager like <filename>udev</filename> or |
| 8137 | <filename>busybox-mdev</filename>. |
| 8138 | You choose the device manager by defining the |
| 8139 | <filename>VIRTUAL-RUNTIME_dev_manager</filename> variable |
| 8140 | in your machine or distro configuration file. |
| 8141 | Alternatively, you can set this variable in your |
| 8142 | <filename>local.conf</filename> configuration file: |
| 8143 | <literallayout class='monospaced'> |
| 8144 | VIRTUAL-RUNTIME_dev_manager = "udev" |
| 8145 | |
| 8146 | # Some alternative values |
| 8147 | # VIRTUAL-RUNTIME_dev_manager = "busybox-mdev" |
| 8148 | # VIRTUAL-RUNTIME_dev_manager = "systemd" |
| 8149 | </literallayout> |
| 8150 | </para> |
| 8151 | </section> |
| 8152 | </section> |
| 8153 | |
| 8154 | <section id="platdev-appdev-srcrev"> |
| 8155 | <title>Using an External SCM</title> |
| 8156 | |
| 8157 | <para> |
| 8158 | If you're working on a recipe that pulls from an external Source |
| 8159 | Code Manager (SCM), it is possible to have the OpenEmbedded build |
| 8160 | system notice new recipe changes added to the SCM and then build |
| 8161 | the resulting packages that depend on the new recipes by using |
| 8162 | the latest versions. |
| 8163 | This only works for SCMs from which it is possible to get a |
| 8164 | sensible revision number for changes. |
| 8165 | Currently, you can do this with Apache Subversion (SVN), Git, and |
| 8166 | Bazaar (BZR) repositories. |
| 8167 | </para> |
| 8168 | |
| 8169 | <para> |
| 8170 | To enable this behavior, the |
| 8171 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink> |
| 8172 | of the recipe needs to reference |
| 8173 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>. |
| 8174 | Here is an example: |
| 8175 | <literallayout class='monospaced'> |
| 8176 | PV = "1.2.3+git${SRCPV}" |
| 8177 | </literallayout> |
| 8178 | Then, you can add the following to your |
| 8179 | <filename>local.conf</filename>: |
| 8180 | <literallayout class='monospaced'> |
| 8181 | SRCREV_pn-<replaceable>PN</replaceable> = "${AUTOREV}" |
| 8182 | </literallayout> |
| 8183 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink> |
| 8184 | is the name of the recipe for which you want to enable automatic source |
| 8185 | revision updating. |
| 8186 | </para> |
| 8187 | |
| 8188 | <para> |
| 8189 | If you do not want to update your local configuration file, you can |
| 8190 | add the following directly to the recipe to finish enabling |
| 8191 | the feature: |
| 8192 | <literallayout class='monospaced'> |
| 8193 | SRCREV = "${AUTOREV}" |
| 8194 | </literallayout> |
| 8195 | </para> |
| 8196 | |
| 8197 | <para> |
| 8198 | The Yocto Project provides a distribution named |
| 8199 | <filename>poky-bleeding</filename>, whose configuration |
| 8200 | file contains the line: |
| 8201 | <literallayout class='monospaced'> |
| 8202 | require conf/distro/include/poky-floating-revisions.inc |
| 8203 | </literallayout> |
| 8204 | This line pulls in the listed include file that contains |
| 8205 | numerous lines of exactly that form: |
| 8206 | <literallayout class='monospaced'> |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 8207 | #SRCREV_pn-opkg-native ?= "${AUTOREV}" |
| 8208 | #SRCREV_pn-opkg-sdk ?= "${AUTOREV}" |
| 8209 | #SRCREV_pn-opkg ?= "${AUTOREV}" |
| 8210 | #SRCREV_pn-opkg-utils-native ?= "${AUTOREV}" |
| 8211 | #SRCREV_pn-opkg-utils ?= "${AUTOREV}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 8212 | SRCREV_pn-gconf-dbus ?= "${AUTOREV}" |
| 8213 | SRCREV_pn-matchbox-common ?= "${AUTOREV}" |
| 8214 | SRCREV_pn-matchbox-config-gtk ?= "${AUTOREV}" |
| 8215 | SRCREV_pn-matchbox-desktop ?= "${AUTOREV}" |
| 8216 | SRCREV_pn-matchbox-keyboard ?= "${AUTOREV}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 8217 | SRCREV_pn-matchbox-panel-2 ?= "${AUTOREV}" |
| 8218 | SRCREV_pn-matchbox-themes-extra ?= "${AUTOREV}" |
| 8219 | SRCREV_pn-matchbox-terminal ?= "${AUTOREV}" |
| 8220 | SRCREV_pn-matchbox-wm ?= "${AUTOREV}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 8221 | SRCREV_pn-settings-daemon ?= "${AUTOREV}" |
| 8222 | SRCREV_pn-screenshot ?= "${AUTOREV}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 8223 | . |
| 8224 | . |
| 8225 | . |
| 8226 | </literallayout> |
| 8227 | These lines allow you to experiment with building a |
| 8228 | distribution that tracks the latest development source |
| 8229 | for numerous packages. |
| 8230 | <note><title>Caution</title> |
| 8231 | The <filename>poky-bleeding</filename> distribution |
| 8232 | is not tested on a regular basis. |
| 8233 | Keep this in mind if you use it. |
| 8234 | </note> |
| 8235 | </para> |
| 8236 | </section> |
| 8237 | |
| 8238 | <section id='creating-a-read-only-root-filesystem'> |
| 8239 | <title>Creating a Read-Only Root Filesystem</title> |
| 8240 | |
| 8241 | <para> |
| 8242 | Suppose, for security reasons, you need to disable |
| 8243 | your target device's root filesystem's write permissions |
| 8244 | (i.e. you need a read-only root filesystem). |
| 8245 | Or, perhaps you are running the device's operating system |
| 8246 | from a read-only storage device. |
| 8247 | For either case, you can customize your image for |
| 8248 | that behavior. |
| 8249 | </para> |
| 8250 | |
| 8251 | <note> |
| 8252 | Supporting a read-only root filesystem requires that the system and |
| 8253 | applications do not try to write to the root filesystem. |
| 8254 | You must configure all parts of the target system to write |
| 8255 | elsewhere, or to gracefully fail in the event of attempting to |
| 8256 | write to the root filesystem. |
| 8257 | </note> |
| 8258 | |
| 8259 | <section id='creating-the-root-filesystem'> |
| 8260 | <title>Creating the Root Filesystem</title> |
| 8261 | |
| 8262 | <para> |
| 8263 | To create the read-only root filesystem, simply add the |
| 8264 | "read-only-rootfs" feature to your image. |
| 8265 | Using either of the following statements in your |
| 8266 | image recipe or from within the |
| 8267 | <filename>local.conf</filename> file found in the |
| 8268 | <link linkend='build-directory'>Build Directory</link> |
| 8269 | causes the build system to create a read-only root filesystem: |
| 8270 | <literallayout class='monospaced'> |
| 8271 | IMAGE_FEATURES = "read-only-rootfs" |
| 8272 | </literallayout> |
| 8273 | or |
| 8274 | <literallayout class='monospaced'> |
| 8275 | EXTRA_IMAGE_FEATURES += "read-only-rootfs" |
| 8276 | </literallayout> |
| 8277 | </para> |
| 8278 | |
| 8279 | <para> |
| 8280 | For more information on how to use these variables, see the |
| 8281 | "<link linkend='usingpoky-extend-customimage-imagefeatures'>Customizing Images Using Custom <filename>IMAGE_FEATURES</filename> and <filename>EXTRA_IMAGE_FEATURES</filename></link>" |
| 8282 | section. |
| 8283 | For information on the variables, see |
| 8284 | <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink> |
| 8285 | and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink>. |
| 8286 | </para> |
| 8287 | </section> |
| 8288 | |
| 8289 | <section id='post-installation-scripts'> |
| 8290 | <title>Post-Installation Scripts</title> |
| 8291 | |
| 8292 | <para> |
| 8293 | It is very important that you make sure all |
| 8294 | post-Installation (<filename>pkg_postinst</filename>) scripts |
| 8295 | for packages that are installed into the image can be run |
| 8296 | at the time when the root filesystem is created during the |
| 8297 | build on the host system. |
| 8298 | These scripts cannot attempt to run during first-boot on the |
| 8299 | target device. |
| 8300 | With the "read-only-rootfs" feature enabled, |
| 8301 | the build system checks during root filesystem creation to make |
| 8302 | sure all post-installation scripts succeed. |
| 8303 | If any of these scripts still need to be run after the root |
| 8304 | filesystem is created, the build immediately fails. |
| 8305 | These build-time checks ensure that the build fails |
| 8306 | rather than the target device fails later during its |
| 8307 | initial boot operation. |
| 8308 | </para> |
| 8309 | |
| 8310 | <para> |
| 8311 | Most of the common post-installation scripts generated by the |
| 8312 | build system for the out-of-the-box Yocto Project are engineered |
| 8313 | so that they can run during root filesystem creation |
| 8314 | (e.g. post-installation scripts for caching fonts). |
| 8315 | However, if you create and add custom scripts, you need |
| 8316 | to be sure they can be run during this file system creation. |
| 8317 | </para> |
| 8318 | |
| 8319 | <para> |
| 8320 | Here are some common problems that prevent |
| 8321 | post-installation scripts from running during root filesystem |
| 8322 | creation: |
| 8323 | <itemizedlist> |
| 8324 | <listitem><para> |
| 8325 | <emphasis>Not using $D in front of absolute |
| 8326 | paths:</emphasis> |
| 8327 | The build system defines |
| 8328 | <filename>$</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink> |
| 8329 | when the root filesystem is created. |
| 8330 | Furthermore, <filename>$D</filename> is blank when the |
| 8331 | script is run on the target device. |
| 8332 | This implies two purposes for <filename>$D</filename>: |
| 8333 | ensuring paths are valid in both the host and target |
| 8334 | environments, and checking to determine which |
| 8335 | environment is being used as a method for taking |
| 8336 | appropriate actions. |
| 8337 | </para></listitem> |
| 8338 | <listitem><para> |
| 8339 | <emphasis>Attempting to run processes that are |
| 8340 | specific to or dependent on the target |
| 8341 | architecture:</emphasis> |
| 8342 | You can work around these attempts by using native |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 8343 | tools, which run on the host system, |
| 8344 | to accomplish the same tasks, or |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 8345 | by alternatively running the processes under QEMU, |
| 8346 | which has the <filename>qemu_run_binary</filename> |
| 8347 | function. |
| 8348 | For more information, see the |
| 8349 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-qemu'><filename>qemu</filename></ulink> |
| 8350 | class.</para></listitem> |
| 8351 | </itemizedlist> |
| 8352 | </para> |
| 8353 | </section> |
| 8354 | |
| 8355 | <section id='areas-with-write-access'> |
| 8356 | <title>Areas With Write Access</title> |
| 8357 | |
| 8358 | <para> |
| 8359 | With the "read-only-rootfs" feature enabled, |
| 8360 | any attempt by the target to write to the root filesystem at |
| 8361 | runtime fails. |
| 8362 | Consequently, you must make sure that you configure processes |
| 8363 | and applications that attempt these types of writes do so |
| 8364 | to directories with write access (e.g. |
| 8365 | <filename>/tmp</filename> or <filename>/var/run</filename>). |
| 8366 | </para> |
| 8367 | </section> |
| 8368 | </section> |
| 8369 | |
| 8370 | <section id="performing-automated-runtime-testing"> |
| 8371 | <title>Performing Automated Runtime Testing</title> |
| 8372 | |
| 8373 | <para> |
| 8374 | The OpenEmbedded build system makes available a series of automated |
| 8375 | tests for images to verify runtime functionality. |
| 8376 | You can run these tests on either QEMU or actual target hardware. |
| 8377 | Tests are written in Python making use of the |
| 8378 | <filename>unittest</filename> module, and the majority of them |
| 8379 | run commands on the target system over SSH. |
| 8380 | This section describes how you set up the environment to use these |
| 8381 | tests, run available tests, and write and add your own tests. |
| 8382 | </para> |
| 8383 | |
| 8384 | <section id='enabling-tests'> |
| 8385 | <title>Enabling Tests</title> |
| 8386 | |
| 8387 | <para> |
| 8388 | Depending on whether you are planning to run tests using |
| 8389 | QEMU or on the hardware, you have to take |
| 8390 | different steps to enable the tests. |
| 8391 | See the following subsections for information on how to |
| 8392 | enable both types of tests. |
| 8393 | </para> |
| 8394 | |
| 8395 | <section id='qemu-image-enabling-tests'> |
| 8396 | <title>Enabling Runtime Tests on QEMU</title> |
| 8397 | |
| 8398 | <para> |
| 8399 | In order to run tests, you need to do the following: |
| 8400 | <itemizedlist> |
| 8401 | <listitem><para><emphasis>Set up to avoid interaction |
| 8402 | with <filename>sudo</filename> for networking:</emphasis> |
| 8403 | To accomplish this, you must do one of the |
| 8404 | following: |
| 8405 | <itemizedlist> |
| 8406 | <listitem><para>Add |
| 8407 | <filename>NOPASSWD</filename> for your user |
| 8408 | in <filename>/etc/sudoers</filename> either for |
| 8409 | all commands or just for |
| 8410 | <filename>runqemu-ifup</filename>. |
| 8411 | You must provide the full path as that can |
| 8412 | change if you are using multiple clones of the |
| 8413 | source repository. |
| 8414 | <note> |
| 8415 | On some distributions, you also need to |
| 8416 | comment out "Defaults requiretty" in |
| 8417 | <filename>/etc/sudoers</filename>. |
| 8418 | </note></para></listitem> |
| 8419 | <listitem><para>Manually configure a tap interface |
| 8420 | for your system.</para></listitem> |
| 8421 | <listitem><para>Run as root the script in |
| 8422 | <filename>scripts/runqemu-gen-tapdevs</filename>, |
| 8423 | which should generate a list of tap devices. |
| 8424 | This is the option typically chosen for |
| 8425 | Autobuilder-type environments. |
| 8426 | </para></listitem> |
| 8427 | </itemizedlist></para></listitem> |
| 8428 | <listitem><para><emphasis>Set the |
| 8429 | <filename>DISPLAY</filename> variable:</emphasis> |
| 8430 | You need to set this variable so that you have an X |
| 8431 | server available (e.g. start |
| 8432 | <filename>vncserver</filename> for a headless machine). |
| 8433 | </para></listitem> |
| 8434 | <listitem><para><emphasis>Be sure your host's firewall |
| 8435 | accepts incoming connections from |
| 8436 | 192.168.7.0/24:</emphasis> |
| 8437 | Some of the tests (in particular smart tests) start an |
| 8438 | HTTP server on a random high number port, which is |
| 8439 | used to serve files to the target. |
| 8440 | The smart module serves |
| 8441 | <filename>${DEPLOY_DIR}/rpm</filename> so it can run |
| 8442 | smart channel commands. That means your host's firewall |
| 8443 | must accept incoming connections from 192.168.7.0/24, |
| 8444 | which is the default IP range used for tap devices |
| 8445 | by <filename>runqemu</filename>.</para></listitem> |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 8446 | <listitem><para><emphasis>Be sure your host has the |
| 8447 | correct packages installed:</emphasis> |
| 8448 | Depending your host's distribution, you need |
| 8449 | to have the following packages installed: |
| 8450 | <itemizedlist> |
| 8451 | <listitem><para>Ubuntu and Debian: |
| 8452 | <filename>sysstat</filename> and |
| 8453 | <filename>iproute2</filename> |
| 8454 | </para></listitem> |
| 8455 | <listitem><para>OpenSUSE: |
| 8456 | <filename>sysstat</filename> and |
| 8457 | <filename>iproute2</filename> |
| 8458 | </para></listitem> |
| 8459 | <listitem><para>Fedora: |
| 8460 | <filename>sysstat</filename> and |
| 8461 | <filename>iproute</filename> |
| 8462 | </para></listitem> |
| 8463 | <listitem><para>CentOS: |
| 8464 | <filename>sysstat</filename> and |
| 8465 | <filename>iproute</filename> |
| 8466 | </para></listitem> |
| 8467 | </itemizedlist> |
| 8468 | </para></listitem> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 8469 | </itemizedlist> |
| 8470 | </para> |
| 8471 | |
| 8472 | <para> |
| 8473 | Once you start running the tests, the following happens: |
| 8474 | <orderedlist> |
| 8475 | <listitem><para>A copy of the root filesystem is written |
| 8476 | to <filename>${WORKDIR}/testimage</filename>. |
| 8477 | </para></listitem> |
| 8478 | <listitem><para>The image is booted under QEMU using the |
| 8479 | standard <filename>runqemu</filename> script. |
| 8480 | </para></listitem> |
| 8481 | <listitem><para>A default timeout of 500 seconds occurs |
| 8482 | to allow for the boot process to reach the login prompt. |
| 8483 | You can change the timeout period by setting |
| 8484 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_QEMUBOOT_TIMEOUT'><filename>TEST_QEMUBOOT_TIMEOUT</filename></ulink> |
| 8485 | in the <filename>local.conf</filename> file. |
| 8486 | </para></listitem> |
| 8487 | <listitem><para>Once the boot process is reached and the |
| 8488 | login prompt appears, the tests run. |
| 8489 | The full boot log is written to |
| 8490 | <filename>${WORKDIR}/testimage/qemu_boot_log</filename>. |
| 8491 | </para></listitem> |
| 8492 | <listitem><para>Each test module loads in the order found |
| 8493 | in <filename>TEST_SUITES</filename>. |
| 8494 | You can find the full output of the commands run over |
| 8495 | SSH in |
| 8496 | <filename>${WORKDIR}/testimgage/ssh_target_log</filename>. |
| 8497 | </para></listitem> |
| 8498 | <listitem><para>If no failures occur, the task running the |
| 8499 | tests ends successfully. |
| 8500 | You can find the output from the |
| 8501 | <filename>unittest</filename> in the task log at |
| 8502 | <filename>${WORKDIR}/temp/log.do_testimage</filename>. |
| 8503 | </para></listitem> |
| 8504 | </orderedlist> |
| 8505 | </para> |
| 8506 | </section> |
| 8507 | |
| 8508 | <section id='hardware-image-enabling-tests'> |
| 8509 | <title>Enabling Runtime Tests on Hardware</title> |
| 8510 | |
| 8511 | <para> |
| 8512 | The OpenEmbedded build system can run tests on real |
| 8513 | hardware, and for certain devices it can also deploy |
| 8514 | the image to be tested onto the device beforehand. |
| 8515 | </para> |
| 8516 | |
| 8517 | <para> |
| 8518 | For automated deployment, a "master image" is installed |
| 8519 | onto the hardware once as part of setup. |
| 8520 | Then, each time tests are to be run, the following |
| 8521 | occurs: |
| 8522 | <orderedlist> |
| 8523 | <listitem><para>The master image is booted into and |
| 8524 | used to write the image to be tested to |
| 8525 | a second partition. |
| 8526 | </para></listitem> |
| 8527 | <listitem><para>The device is then rebooted using an |
| 8528 | external script that you need to provide. |
| 8529 | </para></listitem> |
| 8530 | <listitem><para>The device boots into the image to be |
| 8531 | tested. |
| 8532 | </para></listitem> |
| 8533 | </orderedlist> |
| 8534 | </para> |
| 8535 | |
| 8536 | <para> |
| 8537 | When running tests (independent of whether the image |
| 8538 | has been deployed automatically or not), the device is |
| 8539 | expected to be connected to a network on a |
| 8540 | pre-determined IP address. |
| 8541 | You can either use static IP addresses written into |
| 8542 | the image, or set the image to use DHCP and have your |
| 8543 | DHCP server on the test network assign a known IP address |
| 8544 | based on the MAC address of the device. |
| 8545 | </para> |
| 8546 | |
| 8547 | <para> |
| 8548 | In order to run tests on hardware, you need to set |
| 8549 | <filename>TEST_TARGET</filename> to an appropriate value. |
| 8550 | For QEMU, you do not have to change anything, the default |
| 8551 | value is "QemuTarget". |
| 8552 | For running tests on hardware, the following options exist: |
| 8553 | <itemizedlist> |
| 8554 | <listitem><para><emphasis>"SimpleRemoteTarget":</emphasis> |
| 8555 | Choose "SimpleRemoteTarget" if you are going to |
| 8556 | run tests on a target system that is already |
| 8557 | running the image to be tested and is available |
| 8558 | on the network. |
| 8559 | You can use "SimpleRemoteTarget" in conjunction |
| 8560 | with either real hardware or an image running |
| 8561 | within a separately started QEMU or any |
| 8562 | other virtual machine manager. |
| 8563 | </para></listitem> |
| 8564 | <listitem><para><emphasis>"GummibootTarget":</emphasis> |
| 8565 | Choose "GummibootTarget" if your hardware is |
| 8566 | an EFI-based machine with |
| 8567 | <filename>gummiboot</filename> as bootloader and |
| 8568 | <filename>core-image-testmaster</filename> |
| 8569 | (or something similar) is installed. |
| 8570 | Also, your hardware under test must be in a |
| 8571 | DHCP-enabled network that gives it the same IP |
| 8572 | address for each reboot.</para> |
| 8573 | <para>If you choose "GummibootTarget", there are |
| 8574 | additional requirements and considerations. |
| 8575 | See the |
| 8576 | "<link linkend='selecting-gummiboottarget'>Selecting GummibootTarget</link>" |
| 8577 | section, which follows, for more information. |
| 8578 | </para></listitem> |
| 8579 | <listitem><para><emphasis>"BeagleBoneTarget":</emphasis> |
| 8580 | Choose "BeagleBoneTarget" if you are deploying |
| 8581 | images and running tests on the BeagleBone |
| 8582 | "Black" or original "White" hardware. |
| 8583 | For information on how to use these tests, see the |
| 8584 | comments at the top of the BeagleBoneTarget |
| 8585 | <filename>meta-yocto-bsp/lib/oeqa/controllers/beaglebonetarget.py</filename> |
| 8586 | file. |
| 8587 | </para></listitem> |
| 8588 | <listitem><para><emphasis>"EdgeRouterTarget":</emphasis> |
| 8589 | Choose "EdgeRouterTarget" is you are deploying |
| 8590 | images and running tests on the Ubiquiti Networks |
| 8591 | EdgeRouter Lite. |
| 8592 | For information on how to use these tests, see the |
| 8593 | comments at the top of the EdgeRouterTarget |
| 8594 | <filename>meta-yocto-bsp/lib/oeqa/controllers/edgeroutertarget.py</filename> |
| 8595 | file. |
| 8596 | </para></listitem> |
| 8597 | <listitem><para><emphasis>"GrubTarget":</emphasis> |
| 8598 | Choose the "supports deploying images and running |
| 8599 | tests on any generic PC that boots using GRUB. |
| 8600 | For information on how to use these tests, see the |
| 8601 | comments at the top of the GrubTarget |
| 8602 | <filename>meta-yocto-bsp/lib/oeqa/controllers/grubtarget.py</filename> |
| 8603 | file. |
| 8604 | </para></listitem> |
| 8605 | <listitem><para><emphasis>"<replaceable>your-target</replaceable>":</emphasis> |
| 8606 | Create your own custom target if you want to run |
| 8607 | tests when you are deploying images and running |
| 8608 | tests on a custom machine within your BSP layer. |
| 8609 | To do this, you need to add a Python unit that |
| 8610 | defines the target class under |
| 8611 | <filename>lib/oeqa/controllers/</filename> within |
| 8612 | your layer. |
| 8613 | You must also provide an empty |
| 8614 | <filename>__init__.py</filename>. |
| 8615 | For examples, see files in |
| 8616 | <filename>meta-yocto-bsp/lib/oeqa/controllers/</filename>. |
| 8617 | </para></listitem> |
| 8618 | </itemizedlist> |
| 8619 | </para> |
| 8620 | </section> |
| 8621 | |
| 8622 | <section id='selecting-gummiboottarget'> |
| 8623 | <title>Selecting GummibootTarget</title> |
| 8624 | |
| 8625 | <para> |
| 8626 | If you did not set <filename>TEST_TARGET</filename> to |
| 8627 | "GummibootTarget", then you do not need any information |
| 8628 | in this section. |
| 8629 | You can skip down to the |
| 8630 | "<link linkend='qemu-image-running-tests'>Running Tests</link>" |
| 8631 | section. |
| 8632 | </para> |
| 8633 | |
| 8634 | <para> |
| 8635 | If you did set <filename>TEST_TARGET</filename> to |
| 8636 | "GummibootTarget", you also need to perform a one-time |
| 8637 | setup of your master image by doing the following: |
| 8638 | <orderedlist> |
| 8639 | <listitem><para><emphasis>Set <filename>EFI_PROVIDER</filename>:</emphasis> |
| 8640 | Be sure that <filename>EFI_PROVIDER</filename> |
| 8641 | is as follows: |
| 8642 | <literallayout class='monospaced'> |
| 8643 | EFI_PROVIDER = "gummiboot" |
| 8644 | </literallayout> |
| 8645 | </para></listitem> |
| 8646 | <listitem><para><emphasis>Build the master image:</emphasis> |
| 8647 | Build the <filename>core-image-testmaster</filename> |
| 8648 | image. |
| 8649 | The <filename>core-image-testmaster</filename> |
| 8650 | recipe is provided as an example for a |
| 8651 | "master" image and you can customize the image |
| 8652 | recipe as you would any other recipe. |
| 8653 | </para> |
| 8654 | <para>Here are the image recipe requirements: |
| 8655 | <itemizedlist> |
| 8656 | <listitem><para>Inherits |
| 8657 | <filename>core-image</filename> |
| 8658 | so that kernel modules are installed. |
| 8659 | </para></listitem> |
| 8660 | <listitem><para>Installs normal linux utilities |
| 8661 | not busybox ones (e.g. |
| 8662 | <filename>bash</filename>, |
| 8663 | <filename>coreutils</filename>, |
| 8664 | <filename>tar</filename>, |
| 8665 | <filename>gzip</filename>, and |
| 8666 | <filename>kmod</filename>). |
| 8667 | </para></listitem> |
| 8668 | <listitem><para>Uses a custom |
| 8669 | Initial RAM Disk (initramfs) image with a |
| 8670 | custom installer. |
| 8671 | A normal image that you can install usually |
| 8672 | creates a single rootfs partition. |
| 8673 | This image uses another installer that |
| 8674 | creates a specific partition layout. |
| 8675 | Not all Board Support Packages (BSPs) |
| 8676 | can use an installer. |
| 8677 | For such cases, you need to manually create |
| 8678 | the following partition layout on the |
| 8679 | target: |
| 8680 | <itemizedlist> |
| 8681 | <listitem><para>First partition mounted |
| 8682 | under <filename>/boot</filename>, |
| 8683 | labeled "boot". |
| 8684 | </para></listitem> |
| 8685 | <listitem><para>The main rootfs |
| 8686 | partition where this image gets |
| 8687 | installed, which is mounted under |
| 8688 | <filename>/</filename>. |
| 8689 | </para></listitem> |
| 8690 | <listitem><para>Another partition |
| 8691 | labeled "testrootfs" where test |
| 8692 | images get deployed. |
| 8693 | </para></listitem> |
| 8694 | </itemizedlist> |
| 8695 | </para></listitem> |
| 8696 | </itemizedlist> |
| 8697 | </para></listitem> |
| 8698 | <listitem><para><emphasis>Install image:</emphasis> |
| 8699 | Install the image that you just built on the target |
| 8700 | system. |
| 8701 | </para></listitem> |
| 8702 | </orderedlist> |
| 8703 | </para> |
| 8704 | |
| 8705 | <para> |
| 8706 | The final thing you need to do when setting |
| 8707 | <filename>TEST_TARGET</filename> to "GummibootTarget" is |
| 8708 | to set up the test image: |
| 8709 | <orderedlist> |
| 8710 | <listitem><para><emphasis>Set up your <filename>local.conf</filename> file:</emphasis> |
| 8711 | Make sure you have the following statements in |
| 8712 | your <filename>local.conf</filename> file: |
| 8713 | <literallayout class='monospaced'> |
| 8714 | IMAGE_FSTYPES += "tar.gz" |
| 8715 | INHERIT += "testimage" |
| 8716 | TEST_TARGET = "GummibootTarget" |
| 8717 | TEST_TARGET_IP = "192.168.2.3" |
| 8718 | </literallayout> |
| 8719 | </para></listitem> |
| 8720 | <listitem><para><emphasis>Build your test image:</emphasis> |
| 8721 | Use BitBake to build the image: |
| 8722 | <literallayout class='monospaced'> |
| 8723 | $ bitbake core-image-sato |
| 8724 | </literallayout> |
| 8725 | </para></listitem> |
| 8726 | </orderedlist> |
| 8727 | </para> |
| 8728 | </section> |
| 8729 | |
| 8730 | <section id='power-control'> |
| 8731 | <title>Power Control</title> |
| 8732 | |
| 8733 | <para> |
| 8734 | For most hardware targets other than SimpleRemoteTarget, |
| 8735 | you can control power: |
| 8736 | <itemizedlist> |
| 8737 | <listitem><para> |
| 8738 | You can use |
| 8739 | <filename>TEST_POWERCONTROL_CMD</filename> |
| 8740 | together with |
| 8741 | <filename>TEST_POWERCONTROL_EXTRA_ARGS</filename> |
| 8742 | as a command that runs on the host and does power |
| 8743 | cycling. |
| 8744 | The test code passes one argument to that command: |
| 8745 | off, on or cycle (off then on). |
| 8746 | Here is an example that could appear in your |
| 8747 | <filename>local.conf</filename> file: |
| 8748 | <literallayout class='monospaced'> |
| 8749 | TEST_POWERCONTROL_CMD = "powercontrol.exp test 10.11.12.1 nuc1" |
| 8750 | </literallayout> |
| 8751 | In this example, the expect script does the |
| 8752 | following: |
| 8753 | <literallayout class='monospaced'> |
| 8754 | ssh test@10.11.12.1 "pyctl nuc1 <replaceable>arg</replaceable>" |
| 8755 | </literallayout> |
| 8756 | It then runs a Python script that controls power |
| 8757 | for a label called <filename>nuc1</filename>. |
| 8758 | <note> |
| 8759 | You need to customize |
| 8760 | <filename>TEST_POWERCONTROL_CMD</filename> |
| 8761 | and |
| 8762 | <filename>TEST_POWERCONTROL_EXTRA_ARGS</filename> |
| 8763 | for your own setup. |
| 8764 | The one requirement is that it accepts |
| 8765 | "on", "off", and "cycle" as the last argument. |
| 8766 | </note> |
| 8767 | </para></listitem> |
| 8768 | <listitem><para> |
| 8769 | When no command is defined, it connects to the |
| 8770 | device over SSH and uses the classic reboot command |
| 8771 | to reboot the device. |
| 8772 | Classic reboot is fine as long as the machine |
| 8773 | actually reboots (i.e. the SSH test has not |
| 8774 | failed). |
| 8775 | It is useful for scenarios where you have a simple |
| 8776 | setup, typically with a single board, and where |
| 8777 | some manual interaction is okay from time to time. |
| 8778 | </para></listitem> |
| 8779 | </itemizedlist> |
| 8780 | If you have no hardware to automatically perform power |
| 8781 | control but still wish to experiment with automated |
| 8782 | hardware testing, you can use the dialog-power-control |
| 8783 | script that shows a dialog prompting you to perform the |
| 8784 | required power action. |
| 8785 | This script requires either KDialog or Zenity to be |
| 8786 | installed. |
| 8787 | To use this script, set the |
| 8788 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_POWERCONTROL_CMD'><filename>TEST_POWERCONTROL_CMD</filename></ulink> |
| 8789 | variable as follows: |
| 8790 | <literallayout class='monospaced'> |
| 8791 | TEST_POWERCONTROL_CMD = "${COREBASE}/scripts/contrib/dialog-power-control" |
| 8792 | </literallayout> |
| 8793 | </para> |
| 8794 | </section> |
| 8795 | |
| 8796 | <section id='serial-console-connection'> |
| 8797 | <title>Serial Console Connection</title> |
| 8798 | |
| 8799 | <para> |
| 8800 | For test target classes requiring a serial console |
| 8801 | to interact with the bootloader (e.g. BeagleBoneTarget, |
| 8802 | EdgeRouterTarget, and GrubTarget), you need to |
| 8803 | specify a command to use to connect to the serial console |
| 8804 | of the target machine by using the |
| 8805 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SERIALCONTROL_CMD'><filename>TEST_SERIALCONTROL_CMD</filename></ulink> |
| 8806 | variable and optionally the |
| 8807 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SERIALCONTROL_EXTRA_ARGS'><filename>TEST_SERIALCONTROL_EXTRA_ARGS</filename></ulink> |
| 8808 | variable. |
| 8809 | </para> |
| 8810 | |
| 8811 | <para> |
| 8812 | These cases could be a serial terminal program if the |
| 8813 | machine is connected to a local serial port, or a |
| 8814 | <filename>telnet</filename> or |
| 8815 | <filename>ssh</filename> command connecting to a remote |
| 8816 | console server. |
| 8817 | Regardless of the case, the command simply needs to |
| 8818 | connect to the serial console and forward that connection |
| 8819 | to standard input and output as any normal terminal |
| 8820 | program does. |
| 8821 | For example, to use the picocom terminal program on |
| 8822 | serial device <filename>/dev/ttyUSB0</filename> |
| 8823 | at 115200bps, you would set the variable as follows: |
| 8824 | <literallayout class='monospaced'> |
| 8825 | TEST_SERIALCONTROL_CMD = "picocom /dev/ttyUSB0 -b 115200" |
| 8826 | </literallayout> |
| 8827 | For local devices where the serial port device disappears |
| 8828 | when the device reboots, an additional "serdevtry" wrapper |
| 8829 | script is provided. |
| 8830 | To use this wrapper, simply prefix the terminal command |
| 8831 | with |
| 8832 | <filename>${COREBASE}/scripts/contrib/serdevtry</filename>: |
| 8833 | <literallayout class='monospaced'> |
| 8834 | TEST_SERIALCONTROL_CMD = "${COREBASE}/scripts/contrib/serdevtry picocom -b |
| 8835 | 115200 /dev/ttyUSB0" |
| 8836 | </literallayout> |
| 8837 | </para> |
| 8838 | </section> |
| 8839 | </section> |
| 8840 | |
| 8841 | <section id="qemu-image-running-tests"> |
| 8842 | <title>Running Tests</title> |
| 8843 | |
| 8844 | <para> |
| 8845 | You can start the tests automatically or manually: |
| 8846 | <itemizedlist> |
| 8847 | <listitem><para><emphasis>Automatically running tests:</emphasis> |
| 8848 | To run the tests automatically after the |
| 8849 | OpenEmbedded build system successfully creates an image, |
| 8850 | first set the |
| 8851 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_IMAGE'><filename>TEST_IMAGE</filename></ulink> |
| 8852 | variable to "1" in your <filename>local.conf</filename> |
| 8853 | file in the |
| 8854 | <ulink url='&YOCTO_DOCS_DEV_URL;#build-directory'>Build Directory</ulink>: |
| 8855 | <literallayout class='monospaced'> |
| 8856 | TEST_IMAGE = "1" |
| 8857 | </literallayout> |
| 8858 | Next, build your image. |
| 8859 | If the image successfully builds, the tests will be |
| 8860 | run: |
| 8861 | <literallayout class='monospaced'> |
| 8862 | bitbake core-image-sato |
| 8863 | </literallayout></para></listitem> |
| 8864 | <listitem><para><emphasis>Manually running tests:</emphasis> |
| 8865 | To manually run the tests, first globally inherit the |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 8866 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-testimage*'><filename>testimage</filename></ulink> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 8867 | class by editing your <filename>local.conf</filename> |
| 8868 | file: |
| 8869 | <literallayout class='monospaced'> |
| 8870 | INHERIT += "testimage" |
| 8871 | </literallayout> |
| 8872 | Next, use BitBake to run the tests: |
| 8873 | <literallayout class='monospaced'> |
| 8874 | bitbake -c testimage <replaceable>image</replaceable> |
| 8875 | </literallayout></para></listitem> |
| 8876 | </itemizedlist> |
| 8877 | </para> |
| 8878 | |
| 8879 | <para> |
| 8880 | All test files reside in |
| 8881 | <filename>meta/lib/oeqa/runtime</filename> in the |
| 8882 | <link linkend='source-directory'>Source Directory</link>. |
| 8883 | A test name maps directly to a Python module. |
| 8884 | Each test module may contain a number of individual tests. |
| 8885 | Tests are usually grouped together by the area |
| 8886 | tested (e.g tests for systemd reside in |
| 8887 | <filename>meta/lib/oeqa/runtime/systemd.py</filename>). |
| 8888 | </para> |
| 8889 | |
| 8890 | <para> |
| 8891 | You can add tests to any layer provided you place them in the |
| 8892 | proper area and you extend |
| 8893 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink> |
| 8894 | in the <filename>local.conf</filename> file as normal. |
| 8895 | Be sure that tests reside in |
| 8896 | <filename><replaceable>layer</replaceable>/lib/oeqa/runtime</filename>. |
| 8897 | <note> |
| 8898 | Be sure that module names do not collide with module names |
| 8899 | used in the default set of test modules in |
| 8900 | <filename>meta/lib/oeqa/runtime</filename>. |
| 8901 | </note> |
| 8902 | </para> |
| 8903 | |
| 8904 | <para> |
| 8905 | You can change the set of tests run by appending or overriding |
| 8906 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SUITES'><filename>TEST_SUITES</filename></ulink> |
| 8907 | variable in <filename>local.conf</filename>. |
| 8908 | Each name in <filename>TEST_SUITES</filename> represents a |
| 8909 | required test for the image. |
| 8910 | Test modules named within <filename>TEST_SUITES</filename> |
| 8911 | cannot be skipped even if a test is not suitable for an image |
| 8912 | (e.g. running the RPM tests on an image without |
| 8913 | <filename>rpm</filename>). |
| 8914 | Appending "auto" to <filename>TEST_SUITES</filename> causes the |
| 8915 | build system to try to run all tests that are suitable for the |
| 8916 | image (i.e. each test module may elect to skip itself). |
| 8917 | </para> |
| 8918 | |
| 8919 | <para> |
| 8920 | The order you list tests in <filename>TEST_SUITES</filename> |
| 8921 | is important and influences test dependencies. |
| 8922 | Consequently, tests that depend on other tests should be added |
| 8923 | after the test on which they depend. |
| 8924 | For example, since the <filename>ssh</filename> test |
| 8925 | depends on the |
| 8926 | <filename>ping</filename> test, "ssh" needs to come after |
| 8927 | "ping" in the list. |
| 8928 | The test class provides no re-ordering or dependency handling. |
| 8929 | <note> |
| 8930 | Each module can have multiple classes with multiple test |
| 8931 | methods. |
| 8932 | And, Python <filename>unittest</filename> rules apply. |
| 8933 | </note> |
| 8934 | </para> |
| 8935 | |
| 8936 | <para> |
| 8937 | Here are some things to keep in mind when running tests: |
| 8938 | <itemizedlist> |
| 8939 | <listitem><para>The default tests for the image are defined |
| 8940 | as: |
| 8941 | <literallayout class='monospaced'> |
| 8942 | DEFAULT_TEST_SUITES_pn-<replaceable>image</replaceable> = "ping ssh df connman syslog xorg scp vnc date rpm smart dmesg" |
| 8943 | </literallayout></para></listitem> |
| 8944 | <listitem><para>Add your own test to the list of the |
| 8945 | by using the following: |
| 8946 | <literallayout class='monospaced'> |
| 8947 | TEST_SUITES_append = " mytest" |
| 8948 | </literallayout></para></listitem> |
| 8949 | <listitem><para>Run a specific list of tests as follows: |
| 8950 | <literallayout class='monospaced'> |
| 8951 | TEST_SUITES = "test1 test2 test3" |
| 8952 | </literallayout> |
| 8953 | Remember, order is important. |
| 8954 | Be sure to place a test that is dependent on another test |
| 8955 | later in the order.</para></listitem> |
| 8956 | </itemizedlist> |
| 8957 | </para> |
| 8958 | </section> |
| 8959 | |
| 8960 | <section id="exporting-tests"> |
| 8961 | <title>Exporting Tests</title> |
| 8962 | |
| 8963 | <para> |
| 8964 | You can export tests so that they can run independently of |
| 8965 | the build system. |
| 8966 | Exporting tests is required if you want to be able to hand |
| 8967 | the test execution off to a scheduler. |
| 8968 | You can only export tests that are defined in |
| 8969 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SUITES'><filename>TEST_SUITES</filename></ulink>. |
| 8970 | </para> |
| 8971 | |
| 8972 | <para> |
| 8973 | If your image is already built, make sure the following are set |
| 8974 | in your <filename>local.conf</filename> file. |
| 8975 | Be sure to provide the IP address you need: |
| 8976 | <literallayout class='monospaced'> |
| 8977 | TEST_EXPORT_ONLY = "1" |
| 8978 | TEST_TARGET = "simpleremote" |
| 8979 | TEST_TARGET_IP = "192.168.7.2" |
| 8980 | TEST_SERVER_IP = "192.168.7.1" |
| 8981 | </literallayout> |
| 8982 | You can then export the tests with the following: |
| 8983 | <literallayout class='monospaced'> |
| 8984 | $ bitbake core-image-sato -c testimage |
| 8985 | </literallayout> |
| 8986 | Exporting the tests places them in the |
| 8987 | <link linkend='build-directory'>Build Directory</link> in |
| 8988 | <filename>tmp/testimage/core-image-sato</filename>, which |
| 8989 | is controlled by the |
| 8990 | <filename>TEST_EXPORT_DIR</filename> variable. |
| 8991 | </para> |
| 8992 | |
| 8993 | <para> |
| 8994 | You can now run the tests outside of the build environment: |
| 8995 | <literallayout class='monospaced'> |
| 8996 | $ cd tmp/testimage/core-image-sato |
| 8997 | $ ./runexported.py testdata.json |
| 8998 | </literallayout> |
| 8999 | <note> |
| 9000 | This "export" feature does not deploy or boot the target |
| 9001 | image. |
| 9002 | Your target (be it a Qemu or hardware one) |
| 9003 | has to already be up and running when you call |
| 9004 | <filename>runexported.py</filename> |
| 9005 | </note> |
| 9006 | </para> |
| 9007 | |
| 9008 | <para> |
| 9009 | The exported data (i.e. <filename>testdata.json</filename>) |
| 9010 | contains paths to the Build Directory. |
| 9011 | Thus, the contents of the directory can be moved |
| 9012 | to another machine as long as you update some paths in the |
| 9013 | JSON. |
| 9014 | Usually, you only care about the |
| 9015 | <filename>${DEPLOY_DIR}/rpm</filename> directory |
| 9016 | (assuming the RPM and Smart tests are enabled). |
| 9017 | Consequently, running the tests on other machine |
| 9018 | means that you have to move the contents and call |
| 9019 | <filename>runexported.py</filename> with |
| 9020 | "--deploy-dir <replaceable>path</replaceable>" as |
| 9021 | follows: |
| 9022 | <literallayout class='monospaced'> |
| 9023 | ./runexported.py --deploy-dir /new/path/on/this/machine testdata.json |
| 9024 | </literallayout> |
| 9025 | <filename>runexported.py</filename> accepts other arguments |
| 9026 | as well as described using <filename>--help</filename>. |
| 9027 | </para> |
| 9028 | </section> |
| 9029 | |
| 9030 | <section id="qemu-image-writing-new-tests"> |
| 9031 | <title>Writing New Tests</title> |
| 9032 | |
| 9033 | <para> |
| 9034 | As mentioned previously, all new test files need to be in the |
| 9035 | proper place for the build system to find them. |
| 9036 | New tests for additional functionality outside of the core |
| 9037 | should be added to the layer that adds the functionality, in |
| 9038 | <filename><replaceable>layer</replaceable>/lib/oeqa/runtime</filename> |
| 9039 | (as long as |
| 9040 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink> |
| 9041 | is extended in the layer's |
| 9042 | <filename>layer.conf</filename> file as normal). |
| 9043 | Just remember the following: |
| 9044 | <itemizedlist> |
| 9045 | <listitem><para>Filenames need to map directly to test |
| 9046 | (module) names. |
| 9047 | </para></listitem> |
| 9048 | <listitem><para>Do not use module names that |
| 9049 | collide with existing core tests. |
| 9050 | </para></listitem> |
| 9051 | <listitem><para>Minimally, an empty |
| 9052 | <filename>__init__.py</filename> file must exist |
| 9053 | in the runtime directory. |
| 9054 | </para></listitem> |
| 9055 | </itemizedlist> |
| 9056 | </para> |
| 9057 | |
| 9058 | <para> |
| 9059 | To create a new test, start by copying an existing module |
| 9060 | (e.g. <filename>syslog.py</filename> or |
| 9061 | <filename>gcc.py</filename> are good ones to use). |
| 9062 | Test modules can use code from |
| 9063 | <filename>meta/lib/oeqa/utils</filename>, which are helper |
| 9064 | classes. |
| 9065 | </para> |
| 9066 | |
| 9067 | <note> |
| 9068 | Structure shell commands such that you rely on them and they |
| 9069 | return a single code for success. |
| 9070 | Be aware that sometimes you will need to parse the output. |
| 9071 | See the <filename>df.py</filename> and |
| 9072 | <filename>date.py</filename> modules for examples. |
| 9073 | </note> |
| 9074 | |
| 9075 | <para> |
| 9076 | You will notice that all test classes inherit |
| 9077 | <filename>oeRuntimeTest</filename>, which is found in |
| 9078 | <filename>meta/lib/oetest.py</filename>. |
| 9079 | This base class offers some helper attributes, which are |
| 9080 | described in the following sections: |
| 9081 | </para> |
| 9082 | |
| 9083 | <section id='qemu-image-writing-tests-class-methods'> |
| 9084 | <title>Class Methods</title> |
| 9085 | |
| 9086 | <para> |
| 9087 | Class methods are as follows: |
| 9088 | <itemizedlist> |
| 9089 | <listitem><para><emphasis><filename>hasPackage(pkg)</filename>:</emphasis> |
| 9090 | Returns "True" if <filename>pkg</filename> is in the |
| 9091 | installed package list of the image, which is based |
| 9092 | on the manifest file that is generated during the |
| 9093 | <filename>do_rootfs</filename> task. |
| 9094 | </para></listitem> |
| 9095 | <listitem><para><emphasis><filename>hasFeature(feature)</filename>:</emphasis> |
| 9096 | Returns "True" if the feature is in |
| 9097 | <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink> |
| 9098 | or |
| 9099 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>. |
| 9100 | </para></listitem> |
| 9101 | </itemizedlist> |
| 9102 | </para> |
| 9103 | </section> |
| 9104 | |
| 9105 | <section id='qemu-image-writing-tests-class-attributes'> |
| 9106 | <title>Class Attributes</title> |
| 9107 | |
| 9108 | <para> |
| 9109 | Class attributes are as follows: |
| 9110 | <itemizedlist> |
| 9111 | <listitem><para><emphasis><filename>pscmd</filename>:</emphasis> |
| 9112 | Equals "ps -ef" if <filename>procps</filename> is |
| 9113 | installed in the image. |
| 9114 | Otherwise, <filename>pscmd</filename> equals |
| 9115 | "ps" (busybox). |
| 9116 | </para></listitem> |
| 9117 | <listitem><para><emphasis><filename>tc</filename>:</emphasis> |
| 9118 | The called test context, which gives access to the |
| 9119 | following attributes: |
| 9120 | <itemizedlist> |
| 9121 | <listitem><para><emphasis><filename>d</filename>:</emphasis> |
| 9122 | The BitBake datastore, which allows you to |
| 9123 | use stuff such as |
| 9124 | <filename>oeRuntimeTest.tc.d.getVar("VIRTUAL-RUNTIME_init_manager")</filename>. |
| 9125 | </para></listitem> |
| 9126 | <listitem><para><emphasis><filename>testslist</filename> and <filename>testsrequired</filename>:</emphasis> |
| 9127 | Used internally. |
| 9128 | The tests do not need these. |
| 9129 | </para></listitem> |
| 9130 | <listitem><para><emphasis><filename>filesdir</filename>:</emphasis> |
| 9131 | The absolute path to |
| 9132 | <filename>meta/lib/oeqa/runtime/files</filename>, |
| 9133 | which contains helper files for tests meant |
| 9134 | for copying on the target such as small |
| 9135 | files written in C for compilation. |
| 9136 | </para></listitem> |
| 9137 | <listitem><para><emphasis><filename>target</filename>:</emphasis> |
| 9138 | The target controller object used to deploy |
| 9139 | and start an image on a particular target |
| 9140 | (e.g. QemuTarget, SimpleRemote, and |
| 9141 | GummibootTarget). |
| 9142 | Tests usually use the following: |
| 9143 | <itemizedlist> |
| 9144 | <listitem><para><emphasis><filename>ip</filename>:</emphasis> |
| 9145 | The target's IP address. |
| 9146 | </para></listitem> |
| 9147 | <listitem><para><emphasis><filename>server_ip</filename>:</emphasis> |
| 9148 | The host's IP address, which is |
| 9149 | usually used by the "smart" test |
| 9150 | suite. |
| 9151 | </para></listitem> |
| 9152 | <listitem><para><emphasis><filename>run(cmd, timeout=None)</filename>:</emphasis> |
| 9153 | The single, most used method. |
| 9154 | This command is a wrapper for: |
| 9155 | <filename>ssh root@host "cmd"</filename>. |
| 9156 | The command returns a tuple: |
| 9157 | (status, output), which are what |
| 9158 | their names imply - the return code |
| 9159 | of "cmd" and whatever output |
| 9160 | it produces. |
| 9161 | The optional timeout argument |
| 9162 | represents the number of seconds the |
| 9163 | test should wait for "cmd" to |
| 9164 | return. |
| 9165 | If the argument is "None", the |
| 9166 | test uses the default instance's |
| 9167 | timeout period, which is 300 |
| 9168 | seconds. |
| 9169 | If the argument is "0", the test |
| 9170 | runs until the command returns. |
| 9171 | </para></listitem> |
| 9172 | <listitem><para><emphasis><filename>copy_to(localpath, remotepath)</filename>:</emphasis> |
| 9173 | <filename>scp localpath root@ip:remotepath</filename>. |
| 9174 | </para></listitem> |
| 9175 | <listitem><para><emphasis><filename>copy_from(remotepath, localpath)</filename>:</emphasis> |
| 9176 | <filename>scp root@host:remotepath localpath</filename>. |
| 9177 | </para></listitem> |
| 9178 | </itemizedlist></para></listitem> |
| 9179 | </itemizedlist></para></listitem> |
| 9180 | </itemizedlist> |
| 9181 | </para> |
| 9182 | </section> |
| 9183 | |
| 9184 | <section id='qemu-image-writing-tests-instance-attributes'> |
| 9185 | <title>Instance Attributes</title> |
| 9186 | |
| 9187 | <para> |
| 9188 | A single instance attribute exists, which is |
| 9189 | <filename>target</filename>. |
| 9190 | The <filename>target</filename> instance attribute is |
| 9191 | identical to the class attribute of the same name, which |
| 9192 | is described in the previous section. |
| 9193 | This attribute exists as both an instance and class |
| 9194 | attribute so tests can use |
| 9195 | <filename>self.target.run(cmd)</filename> in instance |
| 9196 | methods instead of |
| 9197 | <filename>oeRuntimeTest.tc.target.run(cmd)</filename>. |
| 9198 | </para> |
| 9199 | </section> |
| 9200 | </section> |
| 9201 | </section> |
| 9202 | |
| 9203 | <section id="platdev-gdb-remotedebug"> |
| 9204 | <title>Debugging With the GNU Project Debugger (GDB) Remotely</title> |
| 9205 | |
| 9206 | <para> |
| 9207 | GDB allows you to examine running programs, which in turn helps you to understand and fix problems. |
| 9208 | It also allows you to perform post-mortem style analysis of program crashes. |
| 9209 | GDB is available as a package within the Yocto Project and is |
| 9210 | installed in SDK images by default. |
| 9211 | See the "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>" chapter |
| 9212 | in the Yocto Project Reference Manual for a description of these images. |
| 9213 | You can find information on GDB at <ulink url="http://sourceware.org/gdb/"/>. |
| 9214 | </para> |
| 9215 | |
| 9216 | <tip> |
| 9217 | For best results, install debug (<filename>-dbg</filename>) packages |
| 9218 | for the applications you are going to debug. |
| 9219 | Doing so makes extra debug symbols available that give you more |
| 9220 | meaningful output. |
| 9221 | </tip> |
| 9222 | |
| 9223 | <para> |
| 9224 | Sometimes, due to memory or disk space constraints, it is not possible |
| 9225 | to use GDB directly on the remote target to debug applications. |
| 9226 | These constraints arise because GDB needs to load the debugging information and the |
| 9227 | binaries of the process being debugged. |
| 9228 | Additionally, GDB needs to perform many computations to locate information such as function |
| 9229 | names, variable names and values, stack traces and so forth - even before starting the |
| 9230 | debugging process. |
| 9231 | These extra computations place more load on the target system and can alter the |
| 9232 | characteristics of the program being debugged. |
| 9233 | </para> |
| 9234 | |
| 9235 | <para> |
| 9236 | To help get past the previously mentioned constraints, you can use Gdbserver. |
| 9237 | Gdbserver runs on the remote target and does not load any debugging information |
| 9238 | from the debugged process. |
| 9239 | Instead, a GDB instance processes the debugging information that is run on a |
| 9240 | remote computer - the host GDB. |
| 9241 | The host GDB then sends control commands to Gdbserver to make it stop or start the debugged |
| 9242 | program, as well as read or write memory regions of that debugged program. |
| 9243 | All the debugging information loaded and processed as well |
| 9244 | as all the heavy debugging is done by the host GDB. |
| 9245 | Offloading these processes gives the Gdbserver running on the target a chance to remain |
| 9246 | small and fast. |
| 9247 | <note> |
| 9248 | By default, source files are part of the |
| 9249 | <filename>*-dbg</filename> packages in order to enable GDB |
| 9250 | to show source lines in its output. |
| 9251 | You can save further space on the target by setting the |
| 9252 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_DEBUG_SPLIT_STYLE'><filename>PACKAGE_DEBUG_SPLIT_STYLE</filename></ulink> |
| 9253 | variable to "debug-without-src" so that these packages do not |
| 9254 | include the source files. |
| 9255 | </note> |
| 9256 | </para> |
| 9257 | |
| 9258 | <para> |
| 9259 | Because the host GDB is responsible for loading the debugging information and |
| 9260 | for doing the necessary processing to make actual debugging happen, |
| 9261 | you have to make sure the host can access the unstripped binaries complete |
| 9262 | with their debugging information and also be sure the target is compiled with no optimizations. |
| 9263 | The host GDB must also have local access to all the libraries used by the |
| 9264 | debugged program. |
| 9265 | Because Gdbserver does not need any local debugging information, the binaries on |
| 9266 | the remote target can remain stripped. |
| 9267 | However, the binaries must also be compiled without optimization |
| 9268 | so they match the host's binaries. |
| 9269 | </para> |
| 9270 | |
| 9271 | <para> |
| 9272 | To remain consistent with GDB documentation and terminology, the binary being debugged |
| 9273 | on the remote target machine is referred to as the "inferior" binary. |
| 9274 | For documentation on GDB see the |
| 9275 | <ulink url="http://sourceware.org/gdb/documentation/">GDB site</ulink>. |
| 9276 | </para> |
| 9277 | |
| 9278 | <para> |
| 9279 | The remainder of this section describes the steps you need to take |
| 9280 | to debug using the GNU project debugger. |
| 9281 | </para> |
| 9282 | |
| 9283 | <section id='platdev-gdb-remotedebug-setup'> |
| 9284 | <title>Set Up the Cross-Development Debugging Environment</title> |
| 9285 | |
| 9286 | <para> |
| 9287 | Before you can initiate a remote debugging session, you need |
| 9288 | to be sure you have set up the cross-development environment, |
| 9289 | toolchain, and sysroot. |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 9290 | The <ulink url='&YOCTO_DOCS_SDK_URL;#sdk-intro'>Yocto Project Software Development Kit (SDK) Developer's Guide</ulink> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9291 | describes this process. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9292 | </para> |
| 9293 | </section> |
| 9294 | |
| 9295 | <section id="platdev-gdb-remotedebug-launch-gdbserver"> |
| 9296 | <title>Launch Gdbserver on the Target</title> |
| 9297 | |
| 9298 | <para> |
| 9299 | Make sure Gdbserver is installed on the target. |
| 9300 | If it is not, install the package |
| 9301 | <filename>gdbserver</filename>, which needs the |
| 9302 | <filename>libthread-db1</filename> package. |
| 9303 | </para> |
| 9304 | |
| 9305 | <para> |
| 9306 | Here is an example, that when entered from the host, |
| 9307 | connects to the target and launches Gdbserver in order to |
| 9308 | "debug" a binary named <filename>helloworld</filename>: |
| 9309 | <literallayout class='monospaced'> |
| 9310 | $ gdbserver localhost:2345 /usr/bin/helloworld |
| 9311 | </literallayout> |
| 9312 | Gdbserver should now be listening on port 2345 for debugging |
| 9313 | commands coming from a remote GDB process that is running on |
| 9314 | the host computer. |
| 9315 | Communication between Gdbserver and the host GDB are done |
| 9316 | using TCP. |
| 9317 | To use other communication protocols, please refer to the |
| 9318 | <ulink url='http://www.gnu.org/software/gdb/'>Gdbserver documentation</ulink>. |
| 9319 | </para> |
| 9320 | </section> |
| 9321 | |
| 9322 | <section id="platdev-gdb-remotedebug-launch-gdb"> |
| 9323 | <title>Launch GDB on the Host Computer</title> |
| 9324 | |
| 9325 | <para> |
| 9326 | Running GDB on the host computer takes a number of stages, which |
| 9327 | this section describes. |
| 9328 | </para> |
| 9329 | |
| 9330 | <section id="platdev-gdb-remotedebug-launch-gdb-buildcross"> |
| 9331 | <title>Build the Cross-GDB Package</title> |
| 9332 | <para> |
| 9333 | A suitable GDB cross-binary is required that runs on your |
| 9334 | host computer but also knows about the the ABI of the |
| 9335 | remote target. |
| 9336 | You can get this binary from the |
| 9337 | <link linkend='cross-development-toolchain'>Cross-Development Toolchain</link>. |
| 9338 | Here is an example where the toolchain has been installed |
| 9339 | in the default directory |
| 9340 | <filename>/opt/poky/&DISTRO;</filename>: |
| 9341 | <literallayout class='monospaced'> |
| 9342 | /opt/poky/&DISTRO;/sysroots/i686-pokysdk-linux/usr/bin/armv7a-vfp-neon-poky-linux-gnueabi/arm-poky-linux-gnueabi-gdb |
| 9343 | </literallayout> |
| 9344 | where <filename>arm</filename> is the target architecture |
| 9345 | and <filename>linux-gnueabi</filename> is the target ABI. |
| 9346 | </para> |
| 9347 | |
| 9348 | <para> |
| 9349 | Alternatively, you can use BitBake to build the |
| 9350 | <filename>gdb-cross</filename> binary. |
| 9351 | Here is an example: |
| 9352 | <literallayout class='monospaced'> |
| 9353 | $ bitbake gdb-cross |
| 9354 | </literallayout> |
| 9355 | Once the binary is built, you can find it here: |
| 9356 | <literallayout class='monospaced'> |
| 9357 | tmp/sysroots/<replaceable>host-arch</replaceable>/usr/bin/<replaceable>target-platform</replaceable>/<replaceable>target-abi</replaceable>-gdb |
| 9358 | </literallayout> |
| 9359 | </para> |
| 9360 | </section> |
| 9361 | |
| 9362 | <section id='create-the-gdb-initialization-file'> |
| 9363 | <title>Create the GDB Initialization File and Point to Your Root Filesystem</title> |
| 9364 | |
| 9365 | <para> |
| 9366 | Aside from the GDB cross-binary, you also need a GDB |
| 9367 | initialization file in the same top directory in which |
| 9368 | your binary resides. |
| 9369 | When you start GDB on your host development system, GDB |
| 9370 | finds this initialization file and executes all the |
| 9371 | commands within. |
| 9372 | For information on the <filename>.gdbinit</filename>, see |
| 9373 | "<ulink url='http://sourceware.org/gdb/onlinedocs/gdb/'>Debugging with GDB</ulink>", |
| 9374 | which is maintained by |
| 9375 | <ulink url='http://www.sourceware.org'>sourceware.org</ulink>. |
| 9376 | </para> |
| 9377 | |
| 9378 | <para> |
| 9379 | You need to add a statement in the |
| 9380 | <filename>~/.gdbinit</filename> file that points to your |
| 9381 | root filesystem. |
| 9382 | Here is an example that points to the root filesystem for |
| 9383 | an ARM-based target device: |
| 9384 | <literallayout class='monospaced'> |
| 9385 | set sysroot ~/sysroot_arm |
| 9386 | </literallayout> |
| 9387 | </para> |
| 9388 | </section> |
| 9389 | |
| 9390 | <section id="platdev-gdb-remotedebug-launch-gdb-launchhost"> |
| 9391 | <title>Launch the Host GDB</title> |
| 9392 | |
| 9393 | <para> |
| 9394 | Before launching the host GDB, you need to be sure |
| 9395 | you have sourced the cross-debugging environment script, |
| 9396 | which if you installed the root filesystem in the default |
| 9397 | location is at <filename>/opt/poky/&DISTRO;</filename> |
| 9398 | and begins with the string "environment-setup". |
| 9399 | For more information, see the |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 9400 | <ulink url='&YOCTO_DOCS_SDK_URL;#sdk-manual'>Yocto Project Software Development Kit (SDK) Developer's |
| 9401 | Guide</ulink>. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9402 | </para> |
| 9403 | |
| 9404 | <para> |
| 9405 | Finally, switch to the directory where the binary resides |
| 9406 | and run the <filename>cross-gdb</filename> binary. |
| 9407 | Provide the binary file you are going to debug. |
| 9408 | For example, the following command continues with the |
| 9409 | example used in the previous section by loading |
| 9410 | the <filename>helloworld</filename> binary as well as the |
| 9411 | debugging information: |
| 9412 | <literallayout class='monospaced'> |
| 9413 | $ arm-poky-linux-gnuabi-gdb helloworld |
| 9414 | </literallayout> |
| 9415 | The commands in your <filename>.gdbinit</filename> execute |
| 9416 | and the GDB prompt appears. |
| 9417 | </para> |
| 9418 | </section> |
| 9419 | </section> |
| 9420 | |
| 9421 | <section id='platdev-gdb-connect-to-the-remote-gdb-server'> |
| 9422 | <title>Connect to the Remote GDB Server</title> |
| 9423 | |
| 9424 | <para> |
| 9425 | From the target, you need to connect to the remote GDB |
| 9426 | server that is running on the host. |
| 9427 | You need to specify the remote host and port. |
| 9428 | Here is the command continuing with the example: |
| 9429 | <literallayout class='monospaced'> |
| 9430 | target remote 192.168.7.2:2345 |
| 9431 | </literallayout> |
| 9432 | </para> |
| 9433 | </section> |
| 9434 | |
| 9435 | <section id="platdev-gdb-remotedebug-launch-gdb-using"> |
| 9436 | <title>Use the Debugger</title> |
| 9437 | |
| 9438 | <para> |
| 9439 | You can now proceed with debugging as normal - as if you were debugging |
| 9440 | on the local machine. |
| 9441 | For example, to instruct GDB to break in the "main" function and then |
| 9442 | continue with execution of the inferior binary use the following commands |
| 9443 | from within GDB: |
| 9444 | <literallayout class='monospaced'> |
| 9445 | (gdb) break main |
| 9446 | (gdb) continue |
| 9447 | </literallayout> |
| 9448 | </para> |
| 9449 | |
| 9450 | <para> |
| 9451 | For more information about using GDB, see the project's online documentation at |
| 9452 | <ulink url="http://sourceware.org/gdb/download/onlinedocs/"/>. |
| 9453 | </para> |
| 9454 | </section> |
| 9455 | </section> |
| 9456 | |
| 9457 | <section id='debugging-parallel-make-races'> |
| 9458 | <title>Debugging Parallel Make Races</title> |
| 9459 | |
| 9460 | <para> |
| 9461 | A parallel <filename>make</filename> race occurs when the build |
| 9462 | consists of several parts that are run simultaneously and |
| 9463 | a situation occurs when the output or result of one |
| 9464 | part is not ready for use with a different part of the build that |
| 9465 | depends on that output. |
| 9466 | Parallel make races are annoying and can sometimes be difficult |
| 9467 | to reproduce and fix. |
| 9468 | However, some simple tips and tricks exist that can help |
| 9469 | you debug and fix them. |
| 9470 | This section presents a real-world example of an error encountered |
| 9471 | on the Yocto Project autobuilder and the process used to fix it. |
| 9472 | <note> |
| 9473 | If you cannot properly fix a <filename>make</filename> race |
| 9474 | condition, you can work around it by clearing either the |
| 9475 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink> |
| 9476 | or |
| 9477 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKEINST'><filename>PARALLEL_MAKEINST</filename></ulink> |
| 9478 | variables. |
| 9479 | </note> |
| 9480 | </para> |
| 9481 | |
| 9482 | <section id='the-failure'> |
| 9483 | <title>The Failure</title> |
| 9484 | |
| 9485 | <para> |
| 9486 | For this example, assume that you are building an image that |
| 9487 | depends on the "neard" package. |
| 9488 | And, during the build, BitBake runs into problems and |
| 9489 | creates the following output. |
| 9490 | <note> |
| 9491 | This example log file has longer lines artificially |
| 9492 | broken to make the listing easier to read. |
| 9493 | </note> |
| 9494 | If you examine the output or the log file, you see the |
| 9495 | failure during <filename>make</filename>: |
| 9496 | <literallayout class='monospaced'> |
| 9497 | | DEBUG: SITE files ['endian-little', 'bit-32', 'ix86-common', 'common-linux', 'common-glibc', 'i586-linux', 'common'] |
| 9498 | | DEBUG: Executing shell function do_compile |
| 9499 | | NOTE: make -j 16 |
| 9500 | | make --no-print-directory all-am |
| 9501 | | /bin/mkdir -p include/near |
| 9502 | | /bin/mkdir -p include/near |
| 9503 | | /bin/mkdir -p include/near |
| 9504 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9505 | 0.14-r0/neard-0.14/include/types.h include/near/types.h |
| 9506 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9507 | 0.14-r0/neard-0.14/include/log.h include/near/log.h |
| 9508 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9509 | 0.14-r0/neard-0.14/include/plugin.h include/near/plugin.h |
| 9510 | | /bin/mkdir -p include/near |
| 9511 | | /bin/mkdir -p include/near |
| 9512 | | /bin/mkdir -p include/near |
| 9513 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9514 | 0.14-r0/neard-0.14/include/tag.h include/near/tag.h |
| 9515 | | /bin/mkdir -p include/near |
| 9516 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9517 | 0.14-r0/neard-0.14/include/adapter.h include/near/adapter.h |
| 9518 | | /bin/mkdir -p include/near |
| 9519 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9520 | 0.14-r0/neard-0.14/include/ndef.h include/near/ndef.h |
| 9521 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9522 | 0.14-r0/neard-0.14/include/tlv.h include/near/tlv.h |
| 9523 | | /bin/mkdir -p include/near |
| 9524 | | /bin/mkdir -p include/near |
| 9525 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9526 | 0.14-r0/neard-0.14/include/setting.h include/near/setting.h |
| 9527 | | /bin/mkdir -p include/near |
| 9528 | | /bin/mkdir -p include/near |
| 9529 | | /bin/mkdir -p include/near |
| 9530 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9531 | 0.14-r0/neard-0.14/include/device.h include/near/device.h |
| 9532 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9533 | 0.14-r0/neard-0.14/include/nfc_copy.h include/near/nfc_copy.h |
| 9534 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9535 | 0.14-r0/neard-0.14/include/snep.h include/near/snep.h |
| 9536 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9537 | 0.14-r0/neard-0.14/include/version.h include/near/version.h |
| 9538 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9539 | 0.14-r0/neard-0.14/include/dbus.h include/near/dbus.h |
| 9540 | | ./src/genbuiltin nfctype1 nfctype2 nfctype3 nfctype4 p2p > src/builtin.h |
| 9541 | | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/ |
| 9542 | build/build/tmp/sysroots/qemux86 -DHAVE_CONFIG_H -I. -I./include -I./src -I./gdbus -I/home/pokybuild/ |
| 9543 | yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/glib-2.0 |
| 9544 | -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/ |
| 9545 | lib/glib-2.0/include -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/ |
| 9546 | tmp/sysroots/qemux86/usr/include/dbus-1.0 -I/home/pokybuild/yocto-autobuilder/yocto-slave/ |
| 9547 | nightly-x86/build/build/tmp/sysroots/qemux86/usr/lib/dbus-1.0/include -I/home/pokybuild/yocto-autobuilder/ |
| 9548 | yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/libnl3 |
| 9549 | -DNEAR_PLUGIN_BUILTIN -DPLUGINDIR=\""/usr/lib/near/plugins"\" |
| 9550 | -DCONFIGDIR=\""/etc/neard\"" -O2 -pipe -g -feliminate-unused-debug-types -c |
| 9551 | -o tools/snep-send.o tools/snep-send.c |
| 9552 | | In file included from tools/snep-send.c:16:0: |
| 9553 | | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory |
| 9554 | | #include <near/dbus.h> |
| 9555 | | ^ |
| 9556 | | compilation terminated. |
| 9557 | | make[1]: *** [tools/snep-send.o] Error 1 |
| 9558 | | make[1]: *** Waiting for unfinished jobs.... |
| 9559 | | make: *** [all] Error 2 |
| 9560 | | ERROR: oe_runmake failed |
| 9561 | </literallayout> |
| 9562 | </para> |
| 9563 | </section> |
| 9564 | |
| 9565 | <section id='reproducing-the-error'> |
| 9566 | <title>Reproducing the Error</title> |
| 9567 | |
| 9568 | <para> |
| 9569 | Because race conditions are intermittent, they do not |
| 9570 | manifest themselves every time you do the build. |
| 9571 | In fact, most times the build will complete without problems |
| 9572 | even though the potential race condition exists. |
| 9573 | Thus, once the error surfaces, you need a way to reproduce it. |
| 9574 | </para> |
| 9575 | |
| 9576 | <para> |
| 9577 | In this example, compiling the "neard" package is causing the |
| 9578 | problem. |
| 9579 | So the first thing to do is build "neard" locally. |
| 9580 | Before you start the build, set the |
| 9581 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink> |
| 9582 | variable in your <filename>local.conf</filename> file to |
| 9583 | a high number (e.g. "-j 20"). |
| 9584 | Using a high value for <filename>PARALLEL_MAKE</filename> |
| 9585 | increases the chances of the race condition showing up: |
| 9586 | <literallayout class='monospaced'> |
| 9587 | $ bitbake neard |
| 9588 | </literallayout> |
| 9589 | </para> |
| 9590 | |
| 9591 | <para> |
| 9592 | Once the local build for "neard" completes, start a |
| 9593 | <filename>devshell</filename> build: |
| 9594 | <literallayout class='monospaced'> |
| 9595 | $ bitbake neard -c devshell |
| 9596 | </literallayout> |
| 9597 | For information on how to use a |
| 9598 | <filename>devshell</filename>, see the |
| 9599 | "<link linkend='platdev-appdev-devshell'>Using a Development Shell</link>" |
| 9600 | section. |
| 9601 | </para> |
| 9602 | |
| 9603 | <para> |
| 9604 | In the <filename>devshell</filename>, do the following: |
| 9605 | <literallayout class='monospaced'> |
| 9606 | $ make clean |
| 9607 | $ make tools/snep-send.o |
| 9608 | </literallayout> |
| 9609 | The <filename>devshell</filename> commands cause the failure |
| 9610 | to clearly be visible. |
| 9611 | In this case, a missing dependency exists for the "neard" |
| 9612 | Makefile target. |
| 9613 | Here is some abbreviated, sample output with the |
| 9614 | missing dependency clearly visible at the end: |
| 9615 | <literallayout class='monospaced'> |
| 9616 | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/scott-lenovo/...... |
| 9617 | . |
| 9618 | . |
| 9619 | . |
| 9620 | tools/snep-send.c |
| 9621 | In file included from tools/snep-send.c:16:0: |
| 9622 | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory |
| 9623 | #include <near/dbus.h> |
| 9624 | ^ |
| 9625 | compilation terminated. |
| 9626 | make: *** [tools/snep-send.o] Error 1 |
| 9627 | $ |
| 9628 | </literallayout> |
| 9629 | </para> |
| 9630 | </section> |
| 9631 | |
| 9632 | <section id='creating-a-patch-for-the-fix'> |
| 9633 | <title>Creating a Patch for the Fix</title> |
| 9634 | |
| 9635 | <para> |
| 9636 | Because there is a missing dependency for the Makefile |
| 9637 | target, you need to patch the |
| 9638 | <filename>Makefile.am</filename> file, which is generated |
| 9639 | from <filename>Makefile.in</filename>. |
| 9640 | You can use Quilt to create the patch: |
| 9641 | <literallayout class='monospaced'> |
| 9642 | $ quilt new parallelmake.patch |
| 9643 | Patch patches/parallelmake.patch is now on top |
| 9644 | $ quilt add Makefile.am |
| 9645 | File Makefile.am added to patch patches/parallelmake.patch |
| 9646 | </literallayout> |
| 9647 | For more information on using Quilt, see the |
| 9648 | "<link linkend='using-a-quilt-workflow'>Using Quilt in Your Workflow</link>" |
| 9649 | section. |
| 9650 | </para> |
| 9651 | |
| 9652 | <para> |
| 9653 | At this point you need to make the edits to |
| 9654 | <filename>Makefile.am</filename> to add the missing |
| 9655 | dependency. |
| 9656 | For our example, you have to add the following line |
| 9657 | to the file: |
| 9658 | <literallayout class='monospaced'> |
| 9659 | tools/snep-send.$(OBJEXT): include/near/dbus.h |
| 9660 | </literallayout> |
| 9661 | </para> |
| 9662 | |
| 9663 | <para> |
| 9664 | Once you have edited the file, use the |
| 9665 | <filename>refresh</filename> command to create the patch: |
| 9666 | <literallayout class='monospaced'> |
| 9667 | $ quilt refresh |
| 9668 | Refreshed patch patches/parallelmake.patch |
| 9669 | </literallayout> |
| 9670 | Once the patch file exists, you need to add it back to the |
| 9671 | originating recipe folder. |
| 9672 | Here is an example assuming a top-level |
| 9673 | <link linkend='source-directory'>Source Directory</link> |
| 9674 | named <filename>poky</filename>: |
| 9675 | <literallayout class='monospaced'> |
| 9676 | $ cp patches/parallelmake.patch poky/meta/recipes-connectivity/neard/neard |
| 9677 | </literallayout> |
| 9678 | The final thing you need to do to implement the fix in the |
| 9679 | build is to update the "neard" recipe (i.e. |
| 9680 | <filename>neard-0.14.bb</filename>) so that the |
| 9681 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> |
| 9682 | statement includes the patch file. |
| 9683 | The recipe file is in the folder above the patch. |
| 9684 | Here is what the edited <filename>SRC_URI</filename> |
| 9685 | statement would look like: |
| 9686 | <literallayout class='monospaced'> |
| 9687 | SRC_URI = "${KERNELORG_MIRROR}/linux/network/nfc/${BPN}-${PV}.tar.xz \ |
| 9688 | file://neard.in \ |
| 9689 | file://neard.service.in \ |
| 9690 | file://parallelmake.patch \ |
| 9691 | " |
| 9692 | </literallayout> |
| 9693 | </para> |
| 9694 | |
| 9695 | <para> |
| 9696 | With the patch complete and moved to the correct folder and |
| 9697 | the <filename>SRC_URI</filename> statement updated, you can |
| 9698 | exit the <filename>devshell</filename>: |
| 9699 | <literallayout class='monospaced'> |
| 9700 | $ exit |
| 9701 | </literallayout> |
| 9702 | </para> |
| 9703 | </section> |
| 9704 | |
| 9705 | <section id='testing-the-build'> |
| 9706 | <title>Testing the Build</title> |
| 9707 | |
| 9708 | <para> |
| 9709 | With everything in place, you can get back to trying the |
| 9710 | build again locally: |
| 9711 | <literallayout class='monospaced'> |
| 9712 | $ bitbake neard |
| 9713 | </literallayout> |
| 9714 | This build should succeed. |
| 9715 | </para> |
| 9716 | |
| 9717 | <para> |
| 9718 | Now you can open up a <filename>devshell</filename> again |
| 9719 | and repeat the clean and make operations as follows: |
| 9720 | <literallayout class='monospaced'> |
| 9721 | $ bitbake neard -c devshell |
| 9722 | $ make clean |
| 9723 | $ make tools/snep-send.o |
| 9724 | </literallayout> |
| 9725 | The build should work without issue. |
| 9726 | </para> |
| 9727 | |
| 9728 | <para> |
| 9729 | As with all solved problems, if they originated upstream, you |
| 9730 | need to submit the fix for the recipe in OE-Core and upstream |
| 9731 | so that the problem is taken care of at its source. |
| 9732 | See the |
| 9733 | "<link linkend='how-to-submit-a-change'>How to Submit a Change</link>" |
| 9734 | section for more information. |
| 9735 | </para> |
| 9736 | </section> |
| 9737 | </section> |
| 9738 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 9739 | <!-- |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9740 | <section id="platdev-oprofile"> |
| 9741 | <title>Profiling with OProfile</title> |
| 9742 | |
| 9743 | <para> |
| 9744 | <ulink url="http://oprofile.sourceforge.net/">OProfile</ulink> is a |
| 9745 | statistical profiler well suited for finding performance |
| 9746 | bottlenecks in both user-space software and in the kernel. |
| 9747 | This profiler provides answers to questions like "Which functions does my application spend |
| 9748 | the most time in when doing X?" |
| 9749 | Because the OpenEmbedded build system is well integrated with OProfile, it makes profiling |
| 9750 | applications on target hardware straight forward. |
| 9751 | <note> |
| 9752 | For more information on how to set up and run OProfile, see the |
| 9753 | "<ulink url='&YOCTO_DOCS_PROF_URL;#profile-manual-oprofile'>oprofile</ulink>" |
| 9754 | section in the Yocto Project Profiling and Tracing Manual. |
| 9755 | </note> |
| 9756 | </para> |
| 9757 | |
| 9758 | <para> |
| 9759 | To use OProfile, you need an image that has OProfile installed. |
| 9760 | The easiest way to do this is with "tools-profile" in the |
| 9761 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'>IMAGE_FEATURES</ulink></filename> variable. |
| 9762 | You also need debugging symbols to be available on the system where the analysis |
| 9763 | takes place. |
| 9764 | You can gain access to the symbols by using "dbg-pkgs" in the |
| 9765 | <filename>IMAGE_FEATURES</filename> variable or by |
| 9766 | installing the appropriate debug (<filename>-dbg</filename>) |
| 9767 | packages. |
| 9768 | </para> |
| 9769 | |
| 9770 | <para> |
| 9771 | For successful call graph analysis, the binaries must preserve the frame |
| 9772 | pointer register and should also be compiled with the |
| 9773 | <filename>-fno-omit-framepointer</filename> flag. |
| 9774 | You can achieve this by setting the |
| 9775 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SELECTED_OPTIMIZATION'>SELECTED_OPTIMIZATION</ulink></filename> |
| 9776 | variable with the following options: |
| 9777 | <literallayout class='monospaced'> |
| 9778 | -fexpensive-optimizations |
| 9779 | -fno-omit-framepointer |
| 9780 | -frename-registers |
| 9781 | -O2 |
| 9782 | </literallayout> |
| 9783 | You can also achieve it by setting the |
| 9784 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-DEBUG_BUILD'>DEBUG_BUILD</ulink></filename> |
| 9785 | variable to "1" in the <filename>local.conf</filename> configuration file. |
| 9786 | If you use the <filename>DEBUG_BUILD</filename> variable, |
| 9787 | you also add extra debugging information that can make the debug |
| 9788 | packages large. |
| 9789 | </para> |
| 9790 | |
| 9791 | <section id="platdev-oprofile-target"> |
| 9792 | <title>Profiling on the Target</title> |
| 9793 | |
| 9794 | <para> |
| 9795 | Using OProfile, you can perform all the profiling work on the target device. |
| 9796 | A simple OProfile session might look like the following: |
| 9797 | </para> |
| 9798 | |
| 9799 | <para> |
| 9800 | <literallayout class='monospaced'> |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 9801 | # opcontrol ‐‐reset |
| 9802 | # opcontrol ‐‐start ‐‐separate=lib ‐‐no-vmlinux -c 5 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9803 | . |
| 9804 | . |
| 9805 | [do whatever is being profiled] |
| 9806 | . |
| 9807 | . |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 9808 | # opcontrol ‐‐stop |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9809 | $ opreport -cl |
| 9810 | </literallayout> |
| 9811 | </para> |
| 9812 | |
| 9813 | <para> |
| 9814 | In this example, the <filename>reset</filename> command clears any previously profiled data. |
| 9815 | The next command starts OProfile. |
| 9816 | The options used when starting the profiler separate dynamic library data |
| 9817 | within applications, disable kernel profiling, and enable callgraphing up to |
| 9818 | five levels deep. |
| 9819 | <note> |
| 9820 | To profile the kernel, you would specify the |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 9821 | <filename>‐‐vmlinux=/path/to/vmlinux</filename> option. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9822 | The <filename>vmlinux</filename> file is usually in the source directory in the |
| 9823 | <filename>/boot/</filename> directory and must match the running kernel. |
| 9824 | </note> |
| 9825 | </para> |
| 9826 | |
| 9827 | <para> |
| 9828 | After you perform your profiling tasks, the next command stops the profiler. |
| 9829 | After that, you can view results with the <filename>opreport</filename> command with options |
| 9830 | to see the separate library symbols and callgraph information. |
| 9831 | </para> |
| 9832 | |
| 9833 | <para> |
| 9834 | Callgraphing logs information about time spent in functions and about a function's |
| 9835 | calling function (parent) and called functions (children). |
| 9836 | The higher the callgraphing depth, the more accurate the results. |
| 9837 | However, higher depths also increase the logging overhead. |
| 9838 | Consequently, you should take care when setting the callgraphing depth. |
| 9839 | <note> |
| 9840 | On ARM, binaries need to have the frame pointer enabled for callgraphing to work. |
| 9841 | To accomplish this use the <filename>-fno-omit-framepointer</filename> option |
| 9842 | with <filename>gcc</filename>. |
| 9843 | </note> |
| 9844 | </para> |
| 9845 | |
| 9846 | <para> |
| 9847 | For more information on using OProfile, see the OProfile |
| 9848 | online documentation at |
| 9849 | <ulink url="http://oprofile.sourceforge.net/docs/"/>. |
| 9850 | </para> |
| 9851 | </section> |
| 9852 | |
| 9853 | <section id="platdev-oprofile-oprofileui"> |
| 9854 | <title>Using OProfileUI</title> |
| 9855 | |
| 9856 | <para> |
| 9857 | A graphical user interface for OProfile is also available. |
| 9858 | You can download and build this interface from the Yocto Project at |
| 9859 | <ulink url="&YOCTO_GIT_URL;/cgit.cgi/oprofileui/"></ulink>. |
| 9860 | If the "tools-profile" image feature is selected, all necessary binaries |
| 9861 | are installed onto the target device for OProfileUI interaction. |
| 9862 | For a list of image features that ship with the Yocto Project, |
| 9863 | see the |
| 9864 | "<ulink url='&YOCTO_DOCS_REF_URL;#ref-features-image'>Image Features</ulink>" |
| 9865 | section in the Yocto Project Reference Manual. |
| 9866 | </para> |
| 9867 | |
| 9868 | <para> |
| 9869 | Even though the source directory usually includes all needed patches on the target device, you |
| 9870 | might find you need other OProfile patches for recent OProfileUI features. |
| 9871 | If so, see the <ulink url='&YOCTO_GIT_URL;/cgit.cgi/oprofileui/tree/README'> |
| 9872 | OProfileUI README</ulink> for the most recent information. |
| 9873 | </para> |
| 9874 | |
| 9875 | <section id="platdev-oprofile-oprofileui-online"> |
| 9876 | <title>Online Mode</title> |
| 9877 | |
| 9878 | <para> |
| 9879 | Using OProfile in online mode assumes a working network connection with the target |
| 9880 | hardware. |
| 9881 | With this connection, you just need to run "oprofile-server" on the device. |
| 9882 | By default, OProfile listens on port 4224. |
| 9883 | <note> |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 9884 | You can change the port using the <filename>‐‐port</filename> command-line |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9885 | option. |
| 9886 | </note> |
| 9887 | </para> |
| 9888 | |
| 9889 | <para> |
| 9890 | The client program is called <filename>oprofile-viewer</filename> and its UI is relatively |
| 9891 | straight forward. |
| 9892 | You access key functionality through the buttons on the toolbar, which |
| 9893 | are duplicated in the menus. |
| 9894 | Here are the buttons: |
| 9895 | <itemizedlist> |
| 9896 | <listitem><para><emphasis>Connect:</emphasis> Connects to the remote host. |
| 9897 | You can also supply the IP address or hostname.</para></listitem> |
| 9898 | <listitem><para><emphasis>Disconnect:</emphasis> Disconnects from the target. |
| 9899 | </para></listitem> |
| 9900 | <listitem><para><emphasis>Start:</emphasis> Starts profiling on the device. |
| 9901 | </para></listitem> |
| 9902 | <listitem><para><emphasis>Stop:</emphasis> Stops profiling on the device and |
| 9903 | downloads the data to the local host. |
| 9904 | Stopping the profiler generates the profile and displays it in the viewer. |
| 9905 | </para></listitem> |
| 9906 | <listitem><para><emphasis>Download:</emphasis> Downloads the data from the |
| 9907 | target and generates the profile, which appears in the viewer.</para></listitem> |
| 9908 | <listitem><para><emphasis>Reset:</emphasis> Resets the sample data on the device. |
| 9909 | Resetting the data removes sample information collected from previous |
| 9910 | sampling runs. |
| 9911 | Be sure you reset the data if you do not want to include old sample information. |
| 9912 | </para></listitem> |
| 9913 | <listitem><para><emphasis>Save:</emphasis> Saves the data downloaded from the |
| 9914 | target to another directory for later examination.</para></listitem> |
| 9915 | <listitem><para><emphasis>Open:</emphasis> Loads previously saved data. |
| 9916 | </para></listitem> |
| 9917 | </itemizedlist> |
| 9918 | </para> |
| 9919 | |
| 9920 | <para> |
| 9921 | The client downloads the complete profile archive from |
| 9922 | the target to the host for processing. |
| 9923 | This archive is a directory that contains the sample data, the object files, |
| 9924 | and the debug information for the object files. |
| 9925 | The archive is then converted using the <filename>oparchconv</filename> script, which is |
| 9926 | included in this distribution. |
| 9927 | The script uses <filename>opimport</filename> to convert the archive from |
| 9928 | the target to something that can be processed on the host. |
| 9929 | </para> |
| 9930 | |
| 9931 | <para> |
| 9932 | Downloaded archives reside in the |
| 9933 | <link linkend='build-directory'>Build Directory</link> in |
| 9934 | <filename>tmp</filename> and are cleared up when they are no longer in use. |
| 9935 | </para> |
| 9936 | |
| 9937 | <para> |
| 9938 | If you wish to perform kernel profiling, you need to be sure |
| 9939 | a <filename>vmlinux</filename> file that matches the running kernel is available. |
| 9940 | In the source directory, that file is usually located in |
| 9941 | <filename>/boot/vmlinux-<replaceable>kernelversion</replaceable></filename>, where |
| 9942 | <filename><replaceable>kernelversion</replaceable></filename> is the version of the kernel. |
| 9943 | The OpenEmbedded build system generates separate <filename>vmlinux</filename> |
| 9944 | packages for each kernel it builds. |
| 9945 | Thus, it should just be a question of making sure a matching package is |
| 9946 | installed (e.g. <filename>opkg install kernel-vmlinux</filename>). |
| 9947 | The files are automatically installed into development and profiling images |
| 9948 | alongside OProfile. |
| 9949 | A configuration option exists within the OProfileUI settings page that you can use to |
| 9950 | enter the location of the <filename>vmlinux</filename> file. |
| 9951 | </para> |
| 9952 | |
| 9953 | <para> |
| 9954 | Waiting for debug symbols to transfer from the device can be slow, and it |
| 9955 | is not always necessary to actually have them on the device for OProfile use. |
| 9956 | All that is needed is a copy of the filesystem with the debug symbols present |
| 9957 | on the viewer system. |
| 9958 | The "<link linkend='platdev-gdb-remotedebug-launch-gdb'>Launch GDB on the Host Computer</link>" |
| 9959 | section covers how to create such a directory within |
| 9960 | the source directory and how to use the OProfileUI Settings |
| 9961 | Dialog to specify the location. |
| 9962 | If you specify the directory, it will be used when the file checksums |
| 9963 | match those on the system you are profiling. |
| 9964 | </para> |
| 9965 | </section> |
| 9966 | |
| 9967 | <section id="platdev-oprofile-oprofileui-offline"> |
| 9968 | <title>Offline Mode</title> |
| 9969 | |
| 9970 | <para> |
| 9971 | If network access to the target is unavailable, you can generate |
| 9972 | an archive for processing in <filename>oprofile-viewer</filename> as follows: |
| 9973 | <literallayout class='monospaced'> |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 9974 | # opcontrol ‐‐reset |
| 9975 | # opcontrol ‐‐start ‐‐separate=lib ‐‐no-vmlinux -c 5 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9976 | . |
| 9977 | . |
| 9978 | [do whatever is being profiled] |
| 9979 | . |
| 9980 | . |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 9981 | # opcontrol ‐‐stop |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9982 | # oparchive -o my_archive |
| 9983 | </literallayout> |
| 9984 | </para> |
| 9985 | |
| 9986 | <para> |
| 9987 | In the above example, <filename>my_archive</filename> is the name of the |
| 9988 | archive directory where you would like the profile archive to be kept. |
| 9989 | After the directory is created, you can copy it to another host and load it |
| 9990 | using <filename>oprofile-viewer</filename> open functionality. |
| 9991 | If necessary, the archive is converted. |
| 9992 | </para> |
| 9993 | </section> |
| 9994 | </section> |
| 9995 | </section> |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 9996 | --> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9997 | |
| 9998 | <section id='maintaining-open-source-license-compliance-during-your-products-lifecycle'> |
| 9999 | <title>Maintaining Open Source License Compliance During Your Product's Lifecycle</title> |
| 10000 | |
| 10001 | <para> |
| 10002 | One of the concerns for a development organization using open source |
| 10003 | software is how to maintain compliance with various open source |
| 10004 | licensing during the lifecycle of the product. |
| 10005 | While this section does not provide legal advice or |
| 10006 | comprehensively cover all scenarios, it does |
| 10007 | present methods that you can use to |
| 10008 | assist you in meeting the compliance requirements during a software |
| 10009 | release. |
| 10010 | </para> |
| 10011 | |
| 10012 | <para> |
| 10013 | With hundreds of different open source licenses that the Yocto |
| 10014 | Project tracks, it is difficult to know the requirements of each |
| 10015 | and every license. |
| 10016 | However, the requirements of the major FLOSS licenses can begin |
| 10017 | to be covered by |
| 10018 | assuming that three main areas of concern exist: |
| 10019 | <itemizedlist> |
| 10020 | <listitem><para>Source code must be provided.</para></listitem> |
| 10021 | <listitem><para>License text for the software must be |
| 10022 | provided.</para></listitem> |
| 10023 | <listitem><para>Compilation scripts and modifications to the |
| 10024 | source code must be provided. |
| 10025 | </para></listitem> |
| 10026 | </itemizedlist> |
| 10027 | There are other requirements beyond the scope of these |
| 10028 | three and the methods described in this section |
| 10029 | (e.g. the mechanism through which source code is distributed). |
| 10030 | </para> |
| 10031 | |
| 10032 | <para> |
| 10033 | As different organizations have different methods of complying with |
| 10034 | open source licensing, this section is not meant to imply that |
| 10035 | there is only one single way to meet your compliance obligations, |
| 10036 | but rather to describe one method of achieving compliance. |
| 10037 | The remainder of this section describes methods supported to meet the |
| 10038 | previously mentioned three requirements. |
| 10039 | Once you take steps to meet these requirements, |
| 10040 | and prior to releasing images, sources, and the build system, |
| 10041 | you should audit all artifacts to ensure completeness. |
| 10042 | <note> |
| 10043 | The Yocto Project generates a license manifest during |
| 10044 | image creation that is located |
| 10045 | in <filename>${DEPLOY_DIR}/licenses/<replaceable>image_name-datestamp</replaceable></filename> |
| 10046 | to assist with any audits. |
| 10047 | </note> |
| 10048 | </para> |
| 10049 | |
| 10050 | <section id='providing-the-source-code'> |
| 10051 | <title>Providing the Source Code</title> |
| 10052 | |
| 10053 | <para> |
| 10054 | Compliance activities should begin before you generate the |
| 10055 | final image. |
| 10056 | The first thing you should look at is the requirement that |
| 10057 | tops the list for most compliance groups - providing |
| 10058 | the source. |
| 10059 | The Yocto Project has a few ways of meeting this |
| 10060 | requirement. |
| 10061 | </para> |
| 10062 | |
| 10063 | <para> |
| 10064 | One of the easiest ways to meet this requirement is |
| 10065 | to provide the entire |
| 10066 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink> |
| 10067 | used by the build. |
| 10068 | This method, however, has a few issues. |
| 10069 | The most obvious is the size of the directory since it includes |
| 10070 | all sources used in the build and not just the source used in |
| 10071 | the released image. |
| 10072 | It will include toolchain source, and other artifacts, which |
| 10073 | you would not generally release. |
| 10074 | However, the more serious issue for most companies is accidental |
| 10075 | release of proprietary software. |
| 10076 | The Yocto Project provides an |
| 10077 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-archiver'><filename>archiver</filename></ulink> |
| 10078 | class to help avoid some of these concerns. |
| 10079 | </para> |
| 10080 | |
| 10081 | <para> |
| 10082 | Before you employ <filename>DL_DIR</filename> or the |
| 10083 | archiver class, you need to decide how you choose to |
| 10084 | provide source. |
| 10085 | The source archiver class can generate tarballs and SRPMs |
| 10086 | and can create them with various levels of compliance in mind. |
| 10087 | </para> |
| 10088 | |
| 10089 | <para> |
| 10090 | One way of doing this (but certainly not the only way) is to |
| 10091 | release just the source as a tarball. |
| 10092 | You can do this by adding the following to the |
| 10093 | <filename>local.conf</filename> file found in the |
| 10094 | <link linkend='build-directory'>Build Directory</link>: |
| 10095 | <literallayout class='monospaced'> |
| 10096 | INHERIT += "archiver" |
| 10097 | ARCHIVER_MODE[src] = "original" |
| 10098 | </literallayout> |
| 10099 | During the creation of your image, the source from all |
| 10100 | recipes that deploy packages to the image is placed within |
| 10101 | subdirectories of |
| 10102 | <filename>DEPLOY_DIR/sources</filename> based on the |
| 10103 | <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink> |
| 10104 | for each recipe. |
| 10105 | Releasing the entire directory enables you to comply with |
| 10106 | requirements concerning providing the unmodified source. |
| 10107 | It is important to note that the size of the directory can |
| 10108 | get large. |
| 10109 | </para> |
| 10110 | |
| 10111 | <para> |
| 10112 | A way to help mitigate the size issue is to only release |
| 10113 | tarballs for licenses that require the release of |
| 10114 | source. |
| 10115 | Let us assume you are only concerned with GPL code as |
| 10116 | identified with the following: |
| 10117 | <literallayout class='monospaced'> |
| 10118 | $ cd poky/build/tmp/deploy/sources |
| 10119 | $ mkdir ~/gpl_source_release |
| 10120 | $ for dir in */*GPL*; do cp -r $dir ~/gpl_source_release; done |
| 10121 | </literallayout> |
| 10122 | At this point, you could create a tarball from the |
| 10123 | <filename>gpl_source_release</filename> directory and |
| 10124 | provide that to the end user. |
| 10125 | This method would be a step toward achieving compliance |
| 10126 | with section 3a of GPLv2 and with section 6 of GPLv3. |
| 10127 | </para> |
| 10128 | </section> |
| 10129 | |
| 10130 | <section id='providing-license-text'> |
| 10131 | <title>Providing License Text</title> |
| 10132 | |
| 10133 | <para> |
| 10134 | One requirement that is often overlooked is inclusion |
| 10135 | of license text. |
| 10136 | This requirement also needs to be dealt with prior to |
| 10137 | generating the final image. |
| 10138 | Some licenses require the license text to accompany |
| 10139 | the binary. |
| 10140 | You can achieve this by adding the following to your |
| 10141 | <filename>local.conf</filename> file: |
| 10142 | <literallayout class='monospaced'> |
| 10143 | COPY_LIC_MANIFEST = "1" |
| 10144 | COPY_LIC_DIRS = "1" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 10145 | LICENSE_CREATE_PACKAGE = "1" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10146 | </literallayout> |
| 10147 | Adding these statements to the configuration file ensures |
| 10148 | that the licenses collected during package generation |
| 10149 | are included on your image. |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 10150 | <note> |
| 10151 | <para>Setting all three variables to "1" results in the |
| 10152 | image having two copies of the same license file. |
| 10153 | One copy resides in |
| 10154 | <filename>/usr/share/common-licenses</filename> and |
| 10155 | the other resides in |
| 10156 | <filename>/usr/share/license</filename>.</para> |
| 10157 | |
| 10158 | <para>The reason for this behavior is because |
| 10159 | <ulink url='&YOCTO_DOCS_REF_URL;#var-COPY_LIC_DIRS'><filename>COPY_LIC_DIRS</filename></ulink> |
| 10160 | and |
| 10161 | <ulink url='&YOCTO_DOCS_REF_URL;#var-COPY_LIC_MANIFEST'><filename>COPY_LIC_MANIFEST</filename></ulink> |
| 10162 | add a copy of the license when the image is built but do not |
| 10163 | offer a path for adding licenses for newly installed packages |
| 10164 | to an image. |
| 10165 | <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE_CREATE_PACKAGE'><filename>LICENSE_CREATE_PACKAGE</filename></ulink> |
| 10166 | adds a separate package and an upgrade path for adding |
| 10167 | licenses to an image.</para> |
| 10168 | </note> |
| 10169 | </para> |
| 10170 | |
| 10171 | <para> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10172 | As the source archiver has already archived the original |
| 10173 | unmodified source that contains the license files, |
| 10174 | you would have already met the requirements for inclusion |
| 10175 | of the license information with source as defined by the GPL |
| 10176 | and other open source licenses. |
| 10177 | </para> |
| 10178 | </section> |
| 10179 | |
| 10180 | <section id='providing-compilation-scripts-and-source-code-modifications'> |
| 10181 | <title>Providing Compilation Scripts and Source Code Modifications</title> |
| 10182 | |
| 10183 | <para> |
| 10184 | At this point, we have addressed all we need to address |
| 10185 | prior to generating the image. |
| 10186 | The next two requirements are addressed during the final |
| 10187 | packaging of the release. |
| 10188 | </para> |
| 10189 | |
| 10190 | <para> |
| 10191 | By releasing the version of the OpenEmbedded build system |
| 10192 | and the layers used during the build, you will be providing both |
| 10193 | compilation scripts and the source code modifications in one |
| 10194 | step. |
| 10195 | </para> |
| 10196 | |
| 10197 | <para> |
| 10198 | If the deployment team has a |
| 10199 | <ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP layer</ulink> |
| 10200 | and a distro layer, and those those layers are used to patch, |
| 10201 | compile, package, or modify (in any way) any open source |
| 10202 | software included in your released images, you |
| 10203 | might be required to to release those layers under section 3 of |
| 10204 | GPLv2 or section 1 of GPLv3. |
| 10205 | One way of doing that is with a clean |
| 10206 | checkout of the version of the Yocto Project and layers used |
| 10207 | during your build. |
| 10208 | Here is an example: |
| 10209 | <literallayout class='monospaced'> |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 10210 | # We built using the &DISTRO_NAME_NO_CAP; branch of the poky repo |
| 10211 | $ git clone -b &DISTRO_NAME_NO_CAP; git://git.yoctoproject.org/poky |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10212 | $ cd poky |
| 10213 | # We built using the release_branch for our layers |
| 10214 | $ git clone -b release_branch git://git.mycompany.com/meta-my-bsp-layer |
| 10215 | $ git clone -b release_branch git://git.mycompany.com/meta-my-software-layer |
| 10216 | # clean up the .git repos |
| 10217 | $ find . -name ".git" -type d -exec rm -rf {} \; |
| 10218 | </literallayout> |
| 10219 | One thing a development organization might want to consider |
| 10220 | for end-user convenience is to modify |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 10221 | <filename>meta-poky/conf/bblayers.conf.sample</filename> to |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10222 | ensure that when the end user utilizes the released build |
| 10223 | system to build an image, the development organization's |
| 10224 | layers are included in the <filename>bblayers.conf</filename> |
| 10225 | file automatically: |
| 10226 | <literallayout class='monospaced'> |
| 10227 | # LAYER_CONF_VERSION is increased each time build/conf/bblayers.conf |
| 10228 | # changes incompatibly |
| 10229 | LCONF_VERSION = "6" |
| 10230 | |
| 10231 | BBPATH = "${TOPDIR}" |
| 10232 | BBFILES ?= "" |
| 10233 | |
| 10234 | BBLAYERS ?= " \ |
| 10235 | ##OEROOT##/meta \ |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 10236 | ##OEROOT##/meta-poky \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10237 | ##OEROOT##/meta-yocto-bsp \ |
| 10238 | ##OEROOT##/meta-mylayer \ |
| 10239 | " |
| 10240 | </literallayout> |
| 10241 | Creating and providing an archive of the |
| 10242 | <link linkend='metadata'>Metadata</link> layers |
| 10243 | (recipes, configuration files, and so forth) |
| 10244 | enables you to meet your |
| 10245 | requirements to include the scripts to control compilation |
| 10246 | as well as any modifications to the original source. |
| 10247 | </para> |
| 10248 | </section> |
| 10249 | </section> |
| 10250 | |
| 10251 | <section id='using-the-error-reporting-tool'> |
| 10252 | <title>Using the Error Reporting Tool</title> |
| 10253 | |
| 10254 | <para> |
| 10255 | The error reporting tool allows you to |
| 10256 | submit errors encountered during builds to a central database. |
| 10257 | Outside of the build environment, you can use a web interface to |
| 10258 | browse errors, view statistics, and query for errors. |
| 10259 | The tool works using a client-server system where the client |
| 10260 | portion is integrated with the installed Yocto Project |
| 10261 | <link linkend='source-directory'>Source Directory</link> |
| 10262 | (e.g. <filename>poky</filename>). |
| 10263 | The server receives the information collected and saves it in a |
| 10264 | database. |
| 10265 | </para> |
| 10266 | |
| 10267 | <para> |
| 10268 | A live instance of the error reporting server exists at |
| 10269 | <ulink url='http://errors.yoctoproject.org'></ulink>. |
| 10270 | This server exists so that when you want to get help with |
| 10271 | build failures, you can submit all of the information on the |
| 10272 | failure easily and then point to the URL in your bug report |
| 10273 | or send an email to the mailing list. |
| 10274 | <note> |
| 10275 | If you send error reports to this server, the reports become |
| 10276 | publicly visible. |
| 10277 | </note> |
| 10278 | </para> |
| 10279 | |
| 10280 | <section id='enabling-and-using-the-tool'> |
| 10281 | <title>Enabling and Using the Tool</title> |
| 10282 | |
| 10283 | <para> |
| 10284 | By default, the error reporting tool is disabled. |
| 10285 | You can enable it by inheriting the |
| 10286 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-report-error'><filename>report-error</filename></ulink> |
| 10287 | class by adding the following statement to the end of |
| 10288 | your <filename>local.conf</filename> file in your |
| 10289 | <link linkend='build-directory'>Build Directory</link>. |
| 10290 | <literallayout class='monospaced'> |
| 10291 | INHERIT += "report-error" |
| 10292 | </literallayout> |
| 10293 | </para> |
| 10294 | |
| 10295 | <para> |
| 10296 | By default, the error reporting feature stores information in |
| 10297 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LOG_DIR'><filename>LOG_DIR</filename></ulink><filename>}/error-report</filename>. |
| 10298 | However, you can specify a directory to use by adding the following |
| 10299 | to your <filename>local.conf</filename> file: |
| 10300 | <literallayout class='monospaced'> |
| 10301 | ERR_REPORT_DIR = "path" |
| 10302 | </literallayout> |
| 10303 | Enabling error reporting causes the build process to collect |
| 10304 | the errors and store them in a file as previously described. |
| 10305 | When the build system encounters an error, it includes a |
| 10306 | command as part of the console output. |
| 10307 | You can run the command to send the error file to the server. |
| 10308 | For example, the following command sends the errors to an |
| 10309 | upstream server: |
| 10310 | <literallayout class='monospaced'> |
| 10311 | $ send-error-report /home/brandusa/project/poky/build/tmp/log/error-report/error_report_201403141617.txt |
| 10312 | </literallayout> |
| 10313 | In the previous example, the errors are sent to a public |
| 10314 | database available at |
| 10315 | <ulink url='http://errors.yoctoproject.org'></ulink>, which is |
| 10316 | used by the entire community. |
| 10317 | If you specify a particular server, you can send the errors |
| 10318 | to a different database. |
| 10319 | Use the following command for more information on available |
| 10320 | options: |
| 10321 | <literallayout class='monospaced'> |
| 10322 | $ send-error-report --help |
| 10323 | </literallayout> |
| 10324 | </para> |
| 10325 | |
| 10326 | <para> |
| 10327 | When sending the error file, you are prompted to review the |
| 10328 | data being sent as well as to provide a name and optional |
| 10329 | email address. |
| 10330 | Once you satisfy these prompts, the command returns a link |
| 10331 | from the server that corresponds to your entry in the database. |
| 10332 | For example, here is a typical link: |
| 10333 | <literallayout class='monospaced'> |
| 10334 | http://errors.yoctoproject.org/Errors/Details/9522/ |
| 10335 | </literallayout> |
| 10336 | Following the link takes you to a web interface where you can |
| 10337 | browse, query the errors, and view statistics. |
| 10338 | </para> |
| 10339 | </section> |
| 10340 | |
| 10341 | <section id='disabling-the-tool'> |
| 10342 | <title>Disabling the Tool</title> |
| 10343 | |
| 10344 | <para> |
| 10345 | To disable the error reporting feature, simply remove or comment |
| 10346 | out the following statement from the end of your |
| 10347 | <filename>local.conf</filename> file in your |
| 10348 | <link linkend='build-directory'>Build Directory</link>. |
| 10349 | <literallayout class='monospaced'> |
| 10350 | INHERIT += "report-error" |
| 10351 | </literallayout> |
| 10352 | </para> |
| 10353 | </section> |
| 10354 | |
| 10355 | <section id='setting-up-your-own-error-reporting-server'> |
| 10356 | <title>Setting Up Your Own Error Reporting Server</title> |
| 10357 | |
| 10358 | <para> |
| 10359 | If you want to set up your own error reporting server, you |
| 10360 | can obtain the code from the Git repository at |
| 10361 | <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/error-report-web/'></ulink>. |
| 10362 | Instructions on how to set it up are in the README document. |
| 10363 | </para> |
| 10364 | </section> |
| 10365 | </section> |
| 10366 | </chapter> |
| 10367 | |
| 10368 | <!-- |
| 10369 | vim: expandtab tw=80 ts=4 |
| 10370 | --> |