| 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 | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 21 | <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink> into | 
|  | 22 | multiple layers. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 23 | Layers allow you to isolate different types of customizations from | 
|  | 24 | each other. | 
|  | 25 | You might find it tempting to keep everything in one layer when | 
|  | 26 | working on a single project. | 
|  | 27 | However, the more modular your Metadata, the easier | 
|  | 28 | it is to cope with future changes. | 
|  | 29 | </para> | 
|  | 30 |  | 
|  | 31 | <para> | 
|  | 32 | To illustrate how layers are used to keep things modular, consider | 
|  | 33 | machine customizations. | 
|  | 34 | These types of customizations typically reside in a special layer, | 
|  | 35 | rather than a general layer, called a Board Support Package (BSP) | 
|  | 36 | Layer. | 
|  | 37 | Furthermore, the machine customizations should be isolated from | 
|  | 38 | recipes and Metadata that support a new GUI environment, | 
|  | 39 | for example. | 
|  | 40 | This situation gives you a couple of layers: one for the machine | 
|  | 41 | configurations, and one for the GUI environment. | 
|  | 42 | It is important to understand, however, that the BSP layer can | 
|  | 43 | still make machine-specific additions to recipes within the GUI | 
|  | 44 | environment layer without polluting the GUI layer itself | 
|  | 45 | with those machine-specific changes. | 
|  | 46 | You can accomplish this through a recipe that is a BitBake append | 
|  | 47 | (<filename>.bbappend</filename>) file, which is described later | 
|  | 48 | in this section. | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 49 | <note> | 
|  | 50 | For general information on BSP layer structure, see the | 
|  | 51 | <ulink url='&YOCTO_DOCS_BSP_URL;#bsp'>Board Support Packages (BSP) - Developer's Guide</ulink>. | 
|  | 52 | </note> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 53 | </para> | 
|  | 54 |  | 
|  | 55 | <para> | 
|  | 56 | </para> | 
|  | 57 |  | 
|  | 58 | <section id='yocto-project-layers'> | 
|  | 59 | <title>Layers</title> | 
|  | 60 |  | 
|  | 61 | <para> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 62 | The <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 63 | contains both general layers and BSP | 
|  | 64 | layers right out of the box. | 
|  | 65 | You can easily identify layers that ship with a | 
|  | 66 | Yocto Project release in the Source Directory by their | 
|  | 67 | folder names. | 
|  | 68 | Folders that represent layers typically have names that begin with | 
|  | 69 | the string <filename>meta-</filename>. | 
|  | 70 | <note> | 
|  | 71 | It is not a requirement that a layer name begin with the | 
|  | 72 | prefix <filename>meta-</filename>, but it is a commonly | 
|  | 73 | accepted standard in the Yocto Project community. | 
|  | 74 | </note> | 
|  | 75 | For example, when you set up the Source Directory structure, | 
|  | 76 | you will see several layers: | 
|  | 77 | <filename>meta</filename>, | 
|  | 78 | <filename>meta-skeleton</filename>, | 
|  | 79 | <filename>meta-selftest</filename>, | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 80 | <filename>meta-poky</filename>, and | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 81 | <filename>meta-yocto-bsp</filename>. | 
|  | 82 | Each of these folders represents a distinct layer. | 
|  | 83 | </para> | 
|  | 84 |  | 
|  | 85 | <para> | 
|  | 86 | As another example, if you set up a local copy of the | 
|  | 87 | <filename>meta-intel</filename> Git repository | 
|  | 88 | and then explore the folder of that general layer, | 
|  | 89 | you will discover many Intel-specific BSP layers inside. | 
|  | 90 | For more information on BSP layers, see the | 
|  | 91 | "<ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP Layers</ulink>" | 
|  | 92 | section in the Yocto Project Board Support Package (BSP) | 
|  | 93 | Developer's Guide. | 
|  | 94 | </para> | 
|  | 95 | </section> | 
|  | 96 |  | 
|  | 97 | <section id='creating-your-own-layer'> | 
|  | 98 | <title>Creating Your Own Layer</title> | 
|  | 99 |  | 
|  | 100 | <para> | 
|  | 101 | It is very easy to create your own layers to use with the | 
|  | 102 | OpenEmbedded build system. | 
|  | 103 | The Yocto Project ships with scripts that speed up creating | 
|  | 104 | general layers and BSP layers. | 
|  | 105 | This section describes the steps you perform by hand to create | 
|  | 106 | a layer so that you can better understand them. | 
|  | 107 | For information about the layer-creation scripts, see the | 
|  | 108 | "<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>" | 
|  | 109 | section in the Yocto Project Board Support Package (BSP) | 
|  | 110 | Developer's Guide and the | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 111 | "<link linkend='creating-a-general-layer-using-the-bitbake-layers-script'>Creating a General Layer Using the <filename>bitbake-layers</filename> Script</link>" | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 112 | section further down in this manual. | 
|  | 113 | </para> | 
|  | 114 |  | 
|  | 115 | <para> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 116 | Follow these general steps to create your layer without the aid of a script: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 117 | <orderedlist> | 
|  | 118 | <listitem><para><emphasis>Check Existing Layers:</emphasis> | 
|  | 119 | Before creating a new layer, you should be sure someone | 
|  | 120 | has not already created a layer containing the Metadata | 
|  | 121 | you need. | 
|  | 122 | You can see the | 
|  | 123 | <ulink url='http://layers.openembedded.org/layerindex/layers/'><filename>OpenEmbedded Metadata Index</filename></ulink> | 
|  | 124 | for a list of layers from the OpenEmbedded community | 
|  | 125 | that can be used in the Yocto Project. | 
|  | 126 | </para></listitem> | 
|  | 127 | <listitem><para><emphasis>Create a Directory:</emphasis> | 
|  | 128 | Create the directory for your layer. | 
|  | 129 | While not strictly required, prepend the name of the | 
|  | 130 | folder with the string <filename>meta-</filename>. | 
|  | 131 | For example: | 
|  | 132 | <literallayout class='monospaced'> | 
|  | 133 | meta-mylayer | 
|  | 134 | meta-GUI_xyz | 
|  | 135 | meta-mymachine | 
|  | 136 | </literallayout> | 
|  | 137 | </para></listitem> | 
|  | 138 | <listitem><para><emphasis>Create a Layer Configuration | 
|  | 139 | File:</emphasis> | 
|  | 140 | Inside your new layer folder, you need to create a | 
|  | 141 | <filename>conf/layer.conf</filename> file. | 
|  | 142 | It is easiest to take an existing layer configuration | 
|  | 143 | file and copy that to your layer's | 
|  | 144 | <filename>conf</filename> directory and then modify the | 
|  | 145 | file as needed.</para> | 
|  | 146 | <para>The | 
|  | 147 | <filename>meta-yocto-bsp/conf/layer.conf</filename> file | 
|  | 148 | demonstrates the required syntax: | 
|  | 149 | <literallayout class='monospaced'> | 
|  | 150 | # We have a conf and classes directory, add to BBPATH | 
|  | 151 | BBPATH .= ":${LAYERDIR}" | 
|  | 152 |  | 
|  | 153 | # We have recipes-* directories, add to BBFILES | 
|  | 154 | BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \ | 
|  | 155 | ${LAYERDIR}/recipes-*/*/*.bbappend" | 
|  | 156 |  | 
|  | 157 | BBFILE_COLLECTIONS += "yoctobsp" | 
|  | 158 | BBFILE_PATTERN_yoctobsp = "^${LAYERDIR}/" | 
|  | 159 | BBFILE_PRIORITY_yoctobsp = "5" | 
|  | 160 | LAYERVERSION_yoctobsp = "3" | 
|  | 161 | </literallayout></para> | 
|  | 162 | <para>Here is an explanation of the example: | 
|  | 163 | <itemizedlist> | 
|  | 164 | <listitem><para>The configuration and | 
|  | 165 | classes directory is appended to | 
|  | 166 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink>. | 
|  | 167 | <note> | 
|  | 168 | All non-distro layers, which include all BSP | 
|  | 169 | layers, are expected to append the layer | 
|  | 170 | directory to the | 
|  | 171 | <filename>BBPATH</filename>. | 
|  | 172 | On the other hand, distro layers, such as | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 173 | <filename>meta-poky</filename>, can choose | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 174 | to enforce their own precedence over | 
|  | 175 | <filename>BBPATH</filename>. | 
|  | 176 | For an example of that syntax, see the | 
|  | 177 | <filename>layer.conf</filename> file for | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 178 | the <filename>meta-poky</filename> layer. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 179 | </note></para></listitem> | 
|  | 180 | <listitem><para>The recipes for the layers are | 
|  | 181 | appended to | 
|  | 182 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILES'>BBFILES</ulink></filename>. | 
|  | 183 | </para></listitem> | 
|  | 184 | <listitem><para>The | 
|  | 185 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_COLLECTIONS'>BBFILE_COLLECTIONS</ulink></filename> | 
|  | 186 | variable is then appended with the layer name. | 
|  | 187 | </para></listitem> | 
|  | 188 | <listitem><para>The | 
|  | 189 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PATTERN'>BBFILE_PATTERN</ulink></filename> | 
|  | 190 | variable is set to a regular expression and is | 
|  | 191 | used to match files from | 
|  | 192 | <filename>BBFILES</filename> into a particular | 
|  | 193 | layer. | 
|  | 194 | In this case, | 
|  | 195 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LAYERDIR'>LAYERDIR</ulink></filename> | 
|  | 196 | is used to make <filename>BBFILE_PATTERN</filename> match within the | 
|  | 197 | layer's path.</para></listitem> | 
|  | 198 | <listitem><para>The | 
|  | 199 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PRIORITY'>BBFILE_PRIORITY</ulink></filename> | 
|  | 200 | variable then assigns a priority to the layer. | 
|  | 201 | Applying priorities is useful in situations | 
|  | 202 | where the same recipe might appear in multiple | 
|  | 203 | layers and allows you to choose the layer | 
|  | 204 | that takes precedence.</para></listitem> | 
|  | 205 | <listitem><para>The | 
|  | 206 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LAYERVERSION'>LAYERVERSION</ulink></filename> | 
|  | 207 | variable optionally specifies the version of a | 
|  | 208 | layer as a single number.</para></listitem> | 
|  | 209 | </itemizedlist></para> | 
|  | 210 | <para>Note the use of the | 
|  | 211 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LAYERDIR'>LAYERDIR</ulink></filename> | 
|  | 212 | variable, which expands to the directory of the current | 
|  | 213 | layer.</para> | 
|  | 214 | <para>Through the use of the <filename>BBPATH</filename> | 
|  | 215 | variable, BitBake locates class files | 
|  | 216 | (<filename>.bbclass</filename>), | 
|  | 217 | configuration files, and files that are included | 
|  | 218 | with <filename>include</filename> and | 
|  | 219 | <filename>require</filename> statements. | 
|  | 220 | For these cases, BitBake uses the first file that | 
|  | 221 | matches the name found in <filename>BBPATH</filename>. | 
|  | 222 | This is similar to the way the <filename>PATH</filename> | 
|  | 223 | variable is used for binaries. | 
|  | 224 | It is recommended, therefore, that you use unique | 
|  | 225 | class and configuration | 
|  | 226 | filenames in your custom layer.</para></listitem> | 
|  | 227 | <listitem><para><emphasis>Add Content:</emphasis> Depending | 
|  | 228 | on the type of layer, add the content. | 
|  | 229 | If the layer adds support for a machine, add the machine | 
|  | 230 | configuration in a <filename>conf/machine/</filename> | 
|  | 231 | file within the layer. | 
|  | 232 | If the layer adds distro policy, add the distro | 
|  | 233 | configuration in a <filename>conf/distro/</filename> | 
|  | 234 | file within the layer. | 
|  | 235 | If the layer introduces new recipes, put the recipes | 
|  | 236 | you need in <filename>recipes-*</filename> | 
|  | 237 | subdirectories within the layer. | 
|  | 238 | <note>In order to be compliant with the Yocto Project, | 
|  | 239 | a layer must contain a | 
|  | 240 | <ulink url='&YOCTO_DOCS_BSP_URL;#bsp-filelayout-readme'>README file.</ulink> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 241 | </note> | 
|  | 242 | </para></listitem> | 
|  | 243 | <listitem><para> | 
|  | 244 | <emphasis>Optionally Test for Compatibility:</emphasis> | 
|  | 245 | If you want permission to use the Yocto Project | 
|  | 246 | Compatibility logo with your layer or application that | 
|  | 247 | uses your layer, perform the steps to apply for | 
|  | 248 | compatibility. | 
|  | 249 | See the | 
|  | 250 | "<link linkend='making-sure-your-layer-is-compatible-with-yocto-project'>Making Sure Your Layer is Compatible With Yocto Project</link>" | 
|  | 251 | section for more information. | 
|  | 252 | </para></listitem> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 253 | </orderedlist> | 
|  | 254 | </para> | 
|  | 255 | </section> | 
|  | 256 |  | 
|  | 257 | <section id='best-practices-to-follow-when-creating-layers'> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 258 | <title>Following Best Practices When Creating Layers</title> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 259 |  | 
|  | 260 | <para> | 
|  | 261 | To create layers that are easier to maintain and that will | 
|  | 262 | not impact builds for other machines, you should consider the | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 263 | information in the following list: | 
|  | 264 | <itemizedlist> | 
|  | 265 | <listitem><para> | 
|  | 266 | <emphasis>Avoid "Overlaying" Entire Recipes from Other Layers in Your Configuration:</emphasis> | 
|  | 267 | In other words, do not copy an entire recipe into your | 
|  | 268 | layer and then modify it. | 
|  | 269 | Rather, use an append file | 
|  | 270 | (<filename>.bbappend</filename>) to override only those | 
|  | 271 | parts of the original recipe you need to modify. | 
|  | 272 | </para></listitem> | 
|  | 273 | <listitem><para> | 
|  | 274 | <emphasis>Avoid Duplicating Include Files:</emphasis> | 
|  | 275 | Use append files (<filename>.bbappend</filename>) | 
|  | 276 | for each recipe that uses an include file. | 
|  | 277 | Or, if you are introducing a new recipe that requires | 
|  | 278 | the included file, use the path relative to the | 
|  | 279 | original layer directory to refer to the file. | 
|  | 280 | For example, use | 
|  | 281 | <filename>require recipes-core/</filename><replaceable>package</replaceable><filename>/</filename><replaceable>file</replaceable><filename>.inc</filename> | 
|  | 282 | instead of | 
|  | 283 | <filename>require </filename><replaceable>file</replaceable><filename>.inc</filename>. | 
|  | 284 | If you're finding you have to overlay the include file, | 
|  | 285 | it could indicate a deficiency in the include file in | 
|  | 286 | the layer to which it originally belongs. | 
|  | 287 | If this is the case, you should try to address that | 
|  | 288 | deficiency instead of overlaying the include file. | 
|  | 289 | For example, you could address this by getting the | 
|  | 290 | maintainer of the include file to add a variable or | 
|  | 291 | variables to make it easy to override the parts needing | 
|  | 292 | to be overridden. | 
|  | 293 | </para></listitem> | 
|  | 294 | <listitem><para> | 
|  | 295 | <emphasis>Structure Your Layers:</emphasis> | 
|  | 296 | Proper use of overrides within append files and | 
|  | 297 | placement of machine-specific files within your layer | 
|  | 298 | can ensure that a build is not using the wrong Metadata | 
|  | 299 | and negatively impacting a build for a different | 
|  | 300 | machine. | 
|  | 301 | Following are some examples: | 
|  | 302 | <itemizedlist> | 
|  | 303 | <listitem><para> | 
|  | 304 | <emphasis>Modify Variables to Support a | 
|  | 305 | Different Machine:</emphasis> | 
|  | 306 | Suppose you have a layer named | 
|  | 307 | <filename>meta-one</filename> that adds support | 
|  | 308 | for building machine "one". | 
|  | 309 | To do so, you use an append file named | 
|  | 310 | <filename>base-files.bbappend</filename> and | 
|  | 311 | create a dependency on "foo" by altering the | 
|  | 312 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink> | 
|  | 313 | variable: | 
|  | 314 | <literallayout class='monospaced'> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 315 | DEPENDS = "foo" | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 316 | </literallayout> | 
|  | 317 | The dependency is created during any build that | 
|  | 318 | includes the layer | 
|  | 319 | <filename>meta-one</filename>. | 
|  | 320 | However, you might not want this dependency | 
|  | 321 | for all machines. | 
|  | 322 | For example, suppose you are building for | 
|  | 323 | machine "two" but your | 
|  | 324 | <filename>bblayers.conf</filename> file has the | 
|  | 325 | <filename>meta-one</filename> layer included. | 
|  | 326 | During the build, the | 
|  | 327 | <filename>base-files</filename> for machine | 
|  | 328 | "two" will also have the dependency on | 
|  | 329 | <filename>foo</filename>.</para> | 
|  | 330 | <para>To make sure your changes apply only when | 
|  | 331 | building machine "one", use a machine override | 
|  | 332 | with the <filename>DEPENDS</filename> statement: | 
|  | 333 | <literallayout class='monospaced'> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 334 | DEPENDS_one = "foo" | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 335 | </literallayout> | 
|  | 336 | You should follow the same strategy when using | 
|  | 337 | <filename>_append</filename> and | 
|  | 338 | <filename>_prepend</filename> operations: | 
|  | 339 | <literallayout class='monospaced'> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 340 | DEPENDS_append_one = " foo" | 
|  | 341 | DEPENDS_prepend_one = "foo " | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 342 | </literallayout> | 
|  | 343 | As an actual example, here's a line from the recipe | 
|  | 344 | for gnutls, which adds dependencies on | 
|  | 345 | "argp-standalone" when building with the musl C | 
|  | 346 | library: | 
|  | 347 | <literallayout class='monospaced'> | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 348 | DEPENDS_append_libc-musl = " argp-standalone" | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 349 | </literallayout> | 
|  | 350 | <note> | 
|  | 351 | Avoiding "+=" and "=+" and using | 
|  | 352 | machine-specific | 
|  | 353 | <filename>_append</filename> | 
|  | 354 | and <filename>_prepend</filename> operations | 
|  | 355 | is recommended as well. | 
|  | 356 | </note> | 
|  | 357 | </para></listitem> | 
|  | 358 | <listitem><para> | 
|  | 359 | <emphasis>Place Machine-Specific Files in | 
|  | 360 | Machine-Specific Locations:</emphasis> | 
|  | 361 | When you have a base recipe, such as | 
|  | 362 | <filename>base-files.bb</filename>, that | 
|  | 363 | contains a | 
|  | 364 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> | 
|  | 365 | statement to a file, you can use an append file | 
|  | 366 | to cause the build to use your own version of | 
|  | 367 | the file. | 
|  | 368 | For example, an append file in your layer at | 
|  | 369 | <filename>meta-one/recipes-core/base-files/base-files.bbappend</filename> | 
|  | 370 | could extend | 
|  | 371 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink> | 
|  | 372 | using | 
|  | 373 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink> | 
|  | 374 | as follows: | 
|  | 375 | <literallayout class='monospaced'> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 376 | FILESEXTRAPATHS_prepend := "${THISDIR}/${BPN}:" | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 377 | </literallayout> | 
|  | 378 | The build for machine "one" will pick up your | 
|  | 379 | machine-specific file as long as you have the | 
|  | 380 | file in | 
|  | 381 | <filename>meta-one/recipes-core/base-files/base-files/</filename>. | 
|  | 382 | However, if you are building for a different | 
|  | 383 | machine and the | 
|  | 384 | <filename>bblayers.conf</filename> file includes | 
|  | 385 | the <filename>meta-one</filename> layer and | 
|  | 386 | the location of your machine-specific file is | 
|  | 387 | the first location where that file is found | 
|  | 388 | according to <filename>FILESPATH</filename>, | 
|  | 389 | builds for all machines will also use that | 
|  | 390 | machine-specific file.</para> | 
|  | 391 | <para>You can make sure that a machine-specific | 
|  | 392 | file is used for a particular machine by putting | 
|  | 393 | the file in a subdirectory specific to the | 
|  | 394 | machine. | 
|  | 395 | For example, rather than placing the file in | 
|  | 396 | <filename>meta-one/recipes-core/base-files/base-files/</filename> | 
|  | 397 | as shown above, put it in | 
|  | 398 | <filename>meta-one/recipes-core/base-files/base-files/one/</filename>. | 
|  | 399 | Not only does this make sure the file is used | 
|  | 400 | only when building for machine "one", but the | 
|  | 401 | build process locates the file more quickly.</para> | 
|  | 402 | <para>In summary, you need to place all files | 
|  | 403 | referenced from <filename>SRC_URI</filename> | 
|  | 404 | in a machine-specific subdirectory within the | 
|  | 405 | layer in order to restrict those files to | 
|  | 406 | machine-specific builds. | 
|  | 407 | </para></listitem> | 
|  | 408 | </itemizedlist> | 
|  | 409 | </para></listitem> | 
|  | 410 | <listitem><para> | 
|  | 411 | <emphasis>Perform Steps to Apply for Yocto Project Compatibility:</emphasis> | 
|  | 412 | If you want permission to use the | 
|  | 413 | Yocto Project Compatibility logo with your layer | 
|  | 414 | or application that uses your layer, perform the | 
|  | 415 | steps to apply for compatibility. | 
|  | 416 | See the | 
|  | 417 | "<link linkend='making-sure-your-layer-is-compatible-with-yocto-project'>Making Sure Your Layer is Compatible With Yocto Project</link>" | 
|  | 418 | section for more information. | 
|  | 419 | </para></listitem> | 
|  | 420 | <listitem><para> | 
|  | 421 | <emphasis>Follow the Layer Naming Convention:</emphasis> | 
|  | 422 | Store custom layers in a Git repository that use the | 
|  | 423 | <filename>meta-<replaceable>layer_name</replaceable></filename> | 
|  | 424 | format. | 
|  | 425 | </para></listitem> | 
|  | 426 | <listitem><para> | 
|  | 427 | <emphasis>Group Your Layers Locally:</emphasis> | 
|  | 428 | Clone your repository alongside other cloned | 
|  | 429 | <filename>meta</filename> directories from the | 
|  | 430 | <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>. | 
|  | 431 | </para></listitem> | 
|  | 432 | </itemizedlist> | 
|  | 433 | </para> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 434 | </section> | 
|  | 435 |  | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 436 | <section id='making-sure-your-layer-is-compatible-with-yocto-project'> | 
|  | 437 | <title>Making Sure Your Layer is Compatible With Yocto Project</title> | 
|  | 438 |  | 
|  | 439 | <para> | 
|  | 440 | When you create a layer used with the Yocto Project, it is | 
|  | 441 | advantageous to make sure that the layer interacts well with | 
|  | 442 | existing Yocto Project layers (i.e. the layer is compatible | 
|  | 443 | with the Yocto Project). | 
|  | 444 | Ensuring compatibility makes the layer easy to be consumed | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 445 | by others in the Yocto Project community and could allow you | 
|  | 446 | permission to use the Yocto Project Compatible Logo. | 
|  | 447 | <note> | 
|  | 448 | Only Yocto Project member organizations are permitted to | 
|  | 449 | use the Yocto Project Compatible Logo. | 
|  | 450 | The logo is not available for general use. | 
|  | 451 | For information on how to become a Yocto Project member | 
|  | 452 | organization, see the | 
|  | 453 | <ulink url='&YOCTO_HOME_URL;'>Yocto Project Website</ulink>. | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 454 | </note> | 
|  | 455 | </para> | 
|  | 456 |  | 
|  | 457 | <para> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 458 | The Yocto Project Compatibility Program consists of a layer | 
|  | 459 | application process that requests permission to use the Yocto | 
|  | 460 | Project Compatibility Logo for your layer and application. | 
|  | 461 | The process consists of two parts: | 
|  | 462 | <orderedlist> | 
|  | 463 | <listitem><para> | 
|  | 464 | Successfully passing a script | 
|  | 465 | (<filename>yocto-check-layer</filename>) that | 
|  | 466 | when run against your layer, tests it against | 
|  | 467 | constraints based on experiences of how layers have | 
|  | 468 | worked in the real world and where pitfalls have been | 
|  | 469 | found. | 
|  | 470 | Getting a "PASS" result from the script is required for | 
|  | 471 | successful compatibility registration. | 
|  | 472 | </para></listitem> | 
|  | 473 | <listitem><para> | 
|  | 474 | Completion of an application acceptance form, which | 
|  | 475 | you can find at | 
|  | 476 | <ulink url='https://www.yoctoproject.org/webform/yocto-project-compatible-registration'></ulink>. | 
|  | 477 | </para></listitem> | 
|  | 478 | </orderedlist> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 479 | </para> | 
|  | 480 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 481 | <para> | 
|  | 482 | To be granted permission to use the logo, you need to satisfy | 
|  | 483 | the following: | 
|  | 484 | <itemizedlist> | 
|  | 485 | <listitem><para> | 
|  | 486 | Be able to check the box indicating that you | 
|  | 487 | got a "PASS" when running the script against your | 
|  | 488 | layer. | 
|  | 489 | </para></listitem> | 
|  | 490 | <listitem><para> | 
|  | 491 | Answer "Yes" to the questions on the form or have an | 
|  | 492 | acceptable explanation for any questions answered "No". | 
|  | 493 | </para></listitem> | 
|  | 494 | <listitem><para> | 
|  | 495 | You need to be a Yocto Project Member Organization. | 
|  | 496 | </para></listitem> | 
|  | 497 | </itemizedlist> | 
|  | 498 | </para> | 
|  | 499 |  | 
|  | 500 | <para> | 
|  | 501 | The remainder of this section presents information on the | 
|  | 502 | registration form and on the | 
|  | 503 | <filename>yocto-check-layer</filename> script. | 
|  | 504 | </para> | 
|  | 505 |  | 
|  | 506 | <section id='yocto-project-compatible-program-application'> | 
|  | 507 | <title>Yocto Project Compatible Program Application</title> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 508 |  | 
|  | 509 | <para> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 510 | Use the form to apply for your layer's approval. | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 511 | Upon successful application, you can use the Yocto | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 512 | Project Compatibility Logo with your layer and the | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 513 | application that uses your layer. | 
|  | 514 | </para> | 
|  | 515 |  | 
|  | 516 | <para> | 
|  | 517 | To access the form, use this link: | 
|  | 518 | <ulink url='https://www.yoctoproject.org/webform/yocto-project-compatible-registration'></ulink>. | 
|  | 519 | Follow the instructions on the form to complete your | 
|  | 520 | application. | 
|  | 521 | </para> | 
|  | 522 |  | 
|  | 523 | <para> | 
|  | 524 | The application consists of the following sections: | 
|  | 525 | <itemizedlist> | 
|  | 526 | <listitem><para> | 
|  | 527 | <emphasis>Contact Information:</emphasis> | 
|  | 528 | Provide your contact information as the fields | 
|  | 529 | require. | 
|  | 530 | Along with your information, provide the | 
|  | 531 | released versions of the Yocto Project for which | 
|  | 532 | your layer is compatible. | 
|  | 533 | </para></listitem> | 
|  | 534 | <listitem><para> | 
|  | 535 | <emphasis>Acceptance Criteria:</emphasis> | 
|  | 536 | Provide "Yes" or "No" answers for each of the | 
|  | 537 | items in the checklist. | 
|  | 538 | Space exists at the bottom of the form for any | 
|  | 539 | explanations for items for which you answered "No". | 
|  | 540 | </para></listitem> | 
|  | 541 | <listitem><para> | 
|  | 542 | <emphasis>Recommendations:</emphasis> | 
|  | 543 | Provide answers for the questions regarding Linux | 
|  | 544 | kernel use and build success. | 
|  | 545 | </para></listitem> | 
|  | 546 | </itemizedlist> | 
|  | 547 | </para> | 
|  | 548 | </section> | 
|  | 549 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 550 | <section id='yocto-check-layer-script'> | 
|  | 551 | <title><filename>yocto-check-layer</filename> Script</title> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 552 |  | 
|  | 553 | <para> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 554 | The <filename>yocto-check-layer</filename> script | 
|  | 555 | provides you a way to assess how compatible your layer is | 
|  | 556 | with the Yocto Project. | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 557 | You should run this script prior to using the form to | 
|  | 558 | apply for compatibility as described in the previous | 
|  | 559 | section. | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 560 | You need to achieve a "PASS" result in order to have | 
|  | 561 | your application form successfully processed. | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 562 | </para> | 
|  | 563 |  | 
|  | 564 | <para> | 
|  | 565 | The script divides tests into three areas: COMMON, BSD, | 
|  | 566 | and DISTRO. | 
|  | 567 | For example, given a distribution layer (DISTRO), the | 
|  | 568 | layer must pass both the COMMON and DISTRO related tests. | 
|  | 569 | Furthermore, if your layer is a BSP layer, the layer must | 
|  | 570 | pass the COMMON and BSP set of tests. | 
|  | 571 | </para> | 
|  | 572 |  | 
|  | 573 | <para> | 
|  | 574 | To execute the script, enter the following commands from | 
|  | 575 | your build directory: | 
|  | 576 | <literallayout class='monospaced'> | 
|  | 577 | $ source oe-init-build-env | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 578 | $ yocto-check-layer <replaceable>your_layer_directory</replaceable> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 579 | </literallayout> | 
|  | 580 | Be sure to provide the actual directory for your layer | 
|  | 581 | as part of the command. | 
|  | 582 | </para> | 
|  | 583 |  | 
|  | 584 | <para> | 
|  | 585 | Entering the command causes the script to determine the | 
|  | 586 | type of layer and then to execute a set of specific | 
|  | 587 | tests against the layer. | 
|  | 588 | The following list overviews the test: | 
|  | 589 | <itemizedlist> | 
|  | 590 | <listitem><para> | 
|  | 591 | <filename>common.test_readme</filename>: | 
|  | 592 | Tests if a <filename>README</filename> file | 
|  | 593 | exists in the layer and the file is not empty. | 
|  | 594 | </para></listitem> | 
|  | 595 | <listitem><para> | 
|  | 596 | <filename>common.test_parse</filename>: | 
|  | 597 | Tests to make sure that BitBake can parse the | 
|  | 598 | files without error (i.e. | 
|  | 599 | <filename>bitbake -p</filename>). | 
|  | 600 | </para></listitem> | 
|  | 601 | <listitem><para> | 
|  | 602 | <filename>common.test_show_environment</filename>: | 
|  | 603 | Tests that the global or per-recipe environment | 
|  | 604 | is in order without errors (i.e. | 
|  | 605 | <filename>bitbake -e</filename>). | 
|  | 606 | </para></listitem> | 
|  | 607 | <listitem><para> | 
|  | 608 | <filename>common.test_signatures</filename>: | 
|  | 609 | Tests to be sure that BSP and DISTRO layers do not | 
|  | 610 | come with recipes that change signatures. | 
|  | 611 | </para></listitem> | 
|  | 612 | <listitem><para> | 
|  | 613 | <filename>bsp.test_bsp_defines_machines</filename>: | 
|  | 614 | Tests if a BSP layer has machine configurations. | 
|  | 615 | </para></listitem> | 
|  | 616 | <listitem><para> | 
|  | 617 | <filename>bsp.test_bsp_no_set_machine</filename>: | 
|  | 618 | Tests to ensure a BSP layer does not set the | 
|  | 619 | machine when the layer is added. | 
|  | 620 | </para></listitem> | 
|  | 621 | <listitem><para> | 
|  | 622 | <filename>distro.test_distro_defines_distros</filename>: | 
|  | 623 | Tests if a DISTRO layer has distro configurations. | 
|  | 624 | </para></listitem> | 
|  | 625 | <listitem><para> | 
|  | 626 | <filename>distro.test_distro_no_set_distro</filename>: | 
|  | 627 | Tests to ensure a DISTRO layer does not set the | 
|  | 628 | distribution when the layer is added. | 
|  | 629 | </para></listitem> | 
|  | 630 | </itemizedlist> | 
|  | 631 | </para> | 
|  | 632 | </section> | 
|  | 633 | </section> | 
|  | 634 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 635 | <section id='enabling-your-layer'> | 
|  | 636 | <title>Enabling Your Layer</title> | 
|  | 637 |  | 
|  | 638 | <para> | 
|  | 639 | Before the OpenEmbedded build system can use your new layer, | 
|  | 640 | you need to enable it. | 
|  | 641 | To enable your layer, simply add your layer's path to the | 
|  | 642 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'>BBLAYERS</ulink></filename> | 
|  | 643 | variable in your <filename>conf/bblayers.conf</filename> file, | 
|  | 644 | which is found in the | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 645 | <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 646 | The following example shows how to enable a layer named | 
|  | 647 | <filename>meta-mylayer</filename>: | 
|  | 648 | <literallayout class='monospaced'> | 
|  | 649 | LCONF_VERSION = "6" | 
|  | 650 |  | 
|  | 651 | BBPATH = "${TOPDIR}" | 
|  | 652 | BBFILES ?= "" | 
|  | 653 |  | 
|  | 654 | BBLAYERS ?= " \ | 
|  | 655 | $HOME/poky/meta \ | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 656 | $HOME/poky/meta-poky \ | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 657 | $HOME/poky/meta-yocto-bsp \ | 
|  | 658 | $HOME/poky/meta-mylayer \ | 
|  | 659 | " | 
|  | 660 | </literallayout> | 
|  | 661 | </para> | 
|  | 662 |  | 
|  | 663 | <para> | 
|  | 664 | BitBake parses each <filename>conf/layer.conf</filename> file | 
|  | 665 | as specified in the <filename>BBLAYERS</filename> variable | 
|  | 666 | within the <filename>conf/bblayers.conf</filename> file. | 
|  | 667 | During the processing of each | 
|  | 668 | <filename>conf/layer.conf</filename> file, BitBake adds the | 
|  | 669 | recipes, classes and configurations contained within the | 
|  | 670 | particular layer to the source directory. | 
|  | 671 | </para> | 
|  | 672 | </section> | 
|  | 673 |  | 
|  | 674 | <section id='using-bbappend-files'> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 675 | <title>Using .bbappend Files in Your Layer</title> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 676 |  | 
|  | 677 | <para> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 678 | A recipe that appends Metadata to another recipe is called a | 
|  | 679 | BitBake append file. | 
|  | 680 | A BitBake append file uses the <filename>.bbappend</filename> | 
|  | 681 | file type suffix, while the corresponding recipe to which | 
|  | 682 | Metadata is being appended uses the <filename>.bb</filename> | 
|  | 683 | file type suffix. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 684 | </para> | 
|  | 685 |  | 
|  | 686 | <para> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 687 | You can use a <filename>.bbappend</filename> file in your | 
|  | 688 | layer to make additions or changes to the content of another | 
|  | 689 | layer's recipe without having to copy the other layer's | 
|  | 690 | recipe into your layer. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 691 | Your <filename>.bbappend</filename> file resides in your layer, | 
|  | 692 | while the main <filename>.bb</filename> recipe file to | 
|  | 693 | which you are appending Metadata resides in a different layer. | 
|  | 694 | </para> | 
|  | 695 |  | 
|  | 696 | <para> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 697 | Being able to append information to an existing recipe not only | 
|  | 698 | avoids duplication, but also automatically applies recipe | 
|  | 699 | changes from a different layer into your layer. | 
|  | 700 | If you were copying recipes, you would have to manually merge | 
|  | 701 | changes as they occur. | 
|  | 702 | </para> | 
|  | 703 |  | 
|  | 704 | <para> | 
|  | 705 | When you create an append file, you must use the same root | 
|  | 706 | name as the corresponding recipe file. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 707 | For example, the append file | 
|  | 708 | <filename>someapp_&DISTRO;.bbappend</filename> must apply to | 
|  | 709 | <filename>someapp_&DISTRO;.bb</filename>. | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 710 | This means the original recipe and append file names are | 
|  | 711 | version number-specific. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 712 | If the corresponding recipe is renamed to update to a newer | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 713 | version, you must also rename and possibly update | 
|  | 714 | the corresponding <filename>.bbappend</filename> as well. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 715 | During the build process, BitBake displays an error on starting | 
|  | 716 | if it detects a <filename>.bbappend</filename> file that does | 
|  | 717 | not have a corresponding recipe with a matching name. | 
|  | 718 | See the | 
|  | 719 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_DANGLINGAPPENDS_WARNONLY'><filename>BB_DANGLINGAPPENDS_WARNONLY</filename></ulink> | 
|  | 720 | variable for information on how to handle this error. | 
|  | 721 | </para> | 
|  | 722 |  | 
|  | 723 | <para> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 724 | As an example, consider the main formfactor recipe and a | 
|  | 725 | corresponding formfactor append file both from the | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 726 | <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 727 | Here is the main formfactor recipe, which is named | 
|  | 728 | <filename>formfactor_0.0.bb</filename> and located in the | 
|  | 729 | "meta" layer at | 
|  | 730 | <filename>meta/recipes-bsp/formfactor</filename>: | 
|  | 731 | <literallayout class='monospaced'> | 
|  | 732 | SUMMARY = "Device formfactor information" | 
|  | 733 | SECTION = "base" | 
|  | 734 | LICENSE = "MIT" | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 735 | LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 736 | PR = "r45" | 
|  | 737 |  | 
|  | 738 | SRC_URI = "file://config file://machconfig" | 
|  | 739 | S = "${WORKDIR}" | 
|  | 740 |  | 
|  | 741 | PACKAGE_ARCH = "${MACHINE_ARCH}" | 
|  | 742 | INHIBIT_DEFAULT_DEPS = "1" | 
|  | 743 |  | 
|  | 744 | do_install() { | 
|  | 745 | # Install file only if it has contents | 
|  | 746 | install -d ${D}${sysconfdir}/formfactor/ | 
|  | 747 | install -m 0644 ${S}/config ${D}${sysconfdir}/formfactor/ | 
|  | 748 | if [ -s "${S}/machconfig" ]; then | 
|  | 749 | install -m 0644 ${S}/machconfig ${D}${sysconfdir}/formfactor/ | 
|  | 750 | fi | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 751 | }                </literallayout> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 752 | In the main recipe, note the | 
|  | 753 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> | 
|  | 754 | variable, which tells the OpenEmbedded build system where to | 
|  | 755 | find files during the build. | 
|  | 756 | </para> | 
|  | 757 |  | 
|  | 758 | <para> | 
|  | 759 | Following is the append file, which is named | 
|  | 760 | <filename>formfactor_0.0.bbappend</filename> and is from the | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 761 | Raspberry Pi BSP Layer named | 
|  | 762 | <filename>meta-raspberrypi</filename>. | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 763 | The file is in the layer at | 
|  | 764 | <filename>recipes-bsp/formfactor</filename>: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 765 | <literallayout class='monospaced'> | 
|  | 766 | FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" | 
|  | 767 | </literallayout> | 
|  | 768 | </para> | 
|  | 769 |  | 
|  | 770 | <para> | 
|  | 771 | By default, the build system uses the | 
|  | 772 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink> | 
|  | 773 | variable to locate files. | 
|  | 774 | This append file extends the locations by setting the | 
|  | 775 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink> | 
|  | 776 | variable. | 
|  | 777 | Setting this variable in the <filename>.bbappend</filename> | 
|  | 778 | file is the most reliable and recommended method for adding | 
|  | 779 | directories to the search path used by the build system | 
|  | 780 | to find files. | 
|  | 781 | </para> | 
|  | 782 |  | 
|  | 783 | <para> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 784 | The statement in this example extends the directories to | 
|  | 785 | include | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 786 | <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>, | 
|  | 787 | which resolves to a directory named | 
|  | 788 | <filename>formfactor</filename> in the same directory | 
|  | 789 | in which the append file resides (i.e. | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 790 | <filename>meta-raspberrypi/recipes-bsp/formfactor</filename>. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 791 | This implies that you must have the supporting directory | 
|  | 792 | structure set up that will contain any files or patches you | 
|  | 793 | will be including from the layer. | 
|  | 794 | </para> | 
|  | 795 |  | 
|  | 796 | <para> | 
|  | 797 | Using the immediate expansion assignment operator | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 798 | <filename>:=</filename> is important because of the reference | 
|  | 799 | to <filename>THISDIR</filename>. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 800 | The trailing colon character is important as it ensures that | 
|  | 801 | items in the list remain colon-separated. | 
|  | 802 | <note> | 
|  | 803 | <para> | 
|  | 804 | BitBake automatically defines the | 
|  | 805 | <filename>THISDIR</filename> variable. | 
|  | 806 | You should never set this variable yourself. | 
|  | 807 | Using "_prepend" as part of the | 
|  | 808 | <filename>FILESEXTRAPATHS</filename> ensures your path | 
|  | 809 | will be searched prior to other paths in the final | 
|  | 810 | list. | 
|  | 811 | </para> | 
|  | 812 |  | 
|  | 813 | <para> | 
|  | 814 | Also, not all append files add extra files. | 
|  | 815 | Many append files simply exist to add build options | 
|  | 816 | (e.g. <filename>systemd</filename>). | 
|  | 817 | For these cases, your append file would not even | 
|  | 818 | use the <filename>FILESEXTRAPATHS</filename> statement. | 
|  | 819 | </para> | 
|  | 820 | </note> | 
|  | 821 | </para> | 
|  | 822 | </section> | 
|  | 823 |  | 
|  | 824 | <section id='prioritizing-your-layer'> | 
|  | 825 | <title>Prioritizing Your Layer</title> | 
|  | 826 |  | 
|  | 827 | <para> | 
|  | 828 | Each layer is assigned a priority value. | 
|  | 829 | Priority values control which layer takes precedence if there | 
|  | 830 | are recipe files with the same name in multiple layers. | 
|  | 831 | For these cases, the recipe file from the layer with a higher | 
|  | 832 | priority number takes precedence. | 
|  | 833 | Priority values also affect the order in which multiple | 
|  | 834 | <filename>.bbappend</filename> files for the same recipe are | 
|  | 835 | applied. | 
|  | 836 | You can either specify the priority manually, or allow the | 
|  | 837 | build system to calculate it based on the layer's dependencies. | 
|  | 838 | </para> | 
|  | 839 |  | 
|  | 840 | <para> | 
|  | 841 | To specify the layer's priority manually, use the | 
|  | 842 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PRIORITY'><filename>BBFILE_PRIORITY</filename></ulink> | 
|  | 843 | variable. | 
|  | 844 | For example: | 
|  | 845 | <literallayout class='monospaced'> | 
|  | 846 | BBFILE_PRIORITY_mylayer = "1" | 
|  | 847 | </literallayout> | 
|  | 848 | </para> | 
|  | 849 |  | 
|  | 850 | <note> | 
|  | 851 | <para>It is possible for a recipe with a lower version number | 
|  | 852 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink> | 
|  | 853 | in a layer that has a higher priority to take precedence.</para> | 
|  | 854 | <para>Also, the layer priority does not currently affect the | 
|  | 855 | precedence order of <filename>.conf</filename> | 
|  | 856 | or <filename>.bbclass</filename> files. | 
|  | 857 | Future versions of BitBake might address this.</para> | 
|  | 858 | </note> | 
|  | 859 | </section> | 
|  | 860 |  | 
|  | 861 | <section id='managing-layers'> | 
|  | 862 | <title>Managing Layers</title> | 
|  | 863 |  | 
|  | 864 | <para> | 
|  | 865 | You can use the BitBake layer management tool to provide a view | 
|  | 866 | into the structure of recipes across a multi-layer project. | 
|  | 867 | Being able to generate output that reports on configured layers | 
|  | 868 | with their paths and priorities and on | 
|  | 869 | <filename>.bbappend</filename> files and their applicable | 
|  | 870 | recipes can help to reveal potential problems. | 
|  | 871 | </para> | 
|  | 872 |  | 
|  | 873 | <para> | 
|  | 874 | Use the following form when running the layer management tool. | 
|  | 875 | <literallayout class='monospaced'> | 
|  | 876 | $ bitbake-layers <replaceable>command</replaceable> [<replaceable>arguments</replaceable>] | 
|  | 877 | </literallayout> | 
|  | 878 | The following list describes the available commands: | 
|  | 879 | <itemizedlist> | 
|  | 880 | <listitem><para><filename><emphasis>help:</emphasis></filename> | 
|  | 881 | Displays general help or help on a specified command. | 
|  | 882 | </para></listitem> | 
|  | 883 | <listitem><para><filename><emphasis>show-layers:</emphasis></filename> | 
|  | 884 | Shows the current configured layers. | 
|  | 885 | </para></listitem> | 
|  | 886 | <listitem><para><filename><emphasis>show-recipes:</emphasis></filename> | 
|  | 887 | Lists available recipes and the layers that provide them. | 
|  | 888 | </para></listitem> | 
|  | 889 | <listitem><para><filename><emphasis>show-overlayed:</emphasis></filename> | 
|  | 890 | Lists overlayed recipes. | 
|  | 891 | A recipe is overlayed when a recipe with the same name | 
|  | 892 | exists in another layer that has a higher layer | 
|  | 893 | priority. | 
|  | 894 | </para></listitem> | 
|  | 895 | <listitem><para><filename><emphasis>show-appends:</emphasis></filename> | 
|  | 896 | Lists <filename>.bbappend</filename> files and the | 
|  | 897 | recipe files to which they apply. | 
|  | 898 | </para></listitem> | 
|  | 899 | <listitem><para><filename><emphasis>show-cross-depends:</emphasis></filename> | 
|  | 900 | Lists dependency relationships between recipes that | 
|  | 901 | cross layer boundaries. | 
|  | 902 | </para></listitem> | 
|  | 903 | <listitem><para><filename><emphasis>add-layer:</emphasis></filename> | 
|  | 904 | Adds a layer to <filename>bblayers.conf</filename>. | 
|  | 905 | </para></listitem> | 
|  | 906 | <listitem><para><filename><emphasis>remove-layer:</emphasis></filename> | 
|  | 907 | Removes a layer from <filename>bblayers.conf</filename> | 
|  | 908 | </para></listitem> | 
|  | 909 | <listitem><para><filename><emphasis>flatten:</emphasis></filename> | 
|  | 910 | Flattens the layer configuration into a separate output | 
|  | 911 | directory. | 
|  | 912 | Flattening your layer configuration builds a "flattened" | 
|  | 913 | directory that contains the contents of all layers, | 
|  | 914 | with any overlayed recipes removed and any | 
|  | 915 | <filename>.bbappend</filename> files appended to the | 
|  | 916 | corresponding recipes. | 
|  | 917 | You might have to perform some manual cleanup of the | 
|  | 918 | flattened layer as follows: | 
|  | 919 | <itemizedlist> | 
|  | 920 | <listitem><para>Non-recipe files (such as patches) | 
|  | 921 | are overwritten. | 
|  | 922 | The flatten command shows a warning for these | 
|  | 923 | files. | 
|  | 924 | </para></listitem> | 
|  | 925 | <listitem><para>Anything beyond the normal layer | 
|  | 926 | setup has been added to the | 
|  | 927 | <filename>layer.conf</filename> file. | 
|  | 928 | Only the lowest priority layer's | 
|  | 929 | <filename>layer.conf</filename> is used. | 
|  | 930 | </para></listitem> | 
|  | 931 | <listitem><para>Overridden and appended items from | 
|  | 932 | <filename>.bbappend</filename> files need to be | 
|  | 933 | cleaned up. | 
|  | 934 | The contents of each | 
|  | 935 | <filename>.bbappend</filename> end up in the | 
|  | 936 | flattened recipe. | 
|  | 937 | However, if there are appended or changed | 
|  | 938 | variable values, you need to tidy these up | 
|  | 939 | yourself. | 
|  | 940 | Consider the following example. | 
|  | 941 | Here, the <filename>bitbake-layers</filename> | 
|  | 942 | command adds the line | 
|  | 943 | <filename>#### bbappended ...</filename> so that | 
|  | 944 | you know where the following lines originate: | 
|  | 945 | <literallayout class='monospaced'> | 
|  | 946 | ... | 
|  | 947 | DESCRIPTION = "A useful utility" | 
|  | 948 | ... | 
|  | 949 | EXTRA_OECONF = "--enable-something" | 
|  | 950 | ... | 
|  | 951 |  | 
|  | 952 | #### bbappended from meta-anotherlayer #### | 
|  | 953 |  | 
|  | 954 | DESCRIPTION = "Customized utility" | 
|  | 955 | EXTRA_OECONF += "--enable-somethingelse" | 
|  | 956 | </literallayout> | 
|  | 957 | Ideally, you would tidy up these utilities as | 
|  | 958 | follows: | 
|  | 959 | <literallayout class='monospaced'> | 
|  | 960 | ... | 
|  | 961 | DESCRIPTION = "Customized utility" | 
|  | 962 | ... | 
|  | 963 | EXTRA_OECONF = "--enable-something --enable-somethingelse" | 
|  | 964 | ... | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 965 | </literallayout> | 
|  | 966 | </para></listitem> | 
|  | 967 | </itemizedlist> | 
|  | 968 | </para></listitem> | 
|  | 969 | <listitem><para> | 
|  | 970 | <emphasis><filename>layerindex-fetch</filename>:</emphasis> | 
|  | 971 | Fetches a layer from a layer index, along with its | 
|  | 972 | dependent layers, and adds the layers to the | 
|  | 973 | <filename>conf/bblayers.conf</filename> file. | 
|  | 974 | </para></listitem> | 
|  | 975 | <listitem><para> | 
|  | 976 | <emphasis><filename>layerindex-show-depends</filename>:</emphasis> | 
|  | 977 | Finds layer dependencies from the layer index. | 
|  | 978 | </para></listitem> | 
|  | 979 | <listitem><para> | 
|  | 980 | <emphasis><filename>create-layer</filename>:</emphasis> | 
|  | 981 | Creates a basic layer. | 
|  | 982 | </para></listitem> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 983 | </itemizedlist> | 
|  | 984 | </para> | 
|  | 985 | </section> | 
|  | 986 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 987 | <section id='creating-a-general-layer-using-the-bitbake-layers-script'> | 
|  | 988 | <title>Creating a General Layer Using the <filename>bitbake-layers</filename> Script</title> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 989 |  | 
|  | 990 | <para> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 991 | The <filename>bitbake-layers</filename> script with the | 
|  | 992 | <filename>create-layer</filename> subcommand simplifies | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 993 | creating a new general layer. | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 994 | <note><title>Notes</title> | 
|  | 995 | <itemizedlist> | 
|  | 996 | <listitem><para> | 
|  | 997 | For information on BSP layers, see the | 
|  | 998 | "<ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP Layers</ulink>" | 
|  | 999 | section in the Yocto Project Board Specific (BSP) | 
|  | 1000 | Developer's Guide. | 
|  | 1001 | </para></listitem> | 
|  | 1002 | <listitem><para> | 
|  | 1003 | The <filename>bitbake-layers</filename> script | 
|  | 1004 | replaces the <filename>yocto-layer</filename> | 
|  | 1005 | script, which is deprecated in the Yocto Project | 
|  | 1006 | 2.4 release. | 
|  | 1007 | The <filename>yocto-layer</filename> script | 
|  | 1008 | continues to function as part of the 2.4 release | 
|  | 1009 | but will be removed post 2.4. | 
|  | 1010 | </para></listitem> | 
|  | 1011 | </itemizedlist> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1012 | </note> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1013 | The default mode of the script's operation with this | 
|  | 1014 | subcommand is to create a layer with the following: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1015 | <itemizedlist> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1016 | <listitem><para>A layer priority of 6. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1017 | </para></listitem> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1018 | <listitem><para>A <filename>conf</filename> | 
|  | 1019 | subdirectory that contains a | 
|  | 1020 | <filename>layer.conf</filename> file. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1021 | </para></listitem> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1022 | <listitem><para> | 
|  | 1023 | A <filename>recipes-example</filename> subdirectory | 
|  | 1024 | that contains a further subdirectory named | 
|  | 1025 | <filename>example</filename>, which contains | 
|  | 1026 | an <filename>example.bb</filename> recipe file. | 
|  | 1027 | </para></listitem> | 
|  | 1028 | <listitem><para>A <filename >COPYING.MIT</filename>, | 
|  | 1029 | which is the license statement for the layer. | 
|  | 1030 | The script assumes you want to use the MIT license, | 
|  | 1031 | which is typical for most layers, for the contents of | 
|  | 1032 | the layer itself. | 
|  | 1033 | </para></listitem> | 
|  | 1034 | <listitem><para> | 
|  | 1035 | A <filename>README</filename> file, which is a file | 
|  | 1036 | describing the contents of your new layer. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1037 | </para></listitem> | 
|  | 1038 | </itemizedlist> | 
|  | 1039 | </para> | 
|  | 1040 |  | 
|  | 1041 | <para> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1042 | In its simplest form, you can use the following command form | 
|  | 1043 | to create a layer. | 
|  | 1044 | The command creates a layer whose name corresponds to | 
|  | 1045 | <replaceable>your_layer_name</replaceable> in the current | 
|  | 1046 | directory: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1047 | <literallayout class='monospaced'> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1048 | $ bitbake-layers create-layer <replaceable>your_layer_name</replaceable> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1049 | </literallayout> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1050 | </para> | 
|  | 1051 |  | 
|  | 1052 | <para> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1053 | If you want to set the priority of the layer to other than the | 
|  | 1054 | default value of "6", you can either use the | 
|  | 1055 | <filename>‐‐priority</filename> option or you can | 
|  | 1056 | edit the | 
|  | 1057 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILE_PRIORITY'><filename>BBFILE_PRIORITY</filename></ulink> | 
|  | 1058 | value in the <filename>conf/layer.conf</filename> after the | 
|  | 1059 | script creates it. | 
|  | 1060 | Furthermore, if you want to give the example recipe file | 
|  | 1061 | some name other than the default, you can | 
|  | 1062 | use the | 
|  | 1063 | <filename>‐‐example-recipe-name</filename> option. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1064 | </para> | 
|  | 1065 |  | 
|  | 1066 | <para> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1067 | The easiest way to see how the | 
|  | 1068 | <filename>bitbake-layers create-layer</filename> command | 
|  | 1069 | works is to experiment with the script. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1070 | You can also read the usage information by entering the | 
|  | 1071 | following: | 
|  | 1072 | <literallayout class='monospaced'> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1073 | $ bitbake-layers create-layer --help | 
|  | 1074 | NOTE: Starting bitbake server... | 
|  | 1075 | usage: bitbake-layers create-layer [-h] [--priority PRIORITY] | 
|  | 1076 | [--example-recipe-name EXAMPLERECIPE] | 
|  | 1077 | layerdir | 
|  | 1078 |  | 
|  | 1079 | Create a basic layer | 
|  | 1080 |  | 
|  | 1081 | positional arguments: | 
|  | 1082 | layerdir              Layer directory to create | 
|  | 1083 |  | 
|  | 1084 | optional arguments: | 
|  | 1085 | -h, --help            show this help message and exit | 
|  | 1086 | --priority PRIORITY, -p PRIORITY | 
|  | 1087 | Layer directory to create | 
|  | 1088 | --example-recipe-name EXAMPLERECIPE, -e EXAMPLERECIPE | 
|  | 1089 | Filename of the example recipe | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1090 | </literallayout> | 
|  | 1091 | </para> | 
|  | 1092 |  | 
|  | 1093 | <para> | 
|  | 1094 | Once you create your general layer, you must add it to your | 
|  | 1095 | <filename>bblayers.conf</filename> file. | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1096 | You can add your layer by using the | 
|  | 1097 | <filename>bitbake-layers add-layer</filename> command: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1098 | <literallayout class='monospaced'> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1099 | $ bitbake-layers add-layer <replaceable>your_layer_name</replaceable> | 
|  | 1100 | </literallayout> | 
|  | 1101 | Here is an example where a layer named | 
|  | 1102 | <filename>meta-scottrif</filename> is added and then the | 
|  | 1103 | layers are shown using the | 
|  | 1104 | <filename>bitbake-layers show-layers</filename> command: | 
|  | 1105 | <literallayout class='monospaced'> | 
|  | 1106 | $ bitbake-layers add-layer meta-scottrif | 
|  | 1107 | NOTE: Starting bitbake server... | 
|  | 1108 | Loading cache: 100% |############################################| Time: 0:00:00 | 
|  | 1109 | Loaded 1275 entries from dependency cache. | 
|  | 1110 | Parsing recipes: 100% |##########################################| Time: 0:00:00 | 
|  | 1111 | Parsing of 819 .bb files complete (817 cached, 2 parsed). 1276 targets, 44 skipped, 0 masked, 0 errors. | 
|  | 1112 | $ bitbake-layers show-layers | 
|  | 1113 | NOTE: Starting bitbake server... | 
|  | 1114 | layer                 path                                      priority | 
|  | 1115 | ========================================================================== | 
|  | 1116 | meta                  /home/scottrif/poky/meta                  5 | 
|  | 1117 | meta-poky             /home/scottrif/poky/meta-poky             5 | 
|  | 1118 | meta-yocto-bsp        /home/scottrif/poky/meta-yocto-bsp        5 | 
|  | 1119 | meta-mylayer          /home/scottrif/meta-mylayer               6 | 
|  | 1120 | workspace             /home/scottrif/poky/build/workspace       99 | 
|  | 1121 | meta-scottrif         /home/scottrif/poky/build/meta-scottrif   6 | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1122 | </literallayout> | 
|  | 1123 | Adding the layer to this file enables the build system to | 
|  | 1124 | locate the layer during the build. | 
|  | 1125 | </para> | 
|  | 1126 | </section> | 
|  | 1127 | </section> | 
|  | 1128 |  | 
|  | 1129 | <section id='usingpoky-extend-customimage'> | 
|  | 1130 | <title>Customizing Images</title> | 
|  | 1131 |  | 
|  | 1132 | <para> | 
|  | 1133 | You can customize images to satisfy particular requirements. | 
|  | 1134 | This section describes several methods and provides guidelines for each. | 
|  | 1135 | </para> | 
|  | 1136 |  | 
|  | 1137 | <section id='usingpoky-extend-customimage-localconf'> | 
|  | 1138 | <title>Customizing Images Using <filename>local.conf</filename></title> | 
|  | 1139 |  | 
|  | 1140 | <para> | 
|  | 1141 | Probably the easiest way to customize an image is to add a | 
|  | 1142 | package by way of the <filename>local.conf</filename> | 
|  | 1143 | configuration file. | 
|  | 1144 | Because it is limited to local use, this method generally only | 
|  | 1145 | allows you to add packages and is not as flexible as creating | 
|  | 1146 | your own customized image. | 
|  | 1147 | When you add packages using local variables this way, you need | 
|  | 1148 | to realize that these variable changes are in effect for every | 
|  | 1149 | build and consequently affect all images, which might not | 
|  | 1150 | be what you require. | 
|  | 1151 | </para> | 
|  | 1152 |  | 
|  | 1153 | <para> | 
|  | 1154 | To add a package to your image using the local configuration | 
|  | 1155 | file, use the | 
|  | 1156 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename> | 
|  | 1157 | variable with the <filename>_append</filename> operator: | 
|  | 1158 | <literallayout class='monospaced'> | 
|  | 1159 | IMAGE_INSTALL_append = " strace" | 
|  | 1160 | </literallayout> | 
|  | 1161 | Use of the syntax is important - specifically, the space between | 
|  | 1162 | the quote and the package name, which is | 
|  | 1163 | <filename>strace</filename> in this example. | 
|  | 1164 | This space is required since the <filename>_append</filename> | 
|  | 1165 | operator does not add the space. | 
|  | 1166 | </para> | 
|  | 1167 |  | 
|  | 1168 | <para> | 
|  | 1169 | Furthermore, you must use <filename>_append</filename> instead | 
|  | 1170 | of the <filename>+=</filename> operator if you want to avoid | 
|  | 1171 | ordering issues. | 
|  | 1172 | The reason for this is because doing so unconditionally appends | 
|  | 1173 | to the variable and avoids ordering problems due to the | 
|  | 1174 | variable being set in image recipes and | 
|  | 1175 | <filename>.bbclass</filename> files with operators like | 
|  | 1176 | <filename>?=</filename>. | 
|  | 1177 | Using <filename>_append</filename> ensures the operation takes | 
|  | 1178 | affect. | 
|  | 1179 | </para> | 
|  | 1180 |  | 
|  | 1181 | <para> | 
|  | 1182 | As shown in its simplest use, | 
|  | 1183 | <filename>IMAGE_INSTALL_append</filename> affects all images. | 
|  | 1184 | It is possible to extend the syntax so that the variable | 
|  | 1185 | applies to a specific image only. | 
|  | 1186 | Here is an example: | 
|  | 1187 | <literallayout class='monospaced'> | 
|  | 1188 | IMAGE_INSTALL_append_pn-core-image-minimal = " strace" | 
|  | 1189 | </literallayout> | 
|  | 1190 | This example adds <filename>strace</filename> to the | 
|  | 1191 | <filename>core-image-minimal</filename> image only. | 
|  | 1192 | </para> | 
|  | 1193 |  | 
|  | 1194 | <para> | 
|  | 1195 | You can add packages using a similar approach through the | 
|  | 1196 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-CORE_IMAGE_EXTRA_INSTALL'>CORE_IMAGE_EXTRA_INSTALL</ulink></filename> | 
|  | 1197 | variable. | 
|  | 1198 | If you use this variable, only | 
|  | 1199 | <filename>core-image-*</filename> images are affected. | 
|  | 1200 | </para> | 
|  | 1201 | </section> | 
|  | 1202 |  | 
|  | 1203 | <section id='usingpoky-extend-customimage-imagefeatures'> | 
|  | 1204 | <title>Customizing Images Using Custom <filename>IMAGE_FEATURES</filename> and | 
|  | 1205 | <filename>EXTRA_IMAGE_FEATURES</filename></title> | 
|  | 1206 |  | 
|  | 1207 | <para> | 
|  | 1208 | Another method for customizing your image is to enable or | 
|  | 1209 | disable high-level image features by using the | 
|  | 1210 | <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink> | 
|  | 1211 | and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink> | 
|  | 1212 | variables. | 
|  | 1213 | Although the functions for both variables are nearly equivalent, | 
|  | 1214 | best practices dictate using <filename>IMAGE_FEATURES</filename> | 
|  | 1215 | from within a recipe and using | 
|  | 1216 | <filename>EXTRA_IMAGE_FEATURES</filename> from within | 
|  | 1217 | your <filename>local.conf</filename> file, which is found in the | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1218 | <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1219 | </para> | 
|  | 1220 |  | 
|  | 1221 | <para> | 
|  | 1222 | To understand how these features work, the best reference is | 
|  | 1223 | <filename>meta/classes/core-image.bbclass</filename>. | 
|  | 1224 | This class lists out the available | 
|  | 1225 | <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink> | 
|  | 1226 | of which most map to package groups while some, such as | 
|  | 1227 | <filename>debug-tweaks</filename> and | 
|  | 1228 | <filename>read-only-rootfs</filename>, resolve as general | 
|  | 1229 | configuration settings. | 
|  | 1230 | </para> | 
|  | 1231 |  | 
|  | 1232 | <para> | 
|  | 1233 | In summary, the file looks at the contents of the | 
|  | 1234 | <filename>IMAGE_FEATURES</filename> variable and then maps | 
|  | 1235 | or configures the feature accordingly. | 
|  | 1236 | Based on this information, the build system automatically | 
|  | 1237 | adds the appropriate packages or configurations to the | 
|  | 1238 | <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink> | 
|  | 1239 | variable. | 
|  | 1240 | Effectively, you are enabling extra features by extending the | 
|  | 1241 | class or creating a custom class for use with specialized image | 
|  | 1242 | <filename>.bb</filename> files. | 
|  | 1243 | </para> | 
|  | 1244 |  | 
|  | 1245 | <para> | 
|  | 1246 | Use the <filename>EXTRA_IMAGE_FEATURES</filename> variable | 
|  | 1247 | from within your local configuration file. | 
|  | 1248 | Using a separate area from which to enable features with | 
|  | 1249 | this variable helps you avoid overwriting the features in the | 
|  | 1250 | image recipe that are enabled with | 
|  | 1251 | <filename>IMAGE_FEATURES</filename>. | 
|  | 1252 | The value of <filename>EXTRA_IMAGE_FEATURES</filename> is added | 
|  | 1253 | to <filename>IMAGE_FEATURES</filename> within | 
|  | 1254 | <filename>meta/conf/bitbake.conf</filename>. | 
|  | 1255 | </para> | 
|  | 1256 |  | 
|  | 1257 | <para> | 
|  | 1258 | To illustrate how you can use these variables to modify your | 
|  | 1259 | image, consider an example that selects the SSH server. | 
|  | 1260 | The Yocto Project ships with two SSH servers you can use | 
|  | 1261 | with your images: Dropbear and OpenSSH. | 
|  | 1262 | Dropbear is a minimal SSH server appropriate for | 
|  | 1263 | resource-constrained environments, while OpenSSH is a | 
|  | 1264 | well-known standard SSH server implementation. | 
|  | 1265 | By default, the <filename>core-image-sato</filename> image | 
|  | 1266 | is configured to use Dropbear. | 
|  | 1267 | The <filename>core-image-full-cmdline</filename> and | 
|  | 1268 | <filename>core-image-lsb</filename> images both | 
|  | 1269 | include OpenSSH. | 
|  | 1270 | The <filename>core-image-minimal</filename> image does not | 
|  | 1271 | contain an SSH server. | 
|  | 1272 | </para> | 
|  | 1273 |  | 
|  | 1274 | <para> | 
|  | 1275 | You can customize your image and change these defaults. | 
|  | 1276 | Edit the <filename>IMAGE_FEATURES</filename> variable | 
|  | 1277 | in your recipe or use the | 
|  | 1278 | <filename>EXTRA_IMAGE_FEATURES</filename> in your | 
|  | 1279 | <filename>local.conf</filename> file so that it configures the | 
|  | 1280 | image you are working with to include | 
|  | 1281 | <filename>ssh-server-dropbear</filename> or | 
|  | 1282 | <filename>ssh-server-openssh</filename>. | 
|  | 1283 | </para> | 
|  | 1284 |  | 
|  | 1285 | <note> | 
|  | 1286 | See the | 
|  | 1287 | "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>" | 
|  | 1288 | section in the Yocto Project Reference Manual for a complete | 
|  | 1289 | list of image features that ship with the Yocto Project. | 
|  | 1290 | </note> | 
|  | 1291 | </section> | 
|  | 1292 |  | 
|  | 1293 | <section id='usingpoky-extend-customimage-custombb'> | 
|  | 1294 | <title>Customizing Images Using Custom .bb Files</title> | 
|  | 1295 |  | 
|  | 1296 | <para> | 
|  | 1297 | You can also customize an image by creating a custom recipe | 
|  | 1298 | that defines additional software as part of the image. | 
|  | 1299 | The following example shows the form for the two lines you need: | 
|  | 1300 | <literallayout class='monospaced'> | 
|  | 1301 | IMAGE_INSTALL = "packagegroup-core-x11-base package1 package2" | 
|  | 1302 |  | 
|  | 1303 | inherit core-image | 
|  | 1304 | </literallayout> | 
|  | 1305 | </para> | 
|  | 1306 |  | 
|  | 1307 | <para> | 
|  | 1308 | Defining the software using a custom recipe gives you total | 
|  | 1309 | control over the contents of the image. | 
|  | 1310 | It is important to use the correct names of packages in the | 
|  | 1311 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename> | 
|  | 1312 | variable. | 
|  | 1313 | You must use the OpenEmbedded notation and not the Debian notation for the names | 
|  | 1314 | (e.g. <filename>glibc-dev</filename> instead of <filename>libc6-dev</filename>). | 
|  | 1315 | </para> | 
|  | 1316 |  | 
|  | 1317 | <para> | 
|  | 1318 | The other method for creating a custom image is to base it on an existing image. | 
|  | 1319 | For example, if you want to create an image based on <filename>core-image-sato</filename> | 
|  | 1320 | but add the additional package <filename>strace</filename> to the image, | 
|  | 1321 | copy the <filename>meta/recipes-sato/images/core-image-sato.bb</filename> to a | 
|  | 1322 | new <filename>.bb</filename> and add the following line to the end of the copy: | 
|  | 1323 | <literallayout class='monospaced'> | 
|  | 1324 | IMAGE_INSTALL += "strace" | 
|  | 1325 | </literallayout> | 
|  | 1326 | </para> | 
|  | 1327 | </section> | 
|  | 1328 |  | 
|  | 1329 | <section id='usingpoky-extend-customimage-customtasks'> | 
|  | 1330 | <title>Customizing Images Using Custom Package Groups</title> | 
|  | 1331 |  | 
|  | 1332 | <para> | 
|  | 1333 | For complex custom images, the best approach for customizing | 
|  | 1334 | an image is to create a custom package group recipe that is | 
|  | 1335 | used to build the image or images. | 
|  | 1336 | A good example of a package group recipe is | 
|  | 1337 | <filename>meta/recipes-core/packagegroups/packagegroup-base.bb</filename>. | 
|  | 1338 | </para> | 
|  | 1339 |  | 
|  | 1340 | <para> | 
|  | 1341 | If you examine that recipe, you see that the | 
|  | 1342 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'>PACKAGES</ulink></filename> | 
|  | 1343 | variable lists the package group packages to produce. | 
|  | 1344 | The <filename>inherit packagegroup</filename> statement | 
|  | 1345 | sets appropriate default values and automatically adds | 
|  | 1346 | <filename>-dev</filename>, <filename>-dbg</filename>, and | 
|  | 1347 | <filename>-ptest</filename> complementary packages for each | 
|  | 1348 | package specified in the <filename>PACKAGES</filename> | 
|  | 1349 | statement. | 
|  | 1350 | <note> | 
|  | 1351 | The <filename>inherit packages</filename> should be | 
|  | 1352 | located near the top of the recipe, certainly before | 
|  | 1353 | the <filename>PACKAGES</filename> statement. | 
|  | 1354 | </note> | 
|  | 1355 | </para> | 
|  | 1356 |  | 
|  | 1357 | <para> | 
|  | 1358 | For each package you specify in <filename>PACKAGES</filename>, | 
|  | 1359 | you can use | 
|  | 1360 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'>RDEPENDS</ulink></filename> | 
|  | 1361 | and | 
|  | 1362 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'>RRECOMMENDS</ulink></filename> | 
|  | 1363 | entries to provide a list of packages the parent task package | 
|  | 1364 | should contain. | 
|  | 1365 | You can see examples of these further down in the | 
|  | 1366 | <filename>packagegroup-base.bb</filename> recipe. | 
|  | 1367 | </para> | 
|  | 1368 |  | 
|  | 1369 | <para> | 
|  | 1370 | Here is a short, fabricated example showing the same basic | 
|  | 1371 | pieces: | 
|  | 1372 | <literallayout class='monospaced'> | 
|  | 1373 | DESCRIPTION = "My Custom Package Groups" | 
|  | 1374 |  | 
|  | 1375 | inherit packagegroup | 
|  | 1376 |  | 
|  | 1377 | PACKAGES = "\ | 
|  | 1378 | packagegroup-custom-apps \ | 
|  | 1379 | packagegroup-custom-tools \ | 
|  | 1380 | " | 
|  | 1381 |  | 
|  | 1382 | RDEPENDS_packagegroup-custom-apps = "\ | 
|  | 1383 | dropbear \ | 
|  | 1384 | portmap \ | 
|  | 1385 | psplash" | 
|  | 1386 |  | 
|  | 1387 | RDEPENDS_packagegroup-custom-tools = "\ | 
|  | 1388 | oprofile \ | 
|  | 1389 | oprofileui-server \ | 
|  | 1390 | lttng-tools" | 
|  | 1391 |  | 
|  | 1392 | RRECOMMENDS_packagegroup-custom-tools = "\ | 
|  | 1393 | kernel-module-oprofile" | 
|  | 1394 | </literallayout> | 
|  | 1395 | </para> | 
|  | 1396 |  | 
|  | 1397 | <para> | 
|  | 1398 | In the previous example, two package group packages are created with their dependencies and their | 
|  | 1399 | recommended package dependencies listed: <filename>packagegroup-custom-apps</filename>, and | 
|  | 1400 | <filename>packagegroup-custom-tools</filename>. | 
|  | 1401 | To build an image using these package group packages, you need to add | 
|  | 1402 | <filename>packagegroup-custom-apps</filename> and/or | 
|  | 1403 | <filename>packagegroup-custom-tools</filename> to | 
|  | 1404 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'>IMAGE_INSTALL</ulink></filename>. | 
|  | 1405 | For other forms of image dependencies see the other areas of this section. | 
|  | 1406 | </para> | 
|  | 1407 | </section> | 
|  | 1408 |  | 
|  | 1409 | <section id='usingpoky-extend-customimage-image-name'> | 
|  | 1410 | <title>Customizing an Image Hostname</title> | 
|  | 1411 |  | 
|  | 1412 | <para> | 
|  | 1413 | By default, the configured hostname (i.e. | 
|  | 1414 | <filename>/etc/hostname</filename>) in an image is the | 
|  | 1415 | same as the machine name. | 
|  | 1416 | For example, if | 
|  | 1417 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink> | 
|  | 1418 | equals "qemux86", the configured hostname written to | 
|  | 1419 | <filename>/etc/hostname</filename> is "qemux86". | 
|  | 1420 | </para> | 
|  | 1421 |  | 
|  | 1422 | <para> | 
|  | 1423 | You can customize this name by altering the value of the | 
|  | 1424 | "hostname" variable in the | 
|  | 1425 | <filename>base-files</filename> recipe using either | 
|  | 1426 | an append file or a configuration file. | 
|  | 1427 | Use the following in an append file: | 
|  | 1428 | <literallayout class='monospaced'> | 
|  | 1429 | hostname="myhostname" | 
|  | 1430 | </literallayout> | 
|  | 1431 | Use the following in a configuration file: | 
|  | 1432 | <literallayout class='monospaced'> | 
|  | 1433 | hostname_pn-base-files = "myhostname" | 
|  | 1434 | </literallayout> | 
|  | 1435 | </para> | 
|  | 1436 |  | 
|  | 1437 | <para> | 
|  | 1438 | Changing the default value of the variable "hostname" can be | 
|  | 1439 | useful in certain situations. | 
|  | 1440 | For example, suppose you need to do extensive testing on an | 
|  | 1441 | image and you would like to easily identify the image | 
|  | 1442 | under test from existing images with typical default | 
|  | 1443 | hostnames. | 
|  | 1444 | In this situation, you could change the default hostname to | 
|  | 1445 | "testme", which results in all the images using the name | 
|  | 1446 | "testme". | 
|  | 1447 | Once testing is complete and you do not need to rebuild the | 
|  | 1448 | image for test any longer, you can easily reset the default | 
|  | 1449 | hostname. | 
|  | 1450 | </para> | 
|  | 1451 |  | 
|  | 1452 | <para> | 
|  | 1453 | Another point of interest is that if you unset the variable, | 
|  | 1454 | the image will have no default hostname in the filesystem. | 
|  | 1455 | Here is an example that unsets the variable in a | 
|  | 1456 | configuration file: | 
|  | 1457 | <literallayout class='monospaced'> | 
|  | 1458 | hostname_pn-base-files = "" | 
|  | 1459 | </literallayout> | 
|  | 1460 | Having no default hostname in the filesystem is suitable for | 
|  | 1461 | environments that use dynamic hostnames such as virtual | 
|  | 1462 | machines. | 
|  | 1463 | </para> | 
|  | 1464 | </section> | 
|  | 1465 | </section> | 
|  | 1466 |  | 
|  | 1467 | <section id='new-recipe-writing-a-new-recipe'> | 
|  | 1468 | <title>Writing a New Recipe</title> | 
|  | 1469 |  | 
|  | 1470 | <para> | 
|  | 1471 | Recipes (<filename>.bb</filename> files) are fundamental components | 
|  | 1472 | in the Yocto Project environment. | 
|  | 1473 | Each software component built by the OpenEmbedded build system | 
|  | 1474 | requires a recipe to define the component. | 
|  | 1475 | This section describes how to create, write, and test a new | 
|  | 1476 | recipe. | 
|  | 1477 | <note> | 
|  | 1478 | For information on variables that are useful for recipes and | 
|  | 1479 | for information about recipe naming issues, see the | 
|  | 1480 | "<ulink url='&YOCTO_DOCS_REF_URL;#ref-varlocality-recipe-required'>Required</ulink>" | 
|  | 1481 | section of the Yocto Project Reference Manual. | 
|  | 1482 | </note> | 
|  | 1483 | </para> | 
|  | 1484 |  | 
|  | 1485 | <section id='new-recipe-overview'> | 
|  | 1486 | <title>Overview</title> | 
|  | 1487 |  | 
|  | 1488 | <para> | 
|  | 1489 | The following figure shows the basic process for creating a | 
|  | 1490 | new recipe. | 
|  | 1491 | The remainder of the section provides details for the steps. | 
|  | 1492 | <imagedata fileref="figures/recipe-workflow.png" width="6in" depth="7in" align="center" scalefit="1" /> | 
|  | 1493 | </para> | 
|  | 1494 | </section> | 
|  | 1495 |  | 
|  | 1496 | <section id='new-recipe-locate-or-automatically-create-a-base-recipe'> | 
|  | 1497 | <title>Locate or Automatically Create a Base Recipe</title> | 
|  | 1498 |  | 
|  | 1499 | <para> | 
|  | 1500 | You can always write a recipe from scratch. | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1501 | However, three choices exist that can help you quickly get a | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1502 | start on a new recipe: | 
|  | 1503 | <itemizedlist> | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1504 | <listitem><para> | 
|  | 1505 | <emphasis><filename>devtool add</filename>:</emphasis> | 
|  | 1506 | A command that assists in creating a recipe and | 
|  | 1507 | an environment conducive to development. | 
|  | 1508 | </para></listitem> | 
|  | 1509 | <listitem><para> | 
|  | 1510 | <emphasis><filename>recipetool create</filename>:</emphasis> | 
|  | 1511 | A command provided by the Yocto Project that automates | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1512 | creation of a base recipe based on the source | 
|  | 1513 | files. | 
|  | 1514 | </para></listitem> | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1515 | <listitem><para> | 
|  | 1516 | <emphasis>Existing Recipes:</emphasis> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1517 | Location and modification of an existing recipe that is | 
|  | 1518 | similar in function to the recipe you need. | 
|  | 1519 | </para></listitem> | 
|  | 1520 | </itemizedlist> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1521 | <note> | 
|  | 1522 | For information on recipe syntax, see the | 
|  | 1523 | "<ulink url='&YOCTO_DOCS_REF_URL;#recipe-syntax'>Recipe Syntax</ulink>" | 
|  | 1524 | section in the Yocto Project Reference Manual. | 
|  | 1525 | </note> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1526 | </para> | 
|  | 1527 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1528 | <section id='new-recipe-creating-the-base-recipe-using-devtool'> | 
|  | 1529 | <title>Creating the Base Recipe Using <filename>devtool add</filename></title> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1530 |  | 
|  | 1531 | <para> | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1532 | The <filename>devtool add</filename> command uses the same | 
|  | 1533 | logic for auto-creating the recipe as | 
|  | 1534 | <filename>recipetool create</filename>, which is listed | 
|  | 1535 | below. | 
|  | 1536 | Additionally, however, <filename>devtool add</filename> | 
|  | 1537 | sets up an environment that makes it easy for you to | 
|  | 1538 | patch the source and to make changes to the recipe as | 
|  | 1539 | is often necessary when adding a recipe to build a new | 
|  | 1540 | piece of software to be included in a build. | 
|  | 1541 | </para> | 
|  | 1542 |  | 
|  | 1543 | <para> | 
|  | 1544 | You can find a complete description of the | 
|  | 1545 | <filename>devtool add</filename> command in the | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1546 | "<ulink url='&YOCTO_DOCS_SDK_URL;#sdk-a-closer-look-at-devtool-add'>A Closer Look at <filename>devtool</filename> add</ulink>" | 
|  | 1547 | section in the Yocto Project Application Development | 
|  | 1548 | and the Extensible Software Development Kit (eSDK) manual. | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1549 | </para> | 
|  | 1550 | </section> | 
|  | 1551 |  | 
|  | 1552 | <section id='new-recipe-creating-the-base-recipe-using-recipetool'> | 
|  | 1553 | <title>Creating the Base Recipe Using <filename>recipetool create</filename></title> | 
|  | 1554 |  | 
|  | 1555 | <para> | 
|  | 1556 | <filename>recipetool create</filename> automates creation | 
|  | 1557 | of a base recipe given a set of source code files. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1558 | As long as you can extract or point to the source files, | 
|  | 1559 | the tool will construct a recipe and automatically | 
|  | 1560 | configure all pre-build information into the recipe. | 
|  | 1561 | For example, suppose you have an application that builds | 
|  | 1562 | using Autotools. | 
|  | 1563 | Creating the base recipe using | 
|  | 1564 | <filename>recipetool</filename> results in a recipe | 
|  | 1565 | that has the pre-build dependencies, license requirements, | 
|  | 1566 | and checksums configured. | 
|  | 1567 | </para> | 
|  | 1568 |  | 
|  | 1569 | <para> | 
|  | 1570 | To run the tool, you just need to be in your | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1571 | <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1572 | and have sourced the build environment setup script | 
|  | 1573 | (i.e. | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1574 | <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>oe-init-build-env</filename></ulink>). | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1575 | Here is the basic <filename>recipetool</filename> syntax: | 
|  | 1576 | <note> | 
|  | 1577 | Running <filename>recipetool -h</filename> or | 
|  | 1578 | <filename>recipetool create -h</filename> produces the | 
|  | 1579 | Python-generated help, which presented differently | 
|  | 1580 | than what follows here. | 
|  | 1581 | </note> | 
|  | 1582 | <literallayout class='monospaced'> | 
|  | 1583 | recipetool -h | 
|  | 1584 | recipetool create [-h] | 
|  | 1585 | recipetool [-d] [-q] [--color auto | always | never ] create -o <replaceable>OUTFILE</replaceable> [-m] [-x <replaceable>EXTERNALSRC</replaceable>] <replaceable>source</replaceable> | 
|  | 1586 |  | 
|  | 1587 | -d       Enables debug output. | 
|  | 1588 | -q       Outputs only errors (quiet mode). | 
|  | 1589 | --color  Colorizes the output automatically, always, or never. | 
|  | 1590 | -h       Displays Python generated syntax for recipetool. | 
|  | 1591 | create   Causes recipetool to create a base recipe.  The create | 
|  | 1592 | command is further defined with these options: | 
|  | 1593 |  | 
|  | 1594 | -o <replaceable>OUTFILE</replaceable>      Specifies the full path and filename for the generated | 
|  | 1595 | recipe. | 
|  | 1596 | -m              Causes the recipe to be machine-specific rather than | 
|  | 1597 | architecture-specific (default). | 
|  | 1598 | -x <replaceable>EXTERNALSRC</replaceable>  Fetches and extracts source files from <replaceable>source</replaceable> | 
|  | 1599 | and places them in <replaceable>EXTERNALSRC</replaceable>. | 
|  | 1600 | <replaceable>source</replaceable> must be a URL. | 
|  | 1601 | -h              Displays Python-generated syntax for create. | 
|  | 1602 | <replaceable>source</replaceable>          Specifies the source code on which to base the | 
|  | 1603 | recipe. | 
|  | 1604 | </literallayout> | 
|  | 1605 | </para> | 
|  | 1606 |  | 
|  | 1607 | <para> | 
|  | 1608 | Running <filename>recipetool create -o</filename> <replaceable>OUTFILE</replaceable> | 
|  | 1609 | creates the base recipe and locates it properly in the | 
|  | 1610 | layer that contains your source files. | 
|  | 1611 | Following are some syntax examples: | 
|  | 1612 | </para> | 
|  | 1613 |  | 
|  | 1614 | <para> | 
|  | 1615 | Use this syntax to generate a recipe based on <replaceable>source</replaceable>. | 
|  | 1616 | Once generated, the recipe resides in the existing source | 
|  | 1617 | code layer: | 
|  | 1618 | <literallayout class='monospaced'> | 
|  | 1619 | recipetool create -o <replaceable>OUTFILE</replaceable> <replaceable>source</replaceable> | 
|  | 1620 | </literallayout> | 
|  | 1621 | Use this syntax to generate a recipe using code that you | 
|  | 1622 | extract from <replaceable>source</replaceable>. | 
|  | 1623 | The extracted code is placed in its own layer defined | 
|  | 1624 | by <replaceable>EXTERNALSRC</replaceable>. | 
|  | 1625 | <literallayout class='monospaced'> | 
|  | 1626 | recipetool create -o <replaceable>OUTFILE</replaceable> -x <replaceable>EXTERNALSRC</replaceable> <replaceable>source</replaceable> | 
|  | 1627 | </literallayout> | 
|  | 1628 | Use this syntax to generate a recipe based on <replaceable>source</replaceable>. | 
|  | 1629 | The options direct <filename>recipetool</filename> to | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 1630 | generate debugging information. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1631 | Once generated, the recipe resides in the existing source | 
|  | 1632 | code layer: | 
|  | 1633 | <literallayout class='monospaced'> | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 1634 | recipetool create -d -o <replaceable>OUTFILE</replaceable> <replaceable>source</replaceable> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1635 | </literallayout> | 
|  | 1636 | </para> | 
|  | 1637 | </section> | 
|  | 1638 |  | 
|  | 1639 | <section id='new-recipe-locating-and-using-a-similar-recipe'> | 
|  | 1640 | <title>Locating and Using a Similar Recipe</title> | 
|  | 1641 |  | 
|  | 1642 | <para> | 
|  | 1643 | Before writing a recipe from scratch, it is often useful to | 
|  | 1644 | discover whether someone else has already written one that | 
|  | 1645 | meets (or comes close to meeting) your needs. | 
|  | 1646 | The Yocto Project and OpenEmbedded communities maintain many | 
|  | 1647 | recipes that might be candidates for what you are doing. | 
|  | 1648 | You can find a good central index of these recipes in the | 
|  | 1649 | <ulink url='http://layers.openembedded.org'>OpenEmbedded metadata index</ulink>. | 
|  | 1650 | </para> | 
|  | 1651 |  | 
|  | 1652 | <para> | 
|  | 1653 | Working from an existing recipe or a skeleton recipe is the | 
|  | 1654 | best way to get started. | 
|  | 1655 | Here are some points on both methods: | 
|  | 1656 | <itemizedlist> | 
|  | 1657 | <listitem><para><emphasis>Locate and modify a recipe that | 
|  | 1658 | is close to what you want to do:</emphasis> | 
|  | 1659 | This method works when you are familiar with the | 
|  | 1660 | current recipe space. | 
|  | 1661 | The method does not work so well for those new to | 
|  | 1662 | the Yocto Project or writing recipes.</para> | 
|  | 1663 | <para>Some risks associated with this method are | 
|  | 1664 | using a recipe that has areas totally unrelated to | 
|  | 1665 | what you are trying to accomplish with your recipe, | 
|  | 1666 | not recognizing areas of the recipe that you might | 
|  | 1667 | have to add from scratch, and so forth. | 
|  | 1668 | All these risks stem from unfamiliarity with the | 
|  | 1669 | existing recipe space.</para></listitem> | 
|  | 1670 | <listitem><para><emphasis>Use and modify the following | 
|  | 1671 | skeleton recipe:</emphasis> | 
|  | 1672 | If for some reason you do not want to use | 
|  | 1673 | <filename>recipetool</filename> and you cannot | 
|  | 1674 | find an existing recipe that is close to meeting | 
|  | 1675 | your needs, you can use the following structure to | 
|  | 1676 | provide the fundamental areas of a new recipe. | 
|  | 1677 | <literallayout class='monospaced'> | 
|  | 1678 | DESCRIPTION = "" | 
|  | 1679 | HOMEPAGE = "" | 
|  | 1680 | LICENSE = "" | 
|  | 1681 | SECTION = "" | 
|  | 1682 | DEPENDS = "" | 
|  | 1683 | LIC_FILES_CHKSUM = "" | 
|  | 1684 |  | 
|  | 1685 | SRC_URI = "" | 
|  | 1686 | </literallayout> | 
|  | 1687 | </para></listitem> | 
|  | 1688 | </itemizedlist> | 
|  | 1689 | </para> | 
|  | 1690 | </section> | 
|  | 1691 | </section> | 
|  | 1692 |  | 
|  | 1693 | <section id='new-recipe-storing-and-naming-the-recipe'> | 
|  | 1694 | <title>Storing and Naming the Recipe</title> | 
|  | 1695 |  | 
|  | 1696 | <para> | 
|  | 1697 | Once you have your base recipe, you should put it in your | 
|  | 1698 | own layer and name it appropriately. | 
|  | 1699 | Locating it correctly ensures that the OpenEmbedded build | 
|  | 1700 | system can find it when you use BitBake to process the | 
|  | 1701 | recipe. | 
|  | 1702 | </para> | 
|  | 1703 |  | 
|  | 1704 | <itemizedlist> | 
|  | 1705 | <listitem><para><emphasis>Storing Your Recipe:</emphasis> | 
|  | 1706 | The OpenEmbedded build system locates your recipe | 
|  | 1707 | through the layer's <filename>conf/layer.conf</filename> | 
|  | 1708 | file and the | 
|  | 1709 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BBFILES'><filename>BBFILES</filename></ulink> | 
|  | 1710 | variable. | 
|  | 1711 | This variable sets up a path from which the build system can | 
|  | 1712 | locate recipes. | 
|  | 1713 | Here is the typical use: | 
|  | 1714 | <literallayout class='monospaced'> | 
|  | 1715 | BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \ | 
|  | 1716 | ${LAYERDIR}/recipes-*/*/*.bbappend" | 
|  | 1717 | </literallayout> | 
|  | 1718 | Consequently, you need to be sure you locate your new recipe | 
|  | 1719 | inside your layer such that it can be found.</para> | 
|  | 1720 | <para>You can find more information on how layers are | 
|  | 1721 | structured in the | 
|  | 1722 | "<link linkend='understanding-and-creating-layers'>Understanding and Creating Layers</link>" | 
|  | 1723 | section.</para></listitem> | 
|  | 1724 | <listitem><para><emphasis>Naming Your Recipe:</emphasis> | 
|  | 1725 | When you name your recipe, you need to follow this naming | 
|  | 1726 | convention: | 
|  | 1727 | <literallayout class='monospaced'> | 
|  | 1728 | <replaceable>basename</replaceable>_<replaceable>version</replaceable>.bb | 
|  | 1729 | </literallayout> | 
|  | 1730 | Use lower-cased characters and do not include the reserved | 
|  | 1731 | suffixes <filename>-native</filename>, | 
|  | 1732 | <filename>-cross</filename>, <filename>-initial</filename>, | 
|  | 1733 | or <filename>-dev</filename> casually (i.e. do not use them | 
|  | 1734 | as part of your recipe name unless the string applies). | 
|  | 1735 | Here are some examples: | 
|  | 1736 | <literallayout class='monospaced'> | 
|  | 1737 | cups_1.7.0.bb | 
|  | 1738 | gawk_4.0.2.bb | 
|  | 1739 | irssi_0.8.16-rc1.bb | 
|  | 1740 | </literallayout></para></listitem> | 
|  | 1741 | </itemizedlist> | 
|  | 1742 | </section> | 
|  | 1743 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1744 | <section id='new-recipe-running-a-build-on-the-recipe'> | 
|  | 1745 | <title>Running a Build on the Recipe</title> | 
|  | 1746 |  | 
|  | 1747 | <para> | 
|  | 1748 | Creating a new recipe is usually an iterative process that | 
|  | 1749 | requires using BitBake to process the recipe multiple times in | 
|  | 1750 | order to progressively discover and add information to the | 
|  | 1751 | recipe file. | 
|  | 1752 | </para> | 
|  | 1753 |  | 
|  | 1754 | <para> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1755 | Assuming you have sourced the build environment setup script (i.e. | 
|  | 1756 | <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1757 | and you are in the | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1758 | <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>, | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1759 | use BitBake to process your recipe. | 
|  | 1760 | All you need to provide is the | 
|  | 1761 | <filename><replaceable>basename</replaceable></filename> of the recipe as described | 
|  | 1762 | in the previous section: | 
|  | 1763 | <literallayout class='monospaced'> | 
|  | 1764 | $ bitbake <replaceable>basename</replaceable> | 
|  | 1765 | </literallayout> | 
|  | 1766 |  | 
|  | 1767 | </para> | 
|  | 1768 |  | 
|  | 1769 | <para> | 
|  | 1770 | During the build, the OpenEmbedded build system creates a | 
|  | 1771 | temporary work directory for each recipe | 
|  | 1772 | (<filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}</filename>) | 
|  | 1773 | where it keeps extracted source files, log files, intermediate | 
|  | 1774 | compilation and packaging files, and so forth. | 
|  | 1775 | </para> | 
|  | 1776 |  | 
|  | 1777 | <para> | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1778 | The path to the per-recipe temporary work directory depends | 
|  | 1779 | on the context in which it is being built. | 
|  | 1780 | The quickest way to find this path is to have BitBake return it | 
|  | 1781 | by running the following: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1782 | <literallayout class='monospaced'> | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1783 | $ bitbake -e <replaceable>basename</replaceable> | grep ^WORKDIR= | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1784 | </literallayout> | 
|  | 1785 | As an example, assume a Source Directory top-level folder named | 
|  | 1786 | <filename>poky</filename>, a default Build Directory at | 
|  | 1787 | <filename>poky/build</filename>, and a | 
|  | 1788 | <filename>qemux86-poky-linux</filename> machine target system. | 
|  | 1789 | Furthermore, suppose your recipe is named | 
|  | 1790 | <filename>foo_1.3.0.bb</filename>. | 
|  | 1791 | In this case, the work directory the build system uses to | 
|  | 1792 | build the package would be as follows: | 
|  | 1793 | <literallayout class='monospaced'> | 
|  | 1794 | poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0 | 
|  | 1795 | </literallayout> | 
|  | 1796 | Inside this directory you can find sub-directories such as | 
|  | 1797 | <filename>image</filename>, <filename>packages-split</filename>, | 
|  | 1798 | and <filename>temp</filename>. | 
|  | 1799 | After the build, you can examine these to determine how well | 
|  | 1800 | the build went. | 
|  | 1801 | <note> | 
|  | 1802 | You can find log files for each task in the recipe's | 
|  | 1803 | <filename>temp</filename> directory (e.g. | 
|  | 1804 | <filename>poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0/temp</filename>). | 
|  | 1805 | Log files are named <filename>log.<replaceable>taskname</replaceable></filename> | 
|  | 1806 | (e.g. <filename>log.do_configure</filename>, | 
|  | 1807 | <filename>log.do_fetch</filename>, and | 
|  | 1808 | <filename>log.do_compile</filename>). | 
|  | 1809 | </note> | 
|  | 1810 | </para> | 
|  | 1811 |  | 
|  | 1812 | <para> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1813 | You can find more information about the build process in | 
|  | 1814 | "<ulink url='&YOCTO_DOCS_REF_URL;#ref-development-environment'>The Yocto Project Development Environment</ulink>" | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1815 | chapter of the Yocto Project Reference Manual. | 
|  | 1816 | </para> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1817 | </section> | 
|  | 1818 |  | 
|  | 1819 | <section id='new-recipe-fetching-code'> | 
|  | 1820 | <title>Fetching Code</title> | 
|  | 1821 |  | 
|  | 1822 | <para> | 
|  | 1823 | The first thing your recipe must do is specify how to fetch | 
|  | 1824 | the source files. | 
|  | 1825 | Fetching is controlled mainly through the | 
|  | 1826 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> | 
|  | 1827 | variable. | 
|  | 1828 | Your recipe must have a <filename>SRC_URI</filename> variable | 
|  | 1829 | that points to where the source is located. | 
|  | 1830 | For a graphical representation of source locations, see the | 
|  | 1831 | "<ulink url='&YOCTO_DOCS_REF_URL;#sources-dev-environment'>Sources</ulink>" | 
|  | 1832 | section in the Yocto Project Reference Manual. | 
|  | 1833 | </para> | 
|  | 1834 |  | 
|  | 1835 | <para> | 
|  | 1836 | The | 
|  | 1837 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-fetch'><filename>do_fetch</filename></ulink> | 
|  | 1838 | task uses the prefix of each entry in the | 
|  | 1839 | <filename>SRC_URI</filename> variable value to determine which | 
|  | 1840 | fetcher to use to get your source files. | 
|  | 1841 | It is the <filename>SRC_URI</filename> variable that triggers | 
|  | 1842 | the fetcher. | 
|  | 1843 | The | 
|  | 1844 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink> | 
|  | 1845 | task uses the variable after source is fetched to apply | 
|  | 1846 | patches. | 
|  | 1847 | The OpenEmbedded build system uses | 
|  | 1848 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESOVERRIDES'><filename>FILESOVERRIDES</filename></ulink> | 
|  | 1849 | for scanning directory locations for local files in | 
|  | 1850 | <filename>SRC_URI</filename>. | 
|  | 1851 | </para> | 
|  | 1852 |  | 
|  | 1853 | <para> | 
|  | 1854 | The <filename>SRC_URI</filename> variable in your recipe must | 
|  | 1855 | define each unique location for your source files. | 
|  | 1856 | It is good practice to not hard-code pathnames in an URL used | 
|  | 1857 | in <filename>SRC_URI</filename>. | 
|  | 1858 | Rather than hard-code these paths, use | 
|  | 1859 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink><filename>}</filename>, | 
|  | 1860 | which causes the fetch process to use the version specified in | 
|  | 1861 | the recipe filename. | 
|  | 1862 | Specifying the version in this manner means that upgrading the | 
|  | 1863 | recipe to a future version is as simple as renaming the recipe | 
|  | 1864 | to match the new version. | 
|  | 1865 | </para> | 
|  | 1866 |  | 
|  | 1867 | <para> | 
|  | 1868 | Here is a simple example from the | 
|  | 1869 | <filename>meta/recipes-devtools/cdrtools/cdrtools-native_3.01a20.bb</filename> | 
|  | 1870 | recipe where the source comes from a single tarball. | 
|  | 1871 | Notice the use of the | 
|  | 1872 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink> | 
|  | 1873 | variable: | 
|  | 1874 | <literallayout class='monospaced'> | 
|  | 1875 | SRC_URI = "ftp://ftp.berlios.de/pub/cdrecord/alpha/cdrtools-${PV}.tar.bz2" | 
|  | 1876 | </literallayout> | 
|  | 1877 | </para> | 
|  | 1878 |  | 
|  | 1879 | <para> | 
|  | 1880 | Files mentioned in <filename>SRC_URI</filename> whose names end | 
|  | 1881 | in a typical archive extension (e.g. <filename>.tar</filename>, | 
|  | 1882 | <filename>.tar.gz</filename>, <filename>.tar.bz2</filename>, | 
|  | 1883 | <filename>.zip</filename>, and so forth), are automatically | 
|  | 1884 | extracted during the | 
|  | 1885 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-unpack'><filename>do_unpack</filename></ulink> | 
|  | 1886 | task. | 
|  | 1887 | For another example that specifies these types of files, see | 
|  | 1888 | the | 
|  | 1889 | "<link linkend='new-recipe-autotooled-package'>Autotooled Package</link>" | 
|  | 1890 | section. | 
|  | 1891 | </para> | 
|  | 1892 |  | 
|  | 1893 | <para> | 
|  | 1894 | Another way of specifying source is from an SCM. | 
|  | 1895 | For Git repositories, you must specify | 
|  | 1896 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink> | 
|  | 1897 | and you should specify | 
|  | 1898 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink> | 
|  | 1899 | to include the revision with | 
|  | 1900 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>. | 
|  | 1901 | Here is an example from the recipe | 
|  | 1902 | <filename>meta/recipes-kernel/blktrace/blktrace_git.bb</filename>: | 
|  | 1903 | <literallayout class='monospaced'> | 
|  | 1904 | SRCREV = "d6918c8832793b4205ed3bfede78c2f915c23385" | 
|  | 1905 |  | 
|  | 1906 | PR = "r6" | 
|  | 1907 | PV = "1.0.5+git${SRCPV}" | 
|  | 1908 |  | 
|  | 1909 | SRC_URI = "git://git.kernel.dk/blktrace.git \ | 
|  | 1910 | file://ldflags.patch" | 
|  | 1911 | </literallayout> | 
|  | 1912 | </para> | 
|  | 1913 |  | 
|  | 1914 | <para> | 
|  | 1915 | If your <filename>SRC_URI</filename> statement includes | 
|  | 1916 | URLs pointing to individual files fetched from a remote server | 
|  | 1917 | other than a version control system, BitBake attempts to | 
|  | 1918 | verify the files against checksums defined in your recipe to | 
|  | 1919 | ensure they have not been tampered with or otherwise modified | 
|  | 1920 | since the recipe was written. | 
|  | 1921 | Two checksums are used: | 
|  | 1922 | <filename>SRC_URI[md5sum]</filename> and | 
|  | 1923 | <filename>SRC_URI[sha256sum]</filename>. | 
|  | 1924 | </para> | 
|  | 1925 |  | 
|  | 1926 | <para> | 
|  | 1927 | If your <filename>SRC_URI</filename> variable points to | 
|  | 1928 | more than a single URL (excluding SCM URLs), you need to | 
|  | 1929 | provide the <filename>md5</filename> and | 
|  | 1930 | <filename>sha256</filename> checksums for each URL. | 
|  | 1931 | For these cases, you provide a name for each URL as part of | 
|  | 1932 | the <filename>SRC_URI</filename> and then reference that name | 
|  | 1933 | in the subsequent checksum statements. | 
|  | 1934 | Here is an example: | 
|  | 1935 | <literallayout class='monospaced'> | 
|  | 1936 | SRC_URI = "${DEBIAN_MIRROR}/main/a/apmd/apmd_3.2.2.orig.tar.gz;name=tarball \ | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1937 | ${DEBIAN_MIRROR}/main/a/apmd/apmd_${PV}.diff.gz;name=patch" | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1938 |  | 
|  | 1939 | SRC_URI[tarball.md5sum] = "b1e6309e8331e0f4e6efd311c2d97fa8" | 
|  | 1940 | SRC_URI[tarball.sha256sum] = "7f7d9f60b7766b852881d40b8ff91d8e39fccb0d1d913102a5c75a2dbb52332d" | 
|  | 1941 |  | 
|  | 1942 | SRC_URI[patch.md5sum] = "57e1b689264ea80f78353519eece0c92" | 
|  | 1943 | SRC_URI[patch.sha256sum] = "7905ff96be93d725544d0040e425c42f9c05580db3c272f11cff75b9aa89d430" | 
|  | 1944 | </literallayout> | 
|  | 1945 | </para> | 
|  | 1946 |  | 
|  | 1947 | <para> | 
|  | 1948 | Proper values for <filename>md5</filename> and | 
|  | 1949 | <filename>sha256</filename> checksums might be available | 
|  | 1950 | with other signatures on the download page for the upstream | 
|  | 1951 | source (e.g. <filename>md5</filename>, | 
|  | 1952 | <filename>sha1</filename>, <filename>sha256</filename>, | 
|  | 1953 | <filename>GPG</filename>, and so forth). | 
|  | 1954 | Because the OpenEmbedded build system only deals with | 
|  | 1955 | <filename>sha256sum</filename> and <filename>md5sum</filename>, | 
|  | 1956 | you should verify all the signatures you find by hand. | 
|  | 1957 | </para> | 
|  | 1958 |  | 
|  | 1959 | <para> | 
|  | 1960 | If no <filename>SRC_URI</filename> checksums are specified | 
|  | 1961 | when you attempt to build the recipe, or you provide an | 
|  | 1962 | incorrect checksum, the build will produce an error for each | 
|  | 1963 | missing or incorrect checksum. | 
|  | 1964 | As part of the error message, the build system provides | 
|  | 1965 | the checksum string corresponding to the fetched file. | 
|  | 1966 | Once you have the correct checksums, you can copy and paste | 
|  | 1967 | them into your recipe and then run the build again to continue. | 
|  | 1968 | <note> | 
|  | 1969 | As mentioned, if the upstream source provides signatures | 
|  | 1970 | for verifying the downloaded source code, you should | 
|  | 1971 | verify those manually before setting the checksum values | 
|  | 1972 | in the recipe and continuing with the build. | 
|  | 1973 | </note> | 
|  | 1974 | </para> | 
|  | 1975 |  | 
|  | 1976 | <para> | 
|  | 1977 | This final example is a bit more complicated and is from the | 
|  | 1978 | <filename>meta/recipes-sato/rxvt-unicode/rxvt-unicode_9.20.bb</filename> | 
|  | 1979 | recipe. | 
|  | 1980 | The example's <filename>SRC_URI</filename> statement identifies | 
|  | 1981 | multiple files as the source files for the recipe: a tarball, a | 
|  | 1982 | patch file, a desktop file, and an icon. | 
|  | 1983 | <literallayout class='monospaced'> | 
|  | 1984 | SRC_URI = "http://dist.schmorp.de/rxvt-unicode/Attic/rxvt-unicode-${PV}.tar.bz2 \ | 
|  | 1985 | file://xwc.patch \ | 
|  | 1986 | file://rxvt.desktop \ | 
|  | 1987 | file://rxvt.png" | 
|  | 1988 | </literallayout> | 
|  | 1989 | </para> | 
|  | 1990 |  | 
|  | 1991 | <para> | 
|  | 1992 | When you specify local files using the | 
|  | 1993 | <filename>file://</filename> URI protocol, the build system | 
|  | 1994 | fetches files from the local machine. | 
|  | 1995 | The path is relative to the | 
|  | 1996 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink> | 
|  | 1997 | variable and searches specific directories in a certain order: | 
|  | 1998 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BP'><filename>BP</filename></ulink><filename>}</filename>, | 
|  | 1999 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-BPN'><filename>BPN</filename></ulink><filename>}</filename>, | 
|  | 2000 | and <filename>files</filename>. | 
|  | 2001 | The directories are assumed to be subdirectories of the | 
|  | 2002 | directory in which the recipe or append file resides. | 
|  | 2003 | For another example that specifies these types of files, see the | 
|  | 2004 | "<link linkend='new-recipe-single-c-file-package-hello-world'>Single .c File Package (Hello World!)</link>" | 
|  | 2005 | section. | 
|  | 2006 | </para> | 
|  | 2007 |  | 
|  | 2008 | <para> | 
|  | 2009 | The previous example also specifies a patch file. | 
|  | 2010 | Patch files are files whose names usually end in | 
|  | 2011 | <filename>.patch</filename> or <filename>.diff</filename> but | 
|  | 2012 | can end with compressed suffixes such as | 
|  | 2013 | <filename>diff.gz</filename> and | 
|  | 2014 | <filename>patch.bz2</filename>, for example. | 
|  | 2015 | The build system automatically applies patches as described | 
|  | 2016 | in the | 
|  | 2017 | "<link linkend='new-recipe-patching-code'>Patching Code</link>" section. | 
|  | 2018 | </para> | 
|  | 2019 | </section> | 
|  | 2020 |  | 
|  | 2021 | <section id='new-recipe-unpacking-code'> | 
|  | 2022 | <title>Unpacking Code</title> | 
|  | 2023 |  | 
|  | 2024 | <para> | 
|  | 2025 | During the build, the | 
|  | 2026 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-unpack'><filename>do_unpack</filename></ulink> | 
|  | 2027 | task unpacks the source with | 
|  | 2028 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename> | 
|  | 2029 | pointing to where it is unpacked. | 
|  | 2030 | </para> | 
|  | 2031 |  | 
|  | 2032 | <para> | 
|  | 2033 | If you are fetching your source files from an upstream source | 
|  | 2034 | archived tarball and the tarball's internal structure matches | 
|  | 2035 | the common convention of a top-level subdirectory named | 
|  | 2036 | <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>, | 
|  | 2037 | then you do not need to set <filename>S</filename>. | 
|  | 2038 | However, if <filename>SRC_URI</filename> specifies to fetch | 
|  | 2039 | source from an archive that does not use this convention, | 
|  | 2040 | or from an SCM like Git or Subversion, your recipe needs to | 
|  | 2041 | define <filename>S</filename>. | 
|  | 2042 | </para> | 
|  | 2043 |  | 
|  | 2044 | <para> | 
|  | 2045 | If processing your recipe using BitBake successfully unpacks | 
|  | 2046 | the source files, you need to be sure that the directory | 
|  | 2047 | pointed to by <filename>${S}</filename> matches the structure | 
|  | 2048 | of the source. | 
|  | 2049 | </para> | 
|  | 2050 | </section> | 
|  | 2051 |  | 
|  | 2052 | <section id='new-recipe-patching-code'> | 
|  | 2053 | <title>Patching Code</title> | 
|  | 2054 |  | 
|  | 2055 | <para> | 
|  | 2056 | Sometimes it is necessary to patch code after it has been | 
|  | 2057 | fetched. | 
|  | 2058 | Any files mentioned in <filename>SRC_URI</filename> whose | 
|  | 2059 | names end in <filename>.patch</filename> or | 
|  | 2060 | <filename>.diff</filename> or compressed versions of these | 
|  | 2061 | suffixes (e.g. <filename>diff.gz</filename> are treated as | 
|  | 2062 | patches. | 
|  | 2063 | The | 
|  | 2064 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink> | 
|  | 2065 | task automatically applies these patches. | 
|  | 2066 | </para> | 
|  | 2067 |  | 
|  | 2068 | <para> | 
|  | 2069 | The build system should be able to apply patches with the "-p1" | 
|  | 2070 | option (i.e. one directory level in the path will be stripped | 
|  | 2071 | off). | 
|  | 2072 | If your patch needs to have more directory levels stripped off, | 
|  | 2073 | specify the number of levels using the "striplevel" option in | 
|  | 2074 | the <filename>SRC_URI</filename> entry for the patch. | 
|  | 2075 | Alternatively, if your patch needs to be applied in a specific | 
|  | 2076 | subdirectory that is not specified in the patch file, use the | 
|  | 2077 | "patchdir" option in the entry. | 
|  | 2078 | </para> | 
|  | 2079 |  | 
|  | 2080 | <para> | 
|  | 2081 | As with all local files referenced in | 
|  | 2082 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> | 
|  | 2083 | using <filename>file://</filename>, you should place | 
|  | 2084 | patch files in a directory next to the recipe either | 
|  | 2085 | named the same as the base name of the recipe | 
|  | 2086 | (<ulink url='&YOCTO_DOCS_REF_URL;#var-BP'><filename>BP</filename></ulink> | 
|  | 2087 | and | 
|  | 2088 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BPN'><filename>BPN</filename></ulink>) | 
|  | 2089 | or "files". | 
|  | 2090 | </para> | 
|  | 2091 | </section> | 
|  | 2092 |  | 
|  | 2093 | <section id='new-recipe-licensing'> | 
|  | 2094 | <title>Licensing</title> | 
|  | 2095 |  | 
|  | 2096 | <para> | 
|  | 2097 | Your recipe needs to have both the | 
|  | 2098 | <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink> | 
|  | 2099 | and | 
|  | 2100 | <ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'><filename>LIC_FILES_CHKSUM</filename></ulink> | 
|  | 2101 | variables: | 
|  | 2102 | <itemizedlist> | 
|  | 2103 | <listitem><para><emphasis><filename>LICENSE</filename>:</emphasis> | 
|  | 2104 | This variable specifies the license for the software. | 
|  | 2105 | If you do not know the license under which the software | 
|  | 2106 | you are building is distributed, you should go to the | 
|  | 2107 | source code and look for that information. | 
|  | 2108 | Typical files containing this information include | 
|  | 2109 | <filename>COPYING</filename>, | 
|  | 2110 | <filename>LICENSE</filename>, and | 
|  | 2111 | <filename>README</filename> files. | 
|  | 2112 | You could also find the information near the top of | 
|  | 2113 | a source file. | 
|  | 2114 | For example, given a piece of software licensed under | 
|  | 2115 | the GNU General Public License version 2, you would | 
|  | 2116 | set <filename>LICENSE</filename> as follows: | 
|  | 2117 | <literallayout class='monospaced'> | 
|  | 2118 | LICENSE = "GPLv2" | 
|  | 2119 | </literallayout></para> | 
|  | 2120 | <para>The licenses you specify within | 
|  | 2121 | <filename>LICENSE</filename> can have any name as long | 
|  | 2122 | as you do not use spaces, since spaces are used as | 
|  | 2123 | separators between license names. | 
|  | 2124 | For standard licenses, use the names of the files in | 
|  | 2125 | <filename>meta/files/common-licenses/</filename> | 
|  | 2126 | or the <filename>SPDXLICENSEMAP</filename> flag names | 
|  | 2127 | defined in <filename>meta/conf/licenses.conf</filename>. | 
|  | 2128 | </para></listitem> | 
|  | 2129 | <listitem><para><emphasis><filename>LIC_FILES_CHKSUM</filename>:</emphasis> | 
|  | 2130 | The OpenEmbedded build system uses this variable to | 
|  | 2131 | make sure the license text has not changed. | 
|  | 2132 | If it has, the build produces an error and it affords | 
|  | 2133 | you the chance to figure it out and correct the problem. | 
|  | 2134 | </para> | 
|  | 2135 | <para>You need to specify all applicable licensing | 
|  | 2136 | files for the software. | 
|  | 2137 | At the end of the configuration step, the build process | 
|  | 2138 | will compare the checksums of the files to be sure | 
|  | 2139 | the text has not changed. | 
|  | 2140 | Any differences result in an error with the message | 
|  | 2141 | containing the current checksum. | 
|  | 2142 | For more explanation and examples of how to set the | 
|  | 2143 | <filename>LIC_FILES_CHKSUM</filename> variable, see the | 
|  | 2144 | "<ulink url='&YOCTO_DOCS_REF_URL;#usingpoky-configuring-LIC_FILES_CHKSUM'>Tracking License Changes</ulink>" | 
|  | 2145 | section in the Yocto Project Reference Manual.</para> | 
|  | 2146 | <para>To determine the correct checksum string, you | 
|  | 2147 | can list the appropriate files in the | 
|  | 2148 | <filename>LIC_FILES_CHKSUM</filename> variable with | 
|  | 2149 | incorrect md5 strings, attempt to build the software, | 
|  | 2150 | and then note the resulting error messages that will | 
|  | 2151 | report the correct md5 strings. | 
|  | 2152 | See the | 
|  | 2153 | "<link linkend='new-recipe-fetching-code'>Fetching Code</link>" | 
|  | 2154 | section for additional information. | 
|  | 2155 | </para> | 
|  | 2156 |  | 
|  | 2157 | <para> | 
|  | 2158 | Here is an example that assumes the software has a | 
|  | 2159 | <filename>COPYING</filename> file: | 
|  | 2160 | <literallayout class='monospaced'> | 
|  | 2161 | LIC_FILES_CHKSUM = "file://COPYING;md5=xxx" | 
|  | 2162 | </literallayout> | 
|  | 2163 | When you try to build the software, the build system | 
|  | 2164 | will produce an error and give you the correct string | 
|  | 2165 | that you can substitute into the recipe file for a | 
|  | 2166 | subsequent build. | 
|  | 2167 | </para></listitem> | 
|  | 2168 | </itemizedlist> | 
|  | 2169 | </para> | 
|  | 2170 |  | 
|  | 2171 | <!-- | 
|  | 2172 |  | 
|  | 2173 | <para> | 
|  | 2174 | For trying this out I created a new recipe named | 
|  | 2175 | <filename>htop_1.0.2.bb</filename> and put it in | 
|  | 2176 | <filename>poky/meta/recipes-extended/htop</filename>. | 
|  | 2177 | There are two license type statements in my very simple | 
|  | 2178 | recipe: | 
|  | 2179 | <literallayout class='monospaced'> | 
|  | 2180 | LICENSE = "" | 
|  | 2181 |  | 
|  | 2182 | LIC_FILES_CHKSUM = "" | 
|  | 2183 |  | 
|  | 2184 | SRC_URI[md5sum] = "" | 
|  | 2185 | SRC_URI[sha256sum] = "" | 
|  | 2186 | </literallayout> | 
|  | 2187 | Evidently, you need to run a <filename>bitbake -c cleanall htop</filename>. | 
|  | 2188 | Next, you delete or comment out the two <filename>SRC_URI</filename> | 
|  | 2189 | lines at the end and then attempt to build the software with | 
|  | 2190 | <filename>bitbake htop</filename>. | 
|  | 2191 | Doing so causes BitBake to report some errors and and give | 
|  | 2192 | you the actual strings you need for the last two | 
|  | 2193 | <filename>SRC_URI</filename> lines. | 
|  | 2194 | Prior to this, you have to dig around in the home page of the | 
|  | 2195 | source for <filename>htop</filename> and determine that the | 
|  | 2196 | software is released under GPLv2. | 
|  | 2197 | You can provide that in the <filename>LICENSE</filename> | 
|  | 2198 | statement. | 
|  | 2199 | Now you edit your recipe to have those two strings for | 
|  | 2200 | the <filename>SRC_URI</filename> statements: | 
|  | 2201 | <literallayout class='monospaced'> | 
|  | 2202 | LICENSE = "GPLv2" | 
|  | 2203 |  | 
|  | 2204 | LIC_FILES_CHKSUM = "" | 
|  | 2205 |  | 
|  | 2206 | SRC_URI = "${SOURCEFORGE_MIRROR}/htop/htop-${PV}.tar.gz" | 
|  | 2207 | SRC_URI[md5sum] = "0d01cca8df3349c74569cefebbd9919e" | 
|  | 2208 | SRC_URI[sha256sum] = "ee60657b044ece0df096c053060df7abf3cce3a568ab34d260049e6a37ccd8a1" | 
|  | 2209 | </literallayout> | 
|  | 2210 | At this point, you can build the software again using the | 
|  | 2211 | <filename>bitbake htop</filename> command. | 
|  | 2212 | There is just a set of errors now associated with the | 
|  | 2213 | empty <filename>LIC_FILES_CHKSUM</filename> variable now. | 
|  | 2214 | </para> | 
|  | 2215 | --> | 
|  | 2216 |  | 
|  | 2217 | </section> | 
|  | 2218 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2219 | <section id='new-dependencies'> | 
|  | 2220 | <title>Dependencies</title> | 
|  | 2221 |  | 
|  | 2222 | <para> | 
|  | 2223 | Most software packages have a short list of other packages | 
|  | 2224 | that they require, which are called dependencies. | 
|  | 2225 | These dependencies fall into two main categories: build-time | 
|  | 2226 | dependencies, which are required when the software is built; | 
|  | 2227 | and runtime dependencies, which are required to be installed | 
|  | 2228 | on the target in order for the software to run. | 
|  | 2229 | </para> | 
|  | 2230 |  | 
|  | 2231 | <para> | 
|  | 2232 | Within a recipe, you specify build-time dependencies using the | 
|  | 2233 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink> | 
|  | 2234 | variable. | 
|  | 2235 | Although nuances exist, items specified in | 
|  | 2236 | <filename>DEPENDS</filename> should be names of other recipes. | 
|  | 2237 | It is important that you specify all build-time dependencies | 
|  | 2238 | explicitly. | 
|  | 2239 | If you do not, due to the parallel nature of BitBake's | 
|  | 2240 | execution, you can end up with a race condition where the | 
|  | 2241 | dependency is present for one task of a recipe (e.g. | 
|  | 2242 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink>) | 
|  | 2243 | and then gone when the next task runs (e.g. | 
|  | 2244 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink>). | 
|  | 2245 | </para> | 
|  | 2246 |  | 
|  | 2247 | <para> | 
|  | 2248 | Another consideration is that configure scripts might | 
|  | 2249 | automatically check for optional dependencies and enable | 
|  | 2250 | corresponding functionality if those dependencies are found. | 
|  | 2251 | This behavior means that to ensure deterministic results and | 
|  | 2252 | thus avoid more race conditions, you need to either explicitly | 
|  | 2253 | specify these dependencies as well, or tell the configure | 
|  | 2254 | script explicitly to disable the functionality. | 
|  | 2255 | If you wish to make a recipe that is more generally useful | 
|  | 2256 | (e.g. publish the recipe in a layer for others to use), | 
|  | 2257 | instead of hard-disabling the functionality, you can use the | 
|  | 2258 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGECONFIG'><filename>PACKAGECONFIG</filename></ulink> | 
|  | 2259 | variable to allow functionality and the corresponding | 
|  | 2260 | dependencies to be enabled and disabled easily by other | 
|  | 2261 | users of the recipe. | 
|  | 2262 | </para> | 
|  | 2263 |  | 
|  | 2264 | <para> | 
|  | 2265 | Similar to build-time dependencies, you specify runtime | 
|  | 2266 | dependencies through a variable - | 
|  | 2267 | <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>, | 
|  | 2268 | which is package-specific. | 
|  | 2269 | All variables that are package-specific need to have the name | 
|  | 2270 | of the package added to the end as an override. | 
|  | 2271 | Since the main package for a recipe has the same name as the | 
|  | 2272 | recipe, and the recipe's name can be found through the | 
|  | 2273 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename> | 
|  | 2274 | variable, then you specify the dependencies for the main | 
|  | 2275 | package by setting <filename>RDEPENDS_${PN}</filename>. | 
|  | 2276 | If the package were named <filename>${PN}-tools</filename>, | 
|  | 2277 | then you would set <filename>RDEPENDS_${PN}-tools</filename>, | 
|  | 2278 | and so forth. | 
|  | 2279 | </para> | 
|  | 2280 |  | 
|  | 2281 | <para> | 
|  | 2282 | Some runtime dependencies will be set automatically at | 
|  | 2283 | packaging time. | 
|  | 2284 | These dependencies include any shared library dependencies | 
|  | 2285 | (i.e. if a package "example" contains "libexample" and | 
|  | 2286 | another package "mypackage" contains a binary that links to | 
|  | 2287 | "libexample" then the OpenEmbedded build system will | 
|  | 2288 | automatically add a runtime dependency to "mypackage" on | 
|  | 2289 | "example"). | 
|  | 2290 | See the | 
|  | 2291 | "<ulink url='&YOCTO_DOCS_REF_URL;#automatically-added-runtime-dependencies'>Automatically Added Runtime Dependencies</ulink>" | 
|  | 2292 | in the Yocto Project Reference Manual for further details. | 
|  | 2293 | </para> | 
|  | 2294 | </section> | 
|  | 2295 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2296 | <section id='new-recipe-configuring-the-recipe'> | 
|  | 2297 | <title>Configuring the Recipe</title> | 
|  | 2298 |  | 
|  | 2299 | <para> | 
|  | 2300 | Most software provides some means of setting build-time | 
|  | 2301 | configuration options before compilation. | 
|  | 2302 | Typically, setting these options is accomplished by running a | 
|  | 2303 | configure script with some options, or by modifying a build | 
|  | 2304 | configuration file. | 
| Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 2305 | <note> | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2306 | As of Yocto Project Release 1.7, some of the core recipes | 
| Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 2307 | that package binary configuration scripts now disable the | 
|  | 2308 | scripts due to the scripts previously requiring error-prone | 
|  | 2309 | path substitution. | 
|  | 2310 | The OpenEmbedded build system uses | 
|  | 2311 | <filename>pkg-config</filename> now, which is much more | 
|  | 2312 | robust. | 
|  | 2313 | You can find a list of the <filename>*-config</filename> | 
|  | 2314 | scripts that are disabled list in the | 
|  | 2315 | "<ulink url='&YOCTO_DOCS_REF_URL;#migration-1.7-binary-configuration-scripts-disabled'>Binary Configuration Scripts Disabled</ulink>" | 
|  | 2316 | section in the Yocto Project Reference Manual. | 
|  | 2317 | </note> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2318 | </para> | 
|  | 2319 |  | 
|  | 2320 | <para> | 
|  | 2321 | A major part of build-time configuration is about checking for | 
|  | 2322 | build-time dependencies and possibly enabling optional | 
|  | 2323 | functionality as a result. | 
|  | 2324 | You need to specify any build-time dependencies for the | 
|  | 2325 | software you are building in your recipe's | 
|  | 2326 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink> | 
|  | 2327 | value, in terms of other recipes that satisfy those | 
|  | 2328 | dependencies. | 
|  | 2329 | You can often find build-time or runtime | 
|  | 2330 | dependencies described in the software's documentation. | 
|  | 2331 | </para> | 
|  | 2332 |  | 
|  | 2333 | <para> | 
|  | 2334 | The following list provides configuration items of note based | 
|  | 2335 | on how your software is built: | 
|  | 2336 | <itemizedlist> | 
|  | 2337 | <listitem><para><emphasis>Autotools:</emphasis> | 
|  | 2338 | If your source files have a | 
|  | 2339 | <filename>configure.ac</filename> file, then your | 
|  | 2340 | software is built using Autotools. | 
|  | 2341 | If this is the case, you just need to worry about | 
|  | 2342 | modifying the configuration.</para> | 
|  | 2343 | <para>When using Autotools, your recipe needs to inherit | 
|  | 2344 | the | 
|  | 2345 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink> | 
|  | 2346 | class and your recipe does not have to contain a | 
|  | 2347 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink> | 
|  | 2348 | task. | 
|  | 2349 | However, you might still want to make some adjustments. | 
|  | 2350 | For example, you can set | 
|  | 2351 | <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OECONF'><filename>EXTRA_OECONF</filename></ulink> | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2352 | or | 
|  | 2353 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGECONFIG_CONFARGS'><filename>PACKAGECONFIG_CONFARGS</filename></ulink> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2354 | to pass any needed configure options that are specific | 
|  | 2355 | to the recipe.</para></listitem> | 
|  | 2356 | <listitem><para><emphasis>CMake:</emphasis> | 
|  | 2357 | If your source files have a | 
|  | 2358 | <filename>CMakeLists.txt</filename> file, then your | 
|  | 2359 | software is built using CMake. | 
|  | 2360 | If this is the case, you just need to worry about | 
|  | 2361 | modifying the configuration.</para> | 
|  | 2362 | <para>When you use CMake, your recipe needs to inherit | 
|  | 2363 | the | 
|  | 2364 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-cmake'><filename>cmake</filename></ulink> | 
|  | 2365 | class and your recipe does not have to contain a | 
|  | 2366 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink> | 
|  | 2367 | task. | 
|  | 2368 | You can make some adjustments by setting | 
|  | 2369 | <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OECMAKE'><filename>EXTRA_OECMAKE</filename></ulink> | 
|  | 2370 | to pass any needed configure options that are specific | 
|  | 2371 | to the recipe.</para></listitem> | 
|  | 2372 | <listitem><para><emphasis>Other:</emphasis> | 
|  | 2373 | If your source files do not have a | 
|  | 2374 | <filename>configure.ac</filename> or | 
|  | 2375 | <filename>CMakeLists.txt</filename> file, then your | 
|  | 2376 | software is built using some method other than Autotools | 
|  | 2377 | or CMake. | 
|  | 2378 | If this is the case, you normally need to provide a | 
|  | 2379 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink> | 
|  | 2380 | task in your recipe | 
|  | 2381 | unless, of course, there is nothing to configure. | 
|  | 2382 | </para> | 
|  | 2383 | <para>Even if your software is not being built by | 
|  | 2384 | Autotools or CMake, you still might not need to deal | 
|  | 2385 | with any configuration issues. | 
|  | 2386 | You need to determine if configuration is even a required step. | 
|  | 2387 | You might need to modify a Makefile or some configuration file | 
|  | 2388 | used for the build to specify necessary build options. | 
|  | 2389 | Or, perhaps you might need to run a provided, custom | 
|  | 2390 | configure script with the appropriate options.</para> | 
|  | 2391 | <para>For the case involving a custom configure | 
|  | 2392 | script, you would run | 
|  | 2393 | <filename>./configure --help</filename> and look for | 
|  | 2394 | the options you need to set.</para></listitem> | 
|  | 2395 | </itemizedlist> | 
|  | 2396 | </para> | 
|  | 2397 |  | 
|  | 2398 | <para> | 
|  | 2399 | Once configuration succeeds, it is always good practice to | 
|  | 2400 | look at the <filename>log.do_configure</filename> file to | 
|  | 2401 | ensure that the appropriate options have been enabled and no | 
|  | 2402 | additional build-time dependencies need to be added to | 
|  | 2403 | <filename>DEPENDS</filename>. | 
|  | 2404 | For example, if the configure script reports that it found | 
|  | 2405 | something not mentioned in <filename>DEPENDS</filename>, or | 
|  | 2406 | that it did not find something that it needed for some | 
|  | 2407 | desired optional functionality, then you would need to add | 
|  | 2408 | those to <filename>DEPENDS</filename>. | 
|  | 2409 | Looking at the log might also reveal items being checked for, | 
|  | 2410 | enabled, or both that you do not want, or items not being found | 
|  | 2411 | that are in <filename>DEPENDS</filename>, in which case | 
|  | 2412 | you would need to look at passing extra options to the | 
|  | 2413 | configure script as needed. | 
|  | 2414 | For reference information on configure options specific to the | 
|  | 2415 | software you are building, you can consult the output of the | 
|  | 2416 | <filename>./configure --help</filename> command within | 
|  | 2417 | <filename>${S}</filename> or consult the software's upstream | 
|  | 2418 | documentation. | 
|  | 2419 | </para> | 
|  | 2420 | </section> | 
|  | 2421 |  | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2422 | <section id='new-recipe-using-headers-to-interface-with-devices'> | 
|  | 2423 | <title>Using Headers to Interface with Devices</title> | 
|  | 2424 |  | 
|  | 2425 | <para> | 
|  | 2426 | If your recipe builds an application that needs to | 
|  | 2427 | communicate with some device or needs an API into a custom | 
|  | 2428 | kernel, you will need to provide appropriate header files. | 
|  | 2429 | Under no circumstances should you ever modify the existing | 
|  | 2430 | <filename>meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc</filename> | 
|  | 2431 | file. | 
|  | 2432 | These headers are used to build <filename>libc</filename> and | 
|  | 2433 | must not be compromised with custom or machine-specific | 
|  | 2434 | header information. | 
|  | 2435 | If you customize <filename>libc</filename> through modified | 
|  | 2436 | headers all other applications that use | 
|  | 2437 | <filename>libc</filename> thus become affected. | 
|  | 2438 | <note><title>Warning</title> | 
|  | 2439 | Never copy and customize the <filename>libc</filename> | 
|  | 2440 | header file (i.e. | 
|  | 2441 | <filename>meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc</filename>). | 
|  | 2442 | </note> | 
|  | 2443 | The correct way to interface to a device or custom kernel is | 
|  | 2444 | to use a separate package that provides the additional headers | 
|  | 2445 | for the driver or other unique interfaces. | 
|  | 2446 | When doing so, your application also becomes responsible for | 
|  | 2447 | creating a dependency on that specific provider. | 
|  | 2448 | </para> | 
|  | 2449 |  | 
|  | 2450 | <para> | 
|  | 2451 | Consider the following: | 
|  | 2452 | <itemizedlist> | 
|  | 2453 | <listitem><para> | 
|  | 2454 | Never modify | 
|  | 2455 | <filename>linux-libc-headers.inc</filename>. | 
|  | 2456 | Consider that file to be part of the | 
|  | 2457 | <filename>libc</filename> system, and not something | 
|  | 2458 | you use to access the kernel directly. | 
|  | 2459 | You should access <filename>libc</filename> through | 
|  | 2460 | specific <filename>libc</filename> calls. | 
|  | 2461 | </para></listitem> | 
|  | 2462 | <listitem><para> | 
|  | 2463 | Applications that must talk directly to devices | 
|  | 2464 | should either provide necessary headers themselves, | 
|  | 2465 | or establish a dependency on a special headers package | 
|  | 2466 | that is specific to that driver. | 
|  | 2467 | </para></listitem> | 
|  | 2468 | </itemizedlist> | 
|  | 2469 | </para> | 
|  | 2470 |  | 
|  | 2471 | <para> | 
|  | 2472 | For example, suppose you want to modify an existing header | 
|  | 2473 | that adds I/O control or network support. | 
|  | 2474 | If the modifications are used by a small number programs, | 
|  | 2475 | providing a unique version of a header is easy and has little | 
|  | 2476 | impact. | 
|  | 2477 | When doing so, bear in mind the guidelines in the previous | 
|  | 2478 | list. | 
|  | 2479 | <note> | 
|  | 2480 | If for some reason your changes need to modify the behavior | 
|  | 2481 | of the <filename>libc</filename>, and subsequently all | 
|  | 2482 | other applications on the system, use a | 
|  | 2483 | <filename>.bbappend</filename> to modify the | 
|  | 2484 | <filename>linux-kernel-headers.inc</filename> file. | 
|  | 2485 | However, take care to not make the changes | 
|  | 2486 | machine specific. | 
|  | 2487 | </note> | 
|  | 2488 | </para> | 
|  | 2489 |  | 
|  | 2490 | <para> | 
|  | 2491 | Consider a case where your kernel is older and you need | 
|  | 2492 | an older <filename>libc</filename> ABI. | 
|  | 2493 | The headers installed by your recipe should still be a | 
|  | 2494 | standard mainline kernel, not your own custom one. | 
|  | 2495 | </para> | 
|  | 2496 |  | 
|  | 2497 | <para> | 
|  | 2498 | When you use custom kernel headers you need to get them from | 
|  | 2499 | <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_KERNEL_DIR'><filename>STAGING_KERNEL_DIR</filename></ulink>, | 
|  | 2500 | which is the directory with kernel headers that are | 
|  | 2501 | required to build out-of-tree modules. | 
|  | 2502 | Your recipe will also need the following: | 
|  | 2503 | <literallayout class='monospaced'> | 
|  | 2504 | do_configure[depends] += "virtual/kernel:do_shared_workdir" | 
|  | 2505 | </literallayout> | 
|  | 2506 | </para> | 
|  | 2507 | </section> | 
|  | 2508 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2509 | <section id='new-recipe-compilation'> | 
|  | 2510 | <title>Compilation</title> | 
|  | 2511 |  | 
|  | 2512 | <para> | 
|  | 2513 | During a build, the <filename>do_compile</filename> task | 
|  | 2514 | happens after source is fetched, unpacked, and configured. | 
|  | 2515 | If the recipe passes through <filename>do_compile</filename> | 
|  | 2516 | successfully, nothing needs to be done. | 
|  | 2517 | </para> | 
|  | 2518 |  | 
|  | 2519 | <para> | 
|  | 2520 | However, if the compile step fails, you need to diagnose the | 
|  | 2521 | failure. | 
| Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 2522 | Here are some common issues that cause failures. | 
|  | 2523 | <note> | 
|  | 2524 | For cases where improper paths are detected for | 
|  | 2525 | configuration files or for when libraries/headers cannot | 
|  | 2526 | be found, be sure you are using the more robust | 
|  | 2527 | <filename>pkg-config</filename>. | 
|  | 2528 | See the note in section | 
|  | 2529 | "<link linkend='new-recipe-configuring-the-recipe'>Configuring the Recipe</link>" | 
|  | 2530 | for additional information. | 
|  | 2531 | </note> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2532 | <itemizedlist> | 
|  | 2533 | <listitem><para><emphasis>Parallel build failures:</emphasis> | 
|  | 2534 | These failures manifest themselves as intermittent | 
|  | 2535 | errors, or errors reporting that a file or directory | 
|  | 2536 | that should be created by some other part of the build | 
|  | 2537 | process could not be found. | 
|  | 2538 | This type of failure can occur even if, upon inspection, | 
|  | 2539 | the file or directory does exist after the build has | 
|  | 2540 | failed, because that part of the build process happened | 
|  | 2541 | in the wrong order.</para> | 
|  | 2542 | <para>To fix the problem, you need to either satisfy | 
|  | 2543 | the missing dependency in the Makefile or whatever | 
|  | 2544 | script produced the Makefile, or (as a workaround) | 
|  | 2545 | set | 
|  | 2546 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink> | 
|  | 2547 | to an empty string: | 
|  | 2548 | <literallayout class='monospaced'> | 
|  | 2549 | PARALLEL_MAKE = "" | 
|  | 2550 | </literallayout></para> | 
|  | 2551 | <para> | 
|  | 2552 | For information on parallel Makefile issues, see the | 
|  | 2553 | "<link linkend='debugging-parallel-make-races'>Debugging Parallel Make Races</link>" | 
|  | 2554 | section. | 
|  | 2555 | </para></listitem> | 
|  | 2556 | <listitem><para><emphasis>Improper host path usage:</emphasis> | 
|  | 2557 | This failure applies to recipes building for the target | 
|  | 2558 | or <filename>nativesdk</filename> only. | 
|  | 2559 | The failure occurs when the compilation process uses | 
|  | 2560 | improper headers, libraries, or other files from the | 
|  | 2561 | host system when cross-compiling for the target. | 
|  | 2562 | </para> | 
|  | 2563 | <para>To fix the problem, examine the | 
|  | 2564 | <filename>log.do_compile</filename> file to identify | 
|  | 2565 | the host paths being used (e.g. | 
|  | 2566 | <filename>/usr/include</filename>, | 
|  | 2567 | <filename>/usr/lib</filename>, and so forth) and then | 
|  | 2568 | either add configure options, apply a patch, or do both. | 
|  | 2569 | </para></listitem> | 
|  | 2570 | <listitem><para><emphasis>Failure to find required | 
|  | 2571 | libraries/headers:</emphasis> | 
|  | 2572 | If a build-time dependency is missing because it has | 
|  | 2573 | not been declared in | 
|  | 2574 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>, | 
|  | 2575 | or because the dependency exists but the path used by | 
|  | 2576 | the build process to find the file is incorrect and the | 
|  | 2577 | configure step did not detect it, the compilation | 
|  | 2578 | process could fail. | 
|  | 2579 | For either of these failures, the compilation process | 
|  | 2580 | notes that files could not be found. | 
|  | 2581 | In these cases, you need to go back and add additional | 
|  | 2582 | options to the configure script as well as possibly | 
|  | 2583 | add additional build-time dependencies to | 
|  | 2584 | <filename>DEPENDS</filename>.</para> | 
|  | 2585 | <para>Occasionally, it is necessary to apply a patch | 
|  | 2586 | to the source to ensure the correct paths are used. | 
|  | 2587 | If you need to specify paths to find files staged | 
|  | 2588 | into the sysroot from other recipes, use the variables | 
|  | 2589 | that the OpenEmbedded build system provides | 
|  | 2590 | (e.g. | 
|  | 2591 | <filename>STAGING_BINDIR</filename>, | 
|  | 2592 | <filename>STAGING_INCDIR</filename>, | 
|  | 2593 | <filename>STAGING_DATADIR</filename>, and so forth). | 
|  | 2594 | <!-- | 
|  | 2595 | (e.g. | 
|  | 2596 | <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_BINDIR'><filename>STAGING_BINDIR</filename></ulink>, | 
|  | 2597 | <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_INCDIR'><filename>STAGING_INCDIR</filename></ulink>, | 
|  | 2598 | <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_DATADIR'><filename>STAGING_DATADIR</filename></ulink>, | 
|  | 2599 | and so forth). | 
|  | 2600 | --> | 
|  | 2601 | </para></listitem> | 
|  | 2602 | </itemizedlist> | 
|  | 2603 | </para> | 
|  | 2604 | </section> | 
|  | 2605 |  | 
|  | 2606 | <section id='new-recipe-installing'> | 
|  | 2607 | <title>Installing</title> | 
|  | 2608 |  | 
|  | 2609 | <para> | 
|  | 2610 | During <filename>do_install</filename>, the task copies the | 
|  | 2611 | built files along with their hierarchy to locations that | 
|  | 2612 | would mirror their locations on the target device. | 
|  | 2613 | The installation process copies files from the | 
|  | 2614 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>, | 
|  | 2615 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-B'><filename>B</filename></ulink><filename>}</filename>, | 
|  | 2616 | and | 
|  | 2617 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}</filename> | 
|  | 2618 | directories to the | 
|  | 2619 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink><filename>}</filename> | 
|  | 2620 | directory to create the structure as it should appear on the | 
|  | 2621 | target system. | 
|  | 2622 | </para> | 
|  | 2623 |  | 
|  | 2624 | <para> | 
|  | 2625 | How your software is built affects what you must do to be | 
|  | 2626 | sure your software is installed correctly. | 
|  | 2627 | The following list describes what you must do for installation | 
|  | 2628 | depending on the type of build system used by the software | 
|  | 2629 | being built: | 
|  | 2630 | <itemizedlist> | 
|  | 2631 | <listitem><para><emphasis>Autotools and CMake:</emphasis> | 
|  | 2632 | If the software your recipe is building uses Autotools | 
|  | 2633 | or CMake, the OpenEmbedded build | 
|  | 2634 | system understands how to install the software. | 
|  | 2635 | Consequently, you do not have to have a | 
|  | 2636 | <filename>do_install</filename> task as part of your | 
|  | 2637 | recipe. | 
|  | 2638 | You just need to make sure the install portion of the | 
|  | 2639 | build completes with no issues. | 
|  | 2640 | However, if you wish to install additional files not | 
|  | 2641 | already being installed by | 
|  | 2642 | <filename>make install</filename>, you should do this | 
|  | 2643 | using a <filename>do_install_append</filename> function | 
|  | 2644 | using the install command as described in | 
|  | 2645 | the "Manual" bulleted item later in this list. | 
|  | 2646 | </para></listitem> | 
|  | 2647 | <listitem><para><emphasis>Other (using | 
|  | 2648 | <filename>make install</filename>):</emphasis> | 
|  | 2649 | You need to define a | 
|  | 2650 | <filename>do_install</filename> function in your | 
|  | 2651 | recipe. | 
|  | 2652 | The function should call | 
|  | 2653 | <filename>oe_runmake install</filename> and will likely | 
|  | 2654 | need to pass in the destination directory as well. | 
|  | 2655 | How you pass that path is dependent on how the | 
|  | 2656 | <filename>Makefile</filename> being run is written | 
|  | 2657 | (e.g. <filename>DESTDIR=${D}</filename>, | 
|  | 2658 | <filename>PREFIX=${D}</filename>, | 
|  | 2659 | <filename>INSTALLROOT=${D}</filename>, and so forth). | 
|  | 2660 | </para> | 
|  | 2661 | <para>For an example recipe using | 
|  | 2662 | <filename>make install</filename>, see the | 
|  | 2663 | "<link linkend='new-recipe-makefile-based-package'>Makefile-Based Package</link>" | 
|  | 2664 | section.</para></listitem> | 
|  | 2665 | <listitem><para><emphasis>Manual:</emphasis> | 
|  | 2666 | You need to define a | 
|  | 2667 | <filename>do_install</filename> function in your | 
|  | 2668 | recipe. | 
|  | 2669 | The function must first use | 
|  | 2670 | <filename>install -d</filename> to create the | 
|  | 2671 | directories under | 
|  | 2672 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink><filename>}</filename>. | 
|  | 2673 | Once the directories exist, your function can use | 
|  | 2674 | <filename>install</filename> to manually install the | 
|  | 2675 | built software into the directories.</para> | 
|  | 2676 | <para>You can find more information on | 
|  | 2677 | <filename>install</filename> at | 
|  | 2678 | <ulink url='http://www.gnu.org/software/coreutils/manual/html_node/install-invocation.html'></ulink>. | 
|  | 2679 | </para></listitem> | 
|  | 2680 | </itemizedlist> | 
|  | 2681 | </para> | 
|  | 2682 |  | 
|  | 2683 | <para> | 
|  | 2684 | For the scenarios that do not use Autotools or | 
|  | 2685 | CMake, you need to track the installation | 
|  | 2686 | and diagnose and fix any issues until everything installs | 
|  | 2687 | correctly. | 
|  | 2688 | You need to look in the default location of | 
|  | 2689 | <filename>${D}</filename>, which is | 
|  | 2690 | <filename>${WORKDIR}/image</filename>, to be sure your | 
|  | 2691 | files have been installed correctly. | 
|  | 2692 | </para> | 
|  | 2693 |  | 
|  | 2694 | <note><title>Notes</title> | 
|  | 2695 | <itemizedlist> | 
|  | 2696 | <listitem><para> | 
|  | 2697 | During the installation process, you might need to | 
|  | 2698 | modify some of the installed files to suit the target | 
|  | 2699 | layout. | 
|  | 2700 | For example, you might need to replace hard-coded paths | 
|  | 2701 | in an initscript with values of variables provided by | 
|  | 2702 | the build system, such as replacing | 
|  | 2703 | <filename>/usr/bin/</filename> with | 
|  | 2704 | <filename>${bindir}</filename>. | 
|  | 2705 | If you do perform such modifications during | 
|  | 2706 | <filename>do_install</filename>, be sure to modify the | 
|  | 2707 | destination file after copying rather than before | 
|  | 2708 | copying. | 
|  | 2709 | Modifying after copying ensures that the build system | 
|  | 2710 | can re-execute <filename>do_install</filename> if | 
|  | 2711 | needed. | 
|  | 2712 | </para></listitem> | 
|  | 2713 | <listitem><para> | 
|  | 2714 | <filename>oe_runmake install</filename>, which can be | 
|  | 2715 | run directly or can be run indirectly by the | 
|  | 2716 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink> | 
|  | 2717 | and | 
|  | 2718 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-cmake'><filename>cmake</filename></ulink> | 
|  | 2719 | classes, runs <filename>make install</filename> in | 
|  | 2720 | parallel. | 
|  | 2721 | Sometimes, a Makefile can have missing dependencies | 
|  | 2722 | between targets that can result in race conditions. | 
|  | 2723 | If you experience intermittent failures during | 
|  | 2724 | <filename>do_install</filename>, you might be able to | 
|  | 2725 | work around them by disabling parallel Makefile | 
|  | 2726 | installs by adding the following to the recipe: | 
|  | 2727 | <literallayout class='monospaced'> | 
|  | 2728 | PARALLEL_MAKEINST = "" | 
|  | 2729 | </literallayout> | 
|  | 2730 | See | 
|  | 2731 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKEINST'><filename>PARALLEL_MAKEINST</filename></ulink> | 
|  | 2732 | for additional information. | 
|  | 2733 | </para></listitem> | 
|  | 2734 | </itemizedlist> | 
|  | 2735 | </note> | 
|  | 2736 | </section> | 
|  | 2737 |  | 
|  | 2738 | <section id='new-recipe-enabling-system-services'> | 
|  | 2739 | <title>Enabling System Services</title> | 
|  | 2740 |  | 
|  | 2741 | <para> | 
|  | 2742 | If you want to install a service, which is a process that | 
|  | 2743 | usually starts on boot and runs in the background, then | 
|  | 2744 | you must include some additional definitions in your recipe. | 
|  | 2745 | </para> | 
|  | 2746 |  | 
|  | 2747 | <para> | 
|  | 2748 | If you are adding services and the service initialization | 
|  | 2749 | script or the service file itself is not installed, you must | 
|  | 2750 | provide for that installation in your recipe using a | 
|  | 2751 | <filename>do_install_append</filename> function. | 
|  | 2752 | If your recipe already has a <filename>do_install</filename> | 
|  | 2753 | function, update the function near its end rather than | 
|  | 2754 | adding an additional <filename>do_install_append</filename> | 
|  | 2755 | function. | 
|  | 2756 | </para> | 
|  | 2757 |  | 
|  | 2758 | <para> | 
|  | 2759 | When you create the installation for your services, you need | 
|  | 2760 | to accomplish what is normally done by | 
|  | 2761 | <filename>make install</filename>. | 
|  | 2762 | In other words, make sure your installation arranges the output | 
|  | 2763 | similar to how it is arranged on the target system. | 
|  | 2764 | </para> | 
|  | 2765 |  | 
|  | 2766 | <para> | 
|  | 2767 | The OpenEmbedded build system provides support for starting | 
|  | 2768 | services two different ways: | 
|  | 2769 | <itemizedlist> | 
|  | 2770 | <listitem><para><emphasis>SysVinit:</emphasis> | 
|  | 2771 | SysVinit is a system and service manager that | 
|  | 2772 | manages the init system used to control the very basic | 
|  | 2773 | functions of your system. | 
|  | 2774 | The init program is the first program | 
|  | 2775 | started by the Linux kernel when the system boots. | 
|  | 2776 | Init then controls the startup, running and shutdown | 
|  | 2777 | of all other programs.</para> | 
|  | 2778 | <para>To enable a service using SysVinit, your recipe | 
|  | 2779 | needs to inherit the | 
|  | 2780 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-update-rc.d'><filename>update-rc.d</filename></ulink> | 
|  | 2781 | class. | 
|  | 2782 | The class helps facilitate safely installing the | 
|  | 2783 | package on the target.</para> | 
|  | 2784 | <para>You will need to set the | 
|  | 2785 | <ulink url='&YOCTO_DOCS_REF_URL;#var-INITSCRIPT_PACKAGES'><filename>INITSCRIPT_PACKAGES</filename></ulink>, | 
|  | 2786 | <ulink url='&YOCTO_DOCS_REF_URL;#var-INITSCRIPT_NAME'><filename>INITSCRIPT_NAME</filename></ulink>, | 
|  | 2787 | and | 
|  | 2788 | <ulink url='&YOCTO_DOCS_REF_URL;#var-INITSCRIPT_PARAMS'><filename>INITSCRIPT_PARAMS</filename></ulink> | 
|  | 2789 | variables within your recipe.</para></listitem> | 
|  | 2790 | <listitem><para><emphasis>systemd:</emphasis> | 
|  | 2791 | System Management Daemon (systemd) was designed to | 
|  | 2792 | replace SysVinit and to provide | 
|  | 2793 | enhanced management of services. | 
|  | 2794 | For more information on systemd, see the systemd | 
|  | 2795 | homepage at | 
|  | 2796 | <ulink url='http://freedesktop.org/wiki/Software/systemd/'></ulink>. | 
|  | 2797 | </para> | 
|  | 2798 | <para>To enable a service using systemd, your recipe | 
|  | 2799 | needs to inherit the | 
|  | 2800 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-systemd'><filename>systemd</filename></ulink> | 
|  | 2801 | class. | 
|  | 2802 | See the <filename>systemd.bbclass</filename> file | 
|  | 2803 | located in your | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2804 | <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2805 | section for more information. | 
|  | 2806 | </para></listitem> | 
|  | 2807 | </itemizedlist> | 
|  | 2808 | </para> | 
|  | 2809 | </section> | 
|  | 2810 |  | 
|  | 2811 | <section id='new-recipe-packaging'> | 
|  | 2812 | <title>Packaging</title> | 
|  | 2813 |  | 
|  | 2814 | <para> | 
|  | 2815 | Successful packaging is a combination of automated processes | 
|  | 2816 | performed by the OpenEmbedded build system and some | 
|  | 2817 | specific steps you need to take. | 
|  | 2818 | The following list describes the process: | 
|  | 2819 | <itemizedlist> | 
|  | 2820 | <listitem><para><emphasis>Splitting Files</emphasis>: | 
|  | 2821 | The <filename>do_package</filename> task splits the | 
|  | 2822 | files produced by the recipe into logical components. | 
|  | 2823 | Even software that produces a single binary might | 
|  | 2824 | still have debug symbols, documentation, and other | 
|  | 2825 | logical components that should be split out. | 
|  | 2826 | The <filename>do_package</filename> task ensures | 
|  | 2827 | that files are split up and packaged correctly. | 
|  | 2828 | </para></listitem> | 
|  | 2829 | <listitem><para><emphasis>Running QA Checks</emphasis>: | 
|  | 2830 | The | 
|  | 2831 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-insane'><filename>insane</filename></ulink> | 
|  | 2832 | class adds a step to | 
|  | 2833 | the package generation process so that output quality | 
|  | 2834 | assurance checks are generated by the OpenEmbedded | 
|  | 2835 | build system. | 
|  | 2836 | This step performs a range of checks to be sure the | 
|  | 2837 | build's output is free of common problems that show | 
|  | 2838 | up during runtime. | 
|  | 2839 | For information on these checks, see the | 
|  | 2840 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-insane'><filename>insane</filename></ulink> | 
|  | 2841 | class and the | 
|  | 2842 | "<ulink url='&YOCTO_DOCS_REF_URL;#ref-qa-checks'>QA Error and Warning Messages</ulink>" | 
|  | 2843 | chapter in the Yocto Project Reference Manual. | 
|  | 2844 | </para></listitem> | 
|  | 2845 | <listitem><para><emphasis>Hand-Checking Your Packages</emphasis>: | 
|  | 2846 | After you build your software, you need to be sure | 
|  | 2847 | your packages are correct. | 
|  | 2848 | Examine the | 
|  | 2849 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/packages-split</filename> | 
|  | 2850 | directory and make sure files are where you expect | 
|  | 2851 | them to be. | 
|  | 2852 | If you discover problems, you can set | 
|  | 2853 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>, | 
|  | 2854 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>, | 
|  | 2855 | <filename>do_install(_append)</filename>, and so forth as | 
|  | 2856 | needed. | 
|  | 2857 | </para></listitem> | 
|  | 2858 | <listitem><para><emphasis>Splitting an Application into Multiple Packages</emphasis>: | 
|  | 2859 | If you need to split an application into several | 
|  | 2860 | packages, see the | 
|  | 2861 | "<link linkend='splitting-an-application-into-multiple-packages'>Splitting an Application into Multiple Packages</link>" | 
|  | 2862 | section for an example. | 
|  | 2863 | </para></listitem> | 
|  | 2864 | <listitem><para><emphasis>Installing a Post-Installation Script</emphasis>: | 
|  | 2865 | For an example showing how to install a | 
|  | 2866 | post-installation script, see the | 
|  | 2867 | "<link linkend='new-recipe-post-installation-scripts'>Post-Installation Scripts</link>" | 
|  | 2868 | section. | 
|  | 2869 | </para></listitem> | 
|  | 2870 | <listitem><para><emphasis>Marking Package Architecture</emphasis>: | 
|  | 2871 | Depending on what your recipe is building and how it | 
|  | 2872 | is configured, it might be important to mark the | 
|  | 2873 | packages produced as being specific to a particular | 
|  | 2874 | machine, or to mark them as not being specific to | 
| Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 2875 | a particular machine or architecture at all.</para> | 
|  | 2876 | <para>By default, packages apply to any machine with the | 
|  | 2877 | same architecture as the target machine. | 
|  | 2878 | When a recipe produces packages that are | 
|  | 2879 | machine-specific (e.g. the | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2880 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink> | 
|  | 2881 | value is passed into the configure script or a patch | 
| Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 2882 | is applied only for a particular machine), you should | 
|  | 2883 | mark them as such by adding the following to the | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2884 | recipe: | 
|  | 2885 | <literallayout class='monospaced'> | 
|  | 2886 | PACKAGE_ARCH = "${MACHINE_ARCH}" | 
| Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 2887 | </literallayout></para> | 
|  | 2888 | <para>On the other hand, if the recipe produces packages | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2889 | that do not contain anything specific to the target | 
|  | 2890 | machine or architecture at all (e.g. recipes | 
|  | 2891 | that simply package script files or configuration | 
|  | 2892 | files), you should use the | 
|  | 2893 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-allarch'><filename>allarch</filename></ulink> | 
|  | 2894 | class to do this for you by adding this to your | 
|  | 2895 | recipe: | 
|  | 2896 | <literallayout class='monospaced'> | 
|  | 2897 | inherit allarch | 
|  | 2898 | </literallayout> | 
|  | 2899 | Ensuring that the package architecture is correct is | 
|  | 2900 | not critical while you are doing the first few builds | 
|  | 2901 | of your recipe. | 
|  | 2902 | However, it is important in order | 
|  | 2903 | to ensure that your recipe rebuilds (or does not | 
|  | 2904 | rebuild) appropriately in response to changes in | 
|  | 2905 | configuration, and to ensure that you get the | 
|  | 2906 | appropriate packages installed on the target machine, | 
|  | 2907 | particularly if you run separate builds for more | 
|  | 2908 | than one target machine. | 
|  | 2909 | </para></listitem> | 
|  | 2910 | </itemizedlist> | 
|  | 2911 | </para> | 
|  | 2912 | </section> | 
|  | 2913 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2914 | <section id='new-sharing-files-between-recipes'> | 
|  | 2915 | <title>Sharing Files Between Recipes</title> | 
|  | 2916 |  | 
|  | 2917 | <para> | 
|  | 2918 | Recipes often need to use files provided by other recipes on | 
|  | 2919 | the build host. | 
|  | 2920 | For example, an application linking to a common library needs | 
|  | 2921 | access to the library itself and its associated headers. | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2922 | The way this access is accomplished is by populating a sysroot | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2923 | with files. | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2924 | Each recipe has two sysroots in its work directory, one for | 
|  | 2925 | target files | 
|  | 2926 | (<filename>recipe-sysroot</filename>) and one for files that | 
|  | 2927 | are native to the build host | 
|  | 2928 | (<filename>recipe-sysroot-native</filename>). | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2929 | <note> | 
|  | 2930 | You could find the term "staging" used within the Yocto | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2931 | project regarding files populating sysroots (e.g. the | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 2932 | <ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_DIR'><filename>STAGING_DIR</filename></ulink> | 
|  | 2933 | variable). | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2934 | </note> | 
|  | 2935 | </para> | 
|  | 2936 |  | 
|  | 2937 | <para> | 
|  | 2938 | Recipes should never populate the sysroot directly (i.e. write | 
|  | 2939 | files into sysroot). | 
|  | 2940 | Instead, files should be installed into standard locations | 
|  | 2941 | during the | 
|  | 2942 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink> | 
|  | 2943 | task within the | 
|  | 2944 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink><filename>}</filename> | 
|  | 2945 | directory. | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2946 | The reason for this limitation is that almost all files that | 
|  | 2947 | populate the sysroot are cataloged in manifests in order to | 
|  | 2948 | ensure the files can be removed later when a recipe is either | 
|  | 2949 | modified or removed. | 
|  | 2950 | Thus, the sysroot is able to remain free from stale files. | 
|  | 2951 | </para> | 
|  | 2952 |  | 
|  | 2953 | <para> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2954 | A subset of the files installed by the | 
|  | 2955 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink> | 
|  | 2956 | task are used by the | 
|  | 2957 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-populate_sysroot'><filename>do_populate_sysroot</filename></ulink> | 
|  | 2958 | task as defined by the the | 
|  | 2959 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SYSROOT_DIRS'><filename>SYSROOT_DIRS</filename></ulink> | 
|  | 2960 | variable to automatically populate the sysroot. | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 2961 | It is possible to modify the list of directories that populate | 
|  | 2962 | the sysroot. | 
|  | 2963 | The following example shows how you could add the | 
|  | 2964 | <filename>/opt</filename> directory to the list of | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2965 | directories within a recipe: | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 2966 | <literallayout class='monospaced'> | 
|  | 2967 | SYSROOT_DIRS += "/opt" | 
|  | 2968 | </literallayout> | 
|  | 2969 | </para> | 
|  | 2970 |  | 
|  | 2971 | <para> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2972 | For a more complete description of the | 
|  | 2973 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-populate_sysroot'><filename>do_populate_sysroot</filename></ulink> | 
|  | 2974 | task and its associated functions, see the | 
|  | 2975 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-staging'><filename>staging</filename></ulink> | 
|  | 2976 | class. | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2977 | </para> | 
|  | 2978 | </section> | 
|  | 2979 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2980 | <section id='properly-versioning-pre-release-recipes'> | 
|  | 2981 | <title>Properly Versioning Pre-Release Recipes</title> | 
|  | 2982 |  | 
|  | 2983 | <para> | 
|  | 2984 | Sometimes the name of a recipe can lead to versioning | 
|  | 2985 | problems when the recipe is upgraded to a final release. | 
|  | 2986 | For example, consider the | 
|  | 2987 | <filename>irssi_0.8.16-rc1.bb</filename> recipe file in | 
|  | 2988 | the list of example recipes in the | 
|  | 2989 | "<link linkend='new-recipe-storing-and-naming-the-recipe'>Storing and Naming the Recipe</link>" | 
|  | 2990 | section. | 
|  | 2991 | This recipe is at a release candidate stage (i.e. | 
|  | 2992 | "rc1"). | 
|  | 2993 | When the recipe is released, the recipe filename becomes | 
|  | 2994 | <filename>irssi_0.8.16.bb</filename>. | 
|  | 2995 | The version change from <filename>0.8.16-rc1</filename> | 
|  | 2996 | to <filename>0.8.16</filename> is seen as a decrease by the | 
|  | 2997 | build system and package managers, so the resulting packages | 
|  | 2998 | will not correctly trigger an upgrade. | 
|  | 2999 | </para> | 
|  | 3000 |  | 
|  | 3001 | <para> | 
|  | 3002 | In order to ensure the versions compare properly, the | 
|  | 3003 | recommended convention is to set | 
|  | 3004 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink> | 
|  | 3005 | within the recipe to | 
|  | 3006 | "<replaceable>previous_version</replaceable>+<replaceable>current_version</replaceable>". | 
|  | 3007 | You can use an additional variable so that you can use the | 
|  | 3008 | current version elsewhere. | 
|  | 3009 | Here is an example: | 
|  | 3010 | <literallayout class='monospaced'> | 
|  | 3011 | REALPV = "0.8.16-rc1" | 
|  | 3012 | PV = "0.8.15+${REALPV}" | 
|  | 3013 | </literallayout> | 
|  | 3014 | </para> | 
|  | 3015 | </section> | 
|  | 3016 |  | 
|  | 3017 | <section id='new-recipe-post-installation-scripts'> | 
|  | 3018 | <title>Post-Installation Scripts</title> | 
|  | 3019 |  | 
|  | 3020 | <para> | 
|  | 3021 | Post-installation scripts run immediately after installing | 
|  | 3022 | a package on the target or during image creation when a | 
|  | 3023 | package is included in an image. | 
|  | 3024 | To add a post-installation script to a package, add a | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 3025 | <filename>pkg_postinst_</filename><replaceable>PACKAGENAME</replaceable><filename>()</filename> function to | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 3026 | the recipe file (<filename>.bb</filename>) and replace | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 3027 | <replaceable>PACKAGENAME</replaceable> with the name of the package | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 3028 | you want to attach to the <filename>postinst</filename> | 
|  | 3029 | script. | 
|  | 3030 | To apply the post-installation script to the main package | 
|  | 3031 | for the recipe, which is usually what is required, specify | 
|  | 3032 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 3033 | in place of <replaceable>PACKAGENAME</replaceable>. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 3034 | </para> | 
|  | 3035 |  | 
|  | 3036 | <para> | 
|  | 3037 | A post-installation function has the following structure: | 
|  | 3038 | <literallayout class='monospaced'> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 3039 | pkg_postinst_<replaceable>PACKAGENAME</replaceable>() { | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 3040 | # Commands to carry out | 
|  | 3041 | } | 
|  | 3042 | </literallayout> | 
|  | 3043 | </para> | 
|  | 3044 |  | 
|  | 3045 | <para> | 
|  | 3046 | The script defined in the post-installation function is | 
|  | 3047 | called when the root filesystem is created. | 
|  | 3048 | If the script succeeds, the package is marked as installed. | 
|  | 3049 | If the script fails, the package is marked as unpacked and | 
|  | 3050 | the script is executed when the image boots again. | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 3051 | <note> | 
|  | 3052 | Any RPM post-installation script that runs on the target | 
|  | 3053 | should return a 0 exit code. | 
|  | 3054 | RPM does not allow non-zero exit codes for these scripts, | 
|  | 3055 | and the RPM package manager will cause the package to fail | 
|  | 3056 | installation on the target. | 
|  | 3057 | </note> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 3058 | </para> | 
|  | 3059 |  | 
|  | 3060 | <para> | 
|  | 3061 | Sometimes it is necessary for the execution of a | 
|  | 3062 | post-installation script to be delayed until the first boot. | 
|  | 3063 | For example, the script might need to be executed on the | 
|  | 3064 | device itself. | 
|  | 3065 | To delay script execution until boot time, use the following | 
|  | 3066 | structure in the post-installation script: | 
|  | 3067 | <literallayout class='monospaced'> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 3068 | pkg_postinst_<replaceable>PACKAGENAME</replaceable>() { | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 3069 | if [ x"$D" = "x" ]; then | 
|  | 3070 | # Actions to carry out on the device go here | 
|  | 3071 | else | 
|  | 3072 | exit 1 | 
|  | 3073 | fi | 
|  | 3074 | } | 
|  | 3075 | </literallayout> | 
|  | 3076 | </para> | 
|  | 3077 |  | 
|  | 3078 | <para> | 
|  | 3079 | The previous example delays execution until the image boots | 
|  | 3080 | again because the environment variable <filename>D</filename> | 
|  | 3081 | points to the directory containing the image when | 
|  | 3082 | the root filesystem is created at build time but is unset | 
|  | 3083 | when executed on the first boot. | 
|  | 3084 | </para> | 
|  | 3085 |  | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 3086 | <para> | 
|  | 3087 | If you have recipes that use <filename>pkg_postinst</filename> | 
|  | 3088 | scripts and they require the use of non-standard native | 
|  | 3089 | tools that have dependencies during rootfs construction, you | 
|  | 3090 | need to use the | 
|  | 3091 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_WRITE_DEPS'><filename>PACKAGE_WRITE_DEPS</filename></ulink> | 
|  | 3092 | variable in your recipe to list these tools. | 
|  | 3093 | If you do not use this variable, the tools might be missing and | 
|  | 3094 | execution of the post-installation script is deferred until | 
|  | 3095 | first boot. | 
|  | 3096 | Deferring the script to first boot is undesirable and for | 
|  | 3097 | read-only rootfs impossible. | 
|  | 3098 | </para> | 
|  | 3099 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 3100 | <note> | 
|  | 3101 | Equivalent support for pre-install, pre-uninstall, and | 
|  | 3102 | post-uninstall scripts exist by way of | 
|  | 3103 | <filename>pkg_preinst</filename>, | 
|  | 3104 | <filename>pkg_prerm</filename>, and | 
|  | 3105 | <filename>pkg_postrm</filename>, respectively. | 
|  | 3106 | These scrips work in exactly the same way as does | 
|  | 3107 | <filename>pkg_postinst</filename> with the exception that they | 
|  | 3108 | run at different times. | 
|  | 3109 | Also, because of when they run, they are not applicable to | 
|  | 3110 | being run at image creation time like | 
|  | 3111 | <filename>pkg_postinst</filename>. | 
|  | 3112 | </note> | 
|  | 3113 | </section> | 
|  | 3114 |  | 
|  | 3115 | <section id='new-recipe-testing'> | 
|  | 3116 | <title>Testing</title> | 
|  | 3117 |  | 
|  | 3118 | <para> | 
|  | 3119 | The final step for completing your recipe is to be sure that | 
|  | 3120 | the software you built runs correctly. | 
|  | 3121 | To accomplish runtime testing, add the build's output | 
|  | 3122 | packages to your image and test them on the target. | 
|  | 3123 | </para> | 
|  | 3124 |  | 
|  | 3125 | <para> | 
|  | 3126 | For information on how to customize your image by adding | 
|  | 3127 | specific packages, see the | 
|  | 3128 | "<link linkend='usingpoky-extend-customimage'>Customizing Images</link>" | 
|  | 3129 | section. | 
|  | 3130 | </para> | 
|  | 3131 | </section> | 
|  | 3132 |  | 
|  | 3133 | <section id='new-recipe-testing-examples'> | 
|  | 3134 | <title>Examples</title> | 
|  | 3135 |  | 
|  | 3136 | <para> | 
|  | 3137 | To help summarize how to write a recipe, this section provides | 
|  | 3138 | some examples given various scenarios: | 
|  | 3139 | <itemizedlist> | 
|  | 3140 | <listitem><para>Recipes that use local files</para></listitem> | 
|  | 3141 | <listitem><para>Using an Autotooled package</para></listitem> | 
|  | 3142 | <listitem><para>Using a Makefile-based package</para></listitem> | 
|  | 3143 | <listitem><para>Splitting an application into multiple packages</para></listitem> | 
|  | 3144 | <listitem><para>Adding binaries to an image</para></listitem> | 
|  | 3145 | </itemizedlist> | 
|  | 3146 | </para> | 
|  | 3147 |  | 
|  | 3148 | <section id='new-recipe-single-c-file-package-hello-world'> | 
|  | 3149 | <title>Single .c File Package (Hello World!)</title> | 
|  | 3150 |  | 
|  | 3151 | <para> | 
|  | 3152 | Building an application from a single file that is stored | 
|  | 3153 | locally (e.g. under <filename>files</filename>) requires | 
|  | 3154 | a recipe that has the file listed in the | 
|  | 3155 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename> | 
|  | 3156 | variable. | 
|  | 3157 | Additionally, you need to manually write the | 
|  | 3158 | <filename>do_compile</filename> and | 
|  | 3159 | <filename>do_install</filename> tasks. | 
|  | 3160 | The <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'>S</ulink></filename> | 
|  | 3161 | variable defines the directory containing the source code, | 
|  | 3162 | which is set to | 
|  | 3163 | <ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink> | 
|  | 3164 | in this case - the directory BitBake uses for the build. | 
|  | 3165 | <literallayout class='monospaced'> | 
|  | 3166 | SUMMARY = "Simple helloworld application" | 
|  | 3167 | SECTION = "examples" | 
|  | 3168 | LICENSE = "MIT" | 
|  | 3169 | LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" | 
|  | 3170 |  | 
|  | 3171 | SRC_URI = "file://helloworld.c" | 
|  | 3172 |  | 
|  | 3173 | S = "${WORKDIR}" | 
|  | 3174 |  | 
|  | 3175 | do_compile() { | 
|  | 3176 | ${CC} helloworld.c -o helloworld | 
|  | 3177 | } | 
|  | 3178 |  | 
|  | 3179 | do_install() { | 
|  | 3180 | install -d ${D}${bindir} | 
|  | 3181 | install -m 0755 helloworld ${D}${bindir} | 
|  | 3182 | } | 
|  | 3183 | </literallayout> | 
|  | 3184 | </para> | 
|  | 3185 |  | 
|  | 3186 | <para> | 
|  | 3187 | By default, the <filename>helloworld</filename>, | 
|  | 3188 | <filename>helloworld-dbg</filename>, and | 
|  | 3189 | <filename>helloworld-dev</filename> packages are built. | 
|  | 3190 | For information on how to customize the packaging process, | 
|  | 3191 | see the | 
|  | 3192 | "<link linkend='splitting-an-application-into-multiple-packages'>Splitting an Application into Multiple Packages</link>" | 
|  | 3193 | section. | 
|  | 3194 | </para> | 
|  | 3195 | </section> | 
|  | 3196 |  | 
|  | 3197 | <section id='new-recipe-autotooled-package'> | 
|  | 3198 | <title>Autotooled Package</title> | 
|  | 3199 | <para> | 
|  | 3200 | Applications that use Autotools such as <filename>autoconf</filename> and | 
|  | 3201 | <filename>automake</filename> require a recipe that has a source archive listed in | 
|  | 3202 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename> and | 
|  | 3203 | also inherit the | 
|  | 3204 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-autotools'><filename>autotools</filename></ulink> | 
|  | 3205 | class, which contains the definitions of all the steps | 
|  | 3206 | needed to build an Autotool-based application. | 
|  | 3207 | The result of the build is automatically packaged. | 
|  | 3208 | And, if the application uses NLS for localization, packages with local information are | 
|  | 3209 | generated (one package per language). | 
|  | 3210 | Following is one example: (<filename>hello_2.3.bb</filename>) | 
|  | 3211 | <literallayout class='monospaced'> | 
|  | 3212 | SUMMARY = "GNU Helloworld application" | 
|  | 3213 | SECTION = "examples" | 
|  | 3214 | LICENSE = "GPLv2+" | 
|  | 3215 | LIC_FILES_CHKSUM = "file://COPYING;md5=751419260aa954499f7abaabaa882bbe" | 
|  | 3216 |  | 
|  | 3217 | SRC_URI = "${GNU_MIRROR}/hello/hello-${PV}.tar.gz" | 
|  | 3218 |  | 
|  | 3219 | inherit autotools gettext | 
|  | 3220 | </literallayout> | 
|  | 3221 | </para> | 
|  | 3222 |  | 
|  | 3223 | <para> | 
|  | 3224 | The variable | 
|  | 3225 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LIC_FILES_CHKSUM'>LIC_FILES_CHKSUM</ulink></filename> | 
|  | 3226 | is used to track source license changes as described in the | 
|  | 3227 | "<ulink url='&YOCTO_DOCS_REF_URL;#usingpoky-configuring-LIC_FILES_CHKSUM'>Tracking License Changes</ulink>" section. | 
|  | 3228 | You can quickly create Autotool-based recipes in a manner similar to the previous example. | 
|  | 3229 | </para> | 
|  | 3230 | </section> | 
|  | 3231 |  | 
|  | 3232 | <section id='new-recipe-makefile-based-package'> | 
|  | 3233 | <title>Makefile-Based Package</title> | 
|  | 3234 |  | 
|  | 3235 | <para> | 
|  | 3236 | Applications that use GNU <filename>make</filename> also require a recipe that has | 
|  | 3237 | the source archive listed in | 
|  | 3238 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>. | 
|  | 3239 | You do not need to add a <filename>do_compile</filename> step since by default BitBake | 
|  | 3240 | starts the <filename>make</filename> command to compile the application. | 
|  | 3241 | If you need additional <filename>make</filename> options, you should store them in the | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 3242 | <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_OEMAKE'><filename>EXTRA_OEMAKE</filename></ulink> | 
|  | 3243 | or | 
|  | 3244 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGECONFIG_CONFARGS'><filename>PACKAGECONFIG_CONFARGS</filename></ulink> | 
|  | 3245 | variables. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 3246 | BitBake passes these options into the GNU <filename>make</filename> invocation. | 
|  | 3247 | Note that a <filename>do_install</filename> task is still required. | 
|  | 3248 | Otherwise, BitBake runs an empty <filename>do_install</filename> task by default. | 
|  | 3249 | </para> | 
|  | 3250 |  | 
|  | 3251 | <para> | 
|  | 3252 | Some applications might require extra parameters to be passed to the compiler. | 
|  | 3253 | For example, the application might need an additional header path. | 
|  | 3254 | You can accomplish this by adding to the | 
|  | 3255 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-CFLAGS'>CFLAGS</ulink></filename> variable. | 
|  | 3256 | The following example shows this: | 
|  | 3257 | <literallayout class='monospaced'> | 
|  | 3258 | CFLAGS_prepend = "-I ${S}/include " | 
|  | 3259 | </literallayout> | 
|  | 3260 | </para> | 
|  | 3261 |  | 
|  | 3262 | <para> | 
|  | 3263 | In the following example, <filename>mtd-utils</filename> is a makefile-based package: | 
|  | 3264 | <literallayout class='monospaced'> | 
|  | 3265 | SUMMARY = "Tools for managing memory technology devices" | 
|  | 3266 | SECTION = "base" | 
|  | 3267 | DEPENDS = "zlib lzo e2fsprogs util-linux" | 
|  | 3268 | HOMEPAGE = "http://www.linux-mtd.infradead.org/" | 
|  | 3269 | LICENSE = "GPLv2+" | 
|  | 3270 | LIC_FILES_CHKSUM = "file://COPYING;md5=0636e73ff0215e8d672dc4c32c317bb3 \ | 
|  | 3271 | file://include/common.h;beginline=1;endline=17;md5=ba05b07912a44ea2bf81ce409380049c" | 
|  | 3272 |  | 
|  | 3273 | # Use the latest version at 26 Oct, 2013 | 
|  | 3274 | SRCREV = "9f107132a6a073cce37434ca9cda6917dd8d866b" | 
|  | 3275 | SRC_URI = "git://git.infradead.org/mtd-utils.git \ | 
|  | 3276 | file://add-exclusion-to-mkfs-jffs2-git-2.patch \ | 
|  | 3277 | " | 
|  | 3278 |  | 
|  | 3279 | PV = "1.5.1+git${SRCPV}" | 
|  | 3280 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 3281 | S = "${WORKDIR}/git" | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 3282 |  | 
|  | 3283 | EXTRA_OEMAKE = "'CC=${CC}' 'RANLIB=${RANLIB}' 'AR=${AR}' 'CFLAGS=${CFLAGS} -I${S}/include -DWITHOUT_XATTR' 'BUILDDIR=${S}'" | 
|  | 3284 |  | 
|  | 3285 | do_install () { | 
|  | 3286 | oe_runmake install DESTDIR=${D} SBINDIR=${sbindir} MANDIR=${mandir} INCLUDEDIR=${includedir} | 
|  | 3287 | } | 
|  | 3288 |  | 
|  | 3289 | PACKAGES =+ "mtd-utils-jffs2 mtd-utils-ubifs mtd-utils-misc" | 
|  | 3290 |  | 
|  | 3291 | FILES_mtd-utils-jffs2 = "${sbindir}/mkfs.jffs2 ${sbindir}/jffs2dump ${sbindir}/jffs2reader ${sbindir}/sumtool" | 
|  | 3292 | FILES_mtd-utils-ubifs = "${sbindir}/mkfs.ubifs ${sbindir}/ubi*" | 
|  | 3293 | FILES_mtd-utils-misc = "${sbindir}/nftl* ${sbindir}/ftl* ${sbindir}/rfd* ${sbindir}/doc* ${sbindir}/serve_image ${sbindir}/recv_image" | 
|  | 3294 |  | 
|  | 3295 | PARALLEL_MAKE = "" | 
|  | 3296 |  | 
|  | 3297 | BBCLASSEXTEND = "native" | 
|  | 3298 | </literallayout> | 
|  | 3299 | </para> | 
|  | 3300 | </section> | 
|  | 3301 |  | 
|  | 3302 | <section id='splitting-an-application-into-multiple-packages'> | 
|  | 3303 | <title>Splitting an Application into Multiple Packages</title> | 
|  | 3304 |  | 
|  | 3305 | <para> | 
|  | 3306 | You can use the variables | 
|  | 3307 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'>PACKAGES</ulink></filename> and | 
|  | 3308 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'>FILES</ulink></filename> | 
|  | 3309 | to split an application into multiple packages. | 
|  | 3310 | </para> | 
|  | 3311 |  | 
|  | 3312 | <para> | 
|  | 3313 | Following is an example that uses the <filename>libxpm</filename> recipe. | 
|  | 3314 | By default, this recipe generates a single package that contains the library along | 
|  | 3315 | with a few binaries. | 
|  | 3316 | You can modify the recipe to split the binaries into separate packages: | 
|  | 3317 | <literallayout class='monospaced'> | 
|  | 3318 | require xorg-lib-common.inc | 
|  | 3319 |  | 
|  | 3320 | SUMMARY = "Xpm: X Pixmap extension library" | 
|  | 3321 | LICENSE = "BSD" | 
|  | 3322 | LIC_FILES_CHKSUM = "file://COPYING;md5=51f4270b012ecd4ab1a164f5f4ed6cf7" | 
|  | 3323 | DEPENDS += "libxext libsm libxt" | 
|  | 3324 | PE = "1" | 
|  | 3325 |  | 
|  | 3326 | XORG_PN = "libXpm" | 
|  | 3327 |  | 
|  | 3328 | PACKAGES =+ "sxpm cxpm" | 
|  | 3329 | FILES_cxpm = "${bindir}/cxpm" | 
|  | 3330 | FILES_sxpm = "${bindir}/sxpm" | 
|  | 3331 | </literallayout> | 
|  | 3332 | </para> | 
|  | 3333 |  | 
|  | 3334 | <para> | 
|  | 3335 | In the previous example, we want to ship the <filename>sxpm</filename> | 
|  | 3336 | and <filename>cxpm</filename> binaries in separate packages. | 
|  | 3337 | Since <filename>bindir</filename> would be packaged into the main | 
|  | 3338 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'>PN</ulink></filename> | 
|  | 3339 | package by default, we prepend the <filename>PACKAGES</filename> | 
|  | 3340 | variable so additional package names are added to the start of list. | 
|  | 3341 | This results in the extra <filename>FILES_*</filename> | 
|  | 3342 | variables then containing information that define which files and | 
|  | 3343 | directories go into which packages. | 
|  | 3344 | Files included by earlier packages are skipped by latter packages. | 
|  | 3345 | Thus, the main <filename>PN</filename> package | 
|  | 3346 | does not include the above listed files. | 
|  | 3347 | </para> | 
|  | 3348 | </section> | 
|  | 3349 |  | 
|  | 3350 | <section id='packaging-externally-produced-binaries'> | 
|  | 3351 | <title>Packaging Externally Produced Binaries</title> | 
|  | 3352 |  | 
|  | 3353 | <para> | 
|  | 3354 | Sometimes, you need to add pre-compiled binaries to an | 
|  | 3355 | image. | 
|  | 3356 | For example, suppose that binaries for proprietary code | 
|  | 3357 | exist, which are created by a particular division of a | 
|  | 3358 | company. | 
|  | 3359 | Your part of the company needs to use those binaries as | 
|  | 3360 | part of an image that you are building using the | 
|  | 3361 | OpenEmbedded build system. | 
|  | 3362 | Since you only have the binaries and not the source code, | 
|  | 3363 | you cannot use a typical recipe that expects to fetch the | 
|  | 3364 | source specified in | 
|  | 3365 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> | 
|  | 3366 | and then compile it. | 
|  | 3367 | </para> | 
|  | 3368 |  | 
|  | 3369 | <para> | 
|  | 3370 | One method is to package the binaries and then install them | 
|  | 3371 | as part of the image. | 
|  | 3372 | Generally, it is not a good idea to package binaries | 
|  | 3373 | since, among other things, it can hinder the ability to | 
|  | 3374 | reproduce builds and could lead to compatibility problems | 
|  | 3375 | with ABI in the future. | 
|  | 3376 | However, sometimes you have no choice. | 
|  | 3377 | </para> | 
|  | 3378 |  | 
|  | 3379 | <para> | 
|  | 3380 | The easiest solution is to create a recipe that uses | 
|  | 3381 | the | 
|  | 3382 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-bin-package'><filename>bin_package</filename></ulink> | 
|  | 3383 | class and to be sure that you are using default locations | 
|  | 3384 | for build artifacts. | 
|  | 3385 | In most cases, the <filename>bin_package</filename> class | 
|  | 3386 | handles "skipping" the configure and compile steps as well | 
|  | 3387 | as sets things up to grab packages from the appropriate | 
|  | 3388 | area. | 
|  | 3389 | In particular, this class sets <filename>noexec</filename> | 
|  | 3390 | on both the | 
|  | 3391 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink> | 
|  | 3392 | and | 
|  | 3393 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink> | 
|  | 3394 | tasks, sets | 
|  | 3395 | <filename>FILES_${PN}</filename> to "/" so that it picks | 
|  | 3396 | up all files, and sets up a | 
|  | 3397 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink> | 
|  | 3398 | task, which effectively copies all files from | 
|  | 3399 | <filename>${S}</filename> to <filename>${D}</filename>. | 
|  | 3400 | The <filename>bin_package</filename> class works well when | 
|  | 3401 | the files extracted into <filename>${S}</filename> are | 
|  | 3402 | already laid out in the way they should be laid out | 
|  | 3403 | on the target. | 
|  | 3404 | For more information on these variables, see the | 
|  | 3405 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink>, | 
|  | 3406 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>, | 
|  | 3407 | <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>, | 
|  | 3408 | and | 
|  | 3409 | <ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink> | 
|  | 3410 | variables in the Yocto Project Reference Manual's variable | 
|  | 3411 | glossary. | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 3412 | <note><title>Notes</title> | 
|  | 3413 | <itemizedlist> | 
|  | 3414 | <listitem><para> | 
|  | 3415 | Using | 
|  | 3416 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink> | 
|  | 3417 | is a good idea even for components distributed | 
|  | 3418 | in binary form, and is often necessary for | 
|  | 3419 | shared libraries. | 
|  | 3420 | For a shared library, listing the library | 
|  | 3421 | dependencies in | 
|  | 3422 | <filename>DEPENDS</filename> makes sure that | 
|  | 3423 | the libraries are available in the staging | 
|  | 3424 | sysroot when other recipes link against the | 
|  | 3425 | library, which might be necessary for | 
|  | 3426 | successful linking. | 
|  | 3427 | </para></listitem> | 
|  | 3428 | <listitem><para> | 
|  | 3429 | Using <filename>DEPENDS</filename> also | 
|  | 3430 | allows runtime dependencies between packages | 
|  | 3431 | to be added automatically. | 
|  | 3432 | See the | 
|  | 3433 | "<ulink url='&YOCTO_DOCS_REF_URL;#automatically-added-runtime-dependencies'>Automatically Added Runtime Dependencies</ulink>" | 
|  | 3434 | section in the Yocto Project Reference Manual | 
|  | 3435 | for more information. | 
|  | 3436 | </para></listitem> | 
|  | 3437 | </itemizedlist> | 
|  | 3438 | </note> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 3439 | </para> | 
|  | 3440 |  | 
|  | 3441 | <para> | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 3442 | If you cannot use the <filename>bin_package</filename> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 3443 | class, you need to be sure you are doing the following: | 
|  | 3444 | <itemizedlist> | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 3445 | <listitem><para> | 
|  | 3446 | Create a recipe where the | 
|  | 3447 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-configure'><filename>do_configure</filename></ulink> | 
|  | 3448 | and | 
|  | 3449 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile</filename></ulink> | 
|  | 3450 | tasks do nothing: | 
|  | 3451 | It is usually sufficient to just not define these | 
|  | 3452 | tasks in the recipe, because the default | 
|  | 3453 | implementations do nothing unless a Makefile is | 
|  | 3454 | found in | 
|  | 3455 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>. | 
|  | 3456 | </para> | 
|  | 3457 |  | 
|  | 3458 | <para>If | 
|  | 3459 | <filename>${S}</filename> might contain a Makefile, | 
|  | 3460 | or if you inherit some class that replaces | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 3461 | <filename>do_configure</filename> and | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 3462 | <filename>do_compile</filename> with custom | 
|  | 3463 | versions, then you can use the | 
|  | 3464 | <filename>[</filename><ulink url='&YOCTO_DOCS_BB_URL;#variable-flags'><filename>noexec</filename></ulink><filename>]</filename> | 
|  | 3465 | flag to turn the tasks into no-ops, as follows: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 3466 | <literallayout class='monospaced'> | 
|  | 3467 | do_configure[noexec] = "1" | 
|  | 3468 | do_compile[noexec] = "1" | 
|  | 3469 | </literallayout> | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 3470 | Unlike | 
|  | 3471 | <ulink url='&YOCTO_DOCS_BB_URL;#deleting-a-task'><filename>deleting the tasks</filename></ulink>, | 
|  | 3472 | using the flag preserves the dependency chain from | 
|  | 3473 | the | 
|  | 3474 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-fetch'><filename>do_fetch</filename></ulink>,                     <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-unpack'><filename>do_unpack</filename></ulink>, | 
|  | 3475 | and | 
|  | 3476 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink> | 
|  | 3477 | tasks to the | 
|  | 3478 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-install'><filename>do_install</filename></ulink> | 
|  | 3479 | task. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 3480 | </para></listitem> | 
|  | 3481 | <listitem><para>Make sure your | 
|  | 3482 | <filename>do_install</filename> task installs the | 
|  | 3483 | binaries appropriately. | 
|  | 3484 | </para></listitem> | 
|  | 3485 | <listitem><para>Ensure that you set up | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 3486 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES</filename></ulink> | 
|  | 3487 | (usually | 
|  | 3488 | <filename>FILES_${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink><filename>}</filename>) | 
|  | 3489 | to point to the files you have installed, which of | 
|  | 3490 | course depends on where you have installed them | 
|  | 3491 | and whether those files are in different locations | 
|  | 3492 | than the defaults. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 3493 | </para></listitem> | 
|  | 3494 | </itemizedlist> | 
|  | 3495 | </para> | 
|  | 3496 | </section> | 
|  | 3497 | </section> | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 3498 |  | 
|  | 3499 | <section id="following-recipe-style-guidelines"> | 
|  | 3500 | <title>Following Recipe Style Guidelines</title> | 
|  | 3501 |  | 
|  | 3502 | <para> | 
|  | 3503 | When writing recipes, it is good to conform to existing | 
|  | 3504 | style guidelines. | 
|  | 3505 | The | 
|  | 3506 | <ulink url='http://www.openembedded.org/wiki/Styleguide'>OpenEmbedded Styleguide</ulink> | 
|  | 3507 | wiki page provides rough guidelines for preferred recipe style. | 
|  | 3508 | </para> | 
|  | 3509 |  | 
|  | 3510 | <para> | 
|  | 3511 | It is common for existing recipes to deviate a bit from this | 
|  | 3512 | style. | 
|  | 3513 | However, aiming for at least a consistent style is a good idea. | 
|  | 3514 | Some practices, such as omitting spaces around | 
|  | 3515 | <filename>=</filename> operators in assignments or ordering | 
|  | 3516 | recipe components in an erratic way, are widely seen as poor | 
|  | 3517 | style. | 
|  | 3518 | </para> | 
|  | 3519 | </section> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 3520 | </section> | 
|  | 3521 |  | 
|  | 3522 | <section id="platdev-newmachine"> | 
|  | 3523 | <title>Adding a New Machine</title> | 
|  | 3524 |  | 
|  | 3525 | <para> | 
|  | 3526 | Adding a new machine to the Yocto Project is a straightforward | 
|  | 3527 | process. | 
|  | 3528 | This section describes how to add machines that are similar | 
|  | 3529 | to those that the Yocto Project already supports. | 
|  | 3530 | <note> | 
|  | 3531 | Although well within the capabilities of the Yocto Project, | 
|  | 3532 | adding a totally new architecture might require | 
|  | 3533 | changes to <filename>gcc/glibc</filename> and to the site | 
|  | 3534 | information, which is beyond the scope of this manual. | 
|  | 3535 | </note> | 
|  | 3536 | </para> | 
|  | 3537 |  | 
|  | 3538 | <para> | 
|  | 3539 | For a complete example that shows how to add a new machine, | 
|  | 3540 | see the | 
|  | 3541 | "<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>" | 
|  | 3542 | section in the Yocto Project Board Support Package (BSP) Developer's Guide. | 
|  | 3543 | </para> | 
|  | 3544 |  | 
|  | 3545 | <section id="platdev-newmachine-conffile"> | 
|  | 3546 | <title>Adding the Machine Configuration File</title> | 
|  | 3547 |  | 
|  | 3548 | <para> | 
|  | 3549 | To add a new machine, you need to add a new machine | 
|  | 3550 | configuration file to the layer's | 
|  | 3551 | <filename>conf/machine</filename> directory. | 
|  | 3552 | This configuration file provides details about the device | 
|  | 3553 | you are adding. | 
|  | 3554 | </para> | 
|  | 3555 |  | 
|  | 3556 | <para> | 
|  | 3557 | The OpenEmbedded build system uses the root name of the | 
|  | 3558 | machine configuration file to reference the new machine. | 
|  | 3559 | For example, given a machine configuration file named | 
|  | 3560 | <filename>crownbay.conf</filename>, the build system | 
|  | 3561 | recognizes the machine as "crownbay". | 
|  | 3562 | </para> | 
|  | 3563 |  | 
|  | 3564 | <para> | 
|  | 3565 | The most important variables you must set in your machine | 
|  | 3566 | configuration file or include from a lower-level configuration | 
|  | 3567 | file are as follows: | 
|  | 3568 | <itemizedlist> | 
|  | 3569 | <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TARGET_ARCH'>TARGET_ARCH</ulink></filename> | 
|  | 3570 | (e.g. "arm")</para></listitem> | 
|  | 3571 | <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PREFERRED_PROVIDER'>PREFERRED_PROVIDER</ulink>_virtual/kernel</filename> | 
|  | 3572 | </para></listitem> | 
|  | 3573 | <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES'>MACHINE_FEATURES</ulink></filename> | 
|  | 3574 | (e.g. "apm screen wifi")</para></listitem> | 
|  | 3575 | </itemizedlist> | 
|  | 3576 | </para> | 
|  | 3577 |  | 
|  | 3578 | <para> | 
|  | 3579 | You might also need these variables: | 
|  | 3580 | <itemizedlist> | 
|  | 3581 | <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SERIAL_CONSOLES'>SERIAL_CONSOLES</ulink></filename> | 
|  | 3582 | (e.g. "115200;ttyS0 115200;ttyS1")</para></listitem> | 
|  | 3583 | <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_IMAGETYPE'>KERNEL_IMAGETYPE</ulink></filename> | 
|  | 3584 | (e.g. "zImage")</para></listitem> | 
|  | 3585 | <listitem><para><filename><ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FSTYPES'>IMAGE_FSTYPES</ulink></filename> | 
|  | 3586 | (e.g. "tar.gz jffs2")</para></listitem> | 
|  | 3587 | </itemizedlist> | 
|  | 3588 | </para> | 
|  | 3589 |  | 
|  | 3590 | <para> | 
|  | 3591 | You can find full details on these variables in the reference | 
|  | 3592 | section. | 
|  | 3593 | You can leverage existing machine <filename>.conf</filename> | 
|  | 3594 | files from <filename>meta-yocto-bsp/conf/machine/</filename>. | 
|  | 3595 | </para> | 
|  | 3596 | </section> | 
|  | 3597 |  | 
|  | 3598 | <section id="platdev-newmachine-kernel"> | 
|  | 3599 | <title>Adding a Kernel for the Machine</title> | 
|  | 3600 |  | 
|  | 3601 | <para> | 
|  | 3602 | The OpenEmbedded build system needs to be able to build a kernel | 
|  | 3603 | for the machine. | 
|  | 3604 | You need to either create a new kernel recipe for this machine, | 
|  | 3605 | or extend an existing kernel recipe. | 
|  | 3606 | You can find several kernel recipe examples in the | 
|  | 3607 | Source Directory at | 
|  | 3608 | <filename>meta/recipes-kernel/linux</filename> | 
|  | 3609 | that you can use as references. | 
|  | 3610 | </para> | 
|  | 3611 |  | 
|  | 3612 | <para> | 
|  | 3613 | If you are creating a new kernel recipe, normal recipe-writing | 
|  | 3614 | rules apply for setting up a | 
|  | 3615 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename>. | 
|  | 3616 | Thus, you need to specify any necessary patches and set | 
|  | 3617 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'>S</ulink></filename> | 
|  | 3618 | to point at the source code. | 
|  | 3619 | You need to create a <filename>do_configure</filename> task that | 
|  | 3620 | configures the unpacked kernel with a | 
|  | 3621 | <filename>defconfig</filename> file. | 
|  | 3622 | You can do this by using a <filename>make defconfig</filename> | 
|  | 3623 | command or, more commonly, by copying in a suitable | 
|  | 3624 | <filename>defconfig</filename> file and then running | 
|  | 3625 | <filename>make oldconfig</filename>. | 
|  | 3626 | By making use of <filename>inherit kernel</filename> and | 
|  | 3627 | potentially some of the <filename>linux-*.inc</filename> files, | 
|  | 3628 | most other functionality is centralized and the defaults of the | 
|  | 3629 | class normally work well. | 
|  | 3630 | </para> | 
|  | 3631 |  | 
|  | 3632 | <para> | 
|  | 3633 | If you are extending an existing kernel recipe, it is usually | 
|  | 3634 | a matter of adding a suitable <filename>defconfig</filename> | 
|  | 3635 | file. | 
|  | 3636 | The file needs to be added into a location similar to | 
|  | 3637 | <filename>defconfig</filename> files used for other machines | 
|  | 3638 | in a given kernel recipe. | 
|  | 3639 | A possible way to do this is by listing the file in the | 
|  | 3640 | <filename>SRC_URI</filename> and adding the machine to the | 
|  | 3641 | expression in | 
|  | 3642 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-COMPATIBLE_MACHINE'>COMPATIBLE_MACHINE</ulink></filename>: | 
|  | 3643 | <literallayout class='monospaced'> | 
|  | 3644 | COMPATIBLE_MACHINE = '(qemux86|qemumips)' | 
|  | 3645 | </literallayout> | 
|  | 3646 | For more information on <filename>defconfig</filename> files, | 
|  | 3647 | see the | 
|  | 3648 | "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#changing-the-configuration'>Changing the Configuration</ulink>" | 
|  | 3649 | section in the Yocto Project Linux Kernel Development Manual. | 
|  | 3650 | </para> | 
|  | 3651 | </section> | 
|  | 3652 |  | 
|  | 3653 | <section id="platdev-newmachine-formfactor"> | 
|  | 3654 | <title>Adding a Formfactor Configuration File</title> | 
|  | 3655 |  | 
|  | 3656 | <para> | 
|  | 3657 | A formfactor configuration file provides information about the | 
|  | 3658 | target hardware for which the image is being built and information that | 
|  | 3659 | the build system cannot obtain from other sources such as the kernel. | 
|  | 3660 | Some examples of information contained in a formfactor configuration file include | 
|  | 3661 | framebuffer orientation, whether or not the system has a keyboard, | 
|  | 3662 | the positioning of the keyboard in relation to the screen, and | 
|  | 3663 | the screen resolution. | 
|  | 3664 | </para> | 
|  | 3665 |  | 
|  | 3666 | <para> | 
|  | 3667 | The build system uses reasonable defaults in most cases. | 
|  | 3668 | However, if customization is | 
|  | 3669 | necessary, you need to create a <filename>machconfig</filename> file | 
|  | 3670 | in the <filename>meta/recipes-bsp/formfactor/files</filename> | 
|  | 3671 | directory. | 
|  | 3672 | This directory contains directories for specific machines such as | 
|  | 3673 | <filename>qemuarm</filename> and <filename>qemux86</filename>. | 
|  | 3674 | For information about the settings available and the defaults, see the | 
|  | 3675 | <filename>meta/recipes-bsp/formfactor/files/config</filename> file found in the | 
|  | 3676 | same area. | 
|  | 3677 | </para> | 
|  | 3678 |  | 
|  | 3679 | <para> | 
|  | 3680 | Following is an example for "qemuarm" machine: | 
|  | 3681 | <literallayout class='monospaced'> | 
|  | 3682 | HAVE_TOUCHSCREEN=1 | 
|  | 3683 | HAVE_KEYBOARD=1 | 
|  | 3684 |  | 
|  | 3685 | DISPLAY_CAN_ROTATE=0 | 
|  | 3686 | DISPLAY_ORIENTATION=0 | 
|  | 3687 | #DISPLAY_WIDTH_PIXELS=640 | 
|  | 3688 | #DISPLAY_HEIGHT_PIXELS=480 | 
|  | 3689 | #DISPLAY_BPP=16 | 
|  | 3690 | DISPLAY_DPI=150 | 
|  | 3691 | DISPLAY_SUBPIXEL_ORDER=vrgb | 
|  | 3692 | </literallayout> | 
|  | 3693 | </para> | 
|  | 3694 | </section> | 
|  | 3695 | </section> | 
|  | 3696 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 3697 | <section id='finding-the-temporary-source-code'> | 
|  | 3698 | <title>Finding Temporary Source Code</title> | 
|  | 3699 |  | 
|  | 3700 | <para> | 
|  | 3701 | You might find it helpful during development to modify the | 
|  | 3702 | temporary source code used by recipes to build packages. | 
|  | 3703 | For example, suppose you are developing a patch and you need to | 
|  | 3704 | experiment a bit to figure out your solution. | 
|  | 3705 | After you have initially built the package, you can iteratively | 
|  | 3706 | tweak the source code, which is located in the | 
|  | 3707 | <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>, | 
|  | 3708 | and then you can force a re-compile and quickly test your altered | 
|  | 3709 | code. | 
|  | 3710 | Once you settle on a solution, you can then preserve your changes | 
|  | 3711 | in the form of patches. | 
|  | 3712 | </para> | 
|  | 3713 |  | 
|  | 3714 | <para> | 
|  | 3715 | During a build, the unpacked temporary source code used by recipes | 
|  | 3716 | to build packages is available in the Build Directory as | 
|  | 3717 | defined by the | 
|  | 3718 | <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink> | 
|  | 3719 | variable. | 
|  | 3720 | Below is the default value for the <filename>S</filename> variable | 
|  | 3721 | as defined in the | 
|  | 3722 | <filename>meta/conf/bitbake.conf</filename> configuration file | 
|  | 3723 | in the | 
|  | 3724 | <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>: | 
|  | 3725 | <literallayout class='monospaced'> | 
|  | 3726 | S = "${WORKDIR}/${BP}" | 
|  | 3727 | </literallayout> | 
|  | 3728 | You should be aware that many recipes override the | 
|  | 3729 | <filename>S</filename> variable. | 
|  | 3730 | For example, recipes that fetch their source from Git usually set | 
|  | 3731 | <filename>S</filename> to <filename>${WORKDIR}/git</filename>. | 
|  | 3732 | <note> | 
|  | 3733 | The | 
|  | 3734 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BP'><filename>BP</filename></ulink> | 
|  | 3735 | represents the base recipe name, which consists of the name | 
|  | 3736 | and version: | 
|  | 3737 | <literallayout class='monospaced'> | 
|  | 3738 | BP = "${BPN}-${PV}" | 
|  | 3739 | </literallayout> | 
|  | 3740 | </note> | 
|  | 3741 | </para> | 
|  | 3742 |  | 
|  | 3743 | <para> | 
|  | 3744 | The path to the work directory for the recipe | 
|  | 3745 | (<ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink>) | 
|  | 3746 | is defined as follows: | 
|  | 3747 | <literallayout class='monospaced'> | 
|  | 3748 | ${TMPDIR}/work/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR} | 
|  | 3749 | </literallayout> | 
|  | 3750 | The actual directory depends on several things: | 
|  | 3751 | <itemizedlist> | 
|  | 3752 | <listitem><para> | 
|  | 3753 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink>: | 
|  | 3754 | The top-level build output directory. | 
|  | 3755 | </para></listitem> | 
|  | 3756 | <listitem><para> | 
|  | 3757 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MULTIMACH_TARGET_SYS'><filename>MULTIMACH_TARGET_SYS</filename></ulink>: | 
|  | 3758 | The target system identifier. | 
|  | 3759 | </para></listitem> | 
|  | 3760 | <listitem><para> | 
|  | 3761 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink>: | 
|  | 3762 | The recipe name. | 
|  | 3763 | </para></listitem> | 
|  | 3764 | <listitem><para> | 
|  | 3765 | <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTENDPE'><filename>EXTENDPE</filename></ulink>: | 
|  | 3766 | The epoch - (if | 
|  | 3767 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PE'><filename>PE</filename></ulink> | 
|  | 3768 | is not specified, which is usually the case for most | 
|  | 3769 | recipes, then <filename>EXTENDPE</filename> is blank). | 
|  | 3770 | </para></listitem> | 
|  | 3771 | <listitem><para> | 
|  | 3772 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>: | 
|  | 3773 | The recipe version. | 
|  | 3774 | </para></listitem> | 
|  | 3775 | <listitem><para> | 
|  | 3776 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>: | 
|  | 3777 | The recipe revision. | 
|  | 3778 | </para></listitem> | 
|  | 3779 | </itemizedlist> | 
|  | 3780 | </para> | 
|  | 3781 |  | 
|  | 3782 | <para> | 
|  | 3783 | As an example, assume a Source Directory top-level folder | 
|  | 3784 | named <filename>poky</filename>, a default Build Directory at | 
|  | 3785 | <filename>poky/build</filename>, and a | 
|  | 3786 | <filename>qemux86-poky-linux</filename> machine target | 
|  | 3787 | system. | 
|  | 3788 | Furthermore, suppose your recipe is named | 
|  | 3789 | <filename>foo_1.3.0.bb</filename>. | 
|  | 3790 | In this case, the work directory the build system uses to | 
|  | 3791 | build the package would be as follows: | 
|  | 3792 | <literallayout class='monospaced'> | 
|  | 3793 | poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0 | 
|  | 3794 | </literallayout> | 
|  | 3795 | </para> | 
|  | 3796 | </section> | 
|  | 3797 |  | 
|  | 3798 | <section id="using-a-quilt-workflow"> | 
|  | 3799 | <title>Using Quilt in Your Workflow</title> | 
|  | 3800 |  | 
|  | 3801 | <para> | 
|  | 3802 | <ulink url='http://savannah.nongnu.org/projects/quilt'>Quilt</ulink> | 
|  | 3803 | is a powerful tool that allows you to capture source code changes | 
|  | 3804 | without having a clean source tree. | 
|  | 3805 | This section outlines the typical workflow you can use to modify | 
|  | 3806 | source code, test changes, and then preserve the changes in the | 
|  | 3807 | form of a patch all using Quilt. | 
|  | 3808 | <note><title>Tip</title> | 
|  | 3809 | With regard to preserving changes to source files, if you | 
|  | 3810 | clean a recipe or have <filename>rm_work</filename> enabled, | 
|  | 3811 | the | 
|  | 3812 | <ulink url='&YOCTO_DOCS_SDK_URL;#using-devtool-in-your-sdk-workflow'><filename>devtool</filename> workflow</ulink> | 
|  | 3813 | as described in the Yocto Project Application Development | 
|  | 3814 | and the Extensible Software Development Kit (eSDK) manual | 
|  | 3815 | is a safer development flow than the flow that uses Quilt. | 
|  | 3816 | </note> | 
|  | 3817 | </para> | 
|  | 3818 |  | 
|  | 3819 | <para> | 
|  | 3820 | Follow these general steps: | 
|  | 3821 | <orderedlist> | 
|  | 3822 | <listitem><para> | 
|  | 3823 | <emphasis>Find the Source Code:</emphasis> | 
|  | 3824 | Temporary source code used by the OpenEmbedded build system | 
|  | 3825 | is kept in the | 
|  | 3826 | <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>. | 
|  | 3827 | See the | 
|  | 3828 | "<link linkend='finding-the-temporary-source-code'>Finding Temporary Source Code</link>" | 
|  | 3829 | section to learn how to locate the directory that has the | 
|  | 3830 | temporary source code for a particular package. | 
|  | 3831 | </para></listitem> | 
|  | 3832 | <listitem><para> | 
|  | 3833 | <emphasis>Change Your Working Directory:</emphasis> | 
|  | 3834 | You need to be in the directory that has the temporary | 
|  | 3835 | source code. | 
|  | 3836 | That directory is defined by the | 
|  | 3837 | <ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink> | 
|  | 3838 | variable.</para></listitem> | 
|  | 3839 | <listitem><para> | 
|  | 3840 | <emphasis>Create a New Patch:</emphasis> | 
|  | 3841 | Before modifying source code, you need to create a new | 
|  | 3842 | patch. | 
|  | 3843 | To create a new patch file, use | 
|  | 3844 | <filename>quilt new</filename> as below: | 
|  | 3845 | <literallayout class='monospaced'> | 
|  | 3846 | $ quilt new my_changes.patch | 
|  | 3847 | </literallayout> | 
|  | 3848 | </para></listitem> | 
|  | 3849 | <listitem><para> | 
|  | 3850 | <emphasis>Notify Quilt and Add Files:</emphasis> | 
|  | 3851 | After creating the patch, you need to notify Quilt about | 
|  | 3852 | the files you plan to edit. | 
|  | 3853 | You notify Quilt by adding the files to the patch you | 
|  | 3854 | just created: | 
|  | 3855 | <literallayout class='monospaced'> | 
|  | 3856 | $ quilt add file1.c file2.c file3.c | 
|  | 3857 | </literallayout> | 
|  | 3858 | </para></listitem> | 
|  | 3859 | <listitem><para> | 
|  | 3860 | <emphasis>Edit the Files:</emphasis> | 
|  | 3861 | Make your changes in the source code to the files you added | 
|  | 3862 | to the patch. | 
|  | 3863 | </para></listitem> | 
|  | 3864 | <listitem><para> | 
|  | 3865 | <emphasis>Test Your Changes:</emphasis> | 
|  | 3866 | Once you have modified the source code, the easiest way to | 
|  | 3867 | test your changes is by calling the | 
|  | 3868 | <filename>do_compile</filename> task as shown in the | 
|  | 3869 | following example: | 
|  | 3870 | <literallayout class='monospaced'> | 
|  | 3871 | $ bitbake -c compile -f <replaceable>package</replaceable> | 
|  | 3872 | </literallayout> | 
|  | 3873 | The <filename>-f</filename> or <filename>--force</filename> | 
|  | 3874 | option forces the specified task to execute. | 
|  | 3875 | If you find problems with your code, you can just keep | 
|  | 3876 | editing and re-testing iteratively until things work | 
|  | 3877 | as expected. | 
|  | 3878 | <note> | 
|  | 3879 | All the modifications you make to the temporary | 
|  | 3880 | source code disappear once you run the | 
|  | 3881 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-clean'><filename>do_clean</filename></ulink> | 
|  | 3882 | or | 
|  | 3883 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-cleanall'><filename>do_cleanall</filename></ulink> | 
|  | 3884 | tasks using BitBake (i.e. | 
|  | 3885 | <filename>bitbake -c clean <replaceable>package</replaceable></filename> | 
|  | 3886 | and | 
|  | 3887 | <filename>bitbake -c cleanall <replaceable>package</replaceable></filename>). | 
|  | 3888 | Modifications will also disappear if you use the | 
|  | 3889 | <filename>rm_work</filename> feature as described | 
|  | 3890 | in the | 
|  | 3891 | "<ulink url='&YOCTO_DOCS_QS_URL;#qs-building-images'>Building Images</ulink>" | 
|  | 3892 | section of the Yocto Project Quick Start. | 
|  | 3893 | </note> | 
|  | 3894 | </para></listitem> | 
|  | 3895 | <listitem><para> | 
|  | 3896 | <emphasis>Generate the Patch:</emphasis> | 
|  | 3897 | Once your changes work as expected, you need to use Quilt | 
|  | 3898 | to generate the final patch that contains all your | 
|  | 3899 | modifications. | 
|  | 3900 | <literallayout class='monospaced'> | 
|  | 3901 | $ quilt refresh | 
|  | 3902 | </literallayout> | 
|  | 3903 | At this point, the <filename>my_changes.patch</filename> | 
|  | 3904 | file has all your edits made to the | 
|  | 3905 | <filename>file1.c</filename>, <filename>file2.c</filename>, | 
|  | 3906 | and <filename>file3.c</filename> files.</para> | 
|  | 3907 |  | 
|  | 3908 | <para>You can find the resulting patch file in the | 
|  | 3909 | <filename>patches/</filename> subdirectory of the source | 
|  | 3910 | (<filename>S</filename>) directory. | 
|  | 3911 | </para></listitem> | 
|  | 3912 | <listitem><para> | 
|  | 3913 | <emphasis>Copy the Patch File:</emphasis> | 
|  | 3914 | For simplicity, copy the patch file into a directory | 
|  | 3915 | named <filename>files</filename>, which you can create | 
|  | 3916 | in the same directory that holds the recipe | 
|  | 3917 | (<filename>.bb</filename>) file or the append | 
|  | 3918 | (<filename>.bbappend</filename>) file. | 
|  | 3919 | Placing the patch here guarantees that the OpenEmbedded | 
|  | 3920 | build system will find the patch. | 
|  | 3921 | Next, add the patch into the | 
|  | 3922 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'>SRC_URI</ulink></filename> | 
|  | 3923 | of the recipe. | 
|  | 3924 | Here is an example: | 
|  | 3925 | <literallayout class='monospaced'> | 
|  | 3926 | SRC_URI += "file://my_changes.patch" | 
|  | 3927 | </literallayout> | 
|  | 3928 | </para></listitem> | 
|  | 3929 | </orderedlist> | 
|  | 3930 | </para> | 
|  | 3931 | </section> | 
|  | 3932 |  | 
|  | 3933 | <section id="platdev-appdev-devshell"> | 
|  | 3934 | <title>Using a Development Shell</title> | 
|  | 3935 |  | 
|  | 3936 | <para> | 
|  | 3937 | When debugging certain commands or even when just editing packages, | 
|  | 3938 | <filename>devshell</filename> can be a useful tool. | 
|  | 3939 | When you invoke <filename>devshell</filename>, all tasks up to and | 
|  | 3940 | including | 
|  | 3941 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink> | 
|  | 3942 | are run for the specified target. | 
|  | 3943 | Then, a new terminal is opened and you are placed in | 
|  | 3944 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink><filename>}</filename>, | 
|  | 3945 | the source directory. | 
|  | 3946 | In the new terminal, all the OpenEmbedded build-related environment variables are | 
|  | 3947 | still defined so you can use commands such as <filename>configure</filename> and | 
|  | 3948 | <filename>make</filename>. | 
|  | 3949 | The commands execute just as if the OpenEmbedded build system were executing them. | 
|  | 3950 | Consequently, working this way can be helpful when debugging a build or preparing | 
|  | 3951 | software to be used with the OpenEmbedded build system. | 
|  | 3952 | </para> | 
|  | 3953 |  | 
|  | 3954 | <para> | 
|  | 3955 | Following is an example that uses <filename>devshell</filename> on a target named | 
|  | 3956 | <filename>matchbox-desktop</filename>: | 
|  | 3957 | <literallayout class='monospaced'> | 
|  | 3958 | $ bitbake matchbox-desktop -c devshell | 
|  | 3959 | </literallayout> | 
|  | 3960 | </para> | 
|  | 3961 |  | 
|  | 3962 | <para> | 
|  | 3963 | This command spawns a terminal with a shell prompt within the OpenEmbedded build environment. | 
|  | 3964 | The <ulink url='&YOCTO_DOCS_REF_URL;#var-OE_TERMINAL'><filename>OE_TERMINAL</filename></ulink> | 
|  | 3965 | variable controls what type of shell is opened. | 
|  | 3966 | </para> | 
|  | 3967 |  | 
|  | 3968 | <para> | 
|  | 3969 | For spawned terminals, the following occurs: | 
|  | 3970 | <itemizedlist> | 
|  | 3971 | <listitem><para>The <filename>PATH</filename> variable includes the | 
|  | 3972 | cross-toolchain.</para></listitem> | 
|  | 3973 | <listitem><para>The <filename>pkgconfig</filename> variables find the correct | 
|  | 3974 | <filename>.pc</filename> files.</para></listitem> | 
|  | 3975 | <listitem><para>The <filename>configure</filename> command finds the | 
|  | 3976 | Yocto Project site files as well as any other necessary files.</para></listitem> | 
|  | 3977 | </itemizedlist> | 
|  | 3978 | </para> | 
|  | 3979 |  | 
|  | 3980 | <para> | 
|  | 3981 | Within this environment, you can run configure or compile | 
|  | 3982 | commands as if they were being run by | 
|  | 3983 | the OpenEmbedded build system itself. | 
|  | 3984 | As noted earlier, the working directory also automatically changes to the | 
|  | 3985 | Source Directory (<ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>). | 
|  | 3986 | </para> | 
|  | 3987 |  | 
|  | 3988 | <para> | 
|  | 3989 | To manually run a specific task using <filename>devshell</filename>, | 
|  | 3990 | run the corresponding <filename>run.*</filename> script in | 
|  | 3991 | the | 
|  | 3992 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/temp</filename> | 
|  | 3993 | directory (e.g., | 
|  | 3994 | <filename>run.do_configure.</filename><replaceable>pid</replaceable>). | 
|  | 3995 | If a task's script does not exist, which would be the case if the task was | 
|  | 3996 | skipped by way of the sstate cache, you can create the task by first running | 
|  | 3997 | it outside of the <filename>devshell</filename>: | 
|  | 3998 | <literallayout class='monospaced'> | 
|  | 3999 | $ bitbake -c <replaceable>task</replaceable> | 
|  | 4000 | </literallayout> | 
|  | 4001 | <note><title>Notes</title> | 
|  | 4002 | <itemizedlist> | 
|  | 4003 | <listitem><para>Execution of a task's <filename>run.*</filename> | 
|  | 4004 | script and BitBake's execution of a task are identical. | 
|  | 4005 | In other words, running the script re-runs the task | 
|  | 4006 | just as it would be run using the | 
|  | 4007 | <filename>bitbake -c</filename> command. | 
|  | 4008 | </para></listitem> | 
|  | 4009 | <listitem><para>Any <filename>run.*</filename> file that does not | 
|  | 4010 | have a <filename>.pid</filename> extension is a | 
|  | 4011 | symbolic link (symlink) to the most recent version of that | 
|  | 4012 | file. | 
|  | 4013 | </para></listitem> | 
|  | 4014 | </itemizedlist> | 
|  | 4015 | </note> | 
|  | 4016 | </para> | 
|  | 4017 |  | 
|  | 4018 | <para> | 
|  | 4019 | Remember, that the <filename>devshell</filename> is a mechanism that allows | 
|  | 4020 | you to get into the BitBake task execution environment. | 
|  | 4021 | And as such, all commands must be called just as BitBake would call them. | 
|  | 4022 | That means you need to provide the appropriate options for | 
|  | 4023 | cross-compilation and so forth as applicable. | 
|  | 4024 | </para> | 
|  | 4025 |  | 
|  | 4026 | <para> | 
|  | 4027 | When you are finished using <filename>devshell</filename>, exit the shell | 
|  | 4028 | or close the terminal window. | 
|  | 4029 | </para> | 
|  | 4030 |  | 
|  | 4031 | <note><title>Notes</title> | 
|  | 4032 | <itemizedlist> | 
|  | 4033 | <listitem><para> | 
|  | 4034 | It is worth remembering that when using <filename>devshell</filename> | 
|  | 4035 | you need to use the full compiler name such as <filename>arm-poky-linux-gnueabi-gcc</filename> | 
|  | 4036 | instead of just using <filename>gcc</filename>. | 
|  | 4037 | The same applies to other applications such as <filename>binutils</filename>, | 
|  | 4038 | <filename>libtool</filename> and so forth. | 
|  | 4039 | BitBake sets up environment variables such as <filename>CC</filename> | 
|  | 4040 | to assist applications, such as <filename>make</filename> to find the correct tools. | 
|  | 4041 | </para></listitem> | 
|  | 4042 | <listitem><para> | 
|  | 4043 | It is also worth noting that <filename>devshell</filename> still works over | 
|  | 4044 | X11 forwarding and similar situations. | 
|  | 4045 | </para></listitem> | 
|  | 4046 | </itemizedlist> | 
|  | 4047 | </note> | 
|  | 4048 | </section> | 
|  | 4049 |  | 
|  | 4050 | <section id="platdev-appdev-devpyshell"> | 
|  | 4051 | <title>Using a Development Python Shell</title> | 
|  | 4052 |  | 
|  | 4053 | <para> | 
|  | 4054 | Similar to working within a development shell as described in | 
|  | 4055 | the previous section, you can also spawn and work within an | 
|  | 4056 | interactive Python development shell. | 
|  | 4057 | When debugging certain commands or even when just editing packages, | 
|  | 4058 | <filename>devpyshell</filename> can be a useful tool. | 
|  | 4059 | When you invoke <filename>devpyshell</filename>, all tasks up to and | 
|  | 4060 | including | 
|  | 4061 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-patch'><filename>do_patch</filename></ulink> | 
|  | 4062 | are run for the specified target. | 
|  | 4063 | Then a new terminal is opened. | 
|  | 4064 | Additionally, key Python objects and code are available in the same | 
|  | 4065 | way they are to BitBake tasks, in particular, the data store 'd'. | 
|  | 4066 | So, commands such as the following are useful when exploring the data | 
|  | 4067 | store and running functions: | 
|  | 4068 | <literallayout class='monospaced'> | 
|  | 4069 | pydevshell> d.getVar("STAGING_DIR", True) | 
|  | 4070 | '/media/build1/poky/build/tmp/sysroots' | 
|  | 4071 | pydevshell> d.getVar("STAGING_DIR", False) | 
|  | 4072 | '${TMPDIR}/sysroots' | 
|  | 4073 | pydevshell> d.setVar("FOO", "bar") | 
|  | 4074 | pydevshell> d.getVar("FOO", True) | 
|  | 4075 | 'bar' | 
|  | 4076 | pydevshell> d.delVar("FOO") | 
|  | 4077 | pydevshell> d.getVar("FOO", True) | 
|  | 4078 | pydevshell> bb.build.exec_func("do_unpack", d) | 
|  | 4079 | pydevshell> | 
|  | 4080 | </literallayout> | 
|  | 4081 | The commands execute just as if the OpenEmbedded build system were executing them. | 
|  | 4082 | Consequently, working this way can be helpful when debugging a build or preparing | 
|  | 4083 | software to be used with the OpenEmbedded build system. | 
|  | 4084 | </para> | 
|  | 4085 |  | 
|  | 4086 | <para> | 
|  | 4087 | Following is an example that uses <filename>devpyshell</filename> on a target named | 
|  | 4088 | <filename>matchbox-desktop</filename>: | 
|  | 4089 | <literallayout class='monospaced'> | 
|  | 4090 | $ bitbake matchbox-desktop -c devpyshell | 
|  | 4091 | </literallayout> | 
|  | 4092 | </para> | 
|  | 4093 |  | 
|  | 4094 | <para> | 
|  | 4095 | This command spawns a terminal and places you in an interactive | 
|  | 4096 | Python interpreter within the OpenEmbedded build environment. | 
|  | 4097 | The <ulink url='&YOCTO_DOCS_REF_URL;#var-OE_TERMINAL'><filename>OE_TERMINAL</filename></ulink> | 
|  | 4098 | variable controls what type of shell is opened. | 
|  | 4099 | </para> | 
|  | 4100 |  | 
|  | 4101 | <para> | 
|  | 4102 | When you are finished using <filename>devpyshell</filename>, you | 
|  | 4103 | can exit the shell either by using Ctrl+d or closing the terminal | 
|  | 4104 | window. | 
|  | 4105 | </para> | 
|  | 4106 | </section> | 
|  | 4107 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 4108 | <section id='platdev-building-targets-with-multiple-configurations'> | 
|  | 4109 | <title>Building Targets with Multiple Configurations</title> | 
|  | 4110 |  | 
|  | 4111 | <para> | 
|  | 4112 | Bitbake also has functionality that allows you to build | 
|  | 4113 | multiple targets at the same time, where each target uses | 
|  | 4114 | a different configuration. | 
|  | 4115 | </para> | 
|  | 4116 |  | 
|  | 4117 | <para> | 
|  | 4118 | In order to accomplish this, you setup each of the configurations | 
|  | 4119 | you need to use in parallel by placing the configuration files in | 
|  | 4120 | your current build directory alongside the usual | 
|  | 4121 | <filename>local.conf</filename> file. | 
|  | 4122 | </para> | 
|  | 4123 |  | 
|  | 4124 | <para> | 
|  | 4125 | Follow these guidelines to create an environment that supports | 
|  | 4126 | multiple configurations: | 
|  | 4127 | <itemizedlist> | 
|  | 4128 | <listitem><para> | 
|  | 4129 | <emphasis>Create Configuration Files</emphasis>: | 
|  | 4130 | You need to create a single configuration file for each | 
|  | 4131 | configuration for which you want to add support. | 
|  | 4132 | These files would contain lines such as the following: | 
|  | 4133 | <literallayout class='monospaced'> | 
|  | 4134 | MACHINE = "A" | 
|  | 4135 | </literallayout> | 
|  | 4136 | The files would contain any other variables that can | 
|  | 4137 | be set and built in the same directory. | 
|  | 4138 | <note> | 
|  | 4139 | You can change the | 
|  | 4140 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink> | 
|  | 4141 | to not conflict. | 
|  | 4142 | </note></para> | 
|  | 4143 |  | 
|  | 4144 | <para> | 
|  | 4145 | Furthermore, the configuration file must be located in the | 
|  | 4146 | current build directory in a directory named | 
|  | 4147 | <filename>multiconfig</filename> under the build's | 
|  | 4148 | <filename>conf</filename> directory where | 
|  | 4149 | <filename>local.conf</filename> resides. | 
|  | 4150 | The reason for this restriction is because the | 
|  | 4151 | <filename>BBPATH</filename> variable is not constructed | 
|  | 4152 | until the layers are parsed. | 
|  | 4153 | Consequently, using the configuration file as a | 
|  | 4154 | pre-configuration file is not possible unless it is | 
|  | 4155 | located in the current working directory. | 
|  | 4156 | </para></listitem> | 
|  | 4157 | <listitem><para> | 
|  | 4158 | <emphasis>Add the BitBake Multi-Config Variable to you Local Configuration File</emphasis>: | 
|  | 4159 | Use the | 
|  | 4160 | <filename>BBMULTICONFIG</filename> | 
|  | 4161 | variable in your <filename>conf/local.conf</filename> | 
|  | 4162 | configuration file to specify each separate configuration. | 
|  | 4163 | For example, the following line tells BitBake it should load | 
|  | 4164 | <filename>conf/multiconfig/configA.conf</filename>, | 
|  | 4165 | <filename>conf/multiconfig/configB.conf</filename>, and | 
|  | 4166 | <filename>conf/multiconfig/configC.conf</filename>. | 
|  | 4167 | <literallayout class='monospaced'> | 
|  | 4168 | BBMULTICONFIG = "configA configB configC" | 
|  | 4169 | </literallayout> | 
|  | 4170 | </para></listitem> | 
|  | 4171 | <listitem><para> | 
|  | 4172 | <emphasis>Launch BitBake</emphasis>: | 
|  | 4173 | Use the following BitBake command form to launch the | 
|  | 4174 | build: | 
|  | 4175 | <literallayout class='monospaced'> | 
|  | 4176 | $ bitbake [multiconfig:<replaceable>multiconfigname</replaceable>:]<replaceable>target</replaceable> [[[multiconfig:<replaceable>multiconfigname</replaceable>:]<replaceable>target</replaceable>] ... ] | 
|  | 4177 | </literallayout> | 
|  | 4178 | Following is an example that supports building a minimal | 
|  | 4179 | image for configuration A alongside a standard | 
|  | 4180 | <filename>core-image-sato</filename>, which takes its | 
|  | 4181 | configuration from <filename>local.conf</filename>: | 
|  | 4182 | <literallayout class='monospaced'> | 
|  | 4183 | $ bitbake multiconfig:configA:core-image-minimal core-image-sato | 
|  | 4184 | </literallayout> | 
|  | 4185 | </para></listitem> | 
|  | 4186 | </itemizedlist> | 
|  | 4187 | </para> | 
|  | 4188 |  | 
|  | 4189 | <para> | 
|  | 4190 | Support for multiple configurations in this current release of | 
|  | 4191 | the Yocto Project (&DISTRO_NAME; &DISTRO;) has some known issues: | 
|  | 4192 | <itemizedlist> | 
|  | 4193 | <listitem><para> | 
|  | 4194 | No inter-multi-configuration dependencies exist. | 
|  | 4195 | </para></listitem> | 
|  | 4196 | <listitem><para> | 
|  | 4197 | Shared State (sstate) optimizations do not exist. | 
|  | 4198 | Consequently, if the build uses the same object twice | 
|  | 4199 | in, for example, two different | 
|  | 4200 | <filename>TMPDIR</filename> directories, the build | 
|  | 4201 | will either load from an existing sstate cache at the | 
|  | 4202 | start or build the object twice. | 
|  | 4203 | </para></listitem> | 
|  | 4204 | </itemizedlist> | 
|  | 4205 | </para> | 
|  | 4206 | </section> | 
|  | 4207 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4208 | <section id="platdev-working-with-libraries"> | 
|  | 4209 | <title>Working With Libraries</title> | 
|  | 4210 |  | 
|  | 4211 | <para> | 
|  | 4212 | Libraries are an integral part of your system. | 
|  | 4213 | This section describes some common practices you might find | 
|  | 4214 | helpful when working with libraries to build your system: | 
|  | 4215 | <itemizedlist> | 
|  | 4216 | <listitem><para><link linkend='including-static-library-files'>How to include static library files</link> | 
|  | 4217 | </para></listitem> | 
|  | 4218 | <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> | 
|  | 4219 | </para></listitem> | 
|  | 4220 | <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> | 
|  | 4221 | </para></listitem> | 
|  | 4222 | </itemizedlist> | 
|  | 4223 | </para> | 
|  | 4224 |  | 
|  | 4225 | <section id='including-static-library-files'> | 
|  | 4226 | <title>Including Static Library Files</title> | 
|  | 4227 |  | 
|  | 4228 | <para> | 
|  | 4229 | If you are building a library and the library offers static linking, you can control | 
|  | 4230 | which static library files (<filename>*.a</filename> files) get included in the | 
|  | 4231 | built library. | 
|  | 4232 | </para> | 
|  | 4233 |  | 
|  | 4234 | <para> | 
|  | 4235 | The <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink> | 
|  | 4236 | and <ulink url='&YOCTO_DOCS_REF_URL;#var-FILES'><filename>FILES_*</filename></ulink> | 
|  | 4237 | variables in the | 
|  | 4238 | <filename>meta/conf/bitbake.conf</filename> configuration file define how files installed | 
|  | 4239 | by the <filename>do_install</filename> task are packaged. | 
|  | 4240 | By default, the <filename>PACKAGES</filename> variable includes | 
|  | 4241 | <filename>${PN}-staticdev</filename>, which represents all static library files. | 
|  | 4242 | <note> | 
|  | 4243 | Some previously released versions of the Yocto Project | 
|  | 4244 | defined the static library files through | 
|  | 4245 | <filename>${PN}-dev</filename>. | 
|  | 4246 | </note> | 
|  | 4247 | Following is part of the BitBake configuration file, where | 
|  | 4248 | you can see how the static library files are defined: | 
|  | 4249 | <literallayout class='monospaced'> | 
|  | 4250 | PACKAGE_BEFORE_PN ?= "" | 
|  | 4251 | PACKAGES = "${PN}-dbg ${PN}-staticdev ${PN}-dev ${PN}-doc ${PN}-locale ${PACKAGE_BEFORE_PN} ${PN}" | 
|  | 4252 | PACKAGES_DYNAMIC = "^${PN}-locale-.*" | 
|  | 4253 | FILES = "" | 
|  | 4254 |  | 
|  | 4255 | FILES_${PN} = "${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*${SOLIBS} \ | 
|  | 4256 | ${sysconfdir} ${sharedstatedir} ${localstatedir} \ | 
|  | 4257 | ${base_bindir}/* ${base_sbindir}/* \ | 
|  | 4258 | ${base_libdir}/*${SOLIBS} \ | 
|  | 4259 | ${base_prefix}/lib/udev/rules.d ${prefix}/lib/udev/rules.d \ | 
|  | 4260 | ${datadir}/${BPN} ${libdir}/${BPN}/* \ | 
|  | 4261 | ${datadir}/pixmaps ${datadir}/applications \ | 
|  | 4262 | ${datadir}/idl ${datadir}/omf ${datadir}/sounds \ | 
|  | 4263 | ${libdir}/bonobo/servers" | 
|  | 4264 |  | 
|  | 4265 | FILES_${PN}-bin = "${bindir}/* ${sbindir}/*" | 
|  | 4266 |  | 
|  | 4267 | FILES_${PN}-doc = "${docdir} ${mandir} ${infodir} ${datadir}/gtk-doc \ | 
|  | 4268 | ${datadir}/gnome/help" | 
|  | 4269 | SECTION_${PN}-doc = "doc" | 
|  | 4270 |  | 
|  | 4271 | FILES_SOLIBSDEV ?= "${base_libdir}/lib*${SOLIBSDEV} ${libdir}/lib*${SOLIBSDEV}" | 
|  | 4272 | FILES_${PN}-dev = "${includedir} ${FILES_SOLIBSDEV} ${libdir}/*.la \ | 
|  | 4273 | ${libdir}/*.o ${libdir}/pkgconfig ${datadir}/pkgconfig \ | 
|  | 4274 | ${datadir}/aclocal ${base_libdir}/*.o \ | 
|  | 4275 | ${libdir}/${BPN}/*.la ${base_libdir}/*.la" | 
|  | 4276 | SECTION_${PN}-dev = "devel" | 
|  | 4277 | ALLOW_EMPTY_${PN}-dev = "1" | 
|  | 4278 | RDEPENDS_${PN}-dev = "${PN} (= ${EXTENDPKGV})" | 
|  | 4279 |  | 
|  | 4280 | FILES_${PN}-staticdev = "${libdir}/*.a ${base_libdir}/*.a ${libdir}/${BPN}/*.a" | 
|  | 4281 | SECTION_${PN}-staticdev = "devel" | 
|  | 4282 | RDEPENDS_${PN}-staticdev = "${PN}-dev (= ${EXTENDPKGV})" | 
|  | 4283 | </literallayout> | 
|  | 4284 | </para> | 
|  | 4285 | </section> | 
|  | 4286 |  | 
|  | 4287 | <section id="combining-multiple-versions-library-files-into-one-image"> | 
|  | 4288 | <title>Combining Multiple Versions of Library Files into One Image</title> | 
|  | 4289 |  | 
|  | 4290 | <para> | 
|  | 4291 | The build system offers the ability to build libraries with different | 
|  | 4292 | target optimizations or architecture formats and combine these together | 
|  | 4293 | into one system image. | 
|  | 4294 | You can link different binaries in the image | 
|  | 4295 | against the different libraries as needed for specific use cases. | 
|  | 4296 | This feature is called "Multilib." | 
|  | 4297 | </para> | 
|  | 4298 |  | 
|  | 4299 | <para> | 
|  | 4300 | An example would be where you have most of a system compiled in 32-bit | 
|  | 4301 | mode using 32-bit libraries, but you have something large, like a database | 
|  | 4302 | engine, that needs to be a 64-bit application and uses 64-bit libraries. | 
|  | 4303 | Multilib allows you to get the best of both 32-bit and 64-bit libraries. | 
|  | 4304 | </para> | 
|  | 4305 |  | 
|  | 4306 | <para> | 
|  | 4307 | While the Multilib feature is most commonly used for 32 and 64-bit differences, | 
|  | 4308 | the approach the build system uses facilitates different target optimizations. | 
|  | 4309 | You could compile some binaries to use one set of libraries and other binaries | 
|  | 4310 | to use a different set of libraries. | 
|  | 4311 | The libraries could differ in architecture, compiler options, or other | 
|  | 4312 | optimizations. | 
|  | 4313 | </para> | 
|  | 4314 |  | 
|  | 4315 | <para> | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 4316 | Several examples exist in the | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4317 | <filename>meta-skeleton</filename> layer found in the | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 4318 | <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4319 | <itemizedlist> | 
|  | 4320 | <listitem><para><filename>conf/multilib-example.conf</filename> | 
|  | 4321 | configuration file</para></listitem> | 
|  | 4322 | <listitem><para><filename>conf/multilib-example2.conf</filename> | 
|  | 4323 | configuration file</para></listitem> | 
|  | 4324 | <listitem><para><filename>recipes-multilib/images/core-image-multilib-example.bb</filename> | 
|  | 4325 | recipe</para></listitem> | 
|  | 4326 | </itemizedlist> | 
|  | 4327 | </para> | 
|  | 4328 |  | 
|  | 4329 | <section id='preparing-to-use-multilib'> | 
|  | 4330 | <title>Preparing to Use Multilib</title> | 
|  | 4331 |  | 
|  | 4332 | <para> | 
|  | 4333 | User-specific requirements drive the Multilib feature. | 
|  | 4334 | Consequently, there is no one "out-of-the-box" configuration that likely | 
|  | 4335 | exists to meet your needs. | 
|  | 4336 | </para> | 
|  | 4337 |  | 
|  | 4338 | <para> | 
|  | 4339 | In order to enable Multilib, you first need to ensure your recipe is | 
|  | 4340 | extended to support multiple libraries. | 
|  | 4341 | Many standard recipes are already extended and support multiple libraries. | 
|  | 4342 | You can check in the <filename>meta/conf/multilib.conf</filename> | 
|  | 4343 | configuration file in the | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 4344 | <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink> to see how this is | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4345 | done using the | 
|  | 4346 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BBCLASSEXTEND'><filename>BBCLASSEXTEND</filename></ulink> | 
|  | 4347 | variable. | 
|  | 4348 | Eventually, all recipes will be covered and this list will | 
|  | 4349 | not be needed. | 
|  | 4350 | </para> | 
|  | 4351 |  | 
|  | 4352 | <para> | 
|  | 4353 | For the most part, the Multilib class extension works automatically to | 
|  | 4354 | extend the package name from <filename>${PN}</filename> to | 
|  | 4355 | <filename>${MLPREFIX}${PN}</filename>, where <filename>MLPREFIX</filename> | 
|  | 4356 | is the particular multilib (e.g. "lib32-" or "lib64-"). | 
|  | 4357 | Standard variables such as | 
|  | 4358 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>, | 
|  | 4359 | <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>, | 
|  | 4360 | <ulink url='&YOCTO_DOCS_REF_URL;#var-RPROVIDES'><filename>RPROVIDES</filename></ulink>, | 
|  | 4361 | <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>, | 
|  | 4362 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink>, and | 
|  | 4363 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES_DYNAMIC'><filename>PACKAGES_DYNAMIC</filename></ulink> | 
|  | 4364 | are automatically extended by the system. | 
|  | 4365 | If you are extending any manual code in the recipe, you can use the | 
|  | 4366 | <filename>${MLPREFIX}</filename> variable to ensure those names are extended | 
|  | 4367 | correctly. | 
|  | 4368 | This automatic extension code resides in <filename>multilib.bbclass</filename>. | 
|  | 4369 | </para> | 
|  | 4370 | </section> | 
|  | 4371 |  | 
|  | 4372 | <section id='using-multilib'> | 
|  | 4373 | <title>Using Multilib</title> | 
|  | 4374 |  | 
|  | 4375 | <para> | 
|  | 4376 | After you have set up the recipes, you need to define the actual | 
|  | 4377 | combination of multiple libraries you want to build. | 
|  | 4378 | You accomplish this through your <filename>local.conf</filename> | 
|  | 4379 | configuration file in the | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 4380 | <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4381 | An example configuration would be as follows: | 
|  | 4382 | <literallayout class='monospaced'> | 
|  | 4383 | MACHINE = "qemux86-64" | 
|  | 4384 | require conf/multilib.conf | 
|  | 4385 | MULTILIBS = "multilib:lib32" | 
|  | 4386 | DEFAULTTUNE_virtclass-multilib-lib32 = "x86" | 
| Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 4387 | IMAGE_INSTALL_append = " lib32-glib-2.0" | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4388 | </literallayout> | 
|  | 4389 | This example enables an | 
|  | 4390 | additional library named <filename>lib32</filename> alongside the | 
|  | 4391 | normal target packages. | 
|  | 4392 | When combining these "lib32" alternatives, the example uses "x86" for tuning. | 
|  | 4393 | For information on this particular tuning, see | 
|  | 4394 | <filename>meta/conf/machine/include/ia32/arch-ia32.inc</filename>. | 
|  | 4395 | </para> | 
|  | 4396 |  | 
|  | 4397 | <para> | 
| Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 4398 | The example then includes <filename>lib32-glib-2.0</filename> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4399 | in all the images, which illustrates one method of including a | 
|  | 4400 | multiple library dependency. | 
|  | 4401 | You can use a normal image build to include this dependency, | 
|  | 4402 | for example: | 
|  | 4403 | <literallayout class='monospaced'> | 
|  | 4404 | $ bitbake core-image-sato | 
|  | 4405 | </literallayout> | 
|  | 4406 | You can also build Multilib packages specifically with a command like this: | 
|  | 4407 | <literallayout class='monospaced'> | 
| Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 4408 | $ bitbake lib32-glib-2.0 | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4409 | </literallayout> | 
|  | 4410 | </para> | 
|  | 4411 | </section> | 
|  | 4412 |  | 
|  | 4413 | <section id='additional-implementation-details'> | 
|  | 4414 | <title>Additional Implementation Details</title> | 
|  | 4415 |  | 
|  | 4416 | <para> | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 4417 | Generic implementation details as well as details that are | 
|  | 4418 | specific to package management systems exist. | 
|  | 4419 | Following are implementation details that exist regardless | 
|  | 4420 | of the package management system: | 
|  | 4421 | <itemizedlist> | 
|  | 4422 | <listitem><para>The typical convention used for the | 
|  | 4423 | class extension code as used by | 
|  | 4424 | Multilib assumes that all package names specified | 
|  | 4425 | in | 
|  | 4426 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink> | 
|  | 4427 | that contain <filename>${PN}</filename> have | 
|  | 4428 | <filename>${PN}</filename> at the start of the name. | 
|  | 4429 | When that convention is not followed and | 
|  | 4430 | <filename>${PN}</filename> appears at | 
|  | 4431 | the middle or the end of a name, problems occur. | 
|  | 4432 | </para></listitem> | 
|  | 4433 | <listitem><para>The | 
|  | 4434 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TARGET_VENDOR'><filename>TARGET_VENDOR</filename></ulink> | 
|  | 4435 | value under Multilib will be extended to | 
|  | 4436 | "-<replaceable>vendor</replaceable>ml<replaceable>multilib</replaceable>" | 
|  | 4437 | (e.g. "-pokymllib32" for a "lib32" Multilib with | 
|  | 4438 | Poky). | 
|  | 4439 | The reason for this slightly unwieldy contraction | 
|  | 4440 | is that any "-" characters in the vendor | 
|  | 4441 | string presently break Autoconf's | 
|  | 4442 | <filename>config.sub</filename>, and | 
|  | 4443 | other separators are problematic for different | 
|  | 4444 | reasons. | 
|  | 4445 | </para></listitem> | 
|  | 4446 | </itemizedlist> | 
|  | 4447 | </para> | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 4448 |  | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 4449 | <para> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4450 | For the RPM Package Management System, the following implementation details | 
|  | 4451 | exist: | 
|  | 4452 | <itemizedlist> | 
|  | 4453 | <listitem><para>A unique architecture is defined for the Multilib packages, | 
|  | 4454 | along with creating a unique deploy folder under | 
|  | 4455 | <filename>tmp/deploy/rpm</filename> in the | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 4456 | <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4457 | For example, consider <filename>lib32</filename> in a | 
|  | 4458 | <filename>qemux86-64</filename> image. | 
|  | 4459 | The possible architectures in the system are "all", "qemux86_64", | 
|  | 4460 | "lib32_qemux86_64", and "lib32_x86".</para></listitem> | 
|  | 4461 | <listitem><para>The <filename>${MLPREFIX}</filename> variable is stripped from | 
|  | 4462 | <filename>${PN}</filename> during RPM packaging. | 
|  | 4463 | The naming for a normal RPM package and a Multilib RPM package in a | 
|  | 4464 | <filename>qemux86-64</filename> system resolves to something similar to | 
|  | 4465 | <filename>bash-4.1-r2.x86_64.rpm</filename> and | 
|  | 4466 | <filename>bash-4.1.r2.lib32_x86.rpm</filename>, respectively. | 
|  | 4467 | </para></listitem> | 
|  | 4468 | <listitem><para>When installing a Multilib image, the RPM backend first | 
|  | 4469 | installs the base image and then installs the Multilib libraries. | 
|  | 4470 | </para></listitem> | 
|  | 4471 | <listitem><para>The build system relies on RPM to resolve the identical files in the | 
|  | 4472 | two (or more) Multilib packages.</para></listitem> | 
|  | 4473 | </itemizedlist> | 
|  | 4474 | </para> | 
|  | 4475 |  | 
|  | 4476 | <para> | 
|  | 4477 | For the IPK Package Management System, the following implementation details exist: | 
|  | 4478 | <itemizedlist> | 
|  | 4479 | <listitem><para>The <filename>${MLPREFIX}</filename> is not stripped from | 
|  | 4480 | <filename>${PN}</filename> during IPK packaging. | 
|  | 4481 | The naming for a normal RPM package and a Multilib IPK package in a | 
|  | 4482 | <filename>qemux86-64</filename> system resolves to something like | 
|  | 4483 | <filename>bash_4.1-r2.x86_64.ipk</filename> and | 
|  | 4484 | <filename>lib32-bash_4.1-rw_x86.ipk</filename>, respectively. | 
|  | 4485 | </para></listitem> | 
|  | 4486 | <listitem><para>The IPK deploy folder is not modified with | 
|  | 4487 | <filename>${MLPREFIX}</filename> because packages with and without | 
|  | 4488 | the Multilib feature can exist in the same folder due to the | 
|  | 4489 | <filename>${PN}</filename> differences.</para></listitem> | 
|  | 4490 | <listitem><para>IPK defines a sanity check for Multilib installation | 
|  | 4491 | using certain rules for file comparison, overridden, etc. | 
|  | 4492 | </para></listitem> | 
|  | 4493 | </itemizedlist> | 
|  | 4494 | </para> | 
|  | 4495 | </section> | 
|  | 4496 | </section> | 
|  | 4497 |  | 
|  | 4498 | <section id='installing-multiple-versions-of-the-same-library'> | 
|  | 4499 | <title>Installing Multiple Versions of the Same Library</title> | 
|  | 4500 |  | 
|  | 4501 | <para> | 
|  | 4502 | Situations can exist where you need to install and use | 
|  | 4503 | multiple versions of the same library on the same system | 
|  | 4504 | at the same time. | 
|  | 4505 | These situations almost always exist when a library API | 
|  | 4506 | changes and you have multiple pieces of software that | 
|  | 4507 | depend on the separate versions of the library. | 
|  | 4508 | To accommodate these situations, you can install multiple | 
|  | 4509 | versions of the same library in parallel on the same system. | 
|  | 4510 | </para> | 
|  | 4511 |  | 
|  | 4512 | <para> | 
|  | 4513 | The process is straightforward as long as the libraries use | 
|  | 4514 | proper versioning. | 
|  | 4515 | With properly versioned libraries, all you need to do to | 
|  | 4516 | individually specify the libraries is create separate, | 
|  | 4517 | appropriately named recipes where the | 
|  | 4518 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink> part of the | 
|  | 4519 | name includes a portion that differentiates each library version | 
|  | 4520 | (e.g.the major part of the version number). | 
|  | 4521 | Thus, instead of having a single recipe that loads one version | 
|  | 4522 | of a library (e.g. <filename>clutter</filename>), you provide | 
|  | 4523 | multiple recipes that result in different versions | 
|  | 4524 | of the libraries you want. | 
|  | 4525 | As an example, the following two recipes would allow the | 
|  | 4526 | two separate versions of the <filename>clutter</filename> | 
|  | 4527 | library to co-exist on the same system: | 
|  | 4528 | <literallayout class='monospaced'> | 
|  | 4529 | clutter-1.6_1.6.20.bb | 
|  | 4530 | clutter-1.8_1.8.4.bb | 
|  | 4531 | </literallayout> | 
|  | 4532 | Additionally, if you have other recipes that depend on a given | 
|  | 4533 | library, you need to use the | 
|  | 4534 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink> | 
|  | 4535 | variable to create the dependency. | 
|  | 4536 | Continuing with the same example, if you want to have a recipe | 
|  | 4537 | depend on the 1.8 version of the <filename>clutter</filename> | 
|  | 4538 | library, use the following in your recipe: | 
|  | 4539 | <literallayout class='monospaced'> | 
|  | 4540 | DEPENDS = "clutter-1.8" | 
|  | 4541 | </literallayout> | 
|  | 4542 | </para> | 
|  | 4543 | </section> | 
|  | 4544 | </section> | 
|  | 4545 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 4546 | <section id='enabling-gobject-introspection-support'> | 
|  | 4547 | <title>Enabling GObject Introspection Support</title> | 
|  | 4548 |  | 
|  | 4549 | <para> | 
|  | 4550 | <ulink url='https://wiki.gnome.org/Projects/GObjectIntrospection'>GObject introspection</ulink> | 
|  | 4551 | is the standard mechanism for accessing GObject-based software | 
|  | 4552 | from runtime environments. | 
|  | 4553 | GObject is a feature of the GLib library that provides an object | 
|  | 4554 | framework for the GNOME desktop and related software. | 
|  | 4555 | GObject Introspection adds information to GObject that allows | 
|  | 4556 | objects created within it to be represented across different | 
|  | 4557 | programming languages. | 
|  | 4558 | If you want to construct GStreamer pipelines using Python, or | 
|  | 4559 | control UPnP infrastructure using Javascript and GUPnP, | 
|  | 4560 | GObject introspection is the only way to do it. | 
|  | 4561 | </para> | 
|  | 4562 |  | 
|  | 4563 | <para> | 
|  | 4564 | This section describes the Yocto Project support for generating | 
|  | 4565 | and packaging GObject introspection data. | 
|  | 4566 | GObject introspection data is a description of the | 
|  | 4567 | API provided by libraries built on top of GLib framework, | 
|  | 4568 | and, in particular, that framework's GObject mechanism. | 
|  | 4569 | GObject Introspection Repository (GIR) files go to | 
|  | 4570 | <filename>-dev</filename> packages, | 
|  | 4571 | <filename>typelib</filename> files go to main packages as they | 
|  | 4572 | are packaged together with libraries that are introspected. | 
|  | 4573 | </para> | 
|  | 4574 |  | 
|  | 4575 | <para> | 
|  | 4576 | The data is generated when building such a library, by linking | 
|  | 4577 | the library with a small executable binary that asks the library | 
|  | 4578 | to describe itself, and then executing the binary and | 
|  | 4579 | processing its output. | 
|  | 4580 | </para> | 
|  | 4581 |  | 
|  | 4582 | <para> | 
|  | 4583 | Generating this data in a cross-compilation environment | 
|  | 4584 | is difficult because the library is produced for the target | 
|  | 4585 | architecture, but its code needs to be executed on the build host. | 
|  | 4586 | This problem is solved with the OpenEmbedded build system by | 
|  | 4587 | running the code through QEMU, which allows precisely that. | 
|  | 4588 | Unfortunately, QEMU does not always work perfectly as mentioned | 
|  | 4589 | in the xxx section. | 
|  | 4590 | </para> | 
|  | 4591 |  | 
|  | 4592 | <section id='enabling-the-generation-of-introspection-data'> | 
|  | 4593 | <title>Enabling the Generation of Introspection Data</title> | 
|  | 4594 |  | 
|  | 4595 | <para> | 
|  | 4596 | Enabling the generation of introspection data (GIR files) | 
|  | 4597 | in your library package involves the following: | 
|  | 4598 | <orderedlist> | 
|  | 4599 | <listitem><para> | 
|  | 4600 | Inherit the | 
|  | 4601 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-gobject-introspection'><filename>gobject-introspection</filename></ulink> | 
|  | 4602 | class. | 
|  | 4603 | </para></listitem> | 
|  | 4604 | <listitem><para> | 
|  | 4605 | Make sure introspection is not disabled anywhere in | 
|  | 4606 | the recipe or from anything the recipe includes. | 
|  | 4607 | Also, make sure that "gobject-introspection-data" is | 
|  | 4608 | not in | 
|  | 4609 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES_BACKFILL_CONSIDERED'><filename>DISTRO_FEATURES_BACKFILL_CONSIDERED</filename></ulink> | 
|  | 4610 | and that "qemu-usermode" is not in | 
|  | 4611 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES_BACKFILL_CONSIDERED'><filename>MACHINE_FEATURES_BACKFILL_CONSIDERED</filename></ulink>. | 
|  | 4612 | If either of these conditions exist, nothing will | 
|  | 4613 | happen. | 
|  | 4614 | </para></listitem> | 
|  | 4615 | <listitem><para> | 
|  | 4616 | Try to build the recipe. | 
|  | 4617 | If you encounter build errors that look like | 
|  | 4618 | something is unable to find | 
|  | 4619 | <filename>.so</filename> libraries, check where these | 
|  | 4620 | libraries are located in the source tree and add | 
|  | 4621 | the following to the recipe: | 
|  | 4622 | <literallayout class='monospaced'> | 
|  | 4623 | GIR_EXTRA_LIBS_PATH = "${B}/<replaceable>something</replaceable>/.libs" | 
|  | 4624 | </literallayout> | 
|  | 4625 | <note> | 
|  | 4626 | See recipes in the <filename>oe-core</filename> | 
|  | 4627 | repository that use that | 
|  | 4628 | <filename>GIR_EXTRA_LIBS_PATH</filename> variable | 
|  | 4629 | as an example. | 
|  | 4630 | </note> | 
|  | 4631 | </para></listitem> | 
|  | 4632 | <listitem><para> | 
|  | 4633 | Look for any other errors, which probably mean that | 
|  | 4634 | introspection support in a package is not entirely | 
|  | 4635 | standard, and thus breaks down in a cross-compilation | 
|  | 4636 | environment. | 
|  | 4637 | For such cases, custom-made fixes are needed. | 
|  | 4638 | A good place to ask and receive help in these cases | 
|  | 4639 | is the | 
|  | 4640 | <ulink url='&YOCTO_DOCS_REF_URL;#resources-mailinglist'>Yocto Project mailing lists</ulink>. | 
|  | 4641 | </para></listitem> | 
|  | 4642 | </orderedlist> | 
|  | 4643 | <note> | 
|  | 4644 | Using a library that no longer builds against the latest | 
|  | 4645 | Yocto Project release and prints introspection related | 
|  | 4646 | errors is a good candidate for the previous procedure. | 
|  | 4647 | </note> | 
|  | 4648 | </para> | 
|  | 4649 | </section> | 
|  | 4650 |  | 
|  | 4651 | <section id='disabling-the-generation-of-introspection-data'> | 
|  | 4652 | <title>Disabling the Generation of Introspection Data</title> | 
|  | 4653 |  | 
|  | 4654 | <para> | 
|  | 4655 | You might find that you do not want to generate | 
|  | 4656 | introspection data. | 
|  | 4657 | Or, perhaps QEMU does not work on your build host and | 
|  | 4658 | target architecture combination. | 
|  | 4659 | If so, you can use either of the following methods to | 
|  | 4660 | disable GIR file generations: | 
|  | 4661 | <itemizedlist> | 
|  | 4662 | <listitem><para> | 
|  | 4663 | Add the following to your distro configuration: | 
|  | 4664 | <literallayout class='monospaced'> | 
|  | 4665 | DISTRO_FEATURES_BACKFILL_CONSIDERED = "gobject-introspection-data" | 
|  | 4666 | </literallayout> | 
|  | 4667 | Adding this statement disables generating | 
|  | 4668 | introspection data using QEMU but will still enable | 
|  | 4669 | building introspection tools and libraries | 
|  | 4670 | (i.e. building them does not require the use of QEMU). | 
|  | 4671 | </para></listitem> | 
|  | 4672 | <listitem><para> | 
|  | 4673 | Add the following to your machine configuration: | 
|  | 4674 | <literallayout class='monospaced'> | 
|  | 4675 | MACHINE_FEATURES_BACKFILL_CONSIDERED = "qemu-usermode" | 
|  | 4676 | </literallayout> | 
|  | 4677 | Adding this statement disables the use of QEMU | 
|  | 4678 | when building packages for your machine. | 
|  | 4679 | Currently, this feature is used only by introspection | 
|  | 4680 | recipes and has the same effect as the previously | 
|  | 4681 | described option. | 
|  | 4682 | <note> | 
|  | 4683 | Future releases of the Yocto Project might have | 
|  | 4684 | other features affected by this option. | 
|  | 4685 | </note> | 
|  | 4686 | </para></listitem> | 
|  | 4687 | </itemizedlist> | 
|  | 4688 | If you disable introspection data, you can still | 
|  | 4689 | obtain it through other means such as copying the data | 
|  | 4690 | from a suitable sysroot, or by generating it on the | 
|  | 4691 | target hardware. | 
|  | 4692 | The OpenEmbedded build system does not currently | 
|  | 4693 | provide specific support for these techniques. | 
|  | 4694 | </para> | 
|  | 4695 | </section> | 
|  | 4696 |  | 
|  | 4697 | <section id='testing-that-introspection-works-in-an-image'> | 
|  | 4698 | <title>Testing that Introspection Works in an Image</title> | 
|  | 4699 |  | 
|  | 4700 | <para> | 
|  | 4701 | Use the following procedure to test if generating | 
|  | 4702 | introspection data is working in an image: | 
|  | 4703 | <orderedlist> | 
|  | 4704 | <listitem><para> | 
|  | 4705 | Make sure that "gobject-introspection-data" is not in | 
|  | 4706 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES_BACKFILL_CONSIDERED'><filename>DISTRO_FEATURES_BACKFILL_CONSIDERED</filename></ulink> | 
|  | 4707 | and that "qemu-usermode" is not in | 
|  | 4708 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES_BACKFILL_CONSIDERED'><filename>MACHINE_FEATURES_BACKFILL_CONSIDERED</filename></ulink>. | 
|  | 4709 | </para></listitem> | 
|  | 4710 | <listitem><para> | 
|  | 4711 | Build <filename>core-image-sato</filename>. | 
|  | 4712 | </para></listitem> | 
|  | 4713 | <listitem><para> | 
|  | 4714 | Launch a Terminal and then start Python in the | 
|  | 4715 | terminal. | 
|  | 4716 | </para></listitem> | 
|  | 4717 | <listitem><para> | 
|  | 4718 | Enter the following in the terminal: | 
|  | 4719 | <literallayout class='monospaced'> | 
|  | 4720 | >>> from gi.repository import GLib | 
|  | 4721 | >>> GLib.get_host_name() | 
|  | 4722 | </literallayout> | 
|  | 4723 | </para></listitem> | 
|  | 4724 | <listitem><para> | 
|  | 4725 | For something a little more advanced, enter the | 
|  | 4726 | following: | 
|  | 4727 | <literallayout class='monospaced'> | 
|  | 4728 | http://python-gtk-3-tutorial.readthedocs.org/en/latest/introduction.html | 
|  | 4729 | </literallayout> | 
|  | 4730 | </para></listitem> | 
|  | 4731 | </orderedlist> | 
|  | 4732 | </para> | 
|  | 4733 | </section> | 
|  | 4734 |  | 
|  | 4735 | <section id='known-issues'> | 
|  | 4736 | <title>Known Issues</title> | 
|  | 4737 |  | 
|  | 4738 | <para> | 
|  | 4739 | The following know issues exist for | 
|  | 4740 | GObject Introspection Support: | 
|  | 4741 | <itemizedlist> | 
|  | 4742 | <listitem><para> | 
|  | 4743 | <filename>qemu-ppc64</filename> immediately crashes. | 
|  | 4744 | Consequently, you cannot build introspection data on | 
|  | 4745 | that architecture. | 
|  | 4746 | </para></listitem> | 
|  | 4747 | <listitem><para> | 
|  | 4748 | x32 is not supported by QEMU. | 
|  | 4749 | Consequently, introspection data is disabled. | 
|  | 4750 | </para></listitem> | 
|  | 4751 | <listitem><para> | 
|  | 4752 | musl causes transient GLib binaries to crash on | 
|  | 4753 | assertion failures. | 
|  | 4754 | Consequently, generating introspection data is | 
|  | 4755 | disabled. | 
|  | 4756 | </para></listitem> | 
|  | 4757 | <listitem><para> | 
|  | 4758 | Because QEMU is not able to run the binaries correctly, | 
|  | 4759 | introspection is disabled for some specific packages | 
|  | 4760 | under specific architectures (e.g. | 
|  | 4761 | <filename>gcr</filename>, | 
|  | 4762 | <filename>libsecret</filename>, and | 
|  | 4763 | <filename>webkit</filename>). | 
|  | 4764 | </para></listitem> | 
|  | 4765 | <listitem><para> | 
|  | 4766 | QEMU usermode might not work properly when running | 
|  | 4767 | 64-bit binaries under 32-bit host machines. | 
|  | 4768 | In particular, "qemumips64" is known to not work under | 
|  | 4769 | i686. | 
|  | 4770 | </para></listitem> | 
|  | 4771 | </itemizedlist> | 
|  | 4772 | </para> | 
|  | 4773 | </section> | 
|  | 4774 | </section> | 
|  | 4775 |  | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 4776 | <section id='dev-optionally-using-an-external-toolchain'> | 
|  | 4777 | <title>Optionally Using an External Toolchain</title> | 
|  | 4778 |  | 
|  | 4779 | <para> | 
|  | 4780 | You might want to use an external toolchain as part of your | 
|  | 4781 | development. | 
|  | 4782 | If this is the case, the fundamental steps you need to accomplish | 
|  | 4783 | are as follows: | 
|  | 4784 | <itemizedlist> | 
|  | 4785 | <listitem><para> | 
|  | 4786 | Understand where the installed toolchain resides. | 
|  | 4787 | For cases where you need to build the external toolchain, | 
|  | 4788 | you would need to take separate steps to build and install | 
|  | 4789 | the toolchain. | 
|  | 4790 | </para></listitem> | 
|  | 4791 | <listitem><para> | 
|  | 4792 | Make sure you add the layer that contains the toolchain to | 
|  | 4793 | your <filename>bblayers.conf</filename> file through the | 
|  | 4794 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'><filename>BBLAYERS</filename></ulink> | 
|  | 4795 | variable. | 
|  | 4796 | </para></listitem> | 
|  | 4797 | <listitem><para> | 
|  | 4798 | Set the | 
|  | 4799 | <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNAL_TOOLCHAIN'><filename>EXTERNAL_TOOLCHAIN</filename></ulink> | 
|  | 4800 | variable in your <filename>local.conf</filename> file | 
|  | 4801 | to the location in which you installed the toolchain. | 
|  | 4802 | </para></listitem> | 
|  | 4803 | </itemizedlist> | 
|  | 4804 | A good example of an external toolchain used with the Yocto Project | 
|  | 4805 | is <trademark class='registered'>Mentor Graphics</trademark> | 
|  | 4806 | Sourcery G++ Toolchain. | 
|  | 4807 | You can see information on how to use that particular layer in the | 
|  | 4808 | <filename>README</filename> file at | 
|  | 4809 | <ulink url='http://github.com/MentorEmbedded/meta-sourcery/'></ulink>. | 
|  | 4810 | You can find further information by reading about the | 
|  | 4811 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TCMODE'><filename>TCMODE</filename></ulink> | 
|  | 4812 | variable in the Yocto Project Reference Manual's variable glossary. | 
|  | 4813 | </para> | 
|  | 4814 | </section> | 
|  | 4815 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 4816 | <section id='creating-partitioned-images-using-wic'> | 
|  | 4817 | <title>Creating Partitioned Images Using Wic</title> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4818 |  | 
|  | 4819 | <para> | 
|  | 4820 | Creating an image for a particular hardware target using the | 
|  | 4821 | OpenEmbedded build system does not necessarily mean you can boot | 
|  | 4822 | that image as is on your device. | 
|  | 4823 | Physical devices accept and boot images in various ways depending | 
|  | 4824 | on the specifics of the device. | 
|  | 4825 | Usually, information about the hardware can tell you what image | 
|  | 4826 | format the device requires. | 
|  | 4827 | Should your device require multiple partitions on an SD card, flash, | 
|  | 4828 | or an HDD, you can use the OpenEmbedded Image Creator, | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 4829 | Wic, to create the properly partitioned image. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4830 | </para> | 
|  | 4831 |  | 
|  | 4832 | <para> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 4833 | The <filename>wic</filename> command generates partitioned | 
|  | 4834 | images from existing OpenEmbedded build artifacts. | 
|  | 4835 | Image generation is driven by partitioning commands | 
|  | 4836 | contained in an Openembedded kickstart file | 
|  | 4837 | (<filename>.wks</filename>) specified either directly on | 
|  | 4838 | the command line or as one of a selection of canned | 
|  | 4839 | kickstart files as shown with the | 
|  | 4840 | <filename>wic list images</filename> command in the | 
|  | 4841 | "<link linkend='using-a-provided-kickstart-file'>Using an Existing Kickstart File</link>" | 
|  | 4842 | section. | 
|  | 4843 | When you apply the command to a given set of build | 
|  | 4844 | artifacts, the result is an image or set of images that | 
|  | 4845 | can be directly written onto media and used on a particular | 
|  | 4846 | system. | 
|  | 4847 | <note> | 
|  | 4848 | For a kickstart file reference, see the | 
|  | 4849 | "<ulink url='&YOCTO_DOCS_REF_URL;#openembedded-kickstart-wks-reference'>OpenEmbedded Kickstart (<filename>.wks</filename>) Reference</ulink>" | 
|  | 4850 | Chapter in the Yocto Project Reference Manual. | 
|  | 4851 | </note> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4852 | </para> | 
|  | 4853 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 4854 | <para> | 
|  | 4855 | The <filename>wic</filename> command and the infrastructure | 
|  | 4856 | it is based on is by definition incomplete. | 
|  | 4857 | The purpose of the command is to allow the generation of | 
|  | 4858 | customized images, and as such, was designed to be | 
|  | 4859 | completely extensible through a plug-in interface. | 
|  | 4860 | See the | 
|  | 4861 | "<ulink url='&YOCTO_DOCS_REF_URL;#wic-plug-ins-interface'>Wic Plug-Ins Interface</ulink>" | 
|  | 4862 | section in the Yocto Project Reference Manual for information | 
|  | 4863 | on these plug-ins. | 
|  | 4864 | </para> | 
|  | 4865 |  | 
|  | 4866 | <para> | 
|  | 4867 | This section provides some background information on Wic, | 
|  | 4868 | describes what you need to have in | 
|  | 4869 | place to run the tool, provides instruction on how to use | 
|  | 4870 | the Wic utility, and provides several examples. | 
|  | 4871 | </para> | 
|  | 4872 |  | 
|  | 4873 | <section id='wic-background'> | 
|  | 4874 | <title>Background</title> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4875 |  | 
|  | 4876 | <para> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 4877 | This section provides some background on the Wic utility. | 
|  | 4878 | While none of this information is required to use | 
|  | 4879 | Wic, you might find it interesting. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4880 | <itemizedlist> | 
|  | 4881 | <listitem><para> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 4882 | The name "Wic" is derived from OpenEmbedded | 
|  | 4883 | Image Creator (oeic). | 
|  | 4884 | The "oe" diphthong in "oeic" was promoted to the | 
|  | 4885 | letter "w", because "oeic" is both difficult to | 
|  | 4886 | remember and to pronounce. | 
|  | 4887 | </para></listitem> | 
|  | 4888 | <listitem><para> | 
|  | 4889 | Wic is loosely based on the | 
|  | 4890 | Meego Image Creator (<filename>mic</filename>) | 
|  | 4891 | framework. | 
|  | 4892 | The Wic implementation has been | 
|  | 4893 | heavily modified to make direct use of OpenEmbedded | 
|  | 4894 | build artifacts instead of package installation and | 
|  | 4895 | configuration, which are already incorporated within | 
|  | 4896 | the OpenEmbedded artifacts. | 
|  | 4897 | </para></listitem> | 
|  | 4898 | <listitem><para> | 
|  | 4899 | Wic is a completely independent | 
|  | 4900 | standalone utility that initially provides | 
|  | 4901 | easier-to-use and more flexible replacements for an | 
|  | 4902 | existing functionality in OE Core's | 
|  | 4903 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-image-live'><filename>image-live</filename></ulink> | 
|  | 4904 | class and <filename>mkefidisk.sh</filename> script. | 
|  | 4905 | The difference between | 
|  | 4906 | Wic and those examples is | 
|  | 4907 | that with Wic the | 
|  | 4908 | functionality of those scripts is implemented | 
|  | 4909 | by a general-purpose partitioning language, which is | 
|  | 4910 | based on Redhat kickstart syntax.</para></listitem> | 
|  | 4911 | </itemizedlist> | 
|  | 4912 | </para> | 
|  | 4913 | </section> | 
|  | 4914 |  | 
|  | 4915 | <section id='wic-requirements'> | 
|  | 4916 | <title>Requirements</title> | 
|  | 4917 |  | 
|  | 4918 | <para> | 
|  | 4919 | In order to use the Wic utility with the OpenEmbedded Build | 
|  | 4920 | system, your system needs to meet the following | 
|  | 4921 | requirements: | 
|  | 4922 | <itemizedlist> | 
|  | 4923 | <listitem><para> | 
|  | 4924 | The Linux distribution on your development host must | 
|  | 4925 | support the Yocto Project. | 
|  | 4926 | See the | 
|  | 4927 | "<ulink url='&YOCTO_DOCS_REF_URL;#detailed-supported-distros'>Supported Linux Distributions</ulink>" | 
|  | 4928 | section in the Yocto Project Reference Manual for | 
|  | 4929 | the list of distributions that support the | 
|  | 4930 | Yocto Project. | 
|  | 4931 | </para></listitem> | 
|  | 4932 | <listitem><para> | 
|  | 4933 | The standard system utilities, such as | 
|  | 4934 | <filename>cp</filename>, must be installed on your | 
|  | 4935 | development host system. | 
|  | 4936 | </para></listitem> | 
|  | 4937 | <listitem><para> | 
|  | 4938 | You must have sourced the build environment | 
|  | 4939 | setup script (i.e. | 
|  | 4940 | <ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>) | 
|  | 4941 | found in the | 
|  | 4942 | <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>. | 
|  | 4943 | </para></listitem> | 
|  | 4944 | <listitem><para> | 
|  | 4945 | You need to have the build artifacts already | 
|  | 4946 | available, which typically means that you must | 
|  | 4947 | have already created an image using the | 
|  | 4948 | Openembedded build system (e.g. | 
|  | 4949 | <filename>core-image-minimal</filename>). | 
|  | 4950 | While it might seem redundant to generate an image | 
|  | 4951 | in order to create an image using | 
|  | 4952 | Wic, the current version of | 
|  | 4953 | Wic requires the artifacts | 
|  | 4954 | in the form generated by the OpenEmbedded build | 
|  | 4955 | system. | 
|  | 4956 | </para></listitem> | 
|  | 4957 | <listitem><para> | 
|  | 4958 | You must build several native tools, which are | 
|  | 4959 | built to run on the build system: | 
|  | 4960 | <literallayout class='monospaced'> | 
|  | 4961 | $ bitbake parted-native dosfstools-native mtools-native | 
|  | 4962 | </literallayout> | 
|  | 4963 | </para></listitem> | 
|  | 4964 | <listitem><para> | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 4965 | Include "wic" as part of the | 
|  | 4966 | <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FSTYPES'><filename>IMAGE_FSTYPES</filename></ulink> | 
|  | 4967 | variable. | 
|  | 4968 | </para></listitem> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4969 | <listitem><para> | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 4970 | Include the name of the | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 4971 | <ulink url='&YOCTO_DOCS_REF_URL;#openembedded-kickstart-wks-reference'>wic kickstart file</ulink> | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 4972 | as part of the | 
|  | 4973 | <ulink url='&YOCTO_DOCS_REF_URL;#var-WKS_FILE'><filename>WKS_FILE</filename></ulink> | 
|  | 4974 | variable | 
|  | 4975 | </para></listitem> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4976 | </itemizedlist> | 
|  | 4977 | </para> | 
|  | 4978 | </section> | 
|  | 4979 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 4980 | <section id='wic-getting-help'> | 
|  | 4981 | <title>Getting Help</title> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4982 |  | 
|  | 4983 | <para> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 4984 | You can get general help for the <filename>wic</filename> | 
|  | 4985 | command by entering the <filename>wic</filename> command | 
|  | 4986 | by itself or by entering the command with a help argument | 
|  | 4987 | as follows: | 
|  | 4988 | <literallayout class='monospaced'> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4989 | $ wic -h | 
|  | 4990 | $ wic --help | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 4991 | </literallayout> | 
|  | 4992 | </para> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4993 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 4994 | <para> | 
|  | 4995 | Currently, Wic supports seven commands: | 
|  | 4996 | <filename>cp</filename>, <filename>create</filename>, | 
|  | 4997 | <filename>help</filename>, <filename>list</filename>, | 
|  | 4998 | <filename>ls</filename>, <filename>rm</filename>, and | 
|  | 4999 | <filename>write</filename>. | 
|  | 5000 | You can get help for these commands as follows with | 
|  | 5001 | <replaceable>command</replaceable> being one of the | 
|  | 5002 | supported commands: | 
|  | 5003 | <literallayout class='monospaced'> | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 5004 | $ wic help <replaceable>command</replaceable> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5005 | </literallayout> | 
|  | 5006 | </para> | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 5007 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5008 | <para> | 
|  | 5009 | You can also get detailed help on a number of topics | 
|  | 5010 | from the help system. | 
|  | 5011 | The output of <filename>wic --help</filename> | 
|  | 5012 | displays a list of available help | 
|  | 5013 | topics under a "Help topics" heading. | 
|  | 5014 | You can have the help system display the help text for | 
|  | 5015 | a given topic by prefacing the topic with | 
|  | 5016 | <filename>wic help</filename>: | 
|  | 5017 | <literallayout class='monospaced'> | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 5018 | $ wic help <replaceable>help_topic</replaceable> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5019 | </literallayout> | 
|  | 5020 | </para> | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 5021 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5022 | <para> | 
|  | 5023 | You can find out more about the images Wic creates using | 
|  | 5024 | the existing kickstart files with the following form of | 
|  | 5025 | the command: | 
|  | 5026 | <literallayout class='monospaced'> | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 5027 | $ wic list <replaceable>image</replaceable> help | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5028 | </literallayout> | 
|  | 5029 | For <replaceable>image</replaceable>, you can provide | 
|  | 5030 | any of the following: | 
|  | 5031 | <literallayout class='monospaced'> | 
|  | 5032 | beaglebone | 
|  | 5033 | mpc8315e-rdb | 
|  | 5034 | genericx86 | 
|  | 5035 | edgerouter | 
|  | 5036 | qemux86-directdisk | 
|  | 5037 | directdisk-gpt | 
|  | 5038 | mkefidisk | 
|  | 5039 | directdisk | 
|  | 5040 | systemd-bootdisk | 
|  | 5041 | mkhybridiso | 
|  | 5042 | sdimage-bootpart | 
|  | 5043 | directdisk-multi-rootfs | 
|  | 5044 | directdisk-bootloader-config | 
|  | 5045 | </literallayout> | 
|  | 5046 | </para> | 
|  | 5047 | </section> | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 5048 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5049 | <section id='operational-modes'> | 
|  | 5050 | <title>Operational Modes</title> | 
|  | 5051 |  | 
|  | 5052 | <para> | 
|  | 5053 | You can use Wic in two different | 
|  | 5054 | modes, depending on how much control you need for | 
|  | 5055 | specifying the Openembedded build artifacts that are | 
|  | 5056 | used for creating the image: Raw and Cooked: | 
|  | 5057 | <itemizedlist> | 
|  | 5058 | <listitem><para> | 
|  | 5059 | <emphasis>Raw Mode:</emphasis> | 
|  | 5060 | You explicitly specify build artifacts through | 
|  | 5061 | <filename>wic</filename> command-line arguments. | 
|  | 5062 | </para></listitem> | 
|  | 5063 | <listitem><para> | 
|  | 5064 | <emphasis>Cooked Mode:</emphasis> | 
|  | 5065 | The current | 
|  | 5066 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink> | 
|  | 5067 | setting and image name are used to automatically | 
|  | 5068 | locate and provide the build artifacts. | 
|  | 5069 | You just supply a kickstart file and the name | 
|  | 5070 | of the image from which to use artifacts. | 
|  | 5071 | </para></listitem> | 
|  | 5072 | </itemizedlist> | 
|  | 5073 | </para> | 
|  | 5074 |  | 
|  | 5075 | <para> | 
|  | 5076 | Regardless of the mode you use, you need to have the build | 
|  | 5077 | artifacts ready and available. | 
|  | 5078 | </para> | 
|  | 5079 |  | 
|  | 5080 | <section id='raw-mode'> | 
|  | 5081 | <title>Raw Mode</title> | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 5082 |  | 
|  | 5083 | <para> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5084 | Running Wic in raw mode allows you to specify all the | 
|  | 5085 | partitions through the <filename>wic</filename> | 
|  | 5086 | command line. | 
|  | 5087 | The primary use for raw mode is if you have built | 
|  | 5088 | your kernel outside of the Yocto Project | 
|  | 5089 | <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>. | 
|  | 5090 | In other words, you can point to arbitrary kernel, | 
|  | 5091 | root filesystem locations, and so forth. | 
|  | 5092 | Contrast this behavior with cooked mode where Wic | 
|  | 5093 | looks in the Build Directory (e.g. | 
|  | 5094 | <filename>tmp/deploy/images/</filename><replaceable>machine</replaceable>). | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 5095 | </para> | 
|  | 5096 |  | 
|  | 5097 | <para> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5098 | The general form of the | 
|  | 5099 | <filename>wic</filename> command in raw mode is: | 
|  | 5100 | <literallayout class='monospaced'> | 
|  | 5101 | $ wic create <replaceable>wks_file</replaceable> <replaceable>options</replaceable> ... | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5102 |  | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 5103 | Where: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5104 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5105 | <replaceable>wks_file</replaceable>: | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 5106 | An OpenEmbedded kickstart file.  You can provide | 
|  | 5107 | your own custom file or use a file from a set of | 
|  | 5108 | existing files as described by further options. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5109 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5110 | optional arguments: | 
|  | 5111 | -h, --help            show this help message and exit | 
|  | 5112 | -o <replaceable>OUTDIR</replaceable>, --outdir <replaceable>OUTDIR</replaceable> | 
|  | 5113 | name of directory to create image in | 
|  | 5114 | -e <replaceable>IMAGE_NAME</replaceable>, --image-name <replaceable>IMAGE_NAME</replaceable> | 
|  | 5115 | name of the image to use the artifacts from e.g. core- | 
|  | 5116 | image-sato | 
|  | 5117 | -r <replaceable>ROOTFS_DIR</replaceable>, --rootfs-dir <replaceable>ROOTFS_DIR</replaceable> | 
|  | 5118 | path to the /rootfs dir to use as the .wks rootfs | 
|  | 5119 | source | 
|  | 5120 | -b <replaceable>BOOTIMG_DIR</replaceable>, --bootimg-dir <replaceable>BOOTIMG_DIR</replaceable> | 
|  | 5121 | path to the dir containing the boot artifacts (e.g. | 
|  | 5122 | /EFI or /syslinux dirs) to use as the .wks bootimg | 
|  | 5123 | source | 
|  | 5124 | -k <replaceable>KERNEL_DIR</replaceable>, --kernel-dir <replaceable>KERNEL_DIR</replaceable> | 
|  | 5125 | path to the dir containing the kernel to use in the | 
|  | 5126 | .wks bootimg | 
|  | 5127 | -n <replaceable>NATIVE_SYSROOT</replaceable>, --native-sysroot <replaceable>NATIVE_SYSROOT</replaceable> | 
|  | 5128 | path to the native sysroot containing the tools to use | 
|  | 5129 | to build the image | 
|  | 5130 | -s, --skip-build-check | 
|  | 5131 | skip the build check | 
|  | 5132 | -f, --build-rootfs    build rootfs | 
|  | 5133 | -c {gzip,bzip2,xz}, --compress-with {gzip,bzip2,xz} | 
|  | 5134 | compress image with specified compressor | 
|  | 5135 | -m, --bmap            generate .bmap | 
|  | 5136 | --no-fstab-update     Do not change fstab file. | 
|  | 5137 | -v <replaceable>VARS_DIR</replaceable>, --vars <replaceable>VARS_DIR</replaceable> | 
|  | 5138 | directory with <image>.env files that store bitbake | 
|  | 5139 | variables | 
|  | 5140 | -D, --debug           output debug information | 
|  | 5141 | </literallayout> | 
|  | 5142 | <note> | 
|  | 5143 | You do not need root privileges to run | 
|  | 5144 | Wic. | 
|  | 5145 | In fact, you should not run as root when using the | 
|  | 5146 | utility. | 
|  | 5147 | </note> | 
|  | 5148 | </para> | 
|  | 5149 | </section> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5150 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5151 | <section id='cooked-mode'> | 
|  | 5152 | <title>Cooked Mode</title> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5153 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5154 | <para> | 
|  | 5155 | Running Wic in cooked mode leverages off artifacts in | 
|  | 5156 | Build Directory. | 
|  | 5157 | In other words, you do not have to specify kernel or | 
|  | 5158 | root filesystem locations as part of the command. | 
|  | 5159 | All you need to provide is a kickstart file and the | 
|  | 5160 | name of the image from which to use artifacts by using | 
|  | 5161 | the "-e" option. | 
|  | 5162 | Wic looks in the Build Directory (e.g. | 
|  | 5163 | <filename>tmp/deploy/images/</filename><replaceable>machine</replaceable>) | 
|  | 5164 | for artifacts. | 
|  | 5165 | </para> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5166 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5167 | <para> | 
|  | 5168 | The general form of the <filename>wic</filename> | 
|  | 5169 | command using Cooked Mode is as follows: | 
|  | 5170 | <literallayout class='monospaced'> | 
|  | 5171 | $ wic create <replaceable>wks_file</replaceable> -e <replaceable>IMAGE_NAME</replaceable> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5172 |  | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 5173 | Where: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5174 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5175 | <replaceable>wks_file</replaceable>: | 
|  | 5176 | An OpenEmbedded kickstart file.  You can provide | 
|  | 5177 | your own custom file or use a file from a set of | 
|  | 5178 | existing files provided with the Yocto Project | 
|  | 5179 | release. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5180 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5181 | required argument: | 
|  | 5182 | -e <replaceable>IMAGE_NAME</replaceable>, --image-name <replaceable>IMAGE_NAME</replaceable> | 
|  | 5183 | name of the image to use the artifacts from e.g. core- | 
|  | 5184 | image-sato | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 5185 | </literallayout> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5186 | </para> | 
|  | 5187 | </section> | 
|  | 5188 | </section> | 
|  | 5189 |  | 
|  | 5190 | <section id='using-a-provided-kickstart-file'> | 
|  | 5191 | <title>Using an Existing Kickstart File</title> | 
|  | 5192 |  | 
|  | 5193 | <para> | 
|  | 5194 | If you do not want to create your own kickstart file, you | 
|  | 5195 | can use an existing file provided by the Wic installation. | 
|  | 5196 | As shipped, kickstart files can be found in the | 
|  | 5197 | Yocto Project | 
|  | 5198 | <ulink url='&YOCTO_DOCS_REF_URL;#source-repositories'>Source Repositories</ulink> | 
|  | 5199 | in the following two locations: | 
|  | 5200 | <literallayout class='monospaced'> | 
|  | 5201 | poky/meta-yocto-bsp/wic | 
|  | 5202 | poky/scripts/lib/wic/canned-wks | 
|  | 5203 | </literallayout> | 
|  | 5204 | Use the following command to list the available kickstart | 
|  | 5205 | files: | 
|  | 5206 | <literallayout class='monospaced'> | 
|  | 5207 | $ wic list images | 
|  | 5208 | beaglebone                    		Create SD card image for Beaglebone | 
|  | 5209 | mpc8315e-rdb                  		Create SD card image for MPC8315E-RDB | 
|  | 5210 | genericx86                    		Create an EFI disk image for genericx86* | 
|  | 5211 | edgerouter                    		Create SD card image for Edgerouter | 
|  | 5212 | qemux86-directdisk            		Create a qemu machine 'pcbios' direct disk image | 
|  | 5213 | directdisk-gpt                		Create a 'pcbios' direct disk image | 
|  | 5214 | mkefidisk                     		Create an EFI disk image | 
|  | 5215 | directdisk                    		Create a 'pcbios' direct disk image | 
|  | 5216 | systemd-bootdisk              		Create an EFI disk image with systemd-boot | 
|  | 5217 | mkhybridiso                   		Create a hybrid ISO image | 
|  | 5218 | sdimage-bootpart              		Create SD card image with a boot partition | 
|  | 5219 | directdisk-multi-rootfs       		Create multi rootfs image using rootfs plugin | 
|  | 5220 | directdisk-bootloader-config  		Create a 'pcbios' direct disk image with custom bootloader config | 
|  | 5221 | </literallayout> | 
|  | 5222 | When you use an existing file, you do not have to use the | 
|  | 5223 | <filename>.wks</filename> extension. | 
|  | 5224 | Here is an example in Raw Mode that uses the | 
|  | 5225 | <filename>directdisk</filename> file: | 
|  | 5226 | <literallayout class='monospaced'> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5227 | $ wic create directdisk -r <replaceable>rootfs_dir</replaceable> -b <replaceable>bootimg_dir</replaceable> \ | 
|  | 5228 | -k <replaceable>kernel_dir</replaceable> -n <replaceable>native_sysroot</replaceable> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5229 | </literallayout> | 
|  | 5230 | </para> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5231 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5232 | <para> | 
|  | 5233 | Here are the actual partition language commands | 
|  | 5234 | used in the <filename>genericx86.wks</filename> file to | 
|  | 5235 | generate an image: | 
|  | 5236 | <literallayout class='monospaced'> | 
|  | 5237 | # short-description: Create an EFI disk image for genericx86* | 
|  | 5238 | # long-description: Creates a partitioned EFI disk image for genericx86* machines | 
|  | 5239 | part /boot --source bootimg-efi --sourceparams="loader=grub-efi" --ondisk sda --label msdos --active --align 1024 | 
|  | 5240 | part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5241 | part swap --ondisk sda --size 44 --label swap1 --fstype=swap | 
|  | 5242 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5243 | bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=ttyS0,115200 console=tty0" | 
|  | 5244 | </literallayout> | 
|  | 5245 | </para> | 
|  | 5246 | </section> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5247 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5248 | <section id='wic-usage-examples'> | 
|  | 5249 | <title>Examples</title> | 
|  | 5250 |  | 
|  | 5251 | <para> | 
|  | 5252 | This section provides several examples that show how to use | 
|  | 5253 | the Wic utility. | 
|  | 5254 | All the examples assume the list of requirements in the | 
|  | 5255 | "<link linkend='wic-requirements'>Requirements</link>" | 
|  | 5256 | section have been met. | 
|  | 5257 | The examples assume the previously generated image is | 
|  | 5258 | <filename>core-image-minimal</filename>. | 
|  | 5259 | </para> | 
|  | 5260 |  | 
|  | 5261 | <section id='generate-an-image-using-a-provided-kickstart-file'> | 
|  | 5262 | <title>Generate an Image using an Existing Kickstart File</title> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5263 |  | 
|  | 5264 | <para> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5265 | This example runs in Cooked Mode and uses the | 
|  | 5266 | <filename>mkefidisk</filename> kickstart file: | 
|  | 5267 | <literallayout class='monospaced'> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5268 | $ wic create mkefidisk -e core-image-minimal | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5269 | INFO: Building wic-tools... | 
|  | 5270 | . | 
|  | 5271 | . | 
|  | 5272 | . | 
|  | 5273 | INFO: The new image(s) can be found here: | 
|  | 5274 | ./mkefidisk-201710061409-sda.direct | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5275 |  | 
|  | 5276 | The following build artifacts were used to create the image(s): | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5277 | ROOTFS_DIR:                   /home/scottrif/poky/build/tmp.wic.r4hkds0b/rootfs_copy | 
|  | 5278 | BOOTIMG_DIR:                  /home/scottrif/poky/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share | 
|  | 5279 | KERNEL_DIR:                   /home/scottrif/poky/build/tmp/deploy/images/qemux86 | 
|  | 5280 | NATIVE_SYSROOT:               /home/scottrif/poky/build/tmp/work/i586-poky-linux/wic-tools/1.0-r0/recipe-sysroot-native | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5281 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5282 | INFO: The image(s) were created using OE kickstart file: | 
|  | 5283 | /home/scottrif/poky/scripts/lib/wic/canned-wks/mkefidisk.wks | 
|  | 5284 | </literallayout> | 
|  | 5285 | The previous example shows the easiest way to create | 
|  | 5286 | an image by running in cooked mode and supplying | 
|  | 5287 | a kickstart file and the "-e" option to point to the | 
|  | 5288 | existing build artifacts. | 
|  | 5289 | Your <filename>local.conf</filename> file needs to have | 
|  | 5290 | the | 
|  | 5291 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink> | 
|  | 5292 | variable set to the machine you are using, which is | 
|  | 5293 | "qemux86" in this example. | 
|  | 5294 | </para> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5295 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5296 | <para> | 
|  | 5297 | Once the image builds, the output provides image | 
|  | 5298 | location, artifact use, and kickstart file information. | 
|  | 5299 | <note> | 
|  | 5300 | You should always verify the details provided in the | 
|  | 5301 | output to make sure that the image was indeed | 
|  | 5302 | created exactly as expected. | 
|  | 5303 | </note> | 
|  | 5304 | </para> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5305 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5306 | <para> | 
|  | 5307 | Continuing with the example, you can now write the | 
|  | 5308 | image to a USB stick, or whatever media for which you | 
|  | 5309 | built your image, and boot from the media. | 
|  | 5310 | You can write the image by using | 
|  | 5311 | <filename>bmaptool</filename> or | 
|  | 5312 | <filename>dd</filename>: | 
|  | 5313 | <literallayout class='monospaced'> | 
|  | 5314 | $ oe-run-native bmaptool copy build/mkefidisk-201710061409-sda.direct /dev/sd<replaceable>X</replaceable> | 
|  | 5315 | </literallayout> | 
|  | 5316 | or | 
|  | 5317 | <literallayout class='monospaced'> | 
|  | 5318 | $ sudo dd if=build/mkefidisk-201710061409-sda.direct of=/dev/sd<replaceable>X</replaceable> | 
|  | 5319 | </literallayout> | 
|  | 5320 | <note> | 
|  | 5321 | For more information on how to use the | 
|  | 5322 | <filename>bmaptool</filename> to flash a device | 
|  | 5323 | with an image, see the | 
|  | 5324 | "<link linkend='flashing-images-using-bmaptool'>Flashing Images Using <filename>bmaptool</filename></link>" | 
|  | 5325 | section. | 
|  | 5326 | </note> | 
|  | 5327 | </para> | 
|  | 5328 | </section> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5329 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5330 | <section id='using-a-modified-kickstart-file'> | 
|  | 5331 | <title>Using a Modified Kickstart File</title> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5332 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5333 | <para> | 
|  | 5334 | Because partitioned image creation is driven by the | 
|  | 5335 | kickstart file, it is easy to affect image creation by | 
|  | 5336 | changing the parameters in the file. | 
|  | 5337 | This next example demonstrates that through modification | 
|  | 5338 | of the <filename>directdisk-gpt</filename> kickstart | 
|  | 5339 | file. | 
|  | 5340 | </para> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5341 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5342 | <para> | 
|  | 5343 | As mentioned earlier, you can use the command | 
|  | 5344 | <filename>wic list images</filename> to show the list | 
|  | 5345 | of existing kickstart files. | 
|  | 5346 | The directory in which the | 
|  | 5347 | <filename>directdisk-gpt.wks</filename> file resides is | 
|  | 5348 | <filename>scripts/lib/image/canned-wks/</filename>, | 
|  | 5349 | which is located in the | 
|  | 5350 | <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink> | 
|  | 5351 | (e.g. <filename>poky</filename>). | 
|  | 5352 | Because available files reside in this directory, | 
|  | 5353 | you can create and add your own custom files to the | 
|  | 5354 | directory. | 
|  | 5355 | Subsequent use of the | 
|  | 5356 | <filename>wic list images</filename> command would then | 
|  | 5357 | include your kickstart files. | 
|  | 5358 | </para> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5359 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5360 | <para> | 
|  | 5361 | In this example, the existing | 
|  | 5362 | <filename>directdisk-gpt</filename> file already does | 
|  | 5363 | most of what is needed. | 
|  | 5364 | However, for the hardware in this example, the image | 
|  | 5365 | will need to boot from <filename>sdb</filename> instead | 
|  | 5366 | of <filename>sda</filename>, which is what the | 
|  | 5367 | <filename>directdisk-gpt</filename> kickstart file | 
|  | 5368 | uses. | 
|  | 5369 | </para> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5370 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5371 | <para> | 
|  | 5372 | The example begins by making a copy of the | 
|  | 5373 | <filename>directdisk-gpt.wks</filename> file in the | 
|  | 5374 | <filename>scripts/lib/image/canned-wks</filename> | 
|  | 5375 | directory and then by changing the lines that specify | 
|  | 5376 | the target disk from which to boot. | 
|  | 5377 | <literallayout class='monospaced'> | 
|  | 5378 | $ cp /home/scottrif/poky/scripts/lib/wic/canned-wks/directdisk-gpt.wks \ | 
|  | 5379 | /home/scottrif/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks | 
|  | 5380 | </literallayout> | 
|  | 5381 | Next, the example modifies the | 
|  | 5382 | <filename>directdisksdb-gpt.wks</filename> file and | 
|  | 5383 | changes all instances of | 
|  | 5384 | "<filename>--ondisk sda</filename>" to | 
|  | 5385 | "<filename>--ondisk sdb</filename>". | 
|  | 5386 | The example changes the following two lines and leaves | 
|  | 5387 | the remaining lines untouched: | 
|  | 5388 | <literallayout class='monospaced'> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5389 | part /boot --source bootimg-pcbios --ondisk sdb --label boot --active --align 1024 | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5390 | part / --source rootfs --ondisk sdb --fstype=ext4 --label platform --align 1024 --use-uuid | 
|  | 5391 | </literallayout> | 
|  | 5392 | Once the lines are changed, the example generates the | 
|  | 5393 | <filename>directdisksdb-gpt</filename> image. | 
|  | 5394 | The command points the process at the | 
|  | 5395 | <filename>core-image-minimal</filename> artifacts for | 
|  | 5396 | the Next Unit of Computing (nuc) | 
|  | 5397 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink> | 
|  | 5398 | the <filename>local.conf</filename>. | 
|  | 5399 | <literallayout class='monospaced'> | 
|  | 5400 | $ wic create directdisksdb-gpt -e core-image-minimal | 
|  | 5401 | INFO: Building wic-tools... | 
|  | 5402 | . | 
|  | 5403 | . | 
|  | 5404 | . | 
|  | 5405 | Initialising tasks: 100% |#######################################| Time: 0:00:01 | 
|  | 5406 | NOTE: Executing SetScene Tasks | 
|  | 5407 | NOTE: Executing RunQueue Tasks | 
|  | 5408 | NOTE: Tasks Summary: Attempted 1161 tasks of which 1157 didn't need to be rerun and all succeeded. | 
|  | 5409 | INFO: Creating image(s)... | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5410 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5411 | INFO: The new image(s) can be found here: | 
|  | 5412 | ./directdisksdb-gpt-201710090938-sdb.direct | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5413 |  | 
|  | 5414 | The following build artifacts were used to create the image(s): | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5415 | ROOTFS_DIR:                   /home/scottrif/poky/build/tmp.wic.hk3wl6zn/rootfs_copy | 
|  | 5416 | BOOTIMG_DIR:                  /home/scottrif/poky/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share | 
|  | 5417 | KERNEL_DIR:                   /home/scottrif/poky/build/tmp/deploy/images/qemux86 | 
|  | 5418 | NATIVE_SYSROOT:               /home/scottrif/poky/build/tmp/work/i586-poky-linux/wic-tools/1.0-r0/recipe-sysroot-native | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 5419 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5420 | INFO: The image(s) were created using OE kickstart file: | 
|  | 5421 | /home/scottrif/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks | 
|  | 5422 | </literallayout> | 
|  | 5423 | Continuing with the example, you can now directly | 
|  | 5424 | <filename>dd</filename> the image to a USB stick, or | 
|  | 5425 | whatever media for which you built your image, | 
|  | 5426 | and boot the resulting media: | 
|  | 5427 | <literallayout class='monospaced'> | 
|  | 5428 | $ sudo dd if=directdisksdb-gpt-201710090938-sdb.direct of=/dev/sdb | 
|  | 5429 | 140966+0 records in | 
|  | 5430 | 140966+0 records out | 
|  | 5431 | 72174592 bytes (72 MB, 69 MiB) copied, 78.0282 s, 925 kB/s | 
|  | 5432 | $ sudo eject /dev/sdb | 
|  | 5433 | </literallayout> | 
|  | 5434 | </para> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5435 | </section> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5436 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5437 | <section id='using-a-modified-kickstart-file-and-running-in-raw-mode'> | 
|  | 5438 | <title>Using a Modified Kickstart File and Running in Raw Mode</title> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5439 |  | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 5440 | <para> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5441 | This next example manually specifies each build artifact | 
|  | 5442 | (runs in Raw Mode) and uses a modified kickstart file. | 
|  | 5443 | The example also uses the <filename>-o</filename> option | 
|  | 5444 | to cause Wic to create the output | 
|  | 5445 | somewhere other than the default output directory, | 
|  | 5446 | which is the current directory: | 
|  | 5447 | <literallayout class='monospaced'> | 
|  | 5448 | $ wic create /home/scottrif/my_yocto/test.wks -o /home/scottrif/testwic \ | 
|  | 5449 | --rootfs-dir /home/scottrif/poky/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/rootfs \ | 
|  | 5450 | --bootimg-dir /home/scottrif/poky/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share \ | 
|  | 5451 | --kernel-dir /home/scottrif/poky/build/tmp/deploy/images/qemux86 \ | 
|  | 5452 | --native-sysroot /home/scottrif/poky/build/tmp/work/i586-poky-linux/wic-tools/1.0-r0/recipe-sysroot-native | 
|  | 5453 |  | 
|  | 5454 | INFO: Creating image(s)... | 
|  | 5455 |  | 
|  | 5456 | INFO: The new image(s) can be found here: | 
|  | 5457 | /home/scottrif/testwic/test-201710091445-sdb.direct | 
|  | 5458 |  | 
|  | 5459 | The following build artifacts were used to create the image(s): | 
|  | 5460 | ROOTFS_DIR:                   /home/scottrif/testwic/tmp.wic.x4wipbmb/rootfs_copy | 
|  | 5461 | BOOTIMG_DIR:                  /home/scottrif/poky/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share | 
|  | 5462 | KERNEL_DIR:                   /home/scottrif/poky/build/tmp/deploy/images/qemux86 | 
|  | 5463 | NATIVE_SYSROOT:               /home/scottrif/poky/build/tmp/work/i586-poky-linux/wic-tools/1.0-r0/recipe-sysroot-native | 
|  | 5464 |  | 
|  | 5465 | INFO: The image(s) were created using OE kickstart file: | 
|  | 5466 | /home/scottrif/my_yocto/test.wks | 
|  | 5467 | </literallayout> | 
|  | 5468 | For this example, | 
|  | 5469 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink> | 
|  | 5470 | did not have to be specified in the | 
|  | 5471 | <filename>local.conf</filename> file since the | 
|  | 5472 | artifact is manually specified. | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 5473 | </para> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5474 | </section> | 
|  | 5475 |  | 
|  | 5476 | <section id='using-wic-to-manipulate-an-image'> | 
|  | 5477 | <title>Using Wic to Manipulate an Image</title> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5478 |  | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 5479 | <para> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5480 | Wic image manipulation allows you to shorten turnaround | 
|  | 5481 | time during image development. | 
|  | 5482 | For example, you can use Wic to delete the kernel partition | 
|  | 5483 | of a Wic image and then insert a newly built kernel. | 
|  | 5484 | This saves you time from having to rebuild the entire image | 
|  | 5485 | each time you modify the kernel. | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 5486 | <note> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5487 | In order to use Wic to manipulate a Wic image as in | 
|  | 5488 | this example, your development machine must have the | 
|  | 5489 | <filename>mtools</filename> package installed. | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 5490 | </note> | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 5491 | </para> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5492 |  | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 5493 | <para> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5494 | The following example examines the contents of the Wic | 
|  | 5495 | image, deletes the existing kernel, and then inserts a | 
|  | 5496 | new kernel: | 
|  | 5497 | <orderedlist> | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 5498 | <listitem><para> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5499 | <emphasis>List the Partitions:</emphasis> | 
|  | 5500 | Use the <filename>wic ls</filename> command to list | 
|  | 5501 | all the partitions in the Wic image: | 
|  | 5502 | <literallayout class='monospaced'> | 
|  | 5503 | $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic | 
|  | 5504 | Num     Start        End          Size      Fstype | 
|  | 5505 | 1       1048576     25041919     23993344  fat16 | 
|  | 5506 | 2      25165824     72157183     46991360  ext4 | 
|  | 5507 | </literallayout> | 
|  | 5508 | The previous output shows two partitions in the | 
|  | 5509 | <filename>core-image-minimal-qemux86.wic</filename> | 
|  | 5510 | image. | 
|  | 5511 | </para></listitem> | 
|  | 5512 | <listitem><para> | 
|  | 5513 | <emphasis>Examine a Particular Partition:</emphasis> | 
|  | 5514 | Use the <filename>wic ls</filename> command again | 
|  | 5515 | but in a different form to examine a particular | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 5516 | partition. | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 5517 | <note> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5518 | You can get command usage on any Wic command | 
|  | 5519 | using the following form: | 
|  | 5520 | <literallayout class='monospaced'> | 
|  | 5521 | $ wic help <replaceable>command</replaceable> | 
|  | 5522 | </literallayout> | 
|  | 5523 | For example, the following command shows you | 
|  | 5524 | the various ways to use the | 
|  | 5525 | <filename>wic ls</filename> command: | 
|  | 5526 | <literallayout class='monospaced'> | 
|  | 5527 | $ wic help ls | 
|  | 5528 | </literallayout> | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 5529 | </note> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5530 | The following command shows what is in Partition | 
|  | 5531 | one: | 
|  | 5532 | <literallayout class='monospaced'> | 
|  | 5533 | $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1 | 
|  | 5534 | Volume in drive : is boot | 
|  | 5535 | Volume Serial Number is E894-1809 | 
|  | 5536 | Directory for ::/ | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 5537 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5538 | libcom32 c32    186500 2017-10-09  16:06 | 
|  | 5539 | libutil  c32     24148 2017-10-09  16:06 | 
|  | 5540 | syslinux cfg       220 2017-10-09  16:06 | 
|  | 5541 | vesamenu c32     27104 2017-10-09  16:06 | 
|  | 5542 | vmlinuz        6904608 2017-10-09  16:06 | 
|  | 5543 | 5 files           7 142 580 bytes | 
|  | 5544 | 16 582 656 bytes free | 
|  | 5545 | </literallayout> | 
|  | 5546 | The previous output shows five files, with the | 
|  | 5547 | <filename>vmlinuz</filename> being the kernel. | 
|  | 5548 | <note> | 
|  | 5549 | If you see the following error, you need to | 
|  | 5550 | update or create a | 
|  | 5551 | <filename>~/.mtoolsrc</filename> file and | 
|  | 5552 | be sure to have the line “mtools_skip_check=1“ | 
|  | 5553 | in the file. | 
|  | 5554 | Then, run the Wic command again: | 
|  | 5555 | <literallayout class='monospaced'> | 
|  | 5556 | ERROR: _exec_cmd: /usr/bin/mdir -i /tmp/wic-parttfokuwra ::/ returned '1' instead of 0 | 
|  | 5557 | output: Total number of sectors (47824) not a multiple of sectors per track (32)! | 
|  | 5558 | Add mtools_skip_check=1 to your .mtoolsrc file to skip this test | 
|  | 5559 | </literallayout> | 
|  | 5560 | </note> | 
|  | 5561 | </para></listitem> | 
|  | 5562 | <listitem><para> | 
|  | 5563 | <emphasis>Remove the Old Kernel:</emphasis> | 
|  | 5564 | Use the <filename>wic rm</filename> command to | 
|  | 5565 | remove the <filename>vmlinuz</filename> file | 
|  | 5566 | (kernel): | 
|  | 5567 | <literallayout class='monospaced'> | 
|  | 5568 | $ wic rm tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz | 
|  | 5569 | </literallayout> | 
|  | 5570 | </para></listitem> | 
|  | 5571 | <listitem><para> | 
|  | 5572 | <emphasis>Add In the New Kernel:</emphasis> | 
|  | 5573 | Use the <filename>wic cp</filename> command to | 
|  | 5574 | add the updated kernel to the Wic image. | 
|  | 5575 | Depending on how you built your kernel, it could | 
|  | 5576 | be in different places. | 
|  | 5577 | If you used <filename>devtool</filename> and | 
|  | 5578 | an SDK to build your kernel, it resides in the | 
|  | 5579 | <filename>tmp/work</filename> directory of the | 
|  | 5580 | extensible SDK. | 
|  | 5581 | If you used <filename>make</filename> to build the | 
|  | 5582 | kernel, the kernel will be in the | 
|  | 5583 | <filename>workspace/sources</filename> area. | 
|  | 5584 | </para> | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 5585 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5586 | <para>The following example assumes | 
|  | 5587 | <filename>devtool</filename> was used to build | 
|  | 5588 | the kernel: | 
|  | 5589 | <literallayout class='monospaced'> | 
|  | 5590 | cp ~/poky_sdk/tmp/work/qemux86-poky-linux/linux-yocto/4.12.12+git999-r0/linux-yocto-4.12.12+git999/arch/x86/boot/bzImage \ | 
|  | 5591 | ~/poky/build/tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz | 
|  | 5592 | </literallayout> | 
|  | 5593 | Once the new kernel is added back into the image, | 
|  | 5594 | you can use the <filename>dd</filename> | 
|  | 5595 | command or | 
|  | 5596 | <link linkend='flashing-images-using-bmaptool'><filename>bmaptool</filename></link> | 
|  | 5597 | to flash your wic image onto an SD card | 
|  | 5598 | or USB stick and test your target. | 
|  | 5599 | <note> | 
|  | 5600 | Using <filename>bmaptool</filename> is | 
|  | 5601 | generally 10 to 20 times faster than using | 
|  | 5602 | <filename>dd</filename>. | 
|  | 5603 | </note> | 
|  | 5604 | </para></listitem> | 
|  | 5605 | </orderedlist> | 
|  | 5606 | </para> | 
|  | 5607 | </section> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5608 | </section> | 
|  | 5609 | </section> | 
|  | 5610 |  | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 5611 | <section id='building-an-initramfs-image'> | 
|  | 5612 | <title>Building an Initial RAM Filesystem (initramfs) Image</title> | 
|  | 5613 |  | 
|  | 5614 | <para> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5615 | An initial RAM filesystem (initramfs) image provides a temporary | 
|  | 5616 | root filesystem used for early system initialization (e.g. | 
|  | 5617 | loading of modules needed to locate and mount the "real" root | 
|  | 5618 | filesystem). | 
|  | 5619 | <note> | 
|  | 5620 | The initramfs image is the successor of initial RAM disk | 
|  | 5621 | (initrd). | 
|  | 5622 | It is a "copy in and out" (cpio) archive of the initial | 
|  | 5623 | filesystem that gets loaded into memory during the Linux | 
|  | 5624 | startup process. | 
|  | 5625 | Because Linux uses the contents of the archive during | 
|  | 5626 | initialization, the initramfs image needs to contain all of the | 
|  | 5627 | device drivers and tools needed to mount the final root | 
|  | 5628 | filesystem. | 
|  | 5629 | </note> | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 5630 | </para> | 
|  | 5631 |  | 
|  | 5632 | <para> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5633 | Follow these steps to create an initramfs image: | 
|  | 5634 | <orderedlist> | 
|  | 5635 | <listitem><para> | 
|  | 5636 | <emphasis>Create the initramfs Image Recipe:</emphasis> | 
|  | 5637 | You can reference the | 
|  | 5638 | <filename>core-image-minimal-initramfs.bb</filename> | 
|  | 5639 | recipe found in the <filename>meta/recipes-core</filename> | 
|  | 5640 | directory of the | 
|  | 5641 | <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink> | 
|  | 5642 | as an example from which to work. | 
|  | 5643 | </para></listitem> | 
|  | 5644 | <listitem><para> | 
|  | 5645 | <emphasis>Decide if You Need to Bundle the initramfs Image | 
|  | 5646 | Into the Kernel Image:</emphasis> | 
|  | 5647 | If you want the initramfs image that is built to be | 
|  | 5648 | bundled in with the kernel image, set the | 
|  | 5649 | <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRAMFS_IMAGE_BUNDLE'><filename>INITRAMFS_IMAGE_BUNDLE</filename></ulink> | 
|  | 5650 | variable to "1" in your <filename>local.conf</filename> | 
|  | 5651 | configuration file and set the | 
|  | 5652 | <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRAMFS_IMAGE'><filename>INITRAMFS_IMAGE</filename></ulink> | 
|  | 5653 | variable in the recipe that builds the kernel image. | 
|  | 5654 | <note><title>Tip</title> | 
|  | 5655 | It is recommended that you do bundle the initramfs | 
|  | 5656 | image with the kernel image to avoid circular | 
|  | 5657 | dependencies between the kernel recipe and the | 
|  | 5658 | initramfs recipe should the initramfs image | 
|  | 5659 | include kernel modules. | 
|  | 5660 | </note> | 
|  | 5661 | Setting the <filename>INITRAMFS_IMAGE_BUNDLE</filename> | 
|  | 5662 | flag causes the initramfs image to be unpacked | 
|  | 5663 | into the <filename>${B}/usr/</filename> directory. | 
|  | 5664 | The unpacked initramfs image is then passed to the kernel's | 
|  | 5665 | <filename>Makefile</filename> using the | 
|  | 5666 | <ulink url='&YOCTO_DOCS_REF_URL;#var-CONFIG_INITRAMFS_SOURCE'><filename>CONFIG_INITRAMFS_SOURCE</filename></ulink> | 
|  | 5667 | variable, allowing the initramfs image to be built into | 
|  | 5668 | the kernel normally. | 
|  | 5669 | <note> | 
|  | 5670 | If you choose to not bundle the initramfs image with | 
|  | 5671 | the kernel image, you are essentially using an | 
|  | 5672 | <ulink url='https://en.wikipedia.org/wiki/Initrd'>Initial RAM Disk (initrd)</ulink>. | 
|  | 5673 | Creating an initrd is handled primarily through the | 
|  | 5674 | <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRD_IMAGE'><filename>INITRD_IMAGE</filename></ulink>, | 
|  | 5675 | <filename>INITRD_LIVE</filename>, and | 
|  | 5676 | <filename>INITRD_IMAGE_LIVE</filename> variables. | 
|  | 5677 | For more information, see the | 
|  | 5678 | <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/poky/tree/meta/classes/image-live.bbclass'><filename>image-live.bbclass</filename></ulink> | 
|  | 5679 | file. | 
|  | 5680 | </note> | 
|  | 5681 | </para></listitem> | 
|  | 5682 | <!-- | 
|  | 5683 | Some notes from Cal: | 
|  | 5684 |  | 
|  | 5685 | A non-bundled initramfs is essentially an initrd, which I am discovering | 
|  | 5686 | to be rather confusingly supported in OE at the moment. | 
|  | 5687 |  | 
|  | 5688 | Its primarily handled through INITRD_IMAGE(_LIVE/_VM) and INITRD(_LIVE/_VM) | 
|  | 5689 | variables. INITRD_IMAGE* is the primary image target, which gets added to | 
|  | 5690 | INITRD*, which is a list of cpio filesystems. You can add more cpio | 
|  | 5691 | filesystems to the INITRD variable to add more to the initrd. For | 
|  | 5692 | instance, meta-intel adds intel-microcode via the following: | 
|  | 5693 |  | 
|  | 5694 | INITRD_LIVE_prepend = "${@bb.utils.contains('MACHINE_FEATURES', 'intel-ucode', '${DEPLOY_DIR_IMAGE}/microcode.cpio ', '', d)}" | 
|  | 5695 |  | 
|  | 5696 | If 'intel-ucode' is in MACHINE_FEATURES, this resolves to: | 
|  | 5697 |  | 
|  | 5698 | INITRD_LIVE_prepend = "${DEPLOY_DIR_IMAGE}/microcode.cpio " | 
|  | 5699 |  | 
|  | 5700 | Unfortunately you need the full path, and its up to you to sort out | 
|  | 5701 | dependencies as well. For instance, we have the following: | 
|  | 5702 |  | 
|  | 5703 | MACHINE_ESSENTIAL_EXTRA_RDEPENDS_append = "${@bb.utils.contains('MACHINE_FEATURES', 'intel-ucode', ' intel-microcode', '', d)}" | 
|  | 5704 |  | 
|  | 5705 | which resolves to: | 
|  | 5706 |  | 
|  | 5707 | MACHINE_ESSENTIAL_EXTRA_RDEPENDS_append = "intel-microcode" | 
|  | 5708 |  | 
|  | 5709 | However, the above is only true with the "live" IMAGE_FSTYPE. Wic is | 
|  | 5710 | another beast entirely, with current wic kickstart files not supporting | 
|  | 5711 | initrds, and only partial support in the source plugins. That being said, | 
|  | 5712 | I know the generic bootfs work Ed is working on will help immensely in this | 
|  | 5713 | aspect. He or Saul can provide more details here. | 
|  | 5714 |  | 
|  | 5715 | Anyhow, its rather fractured and confusing and could probably use a | 
|  | 5716 | rework honestly. I don't know how feasible it is to document all the | 
|  | 5717 | details and corner cases of this area. | 
|  | 5718 | --> | 
|  | 5719 | <listitem><para> | 
|  | 5720 | <emphasis>Optionally Add Items to the initramfs Image | 
|  | 5721 | Through the initramfs Image Recipe:</emphasis> | 
|  | 5722 | If you add items to the initramfs image by way of its | 
|  | 5723 | recipe, you should use | 
|  | 5724 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_INSTALL'><filename>PACKAGE_INSTALL</filename></ulink> | 
|  | 5725 | rather than | 
|  | 5726 | <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>. | 
|  | 5727 | <filename>PACKAGE_INSTALL</filename> gives more direct | 
|  | 5728 | control of what is added to the image as compared to | 
|  | 5729 | the defaults you might not necessarily want that are | 
|  | 5730 | set by the | 
|  | 5731 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-image'><filename>image</filename></ulink> | 
|  | 5732 | or | 
|  | 5733 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-core-image'><filename>core-image</filename></ulink> | 
|  | 5734 | classes. | 
|  | 5735 | </para></listitem> | 
|  | 5736 | <listitem><para> | 
|  | 5737 | <emphasis>Build the Kernel Image and the initramfs | 
|  | 5738 | Image:</emphasis> | 
|  | 5739 | Build your kernel image using BitBake. | 
|  | 5740 | Because the initramfs image recipe is a dependency of the | 
|  | 5741 | kernel image, the initramfs image is built as well and | 
|  | 5742 | bundled with the kernel image if you used the | 
|  | 5743 | <ulink url='&YOCTO_DOCS_REF_URL;#var-INITRAMFS_IMAGE_BUNDLE'><filename>INITRAMFS_IMAGE_BUNDLE</filename></ulink> | 
|  | 5744 | variable described earlier. | 
|  | 5745 | </para></listitem> | 
|  | 5746 | </orderedlist> | 
|  | 5747 | </para> | 
|  | 5748 | </section> | 
|  | 5749 |  | 
|  | 5750 | <section id='flashing-images-using-bmaptool'> | 
|  | 5751 | <title>Flashing Images Using <filename>bmaptool</filename></title> | 
|  | 5752 |  | 
|  | 5753 | <para> | 
|  | 5754 | An easy way to flash an image to a bootable device is to use | 
|  | 5755 | <filename>bmaptool</filename>, which is integrated into the | 
|  | 5756 | OpenEmbedded build system. | 
|  | 5757 | </para> | 
|  | 5758 |  | 
|  | 5759 | <para> | 
|  | 5760 | Following, is an example that shows how to flash a Wic image. | 
|  | 5761 | <note> | 
|  | 5762 | You can use <filename>bmaptool</filename> to flash any | 
|  | 5763 | type of image. | 
|  | 5764 | </note> | 
|  | 5765 | Use these steps to flash an image using | 
|  | 5766 | <filename>bmaptool</filename>: | 
|  | 5767 | <note> | 
|  | 5768 | Unless you are able to install the | 
|  | 5769 | <filename>bmap-tools</filename> package as mentioned in the note | 
|  | 5770 | in the second bullet of step 3 further down, you will need to build | 
|  | 5771 | <filename>bmaptool</filename> before using it. | 
|  | 5772 | Build the tool using the following command: | 
|  | 5773 | <literallayout class='monospaced'> | 
|  | 5774 | $ bitbake bmap-tools-native | 
|  | 5775 | </literallayout> | 
|  | 5776 | </note> | 
|  | 5777 | <orderedlist> | 
|  | 5778 | <listitem><para> | 
|  | 5779 | <emphasis>Update the <filename>local.conf</filename> File:</emphasis> | 
|  | 5780 | Add the following to your <filename>local.conf</filename> | 
|  | 5781 | file: | 
|  | 5782 | <literallayout class='monospaced'> | 
|  | 5783 | IMAGE_FSTYPES += "wic wic.bmap" | 
|  | 5784 | </literallayout> | 
|  | 5785 | </para></listitem> | 
|  | 5786 | <listitem><para> | 
|  | 5787 | <emphasis>Get Your Image:</emphasis> | 
|  | 5788 | Either have your image ready (pre-built) or take the step | 
|  | 5789 | build the image: | 
|  | 5790 | <literallayout class='monospaced'> | 
|  | 5791 | $ bitbake <replaceable>image</replaceable> | 
|  | 5792 | </literallayout> | 
|  | 5793 | </para></listitem> | 
|  | 5794 | <listitem><para> | 
|  | 5795 | <emphasis>Flash the Device:</emphasis> | 
|  | 5796 | Flash the device with the image by using | 
|  | 5797 | <filename>bmaptool</filename> depending on your particular | 
|  | 5798 | setup: | 
|  | 5799 | <itemizedlist> | 
|  | 5800 | <listitem><para> | 
|  | 5801 | If you have write access to the media, | 
|  | 5802 | use this command form: | 
|  | 5803 | <literallayout class='monospaced'> | 
|  | 5804 | $ oe-run-native bmap-tools-native bmaptool copy ./tmp/deploy/images/qemux86-64-core-image-minimal-<replaceable>machine</replaceable>.wic /dev/sd<replaceable>X</replaceable> | 
|  | 5805 | </literallayout> | 
|  | 5806 | </para></listitem> | 
|  | 5807 | <listitem><para> | 
|  | 5808 | If you do not have write access to | 
|  | 5809 | the media, use the following | 
|  | 5810 | commands: | 
|  | 5811 | <literallayout class='monospaced'> | 
|  | 5812 | $ sudo chmod 666 /dev/sd<replaceable>X</replaceable> | 
|  | 5813 | $ oe-run-native bmap-tools-native bmaptool copy ./tmp/deploy/images/qemux86-64-core-image-minimal-<replaceable>machine</replaceable>.wic /dev/sd<replaceable>X</replaceable> | 
|  | 5814 | </literallayout> | 
|  | 5815 | <note> | 
|  | 5816 | If you are using Ubuntu or Debian distributions, | 
|  | 5817 | you can install the | 
|  | 5818 | <filename>bmap-tools</filename> package using | 
|  | 5819 | the following command and then use the tool | 
|  | 5820 | without specifying | 
|  | 5821 | <filename>PATH</filename> even from the | 
|  | 5822 | root account: | 
|  | 5823 | <literallayout class='monospaced'> | 
|  | 5824 | $ sudo apt-get install bmap-tools | 
|  | 5825 | </literallayout> | 
|  | 5826 | </note> | 
|  | 5827 | </para></listitem> | 
|  | 5828 | </itemizedlist> | 
|  | 5829 | </para></listitem> | 
|  | 5830 | </orderedlist> | 
|  | 5831 | </para> | 
|  | 5832 |  | 
|  | 5833 | <para> | 
|  | 5834 | For help on the <filename>bmaptool</filename> command, use the | 
|  | 5835 | following command: | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 5836 | <literallayout class='monospaced'> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5837 | $ bmaptool --help | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 5838 | </literallayout> | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 5839 | </para> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5840 | </section> | 
|  | 5841 |  | 
|  | 5842 | <section id='making-images-more-secure'> | 
|  | 5843 | <title>Making Images More Secure</title> | 
|  | 5844 |  | 
|  | 5845 | <para> | 
|  | 5846 | Security is of increasing concern for embedded devices. | 
|  | 5847 | Consider the issues and problems discussed in just this | 
|  | 5848 | sampling of work found across the Internet: | 
|  | 5849 | <itemizedlist> | 
|  | 5850 | <listitem><para><emphasis> | 
|  | 5851 | "<ulink url='https://www.schneier.com/blog/archives/2014/01/security_risks_9.html'>Security Risks of Embedded Systems</ulink>"</emphasis> | 
|  | 5852 | by Bruce Schneier | 
|  | 5853 | </para></listitem> | 
|  | 5854 | <listitem><para><emphasis> | 
|  | 5855 | "<ulink url='http://internetcensus2012.bitbucket.org/paper.html'>Internet Census 2012</ulink>"</emphasis> | 
|  | 5856 | by Carna Botnet</para></listitem> | 
|  | 5857 | <listitem><para><emphasis> | 
|  | 5858 | "<ulink url='http://elinux.org/images/6/6f/Security-issues.pdf'>Security Issues for Embedded Devices</ulink>"</emphasis> | 
|  | 5859 | by Jake Edge | 
|  | 5860 | </para></listitem> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5861 | </itemizedlist> | 
|  | 5862 | </para> | 
|  | 5863 |  | 
|  | 5864 | <para> | 
|  | 5865 | When securing your image is of concern, there are steps, tools, | 
|  | 5866 | and variables that you can consider to help you reach the | 
|  | 5867 | security goals you need for your particular device. | 
|  | 5868 | Not all situations are identical when it comes to making an | 
|  | 5869 | image secure. | 
|  | 5870 | Consequently, this section provides some guidance and suggestions | 
|  | 5871 | for consideration when you want to make your image more secure. | 
|  | 5872 | <note> | 
|  | 5873 | Because the security requirements and risks are | 
|  | 5874 | different for every type of device, this section cannot | 
|  | 5875 | provide a complete reference on securing your custom OS. | 
|  | 5876 | It is strongly recommended that you also consult other sources | 
|  | 5877 | of information on embedded Linux system hardening and on | 
|  | 5878 | security. | 
|  | 5879 | </note> | 
|  | 5880 | </para> | 
|  | 5881 |  | 
|  | 5882 | <section id='general-considerations'> | 
|  | 5883 | <title>General Considerations</title> | 
|  | 5884 |  | 
|  | 5885 | <para> | 
|  | 5886 | General considerations exist that help you create more | 
|  | 5887 | secure images. | 
|  | 5888 | You should consider the following suggestions to help | 
|  | 5889 | make your device more secure: | 
|  | 5890 | <itemizedlist> | 
|  | 5891 | <listitem><para> | 
|  | 5892 | Scan additional code you are adding to the system | 
|  | 5893 | (e.g. application code) by using static analysis | 
|  | 5894 | tools. | 
|  | 5895 | Look for buffer overflows and other potential | 
|  | 5896 | security problems. | 
|  | 5897 | </para></listitem> | 
|  | 5898 | <listitem><para> | 
|  | 5899 | Pay particular attention to the security for | 
|  | 5900 | any web-based administration interface. | 
|  | 5901 | </para> | 
|  | 5902 | <para>Web interfaces typically need to perform | 
|  | 5903 | administrative functions and tend to need to run with | 
|  | 5904 | elevated privileges. | 
|  | 5905 | Thus, the consequences resulting from the interface's | 
|  | 5906 | security becoming compromised can be serious. | 
|  | 5907 | Look for common web vulnerabilities such as | 
|  | 5908 | cross-site-scripting (XSS), unvalidated inputs, | 
|  | 5909 | and so forth.</para> | 
|  | 5910 | <para>As with system passwords, the default credentials | 
|  | 5911 | for accessing a web-based interface should not be the | 
|  | 5912 | same across all devices. | 
|  | 5913 | This is particularly true if the interface is enabled | 
|  | 5914 | by default as it can be assumed that many end-users | 
|  | 5915 | will not change the credentials. | 
|  | 5916 | </para></listitem> | 
|  | 5917 | <listitem><para> | 
|  | 5918 | Ensure you can update the software on the device to | 
|  | 5919 | mitigate vulnerabilities discovered in the future. | 
|  | 5920 | This consideration especially applies when your | 
|  | 5921 | device is network-enabled. | 
|  | 5922 | </para></listitem> | 
|  | 5923 | <listitem><para> | 
|  | 5924 | Ensure you remove or disable debugging functionality | 
|  | 5925 | before producing the final image. | 
|  | 5926 | For information on how to do this, see the | 
|  | 5927 | "<link linkend='considerations-specific-to-the-openembedded-build-system'>Considerations Specific to the OpenEmbedded Build System</link>" | 
|  | 5928 | section. | 
|  | 5929 | </para></listitem> | 
|  | 5930 | <listitem><para> | 
|  | 5931 | Ensure you have no network services listening that | 
|  | 5932 | are not needed. | 
|  | 5933 | </para></listitem> | 
|  | 5934 | <listitem><para> | 
|  | 5935 | Remove any software from the image that is not needed. | 
|  | 5936 | </para></listitem> | 
|  | 5937 | <listitem><para> | 
|  | 5938 | Enable hardware support for secure boot functionality | 
|  | 5939 | when your device supports this functionality. | 
|  | 5940 | </para></listitem> | 
|  | 5941 | </itemizedlist> | 
|  | 5942 | </para> | 
|  | 5943 | </section> | 
|  | 5944 |  | 
|  | 5945 | <section id='security-flags'> | 
|  | 5946 | <title>Security Flags</title> | 
|  | 5947 |  | 
|  | 5948 | <para> | 
|  | 5949 | The Yocto Project has security flags that you can enable that | 
|  | 5950 | help make your build output more secure. | 
|  | 5951 | The security flags are in the | 
|  | 5952 | <filename>meta/conf/distro/include/security_flags.inc</filename> | 
|  | 5953 | file in your | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5954 | <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5955 | (e.g. <filename>poky</filename>). | 
|  | 5956 | <note> | 
|  | 5957 | Depending on the recipe, certain security flags are enabled | 
|  | 5958 | and disabled by default. | 
|  | 5959 | </note> | 
|  | 5960 | </para> | 
|  | 5961 |  | 
|  | 5962 | <para> | 
|  | 5963 | <!-- | 
|  | 5964 | The GCC/LD flags in <filename>security_flags.inc</filename> | 
|  | 5965 | enable more secure code generation. | 
|  | 5966 | By including the <filename>security_flags.inc</filename> | 
|  | 5967 | file, you enable flags to the compiler and linker that cause | 
|  | 5968 | them to generate more secure code. | 
|  | 5969 | <note> | 
|  | 5970 | The GCC/LD flags are enabled by default in the | 
|  | 5971 | <filename>poky-lsb</filename> distribution. | 
|  | 5972 | </note> | 
|  | 5973 | --> | 
|  | 5974 | Use the following line in your | 
|  | 5975 | <filename>local.conf</filename> file or in your custom | 
|  | 5976 | distribution configuration file to enable the security | 
|  | 5977 | compiler and linker flags for your build: | 
|  | 5978 | <literallayout class='monospaced'> | 
|  | 5979 | require conf/distro/include/security_flags.inc | 
|  | 5980 | </literallayout> | 
|  | 5981 | </para> | 
|  | 5982 | </section> | 
|  | 5983 |  | 
|  | 5984 | <section id='considerations-specific-to-the-openembedded-build-system'> | 
|  | 5985 | <title>Considerations Specific to the OpenEmbedded Build System</title> | 
|  | 5986 |  | 
|  | 5987 | <para> | 
|  | 5988 | You can take some steps that are specific to the | 
|  | 5989 | OpenEmbedded build system to make your images more secure: | 
|  | 5990 | <itemizedlist> | 
|  | 5991 | <listitem><para> | 
|  | 5992 | Ensure "debug-tweaks" is not one of your selected | 
|  | 5993 | <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>. | 
|  | 5994 | When creating a new project, the default is to provide you | 
|  | 5995 | with an initial <filename>local.conf</filename> file that | 
|  | 5996 | enables this feature using the | 
|  | 5997 | <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink> variable with the line: | 
|  | 5998 | <literallayout class='monospaced'> | 
|  | 5999 | EXTRA_IMAGE_FEATURES = "debug-tweaks" | 
|  | 6000 | </literallayout> | 
|  | 6001 | To disable that feature, simply comment out that line in your | 
|  | 6002 | <filename>local.conf</filename> file, or | 
|  | 6003 | make sure <filename>IMAGE_FEATURES</filename> does not contain | 
|  | 6004 | "debug-tweaks" before producing your final image. | 
|  | 6005 | Among other things, leaving this in place sets the | 
|  | 6006 | root password as blank, which makes logging in for | 
|  | 6007 | debugging or inspection easy during | 
|  | 6008 | development but also means anyone can easily log in | 
|  | 6009 | during production. | 
|  | 6010 | </para></listitem> | 
|  | 6011 | <listitem><para> | 
|  | 6012 | It is possible to set a root password for the image | 
|  | 6013 | and also to set passwords for any extra users you might | 
|  | 6014 | add (e.g. administrative or service type users). | 
|  | 6015 | When you set up passwords for multiple images or | 
|  | 6016 | users, you should not duplicate passwords. | 
|  | 6017 | </para> | 
|  | 6018 | <para> | 
|  | 6019 | To set up passwords, use the | 
|  | 6020 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-extrausers'><filename>extrausers</filename></ulink> | 
|  | 6021 | class, which is the preferred method. | 
|  | 6022 | For an example on how to set up both root and user | 
|  | 6023 | passwords, see the | 
|  | 6024 | "<ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-extrausers'><filename>extrausers.bbclass</filename></ulink>" | 
|  | 6025 | section. | 
|  | 6026 | <note> | 
|  | 6027 | When adding extra user accounts or setting a | 
|  | 6028 | root password, be cautious about setting the | 
|  | 6029 | same password on every device. | 
|  | 6030 | If you do this, and the password you have set | 
|  | 6031 | is exposed, then every device is now potentially | 
|  | 6032 | compromised. | 
|  | 6033 | If you need this access but want to ensure | 
|  | 6034 | security, consider setting a different, | 
|  | 6035 | random password for each device. | 
|  | 6036 | Typically, you do this as a separate step after | 
|  | 6037 | you deploy the image onto the device. | 
|  | 6038 | </note> | 
|  | 6039 | </para></listitem> | 
|  | 6040 | <listitem><para> | 
|  | 6041 | Consider enabling a Mandatory Access Control (MAC) | 
|  | 6042 | framework such as SMACK or SELinux and tuning it | 
|  | 6043 | appropriately for your device's usage. | 
|  | 6044 | You can find more information in the | 
|  | 6045 | <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/meta-selinux/'><filename>meta-selinux</filename></ulink> | 
|  | 6046 | layer. | 
|  | 6047 | </para></listitem> | 
|  | 6048 | </itemizedlist> | 
|  | 6049 | </para> | 
|  | 6050 |  | 
|  | 6051 | <para> | 
|  | 6052 | </para> | 
|  | 6053 | </section> | 
|  | 6054 |  | 
|  | 6055 | <section id='tools-for-hardening-your-image'> | 
|  | 6056 | <title>Tools for Hardening Your Image</title> | 
|  | 6057 |  | 
|  | 6058 | <para> | 
|  | 6059 | The Yocto Project provides tools for making your image | 
|  | 6060 | more secure. | 
|  | 6061 | You can find these tools in the | 
|  | 6062 | <filename>meta-security</filename> layer of the | 
|  | 6063 | <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi'>Yocto Project Source Repositories</ulink>. | 
|  | 6064 | </para> | 
|  | 6065 | </section> | 
|  | 6066 | </section> | 
|  | 6067 |  | 
|  | 6068 | <section id='creating-your-own-distribution'> | 
|  | 6069 | <title>Creating Your Own Distribution</title> | 
|  | 6070 |  | 
|  | 6071 | <para> | 
|  | 6072 | When you build an image using the Yocto Project and | 
|  | 6073 | do not alter any distribution | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 6074 | <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink>, | 
|  | 6075 | you are creating a Poky distribution. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6076 | If you wish to gain more control over package alternative | 
|  | 6077 | selections, compile-time options, and other low-level | 
|  | 6078 | configurations, you can create your own distribution. | 
|  | 6079 | </para> | 
|  | 6080 |  | 
|  | 6081 | <para> | 
|  | 6082 | To create your own distribution, the basic steps consist of | 
|  | 6083 | creating your own distribution layer, creating your own | 
|  | 6084 | distribution configuration file, and then adding any needed | 
|  | 6085 | code and Metadata to the layer. | 
|  | 6086 | The following steps provide some more detail: | 
|  | 6087 | <itemizedlist> | 
|  | 6088 | <listitem><para><emphasis>Create a layer for your new distro:</emphasis> | 
|  | 6089 | Create your distribution layer so that you can keep your | 
|  | 6090 | Metadata and code for the distribution separate. | 
|  | 6091 | It is strongly recommended that you create and use your own | 
|  | 6092 | layer for configuration and code. | 
|  | 6093 | Using your own layer as compared to just placing | 
|  | 6094 | configurations in a <filename>local.conf</filename> | 
|  | 6095 | configuration file makes it easier to reproduce the same | 
|  | 6096 | build configuration when using multiple build machines. | 
|  | 6097 | See the | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 6098 | "<link linkend='creating-a-general-layer-using-the-bitbake-layers-script'>Creating a General Layer Using the <filename>bitbake-layers</filename> Script</link>" | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6099 | section for information on how to quickly set up a layer. | 
|  | 6100 | </para></listitem> | 
|  | 6101 | <listitem><para><emphasis>Create the distribution configuration file:</emphasis> | 
|  | 6102 | The distribution configuration file needs to be created in | 
|  | 6103 | the <filename>conf/distro</filename> directory of your | 
|  | 6104 | layer. | 
|  | 6105 | You need to name it using your distribution name | 
|  | 6106 | (e.g. <filename>mydistro.conf</filename>). | 
|  | 6107 | <note> | 
|  | 6108 | The | 
|  | 6109 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink> | 
|  | 6110 | variable in your | 
|  | 6111 | <filename>local.conf</filename> file determines the | 
|  | 6112 | name of your distribution. | 
|  | 6113 | </note></para> | 
|  | 6114 | <para>You can split out parts of your configuration file | 
|  | 6115 | into include files and then "require" them from within | 
|  | 6116 | your distribution configuration file. | 
|  | 6117 | Be sure to place the include files in the | 
|  | 6118 | <filename>conf/distro/include</filename> directory of | 
|  | 6119 | your layer. | 
|  | 6120 | A common example usage of include files would be to | 
|  | 6121 | separate out the selection of desired version and revisions | 
|  | 6122 | for individual recipes. | 
|  | 6123 | </para> | 
|  | 6124 | <para>Your configuration file needs to set the following | 
|  | 6125 | required variables: | 
|  | 6126 | <literallayout class='monospaced'> | 
|  | 6127 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_NAME'><filename>DISTRO_NAME</filename></ulink> | 
|  | 6128 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_VERSION'><filename>DISTRO_VERSION</filename></ulink> | 
|  | 6129 | </literallayout> | 
|  | 6130 | These following variables are optional and you typically | 
|  | 6131 | set them from the distribution configuration file: | 
|  | 6132 | <literallayout class='monospaced'> | 
|  | 6133 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink> | 
|  | 6134 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_EXTRA_RDEPENDS'><filename>DISTRO_EXTRA_RDEPENDS</filename></ulink> | 
|  | 6135 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_EXTRA_RRECOMMENDS'><filename>DISTRO_EXTRA_RRECOMMENDS</filename></ulink> | 
|  | 6136 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TCLIBC'><filename>TCLIBC</filename></ulink> | 
|  | 6137 | </literallayout> | 
|  | 6138 | <tip> | 
|  | 6139 | If you want to base your distribution configuration file | 
|  | 6140 | on the very basic configuration from OE-Core, you | 
|  | 6141 | can use | 
|  | 6142 | <filename>conf/distro/defaultsetup.conf</filename> as | 
|  | 6143 | a reference and just include variables that differ | 
|  | 6144 | as compared to <filename>defaultsetup.conf</filename>. | 
|  | 6145 | Alternatively, you can create a distribution | 
|  | 6146 | configuration file from scratch using the | 
|  | 6147 | <filename>defaultsetup.conf</filename> file | 
|  | 6148 | or configuration files from other distributions | 
|  | 6149 | such as Poky or Angstrom as references. | 
|  | 6150 | </tip></para></listitem> | 
|  | 6151 | <listitem><para><emphasis>Provide miscellaneous variables:</emphasis> | 
|  | 6152 | Be sure to define any other variables for which you want to | 
|  | 6153 | create a default or enforce as part of the distribution | 
|  | 6154 | configuration. | 
|  | 6155 | You can include nearly any variable from the | 
|  | 6156 | <filename>local.conf</filename> file. | 
|  | 6157 | The variables you use are not limited to the list in the | 
|  | 6158 | previous bulleted item.</para></listitem> | 
|  | 6159 | <listitem><para><emphasis>Point to Your distribution configuration file:</emphasis> | 
|  | 6160 | In your <filename>local.conf</filename> file in the | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 6161 | <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>, | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6162 | set your | 
|  | 6163 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink> | 
|  | 6164 | variable to point to your distribution's configuration file. | 
|  | 6165 | For example, if your distribution's configuration file is | 
|  | 6166 | named <filename>mydistro.conf</filename>, then you point | 
|  | 6167 | to it as follows: | 
|  | 6168 | <literallayout class='monospaced'> | 
|  | 6169 | DISTRO = "mydistro" | 
|  | 6170 | </literallayout></para></listitem> | 
|  | 6171 | <listitem><para><emphasis>Add more to the layer if necessary:</emphasis> | 
|  | 6172 | Use your layer to hold other information needed for the | 
|  | 6173 | distribution: | 
|  | 6174 | <itemizedlist> | 
|  | 6175 | <listitem><para>Add recipes for installing | 
|  | 6176 | distro-specific configuration files that are not | 
|  | 6177 | already installed by another recipe. | 
|  | 6178 | If you have distro-specific configuration files | 
|  | 6179 | that are included by an existing recipe, you should | 
|  | 6180 | add an append file (<filename>.bbappend</filename>) | 
|  | 6181 | for those. | 
|  | 6182 | For general information and recommendations | 
|  | 6183 | on how to add recipes to your layer, see the | 
|  | 6184 | "<link linkend='creating-your-own-layer'>Creating Your Own Layer</link>" | 
|  | 6185 | and | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 6186 | "<link linkend='best-practices-to-follow-when-creating-layers'>Following Best Practices When Creating Layers</link>" | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6187 | sections.</para></listitem> | 
|  | 6188 | <listitem><para>Add any image recipes that are specific | 
|  | 6189 | to your distribution.</para></listitem> | 
|  | 6190 | <listitem><para>Add a <filename>psplash</filename> | 
|  | 6191 | append file for a branded splash screen. | 
|  | 6192 | For information on append files, see the | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 6193 | "<link linkend='using-bbappend-files'>Using .bbappend Files in Your Layer</link>" | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6194 | section.</para></listitem> | 
|  | 6195 | <listitem><para>Add any other append files to make | 
|  | 6196 | custom changes that are specific to individual | 
|  | 6197 | recipes.</para></listitem> | 
|  | 6198 | </itemizedlist></para></listitem> | 
|  | 6199 | </itemizedlist> | 
|  | 6200 | </para> | 
|  | 6201 | </section> | 
|  | 6202 |  | 
|  | 6203 | <section id='creating-a-custom-template-configuration-directory'> | 
|  | 6204 | <title>Creating a Custom Template Configuration Directory</title> | 
|  | 6205 |  | 
|  | 6206 | <para> | 
|  | 6207 | If you are producing your own customized version | 
|  | 6208 | of the build system for use by other users, you might | 
|  | 6209 | want to customize the message shown by the setup script or | 
|  | 6210 | you might want to change the template configuration files (i.e. | 
|  | 6211 | <filename>local.conf</filename> and | 
|  | 6212 | <filename>bblayers.conf</filename>) that are created in | 
|  | 6213 | a new build directory. | 
|  | 6214 | </para> | 
|  | 6215 |  | 
|  | 6216 | <para> | 
|  | 6217 | The OpenEmbedded build system uses the environment variable | 
|  | 6218 | <filename>TEMPLATECONF</filename> to locate the directory | 
|  | 6219 | from which it gathers configuration information that ultimately | 
|  | 6220 | ends up in the | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 6221 | <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6222 | <filename>conf</filename> directory. | 
|  | 6223 | By default, <filename>TEMPLATECONF</filename> is set as | 
|  | 6224 | follows in the <filename>poky</filename> repository: | 
|  | 6225 | <literallayout class='monospaced'> | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 6226 | TEMPLATECONF=${TEMPLATECONF:-meta-poky/conf} | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6227 | </literallayout> | 
|  | 6228 | This is the directory used by the build system to find templates | 
|  | 6229 | from which to build some key configuration files. | 
|  | 6230 | If you look at this directory, you will see the | 
|  | 6231 | <filename>bblayers.conf.sample</filename>, | 
|  | 6232 | <filename>local.conf.sample</filename>, and | 
|  | 6233 | <filename>conf-notes.txt</filename> files. | 
|  | 6234 | The build system uses these files to form the respective | 
|  | 6235 | <filename>bblayers.conf</filename> file, | 
|  | 6236 | <filename>local.conf</filename> file, and display the list of | 
|  | 6237 | BitBake targets when running the setup script. | 
|  | 6238 | </para> | 
|  | 6239 |  | 
|  | 6240 | <para> | 
|  | 6241 | To override these default configuration files with | 
|  | 6242 | configurations you want used within every new | 
|  | 6243 | Build Directory, simply set the | 
|  | 6244 | <filename>TEMPLATECONF</filename> variable to your directory. | 
|  | 6245 | The <filename>TEMPLATECONF</filename> variable is set in the | 
|  | 6246 | <filename>.templateconf</filename> file, which is in the | 
|  | 6247 | top-level | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 6248 | <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6249 | folder (e.g. <filename>poky</filename>). | 
|  | 6250 | Edit the <filename>.templateconf</filename> so that it can locate | 
|  | 6251 | your directory. | 
|  | 6252 | </para> | 
|  | 6253 |  | 
|  | 6254 | <para> | 
|  | 6255 | Best practices dictate that you should keep your | 
|  | 6256 | template configuration directory in your custom distribution layer. | 
|  | 6257 | For example, suppose you have a layer named | 
|  | 6258 | <filename>meta-mylayer</filename> located in your home directory | 
|  | 6259 | and you want your template configuration directory named | 
|  | 6260 | <filename>myconf</filename>. | 
|  | 6261 | Changing the <filename>.templateconf</filename> as follows | 
|  | 6262 | causes the OpenEmbedded build system to look in your directory | 
|  | 6263 | and base its configuration files on the | 
|  | 6264 | <filename>*.sample</filename> configuration files it finds. | 
|  | 6265 | The final configuration files (i.e. | 
|  | 6266 | <filename>local.conf</filename> and | 
|  | 6267 | <filename>bblayers.conf</filename> ultimately still end up in | 
|  | 6268 | your Build Directory, but they are based on your | 
|  | 6269 | <filename>*.sample</filename> files. | 
|  | 6270 | <literallayout class='monospaced'> | 
|  | 6271 | TEMPLATECONF=${TEMPLATECONF:-meta-mylayer/myconf} | 
|  | 6272 | </literallayout> | 
|  | 6273 | </para> | 
|  | 6274 |  | 
|  | 6275 | <para> | 
|  | 6276 | Aside from the <filename>*.sample</filename> configuration files, | 
|  | 6277 | the <filename>conf-notes.txt</filename> also resides in the | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 6278 | default <filename>meta-poky/conf</filename> directory. | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 6279 | The script that sets up the build environment | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6280 | (i.e. | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 6281 | <ulink url="&YOCTO_DOCS_REF_URL;#structure-core-script"><filename>&OE_INIT_FILE;</filename></ulink>) | 
|  | 6282 | uses this file to display BitBake targets as part of the script | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6283 | output. | 
|  | 6284 | Customizing this <filename>conf-notes.txt</filename> file is a | 
|  | 6285 | good way to make sure your list of custom targets appears | 
|  | 6286 | as part of the script's output. | 
|  | 6287 | </para> | 
|  | 6288 |  | 
|  | 6289 | <para> | 
|  | 6290 | Here is the default list of targets displayed as a result of | 
|  | 6291 | running either of the setup scripts: | 
|  | 6292 | <literallayout class='monospaced'> | 
|  | 6293 | You can now run 'bitbake <target>' | 
|  | 6294 |  | 
|  | 6295 | Common targets are: | 
|  | 6296 | core-image-minimal | 
|  | 6297 | core-image-sato | 
|  | 6298 | meta-toolchain | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6299 | meta-ide-support | 
|  | 6300 | </literallayout> | 
|  | 6301 | </para> | 
|  | 6302 |  | 
|  | 6303 | <para> | 
|  | 6304 | Changing the listed common targets is as easy as editing your | 
|  | 6305 | version of <filename>conf-notes.txt</filename> in your | 
|  | 6306 | custom template configuration directory and making sure you | 
|  | 6307 | have <filename>TEMPLATECONF</filename> set to your directory. | 
|  | 6308 | </para> | 
|  | 6309 | </section> | 
|  | 6310 |  | 
|  | 6311 | <section id='building-a-tiny-system'> | 
|  | 6312 | <title>Building a Tiny System</title> | 
|  | 6313 |  | 
|  | 6314 | <para> | 
|  | 6315 | Very small distributions have some significant advantages such | 
|  | 6316 | as requiring less on-die or in-package memory (cheaper), better | 
|  | 6317 | performance through efficient cache usage, lower power requirements | 
|  | 6318 | due to less memory, faster boot times, and reduced development | 
|  | 6319 | overhead. | 
|  | 6320 | Some real-world examples where a very small distribution gives | 
|  | 6321 | you distinct advantages are digital cameras, medical devices, | 
|  | 6322 | and small headless systems. | 
|  | 6323 | </para> | 
|  | 6324 |  | 
|  | 6325 | <para> | 
|  | 6326 | This section presents information that shows you how you can | 
|  | 6327 | trim your distribution to even smaller sizes than the | 
|  | 6328 | <filename>poky-tiny</filename> distribution, which is around | 
|  | 6329 | 5 Mbytes, that can be built out-of-the-box using the Yocto Project. | 
|  | 6330 | </para> | 
|  | 6331 |  | 
|  | 6332 | <section id='tiny-system-overview'> | 
|  | 6333 | <title>Overview</title> | 
|  | 6334 |  | 
|  | 6335 | <para> | 
|  | 6336 | The following list presents the overall steps you need to | 
|  | 6337 | consider and perform to create distributions with smaller | 
|  | 6338 | root filesystems, achieve faster boot times, maintain your critical | 
|  | 6339 | functionality, and avoid initial RAM disks: | 
|  | 6340 | <itemizedlist> | 
|  | 6341 | <listitem><para> | 
|  | 6342 | <link linkend='goals-and-guiding-principles'>Determine your goals and guiding principles.</link> | 
|  | 6343 | </para></listitem> | 
|  | 6344 | <listitem><para> | 
|  | 6345 | <link linkend='understand-what-gives-your-image-size'>Understand what contributes to your image size.</link> | 
|  | 6346 | </para></listitem> | 
|  | 6347 | <listitem><para> | 
|  | 6348 | <link linkend='trim-the-root-filesystem'>Reduce the size of the root filesystem.</link> | 
|  | 6349 | </para></listitem> | 
|  | 6350 | <listitem><para> | 
|  | 6351 | <link linkend='trim-the-kernel'>Reduce the size of the kernel.</link> | 
|  | 6352 | </para></listitem> | 
|  | 6353 | <listitem><para> | 
|  | 6354 | <link linkend='remove-package-management-requirements'>Eliminate packaging requirements.</link> | 
|  | 6355 | </para></listitem> | 
|  | 6356 | <listitem><para> | 
|  | 6357 | <link linkend='look-for-other-ways-to-minimize-size'>Look for other ways to minimize size.</link> | 
|  | 6358 | </para></listitem> | 
|  | 6359 | <listitem><para> | 
|  | 6360 | <link linkend='iterate-on-the-process'>Iterate on the process.</link> | 
|  | 6361 | </para></listitem> | 
|  | 6362 | </itemizedlist> | 
|  | 6363 | </para> | 
|  | 6364 | </section> | 
|  | 6365 |  | 
|  | 6366 | <section id='goals-and-guiding-principles'> | 
|  | 6367 | <title>Goals and Guiding Principles</title> | 
|  | 6368 |  | 
|  | 6369 | <para> | 
|  | 6370 | Before you can reach your destination, you need to know | 
|  | 6371 | where you are going. | 
|  | 6372 | Here is an example list that you can use as a guide when | 
|  | 6373 | creating very small distributions: | 
|  | 6374 | <itemizedlist> | 
|  | 6375 | <listitem><para>Determine how much space you need | 
|  | 6376 | (e.g. a kernel that is 1 Mbyte or less and | 
|  | 6377 | a root filesystem that is 3 Mbytes or less). | 
|  | 6378 | </para></listitem> | 
|  | 6379 | <listitem><para>Find the areas that are currently | 
|  | 6380 | taking 90% of the space and concentrate on reducing | 
|  | 6381 | those areas. | 
|  | 6382 | </para></listitem> | 
|  | 6383 | <listitem><para>Do not create any difficult "hacks" | 
|  | 6384 | to achieve your goals.</para></listitem> | 
|  | 6385 | <listitem><para>Leverage the device-specific | 
|  | 6386 | options.</para></listitem> | 
|  | 6387 | <listitem><para>Work in a separate layer so that you | 
|  | 6388 | keep changes isolated. | 
|  | 6389 | For information on how to create layers, see | 
|  | 6390 | the "<link linkend='understanding-and-creating-layers'>Understanding and Creating Layers</link>" section. | 
|  | 6391 | </para></listitem> | 
|  | 6392 | </itemizedlist> | 
|  | 6393 | </para> | 
|  | 6394 | </section> | 
|  | 6395 |  | 
|  | 6396 | <section id='understand-what-gives-your-image-size'> | 
|  | 6397 | <title>Understand What Contributes to Your Image Size</title> | 
|  | 6398 |  | 
|  | 6399 | <para> | 
|  | 6400 | It is easiest to have something to start with when creating | 
|  | 6401 | your own distribution. | 
|  | 6402 | You can use the Yocto Project out-of-the-box to create the | 
|  | 6403 | <filename>poky-tiny</filename> distribution. | 
|  | 6404 | Ultimately, you will want to make changes in your own | 
|  | 6405 | distribution that are likely modeled after | 
|  | 6406 | <filename>poky-tiny</filename>. | 
|  | 6407 | <note> | 
|  | 6408 | To use <filename>poky-tiny</filename> in your build, | 
|  | 6409 | set the | 
|  | 6410 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink> | 
|  | 6411 | variable in your | 
|  | 6412 | <filename>local.conf</filename> file to "poky-tiny" | 
|  | 6413 | as described in the | 
|  | 6414 | "<link linkend='creating-your-own-distribution'>Creating Your Own Distribution</link>" | 
|  | 6415 | section. | 
|  | 6416 | </note> | 
|  | 6417 | </para> | 
|  | 6418 |  | 
|  | 6419 | <para> | 
|  | 6420 | Understanding some memory concepts will help you reduce the | 
|  | 6421 | system size. | 
|  | 6422 | Memory consists of static, dynamic, and temporary memory. | 
|  | 6423 | Static memory is the TEXT (code), DATA (initialized data | 
|  | 6424 | in the code), and BSS (uninitialized data) sections. | 
|  | 6425 | Dynamic memory represents memory that is allocated at runtime: | 
|  | 6426 | stacks, hash tables, and so forth. | 
|  | 6427 | Temporary memory is recovered after the boot process. | 
|  | 6428 | This memory consists of memory used for decompressing | 
|  | 6429 | the kernel and for the <filename>__init__</filename> | 
|  | 6430 | functions. | 
|  | 6431 | </para> | 
|  | 6432 |  | 
|  | 6433 | <para> | 
|  | 6434 | To help you see where you currently are with kernel and root | 
|  | 6435 | filesystem sizes, you can use two tools found in the | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 6436 | <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink> in | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6437 | the <filename>scripts/tiny/</filename> directory: | 
|  | 6438 | <itemizedlist> | 
|  | 6439 | <listitem><para><filename>ksize.py</filename>: Reports | 
|  | 6440 | component sizes for the kernel build objects. | 
|  | 6441 | </para></listitem> | 
|  | 6442 | <listitem><para><filename>dirsize.py</filename>: Reports | 
|  | 6443 | component sizes for the root filesystem.</para></listitem> | 
|  | 6444 | </itemizedlist> | 
|  | 6445 | This next tool and command help you organize configuration | 
|  | 6446 | fragments and view file dependencies in a human-readable form: | 
|  | 6447 | <itemizedlist> | 
|  | 6448 | <listitem><para><filename>merge_config.sh</filename>: | 
|  | 6449 | Helps you manage configuration files and fragments | 
|  | 6450 | within the kernel. | 
|  | 6451 | With this tool, you can merge individual configuration | 
|  | 6452 | fragments together. | 
|  | 6453 | The tool allows you to make overrides and warns you | 
|  | 6454 | of any missing configuration options. | 
|  | 6455 | The tool is ideal for allowing you to iterate on | 
|  | 6456 | configurations, create minimal configurations, and | 
|  | 6457 | create configuration files for different machines | 
|  | 6458 | without having to duplicate your process.</para> | 
|  | 6459 | <para>The <filename>merge_config.sh</filename> script is | 
|  | 6460 | part of the Linux Yocto kernel Git repositories | 
|  | 6461 | (i.e. <filename>linux-yocto-3.14</filename>, | 
|  | 6462 | <filename>linux-yocto-3.10</filename>, | 
|  | 6463 | <filename>linux-yocto-3.8</filename>, and so forth) | 
|  | 6464 | in the | 
|  | 6465 | <filename>scripts/kconfig</filename> directory.</para> | 
|  | 6466 | <para>For more information on configuration fragments, | 
|  | 6467 | see the | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 6468 | "<ulink url='&YOCTO_DOCS_KERNEL_DEV_URL;#creating-config-fragments'>Creating Configuration Fragments</ulink>" | 
|  | 6469 | section in the Yocto Project Linux Kernel Development | 
|  | 6470 | Manual. | 
|  | 6471 | </para></listitem> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 6472 | <listitem><para><filename>bitbake -u taskexp -g <replaceable>bitbake_target</replaceable></filename>: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6473 | Using the BitBake command with these options brings up | 
|  | 6474 | a Dependency Explorer from which you can view file | 
|  | 6475 | dependencies. | 
|  | 6476 | Understanding these dependencies allows you to make | 
|  | 6477 | informed decisions when cutting out various pieces of the | 
|  | 6478 | kernel and root filesystem.</para></listitem> | 
|  | 6479 | </itemizedlist> | 
|  | 6480 | </para> | 
|  | 6481 | </section> | 
|  | 6482 |  | 
|  | 6483 | <section id='trim-the-root-filesystem'> | 
|  | 6484 | <title>Trim the Root Filesystem</title> | 
|  | 6485 |  | 
|  | 6486 | <para> | 
|  | 6487 | The root filesystem is made up of packages for booting, | 
|  | 6488 | libraries, and applications. | 
|  | 6489 | To change things, you can configure how the packaging happens, | 
|  | 6490 | which changes the way you build them. | 
|  | 6491 | You can also modify the filesystem itself or select a different | 
|  | 6492 | filesystem. | 
|  | 6493 | </para> | 
|  | 6494 |  | 
|  | 6495 | <para> | 
|  | 6496 | First, find out what is hogging your root filesystem by running the | 
|  | 6497 | <filename>dirsize.py</filename> script from your root directory: | 
|  | 6498 | <literallayout class='monospaced'> | 
|  | 6499 | $ cd <replaceable>root-directory-of-image</replaceable> | 
|  | 6500 | $ dirsize.py 100000 > dirsize-100k.log | 
|  | 6501 | $ cat dirsize-100k.log | 
|  | 6502 | </literallayout> | 
|  | 6503 | You can apply a filter to the script to ignore files under | 
|  | 6504 | a certain size. | 
|  | 6505 | The previous example filters out any files below 100 Kbytes. | 
|  | 6506 | The sizes reported by the tool are uncompressed, and thus | 
|  | 6507 | will be smaller by a relatively constant factor in a | 
|  | 6508 | compressed root filesystem. | 
|  | 6509 | When you examine your log file, you can focus on areas of the | 
|  | 6510 | root filesystem that take up large amounts of memory. | 
|  | 6511 | </para> | 
|  | 6512 |  | 
|  | 6513 | <para> | 
|  | 6514 | You need to be sure that what you eliminate does not cripple | 
|  | 6515 | the functionality you need. | 
|  | 6516 | One way to see how packages relate to each other is by using | 
|  | 6517 | the Dependency Explorer UI with the BitBake command: | 
|  | 6518 | <literallayout class='monospaced'> | 
|  | 6519 | $ cd <replaceable>image-directory</replaceable> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 6520 | $ bitbake -u taskexp -g <replaceable>image</replaceable> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6521 | </literallayout> | 
|  | 6522 | Use the interface to select potential packages you wish to | 
|  | 6523 | eliminate and see their dependency relationships. | 
|  | 6524 | </para> | 
|  | 6525 |  | 
|  | 6526 | <para> | 
|  | 6527 | When deciding how to reduce the size, get rid of packages that | 
|  | 6528 | result in minimal impact on the feature set. | 
|  | 6529 | For example, you might not need a VGA display. | 
|  | 6530 | Or, you might be able to get by with <filename>devtmpfs</filename> | 
|  | 6531 | and <filename>mdev</filename> instead of | 
|  | 6532 | <filename>udev</filename>. | 
|  | 6533 | </para> | 
|  | 6534 |  | 
|  | 6535 | <para> | 
|  | 6536 | Use your <filename>local.conf</filename> file to make changes. | 
|  | 6537 | For example, to eliminate <filename>udev</filename> and | 
|  | 6538 | <filename>glib</filename>, set the following in the | 
|  | 6539 | local configuration file: | 
|  | 6540 | <literallayout class='monospaced'> | 
|  | 6541 | VIRTUAL-RUNTIME_dev_manager = "" | 
|  | 6542 | </literallayout> | 
|  | 6543 | </para> | 
|  | 6544 |  | 
|  | 6545 | <para> | 
|  | 6546 | Finally, you should consider exactly the type of root | 
|  | 6547 | filesystem you need to meet your needs while also reducing | 
|  | 6548 | its size. | 
|  | 6549 | For example, consider <filename>cramfs</filename>, | 
|  | 6550 | <filename>squashfs</filename>, <filename>ubifs</filename>, | 
|  | 6551 | <filename>ext2</filename>, or an <filename>initramfs</filename> | 
|  | 6552 | using <filename>initramfs</filename>. | 
|  | 6553 | Be aware that <filename>ext3</filename> requires a 1 Mbyte | 
|  | 6554 | journal. | 
|  | 6555 | If you are okay with running read-only, you do not need this | 
|  | 6556 | journal. | 
|  | 6557 | </para> | 
|  | 6558 |  | 
|  | 6559 | <note> | 
|  | 6560 | After each round of elimination, you need to rebuild your | 
|  | 6561 | system and then use the tools to see the effects of your | 
|  | 6562 | reductions. | 
|  | 6563 | </note> | 
|  | 6564 |  | 
|  | 6565 |  | 
|  | 6566 | </section> | 
|  | 6567 |  | 
|  | 6568 | <section id='trim-the-kernel'> | 
|  | 6569 | <title>Trim the Kernel</title> | 
|  | 6570 |  | 
|  | 6571 | <para> | 
|  | 6572 | The kernel is built by including policies for hardware-independent | 
|  | 6573 | aspects. | 
|  | 6574 | What subsystems do you enable? | 
|  | 6575 | For what architecture are you building? | 
|  | 6576 | Which drivers do you build by default? | 
|  | 6577 | <note>You can modify the kernel source if you want to help | 
|  | 6578 | with boot time. | 
|  | 6579 | </note> | 
|  | 6580 | </para> | 
|  | 6581 |  | 
|  | 6582 | <para> | 
|  | 6583 | Run the <filename>ksize.py</filename> script from the top-level | 
|  | 6584 | Linux build directory to get an idea of what is making up | 
|  | 6585 | the kernel: | 
|  | 6586 | <literallayout class='monospaced'> | 
|  | 6587 | $ cd <replaceable>top-level-linux-build-directory</replaceable> | 
|  | 6588 | $ ksize.py > ksize.log | 
|  | 6589 | $ cat ksize.log | 
|  | 6590 | </literallayout> | 
|  | 6591 | When you examine the log, you will see how much space is | 
|  | 6592 | taken up with the built-in <filename>.o</filename> files for | 
|  | 6593 | drivers, networking, core kernel files, filesystem, sound, | 
|  | 6594 | and so forth. | 
|  | 6595 | The sizes reported by the tool are uncompressed, and thus | 
|  | 6596 | will be smaller by a relatively constant factor in a compressed | 
|  | 6597 | kernel image. | 
|  | 6598 | Look to reduce the areas that are large and taking up around | 
|  | 6599 | the "90% rule." | 
|  | 6600 | </para> | 
|  | 6601 |  | 
|  | 6602 | <para> | 
|  | 6603 | To examine, or drill down, into any particular area, use the | 
|  | 6604 | <filename>-d</filename> option with the script: | 
|  | 6605 | <literallayout class='monospaced'> | 
|  | 6606 | $ ksize.py -d > ksize.log | 
|  | 6607 | </literallayout> | 
|  | 6608 | Using this option breaks out the individual file information | 
|  | 6609 | for each area of the kernel (e.g. drivers, networking, and | 
|  | 6610 | so forth). | 
|  | 6611 | </para> | 
|  | 6612 |  | 
|  | 6613 | <para> | 
|  | 6614 | Use your log file to see what you can eliminate from the kernel | 
|  | 6615 | based on features you can let go. | 
|  | 6616 | For example, if you are not going to need sound, you do not | 
|  | 6617 | need any drivers that support sound. | 
|  | 6618 | </para> | 
|  | 6619 |  | 
|  | 6620 | <para> | 
|  | 6621 | After figuring out what to eliminate, you need to reconfigure | 
|  | 6622 | the kernel to reflect those changes during the next build. | 
|  | 6623 | You could run <filename>menuconfig</filename> and make all your | 
|  | 6624 | changes at once. | 
|  | 6625 | However, that makes it difficult to see the effects of your | 
|  | 6626 | individual eliminations and also makes it difficult to replicate | 
|  | 6627 | the changes for perhaps another target device. | 
|  | 6628 | A better method is to start with no configurations using | 
|  | 6629 | <filename>allnoconfig</filename>, create configuration | 
|  | 6630 | fragments for individual changes, and then manage the | 
|  | 6631 | fragments into a single configuration file using | 
|  | 6632 | <filename>merge_config.sh</filename>. | 
|  | 6633 | The tool makes it easy for you to iterate using the | 
|  | 6634 | configuration change and build cycle. | 
|  | 6635 | </para> | 
|  | 6636 |  | 
|  | 6637 | <para> | 
|  | 6638 | Each time you make configuration changes, you need to rebuild | 
|  | 6639 | the kernel and check to see what impact your changes had on | 
|  | 6640 | the overall size. | 
|  | 6641 | </para> | 
|  | 6642 | </section> | 
|  | 6643 |  | 
|  | 6644 | <section id='remove-package-management-requirements'> | 
|  | 6645 | <title>Remove Package Management Requirements</title> | 
|  | 6646 |  | 
|  | 6647 | <para> | 
|  | 6648 | Packaging requirements add size to the image. | 
|  | 6649 | One way to reduce the size of the image is to remove all the | 
|  | 6650 | packaging requirements from the image. | 
|  | 6651 | This reduction includes both removing the package manager | 
|  | 6652 | and its unique dependencies as well as removing the package | 
|  | 6653 | management data itself. | 
|  | 6654 | </para> | 
|  | 6655 |  | 
|  | 6656 | <para> | 
|  | 6657 | To eliminate all the packaging requirements for an image, | 
|  | 6658 | be sure that "package-management" is not part of your | 
|  | 6659 | <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink> | 
|  | 6660 | statement for the image. | 
|  | 6661 | When you remove this feature, you are removing the package | 
|  | 6662 | manager as well as its dependencies from the root filesystem. | 
|  | 6663 | </para> | 
|  | 6664 | </section> | 
|  | 6665 |  | 
|  | 6666 | <section id='look-for-other-ways-to-minimize-size'> | 
|  | 6667 | <title>Look for Other Ways to Minimize Size</title> | 
|  | 6668 |  | 
|  | 6669 | <para> | 
|  | 6670 | Depending on your particular circumstances, other areas that you | 
|  | 6671 | can trim likely exist. | 
|  | 6672 | The key to finding these areas is through tools and methods | 
|  | 6673 | described here combined with experimentation and iteration. | 
|  | 6674 | Here are a couple of areas to experiment with: | 
|  | 6675 | <itemizedlist> | 
|  | 6676 | <listitem><para><filename>glibc</filename>: | 
|  | 6677 | In general, follow this process: | 
|  | 6678 | <orderedlist> | 
|  | 6679 | <listitem><para>Remove <filename>glibc</filename> | 
|  | 6680 | features from | 
|  | 6681 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink> | 
|  | 6682 | that you think you do not need.</para></listitem> | 
|  | 6683 | <listitem><para>Build your distribution. | 
|  | 6684 | </para></listitem> | 
|  | 6685 | <listitem><para>If the build fails due to missing | 
|  | 6686 | symbols in a package, determine if you can | 
|  | 6687 | reconfigure the package to not need those | 
|  | 6688 | features. | 
|  | 6689 | For example, change the configuration to not | 
|  | 6690 | support wide character support as is done for | 
|  | 6691 | <filename>ncurses</filename>. | 
|  | 6692 | Or, if support for those characters is needed, | 
|  | 6693 | determine what <filename>glibc</filename> | 
|  | 6694 | features provide the support and restore the | 
|  | 6695 | configuration. | 
|  | 6696 | </para></listitem> | 
|  | 6697 | <listitem><para>Rebuild and repeat the process. | 
|  | 6698 | </para></listitem> | 
|  | 6699 | </orderedlist></para></listitem> | 
|  | 6700 | <listitem><para><filename>busybox</filename>: | 
|  | 6701 | For BusyBox, use a process similar as described for | 
|  | 6702 | <filename>glibc</filename>. | 
|  | 6703 | A difference is you will need to boot the resulting | 
|  | 6704 | system to see if you are able to do everything you | 
|  | 6705 | expect from the running system. | 
|  | 6706 | You need to be sure to integrate configuration fragments | 
|  | 6707 | into Busybox because BusyBox handles its own core | 
|  | 6708 | features and then allows you to add configuration | 
|  | 6709 | fragments on top. | 
|  | 6710 | </para></listitem> | 
|  | 6711 | </itemizedlist> | 
|  | 6712 | </para> | 
|  | 6713 | </section> | 
|  | 6714 |  | 
|  | 6715 | <section id='iterate-on-the-process'> | 
|  | 6716 | <title>Iterate on the Process</title> | 
|  | 6717 |  | 
|  | 6718 | <para> | 
|  | 6719 | If you have not reached your goals on system size, you need | 
|  | 6720 | to iterate on the process. | 
|  | 6721 | The process is the same. | 
|  | 6722 | Use the tools and see just what is taking up 90% of the root | 
|  | 6723 | filesystem and the kernel. | 
|  | 6724 | Decide what you can eliminate without limiting your device | 
|  | 6725 | beyond what you need. | 
|  | 6726 | </para> | 
|  | 6727 |  | 
|  | 6728 | <para> | 
|  | 6729 | Depending on your system, a good place to look might be | 
|  | 6730 | Busybox, which provides a stripped down | 
|  | 6731 | version of Unix tools in a single, executable file. | 
|  | 6732 | You might be able to drop virtual terminal services or perhaps | 
|  | 6733 | ipv6. | 
|  | 6734 | </para> | 
|  | 6735 | </section> | 
|  | 6736 | </section> | 
|  | 6737 |  | 
|  | 6738 | <section id='building-images-for-more-than-one-machine'> | 
|  | 6739 | <title>Building Images for More than One Machine</title> | 
|  | 6740 |  | 
|  | 6741 | <para> | 
|  | 6742 | A common scenario developers face is creating images for several | 
|  | 6743 | different machines that use the same software environment. | 
|  | 6744 | In this situation, it is tempting to set the | 
|  | 6745 | tunings and optimization flags for each build specifically for | 
|  | 6746 | the targeted hardware (i.e. "maxing out" the tunings). | 
|  | 6747 | Doing so can considerably add to build times and package feed | 
|  | 6748 | maintenance collectively for the machines. | 
|  | 6749 | For example, selecting tunes that are extremely specific to a | 
|  | 6750 | CPU core used in a system might enable some micro optimizations | 
|  | 6751 | in GCC for that particular system but would otherwise not gain | 
|  | 6752 | you much of a performance difference across the other systems | 
|  | 6753 | as compared to using a more general tuning across all the builds | 
|  | 6754 | (e.g. setting | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 6755 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DEFAULTTUNE'><filename>DEFAULTTUNE</filename></ulink> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6756 | specifically for each machine's build). | 
|  | 6757 | Rather than "max out" each build's tunings, you can take steps that | 
|  | 6758 | cause the OpenEmbedded build system to reuse software across the | 
|  | 6759 | various machines where it makes sense. | 
|  | 6760 | </para> | 
|  | 6761 | <para> | 
|  | 6762 | If build speed and package feed maintenance are considerations, | 
|  | 6763 | you should consider the points in this section that can help you | 
|  | 6764 | optimize your tunings to best consider build times and package | 
|  | 6765 | feed maintenance. | 
|  | 6766 | <itemizedlist> | 
|  | 6767 | <listitem><para><emphasis>Share the Build Directory:</emphasis> | 
|  | 6768 | If at all possible, share the | 
|  | 6769 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink> | 
|  | 6770 | across builds. | 
|  | 6771 | The Yocto Project supports switching between different | 
|  | 6772 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink> | 
|  | 6773 | values in the same <filename>TMPDIR</filename>. | 
|  | 6774 | This practice is well supported and regularly used by | 
|  | 6775 | developers when building for multiple machines. | 
|  | 6776 | When you use the same <filename>TMPDIR</filename> for | 
|  | 6777 | multiple machine builds, the OpenEmbedded build system can | 
|  | 6778 | reuse the existing native and often cross-recipes for | 
|  | 6779 | multiple machines. | 
|  | 6780 | Thus, build time decreases. | 
|  | 6781 | <note> | 
|  | 6782 | If | 
|  | 6783 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO'><filename>DISTRO</filename></ulink> | 
|  | 6784 | settings change or fundamental configuration settings | 
|  | 6785 | such as the filesystem layout, you need to work with | 
|  | 6786 | a clean <filename>TMPDIR</filename>. | 
|  | 6787 | Sharing <filename>TMPDIR</filename> under these | 
|  | 6788 | circumstances might work but since it is not | 
|  | 6789 | guaranteed, you should use a clean | 
|  | 6790 | <filename>TMPDIR</filename>. | 
|  | 6791 | </note> | 
|  | 6792 | </para></listitem> | 
|  | 6793 | <listitem><para><emphasis>Enable the Appropriate Package Architecture:</emphasis> | 
|  | 6794 | By default, the OpenEmbedded build system enables three | 
|  | 6795 | levels of package architectures: "all", "tune" or "package", | 
|  | 6796 | and "machine". | 
|  | 6797 | Any given recipe usually selects one of these package | 
|  | 6798 | architectures (types) for its output. | 
|  | 6799 | Depending for what a given recipe creates packages, making | 
|  | 6800 | sure you enable the appropriate package architecture can | 
|  | 6801 | directly impact the build time.</para> | 
|  | 6802 | <para>A recipe that just generates scripts can enable | 
|  | 6803 | "all" architecture because there are no binaries to build. | 
|  | 6804 | To specifically enable "all" architecture, be sure your | 
|  | 6805 | recipe inherits the | 
|  | 6806 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-allarch'><filename>allarch</filename></ulink> | 
|  | 6807 | class. | 
|  | 6808 | This class is useful for "all" architectures because it | 
|  | 6809 | configures many variables so packages can be used across | 
|  | 6810 | multiple architectures.</para> | 
|  | 6811 | <para>If your recipe needs to generate packages that are | 
|  | 6812 | machine-specific or when one of the build or runtime | 
|  | 6813 | dependencies is already machine-architecture dependent, | 
|  | 6814 | which makes your recipe also machine-architecture dependent, | 
|  | 6815 | make sure your recipe enables the "machine" package | 
|  | 6816 | architecture through the | 
|  | 6817 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ARCH'><filename>MACHINE_ARCH</filename></ulink> | 
|  | 6818 | variable: | 
|  | 6819 | <literallayout class='monospaced'> | 
|  | 6820 | PACKAGE_ARCH = "${MACHINE_ARCH}" | 
|  | 6821 | </literallayout> | 
|  | 6822 | When you do not specifically enable a package | 
|  | 6823 | architecture through the | 
|  | 6824 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>, | 
|  | 6825 | The OpenEmbedded build system defaults to the | 
|  | 6826 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TUNE_PKGARCH'><filename>TUNE_PKGARCH</filename></ulink> | 
|  | 6827 | setting: | 
|  | 6828 | <literallayout class='monospaced'> | 
|  | 6829 | PACKAGE_ARCH = "${TUNE_PKGARCH}" | 
|  | 6830 | </literallayout> | 
|  | 6831 | </para></listitem> | 
|  | 6832 | <listitem><para><emphasis>Choose a Generic Tuning File if Possible:</emphasis> | 
|  | 6833 | Some tunes are more generic and can run on multiple targets | 
|  | 6834 | (e.g. an <filename>armv5</filename> set of packages could | 
|  | 6835 | run on <filename>armv6</filename> and | 
|  | 6836 | <filename>armv7</filename> processors in most cases). | 
|  | 6837 | Similarly, <filename>i486</filename> binaries could work | 
|  | 6838 | on <filename>i586</filename> and higher processors. | 
|  | 6839 | You should realize, however, that advances on newer | 
|  | 6840 | processor versions would not be used.</para> | 
|  | 6841 | <para>If you select the same tune for several different | 
|  | 6842 | machines, the OpenEmbedded build system reuses software | 
|  | 6843 | previously built, thus speeding up the overall build time. | 
|  | 6844 | Realize that even though a new sysroot for each machine is | 
|  | 6845 | generated, the software is not recompiled and only one | 
|  | 6846 | package feed exists. | 
|  | 6847 | </para></listitem> | 
|  | 6848 | <listitem><para><emphasis>Manage Granular Level Packaging:</emphasis> | 
|  | 6849 | Sometimes cases exist where injecting another level | 
|  | 6850 | of package architecture beyond the three higher levels | 
|  | 6851 | noted earlier can be useful. | 
|  | 6852 | For example, consider the <filename>emgd</filename> | 
|  | 6853 | graphics stack in the | 
|  | 6854 | <filename>meta-intel</filename> layer. | 
|  | 6855 | In this layer, a subset of software exists that is | 
|  | 6856 | compiled against something different from the rest of the | 
|  | 6857 | generic packages. | 
|  | 6858 | You can examine the key code in the | 
|  | 6859 | <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi'>Source Repositories</ulink> | 
|  | 6860 | "daisy" branch in | 
|  | 6861 | <filename>classes/emgd-gl.bbclass</filename>. | 
|  | 6862 | For a specific set of packages, the code redefines | 
|  | 6863 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink>. | 
|  | 6864 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_EXTRA_ARCHS'><filename>PACKAGE_EXTRA_ARCHS</filename></ulink> | 
|  | 6865 | is then appended with this extra tune name in | 
|  | 6866 | <filename>meta-intel-emgd.inc</filename>. | 
|  | 6867 | The result is that when searching for packages, the | 
|  | 6868 | build system uses a four-level search and the packages | 
|  | 6869 | in this new level are preferred as compared to the standard | 
|  | 6870 | tune. | 
|  | 6871 | The overall result is that the build system reuses most | 
|  | 6872 | software from the common tune except for specific cases | 
|  | 6873 | as needed. | 
|  | 6874 | </para></listitem> | 
|  | 6875 | <listitem><para><emphasis>Use Tools to Debug Issues:</emphasis> | 
|  | 6876 | Sometimes you can run into situations where software is | 
|  | 6877 | being rebuilt when you think it should not be. | 
|  | 6878 | For example, the OpenEmbedded build system might not be | 
|  | 6879 | using shared state between machines when you think it | 
|  | 6880 | should be. | 
|  | 6881 | These types of situations are usually due to references | 
|  | 6882 | to machine-specific variables such as | 
|  | 6883 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>, | 
|  | 6884 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SERIAL_CONSOLE'><filename>SERIAL_CONSOLE</filename></ulink>, | 
|  | 6885 | <ulink url='&YOCTO_DOCS_REF_URL;#var-XSERVER'><filename>XSERVER</filename></ulink>, | 
|  | 6886 | <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_FEATURES'><filename>MACHINE_FEATURES</filename></ulink>, | 
|  | 6887 | and so forth in code that is supposed to only be | 
|  | 6888 | tune-specific or when the recipe depends | 
|  | 6889 | (<ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink>, | 
|  | 6890 | <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink>, | 
|  | 6891 | <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink>, | 
|  | 6892 | <ulink url='&YOCTO_DOCS_REF_URL;#var-RSUGGESTS'><filename>RSUGGESTS</filename></ulink>, | 
|  | 6893 | and so forth) on some other recipe that already has | 
|  | 6894 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink> | 
|  | 6895 | defined as "${MACHINE_ARCH}". | 
|  | 6896 | <note> | 
|  | 6897 | Patches to fix any issues identified are most welcome | 
|  | 6898 | as these issues occasionally do occur. | 
|  | 6899 | </note></para> | 
|  | 6900 | <para>For such cases, you can use some tools to help you | 
|  | 6901 | sort out the situation: | 
|  | 6902 | <itemizedlist> | 
|  | 6903 | <listitem><para><emphasis><filename>sstate-diff-machines.sh</filename>:</emphasis> | 
|  | 6904 | You can find this tool in the | 
|  | 6905 | <filename>scripts</filename> directory of the | 
|  | 6906 | Source Repositories. | 
|  | 6907 | See the comments in the script for information on | 
|  | 6908 | how to use the tool. | 
|  | 6909 | </para></listitem> | 
|  | 6910 | <listitem><para><emphasis>BitBake's "-S printdiff" Option:</emphasis> | 
|  | 6911 | Using this option causes BitBake to try to | 
|  | 6912 | establish the closest signature match it can | 
|  | 6913 | (e.g. in the shared state cache) and then run | 
|  | 6914 | <filename>bitbake-diffsigs</filename> over the | 
|  | 6915 | matches to determine the stamps and delta where | 
|  | 6916 | these two stamp trees diverge. | 
|  | 6917 | </para></listitem> | 
|  | 6918 | </itemizedlist> | 
|  | 6919 | </para></listitem> | 
|  | 6920 | </itemizedlist> | 
|  | 6921 | </para> | 
|  | 6922 | </section> | 
|  | 6923 |  | 
|  | 6924 | <section id='working-with-packages'> | 
|  | 6925 | <title>Working with Packages</title> | 
|  | 6926 |  | 
|  | 6927 | <para> | 
|  | 6928 | This section describes a few tasks that involve packages: | 
|  | 6929 | <itemizedlist> | 
|  | 6930 | <listitem><para> | 
|  | 6931 | <link linkend='excluding-packages-from-an-image'>Excluding packages from an image</link> | 
|  | 6932 | </para></listitem> | 
|  | 6933 | <listitem><para> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 6934 | <link linkend='incrementing-a-binary-package-version'>Incrementing a binary package version</link> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6935 | </para></listitem> | 
|  | 6936 | <listitem><para> | 
|  | 6937 | <link linkend='handling-optional-module-packaging'>Handling optional module packaging</link> | 
|  | 6938 | </para></listitem> | 
|  | 6939 | <listitem><para> | 
|  | 6940 | <link linkend='using-runtime-package-management'>Using Runtime Package Management</link> | 
|  | 6941 | </para></listitem> | 
|  | 6942 | <listitem><para> | 
|  | 6943 | <link linkend='testing-packages-with-ptest'>Setting up and running package test (ptest)</link> | 
|  | 6944 | </para></listitem> | 
|  | 6945 | </itemizedlist> | 
|  | 6946 | </para> | 
|  | 6947 |  | 
|  | 6948 | <section id='excluding-packages-from-an-image'> | 
|  | 6949 | <title>Excluding Packages from an Image</title> | 
|  | 6950 |  | 
|  | 6951 | <para> | 
|  | 6952 | You might find it necessary to prevent specific packages | 
|  | 6953 | from being installed into an image. | 
|  | 6954 | If so, you can use several variables to direct the build | 
|  | 6955 | system to essentially ignore installing recommended packages | 
|  | 6956 | or to not install a package at all. | 
|  | 6957 | </para> | 
|  | 6958 |  | 
|  | 6959 | <para> | 
|  | 6960 | The following list introduces variables you can use to | 
|  | 6961 | prevent packages from being installed into your image. | 
|  | 6962 | Each of these variables only works with IPK and RPM | 
|  | 6963 | package types. | 
|  | 6964 | Support for Debian packages does not exist. | 
|  | 6965 | Also, you can use these variables from your | 
|  | 6966 | <filename>local.conf</filename> file or attach them to a | 
|  | 6967 | specific image recipe by using a recipe name override. | 
|  | 6968 | For more detail on the variables, see the descriptions in the | 
|  | 6969 | Yocto Project Reference Manual's glossary chapter. | 
|  | 6970 | <itemizedlist> | 
|  | 6971 | <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-BAD_RECOMMENDATIONS'><filename>BAD_RECOMMENDATIONS</filename></ulink>: | 
|  | 6972 | Use this variable to specify "recommended-only" | 
|  | 6973 | packages that you do not want installed. | 
|  | 6974 | </para></listitem> | 
|  | 6975 | <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-NO_RECOMMENDATIONS'><filename>NO_RECOMMENDATIONS</filename></ulink>: | 
|  | 6976 | Use this variable to prevent all "recommended-only" | 
|  | 6977 | packages from being installed. | 
|  | 6978 | </para></listitem> | 
|  | 6979 | <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_EXCLUDE'><filename>PACKAGE_EXCLUDE</filename></ulink>: | 
|  | 6980 | Use this variable to prevent specific packages from | 
|  | 6981 | being installed regardless of whether they are | 
|  | 6982 | "recommended-only" or not. | 
|  | 6983 | You need to realize that the build process could | 
|  | 6984 | fail with an error when you | 
|  | 6985 | prevent the installation of a package whose presence | 
|  | 6986 | is required by an installed package. | 
|  | 6987 | </para></listitem> | 
|  | 6988 | </itemizedlist> | 
|  | 6989 | </para> | 
|  | 6990 | </section> | 
|  | 6991 |  | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 6992 | <section id='incrementing-a-binary-package-version'> | 
|  | 6993 | <title>Incrementing a Package Version</title> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6994 |  | 
|  | 6995 | <para> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 6996 | This section provides some background on how binary package | 
|  | 6997 | versioning is accomplished and presents some of the services, | 
|  | 6998 | variables, and terminology involved. | 
|  | 6999 | </para> | 
|  | 7000 |  | 
|  | 7001 | <para> | 
|  | 7002 | In order to understand binary package versioning, you need | 
|  | 7003 | to consider the following: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7004 | <itemizedlist> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 7005 | <listitem><para> | 
|  | 7006 | Binary Package:  The binary package that is eventually | 
|  | 7007 | built and installed into an image. | 
|  | 7008 | </para></listitem> | 
|  | 7009 | <listitem><para> | 
|  | 7010 | Binary Package Version:  The binary package version | 
|  | 7011 | is composed of two components - a version and a | 
|  | 7012 | revision. | 
|  | 7013 | <note> | 
|  | 7014 | Technically, a third component, the "epoch" (i.e. | 
|  | 7015 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PE'><filename>PE</filename></ulink>) | 
|  | 7016 | is involved but this discussion for the most part | 
|  | 7017 | ignores <filename>PE</filename>. | 
|  | 7018 | </note> | 
|  | 7019 | The version and revision are taken from the | 
|  | 7020 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink> | 
|  | 7021 | and | 
|  | 7022 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink> | 
|  | 7023 | variables, respectively. | 
|  | 7024 | </para></listitem> | 
|  | 7025 | <listitem><para> | 
|  | 7026 | <filename>PV</filename>:  The recipe version. | 
|  | 7027 | <filename>PV</filename> represents the version of the | 
|  | 7028 | software being packaged. | 
|  | 7029 | Do not confuse <filename>PV</filename> with the | 
|  | 7030 | binary package version. | 
|  | 7031 | </para></listitem> | 
|  | 7032 | <listitem><para> | 
|  | 7033 | <filename>PR</filename>:  The recipe revision. | 
|  | 7034 | </para></listitem> | 
|  | 7035 | <listitem><para> | 
|  | 7036 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>: | 
|  | 7037 | The OpenEmbedded build system uses this string | 
|  | 7038 | to help define the value of <filename>PV</filename> | 
|  | 7039 | when the source code revision needs to be included | 
|  | 7040 | in it. | 
|  | 7041 | </para></listitem> | 
|  | 7042 | <listitem><para> | 
|  | 7043 | <ulink url='https://wiki.yoctoproject.org/wiki/PR_Service'>PR Service</ulink>: | 
|  | 7044 | A network-based service that helps automate keeping | 
|  | 7045 | package feeds compatible with existing package | 
|  | 7046 | manager applications such as RPM, APT, and OPKG. | 
|  | 7047 | </para></listitem> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7048 | </itemizedlist> | 
|  | 7049 | </para> | 
|  | 7050 |  | 
|  | 7051 | <para> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 7052 | Whenever the binary package content changes, the binary package | 
|  | 7053 | version must change. | 
|  | 7054 | Changing the binary package version is accomplished by changing | 
|  | 7055 | or "bumping" the <filename>PR</filename> and/or | 
|  | 7056 | <filename>PV</filename> values. | 
|  | 7057 | Increasing these values occurs one of two ways: | 
|  | 7058 | <itemizedlist> | 
|  | 7059 | <listitem><para>Automatically using a Package Revision | 
|  | 7060 | Service (PR Service). | 
|  | 7061 | </para></listitem> | 
|  | 7062 | <listitem><para>Manually incrementing the | 
|  | 7063 | <filename>PR</filename> and/or | 
|  | 7064 | <filename>PV</filename> variables. | 
|  | 7065 | </para></listitem> | 
|  | 7066 | </itemizedlist> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7067 | </para> | 
|  | 7068 |  | 
|  | 7069 | <para> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 7070 | Given a primary challenge of any build system and its users | 
|  | 7071 | is how to maintain a package feed that is compatible with | 
|  | 7072 | existing package manager applications such as RPM, APT, and | 
|  | 7073 | OPKG, using an automated system is much preferred over a | 
|  | 7074 | manual system. | 
|  | 7075 | In either system, the main requirement is that binary package | 
|  | 7076 | version numbering increases in a linear fashion and that a | 
|  | 7077 | number of version components exist that support that linear | 
|  | 7078 | progression. | 
|  | 7079 | For information on how to ensure package revisioning remains | 
|  | 7080 | linear, see the | 
|  | 7081 | "<link linkend='automatically-incrementing-a-binary-package-revision-number'>Automatically Incrementing a Binary Package Revision Number</link>" | 
|  | 7082 | section. | 
|  | 7083 | </para> | 
|  | 7084 |  | 
|  | 7085 | <para> | 
|  | 7086 | The following three sections provide related information on the | 
|  | 7087 | PR Service, the manual method for "bumping" | 
|  | 7088 | <filename>PR</filename> and/or <filename>PV</filename>, and | 
|  | 7089 | on how to ensure binary package revisioning remains linear. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7090 | </para> | 
|  | 7091 |  | 
|  | 7092 | <section id='working-with-a-pr-service'> | 
|  | 7093 | <title>Working With a PR Service</title> | 
|  | 7094 |  | 
|  | 7095 | <para> | 
|  | 7096 | As mentioned, attempting to maintain revision numbers in the | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 7097 | <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7098 | is error prone, inaccurate, and causes problems for people | 
|  | 7099 | submitting recipes. | 
|  | 7100 | Conversely, the PR Service automatically generates | 
|  | 7101 | increasing numbers, particularly the revision field, | 
|  | 7102 | which removes the human element. | 
|  | 7103 | <note> | 
|  | 7104 | For additional information on using a PR Service, you | 
|  | 7105 | can see the | 
|  | 7106 | <ulink url='&YOCTO_WIKI_URL;/wiki/PR_Service'>PR Service</ulink> | 
|  | 7107 | wiki page. | 
|  | 7108 | </note> | 
|  | 7109 | </para> | 
|  | 7110 |  | 
|  | 7111 | <para> | 
|  | 7112 | The Yocto Project uses variables in order of | 
|  | 7113 | decreasing priority to facilitate revision numbering (i.e. | 
|  | 7114 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PE'><filename>PE</filename></ulink>, | 
|  | 7115 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>, and | 
|  | 7116 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink> | 
|  | 7117 | for epoch, version, and revision, respectively). | 
|  | 7118 | The values are highly dependent on the policies and | 
|  | 7119 | procedures of a given distribution and package feed. | 
|  | 7120 | </para> | 
|  | 7121 |  | 
|  | 7122 | <para> | 
|  | 7123 | Because the OpenEmbedded build system uses | 
|  | 7124 | "<ulink url='&YOCTO_DOCS_REF_URL;#checksums'>signatures</ulink>", | 
|  | 7125 | which are unique to a given build, the build system | 
|  | 7126 | knows when to rebuild packages. | 
|  | 7127 | All the inputs into a given task are represented by a | 
|  | 7128 | signature, which can trigger a rebuild when different. | 
|  | 7129 | Thus, the build system itself does not rely on the | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 7130 | <filename>PR</filename>, <filename>PV</filename>, and | 
|  | 7131 | <filename>PE</filename> numbers to trigger a rebuild. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7132 | The signatures, however, can be used to generate | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 7133 | these values. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7134 | </para> | 
|  | 7135 |  | 
|  | 7136 | <para> | 
|  | 7137 | The PR Service works with both | 
|  | 7138 | <filename>OEBasic</filename> and | 
|  | 7139 | <filename>OEBasicHash</filename> generators. | 
|  | 7140 | The value of <filename>PR</filename> bumps when the | 
|  | 7141 | checksum changes and the different generator mechanisms | 
|  | 7142 | change signatures under different circumstances. | 
|  | 7143 | </para> | 
|  | 7144 |  | 
|  | 7145 | <para> | 
|  | 7146 | As implemented, the build system includes values from | 
|  | 7147 | the PR Service into the <filename>PR</filename> field as | 
|  | 7148 | an addition using the form "<filename>.x</filename>" so | 
|  | 7149 | <filename>r0</filename> becomes <filename>r0.1</filename>, | 
|  | 7150 | <filename>r0.2</filename> and so forth. | 
|  | 7151 | This scheme allows existing <filename>PR</filename> values | 
|  | 7152 | to be used for whatever reasons, which include manual | 
|  | 7153 | <filename>PR</filename> bumps, should it be necessary. | 
|  | 7154 | </para> | 
|  | 7155 |  | 
|  | 7156 | <para> | 
|  | 7157 | By default, the PR Service is not enabled or running. | 
|  | 7158 | Thus, the packages generated are just "self consistent". | 
|  | 7159 | The build system adds and removes packages and | 
|  | 7160 | there are no guarantees about upgrade paths but images | 
|  | 7161 | will be consistent and correct with the latest changes. | 
|  | 7162 | </para> | 
|  | 7163 |  | 
|  | 7164 | <para> | 
|  | 7165 | The simplest form for a PR Service is for it to exist | 
|  | 7166 | for a single host development system that builds the | 
|  | 7167 | package feed (building system). | 
|  | 7168 | For this scenario, you can enable a local PR Service by | 
|  | 7169 | setting | 
|  | 7170 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PRSERV_HOST'><filename>PRSERV_HOST</filename></ulink> | 
|  | 7171 | in your <filename>local.conf</filename> file in the | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 7172 | <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7173 | <literallayout class='monospaced'> | 
|  | 7174 | PRSERV_HOST = "localhost:0" | 
|  | 7175 | </literallayout> | 
|  | 7176 | Once the service is started, packages will automatically | 
|  | 7177 | get increasing <filename>PR</filename> values and | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 7178 | BitBake takes care of starting and stopping the server. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7179 | </para> | 
|  | 7180 |  | 
|  | 7181 | <para> | 
|  | 7182 | If you have a more complex setup where multiple host | 
|  | 7183 | development systems work against a common, shared package | 
|  | 7184 | feed, you have a single PR Service running and it is | 
|  | 7185 | connected to each building system. | 
|  | 7186 | For this scenario, you need to start the PR Service using | 
|  | 7187 | the <filename>bitbake-prserv</filename> command: | 
|  | 7188 | <literallayout class='monospaced'> | 
|  | 7189 | bitbake-prserv --host <replaceable>ip</replaceable> --port <replaceable>port</replaceable> --start | 
|  | 7190 | </literallayout> | 
|  | 7191 | In addition to hand-starting the service, you need to | 
|  | 7192 | update the <filename>local.conf</filename> file of each | 
|  | 7193 | building system as described earlier so each system | 
|  | 7194 | points to the server and port. | 
|  | 7195 | </para> | 
|  | 7196 |  | 
|  | 7197 | <para> | 
|  | 7198 | It is also recommended you use build history, which adds | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 7199 | some sanity checks to binary package versions, in | 
|  | 7200 | conjunction with the server that is running the PR Service. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7201 | To enable build history, add the following to each building | 
|  | 7202 | system's <filename>local.conf</filename> file: | 
|  | 7203 | <literallayout class='monospaced'> | 
|  | 7204 | # It is recommended to activate "buildhistory" for testing the PR service | 
|  | 7205 | INHERIT += "buildhistory" | 
|  | 7206 | BUILDHISTORY_COMMIT = "1" | 
|  | 7207 | </literallayout> | 
|  | 7208 | For information on build history, see the | 
|  | 7209 | "<ulink url='&YOCTO_DOCS_REF_URL;#maintaining-build-output-quality'>Maintaining Build Output Quality</ulink>" | 
|  | 7210 | section in the Yocto Project Reference Manual. | 
|  | 7211 | </para> | 
|  | 7212 |  | 
|  | 7213 | <note> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 7214 | <para> | 
|  | 7215 | The OpenEmbedded build system does not maintain | 
|  | 7216 | <filename>PR</filename> information as part of the | 
|  | 7217 | shared state (sstate) packages. | 
|  | 7218 | If you maintain an sstate feed, its expected that either | 
|  | 7219 | all your building systems that contribute to the sstate | 
|  | 7220 | feed use a shared PR Service, or you do not run a PR | 
|  | 7221 | Service on any of your building systems. | 
|  | 7222 | Having some systems use a PR Service while others do | 
|  | 7223 | not leads to obvious problems. | 
|  | 7224 | </para> | 
|  | 7225 |  | 
|  | 7226 | <para> | 
|  | 7227 | For more information on shared state, see the | 
|  | 7228 | "<ulink url='&YOCTO_DOCS_REF_URL;#shared-state-cache'>Shared State Cache</ulink>" | 
|  | 7229 | section in the Yocto Project Reference Manual. | 
|  | 7230 | </para> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7231 | </note> | 
|  | 7232 | </section> | 
|  | 7233 |  | 
|  | 7234 | <section id='manually-bumping-pr'> | 
|  | 7235 | <title>Manually Bumping PR</title> | 
|  | 7236 |  | 
|  | 7237 | <para> | 
|  | 7238 | The alternative to setting up a PR Service is to manually | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 7239 | "bump" the | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7240 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink> | 
|  | 7241 | variable. | 
|  | 7242 | </para> | 
|  | 7243 |  | 
|  | 7244 | <para> | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 7245 | If a committed change results in changing the package | 
|  | 7246 | output, then the value of the PR variable needs to be | 
|  | 7247 | increased (or "bumped") as part of that commit. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7248 | For new recipes you should add the <filename>PR</filename> | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 7249 | variable and set its initial value equal to "r0", which is | 
|  | 7250 | the default. | 
|  | 7251 | Even though the default value is "r0", the practice of | 
|  | 7252 | adding it to a new recipe makes it harder to forget to bump | 
|  | 7253 | the variable when you make changes to the recipe in future. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7254 | </para> | 
|  | 7255 |  | 
|  | 7256 | <para> | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 7257 | If you are sharing a common <filename>.inc</filename> file | 
|  | 7258 | with multiple recipes, you can also use the | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7259 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-INC_PR'>INC_PR</ulink></filename> | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 7260 | variable to ensure that the recipes sharing the | 
|  | 7261 | <filename>.inc</filename> file are rebuilt when the | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7262 | <filename>.inc</filename> file itself is changed. | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 7263 | The <filename>.inc</filename> file must set | 
|  | 7264 | <filename>INC_PR</filename> (initially to "r0"), and all | 
|  | 7265 | recipes referring to it should set <filename>PR</filename> | 
|  | 7266 | to "${INC_PR}.0" initially, incrementing the last number | 
|  | 7267 | when the recipe is changed. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7268 | If the <filename>.inc</filename> file is changed then its | 
|  | 7269 | <filename>INC_PR</filename> should be incremented. | 
|  | 7270 | </para> | 
|  | 7271 |  | 
|  | 7272 | <para> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 7273 | When upgrading the version of a binary package, assuming the | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7274 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'>PV</ulink></filename> | 
|  | 7275 | changes, the <filename>PR</filename> variable should be | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 7276 | reset to "r0" (or "${INC_PR}.0" if you are using | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7277 | <filename>INC_PR</filename>). | 
|  | 7278 | </para> | 
|  | 7279 |  | 
|  | 7280 | <para> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 7281 | Usually, version increases occur only to binary packages. | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 7282 | However, if for some reason <filename>PV</filename> changes | 
|  | 7283 | but does not increase, you can increase the | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7284 | <filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PE'>PE</ulink></filename> | 
|  | 7285 | variable (Package Epoch). | 
|  | 7286 | The <filename>PE</filename> variable defaults to "0". | 
|  | 7287 | </para> | 
|  | 7288 |  | 
|  | 7289 | <para> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 7290 | Binary package version numbering strives to follow the | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7291 | <ulink url='http://www.debian.org/doc/debian-policy/ch-controlfields.html'> | 
|  | 7292 | Debian Version Field Policy Guidelines</ulink>. | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 7293 | These guidelines define how versions are compared and what | 
|  | 7294 | "increasing" a version means. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7295 | </para> | 
|  | 7296 | </section> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 7297 |  | 
|  | 7298 | <section id='automatically-incrementing-a-binary-package-revision-number'> | 
|  | 7299 | <title>Automatically Incrementing a Package Version Number</title> | 
|  | 7300 |  | 
|  | 7301 | <para> | 
|  | 7302 | When fetching a repository, BitBake uses the | 
|  | 7303 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink> | 
|  | 7304 | variable to determine the specific source code revision | 
|  | 7305 | from which to build. | 
|  | 7306 | You set the <filename>SRCREV</filename> variable to | 
|  | 7307 | <ulink url='&YOCTO_DOCS_REF_URL;#var-AUTOREV'><filename>AUTOREV</filename></ulink> | 
|  | 7308 | to cause the OpenEmbedded build system to automatically use the | 
|  | 7309 | latest revision of the software: | 
|  | 7310 | <literallayout class='monospaced'> | 
|  | 7311 | SRCREV = "${AUTOREV}" | 
|  | 7312 | </literallayout> | 
|  | 7313 | </para> | 
|  | 7314 |  | 
|  | 7315 | <para> | 
|  | 7316 | Furthermore, you need to reference <filename>SRCPV</filename> | 
|  | 7317 | in <filename>PV</filename> in order to automatically update | 
|  | 7318 | the version whenever the revision of the source code | 
|  | 7319 | changes. | 
|  | 7320 | Here is an example: | 
|  | 7321 | <literallayout class='monospaced'> | 
|  | 7322 | PV = "1.0+git${SRCPV}" | 
|  | 7323 | </literallayout> | 
|  | 7324 | The OpenEmbedded build system substitutes | 
|  | 7325 | <filename>SRCPV</filename> with the following: | 
|  | 7326 | <literallayout class='monospaced'> | 
|  | 7327 | AUTOINC+<replaceable>source_code_revision</replaceable> | 
|  | 7328 | </literallayout> | 
|  | 7329 | The build system replaces the <filename>AUTOINC</filename> with | 
|  | 7330 | a number. | 
|  | 7331 | The number used depends on the state of the PR Service: | 
|  | 7332 | <itemizedlist> | 
|  | 7333 | <listitem><para> | 
|  | 7334 | If PR Service is enabled, the build system increments | 
|  | 7335 | the number, which is similar to the behavior of | 
|  | 7336 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>. | 
|  | 7337 | This behavior results in linearly increasing package | 
|  | 7338 | versions, which is desirable. | 
|  | 7339 | Here is an example: | 
|  | 7340 | <literallayout class='monospaced'> | 
|  | 7341 | hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk | 
|  | 7342 | hello-world-git_0.0+git1+dd2f5c3565-r0.0_armv7a-neon.ipk | 
|  | 7343 | </literallayout> | 
|  | 7344 | </para></listitem> | 
|  | 7345 | <listitem><para> | 
|  | 7346 | If PR Service is not enabled, the build system | 
|  | 7347 | replaces the <filename>AUTOINC</filename> | 
|  | 7348 | placeholder with zero (i.e. "0"). | 
|  | 7349 | This results in changing the package version since | 
|  | 7350 | the source revision is included. | 
|  | 7351 | However, package versions are not increased linearly. | 
|  | 7352 | Here is an example: | 
|  | 7353 | <literallayout class='monospaced'> | 
|  | 7354 | hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk | 
|  | 7355 | hello-world-git_0.0+git0+dd2f5c3565-r0.0_armv7a-neon.ipk | 
|  | 7356 | </literallayout> | 
|  | 7357 | </para></listitem> | 
|  | 7358 | </itemizedlist> | 
|  | 7359 | </para> | 
|  | 7360 |  | 
|  | 7361 | <para> | 
|  | 7362 | In summary, the OpenEmbedded build system does not track the | 
|  | 7363 | history of binary package versions for this purpose. | 
|  | 7364 | <filename>AUTOINC</filename>, in this case, is comparable to | 
|  | 7365 | <filename>PR</filename>. | 
|  | 7366 | If PR server is not enabled, <filename>AUTOINC</filename> | 
|  | 7367 | in the package version is simply replaced by "0". | 
|  | 7368 | If PR server is enabled, the build system keeps track of the | 
|  | 7369 | package versions and bumps the number when the package | 
|  | 7370 | revision changes. | 
|  | 7371 | </para> | 
|  | 7372 | </section> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7373 | </section> | 
|  | 7374 |  | 
|  | 7375 | <section id='handling-optional-module-packaging'> | 
|  | 7376 | <title>Handling Optional Module Packaging</title> | 
|  | 7377 |  | 
|  | 7378 | <para> | 
|  | 7379 | Many pieces of software split functionality into optional | 
|  | 7380 | modules (or plug-ins) and the plug-ins that are built | 
|  | 7381 | might depend on configuration options. | 
|  | 7382 | To avoid having to duplicate the logic that determines what | 
|  | 7383 | modules are available in your recipe or to avoid having | 
|  | 7384 | to package each module by hand, the OpenEmbedded build system | 
|  | 7385 | provides functionality to handle module packaging dynamically. | 
|  | 7386 | </para> | 
|  | 7387 |  | 
|  | 7388 | <para> | 
|  | 7389 | To handle optional module packaging, you need to do two things: | 
|  | 7390 | <itemizedlist> | 
|  | 7391 | <listitem><para>Ensure the module packaging is actually | 
|  | 7392 | done.</para></listitem> | 
|  | 7393 | <listitem><para>Ensure that any dependencies on optional | 
|  | 7394 | modules from other recipes are satisfied by your recipe. | 
|  | 7395 | </para></listitem> | 
|  | 7396 | </itemizedlist> | 
|  | 7397 | </para> | 
|  | 7398 |  | 
|  | 7399 | <section id='making-sure-the-packaging-is-done'> | 
|  | 7400 | <title>Making Sure the Packaging is Done</title> | 
|  | 7401 |  | 
|  | 7402 | <para> | 
|  | 7403 | To ensure the module packaging actually gets done, you use | 
|  | 7404 | the <filename>do_split_packages</filename> function within | 
|  | 7405 | the <filename>populate_packages</filename> Python function | 
|  | 7406 | in your recipe. | 
|  | 7407 | The <filename>do_split_packages</filename> function | 
|  | 7408 | searches for a pattern of files or directories under a | 
|  | 7409 | specified path and creates a package for each one it finds | 
|  | 7410 | by appending to the | 
|  | 7411 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES'><filename>PACKAGES</filename></ulink> | 
|  | 7412 | variable and setting the appropriate values for | 
|  | 7413 | <filename>FILES_packagename</filename>, | 
|  | 7414 | <filename>RDEPENDS_packagename</filename>, | 
|  | 7415 | <filename>DESCRIPTION_packagename</filename>, and so forth. | 
|  | 7416 | Here is an example from the <filename>lighttpd</filename> | 
|  | 7417 | recipe: | 
|  | 7418 | <literallayout class='monospaced'> | 
|  | 7419 | python populate_packages_prepend () { | 
|  | 7420 | lighttpd_libdir = d.expand('${libdir}') | 
|  | 7421 | do_split_packages(d, lighttpd_libdir, '^mod_(.*)\.so$', | 
|  | 7422 | 'lighttpd-module-%s', 'Lighttpd module for %s', | 
|  | 7423 | extra_depends='') | 
|  | 7424 | } | 
|  | 7425 | </literallayout> | 
|  | 7426 | The previous example specifies a number of things in the | 
|  | 7427 | call to <filename>do_split_packages</filename>. | 
|  | 7428 | <itemizedlist> | 
|  | 7429 | <listitem><para>A directory within the files installed | 
|  | 7430 | by your recipe through <filename>do_install</filename> | 
|  | 7431 | in which to search.</para></listitem> | 
|  | 7432 | <listitem><para>A regular expression used to match module | 
|  | 7433 | files in that directory. | 
|  | 7434 | In the example, note the parentheses () that mark | 
|  | 7435 | the part of the expression from which the module | 
|  | 7436 | name should be derived.</para></listitem> | 
|  | 7437 | <listitem><para>A pattern to use for the package names. | 
|  | 7438 | </para></listitem> | 
|  | 7439 | <listitem><para>A description for each package. | 
|  | 7440 | </para></listitem> | 
|  | 7441 | <listitem><para>An empty string for | 
|  | 7442 | <filename>extra_depends</filename>, which disables | 
|  | 7443 | the default dependency on the main | 
|  | 7444 | <filename>lighttpd</filename> package. | 
|  | 7445 | Thus, if a file in <filename>${libdir}</filename> | 
|  | 7446 | called <filename>mod_alias.so</filename> is found, | 
|  | 7447 | a package called <filename>lighttpd-module-alias</filename> | 
|  | 7448 | is created for it and the | 
|  | 7449 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DESCRIPTION'><filename>DESCRIPTION</filename></ulink> | 
|  | 7450 | is set to "Lighttpd module for alias".</para></listitem> | 
|  | 7451 | </itemizedlist> | 
|  | 7452 | </para> | 
|  | 7453 |  | 
|  | 7454 | <para> | 
|  | 7455 | Often, packaging modules is as simple as the previous | 
|  | 7456 | example. | 
|  | 7457 | However, more advanced options exist that you can use | 
|  | 7458 | within <filename>do_split_packages</filename> to modify its | 
|  | 7459 | behavior. | 
|  | 7460 | And, if you need to, you can add more logic by specifying | 
|  | 7461 | a hook function that is called for each package. | 
|  | 7462 | It is also perfectly acceptable to call | 
|  | 7463 | <filename>do_split_packages</filename> multiple times if | 
|  | 7464 | you have more than one set of modules to package. | 
|  | 7465 | </para> | 
|  | 7466 |  | 
|  | 7467 | <para> | 
|  | 7468 | For more examples that show how to use | 
|  | 7469 | <filename>do_split_packages</filename>, see the | 
|  | 7470 | <filename>connman.inc</filename> file in the | 
|  | 7471 | <filename>meta/recipes-connectivity/connman/</filename> | 
|  | 7472 | directory of the <filename>poky</filename> | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 7473 | <ulink url='&YOCTO_DOCS_REF_URL;#yocto-project-repositories'>source repository</ulink>. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7474 | You can also find examples in | 
|  | 7475 | <filename>meta/classes/kernel.bbclass</filename>. | 
|  | 7476 | </para> | 
|  | 7477 |  | 
|  | 7478 | <para> | 
|  | 7479 | Following is a reference that shows | 
|  | 7480 | <filename>do_split_packages</filename> mandatory and | 
|  | 7481 | optional arguments: | 
|  | 7482 | <literallayout class='monospaced'> | 
|  | 7483 | Mandatory arguments | 
|  | 7484 |  | 
|  | 7485 | root | 
|  | 7486 | The path in which to search | 
|  | 7487 | file_regex | 
|  | 7488 | Regular expression to match searched files. | 
|  | 7489 | Use parentheses () to mark the part of this | 
|  | 7490 | expression that should be used to derive the | 
|  | 7491 | module name (to be substituted where %s is | 
|  | 7492 | used in other function arguments as noted below) | 
|  | 7493 | output_pattern | 
|  | 7494 | Pattern to use for the package names. Must | 
|  | 7495 | include %s. | 
|  | 7496 | description | 
|  | 7497 | Description to set for each package. Must | 
|  | 7498 | include %s. | 
|  | 7499 |  | 
|  | 7500 | Optional arguments | 
|  | 7501 |  | 
|  | 7502 | postinst | 
|  | 7503 | Postinstall script to use for all packages | 
|  | 7504 | (as a string) | 
|  | 7505 | recursive | 
|  | 7506 | True to perform a recursive search - default | 
|  | 7507 | False | 
|  | 7508 | hook | 
|  | 7509 | A hook function to be called for every match. | 
|  | 7510 | The function will be called with the following | 
|  | 7511 | arguments (in the order listed): | 
|  | 7512 |  | 
|  | 7513 | f | 
|  | 7514 | Full path to the file/directory match | 
|  | 7515 | pkg | 
|  | 7516 | The package name | 
|  | 7517 | file_regex | 
|  | 7518 | As above | 
|  | 7519 | output_pattern | 
|  | 7520 | As above | 
|  | 7521 | modulename | 
|  | 7522 | The module name derived using file_regex | 
|  | 7523 |  | 
|  | 7524 | extra_depends | 
|  | 7525 | Extra runtime dependencies (RDEPENDS) to be | 
|  | 7526 | set for all packages. The default value of None | 
|  | 7527 | causes a dependency on the main package | 
|  | 7528 | (${PN}) - if you do not want this, pass empty | 
|  | 7529 | string '' for this parameter. | 
|  | 7530 | aux_files_pattern | 
|  | 7531 | Extra item(s) to be added to FILES for each | 
|  | 7532 | package. Can be a single string item or a list | 
|  | 7533 | of strings for multiple items. Must include %s. | 
|  | 7534 | postrm | 
|  | 7535 | postrm script to use for all packages (as a | 
|  | 7536 | string) | 
|  | 7537 | allow_dirs | 
|  | 7538 | True to allow directories to be matched - | 
|  | 7539 | default False | 
|  | 7540 | prepend | 
|  | 7541 | If True, prepend created packages to PACKAGES | 
|  | 7542 | instead of the default False which appends them | 
|  | 7543 | match_path | 
|  | 7544 | match file_regex on the whole relative path to | 
|  | 7545 | the root rather than just the file name | 
|  | 7546 | aux_files_pattern_verbatim | 
|  | 7547 | Extra item(s) to be added to FILES for each | 
|  | 7548 | package, using the actual derived module name | 
|  | 7549 | rather than converting it to something legal | 
|  | 7550 | for a package name. Can be a single string item | 
|  | 7551 | or a list of strings for multiple items. Must | 
|  | 7552 | include %s. | 
|  | 7553 | allow_links | 
|  | 7554 | True to allow symlinks to be matched - default | 
|  | 7555 | False | 
|  | 7556 | summary | 
|  | 7557 | Summary to set for each package. Must include %s; | 
|  | 7558 | defaults to description if not set. | 
|  | 7559 | </literallayout> | 
|  | 7560 | </para> | 
|  | 7561 | </section> | 
|  | 7562 |  | 
|  | 7563 | <section id='satisfying-dependencies'> | 
|  | 7564 | <title>Satisfying Dependencies</title> | 
|  | 7565 |  | 
|  | 7566 | <para> | 
|  | 7567 | The second part for handling optional module packaging | 
|  | 7568 | is to ensure that any dependencies on optional modules | 
|  | 7569 | from other recipes are satisfied by your recipe. | 
|  | 7570 | You can be sure these dependencies are satisfied by | 
|  | 7571 | using the | 
|  | 7572 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGES_DYNAMIC'><filename>PACKAGES_DYNAMIC</filename></ulink> variable. | 
|  | 7573 | Here is an example that continues with the | 
|  | 7574 | <filename>lighttpd</filename> recipe shown earlier: | 
|  | 7575 | <literallayout class='monospaced'> | 
|  | 7576 | PACKAGES_DYNAMIC = "lighttpd-module-.*" | 
|  | 7577 | </literallayout> | 
|  | 7578 | The name specified in the regular expression can of | 
|  | 7579 | course be anything. | 
|  | 7580 | In this example, it is <filename>lighttpd-module-</filename> | 
|  | 7581 | and is specified as the prefix to ensure that any | 
|  | 7582 | <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink> | 
|  | 7583 | and <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink> | 
|  | 7584 | on a package name starting with the prefix are satisfied | 
|  | 7585 | during build time. | 
|  | 7586 | If you are using <filename>do_split_packages</filename> | 
|  | 7587 | as described in the previous section, the value you put in | 
|  | 7588 | <filename>PACKAGES_DYNAMIC</filename> should correspond to | 
|  | 7589 | the name pattern specified in the call to | 
|  | 7590 | <filename>do_split_packages</filename>. | 
|  | 7591 | </para> | 
|  | 7592 | </section> | 
|  | 7593 | </section> | 
|  | 7594 |  | 
|  | 7595 | <section id='using-runtime-package-management'> | 
|  | 7596 | <title>Using Runtime Package Management</title> | 
|  | 7597 |  | 
|  | 7598 | <para> | 
|  | 7599 | During a build, BitBake always transforms a recipe into one or | 
|  | 7600 | more packages. | 
|  | 7601 | For example, BitBake takes the <filename>bash</filename> recipe | 
|  | 7602 | and currently produces the <filename>bash-dbg</filename>, | 
|  | 7603 | <filename>bash-staticdev</filename>, | 
|  | 7604 | <filename>bash-dev</filename>, <filename>bash-doc</filename>, | 
|  | 7605 | <filename>bash-locale</filename>, and | 
|  | 7606 | <filename>bash</filename> packages. | 
|  | 7607 | Not all generated packages are included in an image. | 
|  | 7608 | </para> | 
|  | 7609 |  | 
|  | 7610 | <para> | 
|  | 7611 | In several situations, you might need to update, add, remove, | 
|  | 7612 | or query the packages on a target device at runtime | 
|  | 7613 | (i.e. without having to generate a new image). | 
|  | 7614 | Examples of such situations include: | 
|  | 7615 | <itemizedlist> | 
|  | 7616 | <listitem><para> | 
|  | 7617 | You want to provide in-the-field updates to deployed | 
|  | 7618 | devices (e.g. security updates). | 
|  | 7619 | </para></listitem> | 
|  | 7620 | <listitem><para> | 
|  | 7621 | You want to have a fast turn-around development cycle | 
|  | 7622 | for one or more applications that run on your device. | 
|  | 7623 | </para></listitem> | 
|  | 7624 | <listitem><para> | 
|  | 7625 | You want to temporarily install the "debug" packages | 
|  | 7626 | of various applications on your device so that | 
|  | 7627 | debugging can be greatly improved by allowing | 
|  | 7628 | access to symbols and source debugging. | 
|  | 7629 | </para></listitem> | 
|  | 7630 | <listitem><para> | 
|  | 7631 | You want to deploy a more minimal package selection of | 
|  | 7632 | your device but allow in-the-field updates to add a | 
|  | 7633 | larger selection for customization. | 
|  | 7634 | </para></listitem> | 
|  | 7635 | </itemizedlist> | 
|  | 7636 | </para> | 
|  | 7637 |  | 
|  | 7638 | <para> | 
|  | 7639 | In all these situations, you have something similar to a more | 
|  | 7640 | traditional Linux distribution in that in-field devices | 
|  | 7641 | are able to receive pre-compiled packages from a server for | 
|  | 7642 | installation or update. | 
|  | 7643 | Being able to install these packages on a running, | 
|  | 7644 | in-field device is what is termed "runtime package | 
|  | 7645 | management". | 
|  | 7646 | </para> | 
|  | 7647 |  | 
|  | 7648 | <para> | 
|  | 7649 | In order to use runtime package management, you | 
|  | 7650 | need a host/server machine that serves up the pre-compiled | 
|  | 7651 | packages plus the required metadata. | 
|  | 7652 | You also need package manipulation tools on the target. | 
|  | 7653 | The build machine is a likely candidate to act as the server. | 
|  | 7654 | However, that machine does not necessarily have to be the | 
|  | 7655 | package server. | 
|  | 7656 | The build machine could push its artifacts to another machine | 
|  | 7657 | that acts as the server (e.g. Internet-facing). | 
|  | 7658 | </para> | 
|  | 7659 |  | 
|  | 7660 | <para> | 
|  | 7661 | A simple build that targets just one device produces | 
|  | 7662 | more than one package database. | 
|  | 7663 | In other words, the packages produced by a build are separated | 
|  | 7664 | out into a couple of different package groupings based on | 
|  | 7665 | criteria such as the target's CPU architecture, the target | 
|  | 7666 | board, or the C library used on the target. | 
|  | 7667 | For example, a build targeting the <filename>qemuarm</filename> | 
|  | 7668 | device produces the following three package databases: | 
|  | 7669 | <filename>all</filename>, <filename>armv5te</filename>, and | 
|  | 7670 | <filename>qemuarm</filename>. | 
|  | 7671 | If you wanted your <filename>qemuarm</filename> device to be | 
|  | 7672 | aware of all the packages that were available to it, | 
|  | 7673 | you would need to point it to each of these databases | 
|  | 7674 | individually. | 
|  | 7675 | In a similar way, a traditional Linux distribution usually is | 
|  | 7676 | configured to be aware of a number of software repositories | 
|  | 7677 | from which it retrieves packages. | 
|  | 7678 | </para> | 
|  | 7679 |  | 
|  | 7680 | <para> | 
|  | 7681 | Using runtime package management is completely optional and | 
|  | 7682 | not required for a successful build or deployment in any | 
|  | 7683 | way. | 
|  | 7684 | But if you want to make use of runtime package management, | 
|  | 7685 | you need to do a couple things above and beyond the basics. | 
|  | 7686 | The remainder of this section describes what you need to do. | 
|  | 7687 | </para> | 
|  | 7688 |  | 
|  | 7689 | <section id='runtime-package-management-build'> | 
|  | 7690 | <title>Build Considerations</title> | 
|  | 7691 |  | 
|  | 7692 | <para> | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 7693 | This section describes build considerations of which you | 
|  | 7694 | need to be aware in order to provide support for runtime | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7695 | package management. | 
|  | 7696 | </para> | 
|  | 7697 |  | 
|  | 7698 | <para> | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 7699 | When BitBake generates packages, it needs to know | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7700 | what format or formats to use. | 
|  | 7701 | In your configuration, you use the | 
|  | 7702 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink> | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 7703 | variable to specify the format: | 
|  | 7704 | <orderedlist> | 
|  | 7705 | <listitem><para> | 
|  | 7706 | Open the <filename>local.conf</filename> file | 
|  | 7707 | inside your | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 7708 | <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink> | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 7709 | (e.g. <filename>~/poky/build/conf/local.conf</filename>). | 
|  | 7710 | </para></listitem> | 
|  | 7711 | <listitem><para> | 
|  | 7712 | Select the desired package format as follows: | 
|  | 7713 | <literallayout class='monospaced'> | 
|  | 7714 | PACKAGE_CLASSES ?= “package_<replaceable>packageformat</replaceable>” | 
|  | 7715 | </literallayout> | 
|  | 7716 | where <replaceable>packageformat</replaceable> | 
|  | 7717 | can be "ipk", "rpm", and "deb", which are the | 
|  | 7718 | supported package formats. | 
|  | 7719 | <note> | 
|  | 7720 | Because the Yocto Project supports three | 
|  | 7721 | different package formats, you can set the | 
|  | 7722 | variable with more than one argument. | 
|  | 7723 | However, the OpenEmbedded build system only | 
|  | 7724 | uses the first argument when creating an image | 
|  | 7725 | or Software Development Kit (SDK). | 
|  | 7726 | </note> | 
|  | 7727 | </para></listitem> | 
|  | 7728 | </orderedlist> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7729 | </para> | 
|  | 7730 |  | 
|  | 7731 | <para> | 
|  | 7732 | If you would like your image to start off with a basic | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 7733 | package database containing the packages in your current | 
|  | 7734 | build as well as to have the relevant tools available on the | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7735 | target for runtime package management, you can include | 
|  | 7736 | "package-management" in the | 
|  | 7737 | <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink> | 
|  | 7738 | variable. | 
|  | 7739 | Including "package-management" in this | 
|  | 7740 | configuration variable ensures that when the image | 
|  | 7741 | is assembled for your target, the image includes | 
|  | 7742 | the currently-known package databases as well as | 
|  | 7743 | the target-specific tools required for runtime | 
|  | 7744 | package management to be performed on the target. | 
|  | 7745 | However, this is not strictly necessary. | 
|  | 7746 | You could start your image off without any databases | 
|  | 7747 | but only include the required on-target package | 
|  | 7748 | tool(s). | 
|  | 7749 | As an example, you could include "opkg" in your | 
|  | 7750 | <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink> | 
|  | 7751 | variable if you are using the IPK package format. | 
|  | 7752 | You can then initialize your target's package database(s) | 
|  | 7753 | later once your image is up and running. | 
|  | 7754 | </para> | 
|  | 7755 |  | 
|  | 7756 | <para> | 
|  | 7757 | Whenever you perform any sort of build step that can | 
|  | 7758 | potentially generate a package or modify an existing | 
|  | 7759 | package, it is always a good idea to re-generate the | 
|  | 7760 | package index with: | 
|  | 7761 | <literallayout class='monospaced'> | 
|  | 7762 | $ bitbake package-index | 
|  | 7763 | </literallayout> | 
|  | 7764 | Realize that it is not sufficient to simply do the | 
|  | 7765 | following: | 
|  | 7766 | <literallayout class='monospaced'> | 
|  | 7767 | $ bitbake <replaceable>some-package</replaceable> package-index | 
|  | 7768 | </literallayout> | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 7769 | The reason for this restriction is because BitBake does not | 
|  | 7770 | properly schedule the <filename>package-index</filename> | 
|  | 7771 | target fully after any other target has completed. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7772 | Thus, be sure to run the package update step separately. | 
|  | 7773 | </para> | 
|  | 7774 |  | 
|  | 7775 | <para> | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 7776 | You can use the | 
|  | 7777 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>, | 
|  | 7778 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>, | 
|  | 7779 | and | 
|  | 7780 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink> | 
|  | 7781 | variables to pre-configure target images to use a package | 
|  | 7782 | feed. | 
|  | 7783 | If you do not define these variables, then manual steps | 
|  | 7784 | as described in the subsequent sections are necessary to | 
|  | 7785 | configure the target. | 
|  | 7786 | You should set these variables before building the image | 
|  | 7787 | in order to produce a correctly configured image. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7788 | </para> | 
|  | 7789 |  | 
|  | 7790 | <para> | 
|  | 7791 | When your build is complete, your packages reside in the | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 7792 | <filename>${TMPDIR}/deploy/<replaceable>packageformat</replaceable></filename> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7793 | directory. | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 7794 | For example, if | 
|  | 7795 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-TMPDIR'><filename>TMPDIR</filename></ulink><filename>}</filename> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7796 | is <filename>tmp</filename> and your selected package type | 
|  | 7797 | is IPK, then your IPK packages are available in | 
|  | 7798 | <filename>tmp/deploy/ipk</filename>. | 
|  | 7799 | </para> | 
|  | 7800 | </section> | 
|  | 7801 |  | 
|  | 7802 | <section id='runtime-package-management-server'> | 
|  | 7803 | <title>Host or Server Machine Setup</title> | 
|  | 7804 |  | 
|  | 7805 | <para> | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 7806 | Although other protocols are possible, a server using HTTP | 
|  | 7807 | typically serves packages. | 
|  | 7808 | If you want to use HTTP, then set up and configure a | 
|  | 7809 | web server such as Apache 2, lighttpd, or | 
|  | 7810 | SimpleHTTPServer on the machine serving the packages. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7811 | </para> | 
|  | 7812 |  | 
|  | 7813 | <para> | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 7814 | To keep things simple, this section describes how to set | 
|  | 7815 | up a SimpleHTTPServer web server to share package feeds | 
|  | 7816 | from the developer's machine. | 
|  | 7817 | Although this server might not be the best for a production | 
|  | 7818 | environment, the setup is simple and straight forward. | 
|  | 7819 | Should you want to use a different server more suited for | 
|  | 7820 | production (e.g. Apache 2, Lighttpd, or Nginx), take the | 
|  | 7821 | appropriate steps to do so. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7822 | </para> | 
|  | 7823 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 7824 | <para> | 
|  | 7825 | From within the build directory where you have built an | 
|  | 7826 | image based on your packaging choice (i.e. the | 
|  | 7827 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_CLASSES'><filename>PACKAGE_CLASSES</filename></ulink> | 
|  | 7828 | setting), simply start the server. | 
|  | 7829 | The following example assumes a build directory of | 
|  | 7830 | <filename>~/poky/build/tmp/deploy/rpm</filename> and a | 
|  | 7831 | <filename>PACKAGE_CLASSES</filename> setting of | 
|  | 7832 | "package_rpm": | 
|  | 7833 | <literallayout class='monospaced'> | 
|  | 7834 | $ cd ~/poky/build/tmp/deploy/rpm | 
|  | 7835 | $ python -m SimpleHTTPServer | 
|  | 7836 | </literallayout> | 
|  | 7837 | </para> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7838 | </section> | 
|  | 7839 |  | 
|  | 7840 | <section id='runtime-package-management-target'> | 
|  | 7841 | <title>Target Setup</title> | 
|  | 7842 |  | 
|  | 7843 | <para> | 
|  | 7844 | Setting up the target differs depending on the | 
|  | 7845 | package management system. | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 7846 | This section provides information for RPM, IPK, and DEB. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7847 | </para> | 
|  | 7848 |  | 
|  | 7849 | <section id='runtime-package-management-target-rpm'> | 
|  | 7850 | <title>Using RPM</title> | 
|  | 7851 |  | 
|  | 7852 | <para> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 7853 | The <filename>dnf</filename> application performs | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 7854 | runtime package management of RPM packages. | 
|  | 7855 | You must perform an initial setup for | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 7856 | <filename>dnf</filename> on the target machine | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 7857 | if the | 
|  | 7858 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>, | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 7859 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>, | 
|  | 7860 | and | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 7861 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink> | 
|  | 7862 | variables have not been set or the target image was | 
|  | 7863 | built before the variables were set. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7864 | </para> | 
|  | 7865 |  | 
|  | 7866 | <para> | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 7867 | As an example, assume the target is able to use the | 
|  | 7868 | following package databases: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7869 | <filename>all</filename>, <filename>i586</filename>, | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 7870 | and <filename>qemux86</filename> from a server named | 
|  | 7871 | <filename>my.server</filename>. | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 7872 | You must inform <filename>dnf</filename> of the | 
|  | 7873 | availability of these databases by creating a | 
|  | 7874 | <filename>/etc/yum.repos.d/oe-packages.repo</filename> | 
|  | 7875 | file with the following content: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7876 | <literallayout class='monospaced'> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 7877 | [oe-packages] | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 7878 | baseurl=http://my.server/rpm/i586 http://my.server/rpm/qemux86 http://my.server/rpm/all | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7879 | </literallayout> | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 7880 | From the target machine, fetch the repository: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7881 | <literallayout class='monospaced'> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 7882 | # dnf makecache | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7883 | </literallayout> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 7884 | After everything is set up, <filename>dnf</filename> | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 7885 | is able to find, install, and upgrade packages from | 
|  | 7886 | the specified repository. | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 7887 | <note> | 
|  | 7888 | See the | 
|  | 7889 | <ulink url='http://dnf.readthedocs.io/en/latest/'>DNF documentation</ulink> | 
|  | 7890 | for additional information. | 
|  | 7891 | </note> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7892 | </para> | 
|  | 7893 | </section> | 
|  | 7894 |  | 
|  | 7895 | <section id='runtime-package-management-target-ipk'> | 
|  | 7896 | <title>Using IPK</title> | 
|  | 7897 |  | 
|  | 7898 | <para> | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 7899 | The <filename>opkg</filename> application performs | 
|  | 7900 | runtime package management of IPK packages. | 
|  | 7901 | You must perform an initial setup for | 
|  | 7902 | <filename>opkg</filename> on the target machine | 
|  | 7903 | if the | 
|  | 7904 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>, | 
|  | 7905 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>, and | 
|  | 7906 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink> | 
|  | 7907 | variables have not been set or the target image was | 
|  | 7908 | built before the variables were set. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7909 | </para> | 
|  | 7910 |  | 
|  | 7911 | <para> | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 7912 | The <filename>opkg</filename> application uses | 
|  | 7913 | configuration files to find available package | 
|  | 7914 | databases. | 
|  | 7915 | Thus, you need to create a configuration file inside | 
|  | 7916 | the <filename>/etc/opkg/</filename> direction, which | 
|  | 7917 | informs <filename>opkg</filename> of any repository | 
|  | 7918 | you want to use. | 
|  | 7919 | </para> | 
|  | 7920 |  | 
|  | 7921 | <para> | 
|  | 7922 | As an example, suppose you are serving packages from a | 
|  | 7923 | <filename>ipk/</filename> directory containing the | 
|  | 7924 | <filename>i586</filename>, | 
|  | 7925 | <filename>all</filename>, and | 
|  | 7926 | <filename>qemux86</filename> databases through an | 
|  | 7927 | HTTP server named <filename>my.server</filename>. | 
|  | 7928 | On the target, create a configuration file | 
|  | 7929 | (e.g. <filename>my_repo.conf</filename>) inside the | 
|  | 7930 | <filename>/etc/opkg/</filename> directory containing | 
|  | 7931 | the following: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7932 | <literallayout class='monospaced'> | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 7933 | src/gz all http://my.server/ipk/all | 
|  | 7934 | src/gz i586 http://my.server/ipk/i586 | 
|  | 7935 | src/gz qemux86 http://my.server/ipk/qemux86 | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7936 | </literallayout> | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 7937 | Next, instruct <filename>opkg</filename> to fetch | 
|  | 7938 | the repository information: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7939 | <literallayout class='monospaced'> | 
|  | 7940 | # opkg update | 
|  | 7941 | </literallayout> | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 7942 | The <filename>opkg</filename> application is now able | 
|  | 7943 | to find, install, and upgrade packages from the | 
|  | 7944 | specified repository. | 
|  | 7945 | </para> | 
|  | 7946 | </section> | 
|  | 7947 |  | 
|  | 7948 | <section id='runtime-package-management-target-deb'> | 
|  | 7949 | <title>Using DEB</title> | 
|  | 7950 |  | 
|  | 7951 | <para> | 
|  | 7952 | The <filename>apt</filename> application performs | 
|  | 7953 | runtime package management of DEB packages. | 
|  | 7954 | This application uses a source list file to find | 
|  | 7955 | available package databases. | 
|  | 7956 | You must perform an initial setup for | 
|  | 7957 | <filename>apt</filename> on the target machine | 
|  | 7958 | if the | 
|  | 7959 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_ARCHS'><filename>PACKAGE_FEED_ARCHS</filename></ulink>, | 
|  | 7960 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_BASE_PATHS'><filename>PACKAGE_FEED_BASE_PATHS</filename></ulink>, and | 
|  | 7961 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_FEED_URIS'><filename>PACKAGE_FEED_URIS</filename></ulink> | 
|  | 7962 | variables have not been set or the target image was | 
|  | 7963 | built before the variables were set. | 
|  | 7964 | </para> | 
|  | 7965 |  | 
|  | 7966 | <para> | 
|  | 7967 | To inform <filename>apt</filename> of the repository | 
|  | 7968 | you want to use, you might create a list file (e.g. | 
|  | 7969 | <filename>my_repo.list</filename>) inside the | 
|  | 7970 | <filename>/etc/apt/sources.list.d/</filename> | 
|  | 7971 | directory. | 
|  | 7972 | As an example, suppose you are serving packages from a | 
|  | 7973 | <filename>deb/</filename> directory containing the | 
|  | 7974 | <filename>i586</filename>, | 
|  | 7975 | <filename>all</filename>, and | 
|  | 7976 | <filename>qemux86</filename> databases through an | 
|  | 7977 | HTTP server named <filename>my.server</filename>. | 
|  | 7978 | The list file should contain: | 
|  | 7979 | <literallayout class='monospaced'> | 
|  | 7980 | deb http://my.server/deb/all ./ | 
|  | 7981 | deb http://my.server/deb/i586 ./ | 
|  | 7982 | deb http://my.server/deb/qemux86 ./ | 
|  | 7983 | </literallayout> | 
|  | 7984 | Next, instruct the <filename>apt</filename> | 
|  | 7985 | application to fetch the repository information: | 
|  | 7986 | <literallayout class='monospaced'> | 
|  | 7987 | # apt-get update | 
|  | 7988 | </literallayout> | 
|  | 7989 | After this step, <filename>apt</filename> is able | 
|  | 7990 | to find, install, and upgrade packages from the | 
|  | 7991 | specified repository. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7992 | </para> | 
|  | 7993 | </section> | 
|  | 7994 | </section> | 
|  | 7995 | </section> | 
|  | 7996 |  | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 7997 | <section id='generating-and-using-signed-packages'> | 
|  | 7998 | <title>Generating and Using Signed Packages</title> | 
|  | 7999 | <para> | 
|  | 8000 | In order to add security to RPM packages used during a build, | 
|  | 8001 | you can take steps to securely sign them. | 
|  | 8002 | Once a signature is verified, the OpenEmbedded build system | 
|  | 8003 | can use the package in the build. | 
|  | 8004 | If security fails for a signed package, the build system | 
|  | 8005 | aborts the build. | 
|  | 8006 | </para> | 
|  | 8007 |  | 
|  | 8008 | <para> | 
|  | 8009 | This section describes how to sign RPM packages during a build | 
|  | 8010 | and how to use signed package feeds (repositories) when | 
|  | 8011 | doing a build. | 
|  | 8012 | </para> | 
|  | 8013 |  | 
|  | 8014 | <section id='signing-rpm-packages'> | 
|  | 8015 | <title>Signing RPM Packages</title> | 
|  | 8016 |  | 
|  | 8017 | <para> | 
|  | 8018 | To enable signing RPM packages, you must set up the | 
|  | 8019 | following configurations in either your | 
|  | 8020 | <filename>local.config</filename> or | 
|  | 8021 | <filename>distro.config</filename> file: | 
|  | 8022 | <literallayout class='monospaced'> | 
|  | 8023 | # Inherit sign_rpm.bbclass to enable signing functionality | 
|  | 8024 | INHERIT += " sign_rpm" | 
|  | 8025 | # Define the GPG key that will be used for signing. | 
|  | 8026 | RPM_GPG_NAME = "<replaceable>key_name</replaceable>" | 
|  | 8027 | # Provide passphrase for the key | 
|  | 8028 | RPM_GPG_PASSPHRASE = "<replaceable>passphrase</replaceable>" | 
|  | 8029 | </literallayout> | 
|  | 8030 | <note> | 
|  | 8031 | Be sure to supply appropriate values for both | 
|  | 8032 | <replaceable>key_name</replaceable> and | 
|  | 8033 | <replaceable>passphrase</replaceable> | 
|  | 8034 | </note> | 
|  | 8035 | Aside from the | 
|  | 8036 | <filename>RPM_GPG_NAME</filename> and | 
|  | 8037 | <filename>RPM_GPG_PASSPHRASE</filename> variables in the | 
|  | 8038 | previous example, two optional variables related to signing | 
|  | 8039 | exist: | 
|  | 8040 | <itemizedlist> | 
|  | 8041 | <listitem><para> | 
|  | 8042 | <emphasis><filename>GPG_BIN</filename>:</emphasis> | 
|  | 8043 | Specifies a <filename>gpg</filename> binary/wrapper | 
|  | 8044 | that is executed when the package is signed. | 
|  | 8045 | </para></listitem> | 
|  | 8046 | <listitem><para> | 
|  | 8047 | <emphasis><filename>GPG_PATH</filename>:</emphasis> | 
|  | 8048 | Specifies the <filename>gpg</filename> home | 
|  | 8049 | directory used when the package is signed. | 
|  | 8050 | </para></listitem> | 
|  | 8051 | </itemizedlist> | 
|  | 8052 | </para> | 
|  | 8053 | </section> | 
|  | 8054 |  | 
|  | 8055 | <section id='processing-package-feeds'> | 
|  | 8056 | <title>Processing Package Feeds</title> | 
|  | 8057 |  | 
|  | 8058 | <para> | 
|  | 8059 | In addition to being able to sign RPM packages, you can | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 8060 | also enable signed package feeds for IPK and RPM packages. | 
|  | 8061 | </para> | 
|  | 8062 |  | 
|  | 8063 | <para> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 8064 | The steps you need to take to enable signed package feed | 
|  | 8065 | use are similar to the steps used to sign RPM packages. | 
|  | 8066 | You must define the following in your | 
|  | 8067 | <filename>local.config</filename> or | 
|  | 8068 | <filename>distro.config</filename> file: | 
|  | 8069 | <literallayout class='monospaced'> | 
|  | 8070 | INHERIT += "sign_package_feed" | 
|  | 8071 | PACKAGE_FEED_GPG_NAME = "<replaceable>key_name</replaceable>" | 
|  | 8072 | PACKAGE_FEED_GPG_PASSPHRASE_FILE = "<replaceable>path_to_file_containing_passphrase</replaceable>" | 
|  | 8073 | </literallayout> | 
|  | 8074 | For signed package feeds, the passphrase must exist in a | 
|  | 8075 | separate file, which is pointed to by the | 
|  | 8076 | <filename>PACKAGE_FEED_GPG_PASSPHRASE_FILE</filename> | 
|  | 8077 | variable. | 
|  | 8078 | Regarding security, keeping a plain text passphrase out of | 
|  | 8079 | the configuration is more secure. | 
|  | 8080 | </para> | 
|  | 8081 |  | 
|  | 8082 | <para> | 
|  | 8083 | Aside from the | 
|  | 8084 | <filename>PACKAGE_FEED_GPG_NAME</filename> and | 
|  | 8085 | <filename>PACKAGE_FEED_GPG_PASSPHRASE_FILE</filename> | 
|  | 8086 | variables, three optional variables related to signed | 
|  | 8087 | package feeds exist: | 
|  | 8088 | <itemizedlist> | 
|  | 8089 | <listitem><para> | 
|  | 8090 | <emphasis><filename>GPG_BIN</filename>:</emphasis> | 
|  | 8091 | Specifies a <filename>gpg</filename> binary/wrapper | 
|  | 8092 | that is executed when the package is signed. | 
|  | 8093 | </para></listitem> | 
|  | 8094 | <listitem><para> | 
|  | 8095 | <emphasis><filename>GPG_PATH</filename>:</emphasis> | 
|  | 8096 | Specifies the <filename>gpg</filename> home | 
|  | 8097 | directory used when the package is signed. | 
|  | 8098 | </para></listitem> | 
|  | 8099 | <listitem><para> | 
|  | 8100 | <emphasis><filename>PACKAGE_FEED_GPG_SIGNATURE_TYPE</filename>:</emphasis> | 
|  | 8101 | Specifies the type of <filename>gpg</filename> | 
|  | 8102 | signature. | 
|  | 8103 | This variable applies only to RPM and IPK package | 
|  | 8104 | feeds. | 
|  | 8105 | Allowable values for the | 
|  | 8106 | <filename>PACKAGE_FEED_GPG_SIGNATURE_TYPE</filename> | 
|  | 8107 | are "ASC", which is the default and specifies ascii | 
|  | 8108 | armored, and "BIN", which specifies binary. | 
|  | 8109 | </para></listitem> | 
|  | 8110 | </itemizedlist> | 
|  | 8111 | </para> | 
|  | 8112 | </section> | 
|  | 8113 | </section> | 
|  | 8114 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 8115 | <section id='testing-packages-with-ptest'> | 
|  | 8116 | <title>Testing Packages With ptest</title> | 
|  | 8117 |  | 
|  | 8118 | <para> | 
|  | 8119 | A Package Test (ptest) runs tests against packages built | 
|  | 8120 | by the OpenEmbedded build system on the target machine. | 
|  | 8121 | A ptest contains at least two items: the actual test, and | 
|  | 8122 | a shell script (<filename>run-ptest</filename>) that starts | 
|  | 8123 | the test. | 
|  | 8124 | The shell script that starts the test must not contain | 
|  | 8125 | the actual test - the script only starts the test. | 
|  | 8126 | On the other hand, the test can be anything from a simple | 
|  | 8127 | shell script that runs a binary and checks the output to | 
|  | 8128 | an elaborate system of test binaries and data files. | 
|  | 8129 | </para> | 
|  | 8130 |  | 
|  | 8131 | <para> | 
|  | 8132 | The test generates output in the format used by | 
|  | 8133 | Automake: | 
|  | 8134 | <literallayout class='monospaced'> | 
|  | 8135 | <replaceable>result</replaceable>: <replaceable>testname</replaceable> | 
|  | 8136 | </literallayout> | 
|  | 8137 | where the result can be <filename>PASS</filename>, | 
|  | 8138 | <filename>FAIL</filename>, or <filename>SKIP</filename>, | 
|  | 8139 | and the testname can be any identifying string. | 
|  | 8140 | </para> | 
|  | 8141 |  | 
|  | 8142 | <para> | 
|  | 8143 | For a list of Yocto Project recipes that are already | 
|  | 8144 | enabled with ptest, see the | 
|  | 8145 | <ulink url='https://wiki.yoctoproject.org/wiki/Ptest'>Ptest</ulink> | 
|  | 8146 | wiki page. | 
|  | 8147 | <note> | 
|  | 8148 | A recipe is "ptest-enabled" if it inherits the | 
|  | 8149 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-ptest'><filename>ptest</filename></ulink> | 
|  | 8150 | class. | 
|  | 8151 | </note> | 
|  | 8152 | </para> | 
|  | 8153 |  | 
|  | 8154 | <section id='adding-ptest-to-your-build'> | 
|  | 8155 | <title>Adding ptest to Your Build</title> | 
|  | 8156 |  | 
|  | 8157 | <para> | 
|  | 8158 | To add package testing to your build, add the | 
|  | 8159 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink> | 
|  | 8160 | and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink> | 
|  | 8161 | variables to your <filename>local.conf</filename> file, | 
|  | 8162 | which is found in the | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 8163 | <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 8164 | <literallayout class='monospaced'> | 
|  | 8165 | DISTRO_FEATURES_append = " ptest" | 
|  | 8166 | EXTRA_IMAGE_FEATURES += "ptest-pkgs" | 
|  | 8167 | </literallayout> | 
|  | 8168 | Once your build is complete, the ptest files are installed | 
|  | 8169 | into the | 
|  | 8170 | <filename>/usr/lib/<replaceable>package</replaceable>/ptest</filename> | 
|  | 8171 | directory within the image, where | 
|  | 8172 | <filename><replaceable>package</replaceable></filename> | 
|  | 8173 | is the name of the package. | 
|  | 8174 | </para> | 
|  | 8175 | </section> | 
|  | 8176 |  | 
|  | 8177 | <section id='running-ptest'> | 
|  | 8178 | <title>Running ptest</title> | 
|  | 8179 |  | 
|  | 8180 | <para> | 
|  | 8181 | The <filename>ptest-runner</filename> package installs a | 
|  | 8182 | shell script that loops through all installed ptest test | 
|  | 8183 | suites and runs them in sequence. | 
|  | 8184 | Consequently, you might want to add this package to | 
|  | 8185 | your image. | 
|  | 8186 | </para> | 
|  | 8187 | </section> | 
|  | 8188 |  | 
|  | 8189 | <section id='getting-your-package-ready'> | 
|  | 8190 | <title>Getting Your Package Ready</title> | 
|  | 8191 |  | 
|  | 8192 | <para> | 
|  | 8193 | In order to enable a recipe to run installed ptests | 
|  | 8194 | on target hardware, | 
|  | 8195 | you need to prepare the recipes that build the packages | 
|  | 8196 | you want to test. | 
|  | 8197 | Here is what you have to do for each recipe: | 
|  | 8198 | <itemizedlist> | 
|  | 8199 | <listitem><para><emphasis>Be sure the recipe | 
|  | 8200 | inherits the | 
|  | 8201 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-ptest'><filename>ptest</filename></ulink> | 
|  | 8202 | class:</emphasis> | 
|  | 8203 | Include the following line in each recipe: | 
|  | 8204 | <literallayout class='monospaced'> | 
|  | 8205 | inherit ptest | 
|  | 8206 | </literallayout> | 
|  | 8207 | </para></listitem> | 
|  | 8208 | <listitem><para><emphasis>Create <filename>run-ptest</filename>:</emphasis> | 
|  | 8209 | This script starts your test. | 
|  | 8210 | Locate the script where you will refer to it | 
|  | 8211 | using | 
|  | 8212 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>. | 
|  | 8213 | Here is an example that starts a test for | 
|  | 8214 | <filename>dbus</filename>: | 
|  | 8215 | <literallayout class='monospaced'> | 
|  | 8216 | #!/bin/sh | 
|  | 8217 | cd test | 
|  | 8218 | make -k runtest-TESTS | 
|  | 8219 | </literallayout> | 
|  | 8220 | </para></listitem> | 
|  | 8221 | <listitem><para><emphasis>Ensure dependencies are | 
|  | 8222 | met:</emphasis> | 
|  | 8223 | If the test adds build or runtime dependencies | 
|  | 8224 | that normally do not exist for the package | 
|  | 8225 | (such as requiring "make" to run the test suite), | 
|  | 8226 | use the | 
|  | 8227 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DEPENDS'><filename>DEPENDS</filename></ulink> | 
|  | 8228 | and | 
|  | 8229 | <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink> | 
|  | 8230 | variables in your recipe in order for the package | 
|  | 8231 | to meet the dependencies. | 
|  | 8232 | Here is an example where the package has a runtime | 
|  | 8233 | dependency on "make": | 
|  | 8234 | <literallayout class='monospaced'> | 
|  | 8235 | RDEPENDS_${PN}-ptest += "make" | 
|  | 8236 | </literallayout> | 
|  | 8237 | </para></listitem> | 
|  | 8238 | <listitem><para><emphasis>Add a function to build the | 
|  | 8239 | test suite:</emphasis> | 
|  | 8240 | Not many packages support cross-compilation of | 
|  | 8241 | their test suites. | 
|  | 8242 | Consequently, you usually need to add a | 
|  | 8243 | cross-compilation function to the package. | 
|  | 8244 | </para> | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 8245 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 8246 | <para>Many packages based on Automake compile and | 
|  | 8247 | run the test suite by using a single command | 
|  | 8248 | such as <filename>make check</filename>. | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 8249 | However, the host <filename>make check</filename> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 8250 | builds and runs on the same computer, while | 
|  | 8251 | cross-compiling requires that the package is built | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 8252 | on the host but executed for the target | 
|  | 8253 | architecture (though often, as in the case for | 
|  | 8254 | ptest, the execution occurs on the host). | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 8255 | The built version of Automake that ships with the | 
|  | 8256 | Yocto Project includes a patch that separates | 
|  | 8257 | building and execution. | 
|  | 8258 | Consequently, packages that use the unaltered, | 
|  | 8259 | patched version of <filename>make check</filename> | 
|  | 8260 | automatically cross-compiles.</para> | 
|  | 8261 | <para>Regardless, you still must add a | 
|  | 8262 | <filename>do_compile_ptest</filename> function to | 
|  | 8263 | build the test suite. | 
|  | 8264 | Add a function similar to the following to your | 
|  | 8265 | recipe: | 
|  | 8266 | <literallayout class='monospaced'> | 
|  | 8267 | do_compile_ptest() { | 
|  | 8268 | oe_runmake buildtest-TESTS | 
|  | 8269 | } | 
|  | 8270 | </literallayout> | 
|  | 8271 | </para></listitem> | 
|  | 8272 | <listitem><para><emphasis>Ensure special configurations | 
|  | 8273 | are set:</emphasis> | 
|  | 8274 | If the package requires special configurations | 
|  | 8275 | prior to compiling the test code, you must | 
|  | 8276 | insert a <filename>do_configure_ptest</filename> | 
|  | 8277 | function into the recipe. | 
|  | 8278 | </para></listitem> | 
|  | 8279 | <listitem><para><emphasis>Install the test | 
|  | 8280 | suite:</emphasis> | 
|  | 8281 | The <filename>ptest</filename> class | 
|  | 8282 | automatically copies the file | 
|  | 8283 | <filename>run-ptest</filename> to the target and | 
|  | 8284 | then runs make <filename>install-ptest</filename> | 
|  | 8285 | to run the tests. | 
|  | 8286 | If this is not enough, you need to create a | 
|  | 8287 | <filename>do_install_ptest</filename> function and | 
|  | 8288 | make sure it gets called after the | 
|  | 8289 | "make install-ptest" completes. | 
|  | 8290 | </para></listitem> | 
|  | 8291 | </itemizedlist> | 
|  | 8292 | </para> | 
|  | 8293 | </section> | 
|  | 8294 | </section> | 
|  | 8295 | </section> | 
|  | 8296 |  | 
|  | 8297 | <section id='working-with-source-files'> | 
|  | 8298 | <title>Working with Source Files</title> | 
|  | 8299 |  | 
|  | 8300 | <para> | 
|  | 8301 | The OpenEmbedded build system works with source files located | 
|  | 8302 | through the | 
|  | 8303 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> | 
|  | 8304 | variable. | 
|  | 8305 | When you build something using BitBake, a big part of the operation | 
|  | 8306 | is locating and downloading all the source tarballs. | 
|  | 8307 | For images, downloading all the source for various packages can | 
|  | 8308 | take a significant amount of time. | 
|  | 8309 | </para> | 
|  | 8310 |  | 
|  | 8311 | <para> | 
|  | 8312 | This section presents information for working with source | 
|  | 8313 | files that can lead to more efficient use of resources and | 
|  | 8314 | time. | 
|  | 8315 | </para> | 
|  | 8316 |  | 
|  | 8317 | <section id='setting-up-effective-mirrors'> | 
|  | 8318 | <title>Setting up Effective Mirrors</title> | 
|  | 8319 |  | 
|  | 8320 | <para> | 
|  | 8321 | As mentioned, a good deal that goes into a Yocto Project | 
|  | 8322 | build is simply downloading all of the source tarballs. | 
|  | 8323 | Maybe you have been working with another build system | 
|  | 8324 | (OpenEmbedded or Angstrom) for which you have built up a | 
|  | 8325 | sizable directory of source tarballs. | 
|  | 8326 | Or, perhaps someone else has such a directory for which you | 
|  | 8327 | have read access. | 
|  | 8328 | If so, you can save time by adding statements to your | 
|  | 8329 | configuration file so that the build process checks local | 
|  | 8330 | directories first for existing tarballs before checking the | 
|  | 8331 | Internet. | 
|  | 8332 | </para> | 
|  | 8333 |  | 
|  | 8334 | <para> | 
|  | 8335 | Here is an efficient way to set it up in your | 
|  | 8336 | <filename>local.conf</filename> file: | 
|  | 8337 | <literallayout class='monospaced'> | 
|  | 8338 | SOURCE_MIRROR_URL ?= "file:///home/you/your-download-dir/" | 
|  | 8339 | INHERIT += "own-mirrors" | 
|  | 8340 | BB_GENERATE_MIRROR_TARBALLS = "1" | 
|  | 8341 | # BB_NO_NETWORK = "1" | 
|  | 8342 | </literallayout> | 
|  | 8343 | </para> | 
|  | 8344 |  | 
|  | 8345 | <para> | 
|  | 8346 | In the previous example, the | 
|  | 8347 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BB_GENERATE_MIRROR_TARBALLS'><filename>BB_GENERATE_MIRROR_TARBALLS</filename></ulink> | 
|  | 8348 | variable causes the OpenEmbedded build system to generate | 
|  | 8349 | tarballs of the Git repositories and store them in the | 
|  | 8350 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink> | 
|  | 8351 | directory. | 
|  | 8352 | Due to performance reasons, generating and storing these | 
|  | 8353 | tarballs is not the build system's default behavior. | 
|  | 8354 | </para> | 
|  | 8355 |  | 
|  | 8356 | <para> | 
|  | 8357 | You can also use the | 
|  | 8358 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PREMIRRORS'><filename>PREMIRRORS</filename></ulink> | 
|  | 8359 | variable. | 
|  | 8360 | For an example, see the variable's glossary entry in the | 
|  | 8361 | Yocto Project Reference Manual. | 
|  | 8362 | </para> | 
|  | 8363 | </section> | 
|  | 8364 |  | 
|  | 8365 | <section id='getting-source-files-and-suppressing-the-build'> | 
|  | 8366 | <title>Getting Source Files and Suppressing the Build</title> | 
|  | 8367 |  | 
|  | 8368 | <para> | 
|  | 8369 | Another technique you can use to ready yourself for a | 
|  | 8370 | successive string of build operations, is to pre-fetch | 
|  | 8371 | all the source files without actually starting a build. | 
|  | 8372 | This technique lets you work through any download issues | 
|  | 8373 | and ultimately gathers all the source files into your | 
|  | 8374 | download directory | 
|  | 8375 | <ulink url='&YOCTO_DOCS_REF_URL;#structure-build-downloads'><filename>build/downloads</filename></ulink>, | 
|  | 8376 | which is located with | 
|  | 8377 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink>. | 
|  | 8378 | </para> | 
|  | 8379 |  | 
|  | 8380 | <para> | 
|  | 8381 | Use the following BitBake command form to fetch all the | 
|  | 8382 | necessary sources without starting the build: | 
|  | 8383 | <literallayout class='monospaced'> | 
|  | 8384 | $ bitbake -c fetchall <replaceable>target</replaceable> | 
|  | 8385 | </literallayout> | 
|  | 8386 | This variation of the BitBake command guarantees that you | 
|  | 8387 | have all the sources for that BitBake target should you | 
|  | 8388 | disconnect from the Internet and want to do the build | 
|  | 8389 | later offline. | 
|  | 8390 | </para> | 
|  | 8391 | </section> | 
|  | 8392 | </section> | 
|  | 8393 |  | 
|  | 8394 | <section id="building-software-from-an-external-source"> | 
|  | 8395 | <title>Building Software from an External Source</title> | 
|  | 8396 |  | 
|  | 8397 | <para> | 
|  | 8398 | By default, the OpenEmbedded build system uses the | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 8399 | <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink> | 
|  | 8400 | when building source code. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 8401 | The build process involves fetching the source files, unpacking | 
|  | 8402 | them, and then patching them if necessary before the build takes | 
|  | 8403 | place. | 
|  | 8404 | </para> | 
|  | 8405 |  | 
|  | 8406 | <para> | 
|  | 8407 | Situations exist where you might want to build software from source | 
|  | 8408 | files that are external to and thus outside of the | 
|  | 8409 | OpenEmbedded build system. | 
|  | 8410 | For example, suppose you have a project that includes a new BSP with | 
|  | 8411 | a heavily customized kernel. | 
|  | 8412 | And, you want to minimize exposing the build system to the | 
|  | 8413 | development team so that they can focus on their project and | 
|  | 8414 | maintain everyone's workflow as much as possible. | 
|  | 8415 | In this case, you want a kernel source directory on the development | 
|  | 8416 | machine where the development occurs. | 
|  | 8417 | You want the recipe's | 
|  | 8418 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> | 
|  | 8419 | variable to point to the external directory and use it as is, not | 
|  | 8420 | copy it. | 
|  | 8421 | </para> | 
|  | 8422 |  | 
|  | 8423 | <para> | 
|  | 8424 | To build from software that comes from an external source, all you | 
|  | 8425 | need to do is inherit the | 
|  | 8426 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-externalsrc'><filename>externalsrc</filename></ulink> | 
|  | 8427 | class and then set the | 
|  | 8428 | <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC'><filename>EXTERNALSRC</filename></ulink> | 
|  | 8429 | variable to point to your external source code. | 
|  | 8430 | Here are the statements to put in your | 
|  | 8431 | <filename>local.conf</filename> file: | 
|  | 8432 | <literallayout class='monospaced'> | 
|  | 8433 | INHERIT += "externalsrc" | 
|  | 8434 | EXTERNALSRC_pn-<replaceable>myrecipe</replaceable> = "<replaceable>path-to-your-source-tree</replaceable>" | 
|  | 8435 | </literallayout> | 
|  | 8436 | </para> | 
|  | 8437 |  | 
|  | 8438 | <para> | 
|  | 8439 | This next example shows how to accomplish the same thing by setting | 
|  | 8440 | <filename>EXTERNALSRC</filename> in the recipe itself or in the | 
|  | 8441 | recipe's append file: | 
|  | 8442 | <literallayout class='monospaced'> | 
|  | 8443 | EXTERNALSRC = "<replaceable>path</replaceable>" | 
|  | 8444 | EXTERNALSRC_BUILD = "<replaceable>path</replaceable>" | 
|  | 8445 | </literallayout> | 
|  | 8446 | <note> | 
|  | 8447 | In order for these settings to take effect, you must globally | 
|  | 8448 | or locally inherit the | 
|  | 8449 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-externalsrc'><filename>externalsrc</filename></ulink> | 
|  | 8450 | class. | 
|  | 8451 | </note> | 
|  | 8452 | </para> | 
|  | 8453 |  | 
|  | 8454 | <para> | 
|  | 8455 | By default, <filename>externalsrc.bbclass</filename> builds | 
|  | 8456 | the source code in a directory separate from the external source | 
|  | 8457 | directory as specified by | 
|  | 8458 | <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC'><filename>EXTERNALSRC</filename></ulink>. | 
|  | 8459 | If you need to have the source built in the same directory in | 
|  | 8460 | which it resides, or some other nominated directory, you can set | 
|  | 8461 | <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTERNALSRC_BUILD'><filename>EXTERNALSRC_BUILD</filename></ulink> | 
|  | 8462 | to point to that directory: | 
|  | 8463 | <literallayout class='monospaced'> | 
|  | 8464 | EXTERNALSRC_BUILD_pn-<replaceable>myrecipe</replaceable> = "<replaceable>path-to-your-source-tree</replaceable>" | 
|  | 8465 | </literallayout> | 
|  | 8466 | </para> | 
|  | 8467 | </section> | 
|  | 8468 |  | 
|  | 8469 | <section id="selecting-an-initialization-manager"> | 
|  | 8470 | <title>Selecting an Initialization Manager</title> | 
|  | 8471 |  | 
|  | 8472 | <para> | 
|  | 8473 | By default, the Yocto Project uses SysVinit as the initialization | 
|  | 8474 | manager. | 
|  | 8475 | However, support also exists for systemd, | 
|  | 8476 | which is a full replacement for init with | 
|  | 8477 | parallel starting of services, reduced shell overhead and other | 
|  | 8478 | features that are used by many distributions. | 
|  | 8479 | </para> | 
|  | 8480 |  | 
|  | 8481 | <para> | 
|  | 8482 | If you want to use SysVinit, you do | 
|  | 8483 | not have to do anything. | 
|  | 8484 | But, if you want to use systemd, you must | 
|  | 8485 | take some steps as described in the following sections. | 
|  | 8486 | </para> | 
|  | 8487 |  | 
|  | 8488 | <section id='using-systemd-exclusively'> | 
|  | 8489 | <title>Using systemd Exclusively</title> | 
|  | 8490 |  | 
|  | 8491 | <para> | 
|  | 8492 | Set the these variables in your distribution configuration | 
|  | 8493 | file as follows: | 
|  | 8494 | <literallayout class='monospaced'> | 
|  | 8495 | DISTRO_FEATURES_append = " systemd" | 
|  | 8496 | VIRTUAL-RUNTIME_init_manager = "systemd" | 
|  | 8497 | </literallayout> | 
|  | 8498 | You can also prevent the SysVinit | 
|  | 8499 | distribution feature from | 
|  | 8500 | being automatically enabled as follows: | 
|  | 8501 | <literallayout class='monospaced'> | 
|  | 8502 | DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit" | 
|  | 8503 | </literallayout> | 
|  | 8504 | Doing so removes any redundant SysVinit scripts. | 
|  | 8505 | </para> | 
|  | 8506 |  | 
|  | 8507 | <para> | 
|  | 8508 | To remove  initscripts from your image altogether, | 
|  | 8509 | set this variable also: | 
|  | 8510 | <literallayout class='monospaced'> | 
|  | 8511 | VIRTUAL-RUNTIME_initscripts = "" | 
|  | 8512 | </literallayout> | 
|  | 8513 | </para> | 
|  | 8514 |  | 
|  | 8515 | <para> | 
|  | 8516 | For information on the backfill variable, see | 
|  | 8517 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES_BACKFILL_CONSIDERED'><filename>DISTRO_FEATURES_BACKFILL_CONSIDERED</filename></ulink>. | 
|  | 8518 | </para> | 
|  | 8519 | </section> | 
|  | 8520 |  | 
|  | 8521 | <section id='using-systemd-for-the-main-image-and-using-sysvinit-for-the-rescue-image'> | 
|  | 8522 | <title>Using systemd for the Main Image and Using SysVinit for the Rescue Image</title> | 
|  | 8523 |  | 
|  | 8524 | <para> | 
|  | 8525 | Set these variables in your distribution configuration | 
|  | 8526 | file as follows: | 
|  | 8527 | <literallayout class='monospaced'> | 
|  | 8528 | DISTRO_FEATURES_append = " systemd" | 
|  | 8529 | VIRTUAL-RUNTIME_init_manager = "systemd" | 
|  | 8530 | </literallayout> | 
|  | 8531 | Doing so causes your main image to use the | 
|  | 8532 | <filename>packagegroup-core-boot.bb</filename> recipe and | 
|  | 8533 | systemd. | 
|  | 8534 | The rescue/minimal image cannot use this package group. | 
|  | 8535 | However, it can install SysVinit | 
|  | 8536 | and the appropriate packages will have support for both | 
|  | 8537 | systemd and SysVinit. | 
|  | 8538 | </para> | 
|  | 8539 | </section> | 
|  | 8540 | </section> | 
|  | 8541 |  | 
|  | 8542 | <section id="selecting-dev-manager"> | 
|  | 8543 | <title>Selecting a Device Manager</title> | 
|  | 8544 |  | 
|  | 8545 | <para> | 
|  | 8546 | The Yocto Project provides multiple ways to manage the device | 
|  | 8547 | manager (<filename>/dev</filename>): | 
|  | 8548 | <itemizedlist> | 
|  | 8549 | <listitem><para><emphasis>Persistent and Pre-Populated<filename>/dev</filename>:</emphasis> | 
|  | 8550 | For this case, the <filename>/dev</filename> directory | 
|  | 8551 | is persistent and the required device nodes are created | 
|  | 8552 | during the build. | 
|  | 8553 | </para></listitem> | 
|  | 8554 | <listitem><para><emphasis>Use <filename>devtmpfs</filename> with a Device Manager:</emphasis> | 
|  | 8555 | For this case, the <filename>/dev</filename> directory | 
|  | 8556 | is provided by the kernel as an in-memory file system and | 
|  | 8557 | is automatically populated by the kernel at runtime. | 
|  | 8558 | Additional configuration of device nodes is done in user | 
|  | 8559 | space by a device manager like | 
|  | 8560 | <filename>udev</filename> or | 
|  | 8561 | <filename>busybox-mdev</filename>. | 
|  | 8562 | </para></listitem> | 
|  | 8563 | </itemizedlist> | 
|  | 8564 | </para> | 
|  | 8565 |  | 
|  | 8566 | <section id="static-dev-management"> | 
|  | 8567 | <title>Using Persistent and Pre-Populated<filename>/dev</filename></title> | 
|  | 8568 |  | 
|  | 8569 | <para> | 
|  | 8570 | To use the static method for device population, you need to | 
|  | 8571 | set the | 
|  | 8572 | <ulink url='&YOCTO_DOCS_REF_URL;#var-USE_DEVFS'><filename>USE_DEVFS</filename></ulink> | 
|  | 8573 | variable to "0" as follows: | 
|  | 8574 | <literallayout class='monospaced'> | 
|  | 8575 | USE_DEVFS = "0" | 
|  | 8576 | </literallayout> | 
|  | 8577 | </para> | 
|  | 8578 |  | 
|  | 8579 | <para> | 
|  | 8580 | The content of the resulting <filename>/dev</filename> | 
|  | 8581 | directory is defined in a Device Table file. | 
|  | 8582 | The | 
|  | 8583 | <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_DEVICE_TABLES'><filename>IMAGE_DEVICE_TABLES</filename></ulink> | 
|  | 8584 | variable defines the Device Table to use and should be set | 
|  | 8585 | in the machine or distro configuration file. | 
|  | 8586 | Alternatively, you can set this variable in your | 
|  | 8587 | <filename>local.conf</filename> configuration file. | 
|  | 8588 | </para> | 
|  | 8589 |  | 
|  | 8590 | <para> | 
|  | 8591 | If you do not define the | 
|  | 8592 | <filename>IMAGE_DEVICE_TABLES</filename> variable, the default | 
|  | 8593 | <filename>device_table-minimal.txt</filename> is used: | 
|  | 8594 | <literallayout class='monospaced'> | 
|  | 8595 | IMAGE_DEVICE_TABLES = "device_table-mymachine.txt" | 
|  | 8596 | </literallayout> | 
|  | 8597 | </para> | 
|  | 8598 |  | 
|  | 8599 | <para> | 
|  | 8600 | The population is handled by the <filename>makedevs</filename> | 
|  | 8601 | utility during image creation: | 
|  | 8602 | </para> | 
|  | 8603 | </section> | 
|  | 8604 |  | 
|  | 8605 | <section id="devtmpfs-dev-management"> | 
|  | 8606 | <title>Using <filename>devtmpfs</filename> and a Device Manager</title> | 
|  | 8607 |  | 
|  | 8608 | <para> | 
|  | 8609 | To use the dynamic method for device population, you need to | 
|  | 8610 | use (or be sure to set) the | 
|  | 8611 | <ulink url='&YOCTO_DOCS_REF_URL;#var-USE_DEVFS'><filename>USE_DEVFS</filename></ulink> | 
|  | 8612 | variable to "1", which is the default: | 
|  | 8613 | <literallayout class='monospaced'> | 
|  | 8614 | USE_DEVFS = "1" | 
|  | 8615 | </literallayout> | 
|  | 8616 | With this setting, the resulting <filename>/dev</filename> | 
|  | 8617 | directory is populated by the kernel using | 
|  | 8618 | <filename>devtmpfs</filename>. | 
|  | 8619 | Make sure the corresponding kernel configuration variable | 
|  | 8620 | <filename>CONFIG_DEVTMPFS</filename> is set when building | 
|  | 8621 | you build a Linux kernel. | 
|  | 8622 | </para> | 
|  | 8623 |  | 
|  | 8624 | <para> | 
|  | 8625 | All devices created by <filename>devtmpfs</filename> will be | 
|  | 8626 | owned by <filename>root</filename> and have permissions | 
|  | 8627 | <filename>0600</filename>. | 
|  | 8628 | </para> | 
|  | 8629 |  | 
|  | 8630 | <para> | 
|  | 8631 | To have more control over the device nodes, you can use a | 
|  | 8632 | device manager like <filename>udev</filename> or | 
|  | 8633 | <filename>busybox-mdev</filename>. | 
|  | 8634 | You choose the device manager by defining the | 
|  | 8635 | <filename>VIRTUAL-RUNTIME_dev_manager</filename> variable | 
|  | 8636 | in your machine or distro configuration file. | 
|  | 8637 | Alternatively, you can set this variable in your | 
|  | 8638 | <filename>local.conf</filename> configuration file: | 
|  | 8639 | <literallayout class='monospaced'> | 
|  | 8640 | VIRTUAL-RUNTIME_dev_manager = "udev" | 
|  | 8641 |  | 
|  | 8642 | # Some alternative values | 
|  | 8643 | # VIRTUAL-RUNTIME_dev_manager = "busybox-mdev" | 
|  | 8644 | # VIRTUAL-RUNTIME_dev_manager = "systemd" | 
|  | 8645 | </literallayout> | 
|  | 8646 | </para> | 
|  | 8647 | </section> | 
|  | 8648 | </section> | 
|  | 8649 |  | 
|  | 8650 | <section id="platdev-appdev-srcrev"> | 
|  | 8651 | <title>Using an External SCM</title> | 
|  | 8652 |  | 
|  | 8653 | <para> | 
|  | 8654 | If you're working on a recipe that pulls from an external Source | 
|  | 8655 | Code Manager (SCM), it is possible to have the OpenEmbedded build | 
|  | 8656 | system notice new recipe changes added to the SCM and then build | 
|  | 8657 | the resulting packages that depend on the new recipes by using | 
|  | 8658 | the latest versions. | 
|  | 8659 | This only works for SCMs from which it is possible to get a | 
|  | 8660 | sensible revision number for changes. | 
|  | 8661 | Currently, you can do this with Apache Subversion (SVN), Git, and | 
|  | 8662 | Bazaar (BZR) repositories. | 
|  | 8663 | </para> | 
|  | 8664 |  | 
|  | 8665 | <para> | 
|  | 8666 | To enable this behavior, the | 
|  | 8667 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink> | 
|  | 8668 | of the recipe needs to reference | 
|  | 8669 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink>. | 
|  | 8670 | Here is an example: | 
|  | 8671 | <literallayout class='monospaced'> | 
|  | 8672 | PV = "1.2.3+git${SRCPV}" | 
|  | 8673 | </literallayout> | 
|  | 8674 | Then, you can add the following to your | 
|  | 8675 | <filename>local.conf</filename>: | 
|  | 8676 | <literallayout class='monospaced'> | 
|  | 8677 | SRCREV_pn-<replaceable>PN</replaceable> = "${AUTOREV}" | 
|  | 8678 | </literallayout> | 
|  | 8679 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PN'><filename>PN</filename></ulink> | 
|  | 8680 | is the name of the recipe for which you want to enable automatic source | 
|  | 8681 | revision updating. | 
|  | 8682 | </para> | 
|  | 8683 |  | 
|  | 8684 | <para> | 
|  | 8685 | If you do not want to update your local configuration file, you can | 
|  | 8686 | add the following directly to the recipe to finish enabling | 
|  | 8687 | the feature: | 
|  | 8688 | <literallayout class='monospaced'> | 
|  | 8689 | SRCREV = "${AUTOREV}" | 
|  | 8690 | </literallayout> | 
|  | 8691 | </para> | 
|  | 8692 |  | 
|  | 8693 | <para> | 
|  | 8694 | The Yocto Project provides a distribution named | 
|  | 8695 | <filename>poky-bleeding</filename>, whose configuration | 
|  | 8696 | file contains the line: | 
|  | 8697 | <literallayout class='monospaced'> | 
|  | 8698 | require conf/distro/include/poky-floating-revisions.inc | 
|  | 8699 | </literallayout> | 
|  | 8700 | This line pulls in the listed include file that contains | 
|  | 8701 | numerous lines of exactly that form: | 
|  | 8702 | <literallayout class='monospaced'> | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 8703 | #SRCREV_pn-opkg-native ?= "${AUTOREV}" | 
|  | 8704 | #SRCREV_pn-opkg-sdk ?= "${AUTOREV}" | 
|  | 8705 | #SRCREV_pn-opkg ?= "${AUTOREV}" | 
|  | 8706 | #SRCREV_pn-opkg-utils-native ?= "${AUTOREV}" | 
|  | 8707 | #SRCREV_pn-opkg-utils ?= "${AUTOREV}" | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 8708 | SRCREV_pn-gconf-dbus ?= "${AUTOREV}" | 
|  | 8709 | SRCREV_pn-matchbox-common ?= "${AUTOREV}" | 
|  | 8710 | SRCREV_pn-matchbox-config-gtk ?= "${AUTOREV}" | 
|  | 8711 | SRCREV_pn-matchbox-desktop ?= "${AUTOREV}" | 
|  | 8712 | SRCREV_pn-matchbox-keyboard ?= "${AUTOREV}" | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 8713 | SRCREV_pn-matchbox-panel-2 ?= "${AUTOREV}" | 
|  | 8714 | SRCREV_pn-matchbox-themes-extra ?= "${AUTOREV}" | 
|  | 8715 | SRCREV_pn-matchbox-terminal ?= "${AUTOREV}" | 
|  | 8716 | SRCREV_pn-matchbox-wm ?= "${AUTOREV}" | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 8717 | SRCREV_pn-settings-daemon ?= "${AUTOREV}" | 
|  | 8718 | SRCREV_pn-screenshot ?= "${AUTOREV}" | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 8719 | . | 
|  | 8720 | . | 
|  | 8721 | . | 
|  | 8722 | </literallayout> | 
|  | 8723 | These lines allow you to experiment with building a | 
|  | 8724 | distribution that tracks the latest development source | 
|  | 8725 | for numerous packages. | 
|  | 8726 | <note><title>Caution</title> | 
|  | 8727 | The <filename>poky-bleeding</filename> distribution | 
|  | 8728 | is not tested on a regular basis. | 
|  | 8729 | Keep this in mind if you use it. | 
|  | 8730 | </note> | 
|  | 8731 | </para> | 
|  | 8732 | </section> | 
|  | 8733 |  | 
|  | 8734 | <section id='creating-a-read-only-root-filesystem'> | 
|  | 8735 | <title>Creating a Read-Only Root Filesystem</title> | 
|  | 8736 |  | 
|  | 8737 | <para> | 
|  | 8738 | Suppose, for security reasons, you need to disable | 
|  | 8739 | your target device's root filesystem's write permissions | 
|  | 8740 | (i.e. you need a read-only root filesystem). | 
|  | 8741 | Or, perhaps you are running the device's operating system | 
|  | 8742 | from a read-only storage device. | 
|  | 8743 | For either case, you can customize your image for | 
|  | 8744 | that behavior. | 
|  | 8745 | </para> | 
|  | 8746 |  | 
|  | 8747 | <note> | 
|  | 8748 | Supporting a read-only root filesystem requires that the system and | 
|  | 8749 | applications do not try to write to the root filesystem. | 
|  | 8750 | You must configure all parts of the target system to write | 
|  | 8751 | elsewhere, or to gracefully fail in the event of attempting to | 
|  | 8752 | write to the root filesystem. | 
|  | 8753 | </note> | 
|  | 8754 |  | 
|  | 8755 | <section id='creating-the-root-filesystem'> | 
|  | 8756 | <title>Creating the Root Filesystem</title> | 
|  | 8757 |  | 
|  | 8758 | <para> | 
|  | 8759 | To create the read-only root filesystem, simply add the | 
|  | 8760 | "read-only-rootfs" feature to your image. | 
|  | 8761 | Using either of the following statements in your | 
|  | 8762 | image recipe or from within the | 
|  | 8763 | <filename>local.conf</filename> file found in the | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 8764 | <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 8765 | causes the build system to create a read-only root filesystem: | 
|  | 8766 | <literallayout class='monospaced'> | 
|  | 8767 | IMAGE_FEATURES = "read-only-rootfs" | 
|  | 8768 | </literallayout> | 
|  | 8769 | or | 
|  | 8770 | <literallayout class='monospaced'> | 
|  | 8771 | EXTRA_IMAGE_FEATURES += "read-only-rootfs" | 
|  | 8772 | </literallayout> | 
|  | 8773 | </para> | 
|  | 8774 |  | 
|  | 8775 | <para> | 
|  | 8776 | For more information on how to use these variables, see the | 
|  | 8777 | "<link linkend='usingpoky-extend-customimage-imagefeatures'>Customizing Images Using Custom <filename>IMAGE_FEATURES</filename> and <filename>EXTRA_IMAGE_FEATURES</filename></link>" | 
|  | 8778 | section. | 
|  | 8779 | For information on the variables, see | 
|  | 8780 | <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink> | 
|  | 8781 | and <ulink url='&YOCTO_DOCS_REF_URL;#var-EXTRA_IMAGE_FEATURES'><filename>EXTRA_IMAGE_FEATURES</filename></ulink>. | 
|  | 8782 | </para> | 
|  | 8783 | </section> | 
|  | 8784 |  | 
|  | 8785 | <section id='post-installation-scripts'> | 
|  | 8786 | <title>Post-Installation Scripts</title> | 
|  | 8787 |  | 
|  | 8788 | <para> | 
|  | 8789 | It is very important that you make sure all | 
|  | 8790 | post-Installation (<filename>pkg_postinst</filename>) scripts | 
|  | 8791 | for packages that are installed into the image can be run | 
|  | 8792 | at the time when the root filesystem is created during the | 
|  | 8793 | build on the host system. | 
|  | 8794 | These scripts cannot attempt to run during first-boot on the | 
|  | 8795 | target device. | 
|  | 8796 | With the "read-only-rootfs" feature enabled, | 
|  | 8797 | the build system checks during root filesystem creation to make | 
|  | 8798 | sure all post-installation scripts succeed. | 
|  | 8799 | If any of these scripts still need to be run after the root | 
|  | 8800 | filesystem is created, the build immediately fails. | 
|  | 8801 | These build-time checks ensure that the build fails | 
|  | 8802 | rather than the target device fails later during its | 
|  | 8803 | initial boot operation. | 
|  | 8804 | </para> | 
|  | 8805 |  | 
|  | 8806 | <para> | 
|  | 8807 | Most of the common post-installation scripts generated by the | 
|  | 8808 | build system for the out-of-the-box Yocto Project are engineered | 
|  | 8809 | so that they can run during root filesystem creation | 
|  | 8810 | (e.g. post-installation scripts for caching fonts). | 
|  | 8811 | However, if you create and add custom scripts, you need | 
|  | 8812 | to be sure they can be run during this file system creation. | 
|  | 8813 | </para> | 
|  | 8814 |  | 
|  | 8815 | <para> | 
|  | 8816 | Here are some common problems that prevent | 
|  | 8817 | post-installation scripts from running during root filesystem | 
|  | 8818 | creation: | 
|  | 8819 | <itemizedlist> | 
|  | 8820 | <listitem><para> | 
|  | 8821 | <emphasis>Not using $D in front of absolute | 
|  | 8822 | paths:</emphasis> | 
|  | 8823 | The build system defines | 
|  | 8824 | <filename>$</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-D'><filename>D</filename></ulink> | 
|  | 8825 | when the root filesystem is created. | 
|  | 8826 | Furthermore, <filename>$D</filename> is blank when the | 
|  | 8827 | script is run on the target device. | 
|  | 8828 | This implies two purposes for <filename>$D</filename>: | 
|  | 8829 | ensuring paths are valid in both the host and target | 
|  | 8830 | environments, and checking to determine which | 
|  | 8831 | environment is being used as a method for taking | 
|  | 8832 | appropriate actions. | 
|  | 8833 | </para></listitem> | 
|  | 8834 | <listitem><para> | 
|  | 8835 | <emphasis>Attempting to run processes that are | 
|  | 8836 | specific to or dependent on the target | 
|  | 8837 | architecture:</emphasis> | 
|  | 8838 | You can work around these attempts by using native | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 8839 | tools, which run on the host system, | 
|  | 8840 | to accomplish the same tasks, or | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 8841 | by alternatively running the processes under QEMU, | 
|  | 8842 | which has the <filename>qemu_run_binary</filename> | 
|  | 8843 | function. | 
|  | 8844 | For more information, see the | 
|  | 8845 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-qemu'><filename>qemu</filename></ulink> | 
|  | 8846 | class.</para></listitem> | 
|  | 8847 | </itemizedlist> | 
|  | 8848 | </para> | 
|  | 8849 | </section> | 
|  | 8850 |  | 
|  | 8851 | <section id='areas-with-write-access'> | 
|  | 8852 | <title>Areas With Write Access</title> | 
|  | 8853 |  | 
|  | 8854 | <para> | 
|  | 8855 | With the "read-only-rootfs" feature enabled, | 
|  | 8856 | any attempt by the target to write to the root filesystem at | 
|  | 8857 | runtime fails. | 
|  | 8858 | Consequently, you must make sure that you configure processes | 
|  | 8859 | and applications that attempt these types of writes do so | 
|  | 8860 | to directories with write access (e.g. | 
|  | 8861 | <filename>/tmp</filename> or <filename>/var/run</filename>). | 
|  | 8862 | </para> | 
|  | 8863 | </section> | 
|  | 8864 | </section> | 
|  | 8865 |  | 
|  | 8866 | <section id="performing-automated-runtime-testing"> | 
|  | 8867 | <title>Performing Automated Runtime Testing</title> | 
|  | 8868 |  | 
|  | 8869 | <para> | 
|  | 8870 | The OpenEmbedded build system makes available a series of automated | 
|  | 8871 | tests for images to verify runtime functionality. | 
|  | 8872 | You can run these tests on either QEMU or actual target hardware. | 
|  | 8873 | Tests are written in Python making use of the | 
|  | 8874 | <filename>unittest</filename> module, and the majority of them | 
|  | 8875 | run commands on the target system over SSH. | 
|  | 8876 | This section describes how you set up the environment to use these | 
|  | 8877 | tests, run available tests, and write and add your own tests. | 
|  | 8878 | </para> | 
|  | 8879 |  | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 8880 | <para> | 
|  | 8881 | For information on the test and QA infrastructure available | 
|  | 8882 | within the Yocto Project, see the | 
|  | 8883 | "<ulink url='&YOCTO_DOCS_REF_URL;#testing-and-quality-assurance'>Testing and Quality Assurance</ulink>" | 
|  | 8884 | section in the Yocto Project Reference Manual. | 
|  | 8885 | </para> | 
|  | 8886 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 8887 | <section id='enabling-tests'> | 
|  | 8888 | <title>Enabling Tests</title> | 
|  | 8889 |  | 
|  | 8890 | <para> | 
|  | 8891 | Depending on whether you are planning to run tests using | 
|  | 8892 | QEMU or on the hardware, you have to take | 
|  | 8893 | different steps to enable the tests. | 
|  | 8894 | See the following subsections for information on how to | 
|  | 8895 | enable both types of tests. | 
|  | 8896 | </para> | 
|  | 8897 |  | 
|  | 8898 | <section id='qemu-image-enabling-tests'> | 
|  | 8899 | <title>Enabling Runtime Tests on QEMU</title> | 
|  | 8900 |  | 
|  | 8901 | <para> | 
|  | 8902 | In order to run tests, you need to do the following: | 
|  | 8903 | <itemizedlist> | 
|  | 8904 | <listitem><para><emphasis>Set up to avoid interaction | 
|  | 8905 | with <filename>sudo</filename> for networking:</emphasis> | 
|  | 8906 | To accomplish this, you must do one of the | 
|  | 8907 | following: | 
|  | 8908 | <itemizedlist> | 
|  | 8909 | <listitem><para>Add | 
|  | 8910 | <filename>NOPASSWD</filename> for your user | 
|  | 8911 | in <filename>/etc/sudoers</filename> either for | 
|  | 8912 | all commands or just for | 
|  | 8913 | <filename>runqemu-ifup</filename>. | 
|  | 8914 | You must provide the full path as that can | 
|  | 8915 | change if you are using multiple clones of the | 
|  | 8916 | source repository. | 
|  | 8917 | <note> | 
|  | 8918 | On some distributions, you also need to | 
|  | 8919 | comment out "Defaults requiretty" in | 
|  | 8920 | <filename>/etc/sudoers</filename>. | 
|  | 8921 | </note></para></listitem> | 
|  | 8922 | <listitem><para>Manually configure a tap interface | 
|  | 8923 | for your system.</para></listitem> | 
|  | 8924 | <listitem><para>Run as root the script in | 
|  | 8925 | <filename>scripts/runqemu-gen-tapdevs</filename>, | 
|  | 8926 | which should generate a list of tap devices. | 
|  | 8927 | This is the option typically chosen for | 
|  | 8928 | Autobuilder-type environments. | 
|  | 8929 | </para></listitem> | 
|  | 8930 | </itemizedlist></para></listitem> | 
|  | 8931 | <listitem><para><emphasis>Set the | 
|  | 8932 | <filename>DISPLAY</filename> variable:</emphasis> | 
|  | 8933 | You need to set this variable so that you have an X | 
|  | 8934 | server available (e.g. start | 
|  | 8935 | <filename>vncserver</filename> for a headless machine). | 
|  | 8936 | </para></listitem> | 
|  | 8937 | <listitem><para><emphasis>Be sure your host's firewall | 
|  | 8938 | accepts incoming connections from | 
|  | 8939 | 192.168.7.0/24:</emphasis> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 8940 | Some of the tests (in particular DNF tests) start | 
|  | 8941 | an HTTP server on a random high number port, | 
|  | 8942 | which is used to serve files to the target. | 
|  | 8943 | The DNF module serves | 
|  | 8944 | <filename>${WORKDIR}/oe-rootfs-repo</filename> | 
|  | 8945 | so it can run DNF channel commands. | 
|  | 8946 | That means your host's firewall | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 8947 | must accept incoming connections from 192.168.7.0/24, | 
|  | 8948 | which is the default IP range used for tap devices | 
|  | 8949 | by <filename>runqemu</filename>.</para></listitem> | 
| Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 8950 | <listitem><para><emphasis>Be sure your host has the | 
|  | 8951 | correct packages installed:</emphasis> | 
|  | 8952 | Depending your host's distribution, you need | 
|  | 8953 | to have the following packages installed: | 
|  | 8954 | <itemizedlist> | 
|  | 8955 | <listitem><para>Ubuntu and Debian: | 
|  | 8956 | <filename>sysstat</filename> and | 
|  | 8957 | <filename>iproute2</filename> | 
|  | 8958 | </para></listitem> | 
|  | 8959 | <listitem><para>OpenSUSE: | 
|  | 8960 | <filename>sysstat</filename> and | 
|  | 8961 | <filename>iproute2</filename> | 
|  | 8962 | </para></listitem> | 
|  | 8963 | <listitem><para>Fedora: | 
|  | 8964 | <filename>sysstat</filename> and | 
|  | 8965 | <filename>iproute</filename> | 
|  | 8966 | </para></listitem> | 
|  | 8967 | <listitem><para>CentOS: | 
|  | 8968 | <filename>sysstat</filename> and | 
|  | 8969 | <filename>iproute</filename> | 
|  | 8970 | </para></listitem> | 
|  | 8971 | </itemizedlist> | 
|  | 8972 | </para></listitem> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 8973 | </itemizedlist> | 
|  | 8974 | </para> | 
|  | 8975 |  | 
|  | 8976 | <para> | 
|  | 8977 | Once you start running the tests, the following happens: | 
|  | 8978 | <orderedlist> | 
|  | 8979 | <listitem><para>A copy of the root filesystem is written | 
|  | 8980 | to <filename>${WORKDIR}/testimage</filename>. | 
|  | 8981 | </para></listitem> | 
|  | 8982 | <listitem><para>The image is booted under QEMU using the | 
|  | 8983 | standard <filename>runqemu</filename> script. | 
|  | 8984 | </para></listitem> | 
|  | 8985 | <listitem><para>A default timeout of 500 seconds occurs | 
|  | 8986 | to allow for the boot process to reach the login prompt. | 
|  | 8987 | You can change the timeout period by setting | 
|  | 8988 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_QEMUBOOT_TIMEOUT'><filename>TEST_QEMUBOOT_TIMEOUT</filename></ulink> | 
|  | 8989 | in the <filename>local.conf</filename> file. | 
|  | 8990 | </para></listitem> | 
|  | 8991 | <listitem><para>Once the boot process is reached and the | 
|  | 8992 | login prompt appears, the tests run. | 
|  | 8993 | The full boot log is written to | 
|  | 8994 | <filename>${WORKDIR}/testimage/qemu_boot_log</filename>. | 
|  | 8995 | </para></listitem> | 
|  | 8996 | <listitem><para>Each test module loads in the order found | 
|  | 8997 | in <filename>TEST_SUITES</filename>. | 
|  | 8998 | You can find the full output of the commands run over | 
|  | 8999 | SSH in | 
|  | 9000 | <filename>${WORKDIR}/testimgage/ssh_target_log</filename>. | 
|  | 9001 | </para></listitem> | 
|  | 9002 | <listitem><para>If no failures occur, the task running the | 
|  | 9003 | tests ends successfully. | 
|  | 9004 | You can find the output from the | 
|  | 9005 | <filename>unittest</filename> in the task log at | 
|  | 9006 | <filename>${WORKDIR}/temp/log.do_testimage</filename>. | 
|  | 9007 | </para></listitem> | 
|  | 9008 | </orderedlist> | 
|  | 9009 | </para> | 
|  | 9010 | </section> | 
|  | 9011 |  | 
|  | 9012 | <section id='hardware-image-enabling-tests'> | 
|  | 9013 | <title>Enabling Runtime Tests on Hardware</title> | 
|  | 9014 |  | 
|  | 9015 | <para> | 
|  | 9016 | The OpenEmbedded build system can run tests on real | 
|  | 9017 | hardware, and for certain devices it can also deploy | 
|  | 9018 | the image to be tested onto the device beforehand. | 
|  | 9019 | </para> | 
|  | 9020 |  | 
|  | 9021 | <para> | 
|  | 9022 | For automated deployment, a "master image" is installed | 
|  | 9023 | onto the hardware once as part of setup. | 
|  | 9024 | Then, each time tests are to be run, the following | 
|  | 9025 | occurs: | 
|  | 9026 | <orderedlist> | 
|  | 9027 | <listitem><para>The master image is booted into and | 
|  | 9028 | used to write the image to be tested to | 
|  | 9029 | a second partition. | 
|  | 9030 | </para></listitem> | 
|  | 9031 | <listitem><para>The device is then rebooted using an | 
|  | 9032 | external script that you need to provide. | 
|  | 9033 | </para></listitem> | 
|  | 9034 | <listitem><para>The device boots into the image to be | 
|  | 9035 | tested. | 
|  | 9036 | </para></listitem> | 
|  | 9037 | </orderedlist> | 
|  | 9038 | </para> | 
|  | 9039 |  | 
|  | 9040 | <para> | 
|  | 9041 | When running tests (independent of whether the image | 
|  | 9042 | has been deployed automatically or not), the device is | 
|  | 9043 | expected to be connected to a network on a | 
|  | 9044 | pre-determined IP address. | 
|  | 9045 | You can either use static IP addresses written into | 
|  | 9046 | the image, or set the image to use DHCP and have your | 
|  | 9047 | DHCP server on the test network assign a known IP address | 
|  | 9048 | based on the MAC address of the device. | 
|  | 9049 | </para> | 
|  | 9050 |  | 
|  | 9051 | <para> | 
|  | 9052 | In order to run tests on hardware, you need to set | 
|  | 9053 | <filename>TEST_TARGET</filename> to an appropriate value. | 
|  | 9054 | For QEMU, you do not have to change anything, the default | 
|  | 9055 | value is "QemuTarget". | 
|  | 9056 | For running tests on hardware, the following options exist: | 
|  | 9057 | <itemizedlist> | 
|  | 9058 | <listitem><para><emphasis>"SimpleRemoteTarget":</emphasis> | 
|  | 9059 | Choose "SimpleRemoteTarget" if you are going to | 
|  | 9060 | run tests on a target system that is already | 
|  | 9061 | running the image to be tested and is available | 
|  | 9062 | on the network. | 
|  | 9063 | You can use "SimpleRemoteTarget" in conjunction | 
|  | 9064 | with either real hardware or an image running | 
|  | 9065 | within a separately started QEMU or any | 
|  | 9066 | other virtual machine manager. | 
|  | 9067 | </para></listitem> | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 9068 | <listitem><para><emphasis>"Systemd-bootTarget":</emphasis> | 
|  | 9069 | Choose "Systemd-bootTarget" if your hardware is | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9070 | an EFI-based machine with | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 9071 | <filename>systemd-boot</filename> as bootloader and | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9072 | <filename>core-image-testmaster</filename> | 
|  | 9073 | (or something similar) is installed. | 
|  | 9074 | Also, your hardware under test must be in a | 
|  | 9075 | DHCP-enabled network that gives it the same IP | 
|  | 9076 | address for each reboot.</para> | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 9077 | <para>If you choose "Systemd-bootTarget", there are | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9078 | additional requirements and considerations. | 
|  | 9079 | See the | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 9080 | "<link linkend='selecting-systemd-boottarget'>Selecting Systemd-bootTarget</link>" | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9081 | section, which follows, for more information. | 
|  | 9082 | </para></listitem> | 
|  | 9083 | <listitem><para><emphasis>"BeagleBoneTarget":</emphasis> | 
|  | 9084 | Choose "BeagleBoneTarget" if you are deploying | 
|  | 9085 | images and running tests on the BeagleBone | 
|  | 9086 | "Black" or original "White" hardware. | 
|  | 9087 | For information on how to use these tests, see the | 
|  | 9088 | comments at the top of the BeagleBoneTarget | 
|  | 9089 | <filename>meta-yocto-bsp/lib/oeqa/controllers/beaglebonetarget.py</filename> | 
|  | 9090 | file. | 
|  | 9091 | </para></listitem> | 
|  | 9092 | <listitem><para><emphasis>"EdgeRouterTarget":</emphasis> | 
|  | 9093 | Choose "EdgeRouterTarget" is you are deploying | 
|  | 9094 | images and running tests on the Ubiquiti Networks | 
|  | 9095 | EdgeRouter Lite. | 
|  | 9096 | For information on how to use these tests, see the | 
|  | 9097 | comments at the top of the EdgeRouterTarget | 
|  | 9098 | <filename>meta-yocto-bsp/lib/oeqa/controllers/edgeroutertarget.py</filename> | 
|  | 9099 | file. | 
|  | 9100 | </para></listitem> | 
|  | 9101 | <listitem><para><emphasis>"GrubTarget":</emphasis> | 
|  | 9102 | Choose the "supports deploying images and running | 
|  | 9103 | tests on any generic PC that boots using GRUB. | 
|  | 9104 | For information on how to use these tests, see the | 
|  | 9105 | comments at the top of the GrubTarget | 
|  | 9106 | <filename>meta-yocto-bsp/lib/oeqa/controllers/grubtarget.py</filename> | 
|  | 9107 | file. | 
|  | 9108 | </para></listitem> | 
|  | 9109 | <listitem><para><emphasis>"<replaceable>your-target</replaceable>":</emphasis> | 
|  | 9110 | Create your own custom target if you want to run | 
|  | 9111 | tests when you are deploying images and running | 
|  | 9112 | tests on a custom machine within your BSP layer. | 
|  | 9113 | To do this, you need to add a Python unit that | 
|  | 9114 | defines the target class under | 
|  | 9115 | <filename>lib/oeqa/controllers/</filename> within | 
|  | 9116 | your layer. | 
|  | 9117 | You must also provide an empty | 
|  | 9118 | <filename>__init__.py</filename>. | 
|  | 9119 | For examples, see files in | 
|  | 9120 | <filename>meta-yocto-bsp/lib/oeqa/controllers/</filename>. | 
|  | 9121 | </para></listitem> | 
|  | 9122 | </itemizedlist> | 
|  | 9123 | </para> | 
|  | 9124 | </section> | 
|  | 9125 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 9126 | <section id='selecting-systemd-boottarget'> | 
|  | 9127 | <title>Selecting Systemd-bootTarget</title> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9128 |  | 
|  | 9129 | <para> | 
|  | 9130 | If you did not set <filename>TEST_TARGET</filename> to | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 9131 | "Systemd-bootTarget", then you do not need any information | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9132 | in this section. | 
|  | 9133 | You can skip down to the | 
|  | 9134 | "<link linkend='qemu-image-running-tests'>Running Tests</link>" | 
|  | 9135 | section. | 
|  | 9136 | </para> | 
|  | 9137 |  | 
|  | 9138 | <para> | 
|  | 9139 | If you did set <filename>TEST_TARGET</filename> to | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 9140 | "Systemd-bootTarget", you also need to perform a one-time | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9141 | setup of your master image by doing the following: | 
|  | 9142 | <orderedlist> | 
|  | 9143 | <listitem><para><emphasis>Set <filename>EFI_PROVIDER</filename>:</emphasis> | 
|  | 9144 | Be sure that <filename>EFI_PROVIDER</filename> | 
|  | 9145 | is as follows: | 
|  | 9146 | <literallayout class='monospaced'> | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 9147 | EFI_PROVIDER = "systemd-boot" | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9148 | </literallayout> | 
|  | 9149 | </para></listitem> | 
|  | 9150 | <listitem><para><emphasis>Build the master image:</emphasis> | 
|  | 9151 | Build the <filename>core-image-testmaster</filename> | 
|  | 9152 | image. | 
|  | 9153 | The <filename>core-image-testmaster</filename> | 
|  | 9154 | recipe is provided as an example for a | 
|  | 9155 | "master" image and you can customize the image | 
|  | 9156 | recipe as you would any other recipe. | 
|  | 9157 | </para> | 
|  | 9158 | <para>Here are the image recipe requirements: | 
|  | 9159 | <itemizedlist> | 
|  | 9160 | <listitem><para>Inherits | 
|  | 9161 | <filename>core-image</filename> | 
|  | 9162 | so that kernel modules are installed. | 
|  | 9163 | </para></listitem> | 
|  | 9164 | <listitem><para>Installs normal linux utilities | 
|  | 9165 | not busybox ones (e.g. | 
|  | 9166 | <filename>bash</filename>, | 
|  | 9167 | <filename>coreutils</filename>, | 
|  | 9168 | <filename>tar</filename>, | 
|  | 9169 | <filename>gzip</filename>, and | 
|  | 9170 | <filename>kmod</filename>). | 
|  | 9171 | </para></listitem> | 
|  | 9172 | <listitem><para>Uses a custom | 
|  | 9173 | Initial RAM Disk (initramfs) image with a | 
|  | 9174 | custom installer. | 
|  | 9175 | A normal image that you can install usually | 
|  | 9176 | creates a single rootfs partition. | 
|  | 9177 | This image uses another installer that | 
|  | 9178 | creates a specific partition layout. | 
|  | 9179 | Not all Board Support Packages (BSPs) | 
|  | 9180 | can use an installer. | 
|  | 9181 | For such cases, you need to manually create | 
|  | 9182 | the following partition layout on the | 
|  | 9183 | target: | 
|  | 9184 | <itemizedlist> | 
|  | 9185 | <listitem><para>First partition mounted | 
|  | 9186 | under <filename>/boot</filename>, | 
|  | 9187 | labeled "boot". | 
|  | 9188 | </para></listitem> | 
|  | 9189 | <listitem><para>The main rootfs | 
|  | 9190 | partition where this image gets | 
|  | 9191 | installed, which is mounted under | 
|  | 9192 | <filename>/</filename>. | 
|  | 9193 | </para></listitem> | 
|  | 9194 | <listitem><para>Another partition | 
|  | 9195 | labeled "testrootfs" where test | 
|  | 9196 | images get deployed. | 
|  | 9197 | </para></listitem> | 
|  | 9198 | </itemizedlist> | 
|  | 9199 | </para></listitem> | 
|  | 9200 | </itemizedlist> | 
|  | 9201 | </para></listitem> | 
|  | 9202 | <listitem><para><emphasis>Install image:</emphasis> | 
|  | 9203 | Install the image that you just built on the target | 
|  | 9204 | system. | 
|  | 9205 | </para></listitem> | 
|  | 9206 | </orderedlist> | 
|  | 9207 | </para> | 
|  | 9208 |  | 
|  | 9209 | <para> | 
|  | 9210 | The final thing you need to do when setting | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 9211 | <filename>TEST_TARGET</filename> to "Systemd-bootTarget" is | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9212 | to set up the test image: | 
|  | 9213 | <orderedlist> | 
|  | 9214 | <listitem><para><emphasis>Set up your <filename>local.conf</filename> file:</emphasis> | 
|  | 9215 | Make sure you have the following statements in | 
|  | 9216 | your <filename>local.conf</filename> file: | 
|  | 9217 | <literallayout class='monospaced'> | 
|  | 9218 | IMAGE_FSTYPES += "tar.gz" | 
|  | 9219 | INHERIT += "testimage" | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 9220 | TEST_TARGET = "Systemd-bootTarget" | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9221 | TEST_TARGET_IP = "192.168.2.3" | 
|  | 9222 | </literallayout> | 
|  | 9223 | </para></listitem> | 
|  | 9224 | <listitem><para><emphasis>Build your test image:</emphasis> | 
|  | 9225 | Use BitBake to build the image: | 
|  | 9226 | <literallayout class='monospaced'> | 
|  | 9227 | $ bitbake core-image-sato | 
|  | 9228 | </literallayout> | 
|  | 9229 | </para></listitem> | 
|  | 9230 | </orderedlist> | 
|  | 9231 | </para> | 
|  | 9232 | </section> | 
|  | 9233 |  | 
|  | 9234 | <section id='power-control'> | 
|  | 9235 | <title>Power Control</title> | 
|  | 9236 |  | 
|  | 9237 | <para> | 
|  | 9238 | For most hardware targets other than SimpleRemoteTarget, | 
|  | 9239 | you can control power: | 
|  | 9240 | <itemizedlist> | 
|  | 9241 | <listitem><para> | 
|  | 9242 | You can use | 
|  | 9243 | <filename>TEST_POWERCONTROL_CMD</filename> | 
|  | 9244 | together with | 
|  | 9245 | <filename>TEST_POWERCONTROL_EXTRA_ARGS</filename> | 
|  | 9246 | as a command that runs on the host and does power | 
|  | 9247 | cycling. | 
|  | 9248 | The test code passes one argument to that command: | 
|  | 9249 | off, on or cycle (off then on). | 
|  | 9250 | Here is an example that could appear in your | 
|  | 9251 | <filename>local.conf</filename> file: | 
|  | 9252 | <literallayout class='monospaced'> | 
|  | 9253 | TEST_POWERCONTROL_CMD = "powercontrol.exp test 10.11.12.1 nuc1" | 
|  | 9254 | </literallayout> | 
|  | 9255 | In this example, the expect script does the | 
|  | 9256 | following: | 
|  | 9257 | <literallayout class='monospaced'> | 
|  | 9258 | ssh test@10.11.12.1 "pyctl nuc1 <replaceable>arg</replaceable>" | 
|  | 9259 | </literallayout> | 
|  | 9260 | It then runs a Python script that controls power | 
|  | 9261 | for a label called <filename>nuc1</filename>. | 
|  | 9262 | <note> | 
|  | 9263 | You need to customize | 
|  | 9264 | <filename>TEST_POWERCONTROL_CMD</filename> | 
|  | 9265 | and | 
|  | 9266 | <filename>TEST_POWERCONTROL_EXTRA_ARGS</filename> | 
|  | 9267 | for your own setup. | 
|  | 9268 | The one requirement is that it accepts | 
|  | 9269 | "on", "off", and "cycle" as the last argument. | 
|  | 9270 | </note> | 
|  | 9271 | </para></listitem> | 
|  | 9272 | <listitem><para> | 
|  | 9273 | When no command is defined, it connects to the | 
|  | 9274 | device over SSH and uses the classic reboot command | 
|  | 9275 | to reboot the device. | 
|  | 9276 | Classic reboot is fine as long as the machine | 
|  | 9277 | actually reboots (i.e. the SSH test has not | 
|  | 9278 | failed). | 
|  | 9279 | It is useful for scenarios where you have a simple | 
|  | 9280 | setup, typically with a single board, and where | 
|  | 9281 | some manual interaction is okay from time to time. | 
|  | 9282 | </para></listitem> | 
|  | 9283 | </itemizedlist> | 
|  | 9284 | If you have no hardware to automatically perform power | 
|  | 9285 | control but still wish to experiment with automated | 
|  | 9286 | hardware testing, you can use the dialog-power-control | 
|  | 9287 | script that shows a dialog prompting you to perform the | 
|  | 9288 | required power action. | 
|  | 9289 | This script requires either KDialog or Zenity to be | 
|  | 9290 | installed. | 
|  | 9291 | To use this script, set the | 
|  | 9292 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_POWERCONTROL_CMD'><filename>TEST_POWERCONTROL_CMD</filename></ulink> | 
|  | 9293 | variable as follows: | 
|  | 9294 | <literallayout class='monospaced'> | 
|  | 9295 | TEST_POWERCONTROL_CMD = "${COREBASE}/scripts/contrib/dialog-power-control" | 
|  | 9296 | </literallayout> | 
|  | 9297 | </para> | 
|  | 9298 | </section> | 
|  | 9299 |  | 
|  | 9300 | <section id='serial-console-connection'> | 
|  | 9301 | <title>Serial Console Connection</title> | 
|  | 9302 |  | 
|  | 9303 | <para> | 
|  | 9304 | For test target classes requiring a serial console | 
|  | 9305 | to interact with the bootloader (e.g. BeagleBoneTarget, | 
|  | 9306 | EdgeRouterTarget, and GrubTarget), you need to | 
|  | 9307 | specify a command to use to connect to the serial console | 
|  | 9308 | of the target machine by using the | 
|  | 9309 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SERIALCONTROL_CMD'><filename>TEST_SERIALCONTROL_CMD</filename></ulink> | 
|  | 9310 | variable and optionally the | 
|  | 9311 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SERIALCONTROL_EXTRA_ARGS'><filename>TEST_SERIALCONTROL_EXTRA_ARGS</filename></ulink> | 
|  | 9312 | variable. | 
|  | 9313 | </para> | 
|  | 9314 |  | 
|  | 9315 | <para> | 
|  | 9316 | These cases could be a serial terminal program if the | 
|  | 9317 | machine is connected to a local serial port, or a | 
|  | 9318 | <filename>telnet</filename> or | 
|  | 9319 | <filename>ssh</filename> command connecting to a remote | 
|  | 9320 | console server. | 
|  | 9321 | Regardless of the case, the command simply needs to | 
|  | 9322 | connect to the serial console and forward that connection | 
|  | 9323 | to standard input and output as any normal terminal | 
|  | 9324 | program does. | 
|  | 9325 | For example, to use the picocom terminal program on | 
|  | 9326 | serial device <filename>/dev/ttyUSB0</filename> | 
|  | 9327 | at 115200bps, you would set the variable as follows: | 
|  | 9328 | <literallayout class='monospaced'> | 
|  | 9329 | TEST_SERIALCONTROL_CMD = "picocom /dev/ttyUSB0 -b 115200" | 
|  | 9330 | </literallayout> | 
|  | 9331 | For local devices where the serial port device disappears | 
|  | 9332 | when the device reboots, an additional "serdevtry" wrapper | 
|  | 9333 | script is provided. | 
|  | 9334 | To use this wrapper, simply prefix the terminal command | 
|  | 9335 | with | 
|  | 9336 | <filename>${COREBASE}/scripts/contrib/serdevtry</filename>: | 
|  | 9337 | <literallayout class='monospaced'> | 
|  | 9338 | TEST_SERIALCONTROL_CMD = "${COREBASE}/scripts/contrib/serdevtry picocom -b | 
|  | 9339 | 115200 /dev/ttyUSB0" | 
|  | 9340 | </literallayout> | 
|  | 9341 | </para> | 
|  | 9342 | </section> | 
|  | 9343 | </section> | 
|  | 9344 |  | 
|  | 9345 | <section id="qemu-image-running-tests"> | 
|  | 9346 | <title>Running Tests</title> | 
|  | 9347 |  | 
|  | 9348 | <para> | 
|  | 9349 | You can start the tests automatically or manually: | 
|  | 9350 | <itemizedlist> | 
|  | 9351 | <listitem><para><emphasis>Automatically running tests:</emphasis> | 
|  | 9352 | To run the tests automatically after the | 
|  | 9353 | OpenEmbedded build system successfully creates an image, | 
|  | 9354 | first set the | 
|  | 9355 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_IMAGE'><filename>TEST_IMAGE</filename></ulink> | 
|  | 9356 | variable to "1" in your <filename>local.conf</filename> | 
|  | 9357 | file in the | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 9358 | <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9359 | <literallayout class='monospaced'> | 
|  | 9360 | TEST_IMAGE = "1" | 
|  | 9361 | </literallayout> | 
|  | 9362 | Next, build your image. | 
|  | 9363 | If the image successfully builds, the tests will be | 
|  | 9364 | run: | 
|  | 9365 | <literallayout class='monospaced'> | 
|  | 9366 | bitbake core-image-sato | 
|  | 9367 | </literallayout></para></listitem> | 
|  | 9368 | <listitem><para><emphasis>Manually running tests:</emphasis> | 
|  | 9369 | To manually run the tests, first globally inherit the | 
| Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 9370 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-testimage*'><filename>testimage</filename></ulink> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9371 | class by editing your <filename>local.conf</filename> | 
|  | 9372 | file: | 
|  | 9373 | <literallayout class='monospaced'> | 
|  | 9374 | INHERIT += "testimage" | 
|  | 9375 | </literallayout> | 
|  | 9376 | Next, use BitBake to run the tests: | 
|  | 9377 | <literallayout class='monospaced'> | 
|  | 9378 | bitbake -c testimage <replaceable>image</replaceable> | 
|  | 9379 | </literallayout></para></listitem> | 
|  | 9380 | </itemizedlist> | 
|  | 9381 | </para> | 
|  | 9382 |  | 
|  | 9383 | <para> | 
|  | 9384 | All test files reside in | 
|  | 9385 | <filename>meta/lib/oeqa/runtime</filename> in the | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 9386 | <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9387 | A test name maps directly to a Python module. | 
|  | 9388 | Each test module may contain a number of individual tests. | 
|  | 9389 | Tests are usually grouped together by the area | 
|  | 9390 | tested (e.g tests for systemd reside in | 
|  | 9391 | <filename>meta/lib/oeqa/runtime/systemd.py</filename>). | 
|  | 9392 | </para> | 
|  | 9393 |  | 
|  | 9394 | <para> | 
|  | 9395 | You can add tests to any layer provided you place them in the | 
|  | 9396 | proper area and you extend | 
|  | 9397 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink> | 
|  | 9398 | in the <filename>local.conf</filename> file as normal. | 
|  | 9399 | Be sure that tests reside in | 
|  | 9400 | <filename><replaceable>layer</replaceable>/lib/oeqa/runtime</filename>. | 
|  | 9401 | <note> | 
|  | 9402 | Be sure that module names do not collide with module names | 
|  | 9403 | used in the default set of test modules in | 
|  | 9404 | <filename>meta/lib/oeqa/runtime</filename>. | 
|  | 9405 | </note> | 
|  | 9406 | </para> | 
|  | 9407 |  | 
|  | 9408 | <para> | 
|  | 9409 | You can change the set of tests run by appending or overriding | 
|  | 9410 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SUITES'><filename>TEST_SUITES</filename></ulink> | 
|  | 9411 | variable in <filename>local.conf</filename>. | 
|  | 9412 | Each name in <filename>TEST_SUITES</filename> represents a | 
|  | 9413 | required test for the image. | 
|  | 9414 | Test modules named within <filename>TEST_SUITES</filename> | 
|  | 9415 | cannot be skipped even if a test is not suitable for an image | 
|  | 9416 | (e.g. running the RPM tests on an image without | 
|  | 9417 | <filename>rpm</filename>). | 
|  | 9418 | Appending "auto" to <filename>TEST_SUITES</filename> causes the | 
|  | 9419 | build system to try to run all tests that are suitable for the | 
|  | 9420 | image (i.e. each test module may elect to skip itself). | 
|  | 9421 | </para> | 
|  | 9422 |  | 
|  | 9423 | <para> | 
|  | 9424 | The order you list tests in <filename>TEST_SUITES</filename> | 
|  | 9425 | is important and influences test dependencies. | 
|  | 9426 | Consequently, tests that depend on other tests should be added | 
|  | 9427 | after the test on which they depend. | 
|  | 9428 | For example, since the <filename>ssh</filename> test | 
|  | 9429 | depends on the | 
|  | 9430 | <filename>ping</filename> test, "ssh" needs to come after | 
|  | 9431 | "ping" in the list. | 
|  | 9432 | The test class provides no re-ordering or dependency handling. | 
|  | 9433 | <note> | 
|  | 9434 | Each module can have multiple classes with multiple test | 
|  | 9435 | methods. | 
|  | 9436 | And, Python <filename>unittest</filename> rules apply. | 
|  | 9437 | </note> | 
|  | 9438 | </para> | 
|  | 9439 |  | 
|  | 9440 | <para> | 
|  | 9441 | Here are some things to keep in mind when running tests: | 
|  | 9442 | <itemizedlist> | 
|  | 9443 | <listitem><para>The default tests for the image are defined | 
|  | 9444 | as: | 
|  | 9445 | <literallayout class='monospaced'> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 9446 | DEFAULT_TEST_SUITES_pn-<replaceable>image</replaceable> = "ping ssh df connman syslog xorg scp vnc date rpm dnf dmesg" | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9447 | </literallayout></para></listitem> | 
|  | 9448 | <listitem><para>Add your own test to the list of the | 
|  | 9449 | by using the following: | 
|  | 9450 | <literallayout class='monospaced'> | 
|  | 9451 | TEST_SUITES_append = " mytest" | 
|  | 9452 | </literallayout></para></listitem> | 
|  | 9453 | <listitem><para>Run a specific list of tests as follows: | 
|  | 9454 | <literallayout class='monospaced'> | 
|  | 9455 | TEST_SUITES = "test1 test2 test3" | 
|  | 9456 | </literallayout> | 
|  | 9457 | Remember, order is important. | 
|  | 9458 | Be sure to place a test that is dependent on another test | 
|  | 9459 | later in the order.</para></listitem> | 
|  | 9460 | </itemizedlist> | 
|  | 9461 | </para> | 
|  | 9462 | </section> | 
|  | 9463 |  | 
|  | 9464 | <section id="exporting-tests"> | 
|  | 9465 | <title>Exporting Tests</title> | 
|  | 9466 |  | 
|  | 9467 | <para> | 
|  | 9468 | You can export tests so that they can run independently of | 
|  | 9469 | the build system. | 
|  | 9470 | Exporting tests is required if you want to be able to hand | 
|  | 9471 | the test execution off to a scheduler. | 
|  | 9472 | You can only export tests that are defined in | 
|  | 9473 | <ulink url='&YOCTO_DOCS_REF_URL;#var-TEST_SUITES'><filename>TEST_SUITES</filename></ulink>. | 
|  | 9474 | </para> | 
|  | 9475 |  | 
|  | 9476 | <para> | 
|  | 9477 | If your image is already built, make sure the following are set | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 9478 | in your <filename>local.conf</filename> file: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9479 | <literallayout class='monospaced'> | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 9480 | INHERIT +="testexport" | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 9481 | TEST_TARGET_IP = "<replaceable>IP-address-for-the-test-target</replaceable>" | 
|  | 9482 | TEST_SERVER_IP = "<replaceable>IP-address-for-the-test-server</replaceable>" | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9483 | </literallayout> | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 9484 | You can then export the tests with the following BitBake | 
|  | 9485 | command form: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9486 | <literallayout class='monospaced'> | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 9487 | $ bitbake <replaceable>image</replaceable> -c testexport | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9488 | </literallayout> | 
|  | 9489 | Exporting the tests places them in the | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 9490 | <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink> | 
|  | 9491 | in | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 9492 | <filename>tmp/testexport/</filename><replaceable>image</replaceable>, | 
|  | 9493 | which is controlled by the | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9494 | <filename>TEST_EXPORT_DIR</filename> variable. | 
|  | 9495 | </para> | 
|  | 9496 |  | 
|  | 9497 | <para> | 
|  | 9498 | You can now run the tests outside of the build environment: | 
|  | 9499 | <literallayout class='monospaced'> | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 9500 | $ cd tmp/testexport/<replaceable>image</replaceable> | 
|  | 9501 | $ ./runexported.py testdata.json | 
|  | 9502 | </literallayout> | 
|  | 9503 | </para> | 
|  | 9504 |  | 
|  | 9505 | <para> | 
|  | 9506 | Here is a complete example that shows IP addresses and uses | 
|  | 9507 | the <filename>core-image-sato</filename> image: | 
|  | 9508 | <literallayout class='monospaced'> | 
|  | 9509 | INHERIT +="testexport" | 
|  | 9510 | TEST_TARGET_IP = "192.168.7.2" | 
|  | 9511 | TEST_SERVER_IP = "192.168.7.1" | 
|  | 9512 | </literallayout> | 
|  | 9513 | Use BitBake to export the tests: | 
|  | 9514 | <literallayout class='monospaced'> | 
|  | 9515 | $ bitbake core-image-sato -c testexport | 
|  | 9516 | </literallayout> | 
|  | 9517 | Run the tests outside of the build environment using the | 
|  | 9518 | following: | 
|  | 9519 | <literallayout class='monospaced'> | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 9520 | $ cd tmp/testexport/core-image-sato | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9521 | $ ./runexported.py testdata.json | 
|  | 9522 | </literallayout> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9523 | </para> | 
|  | 9524 | </section> | 
|  | 9525 |  | 
|  | 9526 | <section id="qemu-image-writing-new-tests"> | 
|  | 9527 | <title>Writing New Tests</title> | 
|  | 9528 |  | 
|  | 9529 | <para> | 
|  | 9530 | As mentioned previously, all new test files need to be in the | 
|  | 9531 | proper place for the build system to find them. | 
|  | 9532 | New tests for additional functionality outside of the core | 
|  | 9533 | should be added to the layer that adds the functionality, in | 
|  | 9534 | <filename><replaceable>layer</replaceable>/lib/oeqa/runtime</filename> | 
|  | 9535 | (as long as | 
|  | 9536 | <ulink url='&YOCTO_DOCS_REF_URL;#var-BBPATH'><filename>BBPATH</filename></ulink> | 
|  | 9537 | is extended in the layer's | 
|  | 9538 | <filename>layer.conf</filename> file as normal). | 
|  | 9539 | Just remember the following: | 
|  | 9540 | <itemizedlist> | 
|  | 9541 | <listitem><para>Filenames need to map directly to test | 
|  | 9542 | (module) names. | 
|  | 9543 | </para></listitem> | 
|  | 9544 | <listitem><para>Do not use module names that | 
|  | 9545 | collide with existing core tests. | 
|  | 9546 | </para></listitem> | 
|  | 9547 | <listitem><para>Minimally, an empty | 
|  | 9548 | <filename>__init__.py</filename> file must exist | 
|  | 9549 | in the runtime directory. | 
|  | 9550 | </para></listitem> | 
|  | 9551 | </itemizedlist> | 
|  | 9552 | </para> | 
|  | 9553 |  | 
|  | 9554 | <para> | 
|  | 9555 | To create a new test, start by copying an existing module | 
|  | 9556 | (e.g. <filename>syslog.py</filename> or | 
|  | 9557 | <filename>gcc.py</filename> are good ones to use). | 
|  | 9558 | Test modules can use code from | 
|  | 9559 | <filename>meta/lib/oeqa/utils</filename>, which are helper | 
|  | 9560 | classes. | 
|  | 9561 | </para> | 
|  | 9562 |  | 
|  | 9563 | <note> | 
|  | 9564 | Structure shell commands such that you rely on them and they | 
|  | 9565 | return a single code for success. | 
|  | 9566 | Be aware that sometimes you will need to parse the output. | 
|  | 9567 | See the <filename>df.py</filename> and | 
|  | 9568 | <filename>date.py</filename> modules for examples. | 
|  | 9569 | </note> | 
|  | 9570 |  | 
|  | 9571 | <para> | 
|  | 9572 | You will notice that all test classes inherit | 
|  | 9573 | <filename>oeRuntimeTest</filename>, which is found in | 
|  | 9574 | <filename>meta/lib/oetest.py</filename>. | 
|  | 9575 | This base class offers some helper attributes, which are | 
|  | 9576 | described in the following sections: | 
|  | 9577 | </para> | 
|  | 9578 |  | 
|  | 9579 | <section id='qemu-image-writing-tests-class-methods'> | 
|  | 9580 | <title>Class Methods</title> | 
|  | 9581 |  | 
|  | 9582 | <para> | 
|  | 9583 | Class methods are as follows: | 
|  | 9584 | <itemizedlist> | 
|  | 9585 | <listitem><para><emphasis><filename>hasPackage(pkg)</filename>:</emphasis> | 
|  | 9586 | Returns "True" if <filename>pkg</filename> is in the | 
|  | 9587 | installed package list of the image, which is based | 
|  | 9588 | on the manifest file that is generated during the | 
|  | 9589 | <filename>do_rootfs</filename> task. | 
|  | 9590 | </para></listitem> | 
|  | 9591 | <listitem><para><emphasis><filename>hasFeature(feature)</filename>:</emphasis> | 
|  | 9592 | Returns "True" if the feature is in | 
|  | 9593 | <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink> | 
|  | 9594 | or | 
|  | 9595 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DISTRO_FEATURES'><filename>DISTRO_FEATURES</filename></ulink>. | 
|  | 9596 | </para></listitem> | 
|  | 9597 | </itemizedlist> | 
|  | 9598 | </para> | 
|  | 9599 | </section> | 
|  | 9600 |  | 
|  | 9601 | <section id='qemu-image-writing-tests-class-attributes'> | 
|  | 9602 | <title>Class Attributes</title> | 
|  | 9603 |  | 
|  | 9604 | <para> | 
|  | 9605 | Class attributes are as follows: | 
|  | 9606 | <itemizedlist> | 
|  | 9607 | <listitem><para><emphasis><filename>pscmd</filename>:</emphasis> | 
|  | 9608 | Equals "ps -ef" if <filename>procps</filename> is | 
|  | 9609 | installed in the image. | 
|  | 9610 | Otherwise, <filename>pscmd</filename> equals | 
|  | 9611 | "ps" (busybox). | 
|  | 9612 | </para></listitem> | 
|  | 9613 | <listitem><para><emphasis><filename>tc</filename>:</emphasis> | 
|  | 9614 | The called test context, which gives access to the | 
|  | 9615 | following attributes: | 
|  | 9616 | <itemizedlist> | 
|  | 9617 | <listitem><para><emphasis><filename>d</filename>:</emphasis> | 
|  | 9618 | The BitBake datastore, which allows you to | 
|  | 9619 | use stuff such as | 
|  | 9620 | <filename>oeRuntimeTest.tc.d.getVar("VIRTUAL-RUNTIME_init_manager")</filename>. | 
|  | 9621 | </para></listitem> | 
|  | 9622 | <listitem><para><emphasis><filename>testslist</filename> and <filename>testsrequired</filename>:</emphasis> | 
|  | 9623 | Used internally. | 
|  | 9624 | The tests do not need these. | 
|  | 9625 | </para></listitem> | 
|  | 9626 | <listitem><para><emphasis><filename>filesdir</filename>:</emphasis> | 
|  | 9627 | The absolute path to | 
|  | 9628 | <filename>meta/lib/oeqa/runtime/files</filename>, | 
|  | 9629 | which contains helper files for tests meant | 
|  | 9630 | for copying on the target such as small | 
|  | 9631 | files written in C for compilation. | 
|  | 9632 | </para></listitem> | 
|  | 9633 | <listitem><para><emphasis><filename>target</filename>:</emphasis> | 
|  | 9634 | The target controller object used to deploy | 
|  | 9635 | and start an image on a particular target | 
|  | 9636 | (e.g. QemuTarget, SimpleRemote, and | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 9637 | Systemd-bootTarget). | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9638 | Tests usually use the following: | 
|  | 9639 | <itemizedlist> | 
|  | 9640 | <listitem><para><emphasis><filename>ip</filename>:</emphasis> | 
|  | 9641 | The target's IP address. | 
|  | 9642 | </para></listitem> | 
|  | 9643 | <listitem><para><emphasis><filename>server_ip</filename>:</emphasis> | 
|  | 9644 | The host's IP address, which is | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 9645 | usually used by the DNF test | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9646 | suite. | 
|  | 9647 | </para></listitem> | 
|  | 9648 | <listitem><para><emphasis><filename>run(cmd, timeout=None)</filename>:</emphasis> | 
|  | 9649 | The single, most used method. | 
|  | 9650 | This command is a wrapper for: | 
|  | 9651 | <filename>ssh root@host "cmd"</filename>. | 
|  | 9652 | The command returns a tuple: | 
|  | 9653 | (status, output), which are what | 
|  | 9654 | their names imply - the return code | 
|  | 9655 | of "cmd" and whatever output | 
|  | 9656 | it produces. | 
|  | 9657 | The optional timeout argument | 
|  | 9658 | represents the number of seconds the | 
|  | 9659 | test should wait for "cmd" to | 
|  | 9660 | return. | 
|  | 9661 | If the argument is "None", the | 
|  | 9662 | test uses the default instance's | 
|  | 9663 | timeout period, which is 300 | 
|  | 9664 | seconds. | 
|  | 9665 | If the argument is "0", the test | 
|  | 9666 | runs until the command returns. | 
|  | 9667 | </para></listitem> | 
|  | 9668 | <listitem><para><emphasis><filename>copy_to(localpath, remotepath)</filename>:</emphasis> | 
|  | 9669 | <filename>scp localpath root@ip:remotepath</filename>. | 
|  | 9670 | </para></listitem> | 
|  | 9671 | <listitem><para><emphasis><filename>copy_from(remotepath, localpath)</filename>:</emphasis> | 
|  | 9672 | <filename>scp root@host:remotepath localpath</filename>. | 
|  | 9673 | </para></listitem> | 
|  | 9674 | </itemizedlist></para></listitem> | 
|  | 9675 | </itemizedlist></para></listitem> | 
|  | 9676 | </itemizedlist> | 
|  | 9677 | </para> | 
|  | 9678 | </section> | 
|  | 9679 |  | 
|  | 9680 | <section id='qemu-image-writing-tests-instance-attributes'> | 
|  | 9681 | <title>Instance Attributes</title> | 
|  | 9682 |  | 
|  | 9683 | <para> | 
|  | 9684 | A single instance attribute exists, which is | 
|  | 9685 | <filename>target</filename>. | 
|  | 9686 | The <filename>target</filename> instance attribute is | 
|  | 9687 | identical to the class attribute of the same name, which | 
|  | 9688 | is described in the previous section. | 
|  | 9689 | This attribute exists as both an instance and class | 
|  | 9690 | attribute so tests can use | 
|  | 9691 | <filename>self.target.run(cmd)</filename> in instance | 
|  | 9692 | methods instead of | 
|  | 9693 | <filename>oeRuntimeTest.tc.target.run(cmd)</filename>. | 
|  | 9694 | </para> | 
|  | 9695 | </section> | 
|  | 9696 | </section> | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 9697 |  | 
|  | 9698 | <section id='installing-packages-in-the-dut-without-the-package-manager'> | 
|  | 9699 | <title>Installing Packages in the DUT Without the Package Manager</title> | 
|  | 9700 |  | 
|  | 9701 | <para> | 
|  | 9702 | When a test requires a package built by BitBake, it is possible | 
|  | 9703 | to install that package. | 
|  | 9704 | Installing the package does not require a package manager be | 
|  | 9705 | installed in the device under test (DUT). | 
|  | 9706 | It does, however, require an SSH connection and the target must | 
|  | 9707 | be using the <filename>sshcontrol</filename> class. | 
|  | 9708 | <note> | 
|  | 9709 | This method uses <filename>scp</filename> to copy files | 
|  | 9710 | from the host to the target, which causes permissions and | 
|  | 9711 | special attributes to be lost. | 
|  | 9712 | </note> | 
|  | 9713 | </para> | 
|  | 9714 |  | 
|  | 9715 | <para> | 
|  | 9716 | A JSON file is used to define the packages needed by a test. | 
|  | 9717 | This file must be in the same path as the file used to define | 
|  | 9718 | the tests. | 
|  | 9719 | Furthermore, the filename must map directly to the test | 
|  | 9720 | module name with a <filename>.json</filename> extension. | 
|  | 9721 | </para> | 
|  | 9722 |  | 
|  | 9723 | <para> | 
|  | 9724 | The JSON file must include an object with the test name as | 
|  | 9725 | keys of an object or an array. | 
|  | 9726 | This object (or array of objects) uses the following data: | 
|  | 9727 | <itemizedlist> | 
|  | 9728 | <listitem><para>"pkg" - A mandatory string that is the | 
|  | 9729 | name of the package to be installed. | 
|  | 9730 | </para></listitem> | 
|  | 9731 | <listitem><para>"rm" - An optional boolean, which defaults | 
|  | 9732 | to "false", that specifies to remove the package after | 
|  | 9733 | the test. | 
|  | 9734 | </para></listitem> | 
|  | 9735 | <listitem><para>"extract" - An optional boolean, which | 
|  | 9736 | defaults to "false", that specifies if the package must | 
|  | 9737 | be extracted from the package format. | 
|  | 9738 | When set to "true", the package is not automatically | 
|  | 9739 | installed into the DUT. | 
|  | 9740 | </para></listitem> | 
|  | 9741 | </itemizedlist> | 
|  | 9742 | </para> | 
|  | 9743 |  | 
|  | 9744 | <para> | 
|  | 9745 | Following is an example JSON file that handles test "foo" | 
|  | 9746 | installing package "bar" and test "foobar" installing | 
|  | 9747 | packages "foo" and "bar". | 
|  | 9748 | Once the test is complete, the packages are removed from the | 
|  | 9749 | DUT. | 
|  | 9750 | <literallayout class='monospaced'> | 
|  | 9751 | { | 
|  | 9752 | "foo": { | 
|  | 9753 | "pkg": "bar" | 
|  | 9754 | }, | 
|  | 9755 | "foobar": [ | 
|  | 9756 | { | 
|  | 9757 | "pkg": "foo", | 
|  | 9758 | "rm": true | 
|  | 9759 | }, | 
|  | 9760 | { | 
|  | 9761 | "pkg": "bar", | 
|  | 9762 | "rm": true | 
|  | 9763 | } | 
|  | 9764 | ] | 
|  | 9765 | } | 
|  | 9766 | </literallayout> | 
|  | 9767 | </para> | 
|  | 9768 | </section> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9769 | </section> | 
|  | 9770 |  | 
|  | 9771 | <section id="platdev-gdb-remotedebug"> | 
|  | 9772 | <title>Debugging With the GNU Project Debugger (GDB) Remotely</title> | 
|  | 9773 |  | 
|  | 9774 | <para> | 
|  | 9775 | GDB allows you to examine running programs, which in turn helps you to understand and fix problems. | 
|  | 9776 | It also allows you to perform post-mortem style analysis of program crashes. | 
|  | 9777 | GDB is available as a package within the Yocto Project and is | 
|  | 9778 | installed in SDK images by default. | 
|  | 9779 | See the "<ulink url='&YOCTO_DOCS_REF_URL;#ref-images'>Images</ulink>" chapter | 
|  | 9780 | in the Yocto Project Reference Manual for a description of these images. | 
|  | 9781 | You can find information on GDB at <ulink url="http://sourceware.org/gdb/"/>. | 
|  | 9782 | </para> | 
|  | 9783 |  | 
|  | 9784 | <tip> | 
|  | 9785 | For best results, install debug (<filename>-dbg</filename>) packages | 
|  | 9786 | for the applications you are going to debug. | 
|  | 9787 | Doing so makes extra debug symbols available that give you more | 
|  | 9788 | meaningful output. | 
|  | 9789 | </tip> | 
|  | 9790 |  | 
|  | 9791 | <para> | 
|  | 9792 | Sometimes, due to memory or disk space constraints, it is not possible | 
|  | 9793 | to use GDB directly on the remote target to debug applications. | 
|  | 9794 | These constraints arise because GDB needs to load the debugging information and the | 
|  | 9795 | binaries of the process being debugged. | 
|  | 9796 | Additionally, GDB needs to perform many computations to locate information such as function | 
|  | 9797 | names, variable names and values, stack traces and so forth - even before starting the | 
|  | 9798 | debugging process. | 
|  | 9799 | These extra computations place more load on the target system and can alter the | 
|  | 9800 | characteristics of the program being debugged. | 
|  | 9801 | </para> | 
|  | 9802 |  | 
|  | 9803 | <para> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 9804 | To help get past the previously mentioned constraints, you can use | 
|  | 9805 | gdbserver, which runs on the remote target and does not load any | 
|  | 9806 | debugging information from the debugged process. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9807 | Instead, a GDB instance processes the debugging information that is run on a | 
|  | 9808 | remote computer - the host GDB. | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 9809 | The host GDB then sends control commands to gdbserver to make it stop or start the debugged | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9810 | program, as well as read or write memory regions of that debugged program. | 
|  | 9811 | All the debugging information loaded and processed as well | 
|  | 9812 | as all the heavy debugging is done by the host GDB. | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 9813 | Offloading these processes gives the gdbserver running on the target a chance to remain | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9814 | small and fast. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9815 | </para> | 
|  | 9816 |  | 
|  | 9817 | <para> | 
|  | 9818 | Because the host GDB is responsible for loading the debugging information and | 
|  | 9819 | for doing the necessary processing to make actual debugging happen, | 
|  | 9820 | you have to make sure the host can access the unstripped binaries complete | 
|  | 9821 | with their debugging information and also be sure the target is compiled with no optimizations. | 
|  | 9822 | The host GDB must also have local access to all the libraries used by the | 
|  | 9823 | debugged program. | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 9824 | Because gdbserver does not need any local debugging information, the binaries on | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9825 | the remote target can remain stripped. | 
|  | 9826 | However, the binaries must also be compiled without optimization | 
|  | 9827 | so they match the host's binaries. | 
|  | 9828 | </para> | 
|  | 9829 |  | 
|  | 9830 | <para> | 
|  | 9831 | To remain consistent with GDB documentation and terminology, the binary being debugged | 
|  | 9832 | on the remote target machine is referred to as the "inferior" binary. | 
|  | 9833 | For documentation on GDB see the | 
|  | 9834 | <ulink url="http://sourceware.org/gdb/documentation/">GDB site</ulink>. | 
|  | 9835 | </para> | 
|  | 9836 |  | 
|  | 9837 | <para> | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 9838 | The following steps show you how to debug using the GNU project | 
|  | 9839 | debugger. | 
|  | 9840 | <orderedlist> | 
|  | 9841 | <listitem><para> | 
|  | 9842 | <emphasis>Configure your build system to construct the | 
|  | 9843 | companion debug filesystem:</emphasis></para> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9844 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 9845 | <para>In your <filename>local.conf</filename> file, set | 
|  | 9846 | the following: | 
|  | 9847 | <literallayout class='monospaced'> | 
|  | 9848 | IMAGE_GEN_DEBUGFS = "1" | 
|  | 9849 | IMAGE_FSTYPES_DEBUGFS = "tar.bz2" | 
|  | 9850 | </literallayout> | 
|  | 9851 | These options cause the OpenEmbedded build system | 
|  | 9852 | to generate a special companion filesystem fragment, | 
|  | 9853 | which contains the matching source and debug symbols to | 
|  | 9854 | your deployable filesystem. | 
|  | 9855 | The build system does this by looking at what is in the | 
|  | 9856 | deployed filesystem, and pulling the corresponding | 
|  | 9857 | <filename>-dbg</filename> packages.</para> | 
|  | 9858 |  | 
|  | 9859 | <para>The companion debug filesystem is not a complete | 
|  | 9860 | filesystem, but only contains the debug fragments. | 
|  | 9861 | This filesystem must be combined with the full filesystem | 
|  | 9862 | for debugging. | 
|  | 9863 | Subsequent steps in this procedure show how to combine | 
|  | 9864 | the partial filesystem with the full filesystem. | 
|  | 9865 | </para></listitem> | 
|  | 9866 | <listitem><para> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 9867 | <emphasis>Configure the system to include gdbserver in | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 9868 | the target filesystem:</emphasis></para> | 
|  | 9869 |  | 
|  | 9870 | <para>Make the following addition in either your | 
|  | 9871 | <filename>local.conf</filename> file or in an image | 
|  | 9872 | recipe: | 
|  | 9873 | <literallayout class='monospaced'> | 
|  | 9874 | IMAGE_INSTALL_append = “ gdbserver" | 
|  | 9875 | </literallayout> | 
|  | 9876 | The change makes sure the <filename>gdbserver</filename> | 
|  | 9877 | package is included. | 
|  | 9878 | </para></listitem> | 
|  | 9879 | <listitem><para> | 
|  | 9880 | <emphasis>Build the environment:</emphasis></para> | 
|  | 9881 |  | 
|  | 9882 | <para>Use the following command to construct the image and | 
|  | 9883 | the companion Debug Filesystem: | 
|  | 9884 | <literallayout class='monospaced'> | 
|  | 9885 | $ bitbake <replaceable>image</replaceable> | 
|  | 9886 | </literallayout> | 
|  | 9887 | Build the cross GDB component and make it available | 
|  | 9888 | for debugging. | 
|  | 9889 | Build the SDK that matches the image. | 
|  | 9890 | Building the SDK is best for a production build | 
|  | 9891 | that can be used later for debugging, especially | 
|  | 9892 | during long term maintenance: | 
|  | 9893 | <literallayout class='monospaced'> | 
|  | 9894 | $ bitbake -c populate_sdk <replaceable>image</replaceable> | 
|  | 9895 | </literallayout></para> | 
|  | 9896 |  | 
|  | 9897 | <para>Alternatively, you can build the minimal | 
|  | 9898 | toolchain components that match the target. | 
|  | 9899 | Doing so creates a smaller than typical SDK and only | 
|  | 9900 | contains a minimal set of components with which to | 
|  | 9901 | build simple test applications, as well as run the | 
|  | 9902 | debugger: | 
|  | 9903 | <literallayout class='monospaced'> | 
|  | 9904 | $ bitbake meta-toolchain | 
|  | 9905 | </literallayout></para> | 
|  | 9906 |  | 
|  | 9907 | <para>A final method is to build Gdb itself within | 
|  | 9908 | the build system: | 
|  | 9909 | <literallayout class='monospaced'> | 
|  | 9910 | $ bitbake gdb-cross-<replaceable>architecture</replaceable> | 
|  | 9911 | </literallayout> | 
|  | 9912 | Doing so produces a temporary copy of | 
|  | 9913 | <filename>cross-gdb</filename> you can use for | 
|  | 9914 | debugging during development. | 
|  | 9915 | While this is the quickest approach, the two previous | 
|  | 9916 | methods in this step are better when considering | 
|  | 9917 | long-term maintenance strategies. | 
|  | 9918 | <note> | 
|  | 9919 | If you run | 
|  | 9920 | <filename>bitbake gdb-cross</filename>, the | 
|  | 9921 | OpenEmbedded build system suggests the actual | 
|  | 9922 | image (e.g. <filename>gdb-cross-i586</filename>). | 
|  | 9923 | The suggestion is usually the actual name you want | 
|  | 9924 | to use. | 
|  | 9925 | </note> | 
|  | 9926 | </para></listitem> | 
|  | 9927 | <listitem><para> | 
|  | 9928 | <emphasis>Set up the</emphasis> <filename>debugfs</filename></para> | 
|  | 9929 |  | 
|  | 9930 | <para>Run the following commands to set up the | 
|  | 9931 | <filename>debugfs</filename>: | 
|  | 9932 | <literallayout class='monospaced'> | 
|  | 9933 | $ mkdir debugfs | 
|  | 9934 | $ cd debugfs | 
|  | 9935 | $ tar xvfj <replaceable>build-dir</replaceable>/tmp-glibc/deploy/images/<replaceable>machine</replaceable>/<replaceable>image</replaceable>.rootfs.tar.bz2 | 
|  | 9936 | $ tar xvfj <replaceable>build-dir</replaceable>/tmp-glibc/deploy/images/<replaceable>machine</replaceable>/<replaceable>image</replaceable>-dbg.rootfs.tar.bz2 | 
|  | 9937 | </literallayout> | 
|  | 9938 | </para></listitem> | 
|  | 9939 | <listitem><para> | 
|  | 9940 | <emphasis>Set up GDB</emphasis></para> | 
|  | 9941 |  | 
|  | 9942 | <para>Install the SDK (if you built one) and then | 
|  | 9943 | source the correct environment file. | 
|  | 9944 | Sourcing the environment file puts the SDK in your | 
|  | 9945 | <filename>PATH</filename> environment variable.</para> | 
|  | 9946 |  | 
|  | 9947 | <para>If you are using the build system, Gdb is | 
|  | 9948 | located in | 
|  | 9949 | <replaceable>build-dir</replaceable>/tmp/sysroots/<replaceable>host</replaceable>/usr/bin/<replaceable>architecture</replaceable>/<replaceable>architecture</replaceable>-gdb | 
|  | 9950 | </para></listitem> | 
|  | 9951 | <listitem><para> | 
|  | 9952 | <emphasis>Boot the target:</emphasis></para> | 
|  | 9953 |  | 
|  | 9954 | <para>For information on how to run QEMU, see the | 
|  | 9955 | <ulink url='http://wiki.qemu.org/Documentation/GettingStartedDevelopers'>QEMU Documentation</ulink>. | 
|  | 9956 | <note> | 
|  | 9957 | Be sure to verify that your host can access the | 
|  | 9958 | target via TCP. | 
|  | 9959 | </note> | 
|  | 9960 | </para></listitem> | 
|  | 9961 | <listitem><para> | 
|  | 9962 | <emphasis>Debug a program:</emphasis></para> | 
|  | 9963 |  | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 9964 | <para>Debugging a program involves running gdbserver | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 9965 | on the target and then running Gdb on the host. | 
|  | 9966 | The example in this step debugs | 
|  | 9967 | <filename>gzip</filename>: | 
|  | 9968 | <literallayout class='monospaced'> | 
|  | 9969 | root@qemux86:~# gdbserver localhost:1234 /bin/gzip —help | 
|  | 9970 | </literallayout> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 9971 | For additional gdbserver options, see the | 
|  | 9972 | <ulink url='https://www.gnu.org/software/gdb/documentation/'>GDB Server Documentation</ulink>. | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 9973 | </para> | 
|  | 9974 |  | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 9975 | <para>After running gdbserver on the target, you need | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 9976 | to run Gdb on the host and configure it and connect to | 
|  | 9977 | the target. | 
|  | 9978 | Use these commands: | 
|  | 9979 | <literallayout class='monospaced'> | 
|  | 9980 | $ cd <replaceable>directory-holding-the-debugfs-directory</replaceable> | 
|  | 9981 | $ <replaceable>arch</replaceable>-gdb | 
|  | 9982 |  | 
|  | 9983 | (gdb) set sysroot debugfs | 
|  | 9984 | (gdb) set substitute-path /usr/src/debug debugfs/usr/src/debug | 
|  | 9985 | (gdb) target remote <replaceable>IP-of-target</replaceable>:1234 | 
|  | 9986 | </literallayout> | 
|  | 9987 | At this point, everything should automatically load | 
|  | 9988 | (i.e. matching binaries, symbols and headers). | 
|  | 9989 | <note> | 
|  | 9990 | The Gdb <filename>set</filename> commands in the | 
|  | 9991 | previous example can be placed into the users | 
|  | 9992 | <filename>~/.gdbinit</filename> file. | 
|  | 9993 | Upon starting, Gdb automatically runs whatever | 
|  | 9994 | commands are in that file. | 
|  | 9995 | </note> | 
|  | 9996 | </para></listitem> | 
|  | 9997 | <listitem><para> | 
|  | 9998 | <emphasis>Deploying without a full image | 
|  | 9999 | rebuild:</emphasis></para> | 
|  | 10000 |  | 
|  | 10001 | <para>In many cases, during development you want a | 
|  | 10002 | quick method to deploy a new binary to the target and | 
|  | 10003 | debug it, without waiting for a full image build. | 
|  | 10004 | </para> | 
|  | 10005 |  | 
|  | 10006 | <para>One approach to solving this situation is to | 
|  | 10007 | just build the component you want to debug. | 
|  | 10008 | Once you have built the component, copy the | 
|  | 10009 | executable directly to both the target and the | 
|  | 10010 | host <filename>debugfs</filename>.</para> | 
|  | 10011 |  | 
|  | 10012 | <para>If the binary is processed through the debug | 
|  | 10013 | splitting in OpenEmbedded, you should also | 
|  | 10014 | copy the debug items (i.e. <filename>.debug</filename> | 
|  | 10015 | contents and corresponding | 
|  | 10016 | <filename>/usr/src/debug</filename> files) | 
|  | 10017 | from the work directory. | 
|  | 10018 | Here is an example: | 
|  | 10019 | <literallayout class='monospaced'> | 
|  | 10020 | $ bitbake bash | 
|  | 10021 | $ bitbake -c devshell bash | 
|  | 10022 | $ cd .. | 
|  | 10023 | $ scp packages-split/bash/bin/bash <replaceable>target</replaceable>:/bin/bash | 
|  | 10024 | $ cp -a packages-split/bash-dbg/* <replaceable>path</replaceable>/debugfs | 
|  | 10025 | </literallayout> | 
|  | 10026 | </para></listitem> | 
|  | 10027 | </orderedlist> | 
|  | 10028 | </para> | 
|  | 10029 | </section> | 
|  | 10030 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 10031 | <section id='debugging-with-the-gnu-project-debugger-gdb-on-the-target'> | 
|  | 10032 | <title>Debugging with the GNU Project Debugger (GDB) on the Target</title> | 
|  | 10033 |  | 
|  | 10034 | <para> | 
|  | 10035 | The previous section addressed using GDB remotely for debugging | 
|  | 10036 | purposes, which is the most usual case due to the inherent | 
|  | 10037 | hardware limitations on many embedded devices. | 
|  | 10038 | However, debugging in the target hardware itself is also possible | 
|  | 10039 | with more powerful devices. | 
|  | 10040 | This section describes what you need to do in order to support | 
|  | 10041 | using GDB to debug on the target hardware. | 
|  | 10042 | </para> | 
|  | 10043 |  | 
|  | 10044 | <para> | 
|  | 10045 | To support this kind of debugging, you need do the following: | 
|  | 10046 | <itemizedlist> | 
|  | 10047 | <listitem><para> | 
|  | 10048 | Ensure that GDB is on the target. | 
|  | 10049 | You can do this by adding "gdb" to | 
|  | 10050 | <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_INSTALL'><filename>IMAGE_INSTALL</filename></ulink>: | 
|  | 10051 | <literallayout class='monospaced'> | 
|  | 10052 | IMAGE_INSTALL_append = " gdb" | 
|  | 10053 | </literallayout> | 
|  | 10054 | Alternatively, you can add "tools-debug" to | 
|  | 10055 | <ulink url='&YOCTO_DOCS_REF_URL;#var-IMAGE_FEATURES'><filename>IMAGE_FEATURES</filename></ulink>: | 
|  | 10056 | <literallayout class='monospaced'> | 
|  | 10057 | IMAGE_FEATURES_append = " tools-debug" | 
|  | 10058 | </literallayout> | 
|  | 10059 | </para></listitem> | 
|  | 10060 | <listitem><para> | 
|  | 10061 | Ensure that debug symbols are present. | 
|  | 10062 | You can make sure these symbols are present by installing | 
|  | 10063 | <filename>-dbg</filename>: | 
|  | 10064 | <literallayout class='monospaced'> | 
|  | 10065 | IMAGE_INSTALL_append = " <replaceable>packagename</replaceable>-dbg" | 
|  | 10066 | </literallayout> | 
|  | 10067 | Alternatively, you can do the following to include all the | 
|  | 10068 | debug symbols: | 
|  | 10069 | <literallayout class='monospaced'> | 
|  | 10070 | IMAGE_FEATURES_append = " dbg-pkgs" | 
|  | 10071 | </literallayout> | 
|  | 10072 | </para></listitem> | 
|  | 10073 | </itemizedlist> | 
|  | 10074 | <note> | 
|  | 10075 | To improve the debug information accuracy, you can reduce the | 
|  | 10076 | level of optimization used by the compiler. | 
|  | 10077 | For example, when adding the following line to your | 
|  | 10078 | <filename>local.conf</filename> file, you will reduce | 
|  | 10079 | optimization from | 
|  | 10080 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FULL_OPTIMIZATION'><filename>FULL_OPTIMIZATION</filename></ulink> | 
|  | 10081 | of "-O2" to | 
|  | 10082 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DEBUG_OPTIMIZATION'><filename>DEBUG_OPTIMIZATION</filename></ulink> | 
|  | 10083 | of "-O -fno-omit-frame-pointer": | 
|  | 10084 | <literallayout class='monospaced'> | 
|  | 10085 | DEBUG_BUILD = "1" | 
|  | 10086 | </literallayout> | 
|  | 10087 | Consider that this will reduce the application's performance | 
|  | 10088 | and is recommended only for debugging purposes. | 
|  | 10089 | </note> | 
|  | 10090 | </para> | 
|  | 10091 | </section> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10092 |  | 
|  | 10093 | <section id='debugging-parallel-make-races'> | 
|  | 10094 | <title>Debugging Parallel Make Races</title> | 
|  | 10095 |  | 
|  | 10096 | <para> | 
|  | 10097 | A parallel <filename>make</filename> race occurs when the build | 
|  | 10098 | consists of several parts that are run simultaneously and | 
|  | 10099 | a situation occurs when the output or result of one | 
|  | 10100 | part is not ready for use with a different part of the build that | 
|  | 10101 | depends on that output. | 
|  | 10102 | Parallel make races are annoying and can sometimes be difficult | 
|  | 10103 | to reproduce and fix. | 
|  | 10104 | However, some simple tips and tricks exist that can help | 
|  | 10105 | you debug and fix them. | 
|  | 10106 | This section presents a real-world example of an error encountered | 
|  | 10107 | on the Yocto Project autobuilder and the process used to fix it. | 
|  | 10108 | <note> | 
|  | 10109 | If you cannot properly fix a <filename>make</filename> race | 
|  | 10110 | condition, you can work around it by clearing either the | 
|  | 10111 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink> | 
|  | 10112 | or | 
|  | 10113 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKEINST'><filename>PARALLEL_MAKEINST</filename></ulink> | 
|  | 10114 | variables. | 
|  | 10115 | </note> | 
|  | 10116 | </para> | 
|  | 10117 |  | 
|  | 10118 | <section id='the-failure'> | 
|  | 10119 | <title>The Failure</title> | 
|  | 10120 |  | 
|  | 10121 | <para> | 
|  | 10122 | For this example, assume that you are building an image that | 
|  | 10123 | depends on the "neard" package. | 
|  | 10124 | And, during the build, BitBake runs into problems and | 
|  | 10125 | creates the following output. | 
|  | 10126 | <note> | 
|  | 10127 | This example log file has longer lines artificially | 
|  | 10128 | broken to make the listing easier to read. | 
|  | 10129 | </note> | 
|  | 10130 | If you examine the output or the log file, you see the | 
|  | 10131 | failure during <filename>make</filename>: | 
|  | 10132 | <literallayout class='monospaced'> | 
|  | 10133 | | DEBUG: SITE files ['endian-little', 'bit-32', 'ix86-common', 'common-linux', 'common-glibc', 'i586-linux', 'common'] | 
|  | 10134 | | DEBUG: Executing shell function do_compile | 
|  | 10135 | | NOTE: make -j 16 | 
|  | 10136 | | make --no-print-directory all-am | 
|  | 10137 | | /bin/mkdir -p include/near | 
|  | 10138 | | /bin/mkdir -p include/near | 
|  | 10139 | | /bin/mkdir -p include/near | 
|  | 10140 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ | 
|  | 10141 | 0.14-r0/neard-0.14/include/types.h include/near/types.h | 
|  | 10142 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ | 
|  | 10143 | 0.14-r0/neard-0.14/include/log.h include/near/log.h | 
|  | 10144 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ | 
|  | 10145 | 0.14-r0/neard-0.14/include/plugin.h include/near/plugin.h | 
|  | 10146 | | /bin/mkdir -p include/near | 
|  | 10147 | | /bin/mkdir -p include/near | 
|  | 10148 | | /bin/mkdir -p include/near | 
|  | 10149 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ | 
|  | 10150 | 0.14-r0/neard-0.14/include/tag.h include/near/tag.h | 
|  | 10151 | | /bin/mkdir -p include/near | 
|  | 10152 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ | 
|  | 10153 | 0.14-r0/neard-0.14/include/adapter.h include/near/adapter.h | 
|  | 10154 | | /bin/mkdir -p include/near | 
|  | 10155 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ | 
|  | 10156 | 0.14-r0/neard-0.14/include/ndef.h include/near/ndef.h | 
|  | 10157 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ | 
|  | 10158 | 0.14-r0/neard-0.14/include/tlv.h include/near/tlv.h | 
|  | 10159 | | /bin/mkdir -p include/near | 
|  | 10160 | | /bin/mkdir -p include/near | 
|  | 10161 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ | 
|  | 10162 | 0.14-r0/neard-0.14/include/setting.h include/near/setting.h | 
|  | 10163 | | /bin/mkdir -p include/near | 
|  | 10164 | | /bin/mkdir -p include/near | 
|  | 10165 | | /bin/mkdir -p include/near | 
|  | 10166 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ | 
|  | 10167 | 0.14-r0/neard-0.14/include/device.h include/near/device.h | 
|  | 10168 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ | 
|  | 10169 | 0.14-r0/neard-0.14/include/nfc_copy.h include/near/nfc_copy.h | 
|  | 10170 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ | 
|  | 10171 | 0.14-r0/neard-0.14/include/snep.h include/near/snep.h | 
|  | 10172 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ | 
|  | 10173 | 0.14-r0/neard-0.14/include/version.h include/near/version.h | 
|  | 10174 | | ln -s /home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ | 
|  | 10175 | 0.14-r0/neard-0.14/include/dbus.h include/near/dbus.h | 
|  | 10176 | | ./src/genbuiltin nfctype1 nfctype2 nfctype3 nfctype4 p2p > src/builtin.h | 
|  | 10177 | | i586-poky-linux-gcc  -m32 -march=i586 --sysroot=/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/ | 
|  | 10178 | build/build/tmp/sysroots/qemux86 -DHAVE_CONFIG_H -I. -I./include -I./src -I./gdbus  -I/home/pokybuild/ | 
|  | 10179 | yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/glib-2.0 | 
|  | 10180 | -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/ | 
|  | 10181 | lib/glib-2.0/include  -I/home/pokybuild/yocto-autobuilder/yocto-slave/nightly-x86/build/build/ | 
|  | 10182 | tmp/sysroots/qemux86/usr/include/dbus-1.0 -I/home/pokybuild/yocto-autobuilder/yocto-slave/ | 
|  | 10183 | nightly-x86/build/build/tmp/sysroots/qemux86/usr/lib/dbus-1.0/include  -I/home/pokybuild/yocto-autobuilder/ | 
|  | 10184 | yocto-slave/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/libnl3 | 
|  | 10185 | -DNEAR_PLUGIN_BUILTIN -DPLUGINDIR=\""/usr/lib/near/plugins"\" | 
|  | 10186 | -DCONFIGDIR=\""/etc/neard\"" -O2 -pipe -g -feliminate-unused-debug-types -c | 
|  | 10187 | -o tools/snep-send.o tools/snep-send.c | 
|  | 10188 | | In file included from tools/snep-send.c:16:0: | 
|  | 10189 | | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory | 
|  | 10190 | |  #include <near/dbus.h> | 
|  | 10191 | |                        ^ | 
|  | 10192 | | compilation terminated. | 
|  | 10193 | | make[1]: *** [tools/snep-send.o] Error 1 | 
|  | 10194 | | make[1]: *** Waiting for unfinished jobs.... | 
|  | 10195 | | make: *** [all] Error 2 | 
|  | 10196 | | ERROR: oe_runmake failed | 
|  | 10197 | </literallayout> | 
|  | 10198 | </para> | 
|  | 10199 | </section> | 
|  | 10200 |  | 
|  | 10201 | <section id='reproducing-the-error'> | 
|  | 10202 | <title>Reproducing the Error</title> | 
|  | 10203 |  | 
|  | 10204 | <para> | 
|  | 10205 | Because race conditions are intermittent, they do not | 
|  | 10206 | manifest themselves every time you do the build. | 
|  | 10207 | In fact, most times the build will complete without problems | 
|  | 10208 | even though the potential race condition exists. | 
|  | 10209 | Thus, once the error surfaces, you need a way to reproduce it. | 
|  | 10210 | </para> | 
|  | 10211 |  | 
|  | 10212 | <para> | 
|  | 10213 | In this example, compiling the "neard" package is causing the | 
|  | 10214 | problem. | 
|  | 10215 | So the first thing to do is build "neard" locally. | 
|  | 10216 | Before you start the build, set the | 
|  | 10217 | <ulink url='&YOCTO_DOCS_REF_URL;#var-PARALLEL_MAKE'><filename>PARALLEL_MAKE</filename></ulink> | 
|  | 10218 | variable in your <filename>local.conf</filename> file to | 
|  | 10219 | a high number (e.g. "-j 20"). | 
|  | 10220 | Using a high value for <filename>PARALLEL_MAKE</filename> | 
|  | 10221 | increases the chances of the race condition showing up: | 
|  | 10222 | <literallayout class='monospaced'> | 
|  | 10223 | $ bitbake neard | 
|  | 10224 | </literallayout> | 
|  | 10225 | </para> | 
|  | 10226 |  | 
|  | 10227 | <para> | 
|  | 10228 | Once the local build for "neard" completes, start a | 
|  | 10229 | <filename>devshell</filename> build: | 
|  | 10230 | <literallayout class='monospaced'> | 
|  | 10231 | $ bitbake neard -c devshell | 
|  | 10232 | </literallayout> | 
|  | 10233 | For information on how to use a | 
|  | 10234 | <filename>devshell</filename>, see the | 
|  | 10235 | "<link linkend='platdev-appdev-devshell'>Using a Development Shell</link>" | 
|  | 10236 | section. | 
|  | 10237 | </para> | 
|  | 10238 |  | 
|  | 10239 | <para> | 
|  | 10240 | In the <filename>devshell</filename>, do the following: | 
|  | 10241 | <literallayout class='monospaced'> | 
|  | 10242 | $ make clean | 
|  | 10243 | $ make tools/snep-send.o | 
|  | 10244 | </literallayout> | 
|  | 10245 | The <filename>devshell</filename> commands cause the failure | 
|  | 10246 | to clearly be visible. | 
|  | 10247 | In this case, a missing dependency exists for the "neard" | 
|  | 10248 | Makefile target. | 
|  | 10249 | Here is some abbreviated, sample output with the | 
|  | 10250 | missing dependency clearly visible at the end: | 
|  | 10251 | <literallayout class='monospaced'> | 
|  | 10252 | i586-poky-linux-gcc  -m32 -march=i586 --sysroot=/home/scott-lenovo/...... | 
|  | 10253 | . | 
|  | 10254 | . | 
|  | 10255 | . | 
|  | 10256 | tools/snep-send.c | 
|  | 10257 | In file included from tools/snep-send.c:16:0: | 
|  | 10258 | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory | 
|  | 10259 | #include <near/dbus.h> | 
|  | 10260 | ^ | 
|  | 10261 | compilation terminated. | 
|  | 10262 | make: *** [tools/snep-send.o] Error 1 | 
|  | 10263 | $ | 
|  | 10264 | </literallayout> | 
|  | 10265 | </para> | 
|  | 10266 | </section> | 
|  | 10267 |  | 
|  | 10268 | <section id='creating-a-patch-for-the-fix'> | 
|  | 10269 | <title>Creating a Patch for the Fix</title> | 
|  | 10270 |  | 
|  | 10271 | <para> | 
|  | 10272 | Because there is a missing dependency for the Makefile | 
|  | 10273 | target, you need to patch the | 
|  | 10274 | <filename>Makefile.am</filename> file, which is generated | 
|  | 10275 | from <filename>Makefile.in</filename>. | 
|  | 10276 | You can use Quilt to create the patch: | 
|  | 10277 | <literallayout class='monospaced'> | 
|  | 10278 | $ quilt new parallelmake.patch | 
|  | 10279 | Patch patches/parallelmake.patch is now on top | 
|  | 10280 | $ quilt add Makefile.am | 
|  | 10281 | File Makefile.am added to patch patches/parallelmake.patch | 
|  | 10282 | </literallayout> | 
|  | 10283 | For more information on using Quilt, see the | 
|  | 10284 | "<link linkend='using-a-quilt-workflow'>Using Quilt in Your Workflow</link>" | 
|  | 10285 | section. | 
|  | 10286 | </para> | 
|  | 10287 |  | 
|  | 10288 | <para> | 
|  | 10289 | At this point you need to make the edits to | 
|  | 10290 | <filename>Makefile.am</filename> to add the missing | 
|  | 10291 | dependency. | 
|  | 10292 | For our example, you have to add the following line | 
|  | 10293 | to the file: | 
|  | 10294 | <literallayout class='monospaced'> | 
|  | 10295 | tools/snep-send.$(OBJEXT): include/near/dbus.h | 
|  | 10296 | </literallayout> | 
|  | 10297 | </para> | 
|  | 10298 |  | 
|  | 10299 | <para> | 
|  | 10300 | Once you have edited the file, use the | 
|  | 10301 | <filename>refresh</filename> command to create the patch: | 
|  | 10302 | <literallayout class='monospaced'> | 
|  | 10303 | $ quilt refresh | 
|  | 10304 | Refreshed patch patches/parallelmake.patch | 
|  | 10305 | </literallayout> | 
|  | 10306 | Once the patch file exists, you need to add it back to the | 
|  | 10307 | originating recipe folder. | 
|  | 10308 | Here is an example assuming a top-level | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 10309 | <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10310 | named <filename>poky</filename>: | 
|  | 10311 | <literallayout class='monospaced'> | 
|  | 10312 | $ cp patches/parallelmake.patch poky/meta/recipes-connectivity/neard/neard | 
|  | 10313 | </literallayout> | 
|  | 10314 | The final thing you need to do to implement the fix in the | 
|  | 10315 | build is to update the "neard" recipe (i.e. | 
|  | 10316 | <filename>neard-0.14.bb</filename>) so that the | 
|  | 10317 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> | 
|  | 10318 | statement includes the patch file. | 
|  | 10319 | The recipe file is in the folder above the patch. | 
|  | 10320 | Here is what the edited <filename>SRC_URI</filename> | 
|  | 10321 | statement would look like: | 
|  | 10322 | <literallayout class='monospaced'> | 
|  | 10323 | SRC_URI = "${KERNELORG_MIRROR}/linux/network/nfc/${BPN}-${PV}.tar.xz \ | 
|  | 10324 | file://neard.in \ | 
|  | 10325 | file://neard.service.in \ | 
|  | 10326 | file://parallelmake.patch \ | 
|  | 10327 | " | 
|  | 10328 | </literallayout> | 
|  | 10329 | </para> | 
|  | 10330 |  | 
|  | 10331 | <para> | 
|  | 10332 | With the patch complete and moved to the correct folder and | 
|  | 10333 | the <filename>SRC_URI</filename> statement updated, you can | 
|  | 10334 | exit the <filename>devshell</filename>: | 
|  | 10335 | <literallayout class='monospaced'> | 
|  | 10336 | $ exit | 
|  | 10337 | </literallayout> | 
|  | 10338 | </para> | 
|  | 10339 | </section> | 
|  | 10340 |  | 
|  | 10341 | <section id='testing-the-build'> | 
|  | 10342 | <title>Testing the Build</title> | 
|  | 10343 |  | 
|  | 10344 | <para> | 
|  | 10345 | With everything in place, you can get back to trying the | 
|  | 10346 | build again locally: | 
|  | 10347 | <literallayout class='monospaced'> | 
|  | 10348 | $ bitbake neard | 
|  | 10349 | </literallayout> | 
|  | 10350 | This build should succeed. | 
|  | 10351 | </para> | 
|  | 10352 |  | 
|  | 10353 | <para> | 
|  | 10354 | Now you can open up a <filename>devshell</filename> again | 
|  | 10355 | and repeat the clean and make operations as follows: | 
|  | 10356 | <literallayout class='monospaced'> | 
|  | 10357 | $ bitbake neard -c devshell | 
|  | 10358 | $ make clean | 
|  | 10359 | $ make tools/snep-send.o | 
|  | 10360 | </literallayout> | 
|  | 10361 | The build should work without issue. | 
|  | 10362 | </para> | 
|  | 10363 |  | 
|  | 10364 | <para> | 
|  | 10365 | As with all solved problems, if they originated upstream, you | 
|  | 10366 | need to submit the fix for the recipe in OE-Core and upstream | 
|  | 10367 | so that the problem is taken care of at its source. | 
|  | 10368 | See the | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 10369 | "<link linkend='how-to-submit-a-change'>Submitting a Change to the Yocto Project</link>" | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10370 | section for more information. | 
|  | 10371 | </para> | 
|  | 10372 | </section> | 
|  | 10373 | </section> | 
|  | 10374 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10375 | <section id='maintaining-open-source-license-compliance-during-your-products-lifecycle'> | 
|  | 10376 | <title>Maintaining Open Source License Compliance During Your Product's Lifecycle</title> | 
|  | 10377 |  | 
|  | 10378 | <para> | 
|  | 10379 | One of the concerns for a development organization using open source | 
|  | 10380 | software is how to maintain compliance with various open source | 
|  | 10381 | licensing during the lifecycle of the product. | 
|  | 10382 | While this section does not provide legal advice or | 
|  | 10383 | comprehensively cover all scenarios, it does | 
|  | 10384 | present methods that you can use to | 
|  | 10385 | assist you in meeting the compliance requirements during a software | 
|  | 10386 | release. | 
|  | 10387 | </para> | 
|  | 10388 |  | 
|  | 10389 | <para> | 
|  | 10390 | With hundreds of different open source licenses that the Yocto | 
|  | 10391 | Project tracks, it is difficult to know the requirements of each | 
|  | 10392 | and every license. | 
|  | 10393 | However, the requirements of the major FLOSS licenses can begin | 
|  | 10394 | to be covered by | 
|  | 10395 | assuming that three main areas of concern exist: | 
|  | 10396 | <itemizedlist> | 
|  | 10397 | <listitem><para>Source code must be provided.</para></listitem> | 
|  | 10398 | <listitem><para>License text for the software must be | 
|  | 10399 | provided.</para></listitem> | 
|  | 10400 | <listitem><para>Compilation scripts and modifications to the | 
|  | 10401 | source code must be provided. | 
|  | 10402 | </para></listitem> | 
|  | 10403 | </itemizedlist> | 
|  | 10404 | There are other requirements beyond the scope of these | 
|  | 10405 | three and the methods described in this section | 
|  | 10406 | (e.g. the mechanism through which source code is distributed). | 
|  | 10407 | </para> | 
|  | 10408 |  | 
|  | 10409 | <para> | 
|  | 10410 | As different organizations have different methods of complying with | 
|  | 10411 | open source licensing, this section is not meant to imply that | 
|  | 10412 | there is only one single way to meet your compliance obligations, | 
|  | 10413 | but rather to describe one method of achieving compliance. | 
|  | 10414 | The remainder of this section describes methods supported to meet the | 
|  | 10415 | previously mentioned three requirements. | 
|  | 10416 | Once you take steps to meet these requirements, | 
|  | 10417 | and prior to releasing images, sources, and the build system, | 
|  | 10418 | you should audit all artifacts to ensure completeness. | 
|  | 10419 | <note> | 
|  | 10420 | The Yocto Project generates a license manifest during | 
|  | 10421 | image creation that is located | 
|  | 10422 | in <filename>${DEPLOY_DIR}/licenses/<replaceable>image_name-datestamp</replaceable></filename> | 
|  | 10423 | to assist with any audits. | 
|  | 10424 | </note> | 
|  | 10425 | </para> | 
|  | 10426 |  | 
|  | 10427 | <section id='providing-the-source-code'> | 
|  | 10428 | <title>Providing the Source Code</title> | 
|  | 10429 |  | 
|  | 10430 | <para> | 
|  | 10431 | Compliance activities should begin before you generate the | 
|  | 10432 | final image. | 
|  | 10433 | The first thing you should look at is the requirement that | 
|  | 10434 | tops the list for most compliance groups - providing | 
|  | 10435 | the source. | 
|  | 10436 | The Yocto Project has a few ways of meeting this | 
|  | 10437 | requirement. | 
|  | 10438 | </para> | 
|  | 10439 |  | 
|  | 10440 | <para> | 
|  | 10441 | One of the easiest ways to meet this requirement is | 
|  | 10442 | to provide the entire | 
|  | 10443 | <ulink url='&YOCTO_DOCS_REF_URL;#var-DL_DIR'><filename>DL_DIR</filename></ulink> | 
|  | 10444 | used by the build. | 
|  | 10445 | This method, however, has a few issues. | 
|  | 10446 | The most obvious is the size of the directory since it includes | 
|  | 10447 | all sources used in the build and not just the source used in | 
|  | 10448 | the released image. | 
|  | 10449 | It will include toolchain source, and other artifacts, which | 
|  | 10450 | you would not generally release. | 
|  | 10451 | However, the more serious issue for most companies is accidental | 
|  | 10452 | release of proprietary software. | 
|  | 10453 | The Yocto Project provides an | 
|  | 10454 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-archiver'><filename>archiver</filename></ulink> | 
|  | 10455 | class to help avoid some of these concerns. | 
|  | 10456 | </para> | 
|  | 10457 |  | 
|  | 10458 | <para> | 
|  | 10459 | Before you employ <filename>DL_DIR</filename> or the | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 10460 | <filename>archiver</filename> class, you need to decide how | 
|  | 10461 | you choose to provide source. | 
|  | 10462 | The source <filename>archiver</filename> class can generate | 
|  | 10463 | tarballs and SRPMs and can create them with various levels of | 
|  | 10464 | compliance in mind. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10465 | </para> | 
|  | 10466 |  | 
|  | 10467 | <para> | 
|  | 10468 | One way of doing this (but certainly not the only way) is to | 
|  | 10469 | release just the source as a tarball. | 
|  | 10470 | You can do this by adding the following to the | 
|  | 10471 | <filename>local.conf</filename> file found in the | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 10472 | <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10473 | <literallayout class='monospaced'> | 
|  | 10474 | INHERIT += "archiver" | 
|  | 10475 | ARCHIVER_MODE[src] = "original" | 
|  | 10476 | </literallayout> | 
|  | 10477 | During the creation of your image, the source from all | 
|  | 10478 | recipes that deploy packages to the image is placed within | 
|  | 10479 | subdirectories of | 
|  | 10480 | <filename>DEPLOY_DIR/sources</filename> based on the | 
|  | 10481 | <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE</filename></ulink> | 
|  | 10482 | for each recipe. | 
|  | 10483 | Releasing the entire directory enables you to comply with | 
|  | 10484 | requirements concerning providing the unmodified source. | 
|  | 10485 | It is important to note that the size of the directory can | 
|  | 10486 | get large. | 
|  | 10487 | </para> | 
|  | 10488 |  | 
|  | 10489 | <para> | 
|  | 10490 | A way to help mitigate the size issue is to only release | 
|  | 10491 | tarballs for licenses that require the release of | 
|  | 10492 | source. | 
|  | 10493 | Let us assume you are only concerned with GPL code as | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 10494 | identified by running the following script: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10495 | <literallayout class='monospaced'> | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 10496 | # Script to archive a subset of packages matching specific license(s) | 
|  | 10497 | # Source and license files are copied into sub folders of package folder | 
|  | 10498 | # Must be run from build folder | 
|  | 10499 | #!/bin/bash | 
|  | 10500 | src_release_dir="source-release" | 
|  | 10501 | mkdir -p $src_release_dir | 
|  | 10502 | for a in tmp/deploy/sources/*; do | 
|  | 10503 | for d in $a/*; do | 
|  | 10504 | # Get package name from path | 
|  | 10505 | p=`basename $d` | 
|  | 10506 | p=${p%-*} | 
|  | 10507 | p=${p%-*} | 
|  | 10508 | # Only archive GPL packages (update *GPL* regex for your license check) | 
|  | 10509 | numfiles=`ls tmp/deploy/licenses/$p/*GPL* 2> /dev/null | wc -l` | 
|  | 10510 | if [ $numfiles -gt 1 ]; then | 
|  | 10511 | echo Archiving $p | 
|  | 10512 | mkdir -p $src_release_dir/$p/source | 
|  | 10513 | cp $d/* $src_release_dir/$p/source 2> /dev/null | 
|  | 10514 | mkdir -p $src_release_dir/$p/license | 
|  | 10515 | cp tmp/deploy/licenses/$p/* $src_release_dir/$p/license 2> /dev/null | 
|  | 10516 | fi | 
|  | 10517 | done | 
|  | 10518 | done                </literallayout> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10519 | At this point, you could create a tarball from the | 
|  | 10520 | <filename>gpl_source_release</filename> directory and | 
|  | 10521 | provide that to the end user. | 
|  | 10522 | This method would be a step toward achieving compliance | 
|  | 10523 | with section 3a of GPLv2 and with section 6 of GPLv3. | 
|  | 10524 | </para> | 
|  | 10525 | </section> | 
|  | 10526 |  | 
|  | 10527 | <section id='providing-license-text'> | 
|  | 10528 | <title>Providing License Text</title> | 
|  | 10529 |  | 
|  | 10530 | <para> | 
|  | 10531 | One requirement that is often overlooked is inclusion | 
|  | 10532 | of license text. | 
|  | 10533 | This requirement also needs to be dealt with prior to | 
|  | 10534 | generating the final image. | 
|  | 10535 | Some licenses require the license text to accompany | 
|  | 10536 | the binary. | 
|  | 10537 | You can achieve this by adding the following to your | 
|  | 10538 | <filename>local.conf</filename> file: | 
|  | 10539 | <literallayout class='monospaced'> | 
|  | 10540 | COPY_LIC_MANIFEST = "1" | 
|  | 10541 | COPY_LIC_DIRS = "1" | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 10542 | LICENSE_CREATE_PACKAGE = "1" | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10543 | </literallayout> | 
|  | 10544 | Adding these statements to the configuration file ensures | 
|  | 10545 | that the licenses collected during package generation | 
|  | 10546 | are included on your image. | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 10547 | <note> | 
|  | 10548 | <para>Setting all three variables to "1" results in the | 
|  | 10549 | image having two copies of the same license file. | 
|  | 10550 | One copy resides in | 
|  | 10551 | <filename>/usr/share/common-licenses</filename> and | 
|  | 10552 | the other resides in | 
|  | 10553 | <filename>/usr/share/license</filename>.</para> | 
|  | 10554 |  | 
|  | 10555 | <para>The reason for this behavior is because | 
|  | 10556 | <ulink url='&YOCTO_DOCS_REF_URL;#var-COPY_LIC_DIRS'><filename>COPY_LIC_DIRS</filename></ulink> | 
|  | 10557 | and | 
|  | 10558 | <ulink url='&YOCTO_DOCS_REF_URL;#var-COPY_LIC_MANIFEST'><filename>COPY_LIC_MANIFEST</filename></ulink> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 10559 | add a copy of the license when the image is built but do | 
|  | 10560 | not offer a path for adding licenses for newly installed | 
|  | 10561 | packages to an image. | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 10562 | <ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE_CREATE_PACKAGE'><filename>LICENSE_CREATE_PACKAGE</filename></ulink> | 
|  | 10563 | adds a separate package and an upgrade path for adding | 
|  | 10564 | licenses to an image.</para> | 
|  | 10565 | </note> | 
|  | 10566 | </para> | 
|  | 10567 |  | 
|  | 10568 | <para> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 10569 | As the source <filename>archiver</filename> class has already | 
|  | 10570 | archived the original | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10571 | unmodified source that contains the license files, | 
|  | 10572 | you would have already met the requirements for inclusion | 
|  | 10573 | of the license information with source as defined by the GPL | 
|  | 10574 | and other open source licenses. | 
|  | 10575 | </para> | 
|  | 10576 | </section> | 
|  | 10577 |  | 
|  | 10578 | <section id='providing-compilation-scripts-and-source-code-modifications'> | 
|  | 10579 | <title>Providing Compilation Scripts and Source Code Modifications</title> | 
|  | 10580 |  | 
|  | 10581 | <para> | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 10582 | At this point, we have addressed all we need to | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10583 | prior to generating the image. | 
|  | 10584 | The next two requirements are addressed during the final | 
|  | 10585 | packaging of the release. | 
|  | 10586 | </para> | 
|  | 10587 |  | 
|  | 10588 | <para> | 
|  | 10589 | By releasing the version of the OpenEmbedded build system | 
|  | 10590 | and the layers used during the build, you will be providing both | 
|  | 10591 | compilation scripts and the source code modifications in one | 
|  | 10592 | step. | 
|  | 10593 | </para> | 
|  | 10594 |  | 
|  | 10595 | <para> | 
|  | 10596 | If the deployment team has a | 
|  | 10597 | <ulink url='&YOCTO_DOCS_BSP_URL;#bsp-layers'>BSP layer</ulink> | 
|  | 10598 | and a distro layer, and those those layers are used to patch, | 
|  | 10599 | compile, package, or modify (in any way) any open source | 
|  | 10600 | software included in your released images, you | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 10601 | might be required to release those layers under section 3 of | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10602 | GPLv2 or section 1 of GPLv3. | 
|  | 10603 | One way of doing that is with a clean | 
|  | 10604 | checkout of the version of the Yocto Project and layers used | 
|  | 10605 | during your build. | 
|  | 10606 | Here is an example: | 
|  | 10607 | <literallayout class='monospaced'> | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 10608 | # We built using the &DISTRO_NAME_NO_CAP; branch of the poky repo | 
|  | 10609 | $ git clone -b &DISTRO_NAME_NO_CAP; git://git.yoctoproject.org/poky | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10610 | $ cd poky | 
|  | 10611 | # We built using the release_branch for our layers | 
|  | 10612 | $ git clone -b release_branch git://git.mycompany.com/meta-my-bsp-layer | 
|  | 10613 | $ git clone -b release_branch git://git.mycompany.com/meta-my-software-layer | 
|  | 10614 | # clean up the .git repos | 
|  | 10615 | $ find . -name ".git" -type d -exec rm -rf {} \; | 
|  | 10616 | </literallayout> | 
|  | 10617 | One thing a development organization might want to consider | 
|  | 10618 | for end-user convenience is to modify | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 10619 | <filename>meta-poky/conf/bblayers.conf.sample</filename> to | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10620 | ensure that when the end user utilizes the released build | 
|  | 10621 | system to build an image, the development organization's | 
|  | 10622 | layers are included in the <filename>bblayers.conf</filename> | 
|  | 10623 | file automatically: | 
|  | 10624 | <literallayout class='monospaced'> | 
|  | 10625 | # LAYER_CONF_VERSION is increased each time build/conf/bblayers.conf | 
|  | 10626 | # changes incompatibly | 
|  | 10627 | LCONF_VERSION = "6" | 
|  | 10628 |  | 
|  | 10629 | BBPATH = "${TOPDIR}" | 
|  | 10630 | BBFILES ?= "" | 
|  | 10631 |  | 
|  | 10632 | BBLAYERS ?= " \ | 
|  | 10633 | ##OEROOT##/meta \ | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 10634 | ##OEROOT##/meta-poky \ | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10635 | ##OEROOT##/meta-yocto-bsp \ | 
|  | 10636 | ##OEROOT##/meta-mylayer \ | 
|  | 10637 | " | 
|  | 10638 | </literallayout> | 
|  | 10639 | Creating and providing an archive of the | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 10640 | <ulink url='&YOCTO_DOCS_REF_URL;#metadata'>Metadata</ulink> | 
|  | 10641 | layers (recipes, configuration files, and so forth) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10642 | enables you to meet your | 
|  | 10643 | requirements to include the scripts to control compilation | 
|  | 10644 | as well as any modifications to the original source. | 
|  | 10645 | </para> | 
|  | 10646 | </section> | 
|  | 10647 | </section> | 
|  | 10648 |  | 
|  | 10649 | <section id='using-the-error-reporting-tool'> | 
|  | 10650 | <title>Using the Error Reporting Tool</title> | 
|  | 10651 |  | 
|  | 10652 | <para> | 
|  | 10653 | The error reporting tool allows you to | 
|  | 10654 | submit errors encountered during builds to a central database. | 
|  | 10655 | Outside of the build environment, you can use a web interface to | 
|  | 10656 | browse errors, view statistics, and query for errors. | 
|  | 10657 | The tool works using a client-server system where the client | 
|  | 10658 | portion is integrated with the installed Yocto Project | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 10659 | <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10660 | (e.g. <filename>poky</filename>). | 
|  | 10661 | The server receives the information collected and saves it in a | 
|  | 10662 | database. | 
|  | 10663 | </para> | 
|  | 10664 |  | 
|  | 10665 | <para> | 
|  | 10666 | A live instance of the error reporting server exists at | 
|  | 10667 | <ulink url='http://errors.yoctoproject.org'></ulink>. | 
|  | 10668 | This server exists so that when you want to get help with | 
|  | 10669 | build failures, you can submit all of the information on the | 
|  | 10670 | failure easily and then point to the URL in your bug report | 
|  | 10671 | or send an email to the mailing list. | 
|  | 10672 | <note> | 
|  | 10673 | If you send error reports to this server, the reports become | 
|  | 10674 | publicly visible. | 
|  | 10675 | </note> | 
|  | 10676 | </para> | 
|  | 10677 |  | 
|  | 10678 | <section id='enabling-and-using-the-tool'> | 
|  | 10679 | <title>Enabling and Using the Tool</title> | 
|  | 10680 |  | 
|  | 10681 | <para> | 
|  | 10682 | By default, the error reporting tool is disabled. | 
|  | 10683 | You can enable it by inheriting the | 
|  | 10684 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-report-error'><filename>report-error</filename></ulink> | 
|  | 10685 | class by adding the following statement to the end of | 
|  | 10686 | your <filename>local.conf</filename> file in your | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 10687 | <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10688 | <literallayout class='monospaced'> | 
|  | 10689 | INHERIT += "report-error" | 
|  | 10690 | </literallayout> | 
|  | 10691 | </para> | 
|  | 10692 |  | 
|  | 10693 | <para> | 
|  | 10694 | By default, the error reporting feature stores information in | 
|  | 10695 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-LOG_DIR'><filename>LOG_DIR</filename></ulink><filename>}/error-report</filename>. | 
|  | 10696 | However, you can specify a directory to use by adding the following | 
|  | 10697 | to your <filename>local.conf</filename> file: | 
|  | 10698 | <literallayout class='monospaced'> | 
|  | 10699 | ERR_REPORT_DIR = "path" | 
|  | 10700 | </literallayout> | 
|  | 10701 | Enabling error reporting causes the build process to collect | 
|  | 10702 | the errors and store them in a file as previously described. | 
|  | 10703 | When the build system encounters an error, it includes a | 
|  | 10704 | command as part of the console output. | 
|  | 10705 | You can run the command to send the error file to the server. | 
|  | 10706 | For example, the following command sends the errors to an | 
|  | 10707 | upstream server: | 
|  | 10708 | <literallayout class='monospaced'> | 
|  | 10709 | $ send-error-report /home/brandusa/project/poky/build/tmp/log/error-report/error_report_201403141617.txt | 
|  | 10710 | </literallayout> | 
|  | 10711 | In the previous example, the errors are sent to a public | 
|  | 10712 | database available at | 
|  | 10713 | <ulink url='http://errors.yoctoproject.org'></ulink>, which is | 
|  | 10714 | used by the entire community. | 
|  | 10715 | If you specify a particular server, you can send the errors | 
|  | 10716 | to a different database. | 
|  | 10717 | Use the following command for more information on available | 
|  | 10718 | options: | 
|  | 10719 | <literallayout class='monospaced'> | 
|  | 10720 | $ send-error-report --help | 
|  | 10721 | </literallayout> | 
|  | 10722 | </para> | 
|  | 10723 |  | 
|  | 10724 | <para> | 
|  | 10725 | When sending the error file, you are prompted to review the | 
|  | 10726 | data being sent as well as to provide a name and optional | 
|  | 10727 | email address. | 
|  | 10728 | Once you satisfy these prompts, the command returns a link | 
|  | 10729 | from the server that corresponds to your entry in the database. | 
|  | 10730 | For example, here is a typical link: | 
|  | 10731 | <literallayout class='monospaced'> | 
|  | 10732 | http://errors.yoctoproject.org/Errors/Details/9522/ | 
|  | 10733 | </literallayout> | 
|  | 10734 | Following the link takes you to a web interface where you can | 
|  | 10735 | browse, query the errors, and view statistics. | 
|  | 10736 | </para> | 
|  | 10737 | </section> | 
|  | 10738 |  | 
|  | 10739 | <section id='disabling-the-tool'> | 
|  | 10740 | <title>Disabling the Tool</title> | 
|  | 10741 |  | 
|  | 10742 | <para> | 
|  | 10743 | To disable the error reporting feature, simply remove or comment | 
|  | 10744 | out the following statement from the end of your | 
|  | 10745 | <filename>local.conf</filename> file in your | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 10746 | <ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10747 | <literallayout class='monospaced'> | 
|  | 10748 | INHERIT += "report-error" | 
|  | 10749 | </literallayout> | 
|  | 10750 | </para> | 
|  | 10751 | </section> | 
|  | 10752 |  | 
|  | 10753 | <section id='setting-up-your-own-error-reporting-server'> | 
|  | 10754 | <title>Setting Up Your Own Error Reporting Server</title> | 
|  | 10755 |  | 
|  | 10756 | <para> | 
|  | 10757 | If you want to set up your own error reporting server, you | 
|  | 10758 | can obtain the code from the Git repository at | 
|  | 10759 | <ulink url='http://git.yoctoproject.org/cgit/cgit.cgi/error-report-web/'></ulink>. | 
|  | 10760 | Instructions on how to set it up are in the README document. | 
|  | 10761 | </para> | 
|  | 10762 | </section> | 
|  | 10763 | </section> | 
|  | 10764 | </chapter> | 
|  | 10765 |  | 
|  | 10766 | <!-- | 
|  | 10767 | vim: expandtab tw=80 ts=4 | 
|  | 10768 | --> |