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>, |
| 75 | <filename>meta-yocto</filename>, and |
| 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 |
| 168 | <filename>meta-yocto</filename>, can choose |
| 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 |
| 173 | the <filename>meta-yocto</filename> layer. |
| 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> |
| 339 | As an actual example, here's a line from the recipe for |
| 340 | the OProfile profiler, which lists an extra build-time |
| 341 | dependency when building specifically for 64-bit PowerPC: |
| 342 | <literallayout class='monospaced'> |
| 343 | DEPENDS_append_powerpc64 = " libpfm4" |
| 344 | </literallayout> |
| 345 | <note> |
| 346 | Avoiding "+=" and "=+" and using |
| 347 | machine-specific |
| 348 | <filename>_append</filename> |
| 349 | and <filename>_prepend</filename> operations |
| 350 | is recommended as well. |
| 351 | </note></para></listitem> |
| 352 | <listitem><para><emphasis>Place Machine-Specific Files |
| 353 | in Machine-Specific Locations:</emphasis> |
| 354 | When you have a base recipe, such as |
| 355 | <filename>base-files.bb</filename>, that |
| 356 | contains a |
| 357 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> |
| 358 | statement to a file, you can use an append file |
| 359 | to cause the build to use your own version of |
| 360 | the file. |
| 361 | For example, an append file in your layer at |
| 362 | <filename>meta-one/recipes-core/base-files/base-files.bbappend</filename> |
| 363 | could extend |
| 364 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink> |
| 365 | using |
| 366 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink> |
| 367 | as follows: |
| 368 | <literallayout class='monospaced'> |
| 369 | FILESEXTRAPATHS_prepend := "${THISDIR}/${BPN}:" |
| 370 | </literallayout> |
| 371 | The build for machine "one" will pick up your |
| 372 | machine-specific file as long as you have the |
| 373 | file in |
| 374 | <filename>meta-one/recipes-core/base-files/base-files/</filename>. |
| 375 | However, if you are building for a different |
| 376 | machine and the |
| 377 | <filename>bblayers.conf</filename> file includes |
| 378 | the <filename>meta-one</filename> layer and |
| 379 | the location of your machine-specific file is |
| 380 | the first location where that file is found |
| 381 | according to <filename>FILESPATH</filename>, |
| 382 | builds for all machines will also use that |
| 383 | machine-specific file.</para> |
| 384 | <para>You can make sure that a machine-specific |
| 385 | file is used for a particular machine by putting |
| 386 | the file in a subdirectory specific to the |
| 387 | machine. |
| 388 | For example, rather than placing the file in |
| 389 | <filename>meta-one/recipes-core/base-files/base-files/</filename> |
| 390 | as shown above, put it in |
| 391 | <filename>meta-one/recipes-core/base-files/base-files/one/</filename>. |
| 392 | Not only does this make sure the file is used |
| 393 | only when building for machine "one", but the |
| 394 | build process locates the file more quickly.</para> |
| 395 | <para>In summary, you need to place all files |
| 396 | referenced from <filename>SRC_URI</filename> |
| 397 | in a machine-specific subdirectory within the |
| 398 | layer in order to restrict those files to |
| 399 | machine-specific builds.</para></listitem> |
| 400 | </itemizedlist> |
| 401 | </para> |
| 402 | </section> |
| 403 | |
| 404 | <section id='other-recommendations'> |
| 405 | <title>Other Recommendations</title> |
| 406 | |
| 407 | <para> |
| 408 | We also recommend the following: |
| 409 | <itemizedlist> |
| 410 | <listitem><para>Store custom layers in a Git repository |
| 411 | that uses the |
| 412 | <filename>meta-<replaceable>layer_name</replaceable></filename> format. |
| 413 | </para></listitem> |
| 414 | <listitem><para>Clone the repository alongside other |
| 415 | <filename>meta</filename> directories in the |
| 416 | <link linkend='source-directory'>Source Directory</link>. |
| 417 | </para></listitem> |
| 418 | </itemizedlist> |
| 419 | Following these recommendations keeps your Source Directory and |
| 420 | its configuration entirely inside the Yocto Project's core |
| 421 | base. |
| 422 | </para> |
| 423 | </section> |
| 424 | </section> |
| 425 | |
| 426 | <section id='enabling-your-layer'> |
| 427 | <title>Enabling Your Layer</title> |
| 428 | |
| 429 | <para> |
| 430 | Before the OpenEmbedded build system can use your new layer, |
| 431 | you need to enable it. |
| 432 | To enable your layer, simply add your layer's path to the |
| 433 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'>BBLAYERS</ulink></filename> |
| 434 | variable in your <filename>conf/bblayers.conf</filename> file, |
| 435 | which is found in the |
| 436 | <link linkend='build-directory'>Build Directory</link>. |
| 437 | The following example shows how to enable a layer named |
| 438 | <filename>meta-mylayer</filename>: |
| 439 | <literallayout class='monospaced'> |
| 440 | LCONF_VERSION = "6" |
| 441 | |
| 442 | BBPATH = "${TOPDIR}" |
| 443 | BBFILES ?= "" |
| 444 | |
| 445 | BBLAYERS ?= " \ |
| 446 | $HOME/poky/meta \ |
| 447 | $HOME/poky/meta-yocto \ |
| 448 | $HOME/poky/meta-yocto-bsp \ |
| 449 | $HOME/poky/meta-mylayer \ |
| 450 | " |
| 451 | </literallayout> |
| 452 | </para> |
| 453 | |
| 454 | <para> |
| 455 | BitBake parses each <filename>conf/layer.conf</filename> file |
| 456 | as specified in the <filename>BBLAYERS</filename> variable |
| 457 | within the <filename>conf/bblayers.conf</filename> file. |
| 458 | During the processing of each |
| 459 | <filename>conf/layer.conf</filename> file, BitBake adds the |
| 460 | recipes, classes and configurations contained within the |
| 461 | particular layer to the source directory. |
| 462 | </para> |
| 463 | </section> |
| 464 | |
| 465 | <section id='using-bbappend-files'> |
| 466 | <title>Using .bbappend Files</title> |
| 467 | |
| 468 | <para> |
| 469 | Recipes used to append Metadata to other recipes are called |
| 470 | BitBake append files. |
| 471 | BitBake append files use the <filename>.bbappend</filename> file |
| 472 | type suffix, while the corresponding recipes to which Metadata |
| 473 | is being appended use the <filename>.bb</filename> file type |
| 474 | suffix. |
| 475 | </para> |
| 476 | |
| 477 | <para> |
| 478 | A <filename>.bbappend</filename> file allows your layer to make |
| 479 | additions or changes to the content of another layer's recipe |
| 480 | without having to copy the other recipe into your layer. |
| 481 | Your <filename>.bbappend</filename> file resides in your layer, |
| 482 | while the main <filename>.bb</filename> recipe file to |
| 483 | which you are appending Metadata resides in a different layer. |
| 484 | </para> |
| 485 | |
| 486 | <para> |
| 487 | Append files must have the same root names as their corresponding |
| 488 | recipes. |
| 489 | For example, the append file |
| 490 | <filename>someapp_&DISTRO;.bbappend</filename> must apply to |
| 491 | <filename>someapp_&DISTRO;.bb</filename>. |
| 492 | This means the original recipe and append file names are version |
| 493 | number-specific. |
| 494 | If the corresponding recipe is renamed to update to a newer |
| 495 | version, the corresponding <filename>.bbappend</filename> file must |
| 496 | be renamed (and possibly updated) as well. |
| 497 | During the build process, BitBake displays an error on starting |
| 498 | if it detects a <filename>.bbappend</filename> file that does |
| 499 | not have a corresponding recipe with a matching name. |
| 500 | See the |
| 501 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_DANGLINGAPPENDS_WARNONLY'><filename>BB_DANGLINGAPPENDS_WARNONLY</filename></ulink> |
| 502 | variable for information on how to handle this error. |
| 503 | </para> |
| 504 | |
| 505 | <para> |
| 506 | Being able to append information to an existing recipe not only |
| 507 | avoids duplication, but also automatically applies recipe |
| 508 | changes in a different layer to your layer. |
| 509 | If you were copying recipes, you would have to manually merge |
| 510 | changes as they occur. |
| 511 | </para> |
| 512 | |
| 513 | <para> |
| 514 | As an example, consider the main formfactor recipe and a |
| 515 | corresponding formfactor append file both from the |
| 516 | <link linkend='source-directory'>Source Directory</link>. |
| 517 | Here is the main formfactor recipe, which is named |
| 518 | <filename>formfactor_0.0.bb</filename> and located in the |
| 519 | "meta" layer at |
| 520 | <filename>meta/recipes-bsp/formfactor</filename>: |
| 521 | <literallayout class='monospaced'> |
| 522 | SUMMARY = "Device formfactor information" |
| 523 | SECTION = "base" |
| 524 | LICENSE = "MIT" |
| 525 | LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=4d92cd373abda3937c2bc47fbc49d690 \ |
| 526 | file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" |
| 527 | PR = "r45" |
| 528 | |
| 529 | SRC_URI = "file://config file://machconfig" |
| 530 | S = "${WORKDIR}" |
| 531 | |
| 532 | PACKAGE_ARCH = "${MACHINE_ARCH}" |
| 533 | INHIBIT_DEFAULT_DEPS = "1" |
| 534 | |
| 535 | do_install() { |
| 536 | # Install file only if it has contents |
| 537 | install -d ${D}${sysconfdir}/formfactor/ |
| 538 | install -m 0644 ${S}/config ${D}${sysconfdir}/formfactor/ |
| 539 | if [ -s "${S}/machconfig" ]; then |
| 540 | install -m 0644 ${S}/machconfig ${D}${sysconfdir}/formfactor/ |
| 541 | fi |
| 542 | } |
| 543 | </literallayout> |
| 544 | In the main recipe, note the |
| 545 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> |
| 546 | variable, which tells the OpenEmbedded build system where to |
| 547 | find files during the build. |
| 548 | </para> |
| 549 | |
| 550 | <para> |
| 551 | Following is the append file, which is named |
| 552 | <filename>formfactor_0.0.bbappend</filename> and is from the |
| 553 | Emenlow BSP Layer named |
| 554 | <filename>meta-intel/meta-emenlow</filename>. |
| 555 | The file is in <filename>recipes-bsp/formfactor</filename>: |
| 556 | <literallayout class='monospaced'> |
| 557 | FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" |
| 558 | </literallayout> |
| 559 | </para> |
| 560 | |
| 561 | <para> |
| 562 | By default, the build system uses the |
| 563 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink> |
| 564 | variable to locate files. |
| 565 | This append file extends the locations by setting the |
| 566 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink> |
| 567 | variable. |
| 568 | Setting this variable in the <filename>.bbappend</filename> |
| 569 | file is the most reliable and recommended method for adding |
| 570 | directories to the search path used by the build system |
| 571 | to find files. |
| 572 | </para> |
| 573 | |
| 574 | <para> |
| 575 | The statement in this example extends the directories to include |
| 576 | <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>, |
| 577 | which resolves to a directory named |
| 578 | <filename>formfactor</filename> in the same directory |
| 579 | in which the append file resides (i.e. |
| 580 | <filename>meta-intel/meta-emenlow/recipes-bsp/formfactor/formfactor</filename>. |
| 581 | This implies that you must have the supporting directory |
| 582 | structure set up that will contain any files or patches you |
| 583 | will be including from the layer. |
| 584 | </para> |
| 585 | |
| 586 | <para> |
| 587 | Using the immediate expansion assignment operator |
| 588 | <filename>:=</filename> is important because of the reference to |
| 589 | <filename>THISDIR</filename>. |
| 590 | The trailing colon character is important as it ensures that |
| 591 | items in the list remain colon-separated. |
| 592 | <note> |
| 593 | <para> |
| 594 | BitBake automatically defines the |
| 595 | <filename>THISDIR</filename> variable. |
| 596 | You should never set this variable yourself. |
| 597 | Using "_prepend" as part of the |
| 598 | <filename>FILESEXTRAPATHS</filename> ensures your path |
| 599 | will be searched prior to other paths in the final |
| 600 | list. |
| 601 | </para> |
| 602 | |
| 603 | <para> |
| 604 | Also, not all append files add extra files. |
| 605 | Many append files simply exist to add build options |
| 606 | (e.g. <filename>systemd</filename>). |
| 607 | For these cases, your append file would not even |
| 608 | use the <filename>FILESEXTRAPATHS</filename> statement. |
| 609 | </para> |
| 610 | </note> |
| 611 | </para> |
| 612 | </section> |
| 613 | |
| 614 | <section id='prioritizing-your-layer'> |
| 615 | <title>Prioritizing Your Layer</title> |
| 616 | |
| 617 | <para> |
| 618 | Each layer is assigned a priority value. |
| 619 | Priority values control which layer takes precedence if there |
| 620 | are recipe files with the same name in multiple layers. |
| 621 | For these cases, the recipe file from the layer with a higher |
| 622 | priority number takes precedence. |
| 623 | Priority values also affect the order in which multiple |
| 624 | <filename>.bbappend</filename> files for the same recipe are |
| 625 | applied. |
| 626 | You can either specify the priority manually, or allow the |
| 627 | build system to calculate it based on the layer's dependencies. |
| 628 | </para> |
| 629 | |
| 630 | <para> |
| 631 | To specify the layer's priority manually, use the |
| 632 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PRIORITY'><filename>BBFILE_PRIORITY</filename></ulink> |
| 633 | variable. |
| 634 | For example: |
| 635 | <literallayout class='monospaced'> |
| 636 | BBFILE_PRIORITY_mylayer = "1" |
| 637 | </literallayout> |
| 638 | </para> |
| 639 | |
| 640 | <note> |
| 641 | <para>It is possible for a recipe with a lower version number |
| 642 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink> |
| 643 | in a layer that has a higher priority to take precedence.</para> |
| 644 | <para>Also, the layer priority does not currently affect the |
| 645 | precedence order of <filename>.conf</filename> |
| 646 | or <filename>.bbclass</filename> files. |
| 647 | Future versions of BitBake might address this.</para> |
| 648 | </note> |
| 649 | </section> |
| 650 | |
| 651 | <section id='managing-layers'> |
| 652 | <title>Managing Layers</title> |
| 653 | |
| 654 | <para> |
| 655 | You can use the BitBake layer management tool to provide a view |
| 656 | into the structure of recipes across a multi-layer project. |
| 657 | Being able to generate output that reports on configured layers |
| 658 | with their paths and priorities and on |
| 659 | <filename>.bbappend</filename> files and their applicable |
| 660 | recipes can help to reveal potential problems. |
| 661 | </para> |
| 662 | |
| 663 | <para> |
| 664 | Use the following form when running the layer management tool. |
| 665 | <literallayout class='monospaced'> |
| 666 | $ bitbake-layers <replaceable>command</replaceable> [<replaceable>arguments</replaceable>] |
| 667 | </literallayout> |
| 668 | The following list describes the available commands: |
| 669 | <itemizedlist> |
| 670 | <listitem><para><filename><emphasis>help:</emphasis></filename> |
| 671 | Displays general help or help on a specified command. |
| 672 | </para></listitem> |
| 673 | <listitem><para><filename><emphasis>show-layers:</emphasis></filename> |
| 674 | Shows the current configured layers. |
| 675 | </para></listitem> |
| 676 | <listitem><para><filename><emphasis>show-recipes:</emphasis></filename> |
| 677 | Lists available recipes and the layers that provide them. |
| 678 | </para></listitem> |
| 679 | <listitem><para><filename><emphasis>show-overlayed:</emphasis></filename> |
| 680 | Lists overlayed recipes. |
| 681 | A recipe is overlayed when a recipe with the same name |
| 682 | exists in another layer that has a higher layer |
| 683 | priority. |
| 684 | </para></listitem> |
| 685 | <listitem><para><filename><emphasis>show-appends:</emphasis></filename> |
| 686 | Lists <filename>.bbappend</filename> files and the |
| 687 | recipe files to which they apply. |
| 688 | </para></listitem> |
| 689 | <listitem><para><filename><emphasis>show-cross-depends:</emphasis></filename> |
| 690 | Lists dependency relationships between recipes that |
| 691 | cross layer boundaries. |
| 692 | </para></listitem> |
| 693 | <listitem><para><filename><emphasis>add-layer:</emphasis></filename> |
| 694 | Adds a layer to <filename>bblayers.conf</filename>. |
| 695 | </para></listitem> |
| 696 | <listitem><para><filename><emphasis>remove-layer:</emphasis></filename> |
| 697 | Removes a layer from <filename>bblayers.conf</filename> |
| 698 | </para></listitem> |
| 699 | <listitem><para><filename><emphasis>flatten:</emphasis></filename> |
| 700 | Flattens the layer configuration into a separate output |
| 701 | directory. |
| 702 | Flattening your layer configuration builds a "flattened" |
| 703 | directory that contains the contents of all layers, |
| 704 | with any overlayed recipes removed and any |
| 705 | <filename>.bbappend</filename> files appended to the |
| 706 | corresponding recipes. |
| 707 | You might have to perform some manual cleanup of the |
| 708 | flattened layer as follows: |
| 709 | <itemizedlist> |
| 710 | <listitem><para>Non-recipe files (such as patches) |
| 711 | are overwritten. |
| 712 | The flatten command shows a warning for these |
| 713 | files. |
| 714 | </para></listitem> |
| 715 | <listitem><para>Anything beyond the normal layer |
| 716 | setup has been added to the |
| 717 | <filename>layer.conf</filename> file. |
| 718 | Only the lowest priority layer's |
| 719 | <filename>layer.conf</filename> is used. |
| 720 | </para></listitem> |
| 721 | <listitem><para>Overridden and appended items from |
| 722 | <filename>.bbappend</filename> files need to be |
| 723 | cleaned up. |
| 724 | The contents of each |
| 725 | <filename>.bbappend</filename> end up in the |
| 726 | flattened recipe. |
| 727 | However, if there are appended or changed |
| 728 | variable values, you need to tidy these up |
| 729 | yourself. |
| 730 | Consider the following example. |
| 731 | Here, the <filename>bitbake-layers</filename> |
| 732 | command adds the line |
| 733 | <filename>#### bbappended ...</filename> so that |
| 734 | you know where the following lines originate: |
| 735 | <literallayout class='monospaced'> |
| 736 | ... |
| 737 | DESCRIPTION = "A useful utility" |
| 738 | ... |
| 739 | EXTRA_OECONF = "--enable-something" |
| 740 | ... |
| 741 | |
| 742 | #### bbappended from meta-anotherlayer #### |
| 743 | |
| 744 | DESCRIPTION = "Customized utility" |
| 745 | EXTRA_OECONF += "--enable-somethingelse" |
| 746 | </literallayout> |
| 747 | Ideally, you would tidy up these utilities as |
| 748 | follows: |
| 749 | <literallayout class='monospaced'> |
| 750 | ... |
| 751 | DESCRIPTION = "Customized utility" |
| 752 | ... |
| 753 | EXTRA_OECONF = "--enable-something --enable-somethingelse" |
| 754 | ... |
| 755 | </literallayout></para></listitem> |
| 756 | </itemizedlist></para></listitem> |
| 757 | </itemizedlist> |
| 758 | </para> |
| 759 | </section> |
| 760 | |
| 761 | <section id='creating-a-general-layer-using-the-yocto-layer-script'> |
| 762 | <title>Creating a General Layer Using the yocto-layer Script</title> |
| 763 | |
| 764 | <para> |
| 765 | The <filename>yocto-layer</filename> script simplifies |
| 766 | creating a new general layer. |
| 767 | <note> |
| 768 | For information on BSP layers, see the |
| 769 | "<ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP Layers</ulink>" |
| 770 | section in the Yocto Project Board Specific (BSP) |
| 771 | Developer's Guide. |
| 772 | </note> |
| 773 | The default mode of the script's operation is to prompt you for |
| 774 | information needed to generate the layer: |
| 775 | <itemizedlist> |
| 776 | <listitem><para>The layer priority. |
| 777 | </para></listitem> |
| 778 | <listitem><para>Whether or not to create a sample recipe. |
| 779 | </para></listitem> |
| 780 | <listitem><para>Whether or not to create a sample |
| 781 | append file. |
| 782 | </para></listitem> |
| 783 | </itemizedlist> |
| 784 | </para> |
| 785 | |
| 786 | <para> |
| 787 | Use the <filename>yocto-layer create</filename> sub-command |
| 788 | to create a new general layer. |
| 789 | In its simplest form, you can create a layer as follows: |
| 790 | <literallayout class='monospaced'> |
| 791 | $ yocto-layer create mylayer |
| 792 | </literallayout> |
| 793 | The previous example creates a layer named |
| 794 | <filename>meta-mylayer</filename> in the current directory. |
| 795 | </para> |
| 796 | |
| 797 | <para> |
| 798 | As the <filename>yocto-layer create</filename> command runs, |
| 799 | default values for the prompts appear in brackets. |
| 800 | Pressing enter without supplying anything for the prompts |
| 801 | or pressing enter and providing an invalid response causes the |
| 802 | script to accept the default value. |
| 803 | Once the script completes, the new layer |
| 804 | is created in the current working directory. |
| 805 | The script names the layer by prepending |
| 806 | <filename>meta-</filename> to the name you provide. |
| 807 | </para> |
| 808 | |
| 809 | <para> |
| 810 | Minimally, the script creates the following within the layer: |
| 811 | <itemizedlist> |
| 812 | <listitem><para><emphasis>The <filename>conf</filename> |
| 813 | directory:</emphasis> |
| 814 | This directory contains the layer's configuration file. |
| 815 | The root name for the file is the same as the root name |
| 816 | your provided for the layer (e.g. |
| 817 | <filename><replaceable>layer</replaceable>.conf</filename>). |
| 818 | </para></listitem> |
| 819 | <listitem><para><emphasis>The |
| 820 | <filename>COPYING.MIT</filename> file:</emphasis> |
| 821 | The copyright and use notice for the software. |
| 822 | </para></listitem> |
| 823 | <listitem><para><emphasis>The <filename>README</filename> |
| 824 | file:</emphasis> |
| 825 | A file describing the contents of your new layer. |
| 826 | </para></listitem> |
| 827 | </itemizedlist> |
| 828 | </para> |
| 829 | |
| 830 | <para> |
| 831 | If you choose to generate a sample recipe file, the script |
| 832 | prompts you for the name for the recipe and then creates it |
| 833 | in <filename><replaceable>layer</replaceable>/recipes-example/example/</filename>. |
| 834 | The script creates a <filename>.bb</filename> file and a |
| 835 | directory, which contains a sample |
| 836 | <filename>helloworld.c</filename> source file, along with |
| 837 | a sample patch file. |
| 838 | If you do not provide a recipe name, the script uses |
| 839 | "example". |
| 840 | </para> |
| 841 | |
| 842 | <para> |
| 843 | If you choose to generate a sample append file, the script |
| 844 | prompts you for the name for the file and then creates it |
| 845 | in <filename><replaceable>layer</replaceable>/recipes-example-bbappend/example-bbappend/</filename>. |
| 846 | The script creates a <filename>.bbappend</filename> file and a |
| 847 | directory, which contains a sample patch file. |
| 848 | If you do not provide a recipe name, the script uses |
| 849 | "example". |
| 850 | The script also prompts you for the version of the append file. |
| 851 | The version should match the recipe to which the append file |
| 852 | is associated. |
| 853 | </para> |
| 854 | |
| 855 | <para> |
| 856 | The easiest way to see how the <filename>yocto-layer</filename> |
| 857 | script works is to experiment with the script. |
| 858 | You can also read the usage information by entering the |
| 859 | following: |
| 860 | <literallayout class='monospaced'> |
| 861 | $ yocto-layer help |
| 862 | </literallayout> |
| 863 | </para> |
| 864 | |
| 865 | <para> |
| 866 | Once you create your general layer, you must add it to your |
| 867 | <filename>bblayers.conf</filename> file. |
| 868 | Here is an example where a layer named |
| 869 | <filename>meta-mylayer</filename> is added: |
| 870 | <literallayout class='monospaced'> |
| 871 | BBLAYERS = ?" \ |
| 872 | /usr/local/src/yocto/meta \ |
| 873 | /usr/local/src/yocto/meta-yocto \ |
| 874 | /usr/local/src/yocto/meta-yocto-bsp \ |
| 875 | /usr/local/src/yocto/meta-mylayer \ |
| 876 | " |
| 877 | </literallayout> |
| 878 | Adding the layer to this file enables the build system to |
| 879 | locate the layer during the build. |
| 880 | </para> |
| 881 | </section> |
| 882 | </section> |
| 883 | |
| 884 | <section id='usingpoky-extend-customimage'> |
| 885 | <title>Customizing Images</title> |
| 886 | |
| 887 | <para> |
| 888 | You can customize images to satisfy particular requirements. |
| 889 | This section describes several methods and provides guidelines for each. |
| 890 | </para> |
| 891 | |
| 892 | <section id='usingpoky-extend-customimage-localconf'> |
| 893 | <title>Customizing Images Using <filename>local.conf</filename></title> |
| 894 | |
| 895 | <para> |
| 896 | Probably the easiest way to customize an image is to add a |
| 897 | package by way of the <filename>local.conf</filename> |
| 898 | configuration file. |
| 899 | Because it is limited to local use, this method generally only |
| 900 | allows you to add packages and is not as flexible as creating |
| 901 | your own customized image. |
| 902 | When you add packages using local variables this way, you need |
| 903 | to realize that these variable changes are in effect for every |
| 904 | build and consequently affect all images, which might not |
| 905 | be what you require. |
| 906 | </para> |
| 907 | |
| 908 | <para> |
| 909 | To add a package to your image using the local configuration |
| 910 | file, use the |
| 911 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename> |
| 912 | variable with the <filename>_append</filename> operator: |
| 913 | <literallayout class='monospaced'> |
| 914 | IMAGE_INSTALL_append = " strace" |
| 915 | </literallayout> |
| 916 | Use of the syntax is important - specifically, the space between |
| 917 | the quote and the package name, which is |
| 918 | <filename>strace</filename> in this example. |
| 919 | This space is required since the <filename>_append</filename> |
| 920 | operator does not add the space. |
| 921 | </para> |
| 922 | |
| 923 | <para> |
| 924 | Furthermore, you must use <filename>_append</filename> instead |
| 925 | of the <filename>+=</filename> operator if you want to avoid |
| 926 | ordering issues. |
| 927 | The reason for this is because doing so unconditionally appends |
| 928 | to the variable and avoids ordering problems due to the |
| 929 | variable being set in image recipes and |
| 930 | <filename>.bbclass</filename> files with operators like |
| 931 | <filename>?=</filename>. |
| 932 | Using <filename>_append</filename> ensures the operation takes |
| 933 | affect. |
| 934 | </para> |
| 935 | |
| 936 | <para> |
| 937 | As shown in its simplest use, |
| 938 | <filename>IMAGE_INSTALL_append</filename> affects all images. |
| 939 | It is possible to extend the syntax so that the variable |
| 940 | applies to a specific image only. |
| 941 | Here is an example: |
| 942 | <literallayout class='monospaced'> |
| 943 | IMAGE_INSTALL_append_pn-core-image-minimal = " strace" |
| 944 | </literallayout> |
| 945 | This example adds <filename>strace</filename> to the |
| 946 | <filename>core-image-minimal</filename> image only. |
| 947 | </para> |
| 948 | |
| 949 | <para> |
| 950 | You can add packages using a similar approach through the |
| 951 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-CORE_IMAGE_EXTRA_INSTALL'>CORE_IMAGE_EXTRA_INSTALL</ulink></filename> |
| 952 | variable. |
| 953 | If you use this variable, only |
| 954 | <filename>core-image-*</filename> images are affected. |
| 955 | </para> |
| 956 | </section> |
| 957 | |
| 958 | <section id='usingpoky-extend-customimage-imagefeatures'> |
| 959 | <title>Customizing Images Using Custom <filename>IMAGE_FEATURES</filename> and |
| 960 | <filename>EXTRA_IMAGE_FEATURES</filename></title> |
| 961 | |
| 962 | <para> |
| 963 | Another method for customizing your image is to enable or |
| 964 | disable high-level image features by using the |
| 965 | <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink> |
| 966 | and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink> |
| 967 | variables. |
| 968 | Although the functions for both variables are nearly equivalent, |
| 969 | best practices dictate using <filename>IMAGE_FEATURES</filename> |
| 970 | from within a recipe and using |
| 971 | <filename>EXTRA_IMAGE_FEATURES</filename> from within |
| 972 | your <filename>local.conf</filename> file, which is found in the |
| 973 | <link linkend='build-directory'>Build Directory</link>. |
| 974 | </para> |
| 975 | |
| 976 | <para> |
| 977 | To understand how these features work, the best reference is |
| 978 | <filename>meta/classes/core-image.bbclass</filename>. |
| 979 | This class lists out the available |
| 980 | <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink> |
| 981 | of which most map to package groups while some, such as |
| 982 | <filename>debug-tweaks</filename> and |
| 983 | <filename>read-only-rootfs</filename>, resolve as general |
| 984 | configuration settings. |
| 985 | </para> |
| 986 | |
| 987 | <para> |
| 988 | In summary, the file looks at the contents of the |
| 989 | <filename>IMAGE_FEATURES</filename> variable and then maps |
| 990 | or configures the feature accordingly. |
| 991 | Based on this information, the build system automatically |
| 992 | adds the appropriate packages or configurations to the |
| 993 | <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink> |
| 994 | variable. |
| 995 | Effectively, you are enabling extra features by extending the |
| 996 | class or creating a custom class for use with specialized image |
| 997 | <filename>.bb</filename> files. |
| 998 | </para> |
| 999 | |
| 1000 | <para> |
| 1001 | Use the <filename>EXTRA_IMAGE_FEATURES</filename> variable |
| 1002 | from within your local configuration file. |
| 1003 | Using a separate area from which to enable features with |
| 1004 | this variable helps you avoid overwriting the features in the |
| 1005 | image recipe that are enabled with |
| 1006 | <filename>IMAGE_FEATURES</filename>. |
| 1007 | The value of <filename>EXTRA_IMAGE_FEATURES</filename> is added |
| 1008 | to <filename>IMAGE_FEATURES</filename> within |
| 1009 | <filename>meta/conf/bitbake.conf</filename>. |
| 1010 | </para> |
| 1011 | |
| 1012 | <para> |
| 1013 | To illustrate how you can use these variables to modify your |
| 1014 | image, consider an example that selects the SSH server. |
| 1015 | The Yocto Project ships with two SSH servers you can use |
| 1016 | with your images: Dropbear and OpenSSH. |
| 1017 | Dropbear is a minimal SSH server appropriate for |
| 1018 | resource-constrained environments, while OpenSSH is a |
| 1019 | well-known standard SSH server implementation. |
| 1020 | By default, the <filename>core-image-sato</filename> image |
| 1021 | is configured to use Dropbear. |
| 1022 | The <filename>core-image-full-cmdline</filename> and |
| 1023 | <filename>core-image-lsb</filename> images both |
| 1024 | include OpenSSH. |
| 1025 | The <filename>core-image-minimal</filename> image does not |
| 1026 | contain an SSH server. |
| 1027 | </para> |
| 1028 | |
| 1029 | <para> |
| 1030 | You can customize your image and change these defaults. |
| 1031 | Edit the <filename>IMAGE_FEATURES</filename> variable |
| 1032 | in your recipe or use the |
| 1033 | <filename>EXTRA_IMAGE_FEATURES</filename> in your |
| 1034 | <filename>local.conf</filename> file so that it configures the |
| 1035 | image you are working with to include |
| 1036 | <filename>ssh-server-dropbear</filename> or |
| 1037 | <filename>ssh-server-openssh</filename>. |
| 1038 | </para> |
| 1039 | |
| 1040 | <note> |
| 1041 | See the |
| 1042 | "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>" |
| 1043 | section in the Yocto Project Reference Manual for a complete |
| 1044 | list of image features that ship with the Yocto Project. |
| 1045 | </note> |
| 1046 | </section> |
| 1047 | |
| 1048 | <section id='usingpoky-extend-customimage-custombb'> |
| 1049 | <title>Customizing Images Using Custom .bb Files</title> |
| 1050 | |
| 1051 | <para> |
| 1052 | You can also customize an image by creating a custom recipe |
| 1053 | that defines additional software as part of the image. |
| 1054 | The following example shows the form for the two lines you need: |
| 1055 | <literallayout class='monospaced'> |
| 1056 | IMAGE_INSTALL = "packagegroup-core-x11-base package1 package2" |
| 1057 | |
| 1058 | inherit core-image |
| 1059 | </literallayout> |
| 1060 | </para> |
| 1061 | |
| 1062 | <para> |
| 1063 | Defining the software using a custom recipe gives you total |
| 1064 | control over the contents of the image. |
| 1065 | It is important to use the correct names of packages in the |
| 1066 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename> |
| 1067 | variable. |
| 1068 | You must use the OpenEmbedded notation and not the Debian notation for the names |
| 1069 | (e.g. <filename>glibc-dev</filename> instead of <filename>libc6-dev</filename>). |
| 1070 | </para> |
| 1071 | |
| 1072 | <para> |
| 1073 | The other method for creating a custom image is to base it on an existing image. |
| 1074 | For example, if you want to create an image based on <filename>core-image-sato</filename> |
| 1075 | but add the additional package <filename>strace</filename> to the image, |
| 1076 | copy the <filename>meta/recipes-sato/images/core-image-sato.bb</filename> to a |
| 1077 | new <filename>.bb</filename> and add the following line to the end of the copy: |
| 1078 | <literallayout class='monospaced'> |
| 1079 | IMAGE_INSTALL += "strace" |
| 1080 | </literallayout> |
| 1081 | </para> |
| 1082 | </section> |
| 1083 | |
| 1084 | <section id='usingpoky-extend-customimage-customtasks'> |
| 1085 | <title>Customizing Images Using Custom Package Groups</title> |
| 1086 | |
| 1087 | <para> |
| 1088 | For complex custom images, the best approach for customizing |
| 1089 | an image is to create a custom package group recipe that is |
| 1090 | used to build the image or images. |
| 1091 | A good example of a package group recipe is |
| 1092 | <filename>meta/recipes-core/packagegroups/packagegroup-base.bb</filename>. |
| 1093 | </para> |
| 1094 | |
| 1095 | <para> |
| 1096 | If you examine that recipe, you see that the |
| 1097 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'>PACKAGES</ulink></filename> |
| 1098 | variable lists the package group packages to produce. |
| 1099 | The <filename>inherit packagegroup</filename> statement |
| 1100 | sets appropriate default values and automatically adds |
| 1101 | <filename>-dev</filename>, <filename>-dbg</filename>, and |
| 1102 | <filename>-ptest</filename> complementary packages for each |
| 1103 | package specified in the <filename>PACKAGES</filename> |
| 1104 | statement. |
| 1105 | <note> |
| 1106 | The <filename>inherit packages</filename> should be |
| 1107 | located near the top of the recipe, certainly before |
| 1108 | the <filename>PACKAGES</filename> statement. |
| 1109 | </note> |
| 1110 | </para> |
| 1111 | |
| 1112 | <para> |
| 1113 | For each package you specify in <filename>PACKAGES</filename>, |
| 1114 | you can use |
| 1115 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'>RDEPENDS</ulink></filename> |
| 1116 | and |
| 1117 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'>RRECOMMENDS</ulink></filename> |
| 1118 | entries to provide a list of packages the parent task package |
| 1119 | should contain. |
| 1120 | You can see examples of these further down in the |
| 1121 | <filename>packagegroup-base.bb</filename> recipe. |
| 1122 | </para> |
| 1123 | |
| 1124 | <para> |
| 1125 | Here is a short, fabricated example showing the same basic |
| 1126 | pieces: |
| 1127 | <literallayout class='monospaced'> |
| 1128 | DESCRIPTION = "My Custom Package Groups" |
| 1129 | |
| 1130 | inherit packagegroup |
| 1131 | |
| 1132 | PACKAGES = "\ |
| 1133 | packagegroup-custom-apps \ |
| 1134 | packagegroup-custom-tools \ |
| 1135 | " |
| 1136 | |
| 1137 | RDEPENDS_packagegroup-custom-apps = "\ |
| 1138 | dropbear \ |
| 1139 | portmap \ |
| 1140 | psplash" |
| 1141 | |
| 1142 | RDEPENDS_packagegroup-custom-tools = "\ |
| 1143 | oprofile \ |
| 1144 | oprofileui-server \ |
| 1145 | lttng-tools" |
| 1146 | |
| 1147 | RRECOMMENDS_packagegroup-custom-tools = "\ |
| 1148 | kernel-module-oprofile" |
| 1149 | </literallayout> |
| 1150 | </para> |
| 1151 | |
| 1152 | <para> |
| 1153 | In the previous example, two package group packages are created with their dependencies and their |
| 1154 | recommended package dependencies listed: <filename>packagegroup-custom-apps</filename>, and |
| 1155 | <filename>packagegroup-custom-tools</filename>. |
| 1156 | To build an image using these package group packages, you need to add |
| 1157 | <filename>packagegroup-custom-apps</filename> and/or |
| 1158 | <filename>packagegroup-custom-tools</filename> to |
| 1159 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename>. |
| 1160 | For other forms of image dependencies see the other areas of this section. |
| 1161 | </para> |
| 1162 | </section> |
| 1163 | |
| 1164 | <section id='usingpoky-extend-customimage-image-name'> |
| 1165 | <title>Customizing an Image Hostname</title> |
| 1166 | |
| 1167 | <para> |
| 1168 | By default, the configured hostname (i.e. |
| 1169 | <filename>/etc/hostname</filename>) in an image is the |
| 1170 | same as the machine name. |
| 1171 | For example, if |
| 1172 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink> |
| 1173 | equals "qemux86", the configured hostname written to |
| 1174 | <filename>/etc/hostname</filename> is "qemux86". |
| 1175 | </para> |
| 1176 | |
| 1177 | <para> |
| 1178 | You can customize this name by altering the value of the |
| 1179 | "hostname" variable in the |
| 1180 | <filename>base-files</filename> recipe using either |
| 1181 | an append file or a configuration file. |
| 1182 | Use the following in an append file: |
| 1183 | <literallayout class='monospaced'> |
| 1184 | hostname="myhostname" |
| 1185 | </literallayout> |
| 1186 | Use the following in a configuration file: |
| 1187 | <literallayout class='monospaced'> |
| 1188 | hostname_pn-base-files = "myhostname" |
| 1189 | </literallayout> |
| 1190 | </para> |
| 1191 | |
| 1192 | <para> |
| 1193 | Changing the default value of the variable "hostname" can be |
| 1194 | useful in certain situations. |
| 1195 | For example, suppose you need to do extensive testing on an |
| 1196 | image and you would like to easily identify the image |
| 1197 | under test from existing images with typical default |
| 1198 | hostnames. |
| 1199 | In this situation, you could change the default hostname to |
| 1200 | "testme", which results in all the images using the name |
| 1201 | "testme". |
| 1202 | Once testing is complete and you do not need to rebuild the |
| 1203 | image for test any longer, you can easily reset the default |
| 1204 | hostname. |
| 1205 | </para> |
| 1206 | |
| 1207 | <para> |
| 1208 | Another point of interest is that if you unset the variable, |
| 1209 | the image will have no default hostname in the filesystem. |
| 1210 | Here is an example that unsets the variable in a |
| 1211 | configuration file: |
| 1212 | <literallayout class='monospaced'> |
| 1213 | hostname_pn-base-files = "" |
| 1214 | </literallayout> |
| 1215 | Having no default hostname in the filesystem is suitable for |
| 1216 | environments that use dynamic hostnames such as virtual |
| 1217 | machines. |
| 1218 | </para> |
| 1219 | </section> |
| 1220 | </section> |
| 1221 | |
| 1222 | <section id='new-recipe-writing-a-new-recipe'> |
| 1223 | <title>Writing a New Recipe</title> |
| 1224 | |
| 1225 | <para> |
| 1226 | Recipes (<filename>.bb</filename> files) are fundamental components |
| 1227 | in the Yocto Project environment. |
| 1228 | Each software component built by the OpenEmbedded build system |
| 1229 | requires a recipe to define the component. |
| 1230 | This section describes how to create, write, and test a new |
| 1231 | recipe. |
| 1232 | <note> |
| 1233 | For information on variables that are useful for recipes and |
| 1234 | for information about recipe naming issues, see the |
| 1235 | "<ulink url='&YOCTO_DOCS_REF_URL;#ref-varlocality-recipe-required'>Required</ulink>" |
| 1236 | section of the Yocto Project Reference Manual. |
| 1237 | </note> |
| 1238 | </para> |
| 1239 | |
| 1240 | <section id='new-recipe-overview'> |
| 1241 | <title>Overview</title> |
| 1242 | |
| 1243 | <para> |
| 1244 | The following figure shows the basic process for creating a |
| 1245 | new recipe. |
| 1246 | The remainder of the section provides details for the steps. |
| 1247 | <imagedata fileref="figures/recipe-workflow.png" width="6in" depth="7in" align="center" scalefit="1" /> |
| 1248 | </para> |
| 1249 | </section> |
| 1250 | |
| 1251 | <section id='new-recipe-locate-or-automatically-create-a-base-recipe'> |
| 1252 | <title>Locate or Automatically Create a Base Recipe</title> |
| 1253 | |
| 1254 | <para> |
| 1255 | You can always write a recipe from scratch. |
| 1256 | However, two choices exist that can help you quickly get a |
| 1257 | start on a new recipe: |
| 1258 | <itemizedlist> |
| 1259 | <listitem><para><emphasis><filename>recipetool</filename>:</emphasis> |
| 1260 | A tool provided by the Yocto Project that automates |
| 1261 | creation of a base recipe based on the source |
| 1262 | files. |
| 1263 | </para></listitem> |
| 1264 | <listitem><para><emphasis>Existing Recipes:</emphasis> |
| 1265 | Location and modification of an existing recipe that is |
| 1266 | similar in function to the recipe you need. |
| 1267 | </para></listitem> |
| 1268 | </itemizedlist> |
| 1269 | </para> |
| 1270 | |
| 1271 | <section id='new-recipe-creating-the-base-recipe-using-recipetool'> |
| 1272 | <title>Creating the Base Recipe Using <filename>recipetool</filename></title> |
| 1273 | |
| 1274 | <para> |
| 1275 | <filename>recipetool</filename> automates creation of |
| 1276 | a base recipe given a set of source code files. |
| 1277 | As long as you can extract or point to the source files, |
| 1278 | the tool will construct a recipe and automatically |
| 1279 | configure all pre-build information into the recipe. |
| 1280 | For example, suppose you have an application that builds |
| 1281 | using Autotools. |
| 1282 | Creating the base recipe using |
| 1283 | <filename>recipetool</filename> results in a recipe |
| 1284 | that has the pre-build dependencies, license requirements, |
| 1285 | and checksums configured. |
| 1286 | </para> |
| 1287 | |
| 1288 | <para> |
| 1289 | To run the tool, you just need to be in your |
| 1290 | <link linkend='build-directory'>Build Directory</link> |
| 1291 | and have sourced the build environment setup script |
| 1292 | (i.e. |
| 1293 | <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>oe-init-build-env</filename></ulink> |
| 1294 | or |
| 1295 | <ulink url='&YOCTO_DOCS_REF_URL;#structure-memres-core-script'><filename>oe-init-build-env-memres</filename></ulink>). |
| 1296 | Here is the basic <filename>recipetool</filename> syntax: |
| 1297 | <note> |
| 1298 | Running <filename>recipetool -h</filename> or |
| 1299 | <filename>recipetool create -h</filename> produces the |
| 1300 | Python-generated help, which presented differently |
| 1301 | than what follows here. |
| 1302 | </note> |
| 1303 | <literallayout class='monospaced'> |
| 1304 | recipetool -h |
| 1305 | recipetool create [-h] |
| 1306 | recipetool [-d] [-q] [--color auto | always | never ] create -o <replaceable>OUTFILE</replaceable> [-m] [-x <replaceable>EXTERNALSRC</replaceable>] <replaceable>source</replaceable> |
| 1307 | |
| 1308 | -d Enables debug output. |
| 1309 | -q Outputs only errors (quiet mode). |
| 1310 | --color Colorizes the output automatically, always, or never. |
| 1311 | -h Displays Python generated syntax for recipetool. |
| 1312 | create Causes recipetool to create a base recipe. The create |
| 1313 | command is further defined with these options: |
| 1314 | |
| 1315 | -o <replaceable>OUTFILE</replaceable> Specifies the full path and filename for the generated |
| 1316 | recipe. |
| 1317 | -m Causes the recipe to be machine-specific rather than |
| 1318 | architecture-specific (default). |
| 1319 | -x <replaceable>EXTERNALSRC</replaceable> Fetches and extracts source files from <replaceable>source</replaceable> |
| 1320 | and places them in <replaceable>EXTERNALSRC</replaceable>. |
| 1321 | <replaceable>source</replaceable> must be a URL. |
| 1322 | -h Displays Python-generated syntax for create. |
| 1323 | <replaceable>source</replaceable> Specifies the source code on which to base the |
| 1324 | recipe. |
| 1325 | </literallayout> |
| 1326 | </para> |
| 1327 | |
| 1328 | <para> |
| 1329 | Running <filename>recipetool create -o</filename> <replaceable>OUTFILE</replaceable> |
| 1330 | creates the base recipe and locates it properly in the |
| 1331 | layer that contains your source files. |
| 1332 | Following are some syntax examples: |
| 1333 | </para> |
| 1334 | |
| 1335 | <para> |
| 1336 | Use this syntax to generate a recipe based on <replaceable>source</replaceable>. |
| 1337 | Once generated, the recipe resides in the existing source |
| 1338 | code layer: |
| 1339 | <literallayout class='monospaced'> |
| 1340 | recipetool create -o <replaceable>OUTFILE</replaceable> <replaceable>source</replaceable> |
| 1341 | </literallayout> |
| 1342 | Use this syntax to generate a recipe using code that you |
| 1343 | extract from <replaceable>source</replaceable>. |
| 1344 | The extracted code is placed in its own layer defined |
| 1345 | by <replaceable>EXTERNALSRC</replaceable>. |
| 1346 | <literallayout class='monospaced'> |
| 1347 | recipetool create -o <replaceable>OUTFILE</replaceable> -x <replaceable>EXTERNALSRC</replaceable> <replaceable>source</replaceable> |
| 1348 | </literallayout> |
| 1349 | Use this syntax to generate a recipe based on <replaceable>source</replaceable>. |
| 1350 | The options direct <filename>recipetool</filename> to |
| 1351 | run in "quiet mode" and to generate debugging information. |
| 1352 | Once generated, the recipe resides in the existing source |
| 1353 | code layer: |
| 1354 | <literallayout class='monospaced'> |
| 1355 | recipetool create -o <replaceable>OUTFILE</replaceable> <replaceable>source</replaceable> |
| 1356 | </literallayout> |
| 1357 | </para> |
| 1358 | </section> |
| 1359 | |
| 1360 | <section id='new-recipe-locating-and-using-a-similar-recipe'> |
| 1361 | <title>Locating and Using a Similar Recipe</title> |
| 1362 | |
| 1363 | <para> |
| 1364 | Before writing a recipe from scratch, it is often useful to |
| 1365 | discover whether someone else has already written one that |
| 1366 | meets (or comes close to meeting) your needs. |
| 1367 | The Yocto Project and OpenEmbedded communities maintain many |
| 1368 | recipes that might be candidates for what you are doing. |
| 1369 | You can find a good central index of these recipes in the |
| 1370 | <ulink url='http://layers.openembedded.org'>OpenEmbedded metadata index</ulink>. |
| 1371 | </para> |
| 1372 | |
| 1373 | <para> |
| 1374 | Working from an existing recipe or a skeleton recipe is the |
| 1375 | best way to get started. |
| 1376 | Here are some points on both methods: |
| 1377 | <itemizedlist> |
| 1378 | <listitem><para><emphasis>Locate and modify a recipe that |
| 1379 | is close to what you want to do:</emphasis> |
| 1380 | This method works when you are familiar with the |
| 1381 | current recipe space. |
| 1382 | The method does not work so well for those new to |
| 1383 | the Yocto Project or writing recipes.</para> |
| 1384 | <para>Some risks associated with this method are |
| 1385 | using a recipe that has areas totally unrelated to |
| 1386 | what you are trying to accomplish with your recipe, |
| 1387 | not recognizing areas of the recipe that you might |
| 1388 | have to add from scratch, and so forth. |
| 1389 | All these risks stem from unfamiliarity with the |
| 1390 | existing recipe space.</para></listitem> |
| 1391 | <listitem><para><emphasis>Use and modify the following |
| 1392 | skeleton recipe:</emphasis> |
| 1393 | If for some reason you do not want to use |
| 1394 | <filename>recipetool</filename> and you cannot |
| 1395 | find an existing recipe that is close to meeting |
| 1396 | your needs, you can use the following structure to |
| 1397 | provide the fundamental areas of a new recipe. |
| 1398 | <literallayout class='monospaced'> |
| 1399 | DESCRIPTION = "" |
| 1400 | HOMEPAGE = "" |
| 1401 | LICENSE = "" |
| 1402 | SECTION = "" |
| 1403 | DEPENDS = "" |
| 1404 | LIC_FILES_CHKSUM = "" |
| 1405 | |
| 1406 | SRC_URI = "" |
| 1407 | </literallayout> |
| 1408 | </para></listitem> |
| 1409 | </itemizedlist> |
| 1410 | </para> |
| 1411 | </section> |
| 1412 | </section> |
| 1413 | |
| 1414 | <section id='new-recipe-storing-and-naming-the-recipe'> |
| 1415 | <title>Storing and Naming the Recipe</title> |
| 1416 | |
| 1417 | <para> |
| 1418 | Once you have your base recipe, you should put it in your |
| 1419 | own layer and name it appropriately. |
| 1420 | Locating it correctly ensures that the OpenEmbedded build |
| 1421 | system can find it when you use BitBake to process the |
| 1422 | recipe. |
| 1423 | </para> |
| 1424 | |
| 1425 | <itemizedlist> |
| 1426 | <listitem><para><emphasis>Storing Your Recipe:</emphasis> |
| 1427 | The OpenEmbedded build system locates your recipe |
| 1428 | through the layer's <filename>conf/layer.conf</filename> |
| 1429 | file and the |
| 1430 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILES'><filename>BBFILES</filename></ulink> |
| 1431 | variable. |
| 1432 | This variable sets up a path from which the build system can |
| 1433 | locate recipes. |
| 1434 | Here is the typical use: |
| 1435 | <literallayout class='monospaced'> |
| 1436 | BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \ |
| 1437 | ${LAYERDIR}/recipes-*/*/*.bbappend" |
| 1438 | </literallayout> |
| 1439 | Consequently, you need to be sure you locate your new recipe |
| 1440 | inside your layer such that it can be found.</para> |
| 1441 | <para>You can find more information on how layers are |
| 1442 | structured in the |
| 1443 | "<link linkend='understanding-and-creating-layers'>Understanding and Creating Layers</link>" |
| 1444 | section.</para></listitem> |
| 1445 | <listitem><para><emphasis>Naming Your Recipe:</emphasis> |
| 1446 | When you name your recipe, you need to follow this naming |
| 1447 | convention: |
| 1448 | <literallayout class='monospaced'> |
| 1449 | <replaceable>basename</replaceable>_<replaceable>version</replaceable>.bb |
| 1450 | </literallayout> |
| 1451 | Use lower-cased characters and do not include the reserved |
| 1452 | suffixes <filename>-native</filename>, |
| 1453 | <filename>-cross</filename>, <filename>-initial</filename>, |
| 1454 | or <filename>-dev</filename> casually (i.e. do not use them |
| 1455 | as part of your recipe name unless the string applies). |
| 1456 | Here are some examples: |
| 1457 | <literallayout class='monospaced'> |
| 1458 | cups_1.7.0.bb |
| 1459 | gawk_4.0.2.bb |
| 1460 | irssi_0.8.16-rc1.bb |
| 1461 | </literallayout></para></listitem> |
| 1462 | </itemizedlist> |
| 1463 | </section> |
| 1464 | |
| 1465 | <section id='understanding-recipe-syntax'> |
| 1466 | <title>Understanding Recipe Syntax</title> |
| 1467 | |
| 1468 | <para> |
| 1469 | Understanding recipe file syntax is important for |
| 1470 | writing recipes. |
| 1471 | The following list overviews the basic items that make up a |
| 1472 | BitBake recipe file. |
| 1473 | For more complete BitBake syntax descriptions, see the |
| 1474 | "<ulink url='&YOCTO_DOCS_BB_URL;#bitbake-user-manual-metadata'>Syntax and Operators</ulink>" |
| 1475 | chapter of the BitBake User Manual. |
| 1476 | <itemizedlist> |
| 1477 | <listitem><para><emphasis>Variable Assignments and Manipulations:</emphasis> |
| 1478 | Variable assignments allow a value to be assigned to a |
| 1479 | variable. |
| 1480 | The assignment can be static text or might include |
| 1481 | the contents of other variables. |
| 1482 | In addition to the assignment, appending and prepending |
| 1483 | operations are also supported.</para> |
| 1484 | <para>The following example shows some of the ways |
| 1485 | you can use variables in recipes: |
| 1486 | <literallayout class='monospaced'> |
| 1487 | S = "${WORKDIR}/postfix-${PV}" |
| 1488 | CFLAGS += "-DNO_ASM" |
| 1489 | SRC_URI_append = " file://fixup.patch" |
| 1490 | </literallayout> |
| 1491 | </para></listitem> |
| 1492 | <listitem><para><emphasis>Functions:</emphasis> |
| 1493 | Functions provide a series of actions to be performed. |
| 1494 | You usually use functions to override the default |
| 1495 | implementation of a task function or to complement |
| 1496 | a default function (i.e. append or prepend to an |
| 1497 | existing function). |
| 1498 | Standard functions use <filename>sh</filename> shell |
| 1499 | syntax, although access to OpenEmbedded variables and |
| 1500 | internal methods are also available.</para> |
| 1501 | <para>The following is an example function from the |
| 1502 | <filename>sed</filename> recipe: |
| 1503 | <literallayout class='monospaced'> |
| 1504 | do_install () { |
| 1505 | autotools_do_install |
| 1506 | install -d ${D}${base_bindir} |
| 1507 | mv ${D}${bindir}/sed ${D}${base_bindir}/sed |
| 1508 | rmdir ${D}${bindir}/ |
| 1509 | } |
| 1510 | </literallayout> |
| 1511 | It is also possible to implement new functions that |
| 1512 | are called between existing tasks as long as the |
| 1513 | new functions are not replacing or complementing the |
| 1514 | default functions. |
| 1515 | You can implement functions in Python |
| 1516 | instead of shell. |
| 1517 | Both of these options are not seen in the majority of |
| 1518 | recipes.</para></listitem> |
| 1519 | <listitem><para><emphasis>Keywords:</emphasis> |
| 1520 | BitBake recipes use only a few keywords. |
| 1521 | You use keywords to include common |
| 1522 | functions (<filename>inherit</filename>), load parts |
| 1523 | of a recipe from other files |
| 1524 | (<filename>include</filename> and |
| 1525 | <filename>require</filename>) and export variables |
| 1526 | to the environment (<filename>export</filename>).</para> |
| 1527 | <para>The following example shows the use of some of |
| 1528 | these keywords: |
| 1529 | <literallayout class='monospaced'> |
| 1530 | export POSTCONF = "${STAGING_BINDIR}/postconf" |
| 1531 | inherit autoconf |
| 1532 | require otherfile.inc |
| 1533 | </literallayout> |
| 1534 | </para></listitem> |
| 1535 | <listitem><para><emphasis>Comments:</emphasis> |
| 1536 | Any lines that begin with the hash character |
| 1537 | (<filename>#</filename>) are treated as comment lines |
| 1538 | and are ignored: |
| 1539 | <literallayout class='monospaced'> |
| 1540 | # This is a comment |
| 1541 | </literallayout> |
| 1542 | </para></listitem> |
| 1543 | </itemizedlist> |
| 1544 | </para> |
| 1545 | |
| 1546 | <para> |
| 1547 | This next list summarizes the most important and most commonly |
| 1548 | used parts of the recipe syntax. |
| 1549 | For more information on these parts of the syntax, you can |
| 1550 | reference the |
| 1551 | <ulink url='&YOCTO_DOCS_BB_URL;#bitbake-user-manual-metadata'>Syntax and Operators</ulink> |
| 1552 | chapter in the BitBake User Manual. |
| 1553 | <itemizedlist> |
| 1554 | <listitem><para><emphasis>Line Continuation: <filename>\</filename></emphasis> - |
| 1555 | Use the backward slash (<filename>\</filename>) |
| 1556 | character to split a statement over multiple lines. |
| 1557 | Place the slash character at the end of the line that |
| 1558 | is to be continued on the next line: |
| 1559 | <literallayout class='monospaced'> |
| 1560 | VAR = "A really long \ |
| 1561 | line" |
| 1562 | </literallayout> |
| 1563 | <note> |
| 1564 | You cannot have any characters including spaces |
| 1565 | or tabs after the slash character. |
| 1566 | </note> |
| 1567 | </para></listitem> |
| 1568 | <listitem><para><emphasis>Using Variables: <filename>${...}</filename></emphasis> - |
| 1569 | Use the <filename>${<replaceable>varname</replaceable>}</filename> syntax to |
| 1570 | access the contents of a variable: |
| 1571 | <literallayout class='monospaced'> |
| 1572 | SRC_URI = "${SOURCEFORGE_MIRROR}/libpng/zlib-${PV}.tar.gz" |
| 1573 | </literallayout> |
| 1574 | </para></listitem> |
| 1575 | <listitem><para><emphasis>Quote All Assignments: <filename>"<replaceable>value</replaceable>"</filename></emphasis> - |
| 1576 | Use double quotes around the value in all variable |
| 1577 | assignments. |
| 1578 | <literallayout class='monospaced'> |
| 1579 | VAR1 = "${OTHERVAR}" |
| 1580 | VAR2 = "The version is ${PV}" |
| 1581 | </literallayout> |
| 1582 | </para></listitem> |
| 1583 | <listitem><para><emphasis>Conditional Assignment: <filename>?=</filename></emphasis> - |
| 1584 | Conditional assignment is used to assign a value to |
| 1585 | a variable, but only when the variable is currently |
| 1586 | unset. |
| 1587 | Use the question mark followed by the equal sign |
| 1588 | (<filename>?=</filename>) to make a "soft" assignment |
| 1589 | used for conditional assignment. |
| 1590 | Typically, "soft" assignments are used in the |
| 1591 | <filename>local.conf</filename> file for variables |
| 1592 | that are allowed to come through from the external |
| 1593 | environment. |
| 1594 | </para> |
| 1595 | <para>Here is an example where |
| 1596 | <filename>VAR1</filename> is set to "New value" if |
| 1597 | it is currently empty. |
| 1598 | However, if <filename>VAR1</filename> has already been |
| 1599 | set, it remains unchanged: |
| 1600 | <literallayout class='monospaced'> |
| 1601 | VAR1 ?= "New value" |
| 1602 | </literallayout> |
| 1603 | In this next example, <filename>VAR1</filename> |
| 1604 | is left with the value "Original value": |
| 1605 | <literallayout class='monospaced'> |
| 1606 | VAR1 = "Original value" |
| 1607 | VAR1 ?= "New value" |
| 1608 | </literallayout> |
| 1609 | </para></listitem> |
| 1610 | <listitem><para><emphasis>Appending: <filename>+=</filename></emphasis> - |
| 1611 | Use the plus character followed by the equals sign |
| 1612 | (<filename>+=</filename>) to append values to existing |
| 1613 | variables. |
| 1614 | <note> |
| 1615 | This operator adds a space between the existing |
| 1616 | content of the variable and the new content. |
| 1617 | </note></para> |
| 1618 | <para>Here is an example: |
| 1619 | <literallayout class='monospaced'> |
| 1620 | SRC_URI += "file://fix-makefile.patch" |
| 1621 | </literallayout> |
| 1622 | </para></listitem> |
| 1623 | <listitem><para><emphasis>Prepending: <filename>=+</filename></emphasis> - |
| 1624 | Use the equals sign followed by the plus character |
| 1625 | (<filename>=+</filename>) to prepend values to existing |
| 1626 | variables. |
| 1627 | <note> |
| 1628 | This operator adds a space between the new content |
| 1629 | and the existing content of the variable. |
| 1630 | </note></para> |
| 1631 | <para>Here is an example: |
| 1632 | <literallayout class='monospaced'> |
| 1633 | VAR =+ "Starts" |
| 1634 | </literallayout> |
| 1635 | </para></listitem> |
| 1636 | <listitem><para><emphasis>Appending: <filename>_append</filename></emphasis> - |
| 1637 | Use the <filename>_append</filename> operator to |
| 1638 | append values to existing variables. |
| 1639 | This operator does not add any additional space. |
| 1640 | Also, the operator is applied after all the |
| 1641 | <filename>+=</filename>, and |
| 1642 | <filename>=+</filename> operators have been applied and |
| 1643 | after all <filename>=</filename> assignments have |
| 1644 | occurred. |
| 1645 | </para> |
| 1646 | <para>The following example shows the space being |
| 1647 | explicitly added to the start to ensure the appended |
| 1648 | value is not merged with the existing value: |
| 1649 | <literallayout class='monospaced'> |
| 1650 | SRC_URI_append = " file://fix-makefile.patch" |
| 1651 | </literallayout> |
| 1652 | You can also use the <filename>_append</filename> |
| 1653 | operator with overrides, which results in the actions |
| 1654 | only being performed for the specified target or |
| 1655 | machine: |
| 1656 | <literallayout class='monospaced'> |
| 1657 | SRC_URI_append_sh4 = " file://fix-makefile.patch" |
| 1658 | </literallayout> |
| 1659 | </para></listitem> |
| 1660 | <listitem><para><emphasis>Prepending: <filename>_prepend</filename></emphasis> - |
| 1661 | Use the <filename>_prepend</filename> operator to |
| 1662 | prepend values to existing variables. |
| 1663 | This operator does not add any additional space. |
| 1664 | Also, the operator is applied after all the |
| 1665 | <filename>+=</filename>, and |
| 1666 | <filename>=+</filename> operators have been applied and |
| 1667 | after all <filename>=</filename> assignments have |
| 1668 | occurred. |
| 1669 | </para> |
| 1670 | <para>The following example shows the space being |
| 1671 | explicitly added to the end to ensure the prepended |
| 1672 | value is not merged with the existing value: |
| 1673 | <literallayout class='monospaced'> |
| 1674 | CFLAGS_prepend = "-I${S}/myincludes " |
| 1675 | </literallayout> |
| 1676 | You can also use the <filename>_prepend</filename> |
| 1677 | operator with overrides, which results in the actions |
| 1678 | only being performed for the specified target or |
| 1679 | machine: |
| 1680 | <literallayout class='monospaced'> |
| 1681 | CFLAGS_prepend_sh4 = "-I${S}/myincludes " |
| 1682 | </literallayout> |
| 1683 | </para></listitem> |
| 1684 | <listitem><para><emphasis>Overrides:</emphasis> - |
| 1685 | You can use overrides to set a value conditionally, |
| 1686 | typically based on how the recipe is being built. |
| 1687 | For example, to set the |
| 1688 | <ulink url='&YOCTO_DOCS_REF_URL;#var-KBRANCH'><filename>KBRANCH</filename></ulink> |
| 1689 | variable's value to "standard/base" for any target |
| 1690 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>, |
| 1691 | except for qemuarm where it should be set to |
| 1692 | "standard/arm-versatile-926ejs", you would do the |
| 1693 | following: |
| 1694 | <literallayout class='monospaced'> |
| 1695 | KBRANCH = "standard/base" |
| 1696 | KBRANCH_qemuarm = "standard/arm-versatile-926ejs" |
| 1697 | </literallayout> |
| 1698 | Overrides are also used to separate alternate values |
| 1699 | of a variable in other situations. |
| 1700 | For example, when setting variables such as |
| 1701 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink> |
| 1702 | and |
| 1703 | <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink> |
| 1704 | that are specific to individual packages produced by |
| 1705 | a recipe, you should always use an override that |
| 1706 | specifies the name of the package. |
| 1707 | </para></listitem> |
| 1708 | <listitem><para><emphasis>Indentation:</emphasis> |
| 1709 | Use spaces for indentation rather than than tabs. |
| 1710 | For shell functions, both currently work. |
| 1711 | However, it is a policy decision of the Yocto Project |
| 1712 | to use tabs in shell functions. |
| 1713 | Realize that some layers have a policy to use spaces |
| 1714 | for all indentation. |
| 1715 | </para></listitem> |
| 1716 | <listitem><para><emphasis>Using Python for Complex Operations: <filename>${@<replaceable>python_code</replaceable>}</filename></emphasis> - |
| 1717 | For more advanced processing, it is possible to use |
| 1718 | Python code during variable assignments (e.g. |
| 1719 | search and replacement on a variable).</para> |
| 1720 | <para>You indicate Python code using the |
| 1721 | <filename>${@<replaceable>python_code</replaceable>}</filename> |
| 1722 | syntax for the variable assignment: |
| 1723 | <literallayout class='monospaced'> |
| 1724 | SRC_URI = "ftp://ftp.info-zip.org/pub/infozip/src/zip${@d.getVar('PV',1).replace('.', '')}.tgz |
| 1725 | </literallayout> |
| 1726 | </para></listitem> |
| 1727 | <listitem><para><emphasis>Shell Function Syntax:</emphasis> |
| 1728 | Write shell functions as if you were writing a shell |
| 1729 | script when you describe a list of actions to take. |
| 1730 | You should ensure that your script works with a generic |
| 1731 | <filename>sh</filename> and that it does not require |
| 1732 | any <filename>bash</filename> or other shell-specific |
| 1733 | functionality. |
| 1734 | The same considerations apply to various system |
| 1735 | utilities (e.g. <filename>sed</filename>, |
| 1736 | <filename>grep</filename>, <filename>awk</filename>, |
| 1737 | and so forth) that you might wish to use. |
| 1738 | If in doubt, you should check with multiple |
| 1739 | implementations - including those from BusyBox. |
| 1740 | </para></listitem> |
| 1741 | </itemizedlist> |
| 1742 | </para> |
| 1743 | </section> |
| 1744 | |
| 1745 | <section id='new-recipe-running-a-build-on-the-recipe'> |
| 1746 | <title>Running a Build on the Recipe</title> |
| 1747 | |
| 1748 | <para> |
| 1749 | Creating a new recipe is usually an iterative process that |
| 1750 | requires using BitBake to process the recipe multiple times in |
| 1751 | order to progressively discover and add information to the |
| 1752 | recipe file. |
| 1753 | </para> |
| 1754 | |
| 1755 | <para> |
| 1756 | Assuming you have sourced a build environment setup script (i.e. |
| 1757 | <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink> |
| 1758 | or |
| 1759 | <ulink url='&YOCTO_DOCS_REF_URL;#structure-memres-core-script'><filename>oe-init-build-env-memres</filename></ulink>) |
| 1760 | and you are in the |
| 1761 | <link linkend='build-directory'>Build Directory</link>, |
| 1762 | use BitBake to process your recipe. |
| 1763 | All you need to provide is the |
| 1764 | <filename><replaceable>basename</replaceable></filename> of the recipe as described |
| 1765 | in the previous section: |
| 1766 | <literallayout class='monospaced'> |
| 1767 | $ bitbake <replaceable>basename</replaceable> |
| 1768 | </literallayout> |
| 1769 | |
| 1770 | </para> |
| 1771 | |
| 1772 | <para> |
| 1773 | During the build, the OpenEmbedded build system creates a |
| 1774 | temporary work directory for each recipe |
| 1775 | (<filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}</filename>) |
| 1776 | where it keeps extracted source files, log files, intermediate |
| 1777 | compilation and packaging files, and so forth. |
| 1778 | </para> |
| 1779 | |
| 1780 | <para> |
| 1781 | The per-recipe temporary work directory is constructed as follows and |
| 1782 | depends on several factors: |
| 1783 | <literallayout class='monospaced'> |
| 1784 | BASE_WORKDIR ?= "${TMPDIR}/work" |
| 1785 | WORKDIR = "${BASE_WORKDIR}/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR}" |
| 1786 | </literallayout> |
| 1787 | As an example, assume a Source Directory top-level folder named |
| 1788 | <filename>poky</filename>, a default Build Directory at |
| 1789 | <filename>poky/build</filename>, and a |
| 1790 | <filename>qemux86-poky-linux</filename> machine target system. |
| 1791 | Furthermore, suppose your recipe is named |
| 1792 | <filename>foo_1.3.0.bb</filename>. |
| 1793 | In this case, the work directory the build system uses to |
| 1794 | build the package would be as follows: |
| 1795 | <literallayout class='monospaced'> |
| 1796 | poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0 |
| 1797 | </literallayout> |
| 1798 | Inside this directory you can find sub-directories such as |
| 1799 | <filename>image</filename>, <filename>packages-split</filename>, |
| 1800 | and <filename>temp</filename>. |
| 1801 | After the build, you can examine these to determine how well |
| 1802 | the build went. |
| 1803 | <note> |
| 1804 | You can find log files for each task in the recipe's |
| 1805 | <filename>temp</filename> directory (e.g. |
| 1806 | <filename>poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0/temp</filename>). |
| 1807 | Log files are named <filename>log.<replaceable>taskname</replaceable></filename> |
| 1808 | (e.g. <filename>log.do_configure</filename>, |
| 1809 | <filename>log.do_fetch</filename>, and |
| 1810 | <filename>log.do_compile</filename>). |
| 1811 | </note> |
| 1812 | </para> |
| 1813 | |
| 1814 | <para> |
| 1815 | You can find more information about the build process in the |
| 1816 | "<ulink url='&YOCTO_DOCS_REF_URL;#closer-look'>A Closer Look at the Yocto Project Development Environment</ulink>" |
| 1817 | chapter of the Yocto Project Reference Manual. |
| 1818 | </para> |
| 1819 | |
| 1820 | <para> |
| 1821 | You can also reference the following variables in the |
| 1822 | Yocto Project Reference Manual's glossary for more information: |
| 1823 | <itemizedlist> |
| 1824 | <listitem><ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>: |
| 1825 | The top-level build output directory</listitem> |
| 1826 | <listitem><ulink url='&YOCTO_DOCS_REF_URL;#var-MULTIMACH_TARGET_SYS'><filename>MULTIMACH_TARGET_SYS</filename></ulink>: |
| 1827 | The target system identifier</listitem> |
| 1828 | <listitem><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>: |
| 1829 | The recipe name</listitem> |
| 1830 | <listitem><ulink url='&YOCTO_DOCS_REF_URL;#var-EXTENDPE'><filename>EXTENDPE</filename></ulink>: |
| 1831 | The epoch - (if |
| 1832 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PE'><filename>PE</filename></ulink> |
| 1833 | is not specified, which is usually the case for most |
| 1834 | recipes, then <filename>EXTENDPE</filename> is blank)</listitem> |
| 1835 | <listitem><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>: |
| 1836 | The recipe version</listitem> |
| 1837 | <listitem><ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>: |
| 1838 | The recipe revision</listitem> |
| 1839 | </itemizedlist> |
| 1840 | </para> |
| 1841 | </section> |
| 1842 | |
| 1843 | <section id='new-recipe-fetching-code'> |
| 1844 | <title>Fetching Code</title> |
| 1845 | |
| 1846 | <para> |
| 1847 | The first thing your recipe must do is specify how to fetch |
| 1848 | the source files. |
| 1849 | Fetching is controlled mainly through the |
| 1850 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> |
| 1851 | variable. |
| 1852 | Your recipe must have a <filename>SRC_URI</filename> variable |
| 1853 | that points to where the source is located. |
| 1854 | For a graphical representation of source locations, see the |
| 1855 | "<ulink url='&YOCTO_DOCS_REF_URL;#sources-dev-environment'>Sources</ulink>" |
| 1856 | section in the Yocto Project Reference Manual. |
| 1857 | </para> |
| 1858 | |
| 1859 | <para> |
| 1860 | The |
| 1861 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-fetch'><filename>do_fetch</filename></ulink> |
| 1862 | task uses the prefix of each entry in the |
| 1863 | <filename>SRC_URI</filename> variable value to determine which |
| 1864 | fetcher to use to get your source files. |
| 1865 | It is the <filename>SRC_URI</filename> variable that triggers |
| 1866 | the fetcher. |
| 1867 | The |
| 1868 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink> |
| 1869 | task uses the variable after source is fetched to apply |
| 1870 | patches. |
| 1871 | The OpenEmbedded build system uses |
| 1872 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESOVERRIDES'><filename>FILESOVERRIDES</filename></ulink> |
| 1873 | for scanning directory locations for local files in |
| 1874 | <filename>SRC_URI</filename>. |
| 1875 | </para> |
| 1876 | |
| 1877 | <para> |
| 1878 | The <filename>SRC_URI</filename> variable in your recipe must |
| 1879 | define each unique location for your source files. |
| 1880 | It is good practice to not hard-code pathnames in an URL used |
| 1881 | in <filename>SRC_URI</filename>. |
| 1882 | Rather than hard-code these paths, use |
| 1883 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink><filename>}</filename>, |
| 1884 | which causes the fetch process to use the version specified in |
| 1885 | the recipe filename. |
| 1886 | Specifying the version in this manner means that upgrading the |
| 1887 | recipe to a future version is as simple as renaming the recipe |
| 1888 | to match the new version. |
| 1889 | </para> |
| 1890 | |
| 1891 | <para> |
| 1892 | Here is a simple example from the |
| 1893 | <filename>meta/recipes-devtools/cdrtools/cdrtools-native_3.01a20.bb</filename> |
| 1894 | recipe where the source comes from a single tarball. |
| 1895 | Notice the use of the |
| 1896 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink> |
| 1897 | variable: |
| 1898 | <literallayout class='monospaced'> |
| 1899 | SRC_URI = "ftp://ftp.berlios.de/pub/cdrecord/alpha/cdrtools-${PV}.tar.bz2" |
| 1900 | </literallayout> |
| 1901 | </para> |
| 1902 | |
| 1903 | <para> |
| 1904 | Files mentioned in <filename>SRC_URI</filename> whose names end |
| 1905 | in a typical archive extension (e.g. <filename>.tar</filename>, |
| 1906 | <filename>.tar.gz</filename>, <filename>.tar.bz2</filename>, |
| 1907 | <filename>.zip</filename>, and so forth), are automatically |
| 1908 | extracted during the |
| 1909 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-unpack'><filename>do_unpack</filename></ulink> |
| 1910 | task. |
| 1911 | For another example that specifies these types of files, see |
| 1912 | the |
| 1913 | "<link linkend='new-recipe-autotooled-package'>Autotooled Package</link>" |
| 1914 | section. |
| 1915 | </para> |
| 1916 | |
| 1917 | <para> |
| 1918 | Another way of specifying source is from an SCM. |
| 1919 | For Git repositories, you must specify |
| 1920 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink> |
| 1921 | and you should specify |
| 1922 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink> |
| 1923 | to include the revision with |
| 1924 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>. |
| 1925 | Here is an example from the recipe |
| 1926 | <filename>meta/recipes-kernel/blktrace/blktrace_git.bb</filename>: |
| 1927 | <literallayout class='monospaced'> |
| 1928 | SRCREV = "d6918c8832793b4205ed3bfede78c2f915c23385" |
| 1929 | |
| 1930 | PR = "r6" |
| 1931 | PV = "1.0.5+git${SRCPV}" |
| 1932 | |
| 1933 | SRC_URI = "git://git.kernel.dk/blktrace.git \ |
| 1934 | file://ldflags.patch" |
| 1935 | </literallayout> |
| 1936 | </para> |
| 1937 | |
| 1938 | <para> |
| 1939 | If your <filename>SRC_URI</filename> statement includes |
| 1940 | URLs pointing to individual files fetched from a remote server |
| 1941 | other than a version control system, BitBake attempts to |
| 1942 | verify the files against checksums defined in your recipe to |
| 1943 | ensure they have not been tampered with or otherwise modified |
| 1944 | since the recipe was written. |
| 1945 | Two checksums are used: |
| 1946 | <filename>SRC_URI[md5sum]</filename> and |
| 1947 | <filename>SRC_URI[sha256sum]</filename>. |
| 1948 | </para> |
| 1949 | |
| 1950 | <para> |
| 1951 | If your <filename>SRC_URI</filename> variable points to |
| 1952 | more than a single URL (excluding SCM URLs), you need to |
| 1953 | provide the <filename>md5</filename> and |
| 1954 | <filename>sha256</filename> checksums for each URL. |
| 1955 | For these cases, you provide a name for each URL as part of |
| 1956 | the <filename>SRC_URI</filename> and then reference that name |
| 1957 | in the subsequent checksum statements. |
| 1958 | Here is an example: |
| 1959 | <literallayout class='monospaced'> |
| 1960 | SRC_URI = "${DEBIAN_MIRROR}/main/a/apmd/apmd_3.2.2.orig.tar.gz;name=tarball \ |
| 1961 | ${DEBIAN_MIRROR}/main/a/apmd/apmd_${PV}.diff.gz;name=patch |
| 1962 | |
| 1963 | SRC_URI[tarball.md5sum] = "b1e6309e8331e0f4e6efd311c2d97fa8" |
| 1964 | SRC_URI[tarball.sha256sum] = "7f7d9f60b7766b852881d40b8ff91d8e39fccb0d1d913102a5c75a2dbb52332d" |
| 1965 | |
| 1966 | SRC_URI[patch.md5sum] = "57e1b689264ea80f78353519eece0c92" |
| 1967 | SRC_URI[patch.sha256sum] = "7905ff96be93d725544d0040e425c42f9c05580db3c272f11cff75b9aa89d430" |
| 1968 | </literallayout> |
| 1969 | </para> |
| 1970 | |
| 1971 | <para> |
| 1972 | Proper values for <filename>md5</filename> and |
| 1973 | <filename>sha256</filename> checksums might be available |
| 1974 | with other signatures on the download page for the upstream |
| 1975 | source (e.g. <filename>md5</filename>, |
| 1976 | <filename>sha1</filename>, <filename>sha256</filename>, |
| 1977 | <filename>GPG</filename>, and so forth). |
| 1978 | Because the OpenEmbedded build system only deals with |
| 1979 | <filename>sha256sum</filename> and <filename>md5sum</filename>, |
| 1980 | you should verify all the signatures you find by hand. |
| 1981 | </para> |
| 1982 | |
| 1983 | <para> |
| 1984 | If no <filename>SRC_URI</filename> checksums are specified |
| 1985 | when you attempt to build the recipe, or you provide an |
| 1986 | incorrect checksum, the build will produce an error for each |
| 1987 | missing or incorrect checksum. |
| 1988 | As part of the error message, the build system provides |
| 1989 | the checksum string corresponding to the fetched file. |
| 1990 | Once you have the correct checksums, you can copy and paste |
| 1991 | them into your recipe and then run the build again to continue. |
| 1992 | <note> |
| 1993 | As mentioned, if the upstream source provides signatures |
| 1994 | for verifying the downloaded source code, you should |
| 1995 | verify those manually before setting the checksum values |
| 1996 | in the recipe and continuing with the build. |
| 1997 | </note> |
| 1998 | </para> |
| 1999 | |
| 2000 | <para> |
| 2001 | This final example is a bit more complicated and is from the |
| 2002 | <filename>meta/recipes-sato/rxvt-unicode/rxvt-unicode_9.20.bb</filename> |
| 2003 | recipe. |
| 2004 | The example's <filename>SRC_URI</filename> statement identifies |
| 2005 | multiple files as the source files for the recipe: a tarball, a |
| 2006 | patch file, a desktop file, and an icon. |
| 2007 | <literallayout class='monospaced'> |
| 2008 | SRC_URI = "http://dist.schmorp.de/rxvt-unicode/Attic/rxvt-unicode-${PV}.tar.bz2 \ |
| 2009 | file://xwc.patch \ |
| 2010 | file://rxvt.desktop \ |
| 2011 | file://rxvt.png" |
| 2012 | </literallayout> |
| 2013 | </para> |
| 2014 | |
| 2015 | <para> |
| 2016 | When you specify local files using the |
| 2017 | <filename>file://</filename> URI protocol, the build system |
| 2018 | fetches files from the local machine. |
| 2019 | The path is relative to the |
| 2020 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink> |
| 2021 | variable and searches specific directories in a certain order: |
| 2022 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BP'><filename>BP</filename></ulink><filename>}</filename>, |
| 2023 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BPN'><filename>BPN</filename></ulink><filename>}</filename>, |
| 2024 | and <filename>files</filename>. |
| 2025 | The directories are assumed to be subdirectories of the |
| 2026 | directory in which the recipe or append file resides. |
| 2027 | For another example that specifies these types of files, see the |
| 2028 | "<link linkend='new-recipe-single-c-file-package-hello-world'>Single .c File Package (Hello World!)</link>" |
| 2029 | section. |
| 2030 | </para> |
| 2031 | |
| 2032 | <para> |
| 2033 | The previous example also specifies a patch file. |
| 2034 | Patch files are files whose names usually end in |
| 2035 | <filename>.patch</filename> or <filename>.diff</filename> but |
| 2036 | can end with compressed suffixes such as |
| 2037 | <filename>diff.gz</filename> and |
| 2038 | <filename>patch.bz2</filename>, for example. |
| 2039 | The build system automatically applies patches as described |
| 2040 | in the |
| 2041 | "<link linkend='new-recipe-patching-code'>Patching Code</link>" section. |
| 2042 | </para> |
| 2043 | </section> |
| 2044 | |
| 2045 | <section id='new-recipe-unpacking-code'> |
| 2046 | <title>Unpacking Code</title> |
| 2047 | |
| 2048 | <para> |
| 2049 | During the build, the |
| 2050 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-unpack'><filename>do_unpack</filename></ulink> |
| 2051 | task unpacks the source with |
| 2052 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename> |
| 2053 | pointing to where it is unpacked. |
| 2054 | </para> |
| 2055 | |
| 2056 | <para> |
| 2057 | If you are fetching your source files from an upstream source |
| 2058 | archived tarball and the tarball's internal structure matches |
| 2059 | the common convention of a top-level subdirectory named |
| 2060 | <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>, |
| 2061 | then you do not need to set <filename>S</filename>. |
| 2062 | However, if <filename>SRC_URI</filename> specifies to fetch |
| 2063 | source from an archive that does not use this convention, |
| 2064 | or from an SCM like Git or Subversion, your recipe needs to |
| 2065 | define <filename>S</filename>. |
| 2066 | </para> |
| 2067 | |
| 2068 | <para> |
| 2069 | If processing your recipe using BitBake successfully unpacks |
| 2070 | the source files, you need to be sure that the directory |
| 2071 | pointed to by <filename>${S}</filename> matches the structure |
| 2072 | of the source. |
| 2073 | </para> |
| 2074 | </section> |
| 2075 | |
| 2076 | <section id='new-recipe-patching-code'> |
| 2077 | <title>Patching Code</title> |
| 2078 | |
| 2079 | <para> |
| 2080 | Sometimes it is necessary to patch code after it has been |
| 2081 | fetched. |
| 2082 | Any files mentioned in <filename>SRC_URI</filename> whose |
| 2083 | names end in <filename>.patch</filename> or |
| 2084 | <filename>.diff</filename> or compressed versions of these |
| 2085 | suffixes (e.g. <filename>diff.gz</filename> are treated as |
| 2086 | patches. |
| 2087 | The |
| 2088 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink> |
| 2089 | task automatically applies these patches. |
| 2090 | </para> |
| 2091 | |
| 2092 | <para> |
| 2093 | The build system should be able to apply patches with the "-p1" |
| 2094 | option (i.e. one directory level in the path will be stripped |
| 2095 | off). |
| 2096 | If your patch needs to have more directory levels stripped off, |
| 2097 | specify the number of levels using the "striplevel" option in |
| 2098 | the <filename>SRC_URI</filename> entry for the patch. |
| 2099 | Alternatively, if your patch needs to be applied in a specific |
| 2100 | subdirectory that is not specified in the patch file, use the |
| 2101 | "patchdir" option in the entry. |
| 2102 | </para> |
| 2103 | |
| 2104 | <para> |
| 2105 | As with all local files referenced in |
| 2106 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> |
| 2107 | using <filename>file://</filename>, you should place |
| 2108 | patch files in a directory next to the recipe either |
| 2109 | named the same as the base name of the recipe |
| 2110 | (<ulink url='&YOCTO_DOCS_REF_URL;#var-BP'><filename>BP</filename></ulink> |
| 2111 | and |
| 2112 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BPN'><filename>BPN</filename></ulink>) |
| 2113 | or "files". |
| 2114 | </para> |
| 2115 | </section> |
| 2116 | |
| 2117 | <section id='new-recipe-licensing'> |
| 2118 | <title>Licensing</title> |
| 2119 | |
| 2120 | <para> |
| 2121 | Your recipe needs to have both the |
| 2122 | <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink> |
| 2123 | and |
| 2124 | <ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'><filename>LIC_FILES_CHKSUM</filename></ulink> |
| 2125 | variables: |
| 2126 | <itemizedlist> |
| 2127 | <listitem><para><emphasis><filename>LICENSE</filename>:</emphasis> |
| 2128 | This variable specifies the license for the software. |
| 2129 | If you do not know the license under which the software |
| 2130 | you are building is distributed, you should go to the |
| 2131 | source code and look for that information. |
| 2132 | Typical files containing this information include |
| 2133 | <filename>COPYING</filename>, |
| 2134 | <filename>LICENSE</filename>, and |
| 2135 | <filename>README</filename> files. |
| 2136 | You could also find the information near the top of |
| 2137 | a source file. |
| 2138 | For example, given a piece of software licensed under |
| 2139 | the GNU General Public License version 2, you would |
| 2140 | set <filename>LICENSE</filename> as follows: |
| 2141 | <literallayout class='monospaced'> |
| 2142 | LICENSE = "GPLv2" |
| 2143 | </literallayout></para> |
| 2144 | <para>The licenses you specify within |
| 2145 | <filename>LICENSE</filename> can have any name as long |
| 2146 | as you do not use spaces, since spaces are used as |
| 2147 | separators between license names. |
| 2148 | For standard licenses, use the names of the files in |
| 2149 | <filename>meta/files/common-licenses/</filename> |
| 2150 | or the <filename>SPDXLICENSEMAP</filename> flag names |
| 2151 | defined in <filename>meta/conf/licenses.conf</filename>. |
| 2152 | </para></listitem> |
| 2153 | <listitem><para><emphasis><filename>LIC_FILES_CHKSUM</filename>:</emphasis> |
| 2154 | The OpenEmbedded build system uses this variable to |
| 2155 | make sure the license text has not changed. |
| 2156 | If it has, the build produces an error and it affords |
| 2157 | you the chance to figure it out and correct the problem. |
| 2158 | </para> |
| 2159 | <para>You need to specify all applicable licensing |
| 2160 | files for the software. |
| 2161 | At the end of the configuration step, the build process |
| 2162 | will compare the checksums of the files to be sure |
| 2163 | the text has not changed. |
| 2164 | Any differences result in an error with the message |
| 2165 | containing the current checksum. |
| 2166 | For more explanation and examples of how to set the |
| 2167 | <filename>LIC_FILES_CHKSUM</filename> variable, see the |
| 2168 | "<ulink url='&YOCTO_DOCS_REF_URL;#usingpoky-configuring-LIC_FILES_CHKSUM'>Tracking License Changes</ulink>" |
| 2169 | section in the Yocto Project Reference Manual.</para> |
| 2170 | <para>To determine the correct checksum string, you |
| 2171 | can list the appropriate files in the |
| 2172 | <filename>LIC_FILES_CHKSUM</filename> variable with |
| 2173 | incorrect md5 strings, attempt to build the software, |
| 2174 | and then note the resulting error messages that will |
| 2175 | report the correct md5 strings. |
| 2176 | See the |
| 2177 | "<link linkend='new-recipe-fetching-code'>Fetching Code</link>" |
| 2178 | section for additional information. |
| 2179 | </para> |
| 2180 | |
| 2181 | <para> |
| 2182 | Here is an example that assumes the software has a |
| 2183 | <filename>COPYING</filename> file: |
| 2184 | <literallayout class='monospaced'> |
| 2185 | LIC_FILES_CHKSUM = "file://COPYING;md5=xxx" |
| 2186 | </literallayout> |
| 2187 | When you try to build the software, the build system |
| 2188 | will produce an error and give you the correct string |
| 2189 | that you can substitute into the recipe file for a |
| 2190 | subsequent build. |
| 2191 | </para></listitem> |
| 2192 | </itemizedlist> |
| 2193 | </para> |
| 2194 | |
| 2195 | <!-- |
| 2196 | |
| 2197 | <para> |
| 2198 | For trying this out I created a new recipe named |
| 2199 | <filename>htop_1.0.2.bb</filename> and put it in |
| 2200 | <filename>poky/meta/recipes-extended/htop</filename>. |
| 2201 | There are two license type statements in my very simple |
| 2202 | recipe: |
| 2203 | <literallayout class='monospaced'> |
| 2204 | LICENSE = "" |
| 2205 | |
| 2206 | LIC_FILES_CHKSUM = "" |
| 2207 | |
| 2208 | SRC_URI[md5sum] = "" |
| 2209 | SRC_URI[sha256sum] = "" |
| 2210 | </literallayout> |
| 2211 | Evidently, you need to run a <filename>bitbake -c cleanall htop</filename>. |
| 2212 | Next, you delete or comment out the two <filename>SRC_URI</filename> |
| 2213 | lines at the end and then attempt to build the software with |
| 2214 | <filename>bitbake htop</filename>. |
| 2215 | Doing so causes BitBake to report some errors and and give |
| 2216 | you the actual strings you need for the last two |
| 2217 | <filename>SRC_URI</filename> lines. |
| 2218 | Prior to this, you have to dig around in the home page of the |
| 2219 | source for <filename>htop</filename> and determine that the |
| 2220 | software is released under GPLv2. |
| 2221 | You can provide that in the <filename>LICENSE</filename> |
| 2222 | statement. |
| 2223 | Now you edit your recipe to have those two strings for |
| 2224 | the <filename>SRC_URI</filename> statements: |
| 2225 | <literallayout class='monospaced'> |
| 2226 | LICENSE = "GPLv2" |
| 2227 | |
| 2228 | LIC_FILES_CHKSUM = "" |
| 2229 | |
| 2230 | SRC_URI = "${SOURCEFORGE_MIRROR}/htop/htop-${PV}.tar.gz" |
| 2231 | SRC_URI[md5sum] = "0d01cca8df3349c74569cefebbd9919e" |
| 2232 | SRC_URI[sha256sum] = "ee60657b044ece0df096c053060df7abf3cce3a568ab34d260049e6a37ccd8a1" |
| 2233 | </literallayout> |
| 2234 | At this point, you can build the software again using the |
| 2235 | <filename>bitbake htop</filename> command. |
| 2236 | There is just a set of errors now associated with the |
| 2237 | empty <filename>LIC_FILES_CHKSUM</filename> variable now. |
| 2238 | </para> |
| 2239 | --> |
| 2240 | |
| 2241 | </section> |
| 2242 | |
| 2243 | <section id='new-recipe-configuring-the-recipe'> |
| 2244 | <title>Configuring the Recipe</title> |
| 2245 | |
| 2246 | <para> |
| 2247 | Most software provides some means of setting build-time |
| 2248 | configuration options before compilation. |
| 2249 | Typically, setting these options is accomplished by running a |
| 2250 | configure script with some options, or by modifying a build |
| 2251 | configuration file. |
| 2252 | </para> |
| 2253 | |
| 2254 | <para> |
| 2255 | A major part of build-time configuration is about checking for |
| 2256 | build-time dependencies and possibly enabling optional |
| 2257 | functionality as a result. |
| 2258 | You need to specify any build-time dependencies for the |
| 2259 | software you are building in your recipe's |
| 2260 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink> |
| 2261 | value, in terms of other recipes that satisfy those |
| 2262 | dependencies. |
| 2263 | You can often find build-time or runtime |
| 2264 | dependencies described in the software's documentation. |
| 2265 | </para> |
| 2266 | |
| 2267 | <para> |
| 2268 | The following list provides configuration items of note based |
| 2269 | on how your software is built: |
| 2270 | <itemizedlist> |
| 2271 | <listitem><para><emphasis>Autotools:</emphasis> |
| 2272 | If your source files have a |
| 2273 | <filename>configure.ac</filename> file, then your |
| 2274 | software is built using Autotools. |
| 2275 | If this is the case, you just need to worry about |
| 2276 | modifying the configuration.</para> |
| 2277 | <para>When using Autotools, your recipe needs to inherit |
| 2278 | the |
| 2279 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink> |
| 2280 | class and your recipe does not have to contain a |
| 2281 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink> |
| 2282 | task. |
| 2283 | However, you might still want to make some adjustments. |
| 2284 | For example, you can set |
| 2285 | <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OECONF'><filename>EXTRA_OECONF</filename></ulink> |
| 2286 | to pass any needed configure options that are specific |
| 2287 | to the recipe.</para></listitem> |
| 2288 | <listitem><para><emphasis>CMake:</emphasis> |
| 2289 | If your source files have a |
| 2290 | <filename>CMakeLists.txt</filename> file, then your |
| 2291 | software is built using CMake. |
| 2292 | If this is the case, you just need to worry about |
| 2293 | modifying the configuration.</para> |
| 2294 | <para>When you use CMake, your recipe needs to inherit |
| 2295 | the |
| 2296 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-cmake'><filename>cmake</filename></ulink> |
| 2297 | class and your recipe does not have to contain a |
| 2298 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink> |
| 2299 | task. |
| 2300 | You can make some adjustments by setting |
| 2301 | <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OECMAKE'><filename>EXTRA_OECMAKE</filename></ulink> |
| 2302 | to pass any needed configure options that are specific |
| 2303 | to the recipe.</para></listitem> |
| 2304 | <listitem><para><emphasis>Other:</emphasis> |
| 2305 | If your source files do not have a |
| 2306 | <filename>configure.ac</filename> or |
| 2307 | <filename>CMakeLists.txt</filename> file, then your |
| 2308 | software is built using some method other than Autotools |
| 2309 | or CMake. |
| 2310 | If this is the case, you normally need to provide a |
| 2311 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink> |
| 2312 | task in your recipe |
| 2313 | unless, of course, there is nothing to configure. |
| 2314 | </para> |
| 2315 | <para>Even if your software is not being built by |
| 2316 | Autotools or CMake, you still might not need to deal |
| 2317 | with any configuration issues. |
| 2318 | You need to determine if configuration is even a required step. |
| 2319 | You might need to modify a Makefile or some configuration file |
| 2320 | used for the build to specify necessary build options. |
| 2321 | Or, perhaps you might need to run a provided, custom |
| 2322 | configure script with the appropriate options.</para> |
| 2323 | <para>For the case involving a custom configure |
| 2324 | script, you would run |
| 2325 | <filename>./configure --help</filename> and look for |
| 2326 | the options you need to set.</para></listitem> |
| 2327 | </itemizedlist> |
| 2328 | </para> |
| 2329 | |
| 2330 | <para> |
| 2331 | Once configuration succeeds, it is always good practice to |
| 2332 | look at the <filename>log.do_configure</filename> file to |
| 2333 | ensure that the appropriate options have been enabled and no |
| 2334 | additional build-time dependencies need to be added to |
| 2335 | <filename>DEPENDS</filename>. |
| 2336 | For example, if the configure script reports that it found |
| 2337 | something not mentioned in <filename>DEPENDS</filename>, or |
| 2338 | that it did not find something that it needed for some |
| 2339 | desired optional functionality, then you would need to add |
| 2340 | those to <filename>DEPENDS</filename>. |
| 2341 | Looking at the log might also reveal items being checked for, |
| 2342 | enabled, or both that you do not want, or items not being found |
| 2343 | that are in <filename>DEPENDS</filename>, in which case |
| 2344 | you would need to look at passing extra options to the |
| 2345 | configure script as needed. |
| 2346 | For reference information on configure options specific to the |
| 2347 | software you are building, you can consult the output of the |
| 2348 | <filename>./configure --help</filename> command within |
| 2349 | <filename>${S}</filename> or consult the software's upstream |
| 2350 | documentation. |
| 2351 | </para> |
| 2352 | </section> |
| 2353 | |
| 2354 | <section id='new-recipe-compilation'> |
| 2355 | <title>Compilation</title> |
| 2356 | |
| 2357 | <para> |
| 2358 | During a build, the <filename>do_compile</filename> task |
| 2359 | happens after source is fetched, unpacked, and configured. |
| 2360 | If the recipe passes through <filename>do_compile</filename> |
| 2361 | successfully, nothing needs to be done. |
| 2362 | </para> |
| 2363 | |
| 2364 | <para> |
| 2365 | However, if the compile step fails, you need to diagnose the |
| 2366 | failure. |
| 2367 | Here are some common issues that cause failures: |
| 2368 | <itemizedlist> |
| 2369 | <listitem><para><emphasis>Parallel build failures:</emphasis> |
| 2370 | These failures manifest themselves as intermittent |
| 2371 | errors, or errors reporting that a file or directory |
| 2372 | that should be created by some other part of the build |
| 2373 | process could not be found. |
| 2374 | This type of failure can occur even if, upon inspection, |
| 2375 | the file or directory does exist after the build has |
| 2376 | failed, because that part of the build process happened |
| 2377 | in the wrong order.</para> |
| 2378 | <para>To fix the problem, you need to either satisfy |
| 2379 | the missing dependency in the Makefile or whatever |
| 2380 | script produced the Makefile, or (as a workaround) |
| 2381 | set |
| 2382 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink> |
| 2383 | to an empty string: |
| 2384 | <literallayout class='monospaced'> |
| 2385 | PARALLEL_MAKE = "" |
| 2386 | </literallayout></para> |
| 2387 | <para> |
| 2388 | For information on parallel Makefile issues, see the |
| 2389 | "<link linkend='debugging-parallel-make-races'>Debugging Parallel Make Races</link>" |
| 2390 | section. |
| 2391 | </para></listitem> |
| 2392 | <listitem><para><emphasis>Improper host path usage:</emphasis> |
| 2393 | This failure applies to recipes building for the target |
| 2394 | or <filename>nativesdk</filename> only. |
| 2395 | The failure occurs when the compilation process uses |
| 2396 | improper headers, libraries, or other files from the |
| 2397 | host system when cross-compiling for the target. |
| 2398 | </para> |
| 2399 | <para>To fix the problem, examine the |
| 2400 | <filename>log.do_compile</filename> file to identify |
| 2401 | the host paths being used (e.g. |
| 2402 | <filename>/usr/include</filename>, |
| 2403 | <filename>/usr/lib</filename>, and so forth) and then |
| 2404 | either add configure options, apply a patch, or do both. |
| 2405 | </para></listitem> |
| 2406 | <listitem><para><emphasis>Failure to find required |
| 2407 | libraries/headers:</emphasis> |
| 2408 | If a build-time dependency is missing because it has |
| 2409 | not been declared in |
| 2410 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>, |
| 2411 | or because the dependency exists but the path used by |
| 2412 | the build process to find the file is incorrect and the |
| 2413 | configure step did not detect it, the compilation |
| 2414 | process could fail. |
| 2415 | For either of these failures, the compilation process |
| 2416 | notes that files could not be found. |
| 2417 | In these cases, you need to go back and add additional |
| 2418 | options to the configure script as well as possibly |
| 2419 | add additional build-time dependencies to |
| 2420 | <filename>DEPENDS</filename>.</para> |
| 2421 | <para>Occasionally, it is necessary to apply a patch |
| 2422 | to the source to ensure the correct paths are used. |
| 2423 | If you need to specify paths to find files staged |
| 2424 | into the sysroot from other recipes, use the variables |
| 2425 | that the OpenEmbedded build system provides |
| 2426 | (e.g. |
| 2427 | <filename>STAGING_BINDIR</filename>, |
| 2428 | <filename>STAGING_INCDIR</filename>, |
| 2429 | <filename>STAGING_DATADIR</filename>, and so forth). |
| 2430 | <!-- |
| 2431 | (e.g. |
| 2432 | <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_BINDIR'><filename>STAGING_BINDIR</filename></ulink>, |
| 2433 | <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_INCDIR'><filename>STAGING_INCDIR</filename></ulink>, |
| 2434 | <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_DATADIR'><filename>STAGING_DATADIR</filename></ulink>, |
| 2435 | and so forth). |
| 2436 | --> |
| 2437 | </para></listitem> |
| 2438 | </itemizedlist> |
| 2439 | </para> |
| 2440 | </section> |
| 2441 | |
| 2442 | <section id='new-recipe-installing'> |
| 2443 | <title>Installing</title> |
| 2444 | |
| 2445 | <para> |
| 2446 | During <filename>do_install</filename>, the task copies the |
| 2447 | built files along with their hierarchy to locations that |
| 2448 | would mirror their locations on the target device. |
| 2449 | The installation process copies files from the |
| 2450 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>, |
| 2451 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-B'><filename>B</filename></ulink><filename>}</filename>, |
| 2452 | and |
| 2453 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}</filename> |
| 2454 | directories to the |
| 2455 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink><filename>}</filename> |
| 2456 | directory to create the structure as it should appear on the |
| 2457 | target system. |
| 2458 | </para> |
| 2459 | |
| 2460 | <para> |
| 2461 | How your software is built affects what you must do to be |
| 2462 | sure your software is installed correctly. |
| 2463 | The following list describes what you must do for installation |
| 2464 | depending on the type of build system used by the software |
| 2465 | being built: |
| 2466 | <itemizedlist> |
| 2467 | <listitem><para><emphasis>Autotools and CMake:</emphasis> |
| 2468 | If the software your recipe is building uses Autotools |
| 2469 | or CMake, the OpenEmbedded build |
| 2470 | system understands how to install the software. |
| 2471 | Consequently, you do not have to have a |
| 2472 | <filename>do_install</filename> task as part of your |
| 2473 | recipe. |
| 2474 | You just need to make sure the install portion of the |
| 2475 | build completes with no issues. |
| 2476 | However, if you wish to install additional files not |
| 2477 | already being installed by |
| 2478 | <filename>make install</filename>, you should do this |
| 2479 | using a <filename>do_install_append</filename> function |
| 2480 | using the install command as described in |
| 2481 | the "Manual" bulleted item later in this list. |
| 2482 | </para></listitem> |
| 2483 | <listitem><para><emphasis>Other (using |
| 2484 | <filename>make install</filename>):</emphasis> |
| 2485 | You need to define a |
| 2486 | <filename>do_install</filename> function in your |
| 2487 | recipe. |
| 2488 | The function should call |
| 2489 | <filename>oe_runmake install</filename> and will likely |
| 2490 | need to pass in the destination directory as well. |
| 2491 | How you pass that path is dependent on how the |
| 2492 | <filename>Makefile</filename> being run is written |
| 2493 | (e.g. <filename>DESTDIR=${D}</filename>, |
| 2494 | <filename>PREFIX=${D}</filename>, |
| 2495 | <filename>INSTALLROOT=${D}</filename>, and so forth). |
| 2496 | </para> |
| 2497 | <para>For an example recipe using |
| 2498 | <filename>make install</filename>, see the |
| 2499 | "<link linkend='new-recipe-makefile-based-package'>Makefile-Based Package</link>" |
| 2500 | section.</para></listitem> |
| 2501 | <listitem><para><emphasis>Manual:</emphasis> |
| 2502 | You need to define a |
| 2503 | <filename>do_install</filename> function in your |
| 2504 | recipe. |
| 2505 | The function must first use |
| 2506 | <filename>install -d</filename> to create the |
| 2507 | directories under |
| 2508 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink><filename>}</filename>. |
| 2509 | Once the directories exist, your function can use |
| 2510 | <filename>install</filename> to manually install the |
| 2511 | built software into the directories.</para> |
| 2512 | <para>You can find more information on |
| 2513 | <filename>install</filename> at |
| 2514 | <ulink url='http://www.gnu.org/software/coreutils/manual/html_node/install-invocation.html'></ulink>. |
| 2515 | </para></listitem> |
| 2516 | </itemizedlist> |
| 2517 | </para> |
| 2518 | |
| 2519 | <para> |
| 2520 | For the scenarios that do not use Autotools or |
| 2521 | CMake, you need to track the installation |
| 2522 | and diagnose and fix any issues until everything installs |
| 2523 | correctly. |
| 2524 | You need to look in the default location of |
| 2525 | <filename>${D}</filename>, which is |
| 2526 | <filename>${WORKDIR}/image</filename>, to be sure your |
| 2527 | files have been installed correctly. |
| 2528 | </para> |
| 2529 | |
| 2530 | <note><title>Notes</title> |
| 2531 | <itemizedlist> |
| 2532 | <listitem><para> |
| 2533 | During the installation process, you might need to |
| 2534 | modify some of the installed files to suit the target |
| 2535 | layout. |
| 2536 | For example, you might need to replace hard-coded paths |
| 2537 | in an initscript with values of variables provided by |
| 2538 | the build system, such as replacing |
| 2539 | <filename>/usr/bin/</filename> with |
| 2540 | <filename>${bindir}</filename>. |
| 2541 | If you do perform such modifications during |
| 2542 | <filename>do_install</filename>, be sure to modify the |
| 2543 | destination file after copying rather than before |
| 2544 | copying. |
| 2545 | Modifying after copying ensures that the build system |
| 2546 | can re-execute <filename>do_install</filename> if |
| 2547 | needed. |
| 2548 | </para></listitem> |
| 2549 | <listitem><para> |
| 2550 | <filename>oe_runmake install</filename>, which can be |
| 2551 | run directly or can be run indirectly by the |
| 2552 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink> |
| 2553 | and |
| 2554 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-cmake'><filename>cmake</filename></ulink> |
| 2555 | classes, runs <filename>make install</filename> in |
| 2556 | parallel. |
| 2557 | Sometimes, a Makefile can have missing dependencies |
| 2558 | between targets that can result in race conditions. |
| 2559 | If you experience intermittent failures during |
| 2560 | <filename>do_install</filename>, you might be able to |
| 2561 | work around them by disabling parallel Makefile |
| 2562 | installs by adding the following to the recipe: |
| 2563 | <literallayout class='monospaced'> |
| 2564 | PARALLEL_MAKEINST = "" |
| 2565 | </literallayout> |
| 2566 | See |
| 2567 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKEINST'><filename>PARALLEL_MAKEINST</filename></ulink> |
| 2568 | for additional information. |
| 2569 | </para></listitem> |
| 2570 | </itemizedlist> |
| 2571 | </note> |
| 2572 | </section> |
| 2573 | |
| 2574 | <section id='new-recipe-enabling-system-services'> |
| 2575 | <title>Enabling System Services</title> |
| 2576 | |
| 2577 | <para> |
| 2578 | If you want to install a service, which is a process that |
| 2579 | usually starts on boot and runs in the background, then |
| 2580 | you must include some additional definitions in your recipe. |
| 2581 | </para> |
| 2582 | |
| 2583 | <para> |
| 2584 | If you are adding services and the service initialization |
| 2585 | script or the service file itself is not installed, you must |
| 2586 | provide for that installation in your recipe using a |
| 2587 | <filename>do_install_append</filename> function. |
| 2588 | If your recipe already has a <filename>do_install</filename> |
| 2589 | function, update the function near its end rather than |
| 2590 | adding an additional <filename>do_install_append</filename> |
| 2591 | function. |
| 2592 | </para> |
| 2593 | |
| 2594 | <para> |
| 2595 | When you create the installation for your services, you need |
| 2596 | to accomplish what is normally done by |
| 2597 | <filename>make install</filename>. |
| 2598 | In other words, make sure your installation arranges the output |
| 2599 | similar to how it is arranged on the target system. |
| 2600 | </para> |
| 2601 | |
| 2602 | <para> |
| 2603 | The OpenEmbedded build system provides support for starting |
| 2604 | services two different ways: |
| 2605 | <itemizedlist> |
| 2606 | <listitem><para><emphasis>SysVinit:</emphasis> |
| 2607 | SysVinit is a system and service manager that |
| 2608 | manages the init system used to control the very basic |
| 2609 | functions of your system. |
| 2610 | The init program is the first program |
| 2611 | started by the Linux kernel when the system boots. |
| 2612 | Init then controls the startup, running and shutdown |
| 2613 | of all other programs.</para> |
| 2614 | <para>To enable a service using SysVinit, your recipe |
| 2615 | needs to inherit the |
| 2616 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-update-rc.d'><filename>update-rc.d</filename></ulink> |
| 2617 | class. |
| 2618 | The class helps facilitate safely installing the |
| 2619 | package on the target.</para> |
| 2620 | <para>You will need to set the |
| 2621 | <ulink url='&YOCTO_DOCS_REF_URL;#var-INITSCRIPT_PACKAGES'><filename>INITSCRIPT_PACKAGES</filename></ulink>, |
| 2622 | <ulink url='&YOCTO_DOCS_REF_URL;#var-INITSCRIPT_NAME'><filename>INITSCRIPT_NAME</filename></ulink>, |
| 2623 | and |
| 2624 | <ulink url='&YOCTO_DOCS_REF_URL;#var-INITSCRIPT_PARAMS'><filename>INITSCRIPT_PARAMS</filename></ulink> |
| 2625 | variables within your recipe.</para></listitem> |
| 2626 | <listitem><para><emphasis>systemd:</emphasis> |
| 2627 | System Management Daemon (systemd) was designed to |
| 2628 | replace SysVinit and to provide |
| 2629 | enhanced management of services. |
| 2630 | For more information on systemd, see the systemd |
| 2631 | homepage at |
| 2632 | <ulink url='http://freedesktop.org/wiki/Software/systemd/'></ulink>. |
| 2633 | </para> |
| 2634 | <para>To enable a service using systemd, your recipe |
| 2635 | needs to inherit the |
| 2636 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-systemd'><filename>systemd</filename></ulink> |
| 2637 | class. |
| 2638 | See the <filename>systemd.bbclass</filename> file |
| 2639 | located in your |
| 2640 | <link linkend='source-directory'>Source Directory</link>. |
| 2641 | section for more information. |
| 2642 | </para></listitem> |
| 2643 | </itemizedlist> |
| 2644 | </para> |
| 2645 | </section> |
| 2646 | |
| 2647 | <section id='new-recipe-packaging'> |
| 2648 | <title>Packaging</title> |
| 2649 | |
| 2650 | <para> |
| 2651 | Successful packaging is a combination of automated processes |
| 2652 | performed by the OpenEmbedded build system and some |
| 2653 | specific steps you need to take. |
| 2654 | The following list describes the process: |
| 2655 | <itemizedlist> |
| 2656 | <listitem><para><emphasis>Splitting Files</emphasis>: |
| 2657 | The <filename>do_package</filename> task splits the |
| 2658 | files produced by the recipe into logical components. |
| 2659 | Even software that produces a single binary might |
| 2660 | still have debug symbols, documentation, and other |
| 2661 | logical components that should be split out. |
| 2662 | The <filename>do_package</filename> task ensures |
| 2663 | that files are split up and packaged correctly. |
| 2664 | </para></listitem> |
| 2665 | <listitem><para><emphasis>Running QA Checks</emphasis>: |
| 2666 | The |
| 2667 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-insane'><filename>insane</filename></ulink> |
| 2668 | class adds a step to |
| 2669 | the package generation process so that output quality |
| 2670 | assurance checks are generated by the OpenEmbedded |
| 2671 | build system. |
| 2672 | This step performs a range of checks to be sure the |
| 2673 | build's output is free of common problems that show |
| 2674 | up during runtime. |
| 2675 | For information on these checks, see the |
| 2676 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-insane'><filename>insane</filename></ulink> |
| 2677 | class and the |
| 2678 | "<ulink url='&YOCTO_DOCS_REF_URL;#ref-qa-checks'>QA Error and Warning Messages</ulink>" |
| 2679 | chapter in the Yocto Project Reference Manual. |
| 2680 | </para></listitem> |
| 2681 | <listitem><para><emphasis>Hand-Checking Your Packages</emphasis>: |
| 2682 | After you build your software, you need to be sure |
| 2683 | your packages are correct. |
| 2684 | Examine the |
| 2685 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/packages-split</filename> |
| 2686 | directory and make sure files are where you expect |
| 2687 | them to be. |
| 2688 | If you discover problems, you can set |
| 2689 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>, |
| 2690 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>, |
| 2691 | <filename>do_install(_append)</filename>, and so forth as |
| 2692 | needed. |
| 2693 | </para></listitem> |
| 2694 | <listitem><para><emphasis>Splitting an Application into Multiple Packages</emphasis>: |
| 2695 | If you need to split an application into several |
| 2696 | packages, see the |
| 2697 | "<link linkend='splitting-an-application-into-multiple-packages'>Splitting an Application into Multiple Packages</link>" |
| 2698 | section for an example. |
| 2699 | </para></listitem> |
| 2700 | <listitem><para><emphasis>Installing a Post-Installation Script</emphasis>: |
| 2701 | For an example showing how to install a |
| 2702 | post-installation script, see the |
| 2703 | "<link linkend='new-recipe-post-installation-scripts'>Post-Installation Scripts</link>" |
| 2704 | section. |
| 2705 | </para></listitem> |
| 2706 | <listitem><para><emphasis>Marking Package Architecture</emphasis>: |
| 2707 | Depending on what your recipe is building and how it |
| 2708 | is configured, it might be important to mark the |
| 2709 | packages produced as being specific to a particular |
| 2710 | machine, or to mark them as not being specific to |
| 2711 | a particular machine or architecture at all. |
| 2712 | By default, packages produced for the target are |
| 2713 | marked as being specific to the architecture of the |
| 2714 | target machine because that is usually the desired |
| 2715 | result. |
| 2716 | However, if the recipe configures the software to be |
| 2717 | built specific to the target machine (e.g. the |
| 2718 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink> |
| 2719 | value is passed into the configure script or a patch |
| 2720 | is applied only for a particular machine), then you |
| 2721 | should mark the packages produced as being |
| 2722 | machine-specific by adding the following to the |
| 2723 | recipe: |
| 2724 | <literallayout class='monospaced'> |
| 2725 | PACKAGE_ARCH = "${MACHINE_ARCH}" |
| 2726 | </literallayout> |
| 2727 | On the other hand, if the recipe produces packages |
| 2728 | that do not contain anything specific to the target |
| 2729 | machine or architecture at all (e.g. recipes |
| 2730 | that simply package script files or configuration |
| 2731 | files), you should use the |
| 2732 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-allarch'><filename>allarch</filename></ulink> |
| 2733 | class to do this for you by adding this to your |
| 2734 | recipe: |
| 2735 | <literallayout class='monospaced'> |
| 2736 | inherit allarch |
| 2737 | </literallayout> |
| 2738 | Ensuring that the package architecture is correct is |
| 2739 | not critical while you are doing the first few builds |
| 2740 | of your recipe. |
| 2741 | However, it is important in order |
| 2742 | to ensure that your recipe rebuilds (or does not |
| 2743 | rebuild) appropriately in response to changes in |
| 2744 | configuration, and to ensure that you get the |
| 2745 | appropriate packages installed on the target machine, |
| 2746 | particularly if you run separate builds for more |
| 2747 | than one target machine. |
| 2748 | </para></listitem> |
| 2749 | </itemizedlist> |
| 2750 | </para> |
| 2751 | </section> |
| 2752 | |
| 2753 | <section id='properly-versioning-pre-release-recipes'> |
| 2754 | <title>Properly Versioning Pre-Release Recipes</title> |
| 2755 | |
| 2756 | <para> |
| 2757 | Sometimes the name of a recipe can lead to versioning |
| 2758 | problems when the recipe is upgraded to a final release. |
| 2759 | For example, consider the |
| 2760 | <filename>irssi_0.8.16-rc1.bb</filename> recipe file in |
| 2761 | the list of example recipes in the |
| 2762 | "<link linkend='new-recipe-storing-and-naming-the-recipe'>Storing and Naming the Recipe</link>" |
| 2763 | section. |
| 2764 | This recipe is at a release candidate stage (i.e. |
| 2765 | "rc1"). |
| 2766 | When the recipe is released, the recipe filename becomes |
| 2767 | <filename>irssi_0.8.16.bb</filename>. |
| 2768 | The version change from <filename>0.8.16-rc1</filename> |
| 2769 | to <filename>0.8.16</filename> is seen as a decrease by the |
| 2770 | build system and package managers, so the resulting packages |
| 2771 | will not correctly trigger an upgrade. |
| 2772 | </para> |
| 2773 | |
| 2774 | <para> |
| 2775 | In order to ensure the versions compare properly, the |
| 2776 | recommended convention is to set |
| 2777 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink> |
| 2778 | within the recipe to |
| 2779 | "<replaceable>previous_version</replaceable>+<replaceable>current_version</replaceable>". |
| 2780 | You can use an additional variable so that you can use the |
| 2781 | current version elsewhere. |
| 2782 | Here is an example: |
| 2783 | <literallayout class='monospaced'> |
| 2784 | REALPV = "0.8.16-rc1" |
| 2785 | PV = "0.8.15+${REALPV}" |
| 2786 | </literallayout> |
| 2787 | </para> |
| 2788 | </section> |
| 2789 | |
| 2790 | <section id='new-recipe-post-installation-scripts'> |
| 2791 | <title>Post-Installation Scripts</title> |
| 2792 | |
| 2793 | <para> |
| 2794 | Post-installation scripts run immediately after installing |
| 2795 | a package on the target or during image creation when a |
| 2796 | package is included in an image. |
| 2797 | To add a post-installation script to a package, add a |
| 2798 | <filename>pkg_postinst_PACKAGENAME()</filename> function to |
| 2799 | the recipe file (<filename>.bb</filename>) and replace |
| 2800 | <filename>PACKAGENAME</filename> with the name of the package |
| 2801 | you want to attach to the <filename>postinst</filename> |
| 2802 | script. |
| 2803 | To apply the post-installation script to the main package |
| 2804 | for the recipe, which is usually what is required, specify |
| 2805 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename> |
| 2806 | in place of <filename>PACKAGENAME</filename>. |
| 2807 | </para> |
| 2808 | |
| 2809 | <para> |
| 2810 | A post-installation function has the following structure: |
| 2811 | <literallayout class='monospaced'> |
| 2812 | pkg_postinst_PACKAGENAME() { |
| 2813 | # Commands to carry out |
| 2814 | } |
| 2815 | </literallayout> |
| 2816 | </para> |
| 2817 | |
| 2818 | <para> |
| 2819 | The script defined in the post-installation function is |
| 2820 | called when the root filesystem is created. |
| 2821 | If the script succeeds, the package is marked as installed. |
| 2822 | If the script fails, the package is marked as unpacked and |
| 2823 | the script is executed when the image boots again. |
| 2824 | </para> |
| 2825 | |
| 2826 | <para> |
| 2827 | Sometimes it is necessary for the execution of a |
| 2828 | post-installation script to be delayed until the first boot. |
| 2829 | For example, the script might need to be executed on the |
| 2830 | device itself. |
| 2831 | To delay script execution until boot time, use the following |
| 2832 | structure in the post-installation script: |
| 2833 | <literallayout class='monospaced'> |
| 2834 | pkg_postinst_PACKAGENAME() { |
| 2835 | if [ x"$D" = "x" ]; then |
| 2836 | # Actions to carry out on the device go here |
| 2837 | else |
| 2838 | exit 1 |
| 2839 | fi |
| 2840 | } |
| 2841 | </literallayout> |
| 2842 | </para> |
| 2843 | |
| 2844 | <para> |
| 2845 | The previous example delays execution until the image boots |
| 2846 | again because the environment variable <filename>D</filename> |
| 2847 | points to the directory containing the image when |
| 2848 | the root filesystem is created at build time but is unset |
| 2849 | when executed on the first boot. |
| 2850 | </para> |
| 2851 | |
| 2852 | <note> |
| 2853 | Equivalent support for pre-install, pre-uninstall, and |
| 2854 | post-uninstall scripts exist by way of |
| 2855 | <filename>pkg_preinst</filename>, |
| 2856 | <filename>pkg_prerm</filename>, and |
| 2857 | <filename>pkg_postrm</filename>, respectively. |
| 2858 | These scrips work in exactly the same way as does |
| 2859 | <filename>pkg_postinst</filename> with the exception that they |
| 2860 | run at different times. |
| 2861 | Also, because of when they run, they are not applicable to |
| 2862 | being run at image creation time like |
| 2863 | <filename>pkg_postinst</filename>. |
| 2864 | </note> |
| 2865 | </section> |
| 2866 | |
| 2867 | <section id='new-recipe-testing'> |
| 2868 | <title>Testing</title> |
| 2869 | |
| 2870 | <para> |
| 2871 | The final step for completing your recipe is to be sure that |
| 2872 | the software you built runs correctly. |
| 2873 | To accomplish runtime testing, add the build's output |
| 2874 | packages to your image and test them on the target. |
| 2875 | </para> |
| 2876 | |
| 2877 | <para> |
| 2878 | For information on how to customize your image by adding |
| 2879 | specific packages, see the |
| 2880 | "<link linkend='usingpoky-extend-customimage'>Customizing Images</link>" |
| 2881 | section. |
| 2882 | </para> |
| 2883 | </section> |
| 2884 | |
| 2885 | <section id='new-recipe-testing-examples'> |
| 2886 | <title>Examples</title> |
| 2887 | |
| 2888 | <para> |
| 2889 | To help summarize how to write a recipe, this section provides |
| 2890 | some examples given various scenarios: |
| 2891 | <itemizedlist> |
| 2892 | <listitem><para>Recipes that use local files</para></listitem> |
| 2893 | <listitem><para>Using an Autotooled package</para></listitem> |
| 2894 | <listitem><para>Using a Makefile-based package</para></listitem> |
| 2895 | <listitem><para>Splitting an application into multiple packages</para></listitem> |
| 2896 | <listitem><para>Adding binaries to an image</para></listitem> |
| 2897 | </itemizedlist> |
| 2898 | </para> |
| 2899 | |
| 2900 | <section id='new-recipe-single-c-file-package-hello-world'> |
| 2901 | <title>Single .c File Package (Hello World!)</title> |
| 2902 | |
| 2903 | <para> |
| 2904 | Building an application from a single file that is stored |
| 2905 | locally (e.g. under <filename>files</filename>) requires |
| 2906 | a recipe that has the file listed in the |
| 2907 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename> |
| 2908 | variable. |
| 2909 | Additionally, you need to manually write the |
| 2910 | <filename>do_compile</filename> and |
| 2911 | <filename>do_install</filename> tasks. |
| 2912 | The <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'>S</ulink></filename> |
| 2913 | variable defines the directory containing the source code, |
| 2914 | which is set to |
| 2915 | <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink> |
| 2916 | in this case - the directory BitBake uses for the build. |
| 2917 | <literallayout class='monospaced'> |
| 2918 | SUMMARY = "Simple helloworld application" |
| 2919 | SECTION = "examples" |
| 2920 | LICENSE = "MIT" |
| 2921 | LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" |
| 2922 | |
| 2923 | SRC_URI = "file://helloworld.c" |
| 2924 | |
| 2925 | S = "${WORKDIR}" |
| 2926 | |
| 2927 | do_compile() { |
| 2928 | ${CC} helloworld.c -o helloworld |
| 2929 | } |
| 2930 | |
| 2931 | do_install() { |
| 2932 | install -d ${D}${bindir} |
| 2933 | install -m 0755 helloworld ${D}${bindir} |
| 2934 | } |
| 2935 | </literallayout> |
| 2936 | </para> |
| 2937 | |
| 2938 | <para> |
| 2939 | By default, the <filename>helloworld</filename>, |
| 2940 | <filename>helloworld-dbg</filename>, and |
| 2941 | <filename>helloworld-dev</filename> packages are built. |
| 2942 | For information on how to customize the packaging process, |
| 2943 | see the |
| 2944 | "<link linkend='splitting-an-application-into-multiple-packages'>Splitting an Application into Multiple Packages</link>" |
| 2945 | section. |
| 2946 | </para> |
| 2947 | </section> |
| 2948 | |
| 2949 | <section id='new-recipe-autotooled-package'> |
| 2950 | <title>Autotooled Package</title> |
| 2951 | <para> |
| 2952 | Applications that use Autotools such as <filename>autoconf</filename> and |
| 2953 | <filename>automake</filename> require a recipe that has a source archive listed in |
| 2954 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename> and |
| 2955 | also inherit the |
| 2956 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink> |
| 2957 | class, which contains the definitions of all the steps |
| 2958 | needed to build an Autotool-based application. |
| 2959 | The result of the build is automatically packaged. |
| 2960 | And, if the application uses NLS for localization, packages with local information are |
| 2961 | generated (one package per language). |
| 2962 | Following is one example: (<filename>hello_2.3.bb</filename>) |
| 2963 | <literallayout class='monospaced'> |
| 2964 | SUMMARY = "GNU Helloworld application" |
| 2965 | SECTION = "examples" |
| 2966 | LICENSE = "GPLv2+" |
| 2967 | LIC_FILES_CHKSUM = "file://COPYING;md5=751419260aa954499f7abaabaa882bbe" |
| 2968 | |
| 2969 | SRC_URI = "${GNU_MIRROR}/hello/hello-${PV}.tar.gz" |
| 2970 | |
| 2971 | inherit autotools gettext |
| 2972 | </literallayout> |
| 2973 | </para> |
| 2974 | |
| 2975 | <para> |
| 2976 | The variable |
| 2977 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'>LIC_FILES_CHKSUM</ulink></filename> |
| 2978 | is used to track source license changes as described in the |
| 2979 | "<ulink url='&YOCTO_DOCS_REF_URL;#usingpoky-configuring-LIC_FILES_CHKSUM'>Tracking License Changes</ulink>" section. |
| 2980 | You can quickly create Autotool-based recipes in a manner similar to the previous example. |
| 2981 | </para> |
| 2982 | </section> |
| 2983 | |
| 2984 | <section id='new-recipe-makefile-based-package'> |
| 2985 | <title>Makefile-Based Package</title> |
| 2986 | |
| 2987 | <para> |
| 2988 | Applications that use GNU <filename>make</filename> also require a recipe that has |
| 2989 | the source archive listed in |
| 2990 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>. |
| 2991 | You do not need to add a <filename>do_compile</filename> step since by default BitBake |
| 2992 | starts the <filename>make</filename> command to compile the application. |
| 2993 | If you need additional <filename>make</filename> options, you should store them in the |
| 2994 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OEMAKE'>EXTRA_OEMAKE</ulink></filename> |
| 2995 | variable. |
| 2996 | BitBake passes these options into the GNU <filename>make</filename> invocation. |
| 2997 | Note that a <filename>do_install</filename> task is still required. |
| 2998 | Otherwise, BitBake runs an empty <filename>do_install</filename> task by default. |
| 2999 | </para> |
| 3000 | |
| 3001 | <para> |
| 3002 | Some applications might require extra parameters to be passed to the compiler. |
| 3003 | For example, the application might need an additional header path. |
| 3004 | You can accomplish this by adding to the |
| 3005 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-CFLAGS'>CFLAGS</ulink></filename> variable. |
| 3006 | The following example shows this: |
| 3007 | <literallayout class='monospaced'> |
| 3008 | CFLAGS_prepend = "-I ${S}/include " |
| 3009 | </literallayout> |
| 3010 | </para> |
| 3011 | |
| 3012 | <para> |
| 3013 | In the following example, <filename>mtd-utils</filename> is a makefile-based package: |
| 3014 | <literallayout class='monospaced'> |
| 3015 | SUMMARY = "Tools for managing memory technology devices" |
| 3016 | SECTION = "base" |
| 3017 | DEPENDS = "zlib lzo e2fsprogs util-linux" |
| 3018 | HOMEPAGE = "http://www.linux-mtd.infradead.org/" |
| 3019 | LICENSE = "GPLv2+" |
| 3020 | LIC_FILES_CHKSUM = "file://COPYING;md5=0636e73ff0215e8d672dc4c32c317bb3 \ |
| 3021 | file://include/common.h;beginline=1;endline=17;md5=ba05b07912a44ea2bf81ce409380049c" |
| 3022 | |
| 3023 | # Use the latest version at 26 Oct, 2013 |
| 3024 | SRCREV = "9f107132a6a073cce37434ca9cda6917dd8d866b" |
| 3025 | SRC_URI = "git://git.infradead.org/mtd-utils.git \ |
| 3026 | file://add-exclusion-to-mkfs-jffs2-git-2.patch \ |
| 3027 | " |
| 3028 | |
| 3029 | PV = "1.5.1+git${SRCPV}" |
| 3030 | |
| 3031 | S = "${WORKDIR}/git/" |
| 3032 | |
| 3033 | EXTRA_OEMAKE = "'CC=${CC}' 'RANLIB=${RANLIB}' 'AR=${AR}' 'CFLAGS=${CFLAGS} -I${S}/include -DWITHOUT_XATTR' 'BUILDDIR=${S}'" |
| 3034 | |
| 3035 | do_install () { |
| 3036 | oe_runmake install DESTDIR=${D} SBINDIR=${sbindir} MANDIR=${mandir} INCLUDEDIR=${includedir} |
| 3037 | } |
| 3038 | |
| 3039 | PACKAGES =+ "mtd-utils-jffs2 mtd-utils-ubifs mtd-utils-misc" |
| 3040 | |
| 3041 | FILES_mtd-utils-jffs2 = "${sbindir}/mkfs.jffs2 ${sbindir}/jffs2dump ${sbindir}/jffs2reader ${sbindir}/sumtool" |
| 3042 | FILES_mtd-utils-ubifs = "${sbindir}/mkfs.ubifs ${sbindir}/ubi*" |
| 3043 | FILES_mtd-utils-misc = "${sbindir}/nftl* ${sbindir}/ftl* ${sbindir}/rfd* ${sbindir}/doc* ${sbindir}/serve_image ${sbindir}/recv_image" |
| 3044 | |
| 3045 | PARALLEL_MAKE = "" |
| 3046 | |
| 3047 | BBCLASSEXTEND = "native" |
| 3048 | </literallayout> |
| 3049 | </para> |
| 3050 | </section> |
| 3051 | |
| 3052 | <section id='splitting-an-application-into-multiple-packages'> |
| 3053 | <title>Splitting an Application into Multiple Packages</title> |
| 3054 | |
| 3055 | <para> |
| 3056 | You can use the variables |
| 3057 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'>PACKAGES</ulink></filename> and |
| 3058 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'>FILES</ulink></filename> |
| 3059 | to split an application into multiple packages. |
| 3060 | </para> |
| 3061 | |
| 3062 | <para> |
| 3063 | Following is an example that uses the <filename>libxpm</filename> recipe. |
| 3064 | By default, this recipe generates a single package that contains the library along |
| 3065 | with a few binaries. |
| 3066 | You can modify the recipe to split the binaries into separate packages: |
| 3067 | <literallayout class='monospaced'> |
| 3068 | require xorg-lib-common.inc |
| 3069 | |
| 3070 | SUMMARY = "Xpm: X Pixmap extension library" |
| 3071 | LICENSE = "BSD" |
| 3072 | LIC_FILES_CHKSUM = "file://COPYING;md5=51f4270b012ecd4ab1a164f5f4ed6cf7" |
| 3073 | DEPENDS += "libxext libsm libxt" |
| 3074 | PE = "1" |
| 3075 | |
| 3076 | XORG_PN = "libXpm" |
| 3077 | |
| 3078 | PACKAGES =+ "sxpm cxpm" |
| 3079 | FILES_cxpm = "${bindir}/cxpm" |
| 3080 | FILES_sxpm = "${bindir}/sxpm" |
| 3081 | </literallayout> |
| 3082 | </para> |
| 3083 | |
| 3084 | <para> |
| 3085 | In the previous example, we want to ship the <filename>sxpm</filename> |
| 3086 | and <filename>cxpm</filename> binaries in separate packages. |
| 3087 | Since <filename>bindir</filename> would be packaged into the main |
| 3088 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'>PN</ulink></filename> |
| 3089 | package by default, we prepend the <filename>PACKAGES</filename> |
| 3090 | variable so additional package names are added to the start of list. |
| 3091 | This results in the extra <filename>FILES_*</filename> |
| 3092 | variables then containing information that define which files and |
| 3093 | directories go into which packages. |
| 3094 | Files included by earlier packages are skipped by latter packages. |
| 3095 | Thus, the main <filename>PN</filename> package |
| 3096 | does not include the above listed files. |
| 3097 | </para> |
| 3098 | </section> |
| 3099 | |
| 3100 | <section id='packaging-externally-produced-binaries'> |
| 3101 | <title>Packaging Externally Produced Binaries</title> |
| 3102 | |
| 3103 | <para> |
| 3104 | Sometimes, you need to add pre-compiled binaries to an |
| 3105 | image. |
| 3106 | For example, suppose that binaries for proprietary code |
| 3107 | exist, which are created by a particular division of a |
| 3108 | company. |
| 3109 | Your part of the company needs to use those binaries as |
| 3110 | part of an image that you are building using the |
| 3111 | OpenEmbedded build system. |
| 3112 | Since you only have the binaries and not the source code, |
| 3113 | you cannot use a typical recipe that expects to fetch the |
| 3114 | source specified in |
| 3115 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> |
| 3116 | and then compile it. |
| 3117 | </para> |
| 3118 | |
| 3119 | <para> |
| 3120 | One method is to package the binaries and then install them |
| 3121 | as part of the image. |
| 3122 | Generally, it is not a good idea to package binaries |
| 3123 | since, among other things, it can hinder the ability to |
| 3124 | reproduce builds and could lead to compatibility problems |
| 3125 | with ABI in the future. |
| 3126 | However, sometimes you have no choice. |
| 3127 | </para> |
| 3128 | |
| 3129 | <para> |
| 3130 | The easiest solution is to create a recipe that uses |
| 3131 | the |
| 3132 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-bin-package'><filename>bin_package</filename></ulink> |
| 3133 | class and to be sure that you are using default locations |
| 3134 | for build artifacts. |
| 3135 | In most cases, the <filename>bin_package</filename> class |
| 3136 | handles "skipping" the configure and compile steps as well |
| 3137 | as sets things up to grab packages from the appropriate |
| 3138 | area. |
| 3139 | In particular, this class sets <filename>noexec</filename> |
| 3140 | on both the |
| 3141 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink> |
| 3142 | and |
| 3143 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink> |
| 3144 | tasks, sets |
| 3145 | <filename>FILES_${PN}</filename> to "/" so that it picks |
| 3146 | up all files, and sets up a |
| 3147 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink> |
| 3148 | task, which effectively copies all files from |
| 3149 | <filename>${S}</filename> to <filename>${D}</filename>. |
| 3150 | The <filename>bin_package</filename> class works well when |
| 3151 | the files extracted into <filename>${S}</filename> are |
| 3152 | already laid out in the way they should be laid out |
| 3153 | on the target. |
| 3154 | For more information on these variables, see the |
| 3155 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>, |
| 3156 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>, |
| 3157 | <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>, |
| 3158 | and |
| 3159 | <ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink> |
| 3160 | variables in the Yocto Project Reference Manual's variable |
| 3161 | glossary. |
| 3162 | </para> |
| 3163 | |
| 3164 | <para> |
| 3165 | If you can't use the <filename>bin_package</filename> |
| 3166 | class, you need to be sure you are doing the following: |
| 3167 | <itemizedlist> |
| 3168 | <listitem><para>Create a recipe where the |
| 3169 | <filename>do_configure</filename> and |
| 3170 | <filename>do_compile</filename> tasks do nothing: |
| 3171 | <literallayout class='monospaced'> |
| 3172 | do_configure[noexec] = "1" |
| 3173 | do_compile[noexec] = "1" |
| 3174 | </literallayout> |
| 3175 | Alternatively, you can make these tasks an empty |
| 3176 | function. |
| 3177 | </para></listitem> |
| 3178 | <listitem><para>Make sure your |
| 3179 | <filename>do_install</filename> task installs the |
| 3180 | binaries appropriately. |
| 3181 | </para></listitem> |
| 3182 | <listitem><para>Ensure that you set up |
| 3183 | <filename>FILES</filename> (usually |
| 3184 | <filename>FILES_${PN}</filename>) to point to the |
| 3185 | files you have installed, which of course depends |
| 3186 | on where you have installed them and whether |
| 3187 | those files are in different locations than the |
| 3188 | defaults. |
| 3189 | </para></listitem> |
| 3190 | </itemizedlist> |
| 3191 | </para> |
| 3192 | </section> |
| 3193 | </section> |
| 3194 | </section> |
| 3195 | |
| 3196 | <section id="platdev-newmachine"> |
| 3197 | <title>Adding a New Machine</title> |
| 3198 | |
| 3199 | <para> |
| 3200 | Adding a new machine to the Yocto Project is a straightforward |
| 3201 | process. |
| 3202 | This section describes how to add machines that are similar |
| 3203 | to those that the Yocto Project already supports. |
| 3204 | <note> |
| 3205 | Although well within the capabilities of the Yocto Project, |
| 3206 | adding a totally new architecture might require |
| 3207 | changes to <filename>gcc/glibc</filename> and to the site |
| 3208 | information, which is beyond the scope of this manual. |
| 3209 | </note> |
| 3210 | </para> |
| 3211 | |
| 3212 | <para> |
| 3213 | For a complete example that shows how to add a new machine, |
| 3214 | see the |
| 3215 | "<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>" |
| 3216 | section in the Yocto Project Board Support Package (BSP) Developer's Guide. |
| 3217 | </para> |
| 3218 | |
| 3219 | <section id="platdev-newmachine-conffile"> |
| 3220 | <title>Adding the Machine Configuration File</title> |
| 3221 | |
| 3222 | <para> |
| 3223 | To add a new machine, you need to add a new machine |
| 3224 | configuration file to the layer's |
| 3225 | <filename>conf/machine</filename> directory. |
| 3226 | This configuration file provides details about the device |
| 3227 | you are adding. |
| 3228 | </para> |
| 3229 | |
| 3230 | <para> |
| 3231 | The OpenEmbedded build system uses the root name of the |
| 3232 | machine configuration file to reference the new machine. |
| 3233 | For example, given a machine configuration file named |
| 3234 | <filename>crownbay.conf</filename>, the build system |
| 3235 | recognizes the machine as "crownbay". |
| 3236 | </para> |
| 3237 | |
| 3238 | <para> |
| 3239 | The most important variables you must set in your machine |
| 3240 | configuration file or include from a lower-level configuration |
| 3241 | file are as follows: |
| 3242 | <itemizedlist> |
| 3243 | <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TARGET_ARCH'>TARGET_ARCH</ulink></filename> |
| 3244 | (e.g. "arm")</para></listitem> |
| 3245 | <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PREFERRED_PROVIDER'>PREFERRED_PROVIDER</ulink>_virtual/kernel</filename> |
| 3246 | </para></listitem> |
| 3247 | <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES'>MACHINE_FEATURES</ulink></filename> |
| 3248 | (e.g. "apm screen wifi")</para></listitem> |
| 3249 | </itemizedlist> |
| 3250 | </para> |
| 3251 | |
| 3252 | <para> |
| 3253 | You might also need these variables: |
| 3254 | <itemizedlist> |
| 3255 | <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SERIAL_CONSOLES'>SERIAL_CONSOLES</ulink></filename> |
| 3256 | (e.g. "115200;ttyS0 115200;ttyS1")</para></listitem> |
| 3257 | <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_IMAGETYPE'>KERNEL_IMAGETYPE</ulink></filename> |
| 3258 | (e.g. "zImage")</para></listitem> |
| 3259 | <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FSTYPES'>IMAGE_FSTYPES</ulink></filename> |
| 3260 | (e.g. "tar.gz jffs2")</para></listitem> |
| 3261 | </itemizedlist> |
| 3262 | </para> |
| 3263 | |
| 3264 | <para> |
| 3265 | You can find full details on these variables in the reference |
| 3266 | section. |
| 3267 | You can leverage existing machine <filename>.conf</filename> |
| 3268 | files from <filename>meta-yocto-bsp/conf/machine/</filename>. |
| 3269 | </para> |
| 3270 | </section> |
| 3271 | |
| 3272 | <section id="platdev-newmachine-kernel"> |
| 3273 | <title>Adding a Kernel for the Machine</title> |
| 3274 | |
| 3275 | <para> |
| 3276 | The OpenEmbedded build system needs to be able to build a kernel |
| 3277 | for the machine. |
| 3278 | You need to either create a new kernel recipe for this machine, |
| 3279 | or extend an existing kernel recipe. |
| 3280 | You can find several kernel recipe examples in the |
| 3281 | Source Directory at |
| 3282 | <filename>meta/recipes-kernel/linux</filename> |
| 3283 | that you can use as references. |
| 3284 | </para> |
| 3285 | |
| 3286 | <para> |
| 3287 | If you are creating a new kernel recipe, normal recipe-writing |
| 3288 | rules apply for setting up a |
| 3289 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>. |
| 3290 | Thus, you need to specify any necessary patches and set |
| 3291 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'>S</ulink></filename> |
| 3292 | to point at the source code. |
| 3293 | You need to create a <filename>do_configure</filename> task that |
| 3294 | configures the unpacked kernel with a |
| 3295 | <filename>defconfig</filename> file. |
| 3296 | You can do this by using a <filename>make defconfig</filename> |
| 3297 | command or, more commonly, by copying in a suitable |
| 3298 | <filename>defconfig</filename> file and then running |
| 3299 | <filename>make oldconfig</filename>. |
| 3300 | By making use of <filename>inherit kernel</filename> and |
| 3301 | potentially some of the <filename>linux-*.inc</filename> files, |
| 3302 | most other functionality is centralized and the defaults of the |
| 3303 | class normally work well. |
| 3304 | </para> |
| 3305 | |
| 3306 | <para> |
| 3307 | If you are extending an existing kernel recipe, it is usually |
| 3308 | a matter of adding a suitable <filename>defconfig</filename> |
| 3309 | file. |
| 3310 | The file needs to be added into a location similar to |
| 3311 | <filename>defconfig</filename> files used for other machines |
| 3312 | in a given kernel recipe. |
| 3313 | A possible way to do this is by listing the file in the |
| 3314 | <filename>SRC_URI</filename> and adding the machine to the |
| 3315 | expression in |
| 3316 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-COMPATIBLE_MACHINE'>COMPATIBLE_MACHINE</ulink></filename>: |
| 3317 | <literallayout class='monospaced'> |
| 3318 | COMPATIBLE_MACHINE = '(qemux86|qemumips)' |
| 3319 | </literallayout> |
| 3320 | For more information on <filename>defconfig</filename> files, |
| 3321 | see the |
| 3322 | "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#changing-the-configuration'>Changing the Configuration</ulink>" |
| 3323 | section in the Yocto Project Linux Kernel Development Manual. |
| 3324 | </para> |
| 3325 | </section> |
| 3326 | |
| 3327 | <section id="platdev-newmachine-formfactor"> |
| 3328 | <title>Adding a Formfactor Configuration File</title> |
| 3329 | |
| 3330 | <para> |
| 3331 | A formfactor configuration file provides information about the |
| 3332 | target hardware for which the image is being built and information that |
| 3333 | the build system cannot obtain from other sources such as the kernel. |
| 3334 | Some examples of information contained in a formfactor configuration file include |
| 3335 | framebuffer orientation, whether or not the system has a keyboard, |
| 3336 | the positioning of the keyboard in relation to the screen, and |
| 3337 | the screen resolution. |
| 3338 | </para> |
| 3339 | |
| 3340 | <para> |
| 3341 | The build system uses reasonable defaults in most cases. |
| 3342 | However, if customization is |
| 3343 | necessary, you need to create a <filename>machconfig</filename> file |
| 3344 | in the <filename>meta/recipes-bsp/formfactor/files</filename> |
| 3345 | directory. |
| 3346 | This directory contains directories for specific machines such as |
| 3347 | <filename>qemuarm</filename> and <filename>qemux86</filename>. |
| 3348 | For information about the settings available and the defaults, see the |
| 3349 | <filename>meta/recipes-bsp/formfactor/files/config</filename> file found in the |
| 3350 | same area. |
| 3351 | </para> |
| 3352 | |
| 3353 | <para> |
| 3354 | Following is an example for "qemuarm" machine: |
| 3355 | <literallayout class='monospaced'> |
| 3356 | HAVE_TOUCHSCREEN=1 |
| 3357 | HAVE_KEYBOARD=1 |
| 3358 | |
| 3359 | DISPLAY_CAN_ROTATE=0 |
| 3360 | DISPLAY_ORIENTATION=0 |
| 3361 | #DISPLAY_WIDTH_PIXELS=640 |
| 3362 | #DISPLAY_HEIGHT_PIXELS=480 |
| 3363 | #DISPLAY_BPP=16 |
| 3364 | DISPLAY_DPI=150 |
| 3365 | DISPLAY_SUBPIXEL_ORDER=vrgb |
| 3366 | </literallayout> |
| 3367 | </para> |
| 3368 | </section> |
| 3369 | </section> |
| 3370 | |
| 3371 | <section id="platdev-working-with-libraries"> |
| 3372 | <title>Working With Libraries</title> |
| 3373 | |
| 3374 | <para> |
| 3375 | Libraries are an integral part of your system. |
| 3376 | This section describes some common practices you might find |
| 3377 | helpful when working with libraries to build your system: |
| 3378 | <itemizedlist> |
| 3379 | <listitem><para><link linkend='including-static-library-files'>How to include static library files</link> |
| 3380 | </para></listitem> |
| 3381 | <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> |
| 3382 | </para></listitem> |
| 3383 | <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> |
| 3384 | </para></listitem> |
| 3385 | </itemizedlist> |
| 3386 | </para> |
| 3387 | |
| 3388 | <section id='including-static-library-files'> |
| 3389 | <title>Including Static Library Files</title> |
| 3390 | |
| 3391 | <para> |
| 3392 | If you are building a library and the library offers static linking, you can control |
| 3393 | which static library files (<filename>*.a</filename> files) get included in the |
| 3394 | built library. |
| 3395 | </para> |
| 3396 | |
| 3397 | <para> |
| 3398 | The <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink> |
| 3399 | and <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES_*</filename></ulink> |
| 3400 | variables in the |
| 3401 | <filename>meta/conf/bitbake.conf</filename> configuration file define how files installed |
| 3402 | by the <filename>do_install</filename> task are packaged. |
| 3403 | By default, the <filename>PACKAGES</filename> variable includes |
| 3404 | <filename>${PN}-staticdev</filename>, which represents all static library files. |
| 3405 | <note> |
| 3406 | Some previously released versions of the Yocto Project |
| 3407 | defined the static library files through |
| 3408 | <filename>${PN}-dev</filename>. |
| 3409 | </note> |
| 3410 | Following is part of the BitBake configuration file, where |
| 3411 | you can see how the static library files are defined: |
| 3412 | <literallayout class='monospaced'> |
| 3413 | PACKAGE_BEFORE_PN ?= "" |
| 3414 | PACKAGES = "${PN}-dbg ${PN}-staticdev ${PN}-dev ${PN}-doc ${PN}-locale ${PACKAGE_BEFORE_PN} ${PN}" |
| 3415 | PACKAGES_DYNAMIC = "^${PN}-locale-.*" |
| 3416 | FILES = "" |
| 3417 | |
| 3418 | FILES_${PN} = "${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*${SOLIBS} \ |
| 3419 | ${sysconfdir} ${sharedstatedir} ${localstatedir} \ |
| 3420 | ${base_bindir}/* ${base_sbindir}/* \ |
| 3421 | ${base_libdir}/*${SOLIBS} \ |
| 3422 | ${base_prefix}/lib/udev/rules.d ${prefix}/lib/udev/rules.d \ |
| 3423 | ${datadir}/${BPN} ${libdir}/${BPN}/* \ |
| 3424 | ${datadir}/pixmaps ${datadir}/applications \ |
| 3425 | ${datadir}/idl ${datadir}/omf ${datadir}/sounds \ |
| 3426 | ${libdir}/bonobo/servers" |
| 3427 | |
| 3428 | FILES_${PN}-bin = "${bindir}/* ${sbindir}/*" |
| 3429 | |
| 3430 | FILES_${PN}-doc = "${docdir} ${mandir} ${infodir} ${datadir}/gtk-doc \ |
| 3431 | ${datadir}/gnome/help" |
| 3432 | SECTION_${PN}-doc = "doc" |
| 3433 | |
| 3434 | FILES_SOLIBSDEV ?= "${base_libdir}/lib*${SOLIBSDEV} ${libdir}/lib*${SOLIBSDEV}" |
| 3435 | FILES_${PN}-dev = "${includedir} ${FILES_SOLIBSDEV} ${libdir}/*.la \ |
| 3436 | ${libdir}/*.o ${libdir}/pkgconfig ${datadir}/pkgconfig \ |
| 3437 | ${datadir}/aclocal ${base_libdir}/*.o \ |
| 3438 | ${libdir}/${BPN}/*.la ${base_libdir}/*.la" |
| 3439 | SECTION_${PN}-dev = "devel" |
| 3440 | ALLOW_EMPTY_${PN}-dev = "1" |
| 3441 | RDEPENDS_${PN}-dev = "${PN} (= ${EXTENDPKGV})" |
| 3442 | |
| 3443 | FILES_${PN}-staticdev = "${libdir}/*.a ${base_libdir}/*.a ${libdir}/${BPN}/*.a" |
| 3444 | SECTION_${PN}-staticdev = "devel" |
| 3445 | RDEPENDS_${PN}-staticdev = "${PN}-dev (= ${EXTENDPKGV})" |
| 3446 | </literallayout> |
| 3447 | </para> |
| 3448 | </section> |
| 3449 | |
| 3450 | <section id="combining-multiple-versions-library-files-into-one-image"> |
| 3451 | <title>Combining Multiple Versions of Library Files into One Image</title> |
| 3452 | |
| 3453 | <para> |
| 3454 | The build system offers the ability to build libraries with different |
| 3455 | target optimizations or architecture formats and combine these together |
| 3456 | into one system image. |
| 3457 | You can link different binaries in the image |
| 3458 | against the different libraries as needed for specific use cases. |
| 3459 | This feature is called "Multilib." |
| 3460 | </para> |
| 3461 | |
| 3462 | <para> |
| 3463 | An example would be where you have most of a system compiled in 32-bit |
| 3464 | mode using 32-bit libraries, but you have something large, like a database |
| 3465 | engine, that needs to be a 64-bit application and uses 64-bit libraries. |
| 3466 | Multilib allows you to get the best of both 32-bit and 64-bit libraries. |
| 3467 | </para> |
| 3468 | |
| 3469 | <para> |
| 3470 | While the Multilib feature is most commonly used for 32 and 64-bit differences, |
| 3471 | the approach the build system uses facilitates different target optimizations. |
| 3472 | You could compile some binaries to use one set of libraries and other binaries |
| 3473 | to use a different set of libraries. |
| 3474 | The libraries could differ in architecture, compiler options, or other |
| 3475 | optimizations. |
| 3476 | </para> |
| 3477 | |
| 3478 | <para> |
| 3479 | This section overviews the Multilib process only. |
| 3480 | For more details on how to implement Multilib, see the |
| 3481 | <ulink url='&YOCTO_WIKI_URL;/wiki/Multilib'>Multilib</ulink> wiki |
| 3482 | page. |
| 3483 | </para> |
| 3484 | |
| 3485 | <para> |
| 3486 | Aside from this wiki page, several examples exist in the |
| 3487 | <filename>meta-skeleton</filename> layer found in the |
| 3488 | <link linkend='source-directory'>Source Directory</link>: |
| 3489 | <itemizedlist> |
| 3490 | <listitem><para><filename>conf/multilib-example.conf</filename> |
| 3491 | configuration file</para></listitem> |
| 3492 | <listitem><para><filename>conf/multilib-example2.conf</filename> |
| 3493 | configuration file</para></listitem> |
| 3494 | <listitem><para><filename>recipes-multilib/images/core-image-multilib-example.bb</filename> |
| 3495 | recipe</para></listitem> |
| 3496 | </itemizedlist> |
| 3497 | </para> |
| 3498 | |
| 3499 | <section id='preparing-to-use-multilib'> |
| 3500 | <title>Preparing to Use Multilib</title> |
| 3501 | |
| 3502 | <para> |
| 3503 | User-specific requirements drive the Multilib feature. |
| 3504 | Consequently, there is no one "out-of-the-box" configuration that likely |
| 3505 | exists to meet your needs. |
| 3506 | </para> |
| 3507 | |
| 3508 | <para> |
| 3509 | In order to enable Multilib, you first need to ensure your recipe is |
| 3510 | extended to support multiple libraries. |
| 3511 | Many standard recipes are already extended and support multiple libraries. |
| 3512 | You can check in the <filename>meta/conf/multilib.conf</filename> |
| 3513 | configuration file in the |
| 3514 | <link linkend='source-directory'>Source Directory</link> to see how this is |
| 3515 | done using the |
| 3516 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BBCLASSEXTEND'><filename>BBCLASSEXTEND</filename></ulink> |
| 3517 | variable. |
| 3518 | Eventually, all recipes will be covered and this list will |
| 3519 | not be needed. |
| 3520 | </para> |
| 3521 | |
| 3522 | <para> |
| 3523 | For the most part, the Multilib class extension works automatically to |
| 3524 | extend the package name from <filename>${PN}</filename> to |
| 3525 | <filename>${MLPREFIX}${PN}</filename>, where <filename>MLPREFIX</filename> |
| 3526 | is the particular multilib (e.g. "lib32-" or "lib64-"). |
| 3527 | Standard variables such as |
| 3528 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>, |
| 3529 | <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>, |
| 3530 | <ulink url='&YOCTO_DOCS_REF_URL;#var-RPROVIDES'><filename>RPROVIDES</filename></ulink>, |
| 3531 | <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>, |
| 3532 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>, and |
| 3533 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES_DYNAMIC'><filename>PACKAGES_DYNAMIC</filename></ulink> |
| 3534 | are automatically extended by the system. |
| 3535 | If you are extending any manual code in the recipe, you can use the |
| 3536 | <filename>${MLPREFIX}</filename> variable to ensure those names are extended |
| 3537 | correctly. |
| 3538 | This automatic extension code resides in <filename>multilib.bbclass</filename>. |
| 3539 | </para> |
| 3540 | </section> |
| 3541 | |
| 3542 | <section id='using-multilib'> |
| 3543 | <title>Using Multilib</title> |
| 3544 | |
| 3545 | <para> |
| 3546 | After you have set up the recipes, you need to define the actual |
| 3547 | combination of multiple libraries you want to build. |
| 3548 | You accomplish this through your <filename>local.conf</filename> |
| 3549 | configuration file in the |
| 3550 | <link linkend='build-directory'>Build Directory</link>. |
| 3551 | An example configuration would be as follows: |
| 3552 | <literallayout class='monospaced'> |
| 3553 | MACHINE = "qemux86-64" |
| 3554 | require conf/multilib.conf |
| 3555 | MULTILIBS = "multilib:lib32" |
| 3556 | DEFAULTTUNE_virtclass-multilib-lib32 = "x86" |
| 3557 | IMAGE_INSTALL = "lib32-connman" |
| 3558 | </literallayout> |
| 3559 | This example enables an |
| 3560 | additional library named <filename>lib32</filename> alongside the |
| 3561 | normal target packages. |
| 3562 | When combining these "lib32" alternatives, the example uses "x86" for tuning. |
| 3563 | For information on this particular tuning, see |
| 3564 | <filename>meta/conf/machine/include/ia32/arch-ia32.inc</filename>. |
| 3565 | </para> |
| 3566 | |
| 3567 | <para> |
| 3568 | The example then includes <filename>lib32-connman</filename> |
| 3569 | in all the images, which illustrates one method of including a |
| 3570 | multiple library dependency. |
| 3571 | You can use a normal image build to include this dependency, |
| 3572 | for example: |
| 3573 | <literallayout class='monospaced'> |
| 3574 | $ bitbake core-image-sato |
| 3575 | </literallayout> |
| 3576 | You can also build Multilib packages specifically with a command like this: |
| 3577 | <literallayout class='monospaced'> |
| 3578 | $ bitbake lib32-connman |
| 3579 | </literallayout> |
| 3580 | </para> |
| 3581 | </section> |
| 3582 | |
| 3583 | <section id='additional-implementation-details'> |
| 3584 | <title>Additional Implementation Details</title> |
| 3585 | |
| 3586 | <para> |
| 3587 | Different packaging systems have different levels of native Multilib |
| 3588 | support. |
| 3589 | For the RPM Package Management System, the following implementation details |
| 3590 | exist: |
| 3591 | <itemizedlist> |
| 3592 | <listitem><para>A unique architecture is defined for the Multilib packages, |
| 3593 | along with creating a unique deploy folder under |
| 3594 | <filename>tmp/deploy/rpm</filename> in the |
| 3595 | <link linkend='build-directory'>Build Directory</link>. |
| 3596 | For example, consider <filename>lib32</filename> in a |
| 3597 | <filename>qemux86-64</filename> image. |
| 3598 | The possible architectures in the system are "all", "qemux86_64", |
| 3599 | "lib32_qemux86_64", and "lib32_x86".</para></listitem> |
| 3600 | <listitem><para>The <filename>${MLPREFIX}</filename> variable is stripped from |
| 3601 | <filename>${PN}</filename> during RPM packaging. |
| 3602 | The naming for a normal RPM package and a Multilib RPM package in a |
| 3603 | <filename>qemux86-64</filename> system resolves to something similar to |
| 3604 | <filename>bash-4.1-r2.x86_64.rpm</filename> and |
| 3605 | <filename>bash-4.1.r2.lib32_x86.rpm</filename>, respectively. |
| 3606 | </para></listitem> |
| 3607 | <listitem><para>When installing a Multilib image, the RPM backend first |
| 3608 | installs the base image and then installs the Multilib libraries. |
| 3609 | </para></listitem> |
| 3610 | <listitem><para>The build system relies on RPM to resolve the identical files in the |
| 3611 | two (or more) Multilib packages.</para></listitem> |
| 3612 | </itemizedlist> |
| 3613 | </para> |
| 3614 | |
| 3615 | <para> |
| 3616 | For the IPK Package Management System, the following implementation details exist: |
| 3617 | <itemizedlist> |
| 3618 | <listitem><para>The <filename>${MLPREFIX}</filename> is not stripped from |
| 3619 | <filename>${PN}</filename> during IPK packaging. |
| 3620 | The naming for a normal RPM package and a Multilib IPK package in a |
| 3621 | <filename>qemux86-64</filename> system resolves to something like |
| 3622 | <filename>bash_4.1-r2.x86_64.ipk</filename> and |
| 3623 | <filename>lib32-bash_4.1-rw_x86.ipk</filename>, respectively. |
| 3624 | </para></listitem> |
| 3625 | <listitem><para>The IPK deploy folder is not modified with |
| 3626 | <filename>${MLPREFIX}</filename> because packages with and without |
| 3627 | the Multilib feature can exist in the same folder due to the |
| 3628 | <filename>${PN}</filename> differences.</para></listitem> |
| 3629 | <listitem><para>IPK defines a sanity check for Multilib installation |
| 3630 | using certain rules for file comparison, overridden, etc. |
| 3631 | </para></listitem> |
| 3632 | </itemizedlist> |
| 3633 | </para> |
| 3634 | </section> |
| 3635 | </section> |
| 3636 | |
| 3637 | <section id='installing-multiple-versions-of-the-same-library'> |
| 3638 | <title>Installing Multiple Versions of the Same Library</title> |
| 3639 | |
| 3640 | <para> |
| 3641 | Situations can exist where you need to install and use |
| 3642 | multiple versions of the same library on the same system |
| 3643 | at the same time. |
| 3644 | These situations almost always exist when a library API |
| 3645 | changes and you have multiple pieces of software that |
| 3646 | depend on the separate versions of the library. |
| 3647 | To accommodate these situations, you can install multiple |
| 3648 | versions of the same library in parallel on the same system. |
| 3649 | </para> |
| 3650 | |
| 3651 | <para> |
| 3652 | The process is straightforward as long as the libraries use |
| 3653 | proper versioning. |
| 3654 | With properly versioned libraries, all you need to do to |
| 3655 | individually specify the libraries is create separate, |
| 3656 | appropriately named recipes where the |
| 3657 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink> part of the |
| 3658 | name includes a portion that differentiates each library version |
| 3659 | (e.g.the major part of the version number). |
| 3660 | Thus, instead of having a single recipe that loads one version |
| 3661 | of a library (e.g. <filename>clutter</filename>), you provide |
| 3662 | multiple recipes that result in different versions |
| 3663 | of the libraries you want. |
| 3664 | As an example, the following two recipes would allow the |
| 3665 | two separate versions of the <filename>clutter</filename> |
| 3666 | library to co-exist on the same system: |
| 3667 | <literallayout class='monospaced'> |
| 3668 | clutter-1.6_1.6.20.bb |
| 3669 | clutter-1.8_1.8.4.bb |
| 3670 | </literallayout> |
| 3671 | Additionally, if you have other recipes that depend on a given |
| 3672 | library, you need to use the |
| 3673 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink> |
| 3674 | variable to create the dependency. |
| 3675 | Continuing with the same example, if you want to have a recipe |
| 3676 | depend on the 1.8 version of the <filename>clutter</filename> |
| 3677 | library, use the following in your recipe: |
| 3678 | <literallayout class='monospaced'> |
| 3679 | DEPENDS = "clutter-1.8" |
| 3680 | </literallayout> |
| 3681 | </para> |
| 3682 | </section> |
| 3683 | </section> |
| 3684 | |
| 3685 | <section id='creating-partitioned-images'> |
| 3686 | <title>Creating Partitioned Images</title> |
| 3687 | |
| 3688 | <para> |
| 3689 | Creating an image for a particular hardware target using the |
| 3690 | OpenEmbedded build system does not necessarily mean you can boot |
| 3691 | that image as is on your device. |
| 3692 | Physical devices accept and boot images in various ways depending |
| 3693 | on the specifics of the device. |
| 3694 | Usually, information about the hardware can tell you what image |
| 3695 | format the device requires. |
| 3696 | Should your device require multiple partitions on an SD card, flash, |
| 3697 | or an HDD, you can use the OpenEmbedded Image Creator, |
| 3698 | <filename>wic</filename>, to create the properly partitioned image. |
| 3699 | </para> |
| 3700 | |
| 3701 | <para> |
| 3702 | The <filename>wic</filename> command generates partitioned images |
| 3703 | from existing OpenEmbedded build artifacts. |
| 3704 | Image generation is driven by partitioning commands contained |
| 3705 | in an Openembedded kickstart file (<filename>.wks</filename>) |
| 3706 | specified either directly on the command line or as one of a |
| 3707 | selection of canned <filename>.wks</filename> files as shown |
| 3708 | with the <filename>wic list images</filename> command in the |
| 3709 | "<link linkend='using-a-provided-kickstart_file'>Using an Existing Kickstart File</link>" |
| 3710 | section. |
| 3711 | When applied to a given set of build artifacts, the result is an |
| 3712 | image or set of images that can be directly written onto media and |
| 3713 | used on a particular system. |
| 3714 | </para> |
| 3715 | |
| 3716 | <para> |
| 3717 | The <filename>wic</filename> command and the infrastructure |
| 3718 | it is based on is by definition incomplete. |
| 3719 | Its purpose is to allow the generation of customized images, |
| 3720 | and as such was designed to be completely extensible through a |
| 3721 | plugin interface. |
| 3722 | See the |
| 3723 | "<link linkend='openembedded-kickstart-plugins'>Plugins</link>" |
| 3724 | section for information on these plugins. |
| 3725 | </para> |
| 3726 | |
| 3727 | <para> |
| 3728 | This section provides some background information on |
| 3729 | <filename>wic</filename>, describes what you need to have in |
| 3730 | place to run the tool, provides instruction on how to use |
| 3731 | <filename>wic</filename>, and provides several examples. |
| 3732 | </para> |
| 3733 | |
| 3734 | <section id='wic-background'> |
| 3735 | <title>Background</title> |
| 3736 | |
| 3737 | <para> |
| 3738 | This section provides some background on the |
| 3739 | <filename>wic</filename> utility. |
| 3740 | While none of this information is required to use |
| 3741 | <filename>wic</filename>, you might find it interesting. |
| 3742 | <itemizedlist> |
| 3743 | <listitem><para> |
| 3744 | The name "wic" is derived from OpenEmbedded |
| 3745 | Image Creator (oeic). |
| 3746 | The "oe" diphthong in "oeic" was promoted to the |
| 3747 | letter "w", because "oeic" is both difficult to remember and |
| 3748 | pronounce.</para></listitem> |
| 3749 | <listitem><para> |
| 3750 | <filename>wic</filename> is loosely based on the |
| 3751 | Meego Image Creator (<filename>mic</filename>) |
| 3752 | framework. |
| 3753 | The <filename>wic</filename> implementation has been |
| 3754 | heavily modified to make direct use of OpenEmbedded |
| 3755 | build artifacts instead of package installation and |
| 3756 | configuration, which are already incorporated within |
| 3757 | the OpenEmbedded artifacts.</para></listitem> |
| 3758 | <listitem><para> |
| 3759 | <filename>wic</filename> is a completely independent |
| 3760 | standalone utility that initially provides |
| 3761 | easier-to-use and more flexible replacements for a |
| 3762 | couple bits of existing functionality in OE Core's |
| 3763 | <filename>boot-directdisk.bbclass</filename> and |
| 3764 | <filename>mkefidisk.sh</filename> scripts. |
| 3765 | The difference between |
| 3766 | <filename>wic</filename> and those examples is |
| 3767 | that with <filename>wic</filename> the |
| 3768 | functionality of those scripts is implemented |
| 3769 | by a general-purpose partitioning language, which is |
| 3770 | based on Redhat kickstart syntax.</para></listitem> |
| 3771 | </itemizedlist> |
| 3772 | </para> |
| 3773 | </section> |
| 3774 | |
| 3775 | <section id='wic-requirements'> |
| 3776 | <title>Requirements</title> |
| 3777 | |
| 3778 | <para> |
| 3779 | In order to use the <filename>wic</filename> utility |
| 3780 | with the OpenEmbedded Build system, your system needs |
| 3781 | to meet the following requirements: |
| 3782 | <itemizedlist> |
| 3783 | <listitem><para>The Linux distribution on your |
| 3784 | development host must support the Yocto Project. |
| 3785 | See the |
| 3786 | "<ulink url='&YOCTO_DOCS_REF_URL;#detailed-supported-distros'>Supported Linux Distributions</ulink>" |
| 3787 | section in the Yocto Project Reference Manual for this |
| 3788 | list of distributions.</para></listitem> |
| 3789 | <listitem><para> |
| 3790 | The standard system utilities, such as |
| 3791 | <filename>cp</filename>, must be installed on your |
| 3792 | development host system. |
| 3793 | </para></listitem> |
| 3794 | <listitem><para> |
| 3795 | You need to have the build artifacts already |
| 3796 | available, which typically means that you must |
| 3797 | have already created an image using the |
| 3798 | Openembedded build system (e.g. |
| 3799 | <filename>core-image-minimal</filename>). |
| 3800 | While it might seem redundant to generate an image in |
| 3801 | order to create an image using |
| 3802 | <filename>wic</filename>, the current version of |
| 3803 | <filename>wic</filename> requires the artifacts |
| 3804 | in the form generated by the build system. |
| 3805 | </para></listitem> |
| 3806 | <listitem><para> |
| 3807 | You must build several native tools: |
| 3808 | <literallayout class='monospaced'> |
| 3809 | $ bitbake parted-native dosfstools-native mtools-native |
| 3810 | </literallayout> |
| 3811 | </para></listitem> |
| 3812 | <listitem><para> |
| 3813 | You must have sourced one of the build environment |
| 3814 | setup scripts (i.e. |
| 3815 | <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink> |
| 3816 | or |
| 3817 | <ulink url='&YOCTO_DOCS_REF_URL;#structure-memres-core-script'><filename>oe-init-build-env-memres</filename></ulink>) |
| 3818 | found in the |
| 3819 | <link linkend='build-directory'>Build Directory</link>. |
| 3820 | </para></listitem> |
| 3821 | </itemizedlist> |
| 3822 | </para> |
| 3823 | </section> |
| 3824 | |
| 3825 | <section id='wic-getting-help'> |
| 3826 | <title>Getting Help</title> |
| 3827 | |
| 3828 | <para> |
| 3829 | You can get general help for the <filename>wic</filename> |
| 3830 | by entering the <filename>wic</filename> command by itself |
| 3831 | or by entering the command with a help argument as follows: |
| 3832 | <literallayout class='monospaced'> |
| 3833 | $ wic -h |
| 3834 | $ wic --help |
| 3835 | </literallayout> |
| 3836 | </para> |
| 3837 | |
| 3838 | <para> |
| 3839 | Currently, <filename>wic</filename> supports two commands: |
| 3840 | <filename>create</filename> and <filename>list</filename>. |
| 3841 | You can get help for these commands as follows: |
| 3842 | <literallayout class='monospaced'> |
| 3843 | $ wic help <replaceable>command</replaceable> |
| 3844 | </literallayout> |
| 3845 | </para> |
| 3846 | |
| 3847 | <para> |
| 3848 | You can also get detailed help on a number of topics |
| 3849 | from the help system. |
| 3850 | The output of <filename>wic --help</filename> |
| 3851 | displays a list of available help |
| 3852 | topics under a "Help topics" heading. |
| 3853 | You can have the help system display the help text for |
| 3854 | a given topic by prefacing the topic with |
| 3855 | <filename>wic help</filename>: |
| 3856 | <literallayout class='monospaced'> |
| 3857 | $ wic help <replaceable>help_topic</replaceable> |
| 3858 | </literallayout> |
| 3859 | </para> |
| 3860 | |
| 3861 | <para> |
| 3862 | You can find out more about the images |
| 3863 | <filename>wic</filename> creates using the existing |
| 3864 | kickstart files with the following form of the command: |
| 3865 | <literallayout class='monospaced'> |
| 3866 | $ wic list <replaceable>image</replaceable> help |
| 3867 | </literallayout> |
| 3868 | where <filename><replaceable>image</replaceable></filename> is either |
| 3869 | <filename>directdisk</filename> or |
| 3870 | <filename>mkefidisk</filename>. |
| 3871 | </para> |
| 3872 | </section> |
| 3873 | |
| 3874 | <section id='operational-modes'> |
| 3875 | <title>Operational Modes</title> |
| 3876 | |
| 3877 | <para> |
| 3878 | You can use <filename>wic</filename> in two different |
| 3879 | modes, depending on how much control you need for |
| 3880 | specifying the Openembedded build artifacts that are |
| 3881 | used for creating the image: Raw and Cooked: |
| 3882 | <itemizedlist> |
| 3883 | <listitem><para><emphasis>Raw Mode:</emphasis> |
| 3884 | You explicitly specify build artifacts through |
| 3885 | command-line arguments.</para></listitem> |
| 3886 | <listitem><para><emphasis>Cooked Mode:</emphasis> |
| 3887 | The current |
| 3888 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink> |
| 3889 | setting and image name are used to automatically locate |
| 3890 | and provide the build artifacts.</para></listitem> |
| 3891 | </itemizedlist> |
| 3892 | </para> |
| 3893 | |
| 3894 | <para> |
| 3895 | Regardless of the mode you use, you need to have the build |
| 3896 | artifacts ready and available. |
| 3897 | Additionally, the environment must be set up using the |
| 3898 | <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink> |
| 3899 | or |
| 3900 | <ulink url='&YOCTO_DOCS_REF_URL;#structure-memres-core-script'><filename>oe-init-build-env-memres</filename></ulink> |
| 3901 | script found in the |
| 3902 | <link linkend='build-directory'>Build Directory</link>. |
| 3903 | </para> |
| 3904 | |
| 3905 | <section id='raw-mode'> |
| 3906 | <title>Raw Mode</title> |
| 3907 | |
| 3908 | <para> |
| 3909 | The general form of the 'wic' command in raw mode is: |
| 3910 | <literallayout class='monospaced'> |
| 3911 | $ wic create <replaceable>image_name</replaceable>.wks [<replaceable>options</replaceable>] [...] |
| 3912 | |
| 3913 | Where: |
| 3914 | |
| 3915 | <replaceable>image_name</replaceable>.wks |
| 3916 | An OpenEmbedded kickstart file. You can provide |
| 3917 | your own custom file or use a file from a set of |
| 3918 | existing files as described by further options. |
| 3919 | |
| 3920 | -o <replaceable>OUTDIR</replaceable>, --outdir=<replaceable>OUTDIR</replaceable> |
| 3921 | The name of a directory in which to create image. |
| 3922 | |
| 3923 | -i <replaceable>PROPERTIES_FILE</replaceable>, --infile=<replaceable>PROPERTIES_FILE</replaceable> |
| 3924 | The name of a file containing the values for image |
| 3925 | properties as a JSON file. |
| 3926 | |
| 3927 | -e <replaceable>IMAGE_NAME</replaceable>, --image-name=<replaceable>IMAGE_NAME</replaceable> |
| 3928 | The name of the image from which to use the artifacts |
| 3929 | (e.g. <filename>core-image-sato</filename>). |
| 3930 | |
| 3931 | -r <replaceable>ROOTFS_DIR</replaceable>, --rootfs-dir=<replaceable>ROOTFS_DIR</replaceable> |
| 3932 | The path to the <filename>/rootfs</filename> directory to use as the |
| 3933 | <filename>.wks</filename> rootfs source. |
| 3934 | |
| 3935 | -b <replaceable>BOOTIMG_DIR</replaceable>, --bootimg-dir=<replaceable>BOOTIMG_DIR</replaceable> |
| 3936 | The path to the directory containing the boot artifacts |
| 3937 | (e.g. <filename>/EFI</filename> or <filename>/syslinux</filename>) to use as the <filename>.wks</filename> bootimg |
| 3938 | source. |
| 3939 | |
| 3940 | -k <replaceable>KERNEL_DIR</replaceable>, --kernel-dir=<replaceable>KERNEL_DIR</replaceable> |
| 3941 | The path to the directory containing the kernel to use |
| 3942 | in the <filename>.wks</filename> boot image. |
| 3943 | |
| 3944 | -n <replaceable>NATIVE_SYSROOT</replaceable>, --native-sysroot=<replaceable>NATIVE_SYSROOT</replaceable> |
| 3945 | The path to the native sysroot containing the tools to use |
| 3946 | to build the image. |
| 3947 | |
| 3948 | -s, --skip-build-check |
| 3949 | Skips the build check. |
| 3950 | |
| 3951 | -D, --debug |
| 3952 | Output debug information. |
| 3953 | </literallayout> |
| 3954 | <note> |
| 3955 | You do not need root privileges to run |
| 3956 | <filename>wic</filename>. |
| 3957 | In fact, you should not run as root when using the |
| 3958 | utility. |
| 3959 | </note> |
| 3960 | </para> |
| 3961 | </section> |
| 3962 | |
| 3963 | <section id='cooked-mode'> |
| 3964 | <title>Cooked Mode</title> |
| 3965 | |
| 3966 | <para> |
| 3967 | The general form of the <filename>wic</filename> command |
| 3968 | using Cooked Mode is: |
| 3969 | <literallayout class='monospaced'> |
| 3970 | $ wic create <replaceable>kickstart_file</replaceable> -e <replaceable>image_name</replaceable> |
| 3971 | |
| 3972 | Where: |
| 3973 | |
| 3974 | <replaceable>kickstart_file</replaceable> |
| 3975 | An OpenEmbedded kickstart file. You can provide your own |
| 3976 | custom file or supplied file. |
| 3977 | |
| 3978 | <replaceable>image_name</replaceable> |
| 3979 | Specifies the image built using the OpenEmbedded build |
| 3980 | system. |
| 3981 | </literallayout> |
| 3982 | This form is the simplest and most user-friendly, as it |
| 3983 | does not require specifying all individual parameters. |
| 3984 | All you need to provide is your own |
| 3985 | <filename>.wks</filename> file or one provided with the |
| 3986 | release. |
| 3987 | </para> |
| 3988 | </section> |
| 3989 | </section> |
| 3990 | |
| 3991 | <section id='using-a-provided-kickstart_file'> |
| 3992 | <title>Using an Existing Kickstart File</title> |
| 3993 | |
| 3994 | <para> |
| 3995 | If you do not want to create your own |
| 3996 | <filename>.wks</filename> file, you can use an existing |
| 3997 | file provided by the <filename>wic</filename> installation. |
| 3998 | Use the following command to list the available files: |
| 3999 | <literallayout class='monospaced'> |
| 4000 | $ wic list images |
| 4001 | directdisk Create a 'pcbios' direct disk image |
| 4002 | mkefidisk Create an EFI disk image |
| 4003 | </literallayout> |
| 4004 | When you use an existing file, you do not have to use the |
| 4005 | <filename>.wks</filename> extension. |
| 4006 | Here is an example in Raw Mode that uses the |
| 4007 | <filename>directdisk</filename> file: |
| 4008 | <literallayout class='monospaced'> |
| 4009 | $ wic create directdisk -r <replaceable>rootfs_dir</replaceable> -b <replaceable>bootimg_dir</replaceable> \ |
| 4010 | -k <replaceable>kernel_dir</replaceable> -n <replaceable>native_sysroot</replaceable> |
| 4011 | </literallayout> |
| 4012 | </para> |
| 4013 | |
| 4014 | <para> |
| 4015 | Here are the actual partition language commands |
| 4016 | used in the <filename>mkefidisk.wks</filename> file to generate |
| 4017 | an image: |
| 4018 | <literallayout class='monospaced'> |
| 4019 | # short-description: Create an EFI disk image |
| 4020 | # long-description: Creates a partitioned EFI disk image that the user |
| 4021 | # can directly dd to boot media. |
| 4022 | |
| 4023 | part /boot --source bootimg-efi --ondisk sda --label msdos --active --align 1024 |
| 4024 | |
| 4025 | part / --source rootfs --ondisk sda --fstype=ext3 --label platform --align 1024 |
| 4026 | |
| 4027 | part swap --ondisk sda --size 44 --label swap1 --fstype=swap |
| 4028 | |
| 4029 | bootloader --timeout=10 --append="rootwait rootfstype=ext3 console=ttyPCH0,115200 console=tty0 vmalloc=256MB snd-hda-intel.enable_msi=0" |
| 4030 | </literallayout> |
| 4031 | </para> |
| 4032 | </section> |
| 4033 | |
| 4034 | <section id='wic-usage-examples'> |
| 4035 | <title>Examples</title> |
| 4036 | |
| 4037 | <para> |
| 4038 | This section provides several examples that show how to use |
| 4039 | the <filename>wic</filename> utility. |
| 4040 | All the examples assume the list of requirements in the |
| 4041 | "<link linkend='wic-requirements'>Requirements</link>" section |
| 4042 | have been met. |
| 4043 | The examples assume the previously generated image is |
| 4044 | <filename>core-image-minimal</filename>. |
| 4045 | </para> |
| 4046 | |
| 4047 | <section id='generate-an-image-using-a-provided-kickstart-file'> |
| 4048 | <title>Generate an Image using an Existing Kickstart File</title> |
| 4049 | |
| 4050 | <para> |
| 4051 | This example runs in Cooked Mode and uses the |
| 4052 | <filename>mkefidisk</filename> kickstart file: |
| 4053 | <literallayout class='monospaced'> |
| 4054 | $ wic create mkefidisk -e core-image-minimal |
| 4055 | Checking basic build environment... |
| 4056 | Done. |
| 4057 | |
| 4058 | Creating image(s)... |
| 4059 | |
| 4060 | Info: The new image(s) can be found here: |
| 4061 | /var/tmp/wic/build/mkefidisk-201310230946-sda.direct |
| 4062 | |
| 4063 | The following build artifacts were used to create the image(s): |
| 4064 | ROOTFS_DIR: /home/trz/yocto/yocto-image/build/tmp/work/minnow-poky-linux/core-image-minimal/1.0-r0/rootfs |
| 4065 | 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 |
| 4066 | KERNEL_DIR: /home/trz/yocto/yocto-image/build/tmp/sysroots/minnow/usr/src/kernel |
| 4067 | NATIVE_SYSROOT: /home/trz/yocto/yocto-image/build/tmp/sysroots/x86_64-linux |
| 4068 | |
| 4069 | |
| 4070 | The image(s) were created using OE kickstart file: |
| 4071 | /home/trz/yocto/yocto-image/scripts/lib/image/canned-wks/mkefidisk.wks |
| 4072 | </literallayout> |
| 4073 | This example shows the easiest way to create an image |
| 4074 | by running in Cooked Mode and using the |
| 4075 | <filename>-e</filename> option with an existing kickstart |
| 4076 | file. |
| 4077 | All that is necessary is to specify the image used to |
| 4078 | generate the artifacts. |
| 4079 | Your <filename>local.conf</filename> needs to have the |
| 4080 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink> |
| 4081 | variable set to the machine you are using, which is |
| 4082 | "minnow" in this example. |
| 4083 | </para> |
| 4084 | |
| 4085 | <para> |
| 4086 | The output specifies the exact created as well as where |
| 4087 | it was created. |
| 4088 | The output also names the artifacts used and the exact |
| 4089 | <filename>.wks</filename> script that was used to generate |
| 4090 | the image. |
| 4091 | <note> |
| 4092 | You should always verify the details provided in the |
| 4093 | output to make sure that the image was indeed created |
| 4094 | exactly as expected. |
| 4095 | </note> |
| 4096 | </para> |
| 4097 | |
| 4098 | <para> |
| 4099 | Continuing with the example, you can now directly |
| 4100 | <filename>dd</filename> the image to a USB stick, or |
| 4101 | whatever media for which you built your image, |
| 4102 | and boot the resulting media: |
| 4103 | <literallayout class='monospaced'> |
| 4104 | $ sudo dd if=/var/tmp/wic/build/mkefidisk-201310230946-sda.direct of=/dev/sdb |
| 4105 | [sudo] password for trz: |
| 4106 | 182274+0 records in |
| 4107 | 182274+0 records out |
| 4108 | 93324288 bytes (93 MB) copied, 14.4777 s, 6.4 MB/s |
| 4109 | [trz@empanada ~]$ sudo eject /dev/sdb |
| 4110 | </literallayout> |
| 4111 | </para> |
| 4112 | </section> |
| 4113 | |
| 4114 | <section id='using-a-modified-kickstart-file'> |
| 4115 | <title>Using a Modified Kickstart File</title> |
| 4116 | |
| 4117 | <para> |
| 4118 | Because <filename>wic</filename> image creation is driven |
| 4119 | by the kickstart file, it is easy to affect image creation |
| 4120 | by changing the parameters in the file. |
| 4121 | This next example demonstrates that through modification |
| 4122 | of the <filename>directdisk</filename> kickstart file. |
| 4123 | </para> |
| 4124 | |
| 4125 | <para> |
| 4126 | As mentioned earlier, you can use the command |
| 4127 | <filename>wic list images</filename> to show the list |
| 4128 | of existing kickstart files. |
| 4129 | The directory in which these files reside is |
| 4130 | <filename>scripts/lib/image/canned-wks/</filename> |
| 4131 | located in the |
| 4132 | <link linkend='source-directory'>Source Directory</link>. |
| 4133 | Because the available files reside in this directory, you |
| 4134 | can create and add your own custom files to the directory. |
| 4135 | Subsequent use of the <filename>wic list images</filename> |
| 4136 | command would then include your kickstart files. |
| 4137 | </para> |
| 4138 | |
| 4139 | <para> |
| 4140 | In this example, the existing |
| 4141 | <filename>directdisk</filename> file already does most |
| 4142 | of what is needed. |
| 4143 | However, for the hardware in this example, the image will |
| 4144 | need to boot from <filename>sdb</filename> instead of |
| 4145 | <filename>sda</filename>, which is what the |
| 4146 | <filename>directdisk</filename> kickstart file uses. |
| 4147 | </para> |
| 4148 | |
| 4149 | <para> |
| 4150 | The example begins by making a copy of the |
| 4151 | <filename>directdisk.wks</filename> file in the |
| 4152 | <filename>scripts/lib/image/canned-wks</filename> |
| 4153 | directory and then changing the lines that specify the |
| 4154 | target disk from which to boot. |
| 4155 | <literallayout class='monospaced'> |
| 4156 | $ cp /home/trz/yocto/yocto-image/scripts/lib/image/canned-wks/directdisk.wks \ |
| 4157 | /home/trz/yocto/yocto-image/scripts/lib/image/canned-wks/directdisksdb.wks |
| 4158 | </literallayout> |
| 4159 | Next, the example modifies the |
| 4160 | <filename>directdisksdb.wks</filename> file and changes all |
| 4161 | instances of "<filename>--ondisk sda</filename>" |
| 4162 | to "<filename>--ondisk sdb</filename>". |
| 4163 | The example changes the following two lines and leaves the |
| 4164 | remaining lines untouched: |
| 4165 | <literallayout class='monospaced'> |
| 4166 | part /boot --source bootimg-pcbios --ondisk sdb --label boot --active --align 1024 |
| 4167 | part / --source rootfs --ondisk sdb --fstype=ext3 --label platform --align 1024 |
| 4168 | </literallayout> |
| 4169 | Once the lines are changed, the example generates the |
| 4170 | <filename>directdisksdb</filename> image. |
| 4171 | The command points the process at the |
| 4172 | <filename>core-image-minimal</filename> artifacts for the |
| 4173 | Next Unit of Computing (nuc) |
| 4174 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink> |
| 4175 | the <filename>local.conf</filename>. |
| 4176 | <literallayout class='monospaced'> |
| 4177 | $ wic create directdisksdb -e core-image-minimal |
| 4178 | Checking basic build environment... |
| 4179 | Done. |
| 4180 | |
| 4181 | Creating image(s)... |
| 4182 | |
| 4183 | Info: The new image(s) can be found here: |
| 4184 | /var/tmp/wic/build/directdisksdb-201310231131-sdb.direct |
| 4185 | |
| 4186 | The following build artifacts were used to create the image(s): |
| 4187 | ROOTFS_DIR: /home/trz/yocto/yocto-image/build/tmp/work/nuc-poky-linux/core-image-minimal/1.0-r0/rootfs |
| 4188 | BOOTIMG_DIR: /home/trz/yocto/yocto-image/build/tmp/sysroots/nuc/usr/share |
| 4189 | KERNEL_DIR: /home/trz/yocto/yocto-image/build/tmp/sysroots/nuc/usr/src/kernel |
| 4190 | NATIVE_SYSROOT: /home/trz/yocto/yocto-image/build/tmp/sysroots/x86_64-linux |
| 4191 | |
| 4192 | |
| 4193 | The image(s) were created using OE kickstart file: |
| 4194 | /home/trz/yocto/yocto-image/scripts/lib/image/canned-wks/directdisksdb.wks |
| 4195 | </literallayout> |
| 4196 | Continuing with the example, you can now directly |
| 4197 | <filename>dd</filename> the image to a USB stick, or |
| 4198 | whatever media for which you built your image, |
| 4199 | and boot the resulting media: |
| 4200 | <literallayout class='monospaced'> |
| 4201 | $ sudo dd if=/var/tmp/wic/build/directdisksdb-201310231131-sdb.direct of=/dev/sdb |
| 4202 | 86018+0 records in |
| 4203 | 86018+0 records out |
| 4204 | 44041216 bytes (44 MB) copied, 13.0734 s, 3.4 MB/s |
| 4205 | [trz@empanada tmp]$ sudo eject /dev/sdb |
| 4206 | </literallayout> |
| 4207 | </para> |
| 4208 | </section> |
| 4209 | |
| 4210 | <section id='creating-an-image-based-on-core-image-minimal-and-crownbay-noemgd'> |
| 4211 | <title>Creating an Image Based on <filename>core-image-minimal</filename> and <filename>crownbay-noemgd</filename></title> |
| 4212 | |
| 4213 | <para> |
| 4214 | This example creates an image based on |
| 4215 | <filename>core-image-minimal</filename> and a |
| 4216 | <filename>crownbay-noemgd</filename> |
| 4217 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink> |
| 4218 | that works right out of the box. |
| 4219 | <literallayout class='monospaced'> |
| 4220 | $ wic create directdisk -e core-image-minimal |
| 4221 | |
| 4222 | Checking basic build environment... |
| 4223 | Done. |
| 4224 | |
| 4225 | Creating image(s)... |
| 4226 | |
| 4227 | Info: The new image(s) can be found here: |
| 4228 | /var/tmp/wic/build/directdisk-201309252350-sda.direct |
| 4229 | |
| 4230 | The following build artifacts were used to create the image(s): |
| 4231 | |
| 4232 | ROOTFS_DIR: /home/trz/yocto/yocto-image/build/tmp/work/crownbay_noemgd-poky-linux/core-image-minimal/1.0-r0/rootfs |
| 4233 | BOOTIMG_DIR: /home/trz/yocto/yocto-image/build/tmp/sysroots/crownbay-noemgd/usr/share |
| 4234 | KERNEL_DIR: /home/trz/yocto/yocto-image/build/tmp/sysroots/crownbay-noemgd/usr/src/kernel |
| 4235 | NATIVE_SYSROOT: /home/trz/yocto/yocto-image/build/tmp/sysroots/crownbay-noemgd/usr/src/kernel |
| 4236 | |
| 4237 | The image(s) were created using OE kickstart file: |
| 4238 | /home/trz/yocto/yocto-image/scripts/lib/image/canned-wks/directdisk.wks |
| 4239 | </literallayout> |
| 4240 | </para> |
| 4241 | </section> |
| 4242 | |
| 4243 | <section id='using-a-modified-kickstart-file-and-running-in-raw-mode'> |
| 4244 | <title>Using a Modified Kickstart File and Running in Raw Mode</title> |
| 4245 | |
| 4246 | <para> |
| 4247 | This next example manually specifies each build artifact |
| 4248 | (runs in Raw Mode) and uses a modified kickstart file. |
| 4249 | The example also uses the <filename>-o</filename> option |
| 4250 | to cause <filename>wic</filename> to create the output |
| 4251 | somewhere other than the default |
| 4252 | <filename>/var/tmp/wic</filename> directory: |
| 4253 | <literallayout class='monospaced'> |
| 4254 | $ wic create ~/test.wks -o /home/trz/testwic --rootfs-dir \ |
| 4255 | /home/trz/yocto/yocto-image/build/tmp/work/crownbay_noemgd-poky-linux/core-image-minimal/1.0-r0/rootfs \ |
| 4256 | --bootimg-dir /home/trz/yocto/yocto-image/build/tmp/sysroots/crownbay-noemgd/usr/share \ |
| 4257 | --kernel-dir /home/trz/yocto/yocto-image/build/tmp/sysroots/crownbay-noemgd/usr/src/kernel \ |
| 4258 | --native-sysroot /home/trz/yocto/yocto-image/build/tmp/sysroots/x86_64-linux |
| 4259 | |
| 4260 | Creating image(s)... |
| 4261 | |
| 4262 | Info: The new image(s) can be found here: |
| 4263 | /home/trz/testwic/build/test-201309260032-sda.direct |
| 4264 | |
| 4265 | The following build artifacts were used to create the image(s): |
| 4266 | |
| 4267 | ROOTFS_DIR: /home/trz/yocto/yocto-image/build/tmp/work/crownbay_noemgd-poky-linux/core-image-minimal/1.0-r0/rootfs |
| 4268 | BOOTIMG_DIR: /home/trz/yocto/yocto-image/build/tmp/sysroots/crownbay-noemgd/usr/share |
| 4269 | KERNEL_DIR: /home/trz/yocto/yocto-image/build/tmp/sysroots/crownbay-noemgd/usr/src/kernel |
| 4270 | NATIVE_SYSROOT: /home/trz/yocto/yocto-image/build/tmp/sysroots/crownbay-noemgd/usr/src/kernel |
| 4271 | |
| 4272 | The image(s) were created using OE kickstart file: |
| 4273 | /home/trz/test.wks |
| 4274 | </literallayout> |
| 4275 | For this example, |
| 4276 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink> |
| 4277 | did not have to be specified in the |
| 4278 | <filename>local.conf</filename> file since the artifact is |
| 4279 | manually specified. |
| 4280 | </para> |
| 4281 | </section> |
| 4282 | </section> |
| 4283 | |
| 4284 | <section id='openembedded-kickstart-plugins'> |
| 4285 | <title>Plugins</title> |
| 4286 | |
| 4287 | <para> |
| 4288 | Plugins allow <filename>wic</filename> functionality to |
| 4289 | be extended and specialized by users. |
| 4290 | This section documents the plugin interface, which is |
| 4291 | currently restricted to source plugins. |
| 4292 | </para> |
| 4293 | |
| 4294 | <para> |
| 4295 | Source plugins provide a mechanism to customize |
| 4296 | various aspects of the image generation process in |
| 4297 | <filename>wic</filename>, mainly the contents of |
| 4298 | partitions. |
| 4299 | The plugins provide a mechanism for mapping values |
| 4300 | specified in <filename>.wks</filename> files using the |
| 4301 | <filename>--source</filename> keyword to a |
| 4302 | particular plugin implementation that populates a |
| 4303 | corresponding partition. |
| 4304 | </para> |
| 4305 | |
| 4306 | <para> |
| 4307 | A source plugin is created as a subclass of |
| 4308 | <filename>SourcePlugin</filename>. |
| 4309 | The plugin file containing it is added to |
| 4310 | <filename>scripts/lib/mic/plugins/source/</filename> to |
| 4311 | make the plugin implementation available to the |
| 4312 | <filename>wic</filename> implementation. |
| 4313 | For more information, see |
| 4314 | <filename>scripts/lib/mic/pluginbase.py</filename>. |
| 4315 | </para> |
| 4316 | |
| 4317 | <para> |
| 4318 | Source plugins can also be implemented and added by |
| 4319 | external layers. |
| 4320 | As such, any plugins found in a |
| 4321 | <filename>scripts/lib/mic/plugins/source/</filename> |
| 4322 | directory in an external layer are also made |
| 4323 | available. |
| 4324 | </para> |
| 4325 | |
| 4326 | <para> |
| 4327 | When the <filename>wic</filename> implementation needs |
| 4328 | to invoke a partition-specific implementation, it looks |
| 4329 | for the plugin that has the same name as the |
| 4330 | <filename>--source</filename> parameter given to |
| 4331 | that partition. |
| 4332 | For example, if the partition is set up as follows: |
| 4333 | <literallayout class='monospaced'> |
| 4334 | part /boot --source bootimg-pcbios ... |
| 4335 | </literallayout> |
| 4336 | The methods defined as class members of the plugin |
| 4337 | having the matching <filename>bootimg-pcbios.name</filename> |
| 4338 | class member are used. |
| 4339 | </para> |
| 4340 | |
| 4341 | <para> |
| 4342 | To be more concrete, here is the plugin definition that |
| 4343 | matches a |
| 4344 | <filename>--source bootimg-pcbios</filename> usage, |
| 4345 | along with an example |
| 4346 | method called by the <filename>wic</filename> implementation |
| 4347 | when it needs to invoke an implementation-specific |
| 4348 | partition-preparation function: |
| 4349 | <literallayout class='monospaced'> |
| 4350 | class BootimgPcbiosPlugin(SourcePlugin): |
| 4351 | name = 'bootimg-pcbios' |
| 4352 | |
| 4353 | @classmethod |
| 4354 | def do_prepare_partition(self, part, ...) |
| 4355 | </literallayout> |
| 4356 | If the subclass itself does not implement a function, a |
| 4357 | default version in a superclass is located and |
| 4358 | used, which is why all plugins must be derived from |
| 4359 | <filename>SourcePlugin</filename>. |
| 4360 | </para> |
| 4361 | |
| 4362 | <para> |
| 4363 | The <filename>SourcePlugin</filename> class defines the |
| 4364 | following methods, which is the current set of methods |
| 4365 | that can be implemented or overridden by |
| 4366 | <filename>--source</filename> plugins. |
| 4367 | Any methods not implemented by a |
| 4368 | <filename>SourcePlugin</filename> subclass inherit the |
| 4369 | implementations present in the |
| 4370 | <filename>SourcePlugin</filename> class. |
| 4371 | For more information, see the |
| 4372 | <filename>SourcePlugin</filename> source for details: |
| 4373 | </para> |
| 4374 | |
| 4375 | <para> |
| 4376 | <itemizedlist> |
| 4377 | <listitem><para><emphasis><filename>do_prepare_partition()</filename>:</emphasis> |
| 4378 | Called to do the actual content population for a |
| 4379 | partition. |
| 4380 | In other words, the method prepares the final |
| 4381 | partition image that is incorporated into the |
| 4382 | disk image. |
| 4383 | </para></listitem> |
| 4384 | <listitem><para><emphasis><filename>do_configure_partition()</filename>:</emphasis> |
| 4385 | Called before |
| 4386 | <filename>do_prepare_partition()</filename>. |
| 4387 | This method is typically used to create custom |
| 4388 | configuration files for a partition (e.g. syslinux or |
| 4389 | grub configuration files). |
| 4390 | </para></listitem> |
| 4391 | <listitem><para><emphasis><filename>do_install_disk()</filename>:</emphasis> |
| 4392 | Called after all partitions have been prepared and |
| 4393 | assembled into a disk image. |
| 4394 | This method provides a hook to allow finalization of a |
| 4395 | disk image, (e.g. writing an MBR). |
| 4396 | </para></listitem> |
| 4397 | <listitem><para><emphasis><filename>do_stage_partition()</filename>:</emphasis> |
| 4398 | Special content-staging hook called before |
| 4399 | <filename>do_prepare_partition()</filename>. |
| 4400 | This method is normally empty.</para> |
| 4401 | <para>Typically, a partition just uses the passed-in |
| 4402 | parameters (e.g. the unmodified value of |
| 4403 | <filename>bootimg_dir</filename>). |
| 4404 | However, in some cases things might need to be |
| 4405 | more tailored. |
| 4406 | As an example, certain files might additionally |
| 4407 | need to be taken from |
| 4408 | <filename>bootimg_dir + /boot</filename>. |
| 4409 | This hook allows those files to be staged in a |
| 4410 | customized fashion. |
| 4411 | <note> |
| 4412 | <filename>get_bitbake_var()</filename> |
| 4413 | allows you to access non-standard variables |
| 4414 | that you might want to use for this. |
| 4415 | </note> |
| 4416 | </para></listitem> |
| 4417 | </itemizedlist> |
| 4418 | </para> |
| 4419 | |
| 4420 | <para> |
| 4421 | This scheme is extensible. |
| 4422 | Adding more hooks is a simple matter of adding more |
| 4423 | plugin methods to <filename>SourcePlugin</filename> and |
| 4424 | derived classes. |
| 4425 | The code that then needs to call the plugin methods uses |
| 4426 | <filename>plugin.get_source_plugin_methods()</filename> |
| 4427 | to find the method or methods needed by the call. |
| 4428 | Retrieval of those methods is accomplished |
| 4429 | by filling up a dict with keys |
| 4430 | containing the method names of interest. |
| 4431 | On success, these will be filled in with the actual |
| 4432 | methods. |
| 4433 | Please see the <filename>wic</filename> |
| 4434 | implementation for examples and details. |
| 4435 | </para> |
| 4436 | </section> |
| 4437 | |
| 4438 | <section id='openembedded-kickstart-wks-reference'> |
| 4439 | <title>OpenEmbedded Kickstart (.wks) Reference</title> |
| 4440 | |
| 4441 | <para> |
| 4442 | The current <filename>wic</filename> implementation supports |
| 4443 | only the basic kickstart partitioning commands: |
| 4444 | <filename>partition</filename> (or <filename>part</filename> |
| 4445 | for short) and <filename>bootloader</filename>. |
| 4446 | <note> |
| 4447 | Future updates will implement more commands and options. |
| 4448 | If you use anything that is not specifically |
| 4449 | supported, results can be unpredictable. |
| 4450 | </note> |
| 4451 | </para> |
| 4452 | |
| 4453 | <para> |
| 4454 | The following is a list of the commands, their syntax, |
| 4455 | and meanings. |
| 4456 | The commands are based on the Fedora |
| 4457 | kickstart versions but with modifications to |
| 4458 | reflect <filename>wic</filename> capabilities. |
| 4459 | You can see the original documentation for those commands |
| 4460 | at the following links: |
| 4461 | <itemizedlist> |
| 4462 | <listitem><para> |
| 4463 | <ulink url='http://fedoraproject.org/wiki/Anaconda/Kickstart#part_or_partition'>http://fedoraproject.org/wiki/Anaconda/Kickstart#part_or_partition</ulink> |
| 4464 | </para></listitem> |
| 4465 | <listitem><para> |
| 4466 | <ulink url='http://fedoraproject.org/wiki/Anaconda/Kickstart#bootloader'>http://fedoraproject.org/wiki/Anaconda/Kickstart#bootloader</ulink> |
| 4467 | </para></listitem> |
| 4468 | </itemizedlist> |
| 4469 | </para> |
| 4470 | |
| 4471 | <section id='command-part-or-partition'> |
| 4472 | <title>Command: part or partition</title> |
| 4473 | |
| 4474 | <para> |
| 4475 | This command creates a partition on the system and uses the |
| 4476 | following syntax: |
| 4477 | <literallayout class='monospaced'> |
| 4478 | part <replaceable>mntpoint</replaceable> |
| 4479 | </literallayout> |
| 4480 | The <filename><replaceable>mntpoint</replaceable></filename> |
| 4481 | is where the |
| 4482 | partition will be mounted and must be of one of the |
| 4483 | following forms: |
| 4484 | <itemizedlist> |
| 4485 | <listitem><para><filename>/<replaceable>path</replaceable></filename>: |
| 4486 | For example, <filename>/</filename>, |
| 4487 | <filename>/usr</filename>, and |
| 4488 | <filename>/home</filename></para></listitem> |
| 4489 | <listitem><para><filename>swap</filename>: |
| 4490 | The partition will be used as swap space. |
| 4491 | </para></listitem> |
| 4492 | </itemizedlist> |
| 4493 | </para> |
| 4494 | |
| 4495 | <para> |
| 4496 | Following are the supported options: |
| 4497 | <itemizedlist> |
| 4498 | <listitem><para><emphasis><filename>--size</filename>:</emphasis> |
| 4499 | The minimum partition size in MBytes. |
| 4500 | Specify an integer value such as 500. |
| 4501 | Do not append the number with "MB". |
| 4502 | You do not need this option if you use |
| 4503 | <filename>--source</filename>.</para></listitem> |
| 4504 | <listitem><para><emphasis><filename>--source</filename>:</emphasis> |
| 4505 | This option is a |
| 4506 | <filename>wic</filename>-specific option that |
| 4507 | names the source of the data that populates |
| 4508 | the partition. |
| 4509 | The most common value for this option is |
| 4510 | "rootfs", but you can use any value that maps to |
| 4511 | a valid source plugin. |
| 4512 | For information on the source plugins, see the |
| 4513 | "<link linkend='openembedded-kickstart-plugins'>Plugins</link>" |
| 4514 | section.</para> |
| 4515 | <para>If you use |
| 4516 | <filename>--source rootfs</filename>, |
| 4517 | <filename>wic</filename> creates a partition as |
| 4518 | large as needed and to fill it with the contents of |
| 4519 | the root filesystem pointed to by the |
| 4520 | <filename>-r</filename> command-line option |
| 4521 | or the equivalent rootfs derived from the |
| 4522 | <filename>-e</filename> command-line |
| 4523 | option. |
| 4524 | The filesystem type used to create the |
| 4525 | partition is driven by the value of the |
| 4526 | <filename>--fstype</filename> option |
| 4527 | specified for the partition. |
| 4528 | See the entry on |
| 4529 | <filename>--fstype</filename> that |
| 4530 | follows for more information. |
| 4531 | </para> |
| 4532 | <para>If you use |
| 4533 | <filename>--source <replaceable>plugin-name</replaceable></filename>, |
| 4534 | <filename>wic</filename> creates a partition as |
| 4535 | large as needed and fills it with the contents of |
| 4536 | the partition that is generated by the |
| 4537 | specified plugin name using the data pointed |
| 4538 | to by the <filename>-r</filename> command-line |
| 4539 | option or the equivalent rootfs derived from the |
| 4540 | <filename>-e</filename> command-line |
| 4541 | option. |
| 4542 | Exactly what those contents and |
| 4543 | filesystem type end up being are dependent |
| 4544 | on the given plugin implementation. |
| 4545 | </para></listitem> |
| 4546 | <listitem><para><emphasis><filename>--ondisk</filename> or <filename>--ondrive</filename>:</emphasis> |
| 4547 | Forces the partition to be created on a particular |
| 4548 | disk.</para></listitem> |
| 4549 | <listitem><para><emphasis><filename>--fstype</filename>:</emphasis> |
| 4550 | Sets the file system type for the partition. |
| 4551 | Valid values are: |
| 4552 | <itemizedlist> |
| 4553 | <listitem><para><filename>ext4</filename> |
| 4554 | </para></listitem> |
| 4555 | <listitem><para><filename>ext3</filename> |
| 4556 | </para></listitem> |
| 4557 | <listitem><para><filename>ext2</filename> |
| 4558 | </para></listitem> |
| 4559 | <listitem><para><filename>btrfs</filename> |
| 4560 | </para></listitem> |
| 4561 | <listitem><para><filename>squashfs</filename> |
| 4562 | </para></listitem> |
| 4563 | <listitem><para><filename>swap</filename> |
| 4564 | </para></listitem> |
| 4565 | </itemizedlist></para></listitem> |
| 4566 | <listitem><para><emphasis><filename>--fsoptions</filename>:</emphasis> |
| 4567 | Specifies a free-form string of options to be |
| 4568 | used when mounting the filesystem. |
| 4569 | This string will be copied into the |
| 4570 | <filename>/etc/fstab</filename> file of the |
| 4571 | installed system and should be enclosed in |
| 4572 | quotes. |
| 4573 | If not specified, the default string |
| 4574 | is "defaults". |
| 4575 | </para></listitem> |
| 4576 | <listitem><para><emphasis><filename>--label label</filename>:</emphasis> |
| 4577 | Specifies the label to give to the filesystem to |
| 4578 | be made on the partition. |
| 4579 | If the given label is already in use by another |
| 4580 | filesystem, a new label is created for the |
| 4581 | partition.</para></listitem> |
| 4582 | <listitem><para><emphasis><filename>--active</filename>:</emphasis> |
| 4583 | Marks the partition as active.</para></listitem> |
| 4584 | <listitem><para><emphasis><filename>--align (in KBytes)</filename>:</emphasis> |
| 4585 | This option is a <filename>wic</filename>-specific |
| 4586 | option that says to start a partition on an |
| 4587 | x KBytes boundary.</para></listitem> |
| 4588 | </itemizedlist> |
| 4589 | </para> |
| 4590 | </section> |
| 4591 | |
| 4592 | <section id='command-bootloader'> |
| 4593 | <title>Command: bootloader</title> |
| 4594 | |
| 4595 | <para> |
| 4596 | This command specifies how the boot loader should be |
| 4597 | configured and supports the following options: |
| 4598 | <note> |
| 4599 | Bootloader functionality and boot partitions are |
| 4600 | implemented by the various |
| 4601 | <filename>--source</filename> |
| 4602 | plugins that implement bootloader functionality. |
| 4603 | The bootloader command essentially provides a means of |
| 4604 | modifying bootloader configuration. |
| 4605 | </note> |
| 4606 | <itemizedlist> |
| 4607 | <listitem><para><emphasis><filename>--timeout</filename>:</emphasis> |
| 4608 | Specifies the number of seconds before the |
| 4609 | bootloader times out and boots the default option. |
| 4610 | </para></listitem> |
| 4611 | <listitem><para><emphasis><filename>--append</filename>:</emphasis> |
| 4612 | Specifies kernel parameters. |
| 4613 | These parameters will be added to the syslinux |
| 4614 | <filename>APPEND</filename> or |
| 4615 | <filename>grub</filename> kernel command line. |
| 4616 | </para></listitem> |
| 4617 | </itemizedlist> |
| 4618 | </para> |
| 4619 | </section> |
| 4620 | </section> |
| 4621 | </section> |
| 4622 | |
| 4623 | <section id='configuring-the-kernel'> |
| 4624 | <title>Configuring the Kernel</title> |
| 4625 | |
| 4626 | <para> |
| 4627 | Configuring the Yocto Project kernel consists of making sure the |
| 4628 | <filename>.config</filename> file has all the right information |
| 4629 | in it for the image you are building. |
| 4630 | You can use the <filename>menuconfig</filename> tool and |
| 4631 | configuration fragments to make sure your |
| 4632 | <filename>.config</filename> file is just how you need it. |
| 4633 | You can also save known configurations in a |
| 4634 | <filename>defconfig</filename> file that the build system can use |
| 4635 | for kernel configuration. |
| 4636 | </para> |
| 4637 | |
| 4638 | <para> |
| 4639 | This section describes how to use <filename>menuconfig</filename>, |
| 4640 | create and use configuration fragments, and how to interactively |
| 4641 | modify your <filename>.config</filename> file to create the |
| 4642 | leanest kernel configuration file possible. |
| 4643 | </para> |
| 4644 | |
| 4645 | <para> |
| 4646 | For more information on kernel configuration, see the |
| 4647 | "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#changing-the-configuration'>Changing the Configuration</ulink>" |
| 4648 | section in the Yocto Project Linux Kernel Development Manual. |
| 4649 | </para> |
| 4650 | |
| 4651 | <section id='using-menuconfig'> |
| 4652 | <title>Using <filename>menuconfig</filename></title> |
| 4653 | |
| 4654 | <para> |
| 4655 | The easiest way to define kernel configurations is to set them through the |
| 4656 | <filename>menuconfig</filename> tool. |
| 4657 | This tool provides an interactive method with which |
| 4658 | to set kernel configurations. |
| 4659 | For general information on <filename>menuconfig</filename>, see |
| 4660 | <ulink url='http://en.wikipedia.org/wiki/Menuconfig'></ulink>. |
| 4661 | </para> |
| 4662 | |
| 4663 | <para> |
| 4664 | To use the <filename>menuconfig</filename> tool in the Yocto Project development |
| 4665 | environment, you must launch it using BitBake. |
| 4666 | Thus, the environment must be set up using the |
| 4667 | <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink> |
| 4668 | or |
| 4669 | <ulink url='&YOCTO_DOCS_REF_URL;#structure-memres-core-script'><filename>oe-init-build-env-memres</filename></ulink> |
| 4670 | script found in the |
| 4671 | <link linkend='build-directory'>Build Directory</link>. |
| 4672 | You must also be sure of the state of your build in the |
| 4673 | <link linkend='source-directory'>Source Directory</link>. |
| 4674 | The following commands run <filename>menuconfig</filename> |
| 4675 | assuming the Source Directory's top-level folder is |
| 4676 | <filename>~/poky</filename>: |
| 4677 | <literallayout class='monospaced'> |
| 4678 | $ cd poky |
| 4679 | $ source oe-init-build-env |
| 4680 | $ bitbake linux-yocto -c kernel_configme -f |
| 4681 | $ bitbake linux-yocto -c menuconfig |
| 4682 | </literallayout> |
| 4683 | Once <filename>menuconfig</filename> comes up, its standard |
| 4684 | interface allows you to interactively examine and configure |
| 4685 | all the kernel configuration parameters. |
| 4686 | After making your changes, simply exit the tool and save your |
| 4687 | changes to create an updated version of the |
| 4688 | <filename>.config</filename> configuration file. |
| 4689 | </para> |
| 4690 | |
| 4691 | <para> |
| 4692 | Consider an example that configures the <filename>linux-yocto-3.14</filename> |
| 4693 | kernel. |
| 4694 | The OpenEmbedded build system recognizes this kernel as |
| 4695 | <filename>linux-yocto</filename>. |
| 4696 | Thus, the following commands from the shell in which you previously sourced the |
| 4697 | environment initialization script cleans the shared state cache and the |
| 4698 | <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink> |
| 4699 | directory and then runs <filename>menuconfig</filename>: |
| 4700 | <literallayout class='monospaced'> |
| 4701 | $ bitbake linux-yocto -c menuconfig |
| 4702 | </literallayout> |
| 4703 | </para> |
| 4704 | |
| 4705 | <para> |
| 4706 | Once <filename>menuconfig</filename> launches, use the interface |
| 4707 | to navigate through the selections to find the configuration settings in |
| 4708 | which you are interested. |
| 4709 | For example, consider the <filename>CONFIG_SMP</filename> configuration setting. |
| 4710 | You can find it at <filename>Processor Type and Features</filename> under |
| 4711 | the configuration selection <filename>Symmetric Multi-processing Support</filename>. |
| 4712 | After highlighting the selection, use the arrow keys to select or deselect |
| 4713 | the setting. |
| 4714 | When you are finished with all your selections, exit out and save them. |
| 4715 | </para> |
| 4716 | |
| 4717 | <para> |
| 4718 | Saving the selections updates the <filename>.config</filename> configuration file. |
| 4719 | This is the file that the OpenEmbedded build system uses to configure the |
| 4720 | kernel during the build. |
| 4721 | You can find and examine this file in the Build Directory in |
| 4722 | <filename>tmp/work/</filename>. |
| 4723 | The actual <filename>.config</filename> is located in the area where the |
| 4724 | specific kernel is built. |
| 4725 | For example, if you were building a Linux Yocto kernel based on the |
| 4726 | Linux 3.14 kernel and you were building a QEMU image targeted for |
| 4727 | <filename>x86</filename> architecture, the |
| 4728 | <filename>.config</filename> file would be located here: |
| 4729 | <literallayout class='monospaced'> |
| 4730 | poky/build/tmp/work/qemux86-poky-linux/linux-yocto-3.14.11+git1+84f... |
| 4731 | ...656ed30-r1/linux-qemux86-standard-build |
| 4732 | </literallayout> |
| 4733 | <note> |
| 4734 | The previous example directory is artificially split and many of the characters |
| 4735 | in the actual filename are omitted in order to make it more readable. |
| 4736 | Also, depending on the kernel you are using, the exact pathname |
| 4737 | for <filename>linux-yocto-3.14...</filename> might differ. |
| 4738 | </note> |
| 4739 | </para> |
| 4740 | |
| 4741 | <para> |
| 4742 | Within the <filename>.config</filename> file, you can see the kernel settings. |
| 4743 | For example, the following entry shows that symmetric multi-processor support |
| 4744 | is not set: |
| 4745 | <literallayout class='monospaced'> |
| 4746 | # CONFIG_SMP is not set |
| 4747 | </literallayout> |
| 4748 | </para> |
| 4749 | |
| 4750 | <para> |
| 4751 | A good method to isolate changed configurations is to use a combination of the |
| 4752 | <filename>menuconfig</filename> tool and simple shell commands. |
| 4753 | Before changing configurations with <filename>menuconfig</filename>, copy the |
| 4754 | existing <filename>.config</filename> and rename it to something else, |
| 4755 | use <filename>menuconfig</filename> to make |
| 4756 | as many changes as you want and save them, then compare the renamed configuration |
| 4757 | file against the newly created file. |
| 4758 | You can use the resulting differences as your base to create configuration fragments |
| 4759 | to permanently save in your kernel layer. |
| 4760 | <note> |
| 4761 | Be sure to make a copy of the <filename>.config</filename> and don't just |
| 4762 | rename it. |
| 4763 | The build system needs an existing <filename>.config</filename> |
| 4764 | from which to work. |
| 4765 | </note> |
| 4766 | </para> |
| 4767 | </section> |
| 4768 | |
| 4769 | <section id='creating-a-defconfig-file'> |
| 4770 | <title>Creating a <filename>defconfig</filename> File</title> |
| 4771 | |
| 4772 | <para> |
| 4773 | A <filename>defconfig</filename> file is simply a |
| 4774 | <filename>.config</filename> renamed to "defconfig". |
| 4775 | You can use a <filename>defconfig</filename> file |
| 4776 | to retain a known set of kernel configurations from which the |
| 4777 | OpenEmbedded build system can draw to create the final |
| 4778 | <filename>.config</filename> file. |
| 4779 | <note> |
| 4780 | Out-of-the-box, the Yocto Project never ships a |
| 4781 | <filename>defconfig</filename> or |
| 4782 | <filename>.config</filename> file. |
| 4783 | The OpenEmbedded build system creates the final |
| 4784 | <filename>.config</filename> file used to configure the |
| 4785 | kernel. |
| 4786 | </note> |
| 4787 | </para> |
| 4788 | |
| 4789 | <para> |
| 4790 | To create a <filename>defconfig</filename>, start with a |
| 4791 | complete, working Linux kernel <filename>.config</filename> |
| 4792 | file. |
| 4793 | Copy that file to the appropriate |
| 4794 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename> |
| 4795 | directory in your layer's |
| 4796 | <filename>recipes-kernel/linux</filename> directory, and rename |
| 4797 | the copied file to "defconfig". |
| 4798 | Then, add the following lines to the linux-yocto |
| 4799 | <filename>.bbappend</filename> file in your layer: |
| 4800 | <literallayout class='monospaced'> |
| 4801 | FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" |
| 4802 | SRC_URI += "file://defconfig" |
| 4803 | </literallayout> |
| 4804 | The |
| 4805 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> |
| 4806 | tells the build system how to search for the file, while the |
| 4807 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink> |
| 4808 | extends the |
| 4809 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink> |
| 4810 | variable (search directories) to include the |
| 4811 | <filename>${PN}</filename> directory you created to hold the |
| 4812 | configuration changes. |
| 4813 | <note> |
| 4814 | The build system applies the configurations from the |
| 4815 | <filename>defconfig</filename> file before applying any |
| 4816 | subsequent configuration fragments. |
| 4817 | The final kernel configuration is a combination of the |
| 4818 | configurations in the <filename>defconfig</filename> |
| 4819 | file and any configuration fragments you provide. |
| 4820 | You need to realize that if you have any configuration |
| 4821 | fragments, the build system applies these on top of and |
| 4822 | after applying the existing defconfig file configurations. |
| 4823 | </note> |
| 4824 | For more information on configuring the kernel, see the |
| 4825 | "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#changing-the-configuration'>Changing the Configuration</ulink>" |
| 4826 | and |
| 4827 | "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#generating-configuration-files'>Generating Configuration Files</ulink>" |
| 4828 | sections, both in the Yocto Project Linux Kernel Development |
| 4829 | Manual. |
| 4830 | </para> |
| 4831 | </section> |
| 4832 | |
| 4833 | <section id='creating-config-fragments'> |
| 4834 | <title>Creating Configuration Fragments</title> |
| 4835 | |
| 4836 | <para> |
| 4837 | Configuration fragments are simply kernel options that appear in a file |
| 4838 | placed where the OpenEmbedded build system can find and apply them. |
| 4839 | Syntactically, the configuration statement is identical to what would appear |
| 4840 | in the <filename>.config</filename> file, which is in the |
| 4841 | <link linkend='build-directory'>Build Directory</link>: |
| 4842 | <literallayout class='monospaced'> |
| 4843 | tmp/work/<replaceable>arch</replaceable>-poky-linux/linux-yocto-<replaceable>release_specific_string</replaceable>/linux-<replaceable>arch</replaceable>-<replaceable>build_type</replaceable> |
| 4844 | </literallayout> |
| 4845 | </para> |
| 4846 | |
| 4847 | <para> |
| 4848 | It is simple to create a configuration fragment. |
| 4849 | For example, issuing the following from the shell creates a configuration fragment |
| 4850 | file named <filename>my_smp.cfg</filename> that enables multi-processor support |
| 4851 | within the kernel: |
| 4852 | <literallayout class='monospaced'> |
| 4853 | $ echo "CONFIG_SMP=y" >> my_smp.cfg |
| 4854 | </literallayout> |
| 4855 | <note> |
| 4856 | All configuration fragment files must use the |
| 4857 | <filename>.cfg</filename> extension in order for the |
| 4858 | OpenEmbedded build system to recognize them as a |
| 4859 | configuration fragment. |
| 4860 | </note> |
| 4861 | </para> |
| 4862 | |
| 4863 | <para> |
| 4864 | Where do you put your configuration fragment files? |
| 4865 | You can place these files in the same area pointed to by |
| 4866 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>. |
| 4867 | The OpenEmbedded build system picks up the configuration and |
| 4868 | adds it to the kernel's configuration. |
| 4869 | For example, suppose you had a set of configuration options |
| 4870 | in a file called <filename>myconfig.cfg</filename>. |
| 4871 | If you put that file inside a directory named |
| 4872 | <filename>linux-yocto</filename> that resides in the same |
| 4873 | directory as the kernel's append file and then add a |
| 4874 | <filename>SRC_URI</filename> statement such as the following |
| 4875 | to the kernel's append file, those configuration options |
| 4876 | will be picked up and applied when the kernel is built. |
| 4877 | <literallayout class='monospaced'> |
| 4878 | SRC_URI += "file://myconfig.cfg" |
| 4879 | </literallayout> |
| 4880 | </para> |
| 4881 | |
| 4882 | <para> |
| 4883 | As mentioned earlier, you can group related configurations into multiple files and |
| 4884 | name them all in the <filename>SRC_URI</filename> statement as well. |
| 4885 | For example, you could group separate configurations specifically for Ethernet and graphics |
| 4886 | into their own files and add those by using a <filename>SRC_URI</filename> statement like the |
| 4887 | following in your append file: |
| 4888 | <literallayout class='monospaced'> |
| 4889 | SRC_URI += "file://myconfig.cfg \ |
| 4890 | file://eth.cfg \ |
| 4891 | file://gfx.cfg" |
| 4892 | </literallayout> |
| 4893 | </para> |
| 4894 | </section> |
| 4895 | |
| 4896 | <section id='fine-tuning-the-kernel-configuration-file'> |
| 4897 | <title>Fine-Tuning the Kernel Configuration File</title> |
| 4898 | |
| 4899 | <para> |
| 4900 | You can make sure the <filename>.config</filename> file is as lean or efficient as |
| 4901 | possible by reading the output of the kernel configuration fragment audit, |
| 4902 | noting any issues, making changes to correct the issues, and then repeating. |
| 4903 | </para> |
| 4904 | |
| 4905 | <para> |
| 4906 | As part of the kernel build process, the |
| 4907 | <filename>do_kernel_configcheck</filename> task runs. |
| 4908 | This task validates the kernel configuration by checking the final |
| 4909 | <filename>.config</filename> file against the input files. |
| 4910 | During the check, the task produces warning messages for the following |
| 4911 | issues: |
| 4912 | <itemizedlist> |
| 4913 | <listitem><para>Requested options that did not make the final |
| 4914 | <filename>.config</filename> file.</para></listitem> |
| 4915 | <listitem><para>Configuration items that appear twice in the same |
| 4916 | configuration fragment.</para></listitem> |
| 4917 | <listitem><para>Configuration items tagged as "required" that were overridden. |
| 4918 | </para></listitem> |
| 4919 | <listitem><para>A board overrides a non-board specific option.</para></listitem> |
| 4920 | <listitem><para>Listed options not valid for the kernel being processed. |
| 4921 | In other words, the option does not appear anywhere.</para></listitem> |
| 4922 | </itemizedlist> |
| 4923 | <note> |
| 4924 | The <filename>do_kernel_configcheck</filename> task can |
| 4925 | also optionally report if an option is overridden during |
| 4926 | processing. |
| 4927 | </note> |
| 4928 | </para> |
| 4929 | |
| 4930 | <para> |
| 4931 | For each output warning, a message points to the file |
| 4932 | that contains a list of the options and a pointer to the |
| 4933 | configuration fragment that defines them. |
| 4934 | Collectively, the files are the key to streamlining the |
| 4935 | configuration. |
| 4936 | </para> |
| 4937 | |
| 4938 | <para> |
| 4939 | To streamline the configuration, do the following: |
| 4940 | <orderedlist> |
| 4941 | <listitem><para>Start with a full configuration that you |
| 4942 | know works - it builds and boots successfully. |
| 4943 | This configuration file will be your baseline. |
| 4944 | </para></listitem> |
| 4945 | <listitem><para>Separately run the |
| 4946 | <filename>do_configme</filename> and |
| 4947 | <filename>do_kernel_configcheck</filename> tasks. |
| 4948 | </para></listitem> |
| 4949 | <listitem><para>Take the resulting list of files from the |
| 4950 | <filename>do_kernel_configcheck</filename> task |
| 4951 | warnings and do the following: |
| 4952 | <itemizedlist> |
| 4953 | <listitem><para> |
| 4954 | Drop values that are redefined in the fragment |
| 4955 | but do not change the final |
| 4956 | <filename>.config</filename> file. |
| 4957 | </para></listitem> |
| 4958 | <listitem><para> |
| 4959 | Analyze and potentially drop values from the |
| 4960 | <filename>.config</filename> file that override |
| 4961 | required configurations. |
| 4962 | </para></listitem> |
| 4963 | <listitem><para> |
| 4964 | Analyze and potentially remove non-board |
| 4965 | specific options. |
| 4966 | </para></listitem> |
| 4967 | <listitem><para> |
| 4968 | Remove repeated and invalid options. |
| 4969 | </para></listitem> |
| 4970 | </itemizedlist></para></listitem> |
| 4971 | <listitem><para> |
| 4972 | After you have worked through the output of the kernel |
| 4973 | configuration audit, you can re-run the |
| 4974 | <filename>do_configme</filename> and |
| 4975 | <filename>do_kernel_configcheck</filename> tasks to |
| 4976 | see the results of your changes. |
| 4977 | If you have more issues, you can deal with them as |
| 4978 | described in the previous step. |
| 4979 | </para></listitem> |
| 4980 | </orderedlist> |
| 4981 | </para> |
| 4982 | |
| 4983 | <para> |
| 4984 | Iteratively working through steps two through four eventually yields |
| 4985 | a minimal, streamlined configuration file. |
| 4986 | Once you have the best <filename>.config</filename>, you can build the Linux |
| 4987 | Yocto kernel. |
| 4988 | </para> |
| 4989 | </section> |
| 4990 | </section> |
| 4991 | |
| 4992 | <section id="patching-the-kernel"> |
| 4993 | <title>Patching the Kernel</title> |
| 4994 | |
| 4995 | <para> |
| 4996 | Patching the kernel involves changing or adding configurations to an existing kernel, |
| 4997 | changing or adding recipes to the kernel that are needed to support specific hardware features, |
| 4998 | or even altering the source code itself. |
| 4999 | <note> |
| 5000 | You can use the <filename>yocto-kernel</filename> script |
| 5001 | found in the <link linkend='source-directory'>Source Directory</link> |
| 5002 | under <filename>scripts</filename> to manage kernel patches and configuration. |
| 5003 | 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>" |
| 5004 | section in the Yocto Project Board Support Packages (BSP) Developer's Guide for |
| 5005 | more information.</note> |
| 5006 | </para> |
| 5007 | |
| 5008 | <para> |
| 5009 | This example creates a simple patch by adding some QEMU emulator console |
| 5010 | output at boot time through <filename>printk</filename> statements in the kernel's |
| 5011 | <filename>calibrate.c</filename> source code file. |
| 5012 | Applying the patch and booting the modified image causes the added |
| 5013 | messages to appear on the emulator's console. |
| 5014 | </para> |
| 5015 | |
| 5016 | <para> |
| 5017 | The example assumes a clean build exists for the <filename>qemux86</filename> |
| 5018 | machine in a |
| 5019 | <link linkend='source-directory'>Source Directory</link> |
| 5020 | named <filename>poky</filename>. |
| 5021 | Furthermore, the <link linkend='build-directory'>Build Directory</link> is |
| 5022 | <filename>build</filename> and is located in <filename>poky</filename> and |
| 5023 | the kernel is based on the Linux 3.4 kernel. |
| 5024 | </para> |
| 5025 | |
| 5026 | <para> |
| 5027 | Also, for more information on patching the kernel, see the |
| 5028 | "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#applying-patches'>Applying Patches</ulink>" |
| 5029 | section in the Yocto Project Linux Kernel Development Manual. |
| 5030 | </para> |
| 5031 | |
| 5032 | <section id='create-a-layer-for-your-changes'> |
| 5033 | <title>Create a Layer for your Changes</title> |
| 5034 | |
| 5035 | <para> |
| 5036 | The first step is to create a layer so you can isolate your |
| 5037 | changes. |
| 5038 | Rather than use the <filename>yocto-layer</filename> script |
| 5039 | to create the layer, this example steps through the process |
| 5040 | by hand. |
| 5041 | If you want information on the script that creates a general |
| 5042 | layer, see the |
| 5043 | "<link linkend='creating-a-general-layer-using-the-yocto-layer-script'>Creating a General Layer Using the yocto-layer Script</link>" |
| 5044 | section. |
| 5045 | </para> |
| 5046 | |
| 5047 | <para> |
| 5048 | These two commands create a directory you can use for your |
| 5049 | layer: |
| 5050 | <literallayout class='monospaced'> |
| 5051 | $ cd ~/poky |
| 5052 | $ mkdir meta-mylayer |
| 5053 | </literallayout> |
| 5054 | Creating a directory that follows the Yocto Project layer naming |
| 5055 | conventions sets up the layer for your changes. |
| 5056 | The layer is where you place your configuration files, append |
| 5057 | files, and patch files. |
| 5058 | To learn more about creating a layer and filling it with the |
| 5059 | files you need, see the "<link linkend='understanding-and-creating-layers'>Understanding |
| 5060 | and Creating Layers</link>" section. |
| 5061 | </para> |
| 5062 | </section> |
| 5063 | |
| 5064 | <section id='finding-the-kernel-source-code'> |
| 5065 | <title>Finding the Kernel Source Code</title> |
| 5066 | |
| 5067 | <para> |
| 5068 | Each time you build a kernel image, the kernel source code is fetched |
| 5069 | and unpacked into the following directory: |
| 5070 | <literallayout class='monospaced'> |
| 5071 | ${S}/linux |
| 5072 | </literallayout> |
| 5073 | See the "<link linkend='finding-the-temporary-source-code'>Finding Temporary Source Code</link>" |
| 5074 | section and the |
| 5075 | <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink> variable |
| 5076 | for more information about where source is kept during a build. |
| 5077 | </para> |
| 5078 | |
| 5079 | <para> |
| 5080 | For this example, we are going to patch the |
| 5081 | <filename>init/calibrate.c</filename> file |
| 5082 | by adding some simple console <filename>printk</filename> statements that we can |
| 5083 | see when we boot the image using QEMU. |
| 5084 | </para> |
| 5085 | </section> |
| 5086 | |
| 5087 | <section id='creating-the-patch'> |
| 5088 | <title>Creating the Patch</title> |
| 5089 | |
| 5090 | <para> |
| 5091 | Two methods exist by which you can create the patch: |
| 5092 | <link linkend='using-devtool-in-your-workflow'><filename>devtool</filename></link> and |
| 5093 | <link linkend='using-a-quilt-workflow'>Quilt</link>. |
| 5094 | For kernel patches, the Git workflow is more appropriate. |
| 5095 | This section assumes the Git workflow and shows the steps specific to |
| 5096 | this example. |
| 5097 | <orderedlist> |
| 5098 | <listitem><para><emphasis>Change the working directory</emphasis>: |
| 5099 | Change to where the kernel source code is before making |
| 5100 | your edits to the <filename>calibrate.c</filename> file: |
| 5101 | <literallayout class='monospaced'> |
| 5102 | $ cd ~/poky/build/tmp/work/qemux86-poky-linux/linux-yocto-${PV}-${PR}/linux |
| 5103 | </literallayout> |
| 5104 | Because you are working in an established Git repository, |
| 5105 | you must be in this directory in order to commit your changes |
| 5106 | and create the patch file. |
| 5107 | <note>The <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink> and |
| 5108 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink> variables |
| 5109 | represent the version and revision for the |
| 5110 | <filename>linux-yocto</filename> recipe. |
| 5111 | The <filename>PV</filename> variable includes the Git meta and machine |
| 5112 | hashes, which make the directory name longer than you might |
| 5113 | expect. |
| 5114 | </note></para></listitem> |
| 5115 | <listitem><para><emphasis>Edit the source file</emphasis>: |
| 5116 | Edit the <filename>init/calibrate.c</filename> file to have the |
| 5117 | following changes: |
| 5118 | <literallayout class='monospaced'> |
| 5119 | void calibrate_delay(void) |
| 5120 | { |
| 5121 | unsigned long lpj; |
| 5122 | static bool printed; |
| 5123 | int this_cpu = smp_processor_id(); |
| 5124 | |
| 5125 | printk("*************************************\n"); |
| 5126 | printk("* *\n"); |
| 5127 | printk("* HELLO YOCTO KERNEL *\n"); |
| 5128 | printk("* *\n"); |
| 5129 | printk("*************************************\n"); |
| 5130 | |
| 5131 | if (per_cpu(cpu_loops_per_jiffy, this_cpu)) { |
| 5132 | . |
| 5133 | . |
| 5134 | . |
| 5135 | </literallayout></para></listitem> |
| 5136 | <listitem><para><emphasis>Stage and commit your changes</emphasis>: |
| 5137 | These Git commands display the modified file, stage it, and then |
| 5138 | commit the file: |
| 5139 | <literallayout class='monospaced'> |
| 5140 | $ git status |
| 5141 | $ git add init/calibrate.c |
| 5142 | $ git commit -m "calibrate: Add printk example" |
| 5143 | </literallayout></para></listitem> |
| 5144 | <listitem><para><emphasis>Generate the patch file</emphasis>: |
| 5145 | This Git command creates the a patch file named |
| 5146 | <filename>0001-calibrate-Add-printk-example.patch</filename> |
| 5147 | in the current directory. |
| 5148 | <literallayout class='monospaced'> |
| 5149 | $ git format-patch -1 |
| 5150 | </literallayout> |
| 5151 | </para></listitem> |
| 5152 | </orderedlist> |
| 5153 | </para> |
| 5154 | </section> |
| 5155 | |
| 5156 | <section id='set-up-your-layer-for-the-build'> |
| 5157 | <title>Set Up Your Layer for the Build</title> |
| 5158 | |
| 5159 | <para>These steps get your layer set up for the build: |
| 5160 | <orderedlist> |
| 5161 | <listitem><para><emphasis>Create additional structure</emphasis>: |
| 5162 | Create the additional layer structure: |
| 5163 | <literallayout class='monospaced'> |
| 5164 | $ cd ~/poky/meta-mylayer |
| 5165 | $ mkdir conf |
| 5166 | $ mkdir recipes-kernel |
| 5167 | $ mkdir recipes-kernel/linux |
| 5168 | $ mkdir recipes-kernel/linux/linux-yocto |
| 5169 | </literallayout> |
| 5170 | The <filename>conf</filename> directory holds your configuration files, while the |
| 5171 | <filename>recipes-kernel</filename> directory holds your append file and |
| 5172 | your patch file.</para></listitem> |
| 5173 | <listitem><para><emphasis>Create the layer configuration file</emphasis>: |
| 5174 | Move to the <filename>meta-mylayer/conf</filename> directory and create |
| 5175 | the <filename>layer.conf</filename> file as follows: |
| 5176 | <literallayout class='monospaced'> |
| 5177 | # We have a conf and classes directory, add to BBPATH |
| 5178 | BBPATH .= ":${LAYERDIR}" |
| 5179 | |
| 5180 | # We have recipes-* directories, add to BBFILES |
| 5181 | BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \ |
| 5182 | ${LAYERDIR}/recipes-*/*/*.bbappend" |
| 5183 | |
| 5184 | BBFILE_COLLECTIONS += "mylayer" |
| 5185 | BBFILE_PATTERN_mylayer = "^${LAYERDIR}/" |
| 5186 | BBFILE_PRIORITY_mylayer = "5" |
| 5187 | </literallayout> |
| 5188 | Notice <filename>mylayer</filename> as part of the last three |
| 5189 | statements.</para></listitem> |
| 5190 | <listitem><para><emphasis>Create the kernel recipe append file</emphasis>: |
| 5191 | Move to the <filename>meta-mylayer/recipes-kernel/linux</filename> directory and create |
| 5192 | the <filename>linux-yocto_3.4.bbappend</filename> file as follows: |
| 5193 | <literallayout class='monospaced'> |
| 5194 | FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" |
| 5195 | |
| 5196 | SRC_URI += "file://0001-calibrate-Add-printk-example.patch" |
| 5197 | </literallayout> |
| 5198 | The <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink> |
| 5199 | and <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> |
| 5200 | statements enable the OpenEmbedded build system to find the patch file. |
| 5201 | For more information on using append files, see the |
| 5202 | "<link linkend='using-bbappend-files'>Using .bbappend Files</link>" |
| 5203 | section. |
| 5204 | </para></listitem> |
| 5205 | <listitem><para><emphasis>Put the patch file in your layer</emphasis>: |
| 5206 | Move the <filename>0001-calibrate-Add-printk-example.patch</filename> file to |
| 5207 | the <filename>meta-mylayer/recipes-kernel/linux/linux-yocto</filename> |
| 5208 | directory.</para></listitem> |
| 5209 | </orderedlist> |
| 5210 | </para> |
| 5211 | </section> |
| 5212 | |
| 5213 | <section id='set-up-for-the-build'> |
| 5214 | <title>Set Up for the Build</title> |
| 5215 | |
| 5216 | <para> |
| 5217 | Do the following to make sure the build parameters are set up for the example. |
| 5218 | Once you set up these build parameters, they do not have to change unless you |
| 5219 | change the target architecture of the machine you are building: |
| 5220 | <itemizedlist> |
| 5221 | <listitem><para><emphasis>Build for the correct target architecture:</emphasis> Your |
| 5222 | selected <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink> |
| 5223 | definition within the <filename>local.conf</filename> file in the |
| 5224 | <link linkend='build-directory'>Build Directory</link> |
| 5225 | specifies the target architecture used when building the Linux kernel. |
| 5226 | By default, <filename>MACHINE</filename> is set to |
| 5227 | <filename>qemux86</filename>, which specifies a 32-bit |
| 5228 | <trademark class='registered'>Intel</trademark> Architecture |
| 5229 | target machine suitable for the QEMU emulator.</para></listitem> |
| 5230 | <listitem><para><emphasis>Identify your <filename>meta-mylayer</filename> |
| 5231 | layer:</emphasis> The |
| 5232 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'><filename>BBLAYERS</filename></ulink> |
| 5233 | variable in the |
| 5234 | <filename>bblayers.conf</filename> file found in the |
| 5235 | <filename>poky/build/conf</filename> directory needs to have the path to your local |
| 5236 | <filename>meta-mylayer</filename> layer. |
| 5237 | By default, the <filename>BBLAYERS</filename> variable contains paths to |
| 5238 | <filename>meta</filename>, <filename>meta-yocto</filename>, and |
| 5239 | <filename>meta-yocto-bsp</filename> in the |
| 5240 | <filename>poky</filename> Git repository. |
| 5241 | Add the path to your <filename>meta-mylayer</filename> location: |
| 5242 | <literallayout class='monospaced'> |
| 5243 | BBLAYERS ?= " \ |
| 5244 | $HOME/poky/meta \ |
| 5245 | $HOME/poky/meta-yocto \ |
| 5246 | $HOME/poky/meta-yocto-bsp \ |
| 5247 | $HOME/poky/meta-mylayer \ |
| 5248 | " |
| 5249 | </literallayout></para></listitem> |
| 5250 | </itemizedlist> |
| 5251 | </para> |
| 5252 | </section> |
| 5253 | |
| 5254 | <section id='build-the-modified-qemu-kernel-image'> |
| 5255 | <title>Build the Modified QEMU Kernel Image</title> |
| 5256 | |
| 5257 | <para> |
| 5258 | The following steps build your modified kernel image: |
| 5259 | <orderedlist> |
| 5260 | <listitem><para><emphasis>Be sure your build environment is initialized</emphasis>: |
| 5261 | Your environment should be set up since you previously sourced |
| 5262 | the |
| 5263 | <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink> |
| 5264 | script. |
| 5265 | If it is not, source the script again from <filename>poky</filename>. |
| 5266 | <literallayout class='monospaced'> |
| 5267 | $ cd ~/poky |
| 5268 | $ source &OE_INIT_FILE; |
| 5269 | </literallayout> |
| 5270 | </para></listitem> |
| 5271 | <listitem><para><emphasis>Clean up</emphasis>: |
| 5272 | Be sure to clean the shared state out by using BitBake |
| 5273 | to run from within the Build Directory the |
| 5274 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-cleansstate'><filename>do_cleansstate</filename></ulink> |
| 5275 | task as follows: |
| 5276 | <literallayout class='monospaced'> |
| 5277 | $ bitbake -c cleansstate linux-yocto |
| 5278 | </literallayout></para> |
| 5279 | <para> |
| 5280 | <note> |
| 5281 | Never remove any files by hand from the |
| 5282 | <filename>tmp/deploy</filename> |
| 5283 | directory inside the |
| 5284 | <link linkend='build-directory'>Build Directory</link>. |
| 5285 | Always use the various BitBake clean tasks to |
| 5286 | clear out previous build artifacts. |
| 5287 | For information on the clean tasks, see the |
| 5288 | "<ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-clean'><filename>do_clean</filename></ulink>", |
| 5289 | "<ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-cleanall'><filename>do_cleanall</filename></ulink>", |
| 5290 | and |
| 5291 | "<ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-cleansstate'><filename>do_cleansstate</filename></ulink>" |
| 5292 | sections all in the Yocto Project Reference |
| 5293 | Manual. |
| 5294 | </note> |
| 5295 | </para></listitem> |
| 5296 | <listitem><para><emphasis>Build the image</emphasis>: |
| 5297 | Next, build the kernel image using this command: |
| 5298 | <literallayout class='monospaced'> |
| 5299 | $ bitbake -k linux-yocto |
| 5300 | </literallayout></para></listitem> |
| 5301 | </orderedlist> |
| 5302 | </para> |
| 5303 | </section> |
| 5304 | |
| 5305 | <section id='boot-the-image-and-verify-your-changes'> |
| 5306 | <title>Boot the Image and Verify Your Changes</title> |
| 5307 | |
| 5308 | <para> |
| 5309 | These steps boot the image and allow you to see the changes |
| 5310 | <orderedlist> |
| 5311 | <listitem><para><emphasis>Boot the image</emphasis>: |
| 5312 | Boot the modified image in the QEMU emulator |
| 5313 | using this command: |
| 5314 | <literallayout class='monospaced'> |
| 5315 | $ runqemu qemux86 |
| 5316 | </literallayout></para></listitem> |
| 5317 | <listitem><para><emphasis>Verify the changes</emphasis>: |
| 5318 | Log into the machine using <filename>root</filename> with no password and then |
| 5319 | use the following shell command to scroll through the console's boot output. |
| 5320 | <literallayout class='monospaced'> |
| 5321 | # dmesg | less |
| 5322 | </literallayout> |
| 5323 | You should see the results of your <filename>printk</filename> statements |
| 5324 | as part of the output.</para></listitem> |
| 5325 | </orderedlist> |
| 5326 | </para> |
| 5327 | </section> |
| 5328 | </section> |
| 5329 | |
| 5330 | <section id='making-images-more-secure'> |
| 5331 | <title>Making Images More Secure</title> |
| 5332 | |
| 5333 | <para> |
| 5334 | Security is of increasing concern for embedded devices. |
| 5335 | Consider the issues and problems discussed in just this |
| 5336 | sampling of work found across the Internet: |
| 5337 | <itemizedlist> |
| 5338 | <listitem><para><emphasis> |
| 5339 | "<ulink url='https://www.schneier.com/blog/archives/2014/01/security_risks_9.html'>Security Risks of Embedded Systems</ulink>"</emphasis> |
| 5340 | by Bruce Schneier |
| 5341 | </para></listitem> |
| 5342 | <listitem><para><emphasis> |
| 5343 | "<ulink url='http://internetcensus2012.bitbucket.org/paper.html'>Internet Census 2012</ulink>"</emphasis> |
| 5344 | by Carna Botnet</para></listitem> |
| 5345 | <listitem><para><emphasis> |
| 5346 | "<ulink url='http://elinux.org/images/6/6f/Security-issues.pdf'>Security Issues for Embedded Devices</ulink>"</emphasis> |
| 5347 | by Jake Edge |
| 5348 | </para></listitem> |
| 5349 | <listitem><para><emphasis> |
| 5350 | "<ulink url='https://www.nccgroup.com/media/18475/exploiting_security_gateways_via_their_web_interfaces.pdf'>They ought to know better: Exploiting Security Gateways via their Web Interfaces</ulink>"</emphasis> |
| 5351 | by Ben Williams |
| 5352 | </para></listitem> |
| 5353 | </itemizedlist> |
| 5354 | </para> |
| 5355 | |
| 5356 | <para> |
| 5357 | When securing your image is of concern, there are steps, tools, |
| 5358 | and variables that you can consider to help you reach the |
| 5359 | security goals you need for your particular device. |
| 5360 | Not all situations are identical when it comes to making an |
| 5361 | image secure. |
| 5362 | Consequently, this section provides some guidance and suggestions |
| 5363 | for consideration when you want to make your image more secure. |
| 5364 | <note> |
| 5365 | Because the security requirements and risks are |
| 5366 | different for every type of device, this section cannot |
| 5367 | provide a complete reference on securing your custom OS. |
| 5368 | It is strongly recommended that you also consult other sources |
| 5369 | of information on embedded Linux system hardening and on |
| 5370 | security. |
| 5371 | </note> |
| 5372 | </para> |
| 5373 | |
| 5374 | <section id='general-considerations'> |
| 5375 | <title>General Considerations</title> |
| 5376 | |
| 5377 | <para> |
| 5378 | General considerations exist that help you create more |
| 5379 | secure images. |
| 5380 | You should consider the following suggestions to help |
| 5381 | make your device more secure: |
| 5382 | <itemizedlist> |
| 5383 | <listitem><para> |
| 5384 | Scan additional code you are adding to the system |
| 5385 | (e.g. application code) by using static analysis |
| 5386 | tools. |
| 5387 | Look for buffer overflows and other potential |
| 5388 | security problems. |
| 5389 | </para></listitem> |
| 5390 | <listitem><para> |
| 5391 | Pay particular attention to the security for |
| 5392 | any web-based administration interface. |
| 5393 | </para> |
| 5394 | <para>Web interfaces typically need to perform |
| 5395 | administrative functions and tend to need to run with |
| 5396 | elevated privileges. |
| 5397 | Thus, the consequences resulting from the interface's |
| 5398 | security becoming compromised can be serious. |
| 5399 | Look for common web vulnerabilities such as |
| 5400 | cross-site-scripting (XSS), unvalidated inputs, |
| 5401 | and so forth.</para> |
| 5402 | <para>As with system passwords, the default credentials |
| 5403 | for accessing a web-based interface should not be the |
| 5404 | same across all devices. |
| 5405 | This is particularly true if the interface is enabled |
| 5406 | by default as it can be assumed that many end-users |
| 5407 | will not change the credentials. |
| 5408 | </para></listitem> |
| 5409 | <listitem><para> |
| 5410 | Ensure you can update the software on the device to |
| 5411 | mitigate vulnerabilities discovered in the future. |
| 5412 | This consideration especially applies when your |
| 5413 | device is network-enabled. |
| 5414 | </para></listitem> |
| 5415 | <listitem><para> |
| 5416 | Ensure you remove or disable debugging functionality |
| 5417 | before producing the final image. |
| 5418 | For information on how to do this, see the |
| 5419 | "<link linkend='considerations-specific-to-the-openembedded-build-system'>Considerations Specific to the OpenEmbedded Build System</link>" |
| 5420 | section. |
| 5421 | </para></listitem> |
| 5422 | <listitem><para> |
| 5423 | Ensure you have no network services listening that |
| 5424 | are not needed. |
| 5425 | </para></listitem> |
| 5426 | <listitem><para> |
| 5427 | Remove any software from the image that is not needed. |
| 5428 | </para></listitem> |
| 5429 | <listitem><para> |
| 5430 | Enable hardware support for secure boot functionality |
| 5431 | when your device supports this functionality. |
| 5432 | </para></listitem> |
| 5433 | </itemizedlist> |
| 5434 | </para> |
| 5435 | </section> |
| 5436 | |
| 5437 | <section id='security-flags'> |
| 5438 | <title>Security Flags</title> |
| 5439 | |
| 5440 | <para> |
| 5441 | The Yocto Project has security flags that you can enable that |
| 5442 | help make your build output more secure. |
| 5443 | The security flags are in the |
| 5444 | <filename>meta/conf/distro/include/security_flags.inc</filename> |
| 5445 | file in your |
| 5446 | <link linkend='source-directory'>Source Directory</link> |
| 5447 | (e.g. <filename>poky</filename>). |
| 5448 | <note> |
| 5449 | Depending on the recipe, certain security flags are enabled |
| 5450 | and disabled by default. |
| 5451 | </note> |
| 5452 | </para> |
| 5453 | |
| 5454 | <para> |
| 5455 | <!-- |
| 5456 | The GCC/LD flags in <filename>security_flags.inc</filename> |
| 5457 | enable more secure code generation. |
| 5458 | By including the <filename>security_flags.inc</filename> |
| 5459 | file, you enable flags to the compiler and linker that cause |
| 5460 | them to generate more secure code. |
| 5461 | <note> |
| 5462 | The GCC/LD flags are enabled by default in the |
| 5463 | <filename>poky-lsb</filename> distribution. |
| 5464 | </note> |
| 5465 | --> |
| 5466 | Use the following line in your |
| 5467 | <filename>local.conf</filename> file or in your custom |
| 5468 | distribution configuration file to enable the security |
| 5469 | compiler and linker flags for your build: |
| 5470 | <literallayout class='monospaced'> |
| 5471 | require conf/distro/include/security_flags.inc |
| 5472 | </literallayout> |
| 5473 | </para> |
| 5474 | </section> |
| 5475 | |
| 5476 | <section id='considerations-specific-to-the-openembedded-build-system'> |
| 5477 | <title>Considerations Specific to the OpenEmbedded Build System</title> |
| 5478 | |
| 5479 | <para> |
| 5480 | You can take some steps that are specific to the |
| 5481 | OpenEmbedded build system to make your images more secure: |
| 5482 | <itemizedlist> |
| 5483 | <listitem><para> |
| 5484 | Ensure "debug-tweaks" is not one of your selected |
| 5485 | <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>. |
| 5486 | When creating a new project, the default is to provide you |
| 5487 | with an initial <filename>local.conf</filename> file that |
| 5488 | enables this feature using the |
| 5489 | <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink> variable with the line: |
| 5490 | <literallayout class='monospaced'> |
| 5491 | EXTRA_IMAGE_FEATURES = "debug-tweaks" |
| 5492 | </literallayout> |
| 5493 | To disable that feature, simply comment out that line in your |
| 5494 | <filename>local.conf</filename> file, or |
| 5495 | make sure <filename>IMAGE_FEATURES</filename> does not contain |
| 5496 | "debug-tweaks" before producing your final image. |
| 5497 | Among other things, leaving this in place sets the |
| 5498 | root password as blank, which makes logging in for |
| 5499 | debugging or inspection easy during |
| 5500 | development but also means anyone can easily log in |
| 5501 | during production. |
| 5502 | </para></listitem> |
| 5503 | <listitem><para> |
| 5504 | It is possible to set a root password for the image |
| 5505 | and also to set passwords for any extra users you might |
| 5506 | add (e.g. administrative or service type users). |
| 5507 | When you set up passwords for multiple images or |
| 5508 | users, you should not duplicate passwords. |
| 5509 | </para> |
| 5510 | <para> |
| 5511 | To set up passwords, use the |
| 5512 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-extrausers'><filename>extrausers</filename></ulink> |
| 5513 | class, which is the preferred method. |
| 5514 | For an example on how to set up both root and user |
| 5515 | passwords, see the |
| 5516 | "<ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-extrausers'><filename>extrausers.bbclass</filename></ulink>" |
| 5517 | section. |
| 5518 | <note> |
| 5519 | When adding extra user accounts or setting a |
| 5520 | root password, be cautious about setting the |
| 5521 | same password on every device. |
| 5522 | If you do this, and the password you have set |
| 5523 | is exposed, then every device is now potentially |
| 5524 | compromised. |
| 5525 | If you need this access but want to ensure |
| 5526 | security, consider setting a different, |
| 5527 | random password for each device. |
| 5528 | Typically, you do this as a separate step after |
| 5529 | you deploy the image onto the device. |
| 5530 | </note> |
| 5531 | </para></listitem> |
| 5532 | <listitem><para> |
| 5533 | Consider enabling a Mandatory Access Control (MAC) |
| 5534 | framework such as SMACK or SELinux and tuning it |
| 5535 | appropriately for your device's usage. |
| 5536 | You can find more information in the |
| 5537 | <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/meta-selinux/'><filename>meta-selinux</filename></ulink> |
| 5538 | layer. |
| 5539 | </para></listitem> |
| 5540 | </itemizedlist> |
| 5541 | </para> |
| 5542 | |
| 5543 | <para> |
| 5544 | </para> |
| 5545 | </section> |
| 5546 | |
| 5547 | <section id='tools-for-hardening-your-image'> |
| 5548 | <title>Tools for Hardening Your Image</title> |
| 5549 | |
| 5550 | <para> |
| 5551 | The Yocto Project provides tools for making your image |
| 5552 | more secure. |
| 5553 | You can find these tools in the |
| 5554 | <filename>meta-security</filename> layer of the |
| 5555 | <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi'>Yocto Project Source Repositories</ulink>. |
| 5556 | </para> |
| 5557 | </section> |
| 5558 | </section> |
| 5559 | |
| 5560 | <section id='creating-your-own-distribution'> |
| 5561 | <title>Creating Your Own Distribution</title> |
| 5562 | |
| 5563 | <para> |
| 5564 | When you build an image using the Yocto Project and |
| 5565 | do not alter any distribution |
| 5566 | <link linkend='metadata'>Metadata</link>, you are creating a |
| 5567 | Poky distribution. |
| 5568 | If you wish to gain more control over package alternative |
| 5569 | selections, compile-time options, and other low-level |
| 5570 | configurations, you can create your own distribution. |
| 5571 | </para> |
| 5572 | |
| 5573 | <para> |
| 5574 | To create your own distribution, the basic steps consist of |
| 5575 | creating your own distribution layer, creating your own |
| 5576 | distribution configuration file, and then adding any needed |
| 5577 | code and Metadata to the layer. |
| 5578 | The following steps provide some more detail: |
| 5579 | <itemizedlist> |
| 5580 | <listitem><para><emphasis>Create a layer for your new distro:</emphasis> |
| 5581 | Create your distribution layer so that you can keep your |
| 5582 | Metadata and code for the distribution separate. |
| 5583 | It is strongly recommended that you create and use your own |
| 5584 | layer for configuration and code. |
| 5585 | Using your own layer as compared to just placing |
| 5586 | configurations in a <filename>local.conf</filename> |
| 5587 | configuration file makes it easier to reproduce the same |
| 5588 | build configuration when using multiple build machines. |
| 5589 | See the |
| 5590 | "<link linkend='creating-a-general-layer-using-the-yocto-layer-script'>Creating a General Layer Using the yocto-layer Script</link>" |
| 5591 | section for information on how to quickly set up a layer. |
| 5592 | </para></listitem> |
| 5593 | <listitem><para><emphasis>Create the distribution configuration file:</emphasis> |
| 5594 | The distribution configuration file needs to be created in |
| 5595 | the <filename>conf/distro</filename> directory of your |
| 5596 | layer. |
| 5597 | You need to name it using your distribution name |
| 5598 | (e.g. <filename>mydistro.conf</filename>). |
| 5599 | <note> |
| 5600 | The |
| 5601 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink> |
| 5602 | variable in your |
| 5603 | <filename>local.conf</filename> file determines the |
| 5604 | name of your distribution. |
| 5605 | </note></para> |
| 5606 | <para>You can split out parts of your configuration file |
| 5607 | into include files and then "require" them from within |
| 5608 | your distribution configuration file. |
| 5609 | Be sure to place the include files in the |
| 5610 | <filename>conf/distro/include</filename> directory of |
| 5611 | your layer. |
| 5612 | A common example usage of include files would be to |
| 5613 | separate out the selection of desired version and revisions |
| 5614 | for individual recipes. |
| 5615 | </para> |
| 5616 | <para>Your configuration file needs to set the following |
| 5617 | required variables: |
| 5618 | <literallayout class='monospaced'> |
| 5619 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_NAME'><filename>DISTRO_NAME</filename></ulink> |
| 5620 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_VERSION'><filename>DISTRO_VERSION</filename></ulink> |
| 5621 | </literallayout> |
| 5622 | These following variables are optional and you typically |
| 5623 | set them from the distribution configuration file: |
| 5624 | <literallayout class='monospaced'> |
| 5625 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink> |
| 5626 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_EXTRA_RDEPENDS'><filename>DISTRO_EXTRA_RDEPENDS</filename></ulink> |
| 5627 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_EXTRA_RRECOMMENDS'><filename>DISTRO_EXTRA_RRECOMMENDS</filename></ulink> |
| 5628 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TCLIBC'><filename>TCLIBC</filename></ulink> |
| 5629 | </literallayout> |
| 5630 | <tip> |
| 5631 | If you want to base your distribution configuration file |
| 5632 | on the very basic configuration from OE-Core, you |
| 5633 | can use |
| 5634 | <filename>conf/distro/defaultsetup.conf</filename> as |
| 5635 | a reference and just include variables that differ |
| 5636 | as compared to <filename>defaultsetup.conf</filename>. |
| 5637 | Alternatively, you can create a distribution |
| 5638 | configuration file from scratch using the |
| 5639 | <filename>defaultsetup.conf</filename> file |
| 5640 | or configuration files from other distributions |
| 5641 | such as Poky or Angstrom as references. |
| 5642 | </tip></para></listitem> |
| 5643 | <listitem><para><emphasis>Provide miscellaneous variables:</emphasis> |
| 5644 | Be sure to define any other variables for which you want to |
| 5645 | create a default or enforce as part of the distribution |
| 5646 | configuration. |
| 5647 | You can include nearly any variable from the |
| 5648 | <filename>local.conf</filename> file. |
| 5649 | The variables you use are not limited to the list in the |
| 5650 | previous bulleted item.</para></listitem> |
| 5651 | <listitem><para><emphasis>Point to Your distribution configuration file:</emphasis> |
| 5652 | In your <filename>local.conf</filename> file in the |
| 5653 | <link linkend='build-directory'>Build Directory</link>, |
| 5654 | set your |
| 5655 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink> |
| 5656 | variable to point to your distribution's configuration file. |
| 5657 | For example, if your distribution's configuration file is |
| 5658 | named <filename>mydistro.conf</filename>, then you point |
| 5659 | to it as follows: |
| 5660 | <literallayout class='monospaced'> |
| 5661 | DISTRO = "mydistro" |
| 5662 | </literallayout></para></listitem> |
| 5663 | <listitem><para><emphasis>Add more to the layer if necessary:</emphasis> |
| 5664 | Use your layer to hold other information needed for the |
| 5665 | distribution: |
| 5666 | <itemizedlist> |
| 5667 | <listitem><para>Add recipes for installing |
| 5668 | distro-specific configuration files that are not |
| 5669 | already installed by another recipe. |
| 5670 | If you have distro-specific configuration files |
| 5671 | that are included by an existing recipe, you should |
| 5672 | add an append file (<filename>.bbappend</filename>) |
| 5673 | for those. |
| 5674 | For general information and recommendations |
| 5675 | on how to add recipes to your layer, see the |
| 5676 | "<link linkend='creating-your-own-layer'>Creating Your Own Layer</link>" |
| 5677 | and |
| 5678 | "<link linkend='best-practices-to-follow-when-creating-layers'>Best Practices to Follow When Creating Layers</link>" |
| 5679 | sections.</para></listitem> |
| 5680 | <listitem><para>Add any image recipes that are specific |
| 5681 | to your distribution.</para></listitem> |
| 5682 | <listitem><para>Add a <filename>psplash</filename> |
| 5683 | append file for a branded splash screen. |
| 5684 | For information on append files, see the |
| 5685 | "<link linkend='using-bbappend-files'>Using .bbappend Files</link>" |
| 5686 | section.</para></listitem> |
| 5687 | <listitem><para>Add any other append files to make |
| 5688 | custom changes that are specific to individual |
| 5689 | recipes.</para></listitem> |
| 5690 | </itemizedlist></para></listitem> |
| 5691 | </itemizedlist> |
| 5692 | </para> |
| 5693 | </section> |
| 5694 | |
| 5695 | <section id='creating-a-custom-template-configuration-directory'> |
| 5696 | <title>Creating a Custom Template Configuration Directory</title> |
| 5697 | |
| 5698 | <para> |
| 5699 | If you are producing your own customized version |
| 5700 | of the build system for use by other users, you might |
| 5701 | want to customize the message shown by the setup script or |
| 5702 | you might want to change the template configuration files (i.e. |
| 5703 | <filename>local.conf</filename> and |
| 5704 | <filename>bblayers.conf</filename>) that are created in |
| 5705 | a new build directory. |
| 5706 | </para> |
| 5707 | |
| 5708 | <para> |
| 5709 | The OpenEmbedded build system uses the environment variable |
| 5710 | <filename>TEMPLATECONF</filename> to locate the directory |
| 5711 | from which it gathers configuration information that ultimately |
| 5712 | ends up in the |
| 5713 | <link linkend='build-directory'>Build Directory's</link> |
| 5714 | <filename>conf</filename> directory. |
| 5715 | By default, <filename>TEMPLATECONF</filename> is set as |
| 5716 | follows in the <filename>poky</filename> repository: |
| 5717 | <literallayout class='monospaced'> |
| 5718 | TEMPLATECONF=${TEMPLATECONF:-meta-yocto/conf} |
| 5719 | </literallayout> |
| 5720 | This is the directory used by the build system to find templates |
| 5721 | from which to build some key configuration files. |
| 5722 | If you look at this directory, you will see the |
| 5723 | <filename>bblayers.conf.sample</filename>, |
| 5724 | <filename>local.conf.sample</filename>, and |
| 5725 | <filename>conf-notes.txt</filename> files. |
| 5726 | The build system uses these files to form the respective |
| 5727 | <filename>bblayers.conf</filename> file, |
| 5728 | <filename>local.conf</filename> file, and display the list of |
| 5729 | BitBake targets when running the setup script. |
| 5730 | </para> |
| 5731 | |
| 5732 | <para> |
| 5733 | To override these default configuration files with |
| 5734 | configurations you want used within every new |
| 5735 | Build Directory, simply set the |
| 5736 | <filename>TEMPLATECONF</filename> variable to your directory. |
| 5737 | The <filename>TEMPLATECONF</filename> variable is set in the |
| 5738 | <filename>.templateconf</filename> file, which is in the |
| 5739 | top-level |
| 5740 | <link linkend='source-directory'>Source Directory</link> |
| 5741 | folder (e.g. <filename>poky</filename>). |
| 5742 | Edit the <filename>.templateconf</filename> so that it can locate |
| 5743 | your directory. |
| 5744 | </para> |
| 5745 | |
| 5746 | <para> |
| 5747 | Best practices dictate that you should keep your |
| 5748 | template configuration directory in your custom distribution layer. |
| 5749 | For example, suppose you have a layer named |
| 5750 | <filename>meta-mylayer</filename> located in your home directory |
| 5751 | and you want your template configuration directory named |
| 5752 | <filename>myconf</filename>. |
| 5753 | Changing the <filename>.templateconf</filename> as follows |
| 5754 | causes the OpenEmbedded build system to look in your directory |
| 5755 | and base its configuration files on the |
| 5756 | <filename>*.sample</filename> configuration files it finds. |
| 5757 | The final configuration files (i.e. |
| 5758 | <filename>local.conf</filename> and |
| 5759 | <filename>bblayers.conf</filename> ultimately still end up in |
| 5760 | your Build Directory, but they are based on your |
| 5761 | <filename>*.sample</filename> files. |
| 5762 | <literallayout class='monospaced'> |
| 5763 | TEMPLATECONF=${TEMPLATECONF:-meta-mylayer/myconf} |
| 5764 | </literallayout> |
| 5765 | </para> |
| 5766 | |
| 5767 | <para> |
| 5768 | Aside from the <filename>*.sample</filename> configuration files, |
| 5769 | the <filename>conf-notes.txt</filename> also resides in the |
| 5770 | default <filename>meta-yocto/conf</filename> directory. |
| 5771 | The scripts that set up the build environment |
| 5772 | (i.e. |
| 5773 | <ulink url="&YOCTO_DOCS_REF_URL;#structure-core-script"><filename>&OE_INIT_FILE;</filename></ulink> |
| 5774 | and |
| 5775 | <ulink url="&YOCTO_DOCS_REF_URL;#structure-memres-core-script"><filename>oe-init-build-env-memres</filename></ulink>) |
| 5776 | use this file to display BitBake targets as part of the script |
| 5777 | output. |
| 5778 | Customizing this <filename>conf-notes.txt</filename> file is a |
| 5779 | good way to make sure your list of custom targets appears |
| 5780 | as part of the script's output. |
| 5781 | </para> |
| 5782 | |
| 5783 | <para> |
| 5784 | Here is the default list of targets displayed as a result of |
| 5785 | running either of the setup scripts: |
| 5786 | <literallayout class='monospaced'> |
| 5787 | You can now run 'bitbake <target>' |
| 5788 | |
| 5789 | Common targets are: |
| 5790 | core-image-minimal |
| 5791 | core-image-sato |
| 5792 | meta-toolchain |
| 5793 | adt-installer |
| 5794 | meta-ide-support |
| 5795 | </literallayout> |
| 5796 | </para> |
| 5797 | |
| 5798 | <para> |
| 5799 | Changing the listed common targets is as easy as editing your |
| 5800 | version of <filename>conf-notes.txt</filename> in your |
| 5801 | custom template configuration directory and making sure you |
| 5802 | have <filename>TEMPLATECONF</filename> set to your directory. |
| 5803 | </para> |
| 5804 | </section> |
| 5805 | |
| 5806 | <section id='building-a-tiny-system'> |
| 5807 | <title>Building a Tiny System</title> |
| 5808 | |
| 5809 | <para> |
| 5810 | Very small distributions have some significant advantages such |
| 5811 | as requiring less on-die or in-package memory (cheaper), better |
| 5812 | performance through efficient cache usage, lower power requirements |
| 5813 | due to less memory, faster boot times, and reduced development |
| 5814 | overhead. |
| 5815 | Some real-world examples where a very small distribution gives |
| 5816 | you distinct advantages are digital cameras, medical devices, |
| 5817 | and small headless systems. |
| 5818 | </para> |
| 5819 | |
| 5820 | <para> |
| 5821 | This section presents information that shows you how you can |
| 5822 | trim your distribution to even smaller sizes than the |
| 5823 | <filename>poky-tiny</filename> distribution, which is around |
| 5824 | 5 Mbytes, that can be built out-of-the-box using the Yocto Project. |
| 5825 | </para> |
| 5826 | |
| 5827 | <section id='tiny-system-overview'> |
| 5828 | <title>Overview</title> |
| 5829 | |
| 5830 | <para> |
| 5831 | The following list presents the overall steps you need to |
| 5832 | consider and perform to create distributions with smaller |
| 5833 | root filesystems, achieve faster boot times, maintain your critical |
| 5834 | functionality, and avoid initial RAM disks: |
| 5835 | <itemizedlist> |
| 5836 | <listitem><para> |
| 5837 | <link linkend='goals-and-guiding-principles'>Determine your goals and guiding principles.</link> |
| 5838 | </para></listitem> |
| 5839 | <listitem><para> |
| 5840 | <link linkend='understand-what-gives-your-image-size'>Understand what contributes to your image size.</link> |
| 5841 | </para></listitem> |
| 5842 | <listitem><para> |
| 5843 | <link linkend='trim-the-root-filesystem'>Reduce the size of the root filesystem.</link> |
| 5844 | </para></listitem> |
| 5845 | <listitem><para> |
| 5846 | <link linkend='trim-the-kernel'>Reduce the size of the kernel.</link> |
| 5847 | </para></listitem> |
| 5848 | <listitem><para> |
| 5849 | <link linkend='remove-package-management-requirements'>Eliminate packaging requirements.</link> |
| 5850 | </para></listitem> |
| 5851 | <listitem><para> |
| 5852 | <link linkend='look-for-other-ways-to-minimize-size'>Look for other ways to minimize size.</link> |
| 5853 | </para></listitem> |
| 5854 | <listitem><para> |
| 5855 | <link linkend='iterate-on-the-process'>Iterate on the process.</link> |
| 5856 | </para></listitem> |
| 5857 | </itemizedlist> |
| 5858 | </para> |
| 5859 | </section> |
| 5860 | |
| 5861 | <section id='goals-and-guiding-principles'> |
| 5862 | <title>Goals and Guiding Principles</title> |
| 5863 | |
| 5864 | <para> |
| 5865 | Before you can reach your destination, you need to know |
| 5866 | where you are going. |
| 5867 | Here is an example list that you can use as a guide when |
| 5868 | creating very small distributions: |
| 5869 | <itemizedlist> |
| 5870 | <listitem><para>Determine how much space you need |
| 5871 | (e.g. a kernel that is 1 Mbyte or less and |
| 5872 | a root filesystem that is 3 Mbytes or less). |
| 5873 | </para></listitem> |
| 5874 | <listitem><para>Find the areas that are currently |
| 5875 | taking 90% of the space and concentrate on reducing |
| 5876 | those areas. |
| 5877 | </para></listitem> |
| 5878 | <listitem><para>Do not create any difficult "hacks" |
| 5879 | to achieve your goals.</para></listitem> |
| 5880 | <listitem><para>Leverage the device-specific |
| 5881 | options.</para></listitem> |
| 5882 | <listitem><para>Work in a separate layer so that you |
| 5883 | keep changes isolated. |
| 5884 | For information on how to create layers, see |
| 5885 | the "<link linkend='understanding-and-creating-layers'>Understanding and Creating Layers</link>" section. |
| 5886 | </para></listitem> |
| 5887 | </itemizedlist> |
| 5888 | </para> |
| 5889 | </section> |
| 5890 | |
| 5891 | <section id='understand-what-gives-your-image-size'> |
| 5892 | <title>Understand What Contributes to Your Image Size</title> |
| 5893 | |
| 5894 | <para> |
| 5895 | It is easiest to have something to start with when creating |
| 5896 | your own distribution. |
| 5897 | You can use the Yocto Project out-of-the-box to create the |
| 5898 | <filename>poky-tiny</filename> distribution. |
| 5899 | Ultimately, you will want to make changes in your own |
| 5900 | distribution that are likely modeled after |
| 5901 | <filename>poky-tiny</filename>. |
| 5902 | <note> |
| 5903 | To use <filename>poky-tiny</filename> in your build, |
| 5904 | set the |
| 5905 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink> |
| 5906 | variable in your |
| 5907 | <filename>local.conf</filename> file to "poky-tiny" |
| 5908 | as described in the |
| 5909 | "<link linkend='creating-your-own-distribution'>Creating Your Own Distribution</link>" |
| 5910 | section. |
| 5911 | </note> |
| 5912 | </para> |
| 5913 | |
| 5914 | <para> |
| 5915 | Understanding some memory concepts will help you reduce the |
| 5916 | system size. |
| 5917 | Memory consists of static, dynamic, and temporary memory. |
| 5918 | Static memory is the TEXT (code), DATA (initialized data |
| 5919 | in the code), and BSS (uninitialized data) sections. |
| 5920 | Dynamic memory represents memory that is allocated at runtime: |
| 5921 | stacks, hash tables, and so forth. |
| 5922 | Temporary memory is recovered after the boot process. |
| 5923 | This memory consists of memory used for decompressing |
| 5924 | the kernel and for the <filename>__init__</filename> |
| 5925 | functions. |
| 5926 | </para> |
| 5927 | |
| 5928 | <para> |
| 5929 | To help you see where you currently are with kernel and root |
| 5930 | filesystem sizes, you can use two tools found in the |
| 5931 | <link linkend='source-directory'>Source Directory</link> in |
| 5932 | the <filename>scripts/tiny/</filename> directory: |
| 5933 | <itemizedlist> |
| 5934 | <listitem><para><filename>ksize.py</filename>: Reports |
| 5935 | component sizes for the kernel build objects. |
| 5936 | </para></listitem> |
| 5937 | <listitem><para><filename>dirsize.py</filename>: Reports |
| 5938 | component sizes for the root filesystem.</para></listitem> |
| 5939 | </itemizedlist> |
| 5940 | This next tool and command help you organize configuration |
| 5941 | fragments and view file dependencies in a human-readable form: |
| 5942 | <itemizedlist> |
| 5943 | <listitem><para><filename>merge_config.sh</filename>: |
| 5944 | Helps you manage configuration files and fragments |
| 5945 | within the kernel. |
| 5946 | With this tool, you can merge individual configuration |
| 5947 | fragments together. |
| 5948 | The tool allows you to make overrides and warns you |
| 5949 | of any missing configuration options. |
| 5950 | The tool is ideal for allowing you to iterate on |
| 5951 | configurations, create minimal configurations, and |
| 5952 | create configuration files for different machines |
| 5953 | without having to duplicate your process.</para> |
| 5954 | <para>The <filename>merge_config.sh</filename> script is |
| 5955 | part of the Linux Yocto kernel Git repositories |
| 5956 | (i.e. <filename>linux-yocto-3.14</filename>, |
| 5957 | <filename>linux-yocto-3.10</filename>, |
| 5958 | <filename>linux-yocto-3.8</filename>, and so forth) |
| 5959 | in the |
| 5960 | <filename>scripts/kconfig</filename> directory.</para> |
| 5961 | <para>For more information on configuration fragments, |
| 5962 | see the |
| 5963 | "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#generating-configuration-files'>Generating Configuration Files</ulink>" |
| 5964 | section of the Yocto Project Linux Kernel Development |
| 5965 | Manual and the "<link linkend='creating-config-fragments'>Creating Configuration Fragments</link>" |
| 5966 | section, which is in this manual.</para></listitem> |
| 5967 | <listitem><para><filename>bitbake -u depexp -g <replaceable>bitbake_target</replaceable></filename>: |
| 5968 | Using the BitBake command with these options brings up |
| 5969 | a Dependency Explorer from which you can view file |
| 5970 | dependencies. |
| 5971 | Understanding these dependencies allows you to make |
| 5972 | informed decisions when cutting out various pieces of the |
| 5973 | kernel and root filesystem.</para></listitem> |
| 5974 | </itemizedlist> |
| 5975 | </para> |
| 5976 | </section> |
| 5977 | |
| 5978 | <section id='trim-the-root-filesystem'> |
| 5979 | <title>Trim the Root Filesystem</title> |
| 5980 | |
| 5981 | <para> |
| 5982 | The root filesystem is made up of packages for booting, |
| 5983 | libraries, and applications. |
| 5984 | To change things, you can configure how the packaging happens, |
| 5985 | which changes the way you build them. |
| 5986 | You can also modify the filesystem itself or select a different |
| 5987 | filesystem. |
| 5988 | </para> |
| 5989 | |
| 5990 | <para> |
| 5991 | First, find out what is hogging your root filesystem by running the |
| 5992 | <filename>dirsize.py</filename> script from your root directory: |
| 5993 | <literallayout class='monospaced'> |
| 5994 | $ cd <replaceable>root-directory-of-image</replaceable> |
| 5995 | $ dirsize.py 100000 > dirsize-100k.log |
| 5996 | $ cat dirsize-100k.log |
| 5997 | </literallayout> |
| 5998 | You can apply a filter to the script to ignore files under |
| 5999 | a certain size. |
| 6000 | The previous example filters out any files below 100 Kbytes. |
| 6001 | The sizes reported by the tool are uncompressed, and thus |
| 6002 | will be smaller by a relatively constant factor in a |
| 6003 | compressed root filesystem. |
| 6004 | When you examine your log file, you can focus on areas of the |
| 6005 | root filesystem that take up large amounts of memory. |
| 6006 | </para> |
| 6007 | |
| 6008 | <para> |
| 6009 | You need to be sure that what you eliminate does not cripple |
| 6010 | the functionality you need. |
| 6011 | One way to see how packages relate to each other is by using |
| 6012 | the Dependency Explorer UI with the BitBake command: |
| 6013 | <literallayout class='monospaced'> |
| 6014 | $ cd <replaceable>image-directory</replaceable> |
| 6015 | $ bitbake -u depexp -g <replaceable>image</replaceable> |
| 6016 | </literallayout> |
| 6017 | Use the interface to select potential packages you wish to |
| 6018 | eliminate and see their dependency relationships. |
| 6019 | </para> |
| 6020 | |
| 6021 | <para> |
| 6022 | When deciding how to reduce the size, get rid of packages that |
| 6023 | result in minimal impact on the feature set. |
| 6024 | For example, you might not need a VGA display. |
| 6025 | Or, you might be able to get by with <filename>devtmpfs</filename> |
| 6026 | and <filename>mdev</filename> instead of |
| 6027 | <filename>udev</filename>. |
| 6028 | </para> |
| 6029 | |
| 6030 | <para> |
| 6031 | Use your <filename>local.conf</filename> file to make changes. |
| 6032 | For example, to eliminate <filename>udev</filename> and |
| 6033 | <filename>glib</filename>, set the following in the |
| 6034 | local configuration file: |
| 6035 | <literallayout class='monospaced'> |
| 6036 | VIRTUAL-RUNTIME_dev_manager = "" |
| 6037 | </literallayout> |
| 6038 | </para> |
| 6039 | |
| 6040 | <para> |
| 6041 | Finally, you should consider exactly the type of root |
| 6042 | filesystem you need to meet your needs while also reducing |
| 6043 | its size. |
| 6044 | For example, consider <filename>cramfs</filename>, |
| 6045 | <filename>squashfs</filename>, <filename>ubifs</filename>, |
| 6046 | <filename>ext2</filename>, or an <filename>initramfs</filename> |
| 6047 | using <filename>initramfs</filename>. |
| 6048 | Be aware that <filename>ext3</filename> requires a 1 Mbyte |
| 6049 | journal. |
| 6050 | If you are okay with running read-only, you do not need this |
| 6051 | journal. |
| 6052 | </para> |
| 6053 | |
| 6054 | <note> |
| 6055 | After each round of elimination, you need to rebuild your |
| 6056 | system and then use the tools to see the effects of your |
| 6057 | reductions. |
| 6058 | </note> |
| 6059 | |
| 6060 | |
| 6061 | </section> |
| 6062 | |
| 6063 | <section id='trim-the-kernel'> |
| 6064 | <title>Trim the Kernel</title> |
| 6065 | |
| 6066 | <para> |
| 6067 | The kernel is built by including policies for hardware-independent |
| 6068 | aspects. |
| 6069 | What subsystems do you enable? |
| 6070 | For what architecture are you building? |
| 6071 | Which drivers do you build by default? |
| 6072 | <note>You can modify the kernel source if you want to help |
| 6073 | with boot time. |
| 6074 | </note> |
| 6075 | </para> |
| 6076 | |
| 6077 | <para> |
| 6078 | Run the <filename>ksize.py</filename> script from the top-level |
| 6079 | Linux build directory to get an idea of what is making up |
| 6080 | the kernel: |
| 6081 | <literallayout class='monospaced'> |
| 6082 | $ cd <replaceable>top-level-linux-build-directory</replaceable> |
| 6083 | $ ksize.py > ksize.log |
| 6084 | $ cat ksize.log |
| 6085 | </literallayout> |
| 6086 | When you examine the log, you will see how much space is |
| 6087 | taken up with the built-in <filename>.o</filename> files for |
| 6088 | drivers, networking, core kernel files, filesystem, sound, |
| 6089 | and so forth. |
| 6090 | The sizes reported by the tool are uncompressed, and thus |
| 6091 | will be smaller by a relatively constant factor in a compressed |
| 6092 | kernel image. |
| 6093 | Look to reduce the areas that are large and taking up around |
| 6094 | the "90% rule." |
| 6095 | </para> |
| 6096 | |
| 6097 | <para> |
| 6098 | To examine, or drill down, into any particular area, use the |
| 6099 | <filename>-d</filename> option with the script: |
| 6100 | <literallayout class='monospaced'> |
| 6101 | $ ksize.py -d > ksize.log |
| 6102 | </literallayout> |
| 6103 | Using this option breaks out the individual file information |
| 6104 | for each area of the kernel (e.g. drivers, networking, and |
| 6105 | so forth). |
| 6106 | </para> |
| 6107 | |
| 6108 | <para> |
| 6109 | Use your log file to see what you can eliminate from the kernel |
| 6110 | based on features you can let go. |
| 6111 | For example, if you are not going to need sound, you do not |
| 6112 | need any drivers that support sound. |
| 6113 | </para> |
| 6114 | |
| 6115 | <para> |
| 6116 | After figuring out what to eliminate, you need to reconfigure |
| 6117 | the kernel to reflect those changes during the next build. |
| 6118 | You could run <filename>menuconfig</filename> and make all your |
| 6119 | changes at once. |
| 6120 | However, that makes it difficult to see the effects of your |
| 6121 | individual eliminations and also makes it difficult to replicate |
| 6122 | the changes for perhaps another target device. |
| 6123 | A better method is to start with no configurations using |
| 6124 | <filename>allnoconfig</filename>, create configuration |
| 6125 | fragments for individual changes, and then manage the |
| 6126 | fragments into a single configuration file using |
| 6127 | <filename>merge_config.sh</filename>. |
| 6128 | The tool makes it easy for you to iterate using the |
| 6129 | configuration change and build cycle. |
| 6130 | </para> |
| 6131 | |
| 6132 | <para> |
| 6133 | Each time you make configuration changes, you need to rebuild |
| 6134 | the kernel and check to see what impact your changes had on |
| 6135 | the overall size. |
| 6136 | </para> |
| 6137 | </section> |
| 6138 | |
| 6139 | <section id='remove-package-management-requirements'> |
| 6140 | <title>Remove Package Management Requirements</title> |
| 6141 | |
| 6142 | <para> |
| 6143 | Packaging requirements add size to the image. |
| 6144 | One way to reduce the size of the image is to remove all the |
| 6145 | packaging requirements from the image. |
| 6146 | This reduction includes both removing the package manager |
| 6147 | and its unique dependencies as well as removing the package |
| 6148 | management data itself. |
| 6149 | </para> |
| 6150 | |
| 6151 | <para> |
| 6152 | To eliminate all the packaging requirements for an image, |
| 6153 | be sure that "package-management" is not part of your |
| 6154 | <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink> |
| 6155 | statement for the image. |
| 6156 | When you remove this feature, you are removing the package |
| 6157 | manager as well as its dependencies from the root filesystem. |
| 6158 | </para> |
| 6159 | </section> |
| 6160 | |
| 6161 | <section id='look-for-other-ways-to-minimize-size'> |
| 6162 | <title>Look for Other Ways to Minimize Size</title> |
| 6163 | |
| 6164 | <para> |
| 6165 | Depending on your particular circumstances, other areas that you |
| 6166 | can trim likely exist. |
| 6167 | The key to finding these areas is through tools and methods |
| 6168 | described here combined with experimentation and iteration. |
| 6169 | Here are a couple of areas to experiment with: |
| 6170 | <itemizedlist> |
| 6171 | <listitem><para><filename>glibc</filename>: |
| 6172 | In general, follow this process: |
| 6173 | <orderedlist> |
| 6174 | <listitem><para>Remove <filename>glibc</filename> |
| 6175 | features from |
| 6176 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink> |
| 6177 | that you think you do not need.</para></listitem> |
| 6178 | <listitem><para>Build your distribution. |
| 6179 | </para></listitem> |
| 6180 | <listitem><para>If the build fails due to missing |
| 6181 | symbols in a package, determine if you can |
| 6182 | reconfigure the package to not need those |
| 6183 | features. |
| 6184 | For example, change the configuration to not |
| 6185 | support wide character support as is done for |
| 6186 | <filename>ncurses</filename>. |
| 6187 | Or, if support for those characters is needed, |
| 6188 | determine what <filename>glibc</filename> |
| 6189 | features provide the support and restore the |
| 6190 | configuration. |
| 6191 | </para></listitem> |
| 6192 | <listitem><para>Rebuild and repeat the process. |
| 6193 | </para></listitem> |
| 6194 | </orderedlist></para></listitem> |
| 6195 | <listitem><para><filename>busybox</filename>: |
| 6196 | For BusyBox, use a process similar as described for |
| 6197 | <filename>glibc</filename>. |
| 6198 | A difference is you will need to boot the resulting |
| 6199 | system to see if you are able to do everything you |
| 6200 | expect from the running system. |
| 6201 | You need to be sure to integrate configuration fragments |
| 6202 | into Busybox because BusyBox handles its own core |
| 6203 | features and then allows you to add configuration |
| 6204 | fragments on top. |
| 6205 | </para></listitem> |
| 6206 | </itemizedlist> |
| 6207 | </para> |
| 6208 | </section> |
| 6209 | |
| 6210 | <section id='iterate-on-the-process'> |
| 6211 | <title>Iterate on the Process</title> |
| 6212 | |
| 6213 | <para> |
| 6214 | If you have not reached your goals on system size, you need |
| 6215 | to iterate on the process. |
| 6216 | The process is the same. |
| 6217 | Use the tools and see just what is taking up 90% of the root |
| 6218 | filesystem and the kernel. |
| 6219 | Decide what you can eliminate without limiting your device |
| 6220 | beyond what you need. |
| 6221 | </para> |
| 6222 | |
| 6223 | <para> |
| 6224 | Depending on your system, a good place to look might be |
| 6225 | Busybox, which provides a stripped down |
| 6226 | version of Unix tools in a single, executable file. |
| 6227 | You might be able to drop virtual terminal services or perhaps |
| 6228 | ipv6. |
| 6229 | </para> |
| 6230 | </section> |
| 6231 | </section> |
| 6232 | |
| 6233 | <section id='building-images-for-more-than-one-machine'> |
| 6234 | <title>Building Images for More than One Machine</title> |
| 6235 | |
| 6236 | <para> |
| 6237 | A common scenario developers face is creating images for several |
| 6238 | different machines that use the same software environment. |
| 6239 | In this situation, it is tempting to set the |
| 6240 | tunings and optimization flags for each build specifically for |
| 6241 | the targeted hardware (i.e. "maxing out" the tunings). |
| 6242 | Doing so can considerably add to build times and package feed |
| 6243 | maintenance collectively for the machines. |
| 6244 | For example, selecting tunes that are extremely specific to a |
| 6245 | CPU core used in a system might enable some micro optimizations |
| 6246 | in GCC for that particular system but would otherwise not gain |
| 6247 | you much of a performance difference across the other systems |
| 6248 | as compared to using a more general tuning across all the builds |
| 6249 | (e.g. setting |
| 6250 | <ulink url='var-DEFAULTTUNE'><filename>DEFAULTTUNE</filename></ulink> |
| 6251 | specifically for each machine's build). |
| 6252 | Rather than "max out" each build's tunings, you can take steps that |
| 6253 | cause the OpenEmbedded build system to reuse software across the |
| 6254 | various machines where it makes sense. |
| 6255 | </para> |
| 6256 | <para> |
| 6257 | If build speed and package feed maintenance are considerations, |
| 6258 | you should consider the points in this section that can help you |
| 6259 | optimize your tunings to best consider build times and package |
| 6260 | feed maintenance. |
| 6261 | <itemizedlist> |
| 6262 | <listitem><para><emphasis>Share the Build Directory:</emphasis> |
| 6263 | If at all possible, share the |
| 6264 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink> |
| 6265 | across builds. |
| 6266 | The Yocto Project supports switching between different |
| 6267 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink> |
| 6268 | values in the same <filename>TMPDIR</filename>. |
| 6269 | This practice is well supported and regularly used by |
| 6270 | developers when building for multiple machines. |
| 6271 | When you use the same <filename>TMPDIR</filename> for |
| 6272 | multiple machine builds, the OpenEmbedded build system can |
| 6273 | reuse the existing native and often cross-recipes for |
| 6274 | multiple machines. |
| 6275 | Thus, build time decreases. |
| 6276 | <note> |
| 6277 | If |
| 6278 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink> |
| 6279 | settings change or fundamental configuration settings |
| 6280 | such as the filesystem layout, you need to work with |
| 6281 | a clean <filename>TMPDIR</filename>. |
| 6282 | Sharing <filename>TMPDIR</filename> under these |
| 6283 | circumstances might work but since it is not |
| 6284 | guaranteed, you should use a clean |
| 6285 | <filename>TMPDIR</filename>. |
| 6286 | </note> |
| 6287 | </para></listitem> |
| 6288 | <listitem><para><emphasis>Enable the Appropriate Package Architecture:</emphasis> |
| 6289 | By default, the OpenEmbedded build system enables three |
| 6290 | levels of package architectures: "all", "tune" or "package", |
| 6291 | and "machine". |
| 6292 | Any given recipe usually selects one of these package |
| 6293 | architectures (types) for its output. |
| 6294 | Depending for what a given recipe creates packages, making |
| 6295 | sure you enable the appropriate package architecture can |
| 6296 | directly impact the build time.</para> |
| 6297 | <para>A recipe that just generates scripts can enable |
| 6298 | "all" architecture because there are no binaries to build. |
| 6299 | To specifically enable "all" architecture, be sure your |
| 6300 | recipe inherits the |
| 6301 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-allarch'><filename>allarch</filename></ulink> |
| 6302 | class. |
| 6303 | This class is useful for "all" architectures because it |
| 6304 | configures many variables so packages can be used across |
| 6305 | multiple architectures.</para> |
| 6306 | <para>If your recipe needs to generate packages that are |
| 6307 | machine-specific or when one of the build or runtime |
| 6308 | dependencies is already machine-architecture dependent, |
| 6309 | which makes your recipe also machine-architecture dependent, |
| 6310 | make sure your recipe enables the "machine" package |
| 6311 | architecture through the |
| 6312 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ARCH'><filename>MACHINE_ARCH</filename></ulink> |
| 6313 | variable: |
| 6314 | <literallayout class='monospaced'> |
| 6315 | PACKAGE_ARCH = "${MACHINE_ARCH}" |
| 6316 | </literallayout> |
| 6317 | When you do not specifically enable a package |
| 6318 | architecture through the |
| 6319 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>, |
| 6320 | The OpenEmbedded build system defaults to the |
| 6321 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TUNE_PKGARCH'><filename>TUNE_PKGARCH</filename></ulink> |
| 6322 | setting: |
| 6323 | <literallayout class='monospaced'> |
| 6324 | PACKAGE_ARCH = "${TUNE_PKGARCH}" |
| 6325 | </literallayout> |
| 6326 | </para></listitem> |
| 6327 | <listitem><para><emphasis>Choose a Generic Tuning File if Possible:</emphasis> |
| 6328 | Some tunes are more generic and can run on multiple targets |
| 6329 | (e.g. an <filename>armv5</filename> set of packages could |
| 6330 | run on <filename>armv6</filename> and |
| 6331 | <filename>armv7</filename> processors in most cases). |
| 6332 | Similarly, <filename>i486</filename> binaries could work |
| 6333 | on <filename>i586</filename> and higher processors. |
| 6334 | You should realize, however, that advances on newer |
| 6335 | processor versions would not be used.</para> |
| 6336 | <para>If you select the same tune for several different |
| 6337 | machines, the OpenEmbedded build system reuses software |
| 6338 | previously built, thus speeding up the overall build time. |
| 6339 | Realize that even though a new sysroot for each machine is |
| 6340 | generated, the software is not recompiled and only one |
| 6341 | package feed exists. |
| 6342 | </para></listitem> |
| 6343 | <listitem><para><emphasis>Manage Granular Level Packaging:</emphasis> |
| 6344 | Sometimes cases exist where injecting another level |
| 6345 | of package architecture beyond the three higher levels |
| 6346 | noted earlier can be useful. |
| 6347 | For example, consider the <filename>emgd</filename> |
| 6348 | graphics stack in the |
| 6349 | <filename>meta-intel</filename> layer. |
| 6350 | In this layer, a subset of software exists that is |
| 6351 | compiled against something different from the rest of the |
| 6352 | generic packages. |
| 6353 | You can examine the key code in the |
| 6354 | <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi'>Source Repositories</ulink> |
| 6355 | "daisy" branch in |
| 6356 | <filename>classes/emgd-gl.bbclass</filename>. |
| 6357 | For a specific set of packages, the code redefines |
| 6358 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>. |
| 6359 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_EXTRA_ARCHS'><filename>PACKAGE_EXTRA_ARCHS</filename></ulink> |
| 6360 | is then appended with this extra tune name in |
| 6361 | <filename>meta-intel-emgd.inc</filename>. |
| 6362 | The result is that when searching for packages, the |
| 6363 | build system uses a four-level search and the packages |
| 6364 | in this new level are preferred as compared to the standard |
| 6365 | tune. |
| 6366 | The overall result is that the build system reuses most |
| 6367 | software from the common tune except for specific cases |
| 6368 | as needed. |
| 6369 | </para></listitem> |
| 6370 | <listitem><para><emphasis>Use Tools to Debug Issues:</emphasis> |
| 6371 | Sometimes you can run into situations where software is |
| 6372 | being rebuilt when you think it should not be. |
| 6373 | For example, the OpenEmbedded build system might not be |
| 6374 | using shared state between machines when you think it |
| 6375 | should be. |
| 6376 | These types of situations are usually due to references |
| 6377 | to machine-specific variables such as |
| 6378 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>, |
| 6379 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SERIAL_CONSOLE'><filename>SERIAL_CONSOLE</filename></ulink>, |
| 6380 | <ulink url='&YOCTO_DOCS_REF_URL;#var-XSERVER'><filename>XSERVER</filename></ulink>, |
| 6381 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES'><filename>MACHINE_FEATURES</filename></ulink>, |
| 6382 | and so forth in code that is supposed to only be |
| 6383 | tune-specific or when the recipe depends |
| 6384 | (<ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>, |
| 6385 | <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>, |
| 6386 | <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>, |
| 6387 | <ulink url='&YOCTO_DOCS_REF_URL;#var-RSUGGESTS'><filename>RSUGGESTS</filename></ulink>, |
| 6388 | and so forth) on some other recipe that already has |
| 6389 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink> |
| 6390 | defined as "${MACHINE_ARCH}". |
| 6391 | <note> |
| 6392 | Patches to fix any issues identified are most welcome |
| 6393 | as these issues occasionally do occur. |
| 6394 | </note></para> |
| 6395 | <para>For such cases, you can use some tools to help you |
| 6396 | sort out the situation: |
| 6397 | <itemizedlist> |
| 6398 | <listitem><para><emphasis><filename>sstate-diff-machines.sh</filename>:</emphasis> |
| 6399 | You can find this tool in the |
| 6400 | <filename>scripts</filename> directory of the |
| 6401 | Source Repositories. |
| 6402 | See the comments in the script for information on |
| 6403 | how to use the tool. |
| 6404 | </para></listitem> |
| 6405 | <listitem><para><emphasis>BitBake's "-S printdiff" Option:</emphasis> |
| 6406 | Using this option causes BitBake to try to |
| 6407 | establish the closest signature match it can |
| 6408 | (e.g. in the shared state cache) and then run |
| 6409 | <filename>bitbake-diffsigs</filename> over the |
| 6410 | matches to determine the stamps and delta where |
| 6411 | these two stamp trees diverge. |
| 6412 | </para></listitem> |
| 6413 | </itemizedlist> |
| 6414 | </para></listitem> |
| 6415 | </itemizedlist> |
| 6416 | </para> |
| 6417 | </section> |
| 6418 | |
| 6419 | <section id='working-with-packages'> |
| 6420 | <title>Working with Packages</title> |
| 6421 | |
| 6422 | <para> |
| 6423 | This section describes a few tasks that involve packages: |
| 6424 | <itemizedlist> |
| 6425 | <listitem><para> |
| 6426 | <link linkend='excluding-packages-from-an-image'>Excluding packages from an image</link> |
| 6427 | </para></listitem> |
| 6428 | <listitem><para> |
| 6429 | <link linkend='incrementing-a-package-revision-number'>Incrementing a package revision number</link> |
| 6430 | </para></listitem> |
| 6431 | <listitem><para> |
| 6432 | <link linkend='handling-optional-module-packaging'>Handling optional module packaging</link> |
| 6433 | </para></listitem> |
| 6434 | <listitem><para> |
| 6435 | <link linkend='using-runtime-package-management'>Using Runtime Package Management</link> |
| 6436 | </para></listitem> |
| 6437 | <listitem><para> |
| 6438 | <link linkend='testing-packages-with-ptest'>Setting up and running package test (ptest)</link> |
| 6439 | </para></listitem> |
| 6440 | </itemizedlist> |
| 6441 | </para> |
| 6442 | |
| 6443 | <section id='excluding-packages-from-an-image'> |
| 6444 | <title>Excluding Packages from an Image</title> |
| 6445 | |
| 6446 | <para> |
| 6447 | You might find it necessary to prevent specific packages |
| 6448 | from being installed into an image. |
| 6449 | If so, you can use several variables to direct the build |
| 6450 | system to essentially ignore installing recommended packages |
| 6451 | or to not install a package at all. |
| 6452 | </para> |
| 6453 | |
| 6454 | <para> |
| 6455 | The following list introduces variables you can use to |
| 6456 | prevent packages from being installed into your image. |
| 6457 | Each of these variables only works with IPK and RPM |
| 6458 | package types. |
| 6459 | Support for Debian packages does not exist. |
| 6460 | Also, you can use these variables from your |
| 6461 | <filename>local.conf</filename> file or attach them to a |
| 6462 | specific image recipe by using a recipe name override. |
| 6463 | For more detail on the variables, see the descriptions in the |
| 6464 | Yocto Project Reference Manual's glossary chapter. |
| 6465 | <itemizedlist> |
| 6466 | <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-BAD_RECOMMENDATIONS'><filename>BAD_RECOMMENDATIONS</filename></ulink>: |
| 6467 | Use this variable to specify "recommended-only" |
| 6468 | packages that you do not want installed. |
| 6469 | </para></listitem> |
| 6470 | <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-NO_RECOMMENDATIONS'><filename>NO_RECOMMENDATIONS</filename></ulink>: |
| 6471 | Use this variable to prevent all "recommended-only" |
| 6472 | packages from being installed. |
| 6473 | </para></listitem> |
| 6474 | <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_EXCLUDE'><filename>PACKAGE_EXCLUDE</filename></ulink>: |
| 6475 | Use this variable to prevent specific packages from |
| 6476 | being installed regardless of whether they are |
| 6477 | "recommended-only" or not. |
| 6478 | You need to realize that the build process could |
| 6479 | fail with an error when you |
| 6480 | prevent the installation of a package whose presence |
| 6481 | is required by an installed package. |
| 6482 | </para></listitem> |
| 6483 | </itemizedlist> |
| 6484 | </para> |
| 6485 | </section> |
| 6486 | |
| 6487 | <section id='incrementing-a-package-revision-number'> |
| 6488 | <title>Incrementing a Package Revision Number</title> |
| 6489 | |
| 6490 | <para> |
| 6491 | If a committed change results in changing the package output, |
| 6492 | then the value of the |
| 6493 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink> |
| 6494 | variable needs to be increased (or "bumped"). |
| 6495 | Increasing <filename>PR</filename> occurs one of two ways: |
| 6496 | <itemizedlist> |
| 6497 | <listitem><para>Automatically using a Package Revision |
| 6498 | Service (PR Service).</para></listitem> |
| 6499 | <listitem><para>Manually incrementing the |
| 6500 | <filename>PR</filename> variable.</para></listitem> |
| 6501 | </itemizedlist> |
| 6502 | </para> |
| 6503 | |
| 6504 | <para> |
| 6505 | Given that one of the challenges any build system and its |
| 6506 | users face is how to maintain a package feed that is compatible |
| 6507 | with existing package manager applications such as |
| 6508 | RPM, APT, and OPKG, using an automated system is much |
| 6509 | preferred over a manual system. |
| 6510 | In either system, the main requirement is that version |
| 6511 | numbering increases in a linear fashion and that a number of |
| 6512 | version components exist that support that linear progression. |
| 6513 | </para> |
| 6514 | |
| 6515 | <para> |
| 6516 | The following two sections provide information on the PR Service |
| 6517 | and on manual <filename>PR</filename> bumping. |
| 6518 | </para> |
| 6519 | |
| 6520 | <section id='working-with-a-pr-service'> |
| 6521 | <title>Working With a PR Service</title> |
| 6522 | |
| 6523 | <para> |
| 6524 | As mentioned, attempting to maintain revision numbers in the |
| 6525 | <ulink url='&YOCTO_DOCS_DEV_URL;#metadata'>Metadata</ulink> |
| 6526 | is error prone, inaccurate, and causes problems for people |
| 6527 | submitting recipes. |
| 6528 | Conversely, the PR Service automatically generates |
| 6529 | increasing numbers, particularly the revision field, |
| 6530 | which removes the human element. |
| 6531 | <note> |
| 6532 | For additional information on using a PR Service, you |
| 6533 | can see the |
| 6534 | <ulink url='&YOCTO_WIKI_URL;/wiki/PR_Service'>PR Service</ulink> |
| 6535 | wiki page. |
| 6536 | </note> |
| 6537 | </para> |
| 6538 | |
| 6539 | <para> |
| 6540 | The Yocto Project uses variables in order of |
| 6541 | decreasing priority to facilitate revision numbering (i.e. |
| 6542 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PE'><filename>PE</filename></ulink>, |
| 6543 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>, and |
| 6544 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink> |
| 6545 | for epoch, version, and revision, respectively). |
| 6546 | The values are highly dependent on the policies and |
| 6547 | procedures of a given distribution and package feed. |
| 6548 | </para> |
| 6549 | |
| 6550 | <para> |
| 6551 | Because the OpenEmbedded build system uses |
| 6552 | "<ulink url='&YOCTO_DOCS_REF_URL;#checksums'>signatures</ulink>", |
| 6553 | which are unique to a given build, the build system |
| 6554 | knows when to rebuild packages. |
| 6555 | All the inputs into a given task are represented by a |
| 6556 | signature, which can trigger a rebuild when different. |
| 6557 | Thus, the build system itself does not rely on the |
| 6558 | <filename>PR</filename> numbers to trigger a rebuild. |
| 6559 | The signatures, however, can be used to generate |
| 6560 | <filename>PR</filename> values. |
| 6561 | </para> |
| 6562 | |
| 6563 | <para> |
| 6564 | The PR Service works with both |
| 6565 | <filename>OEBasic</filename> and |
| 6566 | <filename>OEBasicHash</filename> generators. |
| 6567 | The value of <filename>PR</filename> bumps when the |
| 6568 | checksum changes and the different generator mechanisms |
| 6569 | change signatures under different circumstances. |
| 6570 | </para> |
| 6571 | |
| 6572 | <para> |
| 6573 | As implemented, the build system includes values from |
| 6574 | the PR Service into the <filename>PR</filename> field as |
| 6575 | an addition using the form "<filename>.x</filename>" so |
| 6576 | <filename>r0</filename> becomes <filename>r0.1</filename>, |
| 6577 | <filename>r0.2</filename> and so forth. |
| 6578 | This scheme allows existing <filename>PR</filename> values |
| 6579 | to be used for whatever reasons, which include manual |
| 6580 | <filename>PR</filename> bumps, should it be necessary. |
| 6581 | </para> |
| 6582 | |
| 6583 | <para> |
| 6584 | By default, the PR Service is not enabled or running. |
| 6585 | Thus, the packages generated are just "self consistent". |
| 6586 | The build system adds and removes packages and |
| 6587 | there are no guarantees about upgrade paths but images |
| 6588 | will be consistent and correct with the latest changes. |
| 6589 | </para> |
| 6590 | |
| 6591 | <para> |
| 6592 | The simplest form for a PR Service is for it to exist |
| 6593 | for a single host development system that builds the |
| 6594 | package feed (building system). |
| 6595 | For this scenario, you can enable a local PR Service by |
| 6596 | setting |
| 6597 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PRSERV_HOST'><filename>PRSERV_HOST</filename></ulink> |
| 6598 | in your <filename>local.conf</filename> file in the |
| 6599 | <ulink url='&YOCTO_DOCS_DEV_URL;#build-directory'>Build Directory</ulink>: |
| 6600 | <literallayout class='monospaced'> |
| 6601 | PRSERV_HOST = "localhost:0" |
| 6602 | </literallayout> |
| 6603 | Once the service is started, packages will automatically |
| 6604 | get increasing <filename>PR</filename> values and |
| 6605 | BitBake will take care of starting and stopping the server. |
| 6606 | </para> |
| 6607 | |
| 6608 | <para> |
| 6609 | If you have a more complex setup where multiple host |
| 6610 | development systems work against a common, shared package |
| 6611 | feed, you have a single PR Service running and it is |
| 6612 | connected to each building system. |
| 6613 | For this scenario, you need to start the PR Service using |
| 6614 | the <filename>bitbake-prserv</filename> command: |
| 6615 | <literallayout class='monospaced'> |
| 6616 | bitbake-prserv --host <replaceable>ip</replaceable> --port <replaceable>port</replaceable> --start |
| 6617 | </literallayout> |
| 6618 | In addition to hand-starting the service, you need to |
| 6619 | update the <filename>local.conf</filename> file of each |
| 6620 | building system as described earlier so each system |
| 6621 | points to the server and port. |
| 6622 | </para> |
| 6623 | |
| 6624 | <para> |
| 6625 | It is also recommended you use build history, which adds |
| 6626 | some sanity checks to package versions, in conjunction with |
| 6627 | the server that is running the PR Service. |
| 6628 | To enable build history, add the following to each building |
| 6629 | system's <filename>local.conf</filename> file: |
| 6630 | <literallayout class='monospaced'> |
| 6631 | # It is recommended to activate "buildhistory" for testing the PR service |
| 6632 | INHERIT += "buildhistory" |
| 6633 | BUILDHISTORY_COMMIT = "1" |
| 6634 | </literallayout> |
| 6635 | For information on build history, see the |
| 6636 | "<ulink url='&YOCTO_DOCS_REF_URL;#maintaining-build-output-quality'>Maintaining Build Output Quality</ulink>" |
| 6637 | section in the Yocto Project Reference Manual. |
| 6638 | </para> |
| 6639 | |
| 6640 | <note> |
| 6641 | <para>The OpenEmbedded build system does not maintain |
| 6642 | <filename>PR</filename> information as part of the |
| 6643 | shared state (sstate) packages. |
| 6644 | If you maintain an sstate feed, its expected that either |
| 6645 | all your building systems that contribute to the sstate |
| 6646 | feed use a shared PR Service, or you do not run a PR |
| 6647 | Service on any of your building systems. |
| 6648 | Having some systems use a PR Service while others do |
| 6649 | not leads to obvious problems.</para> |
| 6650 | <para>For more information on shared state, see the |
| 6651 | "<ulink url='&YOCTO_DOCS_REF_URL;#shared-state-cache'>Shared State Cache</ulink>" |
| 6652 | section in the Yocto Project Reference Manual.</para> |
| 6653 | </note> |
| 6654 | </section> |
| 6655 | |
| 6656 | <section id='manually-bumping-pr'> |
| 6657 | <title>Manually Bumping PR</title> |
| 6658 | |
| 6659 | <para> |
| 6660 | The alternative to setting up a PR Service is to manually |
| 6661 | bump the |
| 6662 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink> |
| 6663 | variable. |
| 6664 | </para> |
| 6665 | |
| 6666 | <para> |
| 6667 | If a committed change results in changing the package output, |
| 6668 | then the value of the PR variable needs to be increased |
| 6669 | (or "bumped") as part of that commit. |
| 6670 | For new recipes you should add the <filename>PR</filename> |
| 6671 | variable and set its initial value equal to "r0", which is the default. |
| 6672 | Even though the default value is "r0", the practice of adding it to a new recipe makes |
| 6673 | it harder to forget to bump the variable when you make changes |
| 6674 | to the recipe in future. |
| 6675 | </para> |
| 6676 | |
| 6677 | <para> |
| 6678 | If you are sharing a common <filename>.inc</filename> file with multiple recipes, |
| 6679 | you can also use the |
| 6680 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-INC_PR'>INC_PR</ulink></filename> |
| 6681 | variable to ensure that |
| 6682 | the recipes sharing the <filename>.inc</filename> file are rebuilt when the |
| 6683 | <filename>.inc</filename> file itself is changed. |
| 6684 | The <filename>.inc</filename> file must set <filename>INC_PR</filename> |
| 6685 | (initially to "r0"), and all recipes referring to it should set <filename>PR</filename> |
| 6686 | to "$(INC_PR).0" initially, incrementing the last number when the recipe is changed. |
| 6687 | If the <filename>.inc</filename> file is changed then its |
| 6688 | <filename>INC_PR</filename> should be incremented. |
| 6689 | </para> |
| 6690 | |
| 6691 | <para> |
| 6692 | When upgrading the version of a package, assuming the |
| 6693 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'>PV</ulink></filename> |
| 6694 | changes, the <filename>PR</filename> variable should be |
| 6695 | reset to "r0" (or "$(INC_PR).0" if you are using |
| 6696 | <filename>INC_PR</filename>). |
| 6697 | </para> |
| 6698 | |
| 6699 | <para> |
| 6700 | Usually, version increases occur only to packages. |
| 6701 | However, if for some reason <filename>PV</filename> changes but does not |
| 6702 | increase, you can increase the |
| 6703 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PE'>PE</ulink></filename> |
| 6704 | variable (Package Epoch). |
| 6705 | The <filename>PE</filename> variable defaults to "0". |
| 6706 | </para> |
| 6707 | |
| 6708 | <para> |
| 6709 | Version numbering strives to follow the |
| 6710 | <ulink url='http://www.debian.org/doc/debian-policy/ch-controlfields.html'> |
| 6711 | Debian Version Field Policy Guidelines</ulink>. |
| 6712 | These guidelines define how versions are compared and what "increasing" a version means. |
| 6713 | </para> |
| 6714 | </section> |
| 6715 | </section> |
| 6716 | |
| 6717 | <section id='handling-optional-module-packaging'> |
| 6718 | <title>Handling Optional Module Packaging</title> |
| 6719 | |
| 6720 | <para> |
| 6721 | Many pieces of software split functionality into optional |
| 6722 | modules (or plug-ins) and the plug-ins that are built |
| 6723 | might depend on configuration options. |
| 6724 | To avoid having to duplicate the logic that determines what |
| 6725 | modules are available in your recipe or to avoid having |
| 6726 | to package each module by hand, the OpenEmbedded build system |
| 6727 | provides functionality to handle module packaging dynamically. |
| 6728 | </para> |
| 6729 | |
| 6730 | <para> |
| 6731 | To handle optional module packaging, you need to do two things: |
| 6732 | <itemizedlist> |
| 6733 | <listitem><para>Ensure the module packaging is actually |
| 6734 | done.</para></listitem> |
| 6735 | <listitem><para>Ensure that any dependencies on optional |
| 6736 | modules from other recipes are satisfied by your recipe. |
| 6737 | </para></listitem> |
| 6738 | </itemizedlist> |
| 6739 | </para> |
| 6740 | |
| 6741 | <section id='making-sure-the-packaging-is-done'> |
| 6742 | <title>Making Sure the Packaging is Done</title> |
| 6743 | |
| 6744 | <para> |
| 6745 | To ensure the module packaging actually gets done, you use |
| 6746 | the <filename>do_split_packages</filename> function within |
| 6747 | the <filename>populate_packages</filename> Python function |
| 6748 | in your recipe. |
| 6749 | The <filename>do_split_packages</filename> function |
| 6750 | searches for a pattern of files or directories under a |
| 6751 | specified path and creates a package for each one it finds |
| 6752 | by appending to the |
| 6753 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink> |
| 6754 | variable and setting the appropriate values for |
| 6755 | <filename>FILES_packagename</filename>, |
| 6756 | <filename>RDEPENDS_packagename</filename>, |
| 6757 | <filename>DESCRIPTION_packagename</filename>, and so forth. |
| 6758 | Here is an example from the <filename>lighttpd</filename> |
| 6759 | recipe: |
| 6760 | <literallayout class='monospaced'> |
| 6761 | python populate_packages_prepend () { |
| 6762 | lighttpd_libdir = d.expand('${libdir}') |
| 6763 | do_split_packages(d, lighttpd_libdir, '^mod_(.*)\.so$', |
| 6764 | 'lighttpd-module-%s', 'Lighttpd module for %s', |
| 6765 | extra_depends='') |
| 6766 | } |
| 6767 | </literallayout> |
| 6768 | The previous example specifies a number of things in the |
| 6769 | call to <filename>do_split_packages</filename>. |
| 6770 | <itemizedlist> |
| 6771 | <listitem><para>A directory within the files installed |
| 6772 | by your recipe through <filename>do_install</filename> |
| 6773 | in which to search.</para></listitem> |
| 6774 | <listitem><para>A regular expression used to match module |
| 6775 | files in that directory. |
| 6776 | In the example, note the parentheses () that mark |
| 6777 | the part of the expression from which the module |
| 6778 | name should be derived.</para></listitem> |
| 6779 | <listitem><para>A pattern to use for the package names. |
| 6780 | </para></listitem> |
| 6781 | <listitem><para>A description for each package. |
| 6782 | </para></listitem> |
| 6783 | <listitem><para>An empty string for |
| 6784 | <filename>extra_depends</filename>, which disables |
| 6785 | the default dependency on the main |
| 6786 | <filename>lighttpd</filename> package. |
| 6787 | Thus, if a file in <filename>${libdir}</filename> |
| 6788 | called <filename>mod_alias.so</filename> is found, |
| 6789 | a package called <filename>lighttpd-module-alias</filename> |
| 6790 | is created for it and the |
| 6791 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DESCRIPTION'><filename>DESCRIPTION</filename></ulink> |
| 6792 | is set to "Lighttpd module for alias".</para></listitem> |
| 6793 | </itemizedlist> |
| 6794 | </para> |
| 6795 | |
| 6796 | <para> |
| 6797 | Often, packaging modules is as simple as the previous |
| 6798 | example. |
| 6799 | However, more advanced options exist that you can use |
| 6800 | within <filename>do_split_packages</filename> to modify its |
| 6801 | behavior. |
| 6802 | And, if you need to, you can add more logic by specifying |
| 6803 | a hook function that is called for each package. |
| 6804 | It is also perfectly acceptable to call |
| 6805 | <filename>do_split_packages</filename> multiple times if |
| 6806 | you have more than one set of modules to package. |
| 6807 | </para> |
| 6808 | |
| 6809 | <para> |
| 6810 | For more examples that show how to use |
| 6811 | <filename>do_split_packages</filename>, see the |
| 6812 | <filename>connman.inc</filename> file in the |
| 6813 | <filename>meta/recipes-connectivity/connman/</filename> |
| 6814 | directory of the <filename>poky</filename> |
| 6815 | <link linkend='yocto-project-repositories'>source repository</link>. |
| 6816 | You can also find examples in |
| 6817 | <filename>meta/classes/kernel.bbclass</filename>. |
| 6818 | </para> |
| 6819 | |
| 6820 | <para> |
| 6821 | Following is a reference that shows |
| 6822 | <filename>do_split_packages</filename> mandatory and |
| 6823 | optional arguments: |
| 6824 | <literallayout class='monospaced'> |
| 6825 | Mandatory arguments |
| 6826 | |
| 6827 | root |
| 6828 | The path in which to search |
| 6829 | file_regex |
| 6830 | Regular expression to match searched files. |
| 6831 | Use parentheses () to mark the part of this |
| 6832 | expression that should be used to derive the |
| 6833 | module name (to be substituted where %s is |
| 6834 | used in other function arguments as noted below) |
| 6835 | output_pattern |
| 6836 | Pattern to use for the package names. Must |
| 6837 | include %s. |
| 6838 | description |
| 6839 | Description to set for each package. Must |
| 6840 | include %s. |
| 6841 | |
| 6842 | Optional arguments |
| 6843 | |
| 6844 | postinst |
| 6845 | Postinstall script to use for all packages |
| 6846 | (as a string) |
| 6847 | recursive |
| 6848 | True to perform a recursive search - default |
| 6849 | False |
| 6850 | hook |
| 6851 | A hook function to be called for every match. |
| 6852 | The function will be called with the following |
| 6853 | arguments (in the order listed): |
| 6854 | |
| 6855 | f |
| 6856 | Full path to the file/directory match |
| 6857 | pkg |
| 6858 | The package name |
| 6859 | file_regex |
| 6860 | As above |
| 6861 | output_pattern |
| 6862 | As above |
| 6863 | modulename |
| 6864 | The module name derived using file_regex |
| 6865 | |
| 6866 | extra_depends |
| 6867 | Extra runtime dependencies (RDEPENDS) to be |
| 6868 | set for all packages. The default value of None |
| 6869 | causes a dependency on the main package |
| 6870 | (${PN}) - if you do not want this, pass empty |
| 6871 | string '' for this parameter. |
| 6872 | aux_files_pattern |
| 6873 | Extra item(s) to be added to FILES for each |
| 6874 | package. Can be a single string item or a list |
| 6875 | of strings for multiple items. Must include %s. |
| 6876 | postrm |
| 6877 | postrm script to use for all packages (as a |
| 6878 | string) |
| 6879 | allow_dirs |
| 6880 | True to allow directories to be matched - |
| 6881 | default False |
| 6882 | prepend |
| 6883 | If True, prepend created packages to PACKAGES |
| 6884 | instead of the default False which appends them |
| 6885 | match_path |
| 6886 | match file_regex on the whole relative path to |
| 6887 | the root rather than just the file name |
| 6888 | aux_files_pattern_verbatim |
| 6889 | Extra item(s) to be added to FILES for each |
| 6890 | package, using the actual derived module name |
| 6891 | rather than converting it to something legal |
| 6892 | for a package name. Can be a single string item |
| 6893 | or a list of strings for multiple items. Must |
| 6894 | include %s. |
| 6895 | allow_links |
| 6896 | True to allow symlinks to be matched - default |
| 6897 | False |
| 6898 | summary |
| 6899 | Summary to set for each package. Must include %s; |
| 6900 | defaults to description if not set. |
| 6901 | </literallayout> |
| 6902 | </para> |
| 6903 | </section> |
| 6904 | |
| 6905 | <section id='satisfying-dependencies'> |
| 6906 | <title>Satisfying Dependencies</title> |
| 6907 | |
| 6908 | <para> |
| 6909 | The second part for handling optional module packaging |
| 6910 | is to ensure that any dependencies on optional modules |
| 6911 | from other recipes are satisfied by your recipe. |
| 6912 | You can be sure these dependencies are satisfied by |
| 6913 | using the |
| 6914 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES_DYNAMIC'><filename>PACKAGES_DYNAMIC</filename></ulink> variable. |
| 6915 | Here is an example that continues with the |
| 6916 | <filename>lighttpd</filename> recipe shown earlier: |
| 6917 | <literallayout class='monospaced'> |
| 6918 | PACKAGES_DYNAMIC = "lighttpd-module-.*" |
| 6919 | </literallayout> |
| 6920 | The name specified in the regular expression can of |
| 6921 | course be anything. |
| 6922 | In this example, it is <filename>lighttpd-module-</filename> |
| 6923 | and is specified as the prefix to ensure that any |
| 6924 | <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink> |
| 6925 | and <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink> |
| 6926 | on a package name starting with the prefix are satisfied |
| 6927 | during build time. |
| 6928 | If you are using <filename>do_split_packages</filename> |
| 6929 | as described in the previous section, the value you put in |
| 6930 | <filename>PACKAGES_DYNAMIC</filename> should correspond to |
| 6931 | the name pattern specified in the call to |
| 6932 | <filename>do_split_packages</filename>. |
| 6933 | </para> |
| 6934 | </section> |
| 6935 | </section> |
| 6936 | |
| 6937 | <section id='using-runtime-package-management'> |
| 6938 | <title>Using Runtime Package Management</title> |
| 6939 | |
| 6940 | <para> |
| 6941 | During a build, BitBake always transforms a recipe into one or |
| 6942 | more packages. |
| 6943 | For example, BitBake takes the <filename>bash</filename> recipe |
| 6944 | and currently produces the <filename>bash-dbg</filename>, |
| 6945 | <filename>bash-staticdev</filename>, |
| 6946 | <filename>bash-dev</filename>, <filename>bash-doc</filename>, |
| 6947 | <filename>bash-locale</filename>, and |
| 6948 | <filename>bash</filename> packages. |
| 6949 | Not all generated packages are included in an image. |
| 6950 | </para> |
| 6951 | |
| 6952 | <para> |
| 6953 | In several situations, you might need to update, add, remove, |
| 6954 | or query the packages on a target device at runtime |
| 6955 | (i.e. without having to generate a new image). |
| 6956 | Examples of such situations include: |
| 6957 | <itemizedlist> |
| 6958 | <listitem><para> |
| 6959 | You want to provide in-the-field updates to deployed |
| 6960 | devices (e.g. security updates). |
| 6961 | </para></listitem> |
| 6962 | <listitem><para> |
| 6963 | You want to have a fast turn-around development cycle |
| 6964 | for one or more applications that run on your device. |
| 6965 | </para></listitem> |
| 6966 | <listitem><para> |
| 6967 | You want to temporarily install the "debug" packages |
| 6968 | of various applications on your device so that |
| 6969 | debugging can be greatly improved by allowing |
| 6970 | access to symbols and source debugging. |
| 6971 | </para></listitem> |
| 6972 | <listitem><para> |
| 6973 | You want to deploy a more minimal package selection of |
| 6974 | your device but allow in-the-field updates to add a |
| 6975 | larger selection for customization. |
| 6976 | </para></listitem> |
| 6977 | </itemizedlist> |
| 6978 | </para> |
| 6979 | |
| 6980 | <para> |
| 6981 | In all these situations, you have something similar to a more |
| 6982 | traditional Linux distribution in that in-field devices |
| 6983 | are able to receive pre-compiled packages from a server for |
| 6984 | installation or update. |
| 6985 | Being able to install these packages on a running, |
| 6986 | in-field device is what is termed "runtime package |
| 6987 | management". |
| 6988 | </para> |
| 6989 | |
| 6990 | <para> |
| 6991 | In order to use runtime package management, you |
| 6992 | need a host/server machine that serves up the pre-compiled |
| 6993 | packages plus the required metadata. |
| 6994 | You also need package manipulation tools on the target. |
| 6995 | The build machine is a likely candidate to act as the server. |
| 6996 | However, that machine does not necessarily have to be the |
| 6997 | package server. |
| 6998 | The build machine could push its artifacts to another machine |
| 6999 | that acts as the server (e.g. Internet-facing). |
| 7000 | </para> |
| 7001 | |
| 7002 | <para> |
| 7003 | A simple build that targets just one device produces |
| 7004 | more than one package database. |
| 7005 | In other words, the packages produced by a build are separated |
| 7006 | out into a couple of different package groupings based on |
| 7007 | criteria such as the target's CPU architecture, the target |
| 7008 | board, or the C library used on the target. |
| 7009 | For example, a build targeting the <filename>qemuarm</filename> |
| 7010 | device produces the following three package databases: |
| 7011 | <filename>all</filename>, <filename>armv5te</filename>, and |
| 7012 | <filename>qemuarm</filename>. |
| 7013 | If you wanted your <filename>qemuarm</filename> device to be |
| 7014 | aware of all the packages that were available to it, |
| 7015 | you would need to point it to each of these databases |
| 7016 | individually. |
| 7017 | In a similar way, a traditional Linux distribution usually is |
| 7018 | configured to be aware of a number of software repositories |
| 7019 | from which it retrieves packages. |
| 7020 | </para> |
| 7021 | |
| 7022 | <para> |
| 7023 | Using runtime package management is completely optional and |
| 7024 | not required for a successful build or deployment in any |
| 7025 | way. |
| 7026 | But if you want to make use of runtime package management, |
| 7027 | you need to do a couple things above and beyond the basics. |
| 7028 | The remainder of this section describes what you need to do. |
| 7029 | </para> |
| 7030 | |
| 7031 | <section id='runtime-package-management-build'> |
| 7032 | <title>Build Considerations</title> |
| 7033 | |
| 7034 | <para> |
| 7035 | This section describes build considerations that you need |
| 7036 | to be aware of in order to provide support for runtime |
| 7037 | package management. |
| 7038 | </para> |
| 7039 | |
| 7040 | <para> |
| 7041 | When BitBake generates packages it needs to know |
| 7042 | what format or formats to use. |
| 7043 | In your configuration, you use the |
| 7044 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink> |
| 7045 | variable to specify the format. |
| 7046 | <note> |
| 7047 | You can choose to have more than one format but you must |
| 7048 | provide at least one. |
| 7049 | </note> |
| 7050 | </para> |
| 7051 | |
| 7052 | <para> |
| 7053 | If you would like your image to start off with a basic |
| 7054 | package database of the packages in your current build |
| 7055 | as well as have the relevant tools available on the |
| 7056 | target for runtime package management, you can include |
| 7057 | "package-management" in the |
| 7058 | <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink> |
| 7059 | variable. |
| 7060 | Including "package-management" in this |
| 7061 | configuration variable ensures that when the image |
| 7062 | is assembled for your target, the image includes |
| 7063 | the currently-known package databases as well as |
| 7064 | the target-specific tools required for runtime |
| 7065 | package management to be performed on the target. |
| 7066 | However, this is not strictly necessary. |
| 7067 | You could start your image off without any databases |
| 7068 | but only include the required on-target package |
| 7069 | tool(s). |
| 7070 | As an example, you could include "opkg" in your |
| 7071 | <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink> |
| 7072 | variable if you are using the IPK package format. |
| 7073 | You can then initialize your target's package database(s) |
| 7074 | later once your image is up and running. |
| 7075 | </para> |
| 7076 | |
| 7077 | <para> |
| 7078 | Whenever you perform any sort of build step that can |
| 7079 | potentially generate a package or modify an existing |
| 7080 | package, it is always a good idea to re-generate the |
| 7081 | package index with: |
| 7082 | <literallayout class='monospaced'> |
| 7083 | $ bitbake package-index |
| 7084 | </literallayout> |
| 7085 | Realize that it is not sufficient to simply do the |
| 7086 | following: |
| 7087 | <literallayout class='monospaced'> |
| 7088 | $ bitbake <replaceable>some-package</replaceable> package-index |
| 7089 | </literallayout> |
| 7090 | This is because BitBake does not properly schedule the |
| 7091 | <filename>package-index</filename> target fully after any |
| 7092 | other target has completed. |
| 7093 | Thus, be sure to run the package update step separately. |
| 7094 | </para> |
| 7095 | |
| 7096 | <para> |
| 7097 | As described below in the |
| 7098 | "<link linkend='runtime-package-management-target-ipk'>Using IPK</link>" |
| 7099 | section, if you are using IPK as your package format, you |
| 7100 | can make use of the |
| 7101 | <filename>distro-feed-configs</filename> recipe provided |
| 7102 | by <filename>meta-oe</filename> in order to configure your |
| 7103 | target to use your IPK databases. |
| 7104 | </para> |
| 7105 | |
| 7106 | <para> |
| 7107 | When your build is complete, your packages reside in the |
| 7108 | <filename>${TMPDIR}/deploy/<replaceable>package-format</replaceable></filename> |
| 7109 | directory. |
| 7110 | For example, if <filename>${TMPDIR}</filename> |
| 7111 | is <filename>tmp</filename> and your selected package type |
| 7112 | is IPK, then your IPK packages are available in |
| 7113 | <filename>tmp/deploy/ipk</filename>. |
| 7114 | </para> |
| 7115 | </section> |
| 7116 | |
| 7117 | <section id='runtime-package-management-server'> |
| 7118 | <title>Host or Server Machine Setup</title> |
| 7119 | |
| 7120 | <para> |
| 7121 | Typically, packages are served from a server using |
| 7122 | HTTP. |
| 7123 | However, other protocols are possible. |
| 7124 | If you want to use HTTP, then setup and configure a |
| 7125 | web server, such as Apache 2 or lighttpd, on the machine |
| 7126 | serving the packages. |
| 7127 | </para> |
| 7128 | |
| 7129 | <para> |
| 7130 | As previously mentioned, the build machine can act as the |
| 7131 | package server. |
| 7132 | In the following sections that describe server machine |
| 7133 | setups, the build machine is assumed to also be the server. |
| 7134 | </para> |
| 7135 | |
| 7136 | <section id='package-server-apache'> |
| 7137 | <title>Serving Packages via Apache 2</title> |
| 7138 | |
| 7139 | <para> |
| 7140 | This example assumes you are using the Apache 2 |
| 7141 | server: |
| 7142 | <orderedlist> |
| 7143 | <listitem><para> |
| 7144 | Add the directory to your Apache |
| 7145 | configuration, which you can find at |
| 7146 | <filename>/etc/httpd/conf/httpd.conf</filename>. |
| 7147 | Use commands similar to these on the |
| 7148 | development system. |
| 7149 | These example commands assume a top-level |
| 7150 | <link linkend='source-directory'>Source Directory</link> |
| 7151 | named <filename>poky</filename> in your home |
| 7152 | directory. |
| 7153 | The example also assumes an RPM package type. |
| 7154 | If you are using a different package type, such |
| 7155 | as IPK, use "ipk" in the pathnames: |
| 7156 | <literallayout class='monospaced'> |
| 7157 | <VirtualHost *:80> |
| 7158 | .... |
| 7159 | Alias /rpm ~/poky/build/tmp/deploy/rpm |
| 7160 | <Directory "~/poky/build/tmp/deploy/rpm"> |
| 7161 | Options +Indexes |
| 7162 | </Directory> |
| 7163 | </VirtualHost> |
| 7164 | </literallayout></para></listitem> |
| 7165 | <listitem><para> |
| 7166 | Reload the Apache configuration as described |
| 7167 | in this step. |
| 7168 | For all commands, be sure you have root |
| 7169 | privileges. |
| 7170 | </para> |
| 7171 | |
| 7172 | <para> |
| 7173 | If your development system is using Fedora or |
| 7174 | CentOS, use the following: |
| 7175 | <literallayout class='monospaced'> |
| 7176 | # service httpd reload |
| 7177 | </literallayout> |
| 7178 | For Ubuntu and Debian, use the following: |
| 7179 | <literallayout class='monospaced'> |
| 7180 | # /etc/init.d/apache2 reload |
| 7181 | </literallayout> |
| 7182 | For OpenSUSE, use the following: |
| 7183 | <literallayout class='monospaced'> |
| 7184 | # /etc/init.d/apache2 reload |
| 7185 | </literallayout></para></listitem> |
| 7186 | <listitem><para> |
| 7187 | If you are using Security-Enhanced Linux |
| 7188 | (SELinux), you need to label the files as |
| 7189 | being accessible through Apache. |
| 7190 | Use the following command from the development |
| 7191 | host. |
| 7192 | This example assumes RPM package types: |
| 7193 | <literallayout class='monospaced'> |
| 7194 | # chcon -R -h -t httpd_sys_content_t tmp/deploy/rpm |
| 7195 | </literallayout></para></listitem> |
| 7196 | </orderedlist> |
| 7197 | </para> |
| 7198 | </section> |
| 7199 | |
| 7200 | <section id='package-server-lighttpd'> |
| 7201 | <title>Serving Packages via lighttpd</title> |
| 7202 | |
| 7203 | <para> |
| 7204 | If you are using lighttpd, all you need |
| 7205 | to do is to provide a link from your |
| 7206 | <filename>${TMPDIR}/deploy/<replaceable>package-format</replaceable></filename> |
| 7207 | directory to lighttpd's document-root. |
| 7208 | You can determine the specifics of your lighttpd |
| 7209 | installation by looking through its configuration file, |
| 7210 | which is usually found at: |
| 7211 | <filename>/etc/lighttpd/lighttpd.conf</filename>. |
| 7212 | </para> |
| 7213 | |
| 7214 | <para> |
| 7215 | For example, if you are using IPK, lighttpd's |
| 7216 | document-root is set to |
| 7217 | <filename>/var/www/lighttpd</filename>, and you had |
| 7218 | packages for a target named "BOARD", |
| 7219 | then you might create a link from your build location |
| 7220 | to lighttpd's document-root as follows: |
| 7221 | <literallayout class='monospaced'> |
| 7222 | # ln -s $(PWD)/tmp/deploy/ipk /var/www/lighttpd/BOARD-dir |
| 7223 | </literallayout> |
| 7224 | </para> |
| 7225 | |
| 7226 | <para> |
| 7227 | At this point, you need to start the lighttpd server. |
| 7228 | The method used to start the server varies by |
| 7229 | distribution. |
| 7230 | However, one basic method that starts it by hand is: |
| 7231 | <literallayout class='monospaced'> |
| 7232 | # lighttpd -f /etc/lighttpd/lighttpd.conf |
| 7233 | </literallayout> |
| 7234 | </para> |
| 7235 | </section> |
| 7236 | </section> |
| 7237 | |
| 7238 | <section id='runtime-package-management-target'> |
| 7239 | <title>Target Setup</title> |
| 7240 | |
| 7241 | <para> |
| 7242 | Setting up the target differs depending on the |
| 7243 | package management system. |
| 7244 | This section provides information for RPM and IPK. |
| 7245 | </para> |
| 7246 | |
| 7247 | <section id='runtime-package-management-target-rpm'> |
| 7248 | <title>Using RPM</title> |
| 7249 | |
| 7250 | <para> |
| 7251 | The application for performing runtime package |
| 7252 | management of RPM packages on the target is called |
| 7253 | <filename>smart</filename>. |
| 7254 | </para> |
| 7255 | |
| 7256 | <para> |
| 7257 | On the target machine, you need to inform |
| 7258 | <filename>smart</filename> of every package database |
| 7259 | you want to use. |
| 7260 | As an example, suppose your target device can use the |
| 7261 | following three package databases from a server named |
| 7262 | <filename>server.name</filename>: |
| 7263 | <filename>all</filename>, <filename>i586</filename>, |
| 7264 | and <filename>qemux86</filename>. |
| 7265 | Given this example, issue the following commands on the |
| 7266 | target: |
| 7267 | <literallayout class='monospaced'> |
| 7268 | # smart channel --add all type=rpm-md baseurl=http://server.name/rpm/all |
| 7269 | # smart channel --add i585 type=rpm-md baseurl=http://server.name/rpm/i586 |
| 7270 | # smart channel --add qemux86 type=rpm-md baseurl=http://server.name/rpm/qemux86 |
| 7271 | </literallayout> |
| 7272 | Also from the target machine, fetch the repository |
| 7273 | information using this command: |
| 7274 | <literallayout class='monospaced'> |
| 7275 | # smart update |
| 7276 | </literallayout> |
| 7277 | You can now use the <filename>smart query</filename> |
| 7278 | and <filename>smart install</filename> commands to |
| 7279 | find and install packages from the repositories. |
| 7280 | </para> |
| 7281 | </section> |
| 7282 | |
| 7283 | <section id='runtime-package-management-target-ipk'> |
| 7284 | <title>Using IPK</title> |
| 7285 | |
| 7286 | <para> |
| 7287 | The application for performing runtime package |
| 7288 | management of IPK packages on the target is called |
| 7289 | <filename>opkg</filename>. |
| 7290 | </para> |
| 7291 | |
| 7292 | <para> |
| 7293 | In order to inform <filename>opkg</filename> of the |
| 7294 | package databases you want to use, simply create one |
| 7295 | or more <filename>*.conf</filename> files in the |
| 7296 | <filename>/etc/opkg</filename> directory on the target. |
| 7297 | The <filename>opkg</filename> application uses them |
| 7298 | to find its available package databases. |
| 7299 | As an example, suppose you configured your HTTP server |
| 7300 | on your machine named |
| 7301 | <filename>www.mysite.com</filename> to serve files |
| 7302 | from a <filename>BOARD-dir</filename> directory under |
| 7303 | its document-root. |
| 7304 | In this case, you might create a configuration |
| 7305 | file on the target called |
| 7306 | <filename>/etc/opkg/base-feeds.conf</filename> that |
| 7307 | contains: |
| 7308 | <literallayout class='monospaced'> |
| 7309 | src/gz all http://www.mysite.com/BOARD-dir/all |
| 7310 | src/gz armv7a http://www.mysite.com/BOARD-dir/armv7a |
| 7311 | src/gz beaglebone http://www.mysite.com/BOARD-dir/beaglebone |
| 7312 | </literallayout> |
| 7313 | </para> |
| 7314 | |
| 7315 | <para> |
| 7316 | As a way of making it easier to generate and make |
| 7317 | these IPK configuration files available on your |
| 7318 | target, simply define |
| 7319 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FEED_DEPLOYDIR_BASE_URI'><filename>FEED_DEPLOYDIR_BASE_URI</filename></ulink> |
| 7320 | to point to your server and the location within the |
| 7321 | document-root which contains the databases. |
| 7322 | For example: if you are serving your packages over |
| 7323 | HTTP, your server's IP address is 192.168.7.1, and |
| 7324 | your databases are located in a directory called |
| 7325 | <filename>BOARD-dir</filename> underneath your HTTP |
| 7326 | server's document-root, you need to set |
| 7327 | <filename>FEED_DEPLOYDIR_BASE_URI</filename> to |
| 7328 | <filename>http://192.168.7.1/BOARD-dir</filename> and |
| 7329 | a set of configuration files will be generated for you |
| 7330 | in your target to work with this feed. |
| 7331 | </para> |
| 7332 | |
| 7333 | <para> |
| 7334 | On the target machine, fetch (or refresh) the |
| 7335 | repository information using this command: |
| 7336 | <literallayout class='monospaced'> |
| 7337 | # opkg update |
| 7338 | </literallayout> |
| 7339 | You can now use the <filename>opkg list</filename> and |
| 7340 | <filename>opkg install</filename> commands to find and |
| 7341 | install packages from the repositories. |
| 7342 | </para> |
| 7343 | </section> |
| 7344 | </section> |
| 7345 | </section> |
| 7346 | |
| 7347 | <section id='testing-packages-with-ptest'> |
| 7348 | <title>Testing Packages With ptest</title> |
| 7349 | |
| 7350 | <para> |
| 7351 | A Package Test (ptest) runs tests against packages built |
| 7352 | by the OpenEmbedded build system on the target machine. |
| 7353 | A ptest contains at least two items: the actual test, and |
| 7354 | a shell script (<filename>run-ptest</filename>) that starts |
| 7355 | the test. |
| 7356 | The shell script that starts the test must not contain |
| 7357 | the actual test - the script only starts the test. |
| 7358 | On the other hand, the test can be anything from a simple |
| 7359 | shell script that runs a binary and checks the output to |
| 7360 | an elaborate system of test binaries and data files. |
| 7361 | </para> |
| 7362 | |
| 7363 | <para> |
| 7364 | The test generates output in the format used by |
| 7365 | Automake: |
| 7366 | <literallayout class='monospaced'> |
| 7367 | <replaceable>result</replaceable>: <replaceable>testname</replaceable> |
| 7368 | </literallayout> |
| 7369 | where the result can be <filename>PASS</filename>, |
| 7370 | <filename>FAIL</filename>, or <filename>SKIP</filename>, |
| 7371 | and the testname can be any identifying string. |
| 7372 | </para> |
| 7373 | |
| 7374 | <para> |
| 7375 | For a list of Yocto Project recipes that are already |
| 7376 | enabled with ptest, see the |
| 7377 | <ulink url='https://wiki.yoctoproject.org/wiki/Ptest'>Ptest</ulink> |
| 7378 | wiki page. |
| 7379 | <note> |
| 7380 | A recipe is "ptest-enabled" if it inherits the |
| 7381 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-ptest'><filename>ptest</filename></ulink> |
| 7382 | class. |
| 7383 | </note> |
| 7384 | </para> |
| 7385 | |
| 7386 | <section id='adding-ptest-to-your-build'> |
| 7387 | <title>Adding ptest to Your Build</title> |
| 7388 | |
| 7389 | <para> |
| 7390 | To add package testing to your build, add the |
| 7391 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink> |
| 7392 | and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink> |
| 7393 | variables to your <filename>local.conf</filename> file, |
| 7394 | which is found in the |
| 7395 | <link linkend='build-directory'>Build Directory</link>: |
| 7396 | <literallayout class='monospaced'> |
| 7397 | DISTRO_FEATURES_append = " ptest" |
| 7398 | EXTRA_IMAGE_FEATURES += "ptest-pkgs" |
| 7399 | </literallayout> |
| 7400 | Once your build is complete, the ptest files are installed |
| 7401 | into the |
| 7402 | <filename>/usr/lib/<replaceable>package</replaceable>/ptest</filename> |
| 7403 | directory within the image, where |
| 7404 | <filename><replaceable>package</replaceable></filename> |
| 7405 | is the name of the package. |
| 7406 | </para> |
| 7407 | </section> |
| 7408 | |
| 7409 | <section id='running-ptest'> |
| 7410 | <title>Running ptest</title> |
| 7411 | |
| 7412 | <para> |
| 7413 | The <filename>ptest-runner</filename> package installs a |
| 7414 | shell script that loops through all installed ptest test |
| 7415 | suites and runs them in sequence. |
| 7416 | Consequently, you might want to add this package to |
| 7417 | your image. |
| 7418 | </para> |
| 7419 | </section> |
| 7420 | |
| 7421 | <section id='getting-your-package-ready'> |
| 7422 | <title>Getting Your Package Ready</title> |
| 7423 | |
| 7424 | <para> |
| 7425 | In order to enable a recipe to run installed ptests |
| 7426 | on target hardware, |
| 7427 | you need to prepare the recipes that build the packages |
| 7428 | you want to test. |
| 7429 | Here is what you have to do for each recipe: |
| 7430 | <itemizedlist> |
| 7431 | <listitem><para><emphasis>Be sure the recipe |
| 7432 | inherits the |
| 7433 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-ptest'><filename>ptest</filename></ulink> |
| 7434 | class:</emphasis> |
| 7435 | Include the following line in each recipe: |
| 7436 | <literallayout class='monospaced'> |
| 7437 | inherit ptest |
| 7438 | </literallayout> |
| 7439 | </para></listitem> |
| 7440 | <listitem><para><emphasis>Create <filename>run-ptest</filename>:</emphasis> |
| 7441 | This script starts your test. |
| 7442 | Locate the script where you will refer to it |
| 7443 | using |
| 7444 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>. |
| 7445 | Here is an example that starts a test for |
| 7446 | <filename>dbus</filename>: |
| 7447 | <literallayout class='monospaced'> |
| 7448 | #!/bin/sh |
| 7449 | cd test |
| 7450 | make -k runtest-TESTS |
| 7451 | </literallayout> |
| 7452 | </para></listitem> |
| 7453 | <listitem><para><emphasis>Ensure dependencies are |
| 7454 | met:</emphasis> |
| 7455 | If the test adds build or runtime dependencies |
| 7456 | that normally do not exist for the package |
| 7457 | (such as requiring "make" to run the test suite), |
| 7458 | use the |
| 7459 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink> |
| 7460 | and |
| 7461 | <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink> |
| 7462 | variables in your recipe in order for the package |
| 7463 | to meet the dependencies. |
| 7464 | Here is an example where the package has a runtime |
| 7465 | dependency on "make": |
| 7466 | <literallayout class='monospaced'> |
| 7467 | RDEPENDS_${PN}-ptest += "make" |
| 7468 | </literallayout> |
| 7469 | </para></listitem> |
| 7470 | <listitem><para><emphasis>Add a function to build the |
| 7471 | test suite:</emphasis> |
| 7472 | Not many packages support cross-compilation of |
| 7473 | their test suites. |
| 7474 | Consequently, you usually need to add a |
| 7475 | cross-compilation function to the package. |
| 7476 | </para> |
| 7477 | <para>Many packages based on Automake compile and |
| 7478 | run the test suite by using a single command |
| 7479 | such as <filename>make check</filename>. |
| 7480 | However, the native <filename>make check</filename> |
| 7481 | builds and runs on the same computer, while |
| 7482 | cross-compiling requires that the package is built |
| 7483 | on the host but executed on the target. |
| 7484 | The built version of Automake that ships with the |
| 7485 | Yocto Project includes a patch that separates |
| 7486 | building and execution. |
| 7487 | Consequently, packages that use the unaltered, |
| 7488 | patched version of <filename>make check</filename> |
| 7489 | automatically cross-compiles.</para> |
| 7490 | <para>Regardless, you still must add a |
| 7491 | <filename>do_compile_ptest</filename> function to |
| 7492 | build the test suite. |
| 7493 | Add a function similar to the following to your |
| 7494 | recipe: |
| 7495 | <literallayout class='monospaced'> |
| 7496 | do_compile_ptest() { |
| 7497 | oe_runmake buildtest-TESTS |
| 7498 | } |
| 7499 | </literallayout> |
| 7500 | </para></listitem> |
| 7501 | <listitem><para><emphasis>Ensure special configurations |
| 7502 | are set:</emphasis> |
| 7503 | If the package requires special configurations |
| 7504 | prior to compiling the test code, you must |
| 7505 | insert a <filename>do_configure_ptest</filename> |
| 7506 | function into the recipe. |
| 7507 | </para></listitem> |
| 7508 | <listitem><para><emphasis>Install the test |
| 7509 | suite:</emphasis> |
| 7510 | The <filename>ptest</filename> class |
| 7511 | automatically copies the file |
| 7512 | <filename>run-ptest</filename> to the target and |
| 7513 | then runs make <filename>install-ptest</filename> |
| 7514 | to run the tests. |
| 7515 | If this is not enough, you need to create a |
| 7516 | <filename>do_install_ptest</filename> function and |
| 7517 | make sure it gets called after the |
| 7518 | "make install-ptest" completes. |
| 7519 | </para></listitem> |
| 7520 | </itemizedlist> |
| 7521 | </para> |
| 7522 | </section> |
| 7523 | </section> |
| 7524 | </section> |
| 7525 | |
| 7526 | <section id='working-with-source-files'> |
| 7527 | <title>Working with Source Files</title> |
| 7528 | |
| 7529 | <para> |
| 7530 | The OpenEmbedded build system works with source files located |
| 7531 | through the |
| 7532 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> |
| 7533 | variable. |
| 7534 | When you build something using BitBake, a big part of the operation |
| 7535 | is locating and downloading all the source tarballs. |
| 7536 | For images, downloading all the source for various packages can |
| 7537 | take a significant amount of time. |
| 7538 | </para> |
| 7539 | |
| 7540 | <para> |
| 7541 | This section presents information for working with source |
| 7542 | files that can lead to more efficient use of resources and |
| 7543 | time. |
| 7544 | </para> |
| 7545 | |
| 7546 | <section id='setting-up-effective-mirrors'> |
| 7547 | <title>Setting up Effective Mirrors</title> |
| 7548 | |
| 7549 | <para> |
| 7550 | As mentioned, a good deal that goes into a Yocto Project |
| 7551 | build is simply downloading all of the source tarballs. |
| 7552 | Maybe you have been working with another build system |
| 7553 | (OpenEmbedded or Angstrom) for which you have built up a |
| 7554 | sizable directory of source tarballs. |
| 7555 | Or, perhaps someone else has such a directory for which you |
| 7556 | have read access. |
| 7557 | If so, you can save time by adding statements to your |
| 7558 | configuration file so that the build process checks local |
| 7559 | directories first for existing tarballs before checking the |
| 7560 | Internet. |
| 7561 | </para> |
| 7562 | |
| 7563 | <para> |
| 7564 | Here is an efficient way to set it up in your |
| 7565 | <filename>local.conf</filename> file: |
| 7566 | <literallayout class='monospaced'> |
| 7567 | SOURCE_MIRROR_URL ?= "file:///home/you/your-download-dir/" |
| 7568 | INHERIT += "own-mirrors" |
| 7569 | BB_GENERATE_MIRROR_TARBALLS = "1" |
| 7570 | # BB_NO_NETWORK = "1" |
| 7571 | </literallayout> |
| 7572 | </para> |
| 7573 | |
| 7574 | <para> |
| 7575 | In the previous example, the |
| 7576 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_GENERATE_MIRROR_TARBALLS'><filename>BB_GENERATE_MIRROR_TARBALLS</filename></ulink> |
| 7577 | variable causes the OpenEmbedded build system to generate |
| 7578 | tarballs of the Git repositories and store them in the |
| 7579 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink> |
| 7580 | directory. |
| 7581 | Due to performance reasons, generating and storing these |
| 7582 | tarballs is not the build system's default behavior. |
| 7583 | </para> |
| 7584 | |
| 7585 | <para> |
| 7586 | You can also use the |
| 7587 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PREMIRRORS'><filename>PREMIRRORS</filename></ulink> |
| 7588 | variable. |
| 7589 | For an example, see the variable's glossary entry in the |
| 7590 | Yocto Project Reference Manual. |
| 7591 | </para> |
| 7592 | </section> |
| 7593 | |
| 7594 | <section id='getting-source-files-and-suppressing-the-build'> |
| 7595 | <title>Getting Source Files and Suppressing the Build</title> |
| 7596 | |
| 7597 | <para> |
| 7598 | Another technique you can use to ready yourself for a |
| 7599 | successive string of build operations, is to pre-fetch |
| 7600 | all the source files without actually starting a build. |
| 7601 | This technique lets you work through any download issues |
| 7602 | and ultimately gathers all the source files into your |
| 7603 | download directory |
| 7604 | <ulink url='&YOCTO_DOCS_REF_URL;#structure-build-downloads'><filename>build/downloads</filename></ulink>, |
| 7605 | which is located with |
| 7606 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>. |
| 7607 | </para> |
| 7608 | |
| 7609 | <para> |
| 7610 | Use the following BitBake command form to fetch all the |
| 7611 | necessary sources without starting the build: |
| 7612 | <literallayout class='monospaced'> |
| 7613 | $ bitbake -c fetchall <replaceable>target</replaceable> |
| 7614 | </literallayout> |
| 7615 | This variation of the BitBake command guarantees that you |
| 7616 | have all the sources for that BitBake target should you |
| 7617 | disconnect from the Internet and want to do the build |
| 7618 | later offline. |
| 7619 | </para> |
| 7620 | </section> |
| 7621 | </section> |
| 7622 | |
| 7623 | <section id="building-software-from-an-external-source"> |
| 7624 | <title>Building Software from an External Source</title> |
| 7625 | |
| 7626 | <para> |
| 7627 | By default, the OpenEmbedded build system uses the |
| 7628 | <link linkend='build-directory'>Build Directory</link> when |
| 7629 | building source code. |
| 7630 | The build process involves fetching the source files, unpacking |
| 7631 | them, and then patching them if necessary before the build takes |
| 7632 | place. |
| 7633 | </para> |
| 7634 | |
| 7635 | <para> |
| 7636 | Situations exist where you might want to build software from source |
| 7637 | files that are external to and thus outside of the |
| 7638 | OpenEmbedded build system. |
| 7639 | For example, suppose you have a project that includes a new BSP with |
| 7640 | a heavily customized kernel. |
| 7641 | And, you want to minimize exposing the build system to the |
| 7642 | development team so that they can focus on their project and |
| 7643 | maintain everyone's workflow as much as possible. |
| 7644 | In this case, you want a kernel source directory on the development |
| 7645 | machine where the development occurs. |
| 7646 | You want the recipe's |
| 7647 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> |
| 7648 | variable to point to the external directory and use it as is, not |
| 7649 | copy it. |
| 7650 | </para> |
| 7651 | |
| 7652 | <para> |
| 7653 | To build from software that comes from an external source, all you |
| 7654 | need to do is inherit the |
| 7655 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-externalsrc'><filename>externalsrc</filename></ulink> |
| 7656 | class and then set the |
| 7657 | <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC'><filename>EXTERNALSRC</filename></ulink> |
| 7658 | variable to point to your external source code. |
| 7659 | Here are the statements to put in your |
| 7660 | <filename>local.conf</filename> file: |
| 7661 | <literallayout class='monospaced'> |
| 7662 | INHERIT += "externalsrc" |
| 7663 | EXTERNALSRC_pn-<replaceable>myrecipe</replaceable> = "<replaceable>path-to-your-source-tree</replaceable>" |
| 7664 | </literallayout> |
| 7665 | </para> |
| 7666 | |
| 7667 | <para> |
| 7668 | This next example shows how to accomplish the same thing by setting |
| 7669 | <filename>EXTERNALSRC</filename> in the recipe itself or in the |
| 7670 | recipe's append file: |
| 7671 | <literallayout class='monospaced'> |
| 7672 | EXTERNALSRC = "<replaceable>path</replaceable>" |
| 7673 | EXTERNALSRC_BUILD = "<replaceable>path</replaceable>" |
| 7674 | </literallayout> |
| 7675 | <note> |
| 7676 | In order for these settings to take effect, you must globally |
| 7677 | or locally inherit the |
| 7678 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-externalsrc'><filename>externalsrc</filename></ulink> |
| 7679 | class. |
| 7680 | </note> |
| 7681 | </para> |
| 7682 | |
| 7683 | <para> |
| 7684 | By default, <filename>externalsrc.bbclass</filename> builds |
| 7685 | the source code in a directory separate from the external source |
| 7686 | directory as specified by |
| 7687 | <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC'><filename>EXTERNALSRC</filename></ulink>. |
| 7688 | If you need to have the source built in the same directory in |
| 7689 | which it resides, or some other nominated directory, you can set |
| 7690 | <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC_BUILD'><filename>EXTERNALSRC_BUILD</filename></ulink> |
| 7691 | to point to that directory: |
| 7692 | <literallayout class='monospaced'> |
| 7693 | EXTERNALSRC_BUILD_pn-<replaceable>myrecipe</replaceable> = "<replaceable>path-to-your-source-tree</replaceable>" |
| 7694 | </literallayout> |
| 7695 | </para> |
| 7696 | </section> |
| 7697 | |
| 7698 | <section id="selecting-an-initialization-manager"> |
| 7699 | <title>Selecting an Initialization Manager</title> |
| 7700 | |
| 7701 | <para> |
| 7702 | By default, the Yocto Project uses SysVinit as the initialization |
| 7703 | manager. |
| 7704 | However, support also exists for systemd, |
| 7705 | which is a full replacement for init with |
| 7706 | parallel starting of services, reduced shell overhead and other |
| 7707 | features that are used by many distributions. |
| 7708 | </para> |
| 7709 | |
| 7710 | <para> |
| 7711 | If you want to use SysVinit, you do |
| 7712 | not have to do anything. |
| 7713 | But, if you want to use systemd, you must |
| 7714 | take some steps as described in the following sections. |
| 7715 | </para> |
| 7716 | |
| 7717 | <section id='using-systemd-exclusively'> |
| 7718 | <title>Using systemd Exclusively</title> |
| 7719 | |
| 7720 | <para> |
| 7721 | Set the these variables in your distribution configuration |
| 7722 | file as follows: |
| 7723 | <literallayout class='monospaced'> |
| 7724 | DISTRO_FEATURES_append = " systemd" |
| 7725 | VIRTUAL-RUNTIME_init_manager = "systemd" |
| 7726 | </literallayout> |
| 7727 | You can also prevent the SysVinit |
| 7728 | distribution feature from |
| 7729 | being automatically enabled as follows: |
| 7730 | <literallayout class='monospaced'> |
| 7731 | DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit" |
| 7732 | </literallayout> |
| 7733 | Doing so removes any redundant SysVinit scripts. |
| 7734 | </para> |
| 7735 | |
| 7736 | <para> |
| 7737 | To remove initscripts from your image altogether, |
| 7738 | set this variable also: |
| 7739 | <literallayout class='monospaced'> |
| 7740 | VIRTUAL-RUNTIME_initscripts = "" |
| 7741 | </literallayout> |
| 7742 | </para> |
| 7743 | |
| 7744 | <para> |
| 7745 | For information on the backfill variable, see |
| 7746 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES_BACKFILL_CONSIDERED'><filename>DISTRO_FEATURES_BACKFILL_CONSIDERED</filename></ulink>. |
| 7747 | </para> |
| 7748 | </section> |
| 7749 | |
| 7750 | <section id='using-systemd-for-the-main-image-and-using-sysvinit-for-the-rescue-image'> |
| 7751 | <title>Using systemd for the Main Image and Using SysVinit for the Rescue Image</title> |
| 7752 | |
| 7753 | <para> |
| 7754 | Set these variables in your distribution configuration |
| 7755 | file as follows: |
| 7756 | <literallayout class='monospaced'> |
| 7757 | DISTRO_FEATURES_append = " systemd" |
| 7758 | VIRTUAL-RUNTIME_init_manager = "systemd" |
| 7759 | </literallayout> |
| 7760 | Doing so causes your main image to use the |
| 7761 | <filename>packagegroup-core-boot.bb</filename> recipe and |
| 7762 | systemd. |
| 7763 | The rescue/minimal image cannot use this package group. |
| 7764 | However, it can install SysVinit |
| 7765 | and the appropriate packages will have support for both |
| 7766 | systemd and SysVinit. |
| 7767 | </para> |
| 7768 | </section> |
| 7769 | </section> |
| 7770 | |
| 7771 | <section id="selecting-dev-manager"> |
| 7772 | <title>Selecting a Device Manager</title> |
| 7773 | |
| 7774 | <para> |
| 7775 | The Yocto Project provides multiple ways to manage the device |
| 7776 | manager (<filename>/dev</filename>): |
| 7777 | <itemizedlist> |
| 7778 | <listitem><para><emphasis>Persistent and Pre-Populated<filename>/dev</filename>:</emphasis> |
| 7779 | For this case, the <filename>/dev</filename> directory |
| 7780 | is persistent and the required device nodes are created |
| 7781 | during the build. |
| 7782 | </para></listitem> |
| 7783 | <listitem><para><emphasis>Use <filename>devtmpfs</filename> with a Device Manager:</emphasis> |
| 7784 | For this case, the <filename>/dev</filename> directory |
| 7785 | is provided by the kernel as an in-memory file system and |
| 7786 | is automatically populated by the kernel at runtime. |
| 7787 | Additional configuration of device nodes is done in user |
| 7788 | space by a device manager like |
| 7789 | <filename>udev</filename> or |
| 7790 | <filename>busybox-mdev</filename>. |
| 7791 | </para></listitem> |
| 7792 | </itemizedlist> |
| 7793 | </para> |
| 7794 | |
| 7795 | <section id="static-dev-management"> |
| 7796 | <title>Using Persistent and Pre-Populated<filename>/dev</filename></title> |
| 7797 | |
| 7798 | <para> |
| 7799 | To use the static method for device population, you need to |
| 7800 | set the |
| 7801 | <ulink url='&YOCTO_DOCS_REF_URL;#var-USE_DEVFS'><filename>USE_DEVFS</filename></ulink> |
| 7802 | variable to "0" as follows: |
| 7803 | <literallayout class='monospaced'> |
| 7804 | USE_DEVFS = "0" |
| 7805 | </literallayout> |
| 7806 | </para> |
| 7807 | |
| 7808 | <para> |
| 7809 | The content of the resulting <filename>/dev</filename> |
| 7810 | directory is defined in a Device Table file. |
| 7811 | The |
| 7812 | <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_DEVICE_TABLES'><filename>IMAGE_DEVICE_TABLES</filename></ulink> |
| 7813 | variable defines the Device Table to use and should be set |
| 7814 | in the machine or distro configuration file. |
| 7815 | Alternatively, you can set this variable in your |
| 7816 | <filename>local.conf</filename> configuration file. |
| 7817 | </para> |
| 7818 | |
| 7819 | <para> |
| 7820 | If you do not define the |
| 7821 | <filename>IMAGE_DEVICE_TABLES</filename> variable, the default |
| 7822 | <filename>device_table-minimal.txt</filename> is used: |
| 7823 | <literallayout class='monospaced'> |
| 7824 | IMAGE_DEVICE_TABLES = "device_table-mymachine.txt" |
| 7825 | </literallayout> |
| 7826 | </para> |
| 7827 | |
| 7828 | <para> |
| 7829 | The population is handled by the <filename>makedevs</filename> |
| 7830 | utility during image creation: |
| 7831 | </para> |
| 7832 | </section> |
| 7833 | |
| 7834 | <section id="devtmpfs-dev-management"> |
| 7835 | <title>Using <filename>devtmpfs</filename> and a Device Manager</title> |
| 7836 | |
| 7837 | <para> |
| 7838 | To use the dynamic method for device population, you need to |
| 7839 | use (or be sure to set) the |
| 7840 | <ulink url='&YOCTO_DOCS_REF_URL;#var-USE_DEVFS'><filename>USE_DEVFS</filename></ulink> |
| 7841 | variable to "1", which is the default: |
| 7842 | <literallayout class='monospaced'> |
| 7843 | USE_DEVFS = "1" |
| 7844 | </literallayout> |
| 7845 | With this setting, the resulting <filename>/dev</filename> |
| 7846 | directory is populated by the kernel using |
| 7847 | <filename>devtmpfs</filename>. |
| 7848 | Make sure the corresponding kernel configuration variable |
| 7849 | <filename>CONFIG_DEVTMPFS</filename> is set when building |
| 7850 | you build a Linux kernel. |
| 7851 | </para> |
| 7852 | |
| 7853 | <para> |
| 7854 | All devices created by <filename>devtmpfs</filename> will be |
| 7855 | owned by <filename>root</filename> and have permissions |
| 7856 | <filename>0600</filename>. |
| 7857 | </para> |
| 7858 | |
| 7859 | <para> |
| 7860 | To have more control over the device nodes, you can use a |
| 7861 | device manager like <filename>udev</filename> or |
| 7862 | <filename>busybox-mdev</filename>. |
| 7863 | You choose the device manager by defining the |
| 7864 | <filename>VIRTUAL-RUNTIME_dev_manager</filename> variable |
| 7865 | in your machine or distro configuration file. |
| 7866 | Alternatively, you can set this variable in your |
| 7867 | <filename>local.conf</filename> configuration file: |
| 7868 | <literallayout class='monospaced'> |
| 7869 | VIRTUAL-RUNTIME_dev_manager = "udev" |
| 7870 | |
| 7871 | # Some alternative values |
| 7872 | # VIRTUAL-RUNTIME_dev_manager = "busybox-mdev" |
| 7873 | # VIRTUAL-RUNTIME_dev_manager = "systemd" |
| 7874 | </literallayout> |
| 7875 | </para> |
| 7876 | </section> |
| 7877 | </section> |
| 7878 | |
| 7879 | <section id="platdev-appdev-srcrev"> |
| 7880 | <title>Using an External SCM</title> |
| 7881 | |
| 7882 | <para> |
| 7883 | If you're working on a recipe that pulls from an external Source |
| 7884 | Code Manager (SCM), it is possible to have the OpenEmbedded build |
| 7885 | system notice new recipe changes added to the SCM and then build |
| 7886 | the resulting packages that depend on the new recipes by using |
| 7887 | the latest versions. |
| 7888 | This only works for SCMs from which it is possible to get a |
| 7889 | sensible revision number for changes. |
| 7890 | Currently, you can do this with Apache Subversion (SVN), Git, and |
| 7891 | Bazaar (BZR) repositories. |
| 7892 | </para> |
| 7893 | |
| 7894 | <para> |
| 7895 | To enable this behavior, the |
| 7896 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink> |
| 7897 | of the recipe needs to reference |
| 7898 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>. |
| 7899 | Here is an example: |
| 7900 | <literallayout class='monospaced'> |
| 7901 | PV = "1.2.3+git${SRCPV}" |
| 7902 | </literallayout> |
| 7903 | Then, you can add the following to your |
| 7904 | <filename>local.conf</filename>: |
| 7905 | <literallayout class='monospaced'> |
| 7906 | SRCREV_pn-<replaceable>PN</replaceable> = "${AUTOREV}" |
| 7907 | </literallayout> |
| 7908 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink> |
| 7909 | is the name of the recipe for which you want to enable automatic source |
| 7910 | revision updating. |
| 7911 | </para> |
| 7912 | |
| 7913 | <para> |
| 7914 | If you do not want to update your local configuration file, you can |
| 7915 | add the following directly to the recipe to finish enabling |
| 7916 | the feature: |
| 7917 | <literallayout class='monospaced'> |
| 7918 | SRCREV = "${AUTOREV}" |
| 7919 | </literallayout> |
| 7920 | </para> |
| 7921 | |
| 7922 | <para> |
| 7923 | The Yocto Project provides a distribution named |
| 7924 | <filename>poky-bleeding</filename>, whose configuration |
| 7925 | file contains the line: |
| 7926 | <literallayout class='monospaced'> |
| 7927 | require conf/distro/include/poky-floating-revisions.inc |
| 7928 | </literallayout> |
| 7929 | This line pulls in the listed include file that contains |
| 7930 | numerous lines of exactly that form: |
| 7931 | <literallayout class='monospaced'> |
| 7932 | SRCREV_pn-gconf-dbus ?= "${AUTOREV}" |
| 7933 | SRCREV_pn-matchbox-common ?= "${AUTOREV}" |
| 7934 | SRCREV_pn-matchbox-config-gtk ?= "${AUTOREV}" |
| 7935 | SRCREV_pn-matchbox-desktop ?= "${AUTOREV}" |
| 7936 | SRCREV_pn-matchbox-keyboard ?= "${AUTOREV}" |
| 7937 | SRCREV_pn-matchbox-panel ?= "${AUTOREV}" |
| 7938 | SRCREV_pn-matchbox-panel-2 ?= "${AUTOREV}" |
| 7939 | SRCREV_pn-matchbox-themes-extra ?= "${AUTOREV}" |
| 7940 | SRCREV_pn-matchbox-terminal ?= "${AUTOREV}" |
| 7941 | SRCREV_pn-matchbox-wm ?= "${AUTOREV}" |
| 7942 | SRCREV_pn-matchbox-wm-2 ?= "${AUTOREV}" |
| 7943 | SRCREV_pn-settings-daemon ?= "${AUTOREV}" |
| 7944 | SRCREV_pn-screenshot ?= "${AUTOREV}" |
| 7945 | SRCREV_pn-libfakekey ?= "${AUTOREV}" |
| 7946 | SRCREV_pn-oprofileui ?= "${AUTOREV}" |
| 7947 | . |
| 7948 | . |
| 7949 | . |
| 7950 | </literallayout> |
| 7951 | These lines allow you to experiment with building a |
| 7952 | distribution that tracks the latest development source |
| 7953 | for numerous packages. |
| 7954 | <note><title>Caution</title> |
| 7955 | The <filename>poky-bleeding</filename> distribution |
| 7956 | is not tested on a regular basis. |
| 7957 | Keep this in mind if you use it. |
| 7958 | </note> |
| 7959 | </para> |
| 7960 | </section> |
| 7961 | |
| 7962 | <section id='creating-a-read-only-root-filesystem'> |
| 7963 | <title>Creating a Read-Only Root Filesystem</title> |
| 7964 | |
| 7965 | <para> |
| 7966 | Suppose, for security reasons, you need to disable |
| 7967 | your target device's root filesystem's write permissions |
| 7968 | (i.e. you need a read-only root filesystem). |
| 7969 | Or, perhaps you are running the device's operating system |
| 7970 | from a read-only storage device. |
| 7971 | For either case, you can customize your image for |
| 7972 | that behavior. |
| 7973 | </para> |
| 7974 | |
| 7975 | <note> |
| 7976 | Supporting a read-only root filesystem requires that the system and |
| 7977 | applications do not try to write to the root filesystem. |
| 7978 | You must configure all parts of the target system to write |
| 7979 | elsewhere, or to gracefully fail in the event of attempting to |
| 7980 | write to the root filesystem. |
| 7981 | </note> |
| 7982 | |
| 7983 | <section id='creating-the-root-filesystem'> |
| 7984 | <title>Creating the Root Filesystem</title> |
| 7985 | |
| 7986 | <para> |
| 7987 | To create the read-only root filesystem, simply add the |
| 7988 | "read-only-rootfs" feature to your image. |
| 7989 | Using either of the following statements in your |
| 7990 | image recipe or from within the |
| 7991 | <filename>local.conf</filename> file found in the |
| 7992 | <link linkend='build-directory'>Build Directory</link> |
| 7993 | causes the build system to create a read-only root filesystem: |
| 7994 | <literallayout class='monospaced'> |
| 7995 | IMAGE_FEATURES = "read-only-rootfs" |
| 7996 | </literallayout> |
| 7997 | or |
| 7998 | <literallayout class='monospaced'> |
| 7999 | EXTRA_IMAGE_FEATURES += "read-only-rootfs" |
| 8000 | </literallayout> |
| 8001 | </para> |
| 8002 | |
| 8003 | <para> |
| 8004 | For more information on how to use these variables, see the |
| 8005 | "<link linkend='usingpoky-extend-customimage-imagefeatures'>Customizing Images Using Custom <filename>IMAGE_FEATURES</filename> and <filename>EXTRA_IMAGE_FEATURES</filename></link>" |
| 8006 | section. |
| 8007 | For information on the variables, see |
| 8008 | <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink> |
| 8009 | and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink>. |
| 8010 | </para> |
| 8011 | </section> |
| 8012 | |
| 8013 | <section id='post-installation-scripts'> |
| 8014 | <title>Post-Installation Scripts</title> |
| 8015 | |
| 8016 | <para> |
| 8017 | It is very important that you make sure all |
| 8018 | post-Installation (<filename>pkg_postinst</filename>) scripts |
| 8019 | for packages that are installed into the image can be run |
| 8020 | at the time when the root filesystem is created during the |
| 8021 | build on the host system. |
| 8022 | These scripts cannot attempt to run during first-boot on the |
| 8023 | target device. |
| 8024 | With the "read-only-rootfs" feature enabled, |
| 8025 | the build system checks during root filesystem creation to make |
| 8026 | sure all post-installation scripts succeed. |
| 8027 | If any of these scripts still need to be run after the root |
| 8028 | filesystem is created, the build immediately fails. |
| 8029 | These build-time checks ensure that the build fails |
| 8030 | rather than the target device fails later during its |
| 8031 | initial boot operation. |
| 8032 | </para> |
| 8033 | |
| 8034 | <para> |
| 8035 | Most of the common post-installation scripts generated by the |
| 8036 | build system for the out-of-the-box Yocto Project are engineered |
| 8037 | so that they can run during root filesystem creation |
| 8038 | (e.g. post-installation scripts for caching fonts). |
| 8039 | However, if you create and add custom scripts, you need |
| 8040 | to be sure they can be run during this file system creation. |
| 8041 | </para> |
| 8042 | |
| 8043 | <para> |
| 8044 | Here are some common problems that prevent |
| 8045 | post-installation scripts from running during root filesystem |
| 8046 | creation: |
| 8047 | <itemizedlist> |
| 8048 | <listitem><para> |
| 8049 | <emphasis>Not using $D in front of absolute |
| 8050 | paths:</emphasis> |
| 8051 | The build system defines |
| 8052 | <filename>$</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink> |
| 8053 | when the root filesystem is created. |
| 8054 | Furthermore, <filename>$D</filename> is blank when the |
| 8055 | script is run on the target device. |
| 8056 | This implies two purposes for <filename>$D</filename>: |
| 8057 | ensuring paths are valid in both the host and target |
| 8058 | environments, and checking to determine which |
| 8059 | environment is being used as a method for taking |
| 8060 | appropriate actions. |
| 8061 | </para></listitem> |
| 8062 | <listitem><para> |
| 8063 | <emphasis>Attempting to run processes that are |
| 8064 | specific to or dependent on the target |
| 8065 | architecture:</emphasis> |
| 8066 | You can work around these attempts by using native |
| 8067 | tools to accomplish the same tasks, or |
| 8068 | by alternatively running the processes under QEMU, |
| 8069 | which has the <filename>qemu_run_binary</filename> |
| 8070 | function. |
| 8071 | For more information, see the |
| 8072 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-qemu'><filename>qemu</filename></ulink> |
| 8073 | class.</para></listitem> |
| 8074 | </itemizedlist> |
| 8075 | </para> |
| 8076 | </section> |
| 8077 | |
| 8078 | <section id='areas-with-write-access'> |
| 8079 | <title>Areas With Write Access</title> |
| 8080 | |
| 8081 | <para> |
| 8082 | With the "read-only-rootfs" feature enabled, |
| 8083 | any attempt by the target to write to the root filesystem at |
| 8084 | runtime fails. |
| 8085 | Consequently, you must make sure that you configure processes |
| 8086 | and applications that attempt these types of writes do so |
| 8087 | to directories with write access (e.g. |
| 8088 | <filename>/tmp</filename> or <filename>/var/run</filename>). |
| 8089 | </para> |
| 8090 | </section> |
| 8091 | </section> |
| 8092 | |
| 8093 | <section id="performing-automated-runtime-testing"> |
| 8094 | <title>Performing Automated Runtime Testing</title> |
| 8095 | |
| 8096 | <para> |
| 8097 | The OpenEmbedded build system makes available a series of automated |
| 8098 | tests for images to verify runtime functionality. |
| 8099 | You can run these tests on either QEMU or actual target hardware. |
| 8100 | Tests are written in Python making use of the |
| 8101 | <filename>unittest</filename> module, and the majority of them |
| 8102 | run commands on the target system over SSH. |
| 8103 | This section describes how you set up the environment to use these |
| 8104 | tests, run available tests, and write and add your own tests. |
| 8105 | </para> |
| 8106 | |
| 8107 | <section id='enabling-tests'> |
| 8108 | <title>Enabling Tests</title> |
| 8109 | |
| 8110 | <para> |
| 8111 | Depending on whether you are planning to run tests using |
| 8112 | QEMU or on the hardware, you have to take |
| 8113 | different steps to enable the tests. |
| 8114 | See the following subsections for information on how to |
| 8115 | enable both types of tests. |
| 8116 | </para> |
| 8117 | |
| 8118 | <section id='qemu-image-enabling-tests'> |
| 8119 | <title>Enabling Runtime Tests on QEMU</title> |
| 8120 | |
| 8121 | <para> |
| 8122 | In order to run tests, you need to do the following: |
| 8123 | <itemizedlist> |
| 8124 | <listitem><para><emphasis>Set up to avoid interaction |
| 8125 | with <filename>sudo</filename> for networking:</emphasis> |
| 8126 | To accomplish this, you must do one of the |
| 8127 | following: |
| 8128 | <itemizedlist> |
| 8129 | <listitem><para>Add |
| 8130 | <filename>NOPASSWD</filename> for your user |
| 8131 | in <filename>/etc/sudoers</filename> either for |
| 8132 | all commands or just for |
| 8133 | <filename>runqemu-ifup</filename>. |
| 8134 | You must provide the full path as that can |
| 8135 | change if you are using multiple clones of the |
| 8136 | source repository. |
| 8137 | <note> |
| 8138 | On some distributions, you also need to |
| 8139 | comment out "Defaults requiretty" in |
| 8140 | <filename>/etc/sudoers</filename>. |
| 8141 | </note></para></listitem> |
| 8142 | <listitem><para>Manually configure a tap interface |
| 8143 | for your system.</para></listitem> |
| 8144 | <listitem><para>Run as root the script in |
| 8145 | <filename>scripts/runqemu-gen-tapdevs</filename>, |
| 8146 | which should generate a list of tap devices. |
| 8147 | This is the option typically chosen for |
| 8148 | Autobuilder-type environments. |
| 8149 | </para></listitem> |
| 8150 | </itemizedlist></para></listitem> |
| 8151 | <listitem><para><emphasis>Set the |
| 8152 | <filename>DISPLAY</filename> variable:</emphasis> |
| 8153 | You need to set this variable so that you have an X |
| 8154 | server available (e.g. start |
| 8155 | <filename>vncserver</filename> for a headless machine). |
| 8156 | </para></listitem> |
| 8157 | <listitem><para><emphasis>Be sure your host's firewall |
| 8158 | accepts incoming connections from |
| 8159 | 192.168.7.0/24:</emphasis> |
| 8160 | Some of the tests (in particular smart tests) start an |
| 8161 | HTTP server on a random high number port, which is |
| 8162 | used to serve files to the target. |
| 8163 | The smart module serves |
| 8164 | <filename>${DEPLOY_DIR}/rpm</filename> so it can run |
| 8165 | smart channel commands. That means your host's firewall |
| 8166 | must accept incoming connections from 192.168.7.0/24, |
| 8167 | which is the default IP range used for tap devices |
| 8168 | by <filename>runqemu</filename>.</para></listitem> |
| 8169 | </itemizedlist> |
| 8170 | </para> |
| 8171 | |
| 8172 | <para> |
| 8173 | Once you start running the tests, the following happens: |
| 8174 | <orderedlist> |
| 8175 | <listitem><para>A copy of the root filesystem is written |
| 8176 | to <filename>${WORKDIR}/testimage</filename>. |
| 8177 | </para></listitem> |
| 8178 | <listitem><para>The image is booted under QEMU using the |
| 8179 | standard <filename>runqemu</filename> script. |
| 8180 | </para></listitem> |
| 8181 | <listitem><para>A default timeout of 500 seconds occurs |
| 8182 | to allow for the boot process to reach the login prompt. |
| 8183 | You can change the timeout period by setting |
| 8184 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_QEMUBOOT_TIMEOUT'><filename>TEST_QEMUBOOT_TIMEOUT</filename></ulink> |
| 8185 | in the <filename>local.conf</filename> file. |
| 8186 | </para></listitem> |
| 8187 | <listitem><para>Once the boot process is reached and the |
| 8188 | login prompt appears, the tests run. |
| 8189 | The full boot log is written to |
| 8190 | <filename>${WORKDIR}/testimage/qemu_boot_log</filename>. |
| 8191 | </para></listitem> |
| 8192 | <listitem><para>Each test module loads in the order found |
| 8193 | in <filename>TEST_SUITES</filename>. |
| 8194 | You can find the full output of the commands run over |
| 8195 | SSH in |
| 8196 | <filename>${WORKDIR}/testimgage/ssh_target_log</filename>. |
| 8197 | </para></listitem> |
| 8198 | <listitem><para>If no failures occur, the task running the |
| 8199 | tests ends successfully. |
| 8200 | You can find the output from the |
| 8201 | <filename>unittest</filename> in the task log at |
| 8202 | <filename>${WORKDIR}/temp/log.do_testimage</filename>. |
| 8203 | </para></listitem> |
| 8204 | </orderedlist> |
| 8205 | </para> |
| 8206 | </section> |
| 8207 | |
| 8208 | <section id='hardware-image-enabling-tests'> |
| 8209 | <title>Enabling Runtime Tests on Hardware</title> |
| 8210 | |
| 8211 | <para> |
| 8212 | The OpenEmbedded build system can run tests on real |
| 8213 | hardware, and for certain devices it can also deploy |
| 8214 | the image to be tested onto the device beforehand. |
| 8215 | </para> |
| 8216 | |
| 8217 | <para> |
| 8218 | For automated deployment, a "master image" is installed |
| 8219 | onto the hardware once as part of setup. |
| 8220 | Then, each time tests are to be run, the following |
| 8221 | occurs: |
| 8222 | <orderedlist> |
| 8223 | <listitem><para>The master image is booted into and |
| 8224 | used to write the image to be tested to |
| 8225 | a second partition. |
| 8226 | </para></listitem> |
| 8227 | <listitem><para>The device is then rebooted using an |
| 8228 | external script that you need to provide. |
| 8229 | </para></listitem> |
| 8230 | <listitem><para>The device boots into the image to be |
| 8231 | tested. |
| 8232 | </para></listitem> |
| 8233 | </orderedlist> |
| 8234 | </para> |
| 8235 | |
| 8236 | <para> |
| 8237 | When running tests (independent of whether the image |
| 8238 | has been deployed automatically or not), the device is |
| 8239 | expected to be connected to a network on a |
| 8240 | pre-determined IP address. |
| 8241 | You can either use static IP addresses written into |
| 8242 | the image, or set the image to use DHCP and have your |
| 8243 | DHCP server on the test network assign a known IP address |
| 8244 | based on the MAC address of the device. |
| 8245 | </para> |
| 8246 | |
| 8247 | <para> |
| 8248 | In order to run tests on hardware, you need to set |
| 8249 | <filename>TEST_TARGET</filename> to an appropriate value. |
| 8250 | For QEMU, you do not have to change anything, the default |
| 8251 | value is "QemuTarget". |
| 8252 | For running tests on hardware, the following options exist: |
| 8253 | <itemizedlist> |
| 8254 | <listitem><para><emphasis>"SimpleRemoteTarget":</emphasis> |
| 8255 | Choose "SimpleRemoteTarget" if you are going to |
| 8256 | run tests on a target system that is already |
| 8257 | running the image to be tested and is available |
| 8258 | on the network. |
| 8259 | You can use "SimpleRemoteTarget" in conjunction |
| 8260 | with either real hardware or an image running |
| 8261 | within a separately started QEMU or any |
| 8262 | other virtual machine manager. |
| 8263 | </para></listitem> |
| 8264 | <listitem><para><emphasis>"GummibootTarget":</emphasis> |
| 8265 | Choose "GummibootTarget" if your hardware is |
| 8266 | an EFI-based machine with |
| 8267 | <filename>gummiboot</filename> as bootloader and |
| 8268 | <filename>core-image-testmaster</filename> |
| 8269 | (or something similar) is installed. |
| 8270 | Also, your hardware under test must be in a |
| 8271 | DHCP-enabled network that gives it the same IP |
| 8272 | address for each reboot.</para> |
| 8273 | <para>If you choose "GummibootTarget", there are |
| 8274 | additional requirements and considerations. |
| 8275 | See the |
| 8276 | "<link linkend='selecting-gummiboottarget'>Selecting GummibootTarget</link>" |
| 8277 | section, which follows, for more information. |
| 8278 | </para></listitem> |
| 8279 | <listitem><para><emphasis>"BeagleBoneTarget":</emphasis> |
| 8280 | Choose "BeagleBoneTarget" if you are deploying |
| 8281 | images and running tests on the BeagleBone |
| 8282 | "Black" or original "White" hardware. |
| 8283 | For information on how to use these tests, see the |
| 8284 | comments at the top of the BeagleBoneTarget |
| 8285 | <filename>meta-yocto-bsp/lib/oeqa/controllers/beaglebonetarget.py</filename> |
| 8286 | file. |
| 8287 | </para></listitem> |
| 8288 | <listitem><para><emphasis>"EdgeRouterTarget":</emphasis> |
| 8289 | Choose "EdgeRouterTarget" is you are deploying |
| 8290 | images and running tests on the Ubiquiti Networks |
| 8291 | EdgeRouter Lite. |
| 8292 | For information on how to use these tests, see the |
| 8293 | comments at the top of the EdgeRouterTarget |
| 8294 | <filename>meta-yocto-bsp/lib/oeqa/controllers/edgeroutertarget.py</filename> |
| 8295 | file. |
| 8296 | </para></listitem> |
| 8297 | <listitem><para><emphasis>"GrubTarget":</emphasis> |
| 8298 | Choose the "supports deploying images and running |
| 8299 | tests on any generic PC that boots using GRUB. |
| 8300 | For information on how to use these tests, see the |
| 8301 | comments at the top of the GrubTarget |
| 8302 | <filename>meta-yocto-bsp/lib/oeqa/controllers/grubtarget.py</filename> |
| 8303 | file. |
| 8304 | </para></listitem> |
| 8305 | <listitem><para><emphasis>"<replaceable>your-target</replaceable>":</emphasis> |
| 8306 | Create your own custom target if you want to run |
| 8307 | tests when you are deploying images and running |
| 8308 | tests on a custom machine within your BSP layer. |
| 8309 | To do this, you need to add a Python unit that |
| 8310 | defines the target class under |
| 8311 | <filename>lib/oeqa/controllers/</filename> within |
| 8312 | your layer. |
| 8313 | You must also provide an empty |
| 8314 | <filename>__init__.py</filename>. |
| 8315 | For examples, see files in |
| 8316 | <filename>meta-yocto-bsp/lib/oeqa/controllers/</filename>. |
| 8317 | </para></listitem> |
| 8318 | </itemizedlist> |
| 8319 | </para> |
| 8320 | </section> |
| 8321 | |
| 8322 | <section id='selecting-gummiboottarget'> |
| 8323 | <title>Selecting GummibootTarget</title> |
| 8324 | |
| 8325 | <para> |
| 8326 | If you did not set <filename>TEST_TARGET</filename> to |
| 8327 | "GummibootTarget", then you do not need any information |
| 8328 | in this section. |
| 8329 | You can skip down to the |
| 8330 | "<link linkend='qemu-image-running-tests'>Running Tests</link>" |
| 8331 | section. |
| 8332 | </para> |
| 8333 | |
| 8334 | <para> |
| 8335 | If you did set <filename>TEST_TARGET</filename> to |
| 8336 | "GummibootTarget", you also need to perform a one-time |
| 8337 | setup of your master image by doing the following: |
| 8338 | <orderedlist> |
| 8339 | <listitem><para><emphasis>Set <filename>EFI_PROVIDER</filename>:</emphasis> |
| 8340 | Be sure that <filename>EFI_PROVIDER</filename> |
| 8341 | is as follows: |
| 8342 | <literallayout class='monospaced'> |
| 8343 | EFI_PROVIDER = "gummiboot" |
| 8344 | </literallayout> |
| 8345 | </para></listitem> |
| 8346 | <listitem><para><emphasis>Build the master image:</emphasis> |
| 8347 | Build the <filename>core-image-testmaster</filename> |
| 8348 | image. |
| 8349 | The <filename>core-image-testmaster</filename> |
| 8350 | recipe is provided as an example for a |
| 8351 | "master" image and you can customize the image |
| 8352 | recipe as you would any other recipe. |
| 8353 | </para> |
| 8354 | <para>Here are the image recipe requirements: |
| 8355 | <itemizedlist> |
| 8356 | <listitem><para>Inherits |
| 8357 | <filename>core-image</filename> |
| 8358 | so that kernel modules are installed. |
| 8359 | </para></listitem> |
| 8360 | <listitem><para>Installs normal linux utilities |
| 8361 | not busybox ones (e.g. |
| 8362 | <filename>bash</filename>, |
| 8363 | <filename>coreutils</filename>, |
| 8364 | <filename>tar</filename>, |
| 8365 | <filename>gzip</filename>, and |
| 8366 | <filename>kmod</filename>). |
| 8367 | </para></listitem> |
| 8368 | <listitem><para>Uses a custom |
| 8369 | Initial RAM Disk (initramfs) image with a |
| 8370 | custom installer. |
| 8371 | A normal image that you can install usually |
| 8372 | creates a single rootfs partition. |
| 8373 | This image uses another installer that |
| 8374 | creates a specific partition layout. |
| 8375 | Not all Board Support Packages (BSPs) |
| 8376 | can use an installer. |
| 8377 | For such cases, you need to manually create |
| 8378 | the following partition layout on the |
| 8379 | target: |
| 8380 | <itemizedlist> |
| 8381 | <listitem><para>First partition mounted |
| 8382 | under <filename>/boot</filename>, |
| 8383 | labeled "boot". |
| 8384 | </para></listitem> |
| 8385 | <listitem><para>The main rootfs |
| 8386 | partition where this image gets |
| 8387 | installed, which is mounted under |
| 8388 | <filename>/</filename>. |
| 8389 | </para></listitem> |
| 8390 | <listitem><para>Another partition |
| 8391 | labeled "testrootfs" where test |
| 8392 | images get deployed. |
| 8393 | </para></listitem> |
| 8394 | </itemizedlist> |
| 8395 | </para></listitem> |
| 8396 | </itemizedlist> |
| 8397 | </para></listitem> |
| 8398 | <listitem><para><emphasis>Install image:</emphasis> |
| 8399 | Install the image that you just built on the target |
| 8400 | system. |
| 8401 | </para></listitem> |
| 8402 | </orderedlist> |
| 8403 | </para> |
| 8404 | |
| 8405 | <para> |
| 8406 | The final thing you need to do when setting |
| 8407 | <filename>TEST_TARGET</filename> to "GummibootTarget" is |
| 8408 | to set up the test image: |
| 8409 | <orderedlist> |
| 8410 | <listitem><para><emphasis>Set up your <filename>local.conf</filename> file:</emphasis> |
| 8411 | Make sure you have the following statements in |
| 8412 | your <filename>local.conf</filename> file: |
| 8413 | <literallayout class='monospaced'> |
| 8414 | IMAGE_FSTYPES += "tar.gz" |
| 8415 | INHERIT += "testimage" |
| 8416 | TEST_TARGET = "GummibootTarget" |
| 8417 | TEST_TARGET_IP = "192.168.2.3" |
| 8418 | </literallayout> |
| 8419 | </para></listitem> |
| 8420 | <listitem><para><emphasis>Build your test image:</emphasis> |
| 8421 | Use BitBake to build the image: |
| 8422 | <literallayout class='monospaced'> |
| 8423 | $ bitbake core-image-sato |
| 8424 | </literallayout> |
| 8425 | </para></listitem> |
| 8426 | </orderedlist> |
| 8427 | </para> |
| 8428 | </section> |
| 8429 | |
| 8430 | <section id='power-control'> |
| 8431 | <title>Power Control</title> |
| 8432 | |
| 8433 | <para> |
| 8434 | For most hardware targets other than SimpleRemoteTarget, |
| 8435 | you can control power: |
| 8436 | <itemizedlist> |
| 8437 | <listitem><para> |
| 8438 | You can use |
| 8439 | <filename>TEST_POWERCONTROL_CMD</filename> |
| 8440 | together with |
| 8441 | <filename>TEST_POWERCONTROL_EXTRA_ARGS</filename> |
| 8442 | as a command that runs on the host and does power |
| 8443 | cycling. |
| 8444 | The test code passes one argument to that command: |
| 8445 | off, on or cycle (off then on). |
| 8446 | Here is an example that could appear in your |
| 8447 | <filename>local.conf</filename> file: |
| 8448 | <literallayout class='monospaced'> |
| 8449 | TEST_POWERCONTROL_CMD = "powercontrol.exp test 10.11.12.1 nuc1" |
| 8450 | </literallayout> |
| 8451 | In this example, the expect script does the |
| 8452 | following: |
| 8453 | <literallayout class='monospaced'> |
| 8454 | ssh test@10.11.12.1 "pyctl nuc1 <replaceable>arg</replaceable>" |
| 8455 | </literallayout> |
| 8456 | It then runs a Python script that controls power |
| 8457 | for a label called <filename>nuc1</filename>. |
| 8458 | <note> |
| 8459 | You need to customize |
| 8460 | <filename>TEST_POWERCONTROL_CMD</filename> |
| 8461 | and |
| 8462 | <filename>TEST_POWERCONTROL_EXTRA_ARGS</filename> |
| 8463 | for your own setup. |
| 8464 | The one requirement is that it accepts |
| 8465 | "on", "off", and "cycle" as the last argument. |
| 8466 | </note> |
| 8467 | </para></listitem> |
| 8468 | <listitem><para> |
| 8469 | When no command is defined, it connects to the |
| 8470 | device over SSH and uses the classic reboot command |
| 8471 | to reboot the device. |
| 8472 | Classic reboot is fine as long as the machine |
| 8473 | actually reboots (i.e. the SSH test has not |
| 8474 | failed). |
| 8475 | It is useful for scenarios where you have a simple |
| 8476 | setup, typically with a single board, and where |
| 8477 | some manual interaction is okay from time to time. |
| 8478 | </para></listitem> |
| 8479 | </itemizedlist> |
| 8480 | If you have no hardware to automatically perform power |
| 8481 | control but still wish to experiment with automated |
| 8482 | hardware testing, you can use the dialog-power-control |
| 8483 | script that shows a dialog prompting you to perform the |
| 8484 | required power action. |
| 8485 | This script requires either KDialog or Zenity to be |
| 8486 | installed. |
| 8487 | To use this script, set the |
| 8488 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_POWERCONTROL_CMD'><filename>TEST_POWERCONTROL_CMD</filename></ulink> |
| 8489 | variable as follows: |
| 8490 | <literallayout class='monospaced'> |
| 8491 | TEST_POWERCONTROL_CMD = "${COREBASE}/scripts/contrib/dialog-power-control" |
| 8492 | </literallayout> |
| 8493 | </para> |
| 8494 | </section> |
| 8495 | |
| 8496 | <section id='serial-console-connection'> |
| 8497 | <title>Serial Console Connection</title> |
| 8498 | |
| 8499 | <para> |
| 8500 | For test target classes requiring a serial console |
| 8501 | to interact with the bootloader (e.g. BeagleBoneTarget, |
| 8502 | EdgeRouterTarget, and GrubTarget), you need to |
| 8503 | specify a command to use to connect to the serial console |
| 8504 | of the target machine by using the |
| 8505 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SERIALCONTROL_CMD'><filename>TEST_SERIALCONTROL_CMD</filename></ulink> |
| 8506 | variable and optionally the |
| 8507 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SERIALCONTROL_EXTRA_ARGS'><filename>TEST_SERIALCONTROL_EXTRA_ARGS</filename></ulink> |
| 8508 | variable. |
| 8509 | </para> |
| 8510 | |
| 8511 | <para> |
| 8512 | These cases could be a serial terminal program if the |
| 8513 | machine is connected to a local serial port, or a |
| 8514 | <filename>telnet</filename> or |
| 8515 | <filename>ssh</filename> command connecting to a remote |
| 8516 | console server. |
| 8517 | Regardless of the case, the command simply needs to |
| 8518 | connect to the serial console and forward that connection |
| 8519 | to standard input and output as any normal terminal |
| 8520 | program does. |
| 8521 | For example, to use the picocom terminal program on |
| 8522 | serial device <filename>/dev/ttyUSB0</filename> |
| 8523 | at 115200bps, you would set the variable as follows: |
| 8524 | <literallayout class='monospaced'> |
| 8525 | TEST_SERIALCONTROL_CMD = "picocom /dev/ttyUSB0 -b 115200" |
| 8526 | </literallayout> |
| 8527 | For local devices where the serial port device disappears |
| 8528 | when the device reboots, an additional "serdevtry" wrapper |
| 8529 | script is provided. |
| 8530 | To use this wrapper, simply prefix the terminal command |
| 8531 | with |
| 8532 | <filename>${COREBASE}/scripts/contrib/serdevtry</filename>: |
| 8533 | <literallayout class='monospaced'> |
| 8534 | TEST_SERIALCONTROL_CMD = "${COREBASE}/scripts/contrib/serdevtry picocom -b |
| 8535 | 115200 /dev/ttyUSB0" |
| 8536 | </literallayout> |
| 8537 | </para> |
| 8538 | </section> |
| 8539 | </section> |
| 8540 | |
| 8541 | <section id="qemu-image-running-tests"> |
| 8542 | <title>Running Tests</title> |
| 8543 | |
| 8544 | <para> |
| 8545 | You can start the tests automatically or manually: |
| 8546 | <itemizedlist> |
| 8547 | <listitem><para><emphasis>Automatically running tests:</emphasis> |
| 8548 | To run the tests automatically after the |
| 8549 | OpenEmbedded build system successfully creates an image, |
| 8550 | first set the |
| 8551 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_IMAGE'><filename>TEST_IMAGE</filename></ulink> |
| 8552 | variable to "1" in your <filename>local.conf</filename> |
| 8553 | file in the |
| 8554 | <ulink url='&YOCTO_DOCS_DEV_URL;#build-directory'>Build Directory</ulink>: |
| 8555 | <literallayout class='monospaced'> |
| 8556 | TEST_IMAGE = "1" |
| 8557 | </literallayout> |
| 8558 | Next, build your image. |
| 8559 | If the image successfully builds, the tests will be |
| 8560 | run: |
| 8561 | <literallayout class='monospaced'> |
| 8562 | bitbake core-image-sato |
| 8563 | </literallayout></para></listitem> |
| 8564 | <listitem><para><emphasis>Manually running tests:</emphasis> |
| 8565 | To manually run the tests, first globally inherit the |
| 8566 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-testimage'><filename>testimage</filename></ulink> |
| 8567 | class by editing your <filename>local.conf</filename> |
| 8568 | file: |
| 8569 | <literallayout class='monospaced'> |
| 8570 | INHERIT += "testimage" |
| 8571 | </literallayout> |
| 8572 | Next, use BitBake to run the tests: |
| 8573 | <literallayout class='monospaced'> |
| 8574 | bitbake -c testimage <replaceable>image</replaceable> |
| 8575 | </literallayout></para></listitem> |
| 8576 | </itemizedlist> |
| 8577 | </para> |
| 8578 | |
| 8579 | <para> |
| 8580 | All test files reside in |
| 8581 | <filename>meta/lib/oeqa/runtime</filename> in the |
| 8582 | <link linkend='source-directory'>Source Directory</link>. |
| 8583 | A test name maps directly to a Python module. |
| 8584 | Each test module may contain a number of individual tests. |
| 8585 | Tests are usually grouped together by the area |
| 8586 | tested (e.g tests for systemd reside in |
| 8587 | <filename>meta/lib/oeqa/runtime/systemd.py</filename>). |
| 8588 | </para> |
| 8589 | |
| 8590 | <para> |
| 8591 | You can add tests to any layer provided you place them in the |
| 8592 | proper area and you extend |
| 8593 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink> |
| 8594 | in the <filename>local.conf</filename> file as normal. |
| 8595 | Be sure that tests reside in |
| 8596 | <filename><replaceable>layer</replaceable>/lib/oeqa/runtime</filename>. |
| 8597 | <note> |
| 8598 | Be sure that module names do not collide with module names |
| 8599 | used in the default set of test modules in |
| 8600 | <filename>meta/lib/oeqa/runtime</filename>. |
| 8601 | </note> |
| 8602 | </para> |
| 8603 | |
| 8604 | <para> |
| 8605 | You can change the set of tests run by appending or overriding |
| 8606 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SUITES'><filename>TEST_SUITES</filename></ulink> |
| 8607 | variable in <filename>local.conf</filename>. |
| 8608 | Each name in <filename>TEST_SUITES</filename> represents a |
| 8609 | required test for the image. |
| 8610 | Test modules named within <filename>TEST_SUITES</filename> |
| 8611 | cannot be skipped even if a test is not suitable for an image |
| 8612 | (e.g. running the RPM tests on an image without |
| 8613 | <filename>rpm</filename>). |
| 8614 | Appending "auto" to <filename>TEST_SUITES</filename> causes the |
| 8615 | build system to try to run all tests that are suitable for the |
| 8616 | image (i.e. each test module may elect to skip itself). |
| 8617 | </para> |
| 8618 | |
| 8619 | <para> |
| 8620 | The order you list tests in <filename>TEST_SUITES</filename> |
| 8621 | is important and influences test dependencies. |
| 8622 | Consequently, tests that depend on other tests should be added |
| 8623 | after the test on which they depend. |
| 8624 | For example, since the <filename>ssh</filename> test |
| 8625 | depends on the |
| 8626 | <filename>ping</filename> test, "ssh" needs to come after |
| 8627 | "ping" in the list. |
| 8628 | The test class provides no re-ordering or dependency handling. |
| 8629 | <note> |
| 8630 | Each module can have multiple classes with multiple test |
| 8631 | methods. |
| 8632 | And, Python <filename>unittest</filename> rules apply. |
| 8633 | </note> |
| 8634 | </para> |
| 8635 | |
| 8636 | <para> |
| 8637 | Here are some things to keep in mind when running tests: |
| 8638 | <itemizedlist> |
| 8639 | <listitem><para>The default tests for the image are defined |
| 8640 | as: |
| 8641 | <literallayout class='monospaced'> |
| 8642 | DEFAULT_TEST_SUITES_pn-<replaceable>image</replaceable> = "ping ssh df connman syslog xorg scp vnc date rpm smart dmesg" |
| 8643 | </literallayout></para></listitem> |
| 8644 | <listitem><para>Add your own test to the list of the |
| 8645 | by using the following: |
| 8646 | <literallayout class='monospaced'> |
| 8647 | TEST_SUITES_append = " mytest" |
| 8648 | </literallayout></para></listitem> |
| 8649 | <listitem><para>Run a specific list of tests as follows: |
| 8650 | <literallayout class='monospaced'> |
| 8651 | TEST_SUITES = "test1 test2 test3" |
| 8652 | </literallayout> |
| 8653 | Remember, order is important. |
| 8654 | Be sure to place a test that is dependent on another test |
| 8655 | later in the order.</para></listitem> |
| 8656 | </itemizedlist> |
| 8657 | </para> |
| 8658 | </section> |
| 8659 | |
| 8660 | <section id="exporting-tests"> |
| 8661 | <title>Exporting Tests</title> |
| 8662 | |
| 8663 | <para> |
| 8664 | You can export tests so that they can run independently of |
| 8665 | the build system. |
| 8666 | Exporting tests is required if you want to be able to hand |
| 8667 | the test execution off to a scheduler. |
| 8668 | You can only export tests that are defined in |
| 8669 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SUITES'><filename>TEST_SUITES</filename></ulink>. |
| 8670 | </para> |
| 8671 | |
| 8672 | <para> |
| 8673 | If your image is already built, make sure the following are set |
| 8674 | in your <filename>local.conf</filename> file. |
| 8675 | Be sure to provide the IP address you need: |
| 8676 | <literallayout class='monospaced'> |
| 8677 | TEST_EXPORT_ONLY = "1" |
| 8678 | TEST_TARGET = "simpleremote" |
| 8679 | TEST_TARGET_IP = "192.168.7.2" |
| 8680 | TEST_SERVER_IP = "192.168.7.1" |
| 8681 | </literallayout> |
| 8682 | You can then export the tests with the following: |
| 8683 | <literallayout class='monospaced'> |
| 8684 | $ bitbake core-image-sato -c testimage |
| 8685 | </literallayout> |
| 8686 | Exporting the tests places them in the |
| 8687 | <link linkend='build-directory'>Build Directory</link> in |
| 8688 | <filename>tmp/testimage/core-image-sato</filename>, which |
| 8689 | is controlled by the |
| 8690 | <filename>TEST_EXPORT_DIR</filename> variable. |
| 8691 | </para> |
| 8692 | |
| 8693 | <para> |
| 8694 | You can now run the tests outside of the build environment: |
| 8695 | <literallayout class='monospaced'> |
| 8696 | $ cd tmp/testimage/core-image-sato |
| 8697 | $ ./runexported.py testdata.json |
| 8698 | </literallayout> |
| 8699 | <note> |
| 8700 | This "export" feature does not deploy or boot the target |
| 8701 | image. |
| 8702 | Your target (be it a Qemu or hardware one) |
| 8703 | has to already be up and running when you call |
| 8704 | <filename>runexported.py</filename> |
| 8705 | </note> |
| 8706 | </para> |
| 8707 | |
| 8708 | <para> |
| 8709 | The exported data (i.e. <filename>testdata.json</filename>) |
| 8710 | contains paths to the Build Directory. |
| 8711 | Thus, the contents of the directory can be moved |
| 8712 | to another machine as long as you update some paths in the |
| 8713 | JSON. |
| 8714 | Usually, you only care about the |
| 8715 | <filename>${DEPLOY_DIR}/rpm</filename> directory |
| 8716 | (assuming the RPM and Smart tests are enabled). |
| 8717 | Consequently, running the tests on other machine |
| 8718 | means that you have to move the contents and call |
| 8719 | <filename>runexported.py</filename> with |
| 8720 | "--deploy-dir <replaceable>path</replaceable>" as |
| 8721 | follows: |
| 8722 | <literallayout class='monospaced'> |
| 8723 | ./runexported.py --deploy-dir /new/path/on/this/machine testdata.json |
| 8724 | </literallayout> |
| 8725 | <filename>runexported.py</filename> accepts other arguments |
| 8726 | as well as described using <filename>--help</filename>. |
| 8727 | </para> |
| 8728 | </section> |
| 8729 | |
| 8730 | <section id="qemu-image-writing-new-tests"> |
| 8731 | <title>Writing New Tests</title> |
| 8732 | |
| 8733 | <para> |
| 8734 | As mentioned previously, all new test files need to be in the |
| 8735 | proper place for the build system to find them. |
| 8736 | New tests for additional functionality outside of the core |
| 8737 | should be added to the layer that adds the functionality, in |
| 8738 | <filename><replaceable>layer</replaceable>/lib/oeqa/runtime</filename> |
| 8739 | (as long as |
| 8740 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink> |
| 8741 | is extended in the layer's |
| 8742 | <filename>layer.conf</filename> file as normal). |
| 8743 | Just remember the following: |
| 8744 | <itemizedlist> |
| 8745 | <listitem><para>Filenames need to map directly to test |
| 8746 | (module) names. |
| 8747 | </para></listitem> |
| 8748 | <listitem><para>Do not use module names that |
| 8749 | collide with existing core tests. |
| 8750 | </para></listitem> |
| 8751 | <listitem><para>Minimally, an empty |
| 8752 | <filename>__init__.py</filename> file must exist |
| 8753 | in the runtime directory. |
| 8754 | </para></listitem> |
| 8755 | </itemizedlist> |
| 8756 | </para> |
| 8757 | |
| 8758 | <para> |
| 8759 | To create a new test, start by copying an existing module |
| 8760 | (e.g. <filename>syslog.py</filename> or |
| 8761 | <filename>gcc.py</filename> are good ones to use). |
| 8762 | Test modules can use code from |
| 8763 | <filename>meta/lib/oeqa/utils</filename>, which are helper |
| 8764 | classes. |
| 8765 | </para> |
| 8766 | |
| 8767 | <note> |
| 8768 | Structure shell commands such that you rely on them and they |
| 8769 | return a single code for success. |
| 8770 | Be aware that sometimes you will need to parse the output. |
| 8771 | See the <filename>df.py</filename> and |
| 8772 | <filename>date.py</filename> modules for examples. |
| 8773 | </note> |
| 8774 | |
| 8775 | <para> |
| 8776 | You will notice that all test classes inherit |
| 8777 | <filename>oeRuntimeTest</filename>, which is found in |
| 8778 | <filename>meta/lib/oetest.py</filename>. |
| 8779 | This base class offers some helper attributes, which are |
| 8780 | described in the following sections: |
| 8781 | </para> |
| 8782 | |
| 8783 | <section id='qemu-image-writing-tests-class-methods'> |
| 8784 | <title>Class Methods</title> |
| 8785 | |
| 8786 | <para> |
| 8787 | Class methods are as follows: |
| 8788 | <itemizedlist> |
| 8789 | <listitem><para><emphasis><filename>hasPackage(pkg)</filename>:</emphasis> |
| 8790 | Returns "True" if <filename>pkg</filename> is in the |
| 8791 | installed package list of the image, which is based |
| 8792 | on the manifest file that is generated during the |
| 8793 | <filename>do_rootfs</filename> task. |
| 8794 | </para></listitem> |
| 8795 | <listitem><para><emphasis><filename>hasFeature(feature)</filename>:</emphasis> |
| 8796 | Returns "True" if the feature is in |
| 8797 | <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink> |
| 8798 | or |
| 8799 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>. |
| 8800 | </para></listitem> |
| 8801 | </itemizedlist> |
| 8802 | </para> |
| 8803 | </section> |
| 8804 | |
| 8805 | <section id='qemu-image-writing-tests-class-attributes'> |
| 8806 | <title>Class Attributes</title> |
| 8807 | |
| 8808 | <para> |
| 8809 | Class attributes are as follows: |
| 8810 | <itemizedlist> |
| 8811 | <listitem><para><emphasis><filename>pscmd</filename>:</emphasis> |
| 8812 | Equals "ps -ef" if <filename>procps</filename> is |
| 8813 | installed in the image. |
| 8814 | Otherwise, <filename>pscmd</filename> equals |
| 8815 | "ps" (busybox). |
| 8816 | </para></listitem> |
| 8817 | <listitem><para><emphasis><filename>tc</filename>:</emphasis> |
| 8818 | The called test context, which gives access to the |
| 8819 | following attributes: |
| 8820 | <itemizedlist> |
| 8821 | <listitem><para><emphasis><filename>d</filename>:</emphasis> |
| 8822 | The BitBake datastore, which allows you to |
| 8823 | use stuff such as |
| 8824 | <filename>oeRuntimeTest.tc.d.getVar("VIRTUAL-RUNTIME_init_manager")</filename>. |
| 8825 | </para></listitem> |
| 8826 | <listitem><para><emphasis><filename>testslist</filename> and <filename>testsrequired</filename>:</emphasis> |
| 8827 | Used internally. |
| 8828 | The tests do not need these. |
| 8829 | </para></listitem> |
| 8830 | <listitem><para><emphasis><filename>filesdir</filename>:</emphasis> |
| 8831 | The absolute path to |
| 8832 | <filename>meta/lib/oeqa/runtime/files</filename>, |
| 8833 | which contains helper files for tests meant |
| 8834 | for copying on the target such as small |
| 8835 | files written in C for compilation. |
| 8836 | </para></listitem> |
| 8837 | <listitem><para><emphasis><filename>target</filename>:</emphasis> |
| 8838 | The target controller object used to deploy |
| 8839 | and start an image on a particular target |
| 8840 | (e.g. QemuTarget, SimpleRemote, and |
| 8841 | GummibootTarget). |
| 8842 | Tests usually use the following: |
| 8843 | <itemizedlist> |
| 8844 | <listitem><para><emphasis><filename>ip</filename>:</emphasis> |
| 8845 | The target's IP address. |
| 8846 | </para></listitem> |
| 8847 | <listitem><para><emphasis><filename>server_ip</filename>:</emphasis> |
| 8848 | The host's IP address, which is |
| 8849 | usually used by the "smart" test |
| 8850 | suite. |
| 8851 | </para></listitem> |
| 8852 | <listitem><para><emphasis><filename>run(cmd, timeout=None)</filename>:</emphasis> |
| 8853 | The single, most used method. |
| 8854 | This command is a wrapper for: |
| 8855 | <filename>ssh root@host "cmd"</filename>. |
| 8856 | The command returns a tuple: |
| 8857 | (status, output), which are what |
| 8858 | their names imply - the return code |
| 8859 | of "cmd" and whatever output |
| 8860 | it produces. |
| 8861 | The optional timeout argument |
| 8862 | represents the number of seconds the |
| 8863 | test should wait for "cmd" to |
| 8864 | return. |
| 8865 | If the argument is "None", the |
| 8866 | test uses the default instance's |
| 8867 | timeout period, which is 300 |
| 8868 | seconds. |
| 8869 | If the argument is "0", the test |
| 8870 | runs until the command returns. |
| 8871 | </para></listitem> |
| 8872 | <listitem><para><emphasis><filename>copy_to(localpath, remotepath)</filename>:</emphasis> |
| 8873 | <filename>scp localpath root@ip:remotepath</filename>. |
| 8874 | </para></listitem> |
| 8875 | <listitem><para><emphasis><filename>copy_from(remotepath, localpath)</filename>:</emphasis> |
| 8876 | <filename>scp root@host:remotepath localpath</filename>. |
| 8877 | </para></listitem> |
| 8878 | </itemizedlist></para></listitem> |
| 8879 | </itemizedlist></para></listitem> |
| 8880 | </itemizedlist> |
| 8881 | </para> |
| 8882 | </section> |
| 8883 | |
| 8884 | <section id='qemu-image-writing-tests-instance-attributes'> |
| 8885 | <title>Instance Attributes</title> |
| 8886 | |
| 8887 | <para> |
| 8888 | A single instance attribute exists, which is |
| 8889 | <filename>target</filename>. |
| 8890 | The <filename>target</filename> instance attribute is |
| 8891 | identical to the class attribute of the same name, which |
| 8892 | is described in the previous section. |
| 8893 | This attribute exists as both an instance and class |
| 8894 | attribute so tests can use |
| 8895 | <filename>self.target.run(cmd)</filename> in instance |
| 8896 | methods instead of |
| 8897 | <filename>oeRuntimeTest.tc.target.run(cmd)</filename>. |
| 8898 | </para> |
| 8899 | </section> |
| 8900 | </section> |
| 8901 | </section> |
| 8902 | |
| 8903 | <section id="platdev-gdb-remotedebug"> |
| 8904 | <title>Debugging With the GNU Project Debugger (GDB) Remotely</title> |
| 8905 | |
| 8906 | <para> |
| 8907 | GDB allows you to examine running programs, which in turn helps you to understand and fix problems. |
| 8908 | It also allows you to perform post-mortem style analysis of program crashes. |
| 8909 | GDB is available as a package within the Yocto Project and is |
| 8910 | installed in SDK images by default. |
| 8911 | See the "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>" chapter |
| 8912 | in the Yocto Project Reference Manual for a description of these images. |
| 8913 | You can find information on GDB at <ulink url="http://sourceware.org/gdb/"/>. |
| 8914 | </para> |
| 8915 | |
| 8916 | <tip> |
| 8917 | For best results, install debug (<filename>-dbg</filename>) packages |
| 8918 | for the applications you are going to debug. |
| 8919 | Doing so makes extra debug symbols available that give you more |
| 8920 | meaningful output. |
| 8921 | </tip> |
| 8922 | |
| 8923 | <para> |
| 8924 | Sometimes, due to memory or disk space constraints, it is not possible |
| 8925 | to use GDB directly on the remote target to debug applications. |
| 8926 | These constraints arise because GDB needs to load the debugging information and the |
| 8927 | binaries of the process being debugged. |
| 8928 | Additionally, GDB needs to perform many computations to locate information such as function |
| 8929 | names, variable names and values, stack traces and so forth - even before starting the |
| 8930 | debugging process. |
| 8931 | These extra computations place more load on the target system and can alter the |
| 8932 | characteristics of the program being debugged. |
| 8933 | </para> |
| 8934 | |
| 8935 | <para> |
| 8936 | To help get past the previously mentioned constraints, you can use Gdbserver. |
| 8937 | Gdbserver runs on the remote target and does not load any debugging information |
| 8938 | from the debugged process. |
| 8939 | Instead, a GDB instance processes the debugging information that is run on a |
| 8940 | remote computer - the host GDB. |
| 8941 | The host GDB then sends control commands to Gdbserver to make it stop or start the debugged |
| 8942 | program, as well as read or write memory regions of that debugged program. |
| 8943 | All the debugging information loaded and processed as well |
| 8944 | as all the heavy debugging is done by the host GDB. |
| 8945 | Offloading these processes gives the Gdbserver running on the target a chance to remain |
| 8946 | small and fast. |
| 8947 | <note> |
| 8948 | By default, source files are part of the |
| 8949 | <filename>*-dbg</filename> packages in order to enable GDB |
| 8950 | to show source lines in its output. |
| 8951 | You can save further space on the target by setting the |
| 8952 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_DEBUG_SPLIT_STYLE'><filename>PACKAGE_DEBUG_SPLIT_STYLE</filename></ulink> |
| 8953 | variable to "debug-without-src" so that these packages do not |
| 8954 | include the source files. |
| 8955 | </note> |
| 8956 | </para> |
| 8957 | |
| 8958 | <para> |
| 8959 | Because the host GDB is responsible for loading the debugging information and |
| 8960 | for doing the necessary processing to make actual debugging happen, |
| 8961 | you have to make sure the host can access the unstripped binaries complete |
| 8962 | with their debugging information and also be sure the target is compiled with no optimizations. |
| 8963 | The host GDB must also have local access to all the libraries used by the |
| 8964 | debugged program. |
| 8965 | Because Gdbserver does not need any local debugging information, the binaries on |
| 8966 | the remote target can remain stripped. |
| 8967 | However, the binaries must also be compiled without optimization |
| 8968 | so they match the host's binaries. |
| 8969 | </para> |
| 8970 | |
| 8971 | <para> |
| 8972 | To remain consistent with GDB documentation and terminology, the binary being debugged |
| 8973 | on the remote target machine is referred to as the "inferior" binary. |
| 8974 | For documentation on GDB see the |
| 8975 | <ulink url="http://sourceware.org/gdb/documentation/">GDB site</ulink>. |
| 8976 | </para> |
| 8977 | |
| 8978 | <para> |
| 8979 | The remainder of this section describes the steps you need to take |
| 8980 | to debug using the GNU project debugger. |
| 8981 | </para> |
| 8982 | |
| 8983 | <section id='platdev-gdb-remotedebug-setup'> |
| 8984 | <title>Set Up the Cross-Development Debugging Environment</title> |
| 8985 | |
| 8986 | <para> |
| 8987 | Before you can initiate a remote debugging session, you need |
| 8988 | to be sure you have set up the cross-development environment, |
| 8989 | toolchain, and sysroot. |
| 8990 | The "<ulink url='&YOCTO_DOCS_ADT_URL;#adt-prepare'>Preparing for Application Development</ulink>" |
| 8991 | chapter of the Yocto Project Application Developer's Guide |
| 8992 | describes this process. |
| 8993 | Be sure you have read that chapter and have set up |
| 8994 | your environment. |
| 8995 | </para> |
| 8996 | </section> |
| 8997 | |
| 8998 | <section id="platdev-gdb-remotedebug-launch-gdbserver"> |
| 8999 | <title>Launch Gdbserver on the Target</title> |
| 9000 | |
| 9001 | <para> |
| 9002 | Make sure Gdbserver is installed on the target. |
| 9003 | If it is not, install the package |
| 9004 | <filename>gdbserver</filename>, which needs the |
| 9005 | <filename>libthread-db1</filename> package. |
| 9006 | </para> |
| 9007 | |
| 9008 | <para> |
| 9009 | Here is an example, that when entered from the host, |
| 9010 | connects to the target and launches Gdbserver in order to |
| 9011 | "debug" a binary named <filename>helloworld</filename>: |
| 9012 | <literallayout class='monospaced'> |
| 9013 | $ gdbserver localhost:2345 /usr/bin/helloworld |
| 9014 | </literallayout> |
| 9015 | Gdbserver should now be listening on port 2345 for debugging |
| 9016 | commands coming from a remote GDB process that is running on |
| 9017 | the host computer. |
| 9018 | Communication between Gdbserver and the host GDB are done |
| 9019 | using TCP. |
| 9020 | To use other communication protocols, please refer to the |
| 9021 | <ulink url='http://www.gnu.org/software/gdb/'>Gdbserver documentation</ulink>. |
| 9022 | </para> |
| 9023 | </section> |
| 9024 | |
| 9025 | <section id="platdev-gdb-remotedebug-launch-gdb"> |
| 9026 | <title>Launch GDB on the Host Computer</title> |
| 9027 | |
| 9028 | <para> |
| 9029 | Running GDB on the host computer takes a number of stages, which |
| 9030 | this section describes. |
| 9031 | </para> |
| 9032 | |
| 9033 | <section id="platdev-gdb-remotedebug-launch-gdb-buildcross"> |
| 9034 | <title>Build the Cross-GDB Package</title> |
| 9035 | <para> |
| 9036 | A suitable GDB cross-binary is required that runs on your |
| 9037 | host computer but also knows about the the ABI of the |
| 9038 | remote target. |
| 9039 | You can get this binary from the |
| 9040 | <link linkend='cross-development-toolchain'>Cross-Development Toolchain</link>. |
| 9041 | Here is an example where the toolchain has been installed |
| 9042 | in the default directory |
| 9043 | <filename>/opt/poky/&DISTRO;</filename>: |
| 9044 | <literallayout class='monospaced'> |
| 9045 | /opt/poky/&DISTRO;/sysroots/i686-pokysdk-linux/usr/bin/armv7a-vfp-neon-poky-linux-gnueabi/arm-poky-linux-gnueabi-gdb |
| 9046 | </literallayout> |
| 9047 | where <filename>arm</filename> is the target architecture |
| 9048 | and <filename>linux-gnueabi</filename> is the target ABI. |
| 9049 | </para> |
| 9050 | |
| 9051 | <para> |
| 9052 | Alternatively, you can use BitBake to build the |
| 9053 | <filename>gdb-cross</filename> binary. |
| 9054 | Here is an example: |
| 9055 | <literallayout class='monospaced'> |
| 9056 | $ bitbake gdb-cross |
| 9057 | </literallayout> |
| 9058 | Once the binary is built, you can find it here: |
| 9059 | <literallayout class='monospaced'> |
| 9060 | tmp/sysroots/<replaceable>host-arch</replaceable>/usr/bin/<replaceable>target-platform</replaceable>/<replaceable>target-abi</replaceable>-gdb |
| 9061 | </literallayout> |
| 9062 | </para> |
| 9063 | </section> |
| 9064 | |
| 9065 | <section id='create-the-gdb-initialization-file'> |
| 9066 | <title>Create the GDB Initialization File and Point to Your Root Filesystem</title> |
| 9067 | |
| 9068 | <para> |
| 9069 | Aside from the GDB cross-binary, you also need a GDB |
| 9070 | initialization file in the same top directory in which |
| 9071 | your binary resides. |
| 9072 | When you start GDB on your host development system, GDB |
| 9073 | finds this initialization file and executes all the |
| 9074 | commands within. |
| 9075 | For information on the <filename>.gdbinit</filename>, see |
| 9076 | "<ulink url='http://sourceware.org/gdb/onlinedocs/gdb/'>Debugging with GDB</ulink>", |
| 9077 | which is maintained by |
| 9078 | <ulink url='http://www.sourceware.org'>sourceware.org</ulink>. |
| 9079 | </para> |
| 9080 | |
| 9081 | <para> |
| 9082 | You need to add a statement in the |
| 9083 | <filename>~/.gdbinit</filename> file that points to your |
| 9084 | root filesystem. |
| 9085 | Here is an example that points to the root filesystem for |
| 9086 | an ARM-based target device: |
| 9087 | <literallayout class='monospaced'> |
| 9088 | set sysroot ~/sysroot_arm |
| 9089 | </literallayout> |
| 9090 | </para> |
| 9091 | </section> |
| 9092 | |
| 9093 | <section id="platdev-gdb-remotedebug-launch-gdb-launchhost"> |
| 9094 | <title>Launch the Host GDB</title> |
| 9095 | |
| 9096 | <para> |
| 9097 | Before launching the host GDB, you need to be sure |
| 9098 | you have sourced the cross-debugging environment script, |
| 9099 | which if you installed the root filesystem in the default |
| 9100 | location is at <filename>/opt/poky/&DISTRO;</filename> |
| 9101 | and begins with the string "environment-setup". |
| 9102 | For more information, see the |
| 9103 | "<ulink url='&YOCTO_DOCS_ADT_URL;#setting-up-the-cross-development-environment'>Setting Up the Cross-Development Environment</ulink>" |
| 9104 | section in the Yocto Project Application Developer's |
| 9105 | Guide. |
| 9106 | </para> |
| 9107 | |
| 9108 | <para> |
| 9109 | Finally, switch to the directory where the binary resides |
| 9110 | and run the <filename>cross-gdb</filename> binary. |
| 9111 | Provide the binary file you are going to debug. |
| 9112 | For example, the following command continues with the |
| 9113 | example used in the previous section by loading |
| 9114 | the <filename>helloworld</filename> binary as well as the |
| 9115 | debugging information: |
| 9116 | <literallayout class='monospaced'> |
| 9117 | $ arm-poky-linux-gnuabi-gdb helloworld |
| 9118 | </literallayout> |
| 9119 | The commands in your <filename>.gdbinit</filename> execute |
| 9120 | and the GDB prompt appears. |
| 9121 | </para> |
| 9122 | </section> |
| 9123 | </section> |
| 9124 | |
| 9125 | <section id='platdev-gdb-connect-to-the-remote-gdb-server'> |
| 9126 | <title>Connect to the Remote GDB Server</title> |
| 9127 | |
| 9128 | <para> |
| 9129 | From the target, you need to connect to the remote GDB |
| 9130 | server that is running on the host. |
| 9131 | You need to specify the remote host and port. |
| 9132 | Here is the command continuing with the example: |
| 9133 | <literallayout class='monospaced'> |
| 9134 | target remote 192.168.7.2:2345 |
| 9135 | </literallayout> |
| 9136 | </para> |
| 9137 | </section> |
| 9138 | |
| 9139 | <section id="platdev-gdb-remotedebug-launch-gdb-using"> |
| 9140 | <title>Use the Debugger</title> |
| 9141 | |
| 9142 | <para> |
| 9143 | You can now proceed with debugging as normal - as if you were debugging |
| 9144 | on the local machine. |
| 9145 | For example, to instruct GDB to break in the "main" function and then |
| 9146 | continue with execution of the inferior binary use the following commands |
| 9147 | from within GDB: |
| 9148 | <literallayout class='monospaced'> |
| 9149 | (gdb) break main |
| 9150 | (gdb) continue |
| 9151 | </literallayout> |
| 9152 | </para> |
| 9153 | |
| 9154 | <para> |
| 9155 | For more information about using GDB, see the project's online documentation at |
| 9156 | <ulink url="http://sourceware.org/gdb/download/onlinedocs/"/>. |
| 9157 | </para> |
| 9158 | </section> |
| 9159 | </section> |
| 9160 | |
| 9161 | <section id='debugging-parallel-make-races'> |
| 9162 | <title>Debugging Parallel Make Races</title> |
| 9163 | |
| 9164 | <para> |
| 9165 | A parallel <filename>make</filename> race occurs when the build |
| 9166 | consists of several parts that are run simultaneously and |
| 9167 | a situation occurs when the output or result of one |
| 9168 | part is not ready for use with a different part of the build that |
| 9169 | depends on that output. |
| 9170 | Parallel make races are annoying and can sometimes be difficult |
| 9171 | to reproduce and fix. |
| 9172 | However, some simple tips and tricks exist that can help |
| 9173 | you debug and fix them. |
| 9174 | This section presents a real-world example of an error encountered |
| 9175 | on the Yocto Project autobuilder and the process used to fix it. |
| 9176 | <note> |
| 9177 | If you cannot properly fix a <filename>make</filename> race |
| 9178 | condition, you can work around it by clearing either the |
| 9179 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink> |
| 9180 | or |
| 9181 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKEINST'><filename>PARALLEL_MAKEINST</filename></ulink> |
| 9182 | variables. |
| 9183 | </note> |
| 9184 | </para> |
| 9185 | |
| 9186 | <section id='the-failure'> |
| 9187 | <title>The Failure</title> |
| 9188 | |
| 9189 | <para> |
| 9190 | For this example, assume that you are building an image that |
| 9191 | depends on the "neard" package. |
| 9192 | And, during the build, BitBake runs into problems and |
| 9193 | creates the following output. |
| 9194 | <note> |
| 9195 | This example log file has longer lines artificially |
| 9196 | broken to make the listing easier to read. |
| 9197 | </note> |
| 9198 | If you examine the output or the log file, you see the |
| 9199 | failure during <filename>make</filename>: |
| 9200 | <literallayout class='monospaced'> |
| 9201 | | DEBUG: SITE files ['endian-little', 'bit-32', 'ix86-common', 'common-linux', 'common-glibc', 'i586-linux', 'common'] |
| 9202 | | DEBUG: Executing shell function do_compile |
| 9203 | | NOTE: make -j 16 |
| 9204 | | make --no-print-directory all-am |
| 9205 | | /bin/mkdir -p include/near |
| 9206 | | /bin/mkdir -p include/near |
| 9207 | | /bin/mkdir -p include/near |
| 9208 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9209 | 0.14-r0/neard-0.14/include/types.h include/near/types.h |
| 9210 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9211 | 0.14-r0/neard-0.14/include/log.h include/near/log.h |
| 9212 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9213 | 0.14-r0/neard-0.14/include/plugin.h include/near/plugin.h |
| 9214 | | /bin/mkdir -p include/near |
| 9215 | | /bin/mkdir -p include/near |
| 9216 | | /bin/mkdir -p include/near |
| 9217 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9218 | 0.14-r0/neard-0.14/include/tag.h include/near/tag.h |
| 9219 | | /bin/mkdir -p include/near |
| 9220 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9221 | 0.14-r0/neard-0.14/include/adapter.h include/near/adapter.h |
| 9222 | | /bin/mkdir -p include/near |
| 9223 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9224 | 0.14-r0/neard-0.14/include/ndef.h include/near/ndef.h |
| 9225 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9226 | 0.14-r0/neard-0.14/include/tlv.h include/near/tlv.h |
| 9227 | | /bin/mkdir -p include/near |
| 9228 | | /bin/mkdir -p include/near |
| 9229 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9230 | 0.14-r0/neard-0.14/include/setting.h include/near/setting.h |
| 9231 | | /bin/mkdir -p include/near |
| 9232 | | /bin/mkdir -p include/near |
| 9233 | | /bin/mkdir -p include/near |
| 9234 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9235 | 0.14-r0/neard-0.14/include/device.h include/near/device.h |
| 9236 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9237 | 0.14-r0/neard-0.14/include/nfc_copy.h include/near/nfc_copy.h |
| 9238 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9239 | 0.14-r0/neard-0.14/include/snep.h include/near/snep.h |
| 9240 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9241 | 0.14-r0/neard-0.14/include/version.h include/near/version.h |
| 9242 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ |
| 9243 | 0.14-r0/neard-0.14/include/dbus.h include/near/dbus.h |
| 9244 | | ./src/genbuiltin nfctype1 nfctype2 nfctype3 nfctype4 p2p > src/builtin.h |
| 9245 | | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/ |
| 9246 | build/build/tmp/sysroots/qemux86 -DHAVE_CONFIG_H -I. -I./include -I./src -I./gdbus -I/home/pokybuild/ |
| 9247 | yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/glib-2.0 |
| 9248 | -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/ |
| 9249 | lib/glib-2.0/include -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/ |
| 9250 | tmp/sysroots/qemux86/usr/include/dbus-1.0 -I/home/pokybuild/yocto-autobuilder/yocto-slave/ |
| 9251 | nightly-x86/build/build/tmp/sysroots/qemux86/usr/lib/dbus-1.0/include -I/home/pokybuild/yocto-autobuilder/ |
| 9252 | yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/libnl3 |
| 9253 | -DNEAR_PLUGIN_BUILTIN -DPLUGINDIR=\""/usr/lib/near/plugins"\" |
| 9254 | -DCONFIGDIR=\""/etc/neard\"" -O2 -pipe -g -feliminate-unused-debug-types -c |
| 9255 | -o tools/snep-send.o tools/snep-send.c |
| 9256 | | In file included from tools/snep-send.c:16:0: |
| 9257 | | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory |
| 9258 | | #include <near/dbus.h> |
| 9259 | | ^ |
| 9260 | | compilation terminated. |
| 9261 | | make[1]: *** [tools/snep-send.o] Error 1 |
| 9262 | | make[1]: *** Waiting for unfinished jobs.... |
| 9263 | | make: *** [all] Error 2 |
| 9264 | | ERROR: oe_runmake failed |
| 9265 | </literallayout> |
| 9266 | </para> |
| 9267 | </section> |
| 9268 | |
| 9269 | <section id='reproducing-the-error'> |
| 9270 | <title>Reproducing the Error</title> |
| 9271 | |
| 9272 | <para> |
| 9273 | Because race conditions are intermittent, they do not |
| 9274 | manifest themselves every time you do the build. |
| 9275 | In fact, most times the build will complete without problems |
| 9276 | even though the potential race condition exists. |
| 9277 | Thus, once the error surfaces, you need a way to reproduce it. |
| 9278 | </para> |
| 9279 | |
| 9280 | <para> |
| 9281 | In this example, compiling the "neard" package is causing the |
| 9282 | problem. |
| 9283 | So the first thing to do is build "neard" locally. |
| 9284 | Before you start the build, set the |
| 9285 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink> |
| 9286 | variable in your <filename>local.conf</filename> file to |
| 9287 | a high number (e.g. "-j 20"). |
| 9288 | Using a high value for <filename>PARALLEL_MAKE</filename> |
| 9289 | increases the chances of the race condition showing up: |
| 9290 | <literallayout class='monospaced'> |
| 9291 | $ bitbake neard |
| 9292 | </literallayout> |
| 9293 | </para> |
| 9294 | |
| 9295 | <para> |
| 9296 | Once the local build for "neard" completes, start a |
| 9297 | <filename>devshell</filename> build: |
| 9298 | <literallayout class='monospaced'> |
| 9299 | $ bitbake neard -c devshell |
| 9300 | </literallayout> |
| 9301 | For information on how to use a |
| 9302 | <filename>devshell</filename>, see the |
| 9303 | "<link linkend='platdev-appdev-devshell'>Using a Development Shell</link>" |
| 9304 | section. |
| 9305 | </para> |
| 9306 | |
| 9307 | <para> |
| 9308 | In the <filename>devshell</filename>, do the following: |
| 9309 | <literallayout class='monospaced'> |
| 9310 | $ make clean |
| 9311 | $ make tools/snep-send.o |
| 9312 | </literallayout> |
| 9313 | The <filename>devshell</filename> commands cause the failure |
| 9314 | to clearly be visible. |
| 9315 | In this case, a missing dependency exists for the "neard" |
| 9316 | Makefile target. |
| 9317 | Here is some abbreviated, sample output with the |
| 9318 | missing dependency clearly visible at the end: |
| 9319 | <literallayout class='monospaced'> |
| 9320 | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/scott-lenovo/...... |
| 9321 | . |
| 9322 | . |
| 9323 | . |
| 9324 | tools/snep-send.c |
| 9325 | In file included from tools/snep-send.c:16:0: |
| 9326 | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory |
| 9327 | #include <near/dbus.h> |
| 9328 | ^ |
| 9329 | compilation terminated. |
| 9330 | make: *** [tools/snep-send.o] Error 1 |
| 9331 | $ |
| 9332 | </literallayout> |
| 9333 | </para> |
| 9334 | </section> |
| 9335 | |
| 9336 | <section id='creating-a-patch-for-the-fix'> |
| 9337 | <title>Creating a Patch for the Fix</title> |
| 9338 | |
| 9339 | <para> |
| 9340 | Because there is a missing dependency for the Makefile |
| 9341 | target, you need to patch the |
| 9342 | <filename>Makefile.am</filename> file, which is generated |
| 9343 | from <filename>Makefile.in</filename>. |
| 9344 | You can use Quilt to create the patch: |
| 9345 | <literallayout class='monospaced'> |
| 9346 | $ quilt new parallelmake.patch |
| 9347 | Patch patches/parallelmake.patch is now on top |
| 9348 | $ quilt add Makefile.am |
| 9349 | File Makefile.am added to patch patches/parallelmake.patch |
| 9350 | </literallayout> |
| 9351 | For more information on using Quilt, see the |
| 9352 | "<link linkend='using-a-quilt-workflow'>Using Quilt in Your Workflow</link>" |
| 9353 | section. |
| 9354 | </para> |
| 9355 | |
| 9356 | <para> |
| 9357 | At this point you need to make the edits to |
| 9358 | <filename>Makefile.am</filename> to add the missing |
| 9359 | dependency. |
| 9360 | For our example, you have to add the following line |
| 9361 | to the file: |
| 9362 | <literallayout class='monospaced'> |
| 9363 | tools/snep-send.$(OBJEXT): include/near/dbus.h |
| 9364 | </literallayout> |
| 9365 | </para> |
| 9366 | |
| 9367 | <para> |
| 9368 | Once you have edited the file, use the |
| 9369 | <filename>refresh</filename> command to create the patch: |
| 9370 | <literallayout class='monospaced'> |
| 9371 | $ quilt refresh |
| 9372 | Refreshed patch patches/parallelmake.patch |
| 9373 | </literallayout> |
| 9374 | Once the patch file exists, you need to add it back to the |
| 9375 | originating recipe folder. |
| 9376 | Here is an example assuming a top-level |
| 9377 | <link linkend='source-directory'>Source Directory</link> |
| 9378 | named <filename>poky</filename>: |
| 9379 | <literallayout class='monospaced'> |
| 9380 | $ cp patches/parallelmake.patch poky/meta/recipes-connectivity/neard/neard |
| 9381 | </literallayout> |
| 9382 | The final thing you need to do to implement the fix in the |
| 9383 | build is to update the "neard" recipe (i.e. |
| 9384 | <filename>neard-0.14.bb</filename>) so that the |
| 9385 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> |
| 9386 | statement includes the patch file. |
| 9387 | The recipe file is in the folder above the patch. |
| 9388 | Here is what the edited <filename>SRC_URI</filename> |
| 9389 | statement would look like: |
| 9390 | <literallayout class='monospaced'> |
| 9391 | SRC_URI = "${KERNELORG_MIRROR}/linux/network/nfc/${BPN}-${PV}.tar.xz \ |
| 9392 | file://neard.in \ |
| 9393 | file://neard.service.in \ |
| 9394 | file://parallelmake.patch \ |
| 9395 | " |
| 9396 | </literallayout> |
| 9397 | </para> |
| 9398 | |
| 9399 | <para> |
| 9400 | With the patch complete and moved to the correct folder and |
| 9401 | the <filename>SRC_URI</filename> statement updated, you can |
| 9402 | exit the <filename>devshell</filename>: |
| 9403 | <literallayout class='monospaced'> |
| 9404 | $ exit |
| 9405 | </literallayout> |
| 9406 | </para> |
| 9407 | </section> |
| 9408 | |
| 9409 | <section id='testing-the-build'> |
| 9410 | <title>Testing the Build</title> |
| 9411 | |
| 9412 | <para> |
| 9413 | With everything in place, you can get back to trying the |
| 9414 | build again locally: |
| 9415 | <literallayout class='monospaced'> |
| 9416 | $ bitbake neard |
| 9417 | </literallayout> |
| 9418 | This build should succeed. |
| 9419 | </para> |
| 9420 | |
| 9421 | <para> |
| 9422 | Now you can open up a <filename>devshell</filename> again |
| 9423 | and repeat the clean and make operations as follows: |
| 9424 | <literallayout class='monospaced'> |
| 9425 | $ bitbake neard -c devshell |
| 9426 | $ make clean |
| 9427 | $ make tools/snep-send.o |
| 9428 | </literallayout> |
| 9429 | The build should work without issue. |
| 9430 | </para> |
| 9431 | |
| 9432 | <para> |
| 9433 | As with all solved problems, if they originated upstream, you |
| 9434 | need to submit the fix for the recipe in OE-Core and upstream |
| 9435 | so that the problem is taken care of at its source. |
| 9436 | See the |
| 9437 | "<link linkend='how-to-submit-a-change'>How to Submit a Change</link>" |
| 9438 | section for more information. |
| 9439 | </para> |
| 9440 | </section> |
| 9441 | </section> |
| 9442 | |
| 9443 | <section id="platdev-oprofile"> |
| 9444 | <title>Profiling with OProfile</title> |
| 9445 | |
| 9446 | <para> |
| 9447 | <ulink url="http://oprofile.sourceforge.net/">OProfile</ulink> is a |
| 9448 | statistical profiler well suited for finding performance |
| 9449 | bottlenecks in both user-space software and in the kernel. |
| 9450 | This profiler provides answers to questions like "Which functions does my application spend |
| 9451 | the most time in when doing X?" |
| 9452 | Because the OpenEmbedded build system is well integrated with OProfile, it makes profiling |
| 9453 | applications on target hardware straight forward. |
| 9454 | <note> |
| 9455 | For more information on how to set up and run OProfile, see the |
| 9456 | "<ulink url='&YOCTO_DOCS_PROF_URL;#profile-manual-oprofile'>oprofile</ulink>" |
| 9457 | section in the Yocto Project Profiling and Tracing Manual. |
| 9458 | </note> |
| 9459 | </para> |
| 9460 | |
| 9461 | <para> |
| 9462 | To use OProfile, you need an image that has OProfile installed. |
| 9463 | The easiest way to do this is with "tools-profile" in the |
| 9464 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'>IMAGE_FEATURES</ulink></filename> variable. |
| 9465 | You also need debugging symbols to be available on the system where the analysis |
| 9466 | takes place. |
| 9467 | You can gain access to the symbols by using "dbg-pkgs" in the |
| 9468 | <filename>IMAGE_FEATURES</filename> variable or by |
| 9469 | installing the appropriate debug (<filename>-dbg</filename>) |
| 9470 | packages. |
| 9471 | </para> |
| 9472 | |
| 9473 | <para> |
| 9474 | For successful call graph analysis, the binaries must preserve the frame |
| 9475 | pointer register and should also be compiled with the |
| 9476 | <filename>-fno-omit-framepointer</filename> flag. |
| 9477 | You can achieve this by setting the |
| 9478 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SELECTED_OPTIMIZATION'>SELECTED_OPTIMIZATION</ulink></filename> |
| 9479 | variable with the following options: |
| 9480 | <literallayout class='monospaced'> |
| 9481 | -fexpensive-optimizations |
| 9482 | -fno-omit-framepointer |
| 9483 | -frename-registers |
| 9484 | -O2 |
| 9485 | </literallayout> |
| 9486 | You can also achieve it by setting the |
| 9487 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-DEBUG_BUILD'>DEBUG_BUILD</ulink></filename> |
| 9488 | variable to "1" in the <filename>local.conf</filename> configuration file. |
| 9489 | If you use the <filename>DEBUG_BUILD</filename> variable, |
| 9490 | you also add extra debugging information that can make the debug |
| 9491 | packages large. |
| 9492 | </para> |
| 9493 | |
| 9494 | <section id="platdev-oprofile-target"> |
| 9495 | <title>Profiling on the Target</title> |
| 9496 | |
| 9497 | <para> |
| 9498 | Using OProfile, you can perform all the profiling work on the target device. |
| 9499 | A simple OProfile session might look like the following: |
| 9500 | </para> |
| 9501 | |
| 9502 | <para> |
| 9503 | <literallayout class='monospaced'> |
| 9504 | # opcontrol --reset |
| 9505 | # opcontrol --start --separate=lib --no-vmlinux -c 5 |
| 9506 | . |
| 9507 | . |
| 9508 | [do whatever is being profiled] |
| 9509 | . |
| 9510 | . |
| 9511 | # opcontrol --stop |
| 9512 | $ opreport -cl |
| 9513 | </literallayout> |
| 9514 | </para> |
| 9515 | |
| 9516 | <para> |
| 9517 | In this example, the <filename>reset</filename> command clears any previously profiled data. |
| 9518 | The next command starts OProfile. |
| 9519 | The options used when starting the profiler separate dynamic library data |
| 9520 | within applications, disable kernel profiling, and enable callgraphing up to |
| 9521 | five levels deep. |
| 9522 | <note> |
| 9523 | To profile the kernel, you would specify the |
| 9524 | <filename>--vmlinux=/path/to/vmlinux</filename> option. |
| 9525 | The <filename>vmlinux</filename> file is usually in the source directory in the |
| 9526 | <filename>/boot/</filename> directory and must match the running kernel. |
| 9527 | </note> |
| 9528 | </para> |
| 9529 | |
| 9530 | <para> |
| 9531 | After you perform your profiling tasks, the next command stops the profiler. |
| 9532 | After that, you can view results with the <filename>opreport</filename> command with options |
| 9533 | to see the separate library symbols and callgraph information. |
| 9534 | </para> |
| 9535 | |
| 9536 | <para> |
| 9537 | Callgraphing logs information about time spent in functions and about a function's |
| 9538 | calling function (parent) and called functions (children). |
| 9539 | The higher the callgraphing depth, the more accurate the results. |
| 9540 | However, higher depths also increase the logging overhead. |
| 9541 | Consequently, you should take care when setting the callgraphing depth. |
| 9542 | <note> |
| 9543 | On ARM, binaries need to have the frame pointer enabled for callgraphing to work. |
| 9544 | To accomplish this use the <filename>-fno-omit-framepointer</filename> option |
| 9545 | with <filename>gcc</filename>. |
| 9546 | </note> |
| 9547 | </para> |
| 9548 | |
| 9549 | <para> |
| 9550 | For more information on using OProfile, see the OProfile |
| 9551 | online documentation at |
| 9552 | <ulink url="http://oprofile.sourceforge.net/docs/"/>. |
| 9553 | </para> |
| 9554 | </section> |
| 9555 | |
| 9556 | <section id="platdev-oprofile-oprofileui"> |
| 9557 | <title>Using OProfileUI</title> |
| 9558 | |
| 9559 | <para> |
| 9560 | A graphical user interface for OProfile is also available. |
| 9561 | You can download and build this interface from the Yocto Project at |
| 9562 | <ulink url="&YOCTO_GIT_URL;/cgit.cgi/oprofileui/"></ulink>. |
| 9563 | If the "tools-profile" image feature is selected, all necessary binaries |
| 9564 | are installed onto the target device for OProfileUI interaction. |
| 9565 | For a list of image features that ship with the Yocto Project, |
| 9566 | see the |
| 9567 | "<ulink url='&YOCTO_DOCS_REF_URL;#ref-features-image'>Image Features</ulink>" |
| 9568 | section in the Yocto Project Reference Manual. |
| 9569 | </para> |
| 9570 | |
| 9571 | <para> |
| 9572 | Even though the source directory usually includes all needed patches on the target device, you |
| 9573 | might find you need other OProfile patches for recent OProfileUI features. |
| 9574 | If so, see the <ulink url='&YOCTO_GIT_URL;/cgit.cgi/oprofileui/tree/README'> |
| 9575 | OProfileUI README</ulink> for the most recent information. |
| 9576 | </para> |
| 9577 | |
| 9578 | <section id="platdev-oprofile-oprofileui-online"> |
| 9579 | <title>Online Mode</title> |
| 9580 | |
| 9581 | <para> |
| 9582 | Using OProfile in online mode assumes a working network connection with the target |
| 9583 | hardware. |
| 9584 | With this connection, you just need to run "oprofile-server" on the device. |
| 9585 | By default, OProfile listens on port 4224. |
| 9586 | <note> |
| 9587 | You can change the port using the <filename>--port</filename> command-line |
| 9588 | option. |
| 9589 | </note> |
| 9590 | </para> |
| 9591 | |
| 9592 | <para> |
| 9593 | The client program is called <filename>oprofile-viewer</filename> and its UI is relatively |
| 9594 | straight forward. |
| 9595 | You access key functionality through the buttons on the toolbar, which |
| 9596 | are duplicated in the menus. |
| 9597 | Here are the buttons: |
| 9598 | <itemizedlist> |
| 9599 | <listitem><para><emphasis>Connect:</emphasis> Connects to the remote host. |
| 9600 | You can also supply the IP address or hostname.</para></listitem> |
| 9601 | <listitem><para><emphasis>Disconnect:</emphasis> Disconnects from the target. |
| 9602 | </para></listitem> |
| 9603 | <listitem><para><emphasis>Start:</emphasis> Starts profiling on the device. |
| 9604 | </para></listitem> |
| 9605 | <listitem><para><emphasis>Stop:</emphasis> Stops profiling on the device and |
| 9606 | downloads the data to the local host. |
| 9607 | Stopping the profiler generates the profile and displays it in the viewer. |
| 9608 | </para></listitem> |
| 9609 | <listitem><para><emphasis>Download:</emphasis> Downloads the data from the |
| 9610 | target and generates the profile, which appears in the viewer.</para></listitem> |
| 9611 | <listitem><para><emphasis>Reset:</emphasis> Resets the sample data on the device. |
| 9612 | Resetting the data removes sample information collected from previous |
| 9613 | sampling runs. |
| 9614 | Be sure you reset the data if you do not want to include old sample information. |
| 9615 | </para></listitem> |
| 9616 | <listitem><para><emphasis>Save:</emphasis> Saves the data downloaded from the |
| 9617 | target to another directory for later examination.</para></listitem> |
| 9618 | <listitem><para><emphasis>Open:</emphasis> Loads previously saved data. |
| 9619 | </para></listitem> |
| 9620 | </itemizedlist> |
| 9621 | </para> |
| 9622 | |
| 9623 | <para> |
| 9624 | The client downloads the complete profile archive from |
| 9625 | the target to the host for processing. |
| 9626 | This archive is a directory that contains the sample data, the object files, |
| 9627 | and the debug information for the object files. |
| 9628 | The archive is then converted using the <filename>oparchconv</filename> script, which is |
| 9629 | included in this distribution. |
| 9630 | The script uses <filename>opimport</filename> to convert the archive from |
| 9631 | the target to something that can be processed on the host. |
| 9632 | </para> |
| 9633 | |
| 9634 | <para> |
| 9635 | Downloaded archives reside in the |
| 9636 | <link linkend='build-directory'>Build Directory</link> in |
| 9637 | <filename>tmp</filename> and are cleared up when they are no longer in use. |
| 9638 | </para> |
| 9639 | |
| 9640 | <para> |
| 9641 | If you wish to perform kernel profiling, you need to be sure |
| 9642 | a <filename>vmlinux</filename> file that matches the running kernel is available. |
| 9643 | In the source directory, that file is usually located in |
| 9644 | <filename>/boot/vmlinux-<replaceable>kernelversion</replaceable></filename>, where |
| 9645 | <filename><replaceable>kernelversion</replaceable></filename> is the version of the kernel. |
| 9646 | The OpenEmbedded build system generates separate <filename>vmlinux</filename> |
| 9647 | packages for each kernel it builds. |
| 9648 | Thus, it should just be a question of making sure a matching package is |
| 9649 | installed (e.g. <filename>opkg install kernel-vmlinux</filename>). |
| 9650 | The files are automatically installed into development and profiling images |
| 9651 | alongside OProfile. |
| 9652 | A configuration option exists within the OProfileUI settings page that you can use to |
| 9653 | enter the location of the <filename>vmlinux</filename> file. |
| 9654 | </para> |
| 9655 | |
| 9656 | <para> |
| 9657 | Waiting for debug symbols to transfer from the device can be slow, and it |
| 9658 | is not always necessary to actually have them on the device for OProfile use. |
| 9659 | All that is needed is a copy of the filesystem with the debug symbols present |
| 9660 | on the viewer system. |
| 9661 | The "<link linkend='platdev-gdb-remotedebug-launch-gdb'>Launch GDB on the Host Computer</link>" |
| 9662 | section covers how to create such a directory within |
| 9663 | the source directory and how to use the OProfileUI Settings |
| 9664 | Dialog to specify the location. |
| 9665 | If you specify the directory, it will be used when the file checksums |
| 9666 | match those on the system you are profiling. |
| 9667 | </para> |
| 9668 | </section> |
| 9669 | |
| 9670 | <section id="platdev-oprofile-oprofileui-offline"> |
| 9671 | <title>Offline Mode</title> |
| 9672 | |
| 9673 | <para> |
| 9674 | If network access to the target is unavailable, you can generate |
| 9675 | an archive for processing in <filename>oprofile-viewer</filename> as follows: |
| 9676 | <literallayout class='monospaced'> |
| 9677 | # opcontrol --reset |
| 9678 | # opcontrol --start --separate=lib --no-vmlinux -c 5 |
| 9679 | . |
| 9680 | . |
| 9681 | [do whatever is being profiled] |
| 9682 | . |
| 9683 | . |
| 9684 | # opcontrol --stop |
| 9685 | # oparchive -o my_archive |
| 9686 | </literallayout> |
| 9687 | </para> |
| 9688 | |
| 9689 | <para> |
| 9690 | In the above example, <filename>my_archive</filename> is the name of the |
| 9691 | archive directory where you would like the profile archive to be kept. |
| 9692 | After the directory is created, you can copy it to another host and load it |
| 9693 | using <filename>oprofile-viewer</filename> open functionality. |
| 9694 | If necessary, the archive is converted. |
| 9695 | </para> |
| 9696 | </section> |
| 9697 | </section> |
| 9698 | </section> |
| 9699 | |
| 9700 | <section id='maintaining-open-source-license-compliance-during-your-products-lifecycle'> |
| 9701 | <title>Maintaining Open Source License Compliance During Your Product's Lifecycle</title> |
| 9702 | |
| 9703 | <para> |
| 9704 | One of the concerns for a development organization using open source |
| 9705 | software is how to maintain compliance with various open source |
| 9706 | licensing during the lifecycle of the product. |
| 9707 | While this section does not provide legal advice or |
| 9708 | comprehensively cover all scenarios, it does |
| 9709 | present methods that you can use to |
| 9710 | assist you in meeting the compliance requirements during a software |
| 9711 | release. |
| 9712 | </para> |
| 9713 | |
| 9714 | <para> |
| 9715 | With hundreds of different open source licenses that the Yocto |
| 9716 | Project tracks, it is difficult to know the requirements of each |
| 9717 | and every license. |
| 9718 | However, the requirements of the major FLOSS licenses can begin |
| 9719 | to be covered by |
| 9720 | assuming that three main areas of concern exist: |
| 9721 | <itemizedlist> |
| 9722 | <listitem><para>Source code must be provided.</para></listitem> |
| 9723 | <listitem><para>License text for the software must be |
| 9724 | provided.</para></listitem> |
| 9725 | <listitem><para>Compilation scripts and modifications to the |
| 9726 | source code must be provided. |
| 9727 | </para></listitem> |
| 9728 | </itemizedlist> |
| 9729 | There are other requirements beyond the scope of these |
| 9730 | three and the methods described in this section |
| 9731 | (e.g. the mechanism through which source code is distributed). |
| 9732 | </para> |
| 9733 | |
| 9734 | <para> |
| 9735 | As different organizations have different methods of complying with |
| 9736 | open source licensing, this section is not meant to imply that |
| 9737 | there is only one single way to meet your compliance obligations, |
| 9738 | but rather to describe one method of achieving compliance. |
| 9739 | The remainder of this section describes methods supported to meet the |
| 9740 | previously mentioned three requirements. |
| 9741 | Once you take steps to meet these requirements, |
| 9742 | and prior to releasing images, sources, and the build system, |
| 9743 | you should audit all artifacts to ensure completeness. |
| 9744 | <note> |
| 9745 | The Yocto Project generates a license manifest during |
| 9746 | image creation that is located |
| 9747 | in <filename>${DEPLOY_DIR}/licenses/<replaceable>image_name-datestamp</replaceable></filename> |
| 9748 | to assist with any audits. |
| 9749 | </note> |
| 9750 | </para> |
| 9751 | |
| 9752 | <section id='providing-the-source-code'> |
| 9753 | <title>Providing the Source Code</title> |
| 9754 | |
| 9755 | <para> |
| 9756 | Compliance activities should begin before you generate the |
| 9757 | final image. |
| 9758 | The first thing you should look at is the requirement that |
| 9759 | tops the list for most compliance groups - providing |
| 9760 | the source. |
| 9761 | The Yocto Project has a few ways of meeting this |
| 9762 | requirement. |
| 9763 | </para> |
| 9764 | |
| 9765 | <para> |
| 9766 | One of the easiest ways to meet this requirement is |
| 9767 | to provide the entire |
| 9768 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink> |
| 9769 | used by the build. |
| 9770 | This method, however, has a few issues. |
| 9771 | The most obvious is the size of the directory since it includes |
| 9772 | all sources used in the build and not just the source used in |
| 9773 | the released image. |
| 9774 | It will include toolchain source, and other artifacts, which |
| 9775 | you would not generally release. |
| 9776 | However, the more serious issue for most companies is accidental |
| 9777 | release of proprietary software. |
| 9778 | The Yocto Project provides an |
| 9779 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-archiver'><filename>archiver</filename></ulink> |
| 9780 | class to help avoid some of these concerns. |
| 9781 | </para> |
| 9782 | |
| 9783 | <para> |
| 9784 | Before you employ <filename>DL_DIR</filename> or the |
| 9785 | archiver class, you need to decide how you choose to |
| 9786 | provide source. |
| 9787 | The source archiver class can generate tarballs and SRPMs |
| 9788 | and can create them with various levels of compliance in mind. |
| 9789 | </para> |
| 9790 | |
| 9791 | <para> |
| 9792 | One way of doing this (but certainly not the only way) is to |
| 9793 | release just the source as a tarball. |
| 9794 | You can do this by adding the following to the |
| 9795 | <filename>local.conf</filename> file found in the |
| 9796 | <link linkend='build-directory'>Build Directory</link>: |
| 9797 | <literallayout class='monospaced'> |
| 9798 | INHERIT += "archiver" |
| 9799 | ARCHIVER_MODE[src] = "original" |
| 9800 | </literallayout> |
| 9801 | During the creation of your image, the source from all |
| 9802 | recipes that deploy packages to the image is placed within |
| 9803 | subdirectories of |
| 9804 | <filename>DEPLOY_DIR/sources</filename> based on the |
| 9805 | <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink> |
| 9806 | for each recipe. |
| 9807 | Releasing the entire directory enables you to comply with |
| 9808 | requirements concerning providing the unmodified source. |
| 9809 | It is important to note that the size of the directory can |
| 9810 | get large. |
| 9811 | </para> |
| 9812 | |
| 9813 | <para> |
| 9814 | A way to help mitigate the size issue is to only release |
| 9815 | tarballs for licenses that require the release of |
| 9816 | source. |
| 9817 | Let us assume you are only concerned with GPL code as |
| 9818 | identified with the following: |
| 9819 | <literallayout class='monospaced'> |
| 9820 | $ cd poky/build/tmp/deploy/sources |
| 9821 | $ mkdir ~/gpl_source_release |
| 9822 | $ for dir in */*GPL*; do cp -r $dir ~/gpl_source_release; done |
| 9823 | </literallayout> |
| 9824 | At this point, you could create a tarball from the |
| 9825 | <filename>gpl_source_release</filename> directory and |
| 9826 | provide that to the end user. |
| 9827 | This method would be a step toward achieving compliance |
| 9828 | with section 3a of GPLv2 and with section 6 of GPLv3. |
| 9829 | </para> |
| 9830 | </section> |
| 9831 | |
| 9832 | <section id='providing-license-text'> |
| 9833 | <title>Providing License Text</title> |
| 9834 | |
| 9835 | <para> |
| 9836 | One requirement that is often overlooked is inclusion |
| 9837 | of license text. |
| 9838 | This requirement also needs to be dealt with prior to |
| 9839 | generating the final image. |
| 9840 | Some licenses require the license text to accompany |
| 9841 | the binary. |
| 9842 | You can achieve this by adding the following to your |
| 9843 | <filename>local.conf</filename> file: |
| 9844 | <literallayout class='monospaced'> |
| 9845 | COPY_LIC_MANIFEST = "1" |
| 9846 | COPY_LIC_DIRS = "1" |
| 9847 | </literallayout> |
| 9848 | Adding these statements to the configuration file ensures |
| 9849 | that the licenses collected during package generation |
| 9850 | are included on your image. |
| 9851 | As the source archiver has already archived the original |
| 9852 | unmodified source that contains the license files, |
| 9853 | you would have already met the requirements for inclusion |
| 9854 | of the license information with source as defined by the GPL |
| 9855 | and other open source licenses. |
| 9856 | </para> |
| 9857 | </section> |
| 9858 | |
| 9859 | <section id='providing-compilation-scripts-and-source-code-modifications'> |
| 9860 | <title>Providing Compilation Scripts and Source Code Modifications</title> |
| 9861 | |
| 9862 | <para> |
| 9863 | At this point, we have addressed all we need to address |
| 9864 | prior to generating the image. |
| 9865 | The next two requirements are addressed during the final |
| 9866 | packaging of the release. |
| 9867 | </para> |
| 9868 | |
| 9869 | <para> |
| 9870 | By releasing the version of the OpenEmbedded build system |
| 9871 | and the layers used during the build, you will be providing both |
| 9872 | compilation scripts and the source code modifications in one |
| 9873 | step. |
| 9874 | </para> |
| 9875 | |
| 9876 | <para> |
| 9877 | If the deployment team has a |
| 9878 | <ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP layer</ulink> |
| 9879 | and a distro layer, and those those layers are used to patch, |
| 9880 | compile, package, or modify (in any way) any open source |
| 9881 | software included in your released images, you |
| 9882 | might be required to to release those layers under section 3 of |
| 9883 | GPLv2 or section 1 of GPLv3. |
| 9884 | One way of doing that is with a clean |
| 9885 | checkout of the version of the Yocto Project and layers used |
| 9886 | during your build. |
| 9887 | Here is an example: |
| 9888 | <literallayout class='monospaced'> |
| 9889 | # We built using the &DISTRO_NAME; branch of the poky repo |
| 9890 | $ git clone -b &DISTRO_NAME; git://git.yoctoproject.org/poky |
| 9891 | $ cd poky |
| 9892 | # We built using the release_branch for our layers |
| 9893 | $ git clone -b release_branch git://git.mycompany.com/meta-my-bsp-layer |
| 9894 | $ git clone -b release_branch git://git.mycompany.com/meta-my-software-layer |
| 9895 | # clean up the .git repos |
| 9896 | $ find . -name ".git" -type d -exec rm -rf {} \; |
| 9897 | </literallayout> |
| 9898 | One thing a development organization might want to consider |
| 9899 | for end-user convenience is to modify |
| 9900 | <filename>meta-yocto/conf/bblayers.conf.sample</filename> to |
| 9901 | ensure that when the end user utilizes the released build |
| 9902 | system to build an image, the development organization's |
| 9903 | layers are included in the <filename>bblayers.conf</filename> |
| 9904 | file automatically: |
| 9905 | <literallayout class='monospaced'> |
| 9906 | # LAYER_CONF_VERSION is increased each time build/conf/bblayers.conf |
| 9907 | # changes incompatibly |
| 9908 | LCONF_VERSION = "6" |
| 9909 | |
| 9910 | BBPATH = "${TOPDIR}" |
| 9911 | BBFILES ?= "" |
| 9912 | |
| 9913 | BBLAYERS ?= " \ |
| 9914 | ##OEROOT##/meta \ |
| 9915 | ##OEROOT##/meta-yocto \ |
| 9916 | ##OEROOT##/meta-yocto-bsp \ |
| 9917 | ##OEROOT##/meta-mylayer \ |
| 9918 | " |
| 9919 | </literallayout> |
| 9920 | Creating and providing an archive of the |
| 9921 | <link linkend='metadata'>Metadata</link> layers |
| 9922 | (recipes, configuration files, and so forth) |
| 9923 | enables you to meet your |
| 9924 | requirements to include the scripts to control compilation |
| 9925 | as well as any modifications to the original source. |
| 9926 | </para> |
| 9927 | </section> |
| 9928 | </section> |
| 9929 | |
| 9930 | <section id='using-the-error-reporting-tool'> |
| 9931 | <title>Using the Error Reporting Tool</title> |
| 9932 | |
| 9933 | <para> |
| 9934 | The error reporting tool allows you to |
| 9935 | submit errors encountered during builds to a central database. |
| 9936 | Outside of the build environment, you can use a web interface to |
| 9937 | browse errors, view statistics, and query for errors. |
| 9938 | The tool works using a client-server system where the client |
| 9939 | portion is integrated with the installed Yocto Project |
| 9940 | <link linkend='source-directory'>Source Directory</link> |
| 9941 | (e.g. <filename>poky</filename>). |
| 9942 | The server receives the information collected and saves it in a |
| 9943 | database. |
| 9944 | </para> |
| 9945 | |
| 9946 | <para> |
| 9947 | A live instance of the error reporting server exists at |
| 9948 | <ulink url='http://errors.yoctoproject.org'></ulink>. |
| 9949 | This server exists so that when you want to get help with |
| 9950 | build failures, you can submit all of the information on the |
| 9951 | failure easily and then point to the URL in your bug report |
| 9952 | or send an email to the mailing list. |
| 9953 | <note> |
| 9954 | If you send error reports to this server, the reports become |
| 9955 | publicly visible. |
| 9956 | </note> |
| 9957 | </para> |
| 9958 | |
| 9959 | <section id='enabling-and-using-the-tool'> |
| 9960 | <title>Enabling and Using the Tool</title> |
| 9961 | |
| 9962 | <para> |
| 9963 | By default, the error reporting tool is disabled. |
| 9964 | You can enable it by inheriting the |
| 9965 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-report-error'><filename>report-error</filename></ulink> |
| 9966 | class by adding the following statement to the end of |
| 9967 | your <filename>local.conf</filename> file in your |
| 9968 | <link linkend='build-directory'>Build Directory</link>. |
| 9969 | <literallayout class='monospaced'> |
| 9970 | INHERIT += "report-error" |
| 9971 | </literallayout> |
| 9972 | </para> |
| 9973 | |
| 9974 | <para> |
| 9975 | By default, the error reporting feature stores information in |
| 9976 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LOG_DIR'><filename>LOG_DIR</filename></ulink><filename>}/error-report</filename>. |
| 9977 | However, you can specify a directory to use by adding the following |
| 9978 | to your <filename>local.conf</filename> file: |
| 9979 | <literallayout class='monospaced'> |
| 9980 | ERR_REPORT_DIR = "path" |
| 9981 | </literallayout> |
| 9982 | Enabling error reporting causes the build process to collect |
| 9983 | the errors and store them in a file as previously described. |
| 9984 | When the build system encounters an error, it includes a |
| 9985 | command as part of the console output. |
| 9986 | You can run the command to send the error file to the server. |
| 9987 | For example, the following command sends the errors to an |
| 9988 | upstream server: |
| 9989 | <literallayout class='monospaced'> |
| 9990 | $ send-error-report /home/brandusa/project/poky/build/tmp/log/error-report/error_report_201403141617.txt |
| 9991 | </literallayout> |
| 9992 | In the previous example, the errors are sent to a public |
| 9993 | database available at |
| 9994 | <ulink url='http://errors.yoctoproject.org'></ulink>, which is |
| 9995 | used by the entire community. |
| 9996 | If you specify a particular server, you can send the errors |
| 9997 | to a different database. |
| 9998 | Use the following command for more information on available |
| 9999 | options: |
| 10000 | <literallayout class='monospaced'> |
| 10001 | $ send-error-report --help |
| 10002 | </literallayout> |
| 10003 | </para> |
| 10004 | |
| 10005 | <para> |
| 10006 | When sending the error file, you are prompted to review the |
| 10007 | data being sent as well as to provide a name and optional |
| 10008 | email address. |
| 10009 | Once you satisfy these prompts, the command returns a link |
| 10010 | from the server that corresponds to your entry in the database. |
| 10011 | For example, here is a typical link: |
| 10012 | <literallayout class='monospaced'> |
| 10013 | http://errors.yoctoproject.org/Errors/Details/9522/ |
| 10014 | </literallayout> |
| 10015 | Following the link takes you to a web interface where you can |
| 10016 | browse, query the errors, and view statistics. |
| 10017 | </para> |
| 10018 | </section> |
| 10019 | |
| 10020 | <section id='disabling-the-tool'> |
| 10021 | <title>Disabling the Tool</title> |
| 10022 | |
| 10023 | <para> |
| 10024 | To disable the error reporting feature, simply remove or comment |
| 10025 | out the following statement from the end of your |
| 10026 | <filename>local.conf</filename> file in your |
| 10027 | <link linkend='build-directory'>Build Directory</link>. |
| 10028 | <literallayout class='monospaced'> |
| 10029 | INHERIT += "report-error" |
| 10030 | </literallayout> |
| 10031 | </para> |
| 10032 | </section> |
| 10033 | |
| 10034 | <section id='setting-up-your-own-error-reporting-server'> |
| 10035 | <title>Setting Up Your Own Error Reporting Server</title> |
| 10036 | |
| 10037 | <para> |
| 10038 | If you want to set up your own error reporting server, you |
| 10039 | can obtain the code from the Git repository at |
| 10040 | <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/error-report-web/'></ulink>. |
| 10041 | Instructions on how to set it up are in the README document. |
| 10042 | </para> |
| 10043 | </section> |
| 10044 | </section> |
| 10045 | </chapter> |
| 10046 | |
| 10047 | <!-- |
| 10048 | vim: expandtab tw=80 ts=4 |
| 10049 | --> |