| 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='kernel-dev-common'> | 
|  | 6 |  | 
|  | 7 | <title>Common Tasks</title> | 
|  | 8 |  | 
|  | 9 | <para> | 
|  | 10 | This chapter presents several common tasks you perform when you | 
|  | 11 | work with the Yocto Project Linux kernel. | 
|  | 12 | These tasks include preparing a layer, modifying an existing recipe, | 
|  | 13 | iterative development, working with your own sources, and incorporating | 
|  | 14 | out-of-tree modules. | 
|  | 15 | <note> | 
|  | 16 | The examples presented in this chapter work with the Yocto Project | 
|  | 17 | 1.2.2 Release and forward. | 
|  | 18 | </note> | 
|  | 19 | </para> | 
|  | 20 |  | 
|  | 21 | <section id='creating-and-preparing-a-layer'> | 
|  | 22 | <title>Creating and Preparing a Layer</title> | 
|  | 23 |  | 
|  | 24 | <para> | 
|  | 25 | If you are going to be modifying kernel recipes, it is recommended | 
|  | 26 | that you create and prepare your own layer in which to do your | 
|  | 27 | work. | 
|  | 28 | Your layer contains its own | 
|  | 29 | <ulink url='&YOCTO_DOCS_DEV_URL;#bitbake-term'>BitBake</ulink> | 
|  | 30 | append files | 
|  | 31 | (<filename>.bbappend</filename>) and provides a convenient | 
|  | 32 | mechanism to create your own recipe files | 
|  | 33 | (<filename>.bb</filename>). | 
|  | 34 | For details on how to create and work with layers, see the following | 
|  | 35 | sections in the Yocto Project Development Manual: | 
|  | 36 | <itemizedlist> | 
|  | 37 | <listitem><para>"<ulink url='&YOCTO_DOCS_DEV_URL;#understanding-and-creating-layers'>Understanding and Creating Layers</ulink>" for | 
|  | 38 | general information on layers and how to create layers.</para></listitem> | 
|  | 39 | <listitem><para>"<ulink url='&YOCTO_DOCS_DEV_URL;#set-up-your-layer-for-the-build'>Set Up Your Layer for the Build</ulink>" for | 
|  | 40 | specific instructions on setting up a layer for kernel | 
|  | 41 | development.</para></listitem> | 
|  | 42 | </itemizedlist> | 
|  | 43 | </para> | 
|  | 44 | </section> | 
|  | 45 |  | 
|  | 46 | <section id='modifying-an-existing-recipe'> | 
|  | 47 | <title>Modifying an Existing Recipe</title> | 
|  | 48 |  | 
|  | 49 | <para> | 
|  | 50 | In many cases, you can customize an existing linux-yocto recipe to | 
|  | 51 | meet the needs of your project. | 
|  | 52 | Each release of the Yocto Project provides a few Linux | 
|  | 53 | kernel recipes from which you can choose. | 
|  | 54 | These are located in the | 
|  | 55 | <ulink url='&YOCTO_DOCS_DEV_URL;#source-directory'>Source Directory</ulink> | 
|  | 56 | in <filename>meta/recipes-kernel/linux</filename>. | 
|  | 57 | </para> | 
|  | 58 |  | 
|  | 59 | <para> | 
|  | 60 | Modifying an existing recipe can consist of the following: | 
|  | 61 | <itemizedlist> | 
|  | 62 | <listitem><para>Creating the append file</para></listitem> | 
|  | 63 | <listitem><para>Applying patches</para></listitem> | 
|  | 64 | <listitem><para>Changing the configuration</para></listitem> | 
|  | 65 | </itemizedlist> | 
|  | 66 | </para> | 
|  | 67 |  | 
|  | 68 | <para> | 
|  | 69 | Before modifying an existing recipe, be sure that you have created | 
|  | 70 | a minimal, custom layer from which you can work. | 
|  | 71 | See the "<link linkend='creating-and-preparing-a-layer'>Creating and Preparing a Layer</link>" | 
|  | 72 | section for some general resources. | 
|  | 73 | You can also see the | 
|  | 74 | "<ulink url='&YOCTO_DOCS_DEV_URL;#set-up-your-layer-for-the-build'>Set Up Your Layer for the Build</ulink>" section | 
|  | 75 | of the Yocto Project Development Manual for a detailed | 
|  | 76 | example. | 
|  | 77 | </para> | 
|  | 78 |  | 
|  | 79 | <section id='creating-the-append-file'> | 
|  | 80 | <title>Creating the Append File</title> | 
|  | 81 |  | 
|  | 82 | <para> | 
|  | 83 | You create this file in your custom layer. | 
|  | 84 | You also name it accordingly based on the linux-yocto recipe | 
|  | 85 | you are using. | 
|  | 86 | For example, if you are modifying the | 
|  | 87 | <filename>meta/recipes-kernel/linux/linux-yocto_3.19.bb</filename> | 
|  | 88 | recipe, the append file will typically be located as follows | 
|  | 89 | within your custom layer: | 
|  | 90 | <literallayout class='monospaced'> | 
|  | 91 | <replaceable>your-layer</replaceable>/recipes-kernel/linux/linux-yocto_3.19.bbappend | 
|  | 92 | </literallayout> | 
|  | 93 | The append file should initially extend the | 
|  | 94 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink> | 
|  | 95 | search path by prepending the directory that contains your | 
|  | 96 | files to the | 
|  | 97 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink> | 
|  | 98 | variable as follows: | 
|  | 99 | <literallayout class='monospaced'> | 
|  | 100 | FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" | 
|  | 101 | </literallayout> | 
|  | 102 | The path <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> | 
|  | 103 | expands to "linux-yocto" in the current directory for this | 
|  | 104 | example. | 
|  | 105 | If you add any new files that modify the kernel recipe and you | 
|  | 106 | have extended <filename>FILESPATH</filename> as | 
|  | 107 | described above, you must place the files in your layer in the | 
|  | 108 | following area: | 
|  | 109 | <literallayout class='monospaced'> | 
|  | 110 | <replaceable>your-layer</replaceable>/recipes-kernel/linux/linux-yocto/ | 
|  | 111 | </literallayout> | 
|  | 112 | <note>If you are working on a new machine Board Support Package | 
|  | 113 | (BSP), be sure to refer to the | 
|  | 114 | <ulink url='&YOCTO_DOCS_BSP_URL;'>Yocto Project Board Support Package (BSP) Developer's Guide</ulink>. | 
|  | 115 | </note> | 
|  | 116 | </para> | 
|  | 117 | </section> | 
|  | 118 |  | 
|  | 119 | <section id='applying-patches'> | 
|  | 120 | <title>Applying Patches</title> | 
|  | 121 |  | 
|  | 122 | <para> | 
|  | 123 | If you have a single patch or a small series of patches | 
|  | 124 | that you want to apply to the Linux kernel source, you | 
|  | 125 | can do so just as you would with any other recipe. | 
|  | 126 | You first copy the patches to the path added to | 
|  | 127 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink> | 
|  | 128 | in your <filename>.bbappend</filename> file as described in | 
|  | 129 | the previous section, and then reference them in | 
|  | 130 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> | 
|  | 131 | statements. | 
|  | 132 | </para> | 
|  | 133 |  | 
|  | 134 | <para> | 
|  | 135 | For example, you can apply a three-patch series by adding the | 
|  | 136 | following lines to your linux-yocto | 
|  | 137 | <filename>.bbappend</filename> file in your layer: | 
|  | 138 | <literallayout class='monospaced'> | 
|  | 139 | SRC_URI += "file://0001-first-change.patch" | 
|  | 140 | SRC_URI += "file://0002-second-change.patch" | 
|  | 141 | SRC_URI += "file://0003-third-change.patch" | 
|  | 142 | </literallayout> | 
|  | 143 | The next time you run BitBake to build the Linux kernel, | 
|  | 144 | BitBake detects the change in the recipe and fetches and | 
|  | 145 | applies the patches before building the kernel. | 
|  | 146 | </para> | 
|  | 147 |  | 
|  | 148 | <para> | 
|  | 149 | For a detailed example showing how to patch the kernel, see the | 
|  | 150 | "<ulink url='&YOCTO_DOCS_DEV_URL;#patching-the-kernel'>Patching the Kernel</ulink>" | 
|  | 151 | section in the Yocto Project Development Manual. | 
|  | 152 | </para> | 
|  | 153 | </section> | 
|  | 154 |  | 
|  | 155 | <section id='changing-the-configuration'> | 
|  | 156 | <title>Changing the Configuration</title> | 
|  | 157 |  | 
|  | 158 | <para> | 
|  | 159 | You can make wholesale or incremental changes to the final | 
|  | 160 | <filename>.config</filename> file used for the eventual | 
|  | 161 | Linux kernel configuration by including a | 
|  | 162 | <filename>defconfig</filename> file and by specifying | 
|  | 163 | configuration fragments in the | 
|  | 164 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> | 
|  | 165 | to be applied to that file. | 
|  | 166 | </para> | 
|  | 167 |  | 
|  | 168 | <para> | 
|  | 169 | If you have a complete, working Linux kernel | 
|  | 170 | <filename>.config</filename> | 
|  | 171 | file you want to use for the configuration, as before, copy | 
|  | 172 | that file to the appropriate <filename>${PN}</filename> | 
|  | 173 | directory in your layer's | 
|  | 174 | <filename>recipes-kernel/linux</filename> directory, | 
|  | 175 | and rename the copied file to "defconfig". | 
|  | 176 | Then, add the following lines to the linux-yocto | 
|  | 177 | <filename>.bbappend</filename> file in your layer: | 
|  | 178 | <literallayout class='monospaced'> | 
|  | 179 | FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" | 
|  | 180 | SRC_URI += "file://defconfig" | 
|  | 181 | </literallayout> | 
|  | 182 | The <filename>SRC_URI</filename> tells the build system how to | 
|  | 183 | search for the file, while the | 
|  | 184 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink> | 
|  | 185 | extends the | 
|  | 186 | <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESPATH'><filename>FILESPATH</filename></ulink> | 
|  | 187 | variable (search directories) to include the | 
|  | 188 | <filename>${PN}</filename> directory you created to hold the | 
|  | 189 | configuration changes. | 
|  | 190 | </para> | 
|  | 191 |  | 
|  | 192 | <note> | 
|  | 193 | The build system applies the configurations from the | 
|  | 194 | <filename>defconfig</filename> file before applying any | 
|  | 195 | subsequent configuration fragments. | 
|  | 196 | The final kernel configuration is a combination of the | 
|  | 197 | configurations in the <filename>defconfig</filename> file and | 
|  | 198 | any configuration fragments you provide. | 
|  | 199 | You need to realize that if you have any configuration | 
|  | 200 | fragments, the build system applies these on top of and | 
|  | 201 | after applying the existing <filename>defconfig</filename> | 
|  | 202 | file configurations. | 
|  | 203 | </note> | 
|  | 204 |  | 
|  | 205 | <para> | 
|  | 206 | Generally speaking, the preferred approach is to determine the | 
|  | 207 | incremental change you want to make and add that as a | 
|  | 208 | configuration fragment. | 
|  | 209 | For example, if you want to add support for a basic serial | 
|  | 210 | console, create a file named <filename>8250.cfg</filename> in | 
|  | 211 | the <filename>${PN}</filename> directory with the following | 
|  | 212 | content (without indentation): | 
|  | 213 | <literallayout class='monospaced'> | 
|  | 214 | CONFIG_SERIAL_8250=y | 
|  | 215 | CONFIG_SERIAL_8250_CONSOLE=y | 
|  | 216 | CONFIG_SERIAL_8250_PCI=y | 
|  | 217 | CONFIG_SERIAL_8250_NR_UARTS=4 | 
|  | 218 | CONFIG_SERIAL_8250_RUNTIME_UARTS=4 | 
|  | 219 | CONFIG_SERIAL_CORE=y | 
|  | 220 | CONFIG_SERIAL_CORE_CONSOLE=y | 
|  | 221 | </literallayout> | 
|  | 222 | Next, include this configuration fragment and extend the | 
|  | 223 | <filename>FILESPATH</filename> variable in your | 
|  | 224 | <filename>.bbappend</filename> file: | 
|  | 225 | <literallayout class='monospaced'> | 
|  | 226 | FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" | 
|  | 227 | SRC_URI += "file://8250.cfg" | 
|  | 228 | </literallayout> | 
|  | 229 | The next time you run BitBake to build the Linux kernel, BitBake | 
|  | 230 | detects the change in the recipe and fetches and applies the | 
|  | 231 | new configuration before building the kernel. | 
|  | 232 | </para> | 
|  | 233 |  | 
|  | 234 | <para> | 
|  | 235 | For a detailed example showing how to configure the kernel, | 
|  | 236 | see the | 
|  | 237 | "<ulink url='&YOCTO_DOCS_DEV_URL;#configuring-the-kernel'>Configuring the Kernel</ulink>" | 
|  | 238 | section in the Yocto Project Development Manual. | 
|  | 239 | </para> | 
|  | 240 | </section> | 
|  | 241 |  | 
|  | 242 | <section id='using-an-in-tree-defconfig-file'> | 
|  | 243 | <title>Using an "In-Tree"  <filename>defconfig</filename> File</title> | 
|  | 244 |  | 
|  | 245 | <para> | 
|  | 246 | It might be desirable to have kernel configuration fragment | 
|  | 247 | support through a <filename>defconfig</filename> file that | 
|  | 248 | is pulled from the kernel source tree for the configured | 
|  | 249 | machine. | 
|  | 250 | By default, the OpenEmbedded build system looks for | 
|  | 251 | <filename>defconfig</filename> files in the layer used for | 
|  | 252 | Metadata, which is "out-of-tree", and then configures them | 
|  | 253 | using the following: | 
|  | 254 | <literallayout class='monospaced'> | 
|  | 255 | SRC_URI += "file://defconfig" | 
|  | 256 | </literallayout> | 
|  | 257 | If you do not want to maintain copies of | 
|  | 258 | <filename>defconfig</filename> files in your layer but would | 
|  | 259 | rather allow users to use the default configuration from the | 
|  | 260 | kernel tree and still be able to add configuration fragments | 
|  | 261 | to the | 
|  | 262 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> | 
|  | 263 | through, for example, append files, you can direct the | 
|  | 264 | OpenEmbedded build system to use a | 
|  | 265 | <filename>defconfig</filename> file that is "in-tree". | 
|  | 266 | </para> | 
|  | 267 |  | 
|  | 268 | <para> | 
|  | 269 | To specify an "in-tree" <filename>defconfig</filename> file, | 
|  | 270 | edit the recipe that builds your kernel so that it has the | 
|  | 271 | following command form: | 
|  | 272 | <literallayout class='monospaced'> | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 273 | KBUILD_DEFCONFIG_KMACHINE ?= <replaceable>defconfig_file</replaceable> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 274 | </literallayout> | 
|  | 275 | You need to append the variable with | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 276 | <ulink url='&YOCTO_DOCS_REF_URL;#var-KMACHINE'><filename>KMACHINE</filename></ulink> | 
|  | 277 | and then supply the path to your "in-tree" | 
|  | 278 | <filename>defconfig</filename> file. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 279 | </para> | 
|  | 280 |  | 
|  | 281 | <para> | 
|  | 282 | Aside from modifying your kernel recipe and providing your own | 
|  | 283 | <filename>defconfig</filename> file, you need to be sure no | 
|  | 284 | files or statements set <filename>SRC_URI</filename> to use a | 
|  | 285 | <filename>defconfig</filename> other than your "in-tree" | 
|  | 286 | file (e.g. a kernel's <filename>linux-</filename><replaceable>machine</replaceable><filename>.inc</filename> | 
|  | 287 | file). | 
|  | 288 | In other words, if the build system detects a statement | 
|  | 289 | that identifies an "out-of-tree" | 
|  | 290 | <filename>defconfig</filename> file, that statement | 
|  | 291 | will override your | 
|  | 292 | <filename>KBUILD_DEFCONFIG</filename> variable. | 
|  | 293 | </para> | 
|  | 294 |  | 
|  | 295 | <para> | 
|  | 296 | See the | 
|  | 297 | <ulink url='&YOCTO_DOCS_REF_URL;#var-KBUILD_DEFCONFIG'><filename>KBUILD_DEFCONFIG</filename></ulink> | 
|  | 298 | variable description for more information. | 
|  | 299 | </para> | 
|  | 300 | </section> | 
|  | 301 | </section> | 
|  | 302 |  | 
|  | 303 | <section id='using-an-iterative-development-process'> | 
|  | 304 | <title>Using an Iterative Development Process</title> | 
|  | 305 |  | 
|  | 306 | <para> | 
|  | 307 | If you do not have existing patches or configuration files, | 
|  | 308 | you can iteratively generate them from within the BitBake build | 
|  | 309 | environment as described within this section. | 
|  | 310 | During an iterative workflow, running a previously completed BitBake | 
|  | 311 | task causes BitBake to invalidate the tasks that follow the | 
|  | 312 | completed task in the build sequence. | 
|  | 313 | Invalidated tasks rebuild the next time you run the build using | 
|  | 314 | BitBake. | 
|  | 315 | </para> | 
|  | 316 |  | 
|  | 317 | <para> | 
|  | 318 | As you read this section, be sure to substitute the name | 
|  | 319 | of your Linux kernel recipe for the term | 
|  | 320 | "linux-yocto". | 
|  | 321 | </para> | 
|  | 322 |  | 
|  | 323 | <section id='tip-dirty-string'> | 
|  | 324 | <title>"-dirty" String</title> | 
|  | 325 |  | 
|  | 326 | <!-- | 
|  | 327 | <para> | 
|  | 328 | <emphasis>AR - Darren Hart:</emphasis>  This section | 
|  | 329 | originated from the old Yocto Project Kernel Architecture | 
|  | 330 | and Use Manual. | 
|  | 331 | It was decided we need to put it in this section here. | 
|  | 332 | Darren needs to figure out where we want it and what part | 
|  | 333 | of it we want (all, revision???) | 
|  | 334 | </para> | 
|  | 335 | --> | 
|  | 336 |  | 
|  | 337 | <para> | 
|  | 338 | If kernel images are being built with "-dirty" on the | 
|  | 339 | end of the version string, this simply means that | 
|  | 340 | modifications in the source directory have not been committed. | 
|  | 341 | <literallayout class='monospaced'> | 
|  | 342 | $ git status | 
|  | 343 | </literallayout> | 
|  | 344 | </para> | 
|  | 345 |  | 
|  | 346 | <para> | 
|  | 347 | You can use the above Git command to report modified, | 
|  | 348 | removed, or added files. | 
|  | 349 | You should commit those changes to the tree regardless of | 
|  | 350 | whether they will be saved, exported, or used. | 
|  | 351 | Once you commit the changes, you need to rebuild the kernel. | 
|  | 352 | </para> | 
|  | 353 |  | 
|  | 354 | <para> | 
|  | 355 | To force a pickup and commit of all such pending changes, | 
|  | 356 | enter the following: | 
|  | 357 | <literallayout class='monospaced'> | 
|  | 358 | $ git add . | 
|  | 359 | $ git commit -s -a -m "getting rid of -dirty" | 
|  | 360 | </literallayout> | 
|  | 361 | </para> | 
|  | 362 |  | 
|  | 363 | <para> | 
|  | 364 | Next, rebuild the kernel. | 
|  | 365 | </para> | 
|  | 366 | </section> | 
|  | 367 |  | 
|  | 368 | <section id='generating-configuration-files'> | 
|  | 369 | <title>Generating Configuration Files</title> | 
|  | 370 |  | 
|  | 371 | <para> | 
|  | 372 | You can manipulate the <filename>.config</filename> file | 
|  | 373 | used to build a linux-yocto recipe with the | 
|  | 374 | <filename>menuconfig</filename> command as follows: | 
|  | 375 | <literallayout class='monospaced'> | 
|  | 376 | $ bitbake linux-yocto -c menuconfig | 
|  | 377 | </literallayout> | 
|  | 378 | This command starts the Linux kernel configuration tool, | 
|  | 379 | which allows you to prepare a new | 
|  | 380 | <filename>.config</filename> file for the build. | 
|  | 381 | When you exit the tool, be sure to save your changes | 
|  | 382 | at the prompt. | 
|  | 383 | </para> | 
|  | 384 |  | 
|  | 385 | <para> | 
|  | 386 | The resulting <filename>.config</filename> file is | 
|  | 387 | located in | 
|  | 388 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}</filename> under the | 
|  | 389 | <filename>linux-${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-PACKAGE_ARCH'><filename>PACKAGE_ARCH</filename></ulink><filename>}-${<ulink url='&YOCTO_DOCS_REF_URL;#var-LINUX_KERNEL_TYPE'><filename>LINUX_KERNEL_TYPE</filename></ulink>}-build</filename> directory. | 
|  | 390 | You can use the entire <filename>.config</filename> file as the | 
|  | 391 | <filename>defconfig</filename> file as described in the | 
|  | 392 | "<link linkend='changing-the-configuration'>Changing the Configuration</link>" section. | 
| Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 393 | For more information on the <filename>.config</filename> file, | 
|  | 394 | see the | 
|  | 395 | "<ulink url='&YOCTO_DOCS_DEV_URL;#using-menuconfig'>Using <filename>menuconfig</filename></ulink>" | 
|  | 396 | section in the Yocto Project Development Manual. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 397 | </para> | 
|  | 398 |  | 
|  | 399 | <para> | 
|  | 400 | A better method is to create a configuration fragment using the | 
|  | 401 | differences between two configuration files: one previously | 
|  | 402 | created and saved, and one freshly created using the | 
|  | 403 | <filename>menuconfig</filename> tool. | 
|  | 404 | </para> | 
|  | 405 |  | 
|  | 406 | <para> | 
|  | 407 | To create a configuration fragment using this method, follow | 
|  | 408 | these steps: | 
|  | 409 | <orderedlist> | 
|  | 410 | <listitem><para>Complete a build at least through the kernel | 
|  | 411 | configuration task as follows: | 
|  | 412 | <literallayout class='monospaced'> | 
|  | 413 | $ bitbake linux-yocto -c kernel_configme -f | 
|  | 414 | </literallayout> | 
|  | 415 | This step ensures that you will be creating a | 
|  | 416 | <filename>.config</filename> file from a known state. | 
|  | 417 | Because situations exist where your build state might | 
|  | 418 | become unknown, it is best to run the previous | 
|  | 419 | command prior to starting up | 
|  | 420 | <filename>menuconfig</filename>. | 
|  | 421 | </para></listitem> | 
|  | 422 | <listitem><para>Run the <filename>menuconfig</filename> | 
|  | 423 | command: | 
|  | 424 | <literallayout class='monospaced'> | 
|  | 425 | $ bitbake linux-yocto -c menuconfig | 
|  | 426 | </literallayout></para></listitem> | 
|  | 427 | <listitem><para>Run the <filename>diffconfig</filename> | 
|  | 428 | command to prepare a configuration fragment. | 
|  | 429 | The resulting file <filename>fragment.cfg</filename> | 
|  | 430 | will be placed in the | 
|  | 431 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}</filename> directory: | 
|  | 432 | <literallayout class='monospaced'> | 
|  | 433 | $ bitbake linux-yocto -c diffconfig | 
|  | 434 | </literallayout></para></listitem> | 
|  | 435 | </orderedlist> | 
|  | 436 | </para> | 
|  | 437 |  | 
|  | 438 | <para> | 
|  | 439 | The <filename>diffconfig</filename> command creates a file that is a | 
|  | 440 | list of Linux kernel <filename>CONFIG_</filename> assignments. | 
|  | 441 | See the "<link linkend='changing-the-configuration'>Changing the Configuration</link>" | 
|  | 442 | section for information on how to use the output as a | 
|  | 443 | configuration fragment. | 
|  | 444 | <note> | 
|  | 445 | You can also use this method to create configuration | 
|  | 446 | fragments for a BSP. | 
|  | 447 | See the "<link linkend='bsp-descriptions'>BSP Descriptions</link>" | 
|  | 448 | section for more information. | 
|  | 449 | </note> | 
|  | 450 | </para> | 
|  | 451 |  | 
|  | 452 | <para> | 
|  | 453 | The kernel tools also provide configuration validation. | 
|  | 454 | You can use these tools to produce warnings for when a | 
|  | 455 | requested configuration does not appear in the final | 
|  | 456 | <filename>.config</filename> file or when you override a | 
|  | 457 | policy configuration in a hardware configuration fragment. | 
|  | 458 | Here is an example with some sample output of the command | 
|  | 459 | that runs these tools: | 
|  | 460 | <literallayout class='monospaced'> | 
|  | 461 | $ bitbake linux-yocto -c kernel_configcheck -f | 
|  | 462 |  | 
|  | 463 | ... | 
|  | 464 |  | 
|  | 465 | NOTE: validating kernel configuration | 
|  | 466 | This BSP sets 3 invalid/obsolete kernel options. | 
|  | 467 | These config options are not offered anywhere within this kernel. | 
|  | 468 | The full list can be found in your kernel src dir at: | 
|  | 469 | meta/cfg/standard/mybsp/invalid.cfg | 
|  | 470 |  | 
|  | 471 | This BSP sets 21 kernel options that are possibly non-hardware related. | 
|  | 472 | The full list can be found in your kernel src dir at: | 
|  | 473 | meta/cfg/standard/mybsp/specified_non_hdw.cfg | 
|  | 474 |  | 
|  | 475 | WARNING: There were 2 hardware options requested that do not | 
|  | 476 | have a corresponding value present in the final ".config" file. | 
|  | 477 | This probably means you are not getting the config you wanted. | 
|  | 478 | The full list can be found in your kernel src dir at: | 
|  | 479 | meta/cfg/standard/mybsp/mismatch.cfg | 
|  | 480 | </literallayout> | 
|  | 481 | </para> | 
|  | 482 |  | 
|  | 483 | <para> | 
|  | 484 | The output describes the various problems that you can | 
|  | 485 | encounter along with where to find the offending configuration | 
|  | 486 | items. | 
|  | 487 | You can use the information in the logs to adjust your | 
|  | 488 | configuration files and then repeat the | 
|  | 489 | <filename>kernel_configme</filename> and | 
|  | 490 | <filename>kernel_configcheck</filename> commands until | 
|  | 491 | they produce no warnings. | 
|  | 492 | </para> | 
|  | 493 |  | 
|  | 494 | <para> | 
|  | 495 | For more information on how to use the | 
|  | 496 | <filename>menuconfig</filename> tool, see the | 
|  | 497 | "<ulink url='&YOCTO_DOCS_DEV_URL;#using-menuconfig'>Using <filename>menuconfig</filename></ulink>" | 
|  | 498 | section in the Yocto Project Development Manual. | 
|  | 499 | </para> | 
|  | 500 | </section> | 
|  | 501 |  | 
|  | 502 | <section id='modifying-source-code'> | 
|  | 503 | <title>Modifying Source Code</title> | 
|  | 504 |  | 
|  | 505 | <para> | 
|  | 506 | You can experiment with source code changes and create a | 
|  | 507 | simple patch without leaving the BitBake environment. | 
|  | 508 | To get started, be sure to complete a build at | 
|  | 509 | least through the kernel configuration task: | 
|  | 510 | <literallayout class='monospaced'> | 
|  | 511 | $ bitbake linux-yocto -c kernel_configme -f | 
|  | 512 | </literallayout> | 
|  | 513 | Taking this step ensures you have the sources prepared | 
|  | 514 | and the configuration completed. | 
|  | 515 | You can find the sources in the | 
|  | 516 | <filename>${</filename><ulink url='&YOCTO_DOCS_REF_URL;#var-WORKDIR'><filename>WORKDIR</filename></ulink><filename>}/linux</filename> directory. | 
|  | 517 | </para> | 
|  | 518 |  | 
|  | 519 | <para> | 
|  | 520 | You can edit the sources as you would any other Linux source | 
|  | 521 | tree. | 
|  | 522 | However, keep in mind that you will lose changes if you | 
|  | 523 | trigger the | 
|  | 524 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-fetch'><filename>do_fetch</filename></ulink> | 
|  | 525 | task for the recipe. | 
|  | 526 | You can avoid triggering this task by not using BitBake to | 
|  | 527 | run the | 
|  | 528 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-cleanall'><filename>cleanall</filename></ulink>, | 
|  | 529 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-cleansstate'><filename>cleansstate</filename></ulink>, | 
|  | 530 | or forced | 
|  | 531 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-fetch'><filename>fetch</filename></ulink> | 
|  | 532 | commands. | 
|  | 533 | Also, do not modify the recipe itself while working | 
|  | 534 | with temporary changes or BitBake might run the | 
|  | 535 | <filename>fetch</filename> command depending on the | 
|  | 536 | changes to the recipe. | 
|  | 537 | </para> | 
|  | 538 |  | 
|  | 539 | <para> | 
|  | 540 | To test your temporary changes, instruct BitBake to run the | 
|  | 541 | <filename>compile</filename> again. | 
|  | 542 | The <filename>-f</filename> option forces the command to run | 
|  | 543 | even though BitBake might think it has already done so: | 
|  | 544 | <literallayout class='monospaced'> | 
|  | 545 | $ bitbake linux-yocto -c compile -f | 
|  | 546 | </literallayout> | 
|  | 547 | If the compile fails, you can update the sources and repeat | 
|  | 548 | the <filename>compile</filename>. | 
|  | 549 | Once compilation is successful, you can inspect and test | 
|  | 550 | the resulting build (i.e. kernel, modules, and so forth) from | 
|  | 551 | the following build directory: | 
|  | 552 | <literallayout class='monospaced'> | 
|  | 553 | ${WORKDIR}/linux-${PACKAGE_ARCH}-${LINUX_KERNEL_TYPE}-build | 
|  | 554 | </literallayout> | 
|  | 555 | Alternatively, you can run the <filename>deploy</filename> | 
|  | 556 | command to place the kernel image in the | 
|  | 557 | <filename>tmp/deploy/images</filename> directory: | 
|  | 558 | <literallayout class='monospaced'> | 
|  | 559 | $ bitbake linux-yocto -c deploy | 
|  | 560 | </literallayout> | 
|  | 561 | And, of course, you can perform the remaining installation and | 
|  | 562 | packaging steps by issuing: | 
|  | 563 | <literallayout class='monospaced'> | 
|  | 564 | $ bitbake linux-yocto | 
|  | 565 | </literallayout> | 
|  | 566 | </para> | 
|  | 567 |  | 
|  | 568 | <para> | 
|  | 569 | For rapid iterative development, the edit-compile-repeat loop | 
|  | 570 | described in this section is preferable to rebuilding the | 
|  | 571 | entire recipe because the installation and packaging tasks | 
|  | 572 | are very time consuming. | 
|  | 573 | </para> | 
|  | 574 |  | 
|  | 575 | <para> | 
|  | 576 | Once you are satisfied with your source code modifications, | 
|  | 577 | you can make them permanent by generating patches and | 
|  | 578 | applying them to the | 
|  | 579 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> | 
|  | 580 | statement as described in the | 
|  | 581 | "<link linkend='applying-patches'>Applying Patches</link>" | 
|  | 582 | section. | 
|  | 583 | If you are not familiar with generating patches, refer to the | 
|  | 584 | "<ulink url='&YOCTO_DOCS_DEV_URL;#creating-the-patch'>Creating the Patch</ulink>" | 
|  | 585 | section in the Yocto Project Development Manual. | 
|  | 586 | </para> | 
|  | 587 | </section> | 
|  | 588 | </section> | 
|  | 589 |  | 
|  | 590 | <section id='working-with-your-own-sources'> | 
|  | 591 | <title>Working With Your Own Sources</title> | 
|  | 592 |  | 
|  | 593 | <para> | 
|  | 594 | If you cannot work with one of the Linux kernel | 
|  | 595 | versions supported by existing linux-yocto recipes, you can | 
|  | 596 | still make use of the Yocto Project Linux kernel tooling by | 
|  | 597 | working with your own sources. | 
|  | 598 | When you use your own sources, you will not be able to | 
|  | 599 | leverage the existing kernel | 
|  | 600 | <ulink url='&YOCTO_DOCS_DEV_URL;#metadata'>Metadata</ulink> and | 
|  | 601 | stabilization work of the linux-yocto sources. | 
|  | 602 | However, you will be able to manage your own Metadata in the same | 
|  | 603 | format as the linux-yocto sources. | 
|  | 604 | Maintaining format compatibility facilitates converging with | 
|  | 605 | linux-yocto on a future, mutually-supported kernel version. | 
|  | 606 | </para> | 
|  | 607 |  | 
|  | 608 | <para> | 
|  | 609 | To help you use your own sources, the Yocto Project provides a | 
|  | 610 | linux-yocto custom recipe | 
|  | 611 | (<filename>linux-yocto-custom.bb</filename>) that uses | 
|  | 612 | <filename>kernel.org</filename> sources | 
|  | 613 | and the Yocto Project Linux kernel tools for managing | 
|  | 614 | kernel Metadata. | 
|  | 615 | You can find this recipe in the | 
|  | 616 | <filename>poky</filename> Git repository of the | 
|  | 617 | Yocto Project <ulink url='&YOCTO_GIT_URL;'>Source Repository</ulink> | 
|  | 618 | at: | 
|  | 619 | <literallayout class="monospaced"> | 
|  | 620 | poky/meta-skeleton/recipes-kernel/linux/linux-yocto-custom.bb | 
|  | 621 | </literallayout> | 
|  | 622 | </para> | 
|  | 623 |  | 
|  | 624 | <para> | 
|  | 625 | Here are some basic steps you can use to work with your own sources: | 
|  | 626 | <orderedlist> | 
|  | 627 | <listitem><para>Copy the <filename>linux-yocto-custom.bb</filename> | 
|  | 628 | recipe to your layer and give it a meaningful name. | 
|  | 629 | The name should include the version of the Linux kernel you | 
|  | 630 | are using (e.g. | 
|  | 631 | <filename>linux-yocto-myproject_3.19.bb</filename>, | 
|  | 632 | where "3.19" is the base version of the Linux kernel | 
|  | 633 | with which you would be working).</para></listitem> | 
|  | 634 | <listitem><para>In the same directory inside your layer, | 
|  | 635 | create a matching directory | 
|  | 636 | to store your patches and configuration files (e.g. | 
|  | 637 | <filename>linux-yocto-myproject</filename>). | 
|  | 638 | </para></listitem> | 
|  | 639 | <listitem><para>Make sure you have either a | 
|  | 640 | <filename>defconfig</filename> file or configuration | 
|  | 641 | fragment files. | 
|  | 642 | When you use the <filename>linux-yocto-custom.bb</filename> | 
|  | 643 | recipe, you must specify a configuration. | 
|  | 644 | If you do not have a <filename>defconfig</filename> file, | 
|  | 645 | you can run the following: | 
|  | 646 | <literallayout class='monospaced'> | 
|  | 647 | $ make defconfig | 
|  | 648 | </literallayout> | 
|  | 649 | After running the command, copy the resulting | 
|  | 650 | <filename>.config</filename> to the | 
|  | 651 | <filename>files</filename> directory as "defconfig" and | 
|  | 652 | then add it to the | 
|  | 653 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> | 
|  | 654 | variable in the recipe.</para> | 
|  | 655 | <para>Running the <filename>make defconfig</filename> | 
|  | 656 | command results in the default configuration for your | 
|  | 657 | architecture as defined by your kernel. | 
|  | 658 | However, no guarantee exists that this configuration is | 
|  | 659 | valid for your use case, or that your board will even boot. | 
|  | 660 | This is particularly true for non-x86 architectures. | 
|  | 661 | To use non-x86 <filename>defconfig</filename> files, you | 
|  | 662 | need to be more specific and find one that matches your | 
|  | 663 | board (i.e. for arm, you look in | 
|  | 664 | <filename>arch/arm/configs</filename> and use the one that | 
|  | 665 | is the best starting point for your board). | 
|  | 666 | </para></listitem> | 
|  | 667 | <listitem><para>Edit the following variables in your recipe | 
|  | 668 | as appropriate for your project: | 
|  | 669 | <itemizedlist> | 
|  | 670 | <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>: | 
|  | 671 | The <filename>SRC_URI</filename> should specify | 
|  | 672 | a Git repository that uses one of the supported Git | 
|  | 673 | fetcher protocols (i.e. <filename>file</filename>, | 
|  | 674 | <filename>git</filename>, <filename>http</filename>, | 
|  | 675 | and so forth). | 
|  | 676 | The <filename>SRC_URI</filename> variable should | 
|  | 677 | also specify either a <filename>defconfig</filename> | 
|  | 678 | file or some configuration fragment files. | 
|  | 679 | The skeleton recipe provides an example | 
|  | 680 | <filename>SRC_URI</filename> as a syntax reference. | 
|  | 681 | </para></listitem> | 
|  | 682 | <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-LINUX_VERSION'><filename>LINUX_VERSION</filename></ulink>: | 
|  | 683 | The Linux kernel version you are using (e.g. | 
|  | 684 | "3.19").</para></listitem> | 
|  | 685 | <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-LINUX_VERSION_EXTENSION'><filename>LINUX_VERSION_EXTENSION</filename></ulink>: | 
|  | 686 | The Linux kernel <filename>CONFIG_LOCALVERSION</filename> | 
|  | 687 | that is compiled into the resulting kernel and visible | 
|  | 688 | through the <filename>uname</filename> command. | 
|  | 689 | </para></listitem> | 
|  | 690 | <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-SRCREV'><filename>SRCREV</filename></ulink>: | 
|  | 691 | The commit ID from which you want to build. | 
|  | 692 | </para></listitem> | 
|  | 693 | <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink>: | 
|  | 694 | Treat this variable the same as you would in any other | 
|  | 695 | recipe. | 
|  | 696 | Increment the variable to indicate to the OpenEmbedded | 
|  | 697 | build system that the recipe has changed. | 
|  | 698 | </para></listitem> | 
|  | 699 | <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink>: | 
|  | 700 | The default <filename>PV</filename> assignment is | 
|  | 701 | typically adequate. | 
|  | 702 | It combines the <filename>LINUX_VERSION</filename> | 
|  | 703 | with the Source Control Manager (SCM) revision | 
|  | 704 | as derived from the | 
|  | 705 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRCPV'><filename>SRCPV</filename></ulink> | 
|  | 706 | variable. | 
|  | 707 | The combined results are a string with | 
|  | 708 | the following form: | 
|  | 709 | <literallayout class='monospaced'> | 
|  | 710 | 3.19.11+git1+68a635bf8dfb64b02263c1ac80c948647cc76d5f_1+218bd8d2022b9852c60d32f0d770931e3cf343e2 | 
|  | 711 | </literallayout> | 
|  | 712 | While lengthy, the extra verbosity in <filename>PV</filename> | 
|  | 713 | helps ensure you are using the exact | 
|  | 714 | sources from which you intend to build. | 
|  | 715 | </para></listitem> | 
|  | 716 | <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-COMPATIBLE_MACHINE'><filename>COMPATIBLE_MACHINE</filename></ulink>: | 
|  | 717 | A list of the machines supported by your new recipe. | 
|  | 718 | This variable in the example recipe is set | 
|  | 719 | by default to a regular expression that matches | 
|  | 720 | only the empty string, "(^$)". | 
|  | 721 | This default setting triggers an explicit build | 
|  | 722 | failure. | 
|  | 723 | You must change it to match a list of the machines | 
|  | 724 | that your new recipe supports. | 
|  | 725 | For example, to support the <filename>qemux86</filename> | 
|  | 726 | and <filename>qemux86-64</filename> machines, use | 
|  | 727 | the following form: | 
|  | 728 | <literallayout class='monospaced'> | 
|  | 729 | COMPATIBLE_MACHINE = "qemux86|qemux86-64" | 
|  | 730 | </literallayout></para></listitem> | 
|  | 731 | </itemizedlist></para></listitem> | 
|  | 732 | <listitem><para>Provide further customizations to your recipe | 
|  | 733 | as needed just as you would customize an existing | 
|  | 734 | linux-yocto recipe. | 
|  | 735 | See the "<link linkend='modifying-an-existing-recipe'>Modifying | 
|  | 736 | an Existing Recipe</link>" section for information. | 
|  | 737 | </para></listitem> | 
|  | 738 | </orderedlist> | 
|  | 739 | </para> | 
|  | 740 | </section> | 
|  | 741 |  | 
|  | 742 | <section id='working-with-out-of-tree-modules'> | 
|  | 743 | <title>Working with Out-of-Tree Modules</title> | 
|  | 744 |  | 
|  | 745 | <para> | 
|  | 746 | This section describes steps to build out-of-tree modules on | 
|  | 747 | your target and describes how to incorporate out-of-tree modules | 
|  | 748 | in the build. | 
|  | 749 | </para> | 
|  | 750 |  | 
|  | 751 | <section id='building-out-of-tree-modules-on-the-target'> | 
|  | 752 | <title>Building Out-of-Tree Modules on the Target</title> | 
|  | 753 |  | 
|  | 754 | <para> | 
|  | 755 | While the traditional Yocto Project development model would be | 
|  | 756 | to include kernel modules as part of the normal build | 
|  | 757 | process, you might find it useful to build modules on the | 
|  | 758 | target. | 
|  | 759 | This could be the case if your target system is capable | 
|  | 760 | and powerful enough to handle the necessary compilation. | 
|  | 761 | Before deciding to build on your target, however, you should | 
|  | 762 | consider the benefits of using a proper cross-development | 
|  | 763 | environment from your build host. | 
|  | 764 | </para> | 
|  | 765 |  | 
|  | 766 | <para> | 
|  | 767 | If you want to be able to build out-of-tree modules on | 
|  | 768 | the target, there are some steps you need to take | 
|  | 769 | on the target that is running your SDK image. | 
|  | 770 | Briefly, the <filename>kernel-dev</filename> package | 
|  | 771 | is installed by default on all | 
|  | 772 | <filename>*.sdk</filename> images and the | 
|  | 773 | <filename>kernel-devsrc</filename> package is installed | 
|  | 774 | on many of the <filename>*.sdk</filename> images. | 
|  | 775 | However, you need to create some scripts prior to | 
|  | 776 | attempting to build the out-of-tree modules on the target | 
|  | 777 | that is running that image. | 
|  | 778 | </para> | 
|  | 779 |  | 
|  | 780 | <para> | 
|  | 781 | Prior to attempting to build the out-of-tree modules, | 
|  | 782 | you need to be on the target as root and you need to | 
|  | 783 | change to the <filename>/usr/src/kernel</filename> directory. | 
|  | 784 | Next, <filename>make</filename> the scripts: | 
|  | 785 | <literallayout class='monospaced'> | 
|  | 786 | # cd /usr/src/kernel | 
|  | 787 | # make scripts | 
|  | 788 | </literallayout> | 
|  | 789 | Because all SDK image recipes include | 
|  | 790 | <filename>dev-pkgs</filename>, the | 
|  | 791 | <filename>kernel-dev</filename> packages will be installed | 
|  | 792 | as part of the SDK image and the | 
|  | 793 | <filename>kernel-devsrc</filename> packages will be installed | 
|  | 794 | as part of applicable SDK images. | 
|  | 795 | The SDK uses the scripts when building out-of-tree | 
|  | 796 | modules. | 
|  | 797 | Once you have switched to that directory and created the | 
|  | 798 | scripts, you should be able to build your out-of-tree modules | 
|  | 799 | on the target. | 
|  | 800 | </para> | 
|  | 801 | </section> | 
|  | 802 |  | 
|  | 803 | <section id='incorporating-out-of-tree-modules'> | 
|  | 804 | <title>Incorporating Out-of-Tree Modules</title> | 
|  | 805 |  | 
|  | 806 | <para> | 
|  | 807 | While it is always preferable to work with sources integrated | 
|  | 808 | into the Linux kernel sources, if you need an external kernel | 
|  | 809 | module, the <filename>hello-mod.bb</filename> recipe is | 
|  | 810 | available as a template from which you can create your | 
|  | 811 | own out-of-tree Linux kernel module recipe. | 
|  | 812 | </para> | 
|  | 813 |  | 
|  | 814 | <para> | 
|  | 815 | This template recipe is located in the | 
|  | 816 | <filename>poky</filename> Git repository of the | 
|  | 817 | Yocto Project <ulink url='&YOCTO_GIT_URL;'>Source Repository</ulink> | 
|  | 818 | at: | 
|  | 819 | <literallayout class="monospaced"> | 
|  | 820 | poky/meta-skeleton/recipes-kernel/hello-mod/hello-mod_0.1.bb | 
|  | 821 | </literallayout> | 
|  | 822 | </para> | 
|  | 823 |  | 
|  | 824 | <para> | 
|  | 825 | To get started, copy this recipe to your layer and give it a | 
|  | 826 | meaningful name (e.g. <filename>mymodule_1.0.bb</filename>). | 
|  | 827 | In the same directory, create a new directory named | 
|  | 828 | <filename>files</filename> where you can store any source files, | 
|  | 829 | patches, or other files necessary for building | 
|  | 830 | the module that do not come with the sources. | 
|  | 831 | Finally, update the recipe as needed for the module. | 
|  | 832 | Typically, you will need to set the following variables: | 
|  | 833 | <itemizedlist> | 
|  | 834 | <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-DESCRIPTION'><filename>DESCRIPTION</filename></ulink> | 
|  | 835 | </para></listitem> | 
|  | 836 | <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-LICENSE'><filename>LICENSE*</filename></ulink> | 
|  | 837 | </para></listitem> | 
|  | 838 | <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> | 
|  | 839 | </para></listitem> | 
|  | 840 | <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink> | 
|  | 841 | </para></listitem> | 
|  | 842 | </itemizedlist> | 
|  | 843 | </para> | 
|  | 844 |  | 
|  | 845 | <para> | 
|  | 846 | Depending on the build system used by the module sources, | 
|  | 847 | you might need to make some adjustments. | 
|  | 848 | For example, a typical module <filename>Makefile</filename> | 
|  | 849 | looks much like the one provided with the | 
|  | 850 | <filename>hello-mod</filename> template: | 
|  | 851 | <literallayout class='monospaced'> | 
|  | 852 | obj-m := hello.o | 
|  | 853 |  | 
|  | 854 | SRC := $(shell pwd) | 
|  | 855 |  | 
|  | 856 | all: | 
|  | 857 | $(MAKE) -C $(KERNEL_SRC) M=$(SRC) | 
|  | 858 |  | 
|  | 859 | modules_install: | 
|  | 860 | $(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules_install | 
|  | 861 | ... | 
|  | 862 | </literallayout> | 
|  | 863 | </para> | 
|  | 864 |  | 
|  | 865 | <para> | 
|  | 866 | The important point to note here is the | 
|  | 867 | <ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_SRC'><filename>KERNEL_SRC</filename></ulink> | 
|  | 868 | variable. | 
|  | 869 | The | 
|  | 870 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-classes-module'><filename>module</filename></ulink> | 
|  | 871 | class sets this variable and the | 
|  | 872 | <ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_PATH'><filename>KERNEL_PATH</filename></ulink> | 
|  | 873 | variable to | 
|  | 874 | <filename>${<ulink url='&YOCTO_DOCS_REF_URL;#var-STAGING_KERNEL_DIR'><filename>STAGING_KERNEL_DIR</filename></ulink>}</filename> | 
|  | 875 | with the necessary Linux kernel build information to build | 
|  | 876 | modules. | 
|  | 877 | If your module <filename>Makefile</filename> uses a different | 
|  | 878 | variable, you might want to override the | 
|  | 879 | <ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-compile'><filename>do_compile()</filename></ulink> | 
|  | 880 | step, or create a patch to | 
|  | 881 | the <filename>Makefile</filename> to work with the more typical | 
|  | 882 | <filename>KERNEL_SRC</filename> or | 
|  | 883 | <filename>KERNEL_PATH</filename> variables. | 
|  | 884 | </para> | 
|  | 885 |  | 
|  | 886 | <para> | 
|  | 887 | After you have prepared your recipe, you will likely want to | 
|  | 888 | include the module in your images. | 
|  | 889 | To do this, see the documentation for the following variables in | 
|  | 890 | the Yocto Project Reference Manual and set one of them | 
|  | 891 | appropriately for your machine configuration file: | 
|  | 892 | <itemizedlist> | 
|  | 893 | <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ESSENTIAL_EXTRA_RDEPENDS'><filename>MACHINE_ESSENTIAL_EXTRA_RDEPENDS</filename></ulink> | 
|  | 894 | </para></listitem> | 
|  | 895 | <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS'><filename>MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS</filename></ulink> | 
|  | 896 | </para></listitem> | 
|  | 897 | <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_EXTRA_RDEPENDS'><filename>MACHINE_EXTRA_RDEPENDS</filename></ulink> | 
|  | 898 | </para></listitem> | 
|  | 899 | <listitem><para><ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_EXTRA_RRECOMMENDS'><filename>MACHINE_EXTRA_RRECOMMENDS</filename></ulink> | 
|  | 900 | </para></listitem> | 
|  | 901 | </itemizedlist> | 
|  | 902 | </para> | 
|  | 903 |  | 
|  | 904 | <para> | 
|  | 905 | Modules are often not required for boot and can be excluded from | 
|  | 906 | certain build configurations. | 
|  | 907 | The following allows for the most flexibility: | 
|  | 908 | <literallayout class='monospaced'> | 
|  | 909 | MACHINE_EXTRA_RRECOMMENDS += "kernel-module-mymodule" | 
|  | 910 | </literallayout> | 
|  | 911 | The value is derived by appending the module filename without | 
|  | 912 | the <filename>.ko</filename> extension to the string | 
|  | 913 | "kernel-module-". | 
|  | 914 | </para> | 
|  | 915 |  | 
|  | 916 | <para> | 
|  | 917 | Because the variable is | 
|  | 918 | <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink> | 
|  | 919 | and not a | 
|  | 920 | <ulink url='&YOCTO_DOCS_REF_URL;#var-RDEPENDS'><filename>RDEPENDS</filename></ulink> | 
|  | 921 | variable, the build will not fail if this module is not | 
|  | 922 | available to include in the image. | 
|  | 923 | </para> | 
|  | 924 | </section> | 
|  | 925 | </section> | 
|  | 926 |  | 
|  | 927 |  | 
|  | 928 | <section id='inspecting-changes-and-commits'> | 
|  | 929 | <title>Inspecting Changes and Commits</title> | 
|  | 930 |  | 
|  | 931 | <para> | 
|  | 932 | A common question when working with a kernel is: | 
|  | 933 | "What changes have been applied to this tree?" | 
|  | 934 | Rather than using "grep" across directories to see what has | 
|  | 935 | changed, you can use Git to inspect or search the kernel tree. | 
|  | 936 | Using Git is an efficient way to see what has changed in the tree. | 
|  | 937 | </para> | 
|  | 938 |  | 
|  | 939 | <section id='what-changed-in-a-kernel'> | 
|  | 940 | <title>What Changed in a Kernel?</title> | 
|  | 941 |  | 
|  | 942 | <para> | 
|  | 943 | Following are a few examples that show how to use Git | 
|  | 944 | commands to examine changes. | 
|  | 945 | These examples are by no means the only way to see changes. | 
|  | 946 | <note> | 
|  | 947 | In the following examples, unless you provide a commit | 
|  | 948 | range, <filename>kernel.org</filename> history is blended | 
|  | 949 | with Yocto Project kernel changes. | 
|  | 950 | You can form ranges by using branch names from the | 
|  | 951 | kernel tree as the upper and lower commit markers with | 
|  | 952 | the Git commands. | 
|  | 953 | You can see the branch names through the web interface | 
|  | 954 | to the Yocto Project source repositories at | 
|  | 955 | <ulink url='http://git.yoctoproject.org/cgit.cgi'></ulink>. | 
|  | 956 | </note> | 
|  | 957 | To see a full range of the changes, use the | 
|  | 958 | <filename>git whatchanged</filename> command and specify a | 
|  | 959 | commit range for the branch | 
|  | 960 | (<replaceable>commit</replaceable><filename>..</filename><replaceable>commit</replaceable>). | 
|  | 961 | </para> | 
|  | 962 |  | 
|  | 963 | <para> | 
|  | 964 | Here is an example that looks at what has changed in the | 
|  | 965 | <filename>emenlow</filename> branch of the | 
|  | 966 | <filename>linux-yocto-3.19</filename> kernel. | 
|  | 967 | The lower commit range is the commit associated with the | 
|  | 968 | <filename>standard/base</filename> branch, while | 
|  | 969 | the upper commit range is the commit associated with the | 
|  | 970 | <filename>standard/emenlow</filename> branch. | 
|  | 971 | <literallayout class='monospaced'> | 
|  | 972 | $ git whatchanged origin/standard/base..origin/standard/emenlow | 
|  | 973 | </literallayout> | 
|  | 974 | </para> | 
|  | 975 |  | 
|  | 976 | <para> | 
|  | 977 | To see short, one line summaries of changes use the | 
|  | 978 | <filename>git log</filename> command: | 
|  | 979 | <literallayout class='monospaced'> | 
|  | 980 | $ git log --oneline origin/standard/base..origin/standard/emenlow | 
|  | 981 | </literallayout> | 
|  | 982 | </para> | 
|  | 983 |  | 
|  | 984 | <para> | 
|  | 985 | Use this command to see code differences for the changes: | 
|  | 986 | <literallayout class='monospaced'> | 
|  | 987 | $ git diff origin/standard/base..origin/standard/emenlow | 
|  | 988 | </literallayout> | 
|  | 989 | </para> | 
|  | 990 |  | 
|  | 991 | <para> | 
|  | 992 | Use this command to see the commit log messages and the | 
|  | 993 | text differences: | 
|  | 994 | <literallayout class='monospaced'> | 
|  | 995 | $ git show origin/standard/base..origin/standard/emenlow | 
|  | 996 | </literallayout> | 
|  | 997 | </para> | 
|  | 998 |  | 
|  | 999 | <para> | 
|  | 1000 | Use this command to create individual patches for | 
|  | 1001 | each change. | 
|  | 1002 | Here is an example that that creates patch files for each | 
|  | 1003 | commit and places them in your <filename>Documents</filename> | 
|  | 1004 | directory: | 
|  | 1005 | <literallayout class='monospaced'> | 
|  | 1006 | $ git format-patch -o $HOME/Documents origin/standard/base..origin/standard/emenlow | 
|  | 1007 | </literallayout> | 
|  | 1008 | </para> | 
|  | 1009 | </section> | 
|  | 1010 |  | 
|  | 1011 | <section id='showing-a-particular-feature-or-branch-change'> | 
|  | 1012 | <title>Showing a Particular Feature or Branch Change</title> | 
|  | 1013 |  | 
|  | 1014 | <para> | 
|  | 1015 | Tags in the Yocto Project kernel tree divide changes for | 
|  | 1016 | significant features or branches. | 
|  | 1017 | The <filename>git show</filename> <replaceable>tag</replaceable> | 
|  | 1018 | command shows changes based on a tag. | 
|  | 1019 | Here is an example that shows <filename>systemtap</filename> | 
|  | 1020 | changes: | 
|  | 1021 | <literallayout class='monospaced'> | 
|  | 1022 | $ git show systemtap | 
|  | 1023 | </literallayout> | 
|  | 1024 | You can use the | 
|  | 1025 | <filename>git branch --contains</filename> <replaceable>tag</replaceable> | 
|  | 1026 | command to show the branches that contain a particular feature. | 
|  | 1027 | This command shows the branches that contain the | 
|  | 1028 | <filename>systemtap</filename> feature: | 
|  | 1029 | <literallayout class='monospaced'> | 
|  | 1030 | $ git branch --contains systemtap | 
|  | 1031 | </literallayout> | 
|  | 1032 | </para> | 
|  | 1033 | </section> | 
|  | 1034 | </section> | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1035 |  | 
|  | 1036 | <section id='adding-recipe-space-kernel-features'> | 
|  | 1037 | <title>Adding Recipe-Space Kernel Features</title> | 
|  | 1038 |  | 
|  | 1039 | <para> | 
|  | 1040 | You can add kernel features in the | 
|  | 1041 | <link linkend='recipe-space-metadata'>recipe-space</link> by | 
|  | 1042 | using the | 
|  | 1043 | <ulink url='&YOCTO_DOCS_REF_URL;#var-KERNEL_FEATURES'><filename>KERNEL_FEATURES</filename></ulink> | 
|  | 1044 | variable and by specifying the feature's <filename>.scc</filename> | 
|  | 1045 | file path in the | 
|  | 1046 | <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink> | 
|  | 1047 | statement. | 
|  | 1048 | When you add features using this method, the OpenEmbedded build | 
|  | 1049 | system checks to be sure the features are present. | 
|  | 1050 | If the features are not present, the build stops. | 
|  | 1051 | Kernel features are the last elements processed for configuring | 
|  | 1052 | and patching the kernel. | 
|  | 1053 | Therefore, adding features in this manner is a way | 
|  | 1054 | to enforce specific features are present and enabled | 
|  | 1055 | without needing to do a full audit of any other layer's additions | 
|  | 1056 | to the <filename>SRC_URI</filename> statement. | 
|  | 1057 | </para> | 
|  | 1058 |  | 
|  | 1059 | <para> | 
|  | 1060 | You add a kernel feature by providing the feature as part of the | 
|  | 1061 | <filename>KERNEL_FEATURES</filename> variable and by providing the | 
|  | 1062 | path to the feature's <filename>.scc</filename> file, which is | 
|  | 1063 | relative to the root of the kernel Metadata. | 
|  | 1064 | The OpenEmbedded build system searches all forms of kernel | 
|  | 1065 | Metadata on the <filename>SRC_URI</filename> statement regardless | 
|  | 1066 | of whether the Metadata is in the "kernel-cache", system kernel | 
|  | 1067 | Metadata, or a recipe-space Metadata. | 
|  | 1068 | See the | 
|  | 1069 | "<link linkend='kernel-metadata-location'>Kernel Metadata Location</link>" | 
|  | 1070 | section for additional information. | 
|  | 1071 | </para> | 
|  | 1072 |  | 
|  | 1073 | <para> | 
|  | 1074 | When you specify the feature's <filename>.scc</filename> file | 
|  | 1075 | on the <filename>SRC_URI</filename> statement, the OpenEmbedded | 
|  | 1076 | build system adds the directory of that | 
|  | 1077 | <filename>.scc</filename> file along with all its subdirectories | 
|  | 1078 | to the kernel feature search path. | 
|  | 1079 | Because subdirectories are searched, you can reference a single | 
|  | 1080 | <filename>.scc</filename> file in the | 
|  | 1081 | <filename>SRC_URI</filename> statement to reference multiple kernel | 
|  | 1082 | features. | 
|  | 1083 | </para> | 
|  | 1084 |  | 
|  | 1085 | <para> | 
|  | 1086 | Consider the following example that adds the "test.scc" feature | 
|  | 1087 | to the build. | 
|  | 1088 | <orderedlist> | 
|  | 1089 | <listitem><para> | 
|  | 1090 | Create a <filename>.scc</filename> file and locate it | 
|  | 1091 | just as you would any other patch file, | 
|  | 1092 | <filename>.cfg</filename> file, or fetcher item | 
|  | 1093 | you specify in the <filename>SRC_URI</filename> | 
|  | 1094 | statement. | 
|  | 1095 | <note><title>Notes</title> | 
|  | 1096 | <itemizedlist> | 
|  | 1097 | <listitem><para> | 
|  | 1098 | You must add the directory of the | 
|  | 1099 | <filename>.scc</filename> file to the fetcher's | 
|  | 1100 | search path in the same manner as you would | 
|  | 1101 | add a <filename>.patch</filename> file. | 
|  | 1102 | </para></listitem> | 
|  | 1103 | <listitem><para> | 
|  | 1104 | You can create additional | 
|  | 1105 | <filename>.scc</filename> files beneath the | 
|  | 1106 | directory that contains the file you are | 
|  | 1107 | adding. | 
|  | 1108 | All subdirectories are searched during the | 
|  | 1109 | build as potential feature directories. | 
|  | 1110 | </para></listitem> | 
|  | 1111 | </itemizedlist> | 
|  | 1112 | </note> | 
|  | 1113 | Continuing with the example, suppose the "test.scc" | 
|  | 1114 | feature you are adding has a | 
|  | 1115 | <filename>test.scc</filename> file in the following | 
|  | 1116 | directory: | 
|  | 1117 | <literallayout class='monospaced'> | 
|  | 1118 | <replaceable>my_recipe</replaceable> | 
|  | 1119 | | | 
|  | 1120 | +-linux-yocto | 
|  | 1121 | | | 
|  | 1122 | +-test.cfg | 
|  | 1123 | +-test.scc | 
|  | 1124 | </literallayout> | 
|  | 1125 | In this example, the <filename>linux-yocto</filename> | 
|  | 1126 | directory has both the feature | 
|  | 1127 | <filename>test.scc</filename> file and a similarly | 
|  | 1128 | named configuration fragment file | 
|  | 1129 | <filename>test.cfg</filename>. | 
|  | 1130 | </para></listitem> | 
|  | 1131 | <listitem><para> | 
|  | 1132 | Add the <filename>.scc</filename> file to the | 
|  | 1133 | recipe's <filename>SRC_URI</filename> statement: | 
|  | 1134 | <literallayout class='monospaced'> | 
|  | 1135 | SRC_URI_append = " file://test.scc" | 
|  | 1136 | </literallayout> | 
|  | 1137 | The leading space before the path is important as the | 
|  | 1138 | path is appended to the existing path. | 
|  | 1139 | </para></listitem> | 
|  | 1140 | <listitem><para> | 
|  | 1141 | Specify the feature as a kernel feature: | 
|  | 1142 | <literallayout class='monospaced'> | 
|  | 1143 | KERNEL_FEATURES_append = " test.scc" | 
|  | 1144 | </literallayout> | 
|  | 1145 | The OpenEmbedded build system processes the kernel feature | 
|  | 1146 | when it builds the kernel. | 
|  | 1147 | <note> | 
|  | 1148 | If other features are contained below "test.scc", | 
|  | 1149 | then their directories are relative to the directory | 
|  | 1150 | containing the <filename>test.scc</filename> file. | 
|  | 1151 | </note> | 
|  | 1152 | </para></listitem> | 
|  | 1153 | </orderedlist> | 
|  | 1154 | </para> | 
|  | 1155 | </section> | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1156 | </chapter> | 
|  | 1157 | <!-- | 
|  | 1158 | vim: expandtab tw=80 ts=4 | 
|  | 1159 | --> |